Create RTCP for the media stream unconditionally

RTCP is used to gather session statistics and detect SSRC collisions
so all packets should be relayd to the RTCP layer for monitoring
even if RTCP packets are not being sent.

If RTCP Sender/Receiver reports are needed, RCE_RTCP should be given
when creating a media stream.
This commit is contained in:
Aaro Altonen 2020-08-06 06:12:34 +03:00
parent fb4c781233
commit d06eed5833
5 changed files with 28 additions and 28 deletions

View File

@ -157,17 +157,6 @@ namespace uvg_rtp {
* Used by session to index media streams */
uint32_t get_key();
/* Create RTCP object for this media stream
*
* "src_port" is the port where we receive RTCP reports and
* "dst_port" is the port where we send RTCP reports
*
* RTCP is destroyed automatically when the media stream is destroyed
*
* Return RTP_OK on success
* Return RTP_INITIALIZED if RTCP has already been initialized */
rtp_error_t create_rtcp(uint16_t src_port, uint16_t dst_port);
/* Get pointer to the RTCP object of the media stream
*
* This object is used to control all RTCP-related functionality

View File

@ -25,6 +25,7 @@ namespace uvg_rtp {
class rtcp : public runner {
public:
rtcp(uint32_t ssrc, bool receiver);
rtcp(uvg_rtp::rtp *rtp);
~rtcp();
/* start the RTCP runner thread
@ -143,6 +144,9 @@ 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(ssize_t size, void *packet, int flags, frame::rtp_frame **out);
private:
static void rtcp_runner(rtcp *rtcp);

View File

@ -194,7 +194,11 @@ enum RTP_CTX_ENABLE_FLAGS {
* NOTE: this flag must be coupled with at least RCE_SRTP */
RCE_SRTP_AUTHENTICATE_RTP = 1 << 13,
RCE_LAST = 1 << 14,
/* Enable RTCP for the media stream.
* If SRTP is enabled, SRTCP is used instead */
RCE_RTCP = 1 << 14,
RCE_LAST = 1 << 15,
};
/* These options are given to configuration() */

View File

@ -109,7 +109,14 @@ rtp_error_t uvg_rtp::media_stream::init()
return RTP_MEMORY_ERROR;
}
if (!(rtcp_ = new uvg_rtp::rtcp(rtp_))) {
delete rtp_;
delete pkt_dispatcher_;
return RTP_MEMORY_ERROR;
}
pkt_dispatcher_->install_handler(rtp_->packet_handler);
pkt_dispatcher_->install_handler(rtcp_->packet_handler);
switch (fmt_) {
case RTP_FORMAT_HEVC:
@ -133,6 +140,9 @@ rtp_error_t uvg_rtp::media_stream::init()
return RTP_MEMORY_ERROR;
}
if (ctx_config_.flags & RCE_RTCP)
rtcp_->start();
initialized_ = true;
return pkt_dispatcher_->start(&socket_, ctx_config_.flags);
}
@ -417,19 +427,3 @@ uvg_rtp::rtcp *uvg_rtp::media_stream::get_rtcp()
{
return rtcp_;
}
rtp_error_t uvg_rtp::media_stream::create_rtcp(uint16_t src_port, uint16_t dst_port)
{
rtp_error_t ret;
if (!(rtcp_ = new uvg_rtp::rtcp(rtp_->get_ssrc(), true)))
return RTP_MEMORY_ERROR;
if ((ret = rtcp_->add_participant(addr_, dst_port, src_port, rtp_->get_clock_rate())) != RTP_OK) {
delete rtcp_;
rtcp_ = nullptr;
return ret;
}
return rtcp_->start();
}

View File

@ -35,6 +35,10 @@ uvg_rtp::rtcp::rtcp(uint32_t ssrc, bool receiver):
zero_stats(&sender_stats);
}
uvg_rtp::rtcp::rtcp(uvg_rtp::rtp *rtp)
{
}
uvg_rtp::rtcp::~rtcp()
{
}
@ -1104,3 +1108,8 @@ void uvg_rtp::rtcp::rtcp_runner(uvg_rtp::rtcp *rtcp)
}
}
}
rtp_error_t uvg_rtp::rtcp::packet_handler(ssize_t size, void *packet, int flags, frame::rtp_frame **out)
{
return RTP_PKT_NOT_HANDLED;
}