Add RTCP support to RTP receiver

Receiver calls RTCP after every received frame to update
session statistics
This commit is contained in:
Aaro Altonen 2020-06-18 09:32:59 +03:00
parent 73f5c4a35a
commit 5217d42814
3 changed files with 41 additions and 0 deletions

View File

@ -9,6 +9,8 @@
namespace uvg_rtp {
class rtcp;
class receiver : public runner {
public:
receiver(uvg_rtp::socket& socket, rtp_ctx_conf& conf, rtp_format_t fmt, uvg_rtp::rtp *rtp);
@ -64,6 +66,9 @@ namespace uvg_rtp {
/* Helper function for returning received RTP frames to user (just to make code look cleaner) */
void return_frame(uvg_rtp::frame::rtp_frame *frame);
/* TODO: */
rtp_error_t update_receiver_stats(uvg_rtp::frame::rtp_frame *frame);
/* TODO: */
uvg_rtp::socket& get_socket();
@ -76,8 +81,12 @@ namespace uvg_rtp {
/* Get reference to the media stream's config structure */
rtp_ctx_conf& get_conf();
/* TODO: */
void set_rtcp(uvg_rtp::rtcp *rtcp);
private:
uvg_rtp::socket socket_;
uvg_rtp::rtcp *rtcp_;
uvg_rtp::rtp *rtp_;
rtp_ctx_conf conf_;
rtp_format_t fmt_;

View File

@ -464,5 +464,8 @@ rtp_error_t uvg_rtp::media_stream::create_rtcp(uint16_t src_port, uint16_t dst_p
return ret;
}
if (receiver_)
receiver_->set_rtcp(rtcp_);
return rtcp_->start();
}

View File

@ -5,6 +5,7 @@
#include "debug.hh"
#include "frame.hh"
#include "receiver.hh"
#include "rtcp.hh"
#include "formats/hevc.hh"
#include "formats/opus.hh"
@ -13,6 +14,7 @@
uvg_rtp::receiver::receiver(uvg_rtp::socket& socket, rtp_ctx_conf& conf, rtp_format_t fmt, uvg_rtp::rtp *rtp):
socket_(socket),
rtcp_(nullptr),
rtp_(rtp),
conf_(conf),
fmt_(fmt),
@ -278,6 +280,28 @@ uvg_rtp::frame::rtp_frame *uvg_rtp::receiver::validate_rtp_frame(uint8_t *buffer
return frame;
}
rtp_error_t uvg_rtp::receiver::update_receiver_stats(uvg_rtp::frame::rtp_frame *frame)
{
rtp_error_t ret;
if (rtcp_) {
if ((ret = rtcp_->receiver_update_stats(frame)) != RTP_SSRC_COLLISION)
return ret;
/* TODO: fix ssrc collisions */
/* do { */
/* rtp_ssrc_ = kvz_rtp::random::generate_32(); */
/* } while ((rtcp_->reset_rtcp_state(rtp_ssrc_)) != RTP_OK); */
/* even though we've resolved the SSRC conflict, we still need to return an error
* code because the original packet that caused the conflict is considered "invalid" */
return RTP_INVALID_VALUE;
}
return RTP_OK;
}
uvg_rtp::socket& uvg_rtp::receiver::get_socket()
{
return socket_;
@ -297,3 +321,8 @@ rtp_ctx_conf& uvg_rtp::receiver::get_conf()
{
return conf_;
}
void uvg_rtp::receiver::set_rtcp(uvg_rtp::rtcp *rtcp)
{
rtcp_ = rtcp;
}