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

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

Issue 1993113003: Refactor how padding is calculated. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Self review Created 4 years, 7 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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 static const int kWindowMs = 500; 238 static const int kWindowMs = 500;
239 239
240 int target_rate_kbps_; 240 int target_rate_kbps_;
241 int bytes_remaining_; 241 int bytes_remaining_;
242 }; 242 };
243 } // namespace paced_sender 243 } // namespace paced_sender
244 244
245 const int64_t PacedSender::kMaxQueueLengthMs = 2000; 245 const int64_t PacedSender::kMaxQueueLengthMs = 2000;
246 const float PacedSender::kDefaultPaceMultiplier = 2.5f; 246 const float PacedSender::kDefaultPaceMultiplier = 2.5f;
247 247
248 PacedSender::PacedSender(Clock* clock, 248 PacedSender::PacedSender(Clock* clock, PacketSender* packet_sender)
249 PacketSender* packet_sender)
250 : clock_(clock), 249 : clock_(clock),
251 packet_sender_(packet_sender), 250 packet_sender_(packet_sender),
252 critsect_(CriticalSectionWrapper::CreateCriticalSection()), 251 critsect_(CriticalSectionWrapper::CreateCriticalSection()),
253 paused_(false), 252 paused_(false),
254 probing_enabled_(true), 253 probing_enabled_(true),
255 media_budget_(new paced_sender::IntervalBudget(0)), 254 media_budget_(new paced_sender::IntervalBudget(0)),
256 padding_budget_(new paced_sender::IntervalBudget(0)), 255 padding_budget_(new paced_sender::IntervalBudget(0)),
257 prober_(new BitrateProber()), 256 prober_(new BitrateProber()),
258 estimated_bitrate_bps_(0), 257 estimated_bitrate_bps_(0),
259 min_send_bitrate_kbps_(0u), 258 min_send_bitrate_kbps_(0u),
259 max_padding_bitrate_kbps_(0u),
260 pacing_bitrate_kbps_(0), 260 pacing_bitrate_kbps_(0),
261 time_last_update_us_(clock->TimeInMicroseconds()), 261 time_last_update_us_(clock->TimeInMicroseconds()),
262 packets_(new paced_sender::PacketQueue(clock)), 262 packets_(new paced_sender::PacketQueue(clock)),
263 packet_counter_(0) { 263 packet_counter_(0) {
264 UpdateBytesPerInterval(kMinPacketLimitMs); 264 UpdateBytesPerInterval(kMinPacketLimitMs);
265 } 265 }
266 266
267 PacedSender::~PacedSender() {} 267 PacedSender::~PacedSender() {}
268 268
269 void PacedSender::Pause() { 269 void PacedSender::Pause() {
(...skipping 19 matching lines...) Expand all
289 kDefaultPaceMultiplier; 289 kDefaultPaceMultiplier;
290 } 290 }
291 291
292 void PacedSender::SetAllocatedSendBitrate(int allocated_bitrate, 292 void PacedSender::SetAllocatedSendBitrate(int allocated_bitrate,
293 int padding_bitrate) { 293 int padding_bitrate) {
294 CriticalSectionScoped cs(critsect_.get()); 294 CriticalSectionScoped cs(critsect_.get());
295 min_send_bitrate_kbps_ = allocated_bitrate / 1000; 295 min_send_bitrate_kbps_ = allocated_bitrate / 1000;
296 pacing_bitrate_kbps_ = 296 pacing_bitrate_kbps_ =
297 std::max(min_send_bitrate_kbps_, estimated_bitrate_bps_ / 1000) * 297 std::max(min_send_bitrate_kbps_, estimated_bitrate_bps_ / 1000) *
298 kDefaultPaceMultiplier; 298 kDefaultPaceMultiplier;
299 padding_budget_->set_target_rate_kbps(padding_bitrate / 1000); 299 max_padding_bitrate_kbps_ = padding_bitrate / 1000;
300 } 300 }
301 301
302 void PacedSender::InsertPacket(RtpPacketSender::Priority priority, 302 void PacedSender::InsertPacket(RtpPacketSender::Priority priority,
303 uint32_t ssrc, 303 uint32_t ssrc,
304 uint16_t sequence_number, 304 uint16_t sequence_number,
305 int64_t capture_time_ms, 305 int64_t capture_time_ms,
306 size_t bytes, 306 size_t bytes,
307 bool retransmission) { 307 bool retransmission) {
308 CriticalSectionScoped cs(critsect_.get()); 308 CriticalSectionScoped cs(critsect_.get());
309 RTC_DCHECK(estimated_bitrate_bps_ > 0) 309 RTC_DCHECK(estimated_bitrate_bps_ > 0)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 int64_t elapsed_time_ms = (elapsed_time_us + 500) / 1000; 361 int64_t elapsed_time_ms = (elapsed_time_us + 500) / 1000;
362 return std::max<int64_t>(kMinPacketLimitMs - elapsed_time_ms, 0); 362 return std::max<int64_t>(kMinPacketLimitMs - elapsed_time_ms, 0);
363 } 363 }
364 364
365 void PacedSender::Process() { 365 void PacedSender::Process() {
366 int64_t now_us = clock_->TimeInMicroseconds(); 366 int64_t now_us = clock_->TimeInMicroseconds();
367 CriticalSectionScoped cs(critsect_.get()); 367 CriticalSectionScoped cs(critsect_.get());
368 int64_t elapsed_time_ms = (now_us - time_last_update_us_ + 500) / 1000; 368 int64_t elapsed_time_ms = (now_us - time_last_update_us_ + 500) / 1000;
369 time_last_update_us_ = now_us; 369 time_last_update_us_ = now_us;
370 int target_bitrate_kbps = pacing_bitrate_kbps_; 370 int target_bitrate_kbps = pacing_bitrate_kbps_;
371 padding_budget_->set_target_rate_kbps(
372 std::min(estimated_bitrate_bps_ / 1000, max_padding_bitrate_kbps_));
371 // TODO(holmer): Remove the !paused_ check when issue 5307 has been fixed. 373 // TODO(holmer): Remove the !paused_ check when issue 5307 has been fixed.
372 if (!paused_ && elapsed_time_ms > 0) { 374 if (!paused_ && elapsed_time_ms > 0) {
373 size_t queue_size_bytes = packets_->SizeInBytes(); 375 size_t queue_size_bytes = packets_->SizeInBytes();
374 if (queue_size_bytes > 0) { 376 if (queue_size_bytes > 0) {
375 // Assuming equal size packets and input/output rate, the average packet 377 // Assuming equal size packets and input/output rate, the average packet
376 // has avg_time_left_ms left to get queue_size_bytes out of the queue, if 378 // has avg_time_left_ms left to get queue_size_bytes out of the queue, if
377 // time constraint shall be met. Determine bitrate needed for that. 379 // time constraint shall be met. Determine bitrate needed for that.
378 packets_->UpdateQueueTime(clock_->TimeInMilliseconds()); 380 packets_->UpdateQueueTime(clock_->TimeInMilliseconds());
379 int64_t avg_time_left_ms = std::max<int64_t>( 381 int64_t avg_time_left_ms = std::max<int64_t>(
380 1, kMaxQueueLengthMs - packets_->AverageQueueTimeMs()); 382 1, kMaxQueueLengthMs - packets_->AverageQueueTimeMs());
(...skipping 28 matching lines...) Expand all
409 // Send failed, put it back into the queue. 411 // Send failed, put it back into the queue.
410 packets_->CancelPop(packet); 412 packets_->CancelPop(packet);
411 return; 413 return;
412 } 414 }
413 } 415 }
414 416
415 // TODO(holmer): Remove the paused_ check when issue 5307 has been fixed. 417 // TODO(holmer): Remove the paused_ check when issue 5307 has been fixed.
416 if (paused_ || !packets_->Empty()) 418 if (paused_ || !packets_->Empty())
417 return; 419 return;
418 420
419 size_t padding_needed; 421 // We can not send padding unless a normal packet has first been sent. If we
420 if (prober_->IsProbing()) { 422 // do, time stamps gets messed up.
421 padding_needed = prober_->RecommendedPacketSize(); 423 if (packet_counter_ > 0) {
422 } else { 424 size_t padding_needed = prober_->IsProbing()
423 padding_needed = padding_budget_->bytes_remaining(); 425 ? prober_->RecommendedPacketSize()
426 : padding_budget_->bytes_remaining();
427
428 if (padding_needed > 0)
429 SendPadding(static_cast<size_t>(padding_needed));
424 } 430 }
425
426 if (padding_needed > 0)
427 SendPadding(static_cast<size_t>(padding_needed));
428 } 431 }
429 432
430 bool PacedSender::SendPacket(const paced_sender::Packet& packet, 433 bool PacedSender::SendPacket(const paced_sender::Packet& packet,
431 int probe_cluster_id) { 434 int probe_cluster_id) {
432 // TODO(holmer): Because of this bug issue 5307 we have to send audio 435 // TODO(holmer): Because of this bug issue 5307 we have to send audio
433 // packets even when the pacer is paused. Here we assume audio packets are 436 // packets even when the pacer is paused. Here we assume audio packets are
434 // always high priority and that they are the only high priority packets. 437 // always high priority and that they are the only high priority packets.
435 if (paused_ && packet.priority != kHighPriority) 438 if (paused_ && packet.priority != kHighPriority)
436 return false; 439 return false;
437 critsect_->Leave(); 440 critsect_->Leave();
(...skipping 26 matching lines...) Expand all
464 media_budget_->UseBudget(bytes_sent); 467 media_budget_->UseBudget(bytes_sent);
465 padding_budget_->UseBudget(bytes_sent); 468 padding_budget_->UseBudget(bytes_sent);
466 } 469 }
467 } 470 }
468 471
469 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { 472 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) {
470 media_budget_->IncreaseBudget(delta_time_ms); 473 media_budget_->IncreaseBudget(delta_time_ms);
471 padding_budget_->IncreaseBudget(delta_time_ms); 474 padding_budget_->IncreaseBudget(delta_time_ms);
472 } 475 }
473 } // namespace webrtc 476 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698