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

Side by Side Diff: webrtc/modules/pacing/packet_router.cc

Issue 1628683002: Use separate rtp module lists for send and receive in PacketRouter. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Comments addressed. Created 4 years, 10 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
« no previous file with comments | « webrtc/modules/pacing/packet_router.h ('k') | webrtc/modules/pacing/packet_router_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 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/modules/pacing/packet_router.h" 11 #include "webrtc/modules/pacing/packet_router.h"
12 12
13 #include "webrtc/base/atomicops.h" 13 #include "webrtc/base/atomicops.h"
14 #include "webrtc/base/checks.h" 14 #include "webrtc/base/checks.h"
15 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" 15 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
16 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" 16 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
17 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" 17 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
18 18
19 namespace webrtc { 19 namespace webrtc {
20 20
21 namespace {
22 void AddModule(RtpRtcp* rtp_module, std::list<RtpRtcp*>* rtp_modules) {
23 RTC_DCHECK(std::find(rtp_modules->begin(), rtp_modules->end(), rtp_module) ==
24 rtp_modules->end());
25 rtp_modules->push_back(rtp_module);
26 }
27
28 void RemoveModule(RtpRtcp* rtp_module, std::list<RtpRtcp*>* rtp_modules) {
29 RTC_DCHECK(std::find(rtp_modules->begin(), rtp_modules->end(), rtp_module) !=
30 rtp_modules->end());
31 rtp_modules->remove(rtp_module);
32 }
33
34 bool SendFeedback(rtcp::TransportFeedback* packet,
35 std::list<RtpRtcp*>* rtp_modules) {
36 for (auto* rtp_module : *rtp_modules) {
37 packet->WithPacketSenderSsrc(rtp_module->SSRC());
38 if (rtp_module->SendFeedbackPacket(*packet))
39 return true;
40 }
41 return false;
42 }
43 }
44
21 PacketRouter::PacketRouter() : transport_seq_(0) { 45 PacketRouter::PacketRouter() : transport_seq_(0) {
46 pacer_thread_checker_.DetachFromThread();
22 } 47 }
23 48
24 PacketRouter::~PacketRouter() { 49 PacketRouter::~PacketRouter() {
25 RTC_DCHECK(rtp_modules_.empty()); 50 RTC_DCHECK(send_rtp_modules_.empty());
51 RTC_DCHECK(recv_rtp_modules_.empty());
26 } 52 }
27 53
28 void PacketRouter::AddRtpModule(RtpRtcp* rtp_module) { 54 void PacketRouter::AddRtpModule(RtpRtcp* rtp_module, bool sender) {
29 rtc::CritScope cs(&modules_lock_); 55 rtc::CritScope cs(&modules_crit_);
30 RTC_DCHECK(std::find(rtp_modules_.begin(), rtp_modules_.end(), rtp_module) == 56 if (sender) {
31 rtp_modules_.end()); 57 AddModule(rtp_module, &send_rtp_modules_);
32 rtp_modules_.push_back(rtp_module); 58 } else {
59 AddModule(rtp_module, &recv_rtp_modules_);
60 }
33 } 61 }
34 62
35 void PacketRouter::RemoveRtpModule(RtpRtcp* rtp_module) { 63 void PacketRouter::RemoveRtpModule(RtpRtcp* rtp_module, bool sender) {
36 rtc::CritScope cs(&modules_lock_); 64 rtc::CritScope cs(&modules_crit_);
37 auto it = std::find(rtp_modules_.begin(), rtp_modules_.end(), rtp_module); 65 if (sender) {
38 RTC_DCHECK(it != rtp_modules_.end()); 66 RemoveModule(rtp_module, &send_rtp_modules_);
39 rtp_modules_.erase(it); 67 } else {
68 RemoveModule(rtp_module, &recv_rtp_modules_);
69 }
40 } 70 }
41 71
42 bool PacketRouter::TimeToSendPacket(uint32_t ssrc, 72 bool PacketRouter::TimeToSendPacket(uint32_t ssrc,
43 uint16_t sequence_number, 73 uint16_t sequence_number,
44 int64_t capture_timestamp, 74 int64_t capture_timestamp,
45 bool retransmission) { 75 bool retransmission) {
46 rtc::CritScope cs(&modules_lock_); 76 RTC_DCHECK(pacer_thread_checker_.CalledOnValidThread());
47 for (auto* rtp_module : rtp_modules_) { 77 rtc::CritScope cs(&modules_crit_);
78 for (auto* rtp_module : send_rtp_modules_) {
48 if (rtp_module->SendingMedia() && ssrc == rtp_module->SSRC()) { 79 if (rtp_module->SendingMedia() && ssrc == rtp_module->SSRC()) {
49 return rtp_module->TimeToSendPacket(ssrc, sequence_number, 80 return rtp_module->TimeToSendPacket(ssrc, sequence_number,
50 capture_timestamp, retransmission); 81 capture_timestamp, retransmission);
51 } 82 }
52 } 83 }
53 return true; 84 return true;
54 } 85 }
55 86
56 size_t PacketRouter::TimeToSendPadding(size_t bytes_to_send) { 87 size_t PacketRouter::TimeToSendPadding(size_t bytes_to_send) {
88 RTC_DCHECK(pacer_thread_checker_.CalledOnValidThread());
57 size_t total_bytes_sent = 0; 89 size_t total_bytes_sent = 0;
58 rtc::CritScope cs(&modules_lock_); 90 rtc::CritScope cs(&modules_crit_);
59 for (RtpRtcp* module : rtp_modules_) { 91 for (RtpRtcp* module : send_rtp_modules_) {
60 if (module->SendingMedia()) { 92 if (module->SendingMedia()) {
61 size_t bytes_sent = 93 size_t bytes_sent =
62 module->TimeToSendPadding(bytes_to_send - total_bytes_sent); 94 module->TimeToSendPadding(bytes_to_send - total_bytes_sent);
63 total_bytes_sent += bytes_sent; 95 total_bytes_sent += bytes_sent;
64 if (total_bytes_sent >= bytes_to_send) 96 if (total_bytes_sent >= bytes_to_send)
65 break; 97 break;
66 } 98 }
67 } 99 }
68 return total_bytes_sent; 100 return total_bytes_sent;
69 } 101 }
(...skipping 14 matching lines...) Expand all
84 // operation was successful - otherwise we need to retry. Saving the 116 // operation was successful - otherwise we need to retry. Saving the
85 // return value saves us a load on retry. 117 // return value saves us a load on retry.
86 prev_seq = rtc::AtomicOps::CompareAndSwap(&transport_seq_, desired_prev_seq, 118 prev_seq = rtc::AtomicOps::CompareAndSwap(&transport_seq_, desired_prev_seq,
87 new_seq); 119 new_seq);
88 } while (prev_seq != desired_prev_seq); 120 } while (prev_seq != desired_prev_seq);
89 121
90 return new_seq; 122 return new_seq;
91 } 123 }
92 124
93 bool PacketRouter::SendFeedback(rtcp::TransportFeedback* packet) { 125 bool PacketRouter::SendFeedback(rtcp::TransportFeedback* packet) {
94 rtc::CritScope cs(&modules_lock_); 126 RTC_DCHECK(pacer_thread_checker_.CalledOnValidThread());
95 for (auto* rtp_module : rtp_modules_) { 127 rtc::CritScope cs(&modules_crit_);
96 packet->WithPacketSenderSsrc(rtp_module->SSRC()); 128 if (::webrtc::SendFeedback(packet, &recv_rtp_modules_))
97 if (rtp_module->SendFeedbackPacket(*packet)) 129 return true;
98 return true; 130 if (::webrtc::SendFeedback(packet, &send_rtp_modules_))
99 } 131 return true;
100 return false; 132 return false;
101 } 133 }
102 134
103 } // namespace webrtc 135 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/pacing/packet_router.h ('k') | webrtc/modules/pacing/packet_router_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698