#include <cstdio>
#include <cstdlib>
#include <audio.h>
#include <fcntl.h>
using namespace COMMONCPP_NAMESPACE;
using namespace std;
class ccRTP_AudioReceiver: public Thread
{
private:
TimerPort timerport;
int audiooutput;
public:
ccRTP_AudioReceiver() {
audiooutput=open("/dev/audio",O_WRONLY);
if( audiooutput > 0 ) {
cout << "Audio device is ready to play." << endl;
}else{
cout << "I could not open /dev/audio " << endl;
exit();
}
socket=NULL;
}
~ccRTP_AudioReceiver() {
terminate();
delete socket;
::close(audiooutput);
}
void run(void) {
InetHostAddress local_ip;
local_ip = "127.0.0.1";
if( ! local_ip ) {
cerr << ": IP address is not correct!" << endl;
exit();
}
cout << local_ip.getHostname() <<
" is going to listen to perself through " <<
local_ip << "..." << endl;
socket =
new RTPSession(local_ip,RECEIVER_BASE,0);
cerr << "The receiver could not connect.";
cout << "The RTP queue is ";
cout << "active." << endl;
else
cerr << "not active." << endl;
cout << "Waiting for audio packets..." << endl;
timerport.setTimer(PERIOD);
for( int i=0 ; true ; i++ ) {
do {
if ( NULL == adu )
Thread::sleep(5);
else cout << ".";
}
while ( (NULL == adu) || (adu->
getSize() <= 0) );
if (i==0)
Thread::sleep(20);
break;
cout << "." << flush;
Thread::sleep(timerport.getTimer());
timerport.incTimer(PERIOD);
}
}
};
int main(int argc, char *argv[])
{
cout << "This is audiorx, a simple test program for ccRTP." << endl;
cout << "I am waiting for audio packets on port " << RECEIVER_BASE
<< "." << endl;
cout << "Do you want to hear something? Run audiotx." << endl;
cout << "Strike [Enter] when you are fed up. Enjoy!." << endl;
ccRTP_AudioReceiver *receiver = new ccRTP_AudioReceiver();
receiver->start();
cin.get();
cout << endl << "That's all." << endl;
delete receiver;
exit(0);
}