rtpsend.cpp

00001 // rtpsend
00002 // Send RTP packets using ccRTP.
00003 // Copyright (C) 2001,2002  Federico Montesino <fedemp@altern.org>
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 2 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 

Generated on 14 Aug 2013 for ccRTP by  doxygen 1.4.7