liveMedia/MPEG2TransportUDPServerMediaSubsession.cpp

Go to the documentation of this file.
00001 /**********
00002 This library is free software; you can redistribute it and/or modify it under
00003 the terms of the GNU Lesser General Public License as published by the
00004 Free Software Foundation; either version 2.1 of the License, or (at your
00005 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
00006 
00007 This library is distributed in the hope that it will be useful, but WITHOUT
00008 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00009 FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
00010 more details.
00011 
00012 You should have received a copy of the GNU Lesser General Public License
00013 along with this library; if not, write to the Free Software Foundation, Inc.,
00014 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
00015 **********/
00016 // "liveMedia"
00017 // Copyright (c) 1996-2013 Live Networks, Inc.  All rights reserved.
00018 // A 'ServerMediaSubsession' object that creates new, unicast, "RTPSink"s
00019 // on demand, from an incoming UDP (or RTP/UDP) MPEG-2 Transport Stream
00020 // Implementation
00021 
00022 #include "MPEG2TransportUDPServerMediaSubsession.hh"
00023 #include "BasicUDPSource.hh"
00024 #include "SimpleRTPSource.hh"
00025 #include "MPEG2TransportStreamFramer.hh"
00026 #include "SimpleRTPSink.hh"
00027 #include "GroupsockHelper.hh"
00028 
00029 
00030 MPEG2TransportUDPServerMediaSubsession*
00031 MPEG2TransportUDPServerMediaSubsession::createNew(UsageEnvironment& env,
00032                                                   char const* inputAddressStr, Port const& inputPort, Boolean inputStreamIsRawUDP) {
00033   return new MPEG2TransportUDPServerMediaSubsession(env, inputAddressStr, inputPort, inputStreamIsRawUDP);
00034 }
00035 
00036 MPEG2TransportUDPServerMediaSubsession
00037 ::MPEG2TransportUDPServerMediaSubsession(UsageEnvironment& env,
00038                                          char const* inputAddressStr, Port const& inputPort, Boolean inputStreamIsRawUDP)
00039   : OnDemandServerMediaSubsession(env, True/*reuseFirstSource*/),
00040     fInputPort(inputPort), fInputGroupsock(NULL), fInputStreamIsRawUDP(inputStreamIsRawUDP) {
00041   fInputAddressStr = strDup(inputAddressStr);
00042 }
00043 
00044 MPEG2TransportUDPServerMediaSubsession::
00045 ~MPEG2TransportUDPServerMediaSubsession() {
00046   delete fInputGroupsock;
00047   delete[] (char*)fInputAddressStr;
00048 }
00049 
00050 FramedSource* MPEG2TransportUDPServerMediaSubsession
00051 ::createNewStreamSource(unsigned/* clientSessionId*/, unsigned& estBitrate) {
00052   estBitrate = 5000; // kbps, estimate
00053 
00054   if (fInputGroupsock == NULL) {
00055     // Create a 'groupsock' object for receiving the input stream:
00056     struct in_addr inputAddress;
00057     inputAddress.s_addr = fInputAddressStr == NULL ? 0 : our_inet_addr(fInputAddressStr);
00058     fInputGroupsock = new Groupsock(envir(), inputAddress, fInputPort, 255);
00059   }
00060 
00061   FramedSource* transportStreamSource;
00062   if (fInputStreamIsRawUDP) {
00063     transportStreamSource = BasicUDPSource::createNew(envir(), fInputGroupsock);
00064   } else {
00065     transportStreamSource = SimpleRTPSource::createNew(envir(), fInputGroupsock, 33, 90000, "video/MP2T", 0, False /*no 'M' bit*/);
00066   }
00067   return MPEG2TransportStreamFramer::createNew(envir(), transportStreamSource);
00068 }
00069 
00070 RTPSink* MPEG2TransportUDPServerMediaSubsession
00071 ::createNewRTPSink(Groupsock* rtpGroupsock, unsigned char /*rtpPayloadTypeIfDynamic*/, FramedSource* /*inputSource*/) {
00072   return SimpleRTPSink::createNew(envir(), rtpGroupsock,
00073                                   33, 90000, "video", "MP2T",
00074                                   1, True, False /*no 'M' bit*/);
00075 }

Generated on Tue Jun 18 13:16:51 2013 for live by  doxygen 1.5.2