MetaObject Class Reference

<class description="" goes="" here=""> <short description=""> More...

#include <MetaObject.hpp>

List of all members.


Public Member Functions

 MetaObject (ContainerInfo *stream)
 creates a new meta-object for the given stream.
 MetaObject (const char *configFile)
 creates a new empty meta-object and tries to init from a config file
 ~MetaObject ()
 frees memory for all ContainerInfo objects
ContainerInfofindMp4Stream (u32 lowerDimX, u32 upperDimX, u32 lowerDimY, u32 upperDimY, u32 lowerBitRate, u32 upperBitRate, bool greyScale, float frameRate, bool *isExactMatch)
 search for a stream with specified properties
bool addMP4Stream (ContainerInfo *stream)
bool deleteMP4Stream (ContainerInfo *stream)
 returns true iff the stream is found
const UrlgetUrl () const
bool saveToConfigFile (const char *cfg)
int getNumberOfVariations () const
std::list< ContainerInfo * > * getVariations ()
 returns a pointer to the internal variations.
void releaseVariationsLock ()

Protected Member Functions

bool loadFromConfigFile (const char *cfg)
 if this method is called, it will destroy all previously stored ContainerInfo objects and delete the url.
double calcSimpleQuality (u32 min, u32 max, u32 val)
 calculates quality inside the range min, max for value val

Protected Attributes

list< ContainerInfo * > variations
Urlurl
VMutex lockAccess
u32 pendingOutsideUnlock

Detailed Description

<class description="" goes="" here=""> <short description="">

Author:
Michael Kropfberger and Peter Schojer
Version:
Id
MetaObject.hpp,v 1.10 2006/01/20 15:37:17 mkropfbe Exp

Definition at line 65 of file MetaObject.hpp.


Constructor & Destructor Documentation

MetaObject::MetaObject ContainerInfo stream  ) 
 

creates a new meta-object for the given stream.

Parameters:
stream is shallow copied and destroyed with the meta-object
Definition at line 60 of file MetaObject.cpp.

References ContainerInfo::getUrl(), VMutex::initialize(), ContainerInfo::setMetaObject(), and Url::toString().

00060 { 00061 assert(stream); 00062 url=NULL; 00063 pendingOutsideUnlock=0; 00064 lockAccess.initialize("MetaObject-lockAccess"); 00065 if(stream) { 00066 dprintf_full("MetaObject::MetaObject stream ok\n"); 00067 if (stream->getUrl()) 00068 { 00069 dprintf_full("MetaObject::MetaObject url ok\n"); 00070 url=new Url(stream->getUrl()->toString()); 00071 } 00072 variations.push_back(stream); 00073 } 00074 stream->setMetaObject(this); 00075 };


Member Function Documentation

bool MetaObject::addMP4Stream ContainerInfo stream  ) 
 

Parameters:
return returns false if a stream with the same properties already exists, otherwise the video is added to the MetaObject and true is returned
Definition at line 242 of file MetaObject.cpp.

References ContainerInfo::destroy(), ContainerInfo::getFirstVisualES(), ContainerInfo::getUrl(), Url::isEqual(), VMutex::lock(), VMutex::release(), and ContainerInfo::setMetaObject().

Referenced by CacheManagerLRU::putVideo().

