StrongTemporalAdaptor.hpp

00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: StrongTemporalAdaptor.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 _PS_STRONGTEMPORALADAPTOR_HPP 00045 #define _PS_STRONGTEMPORALADAPTOR_HPP 00046 00047 #include "VideoAdaptor.hpp" 00048 #include "global.hpp" 00049 #include "Frame.hpp" 00050 #include "ESInfo.hpp" 00051 #include "BitField.hpp" 00052 00064 class StrongTemporalAdaptor : public VideoAdaptor { 00065 public: 00066 StrongTemporalAdaptor(VideoESInfo * esi) { 00067 es = esi; 00068 inFrames = 0; 00069 outFrames = 0; 00070 lastDTS = 0; 00071 initialized = false; 00072 strcpy(name,"StrongTemporalAdaptor"); 00073 }; 00074 StrongTemporalAdaptor() { 00075 es = NULL; 00076 inFrames = 0; 00077 outFrames = 0; 00078 lastDTS = 0; 00079 initialized = false; 00080 strcpy(name,"StrongTemporalAdaptor"); 00081 }; 00082 00083 virtual ~ StrongTemporalAdaptor() { 00084 }; 00085 00086 Adaptor * clone() { 00087 return new StrongTemporalAdaptor(es); 00088 }; 00089 00090 list < Frame * >adapt(Frame * frm) { 00091 if(!initialized) 00092 initialize(); 00093 // a temporaladaptor is not allowed to delete the input frame 00094 // because other DataSinks might need it as input 00095 inFrames++; 00096 list < Frame * >tmp; 00097 if (!doAdapt(frm)) { 00098 tmp.push_front(frm); 00099 outFrames++; 00100 } 00101 00102 return tmp; 00103 }; 00104 00105 void initialize() { 00106 if(initialized) 00107 return; 00108 initialized = true; 00109 if(es) { 00110 u32 oldBW=es->getAvgBandwidth(); 00111 float bFrame=es->getAvgBFrameSize(); 00112 u32 newBW=(u32)(oldBW*bFrame); 00113 dprintf_full("TemporalAdaptor::initialize BW %u -%f-> %u\n",oldBW,bFrame,newBW); 00114 es->setAvgBFrameSize(0.0); 00115 es->setNum_B_frames(0); 00116 es->setAvgBandwidth(newBW); 00117 } 00118 }; 00119 list < Frame * >close() { 00120 00121 list < Frame * >tmp; 00122 00123 // set the fps 00124 if (es) { 00125 origVopTimeIncr=es->getVOPTimeIncrement(); 00126 u32 vInc=es->getDuration()/this->outFrames; 00127 u32 t=vInc%origVopTimeIncr; 00128 vInc-=t; 00129 es->setVOPTimeIncrement(vInc); 00130 u64 fs=es->getCurrentDemuxedMediaSize(); 00131 fs*=8000; 00132 fs/=es->getDurationInMs(); 00133 es->setAvgBandwidth((u32)fs); 00134 } 00135 // correct the bitfield, which now shows a too small complete status 00136 if(es && es->getFrameStatistic()) { 00137 BitField* b=new BitField(es->getFrameStatistic()->getSize(),true); 00138 es->setFrameStatistic(b); 00139 } 00140 return tmp; 00141 }; 00143 u32 getTranscodingCosts() const { 00144 return 1000u; 00145 } 00146 protected: 00148 inline bool doAdapt(Frame * &frm) { 00149 u32 i = frm->getType(); 00150 return i == Frame::B_VOP || i == Frame::P_VOP; 00151 }; 00152 u32 inFrames; 00153 u32 outFrames; 00154 u32 lastDTS; 00155 u32 origVopTimeIncr; 00156 }; 00157 00158 00159 #endif