mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-25 19:11:06 +00:00
video: Implement non-fallible constructor and FromIterator for VideoOverlayComposition when building for 1.20
Previous versions needed at least one rectangle for successfull construction.
This commit is contained in:
parent
7037f6d836
commit
3d39faac28
1 changed files with 54 additions and 0 deletions
|
@ -213,6 +213,29 @@ impl fmt::Debug for VideoOverlayCompositionRef {
|
|||
}
|
||||
|
||||
impl VideoOverlayComposition {
|
||||
#[cfg(any(feature = "v1_20", feature = "dox"))]
|
||||
#[doc(alias = "gst_video_overlay_composition_new")]
|
||||
pub fn new<'a>(rects: impl IntoIterator<Item = &'a VideoOverlayRectangle>) -> Self {
|
||||
assert_initialized_main_thread!();
|
||||
|
||||
use std::ptr;
|
||||
|
||||
unsafe {
|
||||
let composition =
|
||||
Self::from_glib_full(ffi::gst_video_overlay_composition_new(ptr::null_mut()));
|
||||
|
||||
rects.into_iter().for_each(|rect| {
|
||||
ffi::gst_video_overlay_composition_add_rectangle(
|
||||
composition.as_mut_ptr(),
|
||||
rect.as_mut_ptr(),
|
||||
);
|
||||
});
|
||||
|
||||
composition
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(any(feature = "v1_20", feature = "dox")))]
|
||||
#[doc(alias = "gst_video_overlay_composition_new")]
|
||||
pub fn new<'a>(
|
||||
rects: impl IntoIterator<Item = &'a VideoOverlayRectangle>,
|
||||
|
@ -306,6 +329,37 @@ impl<'a> IntoIterator for &'a VideoOverlayComposition {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "v1_20", feature = "dox"))]
|
||||
impl std::iter::FromIterator<VideoOverlayRectangle> for VideoOverlayComposition {
|
||||
fn from_iter<T: IntoIterator<Item = VideoOverlayRectangle>>(iter: T) -> Self {
|
||||
assert_initialized_main_thread!();
|
||||
|
||||
use std::ptr;
|
||||
|
||||
unsafe {
|
||||
let composition =
|
||||
Self::from_glib_full(ffi::gst_video_overlay_composition_new(ptr::null_mut()));
|
||||
|
||||
iter.into_iter().for_each(|rect| {
|
||||
ffi::gst_video_overlay_composition_add_rectangle(
|
||||
composition.as_mut_ptr(),
|
||||
rect.as_mut_ptr(),
|
||||
);
|
||||
});
|
||||
|
||||
composition
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "v1_20", feature = "dox"))]
|
||||
impl<'a> std::iter::FromIterator<&'a VideoOverlayRectangle> for VideoOverlayComposition {
|
||||
fn from_iter<T: IntoIterator<Item = &'a VideoOverlayRectangle>>(iter: T) -> Self {
|
||||
assert_initialized_main_thread!();
|
||||
VideoOverlayComposition::new(iter.into_iter())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Iter<'a> {
|
||||
composition: &'a VideoOverlayCompositionRef,
|
||||
idx: u32,
|
||||
|
|
Loading…
Reference in a new issue