rtpsend.cpp
// rtpsend
// Send RTP packets using ccRTP.
// Copyright (C) 2001,2002 Federico Montesino <fedemp@altern.org>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#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;
}
OutgoingDataQueue::setSchedulingTimeout
void setSchedulingTimeout(microtimeout_t to)
Set the default scheduling timeout to use when no data packets are waiting to be sent.
Definition oqueue.h:365
OutgoingDataQueue::addDestination
bool addDestination(const InetHostAddress &ia, tpport_t dataPort=DefaultRTPDataPort, tpport_t controlPort=0)
OutgoingDataQueue::putData
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.
OutgoingDataQueue::setExpireTimeout
void setExpireTimeout(microtimeout_t to)
Set the "expired" timer for expiring packets pending in the send queue which have gone unsent and are...
Definition oqueue.h:380
RTPApplication::setSDESItem
void setSDESItem(SDESItemType item, const std::string &val)
Definition sources.h:384
RTPQueueBase::getLocalSSRC
uint32 getLocalSSRC() const
Definition queuebase.h:185
RTPQueueBase::setPayloadFormat
bool setPayloadFormat(const PayloadFormat &pf)
Set the payload format in use, for timing and payload type identification purposes.
Definition queuebase.h:178
RTPQueueBase::getCurrentRTPClockRate
uint32 getCurrentRTPClockRate() const
Get the clock rate in RTP clock units (for instance, 8000 units per second for PCMU,...
Definition queuebase.h:196
SingleThreadRTPSession::startRunning
void startRunning()
Activate stack and start service thread.
Definition rtp.h:507
StaticPayloadFormat
Static payload format objects.
Definition formats.h:202
sptPCMU
@ sptPCMU
ITU-T G.711. mu-law audio 8 Khz (RFC 1890).
Definition formats.h:76
SDESItemTypeTOOL
@ SDESItemTypeTOOL
Application or tool.
Definition rtcppkt.h:73
RTPSession
SingleThreadRTPSession RTPSession
Uses two pairs of sockets for RTP data and RTCP transmission/reception.
Definition rtp.h:600
defaultApplication
__EXPORT RTPApplication & defaultApplication()
Get the RTPApplication object for the "default" application (the only one used by common applications...
rtp.h
Generic and audio/video profile specific RTP interface of ccRTP.