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-2000 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 1.14  2005/11/30 13:05:01  csoutheren
00031  * Changed tags for Doxygen
00032  *
00033  * Revision 1.13  2003/10/28 22:38:31  dereksmithies
00034  * Rework of jitter buffer. Many thanks to Henry Harrison of Alice Street.
00035  *
00036  * Revision 1.12ACC1.0 6th October 2003 henryh
00037  * Complete change to adaptive algorithm 
00038  *
00039  * Revision 1.12  2002/10/31 00:32:39  robertj
00040  * Enhanced jitter buffer system so operates dynamically between minimum and
00041  *   maximum values. Altered API to assure app writers note the change!
00042  *
00043  * Revision 1.11  2002/09/16 01:14:15  robertj
00044  * Added #define so can select if #pragma interface/implementation is used on
00045  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00046  *
00047  * Revision 1.10  2002/09/03 05:40:18  robertj
00048  * Normalised the multi-include header prevention ifdef/define symbol.
00049  * Added buffer reset on excess buffer overruns.
00050  * Added ability to get buffer overruns for statistics display.
00051  *
00052  * Revision 1.9  2002/08/05 10:03:47  robertj
00053  * Cosmetic changes to normalise the usage of pragma interface/implementation.
00054  *
00055  * Revision 1.8  2001/09/11 00:21:21  robertj
00056  * Fixed missing stack sizes in endpoint for cleaner thread and jitter thread.
00057  *
00058  * Revision 1.7  2001/02/09 05:16:24  robertj
00059  * Added #pragma interface for GNU C++.
00060  *
00061  * Revision 1.6  2000/05/25 02:26:12  robertj
00062  * Added ignore of marker bits on broken clients that sets it on every RTP packet.
00063  *
00064  * Revision 1.5  2000/05/04 11:49:21  robertj
00065  * Added Packets Too Late statistics, requiring major rearrangement of jitter buffer code.
00066  *
00067  * Revision 1.4  2000/05/02 04:32:24  robertj
00068  * Fixed copyright notice comment.
00069  *
00070  * Revision 1.3  2000/04/30 03:56:14  robertj
00071  * More instrumentation to analyse jitter buffer operation.
00072  *
00073  * Revision 1.2  2000/03/20 20:51:13  robertj
00074  * Fixed possible buffer overrun problem in RTP_DataFrames
00075  *
00076  * Revision 1.1  1999/12/23 23:02:35  robertj
00077  * File reorganision for separating RTP from H.323 and creation of LID for VPB support.
00078  *
00079  */
00080 
00081 #ifndef __OPAL_JITTER_H
00082 #define __OPAL_JITTER_H
00083 
00084 #ifdef P_USE_PRAGMA
00085 #pragma interface
00086 #endif
00087 
00088 
00089 #include "rtp.h"
00090 
00091 
00092 class RTP_JitterBufferAnalyser;
00093 
00094 
00096 
00097 class RTP_JitterBuffer : public PThread
00098 {
00099   PCLASSINFO(RTP_JitterBuffer, PThread);
00100 
00101   public:
00102     RTP_JitterBuffer(
00103       RTP_Session & session,   
00104       unsigned minJitterDelay, 
00105       unsigned maxJitterDelay, 
00106       PINDEX stackSize = 30000 
00107     );
00108     ~RTP_JitterBuffer();
00109 
00110 //    PINDEX GetSize() const { return bufferSize; }
00113     void SetDelay(
00114       unsigned minJitterDelay, 
00115       unsigned maxJitterDelay  
00116     );
00117 
00118     void UseImmediateReduction(BOOL state) { doJitterReductionImmediately = state; }
00119 
00125     virtual BOOL ReadData(
00126       DWORD timestamp,        
00127       RTP_DataFrame & frame   
00128     );
00129 
00132     DWORD GetJitterTime() const { return currentJitterTime; }
00133 
00136     DWORD GetPacketsTooLate() const { return packetsTooLate; }
00137 
00140     DWORD GetBufferOverruns() const { return bufferOverruns; }
00141 
00144     DWORD GetMaxConsecutiveMarkerBits() const { return maxConsecutiveMarkerBits; }
00145 
00148     void SetMaxConsecutiveMarkerBits(DWORD max) { maxConsecutiveMarkerBits = max; }
00149 
00150 
00151   protected:
00152     virtual void Main();
00153 
00154     class Entry : public RTP_DataFrame
00155     {
00156       public:
00157         Entry * next;
00158         Entry * prev;
00159         PTimeInterval tick;
00160     };
00161 
00162     RTP_Session & session;
00163     PINDEX        bufferSize;
00164     DWORD         minJitterTime;
00165     DWORD         maxJitterTime;
00166     DWORD         maxConsecutiveMarkerBits;
00167 
00168     unsigned currentDepth;
00169     DWORD    currentJitterTime;
00170     DWORD    packetsTooLate;
00171     unsigned bufferOverruns;
00172     unsigned consecutiveBufferOverruns;
00173     DWORD    consecutiveMarkerBits;
00174     PTimeInterval    consecutiveEarlyPacketStartTime;
00175     DWORD    lastWriteTimestamp;
00176     PTimeInterval lastWriteTick;
00177     DWORD    jitterCalc;
00178     DWORD    targetJitterTime;
00179     unsigned jitterCalcPacketCount;
00180     BOOL     doJitterReductionImmediately;
00181     BOOL     doneFreeTrash;
00182 
00183     Entry * oldestFrame;
00184     Entry * newestFrame;
00185     Entry * freeFrames;
00186     Entry * currentWriteFrame;
00187 
00188     PMutex bufferMutex;
00189     BOOL   shuttingDown;
00190     BOOL   preBuffering;
00191     BOOL   doneFirstWrite;
00192 
00193     RTP_JitterBufferAnalyser * analyser;
00194 };
00195 
00196 
00197 #endif // __OPAL_JITTER_H
00198 
00199 

Generated on Wed Feb 6 23:05:22 2008 for OpenH323 by  doxygen 1.5.4