From 4300bfd5180b7d287d93b04d8e600f34886e0c53 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 24 Mar 2016 17:53:30 +0100 Subject: ad_lavc, vd_lavc: support new Libav decoding API For now only found in Libav. --- video/decode/vd_lavc.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'video/decode/vd_lavc.c') diff --git a/video/decode/vd_lavc.c b/video/decode/vd_lavc.c index 56633c0227..9559e0800f 100644 --- a/video/decode/vd_lavc.c +++ b/video/decode/vd_lavc.c @@ -646,6 +646,7 @@ static void decode(struct dec_video *vd, struct demux_packet *packet, vd_ffmpeg_ctx *ctx = vd->priv; AVCodecContext *avctx = ctx->avctx; struct vd_lavc_params *opts = ctx->opts->vd_lavc_params; + bool consumed = false; AVPacket pkt; if (!avctx) @@ -667,7 +668,23 @@ static void decode(struct dec_video *vd, struct demux_packet *packet, reset_avctx(vd); hwdec_lock(ctx); +#if HAVE_AVCODEC_NEW_CODEC_API + ret = avcodec_send_packet(avctx, packet ? &pkt : NULL); + if (ret >= 0 || ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) { + if (ret >= 0) + consumed = true; + ret = avcodec_receive_frame(avctx, ctx->pic); + if (ret >= 0) + got_picture = 1; + if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) + ret = 0; + } else { + consumed = true; + } +#else ret = avcodec_decode_video2(avctx, ctx->pic, &got_picture, &pkt); + consumed = true; +#endif hwdec_unlock(ctx); // Reset decoder if it was fully flushed. Caller might send more flush @@ -692,10 +709,8 @@ static void decode(struct dec_video *vd, struct demux_packet *packet, return; } - if (packet) { - // always fully consumed + if (packet && consumed) packet->len = 0; - } // Skipped frame, or delayed output due to multithreaded decoding. if (!got_picture) { -- cgit v1.2.3