Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(378)

Side by Side Diff: webrtc/call/rtp_demuxer.cc

Issue 2968693002: SSRC and RSID may only refer to one sink each in RtpDemuxer (Closed)
Patch Set: TODO added. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/call/rtp_demuxer.h" 11 #include "webrtc/call/rtp_demuxer.h"
12 12
13 #include "webrtc/base/checks.h" 13 #include "webrtc/base/checks.h"
14 #include "webrtc/base/logging.h" 14 #include "webrtc/base/logging.h"
15 #include "webrtc/call/rsid_resolution_observer.h" 15 #include "webrtc/call/rsid_resolution_observer.h"
16 #include "webrtc/call/rtp_packet_sink_interface.h" 16 #include "webrtc/call/rtp_packet_sink_interface.h"
17 #include "webrtc/call/rtp_rtcp_demuxer_helper.h" 17 #include "webrtc/call/rtp_rtcp_demuxer_helper.h"
18 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h" 18 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h"
19 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" 19 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h"
20 20
21 namespace webrtc { 21 namespace webrtc {
22 22
23 RtpDemuxer::RtpDemuxer() = default; 23 RtpDemuxer::RtpDemuxer() = default;
24 24
25 RtpDemuxer::~RtpDemuxer() { 25 RtpDemuxer::~RtpDemuxer() {
26 RTC_DCHECK(ssrc_sinks_.empty()); 26 RTC_DCHECK(ssrc_sinks_.empty());
27 RTC_DCHECK(rsid_sinks_.empty()); 27 RTC_DCHECK(rsid_sinks_.empty());
28 } 28 }
29 29
30 void RtpDemuxer::AddSink(uint32_t ssrc, RtpPacketSinkInterface* sink) { 30 bool RtpDemuxer::AddSink(uint32_t ssrc, RtpPacketSinkInterface* sink) {
31 RTC_DCHECK(sink); 31 RTC_DCHECK(sink);
32 RecordSsrcToSinkAssociation(ssrc, sink); 32 // The association might already have been set by a different
33 // configuration source.
34 // We cannot RTC_DCHECK against an attempt to remap an SSRC, because
35 // such a configuration might have come from the network (1. resolution
36 // of an RSID or 2. RTCP messages with RSID resolutions).
37 if (ssrc_sinks_.find(ssrc) == ssrc_sinks_.cend()) {
38 ssrc_sinks_.emplace(ssrc, sink);
39 return true;
40 } else {
41 return false;
42 }
33 } 43 }
34 44
35 void RtpDemuxer::AddSink(const std::string& rsid, 45 void RtpDemuxer::AddSink(const std::string& rsid,
36 RtpPacketSinkInterface* sink) { 46 RtpPacketSinkInterface* sink) {
37 RTC_DCHECK(StreamId::IsLegalName(rsid)); 47 RTC_DCHECK(StreamId::IsLegalName(rsid));
38 RTC_DCHECK(sink); 48 RTC_DCHECK(sink);
39 RTC_DCHECK(!MultimapAssociationExists(rsid_sinks_, rsid, sink)); 49 // TODO(eladalon): Discuss with nisse and danilchap whether we want to
danilchap 2017/06/30 16:45:31 I do not know a use case where adding sink by rsid
eladalon 2017/07/03 08:23:35 Acknowledged.
50 // keep this a DCHECK, or protect against it softly, like with SSRC.
51 RTC_DCHECK(rsid_sinks_.find(rsid) == rsid_sinks_.cend());
40 52
41 rsid_sinks_.emplace(rsid, sink); 53 rsid_sinks_.emplace(rsid, sink);
42 } 54 }
43 55
44 bool RtpDemuxer::RemoveSink(const RtpPacketSinkInterface* sink) { 56 bool RtpDemuxer::RemoveSink(const RtpPacketSinkInterface* sink) {
45 RTC_DCHECK(sink); 57 RTC_DCHECK(sink);
46 return (RemoveFromMultimapByValue(&ssrc_sinks_, sink) + 58 return (RemoveFromMapByValue(&ssrc_sinks_, sink) +
47 RemoveFromMultimapByValue(&rsid_sinks_, sink)) > 0; 59 RemoveFromMapByValue(&rsid_sinks_, sink)) > 0;
48 }
49
50 void RtpDemuxer::RecordSsrcToSinkAssociation(uint32_t ssrc,
51 RtpPacketSinkInterface* sink) {
52 RTC_DCHECK(sink);
53 // The association might already have been set by a different
54 // configuration source.
55 if (!MultimapAssociationExists(ssrc_sinks_, ssrc, sink)) {
56 ssrc_sinks_.emplace(ssrc, sink);
57 }
58 } 60 }
59 61
60 bool RtpDemuxer::OnRtpPacket(const RtpPacketReceived& packet) { 62 bool RtpDemuxer::OnRtpPacket(const RtpPacketReceived& packet) {
61 // TODO(eladalon): This will now check every single packet, but soon a CL will 63 // TODO(eladalon): This will now check every single packet, but soon a CL will
62 // be added which will change the many-to-many association of packets to sinks 64 // be added which will change the many-to-many association of packets to sinks
63 // to a many-to-one, meaning each packet will be associated with one sink 65 // to a many-to-one, meaning each packet will be associated with one sink
64 // at most. Then, only packets with an unknown SSRC will be checked for RSID. 66 // at most. Then, only packets with an unknown SSRC will be checked for RSID.
65 ResolveRsidToSsrcAssociations(packet); 67 ResolveRsidToSsrcAssociations(packet);
66 68
67 auto it_range = ssrc_sinks_.equal_range(packet.Ssrc()); 69 auto it_range = ssrc_sinks_.equal_range(packet.Ssrc());
(...skipping 16 matching lines...) Expand all
84 RTC_DCHECK(observer); 86 RTC_DCHECK(observer);
85 auto it = std::find(rsid_resolution_observers_.begin(), 87 auto it = std::find(rsid_resolution_observers_.begin(),
86 rsid_resolution_observers_.end(), observer); 88 rsid_resolution_observers_.end(), observer);
87 RTC_DCHECK(it != rsid_resolution_observers_.end()); 89 RTC_DCHECK(it != rsid_resolution_observers_.end());
88 rsid_resolution_observers_.erase(it); 90 rsid_resolution_observers_.erase(it);
89 } 91 }
90 92
91 void RtpDemuxer::ResolveRsidToSsrcAssociations( 93 void RtpDemuxer::ResolveRsidToSsrcAssociations(
92 const RtpPacketReceived& packet) { 94 const RtpPacketReceived& packet) {
93 std::string rsid; 95 std::string rsid;
94 if (packet.GetExtension<RtpStreamId>(&rsid)) { 96 if (!packet.GetExtension<RtpStreamId>(&rsid)) {
95 // All streams associated with this RSID need to be marked as associated 97 return;
96 // with this SSRC (if they aren't already). 98 }
97 auto it_range = rsid_sinks_.equal_range(rsid);
98 for (auto it = it_range.first; it != it_range.second; ++it) {
99 RecordSsrcToSinkAssociation(packet.Ssrc(), it->second);
100 }
101 99
102 NotifyObserversOfRsidResolution(rsid, packet.Ssrc()); 100 auto it = rsid_sinks_.find(rsid);
101 if (it == rsid_sinks_.end()) {
102 return;
103 }
103 104
104 // To prevent memory-overuse attacks, forget this RSID. Future packets 105 // If a sink is associated with an RSID, we should associate it with
105 // with this RSID, but a different SSRC, will not spawn new associations. 106 // this SSRC.
106 rsid_sinks_.erase(it_range.first, it_range.second); 107 if (!AddSink(packet.Ssrc(), it->second)) {
108 // In the faulty case of RSIDs mapped to SSRCs which are already associated
109 // with a sink, avoid propagating the problem to the resolution observers.
110 return;
107 } 111 }
112
113 // We make the assumption that observers are only interested in notifications
114 // for RSIDs which are registered with this module. (RTCP sinks are normally
115 // created with RTP sinks.)
116 NotifyObserversOfRsidResolution(rsid, packet.Ssrc());
117
118 // This RSID cannot later be associated with another SSRC.
119 rsid_sinks_.erase(it);
108 } 120 }
109 121
110 void RtpDemuxer::NotifyObserversOfRsidResolution(const std::string& rsid, 122 void RtpDemuxer::NotifyObserversOfRsidResolution(const std::string& rsid,
111 uint32_t ssrc) { 123 uint32_t ssrc) {
112 for (auto* observer : rsid_resolution_observers_) { 124 for (auto* observer : rsid_resolution_observers_) {
113 observer->OnRsidResolved(rsid, ssrc); 125 observer->OnRsidResolved(rsid, ssrc);
114 } 126 }
115 } 127 }
116 128
117 } // namespace webrtc 129 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698