123 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,
124 std::string cname, std::shared_ptr<uvgrtp::socketfactory> sfp,
int rce_flags);
125 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,
126 std::string cname, std::shared_ptr<uvgrtp::socketfactory> sfp, std::shared_ptr<uvgrtp::srtcp> srtcp,
int rce_flags);
141 rtp_error_t generate_report();
147 rtp_error_t handle_incoming_packet(
void* args,
int rce_flags, uint8_t* buffer,
size_t size,
frame::rtp_frame** out);
181 rtp_error_t
send_app_packet(
const char *name, uint8_t subtype, uint32_t payload_len,
const uint8_t *payload);
217 rtp_error_t add_initial_participant(uint32_t clock_rate);
229 rtp_error_t reset_rtcp_state(uint32_t ssrc);
236 uint32_t get_rtcp_interval_ms()
const;
240 void set_session_bandwidth(uint32_t kbps);
242 std::shared_ptr<uvgrtp::socket> get_socket()
const;
251 rtp_error_t set_network_addresses(std::string local_addr, std::string remote_addr,
252 uint16_t local_port, uint16_t dst_port,
bool ipv6);
255 std::vector<uint32_t> get_participants()
const;
272 void set_ts_info(uint64_t clock_start, uint32_t clock_rate, uint32_t rtp_ts_start);
300 rtp_error_t
install_sender_hook(std::function<
void(std::unique_ptr<uvgrtp::frame::rtcp_sender_report>)> sr_handler);
324 rtp_error_t
install_receiver_hook(std::function<
void(std::unique_ptr<uvgrtp::frame::rtcp_receiver_report>)> rr_handler);
348 rtp_error_t
install_sdes_hook(std::function<
void(std::unique_ptr<uvgrtp::frame::rtcp_sdes_packet>)> sdes_handler);
372 rtp_error_t
install_app_hook(std::function<
void(std::unique_ptr<uvgrtp::frame::rtcp_app_packet>)> app_handler);
376 rtp_error_t
install_sender_hook(std::function<
void(std::shared_ptr<uvgrtp::frame::rtcp_sender_report>)> sr_handler);
377 rtp_error_t
install_receiver_hook(std::function<
void(std::shared_ptr<uvgrtp::frame::rtcp_receiver_report>)> rr_handler);
378 rtp_error_t
install_sdes_hook(std::function<
void(std::shared_ptr<uvgrtp::frame::rtcp_sdes_packet>)> sdes_handler);
379 rtp_error_t
install_app_hook(std::function<
void(std::shared_ptr<uvgrtp::frame::rtcp_app_packet>)> app_handler);
392 rtp_error_t
install_send_app_hook(std::string app_name, std::function<std::unique_ptr<uint8_t[]>(uint8_t& subtype, uint32_t& payload_len)> app_sending_func);
414 rtp_error_t update_sender_stats(
size_t pkt_size);
416 void set_socket(std::shared_ptr<uvgrtp::socket> socket);
419 rtp_error_t recv_packet_handler_common(
void *arg,
int rce_flags, uint8_t* read_ptr,
size_t size,
frame::rtp_frame **out);
422 static rtp_error_t send_packet_handler_vec(
void *arg, uvgrtp::buf_vec& buffers);
425 size_t rtcp_length_in_bytes(uint16_t length);
427 void set_payload_size(
size_t mtu_size);
432 rtp_error_t set_sdes_items(
const std::vector<uvgrtp::frame::rtcp_sdes_item>& items);
434 uint32_t size_of_ready_app_packets()
const;
435 uint32_t size_of_apps_from_hook(std::vector< std::shared_ptr<rtcp_app_packet>> packets)
const;
437 uint32_t size_of_compound_packet(uint16_t reports,
438 bool sr_packet,
bool rr_packet,
bool sdes_packet, uint32_t app_size,
bool bye_packet)
const;
441 void read_rtcp_header(
const uint8_t* buffer,
size_t& read_ptr,
443 void read_reports(
const uint8_t* buffer,
size_t& read_ptr,
size_t packet_end, uint8_t count,
444 std::vector<uvgrtp::frame::rtcp_report_block>& reports);
446 void read_ssrc(
const uint8_t* buffer,
size_t& read_ptr, uint32_t& out_ssrc);
451 rtp_error_t handle_sender_report_packet(uint8_t* buffer,
size_t& read_ptr,
size_t packet_end,
453 rtp_error_t handle_receiver_report_packet(uint8_t* buffer,
size_t& read_ptr,
size_t packet_end,
455 rtp_error_t handle_sdes_packet(uint8_t* buffer,
size_t& read_ptr,
size_t packet_end,
457 rtp_error_t handle_bye_packet(uint8_t* buffer,
size_t& read_ptr,
459 rtp_error_t handle_app_packet(uint8_t* buffer,
size_t& read_ptr,
size_t packet_end,
461 rtp_error_t handle_fb_packet(uint8_t* buffer,
size_t& read_ptr,
size_t packet_end,
464 static void rtcp_runner(
rtcp *
rtcp);
469 bool is_participant(uint32_t ssrc)
const;
478 bool collision_detected(uint32_t ssrc)
const;
481 rtp_error_t add_participant(uint32_t ssrc);
489 rtp_error_t init_participant_seq(uint32_t ssrc, uint16_t base_seq);
496 rtp_error_t update_participant_seq(uint32_t ssrc, uint16_t seq);
502 void update_rtcp_bandwidth(
size_t pkt_size);
506 void update_avg_rtcp_size(uint64_t packet_size);
511 double rtcp_interval(
int members,
int senders,
512 double rtcp_bw,
bool we_sent,
double avg_rtcp_size,
bool red_min,
bool randomisation);
518 rtp_error_t remove_timeout_ssrc(uint32_t ssrc);
523 void zero_stats(uvgrtp::sender_statistics *stats);
525 void zero_stats(uvgrtp::receiver_statistics *stats);
528 rtp_error_t send_rtcp_packet_to_participants(uint8_t* frame, uint32_t frame_size,
bool encrypt);
530 void free_participant(std::unique_ptr<rtcp_participant> participant);
532 void cleanup_participants();
535 std::shared_ptr<uvgrtp::srtcp> srtcp_;
553 uint32_t total_bandwidth_;
559 double rtcp_bandwidth_;
563 uint32_t reduced_minimum_;
572 std::string local_addr_;
573 std::string remote_addr_;
574 uint16_t local_port_;
582 size_t avg_rtcp_pkt_pize_;
586 uint64_t avg_rtcp_size_;
590 size_t rtcp_pkt_count_;
591 size_t rtcp_byte_count_;
594 uint32_t rtcp_pkt_sent_count_;
601 std::shared_ptr<std::atomic_uint> ssrc_;
604 std::shared_ptr<std::atomic<uint32_t>> remote_ssrc_;
607 uint64_t clock_start_;
610 uint32_t clock_rate_;
613 uint32_t rtp_ts_start_;
615 std::map<uint32_t, std::unique_ptr<rtcp_participant>> participants_;
616 uint8_t num_receivers_;
620 sockaddr_in socket_address_;
621 sockaddr_in6 socket_address_ipv6_;
627 std::map<uint32_t, uint32_t> ms_since_last_rep_;
630 struct sender_statistics our_stats;
634 std::vector<std::unique_ptr<rtcp_participant>> initial_participants_;
643 std::function<void(std::shared_ptr<uvgrtp::frame::rtcp_sender_report>)> sr_hook_f_;
644 std::function<void(std::unique_ptr<uvgrtp::frame::rtcp_sender_report>)> sr_hook_u_;
645 std::function<void(std::shared_ptr<uvgrtp::frame::rtcp_receiver_report>)> rr_hook_f_;
646 std::function<void(std::unique_ptr<uvgrtp::frame::rtcp_receiver_report>)> rr_hook_u_;
647 std::function<void(std::shared_ptr<uvgrtp::frame::rtcp_sdes_packet>)> sdes_hook_f_;
648 std::function<void(std::unique_ptr<uvgrtp::frame::rtcp_sdes_packet>)> sdes_hook_u_;
649 std::function<void(std::shared_ptr<uvgrtp::frame::rtcp_app_packet>)> app_hook_f_;
650 std::function<void(std::unique_ptr<uvgrtp::frame::rtcp_app_packet>)> app_hook_u_;
651 std::function<void(std::unique_ptr<uvgrtp::frame::rtcp_fb_packet>)> fb_hook_u_;
653 std::mutex sr_mutex_;
654 std::mutex rr_mutex_;
655 std::mutex sdes_mutex_;
656 std::mutex app_mutex_;
657 std::mutex fb_mutex_;
658 mutable std::mutex participants_mutex_;
659 std::mutex send_app_mutex_;
661 std::unique_ptr<std::thread> report_generator_;
662 std::shared_ptr<uvgrtp::socket> rtcp_socket_;
663 std::shared_ptr<uvgrtp::socketfactory> sfp_;
664 std::shared_ptr<uvgrtp::rtcp_reader> rtcp_reader_;
666 bool is_active()
const
673 std::atomic<uint32_t> interval_ms_;
675 std::shared_ptr<uvgrtp::rtp> rtp_ptr_;
677 std::mutex packet_mutex_;
680 std::vector<uvgrtp::frame::rtcp_sdes_item> ourItems_;
681 std::vector<uint32_t> bye_ssrcs_;
683 std::map<std::string, std::deque<rtcp_app_packet>> app_packets_;
685 std::multimap<std::string, std::function <std::unique_ptr<uint8_t[]>(uint8_t& subtype, uint32_t& payload_len)>> outgoing_app_hooks_;