aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-01-05 05:41:57 -0800
committerChris Robinson <[email protected]>2018-01-05 05:41:57 -0800
commit10f2531b6c410573ca4259b44207f34506a60ff2 (patch)
tree1434d3dbc2afdcd6f82b75f19f835b47500484b1 /examples
parentecd327e5e1d603de1522f2afed6882eaab775b28 (diff)
Handle the audio clock diff as nanoseconds in alffplay
Diffstat (limited to 'examples')
-rw-r--r--examples/alffplay.cpp14
1 files changed, 6 insertions, 8 deletions
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<double>::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<nanoseconds>(std::max<nanoseconds>(diff, -AudioSampleCorrectionMax),
+ AudioSampleCorrectionMax);
+ return (int)std::chrono::duration_cast<seconds>(diff*mCodecCtx->sample_rate).count();
}
int AudioState::decodeFrame()