video-meta: Remove extensive validation from add_full()

Validation is already provided for `add_from_info()` and it's wrong for
DMA_DRM formats.

This allows adding video meta for DMA_DRM, where the video info contains
no usable information in most fields.

Additionally suggest using `add_full()` instead of the other variants
for DMA_DRM formats.

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/562

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1774>
This commit is contained in:
Sebastian Dröge 2025-08-12 12:30:47 +03:00
parent d7d9648498
commit db273f5007

View file

@ -28,6 +28,11 @@ impl VideoMeta {
return Err(glib::bool_error!("Unsupported video format {}", format)); return Err(glib::bool_error!("Unsupported video format {}", format));
} }
#[cfg(feature = "v1_24")]
if format == crate::VideoFormat::DmaDrm {
return Err(glib::bool_error!("Use `add_full()` for DMA_DRM formats"));
}
let info = crate::VideoInfo::builder(format, width, height).build()?; let info = crate::VideoInfo::builder(format, width, height).build()?;
if !info.is_valid() { if !info.is_valid() {
@ -74,19 +79,26 @@ impl VideoMeta {
return Err(glib::bool_error!("Unsupported video format {}", format)); return Err(glib::bool_error!("Unsupported video format {}", format));
} }
let info_builder = crate::VideoInfo::builder(format, width, height) assert_eq!(offset.len(), stride.len());
.offset(offset)
.stride(stride);
#[cfg(feature = "v1_16")] unsafe {
let info_builder = info_builder.interlace_mode_if( let meta = ffi::gst_buffer_add_video_meta_full(
crate::VideoInterlaceMode::Alternate, buffer.as_mut_ptr(),
video_frame_flags.contains(crate::VideoFrameFlags::ONEFIELD), video_frame_flags.into_glib(),
); format.into_glib(),
width,
height,
offset.len() as u32,
offset.as_ptr() as *mut _,
stride.as_ptr() as *mut _,
);
let info = info_builder.build()?; if meta.is_null() {
return Err(glib::bool_error!("Failed to add video meta"));
}
Self::add_from_info(buffer, video_frame_flags, &info) Ok(Self::from_mut_ptr(buffer, meta))
}
} }
pub fn add_from_info<'a>( pub fn add_from_info<'a>(
@ -105,6 +117,11 @@ impl VideoMeta {
)); ));
} }
#[cfg(feature = "v1_24")]
if info.format() == crate::VideoFormat::DmaDrm {
return Err(glib::bool_error!("Use `add_full()` for DMA_DRM formats"));
}
if !info.is_valid() { if !info.is_valid() {
return Err(glib::bool_error!("Invalid video info")); return Err(glib::bool_error!("Invalid video info"));
} }
@ -117,24 +134,15 @@ impl VideoMeta {
)); ));
} }
unsafe { Self::add_full(
let meta = ffi::gst_buffer_add_video_meta_full( buffer,
buffer.as_mut_ptr(), video_frame_flags,
video_frame_flags.into_glib(), info.format(),
info.format().into_glib(), info.width(),
info.width(), info.height(),
info.height(), info.offset(),
info.n_planes(), info.stride(),
info.offset().as_ptr() as *mut _, )
info.stride().as_ptr() as *mut _,
);
if meta.is_null() {
return Err(glib::bool_error!("Failed to add video meta"));
}
Ok(Self::from_mut_ptr(buffer, meta))
}
} }
#[doc(alias = "get_flags")] #[doc(alias = "get_flags")]