delaychan.h

Go to the documentation of this file.
00001 /*
00002  * delaychan.h
00003  *
00004  * Class for implementing a serial queue channel in memory.
00005  *
00006  * Portable Windows Library
00007  *
00008  * Copyright (c) 2001 Equivalence Pty. Ltd.
00009  *
00010  * The contents of this file are subject to the Mozilla Public License
00011  * Version 1.0 (the "License"); you may not use this file except in
00012  * compliance with the License. You may obtain a copy of the License at
00013  * http://www.mozilla.org/MPL/
00014  *
00015  * Software distributed under the License is distributed on an "AS IS"
00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  * the License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  * The Original Code is Portable Windows Library.
00021  *
00022  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00023  *
00024  * Contributor(s): ______________________________________.
00025  *
00026  * $Log: delaychan.h,v $
00027  * Revision 1.10  2007/04/18 23:49:50  csoutheren
00028  * Add usage of precompiled headers
00029  *
00030  * Revision 1.9  2006/07/21 01:03:12  csoutheren
00031  * Fixed to PAdaptiveDelay
00032  * Thanks to Paolo Amadini
00033  *
00034  * Revision 1.8  2006/07/19 06:03:34  csoutheren
00035  * Add extension PAdaptiveDelay to set maximum and minimum delay times
00036  * Thanks to Paolo Amadini
00037  *
00038  * Revision 1.7  2006/06/20 12:44:02  csoutheren
00039  * Added new constructor for PDelayChannel
00040  * Thanks to Frederic Heem
00041  *
00042  * Revision 1.6  2005/11/30 12:47:37  csoutheren
00043  * Removed tabs, reformatted some code, and changed tags for Doxygen
00044  *
00045  * Revision 1.5  2004/11/11 07:34:50  csoutheren
00046  * Added #include <ptlib.h>
00047  *
00048  * Revision 1.4  2002/09/16 01:08:59  robertj
00049  * Added #define so can select if #pragma interface/implementation is used on
00050  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00051  *
00052  * Revision 1.3  2002/02/25 11:05:02  rogerh
00053  * New Delay code which solves the accumulated error problem. Based on ideas
00054  * by Tomasz Motylewski <T.Motylewski@bfad.de>, Roger and Craig.
00055  *
00056  * Revision 1.2  2002/01/15 03:55:43  craigs
00057  * Added PAdaptiveDelay class
00058  *
00059  * Revision 1.1  2001/07/10 03:07:07  robertj
00060  * Added queue channel and delay channel classes to ptclib.
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 // End Of File ///////////////////////////////////////////////////////////////

Generated on Fri Mar 7 06:25:02 2008 for PTLib by  doxygen 1.5.1