From patchwork Tue Jul 19 16:56:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 36844 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp1878619pzb; Tue, 19 Jul 2022 09:56:26 -0700 (PDT) X-Google-Smtp-Source: AGRyM1szCHIPFOaEjYUM8pAA7s6qEa6JvMtv0LnFxtEOaan4vl3QZncW45BG5ilHSwoh9MDcNc4D X-Received: by 2002:a17:906:8462:b0:72b:4e05:a8c1 with SMTP id hx2-20020a170906846200b0072b4e05a8c1mr30690020ejc.443.1658249786459; Tue, 19 Jul 2022 09:56:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658249786; cv=none; d=google.com; s=arc-20160816; b=xkEg2+vEhG7GKbSPIAr+gNA7o8sG/cWx66bRehL6XtdoTKYDLINct7KTCAvzqE9MXO FTCO/KbYOKSzTJmPiBxM1iYhT8WKu9TzyK5LVYkMUM9VtpXDI0p0bEJAs62R6Qalw1RU TtE1ymY7nCyxjkeEWOYs6zQx+y1BS5v4kM9cOeR0ghqEmmcnIl04CfMGIWMduc9Ta/lq UwjMX47A1POBNMpOQM8sgGtlOFIYQbq/NywhpGA8KroRvT7j9dPRRaquRoL4dbyf2VeC ztsK+xqSsOwuqtJERytNNavjl7Srh3811G1hsPwBMnaX4u9YD/6zlAHFyW42tOxzSDjq JAkg== 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:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=jsQk6DPr8k5ScMEQ5ANva4H64suA40APnT5x1wUamt4=; b=XJjYZfU5wI/wO06FT3FlV+WBE7mYMX/RGwsYYRWD7rUmMgaZO7hjWdhW6g3dex9KIe ATYYhJw3+MOT2X935pJTkZDp02l5y1FYGIQOO1fzM2rBZUehiPSLWm9DbrJYKjDjTrY2 GGKkBCukw+QTpKBptcU52KOeLTSqMBVgzmUH7soNvOPEbFj8Yx6e57Rg9KMdGixV4Fdo t323zkt3vGJ+lXmIZG0Q4+QAXtjPSiFpL9YP1kKlkJezZAs5s+pUCCTqpq16H0/Ggz0v L5iW9aYJ/HPZpiLBFnxeA5AaQJANCKs7zWhOe0tDoO7NJ4cZKkGTtu+BDW+A0QexyP/J CiZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=WP4l3zWA; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id j1-20020a056402238100b0043ba1e357fesi1720757eda.240.2022.07.19.09.56.25; Tue, 19 Jul 2022 09:56:26 -0700 (PDT) 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=@gmail.com header.s=20210112 header.b=WP4l3zWA; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DD47668B64A; Tue, 19 Jul 2022 19:56:14 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C9EA268A467 for ; Tue, 19 Jul 2022 19:56:07 +0300 (EEST) Received: by mail-wr1-f42.google.com with SMTP id n12so9660418wrc.8 for ; Tue, 19 Jul 2022 09:56:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dO2IOpOSupug+nS9fB6OE6zwqKWk2MZaA/j/xfiaBj0=; b=WP4l3zWAO31hwGHn5Q4pH1EpqMnthr+FZhgc7uVoi9vQXFxtJn6mOKk8pg8jgl3CwR DK3CE0qfn6ONP6JH6waEOWpnDn3CjLdW8S+GGctfjX9s22BKZiyL1v4eysHhiU7S/ydn g1lnxn3tm4pXuXgaHv5pfG39NI4pWfDqxucoqMejekLu92hARIl1JMx9RExMILh4pOc0 q4VwYkUExqzuhUQSevMNKsiWK9xzf0A9luDxqCRi6bKF7L97Om9NNyMfLL3bMjZo7txK 8Jt7iPG+3XI+CZjfmbEz9vND4XAayV8AONlBEKkVjqPOzCeYr1Eu48Ql2FOqPTJZvltH udgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dO2IOpOSupug+nS9fB6OE6zwqKWk2MZaA/j/xfiaBj0=; b=cP50bzpUBw4k548BzZhKCS+hOMCZFFc4fAmZMjth+OpT3MNcYD8rjgjQIQId3jH0u3 7aqFuWZuJ6ipxv0xtcvggwxj79Ln4W6N7hh7x4fH5614LvutH8hPt1JJl8bciN6MaE0V KY+rrUP9jqWhQEQgTGx3PIoWGB6OpD3CsYom5NiyJLz/PEIIalAcCo72HYvU5Q9d4rEq tSXQy63gzYXiVhbPiJLwDT9SL90iAhbdJrdeII7OKBR2QqnA1W+zbzFMtqltKZaZRYVb DW68VeTvRxFyHxiKFB06qra8TCabh79BLQEkysyRfUmNsEua+S7+rGW43hg2FR9vd90e IV5g== X-Gm-Message-State: AJIora88a5dFBF90QNteaKOjm2vZqBse0e/E+PRscvYDwynBFfB0doWS pklCVqjIHyG+3kBb7UMT8nN3NdAumf/hXQ== X-Received: by 2002:a5d:584f:0:b0:21d:bcd6:5c8e with SMTP id i15-20020a5d584f000000b0021dbcd65c8emr26269350wrf.60.1658249766493; Tue, 19 Jul 2022 09:56:06 -0700 (PDT) Received: from localhost ([2a00:5f00:102:0:ed02:7072:7dbf:2431]) by smtp.gmail.com with UTF8SMTPSA id m9-20020adfe949000000b0021d4694fcaesm13786156wrn.107.2022.07.19.09.56.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 19 Jul 2022 09:56:06 -0700 (PDT) From: Emil Velikov To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Jul 2022 17:56:03 +0100 Message-Id: <20220719165604.640770-2-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220719165604.640770-1-emil.l.velikov@gmail.com> References: <20220719165604.640770-1-emil.l.velikov@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] hwcontext_vaapi: do not link against libva-drm.so 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: Mark Thompson , emil.l.velikov@gmail.com Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: a+iCKhYYpG8R From: Emil Velikov There is an internal ABI between libva.so and libva-drm.so. So having mismatched versions can cause all sorts of issues. We had the breakage between libva.so and libva-x11.so addressed with earlier commit. There's no point in waiting for things to break wrt libva-drm.so so pre-emptively, switch to dlopen()-ing the library. Cc: Mark Thompson Signed-off-by: Emil Velikov --- configure | 2 +- libavutil/hwcontext_vaapi.c | 48 +++++++++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/configure b/configure index ab2a29544c..3d0fe0df61 100755 --- a/configure +++ b/configure @@ -3816,7 +3816,7 @@ swscale_suggest="libm stdatomic" avcodec_extralibs="pthreads_extralibs iconv_extralibs dxva2_extralibs" avfilter_extralibs="pthreads_extralibs" -avutil_extralibs="d3d11va_extralibs nanosleep_extralibs pthreads_extralibs vaapi_drm_extralibs vdpau_x11_extralibs" +avutil_extralibs="d3d11va_extralibs nanosleep_extralibs pthreads_extralibs vdpau_x11_extralibs" # programs ffmpeg_deps="avcodec avfilter avformat" diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c index e44d324928..7734a50fc0 100644 --- a/libavutil/hwcontext_vaapi.c +++ b/libavutil/hwcontext_vaapi.c @@ -31,6 +31,8 @@ #endif #if HAVE_VAAPI_DRM # include +# include +# define VA_DRM_LIB "libva-drm.so" VA_ABI #endif #if CONFIG_LIBDRM @@ -66,6 +68,7 @@ typedef struct VAAPIDevicePriv { Display *x11_display; #endif + void *libva_drm; int drm_fd; } VAAPIDevicePriv; @@ -1582,6 +1585,8 @@ static void vaapi_device_free(AVHWDeviceContext *ctx) if (priv->drm_fd >= 0) close(priv->drm_fd); + if (priv->libva_drm) + dlclose(priv->libva_drm); av_freep(&priv); } @@ -1665,6 +1670,8 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, const char *device, #if HAVE_VAAPI_DRM while (!display && try_drm) { + VADisplay (*GetDisplayDRM)(int fd); + // 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. @@ -1722,8 +1729,26 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, const char *device, break; } - display = vaGetDisplayDRM(priv->drm_fd); + priv->libva_drm = dlopen(VA_DRM_LIB, RTLD_NOW | RTLD_LOCAL); + if (!priv->libva_drm) { + av_log(ctx, AV_LOG_ERROR, "Cannot open %s library %s.\n", + VA_DRM_LIB, dlerror()); + return AVERROR_UNKNOWN; + } + + GetDisplayDRM = dlsym(priv->libva_drm, "vaGetDisplayDRM"); + if (!GetDisplayDRM) { + av_log(ctx, AV_LOG_ERROR, "Cannot retrieve %s entrypoint %s.\n", + "vaGetDisplayDRM", dlerror()); + // Always dlclose after the dlerror(). The former can alter the + // error string returned by the latter. + dlclose(priv->libva_drm); + return AVERROR_UNKNOWN; + } + + display = GetDisplayDRM(priv->drm_fd); if (!display) { + dlclose(priv->libva_drm); av_log(ctx, AV_LOG_VERBOSE, "Cannot open a VA display " "from DRM device %s.\n", device); return AVERROR_EXTERNAL; @@ -1811,6 +1836,7 @@ static int vaapi_device_derive(AVHWDeviceContext *ctx, #if HAVE_VAAPI_DRM if (src_ctx->type == AV_HWDEVICE_TYPE_DRM) { AVDRMDeviceContext *src_hwctx = src_ctx->hwctx; + VADisplay (*GetDisplayDRM)(int fd); VADisplay *display; VAAPIDevicePriv *priv; int fd; @@ -1879,8 +1905,26 @@ static int vaapi_device_derive(AVHWDeviceContext *ctx, ctx->user_opaque = priv; ctx->free = &vaapi_device_free; - display = vaGetDisplayDRM(fd); + priv->libva_drm = dlopen(VA_DRM_LIB, RTLD_NOW | RTLD_LOCAL); + if (!priv->libva_drm) { + av_log(ctx, AV_LOG_ERROR, "Cannot open %s library %s.\n", + VA_DRM_LIB, dlerror()); + return AVERROR_UNKNOWN; + } + + GetDisplayDRM = dlsym(priv->libva_drm, "vaGetDisplayDRM"); + if (!GetDisplayDRM) { + av_log(ctx, AV_LOG_ERROR, "Cannot retrieve %s entrypoint %s.\n", + "vaGetDisplayDRM", dlerror()); + // Always dlclose after the dlerror(). The former can alter the + // error string returned by the latter. + dlclose(priv->libva_drm); + return AVERROR_UNKNOWN; + } + + display = GetDisplayDRM(fd); if (!display) { + dlclose(priv->libva_drm); av_log(ctx, AV_LOG_ERROR, "Failed to open a VA display from " "DRM device.\n"); return AVERROR(EIO);