00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _RTSP_CLIENT_HH
00022 #define _RTSP_CLIENT_HH
00023
00024 #ifndef _MEDIA_SESSION_HH
00025 #include "MediaSession.hh"
00026 #endif
00027 #ifndef _NET_ADDRESS_HH
00028 #include "NetAddress.hh"
00029 #endif
00030 #ifndef _DIGEST_AUTHENTICATION_HH
00031 #include "DigestAuthentication.hh"
00032 #endif
00033
00034 #define RTSPCLIENT_SYNCHRONOUS_INTERFACE 1 // For now, continue to support the old synchronous interface as well
00035
00036 class RTSPClient: public Medium {
00037 public:
00038 static RTSPClient* createNew(UsageEnvironment& env, char const* rtspURL,
00039 int verbosityLevel = 0,
00040 char const* applicationName = NULL,
00041 portNumBits tunnelOverHTTPPortNum = 0);
00042
00043
00044
00045
00046 typedef void (responseHandler)(RTSPClient* rtspClient,
00047 int resultCode, char* resultString);
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 unsigned sendDescribeCommand(responseHandler* responseHandler, Authenticator* authenticator = NULL);
00065
00066
00067
00068
00069
00070
00071
00072 unsigned sendOptionsCommand(responseHandler* responseHandler, Authenticator* authenticator = NULL);
00073
00074
00075
00076 unsigned sendAnnounceCommand(char const* sdpDescription, responseHandler* responseHandler, Authenticator* authenticator = NULL);
00077
00078
00079
00080
00081 unsigned sendSetupCommand(MediaSubsession& subsession, responseHandler* responseHandler,
00082 Boolean streamOutgoing = False,
00083 Boolean streamUsingTCP = False,
00084 Boolean forceMulticastOnUnspecified = False,
00085 Authenticator* authenticator = NULL);
00086
00087
00088
00089 unsigned sendPlayCommand(MediaSession& session, responseHandler* responseHandler,
00090 double start = 0.0f, double end = -1.0f, float scale = 1.0f,
00091 Authenticator* authenticator = NULL);
00092
00093
00094
00095 unsigned sendPlayCommand(MediaSubsession& subsession, responseHandler* responseHandler,
00096 double start = 0.0f, double end = -1.0f, float scale = 1.0f,
00097 Authenticator* authenticator = NULL);
00098
00099
00100
00101
00102 unsigned sendPauseCommand(MediaSession& session, responseHandler* responseHandler, Authenticator* authenticator = NULL);
00103
00104
00105 unsigned sendPauseCommand(MediaSubsession& subsession, responseHandler* responseHandler, Authenticator* authenticator = NULL);
00106
00107
00108
00109 unsigned sendRecordCommand(MediaSession& session, responseHandler* responseHandler, Authenticator* authenticator = NULL);
00110
00111
00112 unsigned sendRecordCommand(MediaSubsession& subsession, responseHandler* responseHandler, Authenticator* authenticator = NULL);
00113
00114
00115
00116 unsigned sendTeardownCommand(MediaSession& session, responseHandler* responseHandler, Authenticator* authenticator = NULL);
00117
00118
00119 unsigned sendTeardownCommand(MediaSubsession& subsession, responseHandler* responseHandler, Authenticator* authenticator = NULL);
00120
00121
00122
00123 unsigned sendSetParameterCommand(MediaSession& session, responseHandler* responseHandler,
00124 char const* parameterName, char const* parameterValue,
00125 Authenticator* authenticator = NULL);
00126
00127
00128
00129 unsigned sendGetParameterCommand(MediaSession& session, responseHandler* responseHandler, char const* parameterName,
00130 Authenticator* authenticator = NULL);
00131
00132
00133
00134 Boolean changeResponseHandler(unsigned cseq, responseHandler* newResponseHandler);
00135
00136
00137
00138
00139
00140 int socketNum() const { return fInputSocketNum; }
00141
00142 static Boolean lookupByName(UsageEnvironment& env,
00143 char const* sourceName,
00144 RTSPClient*& resultClient);
00145
00146 static Boolean parseRTSPURL(UsageEnvironment& env, char const* url,
00147 char*& username, char*& password, NetAddress& address, portNumBits& portNum, char const** urlSuffix = NULL);
00148
00149
00150
00151 void setUserAgentString(char const* userAgentName);
00152
00153
00154 unsigned sessionTimeoutParameter() const { return fSessionTimeoutParameter; }
00155
00156 char const* url() const { return fBaseURL; }
00157
00158 static unsigned responseBufferSize;
00159
00160 protected:
00161 RTSPClient(UsageEnvironment& env, char const* rtspURL,
00162 int verbosityLevel, char const* applicationName, portNumBits tunnelOverHTTPPortNum);
00163
00164 virtual ~RTSPClient();
00165
00166 void setBaseURL(char const* url);
00167
00168 private:
00169 virtual Boolean isRTSPClient() const;
00170
00171 public:
00172
00173 class RequestRecord {
00174 public:
00175 RequestRecord(unsigned cseq, char const* commandName, responseHandler* handler,
00176 MediaSession* session = NULL, MediaSubsession* subsession = NULL, u_int32_t booleanFlags = 0,
00177 double start = 0.0f, double end = -1.0f, float scale = 1.0f, char const* contentStr = NULL);
00178 virtual ~RequestRecord();
00179
00180 RequestRecord*& next() { return fNext; }
00181 unsigned& cseq() { return fCSeq; }
00182 char const* commandName() const { return fCommandName; }
00183 MediaSession* session() const { return fSession; }
00184 MediaSubsession* subsession() const { return fSubsession; }
00185 u_int32_t booleanFlags() const { return fBooleanFlags; }
00186 double start() const { return fStart; }
00187 double end() const { return fEnd; }
00188 float scale() const { return fScale; }
00189 char* contentStr() const { return fContentStr; }
00190 responseHandler*& handler() { return fHandler; }
00191
00192 private:
00193 RequestRecord* fNext;
00194 unsigned fCSeq;
00195 char const* fCommandName;
00196 MediaSession* fSession;
00197 MediaSubsession* fSubsession;
00198 u_int32_t fBooleanFlags;
00199 double fStart, fEnd;
00200 float fScale;
00201 char* fContentStr;
00202 responseHandler* fHandler;
00203 };
00204 private:
00205 class RequestQueue {
00206 public:
00207 RequestQueue();
00208 virtual ~RequestQueue();
00209
00210 void enqueue(RequestRecord* request);
00211 RequestRecord* dequeue();
00212 void putAtHead(RequestRecord* request);
00213 RequestRecord* findByCSeq(unsigned cseq);
00214 Boolean isEmpty() const { return fHead == NULL; }
00215
00216 private:
00217 RequestRecord* fHead;
00218 RequestRecord* fTail;
00219 };
00220
00221 void reset();
00222 void resetTCPSockets();
00223 void resetResponseBuffer();
00224 int openConnection();
00225 int connectToServer(int socketNum, portNumBits remotePortNum);
00226 char* createAuthenticatorString(char const* cmd, char const* url);
00227 unsigned sendRequest(RequestRecord* request);
00228 void handleRequestError(RequestRecord* request);
00229 Boolean parseResponseCode(char const* line, unsigned& responseCode, char const*& responseString);
00230 void handleIncomingRequest();
00231 static Boolean checkForHeader(char const* line, char const* headerName, unsigned headerNameLength, char const*& headerParams);
00232 Boolean parseTransportParams(char const* paramsStr,
00233 char*& serverAddressStr, portNumBits& serverPortNum,
00234 unsigned char& rtpChannelId, unsigned char& rtcpChannelId);
00235 Boolean parseScaleParam(char const* paramStr, float& scale);
00236 Boolean parseRTPInfoParams(char const*& paramStr, u_int16_t& seqNum, u_int32_t& timestamp);
00237 Boolean handleSETUPResponse(MediaSubsession& subsession, char const* sessionParamsStr, char const* transportParamsStr,
00238 Boolean streamUsingTCP);
00239 Boolean handlePLAYResponse(MediaSession& session, MediaSubsession& subsession,
00240 char const* scaleParamsStr, char const* rangeParamsStr, char const* rtpInfoParamsStr);
00241 Boolean handleTEARDOWNResponse(MediaSession& session, MediaSubsession& subsession);
00242 Boolean handleGET_PARAMETERResponse(char const* parameterName, char*& resultValueString);
00243 Boolean handleAuthenticationFailure(char const* wwwAuthenticateParamsStr);
00244 Boolean resendCommand(RequestRecord* request);
00245 char const* sessionURL(MediaSession const& session) const;
00246 static void handleAlternativeRequestByte(void*, u_int8_t requestByte);
00247 void handleAlternativeRequestByte1(u_int8_t requestByte);
00248 void constructSubsessionURL(MediaSubsession const& subsession,
00249 char const*& prefix,
00250 char const*& separator,
00251 char const*& suffix);
00252
00253
00254 Boolean setupHTTPTunneling1();
00255 static void responseHandlerForHTTP_GET(RTSPClient* rtspClient, int responseCode, char* responseString);
00256 void responseHandlerForHTTP_GET1(int responseCode, char* responseString);
00257 Boolean setupHTTPTunneling2();
00258
00259
00260 static void connectionHandler(void*, int );
00261 void connectionHandler1();
00262
00263
00264 static void incomingDataHandler(void*, int );
00265 void incomingDataHandler1();
00266 void handleResponseBytes(int newBytesRead);
00267
00268 private:
00269 int fVerbosityLevel;
00270 portNumBits fTunnelOverHTTPPortNum;
00271 char* fUserAgentHeaderStr;
00272 unsigned fUserAgentHeaderStrLen;
00273 int fInputSocketNum, fOutputSocketNum;
00274 netAddressBits fServerAddress;
00275 unsigned fCSeq;
00276 char* fBaseURL;
00277 Authenticator fCurrentAuthenticator;
00278 unsigned char fTCPStreamIdCount;
00279 char* fLastSessionId;
00280 unsigned fSessionTimeoutParameter;
00281 char* fResponseBuffer;
00282 unsigned fResponseBytesAlreadySeen, fResponseBufferBytesLeft;
00283 RequestQueue fRequestsAwaitingConnection, fRequestsAwaitingHTTPTunneling, fRequestsAwaitingResponse;
00284
00285
00286 char fSessionCookie[33];
00287 unsigned fSessionCookieCounter;
00288 Boolean fHTTPTunnelingConnectionIsPending;
00289
00290 #ifdef RTSPCLIENT_SYNCHRONOUS_INTERFACE
00291
00292
00293 public:
00294 static RTSPClient* createNew(UsageEnvironment& env,
00295 int verbosityLevel = 0,
00296 char const* applicationName = NULL,
00297 portNumBits tunnelOverHTTPPortNum = 0);
00298 char* describeURL(char const* url, Authenticator* authenticator = NULL,
00299 Boolean allowKasennaProtocol = False, int timeout = -1);
00300 char* describeWithPassword(char const* url,
00301 char const* username, char const* password,
00302 Boolean allowKasennaProtocol = False,
00303 int timeout = -1);
00304 char* sendOptionsCmd(char const* url,
00305 char* username = NULL, char* password = NULL,
00306 Authenticator* authenticator = NULL,
00307 int timeout = -1);
00308 Boolean announceSDPDescription(char const* url,
00309 char const* sdpDescription,
00310 Authenticator* authenticator = NULL,
00311 int timeout = -1);
00312 Boolean announceWithPassword(char const* url, char const* sdpDescription,
00313 char const* username, char const* password, int timeout = -1);
00314 Boolean setupMediaSubsession(MediaSubsession& subsession,
00315 Boolean streamOutgoing = False,
00316 Boolean streamUsingTCP = False,
00317 Boolean forceMulticastOnUnspecified = False);
00318 Boolean playMediaSession(MediaSession& session,
00319 double start = 0.0f, double end = -1.0f,
00320 float scale = 1.0f);
00321 Boolean playMediaSubsession(MediaSubsession& subsession,
00322 double start = 0.0f, double end = -1.0f,
00323 float scale = 1.0f,
00324 Boolean hackForDSS = False);
00325 Boolean pauseMediaSession(MediaSession& session);
00326 Boolean pauseMediaSubsession(MediaSubsession& subsession);
00327 Boolean recordMediaSubsession(MediaSubsession& subsession);
00328 Boolean setMediaSessionParameter(MediaSession& session,
00329 char const* parameterName,
00330 char const* parameterValue);
00331 Boolean getMediaSessionParameter(MediaSession& session,
00332 char const* parameterName,
00333 char*& parameterValue);
00334 Boolean teardownMediaSession(MediaSession& session);
00335 Boolean teardownMediaSubsession(MediaSubsession& subsession);
00336
00337 static Boolean parseRTSPURLUsernamePassword(char const* url,
00338 char*& username, char*& password);
00339 private:
00340 static void responseHandlerForSyncInterface(RTSPClient* rtspClient,
00341 int responseCode, char* responseString);
00342 void responseHandlerForSyncInterface1(int responseCode, char* responseString);
00343 static void timeoutHandlerForSyncInterface(void* rtspClient);
00344 void timeoutHandlerForSyncInterface1();
00345 TaskToken fTimeoutTask;
00346 char fWatchVariableForSyncInterface;
00347 char* fResultString;
00348 int fResultCode;
00349 #endif
00350 };
00351
00352 #endif