00242 { 00243 lockAccess.lock(); 00244 00245 list<ContainerInfo*>::iterator varCI; 00246 00247 for(varCI=variations.begin(); varCI!=variations.end(); ++varCI) { 00248 // search within one variation for a similar ES entry 00249 if(stream->getUrl()->isEqual((*varCI)->getUrl())) { 00250 // compare quality! 00251 VideoESInfo* vIn=stream->getFirstVisualES(); 00252 VideoESInfo* v=(*varCI)->getFirstVisualES(); 00253 if(v->getWidth()==vIn->getWidth() && 00254 v->getAvgBandwidth()==vIn->getAvgBandwidth() && 00255 v->getFPS()>=vIn->getFPS()) { 00256 // we have same quality stored, delete the inserted one 00257 // for simplicity because the other is probably in use 00258 stream->destroy(); 00259 delete stream;stream=NULL; 00260 lockAccess.release(); 00261 return false; 00262 } 00263 } 00264 } 00265 stream->setMetaObject(this); 00266 variations.push_back(stream); 00267 lockAccess.release(); 00268 return true; 00269 00270 };

double MetaObject::calcSimpleQuality u32  min,
u32  max,
u32  val
[protected]
 

calculates quality inside the range min, max for value val

Parameters:
min specifies the lower border of the range
max specifies the upper border of the range
val specifies a point inside the range
return will be -1 if
min >
max,or will be zero if
val is outside of the range.otherwise a value between 0 and 1 will be returned, which states how close
val is to
max if
val ==
max then 1.0 will be returned
Definition at line 97 of file MetaObject.cpp.

Referenced by findMp4Stream().

00097 { 00098 if(min==max) { 00099 if(min==val) 00100 return 1.0; 00101 00102 return 0.0; 00103 } 00104 if(min>max) 00105 return -1.0; 00106 if(min<=val && val <=max) 00107 return (((double)val)-min)/(max-min); 00108 00109 return 0.0; 00110 }

ContainerInfo * MetaObject::findMp4Stream u32  lowerDimX,
u32  upperDimX,
u32  lowerDimY,
u32  upperDimY,
u32  lowerBitRate,
u32  upperBitRate,
bool  greyScale,
float  frameRate,
bool *  isExactMatch
 

search for a stream with specified properties

Parameters:
lowerDimX specifies the minimum width of the video
upperDimX specifies the maximum width of the video
lowerDimY specifies the minimum height of the video
lowerDimY specifies the maximum height of the video
lowerBitRate specifies the minimum bit-rate in bit/sec
upperBitRate specifies the maximum bit-rate in bit/sec
greyScale specifies if the video should have color or not
isExactMatch specifies if an exact match was found or not. An exact match is anything that fits the specified range If you want to exclude some params from the search, set the lower Value to zero and the upper value to the largest int. Note that
return will only return NULL, if no ContainerInfo object is stored. If no exact match is found, the object nearest to the specified parameters is returned and
isExactMatch is set to false. If you do require an exact match, take the returned ContainerInfo and call makeExactMatch. FIXME: support TemporalAdaptation
Definition at line 132 of file MetaObject.cpp.

References calcSimpleQuality(), ContainerInfo::getESList(), ContainerInfo::getFirstVisualES(), VMutex::lock(), and VMutex::release().

Referenced by ServerSession::setUrl(), and ProxySession::setUrl().

00136 { 00137 00138 dprintf_full("MetaObject::findMp4Stream(u32 lowX=%u,u32 uppX=%u,u32 lowY=%u,u32" 00139 " upY=%u,u32 lowBitRate=%u kbps, u32 upperBitRate=%u kbps,bool greyScale=%i)\n", 00140 lowerDimX,upperDimX,lowerDimY,upperDimY,lowerBitRate/1024,upperBitRate/1024, (int)greyScale); 00141 lockAccess.lock(); 00142 *isExactMatch=false; 00143 ContainerInfo* best=NULL; 00144 int maxHits=0; 00145 if(variations.empty()) { 00146 lockAccess.release(); 00147 return NULL; 00148 } 00149 double bestQuality=0.0, currentQuality=0.0; 00150 u32 bestBitRate; 00151 list<ContainerInfo*>::iterator li=variations.begin(); 00152 while(li!=variations.end()) { 00153 // compare 00154 VideoESInfo* temp = (*li)->getFirstVisualES(); 00155 AudioESInfo* temp2= (*li)->getFirstAudioES(); 00156 u32 sysBitRate= (temp2? temp2->getAvgBandwidth():0); 00157 sysBitRate+=(temp? temp->getAvgBandwidth():0); 00158 int countHits=0; 00159 countHits+=(sysBitRate>=lowerBitRate) ? 1 : 0; 00160 countHits+=(sysBitRate<=upperBitRate) ? 1 : 0; 00161 // problem with network: return the one version with the value 00162 // closest to the specified range, make sure this doesn't have a 00163 // too big influence in case other misses are encountered --> countHits are used for that! 00164 if(lowerBitRate<=upperBitRate) { 00165 if(lowerBitRate<=sysBitRate && sysBitRate<=upperBitRate) { 00166 currentQuality=1.0+calcSimpleQuality(lowerBitRate,upperBitRate,sysBitRate); 00167 } 00168 else { 00169 // if out of range calc a value between 0..1 stating how many % we are off 00170 if(sysBitRate < lowerBitRate && sysBitRate > lowerBitRate/2) { 00171 currentQuality=calcSimpleQuality(lowerBitRate/2,lowerBitRate,sysBitRate); 00172 } 00173 else if(sysBitRate> upperBitRate && sysBitRate < upperBitRate*2) { 00174 currentQuality=1.0-calcSimpleQuality(upperBitRate,upperBitRate*2,sysBitRate); 00175 } 00176 else 00177 currentQuality=0.0; 00178 } 00179 } 00180 else 00181 currentQuality=0.0; 00182 00183 if(temp) { 00184 if(lowerDimX<=upperDimX && lowerDimY<upperDimY && upperDimX>32 && upperDimY>32) { 00185 countHits+=(temp->getWidth()>=lowerDimX) ? 1 : 0; 00186 countHits+=(temp->getHeight()>=lowerDimY) ? 1 : 0; 00187 countHits+=(temp->getWidth()<=upperDimX) ? 1 : 0; 00188 countHits+=(temp->getHeight()<=upperDimY) ? 1 : 0; 00189 currentQuality+=calcSimpleQuality(lowerDimX,upperDimX,temp->getWidth()); 00190 currentQuality+=calcSimpleQuality(lowerDimY,upperDimY,temp->getHeight()); 00191 } 00192 else { 00193 /* ignore the incorrectly given dimension */ 00194 countHits+=4; 00195 } 00196 countHits+=(greyScale!=temp->getHasColor()) ? 1 : 0; 00197 } 00198 else 00199 countHits+=5; //dim+greyscale 00200 00201 if(frameRate>temp->getFPS()) 00202 countHits++; 00203 00204 dprintf_full("MetaObject::findMp4Stream checking on width=%u, height=%u, bitRate=%u kbps," 00205 " hasColor %i: quality %4.2f hits %i\n", 00206 temp->getWidth(),temp->getHeight(),sysBitRate/1024,temp->getHasColor(), currentQuality, countHits); 00207 00208 00209 if(countHits == 8) { 00210 // a perfect hit 00211 maxHits=countHits; 00212 *isExactMatch=true; 00213 dprintf_full("MetaObject::findMp4Stream found a perfect hit (exact match!)\r\n"); 00214 if(currentQuality > bestQuality || currentQuality <= 0.0) { 00215 best=*li; 00216 bestQuality = currentQuality; 00217 bestBitRate = sysBitRate; 00218 } 00219 } 00220 else if ((countHits >= maxHits) && (bestQuality < currentQuality) ) { 00221 // new best match 00222 best=*li; 00223 bestQuality=currentQuality; 00224 maxHits=countHits; 00225 bestBitRate = sysBitRate; 00226 } 00227 ++li; 00228 } 00229 dprintf_full("MetaObject::findMp4Stream has %i hits from 8, quality %4.2f\n",maxHits, bestQuality); 00230 lockAccess.release(); 00231 if (best) { 00232 dprintf_full("MetaObject::findMp4Stream decides on Container with width=%u, height=%u, bitRate=%i kbps firstES id %llu (url %s)\n", 00233 best->getFirstVisualES()->getWidth(),best->getFirstVisualES()->getHeight(), bestBitRate/1024, (*best->getESList()->begin())->getStreamId(), (*best->getESList()->begin())->getInput()); 00234 return best; 00235 } else 00236 return NULL; 00237 };

std::list< ContainerInfo * > * MetaObject::getVariations  ) 
 

returns a pointer to the internal variations.

locks and KEEPS the lock. You must call releaseVariationsLock(), when you are done with the listDefinition at line 396 of file MetaObject.cpp.

References VMutex::lock().

00397 { 00398 lockAccess.lock(); 00399 pendingOutsideUnlock++; 00400 return &variations; 00401 };

bool MetaObject::loadFromConfigFile const char *  cfg  )  [protected]
 

if this method is called, it will destroy all previously stored ContainerInfo objects and delete the url.

Then it will load the cfg file. Recommended use is to call it only from a constructorDefinition at line 354 of file MetaObject.cpp.

References ContainerInfo::loadFromCfgFile(), VMutex::lock(), and VMutex::release().

Referenced by MetaObject().

00354 { 00355 FILE* fp=fopen(cfg,"rb"); 00356 if(!fp) 00357 return false; 00358 00359 lockAccess.lock(); 00360 if(url) { 00361 delete url; 00362 } 00363 00364 list<ContainerInfo*>::iterator start; 00365 while(!variations.empty()) { 00366 start=variations.begin(); 00367 delete (*start); 00368 variations.pop_front(); 00369 } 00370 00371 // everything cleaned up 00372 bool retVal=true; 00373 char *line = new char[1024]; 00374 fgets(line,1024,fp); 00375 // first line contains url 00376 url=new Url(line); 00377 00378 // then read the objects 00379 ContainerInfo* info=NULL; 00380 //int counter=0; 00381 while(!feof(fp)) { 00382 fgets(line,1024,fp); 00383 info=new ContainerInfo(); 00384 if(info->loadFromCfgFile(line)) { 00385 variations.push_back(info); 00386 } 00387 else 00388 retVal=false; 00389 } 00390 fclose(fp); 00391 lockAccess.release(); 00392 delete [] line; 00393 return retVal; 00394 };


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