mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-25 19:11:06 +00:00
video: add alignment API to VideoMeta
This commit is contained in:
parent
87dc92ff4a
commit
18af63beac
1 changed files with 79 additions and 0 deletions
|
@ -152,6 +152,18 @@ impl VideoMeta {
|
||||||
&self.0.stride[0..(self.0.n_planes as usize)]
|
&self.0.stride[0..(self.0.n_planes as usize)]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(any(feature = "v1_18", feature = "dox"))]
|
||||||
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
|
||||||
|
pub fn get_alignment(&self) -> crate::VideoAlignment {
|
||||||
|
crate::VideoAlignment::new(
|
||||||
|
self.0.alignment.padding_top,
|
||||||
|
self.0.alignment.padding_bottom,
|
||||||
|
self.0.alignment.padding_left,
|
||||||
|
self.0.alignment.padding_right,
|
||||||
|
&self.0.alignment.stride_align,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(any(feature = "v1_18", feature = "dox"))]
|
#[cfg(any(feature = "v1_18", feature = "dox"))]
|
||||||
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
|
||||||
pub fn get_plane_size(&self) -> Result<[usize; crate::VIDEO_MAX_PLANES], glib::BoolError> {
|
pub fn get_plane_size(&self) -> Result<[usize; crate::VIDEO_MAX_PLANES], glib::BoolError> {
|
||||||
|
@ -187,6 +199,20 @@ impl VideoMeta {
|
||||||
|
|
||||||
Ok(plane_height)
|
Ok(plane_height)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(any(feature = "v1_18", feature = "dox"))]
|
||||||
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
|
||||||
|
pub fn set_alignment(
|
||||||
|
&mut self,
|
||||||
|
alignment: &crate::VideoAlignment,
|
||||||
|
) -> Result<(), glib::BoolError> {
|
||||||
|
unsafe {
|
||||||
|
glib::glib_result_from_gboolean!(
|
||||||
|
gst_video_sys::gst_video_meta_set_alignment(&mut self.0, alignment.0),
|
||||||
|
"Failed to set alignment on VideoMeta"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl MetaAPI for VideoMeta {
|
unsafe impl MetaAPI for VideoMeta {
|
||||||
|
@ -809,7 +835,60 @@ mod tests {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
let alig = meta.get_alignment();
|
||||||
|
assert_eq!(alig, crate::VideoAlignment::new(0, 0, 0, 0, &[0, 0, 0, 0]));
|
||||||
|
|
||||||
assert_eq!(meta.get_plane_size().unwrap(), [76800, 38400, 0, 0]);
|
assert_eq!(meta.get_plane_size().unwrap(), [76800, 38400, 0, 0]);
|
||||||
assert_eq!(meta.get_plane_height().unwrap(), [240, 120, 0, 0]);
|
assert_eq!(meta.get_plane_height().unwrap(), [240, 120, 0, 0]);
|
||||||
|
|
||||||
|
/* horizontal padding */
|
||||||
|
let mut info = crate::VideoInfo::builder(crate::VideoFormat::Nv12, 320, 240)
|
||||||
|
.build()
|
||||||
|
.expect("Failed to create VideoInfo");
|
||||||
|
let mut alig = crate::VideoAlignment::new(0, 0, 2, 6, &[0, 0, 0, 0]);
|
||||||
|
assert!(info.align(&mut alig));
|
||||||
|
|
||||||
|
let mut meta = VideoMeta::add_full(
|
||||||
|
buffer.get_mut().unwrap(),
|
||||||
|
crate::VideoFrameFlags::empty(),
|
||||||
|
crate::VideoFormat::Nv12,
|
||||||
|
info.width(),
|
||||||
|
info.height(),
|
||||||
|
info.offset(),
|
||||||
|
info.stride(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
meta.set_alignment(&alig).unwrap();
|
||||||
|
|
||||||
|
let alig = meta.get_alignment();
|
||||||
|
assert_eq!(alig, crate::VideoAlignment::new(0, 0, 2, 6, &[0, 0, 0, 0]));
|
||||||
|
|
||||||
|
assert_eq!(meta.get_plane_size().unwrap(), [78720, 39360, 0, 0]);
|
||||||
|
assert_eq!(meta.get_plane_height().unwrap(), [240, 120, 0, 0]);
|
||||||
|
|
||||||
|
/* vertical alignment */
|
||||||
|
let mut info = crate::VideoInfo::builder(crate::VideoFormat::Nv12, 320, 240)
|
||||||
|
.build()
|
||||||
|
.expect("Failed to create VideoInfo");
|
||||||
|
let mut alig = crate::VideoAlignment::new(2, 6, 0, 0, &[0, 0, 0, 0]);
|
||||||
|
assert!(info.align(&mut alig));
|
||||||
|
|
||||||
|
let mut meta = VideoMeta::add_full(
|
||||||
|
buffer.get_mut().unwrap(),
|
||||||
|
crate::VideoFrameFlags::empty(),
|
||||||
|
crate::VideoFormat::Nv12,
|
||||||
|
info.width(),
|
||||||
|
info.height(),
|
||||||
|
info.offset(),
|
||||||
|
info.stride(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
meta.set_alignment(&alig).unwrap();
|
||||||
|
|
||||||
|
let alig = meta.get_alignment();
|
||||||
|
assert_eq!(alig, crate::VideoAlignment::new(2, 6, 0, 0, &[0, 0, 0, 0]));
|
||||||
|
|
||||||
|
assert_eq!(meta.get_plane_size().unwrap(), [79360, 39680, 0, 0]);
|
||||||
|
assert_eq!(meta.get_plane_height().unwrap(), [248, 124, 0, 0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue