From 6a27ae28f9bde981e85c82cf5bf42c5f43fb6f13 Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Wed, 12 Dec 2012 16:42:05 +0100 Subject: [PATCH] mpegvideo: treat delayed pictures as used This requires to move the avcodec_default_free_buffers() call to ff_MPV_common_end() since otherwise delayed pictures would get freed during a size change. --- libavcodec/h264.h | 6 ------ libavcodec/mpegvideo.c | 8 ++++---- libavcodec/mpegvideo.h | 6 ++++++ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/libavcodec/h264.h b/libavcodec/h264.h index 17f63c4b5b..3c99030ed2 100644 --- a/libavcodec/h264.h +++ b/libavcodec/h264.h @@ -95,12 +95,6 @@ #define IS_REF0(a) ((a) & MB_TYPE_REF0) #define IS_8x8DCT(a) ((a) & MB_TYPE_8x8DCT) -/** - * Value of Picture.reference when Picture is not a reference picture, but - * is held for delayed output. - */ -#define DELAYED_PIC_REF 4 - #define QP_MAX_NUM (51 + 2 * 6) // The maximum supported qp /* NAL unit types */ diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 42367e1e48..773c9e258b 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -1008,9 +1008,6 @@ static int free_context_frame(MpegEncContext *s) for (i = 0; i < 3; i++) av_freep(&s->visualization_buffer[i]); - if (!(s->avctx->active_thread_type & FF_THREAD_FRAME)) - avcodec_default_free_buffers(s->avctx); - return 0; } @@ -1126,6 +1123,9 @@ void ff_MPV_common_end(MpegEncContext *s) free_context_frame(s); + if (!(s->avctx->active_thread_type & FF_THREAD_FRAME)) + avcodec_default_free_buffers(s->avctx); + s->context_initialized = 0; s->last_picture_ptr = s->next_picture_ptr = @@ -1244,7 +1244,7 @@ static inline int pic_is_unused(MpegEncContext *s, Picture *pic) { if (pic->f.data[0] == NULL) return 1; - if (pic->needs_realloc) + if (pic->needs_realloc && !(pic->f.reference & DELAYED_PIC_REF)) if (!pic->owner2 || pic->owner2 == s) return 1; return 0; diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index bd4caa3e7b..6c9a7cbda6 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -79,6 +79,12 @@ enum OutputFormat { #define EXT_START_CODE 0x000001b5 #define USER_START_CODE 0x000001b2 +/** + * Value of Picture.reference when Picture is not a reference picture, but + * is held for delayed output. + */ +#define DELAYED_PIC_REF 4 + struct MpegEncContext; /**