ServerSession Class Reference

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

#include <ServerSession.hpp>

Inheritance diagram for ServerSession:

Session VThread List of all members.

Public Member Functions

 ServerSession (int socket, const struct sockaddr_in *client, CacheManager *cm, AdmissionControl *am, bool enableRtx, SessionCounter *counter=NULL, TerminalCapabilities *tc=NULL)
 socket: the raw socket for initializing the session control channel.
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.
bool getOptions (const Url *fileName, const char *remaining)
bool setOptions (const Url *fileName, const char *remaining)
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

bool startDCs (int sessionId, double startTime, double endTime, double prefetch, bool backwardsClosestIFrame)

Protected Attributes

char buffer [MSG_BUFFER_SIZE]
 sets output at the client
CacheManagercm
char * localAddress
char * playerId
std::map< u32, std::map< char *,
char *, struct stringCompare > *,
struct intCompare > 
params
 stores to an session id a map of params
AdmissionControl * admControl
bool enableRtx
SessionCounter * counter

Detailed Description

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

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

Definition at line 86 of file ServerSession.hpp.


Constructor & Destructor Documentation

ServerSession::ServerSession int  socket,
const struct sockaddr_in *  client,
CacheManager cm,
AdmissionControl *  am,
bool  enableRtx,
SessionCounter *  counter = NULL,
TerminalCapabilities tc = NULL
 

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

the client info is deep-copied Definition at line 70 of file ServerSession.cpp.

