From 6d88e1877240084b249917fc91517fc21f57aec9 Mon Sep 17 00:00:00 2001 From: Philippe Normand Date: Tue, 12 Oct 2021 15:46:41 +0100 Subject: [PATCH] gstreamer: Add bindings for querying allocation params This can be used to query downstream for custom allocators. --- gstreamer/src/allocation_params.rs | 8 ++++ gstreamer/src/query.rs | 66 ++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/gstreamer/src/allocation_params.rs b/gstreamer/src/allocation_params.rs index 27d461f70..256c23f87 100644 --- a/gstreamer/src/allocation_params.rs +++ b/gstreamer/src/allocation_params.rs @@ -69,3 +69,11 @@ impl<'a> ToGlibPtr<'a, *const ffi::GstAllocationParams> for AllocationParams { Stash(&self.0, self) } } + +impl FromGlib for AllocationParams { + #[allow(unused_unsafe)] + unsafe fn from_glib(value: ffi::GstAllocationParams) -> Self { + assert_initialized_main_thread!(); + AllocationParams(value) + } +} diff --git a/gstreamer/src/query.rs b/gstreamer/src/query.rs index dadd1b39a..fe109ea17 100644 --- a/gstreamer/src/query.rs +++ b/gstreamer/src/query.rs @@ -9,6 +9,7 @@ use std::mem; use std::ops::{Deref, DerefMut}; use std::ptr; +use glib::object::IsA; use glib::translate::*; mini_object_wrapper!(Query, QueryRef, ffi::GstQuery, || { @@ -947,6 +948,28 @@ impl Allocation { } } + #[doc(alias = "gst_allocation_params")] + #[doc(alias = "gst_query_get_n_allocation_params")] + pub fn allocation_params(&self) -> Vec<(Option, crate::AllocationParams)> { + unsafe { + let n = ffi::gst_query_get_n_allocation_params(self.0.as_ptr()); + let mut params = Vec::with_capacity(n as usize); + for i in 0..n { + let mut allocator = ptr::null_mut(); + let mut p = mem::MaybeUninit::uninit(); + ffi::gst_query_parse_nth_allocation_param( + self.0.as_ptr(), + i, + &mut allocator, + p.as_mut_ptr(), + ); + params.push((from_glib_full(allocator), from_glib(p.assume_init()))); + } + + params + } + } + #[doc(alias = "get_allocation_pools")] #[doc(alias = "gst_query_get_n_allocation_pools")] pub fn allocation_pools(&self) -> Vec<(Option, u32, u32, u32)> { @@ -1070,6 +1093,49 @@ impl Allocation { } } + #[doc(alias = "gst_query_add_allocation_param")] + pub fn add_allocation_param( + &mut self, + allocator: Option<&impl IsA>, + params: crate::AllocationParams, + ) { + unsafe { + ffi::gst_query_add_allocation_param( + self.0.as_mut_ptr(), + allocator.to_glib_none().0 as *mut ffi::GstAllocator, + params.as_ptr(), + ); + } + } + + #[doc(alias = "gst_query_set_nth_allocation_param")] + pub fn set_nth_allocation_param( + &mut self, + idx: u32, + allocator: Option<&impl IsA>, + params: crate::AllocationParams, + ) { + unsafe { + let n = ffi::gst_query_get_n_allocation_params(self.0.as_ptr()); + assert!(idx < n); + ffi::gst_query_set_nth_allocation_param( + self.0.as_mut_ptr(), + idx, + allocator.to_glib_none().0 as *mut ffi::GstAllocator, + params.as_ptr(), + ); + } + } + + #[doc(alias = "gst_query_remove_nth_allocation_param")] + pub fn remove_nth_allocation_param(&mut self, idx: u32) { + unsafe { + let n = ffi::gst_query_get_n_allocation_params(self.0.as_ptr()); + assert!(idx < n); + ffi::gst_query_remove_nth_allocation_param(self.0.as_mut_ptr(), idx); + } + } + #[doc(alias = "gst_query_add_allocation_meta")] pub fn add_allocation_meta( &mut self,