00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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 public:
00029 Listener(InetMcastAddress& ima, tpport_t port):
00030 RTPSession(ima,port)
00031 { }
00032
00033 Listener(InetHostAddress& ia, tpport_t port):
00034 RTPSession(ia,port)
00035 { }
00036
00037 void listen()
00038 {
00039 cout << "My SSRC identifier is: "
00040 << hex << (int)getLocalSSRC() << endl;
00041
00042 defaultApplication().setSDESItem(SDESItemTypeTOOL,
00043 "rtplisten demo app.");
00044 setExpireTimeout(1000000);
00045
00046 setPayloadFormat(StaticPayloadFormat(sptPCMU));
00047 startRunning();
00048 for (;;) {
00049 const AppDataUnit* adu;
00050 while ( (adu = getData(getFirstTimestamp())) ) {
00051 cerr << "I got an app. data unit - "
00052 << adu->getSize()
00053 << " payload octets ("
00054 << "pt " << (int)adu->getType()
00055 << ") from "
00056 << hex << (int)adu->getSource().getID()
00057 << "@" << dec <<
00058 adu->getSource().getNetworkAddress()
00059 << ":"
00060 << adu->getSource().getDataTransportPort()
00061 << endl;
00062 delete adu;
00063 }
00064 Thread::sleep(7);
00065 }
00066 }
00067
00068
00069 void onNewSyncSource(const SyncSource& src)
00070 {
00071 cout << "* New synchronization source: " <<
00072 hex << (int)src.getID() << endl;
00073 }
00074
00075
00076 void
00077 onGotSR(SyncSource& source, SendReport& SR, uint8 blocks)
00078 {
00079 RTPSession::onGotSR(source,SR,blocks);
00080 cout << "I got an SR RTCP report from "
00081 << hex << (int)source.getID() << "@"
00082 << dec
00083 << source.getNetworkAddress() << ":"
00084 << source.getControlTransportPort() << endl;
00085 }
00086
00087
00088 void
00089 onGotRR(SyncSource& source, RecvReport& RR, uint8 blocks)
00090 {
00091 RTPSession::onGotRR(source,RR,blocks);
00092 cout << "I got an RR RTCP report from "
00093 << hex << (int)source.getID() << "@"
00094 << dec
00095 << source.getNetworkAddress() << ":"
00096 << source.getControlTransportPort() << endl;
00097 }
00098
00099
00100 bool
00101 onGotSDESChunk(SyncSource& source, SDESChunk& chunk, size_t len)
00102 {
00103 bool result = RTPSession::onGotSDESChunk(source,chunk,len);
00104 cout << "I got a SDES chunk from "
00105 << hex << (int)source.getID() << "@"
00106 << dec
00107 << source.getNetworkAddress() << ":"
00108 << source.getControlTransportPort()
00109 << " ("
00110 << source.getParticipant()->getSDESItem(SDESItemTypeCNAME)
00111 << ") " << endl;
00112 return result;
00113 }
00114
00115 void
00116 onGotGoodbye(const SyncSource& source, const std::string& reason)
00117 {
00118 cout << "I got a Goodbye packet from "
00119 << hex << (int)source.getID() << "@"
00120 << dec
00121 << source.getNetworkAddress() << ":"
00122 << source.getControlTransportPort() << endl;
00123 cout << " Goodbye reason: \"" << reason << "\"" << endl;
00124 }
00125 };
00126
00127 int
00128 main(int argc, char *argv[])
00129 {
00130 cout << "rtplisten" << endl;
00131
00132 if (argc != 3) {
00133 cerr << "Syntax: " << " ip port" << endl;
00134 exit(1);
00135 }
00136
00137 InetMcastAddress ima;
00138 try {
00139 ima = InetMcastAddress(argv[1]);
00140 } catch (...) { }
00141
00142 Listener *foo;
00143 tpport_t port = atoi(argv[2]);
00144 if ( ima.isInetAddress() ) {
00145 foo = new Listener(ima,port);
00146 cout << "Listening on multicast address " << ima << ":" <<
00147 port << endl;
00148 } else {
00149 InetHostAddress ia(argv[1]);
00150 foo = new Listener(ia,atoi(argv[2]));
00151 cout << "Listening on unicast address " << ia << ":" <<
00152 port << endl;
00153 }
00154 cout << "Press Ctrl-C to finish." << endl;
00155 foo->listen();
00156 delete foo;
00157 return 0;
00158 }
00159