Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members
VITContainerFile.cpp
00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: VITContainerFile.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 00045 #include "VITContainerFile.hpp" 00046 #include "ContainerInfo.hpp" 00047 #include "VideoESInfo.hpp" 00048 #include "AudioESInfo.hpp" 00049 #include "DataChannel.hpp" 00050 #include "io/BufferedFileByteStream.hpp" 00051 #include "io/UnbufferedFileByteStream.hpp" 00052 #include "io/HttpByteStream.hpp" 00053 #include "io/VITMuxDemuxIO.hpp" 00054 00055 00056 ContainerInfo *VITContainerFile::loadContainerInfo(const Url* uri, ByteStream *stream) { 00057 ContainerInfo *ci = NULL; 00058 00059 const char* pUri=NULL; 00060 if(uri) 00061 pUri=uri->toString(); 00062 else 00063 return NULL; 00064 00065 dprintf_full("VITContainerFile: :loadContainerInfo: Init... URI %s\n",pUri); 00066 00067 if (stream == NULL) { //reopen the byteStream 00068 if (strstr(uri->getProtocol(), "file")) 00069 stream = new UnbufferedFileByteStream(uri->getPath(), true /* forReading */); 00070 else if (strstr(uri->getProtocol(), "http")) 00071 stream = new HttpByteStream(uri->toString(), true /* forReading */); 00072 } 00073 00074 if (!stream->open()) { 00075 dprintf_err("VITContainerFile::loadContainerInfo: file not found: %s!\n",pUri); 00076 return NULL; 00077 } 00078 00079 ci = new ContainerInfo(pUri, uri->getPath(), ContainerInfo::VITOOKI); 00080 assert(ci); 00081 ci->setMuxDemuxIO(new VITMuxDemuxIO(stream)); 00082 00083 //FOURCC 00084 char fourcc[5]; 00085 stream->read( fourcc,4); //only read first 4 bytes, add \0 00086 fourcc[4] = '\0'; 00087 if (strcmp(fourcc,"VIT ") != 0) { 00088 dprintf_err("VITContainerFile::loadContainerInfo: file %s is no ViTooKi VIT container file! (got #%s#)\n",uri->toString(),fourcc); 00089 delete ci; 00090 return NULL; 00091 } 00092 00093 //version number 00094 u32 version; 00095 stream->read( &version, sizeof(version)); 00096 if (version != VIT_VERSION_NUMBER) { 00097 dprintf_err("VITContainerFile::loadContainerInfo: VIT file %s has wrong version number %i (expected %i)!\n", 00098 pUri,version,VIT_VERSION_NUMBER); 00099 delete ci; 00100 return NULL; 00101 } 00102 00103 //number of following (muxed) tracks 00104 u32 numTracks; 00105 stream->read( &numTracks, sizeof(numTracks)); 00106 dprintf_full("VITContainerFile::loadContainerInfo: VIT file contains %i elementary streams\n",numTracks); 00107 00108 00109 //get list of tracks 00110 for (u32 curr=0; curr < numTracks; curr++) { 00111 00112 VITTrackInfo ti; 00113 stream->read(&ti, sizeof(ti)); 00114 dprintf_full("VITContainerFile::loadContainerInfo: Header with TrackID %i CodecID %i StreamType %i\n", 00115 ti.streamID, ti.codecID, ti.streamType); 00116 00117 ESInfo *esi; 00118 00119 if (ti.streamType == VIT_VIDEO) { 00120 esi = new VideoESInfo(ti.streamID, ti.streamType, ci, ti.vopinc /*time increment*/, 00121 NULL /*encodedDecoderConfig*/, 0, 0, 00122 ti.kbps * 1024, ti.kbps * 1024, 90000, 0 /*duration*/, 00123 0 /*mediaSize*/, ti.esi.vi.width, ti.esi.vi.height, 00124 true, true, (CodecID)ti.codecID, 1.0 /*quality*/, ti.esi.vi.aspectRatio); 00125 } else 00126 if (ti.streamType == VIT_AUDIO) { 00127 esi = new AudioESInfo(ti.streamID, ti.streamType, ci, ti.vopinc /*time increment*/, 00128 NULL /*encodedDecoderConfig*/, 0, 0, 00129 ti.kbps * 1024, ti.kbps * 1024, 90000, 0 /*duration*/, 00130 0 /*mediaSize*/, ti.esi.ai.sampleRate, ti.esi.ai.channels, true, 00131 (CodecID)ti.codecID, 1.0 /*quality*/, 16 /* bits_per_sample */); 00132 char lang[3]; 00133 strncpy(lang,ti.esi.ai.language,2); 00134 lang[3]='\0'; 00135 ((AudioESInfo*)esi)->setLanguage(lang); 00136 00137 } else { 00138 dprintf_err("VITContainerFile: TrackID %i CodecID %i has UNKNOWN StreamType %i\n", 00139 ti.streamID, ti.codecID, ti.streamType); 00140 delete ci; 00141 return NULL; 00142 } 00143 00144 esi->setInput(uri->toString()); 00145 assert(ci); 00146 ci->addESInfo(esi); 00147 } 00148 00149 //NOTE: dont close the stream since it is needed in VITMuxDemuxIO for reading the frames !!! 00150 //stream->close(); 00151 return ci; 00152 } 00153