From c14521375615e34aa44306f41b4d4e0dd0ad9ba1 Mon Sep 17 00:00:00 2001 From: Heikki Tampio Date: Thu, 15 Jun 2023 13:08:57 +0300 Subject: [PATCH] multiplex: Add RTCP common handler --- include/uvgrtp/rtcp.hh | 1 + src/media_stream.cc | 6 ++++++ src/reception_flow.cc | 12 ++++++++++-- src/reception_flow.hh | 2 ++ src/rtcp.cc | 6 +++++- 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/include/uvgrtp/rtcp.hh b/include/uvgrtp/rtcp.hh index edc1f2b..79e65d2 100644 --- a/include/uvgrtp/rtcp.hh +++ b/include/uvgrtp/rtcp.hh @@ -418,6 +418,7 @@ namespace uvgrtp { /* Update RTCP-related receiver statistics */ static rtp_error_t recv_packet_handler(void *arg, int rce_flags, frame::rtp_frame **out); rtp_error_t new_recv_packet_handler(void* args, int rce_flags, uint8_t* read_ptr, size_t size, frame::rtp_frame** out); + rtp_error_t new_recv_packet_handler_common(void* args, int rce_flags, uint8_t* read_ptr, size_t size, frame::rtp_frame** out); /* Update RTCP-related sender statistics */ static rtp_error_t send_packet_handler_vec(void *arg, uvgrtp::buf_vec& buffers); diff --git a/src/media_stream.cc b/src/media_stream.cc index baf74a3..79d8b70 100644 --- a/src/media_stream.cc +++ b/src/media_stream.cc @@ -337,6 +337,12 @@ rtp_error_t uvgrtp::media_stream::init() if (rce_flags_ & RCE_RTCP_MUX) { rtcp_->set_socket(socket_); + + reception_flow_->new_install_handler( + 6, remote_ssrc_, + std::bind(&uvgrtp::rtcp::new_recv_packet_handler_common, rtcp_, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, + std::placeholders::_4, std::placeholders::_5), rtcp_.get()); + reception_flow_->new_install_handler( 2, remote_ssrc_, std::bind(&uvgrtp::rtcp::new_recv_packet_handler, rtcp_, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, diff --git a/src/reception_flow.cc b/src/reception_flow.cc index 1804806..7be9f26 100644 --- a/src/reception_flow.cc +++ b/src/reception_flow.cc @@ -351,6 +351,11 @@ rtp_error_t uvgrtp::reception_flow::new_install_handler(int type, std::shared_pt NEW_packet_handlers_[remote_ssrc].handler_media.args = args; break; } + case 6: { + NEW_packet_handlers_[remote_ssrc].handler_rtcp_common.handler = handler; + NEW_packet_handlers_[remote_ssrc].handler_rtcp_common.args = args; + break; + } default: { UVG_LOG_ERROR("Invalid type, only types 1-5 are allowed"); break; @@ -617,7 +622,7 @@ void uvgrtp::reception_flow::process_packet(int rce_flags) /* -------------------- RTCP check -------------------- */ if (rce_flags & RCE_RTCP_MUX) { uint8_t pt = (uint8_t)ptr[1]; - //UVG_LOG_DEBUG("Received frame with pt %u", pt); + UVG_LOG_DEBUG("Received frame with pt %u", pt); if (pt >= 200 && pt <= 204) { retval = handlers->handler_rtcp.handler(nullptr, rce_flags, &ptr[0], size, &frame); break; @@ -643,7 +648,10 @@ void uvgrtp::reception_flow::process_packet(int rce_flags) if (retval == RTP_PKT_MODIFIED) { retval = handlers->handler_rtp.handler(nullptr, rce_flags, &ptr[0], size, &frame); } - + // RTCP common handler + if (rce_flags & RCE_RTCP) { + retval = handlers->handler_rtcp_common.handler(handlers->handler_rtcp_common.args, rce_flags, &ptr[0], size, &frame); + } if (retval == RTP_PKT_MODIFIED) { retval = handlers->handler_media.handler(handlers->handler_media.args, rce_flags, &ptr[0], size, &frame); if (retval == RTP_PKT_READY) { diff --git a/src/reception_flow.hh b/src/reception_flow.hh index 699b231..eed420b 100644 --- a/src/reception_flow.hh +++ b/src/reception_flow.hh @@ -73,6 +73,7 @@ namespace uvgrtp { renamethis_handler handler_zrtp; renamethis_handler handler_srtp; renamethis_handler handler_media; + renamethis_handler handler_rtcp_common; std::function getter; }; @@ -139,6 +140,7 @@ namespace uvgrtp { 3 zrtp 4 srtp 5 media + 6 rtcp common getter can be nullptr if there is no getter (for media handlers mostly) */ rtp_error_t new_install_handler(int type, std::shared_ptr> remote_ssrc, diff --git a/src/rtcp.cc b/src/rtcp.cc index 3dfd1de..74d27ab 100644 --- a/src/rtcp.cc +++ b/src/rtcp.cc @@ -1033,10 +1033,14 @@ void uvgrtp::rtcp::update_session_statistics(const uvgrtp::frame::rtp_frame *fra rtp_error_t uvgrtp::rtcp::new_recv_packet_handler(void* args, int rce_flags, uint8_t* read_ptr, size_t size, frame::rtp_frame** out) { - //UVG_LOG_INFO("RTCP packet handled from %u", remote_ssrc_.get()->load()); + UVG_LOG_INFO("RTCP packet handled from %u", remote_ssrc_.get()->load()); return handle_incoming_packet(read_ptr, size); } +rtp_error_t uvgrtp::rtcp::new_recv_packet_handler_common(void* args, int rce_flags, uint8_t* read_ptr, size_t size, frame::rtp_frame** out) +{ + return recv_packet_handler(args, rce_flags, out); +} /* RTCP packet handler is responsible for doing two things: *