OPAL  Version 3.14.3
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: 31115 $
30  * $Author: rjongbloed $
31  * $Date: 2013-12-19 11:33:11 +1100 (Thu, 19 Dec 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_config.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 
102  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  PTimeInterval tick = PTimer::Tick()
119  );
120 
125  virtual PBoolean ReadData(
126  RTP_DataFrame & frame,
127  PTimeInterval tick = PTimer::Tick()
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 
178 
187 
189  uint64_t m_frameTimeSum;
198 
199  enum {
205 
206  typedef std::map<DWORD, RTP_DataFrame> FrameMap;
209 
210 #if PTRACING
211  PTimeInterval m_lastInsertTick;
212  PTimeInterval m_lastRemoveTick;
213 #endif
214 
215  RTP_JitterBufferAnalyser * m_analyser;
216 };
217 
218 
223 {
225  public:
227  const Init & init
228  );
230 
232  virtual void Start();
233 
240  virtual PBoolean ReadData(
241  RTP_DataFrame & frame,
242  const PTimeInterval & tick = 0
243  );
244 
249  virtual PBoolean OnReadPacket(
250  RTP_DataFrame & frame
251  ) = 0;
252 
253  protected:
254  PDECLARE_NOTIFIER(PThread, OpalJitterBufferThread, JitterThreadMain);
255 
258 
259  PThread * m_jitterThread;
260  bool m_running;
261 };
262 
263 
264 #endif // OPAL_RTP_JITTER_H
265 
266