Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "media/renderers/video_renderer_impl.h" | 5 #include "media/renderers/video_renderer_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 } | 309 } |
| 310 | 310 |
| 311 StartSink(); | 311 StartSink(); |
| 312 } else { | 312 } else { |
| 313 StopSink(); | 313 StopSink(); |
| 314 | 314 |
| 315 // Make sure we expire everything we can if we can't read anymore currently, | 315 // Make sure we expire everything we can if we can't read anymore currently, |
| 316 // otherwise playback may hang indefinitely. Note: There are no effective | 316 // otherwise playback may hang indefinitely. Note: There are no effective |
| 317 // frames queued at this point, otherwise FrameReady() would have canceled | 317 // frames queued at this point, otherwise FrameReady() would have canceled |
| 318 // the underflow state before reaching this point. | 318 // the underflow state before reaching this point. |
| 319 if (buffering_state_ == BUFFERING_HAVE_NOTHING) | 319 if (buffering_state_ == BUFFERING_HAVE_NOTHING) { |
| 320 base::AutoLock al(lock_); | |
|
watk
2016/09/26 23:12:43
I just noticed this. The comment on l.292 says not
DaleCurtis
2016/09/26 23:23:42
I think the comment is out of date since we no lon
| |
| 320 RemoveFramesForUnderflowOrBackgroundRendering(); | 321 RemoveFramesForUnderflowOrBackgroundRendering(); |
| 322 } | |
| 321 } | 323 } |
| 322 } | 324 } |
| 323 | 325 |
| 324 void VideoRendererImpl::FrameReadyForCopyingToGpuMemoryBuffers( | 326 void VideoRendererImpl::FrameReadyForCopyingToGpuMemoryBuffers( |
| 325 VideoFrameStream::Status status, | 327 VideoFrameStream::Status status, |
| 326 const scoped_refptr<VideoFrame>& frame) { | 328 const scoped_refptr<VideoFrame>& frame) { |
| 327 if (status != VideoFrameStream::OK || IsBeforeStartTime(frame->timestamp())) { | 329 if (status != VideoFrameStream::OK || IsBeforeStartTime(frame->timestamp())) { |
| 328 VideoRendererImpl::FrameReady(status, frame); | 330 VideoRendererImpl::FrameReady(status, frame); |
| 329 return; | 331 return; |
| 330 } | 332 } |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 task_runner_->PostTask( | 451 task_runner_->PostTask( |
| 450 FROM_HERE, base::Bind(&VideoRendererImpl::OnBufferingStateChange, | 452 FROM_HERE, base::Bind(&VideoRendererImpl::OnBufferingStateChange, |
| 451 weak_factory_.GetWeakPtr(), buffering_state_)); | 453 weak_factory_.GetWeakPtr(), buffering_state_)); |
| 452 } | 454 } |
| 453 | 455 |
| 454 void VideoRendererImpl::TransitionToHaveNothing() { | 456 void VideoRendererImpl::TransitionToHaveNothing() { |
| 455 DVLOG(3) << __func__; | 457 DVLOG(3) << __func__; |
| 456 DCHECK(task_runner_->BelongsToCurrentThread()); | 458 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 457 | 459 |
| 458 base::AutoLock auto_lock(lock_); | 460 base::AutoLock auto_lock(lock_); |
| 461 TransitionToHaveNothing_Locked(); | |
| 462 } | |
| 463 | |
| 464 void VideoRendererImpl::TransitionToHaveNothing_Locked() { | |
| 465 DVLOG(3) << __func__; | |
| 466 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 467 lock_.AssertAcquired(); | |
| 468 | |
| 459 if (buffering_state_ != BUFFERING_HAVE_ENOUGH || HaveEnoughData_Locked()) | 469 if (buffering_state_ != BUFFERING_HAVE_ENOUGH || HaveEnoughData_Locked()) |
| 460 return; | 470 return; |
| 461 | 471 |
| 462 buffering_state_ = BUFFERING_HAVE_NOTHING; | 472 buffering_state_ = BUFFERING_HAVE_NOTHING; |
| 463 task_runner_->PostTask( | 473 task_runner_->PostTask( |
| 464 FROM_HERE, base::Bind(&VideoRendererImpl::OnBufferingStateChange, | 474 FROM_HERE, base::Bind(&VideoRendererImpl::OnBufferingStateChange, |
| 465 weak_factory_.GetWeakPtr(), buffering_state_)); | 475 weak_factory_.GetWeakPtr(), buffering_state_)); |
| 466 } | 476 } |
| 467 | 477 |
| 468 void VideoRendererImpl::AddReadyFrame_Locked( | 478 void VideoRendererImpl::AddReadyFrame_Locked( |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 650 frames_dropped_ += algorithm_->RemoveExpiredFrames( | 660 frames_dropped_ += algorithm_->RemoveExpiredFrames( |
| 651 current_time + algorithm_->average_frame_duration()); | 661 current_time + algorithm_->average_frame_duration()); |
| 652 | 662 |
| 653 // If we've paused for underflow, and still have no effective frames, clear | 663 // If we've paused for underflow, and still have no effective frames, clear |
| 654 // the entire queue. Note: this may cause slight inaccuracies in the number | 664 // the entire queue. Note: this may cause slight inaccuracies in the number |
| 655 // of dropped frames since the frame may have been rendered before. | 665 // of dropped frames since the frame may have been rendered before. |
| 656 if (!sink_started_ && !algorithm_->effective_frames_queued()) { | 666 if (!sink_started_ && !algorithm_->effective_frames_queued()) { |
| 657 frames_dropped_ += algorithm_->frames_queued(); | 667 frames_dropped_ += algorithm_->frames_queued(); |
| 658 algorithm_->Reset( | 668 algorithm_->Reset( |
| 659 VideoRendererAlgorithm::ResetFlag::kPreserveNextFrameEstimates); | 669 VideoRendererAlgorithm::ResetFlag::kPreserveNextFrameEstimates); |
| 670 | |
| 671 // It's possible in the background rendering case for us to expire enough | |
| 672 // frames that we need to transition from HAVE_ENOUGH => HAVE_NOTHING. Just | |
| 673 // calling this function will check if we need to transition or not. | |
| 674 if (buffering_state_ == BUFFERING_HAVE_ENOUGH) | |
| 675 TransitionToHaveNothing_Locked(); | |
| 660 } | 676 } |
| 661 } | 677 } |
| 662 | 678 |
| 663 void VideoRendererImpl::CheckForMetadataChanges(VideoPixelFormat pixel_format, | 679 void VideoRendererImpl::CheckForMetadataChanges(VideoPixelFormat pixel_format, |
| 664 const gfx::Size& natural_size) { | 680 const gfx::Size& natural_size) { |
| 665 DCHECK(task_runner_->BelongsToCurrentThread()); | 681 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 666 | 682 |
| 667 // Notify client of size and opacity changes if this is the first frame | 683 // Notify client of size and opacity changes if this is the first frame |
| 668 // or if those have changed from the last frame. | 684 // or if those have changed from the last frame. |
| 669 if (!have_renderered_frames_ || last_frame_natural_size_ != natural_size) { | 685 if (!have_renderered_frames_ || last_frame_natural_size_ != natural_size) { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 682 | 698 |
| 683 void VideoRendererImpl::AttemptReadAndCheckForMetadataChanges( | 699 void VideoRendererImpl::AttemptReadAndCheckForMetadataChanges( |
| 684 VideoPixelFormat pixel_format, | 700 VideoPixelFormat pixel_format, |
| 685 const gfx::Size& natural_size) { | 701 const gfx::Size& natural_size) { |
| 686 base::AutoLock auto_lock(lock_); | 702 base::AutoLock auto_lock(lock_); |
| 687 CheckForMetadataChanges(pixel_format, natural_size); | 703 CheckForMetadataChanges(pixel_format, natural_size); |
| 688 AttemptRead_Locked(); | 704 AttemptRead_Locked(); |
| 689 } | 705 } |
| 690 | 706 |
| 691 } // namespace media | 707 } // namespace media |
| OLD | NEW |