Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members
TemporalAdaptor.cpp
00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: TemporalAdaptor.cpp * 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 #include "TemporalAdaptor.hpp" 00045 #include "Frame.hpp" 00046 #include "IO.hpp" 00047 #include "BitField.hpp" 00051 TemporalAdaptor::TemporalAdaptor(VideoESInfo * esi) { 00052 es = esi; 00053 inFrames = 0; 00054 outFrames = 0; 00055 lastDTS = 0; 00056 initialized = false; 00057 strcpy(name,"TemporalAdaptor"); 00058 }; 00059 TemporalAdaptor::TemporalAdaptor() { 00060 es = NULL; 00061 inFrames = 0; 00062 outFrames = 0; 00063 lastDTS = 0; 00064 initialized = true; 00065 strcpy(name,"TemporalAdaptor"); 00066 }; 00067 00068 void TemporalAdaptor::initialize() 00069 { 00070 if(initialized) 00071 return; 00072 initialized = true; 00073 if(es) { 00074 u32 oldBW=es->getAvgBandwidth(); 00075 float bFrame=es->getAvgBFrameSize(); 00076 u32 newBW=(u32)(oldBW*bFrame); 00077 dprintf_full("TemporalAdaptor::initialize BW %u -%f-> %u\n",oldBW,bFrame,newBW); 00078 es->setAvgBFrameSize(0.0); 00079 es->setNum_B_frames(0); 00080 es->setAvgBandwidth(newBW); 00081 } 00082 } 00087 list < Frame * >TemporalAdaptor::adapt(Frame * frm) 00088 { 00089 // a temporaladaptor is not allowed to delete the input frame 00090 // because other DataSinks might need it as input 00091 if(!initialized) 00092 initialize(); 00093 inFrames++; 00094 list < Frame * >tmp; 00095 if (!doAdapt(frm)) { 00096 tmp.push_front(frm); 00097 outFrames++; 00098 } 00099 00100 return tmp; 00101 }; 00102 00103 list < Frame * >TemporalAdaptor::close() 00104 { 00105 list < Frame * >tmp; 00106 00107 // set the fps 00108 // make sure it's a multiple of origVopTimeIncr 00109 if (es) { 00110 origVopTimeIncr=es->getVOPTimeIncrement(); 00111 u32 vInc=es->getDuration()/this->outFrames; 00112 u32 t=vInc%origVopTimeIncr; 00113 vInc-=t; 00114 es->setVOPTimeIncrement(vInc); 00115 u64 fs=es->getCurrentDemuxedMediaSize(); 00116 fs*=8000; 00117 fs/=es->getDurationInMs(); 00118 es->setAvgBandwidth((u32)fs); 00119 } 00120 // correct the bitfield, which now shows a too small complete status 00121 if(es && es->getFrameStatistic()) { 00122 BitField* b=new BitField(es->getFrameStatistic()->getSize(),true); 00123 es->setFrameStatistic(b); 00124 } 00125 return tmp; 00126 };