# HG changeset patch # User reimar # Date 1392483179 0 # Node ID a86b7ed5f1dc1be573aab039aa67ca612b5a0f6c # Parent 9249a5caebdf57a73a4d02dd6d7e4feeacb44190 Switch to refcounted API since the old ones have memleaks. A fixable one due to the "non-refcounting" API in fact still using reference counting for the qp tables, and a probably unfixable one (unless we add hacks MPlayer side) due to the sidedata being copied. diff -r 9249a5caebdf -r a86b7ed5f1dc libmpcodecs/vd_ffmpeg.c --- a/libmpcodecs/vd_ffmpeg.c Sat Feb 15 16:52:58 2014 +0000 +++ b/libmpcodecs/vd_ffmpeg.c Sat Feb 15 16:52:59 2014 +0000 @@ -76,6 +76,7 @@ typedef struct { AVCodecContext *avctx; AVFrame *pic; + AVFrame *refcount_frame; enum AVPixelFormat pix_fmt; int do_slices; int do_dr1; @@ -338,7 +339,7 @@ ctx->ip_count= ctx->b_count= 0; - ctx->pic = avcodec_alloc_frame(); + ctx->pic = av_frame_alloc(); ctx->avctx = avcodec_alloc_context3(lavc_codec); avctx = ctx->avctx; avctx->opaque = sh; @@ -482,6 +483,7 @@ set_format_params(avctx, PIX_FMT_XVMC_MPEG2_IDCT); avctx->thread_count = lavc_param_threads; avctx->thread_type = FF_THREAD_FRAME | FF_THREAD_SLICE; + avctx->refcounted_frames = 1; /* open it */ if (avcodec_open2(avctx, lavc_codec, &opts) < 0) { @@ -502,6 +504,10 @@ vd_ffmpeg_ctx *ctx = sh->context; AVCodecContext *avctx = ctx->avctx; + if (ctx->refcount_frame) { + av_frame_unref(ctx->refcount_frame); + ctx->refcount_frame = NULL; + } if(lavc_param_vstats && avctx->coded_frame){ int i; for(i=1; i<32; i++){ @@ -885,6 +891,10 @@ int dr1= ctx->do_dr1; AVPacket pkt; + if (ctx->refcount_frame) { + av_frame_unref(ctx->refcount_frame); + ctx->refcount_frame = NULL; + } if(data && len<=0) return NULL; // skipped frame //ffmpeg interlace (mpeg2) bug have been fixed. no need of -noslices @@ -938,6 +948,7 @@ ctx->palette_sent = 1; } ret = avcodec_decode_video2(avctx, pic, &got_picture, &pkt); + ctx->refcount_frame = pic; pkt.data = NULL; pkt.size = 0; av_packet_free_side_data(&pkt);