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>
19
20 #ifdef CCXX_NAMESPACES
21 using namespace ost;
22 using namespace std;
23 #endif
24
26 {
27 public:
29 { return destinationAddress; }
30
32 { return destinationPort; }
33
35 { return packetsNumber; }
36
38 { return data; }
39
41 { return packetsSize; }
42
43 private:
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
52 InetHostAddress("localhost");
53
55
57
59 {
60 public:
61 virtual int doTest() = 0;
62 };
63
65 {
66 public:
68 {
69 doTest();
70 }
71
73 {
74 // should be valid?
75 //RTPSession tx();
77 tx.setSchedulingTimeout(10000);
78 tx.setExpireTimeout(1000000);
79
81
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);
94 Thread::sleep(TimerPort::getTimer());
95 TimerPort::incTimer(period);
96 }
97 return 0;
98 }
99 };
100
102 {
103 public:
105 {
106 doTest();
107 }
108
110 {
112
113 rx.setSchedulingTimeout(10000);
114 rx.setExpireTimeout(1000000);
115
118 // arbitrary number of loops
119 for ( int i = 0; i < 500 ; i++ ) {
121 while ( (adu = rx.
getData(rx.getFirstTimestamp())) ) {
122
123 delete adu;
124 }
125 Thread::sleep(7);
126 }
127 return 0;
128 }
129 };
130
132 {
134 {
135 doTest();
136 }
137
139 {
140 const uint32 NSESSIONS = 10;
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);
151 return 1;
152 }
153 }
154
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);
166 if ( i == 70 ) {
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;
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++) {
190 cout << " (sender) ";
195 cout << " (" <<
197 << ") " << endl;
198 }
201 cout << "Participants:" << endl;
202 for ( ai = app.
begin(); ai != app.
end(); ai++ ) {
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 ) {
242 tx.start();
243 tx.join();
244 } else if ( recv ) {
246 rx.start();
247 rx.join();
248 } else {
250 m.start();
251 m.join();
252 }
253 exit(result);
254 }
255
const size_t getPacketSize(uint32 i)
ITU-T G.711. mu-law audio 8 Khz (RFC 1890)
tpport_t getDataTransportPort() const
An RTP application, holding identifying RTCP SDES item values.
Synchronization source in an RTP session.
Interface (envelope) to data received over RTP packets.
Canonical end-point identifier.
ParticipantsIterator begin()
uint32 getPacketsNumber() const
const InetHostAddress & getDestinationAddress() const
A class of objects representing remote participants (RTP applications) in a multimedia session...
ParticipantsIterator end()
void startRunning()
Activate stack and start service thread.
SingleThreadRTPSession RTPSession
Uses two pairs of sockets for RTP data and RTCP transmission/reception.
Participant * getParticipant() const
Get the participant this synchronization source is asociated to.
const tpport_t getDestinationPort() const
void setSDESItem(SDESItemType item, const std::string &val)
const InetAddress & getNetworkAddress() const
Iterator through the list of participants in this session.
tpport_t getControlTransportPort() const
const unsigned char * getPacketData(uint32 i)
bool isSender() const
Whether this source sends RTP data packets.
This template class adds the threading aspect to the RTPSessionBase template in one of the many possi...
static const InetHostAddress destinationAddress
const uint8 *const getData() const
Get data as it is received in RTP packets (i.e.
Generic and audio/video profile specific RTP interface of ccRTP.
static unsigned char data[65535]
__EXPORT RTPApplication & defaultApplication()
Get the RTPApplication object for the "default" application (the only one used by common applications...
const std::string & getSDESItem(SDESItemType type) const
Get the value of an SDES item.
int main(int argc, char *argv[])