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_cadence_estimator.h" | 5 #include "media/filters/video_cadence_estimator.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <iterator> | 9 #include <iterator> |
10 #include <limits> | 10 #include <limits> |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 int VideoCadenceEstimator::GetCadenceForFrame(uint64_t frame_number) const { | 146 int VideoCadenceEstimator::GetCadenceForFrame(uint64_t frame_number) const { |
147 DCHECK(has_cadence()); | 147 DCHECK(has_cadence()); |
148 return cadence_[frame_number % cadence_.size()]; | 148 return cadence_[frame_number % cadence_.size()]; |
149 } | 149 } |
150 | 150 |
151 VideoCadenceEstimator::Cadence VideoCadenceEstimator::CalculateCadence( | 151 VideoCadenceEstimator::Cadence VideoCadenceEstimator::CalculateCadence( |
152 base::TimeDelta render_interval, | 152 base::TimeDelta render_interval, |
153 base::TimeDelta frame_duration, | 153 base::TimeDelta frame_duration, |
154 base::TimeDelta max_acceptable_drift, | 154 base::TimeDelta max_acceptable_drift, |
155 base::TimeDelta* time_until_max_drift) const { | 155 base::TimeDelta* time_until_max_drift) const { |
156 DCHECK_LT(max_acceptable_drift, minimum_time_until_max_drift_); | |
157 | |
158 // The perfect cadence is the number of render intervals per frame. | 156 // The perfect cadence is the number of render intervals per frame. |
159 const double perfect_cadence = | 157 const double perfect_cadence = |
160 frame_duration.InSecondsF() / render_interval.InSecondsF(); | 158 frame_duration.InSecondsF() / render_interval.InSecondsF(); |
161 | 159 |
162 // We want to construct a cadence pattern to approximate the perfect cadence | 160 // We want to construct a cadence pattern to approximate the perfect cadence |
163 // while ensuring error doesn't accumulate too quickly. | 161 // while ensuring error doesn't accumulate too quickly. |
164 const double drift_ratio = max_acceptable_drift.InSecondsF() / | 162 const double drift_ratio = max_acceptable_drift.InSecondsF() / |
DaleCurtis
2015/10/01 01:16:38
Actually, maybe we want std::min(minimum_time_unti
| |
165 minimum_time_until_max_drift_.InSecondsF(); | 163 minimum_time_until_max_drift_.InSecondsF(); |
166 const double minimum_acceptable_cadence = | 164 const double minimum_acceptable_cadence = |
167 perfect_cadence / (1.0 + drift_ratio); | 165 perfect_cadence / (1.0 + drift_ratio); |
168 const double maximum_acceptable_cadence = | 166 const double maximum_acceptable_cadence = |
169 perfect_cadence / (1.0 - drift_ratio); | 167 perfect_cadence / (1.0 - drift_ratio); |
170 | 168 |
171 // We've arbitrarily chosen the maximum allowable cadence length as 5. It's | 169 // We've arbitrarily chosen the maximum allowable cadence length as 5. It's |
172 // proven sufficient to support most standard frame and render rates, while | 170 // proven sufficient to support most standard frame and render rates, while |
173 // being small enough that small frame and render timing errors don't render | 171 // being small enough that small frame and render timing errors don't render |
174 // it useless. | 172 // it useless. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 | 212 |
215 std::ostringstream os; | 213 std::ostringstream os; |
216 os << "["; | 214 os << "["; |
217 std::copy(cadence.begin(), cadence.end() - 1, | 215 std::copy(cadence.begin(), cadence.end() - 1, |
218 std::ostream_iterator<int>(os, ":")); | 216 std::ostream_iterator<int>(os, ":")); |
219 os << cadence.back() << "]"; | 217 os << cadence.back() << "]"; |
220 return os.str(); | 218 return os.str(); |
221 } | 219 } |
222 | 220 |
223 } // namespace media | 221 } // namespace media |
OLD | NEW |