mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2025-09-28 12:32:04 +00:00
video: Simplify VideoMeta::add_full()
The n_planes value can be infered from the offset and stride slices size, which both need to match. Fixes #224
This commit is contained in:
parent
dc7937a8d4
commit
80e01dbe3c
1 changed files with 42 additions and 5 deletions
|
@ -42,22 +42,21 @@ impl VideoMeta {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
pub fn add_full<'a>(
|
pub fn add_full<'a>(
|
||||||
buffer: &'a mut gst::BufferRef,
|
buffer: &'a mut gst::BufferRef,
|
||||||
flags: ::VideoFrameFlags,
|
flags: ::VideoFrameFlags,
|
||||||
format: ::VideoFormat,
|
format: ::VideoFormat,
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
n_planes: u32,
|
offset: &[usize],
|
||||||
offset: &[usize; 4],
|
stride: &[i32],
|
||||||
stride: &[i32; 4],
|
|
||||||
) -> gst::MetaRefMut<'a, Self, gst::meta::Standalone> {
|
) -> gst::MetaRefMut<'a, Self, gst::meta::Standalone> {
|
||||||
|
let n_planes = offset.len() as u32;
|
||||||
let info = ::VideoInfo::new(format, width, height)
|
let info = ::VideoInfo::new(format, width, height)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.stride(stride)
|
.stride(stride)
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.expect("Unable to build VideoInfo for given format, offsets and strides");
|
||||||
assert!(buffer.get_size() >= info.size());
|
assert!(buffer.get_size() >= info.size());
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -277,4 +276,42 @@ mod tests {
|
||||||
assert_eq!(meta.get_stride(), &[320 * 4]);
|
assert_eq!(meta.get_stride(), &[320 * 4]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_add_full_get_meta() {
|
||||||
|
gst::init().unwrap();
|
||||||
|
|
||||||
|
let mut buffer = gst::Buffer::with_size(320 * 240 * 4).unwrap();
|
||||||
|
{
|
||||||
|
let meta = VideoMeta::add_full(
|
||||||
|
buffer.get_mut().unwrap(),
|
||||||
|
::VideoFrameFlags::NONE,
|
||||||
|
::VideoFormat::Argb,
|
||||||
|
320,
|
||||||
|
240,
|
||||||
|
&[0],
|
||||||
|
&[320 * 4],
|
||||||
|
);
|
||||||
|
assert_eq!(meta.get_id(), 0);
|
||||||
|
assert_eq!(meta.get_flags(), ::VideoFrameFlags::NONE);
|
||||||
|
assert_eq!(meta.get_format(), ::VideoFormat::Argb);
|
||||||
|
assert_eq!(meta.get_width(), 320);
|
||||||
|
assert_eq!(meta.get_height(), 240);
|
||||||
|
assert_eq!(meta.get_n_planes(), 1);
|
||||||
|
assert_eq!(meta.get_offset(), &[0]);
|
||||||
|
assert_eq!(meta.get_stride(), &[320 * 4]);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
let meta = buffer.get_meta::<VideoMeta>().unwrap();
|
||||||
|
assert_eq!(meta.get_id(), 0);
|
||||||
|
assert_eq!(meta.get_flags(), ::VideoFrameFlags::NONE);
|
||||||
|
assert_eq!(meta.get_format(), ::VideoFormat::Argb);
|
||||||
|
assert_eq!(meta.get_width(), 320);
|
||||||
|
assert_eq!(meta.get_height(), 240);
|
||||||
|
assert_eq!(meta.get_n_planes(), 1);
|
||||||
|
assert_eq!(meta.get_offset(), &[0]);
|
||||||
|
assert_eq!(meta.get_stride(), &[320 * 4]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue