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