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

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

Issue 2789843002: Delete VieRemb class, move functionality to PacketRouter. (Closed)
Patch Set: New method PacketRouter::SendRemb. 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
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/base/timeutils.h"
15 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" 16 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
16 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" 17 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
17 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" 18 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
18 19
19 namespace webrtc { 20 namespace webrtc {
20 21
21 PacketRouter::PacketRouter() : transport_seq_(0) { 22 PacketRouter::PacketRouter() : transport_seq_(0) {
22 pacer_thread_checker_.DetachFromThread(); 23 pacer_thread_checker_.DetachFromThread();
23 } 24 }
24 25
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 // time the CAS operation was executed. Thus, if prev_seq is returned, the 115 // time the CAS operation was executed. Thus, if prev_seq is returned, the
115 // operation was successful - otherwise we need to retry. Saving the 116 // operation was successful - otherwise we need to retry. Saving the
116 // return value saves us a load on retry. 117 // return value saves us a load on retry.
117 prev_seq = rtc::AtomicOps::CompareAndSwap(&transport_seq_, desired_prev_seq, 118 prev_seq = rtc::AtomicOps::CompareAndSwap(&transport_seq_, desired_prev_seq,
118 new_seq); 119 new_seq);
119 } while (prev_seq != desired_prev_seq); 120 } while (prev_seq != desired_prev_seq);
120 121
121 return new_seq; 122 return new_seq;
122 } 123 }
123 124
124 bool PacketRouter::SendFeedback(rtcp::TransportFeedback* packet) { 125 void PacketRouter::OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
126 uint32_t bitrate_bps) {
127 const int kRembSendIntervalMs = 200;
128
129 // % threshold for if we should send a new REMB asap.
130 const uint32_t kSendThresholdPercent = 97;
131
132 int64_t now_ms = rtc::TimeMillis();
133 {
134 rtc::CritScope lock(&remb_crit_);
135
136 // If we already have an estimate, check if the new total estimate is below
137 // kSendThresholdPercent of the previous estimate.
138 if (last_send_bitrate_bps_ > 0) {
139 uint32_t new_remb_bitrate_bps =
140 last_send_bitrate_bps_ - bitrate_bps_ + bitrate_bps;
141
142 if (new_remb_bitrate_bps <
143 kSendThresholdPercent * last_send_bitrate_bps_ / 100) {
144 // The new bitrate estimate is less than kSendThresholdPercent % of the
145 // last report. Send a REMB asap.
146 last_remb_time_ms_ = now_ms - kRembSendIntervalMs;
147 }
148 }
149 bitrate_bps_ = bitrate_bps;
150
151 if (now_ms - last_remb_time_ms_ < kRembSendIntervalMs) {
152 return;
153 }
154 // NOTE: Updated if we intend to send the data; we might not have
155 // a module to actually send it.
156 last_remb_time_ms_ = now_ms;
157 last_send_bitrate_bps_ = bitrate_bps;
158 }
159 SendRemb(bitrate_bps, ssrcs);
160 }
161
162 bool PacketRouter::SendRemb(uint32_t bitrate_bps,
163 const std::vector<uint32_t>& ssrcs) {
164 rtc::CritScope lock(&modules_crit_);
165 // TODO(nisse): Check REMB status of the modules? Or add a loop,
166 // similar to SendTransportFeedback below?
167 RtpRtcp* remb_module;
168 if (!rtp_send_modules_.empty())
169 remb_module = rtp_send_modules_.front();
170 else if (!rtp_receive_modules_.empty())
171 remb_module = rtp_receive_modules_.front();
172 else
173 return false;
174 remb_module->SetREMBData(bitrate_bps, ssrcs);
175 return true;
176 }
177
178 bool PacketRouter::SendTransportFeedback(rtcp::TransportFeedback* packet) {
125 RTC_DCHECK(pacer_thread_checker_.CalledOnValidThread()); 179 RTC_DCHECK(pacer_thread_checker_.CalledOnValidThread());
126 rtc::CritScope cs(&modules_crit_); 180 rtc::CritScope cs(&modules_crit_);
127 // Prefer send modules. 181 // Prefer send modules.
128 for (auto* rtp_module : rtp_send_modules_) { 182 for (auto* rtp_module : rtp_send_modules_) {
129 packet->SetSenderSsrc(rtp_module->SSRC()); 183 packet->SetSenderSsrc(rtp_module->SSRC());
130 if (rtp_module->SendFeedbackPacket(*packet)) 184 if (rtp_module->SendFeedbackPacket(*packet))
131 return true; 185 return true;
132 } 186 }
133 for (auto* rtp_module : rtp_receive_modules_) { 187 for (auto* rtp_module : rtp_receive_modules_) {
134 packet->SetSenderSsrc(rtp_module->SSRC()); 188 packet->SetSenderSsrc(rtp_module->SSRC());
135 if (rtp_module->SendFeedbackPacket(*packet)) 189 if (rtp_module->SendFeedbackPacket(*packet))
136 return true; 190 return true;
137 } 191 }
138 return false; 192 return false;
139 } 193 }
140 194
141 } // namespace webrtc 195 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698