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

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

Issue 2774623006: Let PacketRouter separate send and receive modules. (Closed)
Patch Set: Eliminate std::remove. Created 3 years, 8 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 PacketRouter::PacketRouter() : transport_seq_(0) { 21 PacketRouter::PacketRouter() : transport_seq_(0) {
22 pacer_thread_checker_.DetachFromThread(); 22 pacer_thread_checker_.DetachFromThread();
23 } 23 }
24 24
25 PacketRouter::~PacketRouter() { 25 PacketRouter::~PacketRouter() {
26 RTC_DCHECK(rtp_modules_.empty()); 26 RTC_DCHECK(rtp_send_modules_.empty());
27 RTC_DCHECK(rtp_receive_modules_.empty());
27 } 28 }
28 29
29 void PacketRouter::AddRtpModule(RtpRtcp* rtp_module) { 30 void PacketRouter::AddSendRtpModule(RtpRtcp* rtp_module) {
30 rtc::CritScope cs(&modules_crit_); 31 rtc::CritScope cs(&modules_crit_);
31 RTC_DCHECK(std::find(rtp_modules_.begin(), rtp_modules_.end(), rtp_module) == 32 RTC_DCHECK(std::find(rtp_send_modules_.begin(), rtp_send_modules_.end(),
32 rtp_modules_.end()); 33 rtp_module) == rtp_send_modules_.end());
33 // Put modules which can use regular payload packets (over rtx) instead of 34 // Put modules which can use regular payload packets (over rtx) instead of
34 // padding first as it's less of a waste 35 // padding first as it's less of a waste
35 if ((rtp_module->RtxSendStatus() & kRtxRedundantPayloads) > 0) { 36 if ((rtp_module->RtxSendStatus() & kRtxRedundantPayloads) > 0) {
36 rtp_modules_.push_front(rtp_module); 37 rtp_send_modules_.push_front(rtp_module);
37 } else { 38 } else {
38 rtp_modules_.push_back(rtp_module); 39 rtp_send_modules_.push_back(rtp_module);
39 } 40 }
40 } 41 }
41 42
42 void PacketRouter::RemoveRtpModule(RtpRtcp* rtp_module) { 43 void PacketRouter::RemoveSendRtpModule(RtpRtcp* rtp_module) {
43 rtc::CritScope cs(&modules_crit_); 44 rtc::CritScope cs(&modules_crit_);
44 RTC_DCHECK(std::find(rtp_modules_.begin(), rtp_modules_.end(), rtp_module) != 45 RTC_DCHECK(std::find(rtp_send_modules_.begin(), rtp_send_modules_.end(),
45 rtp_modules_.end()); 46 rtp_module) != rtp_send_modules_.end());
46 rtp_modules_.remove(rtp_module); 47 rtp_send_modules_.remove(rtp_module);
48 }
49
50 void PacketRouter::AddReceiveRtpModule(RtpRtcp* rtp_module) {
51 rtc::CritScope cs(&modules_crit_);
52 RTC_DCHECK(std::find(rtp_receive_modules_.begin(), rtp_receive_modules_.end(),
53 rtp_module) == rtp_receive_modules_.end());
54 rtp_receive_modules_.push_back(rtp_module);
55 }
56
57 void PacketRouter::RemoveReceiveRtpModule(RtpRtcp* rtp_module) {
58 rtc::CritScope cs(&modules_crit_);
59 const auto& it = std::find(rtp_receive_modules_.begin(),
60 rtp_receive_modules_.end(), rtp_module);
61 RTC_DCHECK(it != rtp_receive_modules_.end());
62 rtp_receive_modules_.erase(it);
47 } 63 }
48 64
49 bool PacketRouter::TimeToSendPacket(uint32_t ssrc, 65 bool PacketRouter::TimeToSendPacket(uint32_t ssrc,
50 uint16_t sequence_number, 66 uint16_t sequence_number,
51 int64_t capture_timestamp, 67 int64_t capture_timestamp,
52 bool retransmission, 68 bool retransmission,
53 const PacedPacketInfo& pacing_info) { 69 const PacedPacketInfo& pacing_info) {
54 RTC_DCHECK(pacer_thread_checker_.CalledOnValidThread()); 70 RTC_DCHECK(pacer_thread_checker_.CalledOnValidThread());
55 rtc::CritScope cs(&modules_crit_); 71 rtc::CritScope cs(&modules_crit_);
56 for (auto* rtp_module : rtp_modules_) { 72 for (auto* rtp_module : rtp_send_modules_) {
57 if (!rtp_module->SendingMedia()) 73 if (!rtp_module->SendingMedia())
58 continue; 74 continue;
59 if (ssrc == rtp_module->SSRC() || ssrc == rtp_module->FlexfecSsrc()) { 75 if (ssrc == rtp_module->SSRC() || ssrc == rtp_module->FlexfecSsrc()) {
60 return rtp_module->TimeToSendPacket(ssrc, sequence_number, 76 return rtp_module->TimeToSendPacket(ssrc, sequence_number,
61 capture_timestamp, retransmission, 77 capture_timestamp, retransmission,
62 pacing_info); 78 pacing_info);
63 } 79 }
64 } 80 }
65 return true; 81 return true;
66 } 82 }
67 83
68 size_t PacketRouter::TimeToSendPadding(size_t bytes_to_send, 84 size_t PacketRouter::TimeToSendPadding(size_t bytes_to_send,
69 const PacedPacketInfo& pacing_info) { 85 const PacedPacketInfo& pacing_info) {
70 RTC_DCHECK(pacer_thread_checker_.CalledOnValidThread()); 86 RTC_DCHECK(pacer_thread_checker_.CalledOnValidThread());
71 size_t total_bytes_sent = 0; 87 size_t total_bytes_sent = 0;
72 rtc::CritScope cs(&modules_crit_); 88 rtc::CritScope cs(&modules_crit_);
73 // Rtp modules are ordered by which stream can most benefit from padding. 89 // Rtp modules are ordered by which stream can most benefit from padding.
74 for (RtpRtcp* module : rtp_modules_) { 90 for (RtpRtcp* module : rtp_send_modules_) {
75 if (module->SendingMedia() && module->HasBweExtensions()) { 91 if (module->SendingMedia() && module->HasBweExtensions()) {
76 size_t bytes_sent = module->TimeToSendPadding( 92 size_t bytes_sent = module->TimeToSendPadding(
77 bytes_to_send - total_bytes_sent, pacing_info); 93 bytes_to_send - total_bytes_sent, pacing_info);
78 total_bytes_sent += bytes_sent; 94 total_bytes_sent += bytes_sent;
79 if (total_bytes_sent >= bytes_to_send) 95 if (total_bytes_sent >= bytes_to_send)
80 break; 96 break;
81 } 97 }
82 } 98 }
83 return total_bytes_sent; 99 return total_bytes_sent;
84 } 100 }
(...skipping 14 matching lines...) Expand all
99 // operation was successful - otherwise we need to retry. Saving the 115 // operation was successful - otherwise we need to retry. Saving the
100 // return value saves us a load on retry. 116 // return value saves us a load on retry.
101 prev_seq = rtc::AtomicOps::CompareAndSwap(&transport_seq_, desired_prev_seq, 117 prev_seq = rtc::AtomicOps::CompareAndSwap(&transport_seq_, desired_prev_seq,
102 new_seq); 118 new_seq);
103 } while (prev_seq != desired_prev_seq); 119 } while (prev_seq != desired_prev_seq);
104 120
105 return new_seq; 121 return new_seq;
106 } 122 }
107 123
108 bool PacketRouter::SendFeedback(rtcp::TransportFeedback* packet) { 124 bool PacketRouter::SendFeedback(rtcp::TransportFeedback* packet) {
125 RTC_DCHECK(pacer_thread_checker_.CalledOnValidThread());
109 rtc::CritScope cs(&modules_crit_); 126 rtc::CritScope cs(&modules_crit_);
110 for (auto* rtp_module : rtp_modules_) { 127 // Prefer send modules.
128 for (auto* rtp_module : rtp_send_modules_) {
111 packet->SetSenderSsrc(rtp_module->SSRC()); 129 packet->SetSenderSsrc(rtp_module->SSRC());
112 if (rtp_module->SendFeedbackPacket(*packet)) 130 if (rtp_module->SendFeedbackPacket(*packet))
113 return true; 131 return true;
132 }
133 for (auto* rtp_module : rtp_receive_modules_) {
134 packet->SetSenderSsrc(rtp_module->SSRC());
135 if (rtp_module->SendFeedbackPacket(*packet))
136 return true;
114 } 137 }
115 return false; 138 return false;
116 } 139 }
117 140
118 } // namespace webrtc 141 } // 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