OPAL Version 3.10.4

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files

- File List
- Globals

jitter.h
Go to the documentation of this file.
1 /*
2 * jitter.h
3 *
4 * Jitter buffer support
5 *
6 * Open H323 Library
7 *
8 * Copyright (c) 1999-2001 Equivalence Pty. Ltd.
9 *
10 * The contents of this file are subject to the Mozilla Public License
11 * Version 1.0 (the "License"); you may not use this file except in
12 * compliance with the License. You may obtain a copy of the License at
13 * http://www.mozilla.org/MPL/
14 *
15 * Software distributed under the License is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17 * the License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * The Original Code is Open H323 Library.
21 *
22 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23 *
24 * Portions of this code were written with the assisance of funding from
25 * Vovida Networks, Inc. http://www.vovida.com.
26 *
27 * Contributor(s): ______________________________________.
28 *
29 * $Revision: 25990 $
30 * $Author: rjongbloed $
31 * $Date: 2011-06-08 22:17:09 -0500 (Wed, 08 Jun 2011) $
32 */
33
34 #ifndef OPAL_RTP_JITTER_H
35 #define OPAL_RTP_JITTER_H
36
37 #ifdef P_USE_PRAGMA
38 #pragma interface
39 #endif
40
41 #include <opal/buildopts.h>
42
43 #include <rtp/rtp.h>
44
45
46 class RTP_JitterBuffer;
47 class RTP_JitterBufferAnalyser;
48
49
51
55 class OpalJitterBuffer : public PSafeObject
56 {
57 PCLASSINFO(OpalJitterBuffer, PSafeObject);
58
59 public:
65 OpalJitterBuffer(
66 unsigned minJitterDelay,
67 unsigned maxJitterDelay,
68 unsigned timeUnits = 8,
69 PINDEX packetSize = 2048
70 );
71
74 virtual ~OpalJitterBuffer();
76
80 void PrintOn(
81 ostream & strm
82 ) const;
84
89 void SetDelay(
90 unsigned minJitterDelay,
91 unsigned maxJitterDelay,
92 PINDEX packetSize = 2048
93 );
94
97 void Reset();
98
101 virtual PBoolean WriteData(
102 const RTP_DataFrame & frame,
103 const PTimeInterval & tick = 0
104 );
105
110 virtual PBoolean ReadData(
111 RTP_DataFrame & frame,
112 const PTimeInterval & tick = 0
113 );
114
117 DWORD GetCurrentJitterDelay() const { return m_currentJitterDelay; }
118
121 DWORD GetMinJitterDelay() const { return m_minJitterDelay; }
122
125 DWORD GetMaxJitterDelay() const { return m_maxJitterDelay; }
126
129 unsigned GetTimeUnits() const { return m_timeUnits; }
130
133 DWORD GetPacketsTooLate() const { return m_packetsTooLate; }
134
137 DWORD GetBufferOverruns() const { return m_bufferOverruns; }
138
141 DWORD GetMaxConsecutiveMarkerBits() const { return m_maxConsecutiveMarkerBits; }
142
145 void SetMaxConsecutiveMarkerBits(DWORD max) { m_maxConsecutiveMarkerBits = max; }
147
148 protected:
149 DWORD CalculateRequiredTimestamp(DWORD playOutTimestamp) const;
150 bool AdjustCurrentJitterDelay(int delta);
151
152 unsigned m_timeUnits;
153 PINDEX m_packetSize;
154 DWORD m_minJitterDelay;
155 DWORD m_maxJitterDelay;
156 int m_jitterGrowTime;
157 DWORD m_jitterShrinkPeriod;
158
159 int m_jitterShrinkTime;
160 DWORD m_silenceShrinkPeriod;
161 int m_silenceShrinkTime;
162 DWORD m_jitterDriftPeriod;
163
164 int m_currentJitterDelay;
165 DWORD m_packetsTooLate;
166 DWORD m_bufferOverruns;
167 DWORD m_consecutiveMarkerBits;
168 DWORD m_maxConsecutiveMarkerBits;
169 DWORD m_consecutiveLatePackets;
170
171 DWORD m_averageFrameTime;
172 DWORD m_lastTimestamp;
173 DWORD m_bufferFilledTime;
174 DWORD m_bufferLowTime;
175 DWORD m_bufferEmptiedTime;
176 int m_timestampDelta;
177
178 enum {
179 e_SynchronisationStart,
180 e_SynchronisationFill,
181 e_SynchronisationShrink,
182 e_SynchronisationDone
183 } m_synchronisationState;
184
185 typedef std::map<DWORD, RTP_DataFrame> FrameMap;
186 FrameMap m_frames;
187 PMutex m_bufferMutex;
188
189 RTP_JitterBufferAnalyser * m_analyser;
190 };
191
192
196 class OpalJitterBufferThread : public OpalJitterBuffer
197 {
198 PCLASSINFO(OpalJitterBufferThread, OpalJitterBuffer);
199 public:
200 OpalJitterBufferThread(
201 unsigned minJitterDelay,
202 unsigned maxJitterDelay,
203 unsigned timeUnits = 8,
204 PINDEX packetSize = 2048
205 );
206 ~OpalJitterBufferThread();
207
214 virtual PBoolean ReadData(
215 RTP_DataFrame & frame
216 );
217
222 virtual PBoolean OnReadPacket(
223 RTP_DataFrame & frame
224 ) = 0;
225
226 protected:
227 PDECLARE_NOTIFIER(PThread, OpalJitterBufferThread, JitterThreadMain);
228
230 void StartThread();
231
233 void WaitForThreadTermination();
234
235 PThread * m_jitterThread;
236 bool m_running;
237 };
238
239
241
244 class RTP_JitterBuffer : public OpalJitterBufferThread
245 {
246 PCLASSINFO(RTP_JitterBuffer, OpalJitterBufferThread);
247 public:
248 RTP_JitterBuffer(
249 RTP_Session & session,
250 unsigned minJitterDelay,
251 unsigned maxJitterDelay,
252 unsigned timeUnits = 8,
253 PINDEX packetSize = 2048
254 );
255 ~RTP_JitterBuffer();
256
261 virtual PBoolean OnReadPacket(
262 RTP_DataFrame & frame
263 );
264
265 protected:
267 RTP_Session & m_session;
268 };
269
270 #endif // OPAL_RTP_JITTER_H
271
272