mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-05-29 05:38:16 +00:00
Use let-else instead of match for weak reference upgrades
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1333>
This commit is contained in:
parent
fc4a0d29c6
commit
4a015d94af
|
@ -115,9 +115,8 @@ fn example_main() {
|
||||||
glib::timeout_add_seconds(2 + i as u32, move || {
|
glib::timeout_add_seconds(2 + i as u32, move || {
|
||||||
// Here we temporarily retrieve a strong reference on the pipeline from the weak one
|
// Here we temporarily retrieve a strong reference on the pipeline from the weak one
|
||||||
// we moved into this callback.
|
// we moved into this callback.
|
||||||
let pipeline = match pipeline_weak.upgrade() {
|
let Some(pipeline) = pipeline_weak.upgrade() else {
|
||||||
Some(pipeline) => pipeline,
|
return glib::ControlFlow::Break;
|
||||||
None => return glib::ControlFlow::Break,
|
|
||||||
};
|
};
|
||||||
println!("Sending custom event to the pipeline with send_eos={send_eos}");
|
println!("Sending custom event to the pipeline with send_eos={send_eos}");
|
||||||
let ev = ExampleCustomEvent::new(*send_eos);
|
let ev = ExampleCustomEvent::new(*send_eos);
|
||||||
|
|
|
@ -90,9 +90,8 @@ fn example_main() -> Result<(), Error> {
|
||||||
decodebin.connect_pad_added(move |dbin, src_pad| {
|
decodebin.connect_pad_added(move |dbin, src_pad| {
|
||||||
// Here we temporarily retrieve a strong reference on the pipeline from the weak one
|
// Here we temporarily retrieve a strong reference on the pipeline from the weak one
|
||||||
// we moved into this callback.
|
// we moved into this callback.
|
||||||
let pipeline = match pipeline_weak.upgrade() {
|
let Some(pipeline) = pipeline_weak.upgrade() else {
|
||||||
Some(pipeline) => pipeline,
|
return;
|
||||||
None => return,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Try to detect whether the raw stream decodebin provided us with
|
// Try to detect whether the raw stream decodebin provided us with
|
||||||
|
|
|
@ -120,9 +120,8 @@ fn example_main() -> Result<(), Error> {
|
||||||
src.connect_pad_added(move |dbin, dbin_src_pad| {
|
src.connect_pad_added(move |dbin, dbin_src_pad| {
|
||||||
// Here we temporarily retrieve a strong reference on the pipeline from the weak one
|
// Here we temporarily retrieve a strong reference on the pipeline from the weak one
|
||||||
// we moved into this callback.
|
// we moved into this callback.
|
||||||
let pipeline = match pipeline_weak.upgrade() {
|
let Some(pipeline) = pipeline_weak.upgrade() else {
|
||||||
Some(pipeline) => pipeline,
|
return;
|
||||||
None => return,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let (is_audio, is_video) = {
|
let (is_audio, is_video) = {
|
||||||
|
|
|
@ -55,9 +55,8 @@ fn example_main() {
|
||||||
glib::timeout_add_seconds(5, move || {
|
glib::timeout_add_seconds(5, move || {
|
||||||
// Here we temporarily retrieve a strong reference on the pipeline from the weak one
|
// Here we temporarily retrieve a strong reference on the pipeline from the weak one
|
||||||
// we moved into this callback.
|
// we moved into this callback.
|
||||||
let pipeline = match pipeline_weak.upgrade() {
|
let Some(pipeline) = pipeline_weak.upgrade() else {
|
||||||
Some(pipeline) => pipeline,
|
return glib::ControlFlow::Break;
|
||||||
None => return glib::ControlFlow::Break,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("sending eos");
|
println!("sending eos");
|
||||||
|
|
|
@ -50,9 +50,8 @@ fn example_main() {
|
||||||
let timeout_id = glib::timeout_add_seconds(1, move || {
|
let timeout_id = glib::timeout_add_seconds(1, move || {
|
||||||
// Here we temporarily retrieve a strong reference on the pipeline from the weak one
|
// Here we temporarily retrieve a strong reference on the pipeline from the weak one
|
||||||
// we moved into this callback.
|
// we moved into this callback.
|
||||||
let pipeline = match pipeline_weak.upgrade() {
|
let Some(pipeline) = pipeline_weak.upgrade() else {
|
||||||
Some(pipeline) => pipeline,
|
return glib::ControlFlow::Break;
|
||||||
None => return glib::ControlFlow::Continue,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//let pos = pipeline.query_position(gst::Format::Time).unwrap_or(-1);
|
//let pos = pipeline.query_position(gst::Format::Time).unwrap_or(-1);
|
||||||
|
|
|
@ -203,9 +203,8 @@ fn example_main() -> Result<(), Error> {
|
||||||
|
|
||||||
let depay_weak = depay.downgrade();
|
let depay_weak = depay.downgrade();
|
||||||
rtpbin.connect_pad_added(move |rtpbin, src_pad| {
|
rtpbin.connect_pad_added(move |rtpbin, src_pad| {
|
||||||
let depay = match depay_weak.upgrade() {
|
let Some(depay) = depay_weak.upgrade() else {
|
||||||
Some(depay) => depay,
|
return;
|
||||||
None => return,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
match connect_rtpbin_srcpad(src_pad, &depay) {
|
match connect_rtpbin_srcpad(src_pad, &depay) {
|
||||||
|
|
|
@ -52,9 +52,8 @@ fn example_main() {
|
||||||
decodebin.connect_pad_added(move |_, src_pad| {
|
decodebin.connect_pad_added(move |_, src_pad| {
|
||||||
// Here we temporarily retrieve a strong reference on the pipeline from the weak one
|
// Here we temporarily retrieve a strong reference on the pipeline from the weak one
|
||||||
// we moved into this callback.
|
// we moved into this callback.
|
||||||
let pipeline = match pipeline_weak.upgrade() {
|
let Some(pipeline) = pipeline_weak.upgrade() else {
|
||||||
Some(pipeline) => pipeline,
|
return;
|
||||||
None => return,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// In this example, we are only interested about parsing the ToC, so
|
// In this example, we are only interested about parsing the ToC, so
|
||||||
|
|
|
@ -1254,9 +1254,8 @@ impl Stream for AppSinkStream {
|
||||||
fn poll_next(self: Pin<&mut Self>, context: &mut Context) -> Poll<Option<Self::Item>> {
|
fn poll_next(self: Pin<&mut Self>, context: &mut Context) -> Poll<Option<Self::Item>> {
|
||||||
let mut waker = self.waker_reference.lock().unwrap();
|
let mut waker = self.waker_reference.lock().unwrap();
|
||||||
|
|
||||||
let app_sink = match self.app_sink.upgrade() {
|
let Some(app_sink) = self.app_sink.upgrade() else {
|
||||||
Some(app_sink) => app_sink,
|
return Poll::Ready(None);
|
||||||
None => return Poll::Ready(None),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
app_sink
|
app_sink
|
||||||
|
|
|
@ -588,9 +588,8 @@ impl Sink<gst::Sample> for AppSrcSink {
|
||||||
fn poll_ready(self: Pin<&mut Self>, context: &mut Context) -> Poll<Result<(), Self::Error>> {
|
fn poll_ready(self: Pin<&mut Self>, context: &mut Context) -> Poll<Result<(), Self::Error>> {
|
||||||
let mut waker = self.waker_reference.lock().unwrap();
|
let mut waker = self.waker_reference.lock().unwrap();
|
||||||
|
|
||||||
let app_src = match self.app_src.upgrade() {
|
let Some(app_src) = self.app_src.upgrade() else {
|
||||||
Some(app_src) => app_src,
|
return Poll::Ready(Err(gst::FlowError::Eos));
|
||||||
None => return Poll::Ready(Err(gst::FlowError::Eos)),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let current_level_bytes = app_src.current_level_bytes();
|
let current_level_bytes = app_src.current_level_bytes();
|
||||||
|
@ -606,9 +605,8 @@ impl Sink<gst::Sample> for AppSrcSink {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_send(self: Pin<&mut Self>, sample: gst::Sample) -> Result<(), Self::Error> {
|
fn start_send(self: Pin<&mut Self>, sample: gst::Sample) -> Result<(), Self::Error> {
|
||||||
let app_src = match self.app_src.upgrade() {
|
let Some(app_src) = self.app_src.upgrade() else {
|
||||||
Some(app_src) => app_src,
|
return Err(gst::FlowError::Eos);
|
||||||
None => return Err(gst::FlowError::Eos),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
app_src.push_sample(&sample)?;
|
app_src.push_sample(&sample)?;
|
||||||
|
@ -621,9 +619,8 @@ impl Sink<gst::Sample> for AppSrcSink {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn poll_close(self: Pin<&mut Self>, _: &mut Context) -> Poll<Result<(), Self::Error>> {
|
fn poll_close(self: Pin<&mut Self>, _: &mut Context) -> Poll<Result<(), Self::Error>> {
|
||||||
let app_src = match self.app_src.upgrade() {
|
let Some(app_src) = self.app_src.upgrade() else {
|
||||||
Some(app_src) => app_src,
|
return Poll::Ready(Ok(()));
|
||||||
None => return Poll::Ready(Ok(())),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
app_src.end_of_stream()?;
|
app_src.end_of_stream()?;
|
||||||
|
|
|
@ -24,9 +24,8 @@ fn tutorial_main() -> Result<(), Error> {
|
||||||
let bus = pipeline.bus().expect("Pipeline has no bus");
|
let bus = pipeline.bus().expect("Pipeline has no bus");
|
||||||
let _bus_watch = bus
|
let _bus_watch = bus
|
||||||
.add_watch(move |_, msg| {
|
.add_watch(move |_, msg| {
|
||||||
let pipeline = match pipeline_weak.upgrade() {
|
let Some(pipeline) = pipeline_weak.upgrade() else {
|
||||||
Some(pipeline) => pipeline,
|
return glib::ControlFlow::Continue;
|
||||||
None => return glib::ControlFlow::Continue,
|
|
||||||
};
|
};
|
||||||
let main_loop = &main_loop_clone;
|
let main_loop = &main_loop_clone;
|
||||||
match msg.view() {
|
match msg.view() {
|
||||||
|
|
|
@ -165,9 +165,8 @@ fn main() {
|
||||||
appsrc.set_callbacks(
|
appsrc.set_callbacks(
|
||||||
gst_app::AppSrcCallbacks::builder()
|
gst_app::AppSrcCallbacks::builder()
|
||||||
.need_data(move |_, _size| {
|
.need_data(move |_, _size| {
|
||||||
let data = match data_weak.upgrade() {
|
let Some(data) = data_weak.upgrade() else {
|
||||||
Some(data) => data,
|
return;
|
||||||
None => return,
|
|
||||||
};
|
};
|
||||||
let mut d = data.lock().unwrap();
|
let mut d = data.lock().unwrap();
|
||||||
|
|
||||||
|
@ -176,9 +175,8 @@ fn main() {
|
||||||
|
|
||||||
let data_weak = Arc::downgrade(&data);
|
let data_weak = Arc::downgrade(&data);
|
||||||
d.source_id = Some(glib::source::idle_add(move || {
|
d.source_id = Some(glib::source::idle_add(move || {
|
||||||
let data = match data_weak.upgrade() {
|
let Some(data) = data_weak.upgrade() else {
|
||||||
Some(data) => data,
|
return glib::ControlFlow::Break;
|
||||||
None => return glib::ControlFlow::Break,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let (appsrc, buffer) = {
|
let (appsrc, buffer) = {
|
||||||
|
@ -224,9 +222,8 @@ fn main() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.enough_data(move |_| {
|
.enough_data(move |_| {
|
||||||
let data = match data_weak2.upgrade() {
|
let Some(data) = data_weak2.upgrade() else {
|
||||||
Some(data) => data,
|
return;
|
||||||
None => return,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut data = data.lock().unwrap();
|
let mut data = data.lock().unwrap();
|
||||||
|
@ -242,9 +239,8 @@ fn main() {
|
||||||
appsink.set_callbacks(
|
appsink.set_callbacks(
|
||||||
gst_app::AppSinkCallbacks::builder()
|
gst_app::AppSinkCallbacks::builder()
|
||||||
.new_sample(move |_| {
|
.new_sample(move |_| {
|
||||||
let data = match data_weak.upgrade() {
|
let Some(data) = data_weak.upgrade() else {
|
||||||
Some(data) => data,
|
return Ok(gst::FlowSuccess::Ok);
|
||||||
None => return Ok(gst::FlowSuccess::Ok),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let appsink = {
|
let appsink = {
|
||||||
|
|
|
@ -82,9 +82,8 @@ fn tutorial_main() -> Result<(), Error> {
|
||||||
|
|
||||||
let data_weak = Arc::downgrade(data);
|
let data_weak = Arc::downgrade(data);
|
||||||
d.source_id = Some(glib::source::idle_add(move || {
|
d.source_id = Some(glib::source::idle_add(move || {
|
||||||
let data = match data_weak.upgrade() {
|
let Some(data) = data_weak.upgrade() else {
|
||||||
Some(data) => data,
|
return glib::ControlFlow::Break;
|
||||||
None => return glib::ControlFlow::Break,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let (appsrc, buffer) = {
|
let (appsrc, buffer) = {
|
||||||
|
|
|
@ -56,9 +56,8 @@ fn tutorial_main() -> Result<(), Error> {
|
||||||
use gst::MessageView;
|
use gst::MessageView;
|
||||||
|
|
||||||
let buffering_level = &buffering_level_clone;
|
let buffering_level = &buffering_level_clone;
|
||||||
let pipeline = match pipeline_weak.upgrade() {
|
let Some(pipeline) = pipeline_weak.upgrade() else {
|
||||||
Some(pipeline) => pipeline,
|
return glib::ControlFlow::Break;
|
||||||
None => return glib::ControlFlow::Break,
|
|
||||||
};
|
};
|
||||||
let main_loop = &main_loop_clone;
|
let main_loop = &main_loop_clone;
|
||||||
match msg.view() {
|
match msg.view() {
|
||||||
|
@ -116,9 +115,8 @@ fn tutorial_main() -> Result<(), Error> {
|
||||||
let timeout_id = glib::timeout_add_seconds(1, move || {
|
let timeout_id = glib::timeout_add_seconds(1, move || {
|
||||||
use gst::{format::Percent, GenericFormattedValue as GFV};
|
use gst::{format::Percent, GenericFormattedValue as GFV};
|
||||||
|
|
||||||
let pipeline = match pipeline_weak_.upgrade() {
|
let Some(pipeline) = pipeline_weak_.upgrade() else {
|
||||||
Some(pipeline) => pipeline,
|
return glib::ControlFlow::Break;
|
||||||
None => return glib::ControlFlow::Break,
|
|
||||||
};
|
};
|
||||||
let mut graph = vec![b' '; GRAPH_LENGTH];
|
let mut graph = vec![b' '; GRAPH_LENGTH];
|
||||||
let mut buffering = gst::query::Buffering::new(gst::Format::Percent);
|
let mut buffering = gst::query::Buffering::new(gst::Format::Percent);
|
||||||
|
|
Loading…
Reference in a new issue