Reason for revert: About to fix problem and reland. Original issue's description: > Revert of Create RtcpDemuxer (patchset #13 id:240001 of https://codereview.webrtc.org/2943693003/ ) > > Reason for revert: > Breaks Chromium FYI bots. > > The problem is in the BUILD.gn file. > > Sample failure: > https://build.chromium.org/p/chromium.webrtc.fyi/builders/Linux%20Builder/builds/17829 > > Sample logs: > use_goma = true > """ to /b/c/b/Linux_Builder/src/out/Release/args.gn. > > /b/c/b/Linux_Builder/src/buildtools/linux64/gn gen //out/Release --check > -> returned 1 > ERROR at //third_party/webrtc/call/BUILD.gn:46:5: Can't load input file. > "//webrtc/base:rtc_base_approved", > ^-------------------------------- > > Original issue's description: > > Create RtcpDemuxer. Capabilities: > > 1. Demux RTCP messages according to the sender-SSRC. > > 2. Demux RTCP messages according to the RSID (resolved to an SSRC, then compared to the sender-RTCP). > > 3. Allow listening in on all RTCP messages passing through the demuxer ("broadcast sinks"). > > > > BUG=webrtc:7135 > > > > Review-Url: https://codereview.webrtc.org/2943693003 > > Cr-Commit-Position: refs/heads/master@{#18763} > > Committed:cb83bdf01f> > BUG=webrtc:7135 > > Review-Url: https://codereview.webrtc.org/2957763002 > Cr-Commit-Position: refs/heads/master@{#18764} > Committed:0e7e7869e7BUG=webrtc:7135 Review-Url: https://codereview.webrtc.org/2960623002 Cr-Commit-Position: refs/heads/master@{#18768}
101 lines
3.5 KiB
C++
101 lines
3.5 KiB
C++
/*
|
|
* Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include "webrtc/call/rtcp_demuxer.h"
|
|
|
|
#include "webrtc/base/checks.h"
|
|
#include "webrtc/call/rtcp_packet_sink_interface.h"
|
|
#include "webrtc/call/rtp_rtcp_demuxer_helper.h"
|
|
#include "webrtc/common_types.h"
|
|
|
|
namespace webrtc {
|
|
|
|
RtcpDemuxer::RtcpDemuxer() = default;
|
|
|
|
RtcpDemuxer::~RtcpDemuxer() {
|
|
RTC_DCHECK(ssrc_sinks_.empty());
|
|
RTC_DCHECK(rsid_sinks_.empty());
|
|
RTC_DCHECK(broadcast_sinks_.empty());
|
|
}
|
|
|
|
void RtcpDemuxer::AddSink(uint32_t sender_ssrc, RtcpPacketSinkInterface* sink) {
|
|
RTC_DCHECK(sink);
|
|
RTC_DCHECK(!ContainerHasKey(broadcast_sinks_, sink));
|
|
RTC_DCHECK(!MultimapAssociationExists(ssrc_sinks_, sender_ssrc, sink));
|
|
ssrc_sinks_.emplace(sender_ssrc, sink);
|
|
}
|
|
|
|
void RtcpDemuxer::AddSink(const std::string& rsid,
|
|
RtcpPacketSinkInterface* sink) {
|
|
RTC_DCHECK(StreamId::IsLegalName(rsid));
|
|
RTC_DCHECK(sink);
|
|
RTC_DCHECK(!ContainerHasKey(broadcast_sinks_, sink));
|
|
RTC_DCHECK(!MultimapAssociationExists(rsid_sinks_, rsid, sink));
|
|
rsid_sinks_.emplace(rsid, sink);
|
|
}
|
|
|
|
void RtcpDemuxer::AddBroadcastSink(RtcpPacketSinkInterface* sink) {
|
|
RTC_DCHECK(sink);
|
|
RTC_DCHECK(!MultimapHasValue(ssrc_sinks_, sink));
|
|
RTC_DCHECK(!MultimapHasValue(rsid_sinks_, sink));
|
|
RTC_DCHECK(!ContainerHasKey(broadcast_sinks_, sink));
|
|
broadcast_sinks_.push_back(sink);
|
|
}
|
|
|
|
void RtcpDemuxer::RemoveSink(const RtcpPacketSinkInterface* sink) {
|
|
RTC_DCHECK(sink);
|
|
size_t removal_count = RemoveFromMultimapByValue(&ssrc_sinks_, sink) +
|
|
RemoveFromMultimapByValue(&rsid_sinks_, sink);
|
|
RTC_DCHECK_GT(removal_count, 0);
|
|
}
|
|
|
|
void RtcpDemuxer::RemoveBroadcastSink(const RtcpPacketSinkInterface* sink) {
|
|
RTC_DCHECK(sink);
|
|
auto it = std::find(broadcast_sinks_.begin(), broadcast_sinks_.end(), sink);
|
|
RTC_DCHECK(it != broadcast_sinks_.end());
|
|
broadcast_sinks_.erase(it);
|
|
}
|
|
|
|
void RtcpDemuxer::OnRtcpPacket(rtc::ArrayView<const uint8_t> packet) {
|
|
// Perform sender-SSRC-based demuxing for packets with a sender-SSRC.
|
|
rtc::Optional<uint32_t> sender_ssrc = ParseRtcpPacketSenderSsrc(packet);
|
|
if (sender_ssrc) {
|
|
auto it_range = ssrc_sinks_.equal_range(*sender_ssrc);
|
|
for (auto it = it_range.first; it != it_range.second; ++it) {
|
|
it->second->OnRtcpPacket(packet);
|
|
}
|
|
}
|
|
|
|
// All packets, even those without a sender-SSRC, are broadcast to sinks
|
|
// which listen to broadcasts.
|
|
for (RtcpPacketSinkInterface* sink : broadcast_sinks_) {
|
|
sink->OnRtcpPacket(packet);
|
|
}
|
|
}
|
|
|
|
void RtcpDemuxer::OnRsidResolved(const std::string& rsid, uint32_t ssrc) {
|
|
// Record the new SSRC association for all of the sinks that were associated
|
|
// with the RSID.
|
|
auto it_range = rsid_sinks_.equal_range(rsid);
|
|
for (auto it = it_range.first; it != it_range.second; ++it) {
|
|
RtcpPacketSinkInterface* sink = it->second;
|
|
// Watch out for pre-existing SSRC-based associations.
|
|
if (!MultimapAssociationExists(ssrc_sinks_, ssrc, sink)) {
|
|
AddSink(ssrc, sink);
|
|
}
|
|
}
|
|
|
|
// RSIDs are uniquely associated with SSRCs; no need to keep in memory
|
|
// the RSID-to-sink association of resolved RSIDs.
|
|
rsid_sinks_.erase(it_range.first, it_range.second);
|
|
}
|
|
|
|
} // namespace webrtc
|