liveMedia/include/RTSPClient.hh

Go to the documentation of this file.
00001 /**********
00002 This library is free software; you can redistribute it and/or modify it under
00003 the terms of the GNU Lesser General Public License as published by the
00004 Free Software Foundation; either version 2.1 of the License, or (at your
00005 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
00006 
00007 This library is distributed in the hope that it will be useful, but WITHOUT
00008 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00009 FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
00010 more details.
00011 
00012 You should have received a copy of the GNU Lesser General Public License
00013 along with this library; if not, write to the Free Software Foundation, Inc.,
00014 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
00015 **********/
00016 // "liveMedia"
00017 // Copyright (c) 1996-2008 Live Networks, Inc.  All rights reserved.
00018 // A generic RTSP client
00019 // C++ header
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 class RTSPClient: public Medium {
00035 public:
00036   static RTSPClient* createNew(UsageEnvironment& env,
00037                                int verbosityLevel = 0,
00038                                char const* applicationName = NULL,
00039                                portNumBits tunnelOverHTTPPortNum = 0);
00040   // If "tunnelOverHTTPPortNum" is non-zero, we tunnel RTSP (and RTP)
00041   // over a HTTP connection with the given port number, using the technique
00042   // described in Apple's document <http://developer.apple.com/documentation/QuickTime/QTSS/Concepts/chapter_2_section_14.html>
00043 
00044   int socketNum() const { return fInputSocketNum; }
00045 
00046   static Boolean lookupByName(UsageEnvironment& env,
00047                               char const* sourceName,
00048                               RTSPClient*& resultClient);
00049 
00050   char* describeURL(char const* url, Authenticator* authenticator = NULL,
00051                     Boolean allowKasennaProtocol = False, int timeout = -1);
00052       // Issues a RTSP "DESCRIBE" command
00053       // Returns the SDP description of a session, or NULL if none
00054       // (This is dynamically allocated, and must later be freed
00055       //  by the caller - using "delete[]")
00056   char* describeWithPassword(char const* url,
00057                              char const* username, char const* password,
00058                              Boolean allowKasennaProtocol = False, 
00059                              int timeout = -1);
00060       // Uses "describeURL()" to do a "DESCRIBE" - first
00061       // without using "password", then (if we get an Unauthorized
00062       // response) with an authentication response computed from "password"
00063 
00064   Boolean announceSDPDescription(char const* url,
00065                                  char const* sdpDescription,
00066                                  Authenticator* authenticator = NULL,
00067                                  int timeout = -1);
00068       // Issues a RTSP "ANNOUNCE" command
00069       // Returns True iff this command succeeds
00070   Boolean announceWithPassword(char const* url, char const* sdpDescription,
00071                                char const* username, char const* password, int timeout = -1);
00072       // Uses "announceSDPDescription()" to do an "ANNOUNCE" - first
00073       // without using "password", then (if we get an Unauthorized
00074       // response) with an authentication response computed from "password"
00075 
00076   char* sendOptionsCmd(char const* url,
00077                        char* username = NULL, char* password = NULL,
00078                        Authenticator* authenticator = NULL,
00079                        int timeout = -1);
00080       // Issues a RTSP "OPTIONS" command
00081       // Returns a string containing the list of options, or NULL
00082 
00083   Boolean setupMediaSubsession(MediaSubsession& subsession,
00084                                Boolean streamOutgoing = False,
00085                                Boolean streamUsingTCP = False,
00086                                Boolean forceMulticastOnUnspecified = False);
00087       // Issues a RTSP "SETUP" command on "subsession".
00088       // Returns True iff this command succeeds
00089       // If "forceMulticastOnUnspecified" is True (and "streamUsingTCP" is False),
00090       // then the client will request a multicast stream if the media address
00091       // in the original SDP response was unspecified (i.e., 0.0.0.0).
00092       // Note, however, that not all servers will support this.
00093 
00094   Boolean playMediaSession(MediaSession& session,
00095                            float start = 0.0f, float end = -1.0f,
00096                            float scale = 1.0f);
00097       // Issues an aggregate RTSP "PLAY" command on "session".
00098       // Returns True iff this command succeeds
00099       // (Note: start=-1 means 'resume'; end=-1 means 'play to end')
00100   Boolean playMediaSubsession(MediaSubsession& subsession,
00101                               float start = 0.0f, float end = -1.0f,
00102                               float scale = 1.0f,
00103                               Boolean hackForDSS = False);
00104       // Issues a RTSP "PLAY" command on "subsession".
00105       // Returns True iff this command succeeds
00106       // (Note: start=-1 means 'resume'; end=-1 means 'play to end')
00107 
00108   Boolean pauseMediaSession(MediaSession& session);
00109       // Issues an aggregate RTSP "PAUSE" command on "session".
00110       // Returns True iff this command succeeds
00111   Boolean pauseMediaSubsession(MediaSubsession& subsession);
00112       // Issues a RTSP "PAUSE" command on "subsession".
00113       // Returns True iff this command succeeds
00114 
00115   Boolean recordMediaSubsession(MediaSubsession& subsession);
00116       // Issues a RTSP "RECORD" command on "subsession".
00117       // Returns True iff this command succeeds
00118 
00119   Boolean setMediaSessionParameter(MediaSession& session,
00120                                    char const* parameterName,
00121                                    char const* parameterValue);
00122       // Issues a RTSP "SET_PARAMETER" command on "subsession".
00123       // Returns True iff this command succeeds
00124 
00125   Boolean getMediaSessionParameter(MediaSession& session,
00126                                    char const* parameterName,
00127                                    char*& parameterValue);
00128       // Issues a RTSP "GET_PARAMETER" command on "subsession".
00129       // Returns True iff this command succeeds
00130 
00131   Boolean teardownMediaSession(MediaSession& session);
00132       // Issues an aggregate RTSP "TEARDOWN" command on "session".
00133       // Returns True iff this command succeeds
00134   Boolean teardownMediaSubsession(MediaSubsession& subsession);
00135       // Issues a RTSP "TEARDOWN" command on "subsession".
00136       // Returns True iff this command succeeds
00137 
00138   static Boolean parseRTSPURL(UsageEnvironment& env, char const* url,
00139                               NetAddress& address, portNumBits& portNum,
00140                               char const** urlSuffix = NULL);
00141       // (ignores any "<username>[:<password>]@" in "url")
00142   static Boolean parseRTSPURLUsernamePassword(char const* url,
00143                                               char*& username,
00144                                               char*& password);
00145 
00146   unsigned describeStatus() const { return fDescribeStatusCode; }
00147 
00148   void setUserAgentString(char const* userAgentStr);
00149   // sets an alternative string to be used in RTSP "User-Agent:" headers
00150 
00151   unsigned sessionTimeoutParameter() const { return fSessionTimeoutParameter; }
00152 
00153 #ifdef SUPPORT_REAL_RTSP
00154   Boolean usingRealNetworksChallengeResponse() const { return fRealChallengeStr != NULL; }
00155 #endif
00156 
00157 protected:
00158   RTSPClient(UsageEnvironment& env, int verbosityLevel,
00159              char const* applicationName, portNumBits tunnelOverHTTPPortNum);
00160       // called only by createNew();
00161   virtual ~RTSPClient();
00162 
00163 private: // redefined virtual functions
00164   virtual Boolean isRTSPClient() const;
00165 
00166 private:
00167   void reset();
00168   void resetTCPSockets();
00169 
00170   Boolean openConnectionFromURL(char const* url, Authenticator* authenticator,
00171                                 int timeout = -1);
00172   char* createAuthenticatorString(Authenticator const* authenticator,
00173                                   char const* cmd, char const* url);
00174   static void checkForAuthenticationFailure(unsigned responseCode,
00175                                             char*& nextLineStart,
00176                                             Authenticator* authenticator);
00177   Boolean sendRequest(char const* requestString, char const* tag,
00178                       Boolean base64EncodeIfOverHTTP = True);
00179   Boolean getResponse(char const* tag,
00180                       unsigned& bytesRead, unsigned& responseCode,
00181                       char*& firstLine, char*& nextLineStart,
00182                       Boolean checkFor200Response = True);
00183   unsigned getResponse1(char*& responseBuffer, unsigned responseBufferSize);
00184   Boolean parseResponseCode(char const* line, unsigned& responseCode);
00185   Boolean parseTransportResponse(char const* line,
00186                                  char*& serverAddressStr,
00187                                  portNumBits& serverPortNum,
00188                                  unsigned char& rtpChannelId,
00189                                  unsigned char& rtcpChannelId);
00190   Boolean parseRTPInfoHeader(char*& line, u_int16_t& seqNum, u_int32_t& timestamp);
00191   Boolean parseScaleHeader(char const* line, float& scale);
00192   Boolean parseGetParameterHeader(char const* line,
00193                                   const char* param,
00194                                   char*& value);
00195   char const* sessionURL(MediaSession const& session) const;
00196   void constructSubsessionURL(MediaSubsession const& subsession,
00197                               char const*& prefix,
00198                               char const*& separator,
00199                               char const*& suffix);
00200   Boolean setupHTTPTunneling(char const* urlSuffix, Authenticator* authenticator);
00201 
00202   // Support for handling requests sent back by a server:
00203   static void incomingRequestHandler(void*, int /*mask*/);
00204   void incomingRequestHandler1();
00205   void handleCmd_notSupported(char const* cseq);
00206 
00207 private:
00208   int fVerbosityLevel;
00209   portNumBits fTunnelOverHTTPPortNum;
00210   char* fUserAgentHeaderStr;
00211       unsigned fUserAgentHeaderStrSize;
00212   int fInputSocketNum, fOutputSocketNum;
00213   unsigned fServerAddress;
00214   static unsigned fCSeq; // sequence number, used in consecutive requests
00215       // Note: it's static, to ensure that it differs if more than one
00216       // connection is made to the same server, using the same URL.
00217       // Some servers (e.g., DSS) may have problems with this otherwise.
00218   char* fBaseURL;
00219   Authenticator fCurrentAuthenticator;
00220   unsigned char fTCPStreamIdCount; // used for (optional) RTP/TCP
00221   char* fLastSessionId;
00222   unsigned fSessionTimeoutParameter; // optionally set in response "Session:" headers
00223 #ifdef SUPPORT_REAL_RTSP
00224   char* fRealChallengeStr;
00225   char* fRealETagStr;
00226 #endif
00227   unsigned fDescribeStatusCode;
00228   // 0: OK; 1: connection failed; 2: stream unavailable
00229   char* fResponseBuffer;
00230   unsigned fResponseBufferSize;
00231 
00232   // The following fields are used to implement the non-standard Kasenna protocol:
00233   Boolean fServerIsKasenna;
00234   char* fKasennaContentType;
00235 
00236   // The following is used to deal with Microsoft servers' non-standard use of RTSP:
00237   Boolean fServerIsMicrosoft;
00238 };
00239 
00240 #endif

Generated on Tue Oct 7 15:38:09 2008 for live by  doxygen 1.5.2