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 {
00032 public:
00033 Sender(const unsigned char* data, const InetHostAddress& ia,
00034 tpport_t port, uint32 tstamp, uint16 count) :
00035 RTPSession(InetHostAddress("0.0.0.0")), 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, "rtpsend demo app.");
00043 setSchedulingTimeout(10000);
00044 setExpireTimeout(1000000);
00045
00046 if ( !addDestination(ia,port) ) {
00047 cerr << "Could not connect" << endl;
00048 exit();
00049 }
00050
00051 setPayloadFormat(StaticPayloadFormat(sptPCMU));
00052 startRunning();
00053
00054 uint16 tstampInc = getCurrentRTPClockRate()/packetsPerSecond;
00055 uint32 period = 1000/packetsPerSecond;
00056 TimerPort::setTimer(period);
00057 for ( int i = 0; i < count ; i++ ) {
00058 putData(timestamp + i*tstampInc,
00059 data,strlen((char *)data) + 1);
00060 Thread::sleep(TimerPort::getTimer());
00061 TimerPort::incTimer(period);
00062 }
00063 }
00064
00065 private:
00066 const uint16 packetsPerSecond;
00067 };
00068
00069 int main(int argc, char *argv[])
00070 {
00071 cout << "rtpsend..." << endl;
00072
00073 if (argc != 6) {
00074 cerr << "Syntax: " << "data host port timestamp count" << endl;
00075 exit(1);
00076 }
00077
00078 Sender sender((unsigned char *)argv[1], InetHostAddress(argv[2]),
00079 atoi(argv[3]), atoi(argv[4]), atoi(argv[5]));
00080
00081 cout << "I have sent " << argv[5]
00082 << " RTP packets containing \"" << argv[1]
00083 << "\", with timestamp " << argv[4]
00084 << " to " << argv[2] << ":" << argv[3]
00085 << endl;
00086 return 0;
00087 }
00088