diff --git a/include/uvgrtp/rtcp.hh b/include/uvgrtp/rtcp.hh index 21c0b64..aefb6f4 100644 --- a/include/uvgrtp/rtcp.hh +++ b/include/uvgrtp/rtcp.hh @@ -417,6 +417,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(int rce_flags, uint8_t* read_ptr, size_t size); /* 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 fab5835..9ff8f63 100644 --- a/src/media_stream.cc +++ b/src/media_stream.cc @@ -322,7 +322,19 @@ rtp_error_t uvgrtp::media_stream::init() reception_flow_->map_rtcp_to_rec(remote_ssrc_, rtcp_); rtcp_->set_socket(socket_); } - + /* + reception_flow_->new_install_handler( + 1, + remote_ssrc_, + std::bind(&uvgrtp::rtp::new_packet_handler, rtp_, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), + nullptr); + 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), + nullptr + );*/ + return start_components(); } diff --git a/src/reception_flow.cc b/src/reception_flow.cc index 4d36749..672a555 100644 --- a/src/reception_flow.cc +++ b/src/reception_flow.cc @@ -41,7 +41,6 @@ uvgrtp::reception_flow::reception_flow(bool ipv6) : rtcp_handlers_({}), zrtp_handlers_({}), srtp_handlers_({}), - srtcp_handlers_({}), ring_buffer_(), ring_read_index_(-1), // invalid first index that will increase to a valid one last_ring_write_index_(-1), @@ -327,7 +326,8 @@ rtp_error_t uvgrtp::reception_flow::install_aux_handler( } rtp_error_t uvgrtp::reception_flow::new_install_handler(int type, std::shared_ptr> remote_ssrc, - packet_handler_new handler, std::function getter) + std::function handler, + std::function getter) { handler_new pair = {handler, getter}; switch (type) { @@ -347,10 +347,6 @@ rtp_error_t uvgrtp::reception_flow::new_install_handler(int type, std::shared_pt srtp_handlers_[remote_ssrc] = { handler, getter }; break; } - case 5: { - srtcp_handlers_[remote_ssrc] = { handler, getter }; - break; - } default: { UVG_LOG_ERROR("Invalid type, only types 1-5 are allowed"); break; @@ -690,24 +686,17 @@ void uvgrtp::reception_flow::process_packet(int rce_flags) * 3. Version is 2 -> RTP packet (or SRTP) * 4. Version is 00 -> Keep-Alive/Holepuncher * 5. None of the above match -> User packet */ - + rtp_error_t retval; /* -------------------- RTCP check -------------------- */ if (rce_flags & RCE_RTCP_MUX) { uint8_t pt = (uint8_t)ptr[1]; //UVG_LOG_DEBUG("Received frame with pt %u", pt); if (pt >= 200 && pt <= 204) { - UVG_LOG_INFO("RTCP packet"); - rtcp_map_mutex_.lock(); - for (auto& p : rtcps_map_) { - std::shared_ptr rtcp_ptr = p.second; - if (current_ssrc == p.first.get()->load()) { - (void)rtcp_ptr->handle_incoming_packet(ring_buffer_[ring_read_index_].data, (size_t)ring_buffer_[ring_read_index_].read); - } - else if (p.first.get()->load() == 0) { - (void)rtcp_ptr->handle_incoming_packet(ring_buffer_[ring_read_index_].data, (size_t)ring_buffer_[ring_read_index_].read); + for (auto& p : rtcp_handlers_) { + if (p.first.get()->load() == current_ssrc) { + retval = p.second.handler(rce_flags, &ptr[0], (size_t)ring_buffer_[ring_read_index_].read); } } - rtcp_map_mutex_.unlock(); break; } } diff --git a/src/reception_flow.hh b/src/reception_flow.hh index 177ce1a..8fb088c 100644 --- a/src/reception_flow.hh +++ b/src/reception_flow.hh @@ -61,10 +61,10 @@ namespace uvgrtp { }; // -----------new packet handlers - typedef rtp_error_t(*packet_handler_new)(void*, int, uint8_t*, size_t); + //typedef rtp_error_t(*packet_handler_new)(void*, int, uint8_t*, size_t); struct handler_new { - packet_handler_new handler = nullptr; + std::function handler; std::function getter; }; @@ -130,11 +130,11 @@ namespace uvgrtp { 2 rtcp 3 zrtp 4 srtp - 5 srtcp 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, - packet_handler_new handler, std::function getter); + std::function handler, + std::function getter); /* Install auxiliary handler for the packet * @@ -288,7 +288,6 @@ namespace uvgrtp { std::map>, handler_new> zrtp_handlers_; std::map>, handler_new> srtp_handlers_; - std::map>, handler_new> srtcp_handlers_; std::vector ring_buffer_; std::mutex ring_mutex_; diff --git a/src/rtcp.cc b/src/rtcp.cc index a3dcd48..adfa68f 100644 --- a/src/rtcp.cc +++ b/src/rtcp.cc @@ -1031,6 +1031,13 @@ void uvgrtp::rtcp::update_session_statistics(const uvgrtp::frame::rtp_frame *fra ((double)trans_difference - participants_[frame->header.ssrc]->stats.jitter); } +rtp_error_t uvgrtp::rtcp::new_recv_packet_handler(int rce_flags, uint8_t* read_ptr, size_t size) +{ + UVG_LOG_INFO("RTCP packet handled from %u", remote_ssrc_.get()->load()); + return RTP_OK; +} + + /* RTCP packet handler is responsible for doing two things: * * - it checks whether the packet is coming from an existing user and if so, diff --git a/src/rtp.hh b/src/rtp.hh index 40d3880..9bc2b69 100644 --- a/src/rtp.hh +++ b/src/rtp.hh @@ -45,6 +45,7 @@ namespace uvgrtp { /* Validates the RTP header pointed to by "packet" */ static rtp_error_t packet_handler(ssize_t size, void *packet, int rce_flags, frame::rtp_frame **out); + rtp_error_t new_packet_handler(int rce_flags, uint8_t* read_ptr, size_t size); private: