From 8b6037fa62d69880cef133ed6d6ec482e0975f51 Mon Sep 17 00:00:00 2001 From: Heikki Tampio Date: Wed, 14 Jun 2023 09:51:35 +0300 Subject: [PATCH] multiplex: Distinguish received RTCP packets from RTP packets --- include/uvgrtp/util.hh | 2 +- src/media_stream.cc | 13 ++++++------- src/reception_flow.cc | 15 +++++++++------ src/rtcp.cc | 2 +- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/include/uvgrtp/util.hh b/include/uvgrtp/util.hh index e62749f..2e1ad70 100644 --- a/include/uvgrtp/util.hh +++ b/include/uvgrtp/util.hh @@ -275,7 +275,7 @@ enum RTP_CTX_ENABLE_FLAGS { /** Paces the sending of frame fragments within frame interval (default 1/30 s) */ RCE_PACE_FRAGMENT_SENDING = 1 << 20, - RCE_RTCP_MULTIPLEX = 1 << 21, + RCE_RTCP_MUX = 1 << 21, /// \cond DO_NOT_DOCUMENT RCE_LAST = 1 << 21 diff --git a/src/media_stream.cc b/src/media_stream.cc index 6271ce3..fab5835 100644 --- a/src/media_stream.cc +++ b/src/media_stream.cc @@ -87,7 +87,7 @@ uvgrtp::media_stream::~media_stream() sfp_->clear_port(src_port_, socket_); } } - if (rce_flags_ & RCE_RTCP_MULTIPLEX) { + if (rce_flags_ & RCE_RTCP_MUX) { reception_flow_->clear_rtcp_from_rec(remote_ssrc_); } @@ -318,7 +318,7 @@ rtp_error_t uvgrtp::media_stream::init() reception_flow_->map_handler_key(rtp_handler_key_, remote_ssrc_); reception_flow_->install_aux_handler(rtp_handler_key_, rtcp_.get(), rtcp_->recv_packet_handler, nullptr); - if (rce_flags_ & RCE_RTCP_MULTIPLEX) { + if (rce_flags_ & RCE_RTCP_MUX) { reception_flow_->map_rtcp_to_rec(remote_ssrc_, rtcp_); rtcp_->set_socket(socket_); } @@ -384,7 +384,7 @@ rtp_error_t uvgrtp::media_stream::init(std::shared_ptr zrtp) reception_flow_->install_aux_handler(rtp_handler_key_, srtp_.get(), srtp_->recv_packet_handler, nullptr); reception_flow_->install_aux_handler(rtp_handler_key_, rtcp_.get(), rtcp_->recv_packet_handler, nullptr); - if (rce_flags_ & RCE_RTCP_MULTIPLEX) { + if (rce_flags_ & RCE_RTCP_MUX) { reception_flow_->map_rtcp_to_rec(remote_ssrc_, rtcp_); rtcp_->set_socket(socket_); } @@ -437,7 +437,7 @@ rtp_error_t uvgrtp::media_stream::add_srtp_ctx(uint8_t *key, uint8_t *salt) reception_flow_->install_aux_handler(rtp_handler_key_, rtcp_.get(), rtcp_->recv_packet_handler, nullptr); reception_flow_->install_aux_handler(rtp_handler_key_, srtp_.get(), srtp_->recv_packet_handler, nullptr); - if (rce_flags_ & RCE_RTCP_MULTIPLEX) { + if (rce_flags_ & RCE_RTCP_MUX) { reception_flow_->map_rtcp_to_rec(remote_ssrc_, rtcp_); rtcp_->set_socket(socket_); } @@ -463,7 +463,7 @@ rtp_error_t uvgrtp::media_stream::start_components() } else { - if (!(rce_flags_ & RCE_RTCP_MULTIPLEX)) { + if (!(rce_flags_ & RCE_RTCP_MUX)) { rtcp_->set_network_addresses(local_address_, remote_address_, src_port_ + 1, dst_port_ + 1, ipv6_); } else { @@ -473,12 +473,11 @@ rtp_error_t uvgrtp::media_stream::start_components() bandwidth_ = get_default_bandwidth_kbps(fmt_); rtcp_->set_session_bandwidth(bandwidth_); - uint16_t rtcp_port = src_port_ + 1; std::shared_ptr rtcp_socket; std::shared_ptr rtcp_reader; - if (!(rce_flags_ & RCE_RTCP_MULTIPLEX)) { + if (!(rce_flags_ & RCE_RTCP_MUX)) { // If RTCP is not multiplexed with RTP, configure the socket for RTCP: // 1. If RTCP port is not in use -> create new socket diff --git a/src/reception_flow.cc b/src/reception_flow.cc index e5b0e49..6e06b6f 100644 --- a/src/reception_flow.cc +++ b/src/reception_flow.cc @@ -78,7 +78,7 @@ void uvgrtp::reception_flow::create_ring_buffer() uint8_t* data = new uint8_t[payload_size_]; if (data) { - ring_buffer_.push_back({data, 0}); + ring_buffer_.push_back({ data, 0, {}, {} }); } else { @@ -639,11 +639,13 @@ void uvgrtp::reception_flow::process_packet(int rce_flags) } frame = nullptr; - // rtcp packet types 200 201 202 203 204 - uint8_t pt = (uint8_t)&ptr[1]; - UVG_LOG_DEBUG("Received frame with pt %u", pt); - if (rce_flags & RCE_RTCP_MULTIPLEX) { - if ((uint8_t)&ptr[1] >= 200 && (uint8_t)&ptr[1] <= 204) { + + if (rce_flags & RCE_RTCP_MUX) { + // rtcp packet types 200 201 202 203 204 + uint8_t pt = (uint8_t)ptr[1]; + //UVG_LOG_DEBUG("Received frame with pt %u", pt); + + if (pt >= 200 && pt <= 204) { rtcp_map_mutex_.lock(); for (auto& p : rtcps_map_) { std::shared_ptr rtcp_ptr = p.second; @@ -655,6 +657,7 @@ void uvgrtp::reception_flow::process_packet(int rce_flags) } } rtcp_map_mutex_.unlock(); + break; } } diff --git a/src/rtcp.cc b/src/rtcp.cc index a395b11..a3dcd48 100644 --- a/src/rtcp.cc +++ b/src/rtcp.cc @@ -203,7 +203,7 @@ rtp_error_t uvgrtp::rtcp::start() { active_ = true; ipv6_ = sfp_->get_ipv6(); - if ((rce_flags_ & RCE_RTCP_MULTIPLEX)) { + if ((rce_flags_ & RCE_RTCP_MUX)) { if (ipv6_) { socket_address_ipv6_ = uvgrtp::socket::create_ip6_sockaddr(remote_addr_, dst_port_); }