diff --git a/include/uvgrtp/frame.hh b/include/uvgrtp/frame.hh index 57025df..b4ee337 100644 --- a/include/uvgrtp/frame.hh +++ b/include/uvgrtp/frame.hh @@ -160,7 +160,7 @@ namespace uvgrtp { /** \brief Size of the payload in bytes. Added by uvgRTP to help process the payload. */ size_t payload_len = 0; }; - /** \brief Feedback message. See RFC 5104 section 6.1 */ + /** \brief Feedback message. See RFC 4585 section 6.1 */ struct rtcp_fb_packet { struct rtcp_header header; uint32_t sender_ssrc = 0; diff --git a/include/uvgrtp/rtcp.hh b/include/uvgrtp/rtcp.hh index 11d2f4e..58577b4 100644 --- a/include/uvgrtp/rtcp.hh +++ b/include/uvgrtp/rtcp.hh @@ -371,6 +371,18 @@ namespace uvgrtp { */ rtp_error_t install_app_hook(std::function)> app_handler); + /** + * \brief Install an RTCP FB packet hook + * + * \details This function is called when an RTCP FB (RFC 4585 section 6.1) packet is received + * + * \param app_handler C++ function pointer to the hook + * + * \retval RTP_OK on success + * \retval RTP_INVALID_VALUE If hook is nullptr + */ + rtp_error_t install_fb_hook(std::function)> fb_handler); + /// \cond DO_NOT_DOCUMENT // These have been replaced by functions with unique_ptr in them rtp_error_t install_sender_hook(std::function)> sr_handler); @@ -648,11 +660,13 @@ namespace uvgrtp { std::function)> sdes_hook_u_; std::function)> app_hook_f_; std::function)> app_hook_u_; + std::function)> fb_hook_u_; std::mutex sr_mutex_; std::mutex rr_mutex_; std::mutex sdes_mutex_; std::mutex app_mutex_; + std::mutex fb_mutex_; mutable std::mutex participants_mutex_; std::mutex send_app_mutex_; diff --git a/src/rtcp.cc b/src/rtcp.cc index 186ab0e..e21a454 100644 --- a/src/rtcp.cc +++ b/src/rtcp.cc @@ -69,6 +69,7 @@ uvgrtp::rtcp::rtcp(std::shared_ptr rtp, std::shared_ptr)> fb_handler) +{ + if (!fb_handler) + { + return RTP_INVALID_VALUE; + } + fb_mutex_.lock(); + fb_hook_u_ = fb_handler; + fb_mutex_.unlock(); + + return RTP_OK; +} + uvgrtp::frame::rtcp_sender_report* uvgrtp::rtcp::get_sender_packet(uint32_t ssrc) { std::lock_guard prtcp_lock(participants_mutex_); @@ -1613,6 +1627,12 @@ rtp_error_t uvgrtp::rtcp::handle_fb_packet(uint8_t* packet, size_t& read_ptr, { frame->fci = nullptr; } + /* The last FB packet is not saved. If we want to do that, just save it in the participants_ map. */ + fb_mutex_.lock(); + if (fb_hook_u_) { + fb_hook_u_(std::unique_ptr(frame)); + } + fb_mutex_.unlock(); return RTP_OK; }