From patchwork Tue Jul 19 16:56:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 36843 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp1878528pzb; Tue, 19 Jul 2022 09:56:17 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uRIYuYSxVmAryZWUO7ojqCP7Q09a5veREVTqlbuipaLkq7rcY0PWJoL11dMhXYSS2HZ5+p X-Received: by 2002:a17:907:28ca:b0:72b:110a:b34e with SMTP id en10-20020a17090728ca00b0072b110ab34emr31591528ejc.113.1658249776815; Tue, 19 Jul 2022 09:56:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658249776; cv=none; d=google.com; s=arc-20160816; b=dfQPvakrnVM0PgtMW4srof0m6E4MTunkS+UMRHErHLm4haRNh3PJqkbi208L4POmUe /EU3RxlEj2WiNr0/AbMBd0/mVtC5evnEhuJrxqtPL7n6spW/iCnOp8pQcp41Nnr25ezA m/gDpEt306K39NHJWauU1FdBzi8MGBNkznaLUpAemytLC8MrGCYzn9sBE9s6//k/+upb di10fYkRMrjwxxqwD0AbGwGdnjb4mzXJRvahtToc9HjtW8cL54Mf+HzJESioU1WaqZEe dKZQw85rYwU12UhkL6TKhFCHalpcL4/TiOX1PnJlutO894XFupRqVyHbIcAK155UvEPW xvAQ== 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=gZmEDcMCHy2NxZPiz/Mgi3+0eSBH69TTg4TZPbejbh4=; b=J4VJRgeyxQmpluTnXtbaFAQgg91JH1YuRGSLB0KZ3mRThjTsibq8iNtjmJJU5ov0iT kENhzbS/QG3Q2BNQ82s8en32hF5nOIti4Fk1ybRpFjgcz0uXEvO9Gc4hD2ZLuhsyM+a8 ozhrpcuQVgU+v2lbZty+XLyl/uhhRj7+d941R62XtTNhPdOqoZh6GJ6wHzw8iT6jmqXZ CxxNPJzxapYPxKOU36/Ji/yFcr79ibRjZxjYs+VOj9TvoBLjAp/fnGWazcn3bOLa5jOM HjGthX+OFNAFf22qXeq7VgTlmOycF7+vZHNZKXSrFravTnN5FZTh9/YGfZPCVzGpKJt8 gNeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=MxFBMVo9; 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 l24-20020a170907915800b00711d89b830asi15942727ejs.819.2022.07.19.09.56.16; Tue, 19 Jul 2022 09:56:16 -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=MxFBMVo9; 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 D561F68B44A; Tue, 19 Jul 2022 19:56:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7976E68A467 for ; Tue, 19 Jul 2022 19:56:06 +0300 (EEST) Received: by mail-wm1-f50.google.com with SMTP id p26-20020a1c545a000000b003a2fb7c1274so7788851wmi.1 for ; Tue, 19 Jul 2022 09:56:06 -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:mime-version :content-transfer-encoding; bh=YITKel03Snormo2Fa/J70IbQzMTC/5cw4tARiiJyb8s=; b=MxFBMVo9O6np8214hCs66N0ah5CO9LpxDlHv8nv7zesWUa2bcLLmuuRLW+m+sNnsKL c2FqZK3bArD0y5mnoQ3iu3dlnpHGy1b1Nm0WO1MQF0wfmu0yR3T87piIZ49LfhC+I2It +SYBY0jxxTeZbEuXg7r6O6BE5AFku4HXMWiw8lbn2pc2uGWgWyt+JB9ERsAt7FCvy64w iUaZdyQH6fWqRyKjwFRfnHjxKXGUBAd0ZvtIWqoraGSYDAiSeCJs3C8ZtnDS3RXVR0SY MJIvV4GgceeTB8XASy/QNmg16CRVuyhPOXAwXMWNyWHYALx19vdOjeRFnDlK9/yI4VJ7 +MoQ== 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:mime-version :content-transfer-encoding; bh=YITKel03Snormo2Fa/J70IbQzMTC/5cw4tARiiJyb8s=; b=LL7aLmvX51/p0aPgk1e4G4b3bDGsgIqPF3Uegm/Ci7HtUoHymZbblAvL5YiCW/Mgcs Zb2MUJ0Cm5SC+OJfY7Oo31Gq5yFumUcFkg2vQ7CTSX9VbXxKb0s2oIJ6NNwYmttCEnAb KUj9C+QCJ3ocCO/8bqZEqwhQlYIxKECOh5uDG7Rj+SkD+cCmJgivpPgqj57+QgGlNkxR fiigs8FbAqoTAB7iGa3p9qZhKBysSUz45PjO+nKkkNlk9y+uLs4TNcUAf/98H6NvbVYu AggrM7BwXzvjYYnXOy5p7o35VHkJPl+3TpXPbdK8htfiiy2GOJXVc3M30r+AY301RUHk jfvQ== X-Gm-Message-State: AJIora8v7xhZWqSGH/VtbLlc+dOmIFWDnY5nb2mIB2A17BZrk80MOwmp WFeMVjV6FiKEN457g2cLExwioB5R7NyL6Q== X-Received: by 2002:a05:600c:3845:b0:3a3:227d:c1c6 with SMTP id s5-20020a05600c384500b003a3227dc1c6mr226619wmr.9.1658249765597; Tue, 19 Jul 2022 09:56:05 -0700 (PDT) Received: from localhost ([2a00:5f00:102:0:ed02:7072:7dbf:2431]) by smtp.gmail.com with UTF8SMTPSA id n11-20020a05600c294b00b003a325bd8517sm2389553wmd.5.2022.07.19.09.56.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 19 Jul 2022 09:56:05 -0700 (PDT) From: Emil Velikov To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Jul 2022 17:56:02 +0100 Message-Id: <20220719165604.640770-1-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.37.0 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: 6bgMyJNzQSpz 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: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); From patchwork Tue Jul 19 16:56:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 36845 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp1878710pzb; Tue, 19 Jul 2022 09:56:37 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vmLmXg0lqaHiGuXbGnEZSpWZTok6eiEo9qhOZqQpSNDmI/amHPGmNB2mIVGdMpeRrTV2uG X-Received: by 2002:a05:6402:5cb:b0:434:eb48:754f with SMTP id n11-20020a05640205cb00b00434eb48754fmr45659452edx.421.1658249796896; Tue, 19 Jul 2022 09:56:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658249796; cv=none; d=google.com; s=arc-20160816; b=Q6s4LIeP8aQ6FSUaIc2sZaH719HR99Rf0pDKl4JUeF26hbZB+cJ2DftlUTOouTyfkW 9c5TLyQ+aqgTHkD8YY9Jk4wIhC278WPXuMRT9C6fFbEihrkn07poKONypxaSKsGPGnRs jd57t6m39cTZ40ruNxJgNtELYXNT+u6Kj8WzyvXeGGRoMCKDs17OWHW6g3Mz69h5FYGw xBqx8kEFRZH0RUEEVaf/GwEUeAjM8Vu9IevnkjbIvLWdIAPwFcuef8g+LVg4nt6u9omN aIr44ppFAgjEAzQ2gJSmhJGL/tsLJrIJMb01TDRBKC2q3yGMYqWwH8Cl3fBn9SjS7uEZ iq5Q== 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=pREn6wz1JsIzO6V7jqNqUZDVx6d0A8DHIpLzfUax+3wHJTl1Q7pmJaurH21llz88/I Ir7VIfdY+lCUbCc3iYoztiHOjjyXbWwjPjlT+dK8vXe8JFGN157Ag7UK4gU0N7EcvwW1 c578B+7JVh5bYZ/7CgAaX1VThjp3PQKx5p423ZJyL+sktzlcHvuXudqZ74ftLxE3jqT2 ezmZvbAwjpE9lc6nc6DEWUJ6swWSMckUt6dNBgzWMLeCO9Rg7+Eco/iUKObezPoqk4tS iw35LYxg9D4o6ICXxZXvzcXaJ627qqNwaZae/dLIGy5/WBewN6W77Tlpax8e8t43SZ1Y qHlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="egocP9F/"; 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 j25-20020a170906095900b00722e3529906si17233103ejd.324.2022.07.19.09.56.35; Tue, 19 Jul 2022 09:56:36 -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="egocP9F/"; 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 D14C968B63E; Tue, 19 Jul 2022 19:56:15 +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 5A39D68B61E for ; Tue, 19 Jul 2022 19:56:08 +0300 (EEST) Received: by mail-wr1-f49.google.com with SMTP id z12so22526065wrq.7 for ; Tue, 19 Jul 2022 09:56:08 -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=egocP9F/Izh4YVy073jGJp1oklDIvEixM1f/XQZtEXSRZgP5A79UOpdoD2I3Zc2hJj UPeGm8lTsWXZd1h1BpU5dkPR8DaWt45vClYnOSUOR/H0MEyaJdRddVtNtxDIGcC9+Yz4 vWJnd51Hz4PW025skC4emgC0+psOXDXcgz4nC6HltesA3whl6adeezXpMFvLPDmsgC3u UD5/gZL0fTZKfLdjr3lOhis7074ZdshyIxRYCEy8/av/R0n501TK0JmICYngKajG4xFH Dq2/4jq+OcvhxkwzXE8msr20mcpEQ56efJHazLVyD5KhVFB1s6pHunSFMJU6980f6hGp Dk5g== 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=x8hVgbgXsT2yhCp/Z2/BPoTTqvBEOZD2ztDT4L4bW8cxTTOp8u5bfu+MAv4xOWkqBI zveZbE8n1O36tHPqkO7bq/ouuLtPrPahl9FwUaCzBWu01/FGcACFSK+JhqZdkuQ5+prW /ciPS8H11uxzOmqNMsyyFcpl8Ys5Ro9G2zJK4P7T4U5NH3DJEfd5y0zzbxZtbOzC6fkm Chv9YuY2edzXJ7523SWHJAXn1yWpwN4YgSU+Kkc3Md0FUGncrFrH7f/wGs+o/SEJe+69 lDgt3/vOwzub6kgdFwUUq1yqAzHG0X8BTD0I7UOoZ+/1Ed7AavNCrNRyEZ9FSoWvUh7O LlXQ== X-Gm-Message-State: AJIora/9l9Kz1nslk02NeV+v2qR5rB3CgnzE9dGgoQWtXZVB2FkBHtQb mfU7/9OI7aMamkD1i55zAYmX+dSADor0vw== X-Received: by 2002:a05:6000:1686:b0:21d:6e46:2fa with SMTP id y6-20020a056000168600b0021d6e4602famr27307613wrd.691.1658249767413; Tue, 19 Jul 2022 09:56:07 -0700 (PDT) Received: from localhost ([2a00:5f00:102:0:ed02:7072:7dbf:2431]) by smtp.gmail.com with UTF8SMTPSA id p17-20020adff211000000b0021d9207e6f1sm13699055wro.34.2022.07.19.09.56.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 19 Jul 2022 09:56:07 -0700 (PDT) From: Emil Velikov To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Jul 2022 17:56:04 +0100 Message-Id: <20220719165604.640770-3-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 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: /3YvIK7rixvY 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;