Commit 71b147d2 authored by Mina Almasry's avatar Mina Almasry Committed by Commit Bot

Some tweaks to AV sync code

- Reduce multipliers from 0.9/1.1 to 0.95/1.05. The current multipliers
seem too drastic.
- Remove logging that doesn't seem too useful for now.
- Add difference_slope logging. It may be useful to log in which
direction the difference is going and how fast.
- Only set the playback rate in the sync'd case if there is
a difference. Otherwise we're making uncessary calls and causing logspam

BUG=internal 73746352
TEST=On device

Change-Id: If073b98892e84ca8f13435f7322012daeb6ffe1a
Reviewed-on: https://chromium-review.googlesource.com/956877
Commit-Queue: Mina Almasry <almasrymina@chromium.org>
Reviewed-by: default avatarKenneth MacKay <kmackay@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542609}
parent eefa2858
...@@ -27,8 +27,8 @@ const int kHardCorrectionThresholdUs = 200000; ...@@ -27,8 +27,8 @@ const int kHardCorrectionThresholdUs = 200000;
// When doing a soft correction, we will do so by changing the rate of video // When doing a soft correction, we will do so by changing the rate of video
// playback. These constants define the multiplier in either direction. // playback. These constants define the multiplier in either direction.
const double kRateReduceMultiplier = 0.9; const double kRateReduceMultiplier = 0.95;
const double kRateIncreaseMultiplier = 1.1; const double kRateIncreaseMultiplier = 1.05;
// Length of time after which data is forgotten from our linear regression // Length of time after which data is forgotten from our linear regression
// models. // models.
...@@ -37,6 +37,13 @@ const int kLinearRegressionDataLifetimeUs = 500000; ...@@ -37,6 +37,13 @@ const int kLinearRegressionDataLifetimeUs = 500000;
// Time interval between AV sync upkeeps. // Time interval between AV sync upkeeps.
constexpr base::TimeDelta kAvSyncUpkeepInterval = constexpr base::TimeDelta kAvSyncUpkeepInterval =
base::TimeDelta::FromMilliseconds(10); base::TimeDelta::FromMilliseconds(10);
// When we're in sync (i.e. the apts and vpts difference is
// < kSoftCorrectionThresholdUs), if the apts and vpts slopes are different by
// this threshold, we'll reset the video playback rate to be equal to the apts
// slope.
const double kInSyncResetThreshold = 0.05;
} // namespace } // namespace
std::unique_ptr<AvSync> AvSync::Create( std::unique_ptr<AvSync> AvSync::Create(
...@@ -131,25 +138,23 @@ void AvSyncVideo::UpkeepAvSync() { ...@@ -131,25 +138,23 @@ void AvSyncVideo::UpkeepAvSync() {
} }
int64_t difference; int64_t difference;
double difference_slope;
error_->EstimateY(now, &difference, &error); error_->EstimateY(now, &difference, &error);
error_->EstimateSlope(&difference_slope, &error);
VLOG(4) << "Pts_monitor." VLOG(3) << "Pts_monitor."
<< " current_apts=" << current_apts / 1000
<< " current_vpts=" << std::setw(5) << current_vpts / 1000
<< " difference=" << std::setw(5) << difference / 1000 << " difference=" << std::setw(5) << difference / 1000
<< " wall_time=" << std::setw(5) << now / 1000
<< " apts_slope=" << std::setw(10) << apts_slope << " apts_slope=" << std::setw(10) << apts_slope
<< " vpts_slope=" << std::setw(10) << vpts_slope; << " vpts_slope=" << std::setw(10) << vpts_slope
<< " difference_slope=" << std::setw(10) << difference_slope;
// Seems the ideal value here depends on the frame rate. // Seems the ideal value here depends on the frame rate.
if (abs(difference) > kSoftCorrectionThresholdUs) { if (abs(difference) > kSoftCorrectionThresholdUs) {
VLOG(2) << "Correction." VLOG(2) << "Correction."
<< " current_apts=" << current_apts / 1000
<< " current_vpts=" << std::setw(5) << current_vpts / 1000
<< " difference=" << std::setw(5) << difference / 1000 << " difference=" << std::setw(5) << difference / 1000
<< " wall_time=" << std::setw(5) << now / 1000
<< " apts_slope=" << std::setw(10) << apts_slope << " apts_slope=" << std::setw(10) << apts_slope
<< " vpts_slope=" << std::setw(10) << vpts_slope; << " vpts_slope=" << std::setw(10) << vpts_slope
<< " difference_slope=" << std::setw(10) << difference_slope;
if (abs(difference) > kHardCorrectionThresholdUs) { if (abs(difference) > kHardCorrectionThresholdUs) {
// Do a hard correction. // Do a hard correction.
...@@ -177,8 +182,11 @@ void AvSyncVideo::UpkeepAvSync() { ...@@ -177,8 +182,11 @@ void AvSyncVideo::UpkeepAvSync() {
// find the video playback rate at which vtps_slope == apts_slope. These // find the video playback rate at which vtps_slope == apts_slope. These
// are slightly different values since the video playback rate is probably // are slightly different values since the video playback rate is probably
// not phase locked at all with monotonic_raw. // not phase locked at all with monotonic_raw.
backend_->video_decoder()->SetPlaybackRate(apts_slope); if (abs(current_video_playback_rate_ - apts_slope) >
current_video_playback_rate_ = apts_slope; kInSyncResetThreshold) {
backend_->video_decoder()->SetPlaybackRate(apts_slope);
current_video_playback_rate_ = apts_slope;
}
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment