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 #ifndef _DELAYCHAN_H
00065 #define _DELAYCHAN_H
00066
00067
00068 #ifdef P_USE_PRAGMA
00069 #pragma interface
00070 #endif
00071
00072 #ifndef _PTLIB_H
00073 #include <ptlib.h>
00074 #endif
00075
00084 class PAdaptiveDelay : public PObject
00085 {
00086 PCLASSINFO(PAdaptiveDelay, PObject);
00087
00088 public:
00089
00096 PAdaptiveDelay(
00097 unsigned maximumSlip = 0,
00098 unsigned minimumDelay = 0
00099 );
00101
00110 void SetMaximumSlip(PTimeInterval maximumSlip)
00111 { jitterLimit = maximumSlip; }
00112
00114 PTimeInterval GetMaximumSlip() const
00115 { return jitterLimit; }
00117
00134 BOOL Delay(int time);
00135
00139 void Restart();
00141
00142 protected:
00143 BOOL firstTime;
00144 PTime targetTime;
00145
00146 PTimeInterval jitterLimit;
00147 PTimeInterval minimumDelay;
00148 };
00149
00150
00166 class PDelayChannel : public PIndirectChannel
00167 {
00168 PCLASSINFO(PDelayChannel, PIndirectChannel);
00169 public:
00172 enum Mode {
00173 DelayReadsOnly,
00174 DelayWritesOnly,
00175 DelayReadsAndWrites
00176 };
00177
00185 PDelayChannel(
00186 Mode mode,
00187 unsigned frameDelay,
00188 PINDEX frameSize = 0,
00189 unsigned maximumSlip = 250,
00190 unsigned minimumDelay = 10
00191 );
00192
00200 PDelayChannel(
00201 PChannel &channel,
00202 Mode mode,
00203 unsigned frameDelay,
00204 PINDEX frameSize = 0,
00205 unsigned maximumSlip = 250,
00206 unsigned minimumDelay = 10
00207 );
00209
00210
00224 virtual BOOL Read(
00225 void * buf,
00226 PINDEX len
00227 );
00228
00238 virtual BOOL Write(
00239 const void * buf,
00240 PINDEX len
00241 );
00243
00244
00245 protected:
00246 virtual void Wait(PINDEX count, PTimeInterval & nextTick);
00247
00248 Mode mode;
00249 unsigned frameDelay;
00250 PINDEX frameSize;
00251 PTimeInterval maximumSlip;
00252 PTimeInterval minimumDelay;
00253
00254 PTimeInterval nextReadTick;
00255 PTimeInterval nextWriteTick;
00256 };
00257
00258
00259 #endif // _DELAYCHAN_H
00260
00261
00262