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) {
enc.static_pad("src").unwrap().add_probe(
gst::PadProbeType::EVENT_DOWNSTREAM,
move |_pad, info| match info.data {
Some(gst::PadProbeData::Event(ref ev)) => match ev.view() {
gst::EventView::Caps(e) => {
let mime = gst_pbutils::codec_utils_caps_get_mime_codec(e.caps());
move |_pad, info| {
let Some(ev) = info.event() else {
return gst::PadProbeReturn::Ok;
};
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();
state.all_mimes.push(mime.unwrap().into());
state.maybe_write_manifest();
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) {
enc.static_pad("src").unwrap().add_probe(
gst::PadProbeType::EVENT_DOWNSTREAM,
move |_pad, info| match info.data {
Some(gst::PadProbeData::Event(ref ev)) => match ev.view() {
gst::EventView::Caps(e) => {
let mime = gst_pbutils::codec_utils_caps_get_mime_codec(e.caps());
move |_pad, info| {
let Some(ev) = info.event() else {
return gst::PadProbeReturn::Ok;
};
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();
state.all_mimes.push(mime.unwrap().into());
state.maybe_write_manifest();
gst::PadProbeReturn::Remove
}
_ => gst::PadProbeReturn::Ok,
},
_ => gst::PadProbeReturn::Ok,
},
);
}

View file

@ -358,15 +358,20 @@ impl WebRTCSrc {
.build();
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| {
if let Some(gst::PadProbeData::Event(ref ev)) = info.data {
if let gst::EventView::Navigation(ev) = ev.view() {
let Some(ev) = info.event() else {
return gst::PadProbeReturn::Ok;
};
if ev.type_() != gst::EventType::Navigation {
return gst::PadProbeReturn::Ok;
};
this.send_navigation_event (gst_video::NavigationEvent::parse(ev).unwrap());
}
}
gst::PadProbeReturn::Ok
})
}),
);
}

View file

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

View file

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

View file

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

View file

@ -300,7 +300,7 @@ impl TranscriberBin {
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();
while let Some(meta) = buffer.meta_mut::<gst_video::VideoCaptionMeta>() {
meta.remove().unwrap();