00001 /* 00002 * jitter.h 00003 * 00004 * Jitter buffer support 00005 * 00006 * Open H323 Library 00007 * 00008 * Copyright (c) 1999-2001 Equivalence Pty. Ltd. 00009 * 00010 * The contents of this file are subject to the Mozilla Public License 00011 * Version 1.0 (the "License"); you may not use this file except in 00012 * compliance with the License. You may obtain a copy of the License at 00013 * http://www.mozilla.org/MPL/ 00014 * 00015 * Software distributed under the License is distributed on an "AS IS" 00016 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00017 * the License for the specific language governing rights and limitations 00018 * under the License. 00019 * 00020 * The Original Code is Open H323 Library. 00021 * 00022 * The Initial Developer of the Original Code is Equivalence Pty. Ltd. 00023 * 00024 * Portions of this code were written with the assisance of funding from 00025 * Vovida Networks, Inc. http://www.vovida.com. 00026 * 00027 * Contributor(s): ______________________________________. 00028 * 00029 * $Log: jitter.h,v $ 00030 * Revision 2.8 2005/12/30 14:29:15 dsandras 00031 * Removed the assumption that the jitter will contain a 8 kHz signal. 00032 * 00033 * Revision 2.7 2005/11/30 13:35:26 csoutheren 00034 * Changed tags for Doxygen 00035 * 00036 * Revision 2.6 2004/02/19 10:47:01 rjongbloed 00037 * Merged OpenH323 version 1.13.1 changes. 00038 * 00039 * Revision 2.5 2002/11/10 11:33:17 robertj 00040 * Updated to OpenH323 v1.10.3 00041 * 00042 * Revision 2.4 2002/09/16 02:52:35 robertj 00043 * Added #define so can select if #pragma interface/implementation is used on 00044 * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan. 00045 * 00046 * Revision 2.3 2002/09/04 06:01:47 robertj 00047 * Updated to OpenH323 v1.9.6 00048 * 00049 * Revision 2.2 2002/04/15 08:50:14 robertj 00050 * Added buffer reset on excess buffer overruns. 00051 * 00052 * Revision 2.1 2001/10/05 00:22:13 robertj 00053 * Updated to PWLib 1.2.0 and OpenH323 1.7.0 00054 * 00055 * Revision 2.0 2001/07/27 15:48:24 robertj 00056 * Conversion of OpenH323 to Open Phone Abstraction Library (OPAL) 00057 * 00058 * Revision 1.13 2003/10/28 22:38:31 dereksmithies 00059 * Rework of jitter buffer. Many thanks to Henry Harrison of Alice Street. 00060 * 00061 * Revision 1.12ACC1.0 6th October 2003 henryh 00062 * Complete change to adaptive algorithm 00063 * 00064 * Revision 1.12 2002/10/31 00:32:39 robertj 00065 * Enhanced jitter buffer system so operates dynamically between minimum and 00066 * maximum values. Altered API to assure app writers note the change! 00067 * 00068 * Revision 1.11 2002/09/16 01:14:15 robertj 00069 * Added #define so can select if #pragma interface/implementation is used on 00070 * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan. 00071 * 00072 * Revision 1.10 2002/09/03 05:40:18 robertj 00073 * Normalised the multi-include header prevention ifdef/define symbol. 00074 * Added buffer reset on excess buffer overruns. 00075 * Added ability to get buffer overruns for statistics display. 00076 * 00077 * Revision 1.9 2002/08/05 10:03:47 robertj 00078 * Cosmetic changes to normalise the usage of pragma interface/implementation. 00079 * 00080 * Revision 1.8 2001/09/11 00:21:21 robertj 00081 * Fixed missing stack sizes in endpoint for cleaner thread and jitter thread. 00082 * 00083 * Revision 1.7 2001/02/09 05:16:24 robertj 00084 * Added #pragma interface for GNU C++. 00085 * 00086 * Revision 1.6 2000/05/25 02:26:12 robertj 00087 * Added ignore of marker bits on broken clients that sets it on every RTP packet. 00088 * 00089 * Revision 1.5 2000/05/04 11:49:21 robertj 00090 * Added Packets Too Late statistics, requiring major rearrangement of jitter buffer code. 00091 * 00092 * Revision 1.4 2000/05/02 04:32:24 robertj 00093 * Fixed copyright notice comment. 00094 * 00095 * Revision 1.3 2000/04/30 03:56:14 robertj 00096 * More instrumentation to analyse jitter buffer operation. 00097 * 00098 * Revision 1.2 2000/03/20 20:51:13 robertj 00099 * Fixed possible buffer overrun problem in RTP_DataFrames 00100 * 00101 * Revision 1.1 1999/12/23 23:02:35 robertj 00102 * File reorganision for separating RTP from H.323 and creation of LID for VPB support. 00103 * 00104 */ 00105 00106 #ifndef __OPAL_JITTER_H 00107 #define __OPAL_JITTER_H 00108 00109 #ifdef P_USE_PRAGMA 00110 #pragma interface 00111 #endif 00112 00113 00114 #include <rtp/rtp.h> 00115 00116 00117 class RTP_JitterBufferAnalyser; 00118 00119 00121 00122 class RTP_JitterBuffer : public PThread 00123 { 00124 PCLASSINFO(RTP_JitterBuffer, PThread); 00125 00126 public: 00127 RTP_JitterBuffer( 00128 RTP_Session & session, 00129 unsigned minJitterDelay, 00130 unsigned maxJitterDelay, 00131 unsigned timeUnits = 8, 00132 PINDEX stackSize = 30000 00133 ); 00134 ~RTP_JitterBuffer(); 00135 00136 // PINDEX GetSize() const { return bufferSize; } 00139 void SetDelay( 00140 unsigned minJitterDelay, 00141 unsigned maxJitterDelay 00142 ); 00143 00144 void UseImmediateReduction(BOOL state) { doJitterReductionImmediately = state; } 00145 00151 virtual BOOL ReadData( 00152 DWORD timestamp, 00153 RTP_DataFrame & frame 00154 ); 00155 00158 DWORD GetJitterTime() const { return currentJitterTime; } 00159 00162 unsigned GetTimeUnits() const { return timeUnits; } 00163 00166 DWORD GetPacketsTooLate() const { return packetsTooLate; } 00167 00170 DWORD GetBufferOverruns() const { return bufferOverruns; } 00171 00174 DWORD GetMaxConsecutiveMarkerBits() const { return maxConsecutiveMarkerBits; } 00175 00178 void SetMaxConsecutiveMarkerBits(DWORD max) { maxConsecutiveMarkerBits = max; } 00179 00180 00181 protected: 00182 virtual void Main(); 00183 00184 class Entry : public RTP_DataFrame 00185 { 00186 public: 00187 Entry * next; 00188 Entry * prev; 00189 PTimeInterval tick; 00190 }; 00191 00192 RTP_Session & session; 00193 PINDEX bufferSize; 00194 DWORD minJitterTime; 00195 DWORD maxJitterTime; 00196 DWORD maxConsecutiveMarkerBits; 00197 00198 unsigned timeUnits; 00199 unsigned currentDepth; 00200 DWORD currentJitterTime; 00201 DWORD packetsTooLate; 00202 unsigned bufferOverruns; 00203 unsigned consecutiveBufferOverruns; 00204 DWORD consecutiveMarkerBits; 00205 PTimeInterval consecutiveEarlyPacketStartTime; 00206 DWORD lastWriteTimestamp; 00207 PTimeInterval lastWriteTick; 00208 DWORD jitterCalc; 00209 DWORD targetJitterTime; 00210 unsigned jitterCalcPacketCount; 00211 BOOL doJitterReductionImmediately; 00212 BOOL doneFreeTrash; 00213 00214 Entry * oldestFrame; 00215 Entry * newestFrame; 00216 Entry * freeFrames; 00217 Entry * currentWriteFrame; 00218 00219 PMutex bufferMutex; 00220 BOOL shuttingDown; 00221 BOOL preBuffering; 00222 BOOL doneFirstWrite; 00223 00224 RTP_JitterBufferAnalyser * analyser; 00225 }; 00226 00227 00228 #endif // __OPAL_JITTER_H 00229 00230