Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members
ContainerFile.cpp
00001 00002 /*********************************************************************** 00003 * * 00004 * ViTooKi * 00005 * * 00006 * title: ContainerFile.cpp * 00007 * * 00008 * * 00009 * * 00010 * ITEC institute of the University of Klagenfurt (Austria) * 00011 * http://www.itec.uni-klu.ac.at * 00012 * * 00013 * * 00014 * For more information visit the ViTooKi homepage: * 00015 * http://ViTooKi.sourceforge.net * 00016 * vitooki-user@lists.sourceforge.net * 00017 * vitooki-devel@lists.sourceforge.net * 00018 * * 00019 * This file is part of ViTooKi, a free video toolkit. * 00020 * ViTooKi is free software; you can redistribute it and/or * 00021 * modify it under the terms of the GNU General Public License * 00022 * as published by the Free Software Foundation; either version 2 * 00023 * of the License, or (at your option) any later version. * 00024 * * 00025 * This program is distributed in the hope that it will be useful, * 00026 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00027 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00028 * GNU General Public License for more details. * 00029 * * 00030 * You should have received a copy of the GNU General Public License * 00031 * along with this program; if not, write to the Free Software * 00032 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * 00033 * MA 02111-1307, USA. * 00034 * * 00035 ***********************************************************************/ 00036 00037 /*********************************************************************** 00038 * * 00039 * REVISION HISTORY: * 00040 * * 00041 * * 00042 * * 00043 ***********************************************************************/ 00044 00045 #include "net/Url.hpp" 00046 00047 #ifdef ENABLE_DVDREAD 00048 #include "DVDContainerFile.hpp" 00049 #endif 00050 00051 #include "ContainerFile.hpp" 00052 #include "ISOMP4ContainerFile.hpp" 00053 #include "ffMP4ContainerFile.hpp" 00054 #include "MKContainerFile.hpp" 00055 #include "VITContainerFile.hpp" 00056 #include "OGGContainerFile.hpp" 00057 #include "io/HttpByteStream.hpp" 00058 00059 00063 ContainerInfo *ContainerFile::loadContainerInfo(const char *fileName, Url* uri, const ParseType type) { 00064 ContainerInfo * info = NULL; 00065 HttpByteStream *stream = NULL; 00066 HttpMimeType mimeType = mime_unknown; 00067 00068 dprintf_full("ContainerFile::loadContainerInfo: ####HANDLE####\n"); 00069 #ifdef ENABLE_DVDREAD 00070 dvd_handle_t *dvd_handle = DVDContainerFile::openDVD(fileName); 00071 00072 if(dvd_handle) { 00073 // treat as DVD 00074 u32 main_title_no = DVDContainerFile::getMainTitleNo(dvd_handle); 00075 /* load the containerinfo for the main video title set */ 00076 info = DVDContainerFile::loadContainerInfo(dvd_handle,main_title_no); 00077 delete dvd_handle; 00078 } 00079 #endif 00080 00081 00082 if(info==NULL) { 00083 // was not detected by DVD? 00084 00085 if (!uri) 00086 uri = new Url(fileName); 00087 00088 if (strstr(uri->getProtocol(), "http")) { 00089 stream = new HttpByteStream(uri->toString(), true /* forReading */); 00090 if (!stream->open()) { 00091 dprintf_err("ContainerFile::loadContainerInfo: file not found: %s!\n",fileName); 00092 return NULL; 00093 } 00094 mimeType = stream->getMimeTypeEnum(); 00095 } 00096 00097 00098 const char* suffix=strrchr(fileName,'.'); 00099 if(suffix || (mimeType != mime_unknown)) { 00100 00101 // handle VITOOKI file format 00102 if((mimeType == mime_vit) || strstr(fileName,".vit") || strstr(fileName,".VIT")) { 00103 dprintf_full("ContainerFile::loadContainerInfo(): VITOOKI container detected!\n"); 00104 info = VITContainerFile::loadContainerInfo(uri,stream); 00105 }// if .vit 00106 00107 #ifdef ENABLE_OGG 00108 // handle OGG file format 00109 else if((mimeType == mime_ogg) || strstr(fileName,".ogg") || strstr(fileName,".OGG")) { 00110 dprintf_full("ContainerFile::loadContainerInfo(): OGG container detected!\n"); 00111 info = OGGContainerFile::loadContainerInfo(uri,stream); 00112 }// if .ogg 00113 #endif 00114 00115 #ifdef ENABLE_MKV 00116 // handle MATROSKA file format 00117 else if((mimeType == mime_mkv) || strstr(fileName,".mkv") || strstr(fileName,".MKV")) { 00118 if (stream) 00119 stream->close(); //direct stream passing not yet supported.... 00120 dprintf_full("ContainerFile::loadContainerInfo(): MATROSKA detected!\n"); 00121 info = MKContainerFile::loadContainerInfo(fileName,uri); 00122 }// if .mkv 00123 #endif 00124 00125 else if(strstr(fileName,".mp4") || strstr(fileName,".MP4") || mimeType == mime_mp4) { 00126 if (stream) 00127 stream->close(); //direct stream passing not yet supported.... 00128 00129 // we can now choose between ISOMP4 or ffmpeg 00130 // assume that if ISOMP4 is defined this is the preferred one 00131 dprintf_full("ContainerFile::loadContainerInfo(): MP4 detected!\n"); 00132 #ifdef ISOMP4 00133 info = ISOMP4ContainerFile::loadContainerInfo(fileName,uri); 00134 #endif 00135 #ifdef ENABLE_FFMPEG 00136 // if this fails try ffmpeg 00137 if(info==NULL) 00138 info = ffMP4ContainerFile::loadContainerInfo(fileName,uri,(ffMP4ContainerFile::ParseType)type); 00139 #endif 00140 }//if .mp4 00141 else { 00142 if (stream) 00143 stream->close(); //direct stream passing not yet supported.... 00144 00145 #ifdef ENABLE_FFMPEG 00146 dprintf_full("ContainerFile::loadContainerInfo(): UNDEFINED detected!\n"); 00147 // NOT KNOWN, still give it a try with ffmpeg.... 00148 info = ffMP4ContainerFile::loadContainerInfo(fileName,uri,(ffMP4ContainerFile::ParseType)type); 00149 #endif 00150 }// NOT KNOWN extension 00151 } //has suffix 00152 else { 00153 // no suffix and no mimetype????? try ffmpeg and hope 00154 if (stream) 00155 stream->close(); //direct stream passing not yet supported.... 00156 #ifdef ENABLE_FFMPEG 00157 info = ffMP4ContainerFile::loadContainerInfo(fileName,uri,(ffMP4ContainerFile::ParseType)type); 00158 #endif 00159 } 00160 } 00161 00162 return info; 00163 } 00164 00165 00167 bool ContainerFile::saveToContainerFile(const char *fileName, ContainerInfo *ci) { 00168 dprintf_err("ContainerFile::saveToContainerFile: FIXME not implemented\n"); 00169 return false; 00170 }