ccRTP 2.1.2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
rtplisten.cpp
Go to the documentation of this file.
1 // rtplisten
2 // Listen for RTP packets.
3 // Copyright (C) 2001-2015 Federico Montesino <fedemp@altern.org>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 
19 #include <cstdlib>
20 #include <ccrtp/rtp.h>
21 
22 #ifdef CCXX_NAMESPACES
23 using namespace ost;
24 using namespace std;
25 #endif
26 
28 {
29 public:
30  Listener(InetMcastAddress& ima, tpport_t port) :
31  RTPSession(ima,port) {}
32 
33  Listener(InetHostAddress& ia, tpport_t port) :
34  RTPSession(ia,port) {}
35 
36  void listen()
37  {
38  cout << "My SSRC identifier is: "
39  << hex << (int)getLocalSSRC() << endl;
40 
42  "rtplisten demo app.");
43  setExpireTimeout(1000000);
44 
45  setPayloadFormat(StaticPayloadFormat(sptPCMU));
46  startRunning();
47  for (;;) {
48  const AppDataUnit* adu;
49  while ( (adu = getData(getFirstTimestamp())) ) {
50  cerr << "I got an app. data unit - "
51  << adu->getSize()
52  << " payload octets ("
53  << "pt " << (int)adu->getType()
54  << ") from "
55  << hex << (int)adu->getSource().getID()
56  << "@" << dec <<
58  << ":"
60  << endl;
61  delete adu;
62  }
63  Thread::sleep(7);
64  }
65  }
66 
67  // redefined from IncomingDataQueue
68  void onNewSyncSource(const SyncSource& src)
69  {
70  cout << "* New synchronization source: " <<
71  hex << (int)src.getID() << endl;
72  }
73 
74  // redefined from QueueRTCPManager
75  void onGotSR(SyncSource& source, SendReport& SR, uint8 blocks)
76  {
77  RTPSession::onGotSR(source,SR,blocks);
78  cout << "I got an SR RTCP report from "
79  << hex << (int)source.getID() << "@"
80  << dec
81  << source.getNetworkAddress() << ":"
82  << source.getControlTransportPort() << endl;
83  }
84 
85  // redefined from QueueRTCPManager
86  void onGotRR(SyncSource& source, RecvReport& RR, uint8 blocks)
87  {
88  RTPSession::onGotRR(source,RR,blocks);
89  cout << "I got an RR RTCP report from "
90  << hex << (int)source.getID() << "@"
91  << dec
92  << source.getNetworkAddress() << ":"
93  << source.getControlTransportPort() << endl;
94  }
95 
96  // redefined from QueueRTCPManager
97  bool onGotSDESChunk(SyncSource& source, SDESChunk& chunk, size_t len)
98  {
99  bool result = RTPSession::onGotSDESChunk(source,chunk,len);
100  cout << "I got a SDES chunk from "
101  << hex << (int)source.getID() << "@"
102  << dec
103  << source.getNetworkAddress() << ":"
104  << source.getControlTransportPort()
105  << " ("
107  << ") " << endl;
108  return result;
109  }
110 
111  void onGotGoodbye(const SyncSource& source, const std::string& reason)
112  {
113  cout << "I got a Goodbye packet from "
114  << hex << (int)source.getID() << "@"
115  << dec
116  << source.getNetworkAddress() << ":"
117  << source.getControlTransportPort() << endl;
118  cout << " Goodbye reason: \"" << reason << "\"" << endl;
119  }
120 };
121 
122 int main(int argc, char *argv[])
123 {
124  cout << "rtplisten" << endl;
125 
126  if (argc != 3) {
127  cerr << "Syntax: " << " ip port" << endl;
128  exit(1);
129  }
130 
131  InetMcastAddress ima;
132  try {
133  ima = InetMcastAddress(argv[1]);
134  } catch (...) { }
135 
136  Listener *foo;
137  tpport_t port = atoi(argv[2]);
138  if ( ima.isInetAddress() ) {
139  foo = new Listener(ima,port);
140  cout << "Listening on multicast address " << ima << ":" <<
141  port << endl;
142  } else {
143  InetHostAddress ia(argv[1]);
144  foo = new Listener(ia,atoi(argv[2]));
145  cout << "Listening on unicast address " << ia << ":" <<
146  port << endl;
147  }
148  cout << "Press Ctrl-C to finish." << endl;
149  foo->listen();
150  delete foo;
151  return 0;
152 }
153 
PayloadType getType() const
Definition: queuebase.h:94
ITU-T G.711. mu-law audio 8 Khz (RFC 1890)
Definition: formats.h:75
tpport_t getDataTransportPort() const
Definition: sources.h:271
Synchronization source in an RTP session.
Definition: sources.h:192
Interface (envelope) to data received over RTP packets.
Definition: queuebase.h:68
Canonical end-point identifier.
Definition: rtcppkt.h:67
bool onGotSDESChunk(SyncSource &source, SDESChunk &chunk, size_t len)
Definition: rtplisten.cpp:97
void onGotRR(SyncSource &source, RecvReport &RR, uint8 blocks)
Definition: rtplisten.cpp:86
void onGotSR(SyncSource &source, SendReport &SR, uint8 blocks)
Definition: rtplisten.cpp:75
void onNewSyncSource(const SyncSource &src)
Definition: rtplisten.cpp:68
void onGotGoodbye(const SyncSource &source, const std::string &reason)
Definition: rtplisten.cpp:111
Participant * getParticipant() const
Get the participant this synchronization source is asociated to.
Definition: sources.h:268
void setSDESItem(SDESItemType item, const std::string &val)
Definition: sources.h:382
Listener(InetHostAddress &ia, tpport_t port)
Definition: rtplisten.cpp:33
const InetAddress & getNetworkAddress() const
Definition: sources.h:277
tpport_t getControlTransportPort() const
Definition: sources.h:274
This template class adds the threading aspect to the RTPSessionBase template in one of the many possi...
Definition: rtp.h:418
Listener(InetMcastAddress &ima, tpport_t port)
Definition: rtplisten.cpp:30
const SyncSource & getSource() const
Definition: queuebase.h:119
size_t getSize() const
Definition: queuebase.h:112
Static payload format objects.
Definition: formats.h:200
uint32 getID() const
Definition: sources.h:257
Generic and audio/video profile specific RTP interface of ccRTP.
int main(int argc, char *argv[])
Definition: rtplisten.cpp:122
Application or tool.
Definition: rtcppkt.h:72
__EXPORT RTPApplication & defaultApplication()
Get the RTPApplication object for the "default" application (the only one used by common applications...
Definition: source.cpp:128
void listen()
Definition: rtplisten.cpp:36
const std::string & getSDESItem(SDESItemType type) const
Get the value of an SDES item.
Definition: sources.h:140