From patchwork Mon May 6 14:49:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 13008 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id B0C394482AD for ; Mon, 6 May 2019 17:49:42 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A47AB68AD4A; Mon, 6 May 2019 17:49:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 77D2668A772 for ; Mon, 6 May 2019 17:49:35 +0300 (EEST) Received: by mail-wm1-f48.google.com with SMTP id q15so16130963wmf.3 for ; Mon, 06 May 2019 07:49:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jkqxz-net.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=7vX6VxFm3mcJnCs1xUjT3KmFUIlIpVXDxIZxYUAVhRw=; b=K8dL4krmK2f37ml8wk7pCkOoLXC2C9oC1Cep98VY7S8FsPZ/Vd9MUsaeUQU6+Sgr17 FC8EWciJUjWt9yBkcnfSnn5wAMeEsJBIkbbQ5CnhJIr+ubvY2SZWLQY078GpU+fstXPR rHvl8ukZbTXNX5eh32F9ksePUV3ERPZTr1lbs9GhrU4LoJDCQfpjah2RLw4FTU2Vx0oa 2uOVDL8BCAko75g4Z2eXfvdbDSG/xnPr7FV117dAh+Vye0+Kc8v8nkmt46u9w3oHYoCd wuillbILVsUM/XJnYBr8E2uwSzuOg/A8OeIs1XFB3BJU2Kxx8kkn7oYLOcdTtvHTg4Dy njfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7vX6VxFm3mcJnCs1xUjT3KmFUIlIpVXDxIZxYUAVhRw=; b=qhOCUGi3TGuttJRLinHhIPhaqFPj4K7ZZFJlgJsE1LcC77cYMggLKsODR7H6HN+urA 99BE6T4/8F606BWx5FH/HhYir7QPZmPhYGofk10klDKcMW4Wm7akPLoQAgSoSE7nvuKT gwWii4NUG4L5+49fjNI9zNP7XtM1lcghdLnDPK4EXNVpMKWEZR90rzWBgGBgu/hpX1LN triKMM15z2lxAcwXsxQ3hKOVEu451Y8i5wF8zzP/CIuEPhjs2PEvH/wyygcX4cbQ9q+c XYBBugGj2jOj+hKAd0LrxmIDBz50x/Fmk0cnnnshmFTOZLlH1bkxTAChlTKITzO7Wb4E qJow== X-Gm-Message-State: APjAAAUUX1nUYibrEq7HP/WyoWzQsmbPlda9lPUBLz9Zy3WiPh//ZMjv OZ6sso5KVHXPA9J0F5E5nMd6ttlp4cw= X-Google-Smtp-Source: APXvYqyZ1pk1vMRJWB5xxnXiJwL0FJWybxq+g7ihJ6mBt+du6YXcppIrZ5a/WKxRjNB84Bw19R7WNQ== X-Received: by 2002:a1c:7613:: with SMTP id r19mr9296132wmc.120.1557154174671; Mon, 06 May 2019 07:49:34 -0700 (PDT) Received: from rywe.jkqxz.net (cpc91242-cmbg18-2-0-cust650.5-4.cable.virginm.net. [82.8.130.139]) by smtp.gmail.com with ESMTPSA id l19sm14691742wrg.29.2019.05.06.07.49.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 07:49:34 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 6 May 2019 15:49:24 +0100 Message-Id: <20190506144928.28501-4-sw@jkqxz.net> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190506144928.28501-1-sw@jkqxz.net> References: <20190506144928.28501-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/7] hwcontext_vaapi: Make default DRM device selection more helpful X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Iterate over available render devices and pick the first one which looks usable. Adds an option to specify the name of the kernel driver associated with the desired device, so that it is possible to select a specific type of device in a multiple-device system without knowing the card numbering. For example: -init_hw_device vaapi:,kernel_driver=amdgpu will select only devices using the "amdgpu" driver (as used with recent AMD graphics cards). Kernel driver selection requires libdrm to work. --- libavutil/hwcontext_vaapi.c | 76 +++++++++++++++++++++++++++++-------- 1 file changed, 60 insertions(+), 16 deletions(-) diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c index 561b82fcce..c151f8da93 100644 --- a/libavutil/hwcontext_vaapi.c +++ b/libavutil/hwcontext_vaapi.c @@ -27,6 +27,7 @@ #if CONFIG_LIBDRM # include +# include # include # ifndef DRM_FORMAT_MOD_INVALID # define DRM_FORMAT_MOD_INVALID ((1ULL << 56) - 1) @@ -1521,26 +1522,69 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, const char *device, #endif #if HAVE_VAAPI_DRM - if (!display && try_drm) { - // Try to open the device as a DRM path. - // Default to using the first render node if the user did not - // supply a path. - const char *path = device ? device : "/dev/dri/renderD128"; - priv->drm_fd = open(path, O_RDWR); - if (priv->drm_fd < 0) { - av_log(ctx, AV_LOG_VERBOSE, "Cannot open DRM device %s.\n", - path); + while (!display && 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. + int loglevel = try_all ? AV_LOG_VERBOSE : AV_LOG_ERROR; + if (device) { + priv->drm_fd = open(device, O_RDWR); + if (priv->drm_fd < 0) { + av_log(ctx, loglevel, "Failed to open %s as " + "DRM device node.\n", device); + break; + } } else { - display = vaGetDisplayDRM(priv->drm_fd); - if (!display) { - av_log(ctx, AV_LOG_ERROR, "Cannot open a VA display " - "from DRM device %s.\n", path); - return AVERROR_UNKNOWN; + const AVDictionaryEntry *kernel_driver; + char path[64]; + int n, max_devices = 8; + kernel_driver = av_dict_get(opts, "kernel_driver", NULL, 0); + for (n = 0; n < max_devices; n++) { + snprintf(path, sizeof(path), + "/dev/dri/renderD%d", 128 + n); + priv->drm_fd = open(path, O_RDWR); + if (priv->drm_fd < 0) { + av_log(ctx, AV_LOG_VERBOSE, "Cannot open " + "DRM render node for device %d.\n", n); + continue; + } +#if CONFIG_LIBDRM + 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", + n, info->name); + drmFreeVersion(info); + close(priv->drm_fd); + priv->drm_fd = -1; + continue; + } + av_log(ctx, AV_LOG_VERBOSE, "Trying to use " + "DRM render node for device %d, " + "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; } + if (n >= max_devices) + break; + } - av_log(ctx, AV_LOG_VERBOSE, "Opened VA display via " - "DRM device %s.\n", path); + display = vaGetDisplayDRM(priv->drm_fd); + if (!display) { + av_log(ctx, AV_LOG_VERBOSE, "Cannot open a VA display " + "from DRM device %s.\n", device); + return AVERROR_EXTERNAL; } + break; } #endif