From 2101b1f76e5e7eab4b4ea632db226fb76d99eeda Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Tue, 14 Jul 2020 18:01:32 -0700 Subject: *: rework avd/frameno handling for cached mode This brings the !--on-the-fly-encoding mode up to speed. The cached file header loses the total_frames counter, as the capture_frameno already represents this. Dropped frames are detected by simply looking at the difference between the previous capture_frameno and the current one. This simply gets passed to the encoder as a n_frames count so theora can duplicate the frames as needed. This was being done manually before by looking at the frameno and total frames in each header and maintaining separate counts for "extra frames" "missed frames" etc, and resubmitting entire frames multiply for encoding dropped frames. So a chunk of code has been thrown out from rmd_load_cache.c, and some general cleanups have occurred there as well. I also needed to add more locking around pdata->avd accesses. --- src/rmd_encode_image_buffer.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/rmd_encode_image_buffer.c') diff --git a/src/rmd_encode_image_buffer.c b/src/rmd_encode_image_buffer.c index d83c694..5b08620 100644 --- a/src/rmd_encode_image_buffer.c +++ b/src/rmd_encode_image_buffer.c @@ -95,7 +95,7 @@ void *rmdEncodeImageBuffer(ProgData *pdata) { //this function is meant to be called normally //not through a thread of it's own -void rmdSyncEncodeImageBuffer(ProgData *pdata) { +void rmdSyncEncodeImageBuffer(ProgData *pdata, unsigned int n_frames) { EncData *enc_data = pdata->enc_data; if (theora_encode_YUVin(&enc_data->m_th_st, &enc_data->yuv)) { @@ -103,14 +103,23 @@ void rmdSyncEncodeImageBuffer(ProgData *pdata) { return; } - if (theora_encode_packetout(&enc_data->m_th_st, !pdata->running, &enc_data->m_ogg_pckt1) == 1) { + if (n_frames > 1) + theora_control( &enc_data->m_th_st, + TH_ENCCTL_SET_DUP_COUNT, + (void *)&(int){n_frames - 1}, + sizeof(int)); + + 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); - + /* TODO: this is the only real difference from what's open-coded above, + * investigate why this is done this way and make the thread just call + * this function instead of duplicating it. + */ if (!pdata->running) enc_data->m_ogg_ts.e_o_s = 1; - - pdata->avd += pdata->frametime; pthread_mutex_unlock(&pdata->libogg_mutex); } + + pdata->avd += pdata->frametime * n_frames; } -- cgit v1.2.3