OPAL  Version 3.12.5
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: 29341 $
30  * $Author: rjongbloed $
31  * $Date: 2013-03-27 02:06:24 -0500 (Wed, 27 Mar 2013) $
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 #include <ptlib/safecoll.h>
45 
46 
47 class RTP_JitterBuffer;
48 class RTP_JitterBufferAnalyser;
49 class OpalRTPSession;
50 
51 
53 
57 class OpalJitterBuffer : public PSafeObject
58 {
59  PCLASSINFO(OpalJitterBuffer, PSafeObject);
60 
61  public:
63  struct Init {
64  Init(unsigned minDelay = 0, unsigned maxDelay = 0)
65  : m_minJitterDelay(minDelay)
66  , m_maxJitterDelay(maxDelay != 0 ? maxDelay : minDelay)
67  , m_timeUnits(8)
68  , m_packetSize(2048)
69  { }
70 
71  unsigned m_minJitterDelay;
72  unsigned m_maxJitterDelay;
73  unsigned m_timeUnits;
74  PINDEX m_packetSize;
75  };
76 
83  const Init & init
84  );
85 
88  virtual ~OpalJitterBuffer();
90 
94  void PrintOn(
95  ostream & strm
96  ) const;
98 
101  virtual void Start() { }
103 
106  void SetDelay(
107  const Init & init
108  );
109 
112  void Reset();
113 
116  virtual PBoolean WriteData(
117  const RTP_DataFrame & frame,
118  const PTimeInterval & tick = 0
119  );
120 
125  virtual PBoolean ReadData(
126  RTP_DataFrame & frame,
127  const PTimeInterval & tick = 0
128  );
129 
132  DWORD GetCurrentJitterDelay() const { return m_currentJitterDelay; }
133 
136  DWORD GetMinJitterDelay() const { return m_minJitterDelay; }
137 
140  DWORD GetMaxJitterDelay() const { return m_maxJitterDelay; }
141 
144  unsigned GetTimeUnits() const { return m_timeUnits; }
145 
148  DWORD GetPacketsTooLate() const { return m_packetsTooLate; }
149 
152  DWORD GetBufferOverruns() const { return m_bufferOverruns; }
153 
157 
162 
163  protected:
164  DWORD CalculateRequiredTimestamp(DWORD playOutTimestamp) const;
165  bool AdjustCurrentJitterDelay(int delta);
166 
167  unsigned m_timeUnits;
168  PINDEX m_packetSize;
173  int m_jitterShrinkTime;
178 
185 
196 
197  enum {
203 
204  typedef std::map<DWORD, RTP_DataFrame> FrameMap;
207 
208  RTP_JitterBufferAnalyser * m_analyser;
209 };
210 
211 
216 {
218  public:
220  const Init & init
221  );
223 
225  virtual void Start();
226 
233  virtual PBoolean ReadData(
234  RTP_DataFrame & frame,
235  const PTimeInterval & tick = 0
236  );
237 
242  virtual PBoolean OnReadPacket(
243  RTP_DataFrame & frame
244  ) = 0;
245 
246  protected:
247  PDECLARE_NOTIFIER(PThread, OpalJitterBufferThread, JitterThreadMain);
248 
251 
252  PThread * m_jitterThread;
253  bool m_running;
254 };
255 
256 
257 #endif // OPAL_RTP_JITTER_H
258 
259