diff --git a/examples/src/bin/cairo_compositor.rs b/examples/src/bin/cairo_compositor.rs index f6adb31f0..13f6fe5a9 100644 --- a/examples/src/bin/cairo_compositor.rs +++ b/examples/src/bin/cairo_compositor.rs @@ -200,7 +200,7 @@ mod cairo_compositor { caps }; - q.set_result(Some(&caps)); + q.set_result(&caps); true } diff --git a/examples/src/glupload.rs b/examples/src/glupload.rs index e13266de6..87fe5939e 100644 --- a/examples/src/glupload.rs +++ b/examples/src/glupload.rs @@ -424,7 +424,7 @@ impl App { msg.src().map(|s| s.downcast::().unwrap()) { let context = gst::Context::new(context_type, true); - context.set_gl_display(Some(&gl_display)); + context.set_gl_display(&gl_display); el.set_context(&context); } } diff --git a/gstreamer-gl/src/context.rs b/gstreamer-gl/src/context.rs index 6a3bce047..697fa38f4 100644 --- a/gstreamer-gl/src/context.rs +++ b/gstreamer-gl/src/context.rs @@ -11,7 +11,7 @@ pub trait ContextGLExt { #[doc(alias = "gst_context_get_gl_display")] fn gl_display(&self) -> Option; #[doc(alias = "gst_context_set_gl_display")] - fn set_gl_display>(&self, display: Option<&T>); + fn set_gl_display<'a, T: IsA>(&self, display: impl Into>); } impl ContextGLExt for ContextRef { @@ -29,11 +29,11 @@ impl ContextGLExt for ContextRef { } } - fn set_gl_display>(&self, display: Option<&T>) { + fn set_gl_display<'a, T: IsA>(&self, display: impl Into>) { unsafe { ffi::gst_context_set_gl_display( self.as_mut_ptr(), - display.map(|d| d.as_ref()).to_glib_none().0, + display.into().map(|d| d.as_ref()).to_glib_none().0, ); } } diff --git a/gstreamer/src/buffer_pool.rs b/gstreamer/src/buffer_pool.rs index 92b0aa1ad..ccf4eaa70 100644 --- a/gstreamer/src/buffer_pool.rs +++ b/gstreamer/src/buffer_pool.rs @@ -413,7 +413,7 @@ mod tests { use crate::prelude::*; #[test] - fn test_pool() { + fn pool_with_params() { crate::init().unwrap(); let pool = crate::BufferPool::new(); @@ -436,4 +436,18 @@ mod tests { pool.set_active(false).unwrap(); } + + #[test] + fn pool_no_params() { + crate::init().unwrap(); + + let pool = crate::BufferPool::new(); + let mut config = pool.config(); + config.set_params(None, 1024, 0, 2); + pool.set_config(config).unwrap(); + + pool.set_active(true).unwrap(); + let _buf1 = pool.acquire_buffer(None).unwrap(); + pool.set_active(false).unwrap(); + } } diff --git a/gstreamer/src/query.rs b/gstreamer/src/query.rs index 5c6acb13b..635ec85c4 100644 --- a/gstreamer/src/query.rs +++ b/gstreamer/src/query.rs @@ -965,17 +965,29 @@ impl Uri { } #[doc(alias = "gst_query_set_uri")] - pub fn set_uri(&mut self, uri: Option<&str>) { + pub fn set_uri<'a, T>(&mut self, uri: impl Into>) + where + T: 'a + AsRef + ?Sized, + { unsafe { - ffi::gst_query_set_uri(self.as_mut_ptr(), uri.to_glib_none().0); + ffi::gst_query_set_uri( + self.as_mut_ptr(), + uri.into().map(AsRef::as_ref).to_glib_none().0, + ); } } #[doc(alias = "gst_query_set_uri_redirection")] #[doc(alias = "gst_query_set_uri_redirection_permanent")] - pub fn set_redirection(&mut self, uri: Option<&str>, permanent: bool) { + pub fn set_redirection<'a, T>(&mut self, uri: impl Into>, permanent: bool) + where + T: 'a + AsRef + ?Sized, + { unsafe { - ffi::gst_query_set_uri_redirection(self.as_mut_ptr(), uri.to_glib_none().0); + ffi::gst_query_set_uri_redirection( + self.as_mut_ptr(), + uri.into().map(AsRef::as_ref).to_glib_none().0, + ); ffi::gst_query_set_uri_redirection_permanent( self.0.as_mut_ptr(), permanent.into_glib(), @@ -1453,11 +1465,12 @@ impl Caps { } #[doc(alias = "gst_query_set_caps_result")] - pub fn set_result(&mut self, caps: Option<&crate::Caps>) { + pub fn set_result<'a>(&mut self, caps: impl Into>) { unsafe { ffi::gst_query_set_caps_result( self.as_mut_ptr(), - caps.map(|caps| caps.as_mut_ptr()) + caps.into() + .map(|caps| caps.as_mut_ptr()) .unwrap_or(ptr::null_mut()), ); } @@ -1527,11 +1540,12 @@ impl Context { } #[doc(alias = "gst_query_set_context")] - pub fn set_context(&mut self, context: Option<&crate::Context>) { + pub fn set_context<'a>(&mut self, context: impl Into>) { unsafe { ffi::gst_query_set_context( self.as_mut_ptr(), context + .into() .map(|context| context.as_mut_ptr()) .unwrap_or(ptr::null_mut()), ); @@ -1710,4 +1724,53 @@ mod tests { let p = Position::new(crate::Format::Time); assert!(!p.as_mut_ptr().is_null()); } + + #[test] + fn allocation_need_pool() { + crate::init().unwrap(); + + let mut a = Allocation::new(&crate::Caps::builder("foo/bar").build(), true); + let pool = crate::BufferPool::new(); + a.add_allocation_pool(Some(&pool), 1024, 1, 4); + } + + #[test] + fn allocation_do_not_need_pool() { + crate::init().unwrap(); + + let mut a = Allocation::new(&crate::Caps::builder("foo/bar").build(), false); + a.add_allocation_pool(crate::BufferPool::NONE, 1024, 1, 4); + + // cannot infer type of the type parameter `T` declared on the enum `Option` + //a.add_allocation_pool(None, 1024, 1, 4); + + // This would be possible if we moved the `crate::BufferPool` + // as a generic argument instead of using current arg type: + // - `pool: Option<&impl IsA>` + //a.add_allocation_pool::(None, 1024, 1, 4); + } + + #[test] + fn set_uri() { + crate::init().unwrap(); + + let mut uri_q = Uri::new(); + uri_q.set_uri("https://test.org"); + uri_q.set_uri(&String::from("https://test.org")); + + uri_q.set_uri(Some("https://test.org")); + uri_q.set_uri(Some(&String::from("https://test.org"))); + + // FIXME: this is commented out for now due to an inconsistent + // assertion in `GStreamer` which results in critical logs. + /* + let none: Option<&str> = None; + uri_q.set_uri(none); + + let none: Option = None; + uri_q.set_uri(none.as_ref()); + + uri_q.set_uri::(None); + */ + } } diff --git a/gstreamer/src/toc.rs b/gstreamer/src/toc.rs index 5fbbdb8f3..88ae14bfe 100644 --- a/gstreamer/src/toc.rs +++ b/gstreamer/src/toc.rs @@ -58,11 +58,12 @@ impl TocRef { } #[doc(alias = "gst_toc_set_tags")] - pub fn set_tags(&mut self, tag_list: Option) { + pub fn set_tags(&mut self, tag_list: impl Into>) { unsafe { ffi::gst_toc_set_tags( self.as_mut_ptr(), tag_list + .into() .map(|t| t.into_glib_ptr()) .unwrap_or(ptr::null_mut()), ); @@ -70,11 +71,14 @@ impl TocRef { } #[doc(alias = "gst_toc_merge_tags")] - pub fn merge_tags(&mut self, tag_list: Option<&TagList>, mode: TagMergeMode) { + pub fn merge_tags<'a>(&mut self, tag_list: impl Into>, mode: TagMergeMode) { unsafe { ffi::gst_toc_merge_tags( self.as_mut_ptr(), - tag_list.map(|l| l.as_mut_ptr()).unwrap_or(ptr::null_mut()), + tag_list + .into() + .map(|l| l.as_mut_ptr()) + .unwrap_or(ptr::null_mut()), mode.into_glib(), ); } @@ -192,11 +196,12 @@ impl TocEntryRef { } #[doc(alias = "gst_toc_entry_set_tags")] - pub fn set_tags(&mut self, tag_list: Option) { + pub fn set_tags(&mut self, tag_list: impl Into>) { unsafe { ffi::gst_toc_entry_set_tags( self.as_mut_ptr(), tag_list + .into() .map(|t| t.into_glib_ptr()) .unwrap_or(ptr::null_mut()), ); @@ -204,11 +209,14 @@ impl TocEntryRef { } #[doc(alias = "gst_toc_entry_merge_tags")] - pub fn merge_tags(&mut self, tag_list: Option<&TagList>, mode: TagMergeMode) { + pub fn merge_tags<'a>(&mut self, tag_list: impl Into>, mode: TagMergeMode) { unsafe { ffi::gst_toc_entry_merge_tags( self.as_mut_ptr(), - tag_list.map(|l| l.as_mut_ptr()).unwrap_or(ptr::null_mut()), + tag_list + .into() + .map(|l| l.as_mut_ptr()) + .unwrap_or(ptr::null_mut()), mode.into_glib(), ); } diff --git a/gstreamer/src/toc_serde.rs b/gstreamer/src/toc_serde.rs index 09010ad18..4717d7390 100644 --- a/gstreamer/src/toc_serde.rs +++ b/gstreamer/src/toc_serde.rs @@ -135,7 +135,7 @@ mod tests { tags.get_mut() .unwrap() .add::(&"toc", TagMergeMode::Append); - toc.set_tags(Some(tags)); + toc.set_tags(tags); let mut toc_edition = TocEntry::new(TocEntryType::Edition, "edition"); { @@ -154,7 +154,7 @@ mod tests { tags.get_mut() .unwrap() .add::<Title>(&"chapter 1.1", TagMergeMode::Append); - toc_chap_1_1.set_tags(Some(tags)); + toc_chap_1_1.set_tags(tags); } toc_chap_1.append_sub_entry(toc_chap_1_1); @@ -166,7 +166,7 @@ mod tests { tags.get_mut() .unwrap() .add::<Title>(&"chapter 1.2", TagMergeMode::Append); - toc_chap_1_2.set_tags(Some(tags)); + toc_chap_1_2.set_tags(tags); } toc_chap_1.append_sub_entry(toc_chap_1_2); } @@ -180,7 +180,7 @@ mod tests { tags.get_mut() .unwrap() .add::<Title>(&"chapter 2", TagMergeMode::Append); - toc_chap_2.set_tags(Some(tags)); + toc_chap_2.set_tags(tags); } toc_edition.append_sub_entry(toc_chap_2); } @@ -415,7 +415,7 @@ mod tests { tags.get_mut() .unwrap() .add::<Title>(&"toc", TagMergeMode::Append); - toc.set_tags(Some(tags)); + toc.set_tags(tags); let mut toc_edition = TocEntry::new(TocEntryType::Edition, "edition"); { @@ -434,7 +434,7 @@ mod tests { tags.get_mut() .unwrap() .add::<Title>(&"chapter 1.1", TagMergeMode::Append); - toc_chap_1_1.set_tags(Some(tags)); + toc_chap_1_1.set_tags(tags); } toc_chap_1.append_sub_entry(toc_chap_1_1); @@ -446,7 +446,7 @@ mod tests { tags.get_mut() .unwrap() .add::<Title>(&"chapter 1.2", TagMergeMode::Append); - toc_chap_1_2.set_tags(Some(tags)); + toc_chap_1_2.set_tags(tags); } toc_chap_1.append_sub_entry(toc_chap_1_2); } @@ -460,7 +460,7 @@ mod tests { tags.get_mut() .unwrap() .add::<Title>(&"chapter 2", TagMergeMode::Append); - toc_chap_2.set_tags(Some(tags)); + toc_chap_2.set_tags(tags); } toc_edition.append_sub_entry(toc_chap_2); }