multiplex: Handle RTCP packets in reception_flow
This commit is contained in:
parent
7441109929
commit
f2dc819cd1
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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<std::atomic<std::uint32_t>> remote_ssrc,
|
||||
packet_handler_new handler, std::function<rtp_error_t(uvgrtp::frame::rtp_frame**)> getter)
|
||||
std::function<rtp_error_t(int, uint8_t*, size_t)> handler,
|
||||
std::function<rtp_error_t(uvgrtp::frame::rtp_frame**)> 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<uvgrtp::rtcp> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<rtp_error_t(int, uint8_t*, size_t)> handler;
|
||||
std::function<rtp_error_t(uvgrtp::frame::rtp_frame ** out)> 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<std::atomic<std::uint32_t>> remote_ssrc,
|
||||
packet_handler_new handler, std::function<rtp_error_t(uvgrtp::frame::rtp_frame**)> getter);
|
||||
std::function<rtp_error_t(int, uint8_t*, size_t)> handler,
|
||||
std::function<rtp_error_t(uvgrtp::frame::rtp_frame**)> getter);
|
||||
|
||||
/* Install auxiliary handler for the packet
|
||||
*
|
||||
|
@ -288,7 +288,6 @@ namespace uvgrtp {
|
|||
std::map<std::shared_ptr<std::atomic<std::uint32_t>>, handler_new> zrtp_handlers_;
|
||||
|
||||
std::map<std::shared_ptr<std::atomic<std::uint32_t>>, handler_new> srtp_handlers_;
|
||||
std::map<std::shared_ptr<std::atomic<std::uint32_t>>, handler_new> srtcp_handlers_;
|
||||
|
||||
std::vector<Buffer> ring_buffer_;
|
||||
std::mutex ring_mutex_;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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:
|
||||
|
||||
|
|
Loading…
Reference in New Issue