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

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

Issue 2904903002: Create unit tests for RtpDemuxer (Closed)
Patch Set: Created 3 years, 6 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/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 {
danilchap 2017/05/24 13:45:43 prefer to put anonymous namespace inside namespace
16
17 template <typename key_t, typename val_t>
danilchap 2017/05/24 13:45:42 may be typename Key, typename Value "Template para
18 bool MultimapAssociationExists(std::multimap<key_t, val_t> multimap,
danilchap 2017/05/24 13:45:42 const mutlimap<...>&
19 key_t key,
20 val_t val) {
21 auto it_range = multimap.equal_range(key);
22 using ref_t = typename std::multimap<key_t, val_t>::const_reference;
23 return std::any_of(it_range.first, it_range.second,
24 [val](ref_t elem) { return elem.second == val; });
25 }
26
27 } // namespace
28
15 namespace webrtc { 29 namespace webrtc {
16 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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698