CacheManagerLRU Class Reference

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

#include <CacheManagerLRU.hpp>

Inheritance diagram for CacheManagerLRU:

CacheManager List of all members.

Public Member Functions

 CacheManagerLRU (u32 size, bool serverMode)
void putVideo (ContainerInfo *video, u32 dskSpaceAlreadyReserved=0)
 inserts the video, if the video is smaller than the total cache size.
ContainerInfogetVideo (const Url *URL)
 returns an ContainerInfo for the given url, if the URL is cached.
u32 getCacheSize () const
u32 getActSize () const
u32 getRequests () const
u32 getHits () const
u64 getByteRequested () const
u64 getByteHits () const
double getQualityHits () const
void getContent ()
void saveCacheIndexToDir (const char *dir)

Protected Member Functions

bool replace (bool testPriorDelete)
void internalConsistencyCheck ()
MetaObjectfindMetaObject (const Url *url)
void deleteMetaObject (const Url *url)
u32 getSizeOfNotLockedObjects ()
 requires mutex to be locked

Protected Attributes

list< ContainerInfo * > lrulist
 list of video objects, which will be replaced
list< MetaObject * > metaObjects
 stores metaobjects

Detailed Description

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

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

Definition at line 64 of file CacheManagerLRU.hpp.


Member Function Documentation

ContainerInfo * CacheManagerLRU::getVideo const Url URL  )  [virtual]
 

returns an ContainerInfo for the given url, if the URL is cached.

lock count is increased by one. If the client/session object is finished with the ContainerInfo object it has to call info->unlock()!!!!

Implements CacheManager.

Definition at line 171 of file CacheManagerLRU.cpp.

References ContainerInfo::getFirstVisualES(), ContainerInfo::getUrl(), lrulist, and Url::toString().

