ad_lavc: use new AVFrame API

Set refcounted_frames, because in some versions of libavcodec mixing the
new AVFrame API and non-refcounted decoding could cause memory
corruption. Likewise, it's probably still required to unref a frame
before calling the decoder.
This commit is contained in:
wm4 2014-03-16 12:50:15 +01:00
parent 8e6bd496ca
commit f2374f4e4b
1 changed files with 4 additions and 2 deletions

View File

@ -205,7 +205,8 @@ static int init(struct dec_audio *da, const char *decoder)
lavc_context = avcodec_alloc_context3(lavc_codec);
ctx->avctx = lavc_context;
ctx->avframe = avcodec_alloc_frame();
ctx->avframe = av_frame_alloc();
lavc_context->refcounted_frames = 1;
lavc_context->codec_type = AVMEDIA_TYPE_AUDIO;
lavc_context->codec_id = lavc_codec->id;
@ -289,7 +290,7 @@ static void uninit(struct dec_audio *da)
av_freep(&lavc_context->extradata);
av_freep(&lavc_context);
}
avcodec_free_frame(&ctx->avframe);
av_frame_free(&ctx->avframe);
}
static int control(struct dec_audio *da, int cmd, void *arg)
@ -331,6 +332,7 @@ static int decode_new_packet(struct dec_audio *da)
}
int got_frame = 0;
av_frame_unref(priv->avframe);
int ret = avcodec_decode_audio4(avctx, priv->avframe, &got_frame, &pkt);
if (mpkt) {
// At least "shorten" decodes sub-frames, instead of the whole packet.