Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

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

Generated on Sat Mar 5 14:59:09 2005 for OpenH323 by  doxygen 1.4.1