Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(874)

Side by Side Diff: media/renderers/video_renderer_impl.cc

Issue 2570013003: Fix underflow correction occurring during normal rendering. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/renderers/video_renderer_impl.h ('k') | media/renderers/video_renderer_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 std::vector<base::TimeTicks> current_time; 631 std::vector<base::TimeTicks> current_time;
632 wall_clock_time_cb_.Run(std::vector<base::TimeDelta>(), &current_time); 632 wall_clock_time_cb_.Run(std::vector<base::TimeDelta>(), &current_time);
633 return current_time[0]; 633 return current_time[0];
634 } 634 }
635 635
636 bool VideoRendererImpl::IsBeforeStartTime(base::TimeDelta timestamp) { 636 bool VideoRendererImpl::IsBeforeStartTime(base::TimeDelta timestamp) {
637 return timestamp + video_frame_stream_->AverageDuration() < start_timestamp_; 637 return timestamp + video_frame_stream_->AverageDuration() < start_timestamp_;
638 } 638 }
639 639
640 void VideoRendererImpl::RemoveFramesForUnderflowOrBackgroundRendering() { 640 void VideoRendererImpl::RemoveFramesForUnderflowOrBackgroundRendering() {
641 // Nothing to do if we're not underflowing, background rendering, or frame 641 // Nothing to do if frame dropping is disabled for testing or we have nothing.
642 // dropping is disabled (test only). 642 if (!drop_frames_ || !algorithm_->frames_queued())
643 const bool have_nothing = buffering_state_ == BUFFERING_HAVE_NOTHING;
644 if (!was_background_rendering_ && !have_nothing && !drop_frames_)
645 return;
646
647 // If there are no frames to remove, nothing can be done.
648 if (!algorithm_->frames_queued())
649 return; 643 return;
650 644
651 // If we're paused for prerolling (current time is 0), don't expire any 645 // If we're paused for prerolling (current time is 0), don't expire any
652 // frames. It's possible that during preroll |have_nothing| is false while 646 // frames. It's possible that during preroll |have_nothing| is false while
653 // |was_background_rendering_| is true. We differentiate this from actual 647 // |was_background_rendering_| is true. We differentiate this from actual
654 // background rendering by checking if current time is 0. 648 // background rendering by checking if current time is 0.
655 const base::TimeTicks current_time = GetCurrentMediaTimeAsWallClockTime(); 649 const base::TimeTicks current_time = GetCurrentMediaTimeAsWallClockTime();
656 if (current_time.is_null()) 650 if (current_time.is_null())
657 return; 651 return;
658 652
659 // Background rendering updates may not be ticking fast enough to remove 653 // Background rendering updates may not be ticking fast enough to remove
660 // expired frames, so provide a boost here by ensuring we don't exit the 654 // expired frames, so provide a boost here by ensuring we don't exit the
661 // decoding cycle too early. Dropped frames are not counted in this case. 655 // decoding cycle too early. Dropped frames are not counted in this case.
662 if (was_background_rendering_) { 656 if (was_background_rendering_) {
663 algorithm_->RemoveExpiredFrames(tick_clock_->NowTicks()); 657 algorithm_->RemoveExpiredFrames(tick_clock_->NowTicks());
664 return; 658 return;
665 } 659 }
666 660
667 // Use the current media wall clock time plus the frame duration since
668 // RemoveExpiredFrames() is expecting the end point of an interval (it will
669 // subtract from the given value). It's important to always call this so
670 // that frame statistics are updated correctly.
671 frames_dropped_ += algorithm_->RemoveExpiredFrames(
672 current_time + algorithm_->average_frame_duration());
673
674 // If we've paused for underflow, and still have no effective frames, clear 661 // If we've paused for underflow, and still have no effective frames, clear
675 // the entire queue. Note: this may cause slight inaccuracies in the number 662 // the entire queue. Note: this may cause slight inaccuracies in the number
676 // of dropped frames since the frame may have been rendered before. 663 // of dropped frames since the frame may have been rendered before.
677 if (!sink_started_ && !algorithm_->effective_frames_queued()) { 664 if (!sink_started_ && !algorithm_->effective_frames_queued()) {
678 frames_dropped_ += algorithm_->frames_queued(); 665 frames_dropped_ += algorithm_->frames_queued();
679 algorithm_->Reset( 666 algorithm_->Reset(
680 VideoRendererAlgorithm::ResetFlag::kPreserveNextFrameEstimates); 667 VideoRendererAlgorithm::ResetFlag::kPreserveNextFrameEstimates);
681 painted_first_frame_ = false; 668 painted_first_frame_ = false;
682 669
683 // It's possible in the background rendering case for us to expire enough 670 // It's possible in the background rendering case for us to expire enough
684 // frames that we need to transition from HAVE_ENOUGH => HAVE_NOTHING. Just 671 // frames that we need to transition from HAVE_ENOUGH => HAVE_NOTHING. Just
685 // calling this function will check if we need to transition or not. 672 // calling this function will check if we need to transition or not.
686 if (buffering_state_ == BUFFERING_HAVE_ENOUGH) 673 if (buffering_state_ == BUFFERING_HAVE_ENOUGH)
687 TransitionToHaveNothing_Locked(); 674 TransitionToHaveNothing_Locked();
675 return;
688 } 676 }
677
678 // Use the current media wall clock time plus the frame duration since
679 // RemoveExpiredFrames() is expecting the end point of an interval (it will
680 // subtract from the given value). It's important to always call this so
681 // that frame statistics are updated correctly.
682 if (buffering_state_ == BUFFERING_HAVE_NOTHING) {
683 frames_dropped_ += algorithm_->RemoveExpiredFrames(
684 current_time + algorithm_->average_frame_duration());
685 return;
686 }
687
688 // If we reach this point, the normal rendering process will take care of
689 // removing any expired frames.
689 } 690 }
690 691
691 void VideoRendererImpl::CheckForMetadataChanges(VideoPixelFormat pixel_format, 692 void VideoRendererImpl::CheckForMetadataChanges(VideoPixelFormat pixel_format,
692 const gfx::Size& natural_size) { 693 const gfx::Size& natural_size) {
693 DCHECK(task_runner_->BelongsToCurrentThread()); 694 DCHECK(task_runner_->BelongsToCurrentThread());
694 695
695 // Notify client of size and opacity changes if this is the first frame 696 // Notify client of size and opacity changes if this is the first frame
696 // or if those have changed from the last frame. 697 // or if those have changed from the last frame.
697 if (!have_renderered_frames_ || last_frame_natural_size_ != natural_size) { 698 if (!have_renderered_frames_ || last_frame_natural_size_ != natural_size) {
698 last_frame_natural_size_ = natural_size; 699 last_frame_natural_size_ = natural_size;
(...skipping 11 matching lines...) Expand all
710 711
711 void VideoRendererImpl::AttemptReadAndCheckForMetadataChanges( 712 void VideoRendererImpl::AttemptReadAndCheckForMetadataChanges(
712 VideoPixelFormat pixel_format, 713 VideoPixelFormat pixel_format,
713 const gfx::Size& natural_size) { 714 const gfx::Size& natural_size) {
714 base::AutoLock auto_lock(lock_); 715 base::AutoLock auto_lock(lock_);
715 CheckForMetadataChanges(pixel_format, natural_size); 716 CheckForMetadataChanges(pixel_format, natural_size);
716 AttemptRead_Locked(); 717 AttemptRead_Locked();
717 } 718 }
718 719
719 } // namespace media 720 } // namespace media
OLDNEW
« no previous file with comments | « media/renderers/video_renderer_impl.h ('k') | media/renderers/video_renderer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698