multiplex: Add args for media packet handlers

This commit is contained in:
Heikki Tampio 2023-06-15 10:41:02 +03:00
parent f08f178ed3
commit 5c1af1fd2a
7 changed files with 43 additions and 37 deletions

View File

@ -633,7 +633,7 @@ bool uvgrtp::formats::h26x::is_duplicate_frame(uint32_t timestamp, uint16_t seq_
}
return false;
}
rtp_error_t uvgrtp::formats::h26x::new_packet_handler(int rce_flags, uint8_t* read_ptr, size_t size, uvgrtp::frame::rtp_frame** out)
rtp_error_t uvgrtp::formats::h26x::new_packet_handler(void* args, int rce_flags, uint8_t* read_ptr, size_t size, uvgrtp::frame::rtp_frame** out)
{
return packet_handler(rce_flags, out);
}

View File

@ -116,7 +116,7 @@ namespace uvgrtp {
* Return RTP_PKT_MODIFIED if the packet was modified but should be forwarded to other handlers
* Return RTP_GENERIC_ERROR if the packet was corrupted in some way */
rtp_error_t packet_handler(int rce_flags, frame::rtp_frame** frame);
rtp_error_t new_packet_handler(int rce_flags, uint8_t* read_ptr, size_t size, uvgrtp::frame::rtp_frame** out);
rtp_error_t new_packet_handler(void* args, int rce_flags, uint8_t* read_ptr, size_t size, uvgrtp::frame::rtp_frame** out);
protected:

View File

@ -102,10 +102,10 @@ uvgrtp::formats::media_frame_info_t *uvgrtp::formats::media::get_media_frame_inf
{
return &minfo_;
}
rtp_error_t uvgrtp::formats::media::new_packet_handler(int rce_flags, uint8_t* read_ptr, size_t size, frame::rtp_frame** out)
rtp_error_t uvgrtp::formats::media::new_packet_handler(void* args, int rce_flags, uint8_t* read_ptr, size_t size, frame::rtp_frame** out)
{
UVG_LOG_ERROR("Missing args...........");
return packet_handler(nullptr, rce_flags, out);
return packet_handler(args, rce_flags, out);
}
rtp_error_t uvgrtp::formats::media::packet_handler(void *arg, int rce_flags, uvgrtp::frame::rtp_frame **out)

View File

@ -68,7 +68,7 @@ namespace uvgrtp {
* Return RTP_PKT_MODIFIED if the packet was modified but should be forwarded to other handlers
* Return RTP_GENERIC_ERROR if the packet was corrupted in some way */
static rtp_error_t packet_handler(void *arg, int rce_flags, frame::rtp_frame **frame);
rtp_error_t new_packet_handler(int rce_flags, uint8_t* read_ptr, size_t size, frame::rtp_frame** out);
rtp_error_t new_packet_handler(void* args, int rce_flags, uint8_t* read_ptr, size_t size, frame::rtp_frame** out);
/* Return pointer to the internal frame info structure which is relayed to packet handler */
media_frame_info_t *get_media_frame_info();

View File

@ -206,30 +206,30 @@ rtp_error_t uvgrtp::media_stream::create_media(rtp_format_t fmt)
case RTP_FORMAT_H264:
{
uvgrtp::formats::h264* format_264 = new uvgrtp::formats::h264(socket_, rtp_, rce_flags_);
reception_flow_->new_install_handler(
5, remote_ssrc_,
std::bind(&uvgrtp::formats::h264::new_packet_handler, format_264, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4),
std::bind(&uvgrtp::formats::h264::frame_getter, format_264, std::placeholders::_1));
reception_flow_->new_install_handler2(
remote_ssrc_,
std::bind(&uvgrtp::formats::h264::new_packet_handler, format_264, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5),
std::bind(&uvgrtp::formats::h264::frame_getter, format_264, std::placeholders::_1), nullptr);
media_.reset(format_264);
break;
}
case RTP_FORMAT_H265:
{
uvgrtp::formats::h265* format_265 = new uvgrtp::formats::h265(socket_, rtp_, rce_flags_);
reception_flow_->new_install_handler(
5, remote_ssrc_,
std::bind(&uvgrtp::formats::h265::new_packet_handler, format_265, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4),
std::bind(&uvgrtp::formats::h265::frame_getter, format_265, std::placeholders::_1));
reception_flow_->new_install_handler2(
remote_ssrc_,
std::bind(&uvgrtp::formats::h265::new_packet_handler, format_265, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5),
std::bind(&uvgrtp::formats::h265::frame_getter, format_265, std::placeholders::_1), nullptr);
media_.reset(format_265);
break;
}
case RTP_FORMAT_H266:
{
uvgrtp::formats::h266* format_266 = new uvgrtp::formats::h266(socket_, rtp_, rce_flags_);
reception_flow_->new_install_handler(
5, remote_ssrc_,
std::bind(&uvgrtp::formats::h266::new_packet_handler, format_266, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4),
std::bind(&uvgrtp::formats::h266::frame_getter, format_266, std::placeholders::_1));
reception_flow_->new_install_handler2(
remote_ssrc_,
std::bind(&uvgrtp::formats::h266::new_packet_handler, format_266, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5),
std::bind(&uvgrtp::formats::h266::frame_getter, format_266, std::placeholders::_1), nullptr);
media_.reset(format_266);
break;
}
@ -259,10 +259,10 @@ rtp_error_t uvgrtp::media_stream::create_media(rtp_format_t fmt)
case RTP_FORMAT_VDVI:
{
media_ = std::unique_ptr<uvgrtp::formats::media>(new uvgrtp::formats::media(socket_, rtp_, rce_flags_));
reception_flow_->new_install_handler(
5, remote_ssrc_,
std::bind(&uvgrtp::formats::media::new_packet_handler, media_.get(), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4),
nullptr);
reception_flow_->new_install_handler2(
remote_ssrc_,
std::bind(&uvgrtp::formats::media::new_packet_handler, media_.get(), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5),
nullptr, media_->get_media_frame_info());
break;
}
default:
@ -320,17 +320,14 @@ rtp_error_t uvgrtp::media_stream::init()
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, std::placeholders::_4),
nullptr);
std::bind(&uvgrtp::rtp::new_packet_handler, rtp_, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
if (rce_flags_ & RCE_RTCP_MUX) {
rtcp_->set_socket(socket_);
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
);
std::bind(&uvgrtp::rtcp::new_recv_packet_handler, rtcp_, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
}
return start_components();

View File

@ -323,8 +323,7 @@ rtp_error_t uvgrtp::reception_flow::install_aux_handler(
}
rtp_error_t uvgrtp::reception_flow::new_install_handler(int type, std::shared_ptr<std::atomic<std::uint32_t>> remote_ssrc,
std::function<rtp_error_t(int, uint8_t*, size_t, frame::rtp_frame** out)> handler,
std::function<rtp_error_t(uvgrtp::frame::rtp_frame**)> getter)
std::function<rtp_error_t(int, uint8_t*, size_t, frame::rtp_frame** out)> handler)
{
switch (type) {
case 1: {
@ -343,16 +342,22 @@ rtp_error_t uvgrtp::reception_flow::new_install_handler(int type, std::shared_pt
NEW_packet_handlers_[remote_ssrc].handler_srtp = handler;
break;
}
case 5: {
NEW_packet_handlers_[remote_ssrc].handler_media = handler;
break;
}
default: {
UVG_LOG_ERROR("Invalid type, only types 1-5 are allowed");
break;
}
}
return RTP_OK;
}
rtp_error_t uvgrtp::reception_flow::new_install_handler2(std::shared_ptr<std::atomic<std::uint32_t>> remote_ssrc,
std::function<rtp_error_t(void*, int, uint8_t*, size_t, frame::rtp_frame** out)> handler,
std::function<rtp_error_t(uvgrtp::frame::rtp_frame**)> getter,
void* args)
{
NEW_packet_handlers_[remote_ssrc].handler_media = handler;
NEW_packet_handlers_[remote_ssrc].getter = getter;
NEW_packet_handlers_[remote_ssrc].args = args;
return RTP_OK;
}
@ -720,7 +725,7 @@ void uvgrtp::reception_flow::process_packet(int rce_flags)
retval = handlers->handler_rtp(rce_flags, &ptr[0], size, &frame);
if (retval == RTP_PKT_MODIFIED) {
retval = handlers->handler_media(rce_flags, &ptr[0], size, &frame);
retval = handlers->handler_media(handlers->args, rce_flags, &ptr[0], size, &frame);
if (retval == RTP_PKT_READY) {
return_frame(frame);
break;

View File

@ -68,8 +68,9 @@ namespace uvgrtp {
std::function<rtp_error_t(int, uint8_t*, size_t, frame::rtp_frame** out)> handler_rtcp;
std::function<rtp_error_t(int, uint8_t*, size_t, frame::rtp_frame** out)> handler_zrtp;
std::function<rtp_error_t(int, uint8_t*, size_t, frame::rtp_frame** out)> handler_srtp;
std::function<rtp_error_t(int, uint8_t*, size_t, frame::rtp_frame** out)> handler_media;
std::function<rtp_error_t(void*, int, uint8_t*, size_t, frame::rtp_frame** out)> handler_media;
std::function<rtp_error_t(uvgrtp::frame::rtp_frame ** out)> getter;
void* args = nullptr;
};
/* This class handles the reception processing of received RTP packets. It
@ -134,12 +135,15 @@ namespace uvgrtp {
2 rtcp
3 zrtp
4 srtp
5 media
getter can be nullptr if there is no getter (for media handlers mostly)
*/
rtp_error_t new_install_handler(int type, std::shared_ptr<std::atomic<std::uint32_t>> remote_ssrc,
std::function<rtp_error_t(int, uint8_t*, size_t, frame::rtp_frame** out)> handler,
std::function<rtp_error_t(uvgrtp::frame::rtp_frame**)> getter);
std::function<rtp_error_t(int, uint8_t*, size_t, frame::rtp_frame** out)> handler);
rtp_error_t new_install_handler2(std::shared_ptr<std::atomic<std::uint32_t>> remote_ssrc,
std::function<rtp_error_t(void*, int, uint8_t*, size_t, frame::rtp_frame** out)> handler,
std::function<rtp_error_t(uvgrtp::frame::rtp_frame**)> getter,
void* args);
/* Install auxiliary handler for the packet
*