uvgRTP 4.0.0
An open-source library for RTP/SRTP media delivery
Loading...
Searching...
No Matches
rtcp.hh
1#pragma once
2
3#include "uvgrtp/export.hh"
4#include "uvgrtp/definitions.hh"
5
6#include "clock.hh"
7#include "util.hh"
8#include "frame.hh"
9
10#ifdef _WIN32
11#include <ws2ipdef.h>
12#else
13#include <sys/socket.h>
14#include <netinet/in.h>
15#endif
16
17#include <bitset>
18#include <map>
19#include <thread>
20#include <vector>
21#include <functional>
22#include <memory>
23#include <mutex>
24#include <deque>
25#include <atomic>
26
27namespace uvgrtp {
28
30 class socketfactory;
31 class rtp;
32 class srtcp;
33 class rtcp_internal;
35
53 class UVGRTP_EXPORT rtcp {
55 friend class media_stream_internal;
57 public:
59 ~rtcp();
61
66 // the Core api suitable for shared and static library use
67
79 void set_ts_info(uint64_t clock_start, uint32_t clock_rate, uint32_t rtp_ts_start);
80
87
93 rtp_error_t clear_sdes_items();
94
104 rtp_error_t send_app_packet(const char* name, uint8_t subtype, uint32_t payload_len, const uint8_t* payload);
105
122 const char* app_name,
123 uint8_t* (*send_hook)(uint8_t* subtype, uint32_t* payload_len, void* user_arg),
124 void* user_arg
125 );
126
131 rtp_error_t remove_send_app_hook(const char* app_name);
132
139 rtp_error_t send_bye_packet(const uint32_t* ssrcs, size_t count);
140
146 rtp_error_t install_sender_hook(void (*handler)(uvgrtp::frame::rtcp_sr*));
147
153 rtp_error_t install_receiver_hook(void (*handler)(uvgrtp::frame::rtcp_rr*));
154
160 rtp_error_t install_sdes_hook(void (*handler)(uvgrtp::frame::rtcp_sdes*));
161
167 rtp_error_t install_app_hook(void (*handler)(uvgrtp::frame::rtcp_app_packet*));
168
172 rtp_error_t remove_all_hooks();
173
180
187
194
201
202
203 // End of CORE_API group
204
205#if UVGRTP_EXTENDED_API
206
219 rtp_error_t send_sdes_packet(const std::vector<uvgrtp::frame::rtcp_sdes_item>& items);
220
229 rtp_error_t send_bye_packet(const std::vector<uint32_t>& ssrcs);
230
238 rtp_error_t install_sender_hook(std::function<void(std::unique_ptr<uvgrtp::frame::rtcp_sender_report>)> sr_handler);
239
247 rtp_error_t install_receiver_hook(std::function<void(std::unique_ptr<uvgrtp::frame::rtcp_receiver_report>)> rr_handler);
248
256 rtp_error_t install_sdes_hook(std::function<void(std::unique_ptr<uvgrtp::frame::rtcp_sdes_packet>)> sdes_handler);
257
265 rtp_error_t install_app_hook(std::function<void(std::unique_ptr<uvgrtp::frame::rtcp_app_packet>)> app_handler);
266
278 rtp_error_t install_roundtrip_time_hook(std::function<void(uint32_t, uint32_t, double)> rtt_handler);
279
288 rtp_error_t install_send_app_hook(const std::string& app_name,
289 std::function<std::unique_ptr<uint8_t[]>(uint8_t& subtype, uint32_t& payload_len)> app_sending_func);
290
291 rtp_error_t remove_send_app_hook(const std::string& app_name);
292
293
294 // deprecated functions
295
296 // replaced by unique_ptr
297 [[deprecated("Replaced with unique_ptr or C-style hook functions")]]
298 rtp_error_t install_sender_hook(std::function<void(std::shared_ptr<uvgrtp::frame::rtcp_sender_report>)> sr_handler);
299
300 [[deprecated("Replaced with unique_ptr or C-style hook functions")]]
301 rtp_error_t install_receiver_hook(std::function<void(std::shared_ptr<uvgrtp::frame::rtcp_receiver_report>)> rr_handler);
302
303 [[deprecated("Replaced with unique_ptr or C-style hook functions")]]
304 rtp_error_t install_sdes_hook(std::function<void(std::shared_ptr<uvgrtp::frame::rtcp_sdes_packet>)> sdes_handler);
305
306 [[deprecated("Replaced with unique_ptr or C-style hook functions")]]
307 rtp_error_t install_app_hook(std::function<void(std::shared_ptr<uvgrtp::frame::rtcp_app_packet>)> app_handler);
308
309 // replaced by ABI-safe versions
310 [[deprecated("Use install_sender_hook(rtcp_sr*) from Core API instead")]]
311 rtp_error_t install_sender_hook(void (*hook)(uvgrtp::frame::rtcp_sender_report*));
312
313 [[deprecated("Use install_receiver_hook(rtcp_rr*) from Core API instead")]]
314 rtp_error_t install_receiver_hook(void (*hook)(uvgrtp::frame::rtcp_receiver_report*));
315
316 [[deprecated("Use install_sdes_hook(rtcp_sdes*) from Core API instead")]]
317 rtp_error_t install_sdes_hook(void (*hook)(uvgrtp::frame::rtcp_sdes_packet*));
318
319 [[deprecated("Use get_sr from Core API")]]
320 uvgrtp::frame::rtcp_sender_report* get_sender_packet(uint32_t ssrc);
321
322 [[deprecated("Use get_rr from Core API")]]
323 uvgrtp::frame::rtcp_receiver_report* get_receiver_packet(uint32_t ssrc);
324
325 [[deprecated("Use get_sdes from Core API")]]
326 uvgrtp::frame::rtcp_sdes_packet* get_sdes_packet(uint32_t ssrc);
327
328 // End of EXTENDED_API group
329#endif
330
331 private:
332
333 rtcp(std::shared_ptr<uvgrtp::rtp> rtp, std::shared_ptr<std::atomic<std::uint32_t>> ssrc, std::shared_ptr<std::atomic<uint32_t>> remote_ssrc,
334 std::string cname, std::shared_ptr<uvgrtp::socketfactory> sfp, int rce_flags);
335 rtcp(std::shared_ptr<uvgrtp::rtp> rtp, std::shared_ptr<std::atomic<std::uint32_t>> ssrc, std::shared_ptr<std::atomic<uint32_t>> remote_ssrc,
336 std::string cname, std::shared_ptr<uvgrtp::socketfactory> sfp, std::shared_ptr<uvgrtp::srtcp> srtcp, int rce_flags);
337
338
339 rtcp_internal* pimpl_;
340 };
341}
342
343namespace uvg_rtp = uvgrtp;
RTCP instance handles all incoming and outgoing RTCP traffic, including report generation.
Definition rtcp.hh:53
rtp_error_t clear_sdes_items()
Remove all SDES items previously added with add_sdes_item()
rtp_error_t send_app_packet(const char *name, uint8_t subtype, uint32_t payload_len, const uint8_t *payload)
Send an RTCP APP packet.
rtp_error_t remove_send_app_hook(const char *app_name)
Remove a previously installed APP sending hook.
uvgrtp::frame::rtcp_sr * get_sr(uint32_t ssrc)
Get sender report for given SSRC.
uvgrtp::frame::rtcp_app_packet * get_app_packet(uint32_t ssrc)
Get APP packet for given SSRC.
void set_ts_info(uint64_t clock_start, uint32_t clock_rate, uint32_t rtp_ts_start)
Provide timestamping information for RTCP.
rtp_error_t remove_all_hooks()
Remove all installed reception RTCP packet hook, but not app send hook.
rtp_error_t install_send_app_hook(const char *app_name, uint8_t *(*send_hook)(uint8_t *subtype, uint32_t *payload_len, void *user_arg), void *user_arg)
Install a hook for generating RTCP APP packets during RTCP reporting.
rtp_error_t send_bye_packet(const uint32_t *ssrcs, size_t count)
Send an RTCP BYE packet to indicate stream end.
uvgrtp::frame::rtcp_rr * get_rr(uint32_t ssrc)
Get receiver report for given SSRC.
rtp_error_t add_sdes_item(const uvgrtp::frame::rtcp_sdes_item &item)
Add an SDES item that will be included in all future RTCP SDES packets.
rtp_error_t install_app_hook(void(*handler)(uvgrtp::frame::rtcp_app_packet *))
Install a callback for incoming RTCP APP packets.
rtp_error_t install_sdes_hook(void(*handler)(uvgrtp::frame::rtcp_sdes *))
Install a callback for incoming RTCP SDES packets.
uvgrtp::frame::rtcp_sdes * get_sdes(uint32_t ssrc)
Get SDES packet for given SSRC.
rtp_error_t install_receiver_hook(void(*handler)(uvgrtp::frame::rtcp_rr *))
Install a callback for incoming RTCP Receiver Reports.
rtp_error_t install_sender_hook(void(*handler)(uvgrtp::frame::rtcp_sr *))
Install a callback for incoming RTCP Sender Reports.
rtp_error_t install_receiver_hook(std::function< void(std::unique_ptr< uvgrtp::frame::rtcp_receiver_report >)> rr_handler)
Install a C++ callback for incoming RTCP Receiver Reports.
rtp_error_t install_sdes_hook(std::function< void(std::unique_ptr< uvgrtp::frame::rtcp_sdes_packet >)> sdes_handler)
Install a C++ callback for incoming RTCP SDES packets.
rtp_error_t send_sdes_packet(const std::vector< uvgrtp::frame::rtcp_sdes_item > &items)
Send an RTCP SDES packet with full SDES items.
rtp_error_t install_app_hook(std::function< void(std::unique_ptr< uvgrtp::frame::rtcp_app_packet >)> app_handler)
Install a C++ callback for incoming RTCP APP packets.
rtp_error_t install_sender_hook(std::function< void(std::unique_ptr< uvgrtp::frame::rtcp_sender_report >)> sr_handler)
Install a C++ callback for incoming RTCP Sender Reports.
rtp_error_t install_roundtrip_time_hook(std::function< void(uint32_t, uint32_t, double)> rtt_handler)
Install an Round Trip Time hook.
rtp_error_t send_bye_packet(const std::vector< uint32_t > &ssrcs)
Send an RTCP BYE packet.
rtp_error_t install_send_app_hook(const std::string &app_name, std::function< std::unique_ptr< uint8_t[]>(uint8_t &subtype, uint32_t &payload_len)> app_sending_func)
Install a C++ hook for sending RTCP APP packets during compound report generation.
See RFC 3550 section 6.7 for details on RTCP Application Packet.
Definition frame.hh:223
See RFC 3550 section 6.4.2
Definition frame.hh:340
See RFC 3550 section 6.4.2 for details on the RTCP RR (Receiver Report).
Definition frame.hh:184
See RFC 3550 section 6.5 for details on RTCP SDES Item.
Definition frame.hh:194
See RFC 3550 section 6.5
Definition frame.hh:376
See RFC 3550 section 6.5 for details on RTCP SDES (Source Description).
Definition frame.hh:215
See RFC 3550 section 6.4.1
Definition frame.hh:352
See RFC 3550 section 6.4.1
Definition frame.hh:173