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 {
00055 terminate();
00056 delete duplexA;
00057 delete duplexB;
00058 }
00059
00060
00061 ccRTP_dupHello() : duplexA(NULL), duplexB(NULL)
00062 {}
00063
00064
00065 void run(void)
00066 {
00067
00068
00069
00070
00071
00072
00073 InetHostAddress local_ip;
00074 local_ip = "127.0.0.1";
00075
00076
00077 if( ! local_ip ) {
00078
00079 cerr << ": IP address is not correct!" << endl;
00080 exit();
00081 }
00082
00083 cout << local_ip.getHostname() <<
00084 " is going to talk to perself through " <<
00085 local_ip << "..." << endl;
00086
00087
00088
00089
00090
00091 const int A_BASE = 22222;
00092 const int B_BASE = 33334;
00093
00094 duplexA = new RTPDuplex(local_ip,A_BASE,B_BASE);
00095
00096 duplexB = new RTPDuplex(local_ip,B_BASE,A_BASE);
00097
00098
00099 duplexA->setSchedulingTimeout(90000);
00100 duplexA->setExpireTimeout(2500000);
00101 if( duplexA->connect(local_ip,B_BASE) < 0 )
00102 cerr << "Duplex A could not connect.";
00103
00104
00105 duplexB->setSchedulingTimeout(160000);
00106 duplexB->setExpireTimeout(3500000);
00107 if( duplexB->connect(local_ip,A_BASE) < 0 )
00108 cerr << "Duplex B could not connect.";
00109
00110
00111
00112
00113 if( duplexA->RTPDataQueue::isActive() )
00114 cout << "The queue A is active." << endl;
00115 else
00116 cerr << "The queue A is not active." << endl;
00117
00118 if( duplexB->RTPDataQueue::isActive() )
00119 cout << "The queue B is active." << endl;
00120 else
00121 cerr << "The queue B is not active." << endl;
00122
00123
00124 cout << "Transmitting..." << endl;
00125
00126
00127
00128 unsigned char helloA[] = "Hello, brave gnu world from A!";
00129 unsigned char helloB[] = "Hello, brave gnu world from B!";
00130
00131
00132 time_t sending_time;
00133 time_t receiving_time;
00134 char tmstring[30];
00135
00136 StaticPayloadFormat pf = sptMP2T;
00137 duplexA->setPayloadFormat(pf);
00138 duplexB->setPayloadFormat(pf);
00139
00140
00141
00142 for( int i = 0 ; true ; i++ ) {
00143
00144
00145
00146
00147
00148
00149 sending_time = time(NULL);
00150 duplexA->putData(2*(i)*90000,helloA,
00151 strlen((char *)helloA));
00152
00153 strftime(tmstring,30,"%X",localtime(&sending_time));
00154 cout << "A: sending message at " << tmstring << "..."
00155 << endl;
00156
00157
00158 receiving_time = time(NULL);
00159 const AppDataUnit* aduA =
00160 duplexA->getData(duplexA->getFirstTimestamp());
00161 if ( aduA ) {
00162
00163 strftime(tmstring,30,"%X",localtime(&receiving_time));
00164 cout << "A:[receiving at " << tmstring << "]: " <<
00165 aduA->getData() << endl;
00166 }
00167
00168 Thread::sleep(100);
00169
00170
00171 sending_time = time(NULL);
00172 duplexB->putData(2*(i)*90000,helloB,
00173 strlen((char *)helloB));
00174
00175 strftime(tmstring,30,"%X",localtime(&sending_time));
00176 cout << "B: sending message at " << tmstring << "..."
00177 << endl;
00178
00179
00180 receiving_time = time(NULL);
00181 const AppDataUnit* aduB =
00182 duplexB->getData(duplexB->getFirstTimestamp());
00183 if ( aduB ) {
00184
00185 strftime(tmstring,30,"%X",localtime(&receiving_time));
00186 cout << "B:[receiving at " << tmstring << "]: " <<
00187 aduB->getData() << endl;
00188 }
00189
00190 Thread::sleep(1900);
00191 }
00192
00193 }
00194 };
00195
00196 int main(int argc, char *argv[])
00197 {
00198
00199 ccRTP_dupHello *hello = new ccRTP_dupHello;
00200
00201 cout << "This is rtpduphello, a very simple test program for ccRTP."
00202 << endl << "Strike [Enter] when you are fed up." << endl;
00203
00204
00205 hello->start();
00206
00207 cin.get();
00208
00209 cout << endl << "That's all" << endl;
00210
00211 delete hello;
00212
00213 exit(0);
00214 }
00215