Create RTCP for every connection

RTCP is used for SSRC collision checking.
The actual RTCP functionality must be enabled explictly by
calling create_rtcp().

The line between packet validation and RTCP is becoming a little
blurry and a more coherent model for validation is a future task:
This commit is contained in:
Aaro Altonen 2019-08-15 09:17:39 +03:00
parent 13b401ea75
commit 5de08b2d99
4 changed files with 28 additions and 5 deletions

View File

@ -3,6 +3,7 @@
#include <unistd.h>
#endif
#include <cassert>
#include <cstring>
#include <iostream>
@ -188,10 +189,7 @@ void kvz_rtp::connection::update_rtp_sequence(uint8_t *buffer)
rtp_error_t kvz_rtp::connection::create_rtcp(std::string dst_addr, int dst_port, int src_port)
{
if ((rtcp_ = new kvz_rtp::rtcp(rtp_ssrc_, reader_)) == nullptr) {
LOG_ERROR("Failed to allocate RTCP instance!");
return RTP_MEMORY_ERROR;
}
assert(rtcp_ != nullptr);
if ((rtp_errno = rtcp_->add_participant(dst_addr, dst_port, src_port, clock_rate_)) != RTP_OK) {
LOG_ERROR("Failed to add RTCP participant!");

View File

@ -77,6 +77,11 @@ rtp_error_t kvz_rtp::reader::start()
}
runner_->detach();
if ((rtcp_ = new kvz_rtp::rtcp(get_ssrc(), true)) == nullptr) {
LOG_ERROR("Failed to allocate RTCP instance!");
return RTP_MEMORY_ERROR;
}
return RTP_OK;
}

View File

@ -23,7 +23,7 @@ kvz_rtp::rtcp::rtcp(uint32_t ssrc, bool receiver):
tp_(0), tc_(0), tn_(0), pmembers_(0),
members_(0), senders_(0), rtcp_bandwidth_(0),
we_sent_(0), avg_rtcp_pkt_pize_(0), rtcp_pkt_count_(0),
initial_(true), active_(false), num_receivers_(0)
initial_(true), active_(false), num_receivers_(0), runner_(nullptr)
{
ssrc_ = ssrc;
@ -127,6 +127,9 @@ rtp_error_t kvz_rtp::rtcp::start()
rtp_error_t kvz_rtp::rtcp::terminate()
{
if (runner_ == nullptr)
return RTP_OK;
/* when the member count is less than 50,
* we can just send the BYE message and destroy the session */
if (members_ < 50) {
@ -377,6 +380,18 @@ rtp_error_t kvz_rtp::rtcp::receiver_update_stats(kvz_rtp::frame::rtp_frame *fram
return RTP_INVALID_VALUE;
}
/* RTCP runner is not running so we don't need to do any other checks,
* just create new participant so we can check for SSRC collisions */
if (runner_ == nullptr) {
if (participants_.find(frame->header.ssrc) == participants_.end()) {
auto participant = new struct participant;
participant->address = frame->src_addr;
participants_[frame->header.ssrc] = participant;
}
return RTP_OK;
}
if (!kvz_rtp::rtcp::is_participant(frame->header.ssrc)) {
LOG_WARN("Got RTP packet from unknown source: 0x%x", frame->header.ssrc);
init_new_participant(frame);

View File

@ -63,6 +63,11 @@ rtp_error_t kvz_rtp::writer::start()
addr_out_ = socket_.create_sockaddr(AF_INET, dst_addr_, dst_port_);
socket_.set_sockaddr(addr_out_);
if ((rtcp_ = new kvz_rtp::rtcp(get_ssrc(), false)) == nullptr) {
LOG_ERROR("Failed to allocate RTCP instance!");
return RTP_MEMORY_ERROR;
}
return RTP_OK;
}