diff --git a/src/conn.cc b/src/conn.cc index 3951e3b..6665647 100644 --- a/src/conn.cc +++ b/src/conn.cc @@ -3,6 +3,7 @@ #include #endif +#include #include #include @@ -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!"); diff --git a/src/reader.cc b/src/reader.cc index abf3d5a..e0d139c 100644 --- a/src/reader.cc +++ b/src/reader.cc @@ -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; } diff --git a/src/rtcp.cc b/src/rtcp.cc index ec53a36..bda2fca 100644 --- a/src/rtcp.cc +++ b/src/rtcp.cc @@ -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); diff --git a/src/writer.cc b/src/writer.cc index 1d75dad..74b5acc 100644 --- a/src/writer.cc +++ b/src/writer.cc @@ -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; }