Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 1 | // rtpsend |
| 2 | // Send RTP packets using ccRTP. |
| 3 | // Copyright (C) 2001,2002 Federico Montesino <fedemp@altern.org> |
| 4 | // |
| 5 | // This program is free software; you can redistribute it and/or modify |
| 6 | // it under the terms of the GNU General Public License as published by |
| 7 | // the Free Software Foundation; either version 2 of the License, or |
| 8 | // (at your option) any later version. |
| 9 | // |
| 10 | // This program is distributed in the hope that it will be useful, |
| 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | // GNU General Public License for more details. |
| 14 | // |
| 15 | // You should have received a copy of the GNU General Public License |
| 16 | // along with this program; if not, write to the Free Software |
| 17 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | |
| 19 | #include <cstdlib> |
| 20 | #include <ccrtp/rtp.h> |
| 21 | |
| 22 | #ifdef CCXX_NAMESPACES |
| 23 | using namespace ost; |
| 24 | using namespace std; |
| 25 | #endif |
| 26 | |
| 27 | /** |
| 28 | * @brief This class sends an RTP Packet |
| 29 | **/ |
| 30 | class Sender: public RTPSession, public TimerPort |
| 31 | { |
| 32 | public: |
| 33 | Sender(const unsigned char* data, const InetHostAddress& ia, |
| 34 | tpport_t port, uint32 tstamp, uint16 count) : |
| 35 | RTPSession(InetHostAddress("0.0.0.0")), packetsPerSecond(10) |
| 36 | { |
| 37 | uint32 timestamp = tstamp? tstamp : 0; |
| 38 | |
| 39 | cout << "My SSRC identifier is: " |
| 40 | << hex << (int)getLocalSSRC() << endl; |
| 41 | |
| 42 | defaultApplication().setSDESItem(SDESItemTypeTOOL, "rtpsend demo app."); |
| 43 | setSchedulingTimeout(10000); |
| 44 | setExpireTimeout(1000000); |
| 45 | |
| 46 | if ( !addDestination(ia,port) ) { |
| 47 | cerr << "Could not connect" << endl; |
| 48 | exit(); |
| 49 | } |
| 50 | |
| 51 | setPayloadFormat(StaticPayloadFormat(sptPCMU)); |
| 52 | startRunning(); |
| 53 | |
| 54 | uint16 tstampInc = getCurrentRTPClockRate()/packetsPerSecond; |
| 55 | uint32 period = 1000/packetsPerSecond; |
| 56 | TimerPort::setTimer(period); |
| 57 | for ( int i = 0; i < count ; i++ ) { |
| 58 | putData(timestamp + i*tstampInc, |
| 59 | data,strlen((char *)data) + 1); |
| 60 | Thread::sleep(TimerPort::getTimer()); |
| 61 | TimerPort::incTimer(period); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | private: |
| 66 | const uint16 packetsPerSecond; |
| 67 | }; |
| 68 | |
| 69 | int main(int argc, char *argv[]) |
| 70 | { |
| 71 | cout << "rtpsend..." << endl; |
| 72 | |
| 73 | if (argc != 6) { |
| 74 | cerr << "Syntax: " << "data host port timestamp count" << endl; |
| 75 | exit(1); |
| 76 | } |
| 77 | |
| 78 | Sender sender((unsigned char *)argv[1], InetHostAddress(argv[2]), |
| 79 | atoi(argv[3]), atoi(argv[4]), atoi(argv[5])); |
| 80 | |
| 81 | cout << "I have sent " << argv[5] |
| 82 | << " RTP packets containing \"" << argv[1] |
| 83 | << "\", with timestamp " << argv[4] |
| 84 | << " to " << argv[2] << ":" << argv[3] |
| 85 | << endl; |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | /** EMACS ** |
| 90 | * Local variables: |
| 91 | * mode: c++ |
| 92 | * c-basic-offset: 4 |
| 93 | * End: |
| 94 | */ |
| 95 | |
| 96 | |
| 97 | |
| 98 | |