From dc7e705f44df058f9153a5ac020a9e92263558de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sat, 16 Oct 2021 15:36:20 +0300 Subject: [PATCH] base: decide_query in Aggregator/BaseTransform propose_allocation() is nullable --- gstreamer-base/src/subclass/aggregator.rs | 21 ++++++++++++------- gstreamer-base/src/subclass/base_transform.rs | 21 ++++++++++++------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/gstreamer-base/src/subclass/aggregator.rs b/gstreamer-base/src/subclass/aggregator.rs index bb3302a54..84d429cbe 100644 --- a/gstreamer-base/src/subclass/aggregator.rs +++ b/gstreamer-base/src/subclass/aggregator.rs @@ -153,7 +153,7 @@ pub trait AggregatorImpl: AggregatorImplExt + ElementImpl { &self, element: &Self::Type, pad: &AggregatorPad, - decide_query: gst::query::Allocation<&gst::QueryRef>, + decide_query: Option>, query: gst::query::Allocation<&mut gst::QueryRef>, ) -> Result<(), gst::ErrorMessage> { self.parent_propose_allocation(element, pad, decide_query, query) @@ -289,7 +289,7 @@ pub trait AggregatorImplExt: ObjectSubclass { &self, element: &Self::Type, pad: &AggregatorPad, - decide_query: gst::query::Allocation<&gst::QueryRef>, + decide_query: Option>, query: gst::query::Allocation<&mut gst::QueryRef>, ) -> Result<(), gst::ErrorMessage>; @@ -692,7 +692,7 @@ impl AggregatorImplExt for T { &self, element: &Self::Type, pad: &AggregatorPad, - decide_query: gst::query::Allocation<&gst::QueryRef>, + decide_query: Option>, query: gst::query::Allocation<&mut gst::QueryRef>, ) -> Result<(), gst::ErrorMessage> { unsafe { @@ -704,7 +704,10 @@ impl AggregatorImplExt for T { if from_glib(f( element.unsafe_cast_ref::().to_glib_none().0, pad.to_glib_none().0, - decide_query.as_mut_ptr(), + decide_query + .as_ref() + .map(|q| q.as_mut_ptr()) + .unwrap_or(ptr::null_mut()), query.as_mut_ptr(), )) { Ok(()) @@ -1176,9 +1179,13 @@ unsafe extern "C" fn aggregator_propose_allocation( let instance = &*(ptr as *mut T::Instance); let imp = instance.impl_(); let wrap: Borrowed = from_glib_borrow(ptr); - let decide_query = match gst::QueryRef::from_ptr(decide_query).view() { - gst::QueryView::Allocation(allocation) => allocation, - _ => unreachable!(), + let decide_query = if decide_query.is_null() { + None + } else { + match gst::QueryRef::from_ptr(decide_query).view() { + gst::QueryView::Allocation(allocation) => Some(allocation), + _ => unreachable!(), + } }; let query = match gst::QueryRef::from_mut_ptr(query).view_mut() { gst::QueryView::Allocation(allocation) => allocation, diff --git a/gstreamer-base/src/subclass/base_transform.rs b/gstreamer-base/src/subclass/base_transform.rs index 0679c9f97..8d8d8b5f7 100644 --- a/gstreamer-base/src/subclass/base_transform.rs +++ b/gstreamer-base/src/subclass/base_transform.rs @@ -138,7 +138,7 @@ pub trait BaseTransformImpl: BaseTransformImplExt + ElementImpl { fn propose_allocation( &self, element: &Self::Type, - decide_query: gst::query::Allocation<&gst::QueryRef>, + decide_query: Option>, query: gst::query::Allocation<&mut gst::QueryRef>, ) -> Result<(), gst::ErrorMessage> { self.parent_propose_allocation(element, decide_query, query) @@ -277,7 +277,7 @@ pub trait BaseTransformImplExt: ObjectSubclass { fn parent_propose_allocation( &self, element: &Self::Type, - decide_query: gst::query::Allocation<&gst::QueryRef>, + decide_query: Option>, query: gst::query::Allocation<&mut gst::QueryRef>, ) -> Result<(), gst::ErrorMessage>; @@ -717,7 +717,7 @@ impl BaseTransformImplExt for T { fn parent_propose_allocation( &self, element: &Self::Type, - decide_query: gst::query::Allocation<&gst::QueryRef>, + decide_query: Option>, query: gst::query::Allocation<&mut gst::QueryRef>, ) -> Result<(), gst::ErrorMessage> { unsafe { @@ -728,7 +728,10 @@ impl BaseTransformImplExt for T { .map(|f| { if from_glib(f( element.unsafe_cast_ref::().to_glib_none().0, - decide_query.as_mut_ptr(), + decide_query + .as_ref() + .map(|q| q.as_mut_ptr()) + .unwrap_or(ptr::null_mut()), query.as_mut_ptr(), )) { Ok(()) @@ -1327,9 +1330,13 @@ unsafe extern "C" fn base_transform_propose_allocation( let instance = &*(ptr as *mut T::Instance); let imp = instance.impl_(); let wrap: Borrowed = from_glib_borrow(ptr); - let decide_query = match gst::QueryRef::from_ptr(decide_query).view() { - gst::QueryView::Allocation(allocation) => allocation, - _ => unreachable!(), + let decide_query = if decide_query.is_null() { + None + } else { + match gst::QueryRef::from_ptr(decide_query).view() { + gst::QueryView::Allocation(allocation) => Some(allocation), + _ => unreachable!(), + } }; let query = match gst::QueryRef::from_mut_ptr(query).view_mut() { gst::QueryView::Allocation(allocation) => allocation,