From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 5245C43BA7 for ; Wed, 20 Jul 2022 10:57:15 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1760668B60C; Wed, 20 Jul 2022 13:56:58 +0300 (EEST) Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2281268B4F7 for ; Wed, 20 Jul 2022 13:56:50 +0300 (EEST) Received: by mail-wr1-f43.google.com with SMTP id e15so20330349wro.5 for ; Wed, 20 Jul 2022 03:56:50 -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=bqK6p0//qMjA9pkodzGvMtaZoaxnfbcQdoanKEv4cag=; b=alaWtdAw9lI+NBiFmGjnxGWA7wy3BeMhNtvTEuXp4hDZXrz5oXuZhuua++8WRRbpKA tukzv8AGjh8YGx0tLJbh01JKiVAlaIIUxDuOGn2B8Lf2vTIZYH7RJgKu0law3jnhWGRO rEOVsWtDMZRZXMGnVAKnBi+H+Graq08QUaCNuUL/ykAYmlC47i9v8dR4uMWgrsnk+U8N sbFTGl5a2em2NbwMb7HMEGv/DgVrTqJTaB/zu30x+QDx0uBX1qGdws2rtigEIK3hrBYJ YcI3iYPtGzdNHzGntEUDcBZi5LV+voWUJy/LQMEi+1IQjPfB6/L8A43xY8jlWXYPVNt1 NEoQ== 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=bqK6p0//qMjA9pkodzGvMtaZoaxnfbcQdoanKEv4cag=; b=6cSrz9sD6SMqhwyHP2Xjht2yRwm08wMTLGLvfLhiFRQYc646iVFAFhW95R3Mb/QQU+ eIHXyBtjKbQqa8sVnFkgZaYxYGLMJcU0PmPh7qbkkurLppjcqzu/rKVnBkiHy+xiRPga fmW903NM5jXETwMLNAIDw3Ok4jGTsx5bZJb+NQ8rUmV06WI1jo8mIV1BMZhY/FG9aozG UXRWxzlyhHhGcN8Mf//V3UMm/esHsB9w6w4cS3Mk4wmjfq5RWPU/M4n9DePsP3WV3d46 u4MxiNCpfBmIE9yK/klET2hWxtFM384MP8cbQVCLEbY2hZRGkmoUrAFizZC8YVLnIjco d2vg== X-Gm-Message-State: AJIora8mkparD1lLtBugSzptHnMAqa1M6L5NrawSNr2f1NsWtcWWNxeW nkS3ni7RwqFhH6uhCL1OdZYjRagE88MgKg== X-Google-Smtp-Source: AGRyM1uU8GaoA2eMUDWIq9LCgsp4X5jc8ttYt9blYwT5HyTASCuFlFSo9Y2++xPsu8CCc1mw3HlT0g== X-Received: by 2002:a5d:6391:0:b0:21e:4d6c:5e28 with SMTP id p17-20020a5d6391000000b0021e4d6c5e28mr985610wru.575.1658314609217; Wed, 20 Jul 2022 03:56:49 -0700 (PDT) Received: from localhost ([2a00:5f00:102:0:a792:c012:897f:7da6]) by smtp.gmail.com with UTF8SMTPSA id v130-20020a1cac88000000b003a03be171b1sm2079205wme.43.2022.07.20.03.56.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 20 Jul 2022 03:56:48 -0700 (PDT) From: Emil Velikov To: ffmpeg-devel@ffmpeg.org Date: Wed, 20 Jul 2022 11:56:45 +0100 Message-Id: <20220720105646.716398-3-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220720105646.716398-1-emil.l.velikov@gmail.com> References: <20220720105646.716398-1-emil.l.velikov@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 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 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: 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. Signed-off-by: Emil Velikov --- v2: rebase against the libdl fixup --- configure | 2 +- libavutil/hwcontext_vaapi.c | 48 +++++++++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/configure b/configure index 605afd58a7..a941d4b927 100755 --- a/configure +++ b/configure @@ -3817,7 +3817,7 @@ swscale_suggest="libm stdatomic" avcodec_extralibs="pthreads_extralibs iconv_extralibs dxva2_extralibs" avfilter_extralibs="pthreads_extralibs" avutil_deps="libdl" -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); -- 2.37.0 _______________________________________________ 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".