-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathrtp_service.h
65 lines (51 loc) · 2.12 KB
/
rtp_service.h
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
#pragma once
#include "log.h"
#include "rtp_packet.h"
#include "rtcp_packet.h"
#include "connection.h"
#include <algorithm>
#include <boost\asio.hpp>
namespace media
{
// This class provides all the socket IO and timers needed for an RTP/RTCP
// endpoint. It is bound to a boost::asio::io_service object that will be
// used for IO completion callbacks. All callbacks will be run through a
// single boost::asio::io_service::strand to ensure that operations within
// an instance of this class are synchronous (regardless of the number of
// threads bound to the io_service object).
class rtp_service
{
boost::asio::io_service::strand io_strand;
connection c1, c2;
connection* rtp;
connection* rtcp;
boost::asio::deadline_timer rtcp_timer;
bool started;
ntp_time_t ntp_start_time;
uint32_t rtp_start_time;
void stop_request_received();
public:
rtp_service(boost::asio::io_service&);
~rtp_service();
// Opens a pair of UDP sockets on the specified ports. If both are
// zero, a pair of adjacent, ephemeral ports are opened. If only one
// is zero, any available ephemeral port will be used. Otherwise,
// the ports specified will attempt to be used. If either port is
// non-zero and already in use, or no adjacent ephemeral ports could be
// allocated, an exception is thrown.
void open(const boost::asio::ip::address& iface, int& rtp_port, int& rtcp_port);
void start();
void stop();
uint32_t get_rtp_time(const ntp_time_t&);
uint32_t get_rtp_start();
void set_rtcp_peer(const boost::asio::ip::udp::endpoint&);
void set_rtp_peer(const boost::asio::ip::udp::endpoint&);
void send_rtp(rtp_packet&);
void send_rtcp(rtcp_packet&);
void receive_rtp(std::function<void(rtp_packet&)> cb);
void receive_rtcp(std::function<void(rtcp_packet&)> cb);
void start_timer(int ms, std::function<void()> cb);
void post(std::function<void()> cb);
std::string to_string();
};
}