Implement RTCP sender packet handler
This handler only grabs the packet size and changes the role from receiver to sender if that hasn't been done yet
This commit is contained in:
parent
49ddc269db
commit
f4024dd730
|
@ -193,8 +193,15 @@ namespace uvg_rtp {
|
|||
rtp_error_t install_sdes_hook(void (*hook)(uvg_rtp::frame::rtcp_sdes_frame *));
|
||||
rtp_error_t install_app_hook(void (*hook)(uvg_rtp::frame::rtcp_app_frame *));
|
||||
|
||||
/* Update RTCP-related session statistics */
|
||||
static rtp_error_t packet_handler(void *arg, int flags, frame::rtp_frame **out);
|
||||
/* Update RTCP-related sender statistics */
|
||||
rtp_error_t update_sender_stats(size_t pkt_size);
|
||||
|
||||
/* Update RTCP-related receiver statistics */
|
||||
static rtp_error_t recv_packet_handler(void *arg, int flags, frame::rtp_frame **out);
|
||||
|
||||
/* Update RTCP-related sender statistics */
|
||||
static rtp_error_t send_packet_handler_buf(void *arg, ssize_t len, void *buf);
|
||||
static rtp_error_t send_packet_handler_vec(void *arg, std::vector<std::pair<size_t, uint8_t *>>& buffers);
|
||||
|
||||
private:
|
||||
static void rtcp_runner(rtcp *rtcp);
|
||||
|
|
|
@ -116,8 +116,11 @@ rtp_error_t uvg_rtp::media_stream::init()
|
|||
return RTP_MEMORY_ERROR;
|
||||
}
|
||||
|
||||
socket_.install_handler(rtcp_, rtcp_->send_packet_handler_buf);
|
||||
socket_.install_handler(rtcp_, rtcp_->send_packet_handler_vec);
|
||||
|
||||
rtp_handler_key_ = pkt_dispatcher_->install_handler(rtp_->packet_handler);
|
||||
pkt_dispatcher_->install_aux_handler(rtp_handler_key_, rtcp_, rtcp_->packet_handler);
|
||||
pkt_dispatcher_->install_aux_handler(rtp_handler_key_, rtcp_, rtcp_->recv_packet_handler);
|
||||
|
||||
switch (fmt_) {
|
||||
case RTP_FORMAT_HEVC:
|
||||
|
|
31
src/rtcp.cc
31
src/rtcp.cc
|
@ -251,6 +251,17 @@ rtp_error_t uvg_rtp::rtcp::init_new_participant(uvg_rtp::frame::rtp_frame *frame
|
|||
return ret;
|
||||
}
|
||||
|
||||
rtp_error_t uvg_rtp::rtcp::update_sender_stats(size_t pkt_size)
|
||||
{
|
||||
if (our_role_ == RECEIVER)
|
||||
our_role_ = SENDER;
|
||||
|
||||
our_stats.sent_pkts += 1;
|
||||
our_stats.sent_bytes += pkt_size;
|
||||
|
||||
return RTP_OK;
|
||||
}
|
||||
|
||||
rtp_error_t uvg_rtp::rtcp::init_participant_seq(uint32_t ssrc, uint16_t base_seq)
|
||||
{
|
||||
if (participants_.find(ssrc) == participants_.end())
|
||||
|
@ -398,7 +409,7 @@ void uvg_rtp::rtcp::update_session_statistics(uvg_rtp::frame::rtp_frame *frame)
|
|||
* have been received.
|
||||
* - it keeps track of participants' SSRCs and if a collision
|
||||
* is detected, the RTP context is updated */
|
||||
rtp_error_t uvg_rtp::rtcp::packet_handler(void *arg, int flags, frame::rtp_frame **out)
|
||||
rtp_error_t uvg_rtp::rtcp::recv_packet_handler(void *arg, int flags, frame::rtp_frame **out)
|
||||
{
|
||||
(void)flags;
|
||||
|
||||
|
@ -427,6 +438,24 @@ rtp_error_t uvg_rtp::rtcp::packet_handler(void *arg, int flags, frame::rtp_frame
|
|||
return RTP_PKT_NOT_HANDLED;
|
||||
}
|
||||
|
||||
rtp_error_t uvg_rtp::rtcp::send_packet_handler_buf(void *arg, ssize_t len, void *buf)
|
||||
{
|
||||
return ((uvg_rtp::rtcp *)arg)->update_sender_stats(len - uvg_rtp::frame::HEADER_SIZE_RTP);
|
||||
}
|
||||
|
||||
rtp_error_t uvg_rtp::rtcp::send_packet_handler_vec(void *arg, std::vector<std::pair<size_t, uint8_t *>>& buffers)
|
||||
{
|
||||
ssize_t pkt_size = -uvg_rtp::frame::HEADER_SIZE_RTP;
|
||||
|
||||
for (auto& buffer : buffers)
|
||||
pkt_size += buffer.first;
|
||||
|
||||
if (pkt_size < 0)
|
||||
return RTP_INVALID_VALUE;
|
||||
|
||||
return ((uvg_rtp::rtcp *)arg)->update_sender_stats(pkt_size);
|
||||
}
|
||||
|
||||
rtp_error_t uvg_rtp::rtcp::handle_incoming_packet(uint8_t *buffer, size_t size)
|
||||
{
|
||||
(void)size;
|
||||
|
|
Loading…
Reference in New Issue