#include <cstdio>
#include <cstdlib>
#include <audio.h>
#include <fcntl.h>
using namespace ost;
using namespace std;
#ifndef O_NDELAY
#define O_NDELAY 0
#endif
class ccRTP_AudioTransmitter: public Thread
{
private:
TimerPort timerport;
int audioinput;
bool sendingfile;
public:
ccRTP_AudioTransmitter(char *filename=(char *)"") {
if( !strcmp(filename,"") ) {
filename=(char *)"/dev/audio";
sendingfile = false;
}else{
sendingfile = true;
}
audioinput=open(filename,O_RDONLY|O_NDELAY);
if( audioinput >= 0 ) {
cout << "Ready to transmit " << filename << "." <<endl;
}else{
cout << "I could not open " << filename << "." << endl;
exit();
}
socket=NULL;
}
~ccRTP_AudioTransmitter() {
terminate();
delete socket;
::close(audioinput);
}
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 transmit audio to perself through " <<
local_ip << "..." << endl;
socket =
new RTPSession(local_ip,TRANSMITTER_BASE);
cerr << "I could not connect.";
cout << "The RTP queue service thread is ";
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;
timerport.setTimer(PERIOD);
for( int i = 0 ; (!sendingfile || count > 0) ; i++ ) {
count = ::read(audioinput,buffer,PACKET_SIZE);
if( count > 0 ) {
socket->
putData(PACKET_SIZE*i,buffer,
PACKET_SIZE);
}
cout << "." << flush;
Thread::sleep(timerport.getTimer());
timerport.incTimer(PERIOD);
}
cout << endl << "I have got no more data to send. " <<endl;
}
};
int main(int argc, char *argv[])
{
cout << "This is audiotx, a simple test program for ccRTP." << endl;
cout << "You should have run audiorx (the server/receiver) before." << endl;
cout << "Strike [Enter] when you are fed up. Enjoy!." << endl;
ccRTP_AudioTransmitter *transmitter;
if ( argc == 2 )
transmitter = new ccRTP_AudioTransmitter(argv[1]);
else
transmitter = new ccRTP_AudioTransmitter();
transmitter->start();
cin.get();
cout << endl << "That's all." << endl;
delete transmitter;
exit(0);
}
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)
void putData(uint32 stamp, const unsigned char *data=NULL, size_t len=0)
This is used to create a data packet in the send queue.
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.