rtplisten.cpp

00001 // rtplisten
00002 // Listen for RTP packets.
00003 // Copyright (C) 2001,2002,2003,2004 Federico Montesino <fedemp@altern.org>
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 2 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 #include <cstdlib>
00020 #include <ccrtp/rtp.h>
00021 
00022 #ifdef  CCXX_NAMESPACES
00023 using namespace ost;
00024 using namespace std;
00025 #endif
00026 
00027 class Listener: RTPSession
00028 {
00029 public:
00030     Listener(InetMcastAddress& ima, tpport_t port) :
00031     RTPSession(ima,port) {}
00032 
00033     Listener(InetHostAddress& ia, tpport_t port) :
00034     RTPSession(ia,port) {}
00035 
00036     void listen()
00037     {
00038         cout << "My SSRC identifier is: "
00039              << hex << (int)getLocalSSRC() << endl;
00040 
00041         defaultApplication().setSDESItem(SDESItemTypeTOOL,
00042                          "rtplisten demo app.");
00043         setExpireTimeout(1000000);
00044 
00045         setPayloadFormat(StaticPayloadFormat(sptPCMU));
00046         startRunning();
00047         for (;;) {
00048             const AppDataUnit* adu;
00049             while ( (adu = getData(getFirstTimestamp())) ) {
00050                 cerr << "I got an app. data unit - "
00051                      << adu->getSize()
00052                      << " payload octets ("
00053                      << "pt " << (int)adu->getType()
00054                      << ") from "
00055                      << hex << (int)adu->getSource().getID()
00056                      << "@" << dec <<
00057                     adu->getSource().getNetworkAddress()
00058                      << ":"
00059                      << adu->getSource().getDataTransportPort()
00060                      << endl;
00061                 delete adu;
00062             }
00063             Thread::sleep(7);
00064         }
00065     }
00066 
00067     // redefined from IncomingDataQueue
00068     void onNewSyncSource(const SyncSource& src)
00069     {
00070         cout << "* New synchronization source: " <<
00071              hex << (int)src.getID() << endl;
00072     }
00073 
00074     // redefined from QueueRTCPManager
00075     void onGotSR(SyncSource& source, SendReport& SR, uint8 blocks)
00076     {
00077         RTPSession::onGotSR(source,SR,blocks);
00078         cout << "I got an SR RTCP report from "
00079              << hex << (int)source.getID() << "@"
00080              << dec
00081              << source.getNetworkAddress() << ":"
00082              << source.getControlTransportPort() << endl;
00083     }
00084 
00085     // redefined from QueueRTCPManager
00086     void onGotRR(SyncSource& source, RecvReport& RR, uint8 blocks)
00087     {
00088         RTPSession::onGotRR(source,RR,blocks);
00089         cout << "I got an RR RTCP report from "
00090              << hex << (int)source.getID() << "@"
00091              << dec
00092              << source.getNetworkAddress() << ":"
00093              << source.getControlTransportPort() << endl;
00094     }
00095 
00096     // redefined from QueueRTCPManager
00097     bool onGotSDESChunk(SyncSource& source, SDESChunk& chunk, size_t len)
00098     {
00099         bool result = RTPSession::onGotSDESChunk(source,chunk,len);
00100         cout << "I got a SDES chunk from "
00101              << hex << (int)source.getID() << "@"
00102              << dec
00103              << source.getNetworkAddress() << ":"
00104              << source.getControlTransportPort()
00105              << " ("
00106              << source.getParticipant()->getSDESItem(SDESItemTypeCNAME)
00107              << ") " << endl;
00108         return result;
00109     }
00110 
00111     void onGotGoodbye(const SyncSource& source, const std::string& reason)
00112     {
00113         cout << "I got a Goodbye packet from "
00114              << hex << (int)source.getID() << "@"
00115              << dec
00116              << source.getNetworkAddress() << ":"
00117              << source.getControlTransportPort() << endl;
00118         cout << "   Goodbye reason: \"" << reason << "\"" << endl;
00119     }
00120 };
00121 
00122 int main(int argc, char *argv[])
00123 {
00124     cout << "rtplisten" << endl;
00125 
00126     if (argc != 3) {
00127         cerr << "Syntax: " << " ip port" << endl;
00128         exit(1);
00129     }
00130 
00131     InetMcastAddress ima;
00132     try {
00133         ima = InetMcastAddress(argv[1]);
00134     } catch (...) { }
00135 
00136     Listener *foo;
00137     tpport_t port = atoi(argv[2]);
00138     if ( ima.isInetAddress() ) {
00139         foo = new Listener(ima,port);
00140         cout << "Listening on multicast address " << ima << ":" <<
00141             port << endl;
00142     } else {
00143         InetHostAddress ia(argv[1]);
00144         foo = new Listener(ia,atoi(argv[2]));
00145         cout << "Listening on unicast address " << ia << ":" <<
00146             port << endl;
00147     }
00148     cout << "Press Ctrl-C to finish." << endl;
00149     foo->listen();
00150     delete foo;
00151     return 0;
00152 }
00153 

Generated on 14 Aug 2013 for ccRTP by  doxygen 1.4.7