ccRTP 2.1.2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
rtpsend.cpp
Go to the documentation of this file.
1 // rtpsend
2 // Send RTP packets using ccRTP.
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 
30 class Sender: public RTPSession, public TimerPort
31 {
32 public:
33  Sender(const unsigned char* data, const InetHostAddress& ia,
34  tpport_t port, uint32 tstamp, uint16 count) :
35  RTPSession(InetHostAddress("0.0.0.0")), packetsPerSecond(10)
36  {
37  uint32 timestamp = tstamp? tstamp : 0;
38 
39  cout << "My SSRC identifier is: "
40  << hex << (int)getLocalSSRC() << endl;
41 
42  defaultApplication().setSDESItem(SDESItemTypeTOOL, "rtpsend demo app.");
43  setSchedulingTimeout(10000);
44  setExpireTimeout(1000000);
45 
46  if ( !addDestination(ia,port) ) {
47  cerr << "Could not connect" << endl;
48  exit();
49  }
50 
51  setPayloadFormat(StaticPayloadFormat(sptPCMU));
52  startRunning();
53 
54  uint16 tstampInc = getCurrentRTPClockRate()/packetsPerSecond;
55  uint32 period = 1000/packetsPerSecond;
56  TimerPort::setTimer(period);
57  for ( int i = 0; i < count ; i++ ) {
58  putData(timestamp + i*tstampInc,
59  data,strlen((char *)data) + 1);
60  Thread::sleep(TimerPort::getTimer());
61  TimerPort::incTimer(period);
62  }
63  }
64 
65 private:
66  const uint16 packetsPerSecond;
67 };
68 
69 int main(int argc, char *argv[])
70 {
71  cout << "rtpsend..." << endl;
72 
73  if (argc != 6) {
74  cerr << "Syntax: " << "data host port timestamp count" << endl;
75  exit(1);
76  }
77 
78  Sender sender((unsigned char *)argv[1], InetHostAddress(argv[2]),
79  atoi(argv[3]), atoi(argv[4]), atoi(argv[5]));
80 
81  cout << "I have sent " << argv[5]
82  << " RTP packets containing \"" << argv[1]
83  << "\", with timestamp " << argv[4]
84  << " to " << argv[2] << ":" << argv[3]
85  << endl;
86  return 0;
87 }
88 
ITU-T G.711. mu-law audio 8 Khz (RFC 1890)
Definition: formats.h:75
int main(int argc, char *argv[])
Definition: rtpsend.cpp:69
const uint16 packetsPerSecond
Definition: rtpsend.cpp:66
void setSDESItem(SDESItemType item, const std::string &val)
Definition: sources.h:382
This template class adds the threading aspect to the RTPSessionBase template in one of the many possi...
Definition: rtp.h:418
Static payload format objects.
Definition: formats.h:200
Generic and audio/video profile specific RTP interface of ccRTP.
Sender(const unsigned char *data, const InetHostAddress &ia, tpport_t port, uint32 tstamp, uint16 count)
Definition: rtpsend.cpp:33
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
This class sends an RTP Packet.
Definition: rtpsend.cpp:30