ContainerInfo.hpp

00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: ContainerInfo.hpp * 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 #ifndef PS_CONTAINERINFO_HPP 00045 #define PS_CONTAINERINFO_HPP 00046 00047 #ifdef ISOMP4 00048 #include "ISOMovies.h" 00049 #endif 00050 #ifndef WINCE 00051 #include <fcntl.h> 00052 #endif 00053 #include "global.hpp" 00054 00055 #include "Adaptor.hpp" 00056 #include "IO.hpp" 00057 #include "net/Url.hpp" 00058 struct rtx_group; 00059 struct rtx_info; 00060 class MetaObject; 00061 class ESInfo; 00062 class TerminalCapabilities; 00063 class ReferenceCounter; 00064 class VideoESInfo; 00065 class AudioESInfo; 00066 00067 #define MP4CONF_VERSION 7 00068 00069 struct MetaItem { 00073 MetaItem(u32 es, float q, u32 s, Adaptor * a) { 00074 quality = q; 00075 esId = es; 00076 size = s; 00077 adapt = a; 00078 }; 00079 ~MetaItem() { 00080 if (adapt) 00081 delete adapt; 00082 } 00083 Adaptor *getClonedAdaptor() { 00084 if (adapt) 00085 return adapt->clone(); 00086 else 00087 return NULL; 00088 }; 00089 MetaItem *clone() { 00090 return new MetaItem(esId, quality, size, getClonedAdaptor()); 00091 }; 00092 00093 float quality; 00094 u32 size; 00095 Adaptor *adapt; 00096 u32 esId; 00097 }; 00098 00099 struct QualityInfo { 00102 QualityInfo(u32 size, u8 maxSteps = 5) { 00103 lastRequestTime = 0; 00104 currentQAStep = 0; 00105 maxQASteps = 1; 00106 stepLimit = maxSteps; 00107 steps = new MetaItem *[stepLimit]; 00108 // init array to NULL 00109 memset((char*)steps,0,sizeof(MetaItem*)*stepLimit); 00110 // the first entry is the original video, no need for a real Adaptor 00111 steps[currentQAStep] = new MetaItem(0, 1.0, size, NULL); 00112 }; 00114 QualityInfo(QualityInfo & qi) { 00115 lastRequestTime = 0; 00116 currentQAStep = qi.currentQAStep; 00117 maxQASteps = qi.maxQASteps; 00118 stepLimit = qi.stepLimit; 00119 steps = new MetaItem *[stepLimit]; 00120 for (int i = 0; i < maxQASteps; i++) 00121 steps[i] = qi.steps[i]->clone(); 00122 }; 00123 ~QualityInfo() { 00124 for (int i = 0; i < maxQASteps; i++) { 00125 if(steps[i]) 00126 delete steps[i]; 00127 } 00128 delete[] steps; 00129 }; 00131 bool addMetaItem(MetaItem * m) { 00132 if (maxQASteps >= stepLimit) 00133 return false; 00134 steps[maxQASteps] = m; 00135 maxQASteps++; 00136 return true; 00137 } 00138 u32 lastRequestTime; 00139 MetaItem **steps; 00140 u8 currentQAStep; 00141 u8 maxQASteps; 00142 u8 stepLimit; 00143 u32 esInfoId; 00144 }; 00145 00146 00158 class ContainerInfo { 00159 public: 00160 00161 typedef enum { UNKNOWN_CONTAINER, AVI, MP4, MATROSKA, VITOOKI, DVD, SDP, OGG} ContainerType; 00162 00163 00169 ContainerInfo(const char *url, const char* locFile, const ContainerType type); 00173 ContainerInfo(); 00174 00177 ContainerInfo(QualityInfo & q); 00178 00179 virtual ~ ContainerInfo(); 00180 00184 list < ESInfo * >* getESList() { 00185 return &esList; 00186 }; 00187 00192 ESInfo *getES(u32 streamId) const; 00193 00195 VideoESInfo *getFirstVisualES(); 00196 00198 u32 getNumberOfVisualStreams() const; 00199 00201 u32 getNumberOfAudioStreams() const; 00202 00204 AudioESInfo *getFirstAudioES(); 00205 00206 /* @returns the type from the enumeration like MP4, DVD or SDP */ 00207 ContainerType getContainerType() { return type; }; 00208 00209 /* sets the container type 00210 * @param ctype: enumeration like MP4, DVD or SDP */ 00211 void setContainerType(ContainerType ctype) { type=ctype; }; 00212 00214 IO *getMuxDemuxIO() { return muxDemuxIO; }; 00215 00217 void setMuxDemuxIO(IO *demuxio) { muxDemuxIO = demuxio; }; 00218 00223 bool saveToCfgFile(char *indexName); 00224 00231 bool loadFromCfgFile(char *indexName); 00232 00234 const Url *getUrl() const; 00235 00236 /* shallow copies url */ 00237 void setUrl(Url *uri); 00238 00239 /* deep copies loclFile */ 00240 void setLocalFile(const char* loclFile); 00241 00242 const char* getLocalFile() const { 00243 return localFile; 00244 } 00245 00249 void setIODHandle(u8 * iodHandle, u32 iodHandleSize); 00250 00252 const u8 *getIODHandle(u32 & size) const { 00253 size = iodHandleSize; 00254 return iodHandle; 00255 }; 00256 00260 void addESInfo(ESInfo * esobj) { 00261 esList.push_back(esobj); 00262 }; 00263 00264 inline u32 getActSize() const { 00265 return qinfo.steps[qinfo.currentQAStep]->size; 00266 }; 00267 00268 inline float getActQuality() const { 00269 return qinfo.steps[qinfo.currentQAStep]->quality; 00270 }; 00271 00272 u32 getLastRequestTime() const { 00273 return lastAccessTime; 00274 }; 00275 00276 void setLastRequestTime(u32 last) { 00277 lastAccessTime = last; 00278 }; 00279 00282 u32 getFileSize() const; 00283 00286 u32 getEstimatedNetworkFileSize(); 00287 00288 void setMetaObject(MetaObject* meta); 00289 00290 MetaObject* getMetaObject(); 00291 00293 bool hasAudio()const; 00294 00295 QualityInfo *getQualityInfo() { 00296 return &qinfo; 00297 }; 00299 ContainerInfo * clone(); 00300 00301 ReferenceCounter* getUsageCounter(); 00302 00304 bool destroy(); 00305 00306 rtx_group* getRtxGroup(u32 esId,list<rtx_group*>* rtxInfo) const; 00307 00308 00309 private: 00310 void clear(); 00311 ESInfo *parseES(char *line); 00312 00313 00314 protected: 00316 ContainerType type; 00317 00318 list < ESInfo * >esList; 00319 00321 IO *muxDemuxIO; 00322 00324 Url *url; 00325 00327 char *localFile; 00328 00330 MetaObject* metaObj; 00331 00333 u8 *iodHandle; 00334 00336 u32 iodHandleSize; 00337 00339 u32 timeScale; 00340 00342 u32 lastAccessTime; 00343 00345 ReferenceCounter* usageCounter; 00346 00348 QualityInfo qinfo; 00349 00350 /* Name of the video */ 00351 char *Name; 00352 00353 /* Description of the Video's content */ 00354 char *Description; 00355 00356 /* Video's MimeType */ 00357 char *MimeType; 00358 }; 00359 00360 #endif