From d6e9cd33c02af74605a4397c175f8686e4c01130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 19 Jan 2023 16:08:16 +0200 Subject: [PATCH] gstreamer: Make allocation query caps optional See also https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3752 Part-of: --- gstreamer/src/query.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/gstreamer/src/query.rs b/gstreamer/src/query.rs index ed6b9438f..06b1f38a8 100644 --- a/gstreamer/src/query.rs +++ b/gstreamer/src/query.rs @@ -1019,11 +1019,12 @@ impl Uri { declare_concrete_query!(Allocation, T); impl Allocation { #[doc(alias = "gst_query_new_allocation")] - pub fn new(caps: &crate::Caps, need_pool: bool) -> Self { + pub fn new(caps: Option<&crate::Caps>, need_pool: bool) -> Self { skip_assert_initialized!(); unsafe { Self(from_glib_full(ffi::gst_query_new_allocation( - caps.as_mut_ptr(), + caps.map(|caps| caps.as_mut_ptr()) + .unwrap_or(ptr::null_mut()), need_pool.into_glib(), ))) } @@ -1032,24 +1033,28 @@ impl Allocation { impl Allocation { #[doc(alias = "gst_query_parse_allocation")] - pub fn get(&self) -> (&crate::CapsRef, bool) { + pub fn get(&self) -> (Option<&crate::CapsRef>, bool) { unsafe { let mut caps = ptr::null_mut(); let mut need_pool = mem::MaybeUninit::uninit(); ffi::gst_query_parse_allocation(self.as_mut_ptr(), &mut caps, need_pool.as_mut_ptr()); ( - crate::CapsRef::from_ptr(caps), + if caps.is_null() { + None + } else { + Some(crate::CapsRef::from_ptr(caps)) + }, from_glib(need_pool.assume_init()), ) } } #[doc(alias = "gst_query_parse_allocation")] - pub fn get_owned(&self) -> (crate::Caps, bool) { + pub fn get_owned(&self) -> (Option, bool) { unsafe { let (caps, need_pool) = self.get(); - (from_glib_none(caps.as_ptr()), need_pool) + (caps.map(|caps| from_glib_none(caps.as_ptr())), need_pool) } } @@ -1749,7 +1754,7 @@ mod tests { fn allocation_need_pool() { crate::init().unwrap(); - let mut a = Allocation::new(&crate::Caps::builder("foo/bar").build(), true); + let mut a = Allocation::new(Some(&crate::Caps::new_empty_simple("foo/bar")), true); let pool = crate::BufferPool::new(); a.add_allocation_pool(Some(&pool), 1024, 1, 4); } @@ -1758,7 +1763,7 @@ mod tests { fn allocation_do_not_need_pool() { crate::init().unwrap(); - let mut a = Allocation::new(&crate::Caps::builder("foo/bar").build(), false); + let mut a = Allocation::new(Some(&crate::Caps::new_empty_simple("foo/bar")), false); a.add_allocation_pool(crate::BufferPool::NONE, 1024, 1, 4); // cannot infer type of the type parameter `T` declared on the enum `Option`