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-2012 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 setStreamScale(unsigned clientSessionId, void* streamToken, float scale);
00069   virtual FramedSource* getStreamSource(void* streamToken);
00070   virtual void deleteStream(unsigned clientSessionId, void*& streamToken);
00071 
00072 protected: // new virtual functions, possibly redefined by subclasses
00073   virtual char const* getAuxSDPLine(RTPSink* rtpSink,
00074                                     FramedSource* inputSource);
00075   virtual void seekStreamSource(FramedSource* inputSource, double& seekNPT, double streamDuration, u_int64_t& numBytes);
00076     // "streamDuration", if >0.0, specifies how much data to stream, past "seekNPT".  (If <=0.0, all remaining data is streamed.)
00077   virtual void setStreamSourceScale(FramedSource* inputSource, float scale);
00078   virtual void closeStreamSource(FramedSource* inputSource);
00079 
00080 protected: // new virtual functions, defined by all subclasses
00081   virtual FramedSource* createNewStreamSource(unsigned clientSessionId,
00082                                               unsigned& estBitrate) = 0;
00083       // "estBitrate" is the stream's estimated bitrate, in kbps
00084   virtual RTPSink* createNewRTPSink(Groupsock* rtpGroupsock,
00085                                     unsigned char rtpPayloadTypeIfDynamic,
00086                                     FramedSource* inputSource) = 0;
00087 
00088 private:
00089   void setSDPLinesFromRTPSink(RTPSink* rtpSink, FramedSource* inputSource,
00090                               unsigned estBitrate);
00091       // used to implement "sdpLines()"
00092 
00093 protected:
00094   char* fSDPLines;
00095 
00096 private:
00097   Boolean fReuseFirstSource;
00098   portNumBits fInitialPortNum;
00099   HashTable* fDestinationsHashTable; // indexed by client session id
00100   void* fLastStreamToken;
00101   char fCNAME[100]; // for RTCP
00102   friend class StreamState;
00103 };
00104 
00105 
00106 // A class that represents the state of an ongoing stream.  This is used only internally, in the implementation of
00107 // "OnDemandServerMediaSubsession", but we expose the definition here, in case subclasses of "OnDemandServerMediaSubsession"
00108 // want to access it.
00109 class Destinations {
00110 public:
00111   Destinations(struct in_addr const& destAddr,
00112                Port const& rtpDestPort,
00113                Port const& rtcpDestPort)
00114     : isTCP(False), addr(destAddr), rtpPort(rtpDestPort), rtcpPort(rtcpDestPort) {
00115   }
00116   Destinations(int tcpSockNum, unsigned char rtpChanId, unsigned char rtcpChanId)
00117     : isTCP(True), rtpPort(0) /*dummy*/, rtcpPort(0) /*dummy*/,
00118       tcpSocketNum(tcpSockNum), rtpChannelId(rtpChanId), rtcpChannelId(rtcpChanId) {
00119   }
00120 
00121 public:
00122   Boolean isTCP;
00123   struct in_addr addr;
00124   Port rtpPort;
00125   Port rtcpPort;
00126   int tcpSocketNum;
00127   unsigned char rtpChannelId, rtcpChannelId;
00128 };
00129 
00130 class StreamState {
00131 public:
00132   StreamState(OnDemandServerMediaSubsession& master,
00133               Port const& serverRTPPort, Port const& serverRTCPPort,
00134               RTPSink* rtpSink, BasicUDPSink* udpSink,
00135               unsigned totalBW, FramedSource* mediaSource,
00136               Groupsock* rtpGS, Groupsock* rtcpGS);
00137   virtual ~StreamState();
00138 
00139   void startPlaying(Destinations* destinations,
00140                     TaskFunc* rtcpRRHandler, void* rtcpRRHandlerClientData,
00141                     ServerRequestAlternativeByteHandler* serverRequestAlternativeByteHandler,
00142                     void* serverRequestAlternativeByteHandlerClientData);
00143   void pause();
00144   void endPlaying(Destinations* destinations);
00145   void reclaim();
00146 
00147   unsigned& referenceCount() { return fReferenceCount; }
00148 
00149   Port const& serverRTPPort() const { return fServerRTPPort; }
00150   Port const& serverRTCPPort() const { return fServerRTCPPort; }
00151 
00152   RTPSink* rtpSink() const { return fRTPSink; }
00153 
00154   float streamDuration() const { return fStreamDuration; }
00155 
00156   FramedSource* mediaSource() const { return fMediaSource; }
00157 
00158 private:
00159   OnDemandServerMediaSubsession& fMaster;
00160   Boolean fAreCurrentlyPlaying;
00161   unsigned fReferenceCount;
00162 
00163   Port fServerRTPPort, fServerRTCPPort;
00164 
00165   RTPSink* fRTPSink;
00166   BasicUDPSink* fUDPSink;
00167 
00168   float fStreamDuration;
00169   unsigned fTotalBW;
00170   RTCPInstance* fRTCPInstance;
00171 
00172   FramedSource* fMediaSource;
00173 
00174   Groupsock* fRTPgs;
00175   Groupsock* fRTCPgs;
00176 };
00177 
00178 #endif

Generated on Thu May 17 07:11:46 2012 for live by  doxygen 1.5.2