OPAL  Version 3.10.4
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:
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 
142 
147 
148  protected:
149  DWORD CalculateRequiredTimestamp(DWORD playOutTimestamp) const;
150  bool AdjustCurrentJitterDelay(int delta);
151 
152  unsigned m_timeUnits;
153  PINDEX m_packetSize;
158 
163 
170 
177 
178  enum {
184 
185  typedef std::map<DWORD, RTP_DataFrame> FrameMap;
188 
189  RTP_JitterBufferAnalyser * m_analyser;
190 };
191 
192 
197 {
199  public:
201  unsigned minJitterDelay,
202  unsigned maxJitterDelay,
203  unsigned timeUnits = 8,
204  PINDEX packetSize = 2048
205  );
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 
234 
235  PThread * m_jitterThread;
236  bool m_running;
237 };
238 
239 
241 
245 {
247  public:
249  RTP_Session & session,
250  unsigned minJitterDelay,
251  unsigned maxJitterDelay,
252  unsigned timeUnits = 8,
253  PINDEX packetSize = 2048
254  );
256 
261  virtual PBoolean OnReadPacket(
262  RTP_DataFrame & frame
263  );
264 
265  protected:
268 };
269 
270 #endif // OPAL_RTP_JITTER_H
271 
272