From 8866a769c2982bc600c711a60b1935b61a677b1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 6 Aug 2025 12:20:46 +0300 Subject: [PATCH] video-meta: Add `add_from_info()` function that takes a `VideoInfo` Most callers have a video info already anyway and this reduces the number of parameters. Part-of: --- gstreamer-video/src/video_meta.rs | 32 ++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/gstreamer-video/src/video_meta.rs b/gstreamer-video/src/video_meta.rs index 955250d35..4162eba0a 100644 --- a/gstreamer-video/src/video_meta.rs +++ b/gstreamer-video/src/video_meta.rs @@ -74,7 +74,6 @@ impl VideoMeta { return Err(glib::bool_error!("Unsupported video format {}", format)); } - let n_planes = offset.len() as u32; let info_builder = crate::VideoInfo::builder(format, width, height) .offset(offset) .stride(stride); @@ -87,6 +86,25 @@ impl VideoMeta { let info = info_builder.build()?; + Self::add_from_info(buffer, video_frame_flags, &info) + } + + pub fn add_from_info<'a>( + buffer: &'a mut gst::BufferRef, + video_frame_flags: crate::VideoFrameFlags, + info: &crate::VideoInfo, + ) -> Result, glib::BoolError> { + skip_assert_initialized!(); + + if info.format() == crate::VideoFormat::Unknown + || info.format() == crate::VideoFormat::Encoded + { + return Err(glib::bool_error!( + "Unsupported video format {}", + info.format() + )); + } + if !info.is_valid() { return Err(glib::bool_error!("Invalid video info")); } @@ -103,12 +121,12 @@ impl VideoMeta { let meta = ffi::gst_buffer_add_video_meta_full( buffer.as_mut_ptr(), video_frame_flags.into_glib(), - format.into_glib(), - width, - height, - n_planes, - offset.as_ptr() as *mut _, - stride.as_ptr() as *mut _, + info.format().into_glib(), + info.width(), + info.height(), + info.n_planes(), + info.offset().as_ptr() as *mut _, + info.stride().as_ptr() as *mut _, ); if meta.is_null() {