From 10f2531b6c410573ca4259b44207f34506a60ff2 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 5 Jan 2018 05:41:57 -0800 Subject: Handle the audio clock diff as nanoseconds in alffplay --- examples/alffplay.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'examples') diff --git a/examples/alffplay.cpp b/examples/alffplay.cpp index 68602a8f..623e59b1 100644 --- a/examples/alffplay.cpp +++ b/examples/alffplay.cpp @@ -71,7 +71,7 @@ const milliseconds VideoSyncThreshold(10); #define VIDEO_PICTURE_QUEUE_SIZE 16 const seconds_d64 AudioSyncThreshold(0.03); -const seconds_d64 AudioSampleCorrectionMax(0.05); +const milliseconds AudioSampleCorrectionMax(50); /* Averaging filter coefficient for audio sync. */ #define AUDIO_DIFF_AVG_NB 20 const double AudioAvgFilterCoeff = std::pow(0.01, 1.0/AUDIO_DIFF_AVG_NB); @@ -471,12 +471,12 @@ int AudioState::getSync() return 0; auto ref_clock = mMovie.getMasterClock(); - auto diff = seconds_d64(ref_clock - getClockNoLock()); + auto diff = ref_clock - getClockNoLock(); if(!(diff < AVNoSyncThreshold && diff > -AVNoSyncThreshold)) { /* Difference is TOO big; reset accumulated average */ - mClockDiffAvg = std::chrono::duration::zero(); + mClockDiffAvg = seconds_d64::zero(); return 0; } @@ -487,11 +487,9 @@ int AudioState::getSync() return 0; /* Constrain the per-update difference to avoid exceedingly large skips */ - if(!(diff < AudioSampleCorrectionMax)) - return (int)(AudioSampleCorrectionMax * mCodecCtx->sample_rate).count(); - if(!(diff > -AudioSampleCorrectionMax)) - return (int)(-AudioSampleCorrectionMax * mCodecCtx->sample_rate).count(); - return (int)(diff.count()*mCodecCtx->sample_rate); + diff = std::min(std::max(diff, -AudioSampleCorrectionMax), + AudioSampleCorrectionMax); + return (int)std::chrono::duration_cast(diff*mCodecCtx->sample_rate).count(); } int AudioState::decodeFrame() -- cgit v1.2.3