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 17AC04C5B2 for ; Mon, 26 May 2025 06:53:43 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id BB65468D15E; Mon, 26 May 2025 09:53:38 +0300 (EEST) Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id E475A68CCAD for ; Mon, 26 May 2025 09:53:31 +0300 (EEST) Received: from loongson.cn (unknown [36.33.26.33]) by gateway (Coremail) with SMTP id _____8DxDePjDzRo_JT8AA--.44398S3; Mon, 26 May 2025 14:53:23 +0800 (CST) Received: from localhost (unknown [36.33.26.33]) by front1 (Coremail) with SMTP id qMiowMBx3xviDzRoPRzyAA--.45322S3; Mon, 26 May 2025 14:53:22 +0800 (CST) From: zhoupeng To: ffmpeg-devel@ffmpeg.org Date: Mon, 26 May 2025 14:53:13 +0800 Message-Id: <20250526065313.3540-1-zhoupeng@loongson.cn> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-CM-TRANSID: qMiowMBx3xviDzRoPRzyAA--.45322S3 X-CM-SenderInfo: p2kr31hhqjqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoW3Wr1fXw1UCw45Gr13ur18tFc_yoW7Zr47pw 4xtFyqyryrGFsxGa42qr1qgayYkryIy3Z5Cr95Aw1kWw1SyrW5J3W3Gr15Zw1UGFWDJanY yF4UurW29FWIk3gCm3ZEXasCq-sJn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkFb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJr0_GcWl84ACjcxK6I8E87Iv6xkF7I0E14v2 6F4UJVW0owAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYIkI8VC2zVCFFI0UMc 02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAF wI0_Gr1j6F4UJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1Y6r17MIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE 42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6x kF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x07UuuWLUUUUU= Subject: [FFmpeg-devel] [PATCH v1] hwcontext_vaapi: Fix VAAPI initialization failure. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: zhoupeng Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Fix VA-API initialization failure caused by defaulting to VAAPI_DRM when hardware drivers only support VAAPI_X11. Each VAAPI scheme checks driver support through the successful return of vaInitialize.If unsupported, it continues to the next scheme without immediate failure. --- libavutil/hwcontext_vaapi.c | 104 +++++++++++++++++++----------------- 1 file changed, 56 insertions(+), 48 deletions(-) diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c index 95aa38d9d2..eacb7ae00f 100644 --- a/libavutil/hwcontext_vaapi.c +++ b/libavutil/hwcontext_vaapi.c @@ -1666,12 +1666,23 @@ static void vaapi_device_log_info(void *context, const char *message) #endif static int vaapi_device_connect(AVHWDeviceContext *ctx, - VADisplay display) + VADisplay display, char *driver_name) { AVVAAPIDeviceContext *hwctx = ctx->hwctx; int major, minor; VAStatus vas; +#if VA_CHECK_VERSION(0, 38, 0) + if (driver_name) { + vas = vaSetDriverName(display, driver_name); + if (vas != VA_STATUS_SUCCESS) { + av_log(ctx, AV_LOG_ERROR, "Failed to set driver name to " + "%s: %d (%s).\n", driver_name, vas, vaErrorStr(vas)); + return AVERROR_EXTERNAL; + } + } +#endif + #if CONFIG_VAAPI_1 vaSetErrorCallback(display, &vaapi_device_log_error, ctx); vaSetInfoCallback (display, &vaapi_device_log_info, ctx); @@ -1698,6 +1709,8 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, const char *device, VADisplay display = NULL; const AVDictionaryEntry *ent; int try_drm, try_x11, try_win32, try_all; + char *driver_name = NULL; + int ret = -1; priv = av_mallocz(sizeof(*priv)); if (!priv) @@ -1729,8 +1742,14 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, const char *device, try_win32 = HAVE_VAAPI_WIN32; } +#if VA_CHECK_VERSION(0, 38, 0) + ent = av_dict_get(opts, "driver", NULL, 0); + if (ent) + driver_name = ent->value; +#endif + #if HAVE_VAAPI_DRM - while (!display && try_drm) { + while ((ret < 0) && try_drm) { // If the device is specified, try to open it as a DRM device node. // If not, look for a usable render node, possibly restricted to those // using a specified kernel driver. @@ -1844,17 +1863,23 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, const char *device, } display = vaGetDisplayDRM(priv->drm_fd); - if (!display) { + if (display) { + ret = vaapi_device_connect(ctx, display, driver_name); + if (ret < 0) { + close(priv->drm_fd); + priv->drm_fd = -1; + vaTerminate(display); + display = NULL; + } + } else av_log(ctx, AV_LOG_VERBOSE, "Cannot open a VA display " "from DRM device %s.\n", device); - return AVERROR_EXTERNAL; - } break; } #endif #if HAVE_VAAPI_X11 - if (!display && try_x11) { + if ((ret < 0) && try_x11) { // Try to open the device as an X11 display. priv->x11_display = XOpenDisplay(device); if (!priv->x11_display) { @@ -1862,20 +1887,26 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, const char *device, "%s.\n", XDisplayName(device)); } else { display = vaGetDisplay(priv->x11_display); - if (!display) { + if (display) { + av_log(ctx, AV_LOG_VERBOSE, "Opened VA display via " + "X11 display %s.\n", XDisplayName(device)); + + ret = vaapi_device_connect(ctx, display, driver_name); + if (ret < 0) { + vaTerminate(display); + XCloseDisplay(priv->x11_display); + display = NULL; + priv->x11_display = NULL; + } + } else av_log(ctx, AV_LOG_ERROR, "Cannot open a VA display " "from X11 display %s.\n", XDisplayName(device)); - return AVERROR_UNKNOWN; - } - - av_log(ctx, AV_LOG_VERBOSE, "Opened VA display via " - "X11 display %s.\n", XDisplayName(device)); } } #endif #if HAVE_VAAPI_WIN32 - if (!display && try_win32) { + if ((ret < 0) && try_win32) { // Try to create a display from the specified device, if any. if (!device) { display = vaGetDisplayWin32(NULL); @@ -1925,45 +1956,22 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, const char *device, #endif } - if (!display) { + if (display) { + av_log(ctx, AV_LOG_VERBOSE, "Opened VA display via " + "Win32 display.\n"); + + ret = vaapi_device_connect(ctx, display, driver_name); + if (ret < 0) { + vaTerminate(display); + display = NULL; + } + } else av_log(ctx, AV_LOG_ERROR, "Cannot open a VA display " "from Win32 display.\n"); - return AVERROR_UNKNOWN; - } - - av_log(ctx, AV_LOG_VERBOSE, "Opened VA display via " - "Win32 display.\n"); - } -#endif - - if (!display) { - if (device) - av_log(ctx, AV_LOG_ERROR, "No VA display found for " - "device %s.\n", device); - else - av_log(ctx, AV_LOG_ERROR, "No VA display found for " - "any default device.\n"); - return AVERROR(EINVAL); } - - ent = av_dict_get(opts, "driver", NULL, 0); - if (ent) { -#if VA_CHECK_VERSION(0, 38, 0) - VAStatus vas; - vas = vaSetDriverName(display, ent->value); - if (vas != VA_STATUS_SUCCESS) { - av_log(ctx, AV_LOG_ERROR, "Failed to set driver name to " - "%s: %d (%s).\n", ent->value, vas, vaErrorStr(vas)); - vaTerminate(display); - return AVERROR_EXTERNAL; - } -#else - av_log(ctx, AV_LOG_WARNING, "Driver name setting is not " - "supported with this VAAPI version.\n"); #endif - } - return vaapi_device_connect(ctx, display); + return ret; } static int vaapi_device_derive(AVHWDeviceContext *ctx, @@ -2048,7 +2056,7 @@ static int vaapi_device_derive(AVHWDeviceContext *ctx, return AVERROR(EIO); } - return vaapi_device_connect(ctx, display); + return vaapi_device_connect(ctx, display, NULL); } #endif return AVERROR(ENOSYS); -- 2.20.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".