D:/Storage/CVS_Head/h323plus/include/jitter.h

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

Generated on Thu Oct 25 13:42:34 2007 for h323plus by  doxygen 1.5.2