rtcp: Enable installing a hook for RTCP Feedback packets

This commit is contained in:
Heikki Tampio 2023-07-31 15:56:06 +03:00
parent acba0d67fb
commit 01af435fe6
3 changed files with 35 additions and 1 deletions

View File

@ -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;

View File

@ -371,6 +371,18 @@ namespace uvgrtp {
*/
rtp_error_t install_app_hook(std::function<void(std::unique_ptr<uvgrtp::frame::rtcp_app_packet>)> 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<void(std::unique_ptr<uvgrtp::frame::rtcp_fb_packet>)> 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<void(std::shared_ptr<uvgrtp::frame::rtcp_sender_report>)> sr_handler);
@ -648,11 +660,13 @@ namespace uvgrtp {
std::function<void(std::unique_ptr<uvgrtp::frame::rtcp_sdes_packet>)> sdes_hook_u_;
std::function<void(std::shared_ptr<uvgrtp::frame::rtcp_app_packet>)> app_hook_f_;
std::function<void(std::unique_ptr<uvgrtp::frame::rtcp_app_packet>)> app_hook_u_;
std::function<void(std::unique_ptr<uvgrtp::frame::rtcp_fb_packet>)> 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_;

View File

@ -69,6 +69,7 @@ uvgrtp::rtcp::rtcp(std::shared_ptr<uvgrtp::rtp> rtp, std::shared_ptr<std::atomic
sdes_hook_u_(nullptr),
app_hook_f_(nullptr),
app_hook_u_(nullptr),
fb_hook_u_(nullptr),
sfp_(sfp),
rtcp_reader_(nullptr),
active_(false),
@ -686,6 +687,19 @@ rtp_error_t uvgrtp::rtcp::install_app_hook(std::function<void(std::unique_ptr<uv
return RTP_OK;
}
rtp_error_t uvgrtp::rtcp::install_fb_hook(std::function<void(std::unique_ptr<uvgrtp::frame::rtcp_fb_packet>)> 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<std::mutex> 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<uvgrtp::frame::rtcp_fb_packet>(frame));
}
fb_mutex_.unlock();
return RTP_OK;
}