ESSynchronizer.hpp

00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: ESSynchronizer.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 _ESSYNCHRONIZER_HPP 00045 #define _ESSYNCHRONIZER_HPP 00046 #include "Adaptor.hpp" 00047 #include "AdaptorChain.hpp" 00048 #include "GlobalTimer.hpp" 00049 #include "Frame.hpp" 00050 #include "ESInfo.hpp" 00051 00052 #ifdef WIN32 00053 #ifndef WINCE 00054 #include <sys/timeb.h> 00055 #endif 00056 #else 00057 #include <sys/time.h> 00058 #endif 00059 00060 #include "VCondition.hpp" 00061 #include <time.h> 00062 #include "VMutex.hpp" 00063 00064 /* how many msecs for "behind frames" are tolerated? */ 00065 #if (defined (BUILD_ARCH_ARM) || defined (WINCE)) 00066 #define ESSYNC_GRACE_MSECS 500 00067 #else 00068 #define ESSYNC_GRACE_MSECS 100 00069 #endif 00070 00071 /* threshold for stream discontinuity detection 00072 * (in milliseconds of media time) 00073 */ 00074 #define ESSYNC_DISCONT_MSECS 1001 //more than one second... 00075 00088 class ESSynchronizer:public Adaptor { 00089 public: 00090 00091 /* Constructor 00092 each ES needs one Synchronizer object 00093 interval = time interval before average of FPS and aBW is built 00094 (presented in ms) 00095 */ 00096 ESSynchronizer(ESInfo* esi, GlobalTimer * globalTimer); 00097 00098 virtual ~ESSynchronizer(); 00099 00110 list < Frame * >adapt(Frame * frm); 00111 00112 Adaptor *clone() { return new ESSynchronizer(es,globalTimer); }; 00113 00114 void initialize(); 00115 00116 list < Frame * >close() { 00117 list < Frame * >tmp; 00118 return tmp; 00119 }; 00120 00131 void setPaused(bool pause); 00132 00137 void setESInfo(ESInfo * esi) {es=esi;}; 00138 ESInfo * getESInfo() { return es;} 00139 00141 GlobalTimer *getGlobalTimer() const { return globalTimer; } 00142 00149 bool setOutputRateFactor(double factor); 00150 00154 double getOutputRateFactor() const { return outputRate; } 00155 00164 bool adjust(double sec); 00165 00167 virtual u32 getTranscodingCosts() const { 00168 // costs for essync do exist but how high are they per second? 00169 // assume 5000 00170 return 5000u; 00171 } 00172 00173 private: 00174 GlobalTimer * globalTimer; 00175 VCondition cond_pause; // condition is true <=> data channel is *not* paused 00176 VMutex cond_pause_mutex; 00177 bool paused; 00178 00179 int dropCount; 00180 00181 protected: 00182 ESInfo* es; 00183 struct timeval tv; 00184 long frmCount; 00185 00187 double outputRate; 00188 }; 00189 #endif 00190