@@ -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"
@@ -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 <va/va_x11.h>
+# include <dlfcn.h>
+# define VA_X11_LIB "libva-x11.so" VA_ABI
#endif
#if HAVE_VAAPI_DRM
# include <va/va_drm.h>
@@ -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;