ContainerInfo.cpp

00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: ContainerInfo.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 "ContainerInfo.hpp" 00045 #include "VideoESInfo.hpp" 00046 #include "AudioESInfo.hpp" 00047 #include "BifsESInfo.hpp" 00048 #include "ObjectDescriptorESInfo.hpp" 00049 #include "global.hpp" 00050 #include "io/IOCreator.hpp" 00051 00052 #include <stdio.h> 00053 #ifndef WINCE 00054 #include <sys/types.h> 00055 #include <sys/stat.h> 00056 #include <iostream> 00057 #endif //wince 00058 #ifndef WIN32 00059 #include <netdb.h> 00060 #include <netinet/in.h> 00061 #include <arpa/inet.h> 00062 #endif 00063 #ifndef WINCE 00064 #include <sys/stat.h> 00065 #include <fcntl.h> 00066 #endif //wince 00067 #include <string.h> 00068 #include "BitField.hpp" 00069 #include "ReferenceCounter.hpp" 00070 00071 00072 //FIXME: CacheContainerInfo 00073 #include "cache/MetaObject.hpp" 00074 00075 ContainerInfo::ContainerInfo(const char *uri, const char *locFile, ContainerType ctype) : qinfo(0,5) { 00076 dprintf_small("ContainerInfo:: VOB local: %s URI: %s\n", locFile, uri); 00077 type = ctype; 00078 muxDemuxIO = NULL; 00079 00080 //assert(uri || locFile); 00081 if(uri) 00082 url = new Url(uri); 00083 else 00084 url=NULL; 00085 localFile=NULL; 00086 if(locFile) { 00087 setLocalFile(locFile); // correct / 00088 } 00089 00090 iodHandle = NULL; 00091 iodHandleSize = 0; 00092 metaObj=NULL; 00093 lastAccessTime = 0; 00094 usageCounter=new ReferenceCounter(); 00095 } 00096 00097 00101 ContainerInfo::ContainerInfo(): qinfo(0,5) 00102 { 00103 url = NULL; 00104 muxDemuxIO = NULL; 00105 metaObj=NULL; 00106 localFile = NULL; 00107 iodHandle = NULL; 00108 iodHandleSize = 0; 00109 lastAccessTime = 0; 00110 usageCounter=new ReferenceCounter(); 00111 esList.clear(); 00112 } 00113 00116 ContainerInfo::ContainerInfo(QualityInfo & q): qinfo(q) 00117 { 00118 url = NULL; 00119 muxDemuxIO = NULL; 00120 iodHandle = NULL; 00121 localFile = NULL; 00122 iodHandleSize = 0; 00123 lastAccessTime = 0; 00124 metaObj=NULL; 00125 usageCounter=new ReferenceCounter(); 00126 } 00127 00128 ContainerInfo::~ContainerInfo() 00129 { 00130 dprintf_full("ContainerInfo::~ContainerInfo() %s\n",(localFile?localFile:"NULL")); 00131 clear(); 00132 } 00133 00134 void 00135 ContainerInfo::clear() 00136 { 00137 if (iodHandle) 00138 delete[] iodHandle; 00139 00140 if (url) 00141 delete url; 00142 00143 if(localFile) 00144 delete[] localFile; 00145 00146 if (muxDemuxIO) 00147 delete muxDemuxIO; 00148 00149 iodHandle = NULL; 00150 url = NULL; 00151 localFile=NULL; 00152 iodHandleSize = 0; 00153 // also delete all es 00154 list < ESInfo * >::iterator li = esList.begin(); 00155 while (!esList.empty()) { 00156 li = esList.begin(); 00157 dprintf_full("ContainerInfo::clear() going to delete ESinfo id %llu\n",(*li)->getStreamId()); 00158 delete(*li); 00159 esList.pop_front(); 00160 } 00161 if(usageCounter &&!usageCounter->deactivateWhenUsage(0)) { 00162 dprintf_err("ContainerInfo::clear: destroying ContainerInfo which is still in use!\n"); 00163 } 00164 if(usageCounter) 00165 delete usageCounter; 00166 } 00167 00168 void ContainerInfo::setIODHandle(u8 * iod, u32 iodSize) 00169 { 00170 if (iod && iodSize > 0) { 00171 if (iodHandle) 00172 delete[] iodHandle; 00173 iodHandle = new u8[iodSize]; 00174 memcpy((char *) iodHandle, (char *) iod, iodSize); 00175 iodHandleSize = iodSize; 00176 } else { 00177 dprintf_err("Illegal parameters in ContainerInfo::setIODHandle\n"); 00178 } 00179 } 00180 00181 00182 00184 bool ContainerInfo::saveToCfgFile(char *indexName) 00185 { 00186 // check if the entry is valid 00187 if (!url || (iodHandleSize>0 && !iodHandle) ) 00188 return false; 00189 // either localfile or url must be set 00190 if(!localFile && !url) 00191 return false; 00192 FILE* file=fopen(indexName,"wb"); 00193 char *oneLine = new char[4096]; 00194 oneLine[0] = 0; 00195 u32 len = 0; 00196 if (file) { 00197 00198 // Format: version magic number 00199 // url <space> \r\n 00200 // localFile or NULL \r\n 00201 // iodHandleSize <space> iodHandle <space> <nrES> <space> \r\n 00202 // each ES entry has the following format (one single Line, entries within 00203 // line separated by <space>): 00204 // streamId handlerType encodedDecoderConfig objectType streamType 00205 // bufferSize [<fileName_of_input>||null] \r\n 00206 00207 if(url) { 00208 sprintf(oneLine, "%i \r\n%s \r\n%s \r\n%i ", MP4CONF_VERSION,(localFile?localFile:"NULL"), url->toString(), iodHandleSize); 00209 } 00210 else { //FIXME: this is dead code 00211 sprintf(oneLine, "%i \r\n%s \r\nNULL \r\n%i ", MP4CONF_VERSION,localFile, iodHandleSize); 00212 } 00213 len = strlen(oneLine); 00214 if (len != fwrite(oneLine,1, len, file)) { 00215 fclose(file); 00216 #ifndef WINCE 00217 ::remove(indexName); 00218 #else 00219 DeleteFile((LPCTSTR)indexName); 00220 #endif 00221 delete [] oneLine; 00222 return false; 00223 } 00224 // now write the IOD 00225 00226 if (iodHandle && iodHandleSize>0 && (iodHandleSize != 00227 fwrite(iodHandle, 1, iodHandleSize,file)) ) { 00228 fclose(file); 00229 #ifndef WINCE 00230 ::remove(indexName); 00231 #else 00232 DeleteFile((LPCTSTR)indexName); 00233 #endif 00234 delete [] oneLine; 00235 return false; 00236 } 00237 oneLine[0] = 0; 00238 sprintf(oneLine, " %i \r\n", esList.size()); 00239 len = strlen(oneLine); 00240 if (len != fwrite(oneLine, 1, len, file)) { 00241 fclose(file); 00242 #ifndef WINCE 00243 ::remove(indexName); 00244 #else 00245 DeleteFile((LPCTSTR)indexName); 00246 #endif 00247 delete [] oneLine; 00248 return false; 00249 } 00250 // now start to write the ES 00251 u32 tid = 0; 00252 u32 handlerType = 0; 00253 const u8 *decoderConfig = NULL; 00254 u32 decConfSize = 0; 00255 u32 objectType = 0; 00256 u32 streamType = 0; 00257 u32 bufferSize = 0; 00258 u32 width = 0; 00259 u32 height = 0; 00260 u32 avg = 0; 00261 u32 max = 0; 00262 u32 time = 0; 00263 u64 dur = 0; 00264 u32 size = 0; 00265 u32 ticks = 0; 00266 char *input = NULL; 00267 u32 hasColor= true; 00268 u32 isComplete = true; 00269 u32 codecId= 0; 00270 float quality= 0.0; 00271 float aspectRatio=0; 00272 u32 gop_size=0; 00273 u32 bFrames=0; 00274 u32 audioSampleRate=0; 00275 u32 numChannels=2; 00276 bool hasInput = true; 00277 char* stat=NULL; 00278 float bframesize=0.0; 00279 u32 staticFramePattern=0; 00280 00281 list < ESInfo * >::iterator li = esList.begin(); 00282 for (int i = 0; i < (int) esList.size(); i++) { 00283 tid = (*li)->getStreamId(); 00284 streamType = (*li)->getStreamType(); 00285 handlerType = (*li)->getHandlerType(); 00286 decoderConfig = (*li)->getEncodedDecoderConfig(); 00287 decConfSize = strlen((const char *) decoderConfig); 00288 objectType = (*li)->getObjectType(); 00289 00290 bufferSize = (*li)->getBufferSize(); 00291 if(handlerType==MP4VisualHandlerType) { 00292 width = ((VideoESInfo*)(*li))->getWidth(); 00293 height = ((VideoESInfo*)(*li))->getHeight(); 00294 hasColor= ( ((VideoESInfo*)(*li))->getHasColor() ? 1 : 0); 00295 aspectRatio= ((VideoESInfo*)(*li))->getAspectRatio(); 00296 gop_size=((VideoESInfo*)(*li))->getGOP_size(); 00297 bFrames=((VideoESInfo*)(*li))->getNum_B_frames(); 00298 bframesize=((VideoESInfo*)(*li))->getAvgBFrameSize(); 00299 staticFramePattern=(((VideoESInfo*)(*li))->hasStaticFramePattern()? 1 : 0); 00300 } 00301 else { 00302 width=0; 00303 height=0; 00304 hasColor=true; 00305 } 00306 if(handlerType==MP4AudioHandlerType) { 00307 audioSampleRate=((AudioESInfo*)(*li))->getSampleRate(); 00308 numChannels=((AudioESInfo*)(*li))->getAudioChannels(); 00309 } 00310 else { 00311 audioSampleRate=0; 00312 numChannels=0; 00313 } 00314 avg = (*li)->getAvgBandwidth(); 00315 max = (*li)->getMaxBandwidth(); 00316 time = (*li)->getMediaTimeScale(); 00317 dur = (*li)->getDuration(); 00318 size = (*li)->getOrigMediaSize(); 00319 ticks = (*li)->getVOPTimeIncrement(); 00320 input = (char*) (*li)->getInput(); 00321 00322 isComplete = ( (*li)->getCompleteState() ? 1 : 0); 00323 codecId= (u32) (*li)->getCodecID(); 00324 quality= (*li)->getStreamQuality(); 00325 hasInput = true; 00326 if (!input) { 00327 input = new char[5]; 00328 strcpy(input, "NULL"); 00329 hasInput = false; 00330 } 00331 00332 if((*li)->getFrameStatistic() && 00333 (*li)->getFrameStatistic()->getSize()>0) { 00334 stat=(*li)->getFrameStatistic()->toAsciiString(); 00335 } 00336 else { 00337 stat=new char[5]; 00338 strcpy(stat,"NULL"); 00339 } 00340 dprintf_small("Wrote:%u %u %u %s %u %u %u %s \r\n", tid, 00341 handlerType, decConfSize, decoderConfig, 00342 objectType, streamType, bufferSize, input); 00343 ++li; // increase list iterator 00344 // streamId handlerType decConfSize encodedDecoderConfig objectType 00345 // streamType bufferSize width height avg max time dur mediasize .... [<fileName_of_input>||null] \r\n 00346 oneLine[0] = 0; 00347 00348 // dur is 64 bit -> split in two 32 bit valus -> higher 32 bit first 00349 sprintf(oneLine," %u %u %u %s %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %6.6f %6.6f %u %u %f %u %u %u %s \r\n", 00350 tid, handlerType, decConfSize, decoderConfig, 00351 objectType, streamType, bufferSize, width, height, avg, 00352 max, time, (u32) (dur >> 32), (u32) dur, size, 00353 ticks, hasColor, isComplete, codecId, quality, aspectRatio, 00354 gop_size,bFrames,bframesize,staticFramePattern, 00355 audioSampleRate, numChannels,input); 00356 len = strlen(oneLine); 00357 00358 if (len != fwrite(oneLine, 1, len, file)) { 00359 fclose(file); 00360 #ifndef WINCE 00361 ::remove(indexName); 00362 #else 00363 DeleteFile((LPCTSTR)indexName); 00364 #endif 00365 delete [] oneLine; 00366 return false; 00367 } 00368 fprintf(file,"%s \r\n",stat); 00369 delete stat; 00370 stat=NULL; 00371 if (!hasInput) { 00372 delete input; 00373 input = NULL; 00374 } 00375 } 00376 fclose(file); 00377 delete [] oneLine; 00378 return true; 00379 } else { 00380 delete [] oneLine; 00381 return false; 00382 } 00383 } 00384 00385 00386 bool ContainerInfo::loadFromCfgFile(char *indexName) { 00387 FILE *file = fopen(indexName, "rb"); 00388 if (!file) 00389 return false; 00390 00391 char *line = new char[MAX_BUFFER_SIZE]; 00392 int versionMagic=0; 00393 // get version number 00394 line[0] = 0; 00395 fgets(line, MAX_BUFFER_SIZE, file); 00396 sscanf(line,"%i",&versionMagic); 00397 if(versionMagic!=MP4CONF_VERSION) { 00398 dprintf_err("Detected old mp4.conf file\n"); 00399 fclose(file); 00400 delete [] line; 00401 return false; 00402 } 00403 // line contains localFile \r\n 00404 line[0] = 0; 00405 fgets(line, MAX_BUFFER_SIZE, file); 00406 if(localFile) { 00407 delete[] localFile; 00408 localFile=NULL; 00409 } 00410 if(strlen(line)>3) { 00411 if(strstr(line,"NULL")) { 00412 localFile=NULL; 00413 } 00414 else { 00415 localFile=new char[strlen(line)+1]; 00416 strcpy(localFile,line); 00417 } 00418 } 00419 00420 dprintf_full("ContainerInfo::loadFromCfgFile: EMPTY Mp4StreamInfo object created\r\n"); 00421 //2nd line: URL or NULL 00422 line[0] = 0; 00423 fgets(line, MAX_BUFFER_SIZE, file); 00424 if (strlen(line) < 4) { 00425 fclose(file); 00426 delete [] line; 00427 return false; 00428 } 00429 if(url) { 00430 delete url; 00431 } 00432 url = new Url(line); 00433 if (!url->toString()) { 00434 clear(); 00435 fclose(file); 00436 delete [] line; 00437 return false; 00438 } 00439 // 3rd line: iodHandleSize <space> iodHandle <space> <nrES> <space> \r\n 00440 00441 //read iodHandleSize 00442 int pos = 0; 00443 int ch = 0; 00444 bool space = false; 00445 while (!space) { 00446 ch = fgetc(file); 00447 if (ch < 0) { 00448 clear(); 00449 fclose(file); 00450 delete [] line; 00451 return false; 00452 } 00453 line[pos] = (char) ch; 00454 if (line[pos] == ' ') 00455 space = true; 00456 pos++; 00457 } 00458 // pos contains the number of chars read 00459 line[pos] = 0; 00460 iodHandleSize = atoi(line); 00461 if (iodHandleSize < 0) { 00462 dprintf_err("ContainerInfo: illegal iodHandleSize\n"); 00463 clear(); 00464 fclose(file); 00465 delete [] line; 00466 return false; 00467 } 00468 if(iodHandleSize>0) { 00469 iodHandle = new u8[iodHandleSize]; 00470 iodHandle[0] = 0; 00471 } 00472 else 00473 iodHandle=NULL; 00474 00475 if (iodHandle && 00476 (iodHandleSize) != fread(iodHandle, 1, iodHandleSize, file)) { 00477 dprintf_err("ContainerInfo: Failed to read IOD\n"); 00478 clear(); 00479 fclose(file); 00480 delete [] line; 00481 return false; 00482 } 00483 00484 // now read the number of ES 00485 line[0] = 0; 00486 fgets(line, MAX_BUFFER_SIZE, file); 00487 if (strlen(line) < 4) { 00488 dprintf_err("ContainerInfo: failed to read 2nd Line\n"); 00489 clear(); 00490 fclose(file); 00491 delete [] line; 00492 return false; 00493 } 00494 int nrEs = -1; 00495 if (1 != sscanf(line, " %i", &nrEs)) { 00496 dprintf_err("ContainerInfo: failed to read nrES\n"); 00497 clear(); 00498 fclose(file); 00499 return false; 00500 } 00501 if (nrEs < 0) { 00502 dprintf_err("ContainerInfo: illegal nrES\n"); 00503 clear(); 00504 fclose(file); 00505 delete [] line; 00506 return false; 00507 } 00508 // read the ES entries 00509 u32 size = 0; 00510 for (int i = 0; i < nrEs; i++) { 00511 line[0] = 0; 00512 fgets(line, MAX_BUFFER_SIZE, file); 00513 if (strlen(line) == 0) { 00514 clear(); 00515 fclose(file); 00516 delete [] line; 00517 return false; 00518 } 00519 ESInfo *entry = parseES(line); 00520 if (!entry) { 00521 dprintf_err("ContainerInfo: failed to read ES %i\n", i); 00522 clear(); 00523 fclose(file); 00524 delete [] line; 00525 return false; 00526 } 00527 u32 sample=entry->getNumberOfMediaSamples(); 00528 if(sample==0) { 00529 fgets(line, MAX_BUFFER_SIZE, file); // read NULL string 00530 } 00531 else { 00532 char* data=new char[sample+5]; 00533 fgets(data,sample+5,file); 00534 if(strcmp(data,"NULL")!=0) { 00535 data[sample]='\0'; 00536 entry->setFrameStatistic(BitField::fromAsciiString(data)); 00537 } 00538 delete[] data; 00539 } 00540 addESInfo(entry); 00541 size += entry->getOrigMediaSize(); 00542 } 00543 qinfo.steps[0]->size = size; 00544 fclose(file); 00545 delete [] line; 00546 return true; 00547 } 00548 00549 00550 ESInfo *ContainerInfo::parseES(char *line) { 00551 00552 ESInfo *result=NULL; 00553 u32 tid; 00554 u32 handlerType; 00555 u8 *decoderConfig=NULL; 00556 u32 decConfSize; 00557 u32 objectType; 00558 u32 streamType; 00559 u32 bufferSize; 00560 u32 width; 00561 u32 height; 00562 u32 avg; 00563 u32 max; 00564 u32 time; 00565 u64 dur; 00566 u32 dl, dh, size; 00567 u32 tickInc = 0; 00568 u32 hasColor=1; 00569 u32 codecId; 00570 u32 gop_size=0; 00571 u32 numBFrames=0; 00572 float quality; 00573 float aspectRatio=1.0; 00574 u32 audioSampleRate; 00575 u32 numChannels; 00576 bool bColor; 00577 bool bIsComplete; 00578 u32 staticFramePattern=0; 00579 bool bStaticFramePattern=false; 00580 float bframesize=0.0; 00581 u32 isComplete=1; 00582 char *fileName = new char[4096]; 00583 00584 // streamId handlerType decConfSize encodedDecoderConfig objectType 00585 // streamType bufferSize width height avg max timescale duration [<fileName_of_input>||null] \r\n 00586 if (3 != sscanf(line, "%u %u %u", &tid, &handlerType, &decConfSize)) { 00587 dprintf_err("ContainerInfo::parseES1: Invalid or old ES File! Delete your demux dir\n%s\n",line); 00588 delete [] fileName; 00589 return NULL; 00590 } 00591 decoderConfig = new u8[decConfSize + 1]; 00592 // duration is 64 bits, read higher bits first, then lower 00593 if (28 != sscanf(line, "%u %u %u %s %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %f %f %u %u %f %u %u %u %s ", 00594 &tid, &handlerType, &decConfSize, decoderConfig, 00595 &objectType, &streamType, &bufferSize, &width, &height, 00596 &avg, &max, &time, &dh, &dl, &size, &tickInc, &hasColor, &isComplete, 00597 &codecId, &quality, &aspectRatio, &gop_size, &numBFrames, &bframesize,&staticFramePattern, 00598 &audioSampleRate, &numChannels, fileName)) { 00599 dprintf_err("ContainerInfo::parseES2: Invalid or old ES File! Delete your demux dir\n%s\n",line); 00600 delete [] fileName; 00601 return NULL; 00602 } 00603 bStaticFramePattern= (staticFramePattern==1) ? true : false; 00604 bColor = (hasColor==1) ? true : false; 00605 bIsComplete = (isComplete==1) ? true : false; 00606 dur = dh; 00607 dur <<= 32; 00608 dur += dl; 00609 dprintf_small 00610 ("Read:%i %i %i %s %i %i %i %i %i %i %i %i %i %i %i %i %i %s \r\n", tid, 00611 handlerType, decConfSize, decoderConfig, objectType, streamType, 00612 bufferSize, width, height, avg, max, time, dh, dl, size, hasColor, isComplete, 00613 fileName); 00614 if(time==0) { 00615 dprintf_err("ContainerInfo::parseES: wrong timescale in conf file!\n"); 00616 fprintf(stderr,"ContainerInfo::parseES: wrong timescale in conf file!\n"); 00617 time=90000; 00618 } 00619 if(handlerType==MP4VisualHandlerType) { 00620 result = new VideoESInfo(tid, streamType, this, tickInc, decoderConfig, objectType, 00621 bufferSize, avg, max, time, dur, size, width, height, 00622 bColor, bIsComplete,(enum CodecID)codecId, quality, 00623 aspectRatio,gop_size,numBFrames,bStaticFramePattern,bframesize); 00624 } 00625 else if(handlerType==MP4AudioHandlerType) { 00626 result= new AudioESInfo(tid, streamType, this, tickInc, decoderConfig, objectType, 00627 bufferSize, avg, max, time, 00628 dur, size, bIsComplete,audioSampleRate, numChannels, 00629 (enum CodecID)codecId, quality); 00630 } 00631 else if(handlerType==MP4SceneDescriptionHandlerType) { 00632 result= new BifsESInfo(tid, streamType, this, tickInc, decoderConfig, objectType, 00633 bufferSize, avg, max, time, dur, size, bIsComplete, 00634 (enum CodecID)codecId, quality); 00635 } 00636 else if(handlerType==MP4ObjectDescriptorHandlerType) { 00637 result= new ObjectDescriptorESInfo(tid, streamType, this, tickInc, decoderConfig, objectType, 00638 bufferSize, avg, max, time, dur, size, bIsComplete, 00639 (enum CodecID)codecId, quality); 00640 } 00641 else { 00642 dprintf_err("ContainerInfo::parseES: Unknown stream type!\n"); 00643 ; 00644 } 00645 if (result && strcmp(fileName, "NULL") != 0) 00646 result->setInput(fileName); 00647 00648 delete [] fileName; 00649 return result; 00650 00651 } 00652 00653 /* 00654 u32 ContainerInfo::getActSize() const { 00655 return qinfo.steps[qinfo.currentQAStep]->size; 00656 } 00657 */ 00658 00659 /* 00660 float ContainerInfo::getActQuality() const { 00661 return qinfo.steps[qinfo.currentQAStep]->quality; 00662 } 00663 */ 00664 00665 bool ContainerInfo::destroy() { 00666 bool ret = true; 00667 if(localFile) { 00668 FILE *fp = fopen(this->localFile, "w"); 00669 00670 if (fp) { 00671 fclose(fp); 00672 #ifndef WINCE 00673 remove(localFile); 00674 #else 00675 DeleteFile((LPCTSTR)localFile); 00676 #endif 00677 ret = true; 00678 } 00679 } 00680 00681 list < ESInfo * >::iterator li = esList.begin(); 00682 // IO *io = NULL; 00683 00684 while (li != esList.end()) { 00685 00686 if ((localFile && strcmp(localFile, (*li)->getInput()) != 0) || !localFile) { 00687 ret &= (*li)->destroy(); 00688 } 00689 00690 ++li; 00691 } 00692 if(localFile) { 00693 delete[] localFile; 00694 localFile = NULL; 00695 } 00696 return ret; 00697 } 00698 00699 00704 ESInfo *ContainerInfo::getES(u32 streamId) const { 00705 list < ESInfo * >::const_iterator li; 00706 if (esList.empty()) 00707 return NULL; 00708 else 00709 li = esList.begin(); 00710 while (li != esList.end()) { 00711 if ((*li)->getStreamId() == streamId) 00712 return (*li); 00713 ++li; 00714 } 00715 return NULL; 00716 } 00717 00718 00719 bool ContainerInfo::hasAudio() const { 00720 00721 list < ESInfo * >::const_iterator li = esList.begin(); 00722 while (li != esList.end()) { 00723 if ((*li)->isAudioStream()) 00724 return true; 00725 ++li; 00726 } 00727 return false; 00728 } 00729 00730 00732 VideoESInfo *ContainerInfo::getFirstVisualES() { 00733 list < ESInfo * >::const_iterator li; 00734 00735 if (esList.empty()) 00736 return NULL; 00737 00738 li = esList.begin(); 00739 while (li != esList.end()) { 00740 if ((*li)->isVisualStream()) 00741 return (VideoESInfo*)(*li); 00742 ++li; 00743 } 00744 return NULL; 00745 } 00746 00747 00749 AudioESInfo *ContainerInfo::getFirstAudioES() { 00750 list < ESInfo * >::const_iterator li; 00751 00752 if (esList.empty()) 00753 return NULL; 00754 00755 li = esList.begin(); 00756 while (li != esList.end()) { 00757 if ((*li)->isAudioStream()) 00758 return (AudioESInfo*)(*li); 00759 ++li; 00760 } 00761 return NULL; 00762 } 00763 00764 00765 00767 ContainerInfo * ContainerInfo::clone() { 00768 00769 ContainerInfo * result = new ContainerInfo(this->qinfo); 00770 Url *uri = NULL; 00771 if (url) { 00772 uri = new Url(url->toString()); 00773 } 00774 00775 result->setUrl(uri); 00776 result->setLocalFile(this->localFile); 00777 result->type=this->type; 00778 if (this->iodHandle) 00779 result->setIODHandle(this->iodHandle, this->iodHandleSize); 00780 list < ESInfo * >::const_iterator li; 00781 if (!esList.empty()) { 00782 li = esList.begin(); 00783 while (li != esList.end()) { 00784 result->addESInfo((*li)->clone(result)); 00785 ++li; 00786 } 00787 } 00788 00789 result->setLastRequestTime(this->lastAccessTime); 00790 return result; 00791 } 00792 00793 00794 void ContainerInfo::setMetaObject(MetaObject* meta) { metaObj=meta;}; 00795 00796 00797 MetaObject* ContainerInfo::getMetaObject() { return metaObj;}; 00798 00799 00800 rtx_group* ContainerInfo::getRtxGroup(u32 esId,list<rtx_group*>* rtxInfo) const { 00801 00802 for( list<rtx_group*>::iterator li=rtxInfo->begin(); 00803 li!=rtxInfo->end(); li++) { 00804 if( (*li)->es && esId==(*li)->es->getStreamId()) 00805 return *li; 00806 } 00807 return NULL; 00808 } 00809 00810 00812 const Url* ContainerInfo::getUrl() const { 00813 return url; 00814 } 00815 00816 00817 void ContainerInfo::setUrl(Url *uri) { 00818 if (url) 00819 delete url; 00820 url = uri; 00821 } 00822 00823 00824 void ContainerInfo::setLocalFile(const char* loclFile) { 00825 if(loclFile) { 00826 if(localFile) 00827 delete[] localFile; 00828 } 00829 else 00830 return; 00831 00832 localFile=new char[strlen(loclFile)+1]; 00833 strcpy(localFile,loclFile); 00834 char* tmp=localFile; 00835 #ifdef WIN32 00836 while(tmp=strchr(tmp,'/')) { 00837 *tmp='\\'; 00838 tmp++; 00839 } 00840 #else 00841 while((tmp=strchr(tmp,'\\')) != NULL) { 00842 *tmp='/'; 00843 tmp++; 00844 } 00845 #endif 00846 } 00847 00848 00849 ReferenceCounter* ContainerInfo::getUsageCounter() { 00850 return usageCounter; 00851 } 00852 00853 00854 u32 ContainerInfo::getFileSize() const { 00855 u32 filesize=0; 00856 FILE* fp=NULL; 00857 00858 if(localFile && (fp=fopen(localFile,"rb"))) { 00859 fseek(fp,0,SEEK_END); 00860 long l=ftell(fp); 00861 if(l>0) 00862 filesize=(u32)l; 00863 fclose(fp); 00864 } 00865 if(filesize==0) { 00866 // sum up the sizes of the demuxed streams 00867 std::list<ESInfo*>::const_iterator li; 00868 for(li=esList.begin();li!=esList.end();++li) { 00869 filesize+=(*li)->getCurrentDemuxedMediaSize(); 00870 } 00871 } 00872 return filesize; 00873 } 00874 00875 00878 u32 ContainerInfo::getEstimatedNetworkFileSize() { 00879 u32 filesize=0; 00880 std::list<ESInfo*>::iterator li; 00881 for(li=esList.begin();li!=esList.end();++li) { 00882 filesize+=(u32)((*li)->getAvgBandwidth() * ( ((double)(*li)->getDurationInMs())/8000.0)); 00883 } 00884 return filesize; 00885 } 00886 00887 00889 u32 ContainerInfo::getNumberOfVisualStreams() const { 00890 u32 cnt=0; 00891 std::list<ESInfo*>::const_iterator li; 00892 for(li=esList.begin();li!=esList.end();++li) { 00893 if((*li)->isVisualStream()) 00894 cnt++; 00895 } 00896 return cnt; 00897 } 00898 00899 00901 u32 ContainerInfo::getNumberOfAudioStreams() const { 00902 u32 cnt=0; 00903 std::list<ESInfo*>::const_iterator li; 00904 for(li=esList.begin();li!=esList.end();++li) { 00905 if((*li)->isAudioStream()) 00906 cnt++; 00907 } 00908 return cnt; 00909 } 00910