summaryrefslogtreecommitdiff
path: root/src/rmd_load_cache.c
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2020-07-14 18:01:32 -0700
committerVito Caputo <vcaputo@pengaru.com>2020-07-14 18:01:32 -0700
commit2101b1f76e5e7eab4b4ea632db226fb76d99eeda (patch)
tree1cac403371ba8104c3b3608b7a1a7b0860a5b46a /src/rmd_load_cache.c
parentb75da7c41ea49c78ac9362f8837d4df9469613c6 (diff)
*: 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.
Diffstat (limited to 'src/rmd_load_cache.c')
-rw-r--r--src/rmd_load_cache.c111
1 files changed, 53 insertions, 58 deletions
diff --git a/src/rmd_load_cache.c b/src/rmd_load_cache.c
index 417b3dc..0d94a37 100644
--- a/src/rmd_load_cache.c
+++ b/src/rmd_load_cache.c
@@ -161,6 +161,14 @@ static int rmdReadFrame(CachedFrame *frame, FILE *ucfp, gzFile ifp) {
return 0;
}
+static int read_header(ProgData *pdata, gzFile ifp, FILE *ucfp, FrameHeader *fheader) {
+ if (!pdata->args.zerocompression) {
+ return gzread(ifp, fheader, sizeof(FrameHeader)) == sizeof(FrameHeader);
+ } else {
+ return fread(fheader, sizeof(FrameHeader), 1, ucfp) == 1;
+ }
+}
+
void *rmdLoadCache(ProgData *pdata) {
yuv_buffer *yuv = &pdata->enc_data->yuv;
@@ -171,9 +179,6 @@ void *rmdLoadCache(ProgData *pdata) {
CachedFrame frame;
int nth_cache = 1,
audio_end = 0,
- extra_frames = 0, //total number of duplicated frames
- missing_frames = 0, //if this is found >0 current run will not load
- //a frame but it will proccess the previous
thread_exit = 0, //0 success, -1 couldn't find files,1 couldn't remove
blocknum_x = pdata->enc_data->yuv.y_width / Y_UNIT_WIDTH,
blocknum_y = pdata->enc_data->yuv.y_height / Y_UNIT_WIDTH,
@@ -184,6 +189,7 @@ void *rmdLoadCache(ProgData *pdata) {
u_int32_t YBlocks[(yuv->y_width * yuv->y_height) / Y_UNIT_BYTES],
UBlocks[(yuv->uv_width * yuv->uv_height) / UV_UNIT_BYTES],
VBlocks[(yuv->uv_width * yuv->uv_height) / UV_UNIT_BYTES];
+ unsigned int last_capture_frameno = 0;
rmdThreadsSetName("rmdEncodeCache");
@@ -225,70 +231,60 @@ void *rmdLoadCache(ProgData *pdata) {
//If sound finishes first,we go on with the video.
//If video ends we will do one more run to flush audio in the ogg file
while (pdata->running) {
+
//video load and encoding
if (pdata->avd <= 0 || pdata->args.nosound || audio_end) {
- if (missing_frames > 0) {
- extra_frames++;
- missing_frames--;
- rmdSyncEncodeImageBuffer(pdata);
- } else if (((!pdata->args.zerocompression) &&
- (gzread(ifp, frame.header, sizeof(FrameHeader)) ==
- sizeof(FrameHeader) )) ||
- ((pdata->args.zerocompression) &&
- (fread(frame.header, sizeof(FrameHeader), 1, ucfp) == 1))) {
- //sync
- missing_frames += frame.header->current_total -
- (extra_frames + frame.header->frameno);
+
+ if (read_header(pdata, ifp, ucfp, frame.header)) {
+
if (pdata->frames_total) {
fprintf(stdout, "\r[%d%%] ",
- ((frame.header->frameno + extra_frames) * 100) / pdata->frames_total);
+ ((frame.header->capture_frameno) * 100) / pdata->capture_frameno);
} else
fprintf(stdout, "\r[%d frames rendered] ",
- (frame.header->frameno + extra_frames));
+ (frame.header->capture_frameno));
fflush(stdout);
- if ( (frame.header->Ynum <= blocknum_x * blocknum_y) &&
- (frame.header->Unum <= blocknum_x * blocknum_y) &&
- (frame.header->Vnum <= blocknum_x * blocknum_y) &&
- !rmdReadFrame( &frame,
- (pdata->args.zerocompression ? ucfp : NULL),
- (pdata->args.zerocompression ? NULL : ifp))
- ) {
-
- //load the blocks for each buffer
- if (frame.header->Ynum)
- for (int j = 0; j < frame.header->Ynum; j++)
- rmdLoadBlock( yuv->y,
- &frame.YData[j * blockszy],
- frame.YBlocks[j],
- yuv->y_width,
- yuv->y_height,
- Y_UNIT_WIDTH);
- if (frame.header->Unum)
- for (int j = 0; j < frame.header->Unum; j++)
- rmdLoadBlock( yuv->u,
- &frame.UData[j * blockszuv],
- frame.UBlocks[j],
- yuv->uv_width,
- yuv->uv_height,
- UV_UNIT_WIDTH);
- if (frame.header->Vnum)
- for (int j = 0; j < frame.header->Vnum; j++)
- rmdLoadBlock( yuv->v,
- &frame.VData[j * blockszuv],
- frame.VBlocks[j],
- yuv->uv_width,
- yuv->uv_height,
- UV_UNIT_WIDTH);
-
- //encode. This is not made in a thread since
- //now blocking is not a problem
- //and this way sync problems
- //can be avoided more easily.
- rmdSyncEncodeImageBuffer(pdata);
- } else {
+
+ if ( (frame.header->Ynum > blocknum_x * blocknum_y) ||
+ (frame.header->Unum > blocknum_x * blocknum_y) ||
+ (frame.header->Vnum > blocknum_x * blocknum_y) ||
+ rmdReadFrame( &frame,
+ pdata->args.zerocompression ? ucfp : NULL,
+ pdata->args.zerocompression ? NULL : ifp) < 0) {
+
raise(SIGINT);
continue;
}
+
+ //load the blocks for each buffer
+ if (frame.header->Ynum)
+ for (int j = 0; j < frame.header->Ynum; j++)
+ rmdLoadBlock( yuv->y,
+ &frame.YData[j * blockszy],
+ frame.YBlocks[j],
+ yuv->y_width,
+ yuv->y_height,
+ Y_UNIT_WIDTH);
+ if (frame.header->Unum)
+ for (int j = 0; j < frame.header->Unum; j++)
+ rmdLoadBlock( yuv->u,
+ &frame.UData[j * blockszuv],
+ frame.UBlocks[j],
+ yuv->uv_width,
+ yuv->uv_height,
+ UV_UNIT_WIDTH);
+ if (frame.header->Vnum)
+ for (int j = 0; j < frame.header->Vnum; j++)
+ rmdLoadBlock( yuv->v,
+ &frame.VData[j * blockszuv],
+ frame.VBlocks[j],
+ yuv->uv_width,
+ yuv->uv_height,
+ UV_UNIT_WIDTH);
+
+ rmdSyncEncodeImageBuffer(pdata, fheader.capture_frameno - last_capture_frameno);
+
+ last_capture_frameno = fheader.capture_frameno;
} else {
if (rmdSwapCacheFilesRead( pdata->cache_data->imgdata,
nth_cache,
@@ -299,7 +295,6 @@ void *rmdLoadCache(ProgData *pdata) {
fprintf(stderr, "\t[Cache File %d]", nth_cache);
nth_cache++;
}
- continue;
}
//audio load and encoding
} else {
© All Rights Reserved