Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members
DataDump.cpp
00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: DataDump.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 "DataDump.hpp" 00045 #include "Frame.hpp" 00046 #include "UncompressedVideoFrame.hpp" 00047 00048 00049 DataDump::DataDump(ESInfo* esi, IO *outStream, bool autoFix) { 00050 00051 es = esi; 00052 out = outStream; 00053 this->autoFix = autoFix; 00054 dummyFrame = NULL; 00055 numFrames = 0; 00056 lastAU.payload = NULL; 00057 strcpy(name,"DataDump"); 00058 } 00059 00060 00061 DataDump::~DataDump() { 00062 delete out; 00063 if (dummyFrame) { 00064 dummyFrame->unsetAU(); 00065 delete dummyFrame; 00066 } 00067 } 00068 00069 00070 void DataDump::initialize() { 00071 } 00072 00073 void DataDump::setESInfo(ESInfo * esi) { 00074 es = esi; 00075 } 00076 00077 ESInfo *DataDump::getESInfo() { 00078 return es; 00079 } 00080 00081 00082 /***************************************************************/ 00083 list < Frame * > DataDump::adapt(Frame * frm) { 00084 list < Frame * >tmp; 00085 u32 thisCTS; 00086 int thisSec; 00087 int done=0; 00088 00089 //call open on first frame 00090 if (numFrames == 0) 00091 if (!out->open()) { 00092 dprintf_err("DataDump: FATAL: not writing, since another IO class is accessing file %s\n",out->getURL()); 00093 //standard forwarding adaptor behaviour 00094 tmp.push_front(frm); 00095 return tmp; 00096 } 00097 00098 UncompressedVideoFrame *thisFrame = (UncompressedVideoFrame*)frm; 00099 thisCTS = frm->getAU()->cts; 00100 thisSec = (int)floor((double)thisCTS / es->getMediaTimeScale()); 00101 dprintf_full("DataDump::adapt frame %i CTS %i, VOP increment %i\n", numFrames, thisCTS,es->getVOPTimeIncrement()); 00102 00103 //FIXME: assert(isVideoFrame) 00104 00105 //first frame, malloc payload, size is always the same for YUV frames! 00106 if (!lastAU.payload) { 00107 dprintf_full("DataDump::adapt creating initial buffers\n"); 00108 lastPayload = (u8*)malloc(thisFrame->getAU()->size); 00109 lastAU.payload = lastPayload; 00110 lastAU.size = thisFrame->getAU()->size; 00111 dummyFrame = new UncompressedVideoFrame(Frame::NN_VOP, thisFrame->getWidth(), thisFrame->getHeight()); 00112 dummyFrame->setMediaTimeScale(thisFrame->getMediaTimeScale()); 00113 dummyFrame->setAU(&lastAU,false); //disable detectFrameType() for efficiency! 00114 } 00115 00116 while(!done) { 00117 if (numFrames * es->getVOPTimeIncrement() == thisCTS) { //NO FRAME LOSS 00118 out->writeFrame(thisFrame); 00119 done=1; 00120 } else if (autoFix) { //catch up BECAUSE OF FRAME LOSS 00121 dprintf_full("DataDump::adapt %i dummyADAPT!\n",numFrames); 00122 out->writeFrame(dummyFrame); 00123 } 00124 numFrames++; 00125 } 00126 00127 00128 // assert(lastAU.size == thisFrame->getAU()->size); 00129 dummyFrame->unsetAU(); 00130 lastAU = thisFrame->getAU(); 00131 lastAU.payload = lastPayload; 00132 lastAU.size = thisFrame->getAU()->size; 00133 memcpy(lastAU.payload, thisFrame->getAU()->payload, thisFrame->getAU()->size); 00134 dummyFrame->setAU(&lastAU,false); //disable detectFrameType() for efficiency! 00135 00136 //standard forwarding adaptor behaviour 00137 tmp.push_front(frm); 00138 return tmp; 00139 }