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_cache_frame.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/rmd_cache_frame.c') diff --git a/src/rmd_cache_frame.c b/src/rmd_cache_frame.c index c2e37bf..5c0ea5b 100644 --- a/src/rmd_cache_frame.c +++ b/src/rmd_cache_frame.c @@ -105,7 +105,7 @@ void *rmdCacheImageBuffer(ProgData *pdata) { v_short_blocks[blocknum_x * blocknum_y]; unsigned long long int total_bytes = 0; unsigned long long int total_received_bytes = 0; - unsigned int capture_frameno = 0; + unsigned int capture_frameno = 0, last_capture_frameno = 0; rmdThreadsSetName("rmdCacheImages"); @@ -181,8 +181,8 @@ void *rmdCacheImageBuffer(ProgData *pdata) { } strncpy(fheader.frame_prefix, "FRAM", 4); - fheader.frameno = ++frameno; - fheader.current_total = pdata->frames_total; + fheader.capture_frameno = capture_frameno; + frameno++; fheader.Ynum = ynum; fheader.Unum = unum; @@ -255,7 +255,9 @@ void *rmdCacheImageBuffer(ProgData *pdata) { nbytes += rmdFlushBlock(NULL, 0, 0, 0, 0, fp, ucfp, 1); /**@________________@**/ - pdata->avd += pdata->frametime; + pthread_mutex_lock(&pdata->avd_mutex); + pdata->avd += pdata->frametime * (capture_frameno - last_capture_frameno); + pthread_mutex_unlock(&pdata->avd_mutex); if (nbytes > CACHE_FILE_SIZE_LIMIT) { if (rmdSwapCacheFilesWrite(pdata->cache_data->imgdata, nth_cache, &fp, &ucfp)) { @@ -279,6 +281,8 @@ void *rmdCacheImageBuffer(ProgData *pdata) { nth_cache++; nbytes = 0; } + + last_capture_frameno = capture_frameno; } total_bytes += nbytes; @@ -307,7 +311,7 @@ void *rmdCacheImageBuffer(ProgData *pdata) { fprintf(stderr, "Saved %d frames in a total of %d requests\n", frameno, - pdata->frames_total); + capture_frameno); fflush(stderr); if (!pdata->args.zerocompression) { -- cgit v1.2.3