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
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 #ifndef __OPAL_JITTER_H
00117 #define __OPAL_JITTER_H
00118
00119 #ifdef P_USE_PRAGMA
00120 #pragma interface
00121 #endif
00122
00123 #include <rtp/rtp.h>
00124
00125 class RTP_JitterBuffer;
00126 class RTP_JitterBufferAnalyser;
00127
00128
00130
00134 class OpalJitterBuffer : public PObject
00135 {
00136 PCLASSINFO(OpalJitterBuffer, PObject);
00137
00138 public:
00139 #if OPAL_RTP_AGGREGATE
00140 friend class RTP_AggregatedHandle;
00141 #endif
00142
00144 OpalJitterBuffer(
00145 unsigned minJitterDelay,
00146 unsigned maxJitterDelay,
00147 unsigned timeUnits = 8,
00148 PINDEX stackSize = 30000
00149 );
00150
00152 ~OpalJitterBuffer();
00153
00155 void PrintOn(ostream & strm ) const;
00156
00162 virtual BOOL OnReadPacket (
00163 RTP_DataFrame & frame,
00164 BOOL loop
00165 ) = 0;
00166
00167
00170 void SetDelay(
00171 unsigned minJitterDelay,
00172 unsigned maxJitterDelay
00173 );
00174
00175 void UseImmediateReduction(BOOL state) { doJitterReductionImmediately = state; }
00176
00182 virtual BOOL ReadData(
00183 DWORD timestamp,
00184 RTP_DataFrame & frame
00185 );
00186
00189 DWORD GetJitterTime() const { return currentJitterTime; }
00190
00193 unsigned GetTimeUnits() const { return timeUnits; }
00194
00197 DWORD GetPacketsTooLate() const { return packetsTooLate; }
00198
00201 DWORD GetBufferOverruns() const { return bufferOverruns; }
00202
00205 DWORD GetMaxConsecutiveMarkerBits() const { return maxConsecutiveMarkerBits; }
00206
00209 void SetMaxConsecutiveMarkerBits(DWORD max) { maxConsecutiveMarkerBits = max; }
00210
00213 void Resume(PHandleAggregator * aggregator = NULL);
00214
00215 PDECLARE_NOTIFIER(PThread, OpalJitterBuffer, JitterThreadMain);
00216
00217 BOOL WaitForTermination(const PTimeInterval & t)
00218 { return (jitterThread == NULL) ? TRUE : jitterThread->WaitForTermination(t); }
00219
00220 protected:
00221 class Entry : public RTP_DataFrame
00222 {
00223 public:
00224 Entry * next;
00225 Entry * prev;
00226 PTimeInterval tick;
00227 };
00228
00229 PINDEX bufferSize;
00230 DWORD minJitterTime;
00231 DWORD maxJitterTime;
00232 DWORD maxConsecutiveMarkerBits;
00233
00234 unsigned timeUnits;
00235 unsigned currentDepth;
00236 DWORD currentJitterTime;
00237 DWORD packetsTooLate;
00238 unsigned bufferOverruns;
00239 unsigned consecutiveBufferOverruns;
00240 DWORD consecutiveMarkerBits;
00241 PTimeInterval consecutiveEarlyPacketStartTime;
00242 DWORD lastWriteTimestamp;
00243 PTimeInterval lastWriteTick;
00244 DWORD jitterCalc;
00245 DWORD targetJitterTime;
00246 unsigned jitterCalcPacketCount;
00247 BOOL doJitterReductionImmediately;
00248 BOOL doneFreeTrash;
00249
00250 Entry * oldestFrame;
00251 Entry * newestFrame;
00252 Entry * freeFrames;
00253 Entry * currentWriteFrame;
00254
00255 PMutex bufferMutex;
00256 BOOL shuttingDown;
00257 BOOL preBuffering;
00258 BOOL doneFirstWrite;
00259
00260 RTP_JitterBufferAnalyser * analyser;
00261
00262 PThread * jitterThread;
00263 PINDEX jitterStackSize;
00264
00265 RTP_AggregatedHandle * aggregratedHandle;
00266
00267 BOOL Init(Entry * & currentReadFrame, BOOL & markerWarning);
00268 BOOL PreRead(Entry * & currentReadFrame, BOOL & markerWarning);
00269 BOOL OnRead(Entry * & currentReadFrame, BOOL & markerWarning, BOOL loop);
00270 void DeInit(Entry * & currentReadFrame, BOOL & markerWarning);
00271 };
00272
00274
00276 class RTP_JitterBuffer : public OpalJitterBuffer
00277 {
00278 PCLASSINFO(RTP_JitterBuffer, OpalJitterBuffer);
00279
00280 public:
00281 RTP_JitterBuffer(
00282 RTP_Session & session,
00283 unsigned minJitterDelay,
00284 unsigned maxJitterDelay,
00285 unsigned timeUnits = 8,
00286 PINDEX stackSize = 30000
00287 );
00288
00289
00294 virtual BOOL OnReadPacket (
00295 RTP_DataFrame & frame,
00296 BOOL loop
00297 ) ;
00298
00299 protected:
00301 RTP_Session & session;
00302 };
00303
00304
00305
00306 #endif // __OPAL_JITTER_H
00307
00308