video_meta: account for alternate interlace mode

In alternate interlace mode, each buffer will carry only one field,
so effectively buffers have half the size of a frame. Without this patch,
VideoMeta::add_full would fail for such cases, and a test case is added
to cover this.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1642>
This commit is contained in:
Carlos Bentzen 2025-02-13 14:02:52 +01:00 committed by Backport Bot
parent 6232c51690
commit c711af989f

View file

@ -75,10 +75,17 @@ impl VideoMeta {
}
let n_planes = offset.len() as u32;
let info = crate::VideoInfo::builder(format, width, height)
let info_builder = crate::VideoInfo::builder(format, width, height)
.offset(offset)
.stride(stride)
.build()?;
.stride(stride);
#[cfg(feature = "v1_16")]
let info_builder = info_builder.interlace_mode_if(
crate::VideoInterlaceMode::Alternate,
video_frame_flags.contains(crate::VideoFrameFlags::ONEFIELD),
);
let info = info_builder.build()?;
if !info.is_valid() {
return Err(glib::bool_error!("Invalid video info"));
@ -1285,6 +1292,23 @@ mod tests {
}
}
#[test]
#[cfg(feature = "v1_16")]
fn test_add_full_alternate_interlacing() {
gst::init().unwrap();
let mut buffer = gst::Buffer::with_size(320 * 120 * 4).unwrap();
VideoMeta::add_full(
buffer.get_mut().unwrap(),
crate::VideoFrameFlags::TOP_FIELD,
crate::VideoFormat::Argb,
320,
240,
&[0],
&[320 * 4],
)
.unwrap();
}
#[test]
#[cfg(feature = "v1_18")]
fn test_video_meta_alignment() {