00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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:
00040 OnDemandServerMediaSubsession(UsageEnvironment& env, Boolean reuseFirstSource,
00041 portNumBits initialPortNum = 6970);
00042 virtual ~OnDemandServerMediaSubsession();
00043
00044 protected:
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:
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
00077 virtual void setStreamSourceScale(FramedSource* inputSource, float scale);
00078 virtual void closeStreamSource(FramedSource* inputSource);
00079
00080 protected:
00081 virtual FramedSource* createNewStreamSource(unsigned clientSessionId,
00082 unsigned& estBitrate) = 0;
00083
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
00092
00093 protected:
00094 char* fSDPLines;
00095
00096 private:
00097 Boolean fReuseFirstSource;
00098 portNumBits fInitialPortNum;
00099 HashTable* fDestinationsHashTable;
00100 void* fLastStreamToken;
00101 char fCNAME[100];
00102 friend class StreamState;
00103 };
00104
00105
00106
00107
00108
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) , rtcpPort(0) ,
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