ccRTP 2.1.2: ccrtptest.cpp Source File

ccRTP 2.1.2
ccrtptest.cpp
Go to the documentation of this file.
1 // test ccRTP functionality
2 // Copyright (C) 2004-2015 Federico Montesino Pouzols <fedemp@altern.org>
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 #include <cstdlib>
18 #include <ccrtp/rtp.h>
19 
20 #ifdef CCXX_NAMESPACES
21 using namespace ost;
22 using namespace std;
23 #endif
24 
25  class PacketsPattern
26 {
27 public:
28   inline const InetHostAddress& getDestinationAddress() const
29 { return destinationAddress; }
30 
31   inline const tpport_t getDestinationPort() const
32 { return destinationPort; }
33 
34   uint32 getPacketsNumber() const
35 { return packetsNumber; }
36 
37   const unsigned char* getPacketData(uint32 i)
38  { return data; }
39 
40   const size_t getPacketSize(uint32 i)
41  { return packetsSize; }
42 
43 private:
44   static const InetHostAddress destinationAddress;
45   static const uint16 destinationPort = 34566;
46   static const uint32 packetsNumber = 100;
47   static const uint32 packetsSize = 100;
48   static unsigned char data[65535];
49 };
50 
51 const InetHostAddress PacketsPattern::destinationAddress =
52  InetHostAddress("localhost");
53 
54 unsigned char PacketsPattern::data[65535];
55 
56  PacketsPattern pattern;
57 
58  class Test
59 {
60 public:
61  virtual int doTest() = 0;
62 };
63 
64  class SendPacketTransmissionTest : public Test, public Thread, public TimerPort
65 {
66 public:
67   void run()
68  {
69  doTest();
70  }
71 
72   int doTest()
73  {
74  // should be valid?
75  //RTPSession tx();
76  RTPSession tx(InetHostAddress("localhost"));
77  tx.setSchedulingTimeout(10000);
78  tx.setExpireTimeout(1000000);
79 
80  tx.startRunning();
81 
82  tx.setPayloadFormat(StaticPayloadFormat(sptPCMU));
83  if ( !tx.addDestination(pattern.getDestinationAddress(),
84  pattern.getDestinationPort()) ) {
85  return 1;
86  }
87 
88  // 50 packets per second (packet duration of 20ms)
89  uint32 period = 20;
90  uint16 inc = tx.getCurrentRTPClockRate()/50;
91  TimerPort::setTimer(period);
92  for ( uint32 i = 0; i < pattern.getPacketsNumber(); i++ ) {
93  tx.putData(i*inc, pattern.getPacketData(i), pattern.getPacketSize(i));
94  Thread::sleep(TimerPort::getTimer());
95  TimerPort::incTimer(period);
96  }
97  return 0;
98  }
99 };
100 
101  class RecvPacketTransmissionTest : public Test, public Thread
102 {
103 public:
104   void run()
105  {
106  doTest();
107  }
108 
109   int doTest()
110  {
111  RTPSession rx(pattern.getDestinationAddress(), pattern.getDestinationPort());
112 
113  rx.setSchedulingTimeout(10000);
114  rx.setExpireTimeout(1000000);
115 
116  rx.startRunning();
117  rx.setPayloadFormat(StaticPayloadFormat(sptPCMU));
118  // arbitrary number of loops
119  for ( int i = 0; i < 500 ; i++ ) {
120  const AppDataUnit* adu;
121  while ( (adu = rx.getData(rx.getFirstTimestamp())) ) {
122 
123  delete adu;
124  }
125  Thread::sleep(7);
126  }
127  return 0;
128  }
129 };
130 
131  class MiscTest : public Test, public Thread, public TimerPort
132 {
133   void run()
134  {
135  doTest();
136  }
137 
138   int doTest()
139  {
140  const uint32 NSESSIONS = 10;
141  RTPSession rx(pattern.getDestinationAddress(),pattern.getDestinationPort());
142  RTPSession **tx = new RTPSession* [NSESSIONS];
143  for ( uint32 i = 0; i < NSESSIONS; i++ ) {
144  tx[i] = new RTPSession(InetHostAddress("localhost"));
145  }
146  for ( uint32 i = 0; i < NSESSIONS; i++) {
147  tx[i]->setSchedulingTimeout(10000);
148  tx[i]->setExpireTimeout(1000000);
149  tx[i]->setPayloadFormat(StaticPayloadFormat(sptPCMU));
150  if ( !tx[i]->addDestination(pattern.getDestinationAddress(), pattern.getDestinationPort()) ) {
151  return 1;
152  }
153  }
154 
155  rx.setPayloadFormat(StaticPayloadFormat(sptPCMU));
156  rx.setSchedulingTimeout(5000);
157  rx.setExpireTimeout(10000000); // 10 seconds!
158  rx.startRunning();
159 
160  for ( uint32 i = 0; i < NSESSIONS; i++) {
161  tx[i]->startRunning();
162  }
163  uint32 period = 20;
164  TimerPort::setTimer(period);
165  for ( uint32 i = 0; i < pattern.getPacketsNumber(); i++ ) {
166  if ( i == 70 ) {
167  RTPApplication &app = defaultApplication();
168  app.setSDESItem(SDESItemTypeCNAME,"foo@bar");
169  }
170  for ( uint32 s = 0; s < NSESSIONS; s++) {
171  // 50 packets per second (packet duration of 20ms)
172  uint16 inc =
173  tx[s]->getCurrentRTPClockRate()/50;
174  tx[s]->putData(i*inc, pattern.getPacketData(i), pattern.getPacketSize(i));
175  }
176  Thread::sleep(TimerPort::getTimer());
177  TimerPort::incTimer(period);
178  }
179 
180  Thread::sleep(5000);
181  for ( uint32 i = 0; i < NSESSIONS; i++ ) {
182  delete tx[i];
183  }
184  RTPSession::SyncSourcesIterator it;
185  cout << "Sources of synchronization:" << endl;
186  for (it = rx.begin() ; it != rx.end(); it++) {
187  const SyncSource &s = *it;
188  cout << s.getID();
189  if ( s.isSender() )
190  cout << " (sender) ";
191  cout << s.getNetworkAddress() << ":" <<
192  s.getControlTransportPort() << "/" <<
193  s.getDataTransportPort();
194  Participant *p = s.getParticipant();
195  cout << " (" <<
196  p->getSDESItem(SDESItemTypeCNAME)
197  << ") " << endl;
198  }
199  RTPApplication &app = defaultApplication();
200  RTPApplication::ParticipantsIterator ai;
201  cout << "Participants:" << endl;
202  for ( ai = app.begin(); ai != app.end(); ai++ ) {
203  const Participant &p = *ai;
204  cout << p.getSDESItem(SDESItemTypeCNAME) << endl;
205  //cout << p.getPRIVPrefix();
206  }
207  delete[] tx;
208  return 0;
209  }
210 };
211 
212 // class TestPacketHeaders { }
213 // header extension
214 
215 // class TestRTCPTransmission { }
216 
217 // class TestMiscellaneous { }
218 
219 // Things that should be tested:
220 // extreme values (0 - big) for putData
221 // segmentation (setMaxSendSegmentSize())
222 // performance: packets/second (depending on packet size and # of participants)
223  int main(int argc, char *argv[])
224 {
225  int result = 0;
226  bool send = false;
227  bool recv = false;
228 
229  // accept as parameter if must run as --send or --recv
230  for (int i = 1; i < argc; ++i) {
231  send |= !strcmp(argv[i], "-s") or !strcmp(argv[i], "--send");
232  if ( send )
233  break;
234  recv |= !strcmp(argv[i], "-r") or !strcmp(argv[i], "--recv");
235  if ( recv )
236  break;
237  }
238 
239  // run several tests in parallel threads
240  if ( send ) {
241  SendPacketTransmissionTest tx;
242  tx.start();
243  tx.join();
244  } else if ( recv ) {
245  RecvPacketTransmissionTest rx;
246  rx.start();
247  rx.join();
248  } else {
249  MiscTest m;
250  m.start();
251  m.join();
252  }
253  exit(result);
254 }
255 
PacketsPattern::getPacketSize
const size_t getPacketSize(uint32 i)
Definition: ccrtptest.cpp:40
sptPCMU
ITU-T G.711. mu-law audio 8 Khz (RFC 1890)
Definition: formats.h:75
SyncSource::getDataTransportPort
tpport_t getDataTransportPort() const
Definition: sources.h:271
RTPApplication
An RTP application, holding identifying RTCP SDES item values.
Definition: sources.h:364
SyncSource
Synchronization source in an RTP session.
Definition: sources.h:192
AppDataUnit
Interface (envelope) to data received over RTP packets.
Definition: queuebase.h:68
SDESItemTypeCNAME
Canonical end-point identifier.
Definition: rtcppkt.h:67
RTPApplication::begin
ParticipantsIterator begin()
Definition: sources.h:445
PacketsPattern::getPacketsNumber
uint32 getPacketsNumber() const
Definition: ccrtptest.cpp:34
Test
Definition: ccrtptest.cpp:58
PacketsPattern::getDestinationAddress
const InetHostAddress & getDestinationAddress() const
Definition: ccrtptest.cpp:28
Participant
A class of objects representing remote participants (RTP applications) in a multimedia session...
Definition: sources.h:124
RTPApplication::end
ParticipantsIterator end()
Definition: sources.h:448
pattern
PacketsPattern pattern
Definition: ccrtptest.cpp:56
SingleThreadRTPSession::startRunning
void startRunning()
Activate stack and start service thread.
Definition: rtp.h:508
RTPSession
SingleThreadRTPSession RTPSession
Uses two pairs of sockets for RTP data and RTCP transmission/reception.
Definition: rtp.h:601
SyncSource::getParticipant
Participant * getParticipant() const
Get the participant this synchronization source is asociated to.
Definition: sources.h:268
PacketsPattern::getDestinationPort
const tpport_t getDestinationPort() const
Definition: ccrtptest.cpp:31
RTPApplication::setSDESItem
void setSDESItem(SDESItemType item, const std::string &val)
Definition: sources.h:382
MiscTest::doTest
int doTest()
Definition: ccrtptest.cpp:138
SyncSource::getNetworkAddress
const InetAddress & getNetworkAddress() const
Definition: sources.h:277
RTPApplication::ParticipantsIterator
Iterator through the list of participants in this session.
Definition: sources.h:401
SyncSource::getControlTransportPort
tpport_t getControlTransportPort() const
Definition: sources.h:274
PacketsPattern::getPacketData
const unsigned char * getPacketData(uint32 i)
Definition: ccrtptest.cpp:37
SyncSource::isSender
bool isSender() const
Whether this source sends RTP data packets.
Definition: sources.h:254
SingleThreadRTPSession
This template class adds the threading aspect to the RTPSessionBase template in one of the many possi...
Definition: rtp.h:418
PacketsPattern::destinationAddress
static const InetHostAddress destinationAddress
Definition: ccrtptest.cpp:44
StaticPayloadFormat
Static payload format objects.
Definition: formats.h:200
MiscTest::run
void run()
Definition: ccrtptest.cpp:133
AppDataUnit::getData
const uint8 *const getData() const
Get data as it is received in RTP packets (i.e.
Definition: queuebase.h:105
SyncSource::getID
uint32 getID() const
Definition: sources.h:257
rtp.h
Generic and audio/video profile specific RTP interface of ccRTP.
PacketsPattern::data
static unsigned char data[65535]
Definition: ccrtptest.cpp:48
defaultApplication
__EXPORT RTPApplication & defaultApplication()
Get the RTPApplication object for the "default" application (the only one used by common applications...
Definition: source.cpp:128
Participant::getSDESItem
const std::string & getSDESItem(SDESItemType type) const
Get the value of an SDES item.
Definition: sources.h:140
main
int main(int argc, char *argv[])
Definition: ccrtptest.cpp:223

Generated on Dec 15, 2017 for ccrtp-2.1.2 (*.h and *.cpp) and libzrtpcpp-2.3.4 (*.h), by   doxygen 1.8.6

AltStyle によって変換されたページ (->オリジナル) /