File: rtpsend.cpp

package info (click to toggle)
libccrtp 2.0.9-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,476 kB
  • sloc: sh: 10,900; cpp: 9,590; ansic: 2,567; makefile: 135
file content (98 lines) | stat: -rw-r--r-- 2,802 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// rtpsend
// Send RTP packets using ccRTP.
// Copyright (C) 2001,2002  Federico Montesino <fedemp@altern.org>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

#include <cstdlib>
#include <ccrtp/rtp.h>

#ifdef  CCXX_NAMESPACES
using namespace ost;
using namespace std;
#endif

/**
 * @brief This class sends an RTP Packet
 **/
class Sender: public RTPSession, public TimerPort
{
public:
    Sender(const unsigned char* data, const InetHostAddress& ia,
    tpport_t port, uint32 tstamp, uint16 count) :
    RTPSession(InetHostAddress("0.0.0.0")), packetsPerSecond(10)
    {
        uint32 timestamp = tstamp? tstamp : 0;

        cout << "My SSRC identifier is: "
             << hex << (int)getLocalSSRC() << endl;

        defaultApplication().setSDESItem(SDESItemTypeTOOL, "rtpsend demo app.");
        setSchedulingTimeout(10000);
        setExpireTimeout(1000000);

        if ( !addDestination(ia,port) ) {
            cerr << "Could not connect" << endl;
            exit();
        }

        setPayloadFormat(StaticPayloadFormat(sptPCMU));
        startRunning();

        uint16 tstampInc = getCurrentRTPClockRate()/packetsPerSecond;
        uint32 period = 1000/packetsPerSecond;
        TimerPort::setTimer(period);
        for ( int i = 0; i < count ; i++ ) {
            putData(timestamp + i*tstampInc,
                data,strlen((char *)data) + 1);
            Thread::sleep(TimerPort::getTimer());
            TimerPort::incTimer(period);
        }
    }

private:
    const uint16 packetsPerSecond;
};

int main(int argc, char *argv[])
{
    cout << "rtpsend..." << endl;

    if (argc != 6) {
        cerr << "Syntax: " << "data host port timestamp count" << endl;
        exit(1);
    }

    Sender sender((unsigned char *)argv[1], InetHostAddress(argv[2]),
        atoi(argv[3]), atoi(argv[4]), atoi(argv[5]));

    cout << "I have sent " << argv[5]
         << " RTP packets containing \"" << argv[1]
         << "\", with timestamp " << argv[4]
         << " to " << argv[2] << ":" << argv[3]
         << endl;
    return 0;
}

/** EMACS **
 * Local variables:
 * mode: c++
 * c-basic-offset: 4
 * End:
 */