From 181663291357bfad4d1e630f3c5932847a2a0520 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Tue, 29 Jan 2013 16:10:55 +0100 Subject: video-decode: Allow reusing an old frame --- src/video_decode.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/video_decode.c') diff --git a/src/video_decode.c b/src/video_decode.c index 993fd14..e6748e0 100644 --- a/src/video_decode.c +++ b/src/video_decode.c @@ -97,9 +97,14 @@ video_decode_get_frame(struct video_decode *vd, struct video_frame **frame) int decoded, got_picture; int ret; - f = calloc(1, sizeof *f); - if (f == NULL) - return -1; + if (*frame != NULL) { + f = *frame; + } else { + f = calloc(1, sizeof *f); + if (f == NULL) + return -1; + f->frame = avcodec_alloc_frame(); + } packet.data = NULL; do { @@ -122,8 +127,6 @@ video_decode_get_frame(struct video_decode *vd, struct video_frame **frame) } } while (packet.stream_index != vd->stream); - f->frame = avcodec_alloc_frame(); - do { #if DEBUG printf("packet.data: %p, packet.siz: %d, packet.strm_idx: %d\n", @@ -150,7 +153,8 @@ video_decode_get_frame(struct video_decode *vd, struct video_frame **frame) f->base.height = vd->codec_ctx->height; f->base.stride = f->frame->linesize[0]; - *frame = &f->base; + if (*frame == NULL) + *frame = &f->base; return 1; } -- cgit