1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
/**********
This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
more details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
**********/
// "liveMedia"
// Copyright (c) 1996-2005 Live Networks, Inc. All rights reserved.
// A 'ServerMediaSubsession' object that represents an existing
// 'RTPSink', rather than one that creates new 'RTPSink's on demand.
// Implementation
#include "PassiveServerMediaSubsession.hh"
#include <GroupsockHelper.hh>
////////// PassiveServerMediaSubsession //////////
PassiveServerMediaSubsession*
PassiveServerMediaSubsession::createNew(RTPSink& rtpSink,
RTCPInstance* rtcpInstance) {
return new PassiveServerMediaSubsession(rtpSink, rtcpInstance);
}
PassiveServerMediaSubsession
::PassiveServerMediaSubsession(RTPSink& rtpSink, RTCPInstance* rtcpInstance)
: ServerMediaSubsession(rtpSink.envir()),
fRTPSink(rtpSink), fRTCPInstance(rtcpInstance), fSDPLines(NULL) {
}
char const*
PassiveServerMediaSubsession::sdpLines() {
if (fSDPLines == NULL ) {
// Construct a set of SDP lines that describe this subsession:
// Use the components from "rtpSink":
Groupsock const& gs = fRTPSink.groupsockBeingUsed();
struct in_addr const& ipAddress = gs.groupAddress();
unsigned short portNum = ntohs(gs.port().num());
unsigned char ttl = gs.ttl();
unsigned char rtpPayloadType = fRTPSink.rtpPayloadType();
char const* mediaType = fRTPSink.sdpMediaType();
char* rtpmapLine = fRTPSink.rtpmapLine();
char const* rangeLine = rangeSDPLine();
char const* auxSDPLine = fRTPSink.auxSDPLine();
if (auxSDPLine == NULL) auxSDPLine = "";
char* const ipAddressStr = strDup(our_inet_ntoa(ipAddress));
char const* const sdpFmt =
"m=%s %d RTP/AVP %d\r\n"
"c=IN IP4 %s/%d\r\n"
"%s"
"%s"
"%s"
"a=control:%s\r\n";
unsigned sdpFmtSize = strlen(sdpFmt)
+ strlen(mediaType) + 5 /* max short len */ + 3 /* max char len */
+ strlen(ipAddressStr) + 3 /* max char len */
+ strlen(rtpmapLine)
+ strlen(rangeLine)
+ strlen(auxSDPLine)
+ strlen(trackId());
char* sdpLines = new char[sdpFmtSize];
sprintf(sdpLines, sdpFmt,
mediaType, // m= <media>
portNum, // m= <port>
rtpPayloadType, // m= <fmt list>
ipAddressStr, // c= <connection address>
ttl, // c= TTL
rtpmapLine, // a=rtpmap:... (if present)
rangeLine, // a=range:... (if present)
auxSDPLine, // optional extra SDP line
trackId()); // a=control:<track-id>
delete[] ipAddressStr; delete[] (char*)rangeLine; delete[] rtpmapLine;
fSDPLines = strDup(sdpLines);
delete[] sdpLines;
}
return fSDPLines;
}
void PassiveServerMediaSubsession
::getStreamParameters(unsigned /*clientSessionId*/,
netAddressBits /*clientAddress*/,
Port const& /*clientRTPPort*/,
Port const& /*clientRTCPPort*/,
int /*tcpSocketNum*/,
unsigned char /*rtpChannelId*/,
unsigned char /*rtcpChannelId*/,
netAddressBits& destinationAddress,
u_int8_t& destinationTTL,
Boolean& isMulticast,
Port& serverRTPPort,
Port& serverRTCPPort,
void*& streamToken) {
isMulticast = True;
Groupsock& gs = fRTPSink.groupsockBeingUsed();
if (destinationTTL == 255) destinationTTL = gs.ttl();
if (destinationAddress == 0) { // normal case
destinationAddress = gs.groupAddress().s_addr;
} else { // use the client-specified destination address instead:
struct in_addr destinationAddr; destinationAddr.s_addr = destinationAddress;
gs.changeDestinationParameters(destinationAddr, 0, destinationTTL);
if (fRTCPInstance != NULL) {
Groupsock* rtcpGS = fRTCPInstance->RTCPgs();
rtcpGS->changeDestinationParameters(destinationAddr, 0, destinationTTL);
}
}
serverRTPPort = gs.port();
if (fRTCPInstance != NULL) {
Groupsock* rtcpGS = fRTCPInstance->RTCPgs();
serverRTCPPort = rtcpGS->port();
}
streamToken = NULL; // not used
}
void PassiveServerMediaSubsession::startStream(unsigned /*clientSessionId*/,
void* /*streamToken*/,
TaskFunc* /*rtcpRRHandler*/,
void* /*rtcpRRHandlerClientData*/,
unsigned short& rtpSeqNum,
unsigned& rtpTimestamp) {
// Note: We don't set a RTCP RR handler, because (i) we're called potentially
// many times on the same "RTCPInstance", and (ii) the "RTCPInstance" remains
// in existence after "stopStream()" is called.
rtpSeqNum = fRTPSink.currentSeqNo();
rtpTimestamp = fRTPSink.currentTimestamp();
}
PassiveServerMediaSubsession::~PassiveServerMediaSubsession() {
delete[] fSDPLines;
}
|