00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <cstdio>
00030 #include <cstdlib>
00031
00032
00033 #include <ccrtp/ext.h>
00034
00035 #ifdef CCXX_NAMESPACES
00036 using namespace ost;
00037 using namespace std;
00038 #endif
00039
00044 class ccRTP_dupHello: public Thread
00045 {
00046 private:
00047
00048
00049 RTPDuplex *duplexA, *duplexB;
00050
00051 public:
00052
00053 ~ccRTP_dupHello(){
00054 terminate();
00055 delete duplexA;
00056 delete duplexB;
00057 }
00058
00059
00060 ccRTP_dupHello() : duplexA(NULL), duplexB(NULL)
00061 { }
00062
00063
00064 void run(void){
00065
00066
00067
00068
00069
00070
00071 InetHostAddress local_ip;
00072 local_ip = "127.0.0.1";
00073
00074
00075 if( ! local_ip ){
00076
00077 cerr << ": IP address is not correct!" << endl;
00078 exit();
00079 }
00080
00081 cout << local_ip.getHostname() <<
00082 " is going to talk to perself through " <<
00083 local_ip << "..." << endl;
00084
00085
00086
00087
00088
00089 const int A_BASE = 22222;
00090 const int B_BASE = 33334;
00091
00092 duplexA = new RTPDuplex(local_ip,A_BASE,B_BASE);
00093
00094 duplexB = new RTPDuplex(local_ip,B_BASE,A_BASE);
00095
00096
00097 duplexA->setSchedulingTimeout(90000);
00098 duplexA->setExpireTimeout(2500000);
00099 if( duplexA->connect(local_ip,B_BASE) < 0 )
00100 cerr << "Duplex A could not connect.";
00101
00102
00103 duplexB->setSchedulingTimeout(160000);
00104 duplexB->setExpireTimeout(3500000);
00105 if( duplexB->connect(local_ip,A_BASE) < 0 )
00106 cerr << "Duplex B could not connect.";
00107
00108
00109
00110
00111 if( duplexA->RTPDataQueue::isActive() )
00112 cout << "The queue A is active." << endl;
00113 else
00114 cerr << "The queue A is not active." << endl;
00115
00116 if( duplexB->RTPDataQueue::isActive() )
00117 cout << "The queue B is active." << endl;
00118 else
00119 cerr << "The queue B is not active." << endl;
00120
00121
00122 cout << "Transmitting..." << endl;
00123
00124
00125
00126 unsigned char helloA[] = "Hello, brave gnu world from A!";
00127 unsigned char helloB[] = "Hello, brave gnu world from B!";
00128
00129
00130 time_t sending_time;
00131 time_t receiving_time;
00132 char tmstring[30];
00133
00134 StaticPayloadFormat pf = sptMP2T;
00135 duplexA->setPayloadFormat(pf);
00136 duplexB->setPayloadFormat(pf);
00137
00138
00139
00140 for( int i = 0 ; true ; i++ ){
00141
00142
00143
00144
00145
00146
00147 sending_time = time(NULL);
00148 duplexA->putData(2*(i)*90000,helloA,
00149 strlen((char *)helloA));
00150
00151 strftime(tmstring,30,"%X",localtime(&sending_time));
00152 cout << "A: sending message at " << tmstring << "..."
00153 << endl;
00154
00155
00156 receiving_time = time(NULL);
00157 const AppDataUnit* aduA =
00158 duplexA->getData(duplexA->getFirstTimestamp());
00159 if ( aduA ) {
00160
00161 strftime(tmstring,30,"%X",localtime(&receiving_time));
00162 cout << "A:[receiving at " << tmstring << "]: " <<
00163 aduA->getData() << endl;
00164 }
00165
00166 Thread::sleep(100);
00167
00168
00169 sending_time = time(NULL);
00170 duplexB->putData(2*(i)*90000,helloB,
00171 strlen((char *)helloB));
00172
00173 strftime(tmstring,30,"%X",localtime(&sending_time));
00174 cout << "B: sending message at " << tmstring << "..."
00175 << endl;
00176
00177
00178 receiving_time = time(NULL);
00179 const AppDataUnit* aduB =
00180 duplexB->getData(duplexB->getFirstTimestamp());
00181 if ( aduB ) {
00182
00183 strftime(tmstring,30,"%X",localtime(&receiving_time));
00184 cout << "B:[receiving at " << tmstring << "]: " <<
00185 aduB->getData() << endl;
00186 }
00187
00188 Thread::sleep(1900);
00189 }
00190
00191 }
00192 };
00193
00194 int main(int argc, char *argv[])
00195 {
00196
00197 ccRTP_dupHello *hello = new ccRTP_dupHello;
00198
00199 cout << "This is rtpduphello, a very simple test program for ccRTP."
00200 << endl << "Strike [Enter] when you are fed up." << endl;
00201
00202
00203 hello->start();
00204
00205 cin.get();
00206
00207 cout << endl << "That's all" << endl;
00208
00209 delete hello;
00210
00211 exit(0);
00212 }
00213