home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2004 March / PCWELT_3_2004.ISO / pcwsoft / flaskmpeg_078_39_src.z.exe / flaskmpeg / MasterClock.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-10-28  |  2.3 KB  |  83 lines

  1. /* 
  2.  *  MasterClock.h
  3.  *
  4.  *    Copyright (C) Alberto Vigata - July 2000 - ultraflask@yahoo.com
  5.  *
  6.  *  This file is part of FlasKMPEG, a free MPEG to MPEG/AVI converter
  7.  *    
  8.  *  FlasKMPEG is free software; you can redistribute it and/or modify
  9.  *  it under the terms of the GNU General Public License as published by
  10.  *  the Free Software Foundation; either version 2, or (at your option)
  11.  *  any later version.
  12.  *   
  13.  *  FlasKMPEG is distributed in the hope that it will be useful,
  14.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  *  GNU General Public License for more details.
  17.  *   
  18.  *  You should have received a copy of the GNU General Public License
  19.  *  along with GNU Make; see the file COPYING.  If not, write to
  20.  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  21.  *
  22.  */
  23.  
  24.  
  25.  
  26.  
  27. #ifndef MASTERCLOCK_H
  28. #define MASTERCLOCK_H
  29.  
  30. #include "FlaskTypes.h"
  31. #include "Thread.h"
  32.  
  33. typedef ui64 tick;
  34. typedef ui64 mmtick; // A mmtick is defined as 100ns time period
  35.  
  36. #define FROMCOUNT_TO_TICK( counterticks, freq ) ((mmtick)((counterticks * 10000) / freq))
  37.  
  38. typedef enum { ClkSystem =0, ClkSlave} ClkType;
  39.  
  40.  
  41. class CMasterClock
  42. {
  43.  
  44.  
  45. public:
  46.   CMasterClock(ClkType nMode);
  47.   ~CMasterClock();
  48.   // Initialize the master clock.
  49.   // Must return true to be able to use all the other methods.
  50.   bool Initialize();
  51.   void Set(tick tkTime);
  52.  
  53.   // The mmticks elapsed from the
  54.   // moment we set the time with
  55.   // Set()
  56.   mmtick GetTickCount();
  57.  
  58.   // Wait waits tkTime, and blocks the calling thread
  59.   // during the period. tkWindowPeriod is the maximum
  60.   // value to wait
  61.   void Wait( mmtick tkTime, mmtick tkWindowPeriod );
  62.  
  63.   // Blocks the calling thread until the time of the
  64.   // clock goes avobe the specified time.
  65.   // The user has to be careful with this function
  66.   // because if the specified time is way off the given
  67.   // clock, the thread will be blocked. 
  68.   void WaitUntil( mmtick tkTime );
  69.  
  70. private:
  71.   ClkType m_nMode;
  72.   tick   m_tiFrequency, m_tiStartTime;
  73.   mmtick m_mmtkStartDelay, m_mmtkStartTime;
  74.  
  75.   mmtick m_tkTime; // when in slave mode, this is the current clock value
  76.   
  77.   CFlCritSec m_csGlobal; // Critical section to control reentrancy
  78.  
  79. };
  80.  
  81. #endif
  82.  
  83.