liveMedia/include/OnDemandServerMediaSubsession.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 'ServerMediaSubsession' object that creates new, unicast, "RTPSink"s
00019 // on demand.
00020 // C++ header
00021 
00022 #ifndef _ON_DEMAND_SERVER_MEDIA_SUBSESSION_HH
00023 #define _ON_DEMAND_SERVER_MEDIA_SUBSESSION_HH
00024 
00025 #ifndef _SERVER_MEDIA_SESSION_HH
00026 #include "ServerMediaSession.hh"
00027 #endif
00028 #ifndef _RTP_SINK_HH
00029 #include "RTPSink.hh"
00030 #endif
00031 #ifndef _BASIC_UDP_SINK_HH
00032 #include "BasicUDPSink.hh"
00033 #endif
00034 #ifndef _RTCP_HH
00035 #include "RTCP.hh"
00036 #endif
00037 
00038 class OnDemandServerMediaSubsession: public ServerMediaSubsession {
00039 protected: // we're a virtual base class
00040   OnDemandServerMediaSubsession(UsageEnvironment& env, Boolean reuseFirstSource,
00041                                 portNumBits initialPortNum = 6970,
00042                                 Boolean multiplexRTCPWithRTP = False);
00043   virtual ~OnDemandServerMediaSubsession();
00044 
00045 protected: // redefined virtual functions
00046   virtual char const* sdpLines();
00047   virtual void getStreamParameters(unsigned clientSessionId,
00048                                    netAddressBits clientAddress,
00049                                    Port const& clientRTPPort,
00050                                    Port const& clientRTCPPort,
00051                                    int tcpSocketNum,
00052                                    unsigned char rtpChannelId,
00053                                    unsigned char rtcpChannelId,
00054                                    netAddressBits& destinationAddress,
00055                                    u_int8_t& destinationTTL,
00056                                    Boolean& isMulticast,
00057                                    Port& serverRTPPort,
00058                                    Port& serverRTCPPort,
00059                                    void*& streamToken);
00060   virtual void startStream(unsigned clientSessionId, void* streamToken,
00061                            TaskFunc* rtcpRRHandler,
00062                            void* rtcpRRHandlerClientData,
00063                            unsigned short& rtpSeqNum,
00064                            unsigned& rtpTimestamp,
00065                            ServerRequestAlternativeByteHandler* serverRequestAlternativeByteHandler,
00066                            void* serverRequestAlternativeByteHandlerClientData);
00067   virtual void pauseStream(unsigned clientSessionId, void* streamToken);
00068   virtual void seekStream(unsigned clientSessionId, void* streamToken, double& seekNPT, double streamDuration, u_int64_t& numBytes);
00069   virtual void seekStream(unsigned clientSessionId, void* streamToken, char*& absStart, char*& absEnd);
00070   virtual void nullSeekStream(unsigned clientSessionId, void* streamToken,
00071                               double streamEndTime, u_int64_t& numBytes);
00072   virtual void setStreamScale(unsigned clientSessionId, void* streamToken, float scale);
00073   virtual float getCurrentNPT(void* streamToken);
00074   virtual FramedSource* getStreamSource(void* streamToken);
00075   virtual void deleteStream(unsigned clientSessionId, void*& streamToken);
00076 
00077 protected: // new virtual functions, possibly redefined by subclasses
00078   virtual char const* getAuxSDPLine(RTPSink* rtpSink,
00079                                     FramedSource* inputSource);
00080   virtual void seekStreamSource(FramedSource* inputSource, double& seekNPT, double streamDuration, u_int64_t& numBytes);
00081     // This routine is used to seek by relative (i.e., NPT) time.
00082     // "streamDuration", if >0.0, specifies how much data to stream, past "seekNPT".  (If <=0.0, all remaining data is streamed.)
00083     // "numBytes" returns the size (in bytes) of the data to be streamed, or 0 if unknown or unlimited.
00084   virtual void seekStreamSource(FramedSource* inputSource, char*& absStart, char*& absEnd);
00085     // This routine is used to seek by 'absolute' time.
00086     // "absStart" should be a string of the form "YYYYMMDDTHHMMSSZ" or "YYYYMMDDTHHMMSS.<frac>Z".
00087     // "absEnd" should be either NULL (for no end time), or a string of the same form as "absStart".
00088     // These strings may be modified in-place, or can be reassigned to a newly-allocated value (after delete[]ing the original).
00089   virtual void setStreamSourceScale(FramedSource* inputSource, float scale);
00090   virtual void setStreamSourceDuration(FramedSource* inputSource, double streamDuration, u_int64_t& numBytes);
00091   virtual void closeStreamSource(FramedSource* inputSource);
00092 
00093 protected: // new virtual functions, defined by all subclasses
00094   virtual FramedSource* createNewStreamSource(unsigned clientSessionId,
00095                                               unsigned& estBitrate) = 0;
00096       // "estBitrate" is the stream's estimated bitrate, in kbps
00097   virtual RTPSink* createNewRTPSink(Groupsock* rtpGroupsock,
00098                                     unsigned char rtpPayloadTypeIfDynamic,
00099                                     FramedSource* inputSource) = 0;
00100 
00101 public:
00102   void multiplexRTCPWithRTP() { fMultiplexRTCPWithRTP = True; }
00103   // An alternative to passing the "multiplexRTCPWithRTP" parameter as True in the constructor
00104 
00105 private:
00106   void setSDPLinesFromRTPSink(RTPSink* rtpSink, FramedSource* inputSource,
00107                               unsigned estBitrate);
00108       // used to implement "sdpLines()"
00109 
00110 protected:
00111   char* fSDPLines;
00112   HashTable* fDestinationsHashTable; // indexed by client session id
00113 
00114 private:
00115   Boolean fReuseFirstSource;
00116   portNumBits fInitialPortNum;
00117   Boolean fMultiplexRTCPWithRTP;
00118   void* fLastStreamToken;
00119   char fCNAME[100]; // for RTCP
00120   friend class StreamState;
00121 };
00122 
00123 
00124 // A class that represents the state of an ongoing stream.  This is used only internally, in the implementation of
00125 // "OnDemandServerMediaSubsession", but we expose the definition here, in case subclasses of "OnDemandServerMediaSubsession"
00126 // want to access it.
00127 
00128 class Destinations {
00129 public:
00130   Destinations(struct in_addr const& destAddr,
00131                Port const& rtpDestPort,
00132                Port const& rtcpDestPort)
00133     : isTCP(False), addr(destAddr), rtpPort(rtpDestPort), rtcpPort(rtcpDestPort) {
00134   }
00135   Destinations(int tcpSockNum, unsigned char rtpChanId, unsigned char rtcpChanId)
00136     : isTCP(True), rtpPort(0) /*dummy*/, rtcpPort(0) /*dummy*/,
00137       tcpSocketNum(tcpSockNum), rtpChannelId(rtpChanId), rtcpChannelId(rtcpChanId) {
00138   }
00139 
00140 public:
00141   Boolean isTCP;
00142   struct in_addr addr;
00143   Port rtpPort;
00144   Port rtcpPort;
00145   int tcpSocketNum;
00146   unsigned char rtpChannelId, rtcpChannelId;
00147 };
00148 
00149 class StreamState {
00150 public:
00151   StreamState(OnDemandServerMediaSubsession& master,
00152               Port const& serverRTPPort, Port const& serverRTCPPort,
00153               RTPSink* rtpSink, BasicUDPSink* udpSink,
00154               unsigned totalBW, FramedSource* mediaSource,
00155               Groupsock* rtpGS, Groupsock* rtcpGS);
00156   virtual ~StreamState();
00157 
00158   void startPlaying(Destinations* destinations,
00159                     TaskFunc* rtcpRRHandler, void* rtcpRRHandlerClientData,
00160                     ServerRequestAlternativeByteHandler* serverRequestAlternativeByteHandler,
00161                     void* serverRequestAlternativeByteHandlerClientData);
00162   void pause();
00163   void endPlaying(Destinations* destinations);
00164   void reclaim();
00165 
00166   unsigned& referenceCount() { return fReferenceCount; }
00167 
00168   Port const& serverRTPPort() const { return fServerRTPPort; }
00169   Port const& serverRTCPPort() const { return fServerRTCPPort; }
00170 
00171   RTPSink* rtpSink() const { return fRTPSink; }
00172 
00173   float streamDuration() const { return fStreamDuration; }
00174 
00175   FramedSource* mediaSource() const { return fMediaSource; }
00176   float& startNPT() { return fStartNPT; }
00177 
00178 private:
00179   OnDemandServerMediaSubsession& fMaster;
00180   Boolean fAreCurrentlyPlaying;
00181   unsigned fReferenceCount;
00182 
00183   Port fServerRTPPort, fServerRTCPPort;
00184 
00185   RTPSink* fRTPSink;
00186   BasicUDPSink* fUDPSink;
00187 
00188   float fStreamDuration;
00189   unsigned fTotalBW;
00190   RTCPInstance* fRTCPInstance;
00191 
00192   FramedSource* fMediaSource;
00193   float fStartNPT; // initial 'normal play time'; reset after each seek
00194 
00195   Groupsock* fRTPgs;
00196   Groupsock* fRTCPgs;
00197 };
00198 
00199 #endif

Generated on Thu Oct 16 16:17:11 2014 for live by  doxygen 1.5.2