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

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

Issue 2746153002: Return a long timeout value from TimeUntilNextProcess when the PacedSender is paused (Closed)
Patch Set: Address comments Created 3 years, 9 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/paced_sender.h ('k') | webrtc/modules/pacing/paced_sender_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) 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
11 #include "webrtc/modules/pacing/paced_sender.h" 11 #include "webrtc/modules/pacing/paced_sender.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <map> 14 #include <map>
15 #include <queue> 15 #include <queue>
16 #include <set> 16 #include <set>
17 #include <vector> 17 #include <vector>
18 18
19 #include "webrtc/base/checks.h" 19 #include "webrtc/base/checks.h"
20 #include "webrtc/base/logging.h" 20 #include "webrtc/base/logging.h"
21 #include "webrtc/modules/include/module_common_types.h" 21 #include "webrtc/modules/include/module_common_types.h"
22 #include "webrtc/modules/pacing/alr_detector.h" 22 #include "webrtc/modules/pacing/alr_detector.h"
23 #include "webrtc/modules/pacing/bitrate_prober.h" 23 #include "webrtc/modules/pacing/bitrate_prober.h"
24 #include "webrtc/modules/utility/include/process_thread.h"
24 #include "webrtc/system_wrappers/include/clock.h" 25 #include "webrtc/system_wrappers/include/clock.h"
25 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" 26 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
26 #include "webrtc/system_wrappers/include/field_trial.h" 27 #include "webrtc/system_wrappers/include/field_trial.h"
27 28
28 namespace { 29 namespace {
29 // Time limit in milliseconds between packet bursts. 30 // Time limit in milliseconds between packet bursts.
30 const int64_t kMinPacketLimitMs = 5; 31 const int64_t kMinPacketLimitMs = 5;
31 32
32 // Upper cap on process interval, in case process has not been called in a long 33 // Upper cap on process interval, in case process has not been called in a long
33 // time. 34 // time.
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 269
269 PacedSender::~PacedSender() {} 270 PacedSender::~PacedSender() {}
270 271
271 void PacedSender::CreateProbeCluster(int bitrate_bps) { 272 void PacedSender::CreateProbeCluster(int bitrate_bps) {
272 CriticalSectionScoped cs(critsect_.get()); 273 CriticalSectionScoped cs(critsect_.get());
273 prober_->CreateProbeCluster(bitrate_bps, clock_->TimeInMilliseconds()); 274 prober_->CreateProbeCluster(bitrate_bps, clock_->TimeInMilliseconds());
274 } 275 }
275 276
276 void PacedSender::Pause() { 277 void PacedSender::Pause() {
277 LOG(LS_INFO) << "PacedSender paused."; 278 LOG(LS_INFO) << "PacedSender paused.";
278 CriticalSectionScoped cs(critsect_.get()); 279 {
279 paused_ = true; 280 CriticalSectionScoped cs(critsect_.get());
281 paused_ = true;
282 }
283 // Tell the process thread to call our TimeUntilNextProcess() method to get
284 // a new (longer) estimate for when to call Process().
285 if (process_thread_)
286 process_thread_->WakeUp(this);
280 } 287 }
281 288
282 void PacedSender::Resume() { 289 void PacedSender::Resume() {
283 LOG(LS_INFO) << "PacedSender resumed."; 290 LOG(LS_INFO) << "PacedSender resumed.";
284 CriticalSectionScoped cs(critsect_.get()); 291 {
285 paused_ = false; 292 CriticalSectionScoped cs(critsect_.get());
293 paused_ = false;
294 }
295 // Tell the process thread to call our TimeUntilNextProcess() method to
296 // refresh the estimate for when to call Process().
297 if (process_thread_)
298 process_thread_->WakeUp(this);
286 } 299 }
287 300
288 void PacedSender::SetProbingEnabled(bool enabled) { 301 void PacedSender::SetProbingEnabled(bool enabled) {
289 RTC_CHECK_EQ(0, packet_counter_); 302 RTC_CHECK_EQ(0, packet_counter_);
290 CriticalSectionScoped cs(critsect_.get()); 303 CriticalSectionScoped cs(critsect_.get());
291 prober_->SetEnabled(enabled); 304 prober_->SetEnabled(enabled);
292 } 305 }
293 306
294 void PacedSender::SetEstimatedBitrate(uint32_t bitrate_bps) { 307 void PacedSender::SetEstimatedBitrate(uint32_t bitrate_bps) {
295 if (bitrate_bps == 0) 308 if (bitrate_bps == 0)
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 } 379 }
367 380
368 int64_t PacedSender::AverageQueueTimeMs() { 381 int64_t PacedSender::AverageQueueTimeMs() {
369 CriticalSectionScoped cs(critsect_.get()); 382 CriticalSectionScoped cs(critsect_.get());
370 packets_->UpdateQueueTime(clock_->TimeInMilliseconds()); 383 packets_->UpdateQueueTime(clock_->TimeInMilliseconds());
371 return packets_->AverageQueueTimeMs(); 384 return packets_->AverageQueueTimeMs();
372 } 385 }
373 386
374 int64_t PacedSender::TimeUntilNextProcess() { 387 int64_t PacedSender::TimeUntilNextProcess() {
375 CriticalSectionScoped cs(critsect_.get()); 388 CriticalSectionScoped cs(critsect_.get());
389 if (paused_)
390 return 1000 * 60 * 60;
391
376 if (prober_->IsProbing()) { 392 if (prober_->IsProbing()) {
377 int64_t ret = prober_->TimeUntilNextProbe(clock_->TimeInMilliseconds()); 393 int64_t ret = prober_->TimeUntilNextProbe(clock_->TimeInMilliseconds());
378 if (ret > 0 || (ret == 0 && !probing_send_failure_)) 394 if (ret > 0 || (ret == 0 && !probing_send_failure_))
379 return ret; 395 return ret;
380 } 396 }
381 int64_t elapsed_time_us = clock_->TimeInMicroseconds() - time_last_update_us_; 397 int64_t elapsed_time_us = clock_->TimeInMicroseconds() - time_last_update_us_;
382 int64_t elapsed_time_ms = (elapsed_time_us + 500) / 1000; 398 int64_t elapsed_time_ms = (elapsed_time_us + 500) / 1000;
383 return std::max<int64_t>(kMinPacketLimitMs - elapsed_time_ms, 0); 399 return std::max<int64_t>(kMinPacketLimitMs - elapsed_time_ms, 0);
384 } 400 }
385 401
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 } 466 }
451 } 467 }
452 if (is_probing) { 468 if (is_probing) {
453 probing_send_failure_ = bytes_sent == 0; 469 probing_send_failure_ = bytes_sent == 0;
454 if (!probing_send_failure_) 470 if (!probing_send_failure_)
455 prober_->ProbeSent(clock_->TimeInMilliseconds(), bytes_sent); 471 prober_->ProbeSent(clock_->TimeInMilliseconds(), bytes_sent);
456 } 472 }
457 alr_detector_->OnBytesSent(bytes_sent, now_us / 1000); 473 alr_detector_->OnBytesSent(bytes_sent, now_us / 1000);
458 } 474 }
459 475
476 void PacedSender::ProcessThreadAttached(ProcessThread* process_thread) {
477 LOG(LS_INFO) << "ProcessThreadAttached 0x" << std::hex << process_thread;
478 process_thread_ = process_thread;
479 }
480
460 bool PacedSender::SendPacket(const paced_sender::Packet& packet, 481 bool PacedSender::SendPacket(const paced_sender::Packet& packet,
461 const PacedPacketInfo& pacing_info) { 482 const PacedPacketInfo& pacing_info) {
462 if (paused_) 483 if (paused_)
463 return false; 484 return false;
464 if (media_budget_->bytes_remaining() == 0 && 485 if (media_budget_->bytes_remaining() == 0 &&
465 pacing_info.probe_cluster_id == PacedPacketInfo::kNotAProbe) { 486 pacing_info.probe_cluster_id == PacedPacketInfo::kNotAProbe) {
466 return false; 487 return false;
467 } 488 }
468 489
469 critsect_->Leave(); 490 critsect_->Leave();
(...skipping 30 matching lines...) Expand all
500 void PacedSender::UpdateBudgetWithElapsedTime(int64_t delta_time_ms) { 521 void PacedSender::UpdateBudgetWithElapsedTime(int64_t delta_time_ms) {
501 media_budget_->IncreaseBudget(delta_time_ms); 522 media_budget_->IncreaseBudget(delta_time_ms);
502 padding_budget_->IncreaseBudget(delta_time_ms); 523 padding_budget_->IncreaseBudget(delta_time_ms);
503 } 524 }
504 525
505 void PacedSender::UpdateBudgetWithBytesSent(size_t bytes_sent) { 526 void PacedSender::UpdateBudgetWithBytesSent(size_t bytes_sent) {
506 media_budget_->UseBudget(bytes_sent); 527 media_budget_->UseBudget(bytes_sent);
507 padding_budget_->UseBudget(bytes_sent); 528 padding_budget_->UseBudget(bytes_sent);
508 } 529 }
509 } // namespace webrtc 530 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/pacing/paced_sender.h ('k') | webrtc/modules/pacing/paced_sender_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698