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 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 frame_duration_calculator_.AddSample(frame.end_time - frame.start_time); | 477 frame_duration_calculator_.AddSample(frame.end_time - frame.start_time); |
478 } | 478 } |
479 frame_queue_.back().start_time = wall_clock_times.back(); | 479 frame_queue_.back().start_time = wall_clock_times.back(); |
480 | 480 |
481 if (!frame_duration_calculator_.count()) | 481 if (!frame_duration_calculator_.count()) |
482 return; | 482 return; |
483 | 483 |
484 // Compute |average_frame_duration_|, a moving average of the last few frames; | 484 // Compute |average_frame_duration_|, a moving average of the last few frames; |
485 // see kMovingAverageSamples for the exact number. | 485 // see kMovingAverageSamples for the exact number. |
486 average_frame_duration_ = frame_duration_calculator_.Average(); | 486 average_frame_duration_ = frame_duration_calculator_.Average(); |
| 487 const base::TimeDelta deviation = frame_duration_calculator_.Deviation(); |
487 | 488 |
488 // Update the frame end time for the last frame based on the average. | 489 // Update the frame end time for the last frame based on the average. |
489 frame_queue_.back().end_time = | 490 frame_queue_.back().end_time = |
490 frame_queue_.back().start_time + average_frame_duration_; | 491 frame_queue_.back().start_time + average_frame_duration_; |
491 | 492 |
492 // ITU-R BR.265 recommends a maximum acceptable drift of +/- half of the frame | 493 // ITU-R BR.265 recommends a maximum acceptable drift of +/- half of the frame |
493 // duration; there are other asymmetric, more lenient measures, that we're | 494 // duration; there are other asymmetric, more lenient measures, that we're |
494 // forgoing in favor of simplicity. | 495 // forgoing in favor of simplicity. |
495 // | 496 // |
496 // We'll always allow at least 16.66ms of drift since literature suggests it's | 497 // We'll always allow at least 16.66ms of drift since literature suggests it's |
497 // well below the floor of detection and is high enough to ensure stability | 498 // well below the floor of detection and is high enough to ensure stability |
498 // for 60fps content. | 499 // for 60fps content. |
499 max_acceptable_drift_ = std::max(average_frame_duration_ / 2, | 500 max_acceptable_drift_ = std::max(average_frame_duration_ / 2, |
500 base::TimeDelta::FromSecondsD(1.0 / 60)); | 501 base::TimeDelta::FromSecondsD(1.0 / 60)); |
501 | 502 |
502 // If we were called via RemoveExpiredFrames() and Render() was never called, | 503 // If we were called via RemoveExpiredFrames() and Render() was never called, |
503 // we may not have a render interval yet. | 504 // we may not have a render interval yet. |
504 if (render_interval_ == base::TimeDelta()) | 505 if (render_interval_ == base::TimeDelta()) |
505 return; | 506 return; |
506 | 507 |
507 const bool cadence_changed = cadence_estimator_.UpdateCadenceEstimate( | 508 const bool cadence_changed = cadence_estimator_.UpdateCadenceEstimate( |
508 render_interval_, average_frame_duration_, max_acceptable_drift_); | 509 render_interval_, average_frame_duration_, deviation, |
| 510 max_acceptable_drift_); |
509 | 511 |
510 // No need to update cadence if there's been no change; cadence will be set | 512 // No need to update cadence if there's been no change; cadence will be set |
511 // as frames are added to the queue. | 513 // as frames are added to the queue. |
512 if (!cadence_changed) | 514 if (!cadence_changed) |
513 return; | 515 return; |
514 | 516 |
515 cadence_frame_counter_ = 0; | 517 cadence_frame_counter_ = 0; |
516 UpdateCadenceForFrames(); | 518 UpdateCadenceForFrames(); |
517 } | 519 } |
518 | 520 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 if (frame.start_time > deadline_min) | 683 if (frame.start_time > deadline_min) |
682 return frame.start_time - deadline_min; | 684 return frame.start_time - deadline_min; |
683 | 685 |
684 // Drift is zero for frames which overlap the deadline interval. | 686 // Drift is zero for frames which overlap the deadline interval. |
685 DCHECK_GE(deadline_min, frame.start_time); | 687 DCHECK_GE(deadline_min, frame.start_time); |
686 DCHECK_GE(frame.end_time, deadline_min); | 688 DCHECK_GE(frame.end_time, deadline_min); |
687 return base::TimeDelta(); | 689 return base::TimeDelta(); |
688 } | 690 } |
689 | 691 |
690 } // namespace media | 692 } // namespace media |
OLD | NEW |