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

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

Issue 2061423003: Refactor NACK bitrate allocation (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixed data race Created 4 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) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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
(...skipping 14 matching lines...) Expand all
25 #include "webrtc/system_wrappers/include/field_trial.h" 25 #include "webrtc/system_wrappers/include/field_trial.h"
26 26
27 namespace { 27 namespace {
28 // Time limit in milliseconds between packet bursts. 28 // Time limit in milliseconds between packet bursts.
29 const int64_t kMinPacketLimitMs = 5; 29 const int64_t kMinPacketLimitMs = 5;
30 30
31 // Upper cap on process interval, in case process has not been called in a long 31 // Upper cap on process interval, in case process has not been called in a long
32 // time. 32 // time.
33 const int64_t kMaxIntervalTimeMs = 30; 33 const int64_t kMaxIntervalTimeMs = 30;
34 34
35 const int64_t kMaxRtt = 1000;
danilchap 2016/06/23 12:46:12 kMaxRttMs
35 } // namespace 36 } // namespace
36 37
37 // TODO(sprang): Move at least PacketQueue and MediaBudget out to separate 38 // TODO(sprang): Move at least PacketQueue and MediaBudget out to separate
38 // files, so that we can more easily test them. 39 // files, so that we can more easily test them.
39 40
40 namespace webrtc { 41 namespace webrtc {
41 namespace paced_sender { 42 namespace paced_sender {
42 struct Packet { 43 struct Packet {
43 Packet(RtpPacketSender::Priority priority, 44 Packet(RtpPacketSender::Priority priority,
44 uint32_t ssrc, 45 uint32_t ssrc,
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 probing_enabled_(true), 254 probing_enabled_(true),
254 media_budget_(new paced_sender::IntervalBudget(0)), 255 media_budget_(new paced_sender::IntervalBudget(0)),
255 padding_budget_(new paced_sender::IntervalBudget(0)), 256 padding_budget_(new paced_sender::IntervalBudget(0)),
256 prober_(new BitrateProber()), 257 prober_(new BitrateProber()),
257 estimated_bitrate_bps_(0), 258 estimated_bitrate_bps_(0),
258 min_send_bitrate_kbps_(0u), 259 min_send_bitrate_kbps_(0u),
259 max_padding_bitrate_kbps_(0u), 260 max_padding_bitrate_kbps_(0u),
260 pacing_bitrate_kbps_(0), 261 pacing_bitrate_kbps_(0),
261 time_last_update_us_(clock->TimeInMicroseconds()), 262 time_last_update_us_(clock->TimeInMicroseconds()),
262 packets_(new paced_sender::PacketQueue(clock)), 263 packets_(new paced_sender::PacketQueue(clock)),
263 packet_counter_(0) { 264 packet_counter_(0),
265 retransmission_rate_(kMaxRtt, 8) { // Scale 8 for bits per second.
danilchap 2016/06/23 12:46:12 shouldn't this be 8000 instead of 8? (scale is for
sprang_webrtc 2016/06/28 09:12:32 Yes.
264 UpdateBytesPerInterval(kMinPacketLimitMs); 266 UpdateBytesPerInterval(kMinPacketLimitMs);
265 } 267 }
266 268
267 PacedSender::~PacedSender() {} 269 PacedSender::~PacedSender() {}
268 270
269 void PacedSender::Pause() { 271 void PacedSender::Pause() {
270 CriticalSectionScoped cs(critsect_.get()); 272 CriticalSectionScoped cs(critsect_.get());
271 paused_ = true; 273 paused_ = true;
272 } 274 }
273 275
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 prober_->OnIncomingPacket(estimated_bitrate_bps_, bytes, now_ms); 321 prober_->OnIncomingPacket(estimated_bitrate_bps_, bytes, now_ms);
320 322
321 if (capture_time_ms < 0) 323 if (capture_time_ms < 0)
322 capture_time_ms = now_ms; 324 capture_time_ms = now_ms;
323 325
324 packets_->Push(paced_sender::Packet(priority, ssrc, sequence_number, 326 packets_->Push(paced_sender::Packet(priority, ssrc, sequence_number,
325 capture_time_ms, now_ms, bytes, 327 capture_time_ms, now_ms, bytes,
326 retransmission, packet_counter_++)); 328 retransmission, packet_counter_++));
327 } 329 }
328 330
331 bool PacedSender::AllocateRetransmissionBitrate(size_t bytes) {
332 int64_t now_ms = clock_->TimeInMilliseconds();
333 CriticalSectionScoped cs(critsect_.get());
334
335 rtc::Optional<uint32_t> retransmission_rate_bps =
336 retransmission_rate_.Rate(now_ms);
337 if (!retransmission_rate_bps) {
338 // Rate not high enough to measure, let it slide.
339 return true;
340 }
341
342 int64_t max_retransmission_rate_bps =
danilchap 2016/06/23 12:46:12 rate (bits/s) * rtt (ms) should result in bits, no
sprang_webrtc 2016/06/28 09:12:32 Not sure what happened here, thought I had removed
343 (2 * rtt_ms_ *
344 std::max(min_send_bitrate_kbps_ * 1000, estimated_bitrate_bps_)) /
345 1000;
346 if (*retransmission_rate_bps < max_retransmission_rate_bps) {
347 retransmission_rate_.Update(bytes, now_ms);
348 return true;
349 }
350
351 return false;
352 }
353
354 int PacedSender::CurrentRetransmissionBitrate() {
355 int64_t now_ms = clock_->TimeInMilliseconds();
356 CriticalSectionScoped cs(critsect_.get());
357 return retransmission_rate_.Rate(now_ms).value_or(0);
358 }
359
360 void PacedSender::OnRttUpdate(int64_t rtt) {
361 RTC_DCHECK_GT(rtt, 0);
362 CriticalSectionScoped cs(critsect_.get());
363 rtt_ms_ = std::min(rtt, kMaxRtt);
364 retransmission_rate_.SetWindowSize(rtt_ms_, clock_->TimeInMilliseconds());
365 }
366
329 int64_t PacedSender::ExpectedQueueTimeMs() const { 367 int64_t PacedSender::ExpectedQueueTimeMs() const {
330 CriticalSectionScoped cs(critsect_.get()); 368 CriticalSectionScoped cs(critsect_.get());
331 RTC_DCHECK_GT(pacing_bitrate_kbps_, 0u); 369 RTC_DCHECK_GT(pacing_bitrate_kbps_, 0u);
332 return static_cast<int64_t>(packets_->SizeInBytes() * 8 / 370 return static_cast<int64_t>(packets_->SizeInBytes() * 8 /
333 pacing_bitrate_kbps_); 371 pacing_bitrate_kbps_);
334 } 372 }
335 373
336 size_t PacedSender::QueueSizePackets() const { 374 size_t PacedSender::QueueSizePackets() const {
337 CriticalSectionScoped cs(critsect_.get()); 375 CriticalSectionScoped cs(critsect_.get());
338 return packets_->SizeInPackets(); 376 return packets_->SizeInPackets();
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 media_budget_->UseBudget(bytes_sent); 509 media_budget_->UseBudget(bytes_sent);
472 padding_budget_->UseBudget(bytes_sent); 510 padding_budget_->UseBudget(bytes_sent);
473 } 511 }
474 } 512 }
475 513
476 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { 514 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) {
477 media_budget_->IncreaseBudget(delta_time_ms); 515 media_budget_->IncreaseBudget(delta_time_ms);
478 padding_budget_->IncreaseBudget(delta_time_ms); 516 padding_budget_->IncreaseBudget(delta_time_ms);
479 } 517 }
480 } // namespace webrtc 518 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698