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 #ifndef __OPAL_JITTER_H
00035 #define __OPAL_JITTER_H
00036
00037 #ifdef P_USE_PRAGMA
00038 #pragma interface
00039 #endif
00040
00041 #include <rtp/rtp.h>
00042
00043 #include <opal/buildopts.h>
00044
00045
00046 class RTP_JitterBuffer;
00047 class RTP_JitterBufferAnalyser;
00048
00049
00051
00055 class OpalJitterBuffer : public PObject
00056 {
00057 PCLASSINFO(OpalJitterBuffer, PObject);
00058
00059 public:
00062 OpalJitterBuffer(
00063 unsigned minJitterDelay,
00064 unsigned maxJitterDelay,
00065 unsigned timeUnits = 8,
00066 PINDEX stackSize = 30000
00067 );
00068
00070 virtual ~OpalJitterBuffer();
00071
00073 void PrintOn(ostream & strm ) const;
00074
00080 virtual PBoolean OnReadPacket (
00081 RTP_DataFrame & frame,
00082 PBoolean loop
00083 ) = 0;
00084
00085
00088 void SetDelay(
00089 unsigned minJitterDelay,
00090 unsigned maxJitterDelay
00091 );
00092
00093 void UseImmediateReduction(PBoolean state) { doJitterReductionImmediately = state; }
00094
00100 virtual PBoolean ReadData(
00101 RTP_DataFrame & frame
00102 );
00103
00106 DWORD GetJitterTime() const { return currentJitterTime; }
00107
00110 unsigned GetTimeUnits() const { return timeUnits; }
00111
00114 DWORD GetPacketsTooLate() const { return packetsTooLate; }
00115
00118 DWORD GetBufferOverruns() const { return bufferOverruns; }
00119
00122 DWORD GetMaxConsecutiveMarkerBits() const { return maxConsecutiveMarkerBits; }
00123
00126 void SetMaxConsecutiveMarkerBits(DWORD max) { maxConsecutiveMarkerBits = max; }
00127
00130 virtual void Resume(PHandleAggregator * aggregator = NULL);
00131
00132 PDECLARE_NOTIFIER(PThread, OpalJitterBuffer, JitterThreadMain);
00133
00134 PBoolean WaitForTermination(const PTimeInterval & t)
00135 {
00136 if (jitterThread == NULL)
00137 return PTrue;
00138 shuttingDown = true;
00139 return jitterThread->WaitForTermination(t);
00140 }
00141
00142 protected:
00143 class Entry : public RTP_DataFrame
00144 {
00145 public:
00146 Entry * next;
00147 Entry * prev;
00148 PTimeInterval tick;
00149 };
00150
00151 PINDEX bufferSize;
00152 DWORD minJitterTime;
00153 DWORD maxJitterTime;
00154 DWORD maxConsecutiveMarkerBits;
00155
00156 unsigned timeUnits;
00157 unsigned currentDepth;
00158 DWORD currentJitterTime;
00159 DWORD packetsTooLate;
00160 unsigned bufferOverruns;
00161 unsigned consecutiveBufferOverruns;
00162 DWORD consecutiveMarkerBits;
00163 PTimeInterval consecutiveEarlyPacketStartTime;
00164 DWORD lastWriteTimestamp;
00165 PTimeInterval lastWriteTick;
00166 DWORD jitterCalc;
00167 DWORD targetJitterTime;
00168 unsigned jitterCalcPacketCount;
00169 PBoolean doJitterReductionImmediately;
00170 PBoolean doneFreeTrash;
00171
00172 Entry * oldestFrame;
00173 Entry * newestFrame;
00174 Entry * freeFrames;
00175 Entry * currentFrame;
00176
00177 PMutex bufferMutex;
00178 bool shuttingDown;
00179 bool preBuffering;
00180 bool firstReadData;
00181
00182 RTP_JitterBufferAnalyser * analyser;
00183
00184 PThread * jitterThread;
00185 PINDEX jitterStackSize;
00186
00187 PBoolean Init(Entry * & currentReadFrame, PBoolean & markerWarning);
00188 PBoolean PreRead(Entry * & currentReadFrame, PBoolean & markerWarning);
00189 PBoolean OnRead(Entry * & currentReadFrame, PBoolean & markerWarning, PBoolean loop);
00190 void DeInit(Entry * & currentReadFrame, PBoolean & markerWarning);
00191 };
00192
00194
00196 class RTP_JitterBuffer : public OpalJitterBuffer
00197 {
00198 PCLASSINFO(RTP_JitterBuffer, OpalJitterBuffer);
00199
00200 public:
00201 RTP_JitterBuffer(
00202 RTP_Session & session,
00203 unsigned minJitterDelay,
00204 unsigned maxJitterDelay,
00205 unsigned timeUnits = 8,
00206 PINDEX stackSize = 30000
00207 );
00208 virtual ~RTP_JitterBuffer();
00209
00214 virtual PBoolean OnReadPacket (
00215 RTP_DataFrame & frame,
00216 PBoolean loop
00217 ) ;
00218
00221 virtual void Resume(PHandleAggregator * aggregator = NULL);
00222
00223 protected:
00225 RTP_Session & session;
00226 };
00227
00228 #endif // __OPAL_JITTER_H
00229
00230