00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <cstdlib>
00020 #include <ccrtp/rtp.h>
00021
00022 #ifdef CCXX_NAMESPACES
00023 using namespace ost;
00024 using namespace std;
00025 #endif
00026
00030 class Sender: public RTPSession, public TimerPort {
00031 public:
00032 Sender(const unsigned char* data, const InetHostAddress& ia,
00033 tpport_t port, uint32 tstamp, uint16 count):
00034 RTPSession(InetHostAddress("0.0.0.0")),
00035 packetsPerSecond(10)
00036 {
00037 uint32 timestamp = tstamp? tstamp : 0;
00038
00039 cout << "My SSRC identifier is: "
00040 << hex << (int)getLocalSSRC() << endl;
00041
00042 defaultApplication().setSDESItem(SDESItemTypeTOOL,
00043 "rtpsend demo app.");
00044 setSchedulingTimeout(10000);
00045 setExpireTimeout(1000000);
00046
00047 if ( !addDestination(ia,port) ) {
00048 cerr << "Could not connect" << endl;
00049 exit();
00050 }
00051
00052 setPayloadFormat(StaticPayloadFormat(sptPCMU));
00053 startRunning();
00054
00055 uint16 tstampInc = getCurrentRTPClockRate()/packetsPerSecond;
00056 uint32 period = 1000/packetsPerSecond;
00057 TimerPort::setTimer(period);
00058 for ( int i = 0; i < count ; i++ ) {
00059 putData(timestamp + i*tstampInc,
00060 data,strlen((char *)data) + 1);
00061 Thread::sleep(TimerPort::getTimer());
00062 TimerPort::incTimer(period);
00063 }
00064 }
00065
00066 private:
00067 const uint16 packetsPerSecond;
00068 };
00069
00070 int
00071 main(int argc, char *argv[])
00072 {
00073 cout << "rtpsend..." << endl;
00074
00075 if (argc != 6) {
00076 cerr << "Syntax: " << "data host port timestamp count" << endl;
00077 exit(1);
00078 }
00079
00080 Sender sender((unsigned char *)argv[1], InetHostAddress(argv[2]),
00081 atoi(argv[3]), atoi(argv[4]), atoi(argv[5]));
00082
00083 cout << "I have sent " << argv[5]
00084 << " RTP packets containing \"" << argv[1]
00085 << "\", with timestamp " << argv[4]
00086 << " to " << argv[2] << ":" << argv[3]
00087 << endl;
00088 return 0;
00089 }
00090