delaychan.h
Go to the documentation of this file.
/*
* delaychan.h
*
* Class for implementing a serial queue channel in memory.
*
* Portable Windows Library
*
* Copyright (c) 2001 Equivalence Pty. Ltd.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Portable Windows Library.
*
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
*
* Contributor(s): ______________________________________.
*
* $Revision: 24177 $
* $Author: rjongbloed $
* $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
*/
#ifndef PTLIB_DELAYCHAN_H
#define PTLIB_DELAYCHAN_H
#include <ptlib/contain.h>
#include <ptlib/object.h>
#include <ptlib/timeint.h>
#include <ptlib/ptime.h>
#include <ptlib/indchan.h>
#ifdef P_USE_PRAGMA
#pragma interface
#endif
class PAdaptiveDelay : public PObject
{
PCLASSINFO(PAdaptiveDelay, PObject);
public:
PAdaptiveDelay(
unsigned maximumSlip = 0,
unsigned minimumDelay = 0
);
void SetMaximumSlip(PTimeInterval maximumSlip)
{ jitterLimit = maximumSlip; }
PTimeInterval GetMaximumSlip() const
{ return jitterLimit; }
PBoolean Delay(int time);
void Restart();
protected:
PBoolean firstTime;
PTime targetTime;
PTimeInterval jitterLimit;
PTimeInterval minimumDelay;
};
class PDelayChannel : public PIndirectChannel
{
PCLASSINFO(PDelayChannel, PIndirectChannel);
public:
enum Mode {
DelayReadsOnly,
DelayWritesOnly,
DelayReadsAndWrites
};
PDelayChannel(
Mode mode,
unsigned frameDelay,
PINDEX frameSize = 0,
unsigned maximumSlip = 250,
unsigned minimumDelay = 10
);
PDelayChannel(
PChannel &channel,
Mode mode,
unsigned frameDelay,
PINDEX frameSize = 0,
unsigned maximumSlip = 250,
unsigned minimumDelay = 10
);
virtual PBoolean Read(
void * buf,
PINDEX len
);
virtual PBoolean Write(
const void * buf,
PINDEX len
);
protected:
virtual void Wait(PINDEX count, PTimeInterval & nextTick);
Mode mode;
unsigned frameDelay;
PINDEX frameSize;
PTimeInterval maximumSlip;
PTimeInterval minimumDelay;
PTimeInterval nextReadTick;
PTimeInterval nextWriteTick;
};
#endif // PTLIB_DELAYCHAN_H
// End Of File ///////////////////////////////////////////////////////////////
timeint.h
PAdaptiveDelay::PAdaptiveDelay
PAdaptiveDelay(unsigned maximumSlip=0, unsigned minimumDelay=0)
Create a new adaptive delay with the specified parameters.
PAdaptiveDelay::GetMaximumSlip
PTimeInterval GetMaximumSlip() const
Get the current slip time.
Definition: delaychan.h:82
PTimeInterval
This class defines an arbitrary time interval to millisecond accuracy.
Definition: timeint.h:55
PDelayChannel::frameSize
PINDEX frameSize
Definition: delaychan.h:218
PCLASSINFO
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:1049
ptime.h
PTime
This class defines an absolute time and date.
Definition: ptime.h:53
PDelayChannel::Mode
Mode
Definition: delaychan.h:140
PIndirectChannel
This is a channel that operates indirectly through another channel(s).
Definition: indchan.h:49
indchan.h
PDelayChannel::DelayWritesOnly
Definition: delaychan.h:142
PAdaptiveDelay::targetTime
PTime targetTime
Definition: delaychan.h:112
PAdaptiveDelay::minimumDelay
PTimeInterval minimumDelay
Definition: delaychan.h:115
PBoolean
BOOL PBoolean
Definition: object.h:102
PAdaptiveDelay::SetMaximumSlip
void SetMaximumSlip(PTimeInterval maximumSlip)
Set the number of milliseconds that the delay may "catch up" by using zero delays.
Definition: delaychan.h:78
PDelayChannel
Class for implementing a "delay line" channel.
Definition: delaychan.h:134
contain.h
PChannel
Abstract class defining I/O channel semantics.
Definition: channel.h:107
PDelayChannel::DelayReadsOnly
Definition: delaychan.h:141
PAdaptiveDelay
Class for implementing an "adaptive" delay.
Definition: delaychan.h:52
PDelayChannel::maximumSlip
PTimeInterval maximumSlip
Definition: delaychan.h:219
PAdaptiveDelay::Delay
PBoolean Delay(int time)
Wait until the specified number of milliseconds have elapsed from the previous call (on average)...
object.h
PDelayChannel::nextWriteTick
PTimeInterval nextWriteTick
Definition: delaychan.h:223
PAdaptiveDelay::Restart
void Restart()
Invalidate the timer.
PDelayChannel::frameDelay
unsigned frameDelay
Definition: delaychan.h:217
PAdaptiveDelay::firstTime
PBoolean firstTime
Definition: delaychan.h:111
PDelayChannel::minimumDelay
PTimeInterval minimumDelay
Definition: delaychan.h:220
PAdaptiveDelay::jitterLimit
PTimeInterval jitterLimit
Definition: delaychan.h:114
PDelayChannel::nextReadTick
PTimeInterval nextReadTick
Definition: delaychan.h:222
PObject
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
PDelayChannel::mode
Mode mode
Definition: delaychan.h:216