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/base/checks.h" | 11 #include "webrtc/base/checks.h" |
12 #include "webrtc/call/rtp_demuxer.h" | 12 #include "webrtc/call/rtp_demuxer.h" |
13 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" | 13 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" |
14 | 14 |
15 namespace webrtc { | 15 namespace webrtc { |
16 | 16 |
| 17 namespace { |
| 18 |
| 19 template <typename Key, typename Value> |
| 20 bool MultimapAssociationExists(const std::multimap<Key, Value>& multimap, |
| 21 Key key, |
| 22 Value val) { |
| 23 auto it_range = multimap.equal_range(key); |
| 24 using Reference = typename std::multimap<Key, Value>::const_reference; |
| 25 return std::any_of(it_range.first, it_range.second, |
| 26 [val](Reference elem) { return elem.second == val; }); |
| 27 } |
| 28 |
| 29 } // namespace |
| 30 |
17 RtpDemuxer::RtpDemuxer() {} | 31 RtpDemuxer::RtpDemuxer() {} |
18 | 32 |
19 RtpDemuxer::~RtpDemuxer() { | 33 RtpDemuxer::~RtpDemuxer() { |
20 RTC_DCHECK(sinks_.empty()); | 34 RTC_DCHECK(sinks_.empty()); |
21 } | 35 } |
22 | 36 |
23 void RtpDemuxer::AddSink(uint32_t ssrc, RtpPacketSinkInterface* sink) { | 37 void RtpDemuxer::AddSink(uint32_t ssrc, RtpPacketSinkInterface* sink) { |
24 RTC_DCHECK(sink); | 38 RTC_DCHECK(sink); |
| 39 RTC_DCHECK(!MultimapAssociationExists(sinks_, ssrc, sink)); |
25 sinks_.emplace(ssrc, sink); | 40 sinks_.emplace(ssrc, sink); |
26 } | 41 } |
27 | 42 |
28 size_t RtpDemuxer::RemoveSink(const RtpPacketSinkInterface* sink) { | 43 size_t RtpDemuxer::RemoveSink(const RtpPacketSinkInterface* sink) { |
29 RTC_DCHECK(sink); | 44 RTC_DCHECK(sink); |
30 size_t count = 0; | 45 size_t count = 0; |
31 for (auto it = sinks_.begin(); it != sinks_.end(); ) { | 46 for (auto it = sinks_.begin(); it != sinks_.end(); ) { |
32 if (it->second == sink) { | 47 if (it->second == sink) { |
33 it = sinks_.erase(it); | 48 it = sinks_.erase(it); |
34 ++count; | 49 ++count; |
35 } else { | 50 } else { |
36 ++it; | 51 ++it; |
37 } | 52 } |
38 } | 53 } |
39 return count; | 54 return count; |
40 } | 55 } |
41 | 56 |
42 bool RtpDemuxer::OnRtpPacket(const RtpPacketReceived& packet) { | 57 bool RtpDemuxer::OnRtpPacket(const RtpPacketReceived& packet) { |
43 bool found = false; | 58 bool found = false; |
44 auto it_range = sinks_.equal_range(packet.Ssrc()); | 59 auto it_range = sinks_.equal_range(packet.Ssrc()); |
45 for (auto it = it_range.first; it != it_range.second; ++it) { | 60 for (auto it = it_range.first; it != it_range.second; ++it) { |
46 found = true; | 61 found = true; |
47 it->second->OnRtpPacket(packet); | 62 it->second->OnRtpPacket(packet); |
48 } | 63 } |
49 return found; | 64 return found; |
50 } | 65 } |
51 | 66 |
52 } // namespace webrtc | 67 } // namespace webrtc |
OLD | NEW |