22 typedef std::vector<std::pair<size_t, uint8_t*>> buf_vec;
30 struct sender_statistics {
32 uint32_t sent_pkts = 0;
33 uint32_t sent_bytes = 0;
34 bool sent_rtp_packet =
false;
37 struct receiver_statistics {
39 uint32_t received_pkts = 0;
40 uint32_t dropped_pkts = 0;
41 uint32_t received_bytes = 0;
42 bool received_rtp_packet =
false;
49 uint64_t initial_ntp = 0;
50 uint32_t initial_rtp = 0;
51 uint32_t clock_rate = 0;
54 uvgrtp::clock::hrc::hrc_t sr_ts;
57 uint32_t base_seq = 0;
62 struct rtcp_participant {
63 std::shared_ptr<uvgrtp::socket> socket =
nullptr;
64 sockaddr_in address = {};
65 struct receiver_statistics stats;
67 uint32_t probation = 0;
78 struct rtcp_app_packet {
79 rtcp_app_packet(
const rtcp_app_packet& orig_packet) =
delete;
80 rtcp_app_packet(
const char* name, uint8_t subtype, uint32_t payload_len,
const uint8_t* payload);
87 const uint8_t* payload;
111 rtcp(std::shared_ptr<uvgrtp::rtp> rtp, std::string cname,
int rce_flags);
112 rtcp(std::shared_ptr<uvgrtp::rtp> rtp, std::string cname, std::shared_ptr<uvgrtp::srtcp> srtcp,
int rce_flags);
127 rtp_error_t generate_report();
133 rtp_error_t handle_incoming_packet(uint8_t *buffer,
size_t size);
167 rtp_error_t
send_app_packet(
const char *name, uint8_t subtype, uint32_t payload_len,
const uint8_t *payload);
196 std::vector<std::shared_ptr<uvgrtp::socket>>& get_sockets();
206 rtp_error_t add_participant(std::string src_addr, std::string dst_addr, uint16_t dst_port, uint16_t src_port, uint32_t clock_rate);
218 rtp_error_t reset_rtcp_state(uint32_t ssrc);
224 uint32_t get_rtcp_interval_ms()
const;
226 void set_session_bandwidth(uint32_t kbps);
229 std::vector<uint32_t> get_participants()
const;
246 void set_ts_info(uint64_t clock_start, uint32_t clock_rate, uint32_t rtp_ts_start);
274 rtp_error_t
install_sender_hook(std::function<
void(std::unique_ptr<uvgrtp::frame::rtcp_sender_report>)> sr_handler);
298 rtp_error_t
install_receiver_hook(std::function<
void(std::unique_ptr<uvgrtp::frame::rtcp_receiver_report>)> rr_handler);
322 rtp_error_t
install_sdes_hook(std::function<
void(std::unique_ptr<uvgrtp::frame::rtcp_sdes_packet>)> sdes_handler);
346 rtp_error_t
install_app_hook(std::function<
void(std::unique_ptr<uvgrtp::frame::rtcp_app_packet>)> app_handler);
350 rtp_error_t
install_sender_hook(std::function<
void(std::shared_ptr<uvgrtp::frame::rtcp_sender_report>)> sr_handler);
351 rtp_error_t
install_receiver_hook(std::function<
void(std::shared_ptr<uvgrtp::frame::rtcp_receiver_report>)> rr_handler);
352 rtp_error_t
install_sdes_hook(std::function<
void(std::shared_ptr<uvgrtp::frame::rtcp_sdes_packet>)> sdes_handler);
353 rtp_error_t
install_app_hook(std::function<
void(std::shared_ptr<uvgrtp::frame::rtcp_app_packet>)> app_handler);
367 rtp_error_t update_sender_stats(
size_t pkt_size);
370 static rtp_error_t recv_packet_handler(
void *arg,
int rce_flags,
frame::rtp_frame **out);
373 static rtp_error_t send_packet_handler_vec(
void *arg, uvgrtp::buf_vec& buffers);
376 size_t rtcp_length_in_bytes(uint16_t length);
378 void set_payload_size(
size_t mtu_size);
383 rtp_error_t set_sdes_items(
const std::vector<uvgrtp::frame::rtcp_sdes_item>& items);
385 uint32_t size_of_ready_app_packets()
const;
387 uint32_t size_of_compound_packet(uint16_t reports,
388 bool sr_packet,
bool rr_packet,
bool sdes_packet, uint32_t app_size,
bool bye_packet)
const;
391 void read_rtcp_header(
const uint8_t* buffer,
size_t& read_ptr,
393 void read_reports(
const uint8_t* buffer,
size_t& read_ptr,
size_t packet_end, uint8_t count,
394 std::vector<uvgrtp::frame::rtcp_report_block>& reports);
396 void read_ssrc(
const uint8_t* buffer,
size_t& read_ptr, uint32_t& out_ssrc);
401 rtp_error_t handle_sender_report_packet(uint8_t* buffer,
size_t& read_ptr,
size_t packet_end,
403 rtp_error_t handle_receiver_report_packet(uint8_t* buffer,
size_t& read_ptr,
size_t packet_end,
405 rtp_error_t handle_sdes_packet(uint8_t* buffer,
size_t& read_ptr,
size_t packet_end,
407 rtp_error_t handle_bye_packet(uint8_t* buffer,
size_t& read_ptr,
size_t packet_end,
409 rtp_error_t handle_app_packet(uint8_t* buffer,
size_t& read_ptr,
size_t packet_end,
412 static void rtcp_runner(
rtcp *
rtcp,
int interval);
417 bool is_participant(uint32_t ssrc)
const;
425 bool collision_detected(uint32_t ssrc,
const sockaddr_in& src_addr)
const;
428 rtp_error_t add_participant(uint32_t ssrc);
436 rtp_error_t init_participant_seq(uint32_t ssrc, uint16_t base_seq);
443 rtp_error_t update_participant_seq(uint32_t ssrc, uint16_t seq);
449 void update_rtcp_bandwidth(
size_t pkt_size);
454 void zero_stats(uvgrtp::sender_statistics *stats);
456 void zero_stats(uvgrtp::receiver_statistics *stats);
459 rtp_error_t send_rtcp_packet_to_participants(uint8_t* frame, uint32_t frame_size,
bool encrypt);
461 void free_participant(std::unique_ptr<rtcp_participant> participant);
463 void cleanup_participants();
466 std::shared_ptr<uvgrtp::srtcp> srtcp_;
488 size_t rtcp_bandwidth_;
500 size_t avg_rtcp_pkt_pize_;
504 size_t rtcp_pkt_count_;
505 size_t rtcp_byte_count_;
508 uint32_t rtcp_pkt_sent_count_;
515 const uint32_t ssrc_;
518 uint64_t clock_start_;
521 uint32_t clock_rate_;
524 uint32_t rtp_ts_start_;
526 std::map<uint32_t, std::unique_ptr<rtcp_participant>> participants_;
527 uint8_t num_receivers_;
530 struct sender_statistics our_stats;
534 std::vector<std::unique_ptr<rtcp_participant>> initial_participants_;
540 std::vector<std::shared_ptr<uvgrtp::socket>> sockets_;
547 std::function<void(std::shared_ptr<uvgrtp::frame::rtcp_sender_report>)> sr_hook_f_;
548 std::function<void(std::unique_ptr<uvgrtp::frame::rtcp_sender_report>)> sr_hook_u_;
549 std::function<void(std::shared_ptr<uvgrtp::frame::rtcp_receiver_report>)> rr_hook_f_;
550 std::function<void(std::unique_ptr<uvgrtp::frame::rtcp_receiver_report>)> rr_hook_u_;
551 std::function<void(std::shared_ptr<uvgrtp::frame::rtcp_sdes_packet>)> sdes_hook_f_;
552 std::function<void(std::unique_ptr<uvgrtp::frame::rtcp_sdes_packet>)> sdes_hook_u_;
553 std::function<void(std::shared_ptr<uvgrtp::frame::rtcp_app_packet>)> app_hook_f_;
554 std::function<void(std::unique_ptr<uvgrtp::frame::rtcp_app_packet>)> app_hook_u_;
556 std::mutex sr_mutex_;
557 std::mutex rr_mutex_;
558 std::mutex sdes_mutex_;
559 std::mutex app_mutex_;
561 std::unique_ptr<std::thread> report_generator_;
563 bool is_active()
const
570 uint32_t interval_ms_;
572 std::mutex packet_mutex_;
575 std::vector<uvgrtp::frame::rtcp_sdes_item> ourItems_;
576 std::vector<uint32_t> bye_ssrcs_;
577 std::map<std::string, std::deque<rtcp_app_packet>> app_packets_;
586namespace uvg_rtp = uvgrtp;
RTCP instance handles all incoming and outgoing RTCP traffic, including report generation.
rtp_error_t install_receiver_hook(void(*hook)(uvgrtp::frame::rtcp_receiver_report *))
Install an RTCP Receiver Report hook.
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 install_receiver_hook(std::function< void(std::unique_ptr< uvgrtp::frame::rtcp_receiver_report >)> rr_handler)
Install an RTCP Receiver Report hook.
rtp_error_t send_bye_packet(std::vector< uint32_t > ssrcs)
Send an RTCP BYE packet.
rtp_error_t install_sdes_hook(std::function< void(std::unique_ptr< uvgrtp::frame::rtcp_sdes_packet >)> sdes_handler)
Install an RTCP SDES packet hook.
rtp_error_t install_sender_hook(void(*hook)(uvgrtp::frame::rtcp_sender_report *))
Install an RTCP Sender Report hook.
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 send_sdes_packet(const std::vector< uvgrtp::frame::rtcp_sdes_item > &items)
Send an RTCP SDES packet.
rtp_error_t install_app_hook(std::function< void(std::unique_ptr< uvgrtp::frame::rtcp_app_packet >)> app_handler)
Install an RTCP APP packet hook.
rtp_error_t install_sender_hook(std::function< void(std::unique_ptr< uvgrtp::frame::rtcp_sender_report >)> sr_handler)
Install an RTCP Sender Report hook.
rtp_error_t remove_all_hooks()
Remove all installed hooks for RTCP.
rtp_error_t install_app_hook(void(*hook)(uvgrtp::frame::rtcp_app_packet *))
Install an RTCP APP packet hook.
rtp_error_t install_sdes_hook(void(*hook)(uvgrtp::frame::rtcp_sdes_packet *))
Install an RTCP SDES packet hook.
See RFC 3550 section 6.4.2
See RFC 3550 section 6.4.1