crosvm/media/libva
Daniel Almeida 26f53eb732 media: libva: open DRM fd as O_RDWR
File::open() opens the file as O_RDONLY, which can cause issues with the
VA-API driver.

In particular for Intel hardware this will cause allocations to fail, as can
be seen in issue #1449 for intel-media-driver. These failed allocations may or
may not crash the VA-API driver, as the driver might eventually dereference a
NULL pointer.

Fix it by opening the DRM fd as O_RDWR. This is also in line with the examples
in libva-utils.

BUG=b:214478588
TEST=`cargo test --features "video-decoder,vaapi" -p devices vaapi::tests::test_get_capabilities -- --ignored` passes on AMD hardware.

Change-Id: Ie3cf2a6512157a3f23f943b54249eb2928082af9
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3782999
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-08-24 01:15:19 +00:00
..
src media: libva: open DRM fd as O_RDWR 2022-08-24 01:15:19 +00:00
bindgen.sh Reland "Add a VAAPI wrapper crate" 2022-07-13 06:51:27 +00:00
build.rs Reland "Add a VAAPI wrapper crate" 2022-07-13 06:51:27 +00:00
Cargo.toml Reland "Add a VAAPI wrapper crate" 2022-07-13 06:51:27 +00:00
libva-wrapper.h Reland "Add a VAAPI wrapper crate" 2022-07-13 06:51:27 +00:00
README.md Reland "Add a VAAPI wrapper crate" 2022-07-13 06:51:27 +00:00

Libva Rust wrapper

Rust wrapper for libva. Provides safe libva abstractions for use within Rust code using its own bindgen-generated bindings.

This crate is used as part of the VirtIO Video VA-API backend. VA-API uses the GPU to perform the actual decoding/encoding of frames. In doing so, it frees the CPU for other uses and reduces power usage in the system. Hardware accelerated media workflows also tend to be faster than their software counterparts.

Note: This create requires the native libva library at link time. It also requires a VA-API driver to be installed on the system. The VA-API driver to use depends on the underlying hardware, e.g.: the implementation for Intel hardware is in intel-media-driver, whereas AMD hardware will depend on Mesa.

An easy way to see whether everything is in order is to run the vainfo utility. This is usually packaged with libva-utils or as a standalone package in some distributions. vainfo will print the VA-API version, the driver string, and a list of supported profiles and endpoints, i.e.:

vainfo: VA-API version: 1.13 (libva 2.13.0)
vainfo: Driver version: Intel iHD driver for Intel(R) Gen Graphics - 22.2.2 ()
vainfo: Supported profile and entrypoints
      VAProfileNone                   : VAEntrypointVideoProc
      VAProfileNone                   : VAEntrypointStats
      VAProfileMPEG2Simple            : VAEntrypointVLD
      VAProfileMPEG2Simple            : VAEntrypointEncSlice
      VAProfileMPEG2Main              : VAEntrypointVLD
      VAProfileMPEG2Main              : VAEntrypointEncSlice
      VAProfileH264Main               : VAEntrypointVLD
      etc

For decoding, the desired profile must be supported under VAEntrypointVLD. For example, in order to decode VP8 media, this line must be present in the output of vainfo:

      VAProfileVP8Version0_3          : VAEntrypointVLD

Whereas to decode H264 Main profile media, this line must be present:

      VAProfileH264Main               : VAEntrypointVLD

For more information on VA-API and its usage within ChromeOS, see this guide.

For a brief introduction on how to use this crate, see the libva_utils_mpeg2vldemo test under src/lib.rs.