From b7bfcb2094c592f0774e09d197265dd2c70f8eeb Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Thu, 3 Dec 2020 10:46:48 +0100 Subject: [PATCH] video: add VideoMeta::get_plane_{height,size} Fix #299 --- gstreamer-video/src/video_meta.rs | 55 +++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/gstreamer-video/src/video_meta.rs b/gstreamer-video/src/video_meta.rs index be3dfa866..a6aac5eed 100644 --- a/gstreamer-video/src/video_meta.rs +++ b/gstreamer-video/src/video_meta.rs @@ -151,6 +151,42 @@ impl VideoMeta { pub fn get_stride(&self) -> &[i32] { &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_plane_size(&self) -> Result<[usize; crate::VIDEO_MAX_PLANES], glib::BoolError> { + let mut plane_size = [0; crate::VIDEO_MAX_PLANES]; + + unsafe { + glib::glib_result_from_gboolean!( + gst_video_sys::gst_video_meta_get_plane_size( + &self.0 as *const _ as usize as *mut _, + plane_size.as_mut_ptr(), + ), + "Failed to get plane size" + )?; + } + + Ok(plane_size) + } + + #[cfg(any(feature = "v1_18", feature = "dox"))] + #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))] + pub fn get_plane_height(&self) -> Result<[u32; crate::VIDEO_MAX_PLANES], glib::BoolError> { + let mut plane_height = [0; crate::VIDEO_MAX_PLANES]; + + unsafe { + glib::glib_result_from_gboolean!( + gst_video_sys::gst_video_meta_get_plane_height( + &self.0 as *const _ as usize as *mut _, + plane_height.as_mut_ptr(), + ), + "Failed to get plane height" + )?; + } + + Ok(plane_height) + } } unsafe impl MetaAPI for VideoMeta { @@ -757,4 +793,23 @@ mod tests { assert_eq!(meta.get_stride(), &[320 * 4]); } } + + #[test] + #[cfg(feature = "v1_18")] + fn test_vide_meta_alignment() { + gst::init().unwrap(); + + let mut buffer = gst::Buffer::with_size(115200).unwrap(); + let meta = VideoMeta::add( + buffer.get_mut().unwrap(), + crate::VideoFrameFlags::empty(), + crate::VideoFormat::Nv12, + 320, + 240, + ) + .unwrap(); + + assert_eq!(meta.get_plane_size().unwrap(), [76800, 38400, 0, 0]); + assert_eq!(meta.get_plane_height().unwrap(), [240, 120, 0, 0]); + } }