Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members
IOCreator.cpp
00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: IOCreator.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 #include "IOCreator.hpp" 00036 00037 #include "../ContainerInfo.hpp" 00038 #include "../BitField.hpp" 00039 #include "../ReferenceCounter.hpp" 00040 #include "../ESInfo.hpp" 00041 #include "../IO.hpp" 00042 00043 #include "ffMP4IO.hpp" 00044 #include "MPGStreamIO.hpp" 00045 #include "YUVStreamIO.hpp" 00046 #include "FilteredIO.hpp" 00047 #include "VITMuxDemuxIO.hpp" 00048 #include "BufferedIO.hpp" 00049 00050 #ifdef ENABLE_MKV 00051 #include "MKIO.hpp" 00052 #endif 00053 00054 #ifdef ENABLE_DVDREAD 00055 #include "DVDIO.hpp" 00056 #endif 00057 00058 IO *IOCreator::createInput(ESInfo* es, bool wrapInFilteredIO) { 00059 // different cases: 00060 // vo set & vo.url is set and this.input is set 00061 // url==input -> create an MP4IO 00062 // not equal and this.input exists -> create MPGStreamIO 00063 00064 char* tmp=NULL; 00065 const char* input; 00066 ContainerInfo* vo=es->getContainerInfo(); 00067 00068 //extract only file part of URL or PATH 00069 input=strrchr(es->getInput(),'/'); 00070 00071 if (!input || strlen(input)==0) { 00072 dprintf_full("IOCreator::createInput(): bad input %s, falling back to localFile\n",input); 00073 input = vo->getLocalFile(); 00074 } 00075 00076 if(input) { 00077 00078 tmp=strrchr(input,'.'); 00079 dprintf_full("IOCreator::createInput(): input %s localFile %s checking on %s codec id %i\n", es->getInput(), vo->getLocalFile(),input, es->getCodecID() ); 00080 00081 //check for extensions first 00082 if (tmp && (strstr(tmp,".yuv") || strstr(tmp,".YUV")) ) { 00083 dprintf_full("IOCreator::createInput(): YUVStreamIO created\r\n"); 00084 YUVStreamIO* yio=new YUVStreamIO((VideoESInfo*)es,vo->getLocalFile(),false); 00085 es->setInput(vo->getLocalFile()); 00086 return yio; 00087 } 00088 00089 #ifdef ENABLE_MKV 00090 if (tmp && (strstr(tmp,".mkv") || strstr(tmp,".MKV")) ) { 00091 dprintf_full("IOCreator::createInput(): MKIO created\r\n"); 00092 MKIO* mkio=new MKIO((VideoESInfo*)es,vo->getLocalFile(),false); 00093 es->setInput(vo->getLocalFile()); 00094 return mkio; 00095 } 00096 #endif 00097 00098 if (tmp && (strstr(tmp,".vit") || strstr(tmp,".VIT")) ) { 00099 dprintf_full("IOCreator::createInput(): VIT BufferedIO created\r\n"); 00100 BufferedIO* bufio=new BufferedIO((VideoESInfo*)es, (MuxDemuxIO*)vo->getMuxDemuxIO(), false); 00101 es->setInput(vo->getLocalFile()); 00102 return bufio; 00103 } 00104 00105 if (tmp && (strstr(tmp,".ogg") || strstr(tmp,".OGG")) ) { 00106 dprintf_full("IOCreator::createInput(): OGG BufferedIO created\r\n"); 00107 BufferedIO* bufio=new BufferedIO((VideoESInfo*)es, (MuxDemuxIO*)vo->getMuxDemuxIO(), false); 00108 es->setInput(vo->getLocalFile()); 00109 return bufio; 00110 } 00111 00112 #ifdef ENABLE_DVDREAD 00113 if(tmp && (strstr(tmp,"vob") || strstr(tmp,"VOB") || strstr(tmp,"iso") || strstr(tmp,"ISO"))) { 00114 DVDIO* dio=new DVDIO(es,input); 00115 if (wrapInFilteredIO) { 00116 BitField* b=new BitField(es->getNumberOfMediaSamples(),true); 00117 FilteredIO* fio=new FilteredIO(dio,b); 00118 return fio; 00119 } else 00120 return dio; 00121 } 00122 #endif 00123 00124 00125 /* no fitting extension, so ffmpeg shall try it's best... 00126 * else verify for supported container formats */ 00127 if ( (es->getCodecID() == CODEC_ID_MP3) || (es->getCodecID() == CODEC_ID_AAC) || // pass audio to MP4IO 00128 (!tmp || IOCreator::verifyContainerExtension(tmp)) ) { 00129 #ifdef ENABLE_FFMPEG 00130 ffMP4IO *mio = new ffMP4IO(es,vo->getLocalFile(),false); 00131 dprintf_full("IOCreator::createInput(): no extension detected, fallback: ffMP4IO created\r\n"); 00132 if (wrapInFilteredIO) { 00133 BitField* b=new BitField(es->getNumberOfMediaSamples(),true); 00134 FilteredIO* fio=new FilteredIO( mio ,b); 00135 return fio; 00136 } else 00137 return mio; 00138 #else 00139 dprintf_full("IOCreator::createInput(): ffMP4IO disabled in this build!\r\n"); 00140 exit(1); 00141 #endif 00142 } 00143 00144 if ( (es->getCodecID() == CODEC_ID_MPEG4AAC) || 00145 //the above is specially mp4-packaged AAC/mp3 (as stored in ./demux) 00146 (es->getCodecID() == CODEC_ID_MPEG4) || 00147 (tmp && strstr(tmp,".m4v") || strstr(tmp,".M4V")) // raw mpeg4 00148 ) { // in demux directory 00149 dprintf_full("IOCreator::createInput(): raw MPGStreamIO created\r\n"); 00150 MPGStreamIO *sio = new MPGStreamIO(es, input, false); 00151 if (wrapInFilteredIO) { 00152 BitField* b=new BitField(es->getNumberOfMediaSamples(),true); 00153 FilteredIO* fio = new FilteredIO(sio, b); 00154 return fio; 00155 } else 00156 return sio; 00157 } 00158 00159 // all other combinations are illegal 00160 dprintf_err("IOCreator::createInput(): Unknown filetype (input %s localFile %s)\r\n", input, vo->getLocalFile()); 00161 return NULL; 00162 00163 } 00164 00165 dprintf_err("IOCreator::createInput(): fatal file detection (input %s localFile %s) \r\n", input, vo->getLocalFile()); 00166 return NULL; 00167 } 00168 00169 00170 bool IOCreator::verifyContainerExtension(const char *file) { 00171 assert(file); 00172 if (strstr(file,".mp4") || strstr(file,".MP4") 00173 || strstr(file,".mpg") || strstr(file,".MPG") 00174 || strstr(file,".mpeg") || strstr(file,".MPEG") 00175 || strstr(file,".vit") || strstr(file,".VIT") //ViTooKis own container format 00176 || strstr(file,".mkv") || strstr(file,".MKV") 00177 || strstr(file,".mp3") || strstr(file,".MP3") // also handle mp3 audio within MP4IO 00178 || strstr(file,".avi") || strstr(file,".AVI") ) 00179 return true; 00180 else 00181 return false; 00182 }