OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/filters/video_renderer_algorithm.h" | 5 #include "media/filters/video_renderer_algorithm.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 namespace media { | 10 namespace media { |
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
678 return base::TimeDelta(); | 678 return base::TimeDelta(); |
679 } | 679 } |
680 | 680 |
681 void VideoRendererAlgorithm::UpdateEffectiveFramesQueued() { | 681 void VideoRendererAlgorithm::UpdateEffectiveFramesQueued() { |
682 if (frame_queue_.empty() || average_frame_duration_.is_zero() || | 682 if (frame_queue_.empty() || average_frame_duration_.is_zero() || |
683 last_deadline_max_.is_null()) { | 683 last_deadline_max_.is_null()) { |
684 effective_frames_queued_ = frame_queue_.size(); | 684 effective_frames_queued_ = frame_queue_.size(); |
685 return; | 685 return; |
686 } | 686 } |
687 | 687 |
688 // Determine the lower bound of the number of effective queues first. | |
689 // Normally, this is 0. | |
690 size_t min_frames_queued = 0; | |
691 // If frame dropping is disabled, the lower bound is the number of frames | |
DaleCurtis
2016/11/16 22:03:44
Add line between these.
DaleCurtis
2016/11/16 22:03:44
Add line between these.
wdzierzanowski
2016/11/23 09:54:06
Done.
| |
692 // that were not rendered yet. | |
693 if (frame_dropping_disabled_) { | |
694 min_frames_queued = std::count_if( | |
695 frame_queue_.cbegin(), frame_queue_.cend(), | |
696 [](const ReadyFrame& frame) { return frame.render_count == 0; }); | |
697 } | |
698 | |
699 // Next, see if can report more frames as queued. | |
700 const size_t frames_queued = CountEffectiveFramesQueued(); | |
DaleCurtis
2016/11/16 22:03:44
Just inline this into the std::max.
wdzierzanowski
2016/11/23 09:54:06
Done.
| |
701 | |
702 effective_frames_queued_ = std::max(min_frames_queued, frames_queued); | |
703 } | |
704 | |
705 size_t VideoRendererAlgorithm::CountEffectiveFramesQueued() const { | |
688 // If we don't have cadence, subtract off any frames which are before | 706 // If we don't have cadence, subtract off any frames which are before |
689 // the last rendered frame or are past their expected rendering time. | 707 // the last rendered frame or are past their expected rendering time. |
690 if (!cadence_estimator_.has_cadence()) { | 708 if (!cadence_estimator_.has_cadence()) { |
691 size_t expired_frames = 0; | 709 size_t expired_frames = 0; |
692 for (; expired_frames < frame_queue_.size(); ++expired_frames) { | 710 for (; expired_frames < frame_queue_.size(); ++expired_frames) { |
693 const ReadyFrame& frame = frame_queue_[expired_frames]; | 711 const ReadyFrame& frame = frame_queue_[expired_frames]; |
694 if (frame.end_time.is_null() || frame.end_time > last_deadline_max_) | 712 if (frame.end_time.is_null() || frame.end_time > last_deadline_max_) |
695 break; | 713 break; |
696 } | 714 } |
697 effective_frames_queued_ = frame_queue_.size() - expired_frames; | 715 return frame_queue_.size() - expired_frames; |
698 return; | |
699 } | 716 } |
700 | 717 |
701 // Find the first usable frame to start counting from. | 718 // Find the first usable frame to start counting from. |
702 const int start_index = FindBestFrameByCadence(nullptr); | 719 const int start_index = FindBestFrameByCadence(nullptr); |
703 if (start_index < 0) { | 720 if (start_index < 0) |
704 effective_frames_queued_ = 0; | 721 return 0; |
705 return; | |
706 } | |
707 | 722 |
708 const base::TimeTicks minimum_start_time = | 723 const base::TimeTicks minimum_start_time = |
709 last_deadline_max_ - max_acceptable_drift_; | 724 last_deadline_max_ - max_acceptable_drift_; |
710 size_t renderable_frame_count = 0; | 725 size_t renderable_frame_count = 0; |
711 for (size_t i = start_index; i < frame_queue_.size(); ++i) { | 726 for (size_t i = start_index; i < frame_queue_.size(); ++i) { |
712 const ReadyFrame& frame = frame_queue_[i]; | 727 const ReadyFrame& frame = frame_queue_[i]; |
713 if (frame.render_count < frame.ideal_render_count && | 728 if (frame.render_count < frame.ideal_render_count && |
714 (frame.end_time.is_null() || frame.end_time > minimum_start_time)) { | 729 (frame.end_time.is_null() || frame.end_time > minimum_start_time)) { |
715 ++renderable_frame_count; | 730 ++renderable_frame_count; |
716 } | 731 } |
717 } | 732 } |
718 | 733 return renderable_frame_count; |
719 effective_frames_queued_ = renderable_frame_count; | |
720 } | 734 } |
721 | 735 |
722 } // namespace media | 736 } // namespace media |
OLD | NEW |