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

Generated on Wed Feb 6 09:02:43 2008 for OpenH323 by  doxygen 1.5.4