From 948fb2ae4bc3842536412bcd167a9f6c55d817f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Laignel?= Date: Tue, 8 Jan 2019 17:13:37 +0100 Subject: [PATCH] Replace XXXReturn with Result ... in function signatures. These breaking changes aim at improving usability by allowing users to take advantage of Rust error management features sur as `ok_or`, `map_err`, `expect` and the `?` operator. See the `examples` and `tutorials` to get an idea of the impacts. --- Gir_Gst.toml | 40 ++++ Gir_GstApp.toml | 20 ++ Gir_GstBase.toml | 25 ++ Gir_GstRtspServer.toml | 15 ++ examples/src/bin/appsink.rs | 38 ++-- examples/src/bin/appsrc.rs | 6 +- examples/src/bin/decodebin.rs | 10 +- examples/src/bin/encodebin.rs | 14 +- examples/src/bin/events.rs | 10 +- examples/src/bin/futures.rs | 10 +- examples/src/bin/ges.rs | 10 +- examples/src/bin/glib-futures.rs | 10 +- examples/src/bin/glupload.rs | 42 ++-- examples/src/bin/gtksink.rs | 10 +- examples/src/bin/gtkvideooverlay.rs | 10 +- examples/src/bin/launch.rs | 10 +- examples/src/bin/launch_glib_main.rs | 10 +- examples/src/bin/pad_probes.rs | 10 +- examples/src/bin/pango-cairo.rs | 6 +- examples/src/bin/playbin.rs | 10 +- examples/src/bin/queries.rs | 10 +- examples/src/bin/rtpfecclient.rs | 19 +- examples/src/bin/rtpfecserver.rs | 21 +- examples/src/bin/tagsetter.rs | 4 +- examples/src/bin/toc.rs | 18 +- examples/src/bin/transmux.rs | 10 +- gstreamer-app/src/app_sink.rs | 100 +++++++- gstreamer-app/src/app_src.rs | 33 ++- gstreamer-app/src/auto/app_sink.rs | 26 --- gstreamer-app/src/auto/app_src.rs | 12 - gstreamer-base/src/aggregator.rs | 9 +- gstreamer-base/src/auto/base_sink.rs | 18 -- gstreamer-base/src/auto/base_src.rs | 24 -- gstreamer-base/src/base_sink.rs | 29 +++ gstreamer-base/src/base_src.rs | 25 ++ gstreamer-base/src/flow_combiner.rs | 32 ++- gstreamer-base/src/subclass/aggregator.rs | 33 ++- gstreamer-base/src/subclass/aggregator_pad.rs | 12 +- gstreamer-base/src/subclass/base_sink.rs | 50 ++-- gstreamer-base/src/subclass/base_src.rs | 4 +- gstreamer-base/src/subclass/base_transform.rs | 13 +- gstreamer-check/src/harness.rs | 36 ++- gstreamer-rtsp-server/src/auto/rtsp_stream.rs | 16 -- .../src/auto/rtsp_stream_transport.rs | 8 - gstreamer-rtsp-server/src/lib.rs | 4 + gstreamer-rtsp-server/src/rtsp_stream.rs | 33 +++ .../src/rtsp_stream_transport.rs | 30 +++ gstreamer/src/auto/element.rs | 39 ---- gstreamer/src/auto/pad.rs | 35 +-- gstreamer/src/clock.rs | 20 +- gstreamer/src/element.rs | 72 ++++++ gstreamer/src/enums.rs | 36 +++ gstreamer/src/pad.rs | 213 +++++++++++++----- gstreamer/src/proxy_pad.rs | 15 +- gstreamer/src/subclass/element.rs | 13 +- tutorials/src/bin/basic-tutorial-1.rs | 10 +- tutorials/src/bin/basic-tutorial-12.rs | 4 +- tutorials/src/bin/basic-tutorial-2.rs | 18 +- tutorials/src/bin/basic-tutorial-3.rs | 22 +- tutorials/src/bin/basic-tutorial-4.rs | 11 +- tutorials/src/bin/basic-tutorial-5.rs | 21 +- tutorials/src/bin/basic-tutorial-6.rs | 11 +- tutorials/src/bin/basic-tutorial-7.rs | 10 +- tutorials/src/bin/basic-tutorial-8.rs | 21 +- 64 files changed, 987 insertions(+), 529 deletions(-) create mode 100644 gstreamer-rtsp-server/src/rtsp_stream.rs create mode 100644 gstreamer-rtsp-server/src/rtsp_stream_transport.rs diff --git a/Gir_Gst.toml b/Gir_Gst.toml index 2dda60f72..5ca86c57d 100644 --- a/Gir_Gst.toml +++ b/Gir_Gst.toml @@ -386,6 +386,26 @@ status = "generate" [object.function.return] bool_return_is_error = "Failed to sync state with parent" + [[object.function]] + name = "change_state" + # Use Result + ignore = true + + [[object.function]] + name = "continue_state" + # Use Result + ignore = true + + [[object.function]] + name = "get_state" + # Use Result + ignore = true + + [[object.function]] + name = "set_state" + # Use Result + ignore = true + [[object.function]] name = "query" # correct mutability @@ -645,6 +665,11 @@ status = "generate" # Buffer can be NULL ignore = true + [[object.function]] + name = "get_last_flow_return" + # Use Result + ignore = true + [[object.function]] name = "query" # Correct mutability @@ -685,6 +710,21 @@ status = "generate" # Pass by value ignore = true + [[object.function]] + name = "link" + # Use Result + ignore = true + + [[object.function]] + name = "link_full" + # Use Result + ignore = true + + [[object.function]] + name = "store_sticky_event" + # Use Result + ignore = true + [[object.function]] name = "new_from_static_template" # Correct mutability diff --git a/Gir_GstApp.toml b/Gir_GstApp.toml index 7bf5b13c0..58bbed88b 100644 --- a/Gir_GstApp.toml +++ b/Gir_GstApp.toml @@ -57,6 +57,16 @@ trait = false # Action signal ignore = true + [[object.signal]] + name = "new-sample" + # Use Result + ignore = true + + [[object.signal]] + name = "new-preroll" + # Use Result + ignore = true + [[object.function]] name = "set_caps" [[object.function.parameter]] @@ -98,6 +108,16 @@ trait = false # Action signal ignore = true + [[object.function]] + name = "end_of_stream" + # Use Result + ignore = true + + [[object.function]] + name = "push_sample" + # Use Result + ignore = true + [[object.function]] name = "set_latency" # ClockTime diff --git a/Gir_GstBase.toml b/Gir_GstBase.toml index dfe5d6ed5..5c227cb4d 100644 --- a/Gir_GstBase.toml +++ b/Gir_GstBase.toml @@ -77,16 +77,41 @@ name = "GstBase.BaseSink" subclassing = true status = "generate" + [[object.function]] + name = "wait" + # Use Result + ignore = true + + [[object.function]] + name = "wait_preroll" + # Use Result + ignore = true + [[object]] name = "GstBase.BaseSrc" subclassing = true status = "generate" + [[object.function]] + name = "start_complete" + # Use Result + ignore = true + + [[object.function]] + name = "start_wait" + # Use Result + ignore = true + [[object.function]] name = "submit_buffer_list" # Pass by value, to be added manually ignore = true + [[object.function]] + name = "wait_playing" + # Use Result + ignore = true + [[object]] name = "GstBase.BaseTransform" subclassing = true diff --git a/Gir_GstRtspServer.toml b/Gir_GstRtspServer.toml index 9d325607e..6a0717a4c 100644 --- a/Gir_GstRtspServer.toml +++ b/Gir_GstRtspServer.toml @@ -122,6 +122,16 @@ status = "generate" name = "GstRtspServer.RTSPStream" status = "generate" + [[object.function]] + name = "recv_rtcp" + # Use Result + ignore = true + + [[object.function]] + name = "recv_rtp" + # Use Result + ignore = true + [[object.function]] name = "query_position" ignore = true @@ -160,6 +170,11 @@ name = "GstRtspServer.RTSPStreamTransport" status = "generate" concurrency = "none" + [[object.function]] + name = "recv_data" + # Use Result + ignore = true + [[object.function]] name = "send_rtcp" [object.function.return] diff --git a/examples/src/bin/appsink.rs b/examples/src/bin/appsink.rs index 5fa1d694a..31bc70ebd 100644 --- a/examples/src/bin/appsink.rs +++ b/examples/src/bin/appsink.rs @@ -87,22 +87,16 @@ fn create_pipeline() -> Result { // Add a handler to the "new-sample" signal. .new_sample(|appsink| { // Pull the sample in question out of the appsink's buffer. - let sample = match appsink.pull_sample() { - None => return gst::FlowReturn::Eos, - Some(sample) => sample, - }; - - let buffer = if let Some(buffer) = sample.get_buffer() { - buffer - } else { + let sample = appsink.pull_sample().ok_or(gst::FlowError::Eos)?; + let buffer = sample.get_buffer().ok_or_else(|| { gst_element_error!( appsink, gst::ResourceError::Failed, ("Failed to get buffer from appsink") ); - return gst::FlowReturn::Error; - }; + gst::FlowError::Error + })?; // At this point, buffer is only a reference to an existing memory region somewhere. // When we want to access its content, we have to map it while requesting the required @@ -111,32 +105,28 @@ fn create_pipeline() -> Result { // on the machine's main memory itself, but rather in the GPU's memory. // So mapping the buffer makes the underlying memory region accessible to us. // See: https://gstreamer.freedesktop.org/documentation/plugin-development/advanced/allocation.html - let map = if let Some(map) = buffer.map_readable() { - map - } else { + let map = buffer.map_readable().ok_or_else(|| { gst_element_error!( appsink, gst::ResourceError::Failed, ("Failed to map buffer readable") ); - return gst::FlowReturn::Error; - }; + gst::FlowError::Error + })?; // We know what format the data in the memory region has, since we requested // it by setting the appsink's caps. So what we do here is interpret the // memory region we mapped as an array of signed 16 bit integers. - let samples = if let Ok(samples) = map.as_slice_of::() { - samples - } else { + let samples = map.as_slice_of::().map_err(|_| { gst_element_error!( appsink, gst::ResourceError::Failed, ("Failed to interprete buffer as S16 PCM") ); - return gst::FlowReturn::Error; - }; + gst::FlowError::Error + })?; // For buffer (= chunk of samples), we calculate the root mean square: // (https://en.wikipedia.org/wiki/Root_mean_square) @@ -150,7 +140,7 @@ fn create_pipeline() -> Result { let rms = (sum / (samples.len() as f64)).sqrt(); println!("rms: {}", rms); - gst::FlowReturn::Ok + Ok(gst::FlowSuccess::Ok) }) .build(), ); @@ -159,7 +149,7 @@ fn create_pipeline() -> Result { } fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> { - pipeline.set_state(gst::State::Playing).into_result()?; + pipeline.set_state(gst::State::Playing)?; let bus = pipeline .get_bus() @@ -171,7 +161,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> { match msg.view() { MessageView::Eos(..) => break, MessageView::Error(err) => { - pipeline.set_state(gst::State::Null).into_result()?; + pipeline.set_state(gst::State::Null)?; Err(ErrorMessage { src: msg .get_src() @@ -186,7 +176,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> { } } - pipeline.set_state(gst::State::Null).into_result()?; + pipeline.set_state(gst::State::Null)?; Ok(()) } diff --git a/examples/src/bin/appsrc.rs b/examples/src/bin/appsrc.rs index 2fc610df9..12223f904 100644 --- a/examples/src/bin/appsrc.rs +++ b/examples/src/bin/appsrc.rs @@ -141,7 +141,7 @@ fn create_pipeline() -> Result { } fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> { - pipeline.set_state(gst::State::Playing).into_result()?; + pipeline.set_state(gst::State::Playing)?; let bus = pipeline .get_bus() @@ -153,7 +153,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> { match msg.view() { MessageView::Eos(..) => break, MessageView::Error(err) => { - pipeline.set_state(gst::State::Null).into_result()?; + pipeline.set_state(gst::State::Null)?; Err(ErrorMessage { src: msg .get_src() @@ -168,7 +168,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> { } } - pipeline.set_state(gst::State::Null).into_result()?; + pipeline.set_state(gst::State::Null)?; Ok(()) } diff --git a/examples/src/bin/decodebin.rs b/examples/src/bin/decodebin.rs index d6940e88d..2b528ad40 100644 --- a/examples/src/bin/decodebin.rs +++ b/examples/src/bin/decodebin.rs @@ -181,7 +181,7 @@ fn example_main() -> Result<(), Error> { // Get the queue element's sink pad and link the decodebin's newly created // src pad for the audio stream to it. let sink_pad = queue.get_static_pad("sink").expect("queue has no sinkpad"); - src_pad.link(&sink_pad).into_result()?; + src_pad.link(&sink_pad)?; } else if is_video { // decodebin found a raw videostream, so we build the follow-up pipeline to // display it using the autovideosink. @@ -205,7 +205,7 @@ fn example_main() -> Result<(), Error> { // Get the queue element's sink pad and link the decodebin's newly created // src pad for the video stream to it. let sink_pad = queue.get_static_pad("sink").expect("queue has no sinkpad"); - src_pad.link(&sink_pad).into_result()?; + src_pad.link(&sink_pad)?; } Ok(()) @@ -243,7 +243,7 @@ fn example_main() -> Result<(), Error> { } }); - pipeline.set_state(gst::State::Playing).into_result()?; + pipeline.set_state(gst::State::Playing)?; let bus = pipeline .get_bus() @@ -259,7 +259,7 @@ fn example_main() -> Result<(), Error> { match msg.view() { MessageView::Eos(..) => break, MessageView::Error(err) => { - pipeline.set_state(gst::State::Null).into_result()?; + pipeline.set_state(gst::State::Null)?; #[cfg(feature = "v1_10")] { @@ -313,7 +313,7 @@ fn example_main() -> Result<(), Error> { } } - pipeline.set_state(gst::State::Null).into_result()?; + pipeline.set_state(gst::State::Null)?; Ok(()) } diff --git a/examples/src/bin/encodebin.rs b/examples/src/bin/encodebin.rs index d3783a9b0..43af237f9 100644 --- a/examples/src/bin/encodebin.rs +++ b/examples/src/bin/encodebin.rs @@ -210,7 +210,7 @@ fn example_main() -> Result<(), Error> { let src_pad = resample .get_static_pad("src") .expect("resample has no srcpad"); - src_pad.link(&enc_sink_pad).into_result()?; + src_pad.link(&enc_sink_pad)?; for e in elements { e.sync_state_with_parent()?; @@ -219,7 +219,7 @@ fn example_main() -> Result<(), Error> { // Get the queue element's sink pad and link the decodebin's newly created // src pad for the audio stream to it. let sink_pad = queue.get_static_pad("sink").expect("queue has no sinkpad"); - dbin_src_pad.link(&sink_pad).into_result()?; + dbin_src_pad.link(&sink_pad)?; } else if is_video { let queue = gst::ElementFactory::make("queue", None).ok_or(MissingElement("queue"))?; @@ -243,7 +243,7 @@ fn example_main() -> Result<(), Error> { let src_pad = scale .get_static_pad("src") .expect("videoscale has no srcpad"); - src_pad.link(&enc_sink_pad).into_result()?; + src_pad.link(&enc_sink_pad)?; for e in elements { e.sync_state_with_parent()? @@ -252,7 +252,7 @@ fn example_main() -> Result<(), Error> { // Get the queue element's sink pad and link the decodebin's newly created // src pad for the video stream to it. let sink_pad = queue.get_static_pad("sink").expect("queue has no sinkpad"); - dbin_src_pad.link(&sink_pad).into_result()?; + dbin_src_pad.link(&sink_pad)?; } Ok(()) @@ -280,7 +280,7 @@ fn example_main() -> Result<(), Error> { } }); - pipeline.set_state(gst::State::Playing).into_result()?; + pipeline.set_state(gst::State::Playing)?; let bus = pipeline .get_bus() @@ -292,7 +292,7 @@ fn example_main() -> Result<(), Error> { match msg.view() { MessageView::Eos(..) => break, MessageView::Error(err) => { - pipeline.set_state(gst::State::Null).into_result()?; + pipeline.set_state(gst::State::Null)?; #[cfg(feature = "v1_10")] { @@ -342,7 +342,7 @@ fn example_main() -> Result<(), Error> { } } - pipeline.set_state(gst::State::Null).into_result()?; + pipeline.set_state(gst::State::Null)?; Ok(()) } diff --git a/examples/src/bin/events.rs b/examples/src/bin/events.rs index e1cc57a1f..cb02100ae 100644 --- a/examples/src/bin/events.rs +++ b/examples/src/bin/events.rs @@ -36,8 +36,9 @@ fn example_main() { let pipeline = gst::parse_launch("audiotestsrc ! fakesink").unwrap(); let bus = pipeline.get_bus().unwrap(); - let ret = pipeline.set_state(gst::State::Playing); - assert_ne!(ret, gst::StateChangeReturn::Failure); + pipeline + .set_state(gst::State::Playing) + .expect("Unable to set the pipeline to the `Playing` state"); // Need to move a new reference into the closure. // !!ATTENTION!!: @@ -122,8 +123,9 @@ fn example_main() { // (see above for how to do this). main_loop.run(); - let ret = pipeline.set_state(gst::State::Null); - assert_ne!(ret, gst::StateChangeReturn::Failure); + pipeline + .set_state(gst::State::Null) + .expect("Unable to set the pipeline to the `Null` state"); // Remove the watch function from the bus. // Again: There can always only be one watch function. diff --git a/examples/src/bin/futures.rs b/examples/src/bin/futures.rs index 79249c7f6..971516588 100644 --- a/examples/src/bin/futures.rs +++ b/examples/src/bin/futures.rs @@ -25,8 +25,9 @@ fn example_main() { let pipeline = gst::parse_launch(&pipeline_str).unwrap(); let bus = pipeline.get_bus().unwrap(); - let ret = pipeline.set_state(gst::State::Playing); - assert_ne!(ret, gst::StateChangeReturn::Failure); + pipeline + .set_state(gst::State::Playing) + .expect("Unable to set the pipeline to the `Playing` state"); // BusStream implements the Stream trait, but Stream::for_each is // calling a closure for each item and returns a Future that resolves @@ -65,8 +66,9 @@ fn example_main() { // Synchronously wait on the future we created above. let _ = block_on(messages); - let ret = pipeline.set_state(gst::State::Null); - assert_ne!(ret, gst::StateChangeReturn::Failure); + pipeline + .set_state(gst::State::Null) + .expect("Unable to set the pipeline to the `Null` state"); } fn main() { diff --git a/examples/src/bin/ges.rs b/examples/src/bin/ges.rs index 49b3c16a0..beda84f17 100644 --- a/examples/src/bin/ges.rs +++ b/examples/src/bin/ges.rs @@ -100,8 +100,9 @@ fn main_loop(uri: &str) -> Result<(), glib::BoolError> { clip.set_inpoint(duration / 2); clip.set_duration(duration / 4); - let ret = pipeline.set_state(gst::State::Playing); - assert_ne!(ret, gst::StateChangeReturn::Failure); + pipeline + .set_state(gst::State::Playing) + .expect("Unable to set the pipeline to the `Playing` state"); let bus = pipeline.get_bus().unwrap(); for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { @@ -122,8 +123,9 @@ fn main_loop(uri: &str) -> Result<(), glib::BoolError> { } } - let ret = pipeline.set_state(gst::State::Null); - assert_ne!(ret, gst::StateChangeReturn::Failure); + pipeline + .set_state(gst::State::Null) + .expect("Unable to set the pipeline to the `Null` state"); Ok(()) } diff --git a/examples/src/bin/glib-futures.rs b/examples/src/bin/glib-futures.rs index 94ebef574..e78a1e0f3 100644 --- a/examples/src/bin/glib-futures.rs +++ b/examples/src/bin/glib-futures.rs @@ -21,8 +21,9 @@ fn example_main() { let pipeline = gst::parse_launch(&pipeline_str).unwrap(); let bus = pipeline.get_bus().unwrap(); - let ret = pipeline.set_state(gst::State::Playing); - assert_ne!(ret, gst::StateChangeReturn::Failure); + pipeline + .set_state(gst::State::Playing) + .expect("Unable to set the pipeline to the `Playing` state"); let messages = gst::BusStream::new(&bus) .for_each(|msg| { @@ -52,8 +53,9 @@ fn example_main() { let _ = ctx.block_on(messages); - let ret = pipeline.set_state(gst::State::Null); - assert_ne!(ret, gst::StateChangeReturn::Failure); + pipeline + .set_state(gst::State::Null) + .expect("Unable to set the pipeline to the `Null` state"); } fn main() { diff --git a/examples/src/bin/glupload.rs b/examples/src/bin/glupload.rs index dc79df7bd..a64ba5ad5 100644 --- a/examples/src/bin/glupload.rs +++ b/examples/src/bin/glupload.rs @@ -428,34 +428,42 @@ impl App { self.appsink.set_callbacks( gst_app::AppSinkCallbacks::new() .new_sample(move |appsink| { - let sample = match appsink.pull_sample() { - None => return gst::FlowReturn::Eos, - Some(sample) => sample, - }; + let sample = appsink.pull_sample().ok_or(gst::FlowError::Eos)?; - let buffer = sample.get_buffer(); - let info = sample - .get_caps() - .and_then(|caps| gst_video::VideoInfo::from_caps(caps.as_ref())); - if buffer.is_none() || info.is_none() { + let _buffer = sample.get_buffer().ok_or_else(|| { gst_element_error!( appsink, gst::ResourceError::Failed, ("Failed to get buffer from appsink") ); - return gst::FlowReturn::Error; - }; + gst::FlowError::Error + })?; - match sender_clone.lock().unwrap().send(sample) { - Ok(_) => return gst::FlowReturn::Ok, - Err(_) => return gst::FlowReturn::Error, - } + let _info = sample + .get_caps() + .and_then(|caps| gst_video::VideoInfo::from_caps(caps.as_ref())) + .ok_or_else(|| { + gst_element_error!( + appsink, + gst::ResourceError::Failed, + ("Failed to get video info from sample") + ); + + gst::FlowError::Error + })?; + + sender_clone + .lock() + .unwrap() + .send(sample) + .map(|_| gst::FlowSuccess::Ok) + .map_err(|_| gst::FlowError::Error) }) .build(), ); - self.pipeline.set_state(gst::State::Playing).into_result()?; + self.pipeline.set_state(gst::State::Playing)?; Ok((bus_handler, receiver)) } @@ -576,7 +584,7 @@ fn main_loop(mut app: App) -> Result<(), Error> { app.pipeline.send_event(gst::Event::new_eos().build()); bus_handler.join().expect("Could join bus handler thread"); - app.pipeline.set_state(gst::State::Null).into_result()?; + app.pipeline.set_state(gst::State::Null)?; Ok(()) } diff --git a/examples/src/bin/gtksink.rs b/examples/src/bin/gtksink.rs index 6f94029d5..e2ad45239 100644 --- a/examples/src/bin/gtksink.rs +++ b/examples/src/bin/gtksink.rs @@ -108,8 +108,9 @@ fn create_ui(app: >k::Application) { let bus = pipeline.get_bus().unwrap(); - let ret = pipeline.set_state(gst::State::Playing); - assert_ne!(ret, gst::StateChangeReturn::Failure); + pipeline + .set_state(gst::State::Playing) + .expect("Unable to set the pipeline to the `Playing` state"); let app_weak = glib::SendWeakRef::from(app.downgrade()); bus.add_watch(move |_, msg| { @@ -141,8 +142,9 @@ fn create_ui(app: >k::Application) { // destroyed once the app is destroyed let timeout_id = RefCell::new(Some(timeout_id)); app.connect_shutdown(move |_| { - let ret = pipeline.set_state(gst::State::Null); - assert_ne!(ret, gst::StateChangeReturn::Failure); + pipeline + .set_state(gst::State::Null) + .expect("Unable to set the pipeline to the `Null` state"); bus.remove_watch(); if let Some(timeout_id) = timeout_id.borrow_mut().take() { diff --git a/examples/src/bin/gtkvideooverlay.rs b/examples/src/bin/gtkvideooverlay.rs index 9f866d8ae..b5e8fe683 100644 --- a/examples/src/bin/gtkvideooverlay.rs +++ b/examples/src/bin/gtkvideooverlay.rs @@ -211,8 +211,9 @@ fn create_ui(app: >k::Application) { let bus = pipeline.get_bus().unwrap(); - let ret = pipeline.set_state(gst::State::Playing); - assert_ne!(ret, gst::StateChangeReturn::Failure); + pipeline + .set_state(gst::State::Playing) + .expect("Unable to set the pipeline to the `Playing` state"); let app_weak = glib::SendWeakRef::from(app.downgrade()); bus.add_watch(move |_, msg| { @@ -244,8 +245,9 @@ fn create_ui(app: >k::Application) { // destroyed once the app is destroyed let timeout_id = RefCell::new(Some(timeout_id)); app.connect_shutdown(move |_| { - let ret = pipeline.set_state(gst::State::Null); - assert_ne!(ret, gst::StateChangeReturn::Failure); + pipeline + .set_state(gst::State::Null) + .expect("Unable to set the pipeline to the `Null` state"); bus.remove_watch(); if let Some(timeout_id) = timeout_id.borrow_mut().take() { diff --git a/examples/src/bin/launch.rs b/examples/src/bin/launch.rs index ffa71d794..f7b4ec68a 100644 --- a/examples/src/bin/launch.rs +++ b/examples/src/bin/launch.rs @@ -43,8 +43,9 @@ fn example_main() { }; let bus = pipeline.get_bus().unwrap(); - let ret = pipeline.set_state(gst::State::Playing); - assert_ne!(ret, gst::StateChangeReturn::Failure); + pipeline + .set_state(gst::State::Playing) + .expect("Unable to set the pipeline to the `Playing` state"); for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { use gst::MessageView; @@ -64,8 +65,9 @@ fn example_main() { } } - let ret = pipeline.set_state(gst::State::Null); - assert_ne!(ret, gst::StateChangeReturn::Failure); + pipeline + .set_state(gst::State::Null) + .expect("Unable to set the pipeline to the `Null` state"); } fn main() { diff --git a/examples/src/bin/launch_glib_main.rs b/examples/src/bin/launch_glib_main.rs index e8136ac79..c8820b32a 100644 --- a/examples/src/bin/launch_glib_main.rs +++ b/examples/src/bin/launch_glib_main.rs @@ -30,8 +30,9 @@ fn example_main() { let pipeline = gst::parse_launch(&pipeline_str).unwrap(); let bus = pipeline.get_bus().unwrap(); - let ret = pipeline.set_state(gst::State::Playing); - assert_ne!(ret, gst::StateChangeReturn::Failure); + pipeline + .set_state(gst::State::Playing) + .expect("Unable to set the pipeline to the `Playing` state"); let main_loop_clone = main_loop.clone(); @@ -60,8 +61,9 @@ fn example_main() { main_loop.run(); - let ret = pipeline.set_state(gst::State::Null); - assert_ne!(ret, gst::StateChangeReturn::Failure); + pipeline + .set_state(gst::State::Null) + .expect("Unable to set the pipeline to the `Null` state"); // Here we remove the bus watch we added above. This avoids a memory leak, that might // otherwise happen because we moved a strong reference (clone of main_loop) into the diff --git a/examples/src/bin/pad_probes.rs b/examples/src/bin/pad_probes.rs index bcea609e1..ec3d0fb45 100644 --- a/examples/src/bin/pad_probes.rs +++ b/examples/src/bin/pad_probes.rs @@ -75,8 +75,9 @@ fn example_main() { gst::PadProbeReturn::Ok }); - let ret = pipeline.set_state(gst::State::Playing); - assert_ne!(ret, gst::StateChangeReturn::Failure); + pipeline + .set_state(gst::State::Playing) + .expect("Unable to set the pipeline to the `Playing` state"); let bus = pipeline.get_bus().unwrap(); for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { @@ -97,8 +98,9 @@ fn example_main() { } } - let ret = pipeline.set_state(gst::State::Null); - assert_ne!(ret, gst::StateChangeReturn::Failure); + pipeline + .set_state(gst::State::Null) + .expect("Unable to set the pipeline to the `Null` state"); } fn main() { diff --git a/examples/src/bin/pango-cairo.rs b/examples/src/bin/pango-cairo.rs index 3bb6d7d75..c344d0446 100644 --- a/examples/src/bin/pango-cairo.rs +++ b/examples/src/bin/pango-cairo.rs @@ -237,7 +237,7 @@ fn create_pipeline() -> Result { } fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> { - pipeline.set_state(gst::State::Playing).into_result()?; + pipeline.set_state(gst::State::Playing)?; let bus = pipeline .get_bus() @@ -249,7 +249,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> { match msg.view() { MessageView::Eos(..) => break, MessageView::Error(err) => { - pipeline.set_state(gst::State::Null).into_result()?; + pipeline.set_state(gst::State::Null)?; Err(ErrorMessage { src: msg .get_src() @@ -264,7 +264,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> { } } - pipeline.set_state(gst::State::Null).into_result()?; + pipeline.set_state(gst::State::Null)?; Ok(()) } diff --git a/examples/src/bin/playbin.rs b/examples/src/bin/playbin.rs index 3e5944663..a27598ca8 100644 --- a/examples/src/bin/playbin.rs +++ b/examples/src/bin/playbin.rs @@ -103,8 +103,9 @@ fn example_main() { // created from an element factory. let bus = playbin.get_bus().unwrap(); - let ret = playbin.set_state(gst::State::Playing); - assert_ne!(ret, gst::StateChangeReturn::Failure); + playbin + .set_state(gst::State::Playing) + .expect("Unable to set the pipeline to the `Playing` state"); for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { use gst::MessageView; @@ -124,8 +125,9 @@ fn example_main() { } } - let ret = playbin.set_state(gst::State::Null); - assert_ne!(ret, gst::StateChangeReturn::Failure); + playbin + .set_state(gst::State::Null) + .expect("Unable to set the pipeline to the `Null` state"); } fn main() { diff --git a/examples/src/bin/queries.rs b/examples/src/bin/queries.rs index 3b93bfde2..6e5ad2074 100644 --- a/examples/src/bin/queries.rs +++ b/examples/src/bin/queries.rs @@ -34,8 +34,9 @@ fn example_main() { let pipeline = gst::parse_launch(&pipeline_str).unwrap(); let bus = pipeline.get_bus().unwrap(); - let ret = pipeline.set_state(gst::State::Playing); - assert_ne!(ret, gst::StateChangeReturn::Failure); + pipeline + .set_state(gst::State::Playing) + .expect("Unable to set the pipeline to the `Playing` state"); // Need to move a new reference into the closure. // !!ATTENTION!!: @@ -119,8 +120,9 @@ fn example_main() { main_loop.run(); - let ret = pipeline.set_state(gst::State::Null); - assert_ne!(ret, gst::StateChangeReturn::Failure); + pipeline + .set_state(gst::State::Null) + .expect("Unable to set the pipeline to the `Null` state"); bus.remove_watch(); glib::source_remove(timeout_id); diff --git a/examples/src/bin/rtpfecclient.rs b/examples/src/bin/rtpfecclient.rs index 85b7dc420..3d178d749 100644 --- a/examples/src/bin/rtpfecclient.rs +++ b/examples/src/bin/rtpfecclient.rs @@ -84,7 +84,7 @@ fn connect_rtpbin_srcpad(src_pad: &gst::Pad, sink: &gst::Element) -> Result<(), match pt { 96 => { let sinkpad = get_static_pad(sink, "sink")?; - src_pad.link(&sinkpad).into_result()?; + src_pad.link(&sinkpad)?; Ok(()) } _ => Err(Error::from(UnknownPT(pt))), @@ -208,7 +208,7 @@ fn example_main() -> Result<(), Error> { let srcpad = get_static_pad(&netsim, "src")?; let sinkpad = get_request_pad(&rtpbin, "recv_rtp_sink_0")?; - srcpad.link(&sinkpad).into_result()?; + srcpad.link(&sinkpad)?; let depay_weak = depay.downgrade(); rtpbin.connect_pad_added(move |rtpbin, src_pad| { @@ -246,8 +246,9 @@ fn example_main() -> Result<(), Error> { .get_bus() .expect("Pipeline without bus. Shouldn't happen!"); - let ret = pipeline.set_state(gst::State::Playing); - assert_ne!(ret, gst::StateChangeReturn::Failure); + pipeline + .set_state(gst::State::Playing) + .expect("Unable to set the pipeline to the `Playing` state"); for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { use gst::MessageView; @@ -255,8 +256,9 @@ fn example_main() -> Result<(), Error> { match msg.view() { MessageView::Eos(..) => break, MessageView::Error(err) => { - let ret = pipeline.set_state(gst::State::Null); - assert_ne!(ret, gst::StateChangeReturn::Failure); + pipeline + .set_state(gst::State::Null) + .expect("Unable to set the pipeline to the `Null` state"); return Err(ErrorMessage { src: msg @@ -286,8 +288,9 @@ fn example_main() -> Result<(), Error> { } } - let ret = pipeline.set_state(gst::State::Null); - assert_ne!(ret, gst::StateChangeReturn::Failure); + pipeline + .set_state(gst::State::Null) + .expect("Unable to set the pipeline to the `Null` state"); Ok(()) } diff --git a/examples/src/bin/rtpfecserver.rs b/examples/src/bin/rtpfecserver.rs index 2e837f129..93b340a8e 100644 --- a/examples/src/bin/rtpfecserver.rs +++ b/examples/src/bin/rtpfecserver.rs @@ -74,7 +74,7 @@ fn get_request_pad(element: &gst::Element, pad_name: &'static str) -> Result Result<(), Error> { let sinkpad = get_static_pad(&sink, "sink")?; - src_pad.link(&sinkpad).into_result()?; + src_pad.link(&sinkpad)?; Ok(()) } @@ -137,11 +137,11 @@ fn example_main() -> Result<(), Error> { let srcpad = get_static_pad(&q2, "src")?; let sinkpad = get_request_pad(&rtpbin, "send_rtp_sink_0")?; - srcpad.link(&sinkpad).into_result()?; + srcpad.link(&sinkpad)?; let srcpad = get_static_pad(&rtpbin, "send_rtp_src_0")?; let sinkpad = get_static_pad(&sink, "sink")?; - srcpad.link(&sinkpad).into_result()?; + srcpad.link(&sinkpad)?; let convclone = conv.clone(); src.connect_pad_added(move |decodebin, src_pad| { @@ -177,8 +177,9 @@ fn example_main() -> Result<(), Error> { .get_bus() .expect("Pipeline without bus. Shouldn't happen!"); - let ret = pipeline.set_state(gst::State::Playing); - assert_ne!(ret, gst::StateChangeReturn::Failure); + pipeline + .set_state(gst::State::Playing) + .expect("Unable to set the pipeline to the `Playing` state"); for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { use gst::MessageView; @@ -186,8 +187,9 @@ fn example_main() -> Result<(), Error> { match msg.view() { MessageView::Eos(..) => break, MessageView::Error(err) => { - let ret = pipeline.set_state(gst::State::Null); - assert_ne!(ret, gst::StateChangeReturn::Failure); + pipeline + .set_state(gst::State::Null) + .expect("Unable to set the pipeline to the `Null` state"); return Err(ErrorMessage { src: msg @@ -217,8 +219,9 @@ fn example_main() -> Result<(), Error> { } } - let ret = pipeline.set_state(gst::State::Null); - assert_ne!(ret, gst::StateChangeReturn::Failure); + pipeline + .set_state(gst::State::Null) + .expect("Unable to set the pipeline to the `Null` state"); Ok(()) } diff --git a/examples/src/bin/tagsetter.rs b/examples/src/bin/tagsetter.rs index 608211189..d11b8d41e 100644 --- a/examples/src/bin/tagsetter.rs +++ b/examples/src/bin/tagsetter.rs @@ -94,7 +94,7 @@ fn example_main() -> Result<(), Error> { let bus = pipeline.get_bus().unwrap(); - pipeline.set_state(gst::State::Playing).into_result()?; + pipeline.set_state(gst::State::Playing)?; for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { use gst::MessageView; @@ -118,7 +118,7 @@ fn example_main() -> Result<(), Error> { } } - pipeline.set_state(gst::State::Null).into_result()?; + pipeline.set_state(gst::State::Null)?; Ok(()) } diff --git a/examples/src/bin/toc.rs b/examples/src/bin/toc.rs index 087e953fe..c4fd587da 100644 --- a/examples/src/bin/toc.rs +++ b/examples/src/bin/toc.rs @@ -75,13 +75,14 @@ fn example_main() { } let sink_pad = queue.get_static_pad("sink").unwrap(); - assert_eq!(src_pad.link(&sink_pad), gst::PadLinkReturn::Ok); + src_pad + .link(&sink_pad) + .expect("Unable to link src pad to sink pad"); }); - assert_ne!( - pipeline.set_state(gst::State::Paused), - gst::StateChangeReturn::Failure - ); + pipeline + .set_state(gst::State::Paused) + .expect("Unable to set the pipeline to the `Paused` state"); let bus = pipeline.get_bus().unwrap(); @@ -161,10 +162,9 @@ fn example_main() { } } - assert_ne!( - pipeline.set_state(gst::State::Null), - gst::StateChangeReturn::Failure - ); + pipeline + .set_state(gst::State::Null) + .expect("Unable to set the pipeline to the `Null` state"); } fn main() { diff --git a/examples/src/bin/transmux.rs b/examples/src/bin/transmux.rs index 6f183ce47..ab4f8bf1a 100644 --- a/examples/src/bin/transmux.rs +++ b/examples/src/bin/transmux.rs @@ -153,7 +153,7 @@ fn example_main() -> Result<(), Error> { }) .expect("Failed to register have-type signal of typefind"); - pipeline.set_state(gst::State::Playing).into_result()?; + pipeline.set_state(gst::State::Playing)?; let bus = pipeline .get_bus() @@ -165,7 +165,7 @@ fn example_main() -> Result<(), Error> { match msg.view() { MessageView::Eos(..) => break, MessageView::Error(err) => { - pipeline.set_state(gst::State::Null).into_result()?; + pipeline.set_state(gst::State::Null)?; Err(ErrorMessage { src: msg @@ -191,7 +191,7 @@ fn example_main() -> Result<(), Error> { } } - pipeline.set_state(gst::State::Null).into_result()?; + pipeline.set_state(gst::State::Null)?; Ok(()) } @@ -209,7 +209,7 @@ fn handle_demux_pad_added( let queue_sink_pad = queue .get_request_pad("sink_%u") .expect("If this happened, something is terribly wrong"); - demux_src_pad.link(&queue_sink_pad).into_result()?; + demux_src_pad.link(&queue_sink_pad)?; // Now that we requested a sink pad fitting our needs from the multiqueue, // the multiqueue automatically created a fitting src pad on the other side. // sink and src pad are linked internally, so we can iterate this internal link chain @@ -224,7 +224,7 @@ fn handle_demux_pad_added( let muxer_sink_pad = muxer .get_compatible_pad(&queue_src_pad, None) .expect("Aww, you found a format that matroska doesn't support!"); - queue_src_pad.link(&muxer_sink_pad).into_result()?; + queue_src_pad.link(&muxer_sink_pad)?; Ok(()) }; diff --git a/gstreamer-app/src/app_sink.rs b/gstreamer-app/src/app_sink.rs index 0561d764c..b1c382b68 100644 --- a/gstreamer-app/src/app_sink.rs +++ b/gstreamer-app/src/app_sink.rs @@ -7,19 +7,27 @@ // except according to those terms. use ffi; +use glib::signal::connect_raw; +use glib::signal::SignalHandlerId; use glib::translate::*; use glib_ffi::gpointer; use gst; use gst_ffi; +use std::boxed::Box as Box_; use std::cell::RefCell; +use std::mem::transmute; use std::ptr; use AppSink; #[cfg_attr(feature = "cargo-clippy", allow(type_complexity))] pub struct AppSinkCallbacks { eos: Option>>, - new_preroll: Option gst::FlowReturn + Send + 'static>>>, - new_sample: Option gst::FlowReturn + Send + 'static>>>, + new_preroll: Option< + RefCell Result + Send + 'static>>, + >, + new_sample: Option< + RefCell Result + Send + 'static>>, + >, callbacks: ffi::GstAppSinkCallbacks, } @@ -40,8 +48,12 @@ impl AppSinkCallbacks { #[cfg_attr(feature = "cargo-clippy", allow(type_complexity))] pub struct AppSinkCallbacksBuilder { eos: Option>>, - new_preroll: Option gst::FlowReturn + Send + 'static>>>, - new_sample: Option gst::FlowReturn + Send + 'static>>>, + new_preroll: Option< + RefCell Result + Send + 'static>>, + >, + new_sample: Option< + RefCell Result + Send + 'static>>, + >, } impl AppSinkCallbacksBuilder { @@ -52,7 +64,9 @@ impl AppSinkCallbacksBuilder { } } - pub fn new_preroll gst::FlowReturn + Send + Sync + 'static>( + pub fn new_preroll< + F: Fn(&AppSink) -> Result + Send + Sync + 'static, + >( self, new_preroll: F, ) -> Self { @@ -62,7 +76,9 @@ impl AppSinkCallbacksBuilder { } } - pub fn new_sample gst::FlowReturn + Send + Sync + 'static>( + pub fn new_sample< + F: Fn(&AppSink) -> Result + Send + Sync + 'static, + >( self, new_sample: F, ) -> Self { @@ -119,7 +135,7 @@ unsafe extern "C" fn trampoline_new_preroll( let callbacks = &*(callbacks as *const AppSinkCallbacks); let ret = if let Some(ref new_preroll) = callbacks.new_preroll { - (&mut *new_preroll.borrow_mut())(&from_glib_borrow(appsink)) + (&mut *new_preroll.borrow_mut())(&from_glib_borrow(appsink)).into() } else { gst::FlowReturn::Error }; @@ -134,7 +150,7 @@ unsafe extern "C" fn trampoline_new_sample( let callbacks = &*(callbacks as *const AppSinkCallbacks); let ret = if let Some(ref new_sample) = callbacks.new_sample { - (&mut *new_sample.borrow_mut())(&from_glib_borrow(appsink)) + (&mut *new_sample.borrow_mut())(&from_glib_borrow(appsink)).into() } else { gst::FlowReturn::Error }; @@ -157,4 +173,72 @@ impl AppSink { ); } } + + pub fn connect_new_sample< + F: Fn(&AppSink) -> Result + Send + Sync + 'static, + >( + &self, + f: F, + ) -> SignalHandlerId { + unsafe { + let f: Box_< + Box_< + Fn(&AppSink) -> Result + + Send + + Sync + + 'static, + >, + > = Box_::new(Box_::new(f)); + connect_raw( + self.to_glib_none().0, + b"new-sample\0".as_ptr() as *const _, + transmute(new_sample_trampoline as usize), + Box_::into_raw(f) as *mut _, + ) + } + } + + pub fn connect_new_preroll< + F: Fn(&AppSink) -> Result + Send + Sync + 'static, + >( + &self, + f: F, + ) -> SignalHandlerId { + unsafe { + let f: Box_< + Box_< + Fn(&AppSink) -> Result + + Send + + Sync + + 'static, + >, + > = Box_::new(Box_::new(f)); + connect_raw( + self.to_glib_none().0, + b"new-preroll\0".as_ptr() as *const _, + transmute(new_preroll_trampoline as usize), + Box_::into_raw(f) as *mut _, + ) + } + } +} + +unsafe extern "C" fn new_sample_trampoline( + this: *mut ffi::GstAppSink, + f: glib_ffi::gpointer, +) -> gst_ffi::GstFlowReturn { + let f: &&(Fn(&AppSink) -> Result + Send + Sync + 'static) = + transmute(f); + let ret: gst::FlowReturn = f(&from_glib_borrow(this)).into(); + ret.to_glib() +} + +unsafe extern "C" fn new_preroll_trampoline( + this: *mut ffi::GstAppSink, + f: glib_ffi::gpointer, +) -> gst_ffi::GstFlowReturn { + let f: &&(Fn(&AppSink) -> Result + Send + Sync + 'static) = + transmute(f); + let ret: gst::FlowReturn = f(&from_glib_borrow(this)).into(); + ret.to_glib() } diff --git a/gstreamer-app/src/app_src.rs b/gstreamer-app/src/app_src.rs index 46e84f874..701a18f92 100644 --- a/gstreamer-app/src/app_src.rs +++ b/gstreamer-app/src/app_src.rs @@ -147,23 +147,44 @@ unsafe extern "C" fn destroy_callbacks(ptr: gpointer) { } impl AppSrc { - pub fn push_buffer(&self, buffer: gst::Buffer) -> gst::FlowReturn { - unsafe { + pub fn end_of_stream(&self) -> Result { + let ret: gst::FlowReturn = + unsafe { from_glib(ffi::gst_app_src_end_of_stream(self.to_glib_none().0)) }; + ret.into_result() + } + + pub fn push_buffer(&self, buffer: gst::Buffer) -> Result { + let ret: gst::FlowReturn = unsafe { from_glib(ffi::gst_app_src_push_buffer( self.to_glib_none().0, buffer.into_ptr(), )) - } + }; + ret.into_result() } #[cfg(any(feature = "v1_14", feature = "dox"))] - pub fn push_buffer_list(&self, list: gst::BufferList) -> gst::FlowReturn { - unsafe { + pub fn push_buffer_list( + &self, + list: gst::BufferList, + ) -> Result { + let ret: gst::FlowReturn = unsafe { from_glib(ffi::gst_app_src_push_buffer_list( self.to_glib_none().0, list.into_ptr(), )) - } + }; + ret.into_result() + } + + pub fn push_sample(&self, sample: &gst::Sample) -> Result { + let ret: gst::FlowReturn = unsafe { + from_glib(ffi::gst_app_src_push_sample( + self.to_glib_none().0, + sample.to_glib_none().0, + )) + }; + ret.into_result() } pub fn set_callbacks(&self, callbacks: AppSrcCallbacks) { diff --git a/gstreamer-app/src/auto/app_sink.rs b/gstreamer-app/src/auto/app_sink.rs index 609c0865d..efa9e8e8a 100644 --- a/gstreamer-app/src/auto/app_sink.rs +++ b/gstreamer-app/src/auto/app_sink.rs @@ -173,22 +173,6 @@ impl AppSink { } } - pub fn connect_new_preroll gst::FlowReturn + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId { - unsafe { - let f: Box_ gst::FlowReturn + Send + Sync + 'static>> = Box_::new(Box_::new(f)); - connect_raw(self.to_glib_none().0, b"new-preroll\0".as_ptr() as *const _, - transmute(new_preroll_trampoline as usize), Box_::into_raw(f) as *mut _) - } - } - - pub fn connect_new_sample gst::FlowReturn + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId { - unsafe { - let f: Box_ gst::FlowReturn + Send + Sync + 'static>> = Box_::new(Box_::new(f)); - connect_raw(self.to_glib_none().0, b"new-sample\0".as_ptr() as *const _, - transmute(new_sample_trampoline as usize), Box_::into_raw(f) as *mut _) - } - } - pub fn connect_property_buffer_list_notify(&self, f: F) -> SignalHandlerId { unsafe { let f: Box_> = Box_::new(Box_::new(f)); @@ -254,16 +238,6 @@ unsafe extern "C" fn eos_trampoline(this: *mut ffi::GstAppSink, f: glib_ffi::gpo f(&from_glib_borrow(this)) } -unsafe extern "C" fn new_preroll_trampoline(this: *mut ffi::GstAppSink, f: glib_ffi::gpointer) -> gst_ffi::GstFlowReturn { - let f: &&(Fn(&AppSink) -> gst::FlowReturn + Send + Sync + 'static) = transmute(f); - f(&from_glib_borrow(this)).to_glib() -} - -unsafe extern "C" fn new_sample_trampoline(this: *mut ffi::GstAppSink, f: glib_ffi::gpointer) -> gst_ffi::GstFlowReturn { - let f: &&(Fn(&AppSink) -> gst::FlowReturn + Send + Sync + 'static) = transmute(f); - f(&from_glib_borrow(this)).to_glib() -} - unsafe extern "C" fn notify_buffer_list_trampoline(this: *mut ffi::GstAppSink, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer) { let f: &&(Fn(&AppSink) + Send + Sync + 'static) = transmute(f); f(&from_glib_borrow(this)) diff --git a/gstreamer-app/src/auto/app_src.rs b/gstreamer-app/src/auto/app_src.rs index 22370df04..cb5656bc6 100644 --- a/gstreamer-app/src/auto/app_src.rs +++ b/gstreamer-app/src/auto/app_src.rs @@ -33,12 +33,6 @@ glib_wrapper! { } impl AppSrc { - pub fn end_of_stream(&self) -> gst::FlowReturn { - unsafe { - from_glib(ffi::gst_app_src_end_of_stream(self.to_glib_none().0)) - } - } - pub fn get_caps(&self) -> Option { unsafe { from_glib_full(ffi::gst_app_src_get_caps(self.to_glib_none().0)) @@ -82,12 +76,6 @@ impl AppSrc { } } - pub fn push_sample(&self, sample: &gst::Sample) -> gst::FlowReturn { - unsafe { - from_glib(ffi::gst_app_src_push_sample(self.to_glib_none().0, sample.to_glib_none().0)) - } - } - //pub fn set_callbacks(&self, callbacks: /*Ignored*/&mut AppSrcCallbacks, notify: /*Unknown conversion*//*Unimplemented*/DestroyNotify) { // unsafe { TODO: call ffi::gst_app_src_set_callbacks() } //} diff --git a/gstreamer-base/src/aggregator.rs b/gstreamer-base/src/aggregator.rs index c07248733..9d652818e 100644 --- a/gstreamer-base/src/aggregator.rs +++ b/gstreamer-base/src/aggregator.rs @@ -15,17 +15,18 @@ use Aggregator; use std::ops; pub trait AggregatorExtManual: 'static { - fn finish_buffer(&self, buffer: gst::Buffer) -> gst::FlowReturn; + fn finish_buffer(&self, buffer: gst::Buffer) -> Result; } impl> AggregatorExtManual for O { - fn finish_buffer(&self, buffer: gst::Buffer) -> gst::FlowReturn { - unsafe { + fn finish_buffer(&self, buffer: gst::Buffer) -> Result { + let ret: gst::FlowReturn = unsafe { from_glib(ffi::gst_aggregator_finish_buffer( self.to_glib_none().0, buffer.into_ptr(), )) - } + }; + ret.into_result() } } diff --git a/gstreamer-base/src/auto/base_sink.rs b/gstreamer-base/src/auto/base_sink.rs index 9f76eb6fb..cff56d0c4 100644 --- a/gstreamer-base/src/auto/base_sink.rs +++ b/gstreamer-base/src/auto/base_sink.rs @@ -88,12 +88,8 @@ pub trait BaseSinkExt: 'static { fn set_ts_offset(&self, offset: gst::ClockTimeDiff); - fn wait(&self, time: gst::ClockTime) -> (gst::FlowReturn, gst::ClockTimeDiff); - fn wait_clock(&self, time: gst::ClockTime) -> (gst::ClockReturn, gst::ClockTimeDiff); - fn wait_preroll(&self) -> gst::FlowReturn; - fn get_property_async(&self) -> bool; fn set_property_async(&self, async: bool); @@ -291,14 +287,6 @@ impl> BaseSinkExt for O { } } - fn wait(&self, time: gst::ClockTime) -> (gst::FlowReturn, gst::ClockTimeDiff) { - unsafe { - let mut jitter = mem::uninitialized(); - let ret = from_glib(ffi::gst_base_sink_wait(self.to_glib_none().0, time.to_glib(), &mut jitter)); - (ret, jitter) - } - } - fn wait_clock(&self, time: gst::ClockTime) -> (gst::ClockReturn, gst::ClockTimeDiff) { unsafe { let mut jitter = mem::uninitialized(); @@ -307,12 +295,6 @@ impl> BaseSinkExt for O { } } - fn wait_preroll(&self) -> gst::FlowReturn { - unsafe { - from_glib(ffi::gst_base_sink_wait_preroll(self.to_glib_none().0)) - } - } - fn get_property_async(&self) -> bool { unsafe { let mut value = Value::from_type(::static_type()); diff --git a/gstreamer-base/src/auto/base_src.rs b/gstreamer-base/src/auto/base_src.rs index 39396d646..6202e2451 100644 --- a/gstreamer-base/src/auto/base_src.rs +++ b/gstreamer-base/src/auto/base_src.rs @@ -66,12 +66,6 @@ pub trait BaseSrcExt: 'static { fn set_live(&self, live: bool); - fn start_complete(&self, ret: gst::FlowReturn); - - fn start_wait(&self) -> gst::FlowReturn; - - fn wait_playing(&self) -> gst::FlowReturn; - fn get_property_num_buffers(&self) -> i32; fn set_property_num_buffers(&self, num_buffers: i32); @@ -188,24 +182,6 @@ impl> BaseSrcExt for O { } } - fn start_complete(&self, ret: gst::FlowReturn) { - unsafe { - ffi::gst_base_src_start_complete(self.to_glib_none().0, ret.to_glib()); - } - } - - fn start_wait(&self) -> gst::FlowReturn { - unsafe { - from_glib(ffi::gst_base_src_start_wait(self.to_glib_none().0)) - } - } - - fn wait_playing(&self) -> gst::FlowReturn { - unsafe { - from_glib(ffi::gst_base_src_wait_playing(self.to_glib_none().0)) - } - } - fn get_property_num_buffers(&self) -> i32 { unsafe { let mut value = Value::from_type(::static_type()); diff --git a/gstreamer-base/src/base_sink.rs b/gstreamer-base/src/base_sink.rs index d39367bf5..4143f8e49 100644 --- a/gstreamer-base/src/base_sink.rs +++ b/gstreamer-base/src/base_sink.rs @@ -10,11 +10,19 @@ use ffi; use glib::translate::*; use glib::{IsA, IsClassFor}; use gst; +use std::mem; use std::ops; use BaseSink; pub trait BaseSinkExtManual: 'static { fn get_segment(&self) -> gst::Segment; + + fn wait( + &self, + time: gst::ClockTime, + ) -> (Result, gst::ClockTimeDiff); + + fn wait_preroll(&self) -> Result; } impl> BaseSinkExtManual for O { @@ -26,6 +34,27 @@ impl> BaseSinkExtManual for O { from_glib_none(&sink.segment as *const _) } } + + fn wait( + &self, + time: gst::ClockTime, + ) -> (Result, gst::ClockTimeDiff) { + unsafe { + let mut jitter = mem::uninitialized(); + let ret: gst::FlowReturn = from_glib(ffi::gst_base_sink_wait( + self.to_glib_none().0, + time.to_glib(), + &mut jitter, + )); + (ret.into_result(), jitter) + } + } + + fn wait_preroll(&self) -> Result { + let ret: gst::FlowReturn = + unsafe { from_glib(ffi::gst_base_sink_wait_preroll(self.to_glib_none().0)) }; + ret.into_result() + } } #[repr(C)] diff --git a/gstreamer-base/src/base_src.rs b/gstreamer-base/src/base_src.rs index ab7f3d92b..e91550033 100644 --- a/gstreamer-base/src/base_src.rs +++ b/gstreamer-base/src/base_src.rs @@ -15,6 +15,12 @@ use BaseSrc; pub trait BaseSrcExtManual: 'static { fn get_segment(&self) -> gst::Segment; + + fn start_complete(&self, ret: Result); + + fn start_wait(&self) -> Result; + + fn wait_playing(&self) -> Result; } impl> BaseSrcExtManual for O { @@ -26,6 +32,25 @@ impl> BaseSrcExtManual for O { from_glib_none(&src.segment as *const _) } } + + fn start_complete(&self, ret: Result) { + let ret: gst::FlowReturn = ret.into(); + unsafe { + ffi::gst_base_src_start_complete(self.to_glib_none().0, ret.to_glib()); + } + } + + fn start_wait(&self) -> Result { + let ret: gst::FlowReturn = + unsafe { from_glib(ffi::gst_base_src_start_wait(self.to_glib_none().0)) }; + ret.into_result() + } + + fn wait_playing(&self) -> Result { + let ret: gst::FlowReturn = + unsafe { from_glib(ffi::gst_base_src_wait_playing(self.to_glib_none().0)) }; + ret.into_result() + } } #[repr(C)] diff --git a/gstreamer-base/src/flow_combiner.rs b/gstreamer-base/src/flow_combiner.rs index 3ea5828fb..56aebff07 100644 --- a/gstreamer-base/src/flow_combiner.rs +++ b/gstreamer-base/src/flow_combiner.rs @@ -57,27 +57,34 @@ impl FlowCombiner { } } - pub fn update_flow(&self, fret: gst::FlowReturn) -> gst::FlowReturn { - unsafe { + pub fn update_flow>( + &self, + fret: FRet, + ) -> Result { + let fret: gst::FlowReturn = fret.into(); + let ret: gst::FlowReturn = unsafe { from_glib(ffi::gst_flow_combiner_update_flow( self.to_glib_none().0, fret.to_glib(), )) - } + }; + ret.into_result() } - pub fn update_pad_flow>( + pub fn update_pad_flow, FRet: Into>( &self, pad: &P, - fret: gst::FlowReturn, - ) -> gst::FlowReturn { - unsafe { + fret: FRet, + ) -> Result { + let fret: gst::FlowReturn = fret.into(); + let ret: gst::FlowReturn = unsafe { from_glib(ffi::gst_flow_combiner_update_pad_flow( self.to_glib_none().0, pad.to_glib_none().0, fret.to_glib(), )) - } + }; + ret.into_result() } } @@ -114,15 +121,18 @@ impl UniqueFlowCombiner { self.0.reset(); } - pub fn update_flow(&mut self, fret: gst::FlowReturn) -> gst::FlowReturn { + pub fn update_flow( + &mut self, + fret: Result, + ) -> Result { self.0.update_flow(fret) } pub fn update_pad_flow>( &mut self, pad: &P, - fret: gst::FlowReturn, - ) -> gst::FlowReturn { + fret: Result, + ) -> Result { self.0.update_pad_flow(pad, fret) } } diff --git a/gstreamer-base/src/subclass/aggregator.rs b/gstreamer-base/src/subclass/aggregator.rs index 9650c5e60..1270e384c 100644 --- a/gstreamer-base/src/subclass/aggregator.rs +++ b/gstreamer-base/src/subclass/aggregator.rs @@ -26,7 +26,7 @@ use AggregatorClass; use AggregatorPad; pub trait AggregatorImpl: ElementImpl + Send + Sync + 'static { - fn flush(&self, aggregator: &Aggregator) -> gst::FlowReturn { + fn flush(&self, aggregator: &Aggregator) -> Result { self.parent_flush(aggregator) } @@ -39,7 +39,11 @@ pub trait AggregatorImpl: ElementImpl + Send + Sync + 'static { self.parent_clip(aggregator, aggregator_pad, buffer) } - fn finish_buffer(&self, aggregator: &Aggregator, buffer: gst::Buffer) -> gst::FlowReturn { + fn finish_buffer( + &self, + aggregator: &Aggregator, + buffer: gst::Buffer, + ) -> Result { self.parent_finish_buffer(aggregator, buffer) } @@ -73,7 +77,11 @@ pub trait AggregatorImpl: ElementImpl + Send + Sync + 'static { self.parent_src_activate(aggregator, mode, active) } - fn aggregate(&self, aggregator: &Aggregator, timeout: bool) -> gst::FlowReturn; + fn aggregate( + &self, + aggregator: &Aggregator, + timeout: bool, + ) -> Result; fn start(&self, aggregator: &Aggregator) -> bool { self.parent_start(aggregator) @@ -113,7 +121,7 @@ pub trait AggregatorImpl: ElementImpl + Send + Sync + 'static { self.parent_negotiated_src_caps(aggregator, caps) } - fn parent_flush(&self, aggregator: &Aggregator) -> gst::FlowReturn { + fn parent_flush(&self, aggregator: &Aggregator) -> Result { unsafe { let data = self.get_type_data(); let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAggregatorClass; @@ -121,6 +129,7 @@ pub trait AggregatorImpl: ElementImpl + Send + Sync + 'static { .flush .map(|f| from_glib(f(aggregator.to_glib_none().0))) .unwrap_or(gst::FlowReturn::Ok) + .into_result() } } @@ -148,7 +157,7 @@ pub trait AggregatorImpl: ElementImpl + Send + Sync + 'static { &self, aggregator: &Aggregator, buffer: gst::Buffer, - ) -> gst::FlowReturn { + ) -> Result { unsafe { let data = self.get_type_data(); let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAggregatorClass; @@ -156,6 +165,7 @@ pub trait AggregatorImpl: ElementImpl + Send + Sync + 'static { .finish_buffer .map(|f| from_glib(f(aggregator.to_glib_none().0, buffer.into_ptr()))) .unwrap_or(gst::FlowReturn::Ok) + .into_result() } } @@ -247,7 +257,11 @@ pub trait AggregatorImpl: ElementImpl + Send + Sync + 'static { } } - fn parent_aggregate(&self, aggregator: &Aggregator, timeout: bool) -> gst::FlowReturn { + fn parent_aggregate( + &self, + aggregator: &Aggregator, + timeout: bool, + ) -> Result { unsafe { let data = self.get_type_data(); let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAggregatorClass; @@ -255,6 +269,7 @@ pub trait AggregatorImpl: ElementImpl + Send + Sync + 'static { .aggregate .map(|f| from_glib(f(aggregator.to_glib_none().0, timeout.to_glib()))) .unwrap_or(gst::FlowReturn::Error) + .into_result() } } @@ -403,7 +418,7 @@ where let wrap: Aggregator = from_glib_borrow(ptr); gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, { - imp.flush(&wrap) + imp.flush(&wrap).into() }) .to_glib() } @@ -447,7 +462,7 @@ where let wrap: Aggregator = from_glib_borrow(ptr); gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, { - imp.finish_buffer(&wrap, from_glib_full(buffer)) + imp.finish_buffer(&wrap, from_glib_full(buffer)).into() }) .to_glib() } @@ -572,7 +587,7 @@ where let wrap: Aggregator = from_glib_borrow(ptr); gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, { - imp.aggregate(&wrap, from_glib(timeout)) + imp.aggregate(&wrap, from_glib(timeout)).into() }) .to_glib() } diff --git a/gstreamer-base/src/subclass/aggregator_pad.rs b/gstreamer-base/src/subclass/aggregator_pad.rs index 1c586600f..f0cf9d9b2 100644 --- a/gstreamer-base/src/subclass/aggregator_pad.rs +++ b/gstreamer-base/src/subclass/aggregator_pad.rs @@ -22,7 +22,11 @@ use AggregatorPad; use AggregatorPadClass; pub trait AggregatorPadImpl: PadImpl + Send + Sync + 'static { - fn flush(&self, aggregator_pad: &AggregatorPad, aggregator: &Aggregator) -> gst::FlowReturn { + fn flush( + &self, + aggregator_pad: &AggregatorPad, + aggregator: &Aggregator, + ) -> Result { self.parent_flush(aggregator_pad, aggregator) } @@ -39,7 +43,7 @@ pub trait AggregatorPadImpl: PadImpl + Send + Sync + 'static { &self, aggregator_pad: &AggregatorPad, aggregator: &Aggregator, - ) -> gst::FlowReturn { + ) -> Result { unsafe { let data = self.get_type_data(); let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAggregatorPadClass; @@ -52,6 +56,7 @@ pub trait AggregatorPadImpl: PadImpl + Send + Sync + 'static { )) }) .unwrap_or(gst::FlowReturn::Ok) + .into_result() } } @@ -101,7 +106,8 @@ where let imp = instance.get_impl(); let wrap: AggregatorPad = from_glib_borrow(ptr); - imp.flush(&wrap, &from_glib_borrow(aggregator)).to_glib() + let res: gst::FlowReturn = imp.flush(&wrap, &from_glib_borrow(aggregator)).into(); + res.to_glib() } unsafe extern "C" fn aggregator_pad_skip_buffer( diff --git a/gstreamer-base/src/subclass/base_sink.rs b/gstreamer-base/src/subclass/base_sink.rs index ae7597f00..7e54ea326 100644 --- a/gstreamer-base/src/subclass/base_sink.rs +++ b/gstreamer-base/src/subclass/base_sink.rs @@ -31,32 +31,40 @@ pub trait BaseSinkImpl: ElementImpl + Send + Sync + 'static { true } - fn render(&self, element: &BaseSink, buffer: &gst::BufferRef) -> gst::FlowReturn; + fn render( + &self, + element: &BaseSink, + buffer: &gst::BufferRef, + ) -> Result; - fn prepare(&self, _element: &BaseSink, _buffer: &gst::BufferRef) -> gst::FlowReturn { - gst::FlowReturn::Ok + fn prepare( + &self, + _element: &BaseSink, + _buffer: &gst::BufferRef, + ) -> Result { + Ok(gst::FlowSuccess::Ok) } - fn render_list(&self, element: &BaseSink, list: &gst::BufferListRef) -> gst::FlowReturn { + fn render_list( + &self, + element: &BaseSink, + list: &gst::BufferListRef, + ) -> Result { for buffer in list.iter() { - let ret = self.render(element, buffer); - if ret != gst::FlowReturn::Ok { - return ret; - } + self.render(element, buffer)?; } - - gst::FlowReturn::Ok + Ok(gst::FlowSuccess::Ok) } - fn prepare_list(&self, element: &BaseSink, list: &gst::BufferListRef) -> gst::FlowReturn { + fn prepare_list( + &self, + element: &BaseSink, + list: &gst::BufferListRef, + ) -> Result { for buffer in list.iter() { - let ret = self.prepare(element, buffer); - if ret != gst::FlowReturn::Ok { - return ret; - } + self.prepare(element, buffer)?; } - - gst::FlowReturn::Ok + Ok(gst::FlowSuccess::Ok) } fn query(&self, element: &BaseSink, query: &mut gst::QueryRef) -> bool { @@ -224,7 +232,7 @@ where let buffer = gst::BufferRef::from_ptr(buffer); gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, { - imp.render(&wrap, buffer) + imp.render(&wrap, buffer).into() }) .to_glib() } @@ -244,7 +252,7 @@ where let buffer = gst::BufferRef::from_ptr(buffer); gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, { - imp.prepare(&wrap, buffer) + imp.prepare(&wrap, buffer).into() }) .to_glib() } @@ -264,7 +272,7 @@ where let list = gst::BufferListRef::from_ptr(list); gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, { - imp.render_list(&wrap, list) + imp.render_list(&wrap, list).into() }) .to_glib() } @@ -284,7 +292,7 @@ where let list = gst::BufferListRef::from_ptr(list); gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, { - imp.prepare_list(&wrap, list) + imp.prepare_list(&wrap, list).into() }) .to_glib() } diff --git a/gstreamer-base/src/subclass/base_src.rs b/gstreamer-base/src/subclass/base_src.rs index 7a86f2bcf..8d5e383a9 100644 --- a/gstreamer-base/src/subclass/base_src.rs +++ b/gstreamer-base/src/subclass/base_src.rs @@ -45,7 +45,7 @@ pub trait BaseSrcImpl: ElementImpl + Send + Sync + 'static { _offset: u64, _length: u32, _buffer: &mut gst::BufferRef, - ) -> gst::FlowReturn { + ) -> Result { unimplemented!() } @@ -325,7 +325,7 @@ where let buffer = gst::BufferRef::from_mut_ptr(buffer); gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, { - imp.fill(&wrap, offset, length, buffer) + imp.fill(&wrap, offset, length, buffer).into() }) .to_glib() } diff --git a/gstreamer-base/src/subclass/base_transform.rs b/gstreamer-base/src/subclass/base_transform.rs index 45454c7cd..83ea35b11 100644 --- a/gstreamer-base/src/subclass/base_transform.rs +++ b/gstreamer-base/src/subclass/base_transform.rs @@ -104,11 +104,15 @@ pub trait BaseTransformImpl: ElementImpl + Send + Sync + 'static { _element: &BaseTransform, _inbuf: &gst::Buffer, _outbuf: &mut gst::BufferRef, - ) -> gst::FlowReturn { + ) -> Result { unimplemented!(); } - fn transform_ip(&self, _element: &BaseTransform, _buf: &mut gst::BufferRef) -> gst::FlowReturn { + fn transform_ip( + &self, + _element: &BaseTransform, + _buf: &mut gst::BufferRef, + ) -> Result { unimplemented!(); } @@ -116,7 +120,7 @@ pub trait BaseTransformImpl: ElementImpl + Send + Sync + 'static { &self, _element: &BaseTransform, _buf: &gst::BufferRef, - ) -> gst::FlowReturn { + ) -> Result { unimplemented!(); } @@ -605,6 +609,7 @@ where &from_glib_borrow(inbuf), gst::BufferRef::from_mut_ptr(outbuf), ) + .into() }) .to_glib() } @@ -628,8 +633,10 @@ where gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, { if from_glib(ffi::gst_base_transform_is_passthrough(ptr)) { imp.transform_ip_passthrough(&wrap, gst::BufferRef::from_ptr(buf)) + .into() } else { imp.transform_ip(&wrap, gst::BufferRef::from_mut_ptr(buf)) + .into() } }) .to_glib() diff --git a/gstreamer-check/src/harness.rs b/gstreamer-check/src/harness.rs index 0a97ea89f..88f1f71e9 100644 --- a/gstreamer-check/src/harness.rs +++ b/gstreamer-check/src/harness.rs @@ -267,8 +267,10 @@ impl Harness { unsafe { from_glib_full(ffi::gst_harness_pull_upstream_event(self.0.as_ptr())) } } - pub fn push(&mut self, buffer: gst::Buffer) -> gst::FlowReturn { - unsafe { from_glib(ffi::gst_harness_push(self.0.as_ptr(), buffer.into_ptr())) } + pub fn push(&mut self, buffer: gst::Buffer) -> Result { + let ret: gst::FlowReturn = + unsafe { from_glib(ffi::gst_harness_push(self.0.as_ptr(), buffer.into_ptr())) }; + ret.into_result() } pub fn push_and_pull(&mut self, buffer: gst::Buffer) -> Option { @@ -289,12 +291,16 @@ impl Harness { } } - pub fn push_from_src(&mut self) -> gst::FlowReturn { - unsafe { from_glib(ffi::gst_harness_push_from_src(self.0.as_ptr())) } + pub fn push_from_src(&mut self) -> Result { + let ret: gst::FlowReturn = + unsafe { from_glib(ffi::gst_harness_push_from_src(self.0.as_ptr())) }; + ret.into_result() } - pub fn push_to_sink(&mut self) -> gst::FlowReturn { - unsafe { from_glib(ffi::gst_harness_push_to_sink(self.0.as_ptr())) } + pub fn push_to_sink(&mut self) -> Result { + let ret: gst::FlowReturn = + unsafe { from_glib(ffi::gst_harness_push_to_sink(self.0.as_ptr())) }; + ret.into_result() } pub fn push_upstream_event(&mut self, event: gst::Event) -> bool { @@ -391,23 +397,29 @@ impl Harness { } } - pub fn sink_push_many(&mut self, pushes: u32) -> gst::FlowReturn { - unsafe { + pub fn sink_push_many(&mut self, pushes: u32) -> Result { + let ret: gst::FlowReturn = unsafe { from_glib(ffi::gst_harness_sink_push_many( self.0.as_ptr(), pushes as i32, )) - } + }; + ret.into_result() } - pub fn src_crank_and_push_many(&mut self, cranks: u32, pushes: u32) -> gst::FlowReturn { - unsafe { + pub fn src_crank_and_push_many( + &mut self, + cranks: u32, + pushes: u32, + ) -> Result { + let ret: gst::FlowReturn = unsafe { from_glib(ffi::gst_harness_src_crank_and_push_many( self.0.as_ptr(), cranks as i32, pushes as i32, )) - } + }; + ret.into_result() } pub fn src_push_event(&mut self) -> bool { diff --git a/gstreamer-rtsp-server/src/auto/rtsp_stream.rs b/gstreamer-rtsp-server/src/auto/rtsp_stream.rs index a75844146..98bdd64a8 100644 --- a/gstreamer-rtsp-server/src/auto/rtsp_stream.rs +++ b/gstreamer-rtsp-server/src/auto/rtsp_stream.rs @@ -124,10 +124,6 @@ pub trait RTSPStreamExt: 'static { fn leave_bin, Q: IsA>(&self, bin: &P, rtpbin: &Q) -> Result<(), glib::error::BoolError>; - fn recv_rtcp(&self, buffer: &gst::Buffer) -> gst::FlowReturn; - - fn recv_rtp(&self, buffer: &gst::Buffer) -> gst::FlowReturn; - fn remove_transport(&self, trans: &RTSPStreamTransport) -> Result<(), glib::error::BoolError>; fn request_aux_sender(&self, sessid: u32) -> Option; @@ -425,18 +421,6 @@ impl> RTSPStreamExt for O { } } - fn recv_rtcp(&self, buffer: &gst::Buffer) -> gst::FlowReturn { - unsafe { - from_glib(ffi::gst_rtsp_stream_recv_rtcp(self.to_glib_none().0, buffer.to_glib_full())) - } - } - - fn recv_rtp(&self, buffer: &gst::Buffer) -> gst::FlowReturn { - unsafe { - from_glib(ffi::gst_rtsp_stream_recv_rtp(self.to_glib_none().0, buffer.to_glib_full())) - } - } - fn remove_transport(&self, trans: &RTSPStreamTransport) -> Result<(), glib::error::BoolError> { unsafe { glib_result_from_gboolean!(ffi::gst_rtsp_stream_remove_transport(self.to_glib_none().0, trans.to_glib_none().0), "Failed to remove transport") diff --git a/gstreamer-rtsp-server/src/auto/rtsp_stream_transport.rs b/gstreamer-rtsp-server/src/auto/rtsp_stream_transport.rs index b1138e521..bb8093829 100644 --- a/gstreamer-rtsp-server/src/auto/rtsp_stream_transport.rs +++ b/gstreamer-rtsp-server/src/auto/rtsp_stream_transport.rs @@ -38,8 +38,6 @@ pub trait RTSPStreamTransportExt: 'static { fn keep_alive(&self); - fn recv_data(&self, channel: u32, buffer: &gst::Buffer) -> gst::FlowReturn; - fn send_rtcp(&self, buffer: &gst::Buffer) -> Result<(), glib::error::BoolError>; fn send_rtp(&self, buffer: &gst::Buffer) -> Result<(), glib::error::BoolError>; @@ -92,12 +90,6 @@ impl> RTSPStreamTransportExt for O { } } - fn recv_data(&self, channel: u32, buffer: &gst::Buffer) -> gst::FlowReturn { - unsafe { - from_glib(ffi::gst_rtsp_stream_transport_recv_data(self.to_glib_none().0, channel, buffer.to_glib_full())) - } - } - fn send_rtcp(&self, buffer: &gst::Buffer) -> Result<(), glib::error::BoolError> { unsafe { glib_result_from_gboolean!(ffi::gst_rtsp_stream_transport_send_rtcp(self.to_glib_none().0, buffer.to_glib_none().0), "Failed to send rtcp") diff --git a/gstreamer-rtsp-server/src/lib.rs b/gstreamer-rtsp-server/src/lib.rs index 72cc4214d..fee1a37a2 100644 --- a/gstreamer-rtsp-server/src/lib.rs +++ b/gstreamer-rtsp-server/src/lib.rs @@ -57,6 +57,8 @@ mod rtsp_context; mod rtsp_media_factory; mod rtsp_server; mod rtsp_session_pool; +mod rtsp_stream; +mod rtsp_stream_transport; mod rtsp_token; pub use rtsp_address_pool::RTSPAddressPoolExtManual; @@ -141,4 +143,6 @@ pub mod prelude { pub use rtsp_media_factory::RTSPMediaFactoryExtManual; pub use rtsp_server::RTSPServerExtManual; pub use rtsp_session_pool::RTSPSessionPoolExtManual; + pub use rtsp_stream::RTSPStreamExtManual; + pub use rtsp_stream_transport::RTSPStreamTransportExtManual; } diff --git a/gstreamer-rtsp-server/src/rtsp_stream.rs b/gstreamer-rtsp-server/src/rtsp_stream.rs new file mode 100644 index 000000000..d0ccfda6b --- /dev/null +++ b/gstreamer-rtsp-server/src/rtsp_stream.rs @@ -0,0 +1,33 @@ +use ffi; +use glib::object::IsA; +use glib::translate::*; +use gst; +use RTSPStream; + +pub trait RTSPStreamExtManual: 'static { + fn recv_rtcp(&self, buffer: &gst::Buffer) -> Result; + + fn recv_rtp(&self, buffer: &gst::Buffer) -> Result; +} + +impl> RTSPStreamExtManual for O { + fn recv_rtcp(&self, buffer: &gst::Buffer) -> Result { + let ret: gst::FlowReturn = unsafe { + from_glib(ffi::gst_rtsp_stream_recv_rtcp( + self.to_glib_none().0, + buffer.to_glib_full(), + )) + }; + ret.into_result() + } + + fn recv_rtp(&self, buffer: &gst::Buffer) -> Result { + let ret: gst::FlowReturn = unsafe { + from_glib(ffi::gst_rtsp_stream_recv_rtp( + self.to_glib_none().0, + buffer.to_glib_full(), + )) + }; + ret.into_result() + } +} diff --git a/gstreamer-rtsp-server/src/rtsp_stream_transport.rs b/gstreamer-rtsp-server/src/rtsp_stream_transport.rs new file mode 100644 index 000000000..450106d4b --- /dev/null +++ b/gstreamer-rtsp-server/src/rtsp_stream_transport.rs @@ -0,0 +1,30 @@ +use ffi; +use glib::object::IsA; +use glib::translate::*; +use gst; +use RTSPStreamTransport; + +pub trait RTSPStreamTransportExtManual: 'static { + fn recv_data( + &self, + channel: u32, + buffer: &gst::Buffer, + ) -> Result; +} + +impl> RTSPStreamTransportExtManual for O { + fn recv_data( + &self, + channel: u32, + buffer: &gst::Buffer, + ) -> Result { + let ret: gst::FlowReturn = unsafe { + from_glib(ffi::gst_rtsp_stream_transport_recv_data( + self.to_glib_none().0, + channel, + buffer.to_glib_full(), + )) + }; + ret.into_result() + } +} diff --git a/gstreamer/src/auto/element.rs b/gstreamer/src/auto/element.rs index 03e54b1c1..701a46f31 100644 --- a/gstreamer/src/auto/element.rs +++ b/gstreamer/src/auto/element.rs @@ -16,9 +16,6 @@ use Pad; use PadLinkCheck; use PadTemplate; use Plugin; -use State; -use StateChange; -use StateChangeReturn; use URIType; use ffi; use glib; @@ -29,7 +26,6 @@ use glib::signal::connect_raw; use glib::translate::*; use glib_ffi; use std::boxed::Box as Box_; -use std::mem; use std::mem::transmute; use std::ptr; @@ -74,10 +70,6 @@ pub trait ElementExt: 'static { //#[cfg(any(feature = "v1_10", feature = "dox"))] //fn call_async(&self, func: /*Unknown conversion*//*Unimplemented*/ElementCallAsyncFunc, destroy_notify: /*Unknown conversion*//*Unimplemented*/DestroyNotify); - fn change_state(&self, transition: StateChange) -> StateChangeReturn; - - fn continue_state(&self, ret: StateChangeReturn) -> StateChangeReturn; - fn create_all_pads(&self); //#[cfg(any(feature = "v1_14", feature = "dox"))] @@ -109,8 +101,6 @@ pub trait ElementExt: 'static { fn get_start_time(&self) -> ClockTime; - fn get_state(&self, timeout: ClockTime) -> (StateChangeReturn, State, State); - fn get_static_pad(&self, name: &str) -> Option; fn is_locked_state(&self) -> bool; @@ -164,8 +154,6 @@ pub trait ElementExt: 'static { fn set_start_time(&self, time: ClockTime); - fn set_state(&self, state: State) -> StateChangeReturn; - fn sync_state_with_parent(&self) -> Result<(), glib::error::BoolError>; fn unlink>(&self, dest: &P); @@ -199,18 +187,6 @@ impl> ElementExt for O { // unsafe { TODO: call ffi::gst_element_call_async() } //} - fn change_state(&self, transition: StateChange) -> StateChangeReturn { - unsafe { - from_glib(ffi::gst_element_change_state(self.to_glib_none().0, transition.to_glib())) - } - } - - fn continue_state(&self, ret: StateChangeReturn) -> StateChangeReturn { - unsafe { - from_glib(ffi::gst_element_continue_state(self.to_glib_none().0, ret.to_glib())) - } - } - fn create_all_pads(&self) { unsafe { ffi::gst_element_create_all_pads(self.to_glib_none().0); @@ -294,15 +270,6 @@ impl> ElementExt for O { } } - fn get_state(&self, timeout: ClockTime) -> (StateChangeReturn, State, State) { - unsafe { - let mut state = mem::uninitialized(); - let mut pending = mem::uninitialized(); - let ret = from_glib(ffi::gst_element_get_state(self.to_glib_none().0, &mut state, &mut pending, timeout.to_glib())); - (ret, from_glib(state), from_glib(pending)) - } - } - fn get_static_pad(&self, name: &str) -> Option { unsafe { from_glib_full(ffi::gst_element_get_static_pad(self.to_glib_none().0, name.to_glib_none().0)) @@ -472,12 +439,6 @@ impl> ElementExt for O { } } - fn set_state(&self, state: State) -> StateChangeReturn { - unsafe { - from_glib(ffi::gst_element_set_state(self.to_glib_none().0, state.to_glib())) - } - } - fn sync_state_with_parent(&self) -> Result<(), glib::error::BoolError> { unsafe { glib_result_from_gboolean!(ffi::gst_element_sync_state_with_parent(self.to_glib_none().0), "Failed to sync state with parent") diff --git a/gstreamer/src/auto/pad.rs b/gstreamer/src/auto/pad.rs index d63bc5978..358de91f0 100644 --- a/gstreamer/src/auto/pad.rs +++ b/gstreamer/src/auto/pad.rs @@ -6,12 +6,11 @@ use Caps; use Element; use Event; use EventType; -use FlowReturn; use Object; use PadClass; use PadDirection; +#[cfg(any(feature = "v1_10", feature = "dox"))] use PadLinkCheck; -use PadLinkReturn; use PadMode; use PadTemplate; #[cfg(any(feature = "v1_10", feature = "dox"))] @@ -89,8 +88,6 @@ pub trait PadExt: 'static { //fn get_element_private(&self) -> /*Unimplemented*/Option; - fn get_last_flow_return(&self) -> FlowReturn; - fn get_offset(&self) -> i64; fn get_pad_template(&self) -> Option; @@ -125,10 +122,6 @@ pub trait PadExt: 'static { //fn iterate_internal_links_default<'a, P: IsA + 'a, Q: Into>>(&self, parent: Q) -> /*Ignored*/Option; - fn link>(&self, sinkpad: &P) -> PadLinkReturn; - - fn link_full>(&self, sinkpad: &P, flags: PadLinkCheck) -> PadLinkReturn; - #[cfg(any(feature = "v1_10", feature = "dox"))] fn link_maybe_ghosting>(&self, sink: &P) -> Result<(), glib::error::BoolError>; @@ -183,8 +176,6 @@ pub trait PadExt: 'static { fn stop_task(&self) -> Result<(), glib::error::BoolError>; - fn store_sticky_event(&self, event: &Event) -> FlowReturn; - fn unlink>(&self, sinkpad: &P) -> Result<(), glib::error::BoolError>; fn use_fixed_caps(&self); @@ -271,12 +262,6 @@ impl> PadExt for O { // unsafe { TODO: call ffi::gst_pad_get_element_private() } //} - fn get_last_flow_return(&self) -> FlowReturn { - unsafe { - from_glib(ffi::gst_pad_get_last_flow_return(self.to_glib_none().0)) - } - } - fn get_offset(&self) -> i64 { unsafe { ffi::gst_pad_get_offset(self.to_glib_none().0) @@ -371,18 +356,6 @@ impl> PadExt for O { // unsafe { TODO: call ffi::gst_pad_iterate_internal_links_default() } //} - fn link>(&self, sinkpad: &P) -> PadLinkReturn { - unsafe { - from_glib(ffi::gst_pad_link(self.to_glib_none().0, sinkpad.to_glib_none().0)) - } - } - - fn link_full>(&self, sinkpad: &P, flags: PadLinkCheck) -> PadLinkReturn { - unsafe { - from_glib(ffi::gst_pad_link_full(self.to_glib_none().0, sinkpad.to_glib_none().0, flags.to_glib())) - } - } - #[cfg(any(feature = "v1_10", feature = "dox"))] fn link_maybe_ghosting>(&self, sink: &P) -> Result<(), glib::error::BoolError> { unsafe { @@ -517,12 +490,6 @@ impl> PadExt for O { } } - fn store_sticky_event(&self, event: &Event) -> FlowReturn { - unsafe { - from_glib(ffi::gst_pad_store_sticky_event(self.to_glib_none().0, event.to_glib_none().0)) - } - } - fn unlink>(&self, sinkpad: &P) -> Result<(), glib::error::BoolError> { unsafe { glib_result_from_gboolean!(ffi::gst_pad_unlink(self.to_glib_none().0, sinkpad.to_glib_none().0), "Failed to unlink pad") diff --git a/gstreamer/src/clock.rs b/gstreamer/src/clock.rs index 1104ad304..ad367c90b 100644 --- a/gstreamer/src/clock.rs +++ b/gstreamer/src/clock.rs @@ -17,7 +17,9 @@ use std::mem; use std::mem::transmute; use std::ptr; use Clock; +use ClockError; use ClockReturn; +use ClockSuccess; use ClockTime; use ClockTimeDiff; @@ -68,26 +70,28 @@ impl ClockId { unsafe { ffi::gst_clock_id_unschedule(self.to_glib_none().0) } } - pub fn wait(&self) -> (ClockReturn, ClockTimeDiff) { + pub fn wait(&self) -> (Result, ClockTimeDiff) { unsafe { let mut jitter = mem::uninitialized(); - let res = ffi::gst_clock_id_wait(self.to_glib_none().0, &mut jitter); - (from_glib(res), jitter) + let res: ClockReturn = + from_glib(ffi::gst_clock_id_wait(self.to_glib_none().0, &mut jitter)); + (res.into_result(), jitter) } } - pub fn wait_async(&self, func: F) -> ClockReturn + pub fn wait_async(&self, func: F) -> Result where F: Fn(&Clock, ClockTime, &ClockId) -> bool + Send + 'static, { - unsafe { + let ret: ClockReturn = unsafe { from_glib(ffi::gst_clock_id_wait_async( self.to_glib_none().0, Some(trampoline_wait_async), into_raw_wait_async(func), Some(destroy_closure_wait_async), )) - } + }; + ret.into_result() } } @@ -251,7 +255,7 @@ mod tests { let id = clock.new_single_shot_id(now + 20 * ::MSECOND).unwrap(); let (res, _) = id.wait(); - assert!(res == ClockReturn::Ok || res == ClockReturn::Early); + assert!(res == Ok(ClockSuccess::Ok) || res == Err(ClockError::Early)); } #[test] @@ -269,7 +273,7 @@ mod tests { true }); - assert!(res == ClockReturn::Ok); + assert!(res == Ok(ClockSuccess::Ok)); assert_eq!(receiver.recv(), Ok(())); } diff --git a/gstreamer/src/element.rs b/gstreamer/src/element.rs index 1610bfff5..2610c6b74 100644 --- a/gstreamer/src/element.rs +++ b/gstreamer/src/element.rs @@ -18,6 +18,7 @@ use glib::translate::{ }; use glib::{IsA, IsClassFor}; use miniobject::MiniObject; +use ClockTime; use Event; use Format; use FormattedValue; @@ -26,6 +27,11 @@ use Pad; use PadTemplate; use QueryRef; use SpecificFormattedValue; +use State; +use StateChange; +use StateChangeError; +use StateChangeReturn; +use StateChangeSuccess; use std::ffi::CStr; use std::mem; @@ -95,6 +101,19 @@ impl FromGlib for NotifyWatchId { pub trait ElementExtManual: 'static { fn get_element_class(&self) -> &ElementClass; + fn change_state(&self, transition: StateChange) + -> Result; + fn continue_state( + &self, + ret: StateChangeReturn, + ) -> Result; + + fn get_state( + &self, + timeout: ClockTime, + ) -> (Result, State, State); + fn set_state(&self, state: State) -> Result; + fn query(&self, query: &mut QueryRef) -> bool; fn send_event(&self, event: Event) -> bool; @@ -203,6 +222,59 @@ impl> ElementExtManual for O { } } + fn change_state( + &self, + transition: StateChange, + ) -> Result { + let ret: StateChangeReturn = unsafe { + from_glib(ffi::gst_element_change_state( + self.to_glib_none().0, + transition.to_glib(), + )) + }; + ret.into_result() + } + + fn continue_state( + &self, + ret: StateChangeReturn, + ) -> Result { + let ret: StateChangeReturn = unsafe { + from_glib(ffi::gst_element_continue_state( + self.to_glib_none().0, + ret.to_glib(), + )) + }; + ret.into_result() + } + + fn get_state( + &self, + timeout: ClockTime, + ) -> (Result, State, State) { + unsafe { + let mut state = mem::uninitialized(); + let mut pending = mem::uninitialized(); + let ret: StateChangeReturn = from_glib(ffi::gst_element_get_state( + self.to_glib_none().0, + &mut state, + &mut pending, + timeout.to_glib(), + )); + (ret.into_result(), from_glib(state), from_glib(pending)) + } + } + + fn set_state(&self, state: State) -> Result { + let ret: StateChangeReturn = unsafe { + from_glib(ffi::gst_element_set_state( + self.to_glib_none().0, + state.to_glib(), + )) + }; + ret.into_result() + } + fn query(&self, query: &mut QueryRef) -> bool { unsafe { from_glib(ffi::gst_element_query( diff --git a/gstreamer/src/enums.rs b/gstreamer/src/enums.rs index 0c27ac4e8..af856c387 100644 --- a/gstreamer/src/enums.rs +++ b/gstreamer/src/enums.rs @@ -75,6 +75,15 @@ impl Error for StateChangeError { } } +impl From> for StateChangeReturn { + fn from(res: Result) -> Self { + match res { + Ok(success) => StateChangeReturn::from_ok(success), + Err(error) => StateChangeReturn::from_error(error), + } + } +} + impl FlowReturn { pub fn into_result(self) -> Result { match self { @@ -186,6 +195,15 @@ impl Error for FlowError { } } +impl From> for FlowReturn { + fn from(res: Result) -> Self { + match res { + Ok(success) => FlowReturn::from_ok(success), + Err(error) => FlowReturn::from_error(error), + } + } +} + impl PadLinkReturn { pub fn into_result(self) -> Result { match self { @@ -261,6 +279,15 @@ impl Error for PadLinkError { } } +impl From> for PadLinkReturn { + fn from(res: Result) -> Self { + match res { + Ok(success) => PadLinkReturn::from_ok(success), + Err(error) => PadLinkReturn::from_error(error), + } + } +} + impl ClockReturn { pub fn into_result(self) -> Result { match self { @@ -343,6 +370,15 @@ impl Error for ClockError { } } +impl From> for ClockReturn { + fn from(res: Result) -> Self { + match res { + Ok(success) => ClockReturn::from_ok(success), + Err(error) => ClockReturn::from_error(error), + } + } +} + impl PartialOrd for ::TypeFindProbability { fn partial_cmp(&self, other: &Self) -> Option { self.to_glib().partial_cmp(&other.to_glib()) diff --git a/gstreamer/src/pad.rs b/gstreamer/src/pad.rs index a2e16d322..63450321e 100644 --- a/gstreamer/src/pad.rs +++ b/gstreamer/src/pad.rs @@ -12,10 +12,15 @@ use BufferList; use Event; use FlowError; use FlowReturn; +use FlowSuccess; use Format; use FormattedValue; use GenericFormattedValue; use Pad; +use PadLinkCheck; +use PadLinkError; +use PadLinkReturn; +use PadLinkSuccess; use PadProbeReturn; use PadProbeType; use Query; @@ -111,11 +116,11 @@ pub trait PadExtManual: 'static { F: Fn(&Pad, &mut PadProbeInfo) -> PadProbeReturn + Send + Sync + 'static; fn remove_probe(&self, id: PadProbeId); - fn chain(&self, buffer: Buffer) -> FlowReturn; - fn push(&self, buffer: Buffer) -> FlowReturn; + fn chain(&self, buffer: Buffer) -> Result; + fn push(&self, buffer: Buffer) -> Result; - fn chain_list(&self, list: BufferList) -> FlowReturn; - fn push_list(&self, list: BufferList) -> FlowReturn; + fn chain_list(&self, list: BufferList) -> Result; + fn push_list(&self, list: BufferList) -> Result; fn pull_range(&self, offset: u64, size: u32) -> Result; fn get_range(&self, offset: u64, size: u32) -> Result; @@ -138,12 +143,21 @@ pub trait PadExtManual: 'static { fn push_event(&self, event: Event) -> bool; fn send_event(&self, event: Event) -> bool; + fn get_last_flow_return(&self) -> Result; + fn iterate_internal_links(&self) -> ::Iterator; fn iterate_internal_links_default<'a, P: IsA<::Object> + 'a, Q: Into>>( &self, parent: Q, ) -> ::Iterator; + fn link>(&self, sinkpad: &P) -> Result; + fn link_full>( + &self, + sinkpad: &P, + flags: PadLinkCheck, + ) -> Result; + fn stream_lock(&self) -> StreamLock; fn set_activate_function(&self, func: F) @@ -156,11 +170,17 @@ pub trait PadExtManual: 'static { fn set_chain_function(&self, func: F) where - F: Fn(&Pad, &Option<::Object>, ::Buffer) -> ::FlowReturn + Send + Sync + 'static; + F: Fn(&Pad, &Option<::Object>, ::Buffer) -> Result + + Send + + Sync + + 'static; fn set_chain_list_function(&self, func: F) where - F: Fn(&Pad, &Option<::Object>, ::BufferList) -> ::FlowReturn + Send + Sync + 'static; + F: Fn(&Pad, &Option<::Object>, ::BufferList) -> Result + + Send + + Sync + + 'static; fn set_event_function(&self, func: F) where @@ -168,7 +188,10 @@ pub trait PadExtManual: 'static { fn set_event_full_function(&self, func: F) where - F: Fn(&Pad, &Option<::Object>, ::Event) -> ::FlowReturn + Send + Sync + 'static; + F: Fn(&Pad, &Option<::Object>, ::Event) -> Result + + Send + + Sync + + 'static; fn set_getrange_function(&self, func: F) where @@ -183,7 +206,10 @@ pub trait PadExtManual: 'static { fn set_link_function(&self, func: F) where - F: Fn(&Pad, &Option<::Object>, &Pad) -> ::PadLinkReturn + Send + Sync + 'static; + F: Fn(&Pad, &Option<::Object>, &Pad) -> Result<::PadLinkSuccess, ::PadLinkError> + + Send + + Sync + + 'static; fn set_query_function(&self, func: F) where @@ -233,6 +259,8 @@ pub trait PadExtManual: 'static { &self, func: F, ); + + fn store_sticky_event(&self, event: &Event) -> Result; } impl> PadExtManual for O { @@ -266,29 +294,37 @@ impl> PadExtManual for O { } } - fn chain(&self, buffer: Buffer) -> FlowReturn { - unsafe { from_glib(ffi::gst_pad_chain(self.to_glib_none().0, buffer.into_ptr())) } - } - - fn push(&self, buffer: Buffer) -> FlowReturn { - unsafe { from_glib(ffi::gst_pad_push(self.to_glib_none().0, buffer.into_ptr())) } - } - - fn chain_list(&self, list: BufferList) -> FlowReturn { + fn chain(&self, buffer: Buffer) -> Result { unsafe { - from_glib(ffi::gst_pad_chain_list( - self.to_glib_none().0, - list.into_ptr(), - )) + FlowReturn::from_glib(ffi::gst_pad_chain(self.to_glib_none().0, buffer.into_ptr())) + .into_result() } } - fn push_list(&self, list: BufferList) -> FlowReturn { + fn push(&self, buffer: Buffer) -> Result { unsafe { - from_glib(ffi::gst_pad_push_list( + FlowReturn::from_glib(ffi::gst_pad_push(self.to_glib_none().0, buffer.into_ptr())) + .into_result() + } + } + + fn chain_list(&self, list: BufferList) -> Result { + unsafe { + FlowReturn::from_glib(ffi::gst_pad_chain_list( self.to_glib_none().0, list.into_ptr(), )) + .into_result() + } + } + + fn push_list(&self, list: BufferList) -> Result { + unsafe { + FlowReturn::from_glib(ffi::gst_pad_push_list( + self.to_glib_none().0, + list.into_ptr(), + )) + .into_result() } } @@ -406,6 +442,12 @@ impl> PadExtManual for O { } } + fn get_last_flow_return(&self) -> Result { + let ret: FlowReturn = + unsafe { from_glib(ffi::gst_pad_get_last_flow_return(self.to_glib_none().0)) }; + ret.into_result() + } + fn iterate_internal_links(&self) -> ::Iterator { unsafe { from_glib_full(ffi::gst_pad_iterate_internal_links(self.to_glib_none().0)) } } @@ -424,6 +466,31 @@ impl> PadExtManual for O { } } + fn link>(&self, sinkpad: &P) -> Result { + let ret: PadLinkReturn = unsafe { + from_glib(ffi::gst_pad_link( + self.to_glib_none().0, + sinkpad.to_glib_none().0, + )) + }; + ret.into_result() + } + + fn link_full>( + &self, + sinkpad: &P, + flags: PadLinkCheck, + ) -> Result { + let ret: PadLinkReturn = unsafe { + from_glib(ffi::gst_pad_link_full( + self.to_glib_none().0, + sinkpad.to_glib_none().0, + flags.to_glib(), + )) + }; + ret.into_result() + } + fn stream_lock(&self) -> StreamLock { unsafe { let pad = self.to_glib_none().0; @@ -469,11 +536,17 @@ impl> PadExtManual for O { fn set_chain_function(&self, func: F) where - F: Fn(&Pad, &Option<::Object>, ::Buffer) -> ::FlowReturn + Send + Sync + 'static, + F: Fn(&Pad, &Option<::Object>, ::Buffer) -> Result + + Send + + Sync + + 'static, { unsafe { let func_box: Box< - Fn(&Pad, &Option<::Object>, ::Buffer) -> ::FlowReturn + Send + Sync + 'static, + Fn(&Pad, &Option<::Object>, ::Buffer) -> Result + + Send + + Sync + + 'static, > = Box::new(func); ffi::gst_pad_set_chain_function_full( self.to_glib_none().0, @@ -486,11 +559,17 @@ impl> PadExtManual for O { fn set_chain_list_function(&self, func: F) where - F: Fn(&Pad, &Option<::Object>, ::BufferList) -> ::FlowReturn + Send + Sync + 'static, + F: Fn(&Pad, &Option<::Object>, ::BufferList) -> Result + + Send + + Sync + + 'static, { unsafe { let func_box: Box< - Fn(&Pad, &Option<::Object>, ::BufferList) -> ::FlowReturn + Send + Sync + 'static, + Fn(&Pad, &Option<::Object>, ::BufferList) -> Result + + Send + + Sync + + 'static, > = Box::new(func); ffi::gst_pad_set_chain_list_function_full( self.to_glib_none().0, @@ -520,11 +599,17 @@ impl> PadExtManual for O { fn set_event_full_function(&self, func: F) where - F: Fn(&Pad, &Option<::Object>, ::Event) -> ::FlowReturn + Send + Sync + 'static, + F: Fn(&Pad, &Option<::Object>, ::Event) -> Result + + Send + + Sync + + 'static, { unsafe { let func_box: Box< - Fn(&Pad, &Option<::Object>, ::Event) -> ::FlowReturn + Send + Sync + 'static, + Fn(&Pad, &Option<::Object>, ::Event) -> Result + + Send + + Sync + + 'static, > = Box::new(func); ffi::gst_pad_set_event_full_function_full( self.to_glib_none().0, @@ -537,7 +622,7 @@ impl> PadExtManual for O { fn set_getrange_function(&self, func: F) where - F: Fn(&Pad, &Option<::Object>, u64, u32) -> Result<::Buffer, ::FlowError> + F: Fn(&Pad, &Option<::Object>, u64, u32) -> Result<::Buffer, FlowError> + Send + Sync + 'static, @@ -545,7 +630,7 @@ impl> PadExtManual for O { unsafe { #[cfg_attr(feature = "cargo-clippy", allow(type_complexity))] let func_box: Box< - Fn(&Pad, &Option<::Object>, u64, u32) -> Result<::Buffer, ::FlowError> + Fn(&Pad, &Option<::Object>, u64, u32) -> Result<::Buffer, FlowError> + Send + Sync + 'static, @@ -578,11 +663,17 @@ impl> PadExtManual for O { fn set_link_function(&self, func: F) where - F: Fn(&Pad, &Option<::Object>, &Pad) -> ::PadLinkReturn + Send + Sync + 'static, + F: Fn(&Pad, &Option<::Object>, &Pad) -> Result<::PadLinkSuccess, ::PadLinkError> + + Send + + Sync + + 'static, { unsafe { let func_box: Box< - Fn(&Pad, &Option<::Object>, &Pad) -> ::PadLinkReturn + Send + Sync + 'static, + Fn(&Pad, &Option<::Object>, &Pad) -> Result<::PadLinkSuccess, ::PadLinkError> + + Send + + Sync + + 'static, > = Box::new(func); ffi::gst_pad_set_link_function_full( self.to_glib_none().0, @@ -910,6 +1001,16 @@ impl> PadExtManual for O { ffi::gst_pad_sticky_events_foreach(self.to_glib_none().0, Some(trampoline), func_ptr); } } + + fn store_sticky_event(&self, event: &Event) -> Result { + let ret: FlowReturn = unsafe { + from_glib(ffi::gst_pad_store_sticky_event( + self.to_glib_none().0, + event.to_glib_none().0, + )) + }; + ret.into_result() + } } #[repr(C)] @@ -1048,17 +1149,18 @@ unsafe extern "C" fn trampoline_chain_function( buffer: *mut ffi::GstBuffer, ) -> ffi::GstFlowReturn { #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] - let func: &&(Fn(&Pad, &Option<::Object>, ::Buffer) -> ::FlowReturn + let func: &&(Fn(&Pad, &Option<::Object>, ::Buffer) -> Result + Send + Sync + 'static) = transmute((*pad).chaindata); - func( + let res: FlowReturn = func( &from_glib_borrow(pad), &from_glib_borrow(parent), from_glib_full(buffer), ) - .to_glib() + .into(); + res.to_glib() } unsafe extern "C" fn trampoline_chain_list_function( @@ -1067,17 +1169,18 @@ unsafe extern "C" fn trampoline_chain_list_function( list: *mut ffi::GstBufferList, ) -> ffi::GstFlowReturn { #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] - let func: &&(Fn(&Pad, &Option<::Object>, ::BufferList) -> ::FlowReturn + let func: &&(Fn(&Pad, &Option<::Object>, ::BufferList) -> Result + Send + Sync + 'static) = transmute((*pad).chainlistdata); - func( + let res: FlowReturn = func( &from_glib_borrow(pad), &from_glib_borrow(parent), from_glib_full(list), ) - .to_glib() + .into(); + res.to_glib() } unsafe extern "C" fn trampoline_event_function( @@ -1103,15 +1206,18 @@ unsafe extern "C" fn trampoline_event_full_function( event: *mut ffi::GstEvent, ) -> ffi::GstFlowReturn { #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] - let func: &&(Fn(&Pad, &Option<::Object>, ::Event) -> ::FlowReturn + Send + Sync + 'static) = - transmute((*pad).eventdata); + let func: &&(Fn(&Pad, &Option<::Object>, ::Event) -> Result + + Send + + Sync + + 'static) = transmute((*pad).eventdata); - func( + let res: FlowReturn = func( &from_glib_borrow(pad), &from_glib_borrow(parent), from_glib_full(event), ) - .to_glib() + .into(); + res.to_glib() } unsafe extern "C" fn trampoline_getrange_function( @@ -1122,7 +1228,7 @@ unsafe extern "C" fn trampoline_getrange_function( buffer: *mut *mut ffi::GstBuffer, ) -> ffi::GstFlowReturn { #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] - let func: &&(Fn(&Pad, &Option<::Object>, u64, u32) -> Result<::Buffer, ::FlowError> + let func: &&(Fn(&Pad, &Option<::Object>, u64, u32) -> Result<::Buffer, FlowError> + Send + Sync + 'static) = transmute((*pad).getrangedata); @@ -1135,9 +1241,9 @@ unsafe extern "C" fn trampoline_getrange_function( ) { Ok(new_buffer) => { *buffer = new_buffer.into_ptr(); - ::FlowReturn::Ok.to_glib() + FlowReturn::Ok.to_glib() } - Err(ret) => ::FlowReturn::from_error(ret).to_glib(), + Err(ret) => FlowReturn::from_error(ret).to_glib(), } } @@ -1163,17 +1269,22 @@ unsafe extern "C" fn trampoline_link_function( peer: *mut ffi::GstPad, ) -> ffi::GstPadLinkReturn { #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] - let func: &&(Fn(&Pad, &Option<::Object>, &::Pad) -> ::PadLinkReturn + let func: &&(Fn( + &Pad, + &Option<::Object>, + &::Pad, + ) -> Result<::PadLinkSuccess, ::PadLinkError> + Send + Sync + 'static) = transmute((*pad).linkdata); - func( + let res: ::PadLinkReturn = func( &from_glib_borrow(pad), &from_glib_borrow(parent), &from_glib_borrow(peer), ) - .to_glib() + .into(); + res.to_glib() } unsafe extern "C" fn trampoline_query_function( @@ -1252,7 +1363,7 @@ mod tests { let mut buffers = buffers_clone.lock().unwrap(); buffers.push(buffer); - ::FlowReturn::Ok + Ok(FlowSuccess::Ok) }); pad.set_active(true).unwrap(); @@ -1261,7 +1372,7 @@ mod tests { let segment = ::FormattedSegment::<::ClockTime>::new(); assert!(pad.send_event(::Event::new_segment(segment.as_ref()).build())); - assert_eq!(pad.chain(::Buffer::new()), ::FlowReturn::Ok); + assert_eq!(pad.chain(::Buffer::new()), Ok(FlowSuccess::Ok)); let events = events.lock().unwrap(); let buffers = buffers.lock().unwrap(); diff --git a/gstreamer/src/proxy_pad.rs b/gstreamer/src/proxy_pad.rs index 6edb51efc..02b76aaa7 100644 --- a/gstreamer/src/proxy_pad.rs +++ b/gstreamer/src/proxy_pad.rs @@ -11,6 +11,7 @@ use Buffer; use BufferList; use FlowError; use FlowReturn; +use FlowSuccess; use Object; use Pad; use ProxyPad; @@ -25,34 +26,36 @@ impl ProxyPad { pad: &P, parent: R, buffer: Buffer, - ) -> FlowReturn { + ) -> Result { skip_assert_initialized!(); let parent = parent.into(); let parent = parent.to_glib_none(); - unsafe { + let ret: FlowReturn = unsafe { from_glib(ffi::gst_proxy_pad_chain_default( pad.to_glib_none().0 as *mut ffi::GstPad, parent.0, buffer.into_ptr(), )) - } + }; + ret.into_result() } pub fn chain_list_default<'a, P: IsA, Q: IsA + 'a, R: Into>>( pad: &P, parent: R, list: BufferList, - ) -> FlowReturn { + ) -> Result { skip_assert_initialized!(); let parent = parent.into(); let parent = parent.to_glib_none(); - unsafe { + let ret: FlowReturn = unsafe { from_glib(ffi::gst_proxy_pad_chain_list_default( pad.to_glib_none().0 as *mut ffi::GstPad, parent.0, list.into_ptr(), )) - } + }; + ret.into_result() } pub fn getrange_default, Q: IsA>( diff --git a/gstreamer/src/subclass/element.rs b/gstreamer/src/subclass/element.rs index 293d6b0a0..3a5c98a00 100644 --- a/gstreamer/src/subclass/element.rs +++ b/gstreamer/src/subclass/element.rs @@ -24,10 +24,16 @@ use Event; use PadTemplate; use QueryRef; use StateChange; +use StateChangeError; use StateChangeReturn; +use StateChangeSuccess; pub trait ElementImpl: ObjectImpl + Send + Sync + 'static { - fn change_state(&self, element: &::Element, transition: StateChange) -> StateChangeReturn { + fn change_state( + &self, + element: &::Element, + transition: StateChange, + ) -> Result { self.parent_change_state(element, transition) } @@ -59,7 +65,7 @@ pub trait ElementImpl: ObjectImpl + Send + Sync + 'static { &self, element: &::Element, transition: StateChange, - ) -> StateChangeReturn { + ) -> Result { unsafe { let data = self.get_type_data(); let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstElementClass; @@ -68,6 +74,7 @@ pub trait ElementImpl: ObjectImpl + Send + Sync + 'static { .change_state .map(|f| from_glib(f(element.to_glib_none().0, transition.to_glib()))) .unwrap_or(::StateChangeReturn::Success) + .into_result() } } @@ -248,7 +255,7 @@ where }; gst_panic_to_error!(&wrap, &instance.panicked(), fallback, { - imp.change_state(&wrap, transition) + imp.change_state(&wrap, transition).into() }) .to_glib() } diff --git a/tutorials/src/bin/basic-tutorial-1.rs b/tutorials/src/bin/basic-tutorial-1.rs index 7f27856de..d1e237070 100644 --- a/tutorials/src/bin/basic-tutorial-1.rs +++ b/tutorials/src/bin/basic-tutorial-1.rs @@ -14,8 +14,9 @@ fn tutorial_main() { let pipeline = gst::parse_launch(&format!("playbin uri={}", uri)).unwrap(); // Start playing - let ret = pipeline.set_state(gst::State::Playing); - assert_ne!(ret, gst::StateChangeReturn::Failure); + pipeline + .set_state(gst::State::Playing) + .expect("Unable to set the pipeline to the `Playing` state"); // Wait until error or EOS let bus = pipeline.get_bus().unwrap(); @@ -38,8 +39,9 @@ fn tutorial_main() { } // Shutdown pipeline - let ret = pipeline.set_state(gst::State::Null); - assert_ne!(ret, gst::StateChangeReturn::Failure); + pipeline + .set_state(gst::State::Null) + .expect("Unable to set the pipeline to the `Null` state"); } fn main() { diff --git a/tutorials/src/bin/basic-tutorial-12.rs b/tutorials/src/bin/basic-tutorial-12.rs index 426508f6a..13e141575 100644 --- a/tutorials/src/bin/basic-tutorial-12.rs +++ b/tutorials/src/bin/basic-tutorial-12.rs @@ -19,8 +19,8 @@ fn tutorial_main() -> Result<(), Error> { let pipeline = gst::parse_launch(&format!("playbin uri={}", uri))?; // Start playing - let ret = pipeline.set_state(gst::State::Playing).into_result()?; - let is_live = ret == gst::StateChangeSuccess::NoPreroll; + let res = pipeline.set_state(gst::State::Playing)?; + let is_live = res == gst::StateChangeSuccess::NoPreroll; let main_loop = glib::MainLoop::new(None, false); let main_loop_clone = main_loop.clone(); diff --git a/tutorials/src/bin/basic-tutorial-2.rs b/tutorials/src/bin/basic-tutorial-2.rs index f15560a23..52af6b656 100644 --- a/tutorials/src/bin/basic-tutorial-2.rs +++ b/tutorials/src/bin/basic-tutorial-2.rs @@ -25,12 +25,9 @@ fn tutorial_main() { source.set_property_from_str("pattern", "smpte"); // Start playing - let ret = pipeline.set_state(gst::State::Playing); - assert_ne!( - ret, - gst::StateChangeReturn::Failure, - "Unable to set the pipeline to the Playing state." - ); + pipeline + .set_state(gst::State::Playing) + .expect("Unable to set the pipeline to the `Playing` state"); // Wait until error or EOS let bus = pipeline.get_bus().unwrap(); @@ -51,12 +48,9 @@ fn tutorial_main() { } } - let ret = pipeline.set_state(gst::State::Null); - assert_ne!( - ret, - gst::StateChangeReturn::Failure, - "Unable to set the pipeline to the Null state." - ); + pipeline + .set_state(gst::State::Null) + .expect("Unable to set the pipeline to the `Null` state"); } fn main() { diff --git a/tutorials/src/bin/basic-tutorial-3.rs b/tutorials/src/bin/basic-tutorial-3.rs index 21e655a4c..7316f4a6e 100644 --- a/tutorials/src/bin/basic-tutorial-3.rs +++ b/tutorials/src/bin/basic-tutorial-3.rs @@ -76,8 +76,8 @@ fn tutorial_main() { return; } - let ret = src_pad.link(&sink_pad); - if ret != gst::PadLinkReturn::Ok { + let res = src_pad.link(&sink_pad); + if !res.is_ok() { println!("Type is {} but link failed.", new_pad_type); } else { println!("Link succeeded (type {}).", new_pad_type); @@ -85,12 +85,9 @@ fn tutorial_main() { }); // Start playing - let ret = pipeline.set_state(gst::State::Playing); - assert_ne!( - ret, - gst::StateChangeReturn::Failure, - "Unable to set the pipeline to the Playing state." - ); + pipeline + .set_state(gst::State::Playing) + .expect("Unable to set the pipeline to the `Playing` state"); // Wait until error or EOS let bus = pipeline.get_bus().unwrap(); @@ -124,12 +121,9 @@ fn tutorial_main() { } } - let ret = pipeline.set_state(gst::State::Null); - assert_ne!( - ret, - gst::StateChangeReturn::Failure, - "Unable to set the pipeline to the Null state." - ); + pipeline + .set_state(gst::State::Null) + .expect("Unable to set the pipeline to the `Null` state"); } fn main() { diff --git a/tutorials/src/bin/basic-tutorial-4.rs b/tutorials/src/bin/basic-tutorial-4.rs index 58158a17d..c42d58ff1 100644 --- a/tutorials/src/bin/basic-tutorial-4.rs +++ b/tutorials/src/bin/basic-tutorial-4.rs @@ -32,8 +32,9 @@ fn tutorial_main() { .expect("Can't set uri property on playbin"); // Start playing - let ret = playbin.set_state(gst::State::Playing); - assert_ne!(ret, gst::StateChangeReturn::Failure); + playbin + .set_state(gst::State::Playing) + .expect("Unable to set the playbin to the `Playing` state"); // Listen to the bus let bus = playbin.get_bus().unwrap(); @@ -92,8 +93,10 @@ fn tutorial_main() { } // Shutdown pipeline - let ret = custom_data.playbin.set_state(gst::State::Null); - assert_ne!(ret, gst::StateChangeReturn::Failure); + custom_data + .playbin + .set_state(gst::State::Null) + .expect("Unable to set the playbin to the `Null` state"); } fn handle_message(custom_data: &mut CustomData, msg: &gst::GstRc) { diff --git a/tutorials/src/bin/basic-tutorial-5.rs b/tutorials/src/bin/basic-tutorial-5.rs index 5615d6cf3..4b1f4e703 100644 --- a/tutorials/src/bin/basic-tutorial-5.rs +++ b/tutorials/src/bin/basic-tutorial-5.rs @@ -121,8 +121,7 @@ mod tutorial5 { let pipeline = &pipeline; pipeline .set_state(gst::State::Playing) - .into_result() - .unwrap(); + .expect("Unable to set the pipeline to the `Playing` state"); }); let pause_button = gtk::Button::new_from_icon_name( @@ -134,8 +133,7 @@ mod tutorial5 { let pipeline = &pipeline; pipeline .set_state(gst::State::Paused) - .into_result() - .unwrap(); + .expect("Unable to set the pipeline to the `Paused` state"); }); let stop_button = gtk::Button::new_from_icon_name( @@ -145,7 +143,9 @@ mod tutorial5 { let pipeline = playbin.clone(); stop_button.connect_clicked(move |_| { let pipeline = &pipeline; - pipeline.set_state(gst::State::Ready).into_result().unwrap(); + pipeline + .set_state(gst::State::Ready) + .expect("Unable to set the pipeline to the `Ready` state"); }); let slider = gtk::Scale::new_with_range( @@ -372,7 +372,9 @@ mod tutorial5 { // We just set the pipeline to READY (which stops playback). gst::MessageView::Eos(..) => { println!("End-Of-Stream reached."); - pipeline.set_state(gst::State::Ready).into_result().unwrap(); + pipeline + .set_state(gst::State::Ready) + .expect("Unable to set the pipeline to the `Ready` state"); } // This is called when an error message is posted on the bus @@ -401,12 +403,13 @@ mod tutorial5 { playbin .set_state(gst::State::Playing) - .into_result() - .unwrap(); + .expect("Unable to set the playbin to the `Playing` state"); gtk::main(); window.hide(); - playbin.set_state(gst::State::Null).into_result().unwrap(); + playbin + .set_state(gst::State::Null) + .expect("Unable to set the playbin to the `Null` state"); bus.remove_signal_watch(); } diff --git a/tutorials/src/bin/basic-tutorial-6.rs b/tutorials/src/bin/basic-tutorial-6.rs index 14fd80ee7..3d014f5dc 100644 --- a/tutorials/src/bin/basic-tutorial-6.rs +++ b/tutorials/src/bin/basic-tutorial-6.rs @@ -111,10 +111,10 @@ fn tutorial_main() { print_pad_capabilities(&sink, "sink"); // Start playing - let ret = pipeline.set_state(gst::State::Playing); - if ret == gst::StateChangeReturn::Failure { + let res = pipeline.set_state(gst::State::Playing); + if res.is_err() { eprintln!( - "Unable to set the pipeline to the playing state (check the bus for error messages)." + "Unable to set the pipeline to the `Playing` state (check the bus for error messages)." ) } @@ -159,8 +159,9 @@ fn tutorial_main() { } // Shutdown pipeline - let ret = pipeline.set_state(gst::State::Null); - assert_ne!(ret, gst::StateChangeReturn::Failure); + pipeline + .set_state(gst::State::Null) + .expect("Unable to set the pipeline to the `Null` state"); } fn main() { diff --git a/tutorials/src/bin/basic-tutorial-7.rs b/tutorials/src/bin/basic-tutorial-7.rs index 0836b1292..b6fa43512 100644 --- a/tutorials/src/bin/basic-tutorial-7.rs +++ b/tutorials/src/bin/basic-tutorial-7.rs @@ -53,7 +53,7 @@ fn tutorial_main() { tee_audio_pad.get_name() ); let queue_audio_pad = audio_queue.get_static_pad("sink").unwrap(); - tee_audio_pad.link(&queue_audio_pad).into_result().unwrap(); + tee_audio_pad.link(&queue_audio_pad).unwrap(); let tee_video_pad = tee.get_request_pad("src_%u").unwrap(); println!( @@ -61,12 +61,11 @@ fn tutorial_main() { tee_video_pad.get_name() ); let queue_video_pad = video_queue.get_static_pad("sink").unwrap(); - tee_video_pad.link(&queue_video_pad).into_result().unwrap(); + tee_video_pad.link(&queue_video_pad).unwrap(); pipeline .set_state(gst::State::Playing) - .into_result() - .expect("Unable to set the pipeline to the Playing state."); + .expect("Unable to set the pipeline to the `Playing` state"); let bus = pipeline.get_bus().unwrap(); for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { use gst::MessageView; @@ -87,8 +86,7 @@ fn tutorial_main() { pipeline .set_state(gst::State::Null) - .into_result() - .expect("Unable to set the pipeline to the Null state."); + .expect("Unable to set the pipeline to the `Null` state"); } fn main() { diff --git a/tutorials/src/bin/basic-tutorial-8.rs b/tutorials/src/bin/basic-tutorial-8.rs index 32d2fe176..05166e21d 100644 --- a/tutorials/src/bin/basic-tutorial-8.rs +++ b/tutorials/src/bin/basic-tutorial-8.rs @@ -108,7 +108,7 @@ fn main() { tee_audio_pad.get_name() ); let queue_audio_pad = audio_queue.get_static_pad("sink").unwrap(); - tee_audio_pad.link(&queue_audio_pad).into_result().unwrap(); + tee_audio_pad.link(&queue_audio_pad).unwrap(); let tee_video_pad = tee.get_request_pad("src_%u").unwrap(); println!( @@ -116,10 +116,10 @@ fn main() { tee_video_pad.get_name() ); let queue_video_pad = video_queue.get_static_pad("sink").unwrap(); - tee_video_pad.link(&queue_video_pad).into_result().unwrap(); + tee_video_pad.link(&queue_video_pad).unwrap(); let tee_app_pad = tee.get_request_pad("src_%u").unwrap(); let queue_app_pad = app_queue.get_static_pad("sink").unwrap(); - tee_app_pad.link(&queue_app_pad).into_result().unwrap(); + tee_app_pad.link(&queue_app_pad).unwrap(); // configure appsrc let info = AudioInfo::new(gst_audio::AudioFormat::S16le, SAMPLE_RATE, 1) @@ -195,10 +195,7 @@ fn main() { (data.appsrc.clone(), buffer) }; - match appsrc.push_buffer(buffer) { - gst::FlowReturn::Ok => glib::Continue(true), - _ => glib::Continue(false), - } + glib::Continue(appsrc.push_buffer(buffer).is_ok()) })); } }); @@ -225,7 +222,7 @@ fn main() { appsink.connect_new_sample(move |_| { let data = match data_weak.upgrade() { Some(data) => data, - None => return gst::FlowReturn::Ok, + None => return Ok(gst::FlowSuccess::Ok), }; let appsink = { @@ -240,7 +237,7 @@ fn main() { let _ = io::stdout().flush(); } - gst::FlowReturn::Ok + Ok(gst::FlowSuccess::Ok) }); let main_loop = glib::MainLoop::new(None, false); @@ -263,15 +260,13 @@ fn main() { pipeline .set_state(gst::State::Playing) - .into_result() - .expect("Unable to set the pipeline to the Playing state."); + .expect("Unable to set the pipeline to the `Playing` state."); main_loop.run(); pipeline .set_state(gst::State::Null) - .into_result() - .expect("Unable to set the pipeline to the Null state."); + .expect("Unable to set the pipeline to the `Null` state."); bus.remove_signal_watch(); }