FilteredIO.cpp

00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: FilteredIO.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 "FilteredIO.hpp" 00045 #include "BitField.hpp" 00046 #include "Frame.hpp" 00047 #include "ESInfo.hpp" 00048 00049 FilteredIO::FilteredIO(IO* _io, BitField* _filter) 00050 { 00051 assert(_io && _filter); 00052 io=_io; 00053 filter=_filter; 00054 assert(filter->isAllSet()); 00055 framesSeen=0; 00056 }; 00057 00058 00059 FilteredIO::~FilteredIO() 00060 { 00061 if(io) 00062 delete io; 00063 00064 if(filter) 00065 delete filter; 00066 }; 00067 00072 Frame * FilteredIO::getFrame() { 00073 Frame* frm = NULL; 00074 bool stop = false; 00075 u32 vopTimeIncrement = io->getESInfo()->getVOPTimeIncrement(); 00076 do { 00077 frm=io->getFrame(); 00078 if(frm) { 00079 if(filter->getBit(frm->getAU()->cts/vopTimeIncrement) || (frm->getAU()->cts==0)) 00080 stop=true; 00081 else { 00082 dprintf_full("FilteredIO::getFrame: throwing away CTS %i VopIncr %i\n",frm->getAU()->cts,vopTimeIncrement); 00083 delete frm; 00084 frm=NULL; 00085 } 00086 } 00087 } while(!stop && io->getState()!=IO::STREAMEOF && io->getState()!=IO::CLOSED && 00088 io->getState()!=IO::CLOSING && io->getState()!=IO::STREAMERR); 00089 framesSeen++; 00090 00091 #ifdef _POSIX_PRIORITY_SCHEDULING 00092 sched_yield(); 00093 #else 00094 // for windows pthread lib! 00095 #ifdef WIN32 00096 #ifndef WINCE 00097 sched_yield(); 00098 #else 00099 Sleep(0); 00100 #endif 00101 #endif 00102 #endif 00103 dprintf_full("FilteredIO::getFrame() CTS %u\n",frm?frm->getAU()->cts:0); 00104 return frm; 00105 }; 00106 00108 int FilteredIO::writeFrame(Frame * frm, ESInfo *out_es) 00109 { 00110 assert(frm); 00111 framesSeen++; 00112 if(filter->getBit(frm->getAU()->cts/io->getESInfo()->getVOPTimeIncrement())) { 00113 return io->writeFrame(frm); 00114 } 00115 00116 #ifdef _POSIX_PRIORITY_SCHEDULING 00117 sched_yield(); //this is necessary to give parallel getFrames a chance 00118 #endif 00119 00120 return 1; 00121 }; 00122 00126 bool FilteredIO::open() 00127 { 00128 framesSeen=0; 00129 return io->open(); 00130 }; 00131 00136 bool FilteredIO::close(bool immediate) 00137 { 00138 return io->close(immediate); 00139 }; 00140 00141 long FilteredIO::setToClosestIFrame(u32 frameNumber, bool backwards) 00142 { 00143 dprintf_full("FilteredIO::setToClosestIFrame\n"); 00144 return io->setToClosestIFrame(frameNumber, backwards); 00145 }; 00146 00150 bool FilteredIO::destroy() 00151 { 00152 return io->destroy(); 00153 }; 00154 00155 IO::State FilteredIO::getState() const 00156 { 00157 return io->getState(); 00158 }; 00159 00161 IO::State FilteredIO::setState(IO::State s) 00162 { 00163 return io->setState(s); 00164 }; 00165 00167 int FilteredIO::getBufferFillLevel() const 00168 { 00169 return io->getBufferFillLevel(); 00170 }; 00171 00177 int FilteredIO::flushBuffer(long from_ts, long to_ts) 00178 { 00179 return io->flushBuffer(from_ts,to_ts); 00180 }; 00181 00183 const char *FilteredIO::getURL() const 00184 { 00185 return io->getURL(); 00186 }; 00187 00188 bool FilteredIO::setToFrameNumber(u32 frameNumber) 00189 { 00190 dprintf_full("FilteredIO::setToFrameNumber\n"); 00191 return io->setToFrameNumber(frameNumber); 00192 }; 00193 00194 void FilteredIO::setResendFrameHeader(bool set) 00195 { 00196 io->setResendFrameHeader(set); 00197 }; 00198 00199 void FilteredIO::run() 00200 { 00201 if(!io->running()) 00202 io->start(); 00203 io->wait(); 00204 }; 00205 00206 void FilteredIO::setESInfo(ESInfo * es) 00207 { 00208 io->setESInfo(es); 00209 }; 00210 00211 void FilteredIO::setRtxInfo(const rtx_info* rtx) 00212 { 00213 io->setRtxInfo(rtx); 00214 }; 00215 00216 IO::State FilteredIO::play(double prefetchTime) 00217 { 00218 return io->play(prefetchTime); 00219 }; 00220 00221 IO::State FilteredIO::pause() 00222 { 00223 return io->pause(); 00224 }; 00225 IO::State FilteredIO::mute() 00226 { 00227 return io->mute(); 00228 }; 00229 00233 bool FilteredIO::setBitField(BitField* b) 00234 { 00235 bool ret=false; 00236 if(b && b->getSize()>0) { 00237 #ifdef DEBUG 00238 char* tmp=b->toHexString(); 00239 dprintf_full("FilteredIO::setBitField %s\n",tmp); 00240 delete tmp; 00241 #endif 00242 ret=(filter->getSize()==b->getSize()); 00243 if(filter) 00244 delete filter; 00245 filter=b; 00246 } 00247 return ret; 00248 } 00249 00250 ESInfo* FilteredIO::getESInfo() { 00251 return io->getESInfo(); 00252 } 00253