testProgs/testRelay.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 // Copyright (c) 1996-2012, Live Networks, Inc.  All rights reserved
00017 // A test program that receives a UDP multicast stream
00018 // and retransmits it to another (multicast or unicast) address & port
00019 // main program
00020 
00021 #include <liveMedia.hh>
00022 #include "BasicUsageEnvironment.hh"
00023 #include "GroupsockHelper.hh"
00024 
00025 UsageEnvironment* env;
00026 
00027 // To receive a "source-specific multicast" (SSM) stream, uncomment this:
00028 //#define USE_SSM 1
00029 
00030 int main(int argc, char** argv) {
00031   // Begin by setting up our usage environment:
00032   TaskScheduler* scheduler = BasicTaskScheduler::createNew();
00033   env = BasicUsageEnvironment::createNew(*scheduler);
00034 
00035   // Create a 'groupsock' for the input multicast group,port:
00036   char const* inputAddressStr
00037 #ifdef USE_SSM
00038     = "232.255.42.42";
00039 #else
00040     = "239.255.42.42";
00041 #endif
00042   struct in_addr inputAddress;
00043   inputAddress.s_addr = our_inet_addr(inputAddressStr);
00044 
00045   Port const inputPort(8888);
00046   unsigned char const inputTTL = 0; // we're only reading from this mcast group
00047 
00048 #ifdef USE_SSM
00049   char* sourceAddressStr = "aaa.bbb.ccc.ddd";
00050                            // replace this with the real source address
00051   struct in_addr sourceFilterAddress;
00052   sourceFilterAddress.s_addr = our_inet_addr(sourceAddressStr);
00053 
00054   Groupsock inputGroupsock(*env, inputAddress, sourceFilterAddress, inputPort);
00055 #else
00056   Groupsock inputGroupsock(*env, inputAddress, inputPort, inputTTL);
00057 #endif
00058 
00059   // Then create a liveMedia 'source' object, encapsulating this groupsock:
00060   FramedSource* source = BasicUDPSource::createNew(*env, &inputGroupsock);
00061 
00062 
00063   // Create a 'groupsock' for the destination address and port:
00064   char const* outputAddressStr = "239.255.43.43"; // this could also be unicast
00065     // Note: You may change "outputAddressStr" to use a different multicast
00066     // (or unicast address), but do *not* change it to use the same multicast
00067     // address as "inputAddressStr".
00068   struct in_addr outputAddress;
00069   outputAddress.s_addr = our_inet_addr(outputAddressStr);
00070 
00071   Port const outputPort(4444);
00072   unsigned char const outputTTL = 255;
00073 
00074   Groupsock outputGroupsock(*env, outputAddress, outputPort, outputTTL);
00075 
00076   // Then create a liveMedia 'sink' object, encapsulating this groupsock:
00077   unsigned const maxPacketSize = 65536; // allow for large UDP packets
00078   MediaSink* sink = BasicUDPSink::createNew(*env, &outputGroupsock, maxPacketSize);
00079 
00080 
00081   // Now, start playing, feeding the sink object from the source:
00082   sink->startPlaying(*source, NULL, NULL);
00083 
00084   env->taskScheduler().doEventLoop(); // does not return
00085 
00086   return 0; // only to prevent compiler warning
00087 }

Generated on Thu May 17 07:11:48 2012 for live by  doxygen 1.5.2