From: Jaroslav Kysela Date: Thu, 20 Sep 2018 13:39:37 +0000 (+0200) Subject: transcode: fix hwaccels_decode_setup_context() for ffmpeg 4.0.2, fixes #5202 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=976b83c7f4830af05ef6283d5c5fd2fdd4fef00e;p=thirdparty%2Ftvheadend.git transcode: fix hwaccels_decode_setup_context() for ffmpeg 4.0.2, fixes #5202 --- diff --git a/src/transcoding/transcode/hwaccels/hwaccels.c b/src/transcoding/transcode/hwaccels/hwaccels.c index 4a8e8218d..7a79cda18 100644 --- a/src/transcoding/transcode/hwaccels/hwaccels.c +++ b/src/transcoding/transcode/hwaccels/hwaccels.c @@ -29,12 +29,12 @@ /* decoding ================================================================= */ +#if LIBAVCODEC_VERSION_MAJOR < 58 /* lifted from libavcodec/utils.c */ static AVHWAccel * find_hwaccel(enum AVCodecID codec_id, enum AVPixelFormat pix_fmt) { AVHWAccel *hwaccel = NULL; - while ((hwaccel = av_hwaccel_next(hwaccel))) { if (hwaccel->id == codec_id && hwaccel->pix_fmt == pix_fmt) { return hwaccel; @@ -42,16 +42,41 @@ find_hwaccel(enum AVCodecID codec_id, enum AVPixelFormat pix_fmt) } return NULL; } +static inline int check_pix_fmt(AVCodecContext *avctx, enum AVPixelFormat pix_fmt) +{ + return find_hwaccel(avctx->codec_id, pix_fmt) == NULL; +} +#else +static const AVCodecHWConfig * +find_hwconfig(const AVCodec *codec, enum AVPixelFormat pix_fmt) +{ + const AVCodecHWConfig *hwcfg = NULL; + int i; + for (i = 0;; i++) { + hwcfg = avcodec_get_hw_config(codec, i); + if (!hwcfg) + break; + if (hwcfg->pix_fmt == pix_fmt) + return hwcfg; + } + return NULL; +} +static inline int check_pix_fmt(AVCodecContext *avctx, enum AVPixelFormat pix_fmt) +{ + return find_hwconfig(avctx->codec, pix_fmt) == NULL; +} +#endif static int hwaccels_decode_setup_context(AVCodecContext *avctx, const enum AVPixelFormat pix_fmt) { - AVHWAccel *hwa = NULL; + const AVPixFmtDescriptor *desc; - if (!(hwa = find_hwaccel(avctx->codec_id, pix_fmt))) { - tvherror(LS_TRANSCODE, "no AVHWAccel for the pixel format"); + if (check_pix_fmt(avctx, pix_fmt)) { + desc = av_pix_fmt_desc_get(pix_fmt); + tvherror(LS_TRANSCODE, "no HWAccel for the pixel format '%s'", desc ? desc->name : ""); return AVERROR(ENOENT); } switch (pix_fmt) {