From patchwork Mon Dec 5 22:33:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 39623 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp3621900pzb; Mon, 5 Dec 2022 14:40:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf6wfmW5pjs7/dX3JzkzAlmi/MwgGYcdIW0FhQBF+1vzv6wJzpmHwv8QhLzqvJmergPkpv1R X-Received: by 2002:aa7:d14f:0:b0:46c:69a:39b0 with SMTP id r15-20020aa7d14f000000b0046c069a39b0mr16816532edo.294.1670280059094; Mon, 05 Dec 2022 14:40:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670280059; cv=none; d=google.com; s=arc-20160816; b=qw+4m5T/RIa/FM1SoStLVZVkomL4IqNEm3TDZv68W8Al1YhW5y5oaaDHfwllfikJDH JQEv8pLdfwp4bAoQyO3wkuI33IuHUCgvQJ4BbTOYS7JCaKz6UodAWtRn+Z7LOkdouWXs cB8pdFu9gn+KxMs8DJ88gi0LRrPFo+QwRcuTs7hvI1g4j92S8iyI+pnHsGXJ5WGyvo/H 5CdL29XjszH28hBWrDotqxHpiVsALpoLazmg4qkM9idNeFuUMQWtp+Eeh+cjRcxEz0xq FpH9SZweIJZT9dXQzXnjYB8FzTtN7LsS6RBCE5/baycWIXKBxGLsa+jFmZ8aC62obsCb g8Pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=V+q1iJYHPxAhsAmuMgt0Wy96KfSiVDY8+SJ6I5oVuAs=; b=QXct2WoWop6GpAvcTxkRNEwp2NM1l0+R+lVbvydkWXpg7hqQ39A36zld6NrdZ9K/6a yRSK6gkyljsTQ9rQTIUKpPx2u9IZNk5VQ2mtwXxnLoTt1NGdxVmhwhqD9zNwlmYNOlRb kY3wsFW3aiZe13n7F7AIldzqjzpVzVbdpzdKTjurxM6/dssFKSEoWFHr4dRjy3lqTKzk jiD/fc/ejc0ryao7m7GjooGZiUeoMb3c5+LNCmWK02CL6rT3/guCKvdEA0ZqALMT/OrJ ZtjYOqkVMz0bWGtSN+VEQq+BOPuVzcSU+8AVKiMR1wFIElkPNdctmp0BgHNNrAxJPyRg ZD3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@chromium.org header.s=google header.b="bG/IaGkJ"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id eb9-20020a0564020d0900b00461f9648c7dsi594234edb.422.2022.12.05.14.40.58; Mon, 05 Dec 2022 14:40:59 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@chromium.org header.s=google header.b="bG/IaGkJ"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CCCCA68BD06; Tue, 6 Dec 2022 00:40:55 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CFFCA68A708 for ; Tue, 6 Dec 2022 00:40:49 +0200 (EET) Received: by mail-pg1-f181.google.com with SMTP id h33so11743399pgm.9 for ; Mon, 05 Dec 2022 14:40:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=AbgvcDmE2GiiwZwJgIieocGT71bmPpqNlxXFHo9Rl/s=; b=bG/IaGkJig0DY/ywaR0sjw/TDa/dB1flsonn9utiiNYXO/qE4Xml1IFM02sVy90Gn4 Ykip2uqSmmiWNrsts1jeeCJCQNelGOO5+M9GvkrC8Ii4ahR6/M1Aha3WhVMO7Snny0fA 6tsYEXqF8d5eZxSvSAqMTixtvCbiMOsL9fzok= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AbgvcDmE2GiiwZwJgIieocGT71bmPpqNlxXFHo9Rl/s=; b=28jwhyFeqlWEVcRFr8DJV69SC4Wb0Wvx0DlNgFlagmVrrz76juzCbnRp+pqsoTm0w2 MMs+4hTdJAwanyC5r1eM3l6O3DhWUNTfi5fTFcHYVY/CC5to3zZxEJ53a9fJtZ5CrodJ z3kbyA/lWnPPwtcCmJoi0Uzf1pLjF5Wa1eGijZy9M38aXZF3UdHEuyGD0V3MHmHSrF4O TDYoHVdNUZCXk+3coyFLEDexVMC+JlSlbAlJtjGFRu71CliMxWqn5ThpXfcRL8GCG1xl g7Ss9tSheMw+c6I4Qa/U+Tnf8cJ1jd4zNKTmNhExUWoI00bP5X1egpoT3RR/TUxLKGtR N1oA== X-Gm-Message-State: ANoB5pmr5ZGH5/qqDH7Y3vUoKGHjkEmJlZJqJUgbGKGgPDpUAXoEH3KU 2fIUunq9GOrx2CaFZMYAbInlTmRmFhPQNJCI X-Received: by 2002:a63:e44b:0:b0:476:f69c:2304 with SMTP id i11-20020a63e44b000000b00476f69c2304mr79500843pgk.77.1670280047654; Mon, 05 Dec 2022 14:40:47 -0800 (PST) Received: from localhost ([2620:15c:9d:2:9b83:ae6f:f47b:bb4d]) by smtp.gmail.com with UTF8SMTPSA id w10-20020a170902e88a00b00186b0ac12c5sm11086603plg.172.2022.12.05.14.40.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 05 Dec 2022 14:40:47 -0800 (PST) From: Brian Norris To: ffmpeg-devel@ffmpeg.org Date: Mon, 5 Dec 2022 14:33:21 -0800 Message-Id: <20221205143317.v2.1.I9025996c33e0a4fe6133de948af3f3e75c214475@changeid> X-Mailer: git-send-email 2.39.0.rc0.267.gcb52ba06e7-goog MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] lavu/hwcontext_vaapi: Skip 'vgem' driver 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: Haihao Xiang , Brian Norris Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: QrnLvZ03RwtS There can be more than one available render node, and it's not guaranteed the first node we come across is the correct one. In particular, 'vgem' devices are common, and are never VAAPI-enabled and thus not valid here. We have a 'kernel_driver' arg already for specifying a single driver we *do* want, but it doesn't support a negation, nor a list. It's easier just to automatically skip 'vgem' anyway, to avoid foisting this burden on users. This has precedent in libva-utils already: bfb6b98ed62a exclude vgem node and invalid drm node in vainfo https://github.com/intel/libva-utils/commit/bfb6b98ed62ac14a840ba62639ab902a23912258 Signed-off-by: Brian Norris --- Changes in v2: - strncmp() -> strcmp() libavutil/hwcontext_vaapi.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c index 4bcde74f6212..938bd5447d5e 100644 --- a/libavutil/hwcontext_vaapi.c +++ b/libavutil/hwcontext_vaapi.c @@ -1700,6 +1700,7 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, const char *device, char path[64]; int n, max_devices = 8; #if CONFIG_LIBDRM + drmVersion *info; const AVDictionaryEntry *kernel_driver; kernel_driver = av_dict_get(opts, "kernel_driver", NULL, 0); #endif @@ -1713,9 +1714,15 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, const char *device, break; } #if CONFIG_LIBDRM + info = drmGetVersion(priv->drm_fd); + if (!info) { + av_log(ctx, AV_LOG_VERBOSE, + "Failed to get DRM version for device %d.\n", n); + close(priv->drm_fd); + priv->drm_fd = -1; + continue; + } if (kernel_driver) { - drmVersion *info; - info = drmGetVersion(priv->drm_fd); if (strcmp(kernel_driver->value, info->name)) { av_log(ctx, AV_LOG_VERBOSE, "Ignoring device %d " "with non-matching kernel driver (%s).\n", @@ -1730,12 +1737,20 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, const char *device, "with matching kernel driver (%s).\n", n, info->name); drmFreeVersion(info); - } else -#endif - { - av_log(ctx, AV_LOG_VERBOSE, "Trying to use " - "DRM render node for device %d.\n", n); + break; + // drmGetVersion() ensures |info->name| is 0-terminated. + } else if (!strcmp(info->name, "vgem")) { + av_log(ctx, AV_LOG_VERBOSE, + "Skipping vgem node for device %d.\n", n); + drmFreeVersion(info); + close(priv->drm_fd); + priv->drm_fd = -1; + continue; } + drmFreeVersion(info); +#endif + av_log(ctx, AV_LOG_VERBOSE, "Trying to use " + "DRM render node for device %d.\n", n); break; } if (n >= max_devices)