Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members
ProxySession.hpp
00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: ProxySession.hpp * 00006 * * 00007 * * 00008 * * 00009 * ITEC institute of the University of Klagenfurt (Austria) * 00010 * http://www.itec.uni-klu.ac.at * 00011 * * 00012 * * 00013 * For more information visit the ViTooKi homepage: * 00014 * http://ViTooKi.sourceforge.net * 00015 * vitooki-user@lists.sourceforge.net * 00016 * vitooki-devel@lists.sourceforge.net * 00017 * * 00018 * This file is part of ViTooKi, a free video toolkit. * 00019 * ViTooKi is free software; you can redistribute it and/or * 00020 * modify it under the terms of the GNU General Public License * 00021 * as published by the Free Software Foundation; either version 2 * 00022 * of the License, or (at your option) any later version. * 00023 * * 00024 * This program is distributed in the hope that it will be useful, * 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00027 * GNU General Public License for more details. * 00028 * * 00029 * You should have received a copy of the GNU General Public License * 00030 * along with this program; if not, write to the Free Software * 00031 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * 00032 * MA 02111-1307, USA. * 00033 * * 00034 ***********************************************************************/ 00035 00036 /*********************************************************************** 00037 * * 00038 * REVISION HISTORY: * 00039 * * 00040 * * 00041 * * 00042 ***********************************************************************/ 00043 00044 #ifndef _PS_PROXY_SESSION 00045 #define _PS_PROXY_SESSION 00046 #include "global.hpp" 00047 00048 #include "Session.hpp" 00049 #include "Protocol.hpp" 00050 #include "ContainerInfo.hpp" 00051 00052 #ifdef ISOMP4 00053 #include "ISOMovies.h" 00054 #endif 00055 00056 struct rtx_group; 00057 class DataChannel; 00058 class DataSink; 00059 class IO; 00060 class Url; 00061 class ServerSession; 00062 class RTSP; 00063 class AdmissionControl; 00064 class CacheManager; 00065 #ifdef WIN32 00066 //#include <winsock.h> 00067 #else 00068 00069 #include <unistd.h> 00070 #include <time.h> 00071 #include <sys/time.h> 00072 #include <sys/socket.h> 00073 #include <netdb.h> 00074 #include <netinet/in.h> 00075 #include <unistd.h> 00076 #endif 00077 #include "../metadata/TerminalCapabilities.hpp" 00078 #include "PortGenerator.hpp" 00079 #include "../SessionCounter.hpp" 00080 typedef struct ProxyStatistics{ 00081 u32 insertsIntoCM; 00082 u32 requests; 00083 u32 endedRequests; 00084 u32 qualHits; 00085 u32 rejected; //due to AC 00086 u32 rejectedDueToSize; 00087 u32 rejectedDueToLocking; 00088 u32 rejectedDueToErr; 00089 u32 deletedDueToLowQuality; 00090 u32 objHits; 00091 u32 objMiss; 00092 u64 bytesRequested; 00093 u64 bytesHit; 00094 ProxyStatistics() { 00095 insertsIntoCM=requests=qualHits=deletedDueToLowQuality= 00096 objHits=rejected=rejectedDueToLocking=rejectedDueToSize=0; 00097 bytesRequested=bytesHit=0; 00098 objMiss=rejectedDueToErr=endedRequests=0; 00099 }; 00100 void saveStatisticTo(FILE* fp) { 00101 if(fp) { 00102 fprintf(fp,"Requests: %u\nFinished Requests: %u\nInserts into CM: %u\n" 00103 "QualHits: %u\n ObjHits: %u\n ObjMiss: %u\n" 00104 "Rejected due to AdmissionControl: %u\n" 00105 "Rejected due to Locking: %u\n" 00106 "Rejected due to Size: %u\n" 00107 "Rejected due to other errors: %u\n" 00108 "Deleted due to low Quality: %u\n" 00109 "BytesReq(KB): %u\nBytesHit(KB): %u\n", 00110 requests,endedRequests,insertsIntoCM, 00111 qualHits,objHits,objMiss, 00112 rejected, 00113 rejectedDueToLocking, 00114 rejectedDueToSize,rejectedDueToErr, 00115 deletedDueToLowQuality, 00116 (u32)(bytesRequested/1024),(u32)(bytesHit/1024)); 00117 } 00118 }; 00119 } ProxyStatistics; 00120 00121 extern ProxyStatistics prxStat; 00122 00135 class ProxySession:public Session { 00136 00137 public: 00138 00139 00146 ProxySession(int socket, const struct sockaddr_in *client, CacheManager * cm, 00147 AdmissionControl* adm, bool allowRTX,SessionCounter* counter=NULL,TerminalCapabilities* defTC=NULL); 00148 00149 ~ProxySession(); 00150 00151 bool getOptions(const Url* fileName, const char* remaining) { dprintf_err("Proxy:getOptions not implemented"); return true;}; 00152 00153 bool setOptions(const Url* fileName, const char* remaining) { dprintf_err("Proxy:setOptions not implemented");return true;}; 00154 00155 bool options(const Url* fileName, const char* remaining); 00156 00157 bool connect(const Url* fileName, const char* remaining); 00158 00159 bool setup(const Url* fileName, const char* remaining); 00160 00161 bool play(const Url* fileName, const char* remaining); 00162 00163 bool pause(const Url* fileName, const char* remaining); 00164 00165 bool tearDown(int sessionKey, bool immediate=false, const Url* fileName=NULL, const char* remaining=NULL); 00166 00167 void run(); 00168 00171 void setUrl(const Url *uri, bool makeExactMatch = true); 00172 00173 SessionState getState() const { 00174 return state; 00175 }; 00176 00178 // void setOutput(IO * out); 00179 00180 protected: 00181 int readData(char* buffer,int numBytes); 00182 ServerSession* serverSession; 00183 /* stores pairs of integers. 00184 The first one is the sessionid from the proxy to the client. 00185 The 2nd form the server to the proxy */ 00186 std::map<u32,u32,struct intCompare> sessionTranslator; 00187 CacheManager *cm; 00188 char buffer[MSG_BUFFER_SIZE + 1]; 00189 char bufferBackup[MSG_BUFFER_SIZE + 1]; 00190 struct sockaddr_in* server; 00191 00192 bool rtxEnabledToServer; 00193 bool rtxEnabledToClient; 00195 bool rtxEnabled; 00197 bool delMp4Stream; 00198 char* playerId; 00199 list < rtx_info* > rtxInfoServer; 00203 bool insertMp4StreamIntoCM; 00204 00208 bool dualMiss; 00209 bool dontCacheDualMiss; 00210 bool noDescribeSeenYet; 00211 SessionCounter* counter; 00212 private: 00213 bool establishConnectionToServer(); 00214 bool handleConnectHit(const Url* fileName); 00215 bool handleConnectMiss(const Url* fileName); 00216 DataSink* handleSetupHit(const Url* fileName, int esId, 00217 int remoteClientPort, int remoteUpperClientPort, 00218 int remoteClientRtxPort, int sessionId,const char* protocol, const char* unicast); 00219 IO* handleSetupMiss(const Url* fileName, int esId, int* sessionId); 00220 void detectRtxCapabilities(); 00221 bool videoFullyCached(ContainerInfo* stream) const; 00222 bool esFullyCached(const ESInfo* es) const; 00223 AdmissionControl* admControl; 00224 00225 00230 ContainerInfo* origSrc; 00231 bool neverForwardMetaData; 00233 u32 origSrcReserved; 00235 u32 mp4StreamReserved; 00236 }; 00237 00238 #endif