video: VideoInfo: implement align()

This commit is contained in:
Guillaume Desmottes 2019-06-17 16:54:11 +05:30
parent 4f024af7d6
commit 491eaf3a73
2 changed files with 30 additions and 1 deletions

View file

@ -36,7 +36,7 @@ lazy_static! {
}
#[derive(Debug, Clone)]
pub struct VideoAlignment(gst_video_sys::GstVideoAlignment);
pub struct VideoAlignment(pub(crate) gst_video_sys::GstVideoAlignment);
impl VideoAlignment {
pub fn get_padding_top(&self) -> u32 {

View file

@ -671,6 +671,16 @@ impl VideoInfo {
}
}
}
#[cfg(any(feature = "v1_12", feature = "dox"))]
pub fn align(&mut self, align: &mut ::VideoAlignment) -> bool {
unsafe {
from_glib(gst_video_sys::gst_video_info_align(
&mut self.0,
&mut align.0,
))
}
}
}
impl Clone for VideoInfo {
@ -920,4 +930,23 @@ mod tests {
let info2 = VideoInfo::from_caps(&caps2).unwrap();
assert!(info == info2);
}
#[cfg(any(feature = "v1_12", feature = "dox"))]
#[test]
fn test_video_align() {
gst::init().unwrap();
let mut info = ::VideoInfo::new(::VideoFormat::Nv16, 1920, 1080)
.build()
.expect("Failed to create VideoInfo");
assert_eq!(info.stride(), [1920, 1920]);
assert_eq!(info.offset(), [0, 2073600]);
let mut align = ::VideoAlignment::new(0, 0, 0, 8, &[0; 4]);
assert!(info.align(&mut align));
assert_eq!(info.stride(), [1928, 1928]);
assert_eq!(info.offset(), [0, 2082240]);
}
}