From 4d6c1be7b69e99534cb6ac37daf8a22e7b2b153d Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 23 Sep 2015 14:01:45 +0200 Subject: vd_lavc: minor cleanup to hwdec fallback code The comment was largely outdated, and described the old situation when we used a "violent" fallback by making get_buffer2 fail completely. Also, for the case when the hw decoder initialization succeeded (in get_format), but get_buffer2 for some reason requests something unexpected, we also can fallback more gracefully and in the same way. --- video/decode/vd_lavc.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/video/decode/vd_lavc.c b/video/decode/vd_lavc.c index d9974e2531..375014e541 100644 --- a/video/decode/vd_lavc.c +++ b/video/decode/vd_lavc.c @@ -568,23 +568,16 @@ static int get_buffer2_hwdec(AVCodecContext *avctx, AVFrame *pic, int flags) struct dec_video *vd = avctx->opaque; vd_ffmpeg_ctx *ctx = vd->priv; - if (ctx->hwdec_failed) - return avcodec_default_get_buffer2(avctx, pic, flags); - - /* Decoders using ffmpeg's hwaccel architecture (everything except vdpau) - * can fall back to software decoding automatically. However, we don't - * want that: multithreading was already disabled. ffmpeg's fallback - * isn't really useful, and causes more trouble than it helps. - * - * Instead of trying to "adjust" the thread_count fields in avctx, let - * decoding fail hard. Then decode_with_fallback() will do our own software - * fallback. Fully reinitializing the decoder is saner, and will probably - * save us from other weird corner cases, like having to "reroute" the - * get_buffer callback. - */ int imgfmt = pixfmt2imgfmt(pic->format); if (!IMGFMT_IS_HWACCEL(imgfmt) || !ctx->hwdec) - return -1; + ctx->hwdec_failed = true; + + /* Hardware decoding failed, and we will trigger a proper fallback later + * when returning from the decode call. (We are forcing complete + * reinitialization later to reset the thread count properly.) + */ + if (ctx->hwdec_failed) + return avcodec_default_get_buffer2(avctx, pic, flags); // We expect it to use the exact size used to create the hw decoder in // get_format_hwdec(). For cropped video, this is expected to be the -- cgit v1.2.3