livesync: Simplify start_src_task and src_loop

This should effect no change in behavior.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1369>
This commit is contained in:
Jan Alexander Steffens (heftig) 2023-10-24 23:09:11 +02:00
parent 01386b8451
commit 0a45f776e0

View file

@ -968,31 +968,17 @@ impl LiveSync {
Ok(gst::FlowSuccess::Ok) Ok(gst::FlowSuccess::Ok)
} }
fn start_src_task(&self) -> Result<(), glib::BoolError> { fn start_src_task(&self, state: &mut State) -> Result<(), glib::BoolError> {
self.srcpad.start_task({ let imp = self.ref_counted();
let pad = self.srcpad.downgrade(); self.srcpad.start_task(move || imp.src_loop())
move || {
let pad = pad.upgrade().unwrap();
let parent = pad.parent_element().unwrap();
let livesync = parent.downcast_ref::<super::LiveSync>().unwrap();
let ret = livesync.imp().src_loop(&pad);
if !ret {
gst::log!(CAT, obj: &parent, "Loop stopping");
let _ = pad.pause_task();
}
}
})
} }
fn src_loop(&self, pad: &gst::Pad) -> bool { fn src_loop(&self) {
let mut err = match self.src_loop_inner() { let Err(mut err) = self.src_loop_inner() else {
Ok(_) => return true, return;
Err(e) => e,
}; };
let eos;
{ let eos = {
let mut state = self.state.lock(); let mut state = self.state.lock();
match state.srcresult { match state.srcresult {
@ -1002,21 +988,22 @@ impl LiveSync {
// Communicate our flow return // Communicate our flow return
Ok(_) => state.srcresult = Err(err), Ok(_) => state.srcresult = Err(err),
} }
eos = state.eos;
state.clock_id = None; state.clock_id = None;
self.cond.notify_all(); self.cond.notify_all();
}
state.eos
};
// Following GstQueue's behavior: // Following GstQueue's behavior:
// > let app know about us giving up if upstream is not expected to do so // > let app know about us giving up if upstream is not expected to do so
// > EOS is already taken care of elsewhere // > EOS is already taken care of elsewhere
if eos && !matches!(err, gst::FlowError::Flushing | gst::FlowError::Eos) { if eos && !matches!(err, gst::FlowError::Flushing | gst::FlowError::Eos) {
self.flow_error(err); self.flow_error(err);
pad.push_event(gst::event::Eos::new()); self.srcpad.push_event(gst::event::Eos::new());
} }
false gst::log!(CAT, imp: self, "Loop stopping");
let _ = self.srcpad.pause_task();
} }
fn src_loop_inner(&self) -> Result<gst::FlowSuccess, gst::FlowError> { fn src_loop_inner(&self) -> Result<gst::FlowSuccess, gst::FlowError> {