00172 { 00173 list < ContainerInfo * >::iterator start, end; 00174 ContainerInfo* vid = NULL; 00175 start = lrulist.begin(); 00176 end = lrulist.end(); 00177 internalConsistencyCheck(); 00178 requests++; 00179 printf("*******CacheManagerLRU::getVideo use URL: #%s#\n", name->toString()); 00180 if (strcmp(name->toString(), "v4l") != 0) 00181 { 00182 00183 if(start==end) { 00184 return NULL; 00185 } 00186 bool firstDel=false; 00187 00188 while(start != end) { 00189 00190 vid=(*start); 00191 dprintf_full("CacheManagerLRU::getVideo found Cached URL: #%s#\n",vid->getUrl()->toString()); 00192 VideoESInfo* ves=vid->getFirstVisualES(); 00193 // AudioESInfo* aes=vid->getFirstAudioES(); 00194 float qual=0.0; 00195 if(ves && ves->getFrameStatistic()) 00196 qual=ves->getFrameStatistic()->getPercentageSetBits(); 00197 dprintf_full("CacheManagerLRU::getVideo found %f complete (use %u)\n",qual,(*start)->getUsageCounter()->getUsage()); 00198 // quality too low and not used (aka quality will improve) 00199 /* if(qual<0.9 && (*start)->getUsageCounter()->deactivateWhenUsage(0)) { 00200 (*start)->destroy(); 00201 MetaObject* meta=(*start)->getMetaObject(); 00202 if(meta->getNumberOfVariations()==1) { 00203 deleteMetaObject(meta->getUrl()); 00204 } 00205 else { 00206 meta->deleteMP4Stream(*start); // frees *start 00207 } 00208 00209 list < ContainerInfo * >::iterator tmp= start; 00210 if(start!=lrulist.begin()) { 00211 start--; // point before the element which is deleted 00212 lrulist.erase(tmp); 00213 } 00214 else { // we delete the first element 00215 lrulist.erase(tmp); 00216 firstDel=true; 00217 start=lrulist.begin(); 00218 } 00219 } 00220 else*/ if ((*start)->getUrl()->isEqual(name,serverMode) ) { 00221 lrulist.push_front(*start); 00222 lrulist.erase(start); 00223 start = lrulist.begin(); 00224 hits++; 00225 byteRequested += (*start)->getFileSize(); 00226 byteHits += (*start)->getFileSize(); 00227 qualityHits += (*start)->getActQuality(); 00228 (*start)->setLastRequestTime(requests); 00229 return (*start); 00230 } 00231 if(!firstDel) 00232 ++start; 00233 } 00234 } 00235 #ifndef WIN32 00236 else 00237 { 00238 dprintf_full("CacheManagerLRU::getVideo: Using v4lContailerfile"); 00239 vid=Video4LinuxContainerFile::loadContainerInfo(); 00240 return vid; 00241 } 00242 #endif 00243 00244 return NULL; 00245 00246 00247 };

void CacheManagerLRU::putVideo ContainerInfo video,
u32  dskSpaceAlreadyReserved = 0
[virtual]
 

inserts the video, if the video is smaller than the total cache size.

If it is bigger, the video will be destroyed and its memory freed! LRU doesn't take advantage of adaptation. We just have full or zero quality

Implements CacheManager.

Definition at line 97 of file CacheManagerLRU.cpp.

References MetaObject::addMP4Stream(), MetaObject::deleteMP4Stream(), ContainerInfo::destroy(), ContainerInfo::getESList(), ContainerInfo::getFileSize(), ContainerInfo::getFirstAudioES(), ContainerInfo::getFirstVisualES(), ContainerInfo::getUrl(), ReferenceCounter::getUsage(), ContainerInfo::getUsageCounter(), lrulist, metaObjects, replace(), and Url::toString().

00098 { 00099 if(video==NULL) { 00100 actSize-= dskSpaceAlreadyReserved; 00101 return; 00102 } 00103 assert(video->getUsageCounter()->getUsage()==0); 00104 internalConsistencyCheck(); 00105 u32 videoSize = video->getFileSize(); 00106 byteRequested += videoSize; 00107 float percBits = 1; 00108 if (video->getFirstVisualES()) { 00109 percBits = video->getFirstVisualES()->getFrameStatistic()->getPercentageSetBits(); 00110 dprintf_full("CacheManagerLRU::putVideo Inserting video %s, comp%f\r\n",video->getUrl()->toString(),percBits); 00111 00112 if(percBits <=0.9) { 00113 actSize-= dskSpaceAlreadyReserved; 00114 prxStat.deletedDueToLowQuality++; 00115 video->destroy(); 00116 dprintf_full("Deleted incomplete video %s\n",video->getUrl()->toString()); 00117 return; 00118 } 00119 } 00120 else if (video->getFirstAudioES()) 00121 //FIXME: this stream only has audio, keep it in cache... 00122 dprintf_full("CacheManagerLRU::putVideo Inserting audio-only stream %s\r\n",video->getUrl()->toString()); 00123 00124 00125 list<ESInfo*> *les=video->getESList(); 00126 list<ESInfo*>::iterator lis; 00127 00128 for(lis=les->begin();lis!=les->end();lis++) { 00129 u64 fs=(*lis)->getCurrentDemuxedMediaSize(); 00130 fs*=8000; 00131 fs/=(*lis)->getDurationInMs(); 00132 (*lis)->setAvgBandwidth((u32)fs); 00133 if( (*lis)->getMaxBandwidth()<(*lis)->getAvgBandwidth()) 00134 (*lis)->setMaxBandwidth((*lis)->getAvgBandwidth()); 00135 } 00136 00137 00138 MetaObject* meta=findMetaObject(video->getUrl()); 00139 if(!meta) { 00140 meta=new MetaObject(video); 00141 metaObjects.push_front(meta); 00142 } 00143 else { 00144 if(!meta->addMP4Stream(video)) { 00145 video=NULL; // was deleted 00146 actSize-= dskSpaceAlreadyReserved; 00147 } 00148 } 00149 00150 if (video && videoSize <= cacheSize) { 00151 lrulist.push_front(video); 00152 actSize += video->getFileSize(); 00153 actSize-= dskSpaceAlreadyReserved; 00154 if (actSize > cacheSize) { 00155 dprintf_full("CacheManagerLRU::putVideo Cache Replacement needed\n"); 00156 replace(false); 00157 } 00158 } else if(video){ 00159 dprintf_full("CacheManagerLRU::putVideo: video %s deleted because its size %i is larger than CacheSize %i\r\n", 00160 video->getUrl()->toString(), videoSize, cacheSize); 00161 meta->deleteMP4Stream(video); 00162 actSize-= dskSpaceAlreadyReserved; 00163 video->destroy(); 00164 delete video; 00165 } 00166 internalConsistencyCheck(); 00167 dprintf_full("CacheManagerLRU::putVideo END\r\n"); 00168 };

bool CacheManagerLRU::replace bool  testPriorDelete  )  [protected, virtual]
 

Parameters:
testPriorDelete tests if enough disk space can be freed so that the actSize is below the cacheSize or if too many objects are locked If this test fails, no files are removed form the cache and false is returned

Implements CacheManager.

Definition at line 320 of file CacheManagerLRU.cpp.

References MetaObject::deleteMP4Stream(), MetaObject::getNumberOfVariations(), getSizeOfNotLockedObjects(), MetaObject::getUrl(), and lrulist.

Referenced by putVideo().

00321 { 00322 list < ContainerInfo * >::iterator end; 00323 internalConsistencyCheck(); 00324 if(testPriorDelete) { 00325 u32 maxMemFreeable=getSizeOfNotLockedObjects(); 00326 // is it possible to get actSize < cacheSize? 00327 assert(actSize>=maxMemFreeable); 00328 if(actSize-maxMemFreeable>cacheSize) 00329 return false; 00330 } 00331 00332 while (!lrulist.empty() && actSize > cacheSize) { 00333 end = --lrulist.end(); 00334 // find a video that is not in use 00335 while( end != lrulist.begin() && 00336 !(*end)->getUsageCounter()->deactivateWhenUsage(0)) 00337 --end; 00338 00339 if ((*end)->getUsageCounter()->getUsage() == 0) { 00340 actSize -= (*end)->getFileSize(); 00341 // LRU just deletes the file 00342 (*end)->destroy(); // deletes the file 00343 MetaObject* meta=(*end)->getMetaObject(); 00344 if(meta->getNumberOfVariations()==1) { 00345 deleteMetaObject(meta->getUrl()); 00346 } 00347 else { 00348 bool ok=meta->deleteMP4Stream(*end); // frees *end 00349 assert(ok); 00350 } 00351 lrulist.erase(end); 00352 } 00353 } 00354 internalConsistencyCheck(); 00355 return (actSize<cacheSize); 00356 }


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