From a34bc85ca1dcfb78431b787e7ca8924d22f990e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 6 May 2022 11:01:02 +0300 Subject: [PATCH] video: Don't change the `VideoOverlayComposition` constructor API based on feature flags Feature flags are additive and a higher feature might be enabled by some other dependency, which then can cause code that assumes the other API fail to compile. Still implement the constructor separately per version to make it clear to the compiler that the constructor can't fail at all in newer versions. --- .../src/video_overlay_composition.rs | 42 ++++++++++++------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/gstreamer-video/src/video_overlay_composition.rs b/gstreamer-video/src/video_overlay_composition.rs index d49fa1322..53be581fb 100644 --- a/gstreamer-video/src/video_overlay_composition.rs +++ b/gstreamer-video/src/video_overlay_composition.rs @@ -213,14 +213,16 @@ 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) -> Self { + pub fn new<'a>( + rects: impl IntoIterator, + ) -> Result { assert_initialized_main_thread!(); - use std::ptr; - + #[cfg(feature = "v1_20")] unsafe { + use std::ptr; + let composition = Self::from_glib_full(ffi::gst_video_overlay_composition_new(ptr::null_mut())); @@ -231,16 +233,9 @@ impl VideoOverlayComposition { ); }); - composition + Ok(composition) } - } - - #[cfg(not(any(feature = "v1_20", feature = "dox")))] - #[doc(alias = "gst_video_overlay_composition_new")] - pub fn new<'a>( - rects: impl IntoIterator, - ) -> Result { - assert_initialized_main_thread!(); + #[cfg(not(feature = "v1_20"))] unsafe { let mut iter = rects.into_iter(); @@ -352,9 +347,9 @@ impl std::iter::FromIterator for VideoOverlayComposition fn from_iter>(iter: T) -> Self { assert_initialized_main_thread!(); - use std::ptr; - unsafe { + use std::ptr; + let composition = Self::from_glib_full(ffi::gst_video_overlay_composition_new(ptr::null_mut())); @@ -374,7 +369,22 @@ impl std::iter::FromIterator for VideoOverlayComposition impl<'a> std::iter::FromIterator<&'a VideoOverlayRectangle> for VideoOverlayComposition { fn from_iter>(iter: T) -> Self { assert_initialized_main_thread!(); - VideoOverlayComposition::new(iter.into_iter()) + + unsafe { + use std::ptr; + + 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 + } } }