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

Generated on Mon Apr 29 13:28:01 2013 for live by  doxygen 1.5.2