From 744110992994d6e4e33496e64c66cdd5ac4cc78f Mon Sep 17 00:00:00 2001 From: Heikki Tampio Date: Wed, 14 Jun 2023 14:22:21 +0300 Subject: [PATCH] multiplex: Add function for installing new handlers to reception_flow --- src/reception_flow.cc | 38 ++++++++++++++++++++++++++++++++++++++ src/reception_flow.hh | 14 +++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/reception_flow.cc b/src/reception_flow.cc index 76f5f01..4d36749 100644 --- a/src/reception_flow.cc +++ b/src/reception_flow.cc @@ -37,6 +37,11 @@ uvgrtp::reception_flow::reception_flow(bool ipv6) : receiver_(nullptr), //user_hook_arg_(nullptr), //user_hook_(nullptr), + rtp_handlers_({}), + 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), @@ -321,6 +326,39 @@ rtp_error_t uvgrtp::reception_flow::install_aux_handler( return RTP_OK; } +rtp_error_t uvgrtp::reception_flow::new_install_handler(int type, std::shared_ptr> remote_ssrc, + packet_handler_new handler, std::function getter) +{ + handler_new pair = {handler, getter}; + switch (type) { + case 1: { + rtp_handlers_[remote_ssrc] = { handler, getter }; + break; + } + case 2: { + rtcp_handlers_[remote_ssrc] = { handler, getter }; + break; + } + case 3: { + zrtp_handlers_[remote_ssrc] = { handler, getter }; + break; + } + case 4: { + 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; + } + } + return RTP_OK; +} + rtp_error_t uvgrtp::reception_flow::install_aux_handler_cpp(uint32_t key, std::function handler, std::function getter) diff --git a/src/reception_flow.hh b/src/reception_flow.hh index 8ef2d1c..177ce1a 100644 --- a/src/reception_flow.hh +++ b/src/reception_flow.hh @@ -124,6 +124,18 @@ namespace uvgrtp { * Return 0 "handler" is nullptr */ uint32_t install_handler(packet_handler handler); + /* + handler types + 1 rtp + 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); + /* Install auxiliary handler for the packet * * This handler is responsible for doing auxiliary operations on the packet @@ -271,9 +283,9 @@ namespace uvgrtp { //void (*user_hook_)(void* arg, uint8_t* payload); // Map different types of handlers by remote SSRCs + std::map>, handler_new> rtp_handlers_; std::map>, handler_new> rtcp_handlers_; std::map>, handler_new> zrtp_handlers_; - std::map>, handler_new> rtp_handlers_; std::map>, handler_new> srtp_handlers_; std::map>, handler_new> srtcp_handlers_;