00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
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
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
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