00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <cstdlib>
00018 #include <ccrtp/rtp.h>
00019
00020 #ifdef CCXX_NAMESPACES
00021 using namespace ost;
00022 using namespace std;
00023 #endif
00024
00025 class PacketsPattern
00026 {
00027 public:
00028 inline const InetHostAddress& getDestinationAddress() const
00029 { return destinationAddress; }
00030
00031 inline const tpport_t getDestinationPort() const
00032 { return destinationPort; }
00033
00034 uint32 getPacketsNumber() const
00035 { return packetsNumber; }
00036
00037 const unsigned char* getPacketData(uint32 i)
00038 { return data; }
00039
00040 const size_t getPacketSize(uint32 i)
00041 { return packetsSize; }
00042
00043 private:
00044 static const InetHostAddress destinationAddress;
00045 static const uint16 destinationPort = 34566;
00046 static const uint32 packetsNumber = 100;
00047 static const uint32 packetsSize = 100;
00048 static unsigned char data[65535];
00049 };
00050
00051 const InetHostAddress PacketsPattern::destinationAddress =
00052 InetHostAddress("localhost");
00053
00054 unsigned char PacketsPattern::data[65535];
00055
00056 PacketsPattern pattern;
00057
00058 class Test
00059 {
00060 public:
00061 virtual int doTest() = 0;
00062 };
00063
00064 class SendPacketTransmissionTest : public Test, public Thread, public TimerPort
00065 {
00066 public:
00067 void run()
00068 {
00069 doTest();
00070 }
00071
00072 int doTest()
00073 {
00074
00075
00076 RTPSession tx(InetHostAddress("localhost"));
00077 tx.setSchedulingTimeout(10000);
00078 tx.setExpireTimeout(1000000);
00079
00080 tx.startRunning();
00081
00082 tx.setPayloadFormat(StaticPayloadFormat(sptPCMU));
00083 if ( !tx.addDestination(pattern.getDestinationAddress(),
00084 pattern.getDestinationPort()) ) {
00085 return 1;
00086 }
00087
00088
00089 uint32 period = 20;
00090 uint16 inc = tx.getCurrentRTPClockRate()/50;
00091 TimerPort::setTimer(period);
00092 for ( uint32 i = 0; i < pattern.getPacketsNumber(); i++ ) {
00093 tx.putData(i*inc, pattern.getPacketData(i), pattern.getPacketSize(i));
00094 Thread::sleep(TimerPort::getTimer());
00095 TimerPort::incTimer(period);
00096 }
00097 return 0;
00098 }
00099 };
00100
00101 class RecvPacketTransmissionTest : public Test, public Thread
00102 {
00103 public:
00104 void run()
00105 {
00106 doTest();
00107 }
00108
00109 int doTest()
00110 {
00111 RTPSession rx(pattern.getDestinationAddress(), pattern.getDestinationPort());
00112
00113 rx.setSchedulingTimeout(10000);
00114 rx.setExpireTimeout(1000000);
00115
00116 rx.startRunning();
00117 rx.setPayloadFormat(StaticPayloadFormat(sptPCMU));
00118
00119 for ( int i = 0; i < 500 ; i++ ) {
00120 const AppDataUnit* adu;
00121 while ( (adu = rx.getData(rx.getFirstTimestamp())) ) {
00122
00123 delete adu;
00124 }
00125 Thread::sleep(7);
00126 }
00127 return 0;
00128 }
00129 };
00130
00131 class MiscTest : public Test, public Thread, public TimerPort
00132 {
00133 void run()
00134 {
00135 doTest();
00136 }
00137
00138 int doTest()
00139 {
00140 const uint32 NSESSIONS = 10;
00141 RTPSession rx(pattern.getDestinationAddress(),pattern.getDestinationPort());
00142 RTPSession **tx = new RTPSession* [NSESSIONS];
00143 for ( uint32 i = 0; i < NSESSIONS; i++ ) {
00144 tx[i] = new RTPSession(InetHostAddress("localhost"));
00145 }
00146 for ( uint32 i = 0; i < NSESSIONS; i++) {
00147 tx[i]->setSchedulingTimeout(10000);
00148 tx[i]->setExpireTimeout(1000000);
00149 tx[i]->setPayloadFormat(StaticPayloadFormat(sptPCMU));
00150 if ( !tx[i]->addDestination(pattern.getDestinationAddress(), pattern.getDestinationPort()) ) {
00151 return 1;
00152 }
00153 }
00154
00155 rx.setPayloadFormat(StaticPayloadFormat(sptPCMU));
00156 rx.setSchedulingTimeout(5000);
00157 rx.setExpireTimeout(10000000);
00158 rx.startRunning();
00159
00160 for ( uint32 i = 0; i < NSESSIONS; i++) {
00161 tx[i]->startRunning();
00162 }
00163 uint32 period = 20;
00164 TimerPort::setTimer(period);
00165 for ( uint32 i = 0; i < pattern.getPacketsNumber(); i++ ) {
00166 if ( i == 70 ) {
00167 RTPApplication &app = defaultApplication();
00168 app.setSDESItem(SDESItemTypeCNAME,"foo@bar");
00169 }
00170 for ( uint32 s = 0; s < NSESSIONS; s++) {
00171
00172 uint16 inc =
00173 tx[s]->getCurrentRTPClockRate()/50;
00174 tx[s]->putData(i*inc, pattern.getPacketData(i), pattern.getPacketSize(i));
00175 }
00176 Thread::sleep(TimerPort::getTimer());
00177 TimerPort::incTimer(period);
00178 }
00179
00180 Thread::sleep(5000);
00181 for ( uint32 i = 0; i < NSESSIONS; i++ ) {
00182 delete tx[i];
00183 }
00184 RTPSession::SyncSourcesIterator it;
00185 cout << "Sources of synchronization:" << endl;
00186 for (it = rx.begin() ; it != rx.end(); it++) {
00187 const SyncSource &s = *it;
00188 cout << s.getID();
00189 if ( s.isSender() )
00190 cout << " (sender) ";
00191 cout << s.getNetworkAddress() << ":" <<
00192 s.getControlTransportPort() << "/" <<
00193 s.getDataTransportPort();
00194 Participant *p = s.getParticipant();
00195 cout << " (" <<
00196 p->getSDESItem(SDESItemTypeCNAME)
00197 << ") " << endl;
00198 }
00199 RTPApplication &app = defaultApplication();
00200 RTPApplication::ParticipantsIterator ai;
00201 cout << "Participants:" << endl;
00202 for ( ai = app.begin(); ai != app.end(); ai++ ) {
00203 const Participant &p = *ai;
00204 cout << p.getSDESItem(SDESItemTypeCNAME) << endl;
00205
00206 }
00207 delete tx;
00208 return 0;
00209 }
00210 };
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 int main(int argc, char *argv[])
00224 {
00225 int result = 0;
00226 bool send = false;
00227 bool recv = false;
00228
00229 RecvPacketTransmissionTest *rx;
00230 SendPacketTransmissionTest *tx;
00231
00232
00233
00234
00235 if ( send ) {
00236 tx = new SendPacketTransmissionTest();
00237 tx->start();
00238 tx->join();
00239 } else if ( recv ) {
00240 rx = new RecvPacketTransmissionTest();
00241 rx->start();
00242 rx->join();
00243 } else {
00244 MiscTest m;
00245 m.start();
00246 m.join();
00247 }
00248 exit(result);
00249 }
00250