| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_ABORT); | 75 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_ABORT); |
| 76 | 76 |
| 77 if (!flush_cb_.is_null()) | 77 if (!flush_cb_.is_null()) |
| 78 base::ResetAndReturn(&flush_cb_).Run(); | 78 base::ResetAndReturn(&flush_cb_).Run(); |
| 79 | 79 |
| 80 if (sink_started_) | 80 if (sink_started_) |
| 81 StopSink(); | 81 StopSink(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void VideoRendererImpl::Flush(const base::Closure& callback) { | 84 void VideoRendererImpl::Flush(const base::Closure& callback) { |
| 85 DVLOG(1) << __FUNCTION__; | 85 DVLOG(1) << __func__; |
| 86 DCHECK(task_runner_->BelongsToCurrentThread()); | 86 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 87 | 87 |
| 88 if (sink_started_) | 88 if (sink_started_) |
| 89 StopSink(); | 89 StopSink(); |
| 90 | 90 |
| 91 base::AutoLock auto_lock(lock_); | 91 base::AutoLock auto_lock(lock_); |
| 92 DCHECK_EQ(state_, kPlaying); | 92 DCHECK_EQ(state_, kPlaying); |
| 93 flush_cb_ = callback; | 93 flush_cb_ = callback; |
| 94 state_ = kFlushing; | 94 state_ = kFlushing; |
| 95 | 95 |
| 96 // This is necessary if the |video_frame_stream_| has already seen an end of | 96 // This is necessary if the |video_frame_stream_| has already seen an end of |
| 97 // stream and needs to drain it before flushing it. | 97 // stream and needs to drain it before flushing it. |
| 98 if (buffering_state_ != BUFFERING_HAVE_NOTHING) { | 98 if (buffering_state_ != BUFFERING_HAVE_NOTHING) { |
| 99 buffering_state_ = BUFFERING_HAVE_NOTHING; | 99 buffering_state_ = BUFFERING_HAVE_NOTHING; |
| 100 task_runner_->PostTask( | 100 task_runner_->PostTask( |
| 101 FROM_HERE, base::Bind(&VideoRendererImpl::OnBufferingStateChange, | 101 FROM_HERE, base::Bind(&VideoRendererImpl::OnBufferingStateChange, |
| 102 weak_factory_.GetWeakPtr(), buffering_state_)); | 102 weak_factory_.GetWeakPtr(), buffering_state_)); |
| 103 } | 103 } |
| 104 received_end_of_stream_ = false; | 104 received_end_of_stream_ = false; |
| 105 rendered_end_of_stream_ = false; | 105 rendered_end_of_stream_ = false; |
| 106 | 106 |
| 107 algorithm_->Reset(); | 107 algorithm_->Reset(); |
| 108 | 108 |
| 109 video_frame_stream_->Reset( | 109 video_frame_stream_->Reset( |
| 110 base::Bind(&VideoRendererImpl::OnVideoFrameStreamResetDone, | 110 base::Bind(&VideoRendererImpl::OnVideoFrameStreamResetDone, |
| 111 weak_factory_.GetWeakPtr())); | 111 weak_factory_.GetWeakPtr())); |
| 112 } | 112 } |
| 113 | 113 |
| 114 void VideoRendererImpl::StartPlayingFrom(base::TimeDelta timestamp) { | 114 void VideoRendererImpl::StartPlayingFrom(base::TimeDelta timestamp) { |
| 115 DVLOG(1) << __FUNCTION__ << "(" << timestamp.InMicroseconds() << ")"; | 115 DVLOG(1) << __func__ << "(" << timestamp.InMicroseconds() << ")"; |
| 116 DCHECK(task_runner_->BelongsToCurrentThread()); | 116 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 117 base::AutoLock auto_lock(lock_); | 117 base::AutoLock auto_lock(lock_); |
| 118 DCHECK_EQ(state_, kFlushed); | 118 DCHECK_EQ(state_, kFlushed); |
| 119 DCHECK(!pending_read_); | 119 DCHECK(!pending_read_); |
| 120 DCHECK_EQ(buffering_state_, BUFFERING_HAVE_NOTHING); | 120 DCHECK_EQ(buffering_state_, BUFFERING_HAVE_NOTHING); |
| 121 | 121 |
| 122 state_ = kPlaying; | 122 state_ = kPlaying; |
| 123 start_timestamp_ = timestamp; | 123 start_timestamp_ = timestamp; |
| 124 AttemptRead_Locked(); | 124 AttemptRead_Locked(); |
| 125 } | 125 } |
| (...skipping 57 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 DVLOG(3) << __func__ << " posted TransitionToHaveNothing."; |
| 194 task_runner_->PostTask( | 194 task_runner_->PostTask( |
| 195 FROM_HERE, base::Bind(&VideoRendererImpl::TransitionToHaveNothing, | 195 FROM_HERE, base::Bind(&VideoRendererImpl::TransitionToHaveNothing, |
| 196 weak_factory_.GetWeakPtr())); | 196 weak_factory_.GetWeakPtr())); |
| 197 } | 197 } |
| 198 | 198 |
| 199 // 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 |
| 200 // and impacting JavaScript visible metrics used by web developers. | 200 // and impacting JavaScript visible metrics used by web developers. |
| 201 // | 201 // |
| 202 // 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 |
| 203 // 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... |
| 436 if (was_background_rendering_ && frames_decoded_) | 436 if (was_background_rendering_ && frames_decoded_) |
| 437 return true; | 437 return true; |
| 438 | 438 |
| 439 if (!low_delay_ && video_frame_stream_->CanReadWithoutStalling()) | 439 if (!low_delay_ && video_frame_stream_->CanReadWithoutStalling()) |
| 440 return false; | 440 return false; |
| 441 | 441 |
| 442 return algorithm_->effective_frames_queued() > 0; | 442 return algorithm_->effective_frames_queued() > 0; |
| 443 } | 443 } |
| 444 | 444 |
| 445 void VideoRendererImpl::TransitionToHaveEnough_Locked() { | 445 void VideoRendererImpl::TransitionToHaveEnough_Locked() { |
| 446 DVLOG(3) << __FUNCTION__; | 446 DVLOG(3) << __func__; |
| 447 DCHECK(task_runner_->BelongsToCurrentThread()); | 447 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 448 DCHECK_EQ(buffering_state_, BUFFERING_HAVE_NOTHING); | 448 DCHECK_EQ(buffering_state_, BUFFERING_HAVE_NOTHING); |
| 449 lock_.AssertAcquired(); | 449 lock_.AssertAcquired(); |
| 450 | 450 |
| 451 buffering_state_ = BUFFERING_HAVE_ENOUGH; | 451 buffering_state_ = BUFFERING_HAVE_ENOUGH; |
| 452 task_runner_->PostTask( | 452 task_runner_->PostTask( |
| 453 FROM_HERE, base::Bind(&VideoRendererImpl::OnBufferingStateChange, | 453 FROM_HERE, base::Bind(&VideoRendererImpl::OnBufferingStateChange, |
| 454 weak_factory_.GetWeakPtr(), buffering_state_)); | 454 weak_factory_.GetWeakPtr(), buffering_state_)); |
| 455 } | 455 } |
| 456 | 456 |
| 457 void VideoRendererImpl::TransitionToHaveNothing() { | 457 void VideoRendererImpl::TransitionToHaveNothing() { |
| 458 DVLOG(3) << __FUNCTION__; | 458 DVLOG(3) << __func__; |
| 459 DCHECK(task_runner_->BelongsToCurrentThread()); | 459 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 460 | 460 |
| 461 base::AutoLock auto_lock(lock_); | 461 base::AutoLock auto_lock(lock_); |
| 462 if (buffering_state_ != BUFFERING_HAVE_ENOUGH || HaveEnoughData_Locked()) | 462 if (buffering_state_ != BUFFERING_HAVE_ENOUGH || HaveEnoughData_Locked()) |
| 463 return; | 463 return; |
| 464 | 464 |
| 465 buffering_state_ = BUFFERING_HAVE_NOTHING; | 465 buffering_state_ = BUFFERING_HAVE_NOTHING; |
| 466 task_runner_->PostTask( | 466 task_runner_->PostTask( |
| 467 FROM_HERE, base::Bind(&VideoRendererImpl::OnBufferingStateChange, | 467 FROM_HERE, base::Bind(&VideoRendererImpl::OnBufferingStateChange, |
| 468 weak_factory_.GetWeakPtr(), buffering_state_)); | 468 weak_factory_.GetWeakPtr(), buffering_state_)); |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 | 690 |
| 691 void VideoRendererImpl::AttemptReadAndCheckForMetadataChanges( | 691 void VideoRendererImpl::AttemptReadAndCheckForMetadataChanges( |
| 692 VideoPixelFormat pixel_format, | 692 VideoPixelFormat pixel_format, |
| 693 const gfx::Size& natural_size) { | 693 const gfx::Size& natural_size) { |
| 694 base::AutoLock auto_lock(lock_); | 694 base::AutoLock auto_lock(lock_); |
| 695 CheckForMetadataChanges(pixel_format, natural_size); | 695 CheckForMetadataChanges(pixel_format, natural_size); |
| 696 AttemptRead_Locked(); | 696 AttemptRead_Locked(); |
| 697 } | 697 } |
| 698 | 698 |
| 699 } // namespace media | 699 } // namespace media |
| OLD | NEW |