1/* ---------------------------------------------------------------------------
2** This software is in the public domain, furnished "as is", without technical
3** support, and with no warranty, express or implied, as to its usefulness for
4** any purpose.
5**
6** MulticastServerMediaSubsession.cpp
7**
8** -------------------------------------------------------------------------*/
9
10#include "MulticastServerMediaSubsession.h"
11#include "DeviceSource.h"
12
13// -----------------------------------------
14// ServerMediaSubsession for Multicast
15// -----------------------------------------
16MulticastServerMediaSubsession* MulticastServerMediaSubsession::createNew(UsageEnvironment& env
17 , struct in_addr destinationAddress
18 , Port rtpPortNum, Port rtcpPortNum
19 , int ttl
20 , StreamReplicator* replicator
21 , const std::string& format)
22{
23 // Create a source
24 FramedSource* source = replicator->createStreamReplica();
25 FramedSource* videoSource = createSource(env, source, format);
26
27 // Create RTP/RTCP groupsock
28 Groupsock* rtpGroupsock = new Groupsock(env, destinationAddress, rtpPortNum, ttl);
29 Groupsock* rtcpGroupsock = new Groupsock(env, destinationAddress, rtcpPortNum, ttl);
30
31 // Create a RTP sink
32 RTPSink* videoSink = createSink(env, rtpGroupsock, 96, format, dynamic_cast<V4L2DeviceSource*>(replicator->inputSource()));
33
34 // Create 'RTCP instance'
35 const unsigned maxCNAMElen = 100;
36 unsigned char CNAME[maxCNAMElen+1];
37 gethostname((char*)CNAME, maxCNAMElen);
38 CNAME[maxCNAMElen] = '\0';
39 RTCPInstance* rtcpInstance = RTCPInstance::createNew(env, rtcpGroupsock, 500, CNAME, videoSink, NULL);
40
41 // Start Playing the Sink
42 videoSink->startPlaying(*videoSource, NULL, NULL);
43
44 return new MulticastServerMediaSubsession(replicator, videoSink, rtcpInstance);
45}
46
47char const* MulticastServerMediaSubsession::sdpLines()
48{
49 if (m_SDPLines.empty())
50 {
51 // Ugly workaround to give SPS/PPS that are get from the RTPSink
52 m_SDPLines.assign(PassiveServerMediaSubsession::sdpLines());
53 m_SDPLines.append(getAuxSDPLine(m_rtpSink,NULL));
54 }
55 return m_SDPLines.c_str();
56}
57
58char const* MulticastServerMediaSubsession::getAuxSDPLine(RTPSink* rtpSink,FramedSource* inputSource)
59{
60 return this->getAuxLine(dynamic_cast<V4L2DeviceSource*>(m_replicator->inputSource()), rtpSink);
61}
62
63