Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members
RTSP.hpp
00001 00002 /*********************************************************************** 00003 * * 00004 * ViTooKi * 00005 * * 00006 * title: RTSP.hpp * 00007 * * 00008 * * 00009 * * 00010 * ITEC institute of the University of Klagenfurt (Austria) * 00011 * http://www.itec.uni-klu.ac.at * 00012 * * 00013 * * 00014 * For more information visit the ViTooKi homepage: * 00015 * http://ViTooKi.sourceforge.net * 00016 * vitooki-user@lists.sourceforge.net * 00017 * vitooki-devel@lists.sourceforge.net * 00018 * * 00019 * This file is part of ViTooKi, a free video toolkit. * 00020 * ViTooKi is free software; you can redistribute it and/or * 00021 * modify it under the terms of the GNU General Public License * 00022 * as published by the Free Software Foundation; either version 2 * 00023 * of the License, or (at your option) any later version. * 00024 * * 00025 * This program is distributed in the hope that it will be useful, * 00026 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00027 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00028 * GNU General Public License for more details. * 00029 * * 00030 * You should have received a copy of the GNU General Public License * 00031 * along with this program; if not, write to the Free Software * 00032 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * 00033 * MA 02111-1307, USA. * 00034 * * 00035 ***********************************************************************/ 00036 00037 /*********************************************************************** 00038 * * 00039 * REVISION HISTORY: * 00040 * * 00041 * * 00042 * * 00043 ***********************************************************************/ 00044 00045 #ifndef _PS_PROXY_RTSP 00046 #define _PS_PROXY_RTSP 00047 #include "Session.hpp" 00048 #include "Protocol.hpp" 00049 #include "../metadata/TerminalCapabilities.hpp" 00050 #include "../metadata/UserPreferences.hpp" 00051 00052 #define INVALID_SESSIONID 0xFFFFFFFF 00053 00054 #ifndef TEARDOWN_ALL 00055 #define TEARDOWN_ALL INVALID_SESSIONID 00056 #endif 00057 00058 class ContainerInfo; 00059 struct rtx_group; 00060 struct rtx_info; 00061 class ESInfo; 00062 class Url; 00063 00075 class RTSP:public Protocol { 00076 00077 public: 00078 RTSP(); 00079 00080 virtual ~RTSP() {}; 00081 00082 bool applyReqToSession(const char *req, u32 bytesRead, Session * ses); 00084 bool applyReqToSession(const char *req, u32 bytesRead, Session * ses, bool optionsCallback); 00085 00089 ContainerInfo * parseResponseDescribe(const char *response, const char *url, char** serverName, 00090 list<rtx_group*> *groups=NULL); 00091 00097 int parseResponseSetup(const char* buffer, int *sessionID, int *clientPort, 00098 int *serverPort,bool *unicast, char** ssrc, 00099 rtx_info* info=NULL); 00100 void generateDescribeForUrl(const char* url, const char* playerId, const TerminalCapabilities* tc=NULL,const UserPreferences* up=NULL); 00104 void generateSetup(const char* url, int trackId, int clientPort,bool unicast,u32 rtxPort=0,int sessionId=-1); 00105 void generatePlay(const char* url, u32 session, double startTime, double nptEnd,double maxPrefetch); 00106 void generatePause(const char* url, u32 session); 00107 void generateTeardown(const char* url, u32 session); 00108 #ifndef WINCE 00109 00114 void generateRedirect(const char* url, const char* newUrl, const time_t* redirectAllowedAtTimePoint=NULL); 00115 #endif 00116 void generateFileNotFound(); 00117 void generateOk(); 00118 void generateSessionNotFound(); 00119 void generateInternalServerError(); 00120 void generateDestUnreachable(); 00121 void generateNotImplemented(); 00122 void generateBadCMD(); 00123 void generateIllegalTransport(); 00124 void generateNotEnoughBandwidth(); 00125 void generateInvalidParameter(const int numParams, const char* const * const param); 00126 void generateSetParameter(const char* url, u32 session, 00127 std::map<char*, char*, struct stringCompare>* params); 00128 void generateGetParameter(const char* url, const u32 session, 00129 const int numParams, const char** params); 00130 00136 void parseGetParameter(const char* req, u32* session,int* numParams, char*** params); 00141 void parseSetParameter(const char* req, u32* session,std::map<char*, char*, struct stringCompare>* params); 00142 bool parseCMDDescribe(Session * ses, const Url *fileName, 00143 const char *remaining, char** playerId); 00144 bool parseCMDSetup(Session * ses, const Url *fileName, 00145 const char * const remaining, bool* hasSessionKey, int* sesKey, 00146 char** protocols, char** unicast,int* esId,int* rPort, int* rPort2, 00147 bool* hasRtxPort, u32* clientRtxPort, char **clientAddress = NULL); 00148 bool parseCMDPlay(Session * ses, const Url *filename, 00149 const char *remaining, int* sessionId, double* startTime, 00150 double* endTime, double* maxPrefetch); 00151 #ifndef WINCE 00152 00155 void parseCMDRedirect(Session* ses, const Url *fileName, const char* remaining, 00156 char** newUrl, time_t* redirectAllowedAtTimePoint); 00157 #endif 00158 void generateResponseGetParameter(std::map<char*, char*, struct stringCompare>* params); 00159 bool generateCMDDescribeReply(Session * ses, const Url *fileName, 00160 const char *sourceServerName, const char* playerId); 00161 bool generateSetupReply(Session * ses, const Url *fileName, 00162 const int sesKey, const char* protocols, const char* unicast, const char* sourceAddress, 00163 const int esId, const int rPort, const int rPort2, const int lport, 00164 const u32 clientRtxPort, const u32 serverRtxPort); 00165 void generateCMDnotSupportedReply(); 00166 void generateCMDOptionsReply(); 00167 00168 00169 void incSeqNr() { seqNr++;}; 00170 void decSeqNr() { if(seqNr>1) seqNr--; }; 00171 static bool isSupportedTransport(const char* protocols); 00172 static bool isCmdOk(const char* buf); 00173 00174 int getLastStatus() const { return lastStatus;}; 00175 const char* getBuffer() const { return buffer;}; 00176 int getDefaultPort() const { return 554;}; 00177 /* parses @param buffer for a sessionid returns INVALID_SESSIONID 00178 * if none is found 00179 */ 00180 static u32 extractSessionId(const char* buffer); 00181 /* searches for the sessionId in @param buffer 00182 * if none is found @param return is NULL, otherwise a new string 00183 * is created with the new sessionid 00184 */ 00185 static char* replaceSessionIdWith(u32 newId,const char* buffer); 00186 static void doTest(); 00187 static void freeMapMemory(std::map<char*,char*,struct stringCompare>* params); 00188 00189 int generateSessionKey(); 00191 int extractSessionKeyFromCMD(const char* remaining); 00193 int getSeqNr() { return seqNr; }; 00194 00195 00197 //int generateCMDTeardown(Session * ses, const Url *filename, const char *remaining); 00198 // void handleCMDPause(Session * ses, const Url *filename, const char *remaining); 00199 00200 00201 protected: 00202 enum MSG_Type 00203 { MSG_DESCRIBE, MSG_SETUP, MSG_PLAY, MSG_PAUSE, MSG_OPTIONS, 00204 MSG_TEARDOWN, GET_PARAMETER, SET_PARAMETER, MSG_REDIRECT, MSG_UNKNOWN 00205 }; 00206 00207 int seqNr; 00208 int lastStatus; 00209 00210 char buffer[MSG_BUFFER_SIZE]; 00211 static const char *const allowedCommands; 00212 static const int SL_PAYLOAD_TYPE; 00213 static const int TTL; 00214 00215 bool optionsCallback; //should options-callback be used? 00216 00217 00218 private: 00219 ESInfo* parseSDPMediaBlock( const char* mediaStart, 00220 const char* mediaEnd, 00221 const double durSeconds, 00222 ContainerInfo * mp4Info, 00223 list<rtx_group*> *groups=NULL); 00224 void parseSDP_RTXBlock(const char* media, 00225 const char* endOfMedia, 00226 list<rtx_group*> *groups); 00227 00228 bool parseRequest(const char *request, int len, MSG_Type * msgtype, 00229 Url **filename, int *cseq, const char **remaining); 00230 00231 bool handleSingleRequest(Session * ses, const char *buffer, int bytesRead); 00232 }; 00233 00234 #endif