// This method does almost everything. void run(void) { // redefined from Thread. // Before using ccRTP you should learn something about other // CommonC++ classes. We need InetHostAddress... // Construct loopback address InetHostAddress local_ip; local_ip = "127.0.0.1"; // Is that correct? if( ! local_ip ){ // this is equivalent to `! local_ip.isInetAddress()' cerr << ": IP address is not correct!" << endl; exit(); } cout << local_ip.getHostname() << " is going to transmit audio to perself through " << local_ip << "..." << endl; // ____Here comes the real RTP stuff____ // Construct the RTP socket. socket = new RTPSession(local_ip,TRANSMITTER_BASE); // Set up connection socket->setSchedulingTimeout(10000); if( !socket->addDestination(local_ip,RECEIVER_BASE) ) cerr << "I could not connect."; socket->setPayloadFormat(StaticPayloadFormat(sptPCMU)); socket->startRunning(); cout << "The RTP queue service thread is "; if( socket->isActive() ) cout << "active." << endl; else cerr << "not active." << endl; cout << "Transmitting " << PACKET_SIZE << " octects long packets " << "every " << PERIOD << " milliseconds..." << endl; unsigned char buffer[PACKET_SIZE]; int count=PACKET_SIZE; // This will be useful for periodic execution TimerPort::setTimer(PERIOD); setCancel(cancelImmediate); // This is the main loop, where packets are transmitted. for( int i = 0 ; (!sendingfile || count > 0) ; i++ ){ count = ::read(audioinput,buffer,PACKET_SIZE); if( count > 0 ){ // send an RTP packet, providing timestamp, // payload type and payload. socket->putData(PACKET_SIZE*i,buffer, PACKET_SIZE); } cout << "." << flush; // Let's wait for the next cycle Thread::sleep(TimerPort::getTimer()); TimerPort::incTimer(PERIOD); } cout << endl << "I have got no more data to send. " <<endl; }