jitter.h

Go to the documentation of this file.
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.11  2007/01/09 23:04:41  dereksmithies
00031  * Abstract out the jitterbuffer. This enables the use of the jitter buffer
00032  * in quite different circumstances (such as iax2 and test programs).
00033  *
00034  * Revision 2.10  2006/11/20 07:27:47  csoutheren
00035  * Fix compilation problem on Linux
00036  *
00037  * Revision 2.9  2006/11/20 03:37:12  csoutheren
00038  * Allow optional inclusion of RTP aggregation
00039  *
00040  * Revision 2.8  2005/12/30 14:29:15  dsandras
00041  * Removed the assumption that the jitter will contain a 8 kHz signal.
00042  *
00043  * Revision 2.7  2005/11/30 13:35:26  csoutheren
00044  * Changed tags for Doxygen
00045  *
00046  * Revision 2.6  2004/02/19 10:47:01  rjongbloed
00047  * Merged OpenH323 version 1.13.1 changes.
00048  *
00049  * Revision 2.5  2002/11/10 11:33:17  robertj
00050  * Updated to OpenH323 v1.10.3
00051  *
00052  * Revision 2.4  2002/09/16 02:52:35  robertj
00053  * Added #define so can select if #pragma interface/implementation is used on
00054  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00055  *
00056  * Revision 2.3  2002/09/04 06:01:47  robertj
00057  * Updated to OpenH323 v1.9.6
00058  *
00059  * Revision 2.2  2002/04/15 08:50:14  robertj
00060  * Added buffer reset on excess buffer overruns.
00061  *
00062  * Revision 2.1  2001/10/05 00:22:13  robertj
00063  * Updated to PWLib 1.2.0 and OpenH323 1.7.0
00064  *
00065  * Revision 2.0  2001/07/27 15:48:24  robertj
00066  * Conversion of OpenH323 to Open Phone Abstraction Library (OPAL)
00067  *
00068  * Revision 1.13  2003/10/28 22:38:31  dereksmithies
00069  * Rework of jitter buffer. Many thanks to Henry Harrison of Alice Street.
00070  *
00071  * Revision 1.12ACC1.0 6th October 2003 henryh
00072  * Complete change to adaptive algorithm 
00073  *
00074  * Revision 1.12  2002/10/31 00:32:39  robertj
00075  * Enhanced jitter buffer system so operates dynamically between minimum and
00076  *   maximum values. Altered API to assure app writers note the change!
00077  *
00078  * Revision 1.11  2002/09/16 01:14:15  robertj
00079  * Added #define so can select if #pragma interface/implementation is used on
00080  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00081  *
00082  * Revision 1.10  2002/09/03 05:40:18  robertj
00083  * Normalised the multi-include header prevention ifdef/define symbol.
00084  * Added buffer reset on excess buffer overruns.
00085  * Added ability to get buffer overruns for statistics display.
00086  *
00087  * Revision 1.9  2002/08/05 10:03:47  robertj
00088  * Cosmetic changes to normalise the usage of pragma interface/implementation.
00089  *
00090  * Revision 1.8  2001/09/11 00:21:21  robertj
00091  * Fixed missing stack sizes in endpoint for cleaner thread and jitter thread.
00092  *
00093  * Revision 1.7  2001/02/09 05:16:24  robertj
00094  * Added #pragma interface for GNU C++.
00095  *
00096  * Revision 1.6  2000/05/25 02:26:12  robertj
00097  * Added ignore of marker bits on broken clients that sets it on every RTP packet.
00098  *
00099  * Revision 1.5  2000/05/04 11:49:21  robertj
00100  * Added Packets Too Late statistics, requiring major rearrangement of jitter buffer code.
00101  *
00102  * Revision 1.4  2000/05/02 04:32:24  robertj
00103  * Fixed copyright notice comment.
00104  *
00105  * Revision 1.3  2000/04/30 03:56:14  robertj
00106  * More instrumentation to analyse jitter buffer operation.
00107  *
00108  * Revision 1.2  2000/03/20 20:51:13  robertj
00109  * Fixed possible buffer overrun problem in RTP_DataFrames
00110  *
00111  * Revision 1.1  1999/12/23 23:02:35  robertj
00112  * File reorganision for separating RTP from H.323 and creation of LID for VPB support.
00113  *
00114  */
00115 
00116 #ifndef __OPAL_JITTER_H
00117 #define __OPAL_JITTER_H
00118 
00119 #ifdef P_USE_PRAGMA
00120 #pragma interface
00121 #endif
00122 
00123 #include <rtp/rtp.h>
00124 
00125 class RTP_JitterBuffer;
00126 class RTP_JitterBufferAnalyser;
00127 
00128 
00130 
00134 class OpalJitterBuffer : public PObject
00135 {
00136   PCLASSINFO(OpalJitterBuffer, PObject);
00137 
00138   public:
00139 #if OPAL_RTP_AGGREGATE
00140     friend class RTP_AggregatedHandle;
00141 #endif
00142 
00144     OpalJitterBuffer(
00145       unsigned minJitterDelay, 
00146       unsigned maxJitterDelay, 
00147       unsigned timeUnits = 8,  
00148       PINDEX stackSize = 30000 
00149     );
00150     
00152     ~OpalJitterBuffer();
00153 
00155     void PrintOn(ostream & strm  ) const;
00156 
00162     virtual BOOL OnReadPacket    (
00163         RTP_DataFrame & frame,  
00164         BOOL loop               
00165         ) = 0;
00166 
00167 //    PINDEX GetSize() const { return bufferSize; }
00170     void SetDelay(
00171       unsigned minJitterDelay, 
00172       unsigned maxJitterDelay  
00173     );
00174 
00175     void UseImmediateReduction(BOOL state) { doJitterReductionImmediately = state; }
00176 
00182     virtual BOOL ReadData(
00183       DWORD timestamp,        
00184       RTP_DataFrame & frame   
00185     );
00186 
00189     DWORD GetJitterTime() const { return currentJitterTime; }
00190 
00193     unsigned GetTimeUnits() const { return timeUnits; }
00194     
00197     DWORD GetPacketsTooLate() const { return packetsTooLate; }
00198 
00201     DWORD GetBufferOverruns() const { return bufferOverruns; }
00202 
00205     DWORD GetMaxConsecutiveMarkerBits() const { return maxConsecutiveMarkerBits; }
00206 
00209     void SetMaxConsecutiveMarkerBits(DWORD max) { maxConsecutiveMarkerBits = max; }
00210 
00213     void Resume(PHandleAggregator * aggregator = NULL);
00214 
00215     PDECLARE_NOTIFIER(PThread, OpalJitterBuffer, JitterThreadMain);
00216 
00217     BOOL WaitForTermination(const PTimeInterval & t)
00218     { return (jitterThread == NULL) ? TRUE : jitterThread->WaitForTermination(t); }
00219 
00220   protected:
00221     class Entry : public RTP_DataFrame
00222     {
00223       public:
00224         Entry * next;
00225         Entry * prev;
00226         PTimeInterval tick;
00227     };
00228 
00229     PINDEX        bufferSize;
00230     DWORD         minJitterTime;
00231     DWORD         maxJitterTime;
00232     DWORD         maxConsecutiveMarkerBits;
00233 
00234     unsigned timeUnits;
00235     unsigned currentDepth;
00236     DWORD    currentJitterTime;
00237     DWORD    packetsTooLate;
00238     unsigned bufferOverruns;
00239     unsigned consecutiveBufferOverruns;
00240     DWORD    consecutiveMarkerBits;
00241     PTimeInterval    consecutiveEarlyPacketStartTime;
00242     DWORD    lastWriteTimestamp;
00243     PTimeInterval lastWriteTick;
00244     DWORD    jitterCalc;
00245     DWORD    targetJitterTime;
00246     unsigned jitterCalcPacketCount;
00247     BOOL     doJitterReductionImmediately;
00248     BOOL     doneFreeTrash;
00249 
00250     Entry * oldestFrame;
00251     Entry * newestFrame;
00252     Entry * freeFrames;
00253     Entry * currentWriteFrame;
00254 
00255     PMutex bufferMutex;
00256     BOOL   shuttingDown;
00257     BOOL   preBuffering;
00258     BOOL   doneFirstWrite;
00259 
00260     RTP_JitterBufferAnalyser * analyser;
00261 
00262     PThread * jitterThread;
00263     PINDEX    jitterStackSize;
00264 
00265     RTP_AggregatedHandle * aggregratedHandle;
00266 
00267     BOOL Init(Entry * & currentReadFrame, BOOL & markerWarning);
00268     BOOL PreRead(Entry * & currentReadFrame, BOOL & markerWarning);
00269     BOOL OnRead(Entry * & currentReadFrame, BOOL & markerWarning, BOOL loop);
00270     void DeInit(Entry * & currentReadFrame, BOOL & markerWarning);
00271 };
00272 
00274 
00276 class RTP_JitterBuffer : public OpalJitterBuffer
00277 {
00278     PCLASSINFO(RTP_JitterBuffer, OpalJitterBuffer);
00279 
00280  public:
00281         RTP_JitterBuffer(
00282             RTP_Session & session,   
00283             unsigned minJitterDelay, 
00284             unsigned maxJitterDelay, 
00285             unsigned timeUnits = 8,  
00286             PINDEX stackSize = 30000 
00287             );
00288         
00289         
00294     virtual BOOL OnReadPacket    (
00295         RTP_DataFrame & frame,  
00296         BOOL loop               
00297         ) ;
00298 
00299  protected:
00301    RTP_Session & session;
00302 };
00303 
00304 
00305 
00306 #endif // __OPAL_JITTER_H
00307 
00308 

Generated on Fri Mar 7 06:33:38 2008 for OPAL by  doxygen 1.5.1