From ccdb704ca805d922ddf77ef8dd2a3cbb8a167927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 8 Apr 2020 15:34:19 +0300 Subject: [PATCH] fallbackswitch: Update aggregator and aggregator bindings from gstreamer git master --- utils/fallbackswitch/src/base/aggregator.rs | 20 +++++++++-- .../src/base/auto/aggregator.rs | 2 ++ utils/fallbackswitch/src/base/gstaggregator.c | 36 ++++++++++++++++--- utils/fallbackswitch/src/base/gstaggregator.h | 5 ++- .../src/base/subclass/aggregator.rs | 28 ++++++--------- utils/fallbackswitch/src/fallbackswitch.rs | 4 +-- 6 files changed, 67 insertions(+), 28 deletions(-) diff --git a/utils/fallbackswitch/src/base/aggregator.rs b/utils/fallbackswitch/src/base/aggregator.rs index d6ac7fa6..fe2866f4 100644 --- a/utils/fallbackswitch/src/base/aggregator.rs +++ b/utils/fallbackswitch/src/base/aggregator.rs @@ -15,9 +15,12 @@ use glib::IsA; use glib::Value; use gst; use std::boxed::Box as Box_; -use std::mem::transmute; +use std::mem; +use std::ptr; pub trait AggregatorExtManual: 'static { + fn get_allocator(&self) -> (Option, gst::AllocationParams); + fn finish_buffer(&self, buffer: gst::Buffer) -> Result; fn get_property_min_upstream_latency(&self) -> gst::ClockTime; @@ -30,6 +33,19 @@ pub trait AggregatorExtManual: 'static { } impl> AggregatorExtManual for O { + fn get_allocator(&self) -> (Option, gst::AllocationParams) { + unsafe { + let mut allocator = ptr::null_mut(); + let mut params = mem::zeroed(); + gst_base_sys::gst_aggregator_get_allocator( + self.as_ref().to_glib_none().0, + &mut allocator, + &mut params, + ); + (from_glib_full(allocator), params.into()) + } + } + fn finish_buffer(&self, buffer: gst::Buffer) -> Result { let ret: gst::FlowReturn = unsafe { from_glib(gst_base_sys::gst_aggregator_finish_buffer( @@ -74,7 +90,7 @@ impl> AggregatorExtManual for O { connect_raw( self.as_ptr() as *mut _, b"notify::min-upstream-latency\0".as_ptr() as *const _, - Some(transmute( + Some(mem::transmute( notify_min_upstream_latency_trampoline:: as usize, )), Box_::into_raw(f), diff --git a/utils/fallbackswitch/src/base/auto/aggregator.rs b/utils/fallbackswitch/src/base/auto/aggregator.rs index 912892ee..6ceefd3d 100644 --- a/utils/fallbackswitch/src/base/auto/aggregator.rs +++ b/utils/fallbackswitch/src/base/auto/aggregator.rs @@ -30,6 +30,8 @@ unsafe impl Sync for Aggregator {} pub const NONE_AGGREGATOR: Option<&Aggregator> = None; pub trait AggregatorExt: 'static { + //fn get_allocator(&self, allocator: /*Ignored*/gst::Allocator, params: /*Ignored*/gst::AllocationParams); + fn get_buffer_pool(&self) -> Option; fn get_latency(&self) -> gst::ClockTime; diff --git a/utils/fallbackswitch/src/base/gstaggregator.c b/utils/fallbackswitch/src/base/gstaggregator.c index 06389895..aaf61226 100644 --- a/utils/fallbackswitch/src/base/gstaggregator.c +++ b/utils/fallbackswitch/src/base/gstaggregator.c @@ -404,7 +404,7 @@ gst_aggregator_pad_queue_is_empty (GstAggregatorPad * pad) * if at least one of the pads has an event or query at the top of its queue. * * Only returns TRUE if all non-EOS pads have a buffer available at the top of - * their queue + * their queue or a clipped buffer already. */ static gboolean gst_aggregator_check_pads_ready (GstAggregator * self, @@ -521,6 +521,9 @@ gst_aggregator_reset_flow_values (GstAggregator * self) self->priv->send_segment = TRUE; gst_segment_init (&GST_AGGREGATOR_PAD (self->srcpad)->segment, GST_FORMAT_TIME); + /* Initialize to -1 so we set it to the start position once the first buffer + * is handled in gst_aggregator_pad_chain_internal() */ + GST_AGGREGATOR_PAD (self->srcpad)->segment.position = -1; self->priv->first_buffer = TRUE; GST_OBJECT_UNLOCK (self); } @@ -774,7 +777,7 @@ gst_aggregator_wait_and_check (GstAggregator * self, gboolean * timeout) } } - res = gst_aggregator_check_pads_ready (self, &have_event_or_query); + res = gst_aggregator_check_pads_ready (self, NULL); SRC_UNLOCK (self); return res; @@ -1631,7 +1634,7 @@ eat: * The queued events with be handled from the src-pad task in * gst_aggregator_do_events_and_queries(). */ -static gboolean +static GstFlowReturn gst_aggregator_default_sink_event_pre_queue (GstAggregator * self, GstAggregatorPad * aggpad, GstEvent * event) { @@ -3077,8 +3080,7 @@ gst_aggregator_pad_class_init (GstAggregatorPadClass * klass) */ gst_aggregator_pad_signals[PAD_SIGNAL_BUFFER_CONSUMED] = g_signal_new ("buffer-consumed", G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST, 0, NULL, NULL, g_cclosure_marshal_generic, - G_TYPE_NONE, 1, GST_TYPE_BUFFER); + G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, GST_TYPE_BUFFER); /** * GstAggregatorPad:emit-signals: @@ -3463,3 +3465,27 @@ gst_aggregator_simple_get_next_time (GstAggregator * self) return next_time; } + +/** + * gst_aggregator_update_segment: + * + * Subclasses should use this to update the segment on their + * source pad, instead of directly pushing new segment events + * downstream. + * + * Since: 1.18 + */ +void +gst_aggregator_update_segment (GstAggregator * self, GstSegment * segment) +{ + g_return_if_fail (GST_IS_AGGREGATOR (self)); + g_return_if_fail (segment != NULL); + + GST_INFO_OBJECT (self, "Updating srcpad segment: %" GST_SEGMENT_FORMAT, + segment); + + GST_OBJECT_LOCK (self); + GST_AGGREGATOR_PAD (self->srcpad)->segment = *segment; + self->priv->send_segment = TRUE; + GST_OBJECT_UNLOCK (self); +} diff --git a/utils/fallbackswitch/src/base/gstaggregator.h b/utils/fallbackswitch/src/base/gstaggregator.h index b8f4216e..100f291c 100644 --- a/utils/fallbackswitch/src/base/gstaggregator.h +++ b/utils/fallbackswitch/src/base/gstaggregator.h @@ -321,7 +321,7 @@ struct _GstAggregatorClass { gboolean (*negotiate) (GstAggregator * self); - gboolean (*sink_event_pre_queue) (GstAggregator * aggregator, + GstFlowReturn (*sink_event_pre_queue) (GstAggregator * aggregator, GstAggregatorPad * aggregator_pad, GstEvent * event); @@ -384,6 +384,9 @@ void gst_aggregator_get_allocator (GstAggregator GST_BASE_API GstClockTime gst_aggregator_simple_get_next_time (GstAggregator * self); +GST_BASE_API +void gst_aggregator_update_segment (GstAggregator * self, + GstSegment * segment); G_END_DECLS diff --git a/utils/fallbackswitch/src/base/subclass/aggregator.rs b/utils/fallbackswitch/src/base/subclass/aggregator.rs index 5f8e2744..08860100 100644 --- a/utils/fallbackswitch/src/base/subclass/aggregator.rs +++ b/utils/fallbackswitch/src/base/subclass/aggregator.rs @@ -61,7 +61,7 @@ pub trait AggregatorImpl: AggregatorImplExt + ElementImpl + Send + Sync + 'stati aggregator: &Aggregator, aggregator_pad: &AggregatorPad, event: gst::Event, - ) -> bool { + ) -> Result { self.parent_sink_event_pre_queue(aggregator, aggregator_pad, event) } @@ -181,7 +181,7 @@ pub trait AggregatorImplExt { aggregator: &Aggregator, aggregator_pad: &AggregatorPad, event: gst::Event, - ) -> bool; + ) -> Result; fn parent_sink_query( &self, @@ -323,7 +323,7 @@ impl AggregatorImplExt for T { aggregator: &Aggregator, aggregator_pad: &AggregatorPad, event: gst::Event, - ) -> bool { + ) -> Result { unsafe { let data = self.get_type_data(); let parent_class = @@ -331,11 +331,12 @@ impl AggregatorImplExt for T { let f = (*parent_class) .sink_event_pre_queue .expect("Missing parent function `sink_event_pre_queue`"); - from_glib(f( + gst::FlowReturn::from_glib(f( aggregator.to_glib_none().0, aggregator_pad.to_glib_none().0, event.into_ptr(), )) + .into_result() } } @@ -712,7 +713,7 @@ unsafe extern "C" fn aggregator_sink_event_pre_queue( ptr: *mut gst_base_sys::GstAggregator, aggregator_pad: *mut gst_base_sys::GstAggregatorPad, event: *mut gst_sys::GstEvent, -) -> glib_sys::gboolean +) -> gst_sys::GstFlowReturn where T: AggregatorImpl, T::Instance: PanicPoison, @@ -721,12 +722,13 @@ where let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - gst_panic_to_error!(&wrap, &instance.panicked(), false, { + gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, { imp.sink_event_pre_queue( &wrap, &from_glib_borrow(aggregator_pad), from_glib_full(event), ) + .into() }) .to_glib() } @@ -934,22 +936,12 @@ where let wrap: Borrowed = from_glib_borrow(ptr); gst_panic_to_error!(&wrap, &instance.panicked(), None, { - let req_name: Option = from_glib_none(req_name); - - // FIXME: Easier way to convert Option to Option<&str>? - let mut _tmp = String::new(); - let req_name = match req_name { - Some(n) => { - _tmp = n; - Some(_tmp.as_str()) - } - None => None, - }; + let req_name: Borrowed> = from_glib_borrow(req_name); imp.create_new_pad( &wrap, &from_glib_borrow(templ), - req_name, + req_name.as_ref().as_ref().map(|s| s.as_str()), Option::::from_glib_borrow(caps) .as_ref() .as_ref(), diff --git a/utils/fallbackswitch/src/fallbackswitch.rs b/utils/fallbackswitch/src/fallbackswitch.rs index 2faafe85..7a317c7c 100644 --- a/utils/fallbackswitch/src/fallbackswitch.rs +++ b/utils/fallbackswitch/src/fallbackswitch.rs @@ -547,13 +547,13 @@ impl AggregatorImpl for FallbackSwitch { agg: &gst_base::Aggregator, agg_pad: &gst_base::AggregatorPad, event: gst::Event, - ) -> bool { + ) -> Result { use gst::EventView; match event.view() { EventView::Gap(_) => { gst_debug!(CAT, obj: agg_pad, "Dropping gap event"); - true + Ok(gst::FlowSuccess::Ok) } _ => self.parent_sink_event_pre_queue(agg, agg_pad, event), }