00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "PassiveServerMediaSubsession.hh"
00023 #include <GroupsockHelper.hh>
00024
00026
00027 PassiveServerMediaSubsession*
00028 PassiveServerMediaSubsession::createNew(RTPSink& rtpSink,
00029 RTCPInstance* rtcpInstance) {
00030 return new PassiveServerMediaSubsession(rtpSink, rtcpInstance);
00031 }
00032
00033 PassiveServerMediaSubsession
00034 ::PassiveServerMediaSubsession(RTPSink& rtpSink, RTCPInstance* rtcpInstance)
00035 : ServerMediaSubsession(rtpSink.envir()),
00036 fRTPSink(rtpSink), fRTCPInstance(rtcpInstance), fSDPLines(NULL) {
00037 }
00038
00039 char const*
00040 PassiveServerMediaSubsession::sdpLines() {
00041 if (fSDPLines == NULL ) {
00042
00043
00044 Groupsock const& gs = fRTPSink.groupsockBeingUsed();
00045 struct in_addr const& ipAddress = gs.groupAddress();
00046 unsigned short portNum = ntohs(gs.port().num());
00047 unsigned char ttl = gs.ttl();
00048 unsigned char rtpPayloadType = fRTPSink.rtpPayloadType();
00049 char const* mediaType = fRTPSink.sdpMediaType();
00050 char* rtpmapLine = fRTPSink.rtpmapLine();
00051 char const* rangeLine = rangeSDPLine();
00052 char const* auxSDPLine = fRTPSink.auxSDPLine();
00053 if (auxSDPLine == NULL) auxSDPLine = "";
00054
00055 char* const ipAddressStr = strDup(our_inet_ntoa(ipAddress));
00056
00057 char const* const sdpFmt =
00058 "m=%s %d RTP/AVP %d\r\n"
00059 "c=IN IP4 %s/%d\r\n"
00060 "%s"
00061 "%s"
00062 "%s"
00063 "a=control:%s\r\n";
00064 unsigned sdpFmtSize = strlen(sdpFmt)
00065 + strlen(mediaType) + 5 + 3
00066 + strlen(ipAddressStr) + 3
00067 + strlen(rtpmapLine)
00068 + strlen(rangeLine)
00069 + strlen(auxSDPLine)
00070 + strlen(trackId());
00071 char* sdpLines = new char[sdpFmtSize];
00072 sprintf(sdpLines, sdpFmt,
00073 mediaType,
00074 portNum,
00075 rtpPayloadType,
00076 ipAddressStr,
00077 ttl,
00078 rtpmapLine,
00079 rangeLine,
00080 auxSDPLine,
00081 trackId());
00082 delete[] ipAddressStr; delete[] (char*)rangeLine; delete[] rtpmapLine;
00083
00084 fSDPLines = strDup(sdpLines);
00085 delete[] sdpLines;
00086 }
00087
00088 return fSDPLines;
00089 }
00090
00091 void PassiveServerMediaSubsession
00092 ::getStreamParameters(unsigned ,
00093 netAddressBits ,
00094 Port const& ,
00095 Port const& ,
00096 int ,
00097 unsigned char ,
00098 unsigned char ,
00099 netAddressBits& destinationAddress,
00100 u_int8_t& destinationTTL,
00101 Boolean& isMulticast,
00102 Port& serverRTPPort,
00103 Port& serverRTCPPort,
00104 void*& streamToken) {
00105 isMulticast = True;
00106 Groupsock& gs = fRTPSink.groupsockBeingUsed();
00107 if (destinationTTL == 255) destinationTTL = gs.ttl();
00108 if (destinationAddress == 0) {
00109 destinationAddress = gs.groupAddress().s_addr;
00110 } else {
00111 struct in_addr destinationAddr; destinationAddr.s_addr = destinationAddress;
00112 gs.changeDestinationParameters(destinationAddr, 0, destinationTTL);
00113 if (fRTCPInstance != NULL) {
00114 Groupsock* rtcpGS = fRTCPInstance->RTCPgs();
00115 rtcpGS->changeDestinationParameters(destinationAddr, 0, destinationTTL);
00116 }
00117 }
00118 serverRTPPort = gs.port();
00119 if (fRTCPInstance != NULL) {
00120 Groupsock* rtcpGS = fRTCPInstance->RTCPgs();
00121 serverRTCPPort = rtcpGS->port();
00122 }
00123 streamToken = NULL;
00124 }
00125
00126 void PassiveServerMediaSubsession::startStream(unsigned ,
00127 void* ,
00128 TaskFunc* ,
00129 void* ,
00130 unsigned short& rtpSeqNum,
00131 unsigned& rtpTimestamp) {
00132
00133
00134
00135 rtpSeqNum = fRTPSink.currentSeqNo();
00136 rtpTimestamp = fRTPSink.currentTimestamp();
00137 }
00138
00139 PassiveServerMediaSubsession::~PassiveServerMediaSubsession() {
00140 delete[] fSDPLines;
00141 }