From 03d4d916f5d48ccf15c6bb0bef86e55a1b4f0ae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chanal?= Date: Tue, 5 Apr 2022 16:02:32 +0200 Subject: [PATCH] Error out on EOS event if no src pad exist This let the application get an error message when ndisrc emits an EOS triggered by 'connect-timeout' for instance. Without this, a simple gst-launch-1.0 ndisrc pad-name="badname" connect-timeout=1000 ! ndisrcdemux ! fakesink will block. --- src/ndisrcdemux/imp.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/ndisrcdemux/imp.rs b/src/ndisrcdemux/imp.rs index 47ca9c5d..a9589a75 100644 --- a/src/ndisrcdemux/imp.rs +++ b/src/ndisrcdemux/imp.rs @@ -48,6 +48,13 @@ impl ObjectSubclass for NdiSrcDemux { |self_, element| self_.sink_chain(pad, element, buffer), ) }) + .event_function(|pad, parent, event| { + NdiSrcDemux::catch_panic_pad_function( + parent, + || false, + |self_, element| self_.sink_event(pad, element, event), + ) + }) .build(); Self { @@ -280,4 +287,26 @@ impl NdiSrcDemux { let mut state = self.state.lock().unwrap(); state.combiner.update_pad_flow(&srcpad, res) } + + fn sink_event(&self, + pad: &gst::Pad, + element: &super::NdiSrcDemux, + event: gst::Event + ) -> bool { + use gst::EventView; + + gst_log!(CAT, obj: pad, "Handling event {:?}", event); + if let EventView::Eos(_) = event.view() { + if element.num_src_pads() == 0 { + // error out on EOS if no src pad are available + gst::element_error!( + element, + gst::StreamError::Demux, + ["EOS without available srcpad(s)"] + ); + } + } + pad.event_default(Some(element), event) + } + }