| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromecast/media/cma/pipeline/media_pipeline_impl.h" | 5 #include "chromecast/media/cma/pipeline/media_pipeline_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 base::Closure done_cb; | 80 base::Closure done_cb; |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 MediaPipelineImpl::MediaPipelineImpl() | 83 MediaPipelineImpl::MediaPipelineImpl() |
| 84 : cdm_context_(nullptr), | 84 : cdm_context_(nullptr), |
| 85 backend_state_(BACKEND_STATE_UNINITIALIZED), | 85 backend_state_(BACKEND_STATE_UNINITIALIZED), |
| 86 playback_rate_(1.0f), | 86 playback_rate_(1.0f), |
| 87 audio_decoder_(nullptr), | 87 audio_decoder_(nullptr), |
| 88 video_decoder_(nullptr), | 88 video_decoder_(nullptr), |
| 89 pending_time_update_task_(false), | 89 pending_time_update_task_(false), |
| 90 last_media_time_(::media::kNoTimestamp()), | 90 last_media_time_(::media::kNoTimestamp), |
| 91 statistics_rolling_counter_(0), | 91 statistics_rolling_counter_(0), |
| 92 audio_bytes_for_bitrate_estimation_(0), | 92 audio_bytes_for_bitrate_estimation_(0), |
| 93 video_bytes_for_bitrate_estimation_(0), | 93 video_bytes_for_bitrate_estimation_(0), |
| 94 playback_stalled_(false), | 94 playback_stalled_(false), |
| 95 playback_stalled_notification_sent_(false), | 95 playback_stalled_notification_sent_(false), |
| 96 weak_factory_(this) { | 96 weak_factory_(this) { |
| 97 CMALOG(kLogControl) << __FUNCTION__; | 97 CMALOG(kLogControl) << __FUNCTION__; |
| 98 weak_this_ = weak_factory_.GetWeakPtr(); | 98 weak_this_ = weak_factory_.GetWeakPtr(); |
| 99 thread_checker_.DetachFromThread(); | 99 thread_checker_.DetachFromThread(); |
| 100 } | 100 } |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 } else if (!is_buffering && (backend_state_ == BACKEND_STATE_PAUSED)) { | 425 } else if (!is_buffering && (backend_state_ == BACKEND_STATE_PAUSED)) { |
| 426 // Once we finish buffering, we need to honour the desired playback rate | 426 // Once we finish buffering, we need to honour the desired playback rate |
| 427 // (rather than just resuming). This way, if playback was paused while | 427 // (rather than just resuming). This way, if playback was paused while |
| 428 // buffering, it will remain paused rather than incorrectly resuming. | 428 // buffering, it will remain paused rather than incorrectly resuming. |
| 429 SetPlaybackRate(playback_rate_); | 429 SetPlaybackRate(playback_rate_); |
| 430 } | 430 } |
| 431 } | 431 } |
| 432 | 432 |
| 433 void MediaPipelineImpl::CheckForPlaybackStall(base::TimeDelta media_time, | 433 void MediaPipelineImpl::CheckForPlaybackStall(base::TimeDelta media_time, |
| 434 base::TimeTicks current_stc) { | 434 base::TimeTicks current_stc) { |
| 435 DCHECK(media_time != ::media::kNoTimestamp()); | 435 DCHECK(media_time != ::media::kNoTimestamp); |
| 436 | 436 |
| 437 // A playback stall is defined as a scenario where the underlying media | 437 // A playback stall is defined as a scenario where the underlying media |
| 438 // pipeline has unexpectedly stopped making forward progress. The pipeline is | 438 // pipeline has unexpectedly stopped making forward progress. The pipeline is |
| 439 // NOT stalled if: | 439 // NOT stalled if: |
| 440 // | 440 // |
| 441 // 1. Media time is progressing | 441 // 1. Media time is progressing |
| 442 // 2. The backend is paused | 442 // 2. The backend is paused |
| 443 // 3. We are currently buffering (this is captured in a separate event) | 443 // 3. We are currently buffering (this is captured in a separate event) |
| 444 if (media_time != last_media_time_ || | 444 if (media_time != last_media_time_ || |
| 445 backend_state_ != BACKEND_STATE_PLAYING || | 445 backend_state_ != BACKEND_STATE_PLAYING || |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 } | 513 } |
| 514 last_sample_time_ = current_time; | 514 last_sample_time_ = current_time; |
| 515 } | 515 } |
| 516 } | 516 } |
| 517 | 517 |
| 518 statistics_rolling_counter_ = | 518 statistics_rolling_counter_ = |
| 519 (statistics_rolling_counter_ + 1) % kStatisticsUpdatePeriod; | 519 (statistics_rolling_counter_ + 1) % kStatisticsUpdatePeriod; |
| 520 | 520 |
| 521 base::TimeDelta media_time = base::TimeDelta::FromMicroseconds( | 521 base::TimeDelta media_time = base::TimeDelta::FromMicroseconds( |
| 522 media_pipeline_backend_->GetCurrentPts()); | 522 media_pipeline_backend_->GetCurrentPts()); |
| 523 if (media_time == ::media::kNoTimestamp()) { | 523 if (media_time == ::media::kNoTimestamp) { |
| 524 pending_time_update_task_ = true; | 524 pending_time_update_task_ = true; |
| 525 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 525 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 526 FROM_HERE, base::Bind(&MediaPipelineImpl::UpdateMediaTime, weak_this_), | 526 FROM_HERE, base::Bind(&MediaPipelineImpl::UpdateMediaTime, weak_this_), |
| 527 kTimeUpdateInterval); | 527 kTimeUpdateInterval); |
| 528 return; | 528 return; |
| 529 } | 529 } |
| 530 base::TimeTicks stc = base::TimeTicks::Now(); | 530 base::TimeTicks stc = base::TimeTicks::Now(); |
| 531 | 531 |
| 532 CheckForPlaybackStall(media_time, stc); | 532 CheckForPlaybackStall(media_time, stc); |
| 533 | 533 |
| 534 base::TimeDelta max_rendering_time = media_time; | 534 base::TimeDelta max_rendering_time = media_time; |
| 535 if (buffering_controller_) { | 535 if (buffering_controller_) { |
| 536 buffering_controller_->SetMediaTime(media_time); | 536 buffering_controller_->SetMediaTime(media_time); |
| 537 | 537 |
| 538 // Receiving the same time twice in a row means playback isn't moving, | 538 // Receiving the same time twice in a row means playback isn't moving, |
| 539 // so don't interpolate ahead. | 539 // so don't interpolate ahead. |
| 540 if (media_time != last_media_time_) { | 540 if (media_time != last_media_time_) { |
| 541 max_rendering_time = buffering_controller_->GetMaxRenderingTime(); | 541 max_rendering_time = buffering_controller_->GetMaxRenderingTime(); |
| 542 if (max_rendering_time == ::media::kNoTimestamp()) | 542 if (max_rendering_time == ::media::kNoTimestamp) |
| 543 max_rendering_time = media_time; | 543 max_rendering_time = media_time; |
| 544 | 544 |
| 545 // Cap interpolation time to avoid interpolating too far ahead. | 545 // Cap interpolation time to avoid interpolating too far ahead. |
| 546 max_rendering_time = | 546 max_rendering_time = |
| 547 std::min(max_rendering_time, media_time + 2 * kTimeUpdateInterval); | 547 std::min(max_rendering_time, media_time + 2 * kTimeUpdateInterval); |
| 548 } | 548 } |
| 549 } | 549 } |
| 550 | 550 |
| 551 last_media_time_ = media_time; | 551 last_media_time_ = media_time; |
| 552 if (!client_.time_update_cb.is_null()) | 552 if (!client_.time_update_cb.is_null()) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 571 | 571 |
| 572 void MediaPipelineImpl::ResetBitrateState() { | 572 void MediaPipelineImpl::ResetBitrateState() { |
| 573 elapsed_time_delta_ = base::TimeDelta::FromSeconds(0); | 573 elapsed_time_delta_ = base::TimeDelta::FromSeconds(0); |
| 574 audio_bytes_for_bitrate_estimation_ = 0; | 574 audio_bytes_for_bitrate_estimation_ = 0; |
| 575 video_bytes_for_bitrate_estimation_ = 0; | 575 video_bytes_for_bitrate_estimation_ = 0; |
| 576 last_sample_time_ = base::TimeTicks::Now(); | 576 last_sample_time_ = base::TimeTicks::Now(); |
| 577 } | 577 } |
| 578 | 578 |
| 579 } // namespace media | 579 } // namespace media |
| 580 } // namespace chromecast | 580 } // namespace chromecast |
| OLD | NEW |