00072 :Session(),enableRtx(enableRTX) 00073 { 00074 assert(c); 00075 assert(am); 00076 this->counter = counter; 00077 termCap=tc; 00078 admControl=am; 00079 state = SESSION_CLOSED; 00080 cm = c; 00081 if (clint) { 00082 client = new sockaddr_in(); 00083 memcpy(client, clint, sizeof(sockaddr_in)); 00084 clientId=(u32)client->sin_addr.s_addr; 00085 } else { 00086 client = NULL; 00087 clientId=0; 00088 } 00089 00090 sessionControlChannel=socket; 00091 sockaddr_in localaddr; 00092 canAdmitRequest=true; 00093 00094 #ifdef WIN32 00095 int slen = sizeof(localaddr); 00096 #else /* */ 00097 socklen_t slen = sizeof(localaddr); 00098 #endif /* */ 00099 00100 memset(&localaddr, 0, sizeof(localaddr)); 00101 getsockname(socket, (sockaddr *) & localaddr, &slen); 00102 const char* tmp=inet_ntoa(localaddr.sin_addr); 00103 localAddress=new char[strlen(tmp)+1]; 00104 strcpy(localAddress,tmp); 00105 prot = NULL; 00106 url = NULL; 00107 00108 userPref=NULL; 00109 suggestedAdaptor=NULL; 00110 // clientObj=NULL; 00111 mp4Stream=NULL; 00112 playerId=NULL; 00113 serverID=NULL; 00114 00115 gtRefCount = new ReferenceCounter(); 00116 globalTimer = new GlobalTimer(); 00117 //this will prevent deletion on DataChannel closes: 00118 gtSharedAdapt = new SharedAdaptor(gtRefCount, (Adaptor*&)globalTimer); 00119 resUsage.cpu=resUsage.disk=resUsage.network=0.0; 00120 }


Member Function Documentation

void ServerSession::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 870 of file ServerSession.cpp.

References ContainerInfo::clone(), CacheManager::findMetaObject(), MetaObject::findMp4Stream(), TerminalCapabilities::getColorDisplay(), TerminalCapabilities::getDisplayHeight(), TerminalCapabilities::getDisplayRefreshRate(), TerminalCapabilities::getDisplayWidth(), Url::getFileName(), ContainerInfo::getFirstVisualES(), TerminalCapabilities::getMaxDecoderBitRateInBit(), TerminalCapabilities::getNetworkCapacityInByte(), CacheManager::getVideo(), and Url::toString().

00871 { 00872 bool insertResUsage=false; 00873 if (cm && uri) { 00874 if (url) { 00875 delete url; 00876 } 00877 dprintf_full("ServerSession::setUrl: %s \r\n", uri->toString()); 00878 //if (url->getFileName() == NULL) 00879 // dprintf_full("ServerSession::setUrl: file NULL!!!\n"); 00880 00881 dprintf_full("ServerSession::setUrl: %s filename: %s\r\n", uri->toString(), uri->getFileName()); 00882 url = new Url(uri->toString()); 00883 bool exactMatch; 00884 MetaObject *meta = cm->findMetaObject(url); 00885 if (meta != NULL) { 00886 dprintf_full("ServerSession::setUrl metadata found\n"); 00887 } else { 00888 dprintf_full("ServerSession::setUrl metadata NOT found\n"); 00889 } 00890 00891 dprintf_full("ServerSession::setUrl termcap: %p, userpref %p meta: %p\n", termCap, userPref, meta); 00892 00893 if( (!termCap && !userPref)) { 00894 // just send ANY version 00895 dprintf_full("ServerSession::setUrl NO metaobject/metadata found!\n"); 00896 mp4Stream = cm->getVideo(url); 00897 if (mp4Stream == NULL) { 00898 fprintf(stderr,"\nERROR: demuxed stream not found or maybe you are starting the server from a different computer (hostname/IP) now? DELETE demux directory!\n"); 00899 //::exit(1); 00900 return; 00901 } 00902 00903 mp4Stream=mp4Stream->clone(); // CM returns the orig video, we don't want it in server 00904 // calc resUsage 00905 VideoESInfo* vis=mp4Stream->getFirstVisualES(); 00906 if(vis) { 00907 00908 dprintf_full("ServerSession::setUrl VIS found\n"); 00909 Feature src(vis); 00910 src.isCached=true; 00911 ResourceUsage* tmpRU=CostFunction::calcResourceUsage(&src,&src,admControl->getResourceLimit()); 00912 if(tmpRU) { 00913 resUsage.network=tmpRU->network; 00914 resUsage.disk=tmpRU->disk; 00915 resUsage.cpu=tmpRU->cpu; 00916 delete tmpRU; 00917 insertResUsage=true; 00918 } 00919 } 00920 } 00921 00922 else if(meta && userPref) { 00923 // FIXME: hardcode delay values to 100ms 00924 dprintf_full("ServerSession::setUrl meta && userPref\n"); 00925 suggestedAdaptor=admControl->makeBestMatch(userPref,100,meta,&mp4Stream,&resUsage); 00926 00927 if(mp4Stream) 00928 mp4Stream=mp4Stream->clone(); 00929 } 00930 else if(meta && termCap ) 00931 { //use MetaObject for best match 00932 // bandwidth should be the minimum of network and decodeBandwidth 00933 // if one of them is zero, ignore the zero param 00934 dprintf_full("ServerSession::setUrl meta && termCap\n"); 00935 u32 bandwidth=termCap->getNetworkCapacityInByte()*8; 00936 if(bandwidth==0) 00937 bandwidth=termCap->getMaxDecoderBitRateInBit(); 00938 else if(termCap->getMaxDecoderBitRateInBit() && 00939 termCap->getMaxDecoderBitRateInBit() < bandwidth) { 00940 bandwidth=termCap->getMaxDecoderBitRateInBit(); 00941 } 00942 dprintf_full("ServerSession::setUrl: termCap->getColorDisplay()=%u\r\n",termCap->getColorDisplay()); 00943 mp4Stream=meta->findMp4Stream(0,termCap->getDisplayWidth(), 0,termCap->getDisplayHeight(), 0,bandwidth, (termCap->getColorDisplay()==0), 00944 (float)termCap->getDisplayRefreshRate(), &exactMatch); 00945 if(mp4Stream) 00946 mp4Stream=mp4Stream->clone(); 00947 if(makeExactMatch && !exactMatch) { 00948 suggestedAdaptor=admControl->makeExactMatch(termCap->getDisplayWidth(), 00949 termCap->getDisplayHeight(), 00950 bandwidth, 00951 (termCap->getColorDisplay()==0), 00952 (float)termCap->getDisplayRefreshRate(), 00953 mp4Stream,&resUsage); 00954 } 00955 else 00956 { 00957 // calc the resource usage for the non transcoding case 00958 if(mp4Stream) 00959 { 00960 VideoESInfo* vis=mp4Stream->getFirstVisualES(); 00961 if(vis) 00962 { 00963 Feature src(vis); 00964 src.isCached=true; 00965 ResourceUsage* tmpRU=CostFunction::calcResourceUsage(&src,&src,admControl->getResourceLimit()); 00966 if(tmpRU) 00967 { 00968 resUsage.network=tmpRU->network; 00969 resUsage.disk=tmpRU->disk; 00970 resUsage.cpu=tmpRU->cpu; 00971 delete tmpRU; 00972 insertResUsage=true; 00973 } 00974 } 00975 } 00976 00977 00978 } 00979 00980 } 00981 #ifndef WINCE 00982 else if(termCap && ((strcmp(uri->getFileName(), "v4l")) ==0)) 00983 { 00984 dprintf_full("ServerSession::setUrl v4l && termCap &&\n"); 00985 u32 bandwidth=termCap->getNetworkCapacityInByte()*8; 00986 if(bandwidth==0) 00987 bandwidth=termCap->getMaxDecoderBitRateInBit(); 00988 else if(termCap->getMaxDecoderBitRateInBit() && termCap->getMaxDecoderBitRateInBit() < bandwidth) 00989 { 00990 bandwidth=termCap->getMaxDecoderBitRateInBit(); 00991 } 00992 dprintf_full("ServerSession::setUrl: v4l termCap->getColorDisplay()=%u\r\n", 00993 termCap->getColorDisplay()); 00994 00995 mp4Stream = Video4LinuxContainerFile::loadContainerInfo(); 00996 if(mp4Stream) 00997 { 00998 dprintf_full("ServerSession::setUrl: v4l mp4stream ok\n"); 00999 mp4Stream=mp4Stream->clone(); 01000 } 01001 else 01002 dprintf_full("ServerSession::setUrl: v4l mp4stream NULL!! \n"); 01003 if(makeExactMatch && !exactMatch) 01004 { 01005 suggestedAdaptor=admControl->makeExactMatch(termCap->getDisplayWidth(), termCap->getDisplayHeight(),bandwidth, (termCap->getColorDisplay()==0), (float)termCap->getDisplayRefreshRate(),mp4Stream,&resUsage); 01006 } 01007 dprintf_full("ServerSession::setUrl: v4l OK\r\n"); 01008 01009 } 01010 #endif 01011 } 01012 01013 // now insert the resource usage for those other cases 01014 if(insertResUsage) 01015 { 01016 if(!userPref && !admControl->insertRequest(&resUsage)) 01017 { 01018 resUsage.cpu=resUsage.disk=resUsage.network=0.0; 01019 if(mp4Stream) 01020 delete mp4Stream; 01021 mp4Stream=NULL; 01022 if(suggestedAdaptor) 01023 delete suggestedAdaptor; 01024 suggestedAdaptor=NULL; 01025 } 01026 } 01027 };

bool ServerSession::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 533 of file ServerSession.cpp.

References buffer, RTSP::generateOk(), RTSP::generateSessionNotFound(), RTSP::getBuffer(), and RTSP::incSeqNr().

00534 { 00535 dprintf_full("ServerSession::tearDown(%i, %i)\r\n",sessionId,immediate); 00536 if(fileName && remaining) { 00537 sessionId=RTSP::extractSessionId(remaining); 00538 } 00539 if((u32)sessionId==TEARDOWN_ALL) { 00540 // teardown all 00541 state = SESSION_CLOSED; 00542 list < DataChannel * >::iterator dcI; 00543 while (!channels.empty()) { 00544 dcI=channels.begin(); 00545 (*dcI)->teardown(clientId,immediate); 00546 // check if we have to delete it, might be shared with other sessions 00547 if((*dcI)->getNumberOfActiveDataSinks()==0) { 00548 (*dcI)->wait(); // wait for thread to finish 00549 delete (*dcI); 00550 } 00551 channels.pop_front(); 00552 } 00553 if(prot) { // can happen that no prot is set when teardown called first 00554 prot->generateOk(); 00555 const char* buf=prot->getBuffer(); 00556 strcpy(buffer,buf); 00557 prot->incSeqNr(); 00558 return true; 00559 } 00560 else 00561 return false; 00562 } 00563 else { 00564 // teardown one session 00565 bool sesFound=false; 00566 list < DataChannel * >::iterator dcI; 00567 if (!channels.empty()) { 00568 dcI = channels.begin(); 00569 while (dcI != channels.end()) { 00570 if ((*dcI)->getSessionId()== (unsigned)sessionId) { 00571 sesFound=true; 00572 (*dcI)->teardown(clientId,immediate); 00573 // check if we have to delete it, might be shared with other sessions 00574 if((*dcI)->getNumberOfActiveDataSinks()==0) { 00575 (*dcI)->wait(); // wait for thread to finish 00576 delete (*dcI); 00577 } 00578 dcI = channels.erase(dcI); 00579 if(channels.empty()) { 00580 state = SESSION_CLOSED; 00581 prot->generateOk(); 00582 const char* buf=prot->getBuffer(); 00583 strcpy(buffer,buf); 00584 prot->incSeqNr(); 00585 return true; 00586 } 00587 } else 00588 ++dcI; 00589 } 00590 } 00591 if(sesFound) { 00592 prot->generateOk(); 00593 } 00594 else { 00595 prot->generateSessionNotFound(); 00596 } 00597 const char* buf=prot->getBuffer(); 00598 strcpy(buffer,buf); 00599 prot->incSeqNr(); 00600 return sesFound; 00601 } 00602 prot->generateSessionNotFound(); 00603 const char* buf=prot->getBuffer(); 00604 strcpy(buffer,buf); 00605 prot->incSeqNr(); 00606 return false; 00607 };


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