Use let-else instead of match for weak reference upgrades

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1375>
This commit is contained in:
Sebastian Dröge 2023-10-30 11:34:35 +02:00
parent 74c04d79c9
commit 855b03a9ea
18 changed files with 90 additions and 135 deletions

View file

@ -642,9 +642,8 @@ impl ObjectImpl for S3HlsSink {
self.hlssink.connect("get-playlist-stream", false, {
let self_weak = self.downgrade();
move |args| -> Option<glib::Value> {
let self_ = match self_weak.upgrade() {
Some(self_) => self_,
None => return None,
let Some(self_) = self_weak.upgrade() else {
return None;
};
let s3client = self_.s3client_from_settings();
@ -677,9 +676,8 @@ impl ObjectImpl for S3HlsSink {
self.hlssink.connect("get-fragment-stream", false, {
let self_weak = self.downgrade();
move |args| -> Option<glib::Value> {
let self_ = match self_weak.upgrade() {
Some(self_) => self_,
None => return None,
let Some(self_) = self_weak.upgrade() else {
return None;
};
let s3client = self_.s3client_from_settings();
@ -712,9 +710,8 @@ impl ObjectImpl for S3HlsSink {
self.hlssink.connect("delete-fragment", false, {
let self_weak = self.downgrade();
move |args| -> Option<glib::Value> {
let self_ = match self_weak.upgrade() {
Some(self_) => self_,
None => return None,
let Some(self_) = self_weak.upgrade() else {
return None;
};
let s3_client = self_.s3client_from_settings();

View file

@ -269,9 +269,8 @@ fn main() -> Result<(), Error> {
match msg.view() {
MessageView::StateChanged(state_changed) => {
let pipeline = match pipeline_weak.upgrade() {
Some(pipeline) => pipeline,
None => break,
let Some(pipeline) = pipeline_weak.upgrade() else {
break;
};
let mut need_write = write_playlist.lock().unwrap();

View file

@ -782,9 +782,8 @@ impl ObjectImpl for HlsSink3 {
.connect("format-location-full", false, {
let imp_weak = self.downgrade();
move |args| {
let imp = match imp_weak.upgrade() {
Some(imp) => imp,
None => return Some(None::<String>.to_value()),
let Some(imp) = imp_weak.upgrade() else {
return Some(None::<String>.to_value());
};
let fragment_id = args[1].get::<u32>().unwrap();
gst::info!(CAT, imp: imp, "Got fragment-id: {}", fragment_id);
@ -1322,9 +1321,8 @@ impl ObjectImpl for HlsCmafSink {
settings.appsink.set_callbacks(
gst_app::AppSinkCallbacks::builder()
.new_sample(move |sink| {
let imp = match self_weak.upgrade() {
Some(imp) => imp,
_ => return Err(gst::FlowError::Eos),
let Some(imp) = self_weak.upgrade() else {
return Err(gst::FlowError::Eos);
};
let sample = sink.pull_sample().map_err(|_| gst::FlowError::Eos)?;

View file

@ -87,9 +87,8 @@ impl DeviceProviderImpl for DeviceProvider {
let mut first = true;
*thread_guard = Some(thread::spawn(move || {
{
let imp = match imp_weak.upgrade() {
None => return,
Some(imp) => imp,
let Some(imp) = imp_weak.upgrade() else {
return;
};
let mut find_guard = imp.find.lock().unwrap();
@ -109,9 +108,8 @@ impl DeviceProviderImpl for DeviceProvider {
}
loop {
let imp = match imp_weak.upgrade() {
None => return,
Some(imp) => imp,
let Some(imp) = imp_weak.upgrade() else {
return;
};
if !imp.is_running.load(atomic::Ordering::SeqCst) {

View file

@ -761,14 +761,12 @@ impl Receiver {
// Capture until error or shutdown
loop {
let receiver = match receiver.upgrade().map(Receiver) {
None => break,
Some(receiver) => receiver,
let Some(receiver) = receiver.upgrade().map(Receiver) else {
break;
};
let element = match receiver.0.element.upgrade() {
None => return,
Some(element) => element,
let Some(element) = receiver.0.element.upgrade() else {
break;
};
let flushing = {

View file

@ -431,9 +431,8 @@ impl SignallableImpl for Signaller {
webrtcbin: &gst::Element| {
let obj_weak = signaller.downgrade();
webrtcbin.connect_notify(Some("ice-gathering-state"), move |webrtcbin, _pspec| {
let obj = match obj_weak.upgrade() {
Some(obj) => obj,
None => return,
let Some(obj) = obj_weak.upgrade() else {
return;
};
let state =

View file

@ -426,9 +426,8 @@ impl WhepSrc {
let self_weak = self.downgrade();
self.webrtcbin
.connect_notify(Some("ice-gathering-state"), move |webrtcbin, _pspec| {
let self_ = match self_weak.upgrade() {
Some(self_) => self_,
None => return,
let Some(self_) = self_weak.upgrade() else {
return;
};
let state = webrtcbin.property::<WebRTCICEGatheringState>("ice-gathering-state");
@ -458,9 +457,8 @@ impl WhepSrc {
let self_weak = self.downgrade();
self.webrtcbin
.connect_notify(Some("ice-connection-state"), move |webrtcbin, _pspec| {
let self_ = match self_weak.upgrade() {
Some(self_) => self_,
None => return,
let Some(self_) = self_weak.upgrade() else {
return;
};
let state = webrtcbin.property::<WebRTCICEConnectionState>("ice-connection-state");
@ -489,9 +487,8 @@ impl WhepSrc {
let self_weak = self.downgrade();
self.webrtcbin
.connect_notify(Some("connection-state"), move |webrtcbin, _pspec| {
let self_ = match self_weak.upgrade() {
Some(self_) => self_,
None => return,
let Some(self_) = self_weak.upgrade() else {
return;
};
let state = webrtcbin.property::<WebRTCPeerConnectionState>("connection-state");
@ -520,9 +517,8 @@ impl WhepSrc {
let self_weak = self.downgrade();
self.webrtcbin.connect_pad_added(move |_, pad| {
let self_ = match self_weak.upgrade() {
Some(self_) => self_,
None => return,
let Some(self_) = self_weak.upgrade() else {
return;
};
gst::debug!(
@ -547,9 +543,8 @@ impl WhepSrc {
let self_weak = self.downgrade();
self.webrtcbin.connect("on-negotiation-needed", false, {
move |_| {
let self_ = match self_weak.upgrade() {
Some(self_) => self_,
None => return None,
let Some(self_) = self_weak.upgrade() else {
return None;
};
let settings = self_.settings.lock().unwrap();
@ -780,9 +775,8 @@ impl WhepSrc {
fn generate_offer(&self) {
let self_weak = self.downgrade();
let promise = gst::Promise::with_change_func(move |reply| {
let self_ = match self_weak.upgrade() {
Some(self_) => self_,
None => return,
let Some(self_) = self_weak.upgrade() else {
return;
};
let reply = match reply {

View file

@ -357,9 +357,8 @@ impl ObjectImpl for WhipSink {
let self_weak = self.downgrade();
self.webrtcbin
.connect_notify(Some("ice-gathering-state"), move |webrtcbin, _pspec| {
let self_ = match self_weak.upgrade() {
Some(self_) => self_,
None => return,
let Some(self_) = self_weak.upgrade() else {
return;
};
let state = webrtcbin.property::<WebRTCICEGatheringState>("ice-gathering-state");

View file

@ -105,9 +105,8 @@ fn create_ui(app: &gtk::Application) {
let video_sink_weak = video_sink.downgrade();
let timeout_id = glib::timeout_add_local(std::time::Duration::from_millis(100), move || {
let video_sink = match video_sink_weak.upgrade() {
Some(video_sink) => video_sink,
None => return glib::ControlFlow::Continue,
let Some(video_sink) = video_sink_weak.upgrade() else {
return glib::ControlFlow::Break;
};
let position = video_sink
@ -121,9 +120,8 @@ fn create_ui(app: &gtk::Application) {
let video_src_pad_weak = video_src_pad.downgrade();
let drop_id = RefCell::new(None);
drop_button.connect_toggled(move |drop_button| {
let video_src_pad = match video_src_pad_weak.upgrade() {
Some(video_src_pad) => video_src_pad,
None => return,
let Some(video_src_pad) = video_src_pad_weak.upgrade() else {
return;
};
let drop = drop_button.is_active();
@ -140,9 +138,8 @@ fn create_ui(app: &gtk::Application) {
let app_weak = app.downgrade();
window.connect_close_request(move |_| {
let app = match app_weak.upgrade() {
Some(app) => app,
None => return glib::Propagation::Stop,
let Some(app) = app_weak.upgrade() else {
return glib::Propagation::Stop;
};
app.quit();
@ -155,9 +152,8 @@ fn create_ui(app: &gtk::Application) {
.add_watch_local(move |_, msg| {
use gst::MessageView;
let app = match app_weak.upgrade() {
Some(app) => app,
None => return glib::ControlFlow::Break,
let Some(app) = app_weak.upgrade() else {
return glib::ControlFlow::Break;
};
match msg.view() {

View file

@ -2893,9 +2893,8 @@ impl FallbackSrc {
self.obj().call_async(move |element| {
let imp = element.imp();
let source = match source_weak.upgrade() {
None => return,
Some(source) => source,
let Some(source) = source_weak.upgrade() else {
return;
};
// Remove blocking pad probes if they are still there as otherwise shutting down the
@ -3081,9 +3080,8 @@ impl FallbackSrc {
let element_weak = element.downgrade();
timeout
.wait_async(move |_clock, _time, _id| {
let element = match element_weak.upgrade() {
None => return,
Some(element) => element,
let Some(element) = element_weak.upgrade() else {
return;
};
gst::debug!(CAT, obj: element, "Woke up, retrying");
@ -3305,9 +3303,8 @@ impl FallbackSrc {
let element_weak = self.obj().downgrade();
timeout
.wait_async(move |_clock, _time, _id| {
let element = match element_weak.upgrade() {
None => return,
Some(element) => element,
let Some(element) = element_weak.upgrade() else {
return;
};
element.call_async(move |element| {

View file

@ -583,9 +583,8 @@ impl FallbackSwitch {
let imp_weak = self.downgrade();
timeout_id
.wait_async(move |_clock, _time, clock_id| {
let imp = match imp_weak.upgrade() {
None => return,
Some(imp) => imp,
let Some(imp) = imp_weak.upgrade() else {
return;
};
imp.on_timeout(clock_id);
})

View file

@ -217,14 +217,12 @@ fn create_ui(app: &gtk::Application) {
let video_sink_weak = video_sink.downgrade();
let togglerecord_weak = togglerecord.downgrade();
let timeout_id = glib::timeout_add_local(std::time::Duration::from_millis(100), move || {
let video_sink = match video_sink_weak.upgrade() {
Some(video_sink) => video_sink,
None => return glib::ControlFlow::Continue,
let Some(video_sink) = video_sink_weak.upgrade() else {
return glib::ControlFlow::Break;
};
let togglerecord = match togglerecord_weak.upgrade() {
Some(togglerecord) => togglerecord,
None => return glib::ControlFlow::Continue,
let Some(togglerecord) = togglerecord_weak.upgrade() else {
return glib::ControlFlow::Break;
};
let position = video_sink
@ -244,9 +242,8 @@ fn create_ui(app: &gtk::Application) {
let togglerecord_weak = togglerecord.downgrade();
record_button.connect_clicked(move |button| {
let togglerecord = match togglerecord_weak.upgrade() {
Some(togglerecord) => togglerecord,
None => return,
let Some(togglerecord) = togglerecord_weak.upgrade() else {
return;
};
let recording = !togglerecord.property::<bool>("record");
@ -257,9 +254,8 @@ fn create_ui(app: &gtk::Application) {
let record_button_weak = record_button.downgrade();
finish_button.connect_clicked(move |button| {
let record_button = match record_button_weak.upgrade() {
Some(record_button) => record_button,
None => return,
let Some(record_button) = record_button_weak.upgrade() else {
return;
};
record_button.set_sensitive(false);
@ -271,9 +267,8 @@ fn create_ui(app: &gtk::Application) {
let app_weak = app.downgrade();
window.connect_close_request(move |_| {
let app = match app_weak.upgrade() {
Some(app) => app,
None => return glib::Propagation::Stop,
let Some(app) = app_weak.upgrade() else {
return glib::Propagation::Stop;
};
app.quit();
@ -286,9 +281,8 @@ fn create_ui(app: &gtk::Application) {
.add_watch_local(move |_, msg| {
use gst::MessageView;
let app = match app_weak.upgrade() {
Some(app) => app,
None => return glib::ControlFlow::Break,
let Some(app) = app_weak.upgrade() else {
return glib::ControlFlow::Break;
};
match msg.view() {

View file

@ -192,9 +192,8 @@ impl PipelineSnapshot {
for signal in &mut signals {
match signal {
SIGUSR1 => {
let tracer = match tracer_weak.upgrade() {
Some(tracer) => tracer,
None => break,
let Some(tracer) = tracer_weak.upgrade() else {
break;
};
let pipelines = {

View file

@ -37,9 +37,8 @@ fn create_pipeline(uris: Vec<String>, iterations: u32) -> anyhow::Result<gst::Pi
let pipeline_weak = pipeline.downgrade();
playlist.connect_pad_added(move |_playlist, src_pad| {
let pipeline = match pipeline_weak.upgrade() {
None => return,
Some(pipeline) => pipeline,
let Some(pipeline) = pipeline_weak.upgrade() else {
return;
};
let pad_name = src_pad.name();
@ -66,9 +65,8 @@ fn create_pipeline(uris: Vec<String>, iterations: u32) -> anyhow::Result<gst::Pi
let pipeline_weak = pipeline.downgrade();
playlist.connect_pad_removed(move |_playlist, pad| {
let pipeline = match pipeline_weak.upgrade() {
None => return,
Some(pipeline) => pipeline,
let Some(pipeline) = pipeline_weak.upgrade() else {
return;
};
// remove sink bin that was handling the pad

View file

@ -1078,9 +1078,8 @@ impl UriPlaylistBin {
);
src_pad.add_probe(gst::PadProbeType::BLOCK_DOWNSTREAM, move |pad, _info| {
let imp = match imp_weak.upgrade() {
Some(imp) => imp,
None => return gst::PadProbeReturn::Remove,
let Some(imp) = imp_weak.upgrade() else {
return gst::PadProbeReturn::Remove;
};
if let Some(parent) = pad.parent() {
@ -1294,9 +1293,8 @@ impl UriPlaylistBin {
return gst::PadProbeReturn::Pass;
}
let element = match element_weak.upgrade() {
Some(element) => element,
None => return gst::PadProbeReturn::Remove,
let Some(element) = element_weak.upgrade() else {
return gst::PadProbeReturn::Remove;
};
let imp = element.imp();
@ -1396,14 +1394,12 @@ impl UriPlaylistBin {
let item_weak = item.downgrade();
sink_pad.add_probe(gst::PadProbeType::BLOCK_DOWNSTREAM, move |pad, info| {
let element = match element_weak.upgrade() {
Some(element) => element,
None => return gst::PadProbeReturn::Remove,
let Some(element) = element_weak.upgrade() else {
return gst::PadProbeReturn::Remove;
};
let parent = pad.parent().unwrap();
let item = match Item::upgrade(&item_weak) {
Some(item) => item,
None => return gst::PadProbeReturn::Remove,
let Some(item) = Item::upgrade(&item_weak) else {
return gst::PadProbeReturn::Remove;
};
if !item.is_streaming() {

View file

@ -110,9 +110,8 @@ fn test(
return;
}
let pipeline = match pipeline_weak.upgrade() {
Some(pipeline) => pipeline,
None => return,
let Some(pipeline) = pipeline_weak.upgrade() else {
return;
};
let sink = gst::ElementFactory::make("fakesink").build().unwrap();

View file

@ -290,9 +290,8 @@ impl TranscriberBin {
let comp_sinkpad = &state.cccombiner.static_pad("sink").unwrap();
// Drop caption meta from video buffer if user preference is transcription
comp_sinkpad.add_probe(gst::PadProbeType::BUFFER, move |_, probe_info| {
let imp = match imp_weak.upgrade() {
None => return gst::PadProbeReturn::Remove,
Some(imp) => imp,
let Some(imp) = imp_weak.upgrade() else {
return gst::PadProbeReturn::Remove;
};
let settings = imp.settings.lock().unwrap();
@ -431,9 +430,8 @@ impl TranscriberBin {
| gst::PadProbeType::BUFFER
| gst::PadProbeType::EVENT_DOWNSTREAM,
move |_pad, _info| {
let imp = match imp_weak.upgrade() {
None => return gst::PadProbeReturn::Pass,
Some(imp) => imp,
let Some(imp) = imp_weak.upgrade() else {
return gst::PadProbeReturn::Remove;
};
imp.disable_transcription_bin();
@ -645,9 +643,8 @@ impl TranscriberBin {
| gst::PadProbeType::BUFFER
| gst::PadProbeType::EVENT_DOWNSTREAM,
move |_pad, _info| {
let imp = match imp_weak.upgrade() {
None => return gst::PadProbeReturn::Remove,
Some(imp) => imp,
let Some(imp) = imp_weak.upgrade() else {
return gst::PadProbeReturn::Remove;
};
if imp.reconfigure_transcription_bin(lang_code_only).is_err() {

View file

@ -75,9 +75,8 @@ fn create_ui(app: &gtk::Application) {
let pipeline_weak = pipeline.downgrade();
let timeout_id = glib::timeout_add_local(std::time::Duration::from_millis(500), move || {
let pipeline = match pipeline_weak.upgrade() {
Some(pipeline) => pipeline,
None => return glib::ControlFlow::Continue,
let Some(pipeline) = pipeline_weak.upgrade() else {
return glib::ControlFlow::Break;
};
let position = pipeline.query_position::<gst::ClockTime>();
@ -96,9 +95,8 @@ fn create_ui(app: &gtk::Application) {
.add_watch_local(move |_, msg| {
use gst::MessageView;
let app = match app_weak.upgrade() {
Some(app) => app,
None => return glib::ControlFlow::Break,
let Some(app) = app_weak.upgrade() else {
return glib::ControlFlow::Break;
};
match msg.view() {