liveMedia/include/ServerMediaSession.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-2014 Live Networks, Inc.  All rights reserved.
00018 // A data structure that represents a session that consists of
00019 // potentially multiple (audio and/or video) sub-sessions
00020 // (This data structure is used for media *streamers* - i.e., servers.
00021 //  For media receivers, use "MediaSession" instead.)
00022 // C++ header
00023 
00024 #ifndef _SERVER_MEDIA_SESSION_HH
00025 #define _SERVER_MEDIA_SESSION_HH
00026 
00027 #ifndef _MEDIA_HH
00028 #include "Media.hh"
00029 #endif
00030 #ifndef _FRAMED_SOURCE_HH
00031 #include "FramedSource.hh"
00032 #endif
00033 #ifndef _GROUPEID_HH
00034 #include "GroupEId.hh"
00035 #endif
00036 #ifndef _RTP_INTERFACE_HH
00037 #include "RTPInterface.hh" // for ServerRequestAlternativeByteHandler
00038 #endif
00039 
00040 class ServerMediaSubsession; // forward
00041 
00042 class ServerMediaSession: public Medium {
00043 public:
00044   static ServerMediaSession* createNew(UsageEnvironment& env,
00045                                        char const* streamName = NULL,
00046                                        char const* info = NULL,
00047                                        char const* description = NULL,
00048                                        Boolean isSSM = False,
00049                                        char const* miscSDPLines = NULL);
00050 
00051   static Boolean lookupByName(UsageEnvironment& env,
00052                               char const* mediumName,
00053                               ServerMediaSession*& resultSession);
00054 
00055   char* generateSDPDescription(); // based on the entire session
00056       // Note: The caller is responsible for freeing the returned string
00057 
00058   char const* streamName() const { return fStreamName; }
00059 
00060   Boolean addSubsession(ServerMediaSubsession* subsession);
00061   unsigned numSubsessions() const { return fSubsessionCounter; }
00062 
00063   void testScaleFactor(float& scale); // sets "scale" to the actual supported scale
00064   float duration() const;
00065     // a result == 0 means an unbounded session (the default)
00066     // a result < 0 means: subsession durations differ; the result is -(the largest).
00067     // a result > 0 means: this is the duration of a bounded session
00068 
00069   unsigned referenceCount() const { return fReferenceCount; }
00070   void incrementReferenceCount() { ++fReferenceCount; }
00071   void decrementReferenceCount() { if (fReferenceCount > 0) --fReferenceCount; }
00072   Boolean& deleteWhenUnreferenced() { return fDeleteWhenUnreferenced; }
00073 
00074   void deleteAllSubsessions();
00075     // Removes and deletes all subsessions added by "addSubsession()", returning us to an 'empty' state
00076     // Note: If you have already added this "ServerMediaSession" to a "RTSPServer" then, before calling this function,
00077     //   you must first close any client connections that use it,
00078     //   by calling "RTSPServer::closeAllClientSessionsForServerMediaSession()".
00079 
00080 protected:
00081   ServerMediaSession(UsageEnvironment& env, char const* streamName,
00082                      char const* info, char const* description,
00083                      Boolean isSSM, char const* miscSDPLines);
00084   // called only by "createNew()"
00085 
00086   virtual ~ServerMediaSession();
00087 
00088 private: // redefined virtual functions
00089   virtual Boolean isServerMediaSession() const;
00090 
00091 private:
00092   Boolean fIsSSM;
00093 
00094   // Linkage fields:
00095   friend class ServerMediaSubsessionIterator;
00096   ServerMediaSubsession* fSubsessionsHead;
00097   ServerMediaSubsession* fSubsessionsTail;
00098   unsigned fSubsessionCounter;
00099 
00100   char* fStreamName;
00101   char* fInfoSDPString;
00102   char* fDescriptionSDPString;
00103   char* fMiscSDPLines;
00104   struct timeval fCreationTime;
00105   unsigned fReferenceCount;
00106   Boolean fDeleteWhenUnreferenced;
00107 };
00108 
00109 
00110 class ServerMediaSubsessionIterator {
00111 public:
00112   ServerMediaSubsessionIterator(ServerMediaSession& session);
00113   virtual ~ServerMediaSubsessionIterator();
00114 
00115   ServerMediaSubsession* next(); // NULL if none
00116   void reset();
00117 
00118 private:
00119   ServerMediaSession& fOurSession;
00120   ServerMediaSubsession* fNextPtr;
00121 };
00122 
00123 
00124 class ServerMediaSubsession: public Medium {
00125 public:
00126   unsigned trackNumber() const { return fTrackNumber; }
00127   char const* trackId();
00128   virtual char const* sdpLines() = 0;
00129   virtual void getStreamParameters(unsigned clientSessionId, // in
00130                                    netAddressBits clientAddress, // in
00131                                    Port const& clientRTPPort, // in
00132                                    Port const& clientRTCPPort, // in
00133                                    int tcpSocketNum, // in (-1 means use UDP, not TCP)
00134                                    unsigned char rtpChannelId, // in (used if TCP)
00135                                    unsigned char rtcpChannelId, // in (used if TCP)
00136                                    netAddressBits& destinationAddress, // in out
00137                                    u_int8_t& destinationTTL, // in out
00138                                    Boolean& isMulticast, // out
00139                                    Port& serverRTPPort, // out
00140                                    Port& serverRTCPPort, // out
00141                                    void*& streamToken // out
00142                                    ) = 0;
00143   virtual void startStream(unsigned clientSessionId, void* streamToken,
00144                            TaskFunc* rtcpRRHandler,
00145                            void* rtcpRRHandlerClientData,
00146                            unsigned short& rtpSeqNum,
00147                            unsigned& rtpTimestamp,
00148                            ServerRequestAlternativeByteHandler* serverRequestAlternativeByteHandler,
00149                            void* serverRequestAlternativeByteHandlerClientData) = 0;
00150   virtual void pauseStream(unsigned clientSessionId, void* streamToken);
00151   virtual void seekStream(unsigned clientSessionId, void* streamToken, double& seekNPT,
00152                           double streamDuration, u_int64_t& numBytes);
00153      // This routine is used to seek by relative (i.e., NPT) time.
00154      // "streamDuration", if >0.0, specifies how much data to stream, past "seekNPT".  (If <=0.0, all remaining data is streamed.)
00155      // "numBytes" returns the size (in bytes) of the data to be streamed, or 0 if unknown or unlimited.
00156   virtual void seekStream(unsigned clientSessionId, void* streamToken, char*& absStart, char*& absEnd);
00157      // This routine is used to seek by 'absolute' time.
00158      // "absStart" should be a string of the form "YYYYMMDDTHHMMSSZ" or "YYYYMMDDTHHMMSS.<frac>Z".
00159      // "absEnd" should be either NULL (for no end time), or a string of the same form as "absStart".
00160      // These strings may be modified in-place, or can be reassigned to a newly-allocated value (after delete[]ing the original).
00161   virtual void nullSeekStream(unsigned clientSessionId, void* streamToken,
00162                               double streamEndTime, u_int64_t& numBytes);
00163      // Called whenever we're handling a "PLAY" command without a specified start time.
00164   virtual void setStreamScale(unsigned clientSessionId, void* streamToken, float scale);
00165   virtual float getCurrentNPT(void* streamToken);
00166   virtual FramedSource* getStreamSource(void* streamToken);
00167   virtual void deleteStream(unsigned clientSessionId, void*& streamToken);
00168 
00169   virtual void testScaleFactor(float& scale); // sets "scale" to the actual supported scale
00170   virtual float duration() const;
00171     // returns 0 for an unbounded session (the default)
00172     // returns > 0 for a bounded session
00173   virtual void getAbsoluteTimeRange(char*& absStartTime, char*& absEndTime) const;
00174     // Subclasses can reimplement this iff they support seeking by 'absolute' time.
00175 
00176   // The following may be called by (e.g.) SIP servers, for which the
00177   // address and port number fields in SDP descriptions need to be non-zero:
00178   void setServerAddressAndPortForSDP(netAddressBits addressBits,
00179                                      portNumBits portBits);
00180 
00181 protected: // we're a virtual base class
00182   ServerMediaSubsession(UsageEnvironment& env);
00183   virtual ~ServerMediaSubsession();
00184 
00185   char const* rangeSDPLine() const;
00186       // returns a string to be delete[]d
00187 
00188   ServerMediaSession* fParentSession;
00189   netAddressBits fServerAddressForSDP;
00190   portNumBits fPortNumForSDP;
00191 
00192 private:
00193   friend class ServerMediaSession;
00194   friend class ServerMediaSubsessionIterator;
00195   ServerMediaSubsession* fNext;
00196 
00197   unsigned fTrackNumber; // within an enclosing ServerMediaSession
00198   char const* fTrackId;
00199 };
00200 
00201 #endif

Generated on Sun Jul 13 05:09:45 2014 for live by  doxygen 1.5.2