From 2b9bf44f784ac7e97becddd7de4fc0db8a8afadc Mon Sep 17 00:00:00 2001 From: Alexandre Courbot Date: Sun, 11 Oct 2020 18:04:09 +0900 Subject: [PATCH] devices/video/decoder: use decoder pixel format type in DecoderDevice Use the decoder's own pixel format type to avoid using the libvda one in the DecoderDevice interface. BUG=b:169295147 BUG=b:161774071 TEST=Youtube video playback works on kukui-arc-r. TEST=Youtube video playback works on hatch-arc-r. Change-Id: I85589c25d337a517e4d98c55e8fb4e968c0c3e46 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2477405 Tested-by: Alexandre Courbot Tested-by: kokoro Commit-Queue: Alexandre Courbot Reviewed-by: Alex Lau --- .../src/virtio/video/decoder/backend/mod.rs | 2 +- .../src/virtio/video/decoder/backend/vda.rs | 25 ++++++++++++++++--- devices/src/virtio/video/decoder/mod.rs | 2 +- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/devices/src/virtio/video/decoder/backend/mod.rs b/devices/src/virtio/video/decoder/backend/mod.rs index 304639de9d..4a13e047b0 100644 --- a/devices/src/virtio/video/decoder/backend/mod.rs +++ b/devices/src/virtio/video/decoder/backend/mod.rs @@ -65,7 +65,7 @@ pub trait DecoderSession { fn use_output_buffer( &self, picture_buffer_id: i32, - format: libvda::PixelFormat, + format: Format, output_buffer: RawFd, planes: &[libvda::FramePlane], ) -> VideoResult<()>; diff --git a/devices/src/virtio/video/decoder/backend/vda.rs b/devices/src/virtio/video/decoder/backend/vda.rs index 4c793a3c7c..29bc707fba 100644 --- a/devices/src/virtio/video/decoder/backend/vda.rs +++ b/devices/src/virtio/video/decoder/backend/vda.rs @@ -28,6 +28,20 @@ impl TryFrom for libvda::Profile { } } +impl TryFrom for libvda::PixelFormat { + type Error = VideoError; + + fn try_from(format: Format) -> Result { + Ok(match format { + Format::NV12 => libvda::PixelFormat::NV12, + _ => { + error!("specified format {} is not supported by VDA", format); + return Err(VideoError::InvalidParameter); + } + }) + } +} + pub struct LibvdaSession<'a> { session: libvda::decode::Session<'a>, } @@ -62,13 +76,16 @@ impl<'a> DecoderSession for LibvdaSession<'a> { fn use_output_buffer( &self, picture_buffer_id: i32, - format: libvda::PixelFormat, + format: Format, output_buffer: RawFd, planes: &[libvda::FramePlane], ) -> VideoResult<()> { - Ok(self - .session - .use_output_buffer(picture_buffer_id, format, output_buffer, planes)?) + Ok(self.session.use_output_buffer( + picture_buffer_id, + libvda::PixelFormat::try_from(format)?, + output_buffer, + planes, + )?) } fn reuse_output_buffer(&self, picture_buffer_id: i32) -> VideoResult<()> { diff --git a/devices/src/virtio/video/decoder/mod.rs b/devices/src/virtio/video/decoder/mod.rs index db5fa6d8c1..845861c058 100644 --- a/devices/src/virtio/video/decoder/mod.rs +++ b/devices/src/virtio/video/decoder/mod.rs @@ -615,7 +615,7 @@ impl<'a, D: DecoderBackend> Decoder { // Take ownership of this file by `into_raw_fd()` as this // file will be closed by libvda. let fd = resource_info.file.into_raw_fd(); - session.use_output_buffer(buffer_id as i32, libvda::PixelFormat::NV12, fd, &planes) + session.use_output_buffer(buffer_id as i32, Format::NV12, fd, &planes) } } }