Clean up usage of pad probes

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1361>
This commit is contained in:
Sebastian Dröge 2023-10-16 19:16:52 +03:00
parent 50dd519c4f
commit d468e1e4a6
7 changed files with 195 additions and 184 deletions

View file

@ -365,19 +365,21 @@ fn setup_appsink(appsink: &gst_app::AppSink, name: &str, path: &Path, is_video:
fn probe_encoder(state: Arc<Mutex<State>>, enc: gst::Element) { fn probe_encoder(state: Arc<Mutex<State>>, enc: gst::Element) {
enc.static_pad("src").unwrap().add_probe( enc.static_pad("src").unwrap().add_probe(
gst::PadProbeType::EVENT_DOWNSTREAM, gst::PadProbeType::EVENT_DOWNSTREAM,
move |_pad, info| match info.data { move |_pad, info| {
Some(gst::PadProbeData::Event(ref ev)) => match ev.view() { let Some(ev) = info.event() else {
gst::EventView::Caps(e) => { return gst::PadProbeReturn::Ok;
let mime = gst_pbutils::codec_utils_caps_get_mime_codec(e.caps()); };
let gst::EventView::Caps(ev) = ev.view() else {
return gst::PadProbeReturn::Ok;
};
let mime = gst_pbutils::codec_utils_caps_get_mime_codec(ev.caps());
let mut state = state.lock().unwrap(); let mut state = state.lock().unwrap();
state.all_mimes.push(mime.unwrap().into()); state.all_mimes.push(mime.unwrap().into());
state.maybe_write_manifest(); state.maybe_write_manifest();
gst::PadProbeReturn::Remove gst::PadProbeReturn::Remove
}
_ => gst::PadProbeReturn::Ok,
},
_ => gst::PadProbeReturn::Ok,
}, },
); );
} }

View file

@ -260,19 +260,21 @@ fn setup_appsink(appsink: &gst_app::AppSink, name: &str, path: &Path, is_video:
fn probe_encoder(state: Arc<Mutex<State>>, enc: gst::Element) { fn probe_encoder(state: Arc<Mutex<State>>, enc: gst::Element) {
enc.static_pad("src").unwrap().add_probe( enc.static_pad("src").unwrap().add_probe(
gst::PadProbeType::EVENT_DOWNSTREAM, gst::PadProbeType::EVENT_DOWNSTREAM,
move |_pad, info| match info.data { move |_pad, info| {
Some(gst::PadProbeData::Event(ref ev)) => match ev.view() { let Some(ev) = info.event() else {
gst::EventView::Caps(e) => { return gst::PadProbeReturn::Ok;
let mime = gst_pbutils::codec_utils_caps_get_mime_codec(e.caps()); };
let gst::EventView::Caps(ev) = ev.view() else {
return gst::PadProbeReturn::Ok;
};
let mime = gst_pbutils::codec_utils_caps_get_mime_codec(ev.caps());
let mut state = state.lock().unwrap(); let mut state = state.lock().unwrap();
state.all_mimes.push(mime.unwrap().into()); state.all_mimes.push(mime.unwrap().into());
state.maybe_write_manifest(); state.maybe_write_manifest();
gst::PadProbeReturn::Remove gst::PadProbeReturn::Remove
}
_ => gst::PadProbeReturn::Ok,
},
_ => gst::PadProbeReturn::Ok,
}, },
); );
} }

View file

@ -358,15 +358,20 @@ impl WebRTCSrc {
.build(); .build();
if self.settings.lock().unwrap().enable_data_channel_navigation { if self.settings.lock().unwrap().enable_data_channel_navigation {
pad.add_probe(gst::PadProbeType::EVENT_UPSTREAM, pad.add_probe(
gst::PadProbeType::EVENT_UPSTREAM,
glib::clone!(@weak self as this => @default-panic, move |_pad, info| { glib::clone!(@weak self as this => @default-panic, move |_pad, info| {
if let Some(gst::PadProbeData::Event(ref ev)) = info.data { let Some(ev) = info.event() else {
if let gst::EventView::Navigation(ev) = ev.view() { return gst::PadProbeReturn::Ok;
};
if ev.type_() != gst::EventType::Navigation {
return gst::PadProbeReturn::Ok;
};
this.send_navigation_event (gst_video::NavigationEvent::parse(ev).unwrap()); this.send_navigation_event (gst_video::NavigationEvent::parse(ev).unwrap());
}
}
gst::PadProbeReturn::Ok gst::PadProbeReturn::Ok
}) }),
); );
} }

View file

@ -1911,8 +1911,14 @@ impl FallbackSrc {
let imp = element.imp(); let imp = element.imp();
match info.data { let Some(ev) = info.event() else {
Some(gst::PadProbeData::Event(ref ev)) if ev.type_() == gst::EventType::Eos => { return gst::PadProbeReturn::Ok;
};
if ev.type_() != gst::EventType::Eos {
return gst::PadProbeReturn::Ok;
}
gst::debug!( gst::debug!(
CAT, CAT,
obj: element, obj: element,
@ -1949,8 +1955,7 @@ impl FallbackSrc {
state.audio_stream.as_ref() state.audio_stream.as_ref()
} }
} { } {
sinkpads sinkpads.extend(stream.switch.sink_pads().into_iter().filter(|p| p != pad));
.extend(stream.switch.sink_pads().into_iter().filter(|p| p != pad));
} }
if let Some(other_stream) = { if let Some(other_stream) = {
@ -1980,9 +1985,6 @@ impl FallbackSrc {
gst::PadProbeReturn::Ok gst::PadProbeReturn::Ok
} }
}
_ => gst::PadProbeReturn::Ok,
}
}); });
let queue_srcpad = queue.static_pad("src").unwrap(); let queue_srcpad = queue.static_pad("src").unwrap();
@ -2056,13 +2058,15 @@ impl FallbackSrc {
let qos_probe_id = block_pad let qos_probe_id = block_pad
.add_probe(gst::PadProbeType::EVENT_UPSTREAM, |_pad, info| { .add_probe(gst::PadProbeType::EVENT_UPSTREAM, |_pad, info| {
if let Some(gst::PadProbeData::Event(ref ev)) = info.data { let Some(ev) = info.event() else {
if let gst::EventView::Qos(_) = ev.view() { return gst::PadProbeReturn::Ok;
return gst::PadProbeReturn::Drop; };
}
if ev.type_() != gst::EventType::Qos {
return gst::PadProbeReturn::Ok;
} }
gst::PadProbeReturn::Ok gst::PadProbeReturn::Drop
}) })
.unwrap(); .unwrap();
@ -2871,19 +2875,17 @@ impl FallbackSrc {
// error. We don't need to remove these pad probes because restarting the source will also // error. We don't need to remove these pad probes because restarting the source will also
// remove/add the pads again. // remove/add the pads again.
for pad in source.source.src_pads() { for pad in source.source.src_pads() {
pad.add_probe( pad.add_probe(gst::PadProbeType::EVENT_DOWNSTREAM, |_pad, info| {
gst::PadProbeType::EVENT_DOWNSTREAM, let Some(ev) = info.event() else {
|_pad, info| match info.data { return gst::PadProbeReturn::Pass;
Some(gst::PadProbeData::Event(ref event)) => { };
if event.type_() == gst::EventType::Eos {
if ev.type_() != gst::EventType::Eos {
return gst::PadProbeReturn::Pass;
}
gst::PadProbeReturn::Drop gst::PadProbeReturn::Drop
} else { })
gst::PadProbeReturn::Ok
}
}
_ => unreachable!(),
},
)
.unwrap(); .unwrap();
} }

View file

@ -66,14 +66,12 @@ fn setup_sender_receiver(
sinkpad.add_probe( sinkpad.add_probe(
gst::PadProbeType::QUERY_UPSTREAM, gst::PadProbeType::QUERY_UPSTREAM,
move |_pad, probe_info| { move |_pad, probe_info| {
let query = match &mut probe_info.data { let Some(query) = probe_info.query_mut() else {
Some(gst::PadProbeData::Query(q)) => q, unreachable!();
_ => unreachable!(),
}; };
use gst::QueryViewMut::*;
match query.view_mut() { match query.view_mut() {
Latency(q) => { gst::QueryViewMut::Latency(q) => {
q.set(live, gst::ClockTime::ZERO, None); q.set(live, gst::ClockTime::ZERO, None);
gst::PadProbeReturn::Handled gst::PadProbeReturn::Handled
} }

View file

@ -1286,10 +1286,14 @@ impl UriPlaylistBin {
let src_pad_name = sync_sink.name().to_string().replace("sink", "src"); let src_pad_name = sync_sink.name().to_string().replace("sink", "src");
let sync_src = state.streamsynchronizer.static_pad(&src_pad_name).unwrap(); let sync_src = state.streamsynchronizer.static_pad(&src_pad_name).unwrap();
sync_src.add_probe(gst::PadProbeType::EVENT_DOWNSTREAM, move |_pad, info| { sync_src.add_probe(gst::PadProbeType::EVENT_DOWNSTREAM, move |_pad, info| {
match info.data { let Some(ev) = info.event() else {
Some(gst::PadProbeData::Event(ref ev)) return gst::PadProbeReturn::Pass;
if ev.type_() == gst::EventType::Eos => };
{
if ev.type_() != gst::EventType::Eos {
return gst::PadProbeReturn::Pass;
}
let element = match element_weak.upgrade() { let element = match element_weak.upgrade() {
Some(element) => element, Some(element) => element,
None => return gst::PadProbeReturn::Remove, None => return gst::PadProbeReturn::Remove,
@ -1313,9 +1317,6 @@ impl UriPlaylistBin {
} else { } else {
gst::PadProbeReturn::Pass gst::PadProbeReturn::Pass
} }
}
_ => gst::PadProbeReturn::Pass,
}
}); });
// ghost streamsynchronizer src pad // ghost streamsynchronizer src pad
@ -1434,10 +1435,14 @@ impl UriPlaylistBin {
gst::PadProbeReturn::Pass gst::PadProbeReturn::Pass
} else { } else {
match info.data { let Some(ev) = info.event() else {
Some(gst::PadProbeData::Event(ref ev)) return gst::PadProbeReturn::Pass;
if ev.type_() == gst::EventType::Eos => };
{
if ev.type_() != gst::EventType::Eos {
return gst::PadProbeReturn::Pass;
}
if item.dec_waiting_eos() { if item.dec_waiting_eos() {
// all the streams are eos, item is now done // all the streams are eos, item is now done
gst::log!( gst::log!(
@ -1473,9 +1478,6 @@ impl UriPlaylistBin {
gst::PadProbeReturn::Remove gst::PadProbeReturn::Remove
} }
_ => gst::PadProbeReturn::Pass,
}
}
}); });
if item.dec_n_pads_pending() == 0 { if item.dec_n_pads_pending() == 0 {

View file

@ -300,7 +300,7 @@ impl TranscriberBin {
return gst::PadProbeReturn::Pass; return gst::PadProbeReturn::Pass;
} }
if let Some(gst::PadProbeData::Buffer(buffer)) = &mut probe_info.data { if let Some(buffer) = probe_info.buffer_mut() {
let buffer = buffer.make_mut(); let buffer = buffer.make_mut();
while let Some(meta) = buffer.meta_mut::<gst_video::VideoCaptionMeta>() { while let Some(meta) = buffer.meta_mut::<gst_video::VideoCaptionMeta>() {
meta.remove().unwrap(); meta.remove().unwrap();