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.9  2006/07/21 01:03:12  csoutheren
00028  * Fixed to PAdaptiveDelay
00029  * Thanks to Paolo Amadini
00030  *
00031  * Revision 1.8  2006/07/19 06:03:34  csoutheren
00032  * Add extension PAdaptiveDelay to set maximum and minimum delay times
00033  * Thanks to Paolo Amadini
00034  *
00035  * Revision 1.7  2006/06/20 12:44:02  csoutheren
00036  * Added new constructor for PDelayChannel
00037  * Thanks to Frederic Heem
00038  *
00039  * Revision 1.6  2005/11/30 12:47:37  csoutheren
00040  * Removed tabs, reformatted some code, and changed tags for Doxygen
00041  *
00042  * Revision 1.5  2004/11/11 07:34:50  csoutheren
00043  * Added #include <ptlib.h>
00044  *
00045  * Revision 1.4  2002/09/16 01:08:59  robertj
00046  * Added #define so can select if #pragma interface/implementation is used on
00047  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00048  *
00049  * Revision 1.3  2002/02/25 11:05:02  rogerh
00050  * New Delay code which solves the accumulated error problem. Based on ideas
00051  * by Tomasz Motylewski <T.Motylewski@bfad.de>, Roger and Craig.
00052  *
00053  * Revision 1.2  2002/01/15 03:55:43  craigs
00054  * Added PAdaptiveDelay class
00055  *
00056  * Revision 1.1  2001/07/10 03:07:07  robertj
00057  * Added queue channel and delay channel classes to ptclib.
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 // End Of File ///////////////////////////////////////////////////////////////

Generated on Sun Sep 6 03:50:33 2009 for PWLib by  doxygen 1.6.1