From 35353445de40311ce1499a36369cff63087f1937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 1 Oct 2018 14:52:31 +0300 Subject: [PATCH] VideoOverlayComposition is supposed to be immutable So remove the add() function and instead require an IntoIterator in the constructor, and require at least one item in the iterator or return None. --- .../src/video_overlay_composition.rs | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/gstreamer-video/src/video_overlay_composition.rs b/gstreamer-video/src/video_overlay_composition.rs index 74372483f..ca2a15475 100644 --- a/gstreamer-video/src/video_overlay_composition.rs +++ b/gstreamer-video/src/video_overlay_composition.rs @@ -185,18 +185,31 @@ impl fmt::Debug for VideoOverlayCompositionRef { } impl VideoOverlayComposition { - pub fn new(rect: &VideoOverlayRectangle) -> Self { - unsafe { from_glib_full(ffi::gst_video_overlay_composition_new(rect.as_mut_ptr())) } + pub fn new<'a, T: IntoIterator>(rects: T) -> Option { + unsafe { + let mut iter = rects.into_iter(); + + let first = match iter.next() { + None => return None, + Some(first) => first, + }; + + let composition = + Self::from_glib_full(ffi::gst_video_overlay_composition_new(first.as_mut_ptr())); + + for rect in iter { + ffi::gst_video_overlay_composition_add_rectangle( + composition.as_mut_ptr(), + rect.as_mut_ptr(), + ); + } + + Some(composition) + } } } impl VideoOverlayCompositionRef { - pub fn add_rectangle(&mut self, rect: &VideoOverlayRectangle) { - unsafe { - ffi::gst_video_overlay_composition_add_rectangle(self.as_mut_ptr(), rect.as_mut_ptr()); - } - } - pub fn n_rectangles(&self) -> u32 { unsafe { ffi::gst_video_overlay_composition_n_rectangles(self.as_mut_ptr()) } }