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 #ifndef _DELAYCHAN_H
00032 #define _DELAYCHAN_H
00033
00034
00035 #ifdef P_USE_PRAGMA
00036 #pragma interface
00037 #endif
00038
00039 #ifndef _PTLIB_H
00040 #include <ptlib.h>
00041 #endif
00042
00051 class PAdaptiveDelay : public PObject
00052 {
00053 PCLASSINFO(PAdaptiveDelay, PObject);
00054
00055 public:
00056
00063 PAdaptiveDelay(
00064 unsigned maximumSlip = 0,
00065 unsigned minimumDelay = 0
00066 );
00068
00077 void SetMaximumSlip(PTimeInterval maximumSlip)
00078 { jitterLimit = maximumSlip; }
00079
00081 PTimeInterval GetMaximumSlip() const
00082 { return jitterLimit; }
00084
00101 PBoolean Delay(int time);
00102
00106 void Restart();
00108
00109 protected:
00110 PBoolean firstTime;
00111 PTime targetTime;
00112
00113 PTimeInterval jitterLimit;
00114 PTimeInterval minimumDelay;
00115 };
00116
00117
00133 class PDelayChannel : public PIndirectChannel
00134 {
00135 PCLASSINFO(PDelayChannel, PIndirectChannel);
00136 public:
00139 enum Mode {
00140 DelayReadsOnly,
00141 DelayWritesOnly,
00142 DelayReadsAndWrites
00143 };
00144
00152 PDelayChannel(
00153 Mode mode,
00154 unsigned frameDelay,
00155 PINDEX frameSize = 0,
00156 unsigned maximumSlip = 250,
00157 unsigned minimumDelay = 10
00158 );
00159
00167 PDelayChannel(
00168 PChannel &channel,
00169 Mode mode,
00170 unsigned frameDelay,
00171 PINDEX frameSize = 0,
00172 unsigned maximumSlip = 250,
00173 unsigned minimumDelay = 10
00174 );
00176
00177
00191 virtual PBoolean Read(
00192 void * buf,
00193 PINDEX len
00194 );
00195
00205 virtual PBoolean Write(
00206 const void * buf,
00207 PINDEX len
00208 );
00210
00211
00212 protected:
00213 virtual void Wait(PINDEX count, PTimeInterval & nextTick);
00214
00215 Mode mode;
00216 unsigned frameDelay;
00217 PINDEX frameSize;
00218 PTimeInterval maximumSlip;
00219 PTimeInterval minimumDelay;
00220
00221 PTimeInterval nextReadTick;
00222 PTimeInterval nextWriteTick;
00223 };
00224
00225
00226 #endif // _DELAYCHAN_H
00227
00228
00229