From b9cd38b79653ac21195971fd076e40909442e4b6 Mon Sep 17 00:00:00 2001 From: Philippe Normand Date: Tue, 12 Oct 2021 16:48:55 +0100 Subject: [PATCH] gstreamer: query: Tidy up allocation pool API Use `impl IsA` and make the `set_nth_` and `remove_nth_` methods check the index bounds. --- gstreamer/src/query.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/gstreamer/src/query.rs b/gstreamer/src/query.rs index fe109ea17..5d4c738ca 100644 --- a/gstreamer/src/query.rs +++ b/gstreamer/src/query.rs @@ -1049,7 +1049,7 @@ impl Allocation { #[doc(alias = "gst_query_add_allocation_pool")] pub fn add_allocation_pool( &mut self, - pool: Option<&crate::BufferPool>, + pool: Option<&impl IsA>, size: u32, min_buffers: u32, max_buffers: u32, @@ -1057,7 +1057,7 @@ impl Allocation { unsafe { ffi::gst_query_add_allocation_pool( self.0.as_mut_ptr(), - pool.to_glib_none().0, + pool.to_glib_none().0 as *mut ffi::GstBufferPool, size, min_buffers, max_buffers, @@ -1069,16 +1069,18 @@ impl Allocation { pub fn set_nth_allocation_pool( &mut self, idx: u32, - pool: Option<&crate::BufferPool>, + pool: Option<&impl IsA>, size: u32, min_buffers: u32, max_buffers: u32, ) { unsafe { + let n = ffi::gst_query_get_n_allocation_pools(self.0.as_ptr()); + assert!(idx < n); ffi::gst_query_set_nth_allocation_pool( self.0.as_mut_ptr(), idx, - pool.to_glib_none().0, + pool.to_glib_none().0 as *mut ffi::GstBufferPool, size, min_buffers, max_buffers, @@ -1089,6 +1091,8 @@ impl Allocation { #[doc(alias = "gst_query_remove_nth_allocation_pool")] pub fn remove_nth_allocation_pool(&mut self, idx: u32) { unsafe { + let n = ffi::gst_query_get_n_allocation_pools(self.0.as_ptr()); + assert!(idx < n); ffi::gst_query_remove_nth_allocation_pool(self.0.as_mut_ptr(), idx); } } @@ -1157,6 +1161,8 @@ impl Allocation { #[doc(alias = "gst_query_remove_nth_allocation_meta")] pub fn remove_nth_allocation_meta(&mut self, idx: u32) { unsafe { + let n = ffi::gst_query_get_n_allocation_metas(self.0.as_ptr()); + assert!(idx < n); ffi::gst_query_remove_nth_allocation_meta(self.0.as_mut_ptr(), idx); } }