OLD | NEW |
---|---|
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 Loading... | |
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 if (process_thread_) | |
284 process_thread_->WakeUp(this); | |
stefan-webrtc
2017/03/15 12:43:18
Is there a point in waking up the thread if we're
tommi
2017/03/15 13:42:56
Yes, I added a comment that explains why:
// Te
| |
280 } | 285 } |
281 | 286 |
282 void PacedSender::Resume() { | 287 void PacedSender::Resume() { |
283 LOG(LS_INFO) << "PacedSender resumed."; | 288 LOG(LS_INFO) << "PacedSender resumed."; |
284 CriticalSectionScoped cs(critsect_.get()); | 289 { |
285 paused_ = false; | 290 CriticalSectionScoped cs(critsect_.get()); |
291 paused_ = false; | |
292 } | |
293 if (process_thread_) | |
294 process_thread_->WakeUp(this); | |
286 } | 295 } |
287 | 296 |
288 void PacedSender::SetProbingEnabled(bool enabled) { | 297 void PacedSender::SetProbingEnabled(bool enabled) { |
289 RTC_CHECK_EQ(0, packet_counter_); | 298 RTC_CHECK_EQ(0, packet_counter_); |
290 CriticalSectionScoped cs(critsect_.get()); | 299 CriticalSectionScoped cs(critsect_.get()); |
291 prober_->SetEnabled(enabled); | 300 prober_->SetEnabled(enabled); |
292 } | 301 } |
293 | 302 |
294 void PacedSender::SetEstimatedBitrate(uint32_t bitrate_bps) { | 303 void PacedSender::SetEstimatedBitrate(uint32_t bitrate_bps) { |
295 if (bitrate_bps == 0) | 304 if (bitrate_bps == 0) |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
366 } | 375 } |
367 | 376 |
368 int64_t PacedSender::AverageQueueTimeMs() { | 377 int64_t PacedSender::AverageQueueTimeMs() { |
369 CriticalSectionScoped cs(critsect_.get()); | 378 CriticalSectionScoped cs(critsect_.get()); |
370 packets_->UpdateQueueTime(clock_->TimeInMilliseconds()); | 379 packets_->UpdateQueueTime(clock_->TimeInMilliseconds()); |
371 return packets_->AverageQueueTimeMs(); | 380 return packets_->AverageQueueTimeMs(); |
372 } | 381 } |
373 | 382 |
374 int64_t PacedSender::TimeUntilNextProcess() { | 383 int64_t PacedSender::TimeUntilNextProcess() { |
375 CriticalSectionScoped cs(critsect_.get()); | 384 CriticalSectionScoped cs(critsect_.get()); |
385 if (paused_) | |
386 return 1000 * 60 * 60; | |
387 | |
376 if (prober_->IsProbing()) { | 388 if (prober_->IsProbing()) { |
377 int64_t ret = prober_->TimeUntilNextProbe(clock_->TimeInMilliseconds()); | 389 int64_t ret = prober_->TimeUntilNextProbe(clock_->TimeInMilliseconds()); |
378 if (ret > 0 || (ret == 0 && !probing_send_failure_)) | 390 if (ret > 0 || (ret == 0 && !probing_send_failure_)) |
379 return ret; | 391 return ret; |
380 } | 392 } |
381 int64_t elapsed_time_us = clock_->TimeInMicroseconds() - time_last_update_us_; | 393 int64_t elapsed_time_us = clock_->TimeInMicroseconds() - time_last_update_us_; |
382 int64_t elapsed_time_ms = (elapsed_time_us + 500) / 1000; | 394 int64_t elapsed_time_ms = (elapsed_time_us + 500) / 1000; |
383 return std::max<int64_t>(kMinPacketLimitMs - elapsed_time_ms, 0); | 395 return std::max<int64_t>(kMinPacketLimitMs - elapsed_time_ms, 0); |
384 } | 396 } |
385 | 397 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
450 } | 462 } |
451 } | 463 } |
452 if (is_probing) { | 464 if (is_probing) { |
453 probing_send_failure_ = bytes_sent == 0; | 465 probing_send_failure_ = bytes_sent == 0; |
454 if (!probing_send_failure_) | 466 if (!probing_send_failure_) |
455 prober_->ProbeSent(clock_->TimeInMilliseconds(), bytes_sent); | 467 prober_->ProbeSent(clock_->TimeInMilliseconds(), bytes_sent); |
456 } | 468 } |
457 alr_detector_->OnBytesSent(bytes_sent, now_us / 1000); | 469 alr_detector_->OnBytesSent(bytes_sent, now_us / 1000); |
458 } | 470 } |
459 | 471 |
472 void PacedSender::ProcessThreadAttached(ProcessThread* process_thread) { | |
stefan-webrtc
2017/03/15 12:43:18
We're never detaching because the thread is assume
tommi
2017/03/15 13:42:56
This method is called when the module is registere
stefan-webrtc
2017/03/15 13:51:17
I see, thanks
| |
473 LOG(LS_INFO) << "ProcessThreadAttached 0x" << std::hex << process_thread; | |
474 process_thread_ = process_thread; | |
475 } | |
476 | |
460 bool PacedSender::SendPacket(const paced_sender::Packet& packet, | 477 bool PacedSender::SendPacket(const paced_sender::Packet& packet, |
461 const PacedPacketInfo& pacing_info) { | 478 const PacedPacketInfo& pacing_info) { |
462 if (paused_) | 479 if (paused_) |
463 return false; | 480 return false; |
464 if (media_budget_->bytes_remaining() == 0 && | 481 if (media_budget_->bytes_remaining() == 0 && |
465 pacing_info.probe_cluster_id == PacedPacketInfo::kNotAProbe) { | 482 pacing_info.probe_cluster_id == PacedPacketInfo::kNotAProbe) { |
466 return false; | 483 return false; |
467 } | 484 } |
468 | 485 |
469 critsect_->Leave(); | 486 critsect_->Leave(); |
(...skipping 30 matching lines...) Expand all Loading... | |
500 void PacedSender::UpdateBudgetWithElapsedTime(int64_t delta_time_ms) { | 517 void PacedSender::UpdateBudgetWithElapsedTime(int64_t delta_time_ms) { |
501 media_budget_->IncreaseBudget(delta_time_ms); | 518 media_budget_->IncreaseBudget(delta_time_ms); |
502 padding_budget_->IncreaseBudget(delta_time_ms); | 519 padding_budget_->IncreaseBudget(delta_time_ms); |
503 } | 520 } |
504 | 521 |
505 void PacedSender::UpdateBudgetWithBytesSent(size_t bytes_sent) { | 522 void PacedSender::UpdateBudgetWithBytesSent(size_t bytes_sent) { |
506 media_budget_->UseBudget(bytes_sent); | 523 media_budget_->UseBudget(bytes_sent); |
507 padding_budget_->UseBudget(bytes_sent); | 524 padding_budget_->UseBudget(bytes_sent); |
508 } | 525 } |
509 } // namespace webrtc | 526 } // namespace webrtc |
OLD | NEW |