#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);
}
Interface (envelope) to data received over RTP packets.
Definition queuebase.h:69
size_t getSize() const
Definition queuebase.h:112
const uint8 *const getData() const
Get data as it is received in RTP packets (i.e.
Definition queuebase.h:105
uint32 getFirstTimestamp(const SyncSource *src=NULL) const
Get timestamp of first packet waiting in the queue.
const AppDataUnit * getData(uint32 stamp, const SyncSource *src=NULL)
Retreive data from a specific timestamped packet if such a packet is currently available in the recei...
void setSchedulingTimeout(microtimeout_t to)
Set the default scheduling timeout to use when no data packets are waiting to be sent.
Definition oqueue.h:364
bool addDestination(const InetHostAddress &ia, tpport_t dataPort=DefaultRTPDataPort, tpport_t controlPort=0)
bool isActive() const
Get active connection state flag.
Definition ioqueue.h:138
bool setPayloadFormat(const PayloadFormat &pf)
Set the payload format in use, for timing and payload type identification purposes.
Definition queuebase.h:177
This template class adds the threading aspect to the RTPSessionBase template in one of the many possi...
Definition rtp.h:421
void startRunning()
Activate stack and start service thread.
Definition rtp.h:508
@ sptPCMU
ITU-T G.711. mu-law audio 8 Khz (RFC 1890)
Definition formats.h:75
SingleThreadRTPSession RTPSession
Uses two pairs of sockets for RTP data and RTCP transmission/reception.
Definition rtp.h:601
Generic and audio/video profile specific RTP interface of ccRTP.