delaychan.h
Go to the documentation of this file.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 #ifndef _DELAYCHAN_H
00062 #define _DELAYCHAN_H
00063
00064
00065 #ifdef P_USE_PRAGMA
00066 #pragma interface
00067 #endif
00068
00069 #include <ptlib.h>
00070
00079 class PAdaptiveDelay : public PObject
00080 {
00081 PCLASSINFO(PAdaptiveDelay, PObject);
00082
00083 public:
00084
00091 PAdaptiveDelay(
00092 unsigned maximumSlip = 0,
00093 unsigned minimumDelay = 0
00094 );
00096
00105 void SetMaximumSlip(PTimeInterval maximumSlip)
00106 { jitterLimit = maximumSlip; }
00107
00109 PTimeInterval GetMaximumSlip() const
00110 { return jitterLimit; }
00112
00129 BOOL Delay(int time);
00130
00134 void Restart();
00136
00137 protected:
00138 BOOL firstTime;
00139 PTime targetTime;
00140
00141 PTimeInterval jitterLimit;
00142 PTimeInterval minimumDelay;
00143 };
00144
00145
00161 class PDelayChannel : public PIndirectChannel
00162 {
00163 PCLASSINFO(PDelayChannel, PIndirectChannel);
00164 public:
00167 enum Mode {
00168 DelayReadsOnly,
00169 DelayWritesOnly,
00170 DelayReadsAndWrites
00171 };
00172
00180 PDelayChannel(
00181 Mode mode,
00182 unsigned frameDelay,
00183 PINDEX frameSize = 0,
00184 unsigned maximumSlip = 250,
00185 unsigned minimumDelay = 10
00186 );
00187
00195 PDelayChannel(
00196 PChannel &channel,
00197 Mode mode,
00198 unsigned frameDelay,
00199 PINDEX frameSize = 0,
00200 unsigned maximumSlip = 250,
00201 unsigned minimumDelay = 10
00202 );
00204
00205
00219 virtual BOOL Read(
00220 void * buf,
00221 PINDEX len
00222 );
00223
00233 virtual BOOL Write(
00234 const void * buf,
00235 PINDEX len
00236 );
00238
00239
00240 protected:
00241 virtual void Wait(PINDEX count, PTimeInterval & nextTick);
00242
00243 Mode mode;
00244 unsigned frameDelay;
00245 PINDEX frameSize;
00246 PTimeInterval maximumSlip;
00247 PTimeInterval minimumDelay;
00248
00249 PTimeInterval nextReadTick;
00250 PTimeInterval nextWriteTick;
00251 };
00252
00253
00254 #endif // _DELAYCHAN_H
00255
00256
00257