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 #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
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
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