ContainerInfo Class Reference

stores pointers to all available ElemStreams (ESInfos) in this container <short description=""> More...

#include <ContainerInfo.hpp>

List of all members.


Public Types

enum  ContainerType {
  UNKNOWN_CONTAINER, AVI, MP4, MATROSKA,
  VITOOKI, DVD, SDP, OGG
}

Public Member Functions

 ContainerInfo (const char *url, const char *locFile, const ContainerType type)
 creates a video object for the given url, the url will be deep-copied.
 ContainerInfo ()
 creates an empty info object.
 ContainerInfo (QualityInfo &q)
 creates an empty info object.
list< ESInfo * > * getESList ()
 returns the list of ESes for this object.
ESInfogetES (u32 streamId) const
 returns for a given streamid the ESInfo object.
VideoESInfo * getFirstVisualES ()
 Returns the first visual ES it finds.
u32 getNumberOfVisualStreams () const
 how many visual streams are part of the Container
u32 getNumberOfAudioStreams () const
 how many audio streams are part of the Container
AudioESInfo * getFirstAudioES ()
 Returns the first visual ES it finds.
ContainerType getContainerType ()
void setContainerType (ContainerType ctype)
IOgetMuxDemuxIO ()
 will be used in conjunction with BufferedIOs created by IOCreator
void setMuxDemuxIO (IO *demuxio)
 will be used in conjunction with BufferedIOs created by IOCreator
bool saveToCfgFile (char *indexName)
 serializes the ContainerInfo to a file.
bool loadFromCfgFile (char *indexName)
 loads an ContainerInfo object from a file.
const UrlgetUrl () const
 returns the url of the video, can return null for demultiplexed videos
void setUrl (Url *uri)
void setLocalFile (const char *loclFile)
const char * getLocalFile () const
void setIODHandle (u8 *iodHandle, u32 iodHandleSize)
 sets the iod at the MP4Stream, a deep-copy is done! iodHandleSize must be a positive number
const u8 * getIODHandle (u32 &size) const
 returns a pointer to the IOD, will update size to contain the iodHandleSize
void addESInfo (ESInfo *esobj)
 adds an ESInfo object to the end of the list of ES's managed by this object
u32 getActSize () const
float getActQuality () const
u32 getLastRequestTime () const
void setLastRequestTime (u32 last)
u32 getFileSize () const
 returns either the filesize of the mp4 file or the sum of the sizes of all demuxed streams
u32 getEstimatedNetworkFileSize ()
 returns for a non-cached object, the estimated filesize according to the SDP description
void setMetaObject (MetaObject *meta)
MetaObjectgetMetaObject ()
bool hasAudio () const
 checks if the MP4 object has one audio stream.
QualityInfo * getQualityInfo ()
ContainerInfoclone ()
 deep-copies the object
ReferenceCountergetUsageCounter ()
bool destroy ()
 deletes all locally stored files belonging to this object
rtx_group * getRtxGroup (u32 esId, list< rtx_group * > *rtxInfo) const

Protected Attributes

ContainerType type
 the format of this container
list< ESInfo * > esList
IOmuxDemuxIO
 will be used in conjunction with BufferedIOs created by IOCreator
Urlurl
 the remote url for this object
char * localFile
 the local cache file.
MetaObjectmetaObj
 points back to the MetaObject
u8 * iodHandle
 iod is not a stream!, seperate it from ES
u32 iodHandleSize
 the byte-size of the iod
u32 timeScale
 the default timescale of the video in ticks/second
u32 lastAccessTime
 cache specific code
ReferenceCounterusageCounter
 usage counter: how many clients are currently accessing this video
QualityInfo qinfo
 information about the current quality and size of the video
char * Name
char * Description
char * MimeType

Detailed Description

stores pointers to all available ElemStreams (ESInfos) in this container <short description="">

Author:
Michael Kropfberger and Peter Schojer
Version:
Id
ContainerInfo.hpp,v 1.21 2006/02/24 08:17:31 mkropfbe Exp

Definition at line 158 of file ContainerInfo.hpp.


Constructor & Destructor Documentation

ContainerInfo::ContainerInfo const char *  url,
const char *  locFile,
const ContainerType  type
 

creates a video object for the given url, the url will be deep-copied.

Always create ContainerInfo objects with the ISOMP4ContainerFile class or use the empty constructor and call loadFromCfgFile afterwards to complete initialization

Parameters:
type: is eg. MP4 or DVD
Definition at line 75 of file ContainerInfo.cpp.

References iodHandle, iodHandleSize, lastAccessTime, localFile, metaObj, muxDemuxIO, type, url, and usageCounter.

00075 : 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 }

ContainerInfo::ContainerInfo  ) 
 

creates an empty info object.

Complete initialization with loadFromCfgFileDefinition at line 101 of file ContainerInfo.cpp.

References iodHandle, iodHandleSize, lastAccessTime, localFile, metaObj, muxDemuxIO, url, and usageCounter.

Referenced by clone().

00101 : 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 }

ContainerInfo::ContainerInfo QualityInfo &  q  ) 
 

creates an empty info object.

with qualityinfo set. Add ESs manuallyDefinition at line 116 of file ContainerInfo.cpp.

References iodHandle, iodHandleSize, lastAccessTime, localFile, metaObj, muxDemuxIO, url, and usageCounter.

00116 : 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 }


Member Function Documentation

ESInfo * ContainerInfo::getES u32  streamId  )  const
 

returns for a given streamid the ESInfo object.

Returns NULL if the streamId was not found. Performance is linear time.Definition at line 704 of file ContainerInfo.cpp.

Referenced by Session::setRtxInfoForES(), and ClientSession::setRtxInfoForES().

00704 { 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 }

list< ESInfo * >* ContainerInfo::getESList  )  [inline]
 

returns the list of ESes for this object.

Note that the ESes are destroyed when the videoobject is deletedDefinition at line 184 of file ContainerInfo.hpp.

Referenced by ContainerDemux::demultiplexAndUpdateIO(), MetaObject::findMp4Stream(), SDP::generate(), and CacheManagerLRU::putVideo().

00184 { 00185 return &esList; 00186 };

bool ContainerInfo::hasAudio  )  const
 

checks if the MP4 object has one audio stream.

Returns false if it hasn't Definition at line 719 of file ContainerInfo.cpp.

00719 { 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 }

bool ContainerInfo::loadFromCfgFile char *  indexName  ) 
 

loads an ContainerInfo object from a file.

if sth. goes wrong, all data loaded so far is freed and false is returned. FIXME: update to include qinfo FIXME: fails when space is in fileNameDefinition at line 386 of file ContainerInfo.cpp.

References addESInfo(), ESInfo::getNumberOfMediaSamples(), ESInfo::getOrigMediaSize(), iodHandle, iodHandleSize, localFile, qinfo, ESInfo::setFrameStatistic(), Url::toString(), and url.

Referenced by MetaObject::loadFromConfigFile().

00386 { 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 }

bool ContainerInfo::saveToCfgFile char *  indexName  ) 
 

serializes the ContainerInfo to a file.

FIXME: update to include qinfo FIXME: fails when space is in fileNameDefinition at line 184 of file ContainerInfo.cpp.

References iodHandle, iodHandleSize, localFile, Url::toString(), and url.

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 }


Member Data Documentation

char* ContainerInfo::localFile [protected]
 

the local cache file.

Can be null Definition at line 327 of file ContainerInfo.hpp.

Referenced by ContainerInfo(), destroy(), getFileSize(), loadFromCfgFile(), and saveToCfgFile().


The documentation for this class was generated from the following files: