base: Add support for propose_allocation()/decide_allocation() in the base classes

This commit is contained in:
Sebastian Dröge 2021-10-16 13:53:57 +03:00
parent b9cd38b796
commit 7e71c74505
4 changed files with 400 additions and 0 deletions

View file

@ -149,6 +149,24 @@ pub trait AggregatorImpl: AggregatorImplExt + ElementImpl {
self.parent_negotiated_src_caps(aggregator, caps) self.parent_negotiated_src_caps(aggregator, caps)
} }
fn propose_allocation(
&self,
element: &Self::Type,
pad: &AggregatorPad,
decide_query: &gst::QueryRef,
query: &mut gst::QueryRef,
) -> Result<(), gst::ErrorMessage> {
self.parent_propose_allocation(element, pad, decide_query, query)
}
fn decide_allocation(
&self,
element: &Self::Type,
query: &mut gst::QueryRef,
) -> Result<(), gst::ErrorMessage> {
self.parent_decide_allocation(element, query)
}
#[cfg(any(feature = "v1_18", feature = "dox"))] #[cfg(any(feature = "v1_18", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
fn negotiate(&self, aggregator: &Self::Type) -> bool { fn negotiate(&self, aggregator: &Self::Type) -> bool {
@ -267,6 +285,20 @@ pub trait AggregatorImplExt: ObjectSubclass {
caps: &gst::Caps, caps: &gst::Caps,
) -> Result<(), gst::LoggableError>; ) -> Result<(), gst::LoggableError>;
fn parent_propose_allocation(
&self,
element: &Self::Type,
pad: &AggregatorPad,
decide_query: &gst::QueryRef,
query: &mut gst::QueryRef,
) -> Result<(), gst::ErrorMessage>;
fn parent_decide_allocation(
&self,
element: &Self::Type,
query: &mut gst::QueryRef,
) -> Result<(), gst::ErrorMessage>;
#[cfg(any(feature = "v1_18", feature = "dox"))] #[cfg(any(feature = "v1_18", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
fn parent_negotiate(&self, aggregator: &Self::Type) -> bool; fn parent_negotiate(&self, aggregator: &Self::Type) -> bool;
@ -656,6 +688,64 @@ impl<T: AggregatorImpl> AggregatorImplExt for T {
} }
} }
fn parent_propose_allocation(
&self,
element: &Self::Type,
pad: &AggregatorPad,
decide_query: &gst::QueryRef,
query: &mut gst::QueryRef,
) -> Result<(), gst::ErrorMessage> {
unsafe {
let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAggregatorClass;
(*parent_class)
.propose_allocation
.map(|f| {
if from_glib(f(
element.unsafe_cast_ref::<Aggregator>().to_glib_none().0,
pad.to_glib_none().0,
decide_query.as_mut_ptr(),
query.as_mut_ptr(),
)) {
Ok(())
} else {
Err(gst::error_msg!(
gst::CoreError::StateChange,
["Parent function `propose_allocation` failed"]
))
}
})
.unwrap_or(Ok(()))
}
}
fn parent_decide_allocation(
&self,
element: &Self::Type,
query: &mut gst::QueryRef,
) -> Result<(), gst::ErrorMessage> {
unsafe {
let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAggregatorClass;
(*parent_class)
.decide_allocation
.map(|f| {
if from_glib(f(
element.unsafe_cast_ref::<Aggregator>().to_glib_none().0,
query.as_mut_ptr(),
)) {
Ok(())
} else {
Err(gst::error_msg!(
gst::CoreError::StateChange,
["Parent function `decide_allocation` failed"]
))
}
})
.unwrap_or(Ok(()))
}
}
#[cfg(any(feature = "v1_18", feature = "dox"))] #[cfg(any(feature = "v1_18", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
fn parent_negotiate(&self, aggregator: &Self::Type) -> bool { fn parent_negotiate(&self, aggregator: &Self::Type) -> bool {
@ -717,6 +807,8 @@ unsafe impl<T: AggregatorImpl> IsSubclassable<T> for Aggregator {
klass.update_src_caps = Some(aggregator_update_src_caps::<T>); klass.update_src_caps = Some(aggregator_update_src_caps::<T>);
klass.fixate_src_caps = Some(aggregator_fixate_src_caps::<T>); klass.fixate_src_caps = Some(aggregator_fixate_src_caps::<T>);
klass.negotiated_src_caps = Some(aggregator_negotiated_src_caps::<T>); klass.negotiated_src_caps = Some(aggregator_negotiated_src_caps::<T>);
klass.propose_allocation = Some(aggregator_propose_allocation::<T>);
klass.decide_allocation = Some(aggregator_decide_allocation::<T>);
#[cfg(any(feature = "v1_18", feature = "dox"))] #[cfg(any(feature = "v1_18", feature = "dox"))]
{ {
klass.sink_event_pre_queue = Some(aggregator_sink_event_pre_queue::<T>); klass.sink_event_pre_queue = Some(aggregator_sink_event_pre_queue::<T>);
@ -1075,6 +1167,56 @@ unsafe extern "C" fn aggregator_negotiated_src_caps<T: AggregatorImpl>(
.into_glib() .into_glib()
} }
unsafe extern "C" fn aggregator_propose_allocation<T: AggregatorImpl>(
ptr: *mut ffi::GstAggregator,
pad: *mut ffi::GstAggregatorPad,
decide_query: *mut gst::ffi::GstQuery,
query: *mut gst::ffi::GstQuery,
) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance);
let imp = instance.impl_();
let wrap: Borrowed<Aggregator> = from_glib_borrow(ptr);
let decide_query = gst::QueryRef::from_ptr(decide_query);
let query = gst::QueryRef::from_mut_ptr(query);
gst::panic_to_error!(&wrap, imp.panicked(), false, {
match imp.propose_allocation(
wrap.unsafe_cast_ref(),
&from_glib_borrow(pad),
decide_query,
query,
) {
Ok(()) => true,
Err(err) => {
wrap.post_error_message(err);
false
}
}
})
.into_glib()
}
unsafe extern "C" fn aggregator_decide_allocation<T: AggregatorImpl>(
ptr: *mut ffi::GstAggregator,
query: *mut gst::ffi::GstQuery,
) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance);
let imp = instance.impl_();
let wrap: Borrowed<Aggregator> = from_glib_borrow(ptr);
let query = gst::QueryRef::from_mut_ptr(query);
gst::panic_to_error!(&wrap, imp.panicked(), false, {
match imp.decide_allocation(wrap.unsafe_cast_ref(), query) {
Ok(()) => true,
Err(err) => {
wrap.post_error_message(err);
false
}
}
})
.into_glib()
}
#[cfg(any(feature = "v1_18", feature = "dox"))] #[cfg(any(feature = "v1_18", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
unsafe extern "C" fn aggregator_negotiate<T: AggregatorImpl>( unsafe extern "C" fn aggregator_negotiate<T: AggregatorImpl>(

View file

@ -77,6 +77,14 @@ pub trait BaseSinkImpl: BaseSinkImplExt + ElementImpl {
fn unlock_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn unlock_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> {
self.parent_unlock_stop(element) self.parent_unlock_stop(element)
} }
fn propose_allocation(
&self,
element: &Self::Type,
query: &mut gst::QueryRef,
) -> Result<(), gst::ErrorMessage> {
self.parent_propose_allocation(element, query)
}
} }
pub trait BaseSinkImplExt: ObjectSubclass { pub trait BaseSinkImplExt: ObjectSubclass {
@ -125,6 +133,12 @@ pub trait BaseSinkImplExt: ObjectSubclass {
fn parent_unlock(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>; fn parent_unlock(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>;
fn parent_unlock_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>; fn parent_unlock_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>;
fn parent_propose_allocation(
&self,
element: &Self::Type,
query: &mut gst::QueryRef,
) -> Result<(), gst::ErrorMessage>;
} }
impl<T: BaseSinkImpl> BaseSinkImplExt for T { impl<T: BaseSinkImpl> BaseSinkImplExt for T {
@ -385,6 +399,33 @@ impl<T: BaseSinkImpl> BaseSinkImplExt for T {
.unwrap_or(Ok(())) .unwrap_or(Ok(()))
} }
} }
fn parent_propose_allocation(
&self,
element: &Self::Type,
query: &mut gst::QueryRef,
) -> Result<(), gst::ErrorMessage> {
unsafe {
let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass;
(*parent_class)
.propose_allocation
.map(|f| {
if from_glib(f(
element.unsafe_cast_ref::<BaseSink>().to_glib_none().0,
query.as_mut_ptr(),
)) {
Ok(())
} else {
Err(gst::error_msg!(
gst::CoreError::StateChange,
["Parent function `propose_allocation` failed"]
))
}
})
.unwrap_or(Ok(()))
}
}
} }
unsafe impl<T: BaseSinkImpl> IsSubclassable<T> for BaseSink { unsafe impl<T: BaseSinkImpl> IsSubclassable<T> for BaseSink {
@ -404,6 +445,7 @@ unsafe impl<T: BaseSinkImpl> IsSubclassable<T> for BaseSink {
klass.fixate = Some(base_sink_fixate::<T>); klass.fixate = Some(base_sink_fixate::<T>);
klass.unlock = Some(base_sink_unlock::<T>); klass.unlock = Some(base_sink_unlock::<T>);
klass.unlock_stop = Some(base_sink_unlock_stop::<T>); klass.unlock_stop = Some(base_sink_unlock_stop::<T>);
klass.propose_allocation = Some(base_sink_propose_allocation::<T>);
} }
fn instance_init(instance: &mut glib::subclass::InitializingObject<T>) { fn instance_init(instance: &mut glib::subclass::InitializingObject<T>) {
@ -627,3 +669,24 @@ unsafe extern "C" fn base_sink_unlock_stop<T: BaseSinkImpl>(
}) })
.into_glib() .into_glib()
} }
unsafe extern "C" fn base_sink_propose_allocation<T: BaseSinkImpl>(
ptr: *mut ffi::GstBaseSink,
query: *mut gst::ffi::GstQuery,
) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance);
let imp = instance.impl_();
let wrap: Borrowed<BaseSink> = from_glib_borrow(ptr);
let query = gst::QueryRef::from_mut_ptr(query);
gst::panic_to_error!(&wrap, imp.panicked(), false, {
match imp.propose_allocation(wrap.unsafe_cast_ref(), query) {
Ok(()) => true,
Err(err) => {
wrap.post_error_message(err);
false
}
}
})
.into_glib()
}

View file

@ -107,6 +107,14 @@ pub trait BaseSrcImpl: BaseSrcImplExt + ElementImpl {
fn unlock_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn unlock_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> {
self.parent_unlock_stop(element) self.parent_unlock_stop(element)
} }
fn decide_allocation(
&self,
element: &Self::Type,
query: &mut gst::QueryRef,
) -> Result<(), gst::ErrorMessage> {
self.parent_decide_allocation(element, query)
}
} }
pub trait BaseSrcImplExt: ObjectSubclass { pub trait BaseSrcImplExt: ObjectSubclass {
@ -168,6 +176,12 @@ pub trait BaseSrcImplExt: ObjectSubclass {
fn parent_unlock(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>; fn parent_unlock(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>;
fn parent_unlock_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>; fn parent_unlock_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>;
fn parent_decide_allocation(
&self,
element: &Self::Type,
query: &mut gst::QueryRef,
) -> Result<(), gst::ErrorMessage>;
} }
impl<T: BaseSrcImpl> BaseSrcImplExt for T { impl<T: BaseSrcImpl> BaseSrcImplExt for T {
@ -569,6 +583,33 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
.unwrap_or(Ok(())) .unwrap_or(Ok(()))
} }
} }
fn parent_decide_allocation(
&self,
element: &Self::Type,
query: &mut gst::QueryRef,
) -> Result<(), gst::ErrorMessage> {
unsafe {
let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSrcClass;
(*parent_class)
.decide_allocation
.map(|f| {
if from_glib(f(
element.unsafe_cast_ref::<BaseSrc>().to_glib_none().0,
query.as_mut_ptr(),
)) {
Ok(())
} else {
Err(gst::error_msg!(
gst::CoreError::StateChange,
["Parent function `decide_allocation` failed"]
))
}
})
.unwrap_or(Ok(()))
}
}
} }
unsafe impl<T: BaseSrcImpl> IsSubclassable<T> for BaseSrc { unsafe impl<T: BaseSrcImpl> IsSubclassable<T> for BaseSrc {
@ -592,6 +633,7 @@ unsafe impl<T: BaseSrcImpl> IsSubclassable<T> for BaseSrc {
klass.fixate = Some(base_src_fixate::<T>); klass.fixate = Some(base_src_fixate::<T>);
klass.unlock = Some(base_src_unlock::<T>); klass.unlock = Some(base_src_unlock::<T>);
klass.unlock_stop = Some(base_src_unlock_stop::<T>); klass.unlock_stop = Some(base_src_unlock_stop::<T>);
klass.decide_allocation = Some(base_src_decide_allocation::<T>);
} }
fn instance_init(instance: &mut glib::subclass::InitializingObject<T>) { fn instance_init(instance: &mut glib::subclass::InitializingObject<T>) {
@ -975,3 +1017,24 @@ unsafe extern "C" fn base_src_unlock_stop<T: BaseSrcImpl>(
}) })
.into_glib() .into_glib()
} }
unsafe extern "C" fn base_src_decide_allocation<T: BaseSrcImpl>(
ptr: *mut ffi::GstBaseSrc,
query: *mut gst::ffi::GstQuery,
) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance);
let imp = instance.impl_();
let wrap: Borrowed<BaseSrc> = from_glib_borrow(ptr);
let query = gst::QueryRef::from_mut_ptr(query);
gst::panic_to_error!(&wrap, imp.panicked(), false, {
match imp.decide_allocation(wrap.unsafe_cast_ref(), query) {
Ok(()) => true,
Err(err) => {
wrap.post_error_message(err);
false
}
}
})
.into_glib()
}

View file

@ -135,6 +135,23 @@ pub trait BaseTransformImpl: BaseTransformImplExt + ElementImpl {
self.parent_transform_ip_passthrough(element, buf) self.parent_transform_ip_passthrough(element, buf)
} }
fn propose_allocation(
&self,
element: &Self::Type,
decide_query: &gst::QueryRef,
query: &mut gst::QueryRef,
) -> Result<(), gst::ErrorMessage> {
self.parent_propose_allocation(element, decide_query, query)
}
fn decide_allocation(
&self,
element: &Self::Type,
query: &mut gst::QueryRef,
) -> Result<(), gst::ErrorMessage> {
self.parent_decide_allocation(element, query)
}
fn copy_metadata( fn copy_metadata(
&self, &self,
element: &Self::Type, element: &Self::Type,
@ -257,6 +274,19 @@ pub trait BaseTransformImplExt: ObjectSubclass {
buf: &gst::Buffer, buf: &gst::Buffer,
) -> Result<gst::FlowSuccess, gst::FlowError>; ) -> Result<gst::FlowSuccess, gst::FlowError>;
fn parent_propose_allocation(
&self,
element: &Self::Type,
decide_query: &gst::QueryRef,
query: &mut gst::QueryRef,
) -> Result<(), gst::ErrorMessage>;
fn parent_decide_allocation(
&self,
element: &Self::Type,
query: &mut gst::QueryRef,
) -> Result<(), gst::ErrorMessage>;
fn parent_copy_metadata( fn parent_copy_metadata(
&self, &self,
element: &Self::Type, element: &Self::Type,
@ -684,6 +714,62 @@ impl<T: BaseTransformImpl> BaseTransformImplExt for T {
} }
} }
fn parent_propose_allocation(
&self,
element: &Self::Type,
decide_query: &gst::QueryRef,
query: &mut gst::QueryRef,
) -> Result<(), gst::ErrorMessage> {
unsafe {
let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseTransformClass;
(*parent_class)
.propose_allocation
.map(|f| {
if from_glib(f(
element.unsafe_cast_ref::<BaseTransform>().to_glib_none().0,
decide_query.as_mut_ptr(),
query.as_mut_ptr(),
)) {
Ok(())
} else {
Err(gst::error_msg!(
gst::CoreError::StateChange,
["Parent function `propose_allocation` failed"]
))
}
})
.unwrap_or(Ok(()))
}
}
fn parent_decide_allocation(
&self,
element: &Self::Type,
query: &mut gst::QueryRef,
) -> Result<(), gst::ErrorMessage> {
unsafe {
let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseTransformClass;
(*parent_class)
.decide_allocation
.map(|f| {
if from_glib(f(
element.unsafe_cast_ref::<BaseTransform>().to_glib_none().0,
query.as_mut_ptr(),
)) {
Ok(())
} else {
Err(gst::error_msg!(
gst::CoreError::StateChange,
["Parent function `decide_allocation` failed"]
))
}
})
.unwrap_or(Ok(()))
}
}
fn parent_copy_metadata( fn parent_copy_metadata(
&self, &self,
element: &Self::Type, element: &Self::Type,
@ -846,6 +932,8 @@ unsafe impl<T: BaseTransformImpl> IsSubclassable<T> for BaseTransform {
klass.sink_event = Some(base_transform_sink_event::<T>); klass.sink_event = Some(base_transform_sink_event::<T>);
klass.src_event = Some(base_transform_src_event::<T>); klass.src_event = Some(base_transform_src_event::<T>);
klass.transform_meta = Some(base_transform_transform_meta::<T>); klass.transform_meta = Some(base_transform_transform_meta::<T>);
klass.propose_allocation = Some(base_transform_propose_allocation::<T>);
klass.decide_allocation = Some(base_transform_decide_allocation::<T>);
klass.copy_metadata = Some(base_transform_copy_metadata::<T>); klass.copy_metadata = Some(base_transform_copy_metadata::<T>);
klass.before_transform = Some(base_transform_before_transform::<T>); klass.before_transform = Some(base_transform_before_transform::<T>);
klass.submit_input_buffer = Some(base_transform_submit_input_buffer::<T>); klass.submit_input_buffer = Some(base_transform_submit_input_buffer::<T>);
@ -1231,6 +1319,50 @@ unsafe extern "C" fn base_transform_transform_meta<T: BaseTransformImpl>(
.into_glib() .into_glib()
} }
unsafe extern "C" fn base_transform_propose_allocation<T: BaseTransformImpl>(
ptr: *mut ffi::GstBaseTransform,
decide_query: *mut gst::ffi::GstQuery,
query: *mut gst::ffi::GstQuery,
) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance);
let imp = instance.impl_();
let wrap: Borrowed<BaseTransform> = from_glib_borrow(ptr);
let decide_query = gst::QueryRef::from_ptr(decide_query);
let query = gst::QueryRef::from_mut_ptr(query);
gst::panic_to_error!(&wrap, imp.panicked(), false, {
match imp.propose_allocation(wrap.unsafe_cast_ref(), decide_query, query) {
Ok(()) => true,
Err(err) => {
wrap.post_error_message(err);
false
}
}
})
.into_glib()
}
unsafe extern "C" fn base_transform_decide_allocation<T: BaseTransformImpl>(
ptr: *mut ffi::GstBaseTransform,
query: *mut gst::ffi::GstQuery,
) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance);
let imp = instance.impl_();
let wrap: Borrowed<BaseTransform> = from_glib_borrow(ptr);
let query = gst::QueryRef::from_mut_ptr(query);
gst::panic_to_error!(&wrap, imp.panicked(), false, {
match imp.decide_allocation(wrap.unsafe_cast_ref(), query) {
Ok(()) => true,
Err(err) => {
wrap.post_error_message(err);
false
}
}
})
.into_glib()
}
unsafe extern "C" fn base_transform_copy_metadata<T: BaseTransformImpl>( unsafe extern "C" fn base_transform_copy_metadata<T: BaseTransformImpl>(
ptr: *mut ffi::GstBaseTransform, ptr: *mut ffi::GstBaseTransform,
inbuf: *mut gst::ffi::GstBuffer, inbuf: *mut gst::ffi::GstBuffer,