OLD | NEW |
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 namespace { | 23 namespace { |
24 constexpr size_t kMaxProcessedSsrcs = 1000; // Prevent memory overuse. | 24 constexpr size_t kMaxProcessedSsrcs = 1000; // Prevent memory overuse. |
25 } // namespace | 25 } // namespace |
26 | 26 |
27 RtpDemuxer::RtpDemuxer() = default; | 27 RtpDemuxer::RtpDemuxer() = default; |
28 | 28 |
29 RtpDemuxer::~RtpDemuxer() { | 29 RtpDemuxer::~RtpDemuxer() { |
30 RTC_DCHECK(sinks_.empty()); | 30 RTC_DCHECK(ssrc_sinks_.empty()); |
31 RTC_DCHECK(rsid_sinks_.empty()); | 31 RTC_DCHECK(rsid_sinks_.empty()); |
32 } | 32 } |
33 | 33 |
34 void RtpDemuxer::AddSink(uint32_t ssrc, RtpPacketSinkInterface* sink) { | 34 void RtpDemuxer::AddSink(uint32_t ssrc, RtpPacketSinkInterface* sink) { |
35 RTC_DCHECK(sink); | 35 RTC_DCHECK(sink); |
36 RecordSsrcToSinkAssociation(ssrc, sink); | 36 RecordSsrcToSinkAssociation(ssrc, sink); |
37 } | 37 } |
38 | 38 |
39 void RtpDemuxer::AddSink(const std::string& rsid, | 39 void RtpDemuxer::AddSink(const std::string& rsid, |
40 RtpPacketSinkInterface* sink) { | 40 RtpPacketSinkInterface* sink) { |
41 RTC_DCHECK(StreamId::IsLegalName(rsid)); | 41 RTC_DCHECK(StreamId::IsLegalName(rsid)); |
42 RTC_DCHECK(sink); | 42 RTC_DCHECK(sink); |
43 RTC_DCHECK(!MultimapAssociationExists(rsid_sinks_, rsid, sink)); | 43 RTC_DCHECK(!MultimapAssociationExists(rsid_sinks_, rsid, sink)); |
44 | 44 |
45 rsid_sinks_.emplace(rsid, sink); | 45 rsid_sinks_.emplace(rsid, sink); |
46 | 46 |
47 // This RSID might now map to an SSRC which we saw earlier. | 47 // This RSID might now map to an SSRC which we saw earlier. |
48 processed_ssrcs_.clear(); | 48 processed_ssrcs_.clear(); |
49 } | 49 } |
50 | 50 |
51 bool RtpDemuxer::RemoveSink(const RtpPacketSinkInterface* sink) { | 51 bool RtpDemuxer::RemoveSink(const RtpPacketSinkInterface* sink) { |
52 RTC_DCHECK(sink); | 52 RTC_DCHECK(sink); |
53 return (RemoveFromMultimapByValue(&sinks_, sink) + | 53 return (RemoveFromMultimapByValue(&ssrc_sinks_, sink) + |
54 RemoveFromMultimapByValue(&rsid_sinks_, sink)) > 0; | 54 RemoveFromMultimapByValue(&rsid_sinks_, sink)) > 0; |
55 } | 55 } |
56 | 56 |
57 void RtpDemuxer::RecordSsrcToSinkAssociation(uint32_t ssrc, | 57 void RtpDemuxer::RecordSsrcToSinkAssociation(uint32_t ssrc, |
58 RtpPacketSinkInterface* sink) { | 58 RtpPacketSinkInterface* sink) { |
59 RTC_DCHECK(sink); | 59 RTC_DCHECK(sink); |
60 // The association might already have been set by a different | 60 // The association might already have been set by a different |
61 // configuration source. | 61 // configuration source. |
62 if (!MultimapAssociationExists(sinks_, ssrc, sink)) { | 62 if (!MultimapAssociationExists(ssrc_sinks_, ssrc, sink)) { |
63 sinks_.emplace(ssrc, sink); | 63 ssrc_sinks_.emplace(ssrc, sink); |
64 } | 64 } |
65 } | 65 } |
66 | 66 |
67 bool RtpDemuxer::OnRtpPacket(const RtpPacketReceived& packet) { | 67 bool RtpDemuxer::OnRtpPacket(const RtpPacketReceived& packet) { |
68 ResolveAssociations(packet); | 68 ResolveAssociations(packet); |
69 auto it_range = sinks_.equal_range(packet.Ssrc()); | 69 auto it_range = ssrc_sinks_.equal_range(packet.Ssrc()); |
70 for (auto it = it_range.first; it != it_range.second; ++it) { | 70 for (auto it = it_range.first; it != it_range.second; ++it) { |
71 it->second->OnRtpPacket(packet); | 71 it->second->OnRtpPacket(packet); |
72 } | 72 } |
73 return it_range.first != it_range.second; | 73 return it_range.first != it_range.second; |
74 } | 74 } |
75 | 75 |
76 void RtpDemuxer::RegisterRsidResolutionObserver( | 76 void RtpDemuxer::RegisterRsidResolutionObserver( |
77 RsidResolutionObserver* observer) { | 77 RsidResolutionObserver* observer) { |
78 RTC_DCHECK(observer); | 78 RTC_DCHECK(observer); |
79 RTC_DCHECK(!ContainerHasKey(rsid_resolution_observers_, observer)); | 79 RTC_DCHECK(!ContainerHasKey(rsid_resolution_observers_, observer)); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 } | 130 } |
131 | 131 |
132 void RtpDemuxer::NotifyObserversOfRsidResolution(const std::string& rsid, | 132 void RtpDemuxer::NotifyObserversOfRsidResolution(const std::string& rsid, |
133 uint32_t ssrc) { | 133 uint32_t ssrc) { |
134 for (auto* observer : rsid_resolution_observers_) { | 134 for (auto* observer : rsid_resolution_observers_) { |
135 observer->OnRsidResolved(rsid, ssrc); | 135 observer->OnRsidResolved(rsid, ssrc); |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 } // namespace webrtc | 139 } // namespace webrtc |
OLD | NEW |