From patchwork Tue Jul 19 16:56:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 36846 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp1878989pzb; Tue, 19 Jul 2022 09:57:11 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vYPwF56FdZSbAEzruMZCoZXEv4Wl0gQRq3Tb7T1AnZaCU/8M2WXGtXHRIAd2N5nKBE3yJZ X-Received: by 2002:a05:6402:11c7:b0:43a:c61c:21cd with SMTP id j7-20020a05640211c700b0043ac61c21cdmr44833297edw.108.1658249831139; Tue, 19 Jul 2022 09:57:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658249831; cv=none; d=google.com; s=arc-20160816; b=yPYjIaAkZEranY8Y/lDiDK7YMpuoFmlyMoNXjPd8+kYY5wzsRhCqrsWK9LM3ap4Pqb 0CjeSkcjrv/B1xUZ/yQUBWJAO3hHS+DFm1lO+Rd10X5LPxM5885+QW0hcIvyz1Phr96X zm5mE4YBpdwIwZ3RLP6+WGkbW/WTa8dNnrC+FmrDikXGH4pJEAlW7R48IBQv6Mv+Btys ORkVY+CP8zaQzRBkkI7hTrB7c/7PCS8EQ9opPbH+hAzNql73+DJA7al2pCskWeCGmTFn AktDqZ8yux8qxCBmBVlqbmhIhnbiq/z4fv824gWx2zK7DGB3bdEnY8eU80FgwMMmCiEO u1gA== 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=gZmEDcMCHy2NxZPiz/Mgi3+0eSBH69TTg4TZPbejbh4=; b=c8u/IttOoZ9Z11fmClj8XBRjkmxVo23sUDrCh1tRNp+jCdDsREDIWKhT3l066arXUA NX1nfQ5jZN8uDeGCxGGfp+h2/g1WxHkq8awn2RwPCBn04pLj4aKU5JCEqS/1bV6sdQ6Q 3Tt8TuMNidVJLDPM9bwnZCuYsecUP9cbNMv7Wuj3LQG+7vFL/hRym7KlWU3q1vCePD8o hgbDPUHvJgznvaX0laJ9owRA6rebrSgNZnSog1UOKy4MFDE/cKS3jk9sbp9qVK0qMcw5 PCg4cpT3lZjgyA2zB26omVdbno18npEms3iaRlv5Xzfbgjwl1ZFxCSv7+FyCFBSSwNt8 1FMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=cEK4Bhjn; 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 e19-20020a50d4d3000000b0043a0e3729f1si16858614edj.493.2022.07.19.09.57.10; Tue, 19 Jul 2022 09:57:11 -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=cEK4Bhjn; 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 EE94068B6F3; Tue, 19 Jul 2022 19:56:59 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6C6FC68B64E for ; Tue, 19 Jul 2022 19:56:58 +0300 (EEST) Received: by mail-wr1-f49.google.com with SMTP id j1so18058254wrs.4 for ; Tue, 19 Jul 2022 09:56:58 -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=YITKel03Snormo2Fa/J70IbQzMTC/5cw4tARiiJyb8s=; b=cEK4BhjnRncQYLOx4sa7Ci1jT/oxt1rCFwNj0eFn4I1IDcOphZZ6FsQeg0ozMyV93l FnbVc/i7QtFHw+kj6HMG6m1cfkKUmnGi67m7XTyVp5nczsGi69dC7za9ORx2yGszJWAA 63sDukuZ4RC5qyUl6kXT/XnSnUWvggl7YAagtK03DgwkB4jpqe5Sz0Od9rnHmdAJCOeS eLFSd3ijGw3tEcDtjpKU+Il2WD706KklEPjzb0liyMfhP+qS0Wv+TKqkIf0SEUli1OIO OONslAwHHnSL4kKPzZH8LBVzb9fuQQhe2YfGv1U7Hkm3xO3VedzkFEaWibJXxm/SKmv8 LPrw== 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=YITKel03Snormo2Fa/J70IbQzMTC/5cw4tARiiJyb8s=; b=WxY41Btkf8YlGKvqOok0PlNQBNyr2w8bC9/pdE1GAtxzylqgA+q3Ls4TYl/yflljKB 4XN7unfgFBXM34xCIwWKzWQ8CtqUQtHUUCOdcGlhVTrBzktzu09b+HnFTj71689i1KOZ rJwkr5iEr76kK5uhc5OkPseJ2Rkf8rkTp2krp3IXhum259bV8d5WtWvjEFGRT1QqTawE Jag93k7jK75kswu3WRYoRA3TJoYaPYz9zozre2le6DyCc5+NZ+yx8Jiw8v8PWMCzSuk+ IJ9NddEM078wLbd0uSxYIx1CQQriuFcs8is2uWe9/vfTVZxYoHf6uNkdcoqFHDfz08lj NTIw== X-Gm-Message-State: AJIora9zi1J2pQYMfnODpfN+C9ygs7mq17d1BRu/Ok2CuhYNtQlM+Svw D5oOtepJbSGMURatX1BE4Uc/OdZVtd7taQ== X-Received: by 2002:adf:b613:0:b0:21d:6da6:d541 with SMTP id f19-20020adfb613000000b0021d6da6d541mr26938158wre.485.1658249817675; Tue, 19 Jul 2022 09:56:57 -0700 (PDT) Received: from localhost ([2a00:5f00:102:0:ed02:7072:7dbf:2431]) by smtp.gmail.com with UTF8SMTPSA id h4-20020a1c2104000000b00397402ae674sm23169629wmh.11.2022.07.19.09.56.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 19 Jul 2022 09:56:57 -0700 (PDT) From: Emil Velikov To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Jul 2022 17:56:54 +0100 Message-Id: <20220719165656.640869-2-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220719165656.640869-1-emil.l.velikov@gmail.com> References: <20220719165656.640869-1-emil.l.velikov@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] hwcontext_vaapi: do not link against libva-x11.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: WiaQu/1ENH// From: Emil Velikov There is an internal ABI between libva.so the libva-XXX.so libraries. With a recent change, the internal va_fool API was removed breaking the ABI. So if libva.so and libva-x11.so are from different version, the whole stack will crash. Instead we can dlopen() the libva-x11 library and gracefully error out. Cc: Mark Thompson Signed-off-by: Emil Velikov --- Greetings team, please consider backporting this for the stable releases. I've noticed that we've got plenty of pre-existing memory and state leaks in vaapi_device_create(). Would it make sense to fix those up? If so I can follow-up with a patch. --- configure | 2 +- libavutil/hwcontext_vaapi.c | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/configure b/configure index 18d9b61a99..ab2a29544c 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 vaapi_x11_extralibs vdpau_x11_extralibs" +avutil_extralibs="d3d11va_extralibs nanosleep_extralibs pthreads_extralibs vaapi_drm_extralibs vdpau_x11_extralibs" # programs ffmpeg_deps="avcodec avfilter avformat" diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c index c3a98bc4b1..e44d324928 100644 --- a/libavutil/hwcontext_vaapi.c +++ b/libavutil/hwcontext_vaapi.c @@ -18,8 +18,16 @@ #include "config.h" +#if CONFIG_VAAPI_1 +# define VA_ABI ".2" +#else +# define VA_ABI ".1" +#endif + #if HAVE_VAAPI_X11 # include +# include +# define VA_X11_LIB "libva-x11.so" VA_ABI #endif #if HAVE_VAAPI_DRM # include @@ -54,6 +62,7 @@ typedef struct VAAPIDevicePriv { #if HAVE_VAAPI_X11 + void *libva_x11; Display *x11_display; #endif @@ -1565,6 +1574,8 @@ static void vaapi_device_free(AVHWDeviceContext *ctx) vaTerminate(hwctx->display); #if HAVE_VAAPI_X11 + if (priv->libva_x11) + dlclose(priv->libva_x11); if (priv->x11_display) XCloseDisplay(priv->x11_display); #endif @@ -1723,14 +1734,35 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, const char *device, #if HAVE_VAAPI_X11 if (!display && try_x11) { + VADisplay (*GetDisplay)(Display *dpy); + + priv->libva_x11 = dlopen(VA_X11_LIB, RTLD_NOW | RTLD_LOCAL); + if (!priv->libva_x11) { + av_log(ctx, AV_LOG_ERROR, "Cannot open %s library %s.\n", + VA_X11_LIB, dlerror()); + return AVERROR_UNKNOWN; + } + + GetDisplay = dlsym(priv->libva_x11, "vaGetDisplay"); + if (!GetDisplay) { + av_log(ctx, AV_LOG_ERROR, "Cannot retrieve %s entrypoint %s.\n", + "vaGetDisplay", dlerror()); + // Always dlclose after the dlerror(). The former can alter the + // error string returned by the latter. + dlclose(priv->libva_x11); + return AVERROR_UNKNOWN; + } + // Try to open the device as an X11 display. priv->x11_display = XOpenDisplay(device); if (!priv->x11_display) { + dlclose(priv->libva_x11); av_log(ctx, AV_LOG_VERBOSE, "Cannot open X11 display " "%s.\n", XDisplayName(device)); } else { - display = vaGetDisplay(priv->x11_display); + display = GetDisplay(priv->x11_display); if (!display) { + dlclose(priv->libva_x11); av_log(ctx, AV_LOG_ERROR, "Cannot open a VA display " "from X11 display %s.\n", XDisplayName(device)); return AVERROR_UNKNOWN; From patchwork Tue Jul 19 16:56:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 36847 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp1879222pzb; Tue, 19 Jul 2022 09:57:21 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vebQI42QvopsyZa1BllxVie5rffKnU10uKyV6Xkw3eGJ37TQk9CtU1htF/1oJ/5BszwLoh X-Received: by 2002:a05:6402:51ca:b0:43a:df65:d180 with SMTP id r10-20020a05640251ca00b0043adf65d180mr45463672edd.255.1658249841591; Tue, 19 Jul 2022 09:57:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658249841; cv=none; d=google.com; s=arc-20160816; b=Sq+ldsQuBfVAuyGvIGFQ9VF32YZHRf6X8QiPResbkviMpyMuIk9oAFuzee5+JFDnLZ GZkmSBu2r2hegFYap4i3fdWFWAx/B4xfOykL8cdr8Otcl9vWgIER4Y+Aq208PMhD9Dwf IK1LPnXmdQn1gnzhJtrQYlW+oYGFrIAif7naKWpAq2Bqzu+t6CKjzMGHwIU7cH9PJcAs PGH21h8l34ITOTD1cRRBLxV+oEoFdLDfhMsHvBKFA+TMwVwtDM23R2XDqv43okCv6sfB iclNlkHCzF2GiFJWRdngkjO03MQ+Fo04nUICST3OTIuCKgxLQbJFen3n+OIkyPUYS94g hyhw== 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=DOYkFTqoYBY4qsKb/dTnHOXrh8Y4MqrSDiFPaeUztTONVjPS2i1/K7j5Qyvy6hYqmA AQzI0gUvFX0wddiuduQzohyGFchWzNtAnlAf/npbqC1c3yM8FqIMKgpOBdQltfHtaZas AXUk6zTc49raGdehWZdL636spQaq8wehdihh8MeJJOGAdPWuByzDuzOa793rpZd6PLBD 6uu9PYBbWDm7ZCoey+xbKdAz9UXxzlitxGWDLXh4UllKHm9u3Hl7BABkOjQlQNsq4swL Yi6hanTDzfECQIVzv6ZAOljBytuR1jplkyak5G98UTdIp+lIT/TBas5i9AKZbgNLa6Mo IbEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=qOtjut9G; 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 u4-20020a50eac4000000b0043a1b0e9663si17905554edp.336.2022.07.19.09.57.20; Tue, 19 Jul 2022 09:57:21 -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=qOtjut9G; 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 DF8D868B701; Tue, 19 Jul 2022 19:57:01 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A702A68B697 for ; Tue, 19 Jul 2022 19:56:59 +0300 (EEST) Received: by mail-wr1-f45.google.com with SMTP id e15so17267591wro.5 for ; Tue, 19 Jul 2022 09:56:59 -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=qOtjut9GWaNc67jdNdIaCbBxuJ9ATvjjaqriKcwFZYvWDe1RSQcwpIhabzvPe/UDxU ucHK47MRkacSEton4H93NRoqdwN8hTOms/5DKlwbaPswuEV7qEtBGpTdI/qsRuAoXOnI PpskjlGlF6TNYkX7TjvkgswZk9uOKICBYDiHKUqgctlgkfrpecLVbWS2/dX5xFQDqXrH wwM38+je7ZHLA5x6dlGvJD1cXsexkk5tHkEABHT1Nt7OmltR96BGcOY53hI8ed+e8HOU CezxE2DVRH0ODM3IwgyFFvbsiAb65K49hFd9/2fyiAJyWEKS4N/Rl3Hk6F7345CtLwcW qHUA== 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=LnXDoyuiUKBW6Yi/2tcgheCC8CijREJDpFB3uL4nd46IZosFshzgqrYFQ0VgaqnFTP OWkuC4AHX6D3VHmIqaBsgfdtbOJFqCz9Ca7AM9cF0fs07Q8FHZ0PZQV2gGVPQQ8c9BVM xNUrT+mwug2Grg6BZitIqtISOTGUS1hot+AzgRO0NmzxuRCesal9uZwOju8FG0B46yjp zeA0RKJMhKfWEBnA7DFiCAJTrQYn6mjyUxUWua5KzpllEoVIiprl4QTi647qwR/l/GPy 3CHDbuhYm14YkRmJXmi1ZKChR01bpjs8gLQdlXEswybcpCTiJuhrO6Uv9IOmfCLhOviu xsTQ== X-Gm-Message-State: AJIora/mxYESPUkjQn+jTiJdQm+te7+S1Yw0GTH4ZXYXQx9ek4IpN6sJ GXr00UoPcT3rR+poaF5Mr2zrmuDOsW8vKg== X-Received: by 2002:adf:f20a:0:b0:21e:2608:9390 with SMTP id p10-20020adff20a000000b0021e26089390mr7175341wro.577.1658249818510; Tue, 19 Jul 2022 09:56:58 -0700 (PDT) Received: from localhost ([2a00:5f00:102:0:ed02:7072:7dbf:2431]) by smtp.gmail.com with UTF8SMTPSA id l13-20020a05600c2ccd00b003a2f2bb72d5sm26984593wmc.45.2022.07.19.09.56.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 19 Jul 2022 09:56:58 -0700 (PDT) From: Emil Velikov To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Jul 2022 17:56:55 +0100 Message-Id: <20220719165656.640869-3-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220719165656.640869-1-emil.l.velikov@gmail.com> References: <20220719165656.640869-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: tYxxgJDE2EW/ 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); From patchwork Tue Jul 19 16:56:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 36848 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp1879340pzb; Tue, 19 Jul 2022 09:57:32 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uCtbx2JocnyIkDXLDrQSeloC6iYHOq8pvUcAPnF/xijigLEXlDIzrwyiaSE0nWnDj4I5vn X-Received: by 2002:a17:906:6a0a:b0:72b:60b8:d2e7 with SMTP id qw10-20020a1709066a0a00b0072b60b8d2e7mr29900184ejc.607.1658249852520; Tue, 19 Jul 2022 09:57:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658249852; cv=none; d=google.com; s=arc-20160816; b=qIFuylLjbSignU+66LIxKegX0DsJColcMZk2lmY5ytkebf5PbBR3/p37lktxnqVrmu UlLKTpXvCVuYeUG4HG2pUbU0bLA7SXPhY4zq7r5ZTQqhFG9zxcJmfgj6vgoZ9MdO5wFw N05aCtdgOSQe1N7IBEIfasa+mcpBlJSyq2BxsBOZlobwNJ2507Aw34R8yTvpKJsSouTD +QadlfhhcImrHk1TPVa2v6XPKsd/ReHWOUv2b4gORXWgGwJ5AJw5Jvl3H4NXT4WB/ldv 0wA2gesJD5m0J9p6AXsFg3MR7RGNKFUeMsCGT7v1UPdW7zZc8u5apR9nj2TZ4Z7I34Qn 4TUA== 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=Hx+w/5BxM5r+c6606vkAnMaahesU+UJ9ZVtu1lRAkR8=; b=ONyeWjZ9LhBNBbh2sEErasi9qXfmlC7aKlskvly78JUsKAeJ5x8LQLRNLOKqKzNjqp z5010eEy71AU7/WG9E9ht6dNmSA+rKOCO+g44Q0m0Gknh7K1bXRDUIEmM2CvSMP9ZEsK 1ma8ye2NurIoDQa/D4M9QpozJ34XSxMtPPSkxsefL3QAbAGtMsbX6gu9VaaiLM/6Ps7y dz7LKe8CcxMV9nctoQo0JfGjGGg4j1d0aTtNLW0RORKQc7KSr79oZhY6CxhrDGoUpaUp PziLMptI12lDnhcGF3ArgHrvfMyuRFWwre6JPUrlG0aXZqGfzpVXzjAU8v0RKgWWrL8T viKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=c93Xtwvb; 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 dp17-20020a170906c15100b006f3d82ce68esi21216957ejc.145.2022.07.19.09.57.31; Tue, 19 Jul 2022 09:57:32 -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=c93Xtwvb; 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 E482D68B70E; Tue, 19 Jul 2022 19:57:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 67B8668B6F9 for ; Tue, 19 Jul 2022 19:57:00 +0300 (EEST) Received: by mail-wm1-f43.google.com with SMTP id ay11-20020a05600c1e0b00b003a3013da120so10408352wmb.5 for ; Tue, 19 Jul 2022 09:57:00 -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=D+cwfkj3FyHmCse3ahY4CIezdr+uKa0BE8y8V5Ed0kU=; b=c93XtwvbFR3frUnB7G872F+OHOIQdeciuCzUV2sYLHkeuo8dqxHt7nQY5+pS8JM8fR lriVXecSnXiuigWSjTeQphIuyhnSyNNum8PmdtPqjdPoahZP8O/64OlpieQQIyd7GOfP T+aTbyEw5VlSnO94mliF+3AiFxuZuuNnVZFlOsXKPtvBd3nadBgBMX4CaiK9NcDshQMi SiKgvzaMTISDFj8bvq1Y9xwOFBUSHXLKYJzGFnqJRQHVozHxFQNkMhVL9XifF4JARd68 hhtoKvmy+LNyHZZbmfBtNMU1Wbtj1Gp+6E7j0rHsqu8qGrAIdoAy13Th4XB+tBzxwPv3 EXqA== 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=D+cwfkj3FyHmCse3ahY4CIezdr+uKa0BE8y8V5Ed0kU=; b=nASgIM4Jd3n7nplK/QdFdZsOTYb0KKop0Dl9gZ5WhXU+X2pSfMrR5ozHvYIXg4NViE SPOba/NUmaTJP7WZb72XtSHuc47TXlR0HI1Jvnq/9LK439ORL94gApw/i+QUKBq9pffr FEwVWvUmIhk7zUakveqsaeFiHY+XlZXkW7HeOvoNrO7cq/if7O2UbayTl8yaOSQR2wq1 6Nz7oBQDT/A86WdGO/kF6r0DLlFioVyPzaXlJzYAHPP0zkuAcGKHm/QPAH7IHVzajdLn nmWc7G38hpPHKqLomEK225XmEhwrfSPEzAShRkqqIEbYdLM69ZKIcHQSK64Ts5PY/yOx cwjA== X-Gm-Message-State: AJIora+qSdZ7wcbM7mevTX35r60A6SYZ78kgT0gqdn+9+bboadhF+v7Y BDA9wCWUPNlpDMgeU1zzq72iE9uPG5Y6Cw== X-Received: by 2002:a05:600c:3b91:b0:3a3:1cbe:d531 with SMTP id n17-20020a05600c3b9100b003a31cbed531mr202266wms.159.1658249819434; Tue, 19 Jul 2022 09:56:59 -0700 (PDT) Received: from localhost ([2a00:5f00:102:0:ed02:7072:7dbf:2431]) by smtp.gmail.com with UTF8SMTPSA id bd20-20020a05600c1f1400b003a3211112f8sm3833068wmb.46.2022.07.19.09.56.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 19 Jul 2022 09:56:59 -0700 (PDT) From: Emil Velikov To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Jul 2022 17:56:56 +0100 Message-Id: <20220719165656.640869-4-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220719165656.640869-1-emil.l.velikov@gmail.com> References: <20220719165656.640869-1-emil.l.velikov@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] hwcontext_vaapi: #if guard VAAPI_DRM specifics 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: qmNB4vGgQgS7 From: Emil Velikov Similar to the VAAPI_X11 bits, guard all the VAAPI_DRM parts behind an disabled. Cc: Mark Thompson Signed-off-by: Emil Velikov --- libavutil/hwcontext_vaapi.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c index 7734a50fc0..7aea3e7b96 100644 --- a/libavutil/hwcontext_vaapi.c +++ b/libavutil/hwcontext_vaapi.c @@ -18,6 +18,10 @@ #include "config.h" +#if !HAVE_VAAPI_X11 && !HAVE_VAAPI_DRM +#error "At least one VAAPI winsys is required X11 or DRM" +#endif + #if CONFIG_VAAPI_1 # define VA_ABI ".2" #else @@ -68,8 +72,10 @@ typedef struct VAAPIDevicePriv { Display *x11_display; #endif +#if HAVE_VAAPI_DRM void *libva_drm; int drm_fd; +#endif } VAAPIDevicePriv; typedef struct VAAPISurfaceFormat { @@ -1583,10 +1589,12 @@ static void vaapi_device_free(AVHWDeviceContext *ctx) XCloseDisplay(priv->x11_display); #endif +#if HAVE_VAAPI_DRM if (priv->drm_fd >= 0) close(priv->drm_fd); if (priv->libva_drm) dlclose(priv->libva_drm); +#endif av_freep(&priv); } @@ -1645,7 +1653,9 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, const char *device, if (!priv) return AVERROR(ENOMEM); +#if HAVE_VAAPI_DRM priv->drm_fd = -1; +#endif ctx->user_opaque = priv; ctx->free = vaapi_device_free;