rtpsend.cpp
#include <cstdlib>
#include <ccrtp/rtp.h>
#ifdef CCXX_NAMESPACES
using namespace ost;
using namespace std;
#endif
class Sender: public RTPSession, public TimerPort {
public:
Sender(const unsigned char* data, const InetHostAddress& ia,
tpport_t port, uint32 tstamp, uint16 count):
RTPSession(InetHostAddress("0.0.0.0")),
packetsPerSecond(10)
{
uint32 timestamp = tstamp? tstamp : 0;
cout << "My SSRC identifier is: "
<< hex << (int)getLocalSSRC() << endl;
defaultApplication().setSDESItem(SDESItemTypeTOOL,
"rtpsend demo app.");
setSchedulingTimeout(10000);
setExpireTimeout(1000000);
if ( !addDestination(ia,port) ) {
cerr << "Could not connect" << endl;
exit();
}
setPayloadFormat(StaticPayloadFormat(sptPCMU));
startRunning();
uint16 tstampInc = getCurrentRTPClockRate()/packetsPerSecond;
uint32 period = 1000/packetsPerSecond;
TimerPort::setTimer(period);
for ( int i = 0; i < count ; i++ ) {
putData(timestamp + i*tstampInc,
data,strlen((char *)data) + 1);
Thread::sleep(TimerPort::getTimer());
TimerPort::incTimer(period);
}
}
private:
const uint16 packetsPerSecond;
};
int
main(int argc, char *argv[])
{
cout << "rtpsend..." << endl;
if (argc != 6) {
cerr << "Syntax: " << "data host port timestamp count" << endl;
exit(1);
}
Sender sender((unsigned char *)argv[1], InetHostAddress(argv[2]),
atoi(argv[3]), atoi(argv[4]), atoi(argv[5]));
cout << "I have sent " << argv[5]
<< " RTP packets containing \"" << argv[1]
<< "\", with timestamp " << argv[4]
<< " to " << argv[2] << ":" << argv[3]
<< endl;
return 0;
}