From b75da7c41ea49c78ac9362f8837d4df9469613c6 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Tue, 14 Jul 2020 15:46:16 -0700 Subject: timer: implement AV-sync This is focused on keeping --on-the-fly-encoding in sync even over long videos. The existing code inevitably would fall into a permanently negative pdata->avd value letting things get increasingly out of sync and never correcting. Before removing the vestigial negative avd "don't wait" logic from get_frame when this permanently negative avd state was entered, get_frame would just start sampling at an unregulated fps. The timer thread which drives get_frame now consults avd on every tick, Depending on which which half is ahead, the timer will either cause get_frame to drop frames by advancing the frameno by more than one, or it will adjust its sleep delay in proportion to the delta. See comments in rmd_timer.c for more details. Note that in testing especially with a loaded system I observed some surprisingly large deltas where multi-second sleeps occurred to let the sound catch back up. I expect to revisit this issue more in the future, but would just like to get things more correct for now. --- src/rmd_encode_sound_buffer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/rmd_encode_sound_buffer.c') diff --git a/src/rmd_encode_sound_buffer.c b/src/rmd_encode_sound_buffer.c index d35a17c..22e4ddc 100644 --- a/src/rmd_encode_sound_buffer.c +++ b/src/rmd_encode_sound_buffer.c @@ -128,8 +128,9 @@ void *rmdEncodeSoundBuffer(ProgData *pdata) { } pthread_mutex_unlock(&pdata->libogg_mutex); - /* this needs synchronizing */ + pthread_mutex_lock(&pdata->avd_mutex); pdata->avd -= pdata->periodtime; + pthread_mutex_unlock(&pdata->avd_mutex); } pthread_mutex_lock(&pdata->vorbis_lib_mutex); -- cgit v1.2.3