Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members
GlobalTimer.hpp
00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: GlobalTimer.hpp * 00006 * * 00007 * * 00008 * * 00009 * ITEC institute of the University of Klagenfurt (Austria) * 00010 * http://www.itec.uni-klu.ac.at * 00011 * * 00012 * * 00013 * For more information visit the ViTooKi homepage: * 00014 * http://ViTooKi.sourceforge.net * 00015 * vitooki-user@lists.sourceforge.net * 00016 * vitooki-devel@lists.sourceforge.net * 00017 * * 00018 * This file is part of ViTooKi, a free video toolkit. * 00019 * ViTooKi is free software; you can redistribute it and/or * 00020 * modify it under the terms of the GNU General Public License * 00021 * as published by the Free Software Foundation; either version 2 * 00022 * of the License, or (at your option) any later version. * 00023 * * 00024 * This program is distributed in the hope that it will be useful, * 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00027 * GNU General Public License for more details. * 00028 * * 00029 * You should have received a copy of the GNU General Public License * 00030 * along with this program; if not, write to the Free Software * 00031 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * 00032 * MA 02111-1307, USA. * 00033 * * 00034 ***********************************************************************/ 00035 00036 /*********************************************************************** 00037 * * 00038 * REVISION HISTORY: * 00039 * * 00040 * * 00041 * * 00042 ***********************************************************************/ 00043 00044 #ifndef _SYNCHRONIZER_HPP 00045 #define _SYNCHRONIZER_HPP 00046 #include "Adaptor.hpp" 00047 #include "AdaptorChain.hpp" 00048 #include "Frame.hpp" 00049 #include "ReferenceCounter.hpp" 00050 #include "VCondition.hpp" 00051 #include "VMutex.hpp" 00052 00053 #ifdef WIN32 00054 #ifndef WINCE 00055 #include <sys/timeb.h> 00056 #endif //wince 00057 #else 00058 #include <sys/time.h> 00059 #endif 00060 #include <time.h> 00061 00062 00083 class GlobalTimer:public Adaptor { 00084 public: 00085 00086 /* Constructor 00087 each ES needs the same GlobalTimer object 00088 */ 00089 GlobalTimer(); 00090 00091 virtual ~GlobalTimer(); 00092 00093 list < Frame * >adapt(Frame * frm); 00094 00095 Adaptor *clone() { return new GlobalTimer(); }; 00096 00097 void reset(); 00098 00099 void initialize(); 00100 00101 list < Frame * >close() { 00102 list < Frame * >tmp; 00103 return tmp; 00104 }; 00105 00110 double getActualSec(); 00111 00112 /* AudioIO calls this to bring A/V in sync */ 00113 void adjustToTS(int ts, int mediaTimeScale); 00114 00118 void adjust(double sec); 00119 00120 void setPaused(bool pause); 00121 00122 bool isPaused() const { return pauseRefCnt.getUsage() > 0; } 00123 00124 void setPrefetching(bool pause); 00125 00126 bool isPrefetching() { return prefetchRefCnt.getUsage() > 0; } 00127 00136 void dropFramesUntil(u32 cts); 00137 00140 void setESInfo(ESInfo * esi) {es=esi;}; 00141 00142 ESInfo * getESInfo() { return es;} 00143 00145 u32 getTranscodingCosts() const { 00146 return 10000u; 00147 } 00148 00149 private: 00150 ESInfo* es; 00151 VCondition cond_block; // condition: _not_ blocked (paused or prefetching) 00152 VMutex cond_block_mutex; // protects also wasBlocked 00153 ReferenceCounter pauseRefCnt; 00154 ReferenceCounter prefetchRefCnt; 00155 bool wasBlocked; 00156 u32 dropUntil; 00157 VMutex time_mutex; // protecting time values below 00158 struct timeval tv; 00159 double actualSec; 00160 double start_dtime; 00161 double now_dtime; 00162 bool firstFrame; 00163 }; 00164 00165 #endif 00166