virtio: video: merge similar frame plane structs
We are using similar structures for describing the planes of a frame in
the decoder and encoder. Consolidate them into a single structure
accessible from the shared format module.
BUG=b:161774071
TEST=arc.VideoDecodeAccel.h264_vm passes on hatch
TEST=arc.VideoEncodeAccel.h264_360p_i420_vm passes on hatch
Change-Id: I289c896e022cbb0952a1f2be626b3f8a6caaf13e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2983091
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Auto-Submit: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: David Staessens <dstaessens@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
diff --git a/devices/src/virtio/video/decoder/backend/mod.rs b/devices/src/virtio/video/decoder/backend/mod.rs
index fa64139..e5b7ffa 100644
--- a/devices/src/virtio/video/decoder/backend/mod.rs
+++ b/devices/src/virtio/video/decoder/backend/mod.rs
@@ -8,17 +8,12 @@
use crate::virtio::video::{
decoder::Capability,
error::{VideoError, VideoResult},
- format::{Format, Rect},
+ format::{Format, FramePlane, Rect},
};
use base::{AsRawDescriptor, RawDescriptor};
pub mod vda;
-pub struct FramePlane {
- pub offset: i32,
- pub stride: i32,
-}
-
/// Contains the device's state for one playback session, i.e. one stream.
pub trait DecoderSession {
/// Tell how many output buffers will be used for this session. This method
diff --git a/devices/src/virtio/video/decoder/backend/vda.rs b/devices/src/virtio/video/decoder/backend/vda.rs
index 115f5bc..e1c5a6f 100644
--- a/devices/src/virtio/video/decoder/backend/vda.rs
+++ b/devices/src/virtio/video/decoder/backend/vda.rs
@@ -54,8 +54,8 @@
impl From<&FramePlane> for libvda::FramePlane {
fn from(plane: &FramePlane) -> Self {
libvda::FramePlane {
- offset: plane.offset,
- stride: plane.stride,
+ offset: plane.offset as i32,
+ stride: plane.stride as i32,
}
}
}
diff --git a/devices/src/virtio/video/decoder/mod.rs b/devices/src/virtio/video/decoder/mod.rs
index a4f6da6..9546546 100644
--- a/devices/src/virtio/video/decoder/mod.rs
+++ b/devices/src/virtio/video/decoder/mod.rs
@@ -637,12 +637,12 @@
ctx.get_resource_info(QueueType::Output, &self.resource_bridge, resource_id)?;
let planes = vec![
FramePlane {
- offset: resource_info.planes[0].offset as i32,
- stride: resource_info.planes[0].stride as i32,
+ offset: resource_info.planes[0].offset as usize,
+ stride: resource_info.planes[0].stride as usize,
},
FramePlane {
- offset: resource_info.planes[1].offset as i32,
- stride: resource_info.planes[1].stride as i32,
+ offset: resource_info.planes[1].offset as usize,
+ stride: resource_info.planes[1].stride as usize,
},
];
diff --git a/devices/src/virtio/video/encoder/backend/mod.rs b/devices/src/virtio/video/encoder/backend/mod.rs
index 2f93906..d6f25f4 100644
--- a/devices/src/virtio/video/encoder/backend/mod.rs
+++ b/devices/src/virtio/video/encoder/backend/mod.rs
@@ -9,10 +9,10 @@
use base::AsRawDescriptor;
use crate::virtio::video::error::VideoResult;
+use crate::virtio::video::format::FramePlane;
use super::encoder::{
EncoderCapabilities, EncoderEvent, InputBufferId, OutputBufferId, SessionConfig,
- VideoFramePlane,
};
pub trait EncoderSession {
@@ -26,7 +26,7 @@
fn encode(
&mut self,
resource: File,
- planes: &[VideoFramePlane],
+ planes: &[FramePlane],
timestamp: u64,
force_keyframe: bool,
) -> VideoResult<InputBufferId>;
diff --git a/devices/src/virtio/video/encoder/backend/vda.rs b/devices/src/virtio/video/encoder/backend/vda.rs
index 7ee41ec..0ee0ea6 100644
--- a/devices/src/virtio/video/encoder/backend/vda.rs
+++ b/devices/src/virtio/video/encoder/backend/vda.rs
@@ -11,7 +11,9 @@
use base::{error, warn, AsRawDescriptor, IntoRawDescriptor};
use super::*;
-use crate::virtio::video::format::{Format, FormatDesc, FormatRange, FrameFormat, Level, Profile};
+use crate::virtio::video::format::{
+ Format, FormatDesc, FormatRange, FrameFormat, FramePlane, Level, Profile,
+};
use crate::virtio::video::{
encoder::{encoder::*, EncoderDevice},
error::{VideoError, VideoResult},
@@ -264,7 +266,7 @@
fn encode(
&mut self,
resource: File,
- planes: &[VideoFramePlane],
+ planes: &[FramePlane],
timestamp: u64,
force_keyframe: bool,
) -> VideoResult<InputBufferId> {
diff --git a/devices/src/virtio/video/encoder/encoder.rs b/devices/src/virtio/video/encoder/encoder.rs
index fd41016..d9836f4 100644
--- a/devices/src/virtio/video/encoder/encoder.rs
+++ b/devices/src/virtio/video/encoder/encoder.rs
@@ -50,12 +50,6 @@
pub frame_rate: u32,
}
-#[derive(Debug)]
-pub struct VideoFramePlane {
- pub offset: usize,
- pub stride: usize,
-}
-
#[derive(Clone)]
pub struct EncoderCapabilities {
pub input_format_descs: Vec<FormatDesc>,
diff --git a/devices/src/virtio/video/encoder/mod.rs b/devices/src/virtio/video/encoder/mod.rs
index 977ff8e..7b75c69 100644
--- a/devices/src/virtio/video/encoder/mod.rs
+++ b/devices/src/virtio/video/encoder/mod.rs
@@ -20,11 +20,11 @@
AsyncCmdResponse, AsyncCmdTag, Device, Token, VideoEvtResponseType,
};
use crate::virtio::video::encoder::encoder::{
- EncoderEvent, InputBufferId, OutputBufferId, SessionConfig, VideoFramePlane,
+ EncoderEvent, InputBufferId, OutputBufferId, SessionConfig,
};
use crate::virtio::video::error::*;
use crate::virtio::video::event::{EvtType, VideoEvt};
-use crate::virtio::video::format::{Format, Level, PlaneFormat, Profile};
+use crate::virtio::video::format::{Format, FramePlane, Level, PlaneFormat, Profile};
use crate::virtio::video::params::Params;
use crate::virtio::video::protocol;
use crate::virtio::video::response::CmdResponse;
@@ -40,7 +40,7 @@
struct InputResource {
resource_handle: u128,
- planes: Vec<VideoFramePlane>,
+ planes: Vec<FramePlane>,
queue_params: Option<QueuedInputResourceParams>,
}
@@ -596,9 +596,9 @@
let resource_info = get_resource_info(&self.resource_bridge, uuid)?;
- let planes: Vec<VideoFramePlane> = resource_info.planes[0..num_planes]
+ let planes: Vec<FramePlane> = resource_info.planes[0..num_planes]
.iter()
- .map(|plane_info| VideoFramePlane {
+ .map(|plane_info| FramePlane {
offset: plane_info.offset as usize,
stride: plane_info.stride as usize,
})
diff --git a/devices/src/virtio/video/format.rs b/devices/src/virtio/video/format.rs
index 6ef6ec2..0f99ecd 100644
--- a/devices/src/virtio/video/format.rs
+++ b/devices/src/virtio/video/format.rs
@@ -237,3 +237,10 @@
pub right: i32,
pub bottom: i32,
}
+
+/// Description of the layout for a single plane.
+#[derive(Debug, Clone)]
+pub struct FramePlane {
+ pub offset: usize,
+ pub stride: usize,
+}