From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 1D82544AFC for ; Wed, 12 Nov 2025 15:25:53 +0000 (UTC) Authentication-Results: ffbox; dkim=fail (body hash mismatch (got b'1qdR8/kUNSJ7b13T8ok1JBYE5smV8V762zRdDqybTmo=', expected b'o7+AhF4ZStLam99skcVYnlnod2GGm3hBU2Fv9GFCbNA=')) header.d=ffmpeg.org header.i=@ffmpeg.org header.a=rsa-sha256 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1762960963; h=mime-version : to : date : message-id : reply-to : subject : list-id : list-archive : list-archive : list-help : list-owner : list-post : list-subscribe : list-unsubscribe : from : cc : content-type : content-transfer-encoding : from; bh=1qdR8/kUNSJ7b13T8ok1JBYE5smV8V762zRdDqybTmo=; b=zghk6HZtF4r7mdpcMP5E+H0j62xZaRkdW0f1bVH3M+RBM/uFx+/HiMX9NmzLdv3EPpW+J gYfVu55A9A9uzSrBZUgXWNN0fa854wyMxQFCrSx4/RUvDULdAR6ms7wQrz//SfOD40LewrP JkNS77ZJVS0C1zFNx9EKSbuqTH3kVnTkL2/GmsU66rxr3kWxBbZGbjIfAIMz6cUuRe2JqnF vZDjC2L10tNreAlpCLgYuMJRLlRiw1+JdO7J3fu9SNocOO1erwuOes9P+BduXsCqYrMrEQX BSWSTO3tgYajUo4VOgcrOGz4qw+2Srg7tuo4TZ9GjLgygZodOxcEPi6qA6Ww== Received: from [172.19.0.2] (unknown [172.19.0.2]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id D47F268FD73; Wed, 12 Nov 2025 17:22:43 +0200 (EET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1762960900; b=sls0ucvNJfE+F0JjLpMBpv0MD23mwONJmXuEgNfNBMTQbvggREP8zmDuR48fPRpMGnW5H R2cC5hbwMUluo+fXHt+PiOC118oO3/QUWnR1C96PzBK5eOxXEH0LbmKt1M/M137UFdYTz91 DnSNSuA6cb41zjwo3mXIyghUtIZg0XAByqrst0PIznxYVBA3dFbYVnedYbp9KaygumrHJ8a Hj49NBXQ8LNcBKaAFkOcvj5Zjj7xmVWlY3eBi+4pVaAZ9J3mRz3qwnxzwOWt6qqzfLUnSyo mIsn8FGVOwJ7VwmW++YYSDmU1C4U1iuNol3o5OrQ9LlfDTIheBQcbI/ocq2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1762960900; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=ZUF8+DJOog1L+34ctXoVJDTBGXttJyFRNvcgpgK69p0=; b=NWM2F0W+9sB4Dliq2OvAcXmyRzGrzDWtTNPf8T8u7snpGPjmGq+axKyIMWm05xBmtDGaG LI/F408Lco2TBH454GGc23MDg01ExU3MSOyVgHMOCv7/yOaYqOS2UAVRekRr2BljJisjTQQ 1zCmmpkvD21sOKaHocSfjlr35sh3FjpGsDOMRb4m8x8A9ndaGbKqZRTt+vzLO/yyEJy9oT5 X6WwahIusXcBYdrfe/4zn8l/7x+yqX9pTasGWZAQHLgCL5LxQHyNNdjtVhuOzDB1ga91H3H D0VoQcFwnw4y2lV/q9762suMpi9jjHXMl9DuFMJYjcjkktX+lQTCpcC+5Lhw== ARC-Authentication-Results: i=1; ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none; dmarc=pass header.from=ffmpeg.org policy.dmarc=quarantine Authentication-Results: ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none (Message is not ARC signed); dmarc=pass (Used From Domain Record) header.from=ffmpeg.org policy.dmarc=quarantine DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1762960884; h=content-type : mime-version : content-transfer-encoding : from : to : reply-to : subject : date : from; bh=o7+AhF4ZStLam99skcVYnlnod2GGm3hBU2Fv9GFCbNA=; b=XGrSqEQeP9dG7oOJoz1ezHTsZTp9RnTmrqjGECljJUIKe5EeQPxKEUyzjuSDM3SoBu6cp 2FStGWtzOKILNdTCmfukGxYHzStasvSF/XXKVnDsGKbEG4k/nEPbj1FEkY2kO2WHib8IEpk Y7IJOPTZfHwdTdflFHAed4NDaPqqA36yMriQLRpzjG3cL4p/DNZJUgccxGJcc7TSZPRJVA+ LBITkwA8stk7zt7QesDcEfrcJjCleOreADSAMcOMyd4BJhLFLpaLSx7BTRdE0c+R3cmnsRg OZc+3JN2PC28SS3cM6nVzYkDYS7g0xmhkm/TAhc0j1XmYqipjMuq5ETmWTSw== Received: from 188d6d40ca7a (code.ffmpeg.org [188.245.149.3]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id BA66468FD31 for ; Wed, 12 Nov 2025 17:21:24 +0200 (EET) MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Nov 2025 15:21:24 -0000 Message-ID: <176296088524.25.17546594433848278804@2cb04c0e5124> Message-ID-Hash: CP2I35KRQFXSPQEXRXLCM7K4C3LXV2WD X-Message-ID-Hash: CP2I35KRQFXSPQEXRXLCM7K4C3LXV2WD X-MailFrom: code@ffmpeg.org X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-ffmpeg-devel.ffmpeg.org-0; header-match-ffmpeg-devel.ffmpeg.org-1; header-match-ffmpeg-devel.ffmpeg.org-2; header-match-ffmpeg-devel.ffmpeg.org-3; emergency; member-moderation X-Mailman-Version: 3.3.10 Precedence: list Reply-To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PATCH] WIP: avutil/hwcontext_vaapi: fix use fourcc not supported by devices (PR #20899) List-Id: FFmpeg development discussions and patches Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Zhao Zhili via ffmpeg-devel Cc: Zhao Zhili Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Archived-At: List-Archive: List-Post: PR #20899 opened by Zhao Zhili (quink) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20899 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20899.patch avutil/hwcontext_vaapi: fix use fourcc not supported by devices 1. A AVPixelFormat can map to multiple VA_FOURCCs, while vaapi_format_from_pix_fmt() only returns the first item matched before this patch. 2. vaapi_frames_init() use vaapi_format_from_pix_fmt() to get the first item. fourcc in this item may not be supported by the device. There is a real issue. av_hwdevice_get_hwframe_constraints returned AV_PIX_FMT_YUV422P is a supported sw_format, while it's only supported by VA_FOURCC_YV16, but vaapi_frames_init try to use VA_FOURCC_422H later. This patch makes vaapi_format_from_pix_fmt return all matched items iteratively, then use strict check in vaapi_frames_init to get the right fourcc. >>From 6bb427af54bf5453b998c3c12a389b087217aeda Mon Sep 17 00:00:00 2001 From: Zhao Zhili Date: Wed, 12 Nov 2025 21:56:36 +0800 Subject: [PATCH 1/2] avutil/hwcontext_vaapi: fix error code for invalid argument Also replace goto by return directly, as there is nothing to cleanup. --- libavutil/hwcontext_vaapi.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c index 753dcf8905..256363eb97 100644 --- a/libavutil/hwcontext_vaapi.c +++ b/libavutil/hwcontext_vaapi.c @@ -222,9 +222,12 @@ static int vaapi_get_image_format(AVHWDeviceContext *hwdev, const VAAPIFormatDescriptor *desc; int i; + if (!image_format) + return AVERROR(EINVAL); + desc = vaapi_format_from_pix_fmt(pix_fmt); - if (!desc || !image_format) - goto fail; + if (!desc) + return AVERROR(ENOSYS); for (i = 0; i < ctx->nb_formats; i++) { if (ctx->formats[i].fourcc == desc->fourcc) { @@ -233,7 +236,6 @@ static int vaapi_get_image_format(AVHWDeviceContext *hwdev, } } -fail: return AVERROR(ENOSYS); } -- 2.49.1 >>From b71c350f9f176dab871c2a89a60a7c58909c81f4 Mon Sep 17 00:00:00 2001 From: Zhao Zhili Date: Wed, 12 Nov 2025 22:35:45 +0800 Subject: [PATCH 2/2] avutil/hwcontext_vaapi: fix use fourcc not supported by devices 1. A AVPixelFormat can map to multiple VA_FOURCCs, while vaapi_format_from_pix_fmt() only returns the first item matched before this patch. 2. vaapi_frames_init() use vaapi_format_from_pix_fmt() to get the first item. fourcc in this item may not be supported by the device. There is a real issue. av_hwdevice_get_hwframe_constraints returned AV_PIX_FMT_YUV422P is a supported sw_format, while it's only supported by VA_FOURCC_YV16, but vaapi_frames_init try to use VA_FOURCC_422H later. This patch makes vaapi_format_from_pix_fmt return all matched items iteratively, then use strict check in vaapi_frames_init to get the right fourcc. --- libavutil/hwcontext_vaapi.c | 72 ++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c index 256363eb97..4f3502797b 100644 --- a/libavutil/hwcontext_vaapi.c +++ b/libavutil/hwcontext_vaapi.c @@ -195,12 +195,17 @@ static const VAAPIFormatDescriptor * } static const VAAPIFormatDescriptor * - vaapi_format_from_pix_fmt(enum AVPixelFormat pix_fmt) + vaapi_format_from_pix_fmt(enum AVPixelFormat pix_fmt, const VAAPIFormatDescriptor *prev) { - int i; - for (i = 0; i < FF_ARRAY_ELEMS(vaapi_format_map); i++) - if (vaapi_format_map[i].pix_fmt == pix_fmt) - return &vaapi_format_map[i]; + const VAAPIFormatDescriptor *end = &vaapi_format_map[FF_ARRAY_ELEMS(vaapi_format_map)]; + if (!prev) + prev = vaapi_format_map; + else + prev++; + + for (; prev < end; prev++) + if (prev->pix_fmt == pix_fmt) + return prev; return NULL; } @@ -214,31 +219,39 @@ static enum AVPixelFormat vaapi_pix_fmt_from_fourcc(unsigned int fourcc) return AV_PIX_FMT_NONE; } -static int vaapi_get_image_format(AVHWDeviceContext *hwdev, +static int vaapi_get_img_desc_and_format(AVHWDeviceContext *hwdev, enum AVPixelFormat pix_fmt, + const VAAPIFormatDescriptor **_desc, VAImageFormat **image_format) { VAAPIDeviceContext *ctx = hwdev->hwctx; - const VAAPIFormatDescriptor *desc; + const VAAPIFormatDescriptor *desc = NULL; int i; - if (!image_format) - return AVERROR(EINVAL); - - desc = vaapi_format_from_pix_fmt(pix_fmt); - if (!desc) - return AVERROR(ENOSYS); - - for (i = 0; i < ctx->nb_formats; i++) { - if (ctx->formats[i].fourcc == desc->fourcc) { - *image_format = &ctx->formats[i].image_format; - return 0; + while ((desc = vaapi_format_from_pix_fmt(pix_fmt, desc))) { + for (i = 0; i < ctx->nb_formats; i++) { + if (ctx->formats[i].fourcc == desc->fourcc) { + if (_desc) + *_desc = desc; + if (image_format) + *image_format = &ctx->formats[i].image_format; + return 0; + } } } return AVERROR(ENOSYS); } +static int vaapi_get_image_format(AVHWDeviceContext *hwdev, + enum AVPixelFormat pix_fmt, + VAImageFormat **image_format) +{ + if (!image_format) + return AVERROR(EINVAL); + return vaapi_get_img_desc_and_format(hwdev, pix_fmt, NULL, image_format); +} + static int vaapi_frames_get_constraints(AVHWDeviceContext *hwdev, const void *hwconfig, AVHWFramesConstraints *constraints) @@ -564,19 +577,23 @@ static int vaapi_frames_init(AVHWFramesContext *hwfc) VAAPIFramesContext *ctx = hwfc->hwctx; AVVAAPIFramesContext *avfc = &ctx->p; AVVAAPIDeviceContext *hwctx = hwfc->device_ctx->hwctx; - const VAAPIFormatDescriptor *desc; - VAImageFormat *expected_format; + const VAAPIFormatDescriptor *desc = NULL; + VAImageFormat *expected_format = NULL; AVBufferRef *test_surface = NULL; VASurfaceID test_surface_id; VAImage test_image; VAStatus vas; int err, i; - desc = vaapi_format_from_pix_fmt(hwfc->sw_format); - if (!desc) { - av_log(hwfc, AV_LOG_ERROR, "Unsupported format: %s.\n", - av_get_pix_fmt_name(hwfc->sw_format)); - return AVERROR(EINVAL); + err = vaapi_get_img_desc_and_format(hwfc->device_ctx, hwfc->sw_format, + &desc, &expected_format); + if (err < 0) { + // Use a relaxed check when pool exist. It can be an external pool. + if (!hwfc->pool || !vaapi_format_from_pix_fmt(hwfc->sw_format, NULL)) { + av_log(hwfc, AV_LOG_ERROR, "Unsupported format: %s.\n", + av_get_pix_fmt_name(hwfc->sw_format)); + return AVERROR(EINVAL); + } } if (!hwfc->pool) { @@ -675,10 +692,7 @@ static int vaapi_frames_init(AVHWFramesContext *hwfc) test_surface_id = (VASurfaceID)(uintptr_t)test_surface->data; ctx->derive_works = 0; - - err = vaapi_get_image_format(hwfc->device_ctx, - hwfc->sw_format, &expected_format); - if (err == 0) { + if (expected_format) { vas = vaDeriveImage(hwctx->display, test_surface_id, &test_image); if (vas == VA_STATUS_SUCCESS) { if (expected_format->fourcc == test_image.format.fourcc) { -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org