Skip to content

core(libva): use dynamic loader#19562

Merged
opencv-pushbot merged 2 commits intoopencv:masterfrom
alalek:libva_dynamic
Feb 19, 2021
Merged

core(libva): use dynamic loader#19562
opencv-pushbot merged 2 commits intoopencv:masterfrom
alalek:libva_dynamic

Conversation

@alalek
Copy link
Copy Markdown
Member

@alalek alalek commented Feb 18, 2021

force_builders=Custom
Xbuild_image:Custom=centos:7
build_image:Custom=ubuntu:20.04
buildworker:Custom=linux-1,linux-4,linux-6
allow_multiple_commits=1

@mshabunin
Copy link
Copy Markdown
Contributor

Checked with this MediaStack: https://github.com/Intel-Media-SDK/MediaSDK/releases/tag/intel-mediasdk-20.5.1

Env setup
export LD_LIBRARY_PATH=/opt/intel/mediasdk-20.5.1/lib64/
export LIBVA_DRIVER_NAME=iHD
export LIBVA_DRIVERS_PATH=/opt/intel/mediasdk-20.5.1/lib64/
export PATH=/opt/intel/mediasdk-20.5.1/bin/:$PATH
Running the sample
$ ./bin/example_va_intel_va_intel_interop ../opencv/samples/data/rubberwhale1.p
ng A B
libva info: VA-API version 1.10.0
libva info: User environment variable requested driver 'iHD'
libva info: Trying to open /opt/intel/mediasdk-20.5.1/lib64//iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_10
libva info: va_openDriver() returns 0
VA display opened successfully
Interop ON : processing time, msec: 1.08985

$ ./bin/example_va_intel_va_intel_interop ../opencv/samples/data/rubberwhale1.png A B -f
libva info: VA-API version 1.10.0
libva info: User environment variable requested driver 'iHD'
libva info: Trying to open /opt/intel/mediasdk-20.5.1/lib64//iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_10
libva info: va_openDriver() returns 0
VA display opened successfully
Interop OFF: processing time, msec: 39.3298
No dependency on libva
$ objdump -p lib/libopencv_core.so | grep NEEDED
  NEEDED               libdl.so.2
  NEEDED               libpthread.so.0
  NEEDED               librt.so.1
  NEEDED               libz.so.1
  NEEDED               libstdc++.so.6
  NEEDED               libm.so.6
  NEEDED               libgcc_s.so.1
  NEEDED               libc.so.6

@mikhail-nikolskiy
Copy link
Copy Markdown
Contributor

mikhail-nikolskiy commented Feb 18, 2021

VADisplay (VAAPI context) contains v-table of all VAAPI functions. VAAPI experts confirm that v-table guarantees backward compatibility.
So all functions, except vaInitilize which creates VADisplay, could be called via v-table if include public header <va/va_backend.h>.
Here is example.

Should be safe to use v-table starting VAAPI 1.0 which dated Oct 21, 2017. Not sure if ok to support only VAAPI>=1.0 in OpenCV, or use universal dlopen()..

VA_MAJOR_VERSION >= 1

@mshabunin
Copy link
Copy Markdown
Contributor

@mikhail-nikolskiy , I think the method with vtable requires runtime libva version checks. Otherwise there can be situation when the library built with fresh libva would expect some new method exists and slightly older libva loaded in runtime would not have this field in vtable. This situation is partially handled by dlopen (older version won't load), but not with vtable. So this approach requires slightly more developer's conciousness and double version checks (in general case, not at current integration level):

#if VERSION > XX  // new_function added in XX
if (ctx->version > XX)
    ctx->new_function()
else
#endif
    cerr << "Not implemented" << endl;

We have somewhat similar code for example in OSX AVFoundation integration:

#if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
if (@available(macOS 10.14, *))
{

Currently dlopen seems more appropriate since it is compatible with both libva 1.x and 2.x with other things more or less equal.

@alalek
Copy link
Copy Markdown
Member Author

alalek commented Feb 19, 2021

@mikhail-nikolskiy Thank you for the information!

Unfortunately we still need to support configurations/platforms with old libva versions:

  • CentOS 7: 0.40.0 (by va_version.h)
  • Ubuntu 16.04: 0.39.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport is needed Label for maintainers. Authors of PR can ignore this category: build/install category: core feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants