summaryrefslogtreecommitdiff
path: root/src/rmd_encode_image_buffer.c
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2020-07-14 15:46:16 -0700
committerVito Caputo <vcaputo@pengaru.com>2020-07-14 15:51:38 -0700
commitb75da7c41ea49c78ac9362f8837d4df9469613c6 (patch)
treef8ee4f7ad88a8dbd63868cb32734b0c2c6fdb4a8 /src/rmd_encode_image_buffer.c
parent48dae516a3fadc46eaf3228eb519728e2a3961e6 (diff)
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.
Diffstat (limited to 'src/rmd_encode_image_buffer.c')
-rw-r--r--src/rmd_encode_image_buffer.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/rmd_encode_image_buffer.c b/src/rmd_encode_image_buffer.c
index 57ac5ce..d83c694 100644
--- a/src/rmd_encode_image_buffer.c
+++ b/src/rmd_encode_image_buffer.c
@@ -74,10 +74,13 @@ void *rmdEncodeImageBuffer(ProgData *pdata) {
while (theora_encode_packetout(&enc_data->m_th_st, 0, &enc_data->m_ogg_pckt1) > 0) {
pthread_mutex_lock(&pdata->libogg_mutex);
ogg_stream_packetin(&enc_data->m_ogg_ts, &enc_data->m_ogg_pckt1);
- pdata->avd += pdata->frametime;
pthread_mutex_unlock(&pdata->libogg_mutex);
}
+ pthread_mutex_lock(&pdata->avd_mutex);
+ pdata->avd += pdata->frametime * n_frames;
+ pthread_mutex_unlock(&pdata->avd_mutex);
+
last_encode_frameno = encode_frameno;
}
© All Rights Reserved