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 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:
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
00080
00081
00082 virtual void seekStreamSource(FramedSource* inputSource, char*& absStart, char*& absEnd);
00083
00084
00085
00086
00087 virtual void setStreamSourceScale(FramedSource* inputSource, float scale);
00088 virtual void closeStreamSource(FramedSource* inputSource);
00089
00090 protected:
00091 virtual FramedSource* createNewStreamSource(unsigned clientSessionId,
00092 unsigned& estBitrate) = 0;
00093
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
00102
00103 protected:
00104 char* fSDPLines;
00105 HashTable* fDestinationsHashTable;
00106
00107 private:
00108 Boolean fReuseFirstSource;
00109 portNumBits fInitialPortNum;
00110 void* fLastStreamToken;
00111 char fCNAME[100];
00112 friend class StreamState;
00113 };
00114
00115
00116
00117
00118
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) , rtcpPort(0) ,
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;
00186
00187 Groupsock* fRTPgs;
00188 Groupsock* fRTCPgs;
00189 };
00190
00191 #endif