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 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 

Generated on Tue Mar 11 21:11:15 2008 for ccRTP by  doxygen 1.5.1