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: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1764>
This commit is contained in:
Sebastian Dröge 2025-08-06 12:20:46 +03:00 committed by Backport Bot
parent 5532d2f10f
commit 8866a769c2

View file

@ -74,7 +74,6 @@ impl VideoMeta {
return Err(glib::bool_error!("Unsupported video format {}", format)); 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) let info_builder = crate::VideoInfo::builder(format, width, height)
.offset(offset) .offset(offset)
.stride(stride); .stride(stride);
@ -87,6 +86,25 @@ impl VideoMeta {
let info = info_builder.build()?; 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<gst::MetaRefMut<'a, Self, gst::meta::Standalone>, 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() { if !info.is_valid() {
return Err(glib::bool_error!("Invalid video info")); return Err(glib::bool_error!("Invalid video info"));
} }
@ -103,12 +121,12 @@ impl VideoMeta {
let meta = ffi::gst_buffer_add_video_meta_full( let meta = ffi::gst_buffer_add_video_meta_full(
buffer.as_mut_ptr(), buffer.as_mut_ptr(),
video_frame_flags.into_glib(), video_frame_flags.into_glib(),
format.into_glib(), info.format().into_glib(),
width, info.width(),
height, info.height(),
n_planes, info.n_planes(),
offset.as_ptr() as *mut _, info.offset().as_ptr() as *mut _,
stride.as_ptr() as *mut _, info.stride().as_ptr() as *mut _,
); );
if meta.is_null() { if meta.is_null() {