ProxySession Class Reference

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

#include <ProxySession.hpp>

Inheritance diagram for ProxySession:

Session VThread List of all members.

Public Member Functions

 ProxySession (int socket, const struct sockaddr_in *client, CacheManager *cm, AdmissionControl *adm, bool allowRTX, SessionCounter *counter=NULL, TerminalCapabilities *defTC=NULL)
 socket: the raw socket for initializing the session control channel.
bool getOptions (const Url *fileName, const char *remaining)
bool setOptions (const Url *fileName, const char *remaining)
bool options (const Url *fileName, const char *remaining)
bool connect (const Url *fileName, const char *remaining)
bool setup (const Url *fileName, const char *remaining)
bool play (const Url *fileName, const char *remaining)
bool pause (const Url *fileName, const char *remaining)
bool tearDown (int sessionKey, bool immediate=false, const Url *fileName=NULL, const char *remaining=NULL)
 teardowns the session specified with sessionKey (if no fileName and no reminaing is specified.
void run ()
void setUrl (const Url *uri, bool makeExactMatch=true)
 deep-copies uri, sets mp4Stream by asking the cacheManager
SessionState getState () const

Protected Member Functions

int readData (char *buffer, int numBytes)
 sets output at the client

Protected Attributes

ServerSessionserverSession
std::map< u32, u32, struct
intCompare > 
sessionTranslator
CacheManagercm
char buffer [MSG_BUFFER_SIZE+1]
char bufferBackup [MSG_BUFFER_SIZE+1]
sockaddr_in * server
bool rtxEnabledToServer
bool rtxEnabledToClient
bool rtxEnabled
 does this proxysession support retransmissions
bool delMp4Stream
 should the created mp4Stream object be deleted
char * playerId
list< rtx_info * > rtxInfoServer
bool insertMp4StreamIntoCM
 is true, when the Mp4Stream Info object is newly created or updated and has to be inserted into the CacheManager
bool dualMiss
 both, the original input stream and the adapted output stream, have to be inserted into the CacheManager
bool dontCacheDualMiss
bool noDescribeSeenYet
SessionCounter * counter

Detailed Description

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

Author:
Michael Kropfberger and Peter Schojer
Version:
Id
ProxySession.hpp,v 1.26 2006/01/20 15:37:54 mkropfbe Exp

Definition at line 135 of file ProxySession.hpp.


Constructor & Destructor Documentation

ProxySession::ProxySession int  socket,
const struct sockaddr_in *  client,
CacheManager cm,
AdmissionControl *  adm,
bool  allowRTX,
SessionCounter *  counter = NULL,
TerminalCapabilities defTC = NULL
 

socket: the raw socket for initializing the session control channel.

the client info is deep-copied

Parameters:
noRTX: if this is set to true the proxy will not support rtx retransmissions and thus create SimpleRtp objects instead of Rtp objects
hideMetaData: never forward any meta-data
Definition at line 93 of file ProxySession.cpp.

References delMp4Stream, dualMiss, and insertMp4StreamIntoCM.

00096 :Session(), 00097 rtxEnabled(allowRTX),neverForwardMetaData(true) 00098 { 00099 assert(adm); 00100 dprintf_full("ProxySession::ProxySession\n"); 00101 prxStat.requests++; 00102 this->counter = counter; 00103 admControl=adm; 00104 state = SESSION_CLOSED; 00105 rtxEnabledToServer=false; 00106 rtxEnabledToClient=false; 00107 delMp4Stream=false; 00108 dualMiss=false; 00109 canAdmitRequest=true; 00110 dontCacheDualMiss=false; 00111 cm = c; 00112 if (clint) { 00113 client = new sockaddr_in(); 00114 memcpy(client, clint, sizeof(sockaddr_in)); 00115 clientId=(u32)client->sin_addr.s_addr; 00116 } else { 00117 client = NULL; 00118 clientId=0; 00119 } 00120 serverSession=NULL; 00121 server=NULL; 00122 sessionControlChannel=socket; 00123 prot = NULL; 00124 url = NULL; 00125 termCap=defTC; 00126 userPref=NULL; 00127 suggestedAdaptor=NULL; 00128 mp4Stream=NULL; 00129 playerId=NULL;serverID=NULL; 00130 insertMp4StreamIntoCM=false; 00131 noDescribeSeenYet=true; 00132 resUsage.cpu=resUsage.disk=resUsage.network=0.0; 00133 origSrc=NULL; 00134 mp4StreamReserved = 0; 00135 origSrcReserved = 0; 00136 }


Member Function Documentation

void ProxySession::setUrl const Url uri,
bool  makeExactMatch = true
[virtual]
 

deep-copies uri, sets mp4Stream by asking the cacheManager

Parameters:
makeExactMatch decides on possible server-side transcoding

Implements Session.

Definition at line 1289 of file ProxySession.cpp.

References ContainerInfo::clone(), ReferenceCounter::decrease(), delMp4Stream, CacheManager::findMetaObject(), MetaObject::findMp4Stream(), TerminalCapabilities::getColorDisplay(), TerminalCapabilities::getDisplayHeight(), TerminalCapabilities::getDisplayRefreshRate(), TerminalCapabilities::getDisplayWidth(), ContainerInfo::getFileSize(), ContainerInfo::getFirstVisualES(), TerminalCapabilities::getMaxDecoderBitRateInBit(), Adaptor::getName(), TerminalCapabilities::getNetworkCapacityInByte(), ContainerInfo::getUsageCounter(), CacheManager::getVideo(), insertMp4StreamIntoCM, CacheManager::lockCache(), CacheManager::reserveDiskSpace(), Adaptor::setESInfo(), Url::toString(), and CacheManager::unlockCache().

01290 { 01291 bool insertResUsage=false; 01292 // problem: a 2nd describe arrives, don't allow that in the same session! 01293 if (cm && uri && !mp4Stream) { 01294 if (url) { 01295 delete url; 01296 } 01297 dprintf_full("ProxySession::setUrl: %s\r\n", uri->toString()); 01298 url = new Url(uri->toString()); 01299 cm->lockCache(); 01300 MetaObject* meta=cm->findMetaObject(url); 01301 01302 01303 bool exactMatch=false; 01304 if( (!termCap && !userPref)) { 01305 mp4Stream = cm->getVideo(url); 01306 01307 // calc resUsage 01308 VideoESInfo* vis=NULL; 01309 if(mp4Stream) 01310 vis=mp4Stream->getFirstVisualES(); 01311 01312 if(vis) { 01313 Feature src(vis); 01314 src.isCached=true; 01315 ResourceUsage* tmpRU=CostFunction::calcResourceUsage(&src,&src,admControl->getResourceLimit()); 01316 if(tmpRU) { 01317 resUsage.network=tmpRU->network; 01318 resUsage.disk=tmpRU->disk; 01319 resUsage.cpu=tmpRU->cpu; 01320 delete tmpRU; 01321 insertResUsage=true; 01322 } 01323 } 01324 insertMp4StreamIntoCM=false; 01325 dprintf_full("ProxySession::setUrl found video (no termcaps or userpref)\n"); 01326 } 01327 else if(meta && userPref) { 01328 // FIXME: hardcode delay values to 100ms 01329 dprintf_full("ProxySession::setUrl meta && userPref\n"); 01330 suggestedAdaptor=admControl->makeBestMatch(userPref,100,meta,&mp4Stream,&resUsage); 01331 dprintf_full("ProxySession::setUrl (N=%f,C=%f,D=%f)\n", 01332 resUsage.network,resUsage.cpu,resUsage.disk); 01333 01334 if(mp4Stream && suggestedAdaptor && resUsage.network>=0.0000001 && 01335 strcmp(suggestedAdaptor->getName(),"Forwarder")!=0 && 01336 !strstr(suggestedAdaptor->getName(),"Temporal")){ // transcoding 01337 // a hit with transcoding! 01338 origSrc=mp4Stream; 01339 mp4Stream=mp4Stream->clone(); 01340 insertMp4StreamIntoCM=true; 01341 01342 u64 durInMS=0; 01343 if(mp4Stream->getFirstVisualES()) 01344 durInMS=mp4Stream->getFirstVisualES()->getDurationInMs(); 01345 else if(mp4Stream->getFirstAudioES()) 01346 durInMS=mp4Stream->getFirstAudioES()->getDurationInMs(); 01347 u32 byteSize=0; 01348 if(userPref) { 01349 byteSize=userPref->bitrate.best/8*durInMS/1000; 01350 } 01351 assert (mp4StreamReserved == 0); 01352 if(cm->reserveDiskSpace(byteSize)) 01353 mp4StreamReserved+=byteSize; 01354 else { 01355 insertMp4StreamIntoCM=false; 01356 } 01357 prxStat.bytesHit+=mp4Stream->getFileSize(); 01358 prxStat.bytesRequested+=mp4Stream->getFileSize(); 01359 prxStat.objHits++; 01360 } 01361 else if(mp4Stream && resUsage.network>=0.0000001 ) { 01362 // never cache temporal transcoding or no transcoding 01363 origSrc=mp4Stream; 01364 insertMp4StreamIntoCM=false; 01365 mp4Stream=mp4Stream->clone(); 01366 this->delMp4Stream=true; 01367 prxStat.bytesHit+=mp4Stream->getFileSize(); 01368 prxStat.bytesRequested+=mp4Stream->getFileSize(); 01369 prxStat.objHits++; 01370 prxStat.qualHits++; 01371 } 01372 else if(mp4Stream) { 01373 // happens in MISS! prxStat.bytesRequested+=mp4Stream->getFileSize(); 01374 mp4Stream=NULL; 01375 } 01376 } 01377 else if(meta && termCap) { 01378 // bandwidth should be the minimum of network and decodeBandwidth 01379 // if one of them is zero, ignore the zero param 01380 u32 bandwidth=termCap->getNetworkCapacityInByte()*8; 01381 if(bandwidth==0) 01382 bandwidth=termCap->getMaxDecoderBitRateInBit(); 01383 else if(termCap->getMaxDecoderBitRateInBit() && 01384 termCap->getMaxDecoderBitRateInBit() < bandwidth) { 01385 bandwidth=termCap->getMaxDecoderBitRateInBit(); 01386 } 01387 mp4Stream=meta->findMp4Stream(0,termCap->getDisplayWidth(), 01388 0,termCap->getDisplayHeight(), 01389 0,bandwidth, 01390 (termCap->getColorDisplay()==0),(float)termCap->getDisplayRefreshRate() ,&exactMatch); 01391 01392 if(makeExactMatch && !exactMatch) { 01393 // clone the mp4Stream 01394 origSrc=mp4Stream; 01395 mp4Stream=mp4Stream->clone(); 01396 mp4Stream->getUsageCounter()->increase(); 01397 insertMp4StreamIntoCM=true; 01398 suggestedAdaptor=admControl->makeExactMatch(termCap->getDisplayWidth(), 01399 termCap->getDisplayHeight(), 01400 bandwidth, 01401 (termCap->getColorDisplay()==0), 01402 (float)termCap->getDisplayRefreshRate(), 01403 mp4Stream,&resUsage); 01404 // check if we have a TemporalAdaptor, do not cache results of temporaladaptor 01405 if(strstr(suggestedAdaptor->getName(),"Temporal") || 01406 strcmp(suggestedAdaptor->getName(),"Forwarder")) { 01407 insertMp4StreamIntoCM=false; 01408 delMp4Stream=true; 01409 } 01410 prxStat.bytesHit+=mp4Stream->getFileSize(); 01411 prxStat.bytesRequested+=mp4Stream->getFileSize(); 01412 prxStat.objHits++; 01413 } 01414 else { 01415 // calc the resource usage for the non transcoding case 01416 origSrc=mp4Stream; 01417 mp4Stream=mp4Stream->clone(); 01418 mp4Stream->getUsageCounter()->increase(); 01419 insertMp4StreamIntoCM=false; 01420 delMp4Stream=true; 01421 if(mp4Stream) { 01422 VideoESInfo* vis=mp4Stream->getFirstVisualES(); 01423 if(vis) { 01424 Feature src(vis); 01425 src.isCached=true; 01426 ResourceUsage* tmpRU=CostFunction::calcResourceUsage(&src,&src,admControl->getResourceLimit()); 01427 if(tmpRU) { 01428 resUsage.network=tmpRU->network; 01429 resUsage.disk=tmpRU->disk; 01430 resUsage.cpu=tmpRU->cpu; 01431 delete tmpRU; 01432 insertResUsage=true; 01433 } 01434 } 01435 } 01436 } 01437 } 01438 cm->unlockCache(); 01439 } 01440 // now insert the resource usage for those other cases (all non-transcoding!) 01441 if(insertResUsage) { 01442 if(!admControl->insertRequest(&resUsage)) { 01443 resUsage.cpu=resUsage.disk=resUsage.network=0.0; 01444 prxStat.bytesRequested+=mp4Stream->getFileSize(); 01445 if(delMp4Stream) { 01446 mp4Stream->getUsageCounter()->decrease(); 01447 delete mp4Stream; 01448 mp4Stream=NULL; 01449 delMp4Stream=false; 01450 } 01451 if(origSrc) 01452 origSrc->getUsageCounter()->decrease(); 01453 origSrc=NULL; 01454 insertMp4StreamIntoCM=false; 01455 if(suggestedAdaptor) 01456 delete suggestedAdaptor; 01457 suggestedAdaptor=NULL; 01458 } 01459 else { 01460 prxStat.bytesHit+=mp4Stream->getFileSize(); 01461 prxStat.bytesRequested+=mp4Stream->getFileSize(); 01462 prxStat.objHits++; 01463 prxStat.qualHits++; 01464 } 01465 } 01466 if(!mp4Stream) 01467 prxStat.objMiss++; 01468 if(suggestedAdaptor && mp4Stream) 01469 suggestedAdaptor->setESInfo(mp4Stream->getFirstVisualES()); 01470 };

bool ProxySession::tearDown int  sessionKey,
bool  immediate = false,
const Url fileName = NULL,
const char *  remaining = NULL
[virtual]
 

teardowns the session specified with sessionKey (if no fileName and no reminaing is specified.

Otherwise remaining will be parsed for the sessionkey, and the first param is ignored

Implements Session.

Definition at line 1124 of file ProxySession.cpp.

References ReferenceCounter::decrease(), RTSP::generateOk(), RTSP::generateSessionNotFound(), RTSP::getBuffer(), ESInfo::getFrameStatistic(), ESInfo::getInput(), DataSink::getOutput(), BitField::getPercentageSetBits(), ESInfo::getUsageCounter(), RTSP::incSeqNr(), and ESInfo::setCompleteState().

01125 { 01126 dprintf_full("ProxySession::tearDown(%i, %i)\r\n",sessionId,immediate); 01127 if(fileName && remaining) { 01128 sessionId=RTSP::extractSessionId(remaining); 01129 } 01130 // serverSession->tearDown(sessionId,immediate,fileName,remaining); 01131 if( ((u32)sessionId)==TEARDOWN_ALL) { 01132 // teardown all 01133 state = SESSION_CLOSED; 01134 list < DataChannel * >::iterator dcI; 01135 while (!channels.empty()) { 01136 dcI=channels.begin(); 01137 // pause the caching client 01138 (*dcI)->pause(0); 01139 DataSink* ds=(*dcI)->getDataSink(0); 01140 if(ds) { 01141 IO* dsOut=ds->getOutput(); 01142 if(dsOut) { 01143 ESInfo* es=(ESInfo*) (*dcI)->getESInfo(); 01144 01145 float completeStatePercent=es->getFrameStatistic()->getPercentageSetBits(); //expensive 01146 if(completeStatePercent>0.75) { 01147 es->setCompleteState(true); 01148 dprintf_full("ProxySession::teardown: stream %s is complete with %f%%\r\n",es->getInput(),completeStatePercent); 01149 } 01150 dprintf_full("ProxySession::teardown: stream %s is cached with %f%%\r\n",es->getInput(),completeStatePercent); 01151 es->getUsageCounter()->decrease(); 01152 } 01153 } 01154 (*dcI)->teardown(clientId,immediate); 01155 // check if we have to delete it, might be shared with other sessions 01156 if((*dcI)->getNumberOfActiveDataSinks()==0) { 01157 (*dcI)->wait(); // wait for thread to finish 01158 delete (*dcI); // decrease RefCounter 01159 } 01160 channels.pop_front(); 01161 } 01162 // generate reply cmd 01163 prot->generateOk(); 01164 strcpy(buffer,prot->getBuffer()); 01165 prot->incSeqNr(); 01166 return true; 01167 } 01168 else { 01169 // teardown one session 01170 list < DataChannel * >::iterator dcI; 01171 if (!channels.empty()) { 01172 dcI = channels.begin(); 01173 while (dcI != channels.end()) { 01174 if ((*dcI)->getSessionId()== (unsigned)sessionId) { 01175 (*dcI)->pause(0); 01176 DataSink* ds=(*dcI)->getDataSink(0); 01177 if(ds) { 01178 IO* dsOut=ds->getOutput(); 01179 if(dsOut) { 01180 ESInfo* es=(ESInfo*) (*dcI)->getESInfo(); 01181 01182 float completeStatePercent=es->getFrameStatistic()->getPercentageSetBits(); //expensive 01183 if(completeStatePercent>0.75) { 01184 es->setCompleteState(true); 01185 dprintf_full("ProxySession::teardown: stream %s is complete with %f%%\r\n",es->getInput(),completeStatePercent); 01186 } 01187 dprintf_full("ProxySession::teardown: stream %s is cached with %f%%\r\n",es->getInput(),completeStatePercent); 01188 es->getUsageCounter()->decrease(); 01189 } 01190 } 01191 (*dcI)->teardown(clientId,immediate); 01192 // check if we have to delete it, might be shared with other sessions 01193 if((*dcI)->getNumberOfActiveDataSinks()==0) { 01194 (*dcI)->wait(); // wait for thread to finish 01195 delete (*dcI); 01196 } 01197 channels.erase(dcI); 01198 if(channels.empty()) 01199 state = SESSION_CLOSED; 01200 prot->generateOk(); 01201 strcpy(buffer,prot->getBuffer()); 01202 prot->incSeqNr(); 01203 return true; 01204 } 01205 else { 01206 ++dcI; 01207 } 01208 } 01209 } 01210 01211 } 01212 // session was not found 01213 prot->generateSessionNotFound(); 01214 dprintf_small("ProxySession::teardown: session %i not found\n",sessionId); 01215 strcpy(buffer,prot->getBuffer()); 01216 prot->incSeqNr(); 01217 return false; 01218 };


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