| 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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 // end of stream, or have frames available. We also don't want to do this in | 183 // end of stream, or have frames available. We also don't want to do this in |
| 184 // background rendering mode unless this isn't the first background render | 184 // background rendering mode unless this isn't the first background render |
| 185 // tick and we haven't seen any decoded frames since the last one. | 185 // tick and we haven't seen any decoded frames since the last one. |
| 186 MaybeFireEndedCallback_Locked(true); | 186 MaybeFireEndedCallback_Locked(true); |
| 187 if (buffering_state_ == BUFFERING_HAVE_ENOUGH && !received_end_of_stream_ && | 187 if (buffering_state_ == BUFFERING_HAVE_ENOUGH && !received_end_of_stream_ && |
| 188 !algorithm_->effective_frames_queued() && | 188 !algorithm_->effective_frames_queued() && |
| 189 (!background_rendering || | 189 (!background_rendering || |
| 190 (!frames_decoded_ && was_background_rendering_))) { | 190 (!frames_decoded_ && was_background_rendering_))) { |
| 191 // Do not set |buffering_state_| here as the lock in FrameReady() may be | 191 // Do not set |buffering_state_| here as the lock in FrameReady() may be |
| 192 // held already and it fire the state changes in the wrong order. | 192 // held already and it fire the state changes in the wrong order. |
| 193 DVLOG(3) << __FUNCTION__ << " posted TransitionToHaveNothing."; |
| 193 task_runner_->PostTask( | 194 task_runner_->PostTask( |
| 194 FROM_HERE, base::Bind(&VideoRendererImpl::TransitionToHaveNothing, | 195 FROM_HERE, base::Bind(&VideoRendererImpl::TransitionToHaveNothing, |
| 195 weak_factory_.GetWeakPtr())); | 196 weak_factory_.GetWeakPtr())); |
| 196 } | 197 } |
| 197 | 198 |
| 198 // We don't count dropped frames in the background to avoid skewing the count | 199 // We don't count dropped frames in the background to avoid skewing the count |
| 199 // and impacting JavaScript visible metrics used by web developers. | 200 // and impacting JavaScript visible metrics used by web developers. |
| 200 // | 201 // |
| 201 // Just after resuming from background rendering, we also don't count the | 202 // Just after resuming from background rendering, we also don't count the |
| 202 // dropped frames since they are likely just dropped due to being too old. | 203 // dropped frames since they are likely just dropped due to being too old. |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 if (was_background_rendering_ && frames_decoded_) | 436 if (was_background_rendering_ && frames_decoded_) |
| 436 return true; | 437 return true; |
| 437 | 438 |
| 438 if (!low_delay_ && video_frame_stream_->CanReadWithoutStalling()) | 439 if (!low_delay_ && video_frame_stream_->CanReadWithoutStalling()) |
| 439 return false; | 440 return false; |
| 440 | 441 |
| 441 return algorithm_->effective_frames_queued() > 0; | 442 return algorithm_->effective_frames_queued() > 0; |
| 442 } | 443 } |
| 443 | 444 |
| 444 void VideoRendererImpl::TransitionToHaveEnough_Locked() { | 445 void VideoRendererImpl::TransitionToHaveEnough_Locked() { |
| 446 DVLOG(3) << __FUNCTION__; |
| 445 DCHECK(task_runner_->BelongsToCurrentThread()); | 447 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 446 DCHECK_EQ(buffering_state_, BUFFERING_HAVE_NOTHING); | 448 DCHECK_EQ(buffering_state_, BUFFERING_HAVE_NOTHING); |
| 447 lock_.AssertAcquired(); | 449 lock_.AssertAcquired(); |
| 448 | 450 |
| 449 buffering_state_ = BUFFERING_HAVE_ENOUGH; | 451 buffering_state_ = BUFFERING_HAVE_ENOUGH; |
| 450 task_runner_->PostTask( | 452 task_runner_->PostTask( |
| 451 FROM_HERE, base::Bind(&VideoRendererImpl::OnBufferingStateChange, | 453 FROM_HERE, base::Bind(&VideoRendererImpl::OnBufferingStateChange, |
| 452 weak_factory_.GetWeakPtr(), buffering_state_)); | 454 weak_factory_.GetWeakPtr(), buffering_state_)); |
| 453 } | 455 } |
| 454 | 456 |
| 455 void VideoRendererImpl::TransitionToHaveNothing() { | 457 void VideoRendererImpl::TransitionToHaveNothing() { |
| 458 DVLOG(3) << __FUNCTION__; |
| 456 DCHECK(task_runner_->BelongsToCurrentThread()); | 459 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 457 | 460 |
| 458 base::AutoLock auto_lock(lock_); | 461 base::AutoLock auto_lock(lock_); |
| 459 if (buffering_state_ != BUFFERING_HAVE_ENOUGH || HaveEnoughData_Locked()) | 462 if (buffering_state_ != BUFFERING_HAVE_ENOUGH || HaveEnoughData_Locked()) |
| 460 return; | 463 return; |
| 461 | 464 |
| 462 buffering_state_ = BUFFERING_HAVE_NOTHING; | 465 buffering_state_ = BUFFERING_HAVE_NOTHING; |
| 463 task_runner_->PostTask( | 466 task_runner_->PostTask( |
| 464 FROM_HERE, base::Bind(&VideoRendererImpl::OnBufferingStateChange, | 467 FROM_HERE, base::Bind(&VideoRendererImpl::OnBufferingStateChange, |
| 465 weak_factory_.GetWeakPtr(), buffering_state_)); | 468 weak_factory_.GetWeakPtr(), buffering_state_)); |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 | 690 |
| 688 void VideoRendererImpl::AttemptReadAndCheckForMetadataChanges( | 691 void VideoRendererImpl::AttemptReadAndCheckForMetadataChanges( |
| 689 VideoPixelFormat pixel_format, | 692 VideoPixelFormat pixel_format, |
| 690 const gfx::Size& natural_size) { | 693 const gfx::Size& natural_size) { |
| 691 base::AutoLock auto_lock(lock_); | 694 base::AutoLock auto_lock(lock_); |
| 692 CheckForMetadataChanges(pixel_format, natural_size); | 695 CheckForMetadataChanges(pixel_format, natural_size); |
| 693 AttemptRead_Locked(); | 696 AttemptRead_Locked(); |
| 694 } | 697 } |
| 695 | 698 |
| 696 } // namespace media | 699 } // namespace media |
| OLD | NEW |