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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 // and MaybeStopSinkAfterFirstPaint() will ignore this request if time starts | 232 // and MaybeStopSinkAfterFirstPaint() will ignore this request if time starts |
233 // before the call executes. | 233 // before the call executes. |
234 if (render_first_frame_and_stop_ && !posted_maybe_stop_after_first_paint_) { | 234 if (render_first_frame_and_stop_ && !posted_maybe_stop_after_first_paint_) { |
235 posted_maybe_stop_after_first_paint_ = true; | 235 posted_maybe_stop_after_first_paint_ = true; |
236 task_runner_->PostDelayedTask( | 236 task_runner_->PostDelayedTask( |
237 FROM_HERE, base::Bind(&VideoRendererImpl::MaybeStopSinkAfterFirstPaint, | 237 FROM_HERE, base::Bind(&VideoRendererImpl::MaybeStopSinkAfterFirstPaint, |
238 weak_factory_.GetWeakPtr()), | 238 weak_factory_.GetWeakPtr()), |
239 base::TimeDelta::FromMilliseconds(250)); | 239 base::TimeDelta::FromMilliseconds(250)); |
240 } | 240 } |
241 | 241 |
242 // To avoid unnecessary work, only post this task if there is a chance of work | 242 // Always post this task, it will acquire new frames if necessary and since it |
243 // to be done. AttemptRead() may still ignore this call for other reasons. | 243 // happens on another thread, even if we don't have room in the queue now, by |
244 if (!rendered_end_of_stream_ && !HaveReachedBufferingCap(effective_frames)) { | 244 // the time it runs (may be delayed up to 50ms for complex decodes!) we might. |
245 task_runner_->PostTask(FROM_HERE, | 245 task_runner_->PostTask(FROM_HERE, base::Bind(&VideoRendererImpl::AttemptRead, |
246 base::Bind(&VideoRendererImpl::AttemptRead, | 246 weak_factory_.GetWeakPtr())); |
247 weak_factory_.GetWeakPtr())); | |
248 } | |
249 | 247 |
250 return result; | 248 return result; |
251 } | 249 } |
252 | 250 |
253 void VideoRendererImpl::OnFrameDropped() { | 251 void VideoRendererImpl::OnFrameDropped() { |
254 base::AutoLock auto_lock(lock_); | 252 base::AutoLock auto_lock(lock_); |
255 DCHECK(use_new_video_renderering_path_); | 253 DCHECK(use_new_video_renderering_path_); |
256 algorithm_->OnLastFrameDropped(); | 254 algorithm_->OnLastFrameDropped(); |
257 } | 255 } |
258 | 256 |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 base::AutoLock auto_lock(lock_); | 676 base::AutoLock auto_lock(lock_); |
679 render_first_frame_and_stop_ = false; | 677 render_first_frame_and_stop_ = false; |
680 } | 678 } |
681 | 679 |
682 if (!time_progressing_ && sink_started_) | 680 if (!time_progressing_ && sink_started_) |
683 StopSink(); | 681 StopSink(); |
684 } | 682 } |
685 | 683 |
686 bool VideoRendererImpl::HaveReachedBufferingCap() { | 684 bool VideoRendererImpl::HaveReachedBufferingCap() { |
687 DCHECK(task_runner_->BelongsToCurrentThread()); | 685 DCHECK(task_runner_->BelongsToCurrentThread()); |
688 return HaveReachedBufferingCap(use_new_video_renderering_path_ | 686 const size_t kMaxVideoFrames = limits::kMaxVideoFrames; |
689 ? algorithm_->EffectiveFramesQueued() | |
690 : 0); | |
691 } | |
692 | 687 |
693 bool VideoRendererImpl::HaveReachedBufferingCap(size_t effective_frames) { | |
694 if (use_new_video_renderering_path_) { | 688 if (use_new_video_renderering_path_) { |
695 // When the display rate is less than the frame rate, the effective frames | 689 // When the display rate is less than the frame rate, the effective frames |
696 // queued may be much smaller than the actual number of frames queued. Here | 690 // queued may be much smaller than the actual number of frames queued. Here |
697 // we ensure that frames_queued() doesn't get excessive. | 691 // we ensure that frames_queued() doesn't get excessive. |
698 return effective_frames >= static_cast<size_t>(limits::kMaxVideoFrames) || | 692 return algorithm_->EffectiveFramesQueued() >= kMaxVideoFrames || |
699 algorithm_->frames_queued() >= | 693 algorithm_->frames_queued() >= 3 * kMaxVideoFrames; |
700 static_cast<size_t>(3 * limits::kMaxVideoFrames); | |
701 } | 694 } |
702 | 695 |
703 return ready_frames_.size() >= static_cast<size_t>(limits::kMaxVideoFrames); | 696 return ready_frames_.size() >= kMaxVideoFrames; |
704 } | 697 } |
705 | 698 |
706 void VideoRendererImpl::StartSink() { | 699 void VideoRendererImpl::StartSink() { |
707 DCHECK(task_runner_->BelongsToCurrentThread()); | 700 DCHECK(task_runner_->BelongsToCurrentThread()); |
708 sink_->Start(this); | 701 sink_->Start(this); |
709 sink_started_ = true; | 702 sink_started_ = true; |
710 was_background_rendering_ = false; | 703 was_background_rendering_ = false; |
711 } | 704 } |
712 | 705 |
713 void VideoRendererImpl::StopSink() { | 706 void VideoRendererImpl::StopSink() { |
(...skipping 23 matching lines...) Expand all Loading... |
737 (algorithm_->frames_queued() == 1u && | 730 (algorithm_->frames_queued() == 1u && |
738 algorithm_->average_frame_duration() == base::TimeDelta())) { | 731 algorithm_->average_frame_duration() == base::TimeDelta())) { |
739 rendered_end_of_stream_ = true; | 732 rendered_end_of_stream_ = true; |
740 task_runner_->PostTask(FROM_HERE, ended_cb_); | 733 task_runner_->PostTask(FROM_HERE, ended_cb_); |
741 } | 734 } |
742 | 735 |
743 return effective_frames; | 736 return effective_frames; |
744 } | 737 } |
745 | 738 |
746 } // namespace media | 739 } // namespace media |
OLD | NEW |