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  * $Revision: 22375 $
00027  * $Author: rjongbloed $
00028  * $Date: 2009-04-06 21:47:23 -0500 (Mon, 06 Apr 2009) $
00029  */
00030 
00031 #ifndef PTLIB_DELAYCHAN_H
00032 #define PTLIB_DELAYCHAN_H
00033 #include <ptlib/contain.h>
00034 #include <ptlib/object.h>
00035 #include <ptlib/timeint.h>
00036 #include <ptlib/ptime.h>
00037 #include <ptlib/indchan.h>
00038 
00039 #ifdef P_USE_PRAGMA
00040 #pragma interface
00041 #endif
00042 
00043 
00052 class PAdaptiveDelay : public PObject
00053 { 
00054   PCLASSINFO(PAdaptiveDelay, PObject);
00055   
00056   public:
00057 
00064     PAdaptiveDelay(
00065       unsigned maximumSlip = 0,   
00066       unsigned minimumDelay = 0   
00067     );
00069 
00078     void SetMaximumSlip(PTimeInterval maximumSlip)
00079     { jitterLimit = maximumSlip; }
00080 
00082     PTimeInterval GetMaximumSlip() const
00083     { return jitterLimit; }
00085 
00102     PBoolean Delay(int time);
00103 
00107     void Restart();
00109  
00110   protected:
00111     PBoolean   firstTime;
00112     PTime  targetTime;
00113 
00114     PTimeInterval  jitterLimit;
00115     PTimeInterval  minimumDelay;
00116 };
00117 
00118 
00134 class PDelayChannel : public PIndirectChannel
00135 {
00136     PCLASSINFO(PDelayChannel, PIndirectChannel);
00137   public:
00140     enum Mode {
00141       DelayReadsOnly,
00142       DelayWritesOnly,
00143       DelayReadsAndWrites
00144     };
00145 
00153     PDelayChannel(
00154       Mode mode,                  
00155       unsigned frameDelay,        
00156       PINDEX frameSize = 0,       
00157       unsigned maximumSlip = 250, 
00158       unsigned minimumDelay = 10  
00159     );
00160     
00168     PDelayChannel(
00169         PChannel &channel,          
00170         Mode mode,                  
00171         unsigned frameDelay,        
00172         PINDEX frameSize = 0,       
00173         unsigned maximumSlip = 250, 
00174         unsigned minimumDelay = 10  
00175                  );    
00177 
00178 
00192     virtual PBoolean Read(
00193       void * buf,   
00194       PINDEX len    
00195     );
00196 
00206     virtual PBoolean Write(
00207       const void * buf, 
00208       PINDEX len        
00209     );
00211 
00212 
00213   protected:
00214     virtual void Wait(PINDEX count, PTimeInterval & nextTick);
00215 
00216     Mode          mode;
00217     unsigned      frameDelay;
00218     PINDEX        frameSize;
00219     PTimeInterval maximumSlip;
00220     PTimeInterval minimumDelay;
00221 
00222     PTimeInterval nextReadTick;
00223     PTimeInterval nextWriteTick;
00224 };
00225 
00226 
00227 #endif // PTLIB_DELAYCHAN_H
00228 
00229 
00230 // End Of File ///////////////////////////////////////////////////////////////

Generated on Thu May 27 01:36:47 2010 for PTLib by  doxygen 1.4.7