From be3c378f289683e8c0e7b7cfaff5dc74972bb074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 17 Dec 2019 21:00:42 +0200 Subject: [PATCH] Use Results instead of Options where they signal an error instead of just a missing value Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/issues/216 --- Gir_Gst.toml | 79 +++++++++++++++++++ Gir_GstApp.toml | 14 +++- Gir_GstAudio.toml | 10 +++ Gir_GstBase.toml | 55 +++++++++++++ Gir_GstEditingServices.toml | 47 ++++++++++- Gir_GstGL.toml | 6 +- Gir_GstPbutils.toml | 35 ++++++++ Gir_GstRtspServer.toml | 42 +++++++++- Gir_GstVideo.toml | 10 +++ examples/src/bin/appsink.rs | 10 +-- examples/src/bin/appsrc.rs | 10 +-- examples/src/bin/decodebin.rs | 24 +++--- examples/src/bin/encodebin.rs | 25 +++--- examples/src/bin/events.rs | 3 +- examples/src/bin/glupload.rs | 10 +-- examples/src/bin/gtksink.rs | 5 +- examples/src/bin/gtkvideooverlay.rs | 3 +- examples/src/bin/launch_glib_main.rs | 3 +- examples/src/bin/pango-cairo.rs | 18 ++--- examples/src/bin/queries.rs | 3 +- examples/src/bin/rtpfecclient.rs | 4 +- examples/src/bin/rtpfecserver.rs | 4 +- examples/src/bin/subclass.rs | 14 ++-- examples/src/bin/transmux.rs | 11 +-- gstreamer-app/src/auto/app_sink.rs | 15 +++- gstreamer-app/src/auto/versions.txt | 4 +- gstreamer-audio/src/audio_format.rs | 6 +- gstreamer-audio/src/audio_format_info.rs | 4 +- gstreamer-audio/src/auto/audio_decoder.rs | 8 +- gstreamer-audio/src/auto/audio_encoder.rs | 8 +- gstreamer-audio/src/auto/versions.txt | 4 +- gstreamer-base/src/adapter.rs | 14 ++-- gstreamer-base/src/auto/adapter.rs | 35 ++++---- gstreamer-base/src/auto/base_sink.rs | 33 -------- gstreamer-base/src/auto/base_src.rs | 29 ------- gstreamer-base/src/auto/functions.rs | 14 +++- gstreamer-base/src/auto/versions.txt | 4 +- gstreamer-base/src/base_sink.rs | 37 +++++++++ gstreamer-base/src/base_src.rs | 29 +++++++ gstreamer-check/src/auto/versions.txt | 4 +- gstreamer-check/src/harness.rs | 49 +++++++----- gstreamer-editing-services/src/auto/clip.rs | 14 ++-- gstreamer-editing-services/src/auto/effect.rs | 8 +- gstreamer-editing-services/src/auto/layer.rs | 7 +- .../src/auto/timeline_element.rs | 16 ++-- .../src/auto/uri_clip.rs | 8 +- .../src/auto/versions.txt | 4 +- gstreamer-gl/src/auto/gl_display.rs | 7 +- gstreamer-gl/src/auto/versions.txt | 4 +- gstreamer-gl/src/gl_video_frame.rs | 2 +- gstreamer-net/src/auto/versions.txt | 4 +- gstreamer-pbutils/src/auto/discoverer_info.rs | 13 ++- .../src/auto/encoding_profile.rs | 6 +- gstreamer-pbutils/src/auto/functions.rs | 18 +++-- gstreamer-pbutils/src/auto/versions.txt | 4 +- gstreamer-player/src/auto/versions.txt | 4 +- gstreamer-rtp/src/auto/versions.txt | 4 +- gstreamer-rtp/src/rtp_buffer.rs | 17 +++- .../src/auto/rtsp_address_pool.rs | 15 +++- .../src/auto/rtsp_media_factory.rs | 14 ++-- .../src/auto/rtsp_mount_points.rs | 8 +- .../src/auto/rtsp_session.rs | 16 +++- .../src/auto/rtsp_session_pool.rs | 7 +- gstreamer-rtsp-server/src/auto/versions.txt | 4 +- gstreamer-rtsp/src/auto/versions.txt | 4 +- gstreamer-sdp/src/auto/versions.txt | 4 +- gstreamer-video/src/auto/versions.txt | 4 +- gstreamer-video/src/auto/video_decoder.rs | 8 +- gstreamer-video/src/auto/video_encoder.rs | 8 +- gstreamer-video/src/video_format.rs | 6 +- gstreamer-video/src/video_format_info.rs | 4 +- gstreamer-video/src/video_frame.rs | 64 +++++++-------- gstreamer-webrtc/src/auto/versions.txt | 4 +- gstreamer/src/allocator.rs | 16 +++- gstreamer/src/auto/date_time.rs | 25 +++--- gstreamer/src/auto/device.rs | 7 +- gstreamer/src/auto/element_factory.rs | 10 ++- gstreamer/src/auto/functions.rs | 14 +++- gstreamer/src/auto/ghost_pad.rs | 9 ++- gstreamer/src/auto/pad_template.rs | 11 +-- gstreamer/src/auto/plugin.rs | 14 +++- gstreamer/src/auto/plugin_feature.rs | 8 +- gstreamer/src/auto/versions.txt | 4 +- gstreamer/src/buffer.rs | 33 ++++---- gstreamer/src/buffer_serde.rs | 2 +- gstreamer/src/bus.rs | 12 +-- gstreamer/src/caps.rs | 8 +- gstreamer/src/caps_features.rs | 8 +- gstreamer/src/clock.rs | 22 ++++-- gstreamer/src/date_time.rs | 12 +-- gstreamer/src/ghost_pad.rs | 6 +- gstreamer/src/memory.rs | 12 +-- gstreamer/src/pad_template.rs | 5 +- gstreamer/src/structure.rs | 6 +- gstreamer/src/subclass/device.rs | 37 +++++++-- gstreamer/src/value.rs | 19 +++-- tutorials/src/bin/basic-tutorial-12.rs | 3 +- tutorials/src/bin/basic-tutorial-8.rs | 2 +- tutorials/src/bin/basic-tutorial-9.rs | 4 +- 99 files changed, 916 insertions(+), 445 deletions(-) diff --git a/Gir_Gst.toml b/Gir_Gst.toml index d7872bace..964f042cb 100644 --- a/Gir_Gst.toml +++ b/Gir_Gst.toml @@ -539,6 +539,15 @@ status = "generate" name = "Gst.ElementFactory" status = "generate" final_type = true + [[object.function]] + name = "create" + [object.function.return] + nullable_return_is_error = "Failed to create element from factory" + + [[object.function]] + name = "make" + [object.function.return] + nullable_return_is_error = "Failed to create element from factory name" [[object]] name = "Gst.TypeFindFactory" @@ -618,6 +627,11 @@ status = "generate" [object.function.return] bool_return_is_error = "Failed to reconfigure the element to use this device" + [[object.function]] + name = "create_element" + [object.function.return] + nullable_return_is_error = "Failed to create element for device" + [[object]] name = "Gst.Object" # For renaming the trait... @@ -851,6 +865,16 @@ status = "generate" name = "Gst.PadTemplate" status = "generate" final_type = true + [[object.function]] + name = "new" + [object.function.return] + nullable_return_is_error = "Failed to create pad template" + + [[object.function]] + name = "new_with_gtype" + [object.function.return] + nullable_return_is_error = "Failed to create pad template" + [[object.function]] name = "new_from_static_pad_template_with_gtype" # static pad template manual @@ -872,6 +896,16 @@ status = "generate" name = "new_from_template" ignore = true + [[object.function]] + name = "new_no_target" + [object.function.return] + nullable_return_is_error = "Failed to create GhostPad" + + [[object.function]] + name = "new_no_target_from_template" + [object.function.return] + nullable_return_is_error = "Failed to create GhostPad" + [[object.function]] name = "construct" ignore = true @@ -988,6 +1022,16 @@ final_type = true [object.function.return] nullable = false + [[object.function]] + name = "load" + [object.function.return] + nullable_return_is_error = "Failed to load plugin" + + [[object.function]] + name = "load_by_name" + [object.function.return] + nullable_return_is_error = "Failed to load plugin" + [[object]] name = "Gst.PluginFeature" status = "generate" @@ -1007,6 +1051,11 @@ status = "generate" name = "set_rank" ignore = true + [[object.function]] + name = "load" + [object.function.return] + nullable_return_is_error = "Failed to load plugin feature" + [[object]] name = "Gst.Registry" status = "generate" @@ -1338,6 +1387,16 @@ status = "generate" # Already a Result nullable = false + [[object.function]] + name = "debug_get_stack_trace" + [object.function.return] + nullable_return_is_error = "Failed to get stack trace" + + [[object.function]] + name = "get_main_executable_path" + [object.function.return] + nullable_return_is_error = "Failed to get main executable path" + [[object]] name = "Gst.StateChangeReturn" status = "generate" @@ -1364,3 +1423,23 @@ status = "generate" [[object.derive]] # Don't auto-implement traits name = "" + + [[object.function]] + name = "new_from_g_date_time" + [object.function.return] + nullable = false + + [[object.function]] + name = "to_g_date_time" + [object.function.return] + nullable_return_is_error = "Can't create glib::DateTime from DateTime" + + [[object.function]] + name = "new_from_iso8601_string" + [object.function.return] + nullable_return_is_error = "Failed to create DateTime from ISO-8601 string" + + [[object.function]] + name = "to_iso8601_string" + [object.function.return] + nullable_return_is_error = "Failed to create ISO-8601 string from DateTime" diff --git a/Gir_GstApp.toml b/Gir_GstApp.toml index e8d1aa564..fdf93563c 100644 --- a/Gir_GstApp.toml +++ b/Gir_GstApp.toml @@ -74,8 +74,18 @@ final_type = true [[object.function]] name = "set_caps" [[object.function.parameter]] - name = "caps" - nullable = true + name = "caps" + nullable = true + + [[object.function]] + name = "pull_preroll" + [object.function.return] + nullable_return_is_error = "Failed to pull preroll sample" + + [[object.function]] + name = "pull_sample" + [object.function.return] + nullable_return_is_error = "Failed to pull sample" [[object]] name = "GstApp.AppSrc" diff --git a/Gir_GstAudio.toml b/Gir_GstAudio.toml index 607e2c572..f920189da 100644 --- a/Gir_GstAudio.toml +++ b/Gir_GstAudio.toml @@ -168,6 +168,11 @@ status = "generate" [object.function.return] nullable = false + [[object.function]] + name = "allocate_output_buffer" + [object.function.return] + nullable_return_is_error = "Failed to allocate output buffer" + [[object]] name = "GstAudio.AudioEncoder" status = "generate" @@ -196,3 +201,8 @@ status = "generate" name = "proxy_getcaps" [object.function.return] nullable = false + + [[object.function]] + name = "allocate_output_buffer" + [object.function.return] + nullable_return_is_error = "Failed to allocate output buffer" diff --git a/Gir_GstBase.toml b/Gir_GstBase.toml index 9f076f5be..efe712300 100644 --- a/Gir_GstBase.toml +++ b/Gir_GstBase.toml @@ -68,6 +68,41 @@ concurrency = "send-unique" # Useless copying of data ignore = true + [[object.function]] + name = "copy_bytes" + [object.function.return] + nullable_return_is_error = "Failed to copy bytes" + + [[object.function]] + name = "get_buffer" + [object.function.return] + nullable_return_is_error = "Failed to get buffer" + + [[object.function]] + name = "get_buffer_fast" + [object.function.return] + nullable_return_is_error = "Failed to get buffer" + + [[object.function]] + name = "get_buffer_list" + [object.function.return] + nullable_return_is_error = "Failed to get buffer list" + + [[object.function]] + name = "take_buffer" + [object.function.return] + nullable_return_is_error = "Failed to take buffer" + + [[object.function]] + name = "take_buffer_fast" + [object.function.return] + nullable_return_is_error = "Failed to take buffer" + + [[object.function]] + name = "take_buffer_list" + [object.function.return] + nullable_return_is_error = "Failed to take buffer list" + [[object]] name = "GstBase.FlowCombiner" # Manual because ref/unref functions were added much later @@ -94,6 +129,11 @@ status = "generate" # Use Result ignore = true + [[object.function]] + name = "query_latency" + # Use Result + ignore = true + [[object]] name = "GstBase.BaseSrc" status = "generate" @@ -123,6 +163,11 @@ status = "generate" # Use Result ignore = true + [[object.function]] + name = "query_latency" + # Use Result + ignore = true + [[object]] name = "GstBase.BaseTransform" status = "generate" @@ -185,6 +230,16 @@ status = "generate" # broken return value ignore = true + [[object.function]] + name = "type_find_helper" + [object.function.return] + nullable_return_is_error = "Could not find type" + + [[object.function]] + name = "type_find_helper_for_extension" + [object.function.return] + nullable_return_is_error = "Could not find type" + [[object]] name = "Gst.Structure" status = "manual" diff --git a/Gir_GstEditingServices.toml b/Gir_GstEditingServices.toml index fd4a07edc..2659ccca9 100644 --- a/Gir_GstEditingServices.toml +++ b/Gir_GstEditingServices.toml @@ -40,11 +40,9 @@ generate = [ "GES.EditMode", "GES.PipelineFlags", "GES.Edge", - "GES.Effect", "GES.TrackType", "GES.BaseEffect", "GES.Group", - "GES.UriClip", "GES.UriClipAsset", "GES.UriSourceAsset", ] @@ -79,6 +77,22 @@ name = "Gst.ClockTime" status = "manual" conversion_type = "scalar" +[[object]] +name = "GES.Effect" +status = "generate" + [[object.function]] + name = "new" + [object.function.return] + nullable_return_is_error = "Failed to create effect from description" + +[[object]] +name = "GES.UriClip" +status = "generate" + [[object.function]] + name = "new" + [object.function.return] + nullable_return_is_error = "Failed to create Uri clip from Uri" + [[object]] name = "GES.Timeline" status = "generate" @@ -205,6 +219,16 @@ status = "generate" [object.function.return] bool_return_is_error = "Failed to the set top effect priority" + [[object.function]] + name = "add_asset" + [object.function.return] + nullable_return_is_error = "Failed to add asset" + + [[object.function]] + name = "split" + [object.function.return] + nullable_return_is_error = "Failed to split clip" + [[object]] name = "GES.Extractable" status = "generate" @@ -227,6 +251,11 @@ status = "generate" [object.function.return] bool_return_is_error = "Failed to remove clip" + [[object.function]] + name = "add_asset" + [object.function.return] + nullable_return_is_error = "Failed to add asset" + [[object]] name = "GES.Project" status = "generate" @@ -281,7 +310,17 @@ status = "generate" [[object.function]] name = "trim" [object.function.return] - bool_return_is_error = "`Failed to trim" + bool_return_is_error = "Failed to trim" + + [[object.function]] + name = "copy" + [object.function.return] + nullable_return_is_error = "Failed to copy timeline element" + + [[object.function]] + name = "paste" + [object.function.return] + nullable_return_is_error = "Failed to paste timeline element" [[object]] name = "GES.TrackElement" @@ -294,4 +333,4 @@ status = "generate" [[object.function]] name = "remove_control_binding" [object.function.return] - bool_return_is_error = "Failed to remove control binding" \ No newline at end of file + bool_return_is_error = "Failed to remove control binding" diff --git a/Gir_GstGL.toml b/Gir_GstGL.toml index d998a0bbc..e338ce023 100644 --- a/Gir_GstGL.toml +++ b/Gir_GstGL.toml @@ -186,6 +186,11 @@ status = "generate" [object.function.return] bool_return_is_error = "Failed to remove window" + [[object.function]] + name = "create_window" + [object.function.return] + nullable_return_is_error = "Failed to create window" + [[object]] name = "GstGL.GLDisplayEGL" status = "generate" @@ -262,7 +267,6 @@ status = "generate" name = "GstGL.GLColorConvert" status = "generate" final_type = true - [[object.function]] name = "set_caps" [object.function.return] diff --git a/Gir_GstPbutils.toml b/Gir_GstPbutils.toml index 75f6c8ed3..70c756842 100644 --- a/Gir_GstPbutils.toml +++ b/Gir_GstPbutils.toml @@ -99,6 +99,16 @@ status = "generate" [object.function.return] nullable = false + [[object.function]] + name = "to_variant" + [object.function.return] + nullable_return_is_error = "Failed to serialize DiscovererInfo to Variant" + + [[object.function]] + name = "from_variant" + [object.function.return] + nullable_return_is_error = "Failed to deserialize DiscovererInfo from Variant" + [[object]] name = "GstPbutils.DiscovererStreamInfo" status = "generate" @@ -180,6 +190,11 @@ status = "generate" # encodingprofile is immutable after constructed ignore = true + [[object.function]] + name = "from_discoverer" + [object.function.return] + nullable_return_is_error = "Failed to create EncodingProfile from DiscovererInfo" + [[object]] name = "GstPbutils.EncodingContainerProfile" status = "generate" @@ -292,3 +307,23 @@ status = "generate" [[object.function]] name = "pb_utils_get_encoder_description" ignore = true + + [[object.function]] + name = "pb_utils_get_element_description" + [object.function.return] + nullable_return_is_error = "Failed to get element description" + + [[object.function]] + name = "pb_utils_get_sink_description" + [object.function.return] + nullable_return_is_error = "Failed to get sink description" + + [[object.function]] + name = "pb_utils_get_source_description" + [object.function.return] + nullable_return_is_error = "Failed to get source description" + + [[object.function]] + name = "plugins_base_version_string" + [object.function.return] + nullable = false diff --git a/Gir_GstRtspServer.toml b/Gir_GstRtspServer.toml index d7665b6e1..56661b6c4 100644 --- a/Gir_GstRtspServer.toml +++ b/Gir_GstRtspServer.toml @@ -26,9 +26,7 @@ generate = [ "GstRtspServer.RTSPAddressPoolResult", "GstRtspServer.RTSPMediaFactoryURI", "GstRtspServer.RTSPMediaStatus", - "GstRtspServer.RTSPMountPoints", "GstRtspServer.RTSPPublishClockMode", - "GstRtspServer.RTSPSession", "GstRtspServer.RTSPSuspendMode", "GstRtspServer.RTSPThreadPool", "GstRtspServer.RTSPThreadType", @@ -225,6 +223,11 @@ status = "generate" [object.function.return] bool_return_is_error = "Failed to add address range" + [[object.function]] + name = "acquire_address" + [object.function.return] + nullable_return_is_error = "Failed to acquire address" + [[object.function]] name = "reserve_address" ignore = true @@ -257,6 +260,16 @@ status = "generate" # Different structure mutability needed ignore = true + [[object.function]] + name = "construct" + [object.function.return] + nullable_return_is_error = "Failed to construct media" + + [[object.function]] + name = "create_element" + [object.function.return] + nullable_return_is_error = "Failed to create media element" + [[object]] name = "GstRtspServer.RTSPSessionMedia" status = "generate" @@ -280,10 +293,14 @@ status = "generate" # GSource return ignore = true + [[object.function]] + name = "create" + [object.function.return] + nullable_return_is_error = "Failed to create session pool" + [[object]] name="GstRtspServer.RTSPAuth" status="generate" - [[object.function]] name = "check" [object.function.return] @@ -297,9 +314,26 @@ status="generate" [[object.function]] name = "make_basic" [object.function.return] - nullable = false + nullable = false [[object.function]] name = "set_default_token" # gir forgets mut ignore = true + +[[object]] +name="GstRtspServer.RTSPMountPoints" +status="generate" + [[object.function]] + name = "make_path" + [object.function.return] + nullable_return_is_error = "Failed to make path" + +[[object]] +name="GstRtspServer.RTSPSession" +status="generate" + [[object.function]] + name = "manage_media" + [object.function.return] + nullable_return_is_error = "Failed to manage media" + diff --git a/Gir_GstVideo.toml b/Gir_GstVideo.toml index ab1da807a..1e11201d9 100644 --- a/Gir_GstVideo.toml +++ b/Gir_GstVideo.toml @@ -160,6 +160,11 @@ status = "generate" [object.function.return] nullable = false + [[object.function]] + name = "allocate_output_buffer" + [object.function.return] + nullable_return_is_error = "Failed to allocate output buffer" + [[object]] name = "GstVideo.VideoEncoder" status = "generate" @@ -216,3 +221,8 @@ status = "generate" name = "proxy_getcaps" [object.function.return] nullable = false + + [[object.function]] + name = "allocate_output_buffer" + [object.function.return] + nullable_return_is_error = "Failed to allocate output buffer" diff --git a/examples/src/bin/appsink.rs b/examples/src/bin/appsink.rs index 7c872c269..5a3338584 100644 --- a/examples/src/bin/appsink.rs +++ b/examples/src/bin/appsink.rs @@ -55,9 +55,9 @@ fn create_pipeline() -> Result { gst::init()?; let pipeline = gst::Pipeline::new(None); - let src = - gst::ElementFactory::make("audiotestsrc", None).ok_or(MissingElement("audiotestsrc"))?; - let sink = gst::ElementFactory::make("appsink", None).ok_or(MissingElement("appsink"))?; + let src = gst::ElementFactory::make("audiotestsrc", None) + .map_err(|_| MissingElement("audiotestsrc"))?; + let sink = gst::ElementFactory::make("appsink", None).map_err(|_| MissingElement("appsink"))?; pipeline.add_many(&[&src, &sink])?; src.link(&sink)?; @@ -87,7 +87,7 @@ 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 = appsink.pull_sample().ok_or(gst::FlowError::Eos)?; + let sample = appsink.pull_sample().map_err(|_| gst::FlowError::Eos)?; let buffer = sample.get_buffer().ok_or_else(|| { gst_element_error!( appsink, @@ -105,7 +105,7 @@ 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 = buffer.map_readable().ok_or_else(|| { + let map = buffer.map_readable().map_err(|_| { gst_element_error!( appsink, gst::ResourceError::Failed, diff --git a/examples/src/bin/appsrc.rs b/examples/src/bin/appsrc.rs index 1f725cabb..2e3c39917 100644 --- a/examples/src/bin/appsrc.rs +++ b/examples/src/bin/appsrc.rs @@ -52,11 +52,11 @@ fn create_pipeline() -> Result { gst::init()?; let pipeline = gst::Pipeline::new(None); - let src = gst::ElementFactory::make("appsrc", None).ok_or(MissingElement("appsrc"))?; - let videoconvert = - gst::ElementFactory::make("videoconvert", None).ok_or(MissingElement("videoconvert"))?; - let sink = - gst::ElementFactory::make("autovideosink", None).ok_or(MissingElement("autovideosink"))?; + let src = gst::ElementFactory::make("appsrc", None).map_err(|_| MissingElement("appsrc"))?; + let videoconvert = gst::ElementFactory::make("videoconvert", None) + .map_err(|_| MissingElement("videoconvert"))?; + let sink = gst::ElementFactory::make("autovideosink", None) + .map_err(|_| MissingElement("autovideosink"))?; pipeline.add_many(&[&src, &videoconvert, &sink])?; gst::Element::link_many(&[&src, &videoconvert, &sink])?; diff --git a/examples/src/bin/decodebin.rs b/examples/src/bin/decodebin.rs index 8ff5634bf..a735a9417 100644 --- a/examples/src/bin/decodebin.rs +++ b/examples/src/bin/decodebin.rs @@ -93,9 +93,9 @@ fn example_main() -> Result<(), Error> { }; let pipeline = gst::Pipeline::new(None); - let src = gst::ElementFactory::make("filesrc", None).ok_or(MissingElement("filesrc"))?; + let src = gst::ElementFactory::make("filesrc", None).map_err(|_| MissingElement("filesrc"))?; let decodebin = - gst::ElementFactory::make("decodebin", None).ok_or(MissingElement("decodebin"))?; + gst::ElementFactory::make("decodebin", None).map_err(|_| MissingElement("decodebin"))?; // Tell the filesrc what file to load src.set_property("location", &uri)?; @@ -157,14 +157,14 @@ fn example_main() -> Result<(), Error> { if is_audio { // decodebin found a raw audiostream, so we build the follow-up pipeline to // play it on the default audio playback device (using autoaudiosink). - let queue = - gst::ElementFactory::make("queue", None).ok_or(MissingElement("queue"))?; + let queue = gst::ElementFactory::make("queue", None) + .map_err(|_| MissingElement("queue"))?; let convert = gst::ElementFactory::make("audioconvert", None) - .ok_or(MissingElement("audioconvert"))?; + .map_err(|_| MissingElement("audioconvert"))?; let resample = gst::ElementFactory::make("audioresample", None) - .ok_or(MissingElement("audioresample"))?; + .map_err(|_| MissingElement("audioresample"))?; let sink = gst::ElementFactory::make("autoaudiosink", None) - .ok_or(MissingElement("autoaudiosink"))?; + .map_err(|_| MissingElement("autoaudiosink"))?; let elements = &[&queue, &convert, &resample, &sink]; pipeline.add_many(elements)?; @@ -185,14 +185,14 @@ fn example_main() -> Result<(), Error> { } else if is_video { // decodebin found a raw videostream, so we build the follow-up pipeline to // display it using the autovideosink. - let queue = - gst::ElementFactory::make("queue", None).ok_or(MissingElement("queue"))?; + let queue = gst::ElementFactory::make("queue", None) + .map_err(|_| MissingElement("queue"))?; let convert = gst::ElementFactory::make("videoconvert", None) - .ok_or(MissingElement("videoconvert"))?; + .map_err(|_| MissingElement("videoconvert"))?; let scale = gst::ElementFactory::make("videoscale", None) - .ok_or(MissingElement("videoscale"))?; + .map_err(|_| MissingElement("videoscale"))?; let sink = gst::ElementFactory::make("autovideosink", None) - .ok_or(MissingElement("autovideosink"))?; + .map_err(|_| MissingElement("autovideosink"))?; let elements = &[&queue, &convert, &scale, &sink]; pipeline.add_many(elements)?; diff --git a/examples/src/bin/encodebin.rs b/examples/src/bin/encodebin.rs index 0e45bc752..8b20b52d4 100644 --- a/examples/src/bin/encodebin.rs +++ b/examples/src/bin/encodebin.rs @@ -117,11 +117,12 @@ fn example_main() -> Result<(), Error> { }; let pipeline = gst::Pipeline::new(None); - let src = - gst::ElementFactory::make("uridecodebin", None).ok_or(MissingElement("uridecodebin"))?; + let src = gst::ElementFactory::make("uridecodebin", None) + .map_err(|_| MissingElement("uridecodebin"))?; let encodebin = - gst::ElementFactory::make("encodebin", None).ok_or(MissingElement("encodebin"))?; - let sink = gst::ElementFactory::make("filesink", None).ok_or(MissingElement("filesink"))?; + gst::ElementFactory::make("encodebin", None).map_err(|_| MissingElement("encodebin"))?; + let sink = + gst::ElementFactory::make("filesink", None).map_err(|_| MissingElement("filesink"))?; src.set_property("uri", &uri) .expect("setting URI Property failed"); @@ -188,12 +189,12 @@ fn example_main() -> Result<(), Error> { let link_to_encodebin = |is_audio, is_video| -> Result<(), Error> { if is_audio { - let queue = - gst::ElementFactory::make("queue", None).ok_or(MissingElement("queue"))?; + let queue = gst::ElementFactory::make("queue", None) + .map_err(|_| MissingElement("queue"))?; let convert = gst::ElementFactory::make("audioconvert", None) - .ok_or(MissingElement("audioconvert"))?; + .map_err(|_| MissingElement("audioconvert"))?; let resample = gst::ElementFactory::make("audioresample", None) - .ok_or(MissingElement("audioresample"))?; + .map_err(|_| MissingElement("audioresample"))?; let elements = &[&queue, &convert, &resample]; pipeline @@ -221,12 +222,12 @@ fn example_main() -> Result<(), Error> { let sink_pad = queue.get_static_pad("sink").expect("queue has no sinkpad"); dbin_src_pad.link(&sink_pad)?; } else if is_video { - let queue = - gst::ElementFactory::make("queue", None).ok_or(MissingElement("queue"))?; + let queue = gst::ElementFactory::make("queue", None) + .map_err(|_| MissingElement("queue"))?; let convert = gst::ElementFactory::make("videoconvert", None) - .ok_or(MissingElement("videoconvert"))?; + .map_err(|_| MissingElement("videoconvert"))?; let scale = gst::ElementFactory::make("videoscale", None) - .ok_or(MissingElement("videoscale"))?; + .map_err(|_| MissingElement("videoscale"))?; let elements = &[&queue, &convert, &scale]; pipeline diff --git a/examples/src/bin/events.rs b/examples/src/bin/events.rs index 35f17fe38..005453092 100644 --- a/examples/src/bin/events.rs +++ b/examples/src/bin/events.rs @@ -116,7 +116,8 @@ fn example_main() { // Tell the mainloop to continue executing this callback. glib::Continue(true) - }); + }) + .expect("Failed to add bus watch"); // Operate GStreamer's bus, facilliating GLib's mainloop here. // This function call will block until you tell the mainloop to quit diff --git a/examples/src/bin/glupload.rs b/examples/src/bin/glupload.rs index e139d1dc8..86c1f5c5e 100644 --- a/examples/src/bin/glupload.rs +++ b/examples/src/bin/glupload.rs @@ -484,7 +484,7 @@ impl App { self.appsink.set_callbacks( gst_app::AppSinkCallbacks::new() .new_sample(move |appsink| { - let sample = appsink.pull_sample().ok_or(gst::FlowError::Eos)?; + let sample = appsink.pull_sample().map_err(|_| gst::FlowError::Eos)?; { let _buffer = sample.get_buffer().ok_or_else(|| { @@ -539,15 +539,15 @@ impl App { fn create_pipeline() -> Result<(gst::Pipeline, gst_app::AppSink, gst::Element), Error> { let pipeline = gst::Pipeline::new(None); let src = gst::ElementFactory::make("videotestsrc", None) - .ok_or(MissingElement("videotestsrc"))?; - let sink = - gst::ElementFactory::make("glsinkbin", None).ok_or(MissingElement("glsinkbin"))?; + .map_err(|_| MissingElement("videotestsrc"))?; + let sink = gst::ElementFactory::make("glsinkbin", None) + .map_err(|_| MissingElement("glsinkbin"))?; pipeline.add_many(&[&src, &sink])?; src.link(&sink)?; let appsink = gst::ElementFactory::make("appsink", None) - .ok_or(MissingElement("appsink"))? + .map_err(|_| MissingElement("appsink"))? .dynamic_cast::() .expect("Sink element is expected to be an appsink!"); diff --git a/examples/src/bin/gtksink.rs b/examples/src/bin/gtksink.rs index 839685ab0..1b4c7409b 100644 --- a/examples/src/bin/gtksink.rs +++ b/examples/src/bin/gtksink.rs @@ -31,7 +31,7 @@ fn create_ui(app: >k::Application) { // in the pipeline, and the widget will be embedded in our gui. // Gstreamer then displays frames in the gtk widget. // First, we try to use the OpenGL version - and if that fails, we fall back to non-OpenGL. - let (sink, widget) = if let Some(gtkglsink) = gst::ElementFactory::make("gtkglsink", None) { + let (sink, widget) = if let Ok(gtkglsink) = gst::ElementFactory::make("gtkglsink", None) { // Using the OpenGL widget succeeded, so we are in for a nice playback experience with // low cpu usage. :) // The gtkglsink essentially allocates an OpenGL texture on the GPU, that it will display. @@ -136,7 +136,8 @@ fn create_ui(app: >k::Application) { }; glib::Continue(true) - }); + }) + .expect("Failed to add bus watch"); // Pipeline reference is owned by the closure below, so will be // destroyed once the app is destroyed diff --git a/examples/src/bin/gtkvideooverlay.rs b/examples/src/bin/gtkvideooverlay.rs index 72c0f57df..fde59357f 100644 --- a/examples/src/bin/gtkvideooverlay.rs +++ b/examples/src/bin/gtkvideooverlay.rs @@ -248,7 +248,8 @@ fn create_ui(app: >k::Application) { }; glib::Continue(true) - }); + }) + .expect("Failed to add bus watch"); // Pipeline reference is owned by the closure below, so will be // destroyed once the app is destroyed diff --git a/examples/src/bin/launch_glib_main.rs b/examples/src/bin/launch_glib_main.rs index 9e600091e..ebcba88dd 100644 --- a/examples/src/bin/launch_glib_main.rs +++ b/examples/src/bin/launch_glib_main.rs @@ -57,7 +57,8 @@ fn example_main() { }; glib::Continue(true) - }); + }) + .expect("Failed to add bus watch"); main_loop.run(); diff --git a/examples/src/bin/pango-cairo.rs b/examples/src/bin/pango-cairo.rs index e5e8d0644..8c821d77b 100644 --- a/examples/src/bin/pango-cairo.rs +++ b/examples/src/bin/pango-cairo.rs @@ -78,16 +78,16 @@ fn create_pipeline() -> Result { gst::init()?; let pipeline = gst::Pipeline::new(None); - let src = - gst::ElementFactory::make("videotestsrc", None).ok_or(MissingElement("videotestsrc"))?; - let overlay = - gst::ElementFactory::make("cairooverlay", None).ok_or(MissingElement("cairooverlay"))?; + let src = gst::ElementFactory::make("videotestsrc", None) + .map_err(|_| MissingElement("videotestsrc"))?; + let overlay = gst::ElementFactory::make("cairooverlay", None) + .map_err(|_| MissingElement("cairooverlay"))?; let capsfilter = - gst::ElementFactory::make("capsfilter", None).ok_or(MissingElement("capsfilter"))?; - let videoconvert = - gst::ElementFactory::make("videoconvert", None).ok_or(MissingElement("videoconvert"))?; - let sink = - gst::ElementFactory::make("autovideosink", None).ok_or(MissingElement("autovideosink"))?; + gst::ElementFactory::make("capsfilter", None).map_err(|_| MissingElement("capsfilter"))?; + let videoconvert = gst::ElementFactory::make("videoconvert", None) + .map_err(|_| MissingElement("videoconvert"))?; + let sink = gst::ElementFactory::make("autovideosink", None) + .map_err(|_| MissingElement("autovideosink"))?; pipeline.add_many(&[&src, &overlay, &capsfilter, &videoconvert, &sink])?; gst::Element::link_many(&[&src, &overlay, &capsfilter, &videoconvert, &sink])?; diff --git a/examples/src/bin/queries.rs b/examples/src/bin/queries.rs index 7348a89eb..1dfab1bec 100644 --- a/examples/src/bin/queries.rs +++ b/examples/src/bin/queries.rs @@ -117,7 +117,8 @@ fn example_main() { }; glib::Continue(true) - }); + }) + .expect("Failed to add bus watch"); main_loop.run(); diff --git a/examples/src/bin/rtpfecclient.rs b/examples/src/bin/rtpfecclient.rs index c79c53313..60d3acf89 100644 --- a/examples/src/bin/rtpfecclient.rs +++ b/examples/src/bin/rtpfecclient.rs @@ -50,8 +50,8 @@ fn make_element( element_name: Option<&str>, ) -> Result { match gst::ElementFactory::make(factory_name, element_name) { - Some(elem) => Ok(elem), - None => Err(Error::from(MissingElement(factory_name))), + Ok(elem) => Ok(elem), + Err(_) => Err(Error::from(MissingElement(factory_name))), } } diff --git a/examples/src/bin/rtpfecserver.rs b/examples/src/bin/rtpfecserver.rs index dd755eec8..ae9d97382 100644 --- a/examples/src/bin/rtpfecserver.rs +++ b/examples/src/bin/rtpfecserver.rs @@ -47,8 +47,8 @@ fn make_element( element_name: Option<&str>, ) -> Result { match gst::ElementFactory::make(factory_name, element_name) { - Some(elem) => Ok(elem), - None => Err(Error::from(MissingElement(factory_name))), + Ok(elem) => Ok(elem), + Err(_) => Err(Error::from(MissingElement(factory_name))), } } diff --git a/examples/src/bin/subclass.rs b/examples/src/bin/subclass.rs index 92dbc31cc..c9ae35a5e 100644 --- a/examples/src/bin/subclass.rs +++ b/examples/src/bin/subclass.rs @@ -209,7 +209,7 @@ mod fir_filter { } // Try mapping the input buffer as writable - let mut data = buf.map_writable().ok_or_else(|| { + let mut data = buf.map_writable().map_err(|_| { gst_element_error!( element, gst::CoreError::Failed, @@ -318,13 +318,13 @@ fn create_pipeline() -> Result { // Create our pipeline with the custom element let pipeline = gst::Pipeline::new(None); - let src = - gst::ElementFactory::make("audiotestsrc", None).ok_or(MissingElement("audiotestsrc"))?; + let src = gst::ElementFactory::make("audiotestsrc", None) + .map_err(|_| MissingElement("audiotestsrc"))?; let filter = fir_filter::FirFilter::new(None); - let conv = - gst::ElementFactory::make("audioconvert", None).ok_or(MissingElement("audioconvert"))?; - let sink = - gst::ElementFactory::make("autoaudiosink", None).ok_or(MissingElement("autoaudiosink"))?; + let conv = gst::ElementFactory::make("audioconvert", None) + .map_err(|_| MissingElement("audioconvert"))?; + let sink = gst::ElementFactory::make("autoaudiosink", None) + .map_err(|_| MissingElement("autoaudiosink"))?; pipeline.add_many(&[&src, filter.upcast_ref(), &conv, &sink])?; src.link(&filter)?; diff --git a/examples/src/bin/transmux.rs b/examples/src/bin/transmux.rs index ca38b5c2e..57f1919f2 100644 --- a/examples/src/bin/transmux.rs +++ b/examples/src/bin/transmux.rs @@ -71,12 +71,13 @@ fn example_main() -> Result<(), Error> { let src = gst::Element::make_from_uri(gst::URIType::Src, uri, None) .expect("We do not seem to support this uri"); let typefinder = - gst::ElementFactory::make("typefind", None).ok_or(MissingElement("typefind"))?; + gst::ElementFactory::make("typefind", None).map_err(|_| MissingElement("typefind"))?; let queue = - gst::ElementFactory::make("multiqueue", None).ok_or(MissingElement("multiqueue"))?; - let muxer = - gst::ElementFactory::make("matroskamux", None).ok_or(MissingElement("matroskamux"))?; - let sink = gst::ElementFactory::make("filesink", None).ok_or(MissingElement("filesink"))?; + gst::ElementFactory::make("multiqueue", None).map_err(|_| MissingElement("multiqueue"))?; + let muxer = gst::ElementFactory::make("matroskamux", None) + .map_err(|_| MissingElement("matroskamux"))?; + let sink = + gst::ElementFactory::make("filesink", None).map_err(|_| MissingElement("filesink"))?; sink.set_property("location", &output_file) .expect("setting location property failed"); diff --git a/gstreamer-app/src/auto/app_sink.rs b/gstreamer-app/src/auto/app_sink.rs index b37997ae6..42ffe0047 100644 --- a/gstreamer-app/src/auto/app_sink.rs +++ b/gstreamer-app/src/auto/app_sink.rs @@ -2,6 +2,7 @@ // from gir-files (https://github.com/gtk-rs/gir-files) // DO NOT EDIT +use glib; use glib::object::ObjectType as ObjectType_; use glib::signal::connect_raw; use glib::signal::SignalHandlerId; @@ -66,16 +67,22 @@ impl AppSink { unsafe { from_glib(gst_app_sys::gst_app_sink_is_eos(self.to_glib_none().0)) } } - pub fn pull_preroll(&self) -> Option { + pub fn pull_preroll(&self) -> Result { unsafe { - from_glib_full(gst_app_sys::gst_app_sink_pull_preroll( + Option::<_>::from_glib_full(gst_app_sys::gst_app_sink_pull_preroll( self.to_glib_none().0, )) + .ok_or_else(|| glib_bool_error!("Failed to pull preroll sample")) } } - pub fn pull_sample(&self) -> Option { - unsafe { from_glib_full(gst_app_sys::gst_app_sink_pull_sample(self.to_glib_none().0)) } + pub fn pull_sample(&self) -> Result { + unsafe { + Option::<_>::from_glib_full(gst_app_sys::gst_app_sink_pull_sample( + self.to_glib_none().0, + )) + .ok_or_else(|| glib_bool_error!("Failed to pull sample")) + } } #[cfg(any(feature = "v1_12", feature = "dox"))] diff --git a/gstreamer-app/src/auto/versions.txt b/gstreamer-app/src/auto/versions.txt index bb4ffb804..992f7403f 100644 --- a/gstreamer-app/src/auto/versions.txt +++ b/gstreamer-app/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ d1e88f9) -from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) +Generated by gir (https://github.com/gtk-rs/gir @ 5836573) +from gir-files (https://github.com/gtk-rs/gir-files @ c067e63) diff --git a/gstreamer-audio/src/audio_format.rs b/gstreamer-audio/src/audio_format.rs index de6fa4241..c821450bf 100644 --- a/gstreamer-audio/src/audio_format.rs +++ b/gstreamer-audio/src/audio_format.rs @@ -47,9 +47,9 @@ impl ::AudioFormat { } impl str::FromStr for ::AudioFormat { - type Err = (); + type Err = glib::BoolError; - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { assert_initialized_main_thread!(); unsafe { @@ -57,7 +57,7 @@ impl str::FromStr for ::AudioFormat { s.to_glib_none().0, )); if fmt == ::AudioFormat::Unknown { - Err(()) + Err(glib_bool_error!("Failed to parse audio format from string")) } else { Ok(fmt) } diff --git a/gstreamer-audio/src/audio_format_info.rs b/gstreamer-audio/src/audio_format_info.rs index 643ee7d55..d66f2349c 100644 --- a/gstreamer-audio/src/audio_format_info.rs +++ b/gstreamer-audio/src/audio_format_info.rs @@ -240,9 +240,9 @@ impl fmt::Display for AudioFormatInfo { } impl str::FromStr for ::AudioFormatInfo { - type Err = (); + type Err = glib::BoolError; - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { skip_assert_initialized!(); let format = s.parse()?; Ok(AudioFormatInfo::from_format(format)) diff --git a/gstreamer-audio/src/auto/audio_decoder.rs b/gstreamer-audio/src/auto/audio_decoder.rs index 3ef670638..e02adc360 100644 --- a/gstreamer-audio/src/auto/audio_decoder.rs +++ b/gstreamer-audio/src/auto/audio_decoder.rs @@ -2,6 +2,7 @@ // from gir-files (https://github.com/gtk-rs/gir-files) // DO NOT EDIT +use glib; use glib::object::Cast; use glib::object::IsA; use glib::signal::connect_raw; @@ -29,7 +30,7 @@ unsafe impl Sync for AudioDecoder {} pub const NONE_AUDIO_DECODER: Option<&AudioDecoder> = None; pub trait AudioDecoderExt: 'static { - fn allocate_output_buffer(&self, size: usize) -> Option; + fn allocate_output_buffer(&self, size: usize) -> Result; fn get_audio_info(&self) -> Option; @@ -99,12 +100,13 @@ pub trait AudioDecoderExt: 'static { } impl> AudioDecoderExt for O { - fn allocate_output_buffer(&self, size: usize) -> Option { + fn allocate_output_buffer(&self, size: usize) -> Result { unsafe { - from_glib_full(gst_audio_sys::gst_audio_decoder_allocate_output_buffer( + Option::<_>::from_glib_full(gst_audio_sys::gst_audio_decoder_allocate_output_buffer( self.as_ref().to_glib_none().0, size, )) + .ok_or_else(|| glib_bool_error!("Failed to allocate output buffer")) } } diff --git a/gstreamer-audio/src/auto/audio_encoder.rs b/gstreamer-audio/src/auto/audio_encoder.rs index 7b4b0c098..b238f5e8f 100644 --- a/gstreamer-audio/src/auto/audio_encoder.rs +++ b/gstreamer-audio/src/auto/audio_encoder.rs @@ -2,6 +2,7 @@ // from gir-files (https://github.com/gtk-rs/gir-files) // DO NOT EDIT +use glib; use glib::object::Cast; use glib::object::IsA; use glib::signal::connect_raw; @@ -28,7 +29,7 @@ unsafe impl Sync for AudioEncoder {} pub const NONE_AUDIO_ENCODER: Option<&AudioEncoder> = None; pub trait AudioEncoderExt: 'static { - fn allocate_output_buffer(&self, size: usize) -> Option; + fn allocate_output_buffer(&self, size: usize) -> Result; fn get_audio_info(&self) -> Option; @@ -105,12 +106,13 @@ pub trait AudioEncoderExt: 'static { } impl> AudioEncoderExt for O { - fn allocate_output_buffer(&self, size: usize) -> Option { + fn allocate_output_buffer(&self, size: usize) -> Result { unsafe { - from_glib_full(gst_audio_sys::gst_audio_encoder_allocate_output_buffer( + Option::<_>::from_glib_full(gst_audio_sys::gst_audio_encoder_allocate_output_buffer( self.as_ref().to_glib_none().0, size, )) + .ok_or_else(|| glib_bool_error!("Failed to allocate output buffer")) } } diff --git a/gstreamer-audio/src/auto/versions.txt b/gstreamer-audio/src/auto/versions.txt index bb4ffb804..992f7403f 100644 --- a/gstreamer-audio/src/auto/versions.txt +++ b/gstreamer-audio/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ d1e88f9) -from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) +Generated by gir (https://github.com/gtk-rs/gir @ 5836573) +from gir-files (https://github.com/gtk-rs/gir-files @ c067e63) diff --git a/gstreamer-base/src/adapter.rs b/gstreamer-base/src/adapter.rs index 2e3ecac8f..6a50b5e07 100644 --- a/gstreamer-base/src/adapter.rs +++ b/gstreamer-base/src/adapter.rs @@ -81,7 +81,7 @@ impl UniqueAdapter { self.0.clear(); } - pub fn copy_bytes(&self, offset: usize, size: usize) -> Option { + pub fn copy_bytes(&self, offset: usize, size: usize) -> Result { self.0.copy_bytes(offset, size) } @@ -98,15 +98,15 @@ impl UniqueAdapter { self.0.flush(flush); } - pub fn get_buffer(&self, nbytes: usize) -> Option { + pub fn get_buffer(&self, nbytes: usize) -> Result { self.0.get_buffer(nbytes) } - pub fn get_buffer_fast(&self, nbytes: usize) -> Option { + pub fn get_buffer_fast(&self, nbytes: usize) -> Result { self.0.get_buffer_fast(nbytes) } - pub fn get_buffer_list(&self, nbytes: usize) -> Option { + pub fn get_buffer_list(&self, nbytes: usize) -> Result { self.0.get_buffer_list(nbytes) } @@ -159,15 +159,15 @@ impl UniqueAdapter { self.0.pts_at_discont() } - pub fn take_buffer(&mut self, nbytes: usize) -> Option { + pub fn take_buffer(&mut self, nbytes: usize) -> Result { self.0.take_buffer(nbytes) } - pub fn take_buffer_fast(&mut self, nbytes: usize) -> Option { + pub fn take_buffer_fast(&mut self, nbytes: usize) -> Result { self.0.take_buffer_fast(nbytes) } - pub fn take_buffer_list(&mut self, nbytes: usize) -> Option { + pub fn take_buffer_list(&mut self, nbytes: usize) -> Result { self.0.take_buffer_list(nbytes) } diff --git a/gstreamer-base/src/auto/adapter.rs b/gstreamer-base/src/auto/adapter.rs index a6d67bb87..813455f96 100644 --- a/gstreamer-base/src/auto/adapter.rs +++ b/gstreamer-base/src/auto/adapter.rs @@ -37,13 +37,14 @@ impl Adapter { } } - pub fn copy_bytes(&self, offset: usize, size: usize) -> Option { + pub fn copy_bytes(&self, offset: usize, size: usize) -> Result { unsafe { - from_glib_full(gst_base_sys::gst_adapter_copy_bytes( + Option::<_>::from_glib_full(gst_base_sys::gst_adapter_copy_bytes( self.to_glib_none().0, offset, size, )) + .ok_or_else(|| glib_bool_error!("Failed to copy bytes")) } } @@ -66,30 +67,33 @@ impl Adapter { } } - pub fn get_buffer(&self, nbytes: usize) -> Option { + pub fn get_buffer(&self, nbytes: usize) -> Result { unsafe { - from_glib_full(gst_base_sys::gst_adapter_get_buffer( + Option::<_>::from_glib_full(gst_base_sys::gst_adapter_get_buffer( self.to_glib_none().0, nbytes, )) + .ok_or_else(|| glib_bool_error!("Failed to get buffer")) } } - pub fn get_buffer_fast(&self, nbytes: usize) -> Option { + pub fn get_buffer_fast(&self, nbytes: usize) -> Result { unsafe { - from_glib_full(gst_base_sys::gst_adapter_get_buffer_fast( + Option::<_>::from_glib_full(gst_base_sys::gst_adapter_get_buffer_fast( self.to_glib_none().0, nbytes, )) + .ok_or_else(|| glib_bool_error!("Failed to get buffer")) } } - pub fn get_buffer_list(&self, nbytes: usize) -> Option { + pub fn get_buffer_list(&self, nbytes: usize) -> Result { unsafe { - from_glib_full(gst_base_sys::gst_adapter_get_buffer_list( + Option::<_>::from_glib_full(gst_base_sys::gst_adapter_get_buffer_list( self.to_glib_none().0, nbytes, )) + .ok_or_else(|| glib_bool_error!("Failed to get buffer list")) } } @@ -211,30 +215,33 @@ impl Adapter { } } - pub fn take_buffer(&self, nbytes: usize) -> Option { + pub fn take_buffer(&self, nbytes: usize) -> Result { unsafe { - from_glib_full(gst_base_sys::gst_adapter_take_buffer( + Option::<_>::from_glib_full(gst_base_sys::gst_adapter_take_buffer( self.to_glib_none().0, nbytes, )) + .ok_or_else(|| glib_bool_error!("Failed to take buffer")) } } - pub fn take_buffer_fast(&self, nbytes: usize) -> Option { + pub fn take_buffer_fast(&self, nbytes: usize) -> Result { unsafe { - from_glib_full(gst_base_sys::gst_adapter_take_buffer_fast( + Option::<_>::from_glib_full(gst_base_sys::gst_adapter_take_buffer_fast( self.to_glib_none().0, nbytes, )) + .ok_or_else(|| glib_bool_error!("Failed to take buffer")) } } - pub fn take_buffer_list(&self, nbytes: usize) -> Option { + pub fn take_buffer_list(&self, nbytes: usize) -> Result { unsafe { - from_glib_full(gst_base_sys::gst_adapter_take_buffer_list( + Option::<_>::from_glib_full(gst_base_sys::gst_adapter_take_buffer_list( self.to_glib_none().0, nbytes, )) + .ok_or_else(|| glib_bool_error!("Failed to take buffer list")) } } diff --git a/gstreamer-base/src/auto/base_sink.rs b/gstreamer-base/src/auto/base_sink.rs index 3e40b22da..875ab5c10 100644 --- a/gstreamer-base/src/auto/base_sink.rs +++ b/gstreamer-base/src/auto/base_sink.rs @@ -14,7 +14,6 @@ use gobject_sys; use gst; use gst_base_sys; use std::boxed::Box as Box_; -use std::mem; use std::mem::transmute; glib_wrapper! { @@ -63,8 +62,6 @@ pub trait BaseSinkExt: 'static { fn is_qos_enabled(&self) -> bool; - fn query_latency(&self) -> Option<(bool, bool, gst::ClockTime, gst::ClockTime)>; - fn set_async_enabled(&self, enabled: bool); fn set_blocksize(&self, blocksize: u32); @@ -264,36 +261,6 @@ impl> BaseSinkExt for O { } } - fn query_latency(&self) -> Option<(bool, bool, gst::ClockTime, gst::ClockTime)> { - unsafe { - let mut live = mem::MaybeUninit::uninit(); - let mut upstream_live = mem::MaybeUninit::uninit(); - let mut min_latency = mem::MaybeUninit::uninit(); - let mut max_latency = mem::MaybeUninit::uninit(); - let ret = from_glib(gst_base_sys::gst_base_sink_query_latency( - self.as_ref().to_glib_none().0, - live.as_mut_ptr(), - upstream_live.as_mut_ptr(), - min_latency.as_mut_ptr(), - max_latency.as_mut_ptr(), - )); - let live = live.assume_init(); - let upstream_live = upstream_live.assume_init(); - let min_latency = min_latency.assume_init(); - let max_latency = max_latency.assume_init(); - if ret { - Some(( - from_glib(live), - from_glib(upstream_live), - from_glib(min_latency), - from_glib(max_latency), - )) - } else { - None - } - } - } - fn set_async_enabled(&self, enabled: bool) { unsafe { gst_base_sys::gst_base_sink_set_async_enabled( diff --git a/gstreamer-base/src/auto/base_src.rs b/gstreamer-base/src/auto/base_src.rs index 2f9f4e6cd..98131c1bc 100644 --- a/gstreamer-base/src/auto/base_src.rs +++ b/gstreamer-base/src/auto/base_src.rs @@ -15,7 +15,6 @@ use gobject_sys; use gst; use gst_base_sys; use std::boxed::Box as Box_; -use std::mem; use std::mem::transmute; glib_wrapper! { @@ -46,8 +45,6 @@ pub trait BaseSrcExt: 'static { fn new_seamless_segment(&self, start: i64, stop: i64, time: i64) -> bool; - fn query_latency(&self) -> Option<(bool, gst::ClockTime, gst::ClockTime)>; - fn set_async(&self, async: bool); fn set_automatic_eos(&self, automatic_eos: bool); @@ -145,32 +142,6 @@ impl> BaseSrcExt for O { } } - fn query_latency(&self) -> Option<(bool, gst::ClockTime, gst::ClockTime)> { - unsafe { - let mut live = mem::MaybeUninit::uninit(); - let mut min_latency = mem::MaybeUninit::uninit(); - let mut max_latency = mem::MaybeUninit::uninit(); - let ret = from_glib(gst_base_sys::gst_base_src_query_latency( - self.as_ref().to_glib_none().0, - live.as_mut_ptr(), - min_latency.as_mut_ptr(), - max_latency.as_mut_ptr(), - )); - let live = live.assume_init(); - let min_latency = min_latency.assume_init(); - let max_latency = max_latency.assume_init(); - if ret { - Some(( - from_glib(live), - from_glib(min_latency), - from_glib(max_latency), - )) - } else { - None - } - } - } - fn set_async(&self, async: bool) { unsafe { gst_base_sys::gst_base_src_set_async(self.as_ref().to_glib_none().0, async.to_glib()); diff --git a/gstreamer-base/src/auto/functions.rs b/gstreamer-base/src/auto/functions.rs index 01236d5fe..b71e92d5a 100644 --- a/gstreamer-base/src/auto/functions.rs +++ b/gstreamer-base/src/auto/functions.rs @@ -2,31 +2,37 @@ // from gir-files (https://github.com/gtk-rs/gir-files) // DO NOT EDIT +use glib; use glib::object::IsA; use glib::translate::*; use gst; use gst_base_sys; -pub fn type_find_helper>(src: &P, size: u64) -> Option { +pub fn type_find_helper>( + src: &P, + size: u64, +) -> Result { assert_initialized_main_thread!(); unsafe { - from_glib_full(gst_base_sys::gst_type_find_helper( + Option::<_>::from_glib_full(gst_base_sys::gst_type_find_helper( src.as_ref().to_glib_none().0, size, )) + .ok_or_else(|| glib_bool_error!("Could not find type")) } } pub fn type_find_helper_for_extension>( obj: Option<&P>, extension: &str, -) -> Option { +) -> Result { assert_initialized_main_thread!(); unsafe { - from_glib_full(gst_base_sys::gst_type_find_helper_for_extension( + Option::<_>::from_glib_full(gst_base_sys::gst_type_find_helper_for_extension( obj.map(|p| p.as_ref()).to_glib_none().0, extension.to_glib_none().0, )) + .ok_or_else(|| glib_bool_error!("Could not find type")) } } diff --git a/gstreamer-base/src/auto/versions.txt b/gstreamer-base/src/auto/versions.txt index bb4ffb804..992f7403f 100644 --- a/gstreamer-base/src/auto/versions.txt +++ b/gstreamer-base/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ d1e88f9) -from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) +Generated by gir (https://github.com/gtk-rs/gir @ 5836573) +from gir-files (https://github.com/gtk-rs/gir-files @ c067e63) diff --git a/gstreamer-base/src/base_sink.rs b/gstreamer-base/src/base_sink.rs index 1f1c57053..8eed32cfe 100644 --- a/gstreamer-base/src/base_sink.rs +++ b/gstreamer-base/src/base_sink.rs @@ -10,6 +10,7 @@ use glib::object::IsA; use glib::translate::*; use gst; use gst_base_sys; +use std::mem; use BaseSink; pub trait BaseSinkExtManual: 'static { @@ -28,6 +29,10 @@ pub trait BaseSinkExtManual: 'static { Result, gst::ClockTimeDiff, ); + + fn query_latency( + &self, + ) -> Result<(bool, bool, gst::ClockTime, gst::ClockTime), glib::BoolError>; } impl> BaseSinkExtManual for O { @@ -80,4 +85,36 @@ impl> BaseSinkExtManual for O { (ret.into_result(), jitter) } } + + fn query_latency( + &self, + ) -> Result<(bool, bool, gst::ClockTime, gst::ClockTime), glib::BoolError> { + unsafe { + let mut live = mem::MaybeUninit::uninit(); + let mut upstream_live = mem::MaybeUninit::uninit(); + let mut min_latency = mem::MaybeUninit::uninit(); + let mut max_latency = mem::MaybeUninit::uninit(); + let ret = from_glib(gst_base_sys::gst_base_sink_query_latency( + self.as_ref().to_glib_none().0, + live.as_mut_ptr(), + upstream_live.as_mut_ptr(), + min_latency.as_mut_ptr(), + max_latency.as_mut_ptr(), + )); + let live = live.assume_init(); + let upstream_live = upstream_live.assume_init(); + let min_latency = min_latency.assume_init(); + let max_latency = max_latency.assume_init(); + if ret { + Ok(( + from_glib(live), + from_glib(upstream_live), + from_glib(min_latency), + from_glib(max_latency), + )) + } else { + Err(glib_bool_error!("Failed to query latency")) + } + } + } } diff --git a/gstreamer-base/src/base_src.rs b/gstreamer-base/src/base_src.rs index b39a0fd0b..506eb7fdf 100644 --- a/gstreamer-base/src/base_src.rs +++ b/gstreamer-base/src/base_src.rs @@ -10,6 +10,7 @@ use glib::object::IsA; use glib::translate::*; use gst; use gst_base_sys; +use std::mem; use BaseSrc; pub trait BaseSrcExtManual: 'static { @@ -20,6 +21,8 @@ pub trait BaseSrcExtManual: 'static { fn start_wait(&self) -> Result; fn wait_playing(&self) -> Result; + + fn query_latency(&self) -> Result<(bool, gst::ClockTime, gst::ClockTime), glib::BoolError>; } impl> BaseSrcExtManual for O { @@ -58,4 +61,30 @@ impl> BaseSrcExtManual for O { }; ret.into_result() } + + fn query_latency(&self) -> Result<(bool, gst::ClockTime, gst::ClockTime), glib::BoolError> { + unsafe { + let mut live = mem::MaybeUninit::uninit(); + let mut min_latency = mem::MaybeUninit::uninit(); + let mut max_latency = mem::MaybeUninit::uninit(); + let ret = from_glib(gst_base_sys::gst_base_src_query_latency( + self.as_ref().to_glib_none().0, + live.as_mut_ptr(), + min_latency.as_mut_ptr(), + max_latency.as_mut_ptr(), + )); + let live = live.assume_init(); + let min_latency = min_latency.assume_init(); + let max_latency = max_latency.assume_init(); + if ret { + Ok(( + from_glib(live), + from_glib(min_latency), + from_glib(max_latency), + )) + } else { + Err(glib_bool_error!("Failed to query latency")) + } + } + } } diff --git a/gstreamer-check/src/auto/versions.txt b/gstreamer-check/src/auto/versions.txt index bb4ffb804..992f7403f 100644 --- a/gstreamer-check/src/auto/versions.txt +++ b/gstreamer-check/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ d1e88f9) -from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) +Generated by gir (https://github.com/gtk-rs/gir @ 5836573) +from gir-files (https://github.com/gtk-rs/gir-files @ c067e63) diff --git a/gstreamer-check/src/harness.rs b/gstreamer-check/src/harness.rs index 3dbe131cc..936326066 100644 --- a/gstreamer-check/src/harness.rs +++ b/gstreamer-check/src/harness.rs @@ -197,12 +197,13 @@ impl Harness { } } - pub fn create_buffer(&mut self, size: usize) -> Option { + pub fn create_buffer(&mut self, size: usize) -> Result { unsafe { - from_glib_full(gst_check_sys::gst_harness_create_buffer( + Option::<_>::from_glib_full(gst_check_sys::gst_harness_create_buffer( self.0.as_ptr(), size, )) + .ok_or_else(|| glib_bool_error!("Failed to create new buffer")) } } @@ -268,19 +269,26 @@ impl Harness { } } - pub fn pull(&mut self) -> Option { - unsafe { from_glib_full(gst_check_sys::gst_harness_pull(self.0.as_ptr())) } - } - - pub fn pull_event(&mut self) -> Option { - unsafe { from_glib_full(gst_check_sys::gst_harness_pull_event(self.0.as_ptr())) } - } - - pub fn pull_upstream_event(&mut self) -> Option { + pub fn pull(&mut self) -> Result { unsafe { - from_glib_full(gst_check_sys::gst_harness_pull_upstream_event( + Option::<_>::from_glib_full(gst_check_sys::gst_harness_pull(self.0.as_ptr())) + .ok_or_else(|| glib_bool_error!("Failed to pull buffer")) + } + } + + pub fn pull_event(&mut self) -> Result { + unsafe { + Option::<_>::from_glib_full(gst_check_sys::gst_harness_pull_event(self.0.as_ptr())) + .ok_or_else(|| glib_bool_error!("Failed to pull event")) + } + } + + pub fn pull_upstream_event(&mut self) -> Result { + unsafe { + Option::<_>::from_glib_full(gst_check_sys::gst_harness_pull_upstream_event( self.0.as_ptr(), )) + .ok_or_else(|| glib_bool_error!("Failed to pull event")) } } @@ -294,12 +302,13 @@ impl Harness { ret.into_result() } - pub fn push_and_pull(&mut self, buffer: gst::Buffer) -> Option { + pub fn push_and_pull(&mut self, buffer: gst::Buffer) -> Result { unsafe { - from_glib_full(gst_check_sys::gst_harness_push_and_pull( + Option::<_>::from_glib_full(gst_check_sys::gst_harness_push_and_pull( self.0.as_ptr(), buffer.into_ptr(), )) + .ok_or_else(|| glib_bool_error!("Failed to push and pull buffer")) } } @@ -488,20 +497,22 @@ impl Harness { //} #[cfg(any(feature = "v1_14", feature = "dox"))] - pub fn take_all_data_as_buffer(&mut self) -> Option { + pub fn take_all_data_as_buffer(&mut self) -> Result { unsafe { - from_glib_full(gst_check_sys::gst_harness_take_all_data_as_buffer( + Option::<_>::from_glib_full(gst_check_sys::gst_harness_take_all_data_as_buffer( self.0.as_ptr(), )) + .ok_or_else(|| glib_bool_error!("Failed to take all data as buffer")) } } #[cfg(any(feature = "v1_14", feature = "dox"))] - pub fn take_all_data_as_bytes(&mut self) -> Option { + pub fn take_all_data_as_bytes(&mut self) -> Result { unsafe { - from_glib_full(gst_check_sys::gst_harness_take_all_data_as_bytes( + Option::<_>::from_glib_full(gst_check_sys::gst_harness_take_all_data_as_bytes( self.0.as_ptr(), )) + .ok_or_else(|| glib_bool_error!("Failed to take all data as bytes")) } } @@ -837,6 +848,6 @@ mod tests { h.set_src_caps_str("application/test"); let buf = gst::Buffer::new(); let buf = h.push_and_pull(buf); - assert!(buf.is_some()); + assert!(buf.is_ok()); } } diff --git a/gstreamer-editing-services/src/auto/clip.rs b/gstreamer-editing-services/src/auto/clip.rs index 5e1f9db53..e58b48765 100644 --- a/gstreamer-editing-services/src/auto/clip.rs +++ b/gstreamer-editing-services/src/auto/clip.rs @@ -33,7 +33,7 @@ glib_wrapper! { pub const NONE_CLIP: Option<&Clip> = None; pub trait ClipExt: 'static { - fn add_asset>(&self, asset: &P) -> Option; + fn add_asset>(&self, asset: &P) -> Result; fn find_track_element>( &self, @@ -74,7 +74,7 @@ pub trait ClipExt: 'static { newpriority: u32, ) -> Result<(), glib::error::BoolError>; - fn split(&self, position: u64) -> Option; + fn split(&self, position: u64) -> Result; fn connect_property_layer_notify(&self, f: F) -> SignalHandlerId; @@ -85,12 +85,13 @@ pub trait ClipExt: 'static { } impl> ClipExt for O { - fn add_asset>(&self, asset: &P) -> Option { + fn add_asset>(&self, asset: &P) -> Result { unsafe { - from_glib_none(ges_sys::ges_clip_add_asset( + Option::<_>::from_glib_none(ges_sys::ges_clip_add_asset( self.as_ref().to_glib_none().0, asset.as_ref().to_glib_none().0, )) + .ok_or_else(|| glib_bool_error!("Failed to add asset")) } } @@ -217,12 +218,13 @@ impl> ClipExt for O { } } - fn split(&self, position: u64) -> Option { + fn split(&self, position: u64) -> Result { unsafe { - from_glib_none(ges_sys::ges_clip_split( + Option::<_>::from_glib_none(ges_sys::ges_clip_split( self.as_ref().to_glib_none().0, position, )) + .ok_or_else(|| glib_bool_error!("Failed to split clip")) } } diff --git a/gstreamer-editing-services/src/auto/effect.rs b/gstreamer-editing-services/src/auto/effect.rs index 6863474f5..644d3fa10 100644 --- a/gstreamer-editing-services/src/auto/effect.rs +++ b/gstreamer-editing-services/src/auto/effect.rs @@ -3,6 +3,7 @@ // DO NOT EDIT use ges_sys; +use glib; use glib::object::IsA; use glib::translate::*; use glib::GString; @@ -23,9 +24,12 @@ glib_wrapper! { } impl Effect { - pub fn new(bin_description: &str) -> Option { + pub fn new(bin_description: &str) -> Result { assert_initialized_main_thread!(); - unsafe { from_glib_none(ges_sys::ges_effect_new(bin_description.to_glib_none().0)) } + unsafe { + Option::<_>::from_glib_none(ges_sys::ges_effect_new(bin_description.to_glib_none().0)) + .ok_or_else(|| glib_bool_error!("Failed to create effect from description")) + } } } diff --git a/gstreamer-editing-services/src/auto/layer.rs b/gstreamer-editing-services/src/auto/layer.rs index 846080802..b080fe989 100644 --- a/gstreamer-editing-services/src/auto/layer.rs +++ b/gstreamer-editing-services/src/auto/layer.rs @@ -50,7 +50,7 @@ pub trait LayerExt: 'static { inpoint: gst::ClockTime, duration: gst::ClockTime, track_types: TrackType, - ) -> Option; + ) -> Result; fn add_clip>(&self, clip: &P) -> Result<(), glib::error::BoolError>; @@ -98,9 +98,9 @@ impl> LayerExt for O { inpoint: gst::ClockTime, duration: gst::ClockTime, track_types: TrackType, - ) -> Option { + ) -> Result { unsafe { - from_glib_none(ges_sys::ges_layer_add_asset( + Option::<_>::from_glib_none(ges_sys::ges_layer_add_asset( self.as_ref().to_glib_none().0, asset.as_ref().to_glib_none().0, start.to_glib(), @@ -108,6 +108,7 @@ impl> LayerExt for O { duration.to_glib(), track_types.to_glib(), )) + .ok_or_else(|| glib_bool_error!("Failed to add asset")) } } diff --git a/gstreamer-editing-services/src/auto/timeline_element.rs b/gstreamer-editing-services/src/auto/timeline_element.rs index 3e4a1998f..4ec96fb40 100644 --- a/gstreamer-editing-services/src/auto/timeline_element.rs +++ b/gstreamer-editing-services/src/auto/timeline_element.rs @@ -34,7 +34,7 @@ pub const NONE_TIMELINE_ELEMENT: Option<&TimelineElement> = None; pub trait TimelineElementExt: 'static { //fn add_child_property>(&self, pspec: /*Ignored*/&glib::ParamSpec, child: &P) -> bool; - fn copy(&self, deep: bool) -> Option; + fn copy(&self, deep: bool) -> Result; //fn get_child_properties(&self, first_property_name: &str, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs); @@ -71,7 +71,7 @@ pub trait TimelineElementExt: 'static { //fn lookup_child(&self, prop_name: &str, pspec: /*Ignored*/glib::ParamSpec) -> Option; - fn paste(&self, paste_position: gst::ClockTime) -> Option; + fn paste(&self, paste_position: gst::ClockTime) -> Result; //fn remove_child_property(&self, pspec: /*Ignored*/&glib::ParamSpec) -> bool; @@ -145,12 +145,13 @@ impl> TimelineElementExt for O { // unsafe { TODO: call ges_sys:ges_timeline_element_add_child_property() } //} - fn copy(&self, deep: bool) -> Option { + fn copy(&self, deep: bool) -> Result { unsafe { - from_glib_none(ges_sys::ges_timeline_element_copy( + Option::<_>::from_glib_none(ges_sys::ges_timeline_element_copy( self.as_ref().to_glib_none().0, deep.to_glib(), )) + .ok_or_else(|| glib_bool_error!("Failed to copy timeline element")) } } @@ -259,12 +260,13 @@ impl> TimelineElementExt for O { // unsafe { TODO: call ges_sys:ges_timeline_element_lookup_child() } //} - fn paste(&self, paste_position: gst::ClockTime) -> Option { + fn paste(&self, paste_position: gst::ClockTime) -> Result { unsafe { - from_glib_full(ges_sys::ges_timeline_element_paste( + Option::<_>::from_glib_full(ges_sys::ges_timeline_element_paste( self.as_ref().to_glib_none().0, paste_position.to_glib(), )) + .ok_or_else(|| glib_bool_error!("Failed to paste timeline element")) } } @@ -424,7 +426,7 @@ impl> TimelineElementExt for O { unsafe { glib_result_from_gboolean!( ges_sys::ges_timeline_element_trim(self.as_ref().to_glib_none().0, start.to_glib()), - "`Failed to trim" + "Failed to trim" ) } } diff --git a/gstreamer-editing-services/src/auto/uri_clip.rs b/gstreamer-editing-services/src/auto/uri_clip.rs index cd87d9948..b065951fe 100644 --- a/gstreamer-editing-services/src/auto/uri_clip.rs +++ b/gstreamer-editing-services/src/auto/uri_clip.rs @@ -3,6 +3,7 @@ // DO NOT EDIT use ges_sys; +use glib; use glib::object::Cast; use glib::object::IsA; use glib::signal::connect_raw; @@ -29,9 +30,12 @@ glib_wrapper! { } impl UriClip { - pub fn new(uri: &str) -> Option { + pub fn new(uri: &str) -> Result { assert_initialized_main_thread!(); - unsafe { from_glib_none(ges_sys::ges_uri_clip_new(uri.to_glib_none().0)) } + unsafe { + Option::<_>::from_glib_none(ges_sys::ges_uri_clip_new(uri.to_glib_none().0)) + .ok_or_else(|| glib_bool_error!("Failed to create Uri clip from Uri")) + } } } diff --git a/gstreamer-editing-services/src/auto/versions.txt b/gstreamer-editing-services/src/auto/versions.txt index bb4ffb804..992f7403f 100644 --- a/gstreamer-editing-services/src/auto/versions.txt +++ b/gstreamer-editing-services/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ d1e88f9) -from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) +Generated by gir (https://github.com/gtk-rs/gir @ 5836573) +from gir-files (https://github.com/gtk-rs/gir-files @ c067e63) diff --git a/gstreamer-gl/src/auto/gl_display.rs b/gstreamer-gl/src/auto/gl_display.rs index 3a457a2ec..0be40a3c8 100644 --- a/gstreamer-gl/src/auto/gl_display.rs +++ b/gstreamer-gl/src/auto/gl_display.rs @@ -53,7 +53,7 @@ pub trait GLDisplayExt: 'static { other_context: &P, ) -> Result; - fn create_window(&self) -> Option; + fn create_window(&self) -> Result; fn filter_gl_api(&self, gl_api: GLAPI); @@ -105,11 +105,12 @@ impl> GLDisplayExt for O { } } - fn create_window(&self) -> Option { + fn create_window(&self) -> Result { unsafe { - from_glib_full(gst_gl_sys::gst_gl_display_create_window( + Option::<_>::from_glib_full(gst_gl_sys::gst_gl_display_create_window( self.as_ref().to_glib_none().0, )) + .ok_or_else(|| glib_bool_error!("Failed to create window")) } } diff --git a/gstreamer-gl/src/auto/versions.txt b/gstreamer-gl/src/auto/versions.txt index bb4ffb804..992f7403f 100644 --- a/gstreamer-gl/src/auto/versions.txt +++ b/gstreamer-gl/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ d1e88f9) -from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) +Generated by gir (https://github.com/gtk-rs/gir @ 5836573) +from gir-files (https://github.com/gtk-rs/gir-files @ c067e63) diff --git a/gstreamer-gl/src/gl_video_frame.rs b/gstreamer-gl/src/gl_video_frame.rs index 08085b8c1..e25de9659 100644 --- a/gstreamer-gl/src/gl_video_frame.rs +++ b/gstreamer-gl/src/gl_video_frame.rs @@ -145,7 +145,7 @@ impl<'a> VideoFrameGLExt for VideoFrameRef<&'a gst::BufferRef> { return None; } - let mut data = self.plane_data(idx)?; + let mut data = self.plane_data(idx).ok()?; let id = &data.read_u32::().ok()?; Some(*id) diff --git a/gstreamer-net/src/auto/versions.txt b/gstreamer-net/src/auto/versions.txt index bb4ffb804..992f7403f 100644 --- a/gstreamer-net/src/auto/versions.txt +++ b/gstreamer-net/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ d1e88f9) -from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) +Generated by gir (https://github.com/gtk-rs/gir @ 5836573) +from gir-files (https://github.com/gtk-rs/gir-files @ c067e63) diff --git a/gstreamer-pbutils/src/auto/discoverer_info.rs b/gstreamer-pbutils/src/auto/discoverer_info.rs index cbfcfd989..6d456baed 100644 --- a/gstreamer-pbutils/src/auto/discoverer_info.rs +++ b/gstreamer-pbutils/src/auto/discoverer_info.rs @@ -160,21 +160,26 @@ impl DiscovererInfo { } } - pub fn to_variant(&self, flags: DiscovererSerializeFlags) -> Option { + pub fn to_variant( + &self, + flags: DiscovererSerializeFlags, + ) -> Result { unsafe { - from_glib_full(gst_pbutils_sys::gst_discoverer_info_to_variant( + Option::<_>::from_glib_full(gst_pbutils_sys::gst_discoverer_info_to_variant( self.to_glib_none().0, flags.to_glib(), )) + .ok_or_else(|| glib_bool_error!("Failed to serialize DiscovererInfo to Variant")) } } - pub fn from_variant(variant: &glib::Variant) -> Option { + pub fn from_variant(variant: &glib::Variant) -> Result { assert_initialized_main_thread!(); unsafe { - from_glib_full(gst_pbutils_sys::gst_discoverer_info_from_variant( + Option::<_>::from_glib_full(gst_pbutils_sys::gst_discoverer_info_from_variant( variant.to_glib_none().0, )) + .ok_or_else(|| glib_bool_error!("Failed to deserialize DiscovererInfo from Variant")) } } } diff --git a/gstreamer-pbutils/src/auto/encoding_profile.rs b/gstreamer-pbutils/src/auto/encoding_profile.rs index 26abc86a3..2d8d9e40c 100644 --- a/gstreamer-pbutils/src/auto/encoding_profile.rs +++ b/gstreamer-pbutils/src/auto/encoding_profile.rs @@ -2,6 +2,7 @@ // from gir-files (https://github.com/gtk-rs/gir-files) // DO NOT EDIT +use glib; use glib::object::IsA; use glib::translate::*; use glib::GString; @@ -33,12 +34,13 @@ impl EncodingProfile { } } - pub fn from_discoverer(info: &DiscovererInfo) -> Option { + pub fn from_discoverer(info: &DiscovererInfo) -> Result { skip_assert_initialized!(); unsafe { - from_glib_full(gst_pbutils_sys::gst_encoding_profile_from_discoverer( + Option::<_>::from_glib_full(gst_pbutils_sys::gst_encoding_profile_from_discoverer( info.to_glib_none().0, )) + .ok_or_else(|| glib_bool_error!("Failed to create EncodingProfile from DiscovererInfo")) } } } diff --git a/gstreamer-pbutils/src/auto/functions.rs b/gstreamer-pbutils/src/auto/functions.rs index e46f9cf11..ba43ec69a 100644 --- a/gstreamer-pbutils/src/auto/functions.rs +++ b/gstreamer-pbutils/src/auto/functions.rs @@ -2,6 +2,7 @@ // from gir-files (https://github.com/gtk-rs/gir-files) // DO NOT EDIT +use glib; use glib::translate::*; use glib::GString; use gst_pbutils_sys; @@ -26,30 +27,33 @@ pub fn encoding_list_available_categories() -> Vec { } } -pub fn pb_utils_get_element_description(factory_name: &str) -> Option { +pub fn pb_utils_get_element_description(factory_name: &str) -> Result { assert_initialized_main_thread!(); unsafe { - from_glib_full(gst_pbutils_sys::gst_pb_utils_get_element_description( + Option::<_>::from_glib_full(gst_pbutils_sys::gst_pb_utils_get_element_description( factory_name.to_glib_none().0, )) + .ok_or_else(|| glib_bool_error!("Failed to get element description")) } } -pub fn pb_utils_get_sink_description(protocol: &str) -> Option { +pub fn pb_utils_get_sink_description(protocol: &str) -> Result { assert_initialized_main_thread!(); unsafe { - from_glib_full(gst_pbutils_sys::gst_pb_utils_get_sink_description( + Option::<_>::from_glib_full(gst_pbutils_sys::gst_pb_utils_get_sink_description( protocol.to_glib_none().0, )) + .ok_or_else(|| glib_bool_error!("Failed to get sink description")) } } -pub fn pb_utils_get_source_description(protocol: &str) -> Option { +pub fn pb_utils_get_source_description(protocol: &str) -> Result { assert_initialized_main_thread!(); unsafe { - from_glib_full(gst_pbutils_sys::gst_pb_utils_get_source_description( + Option::<_>::from_glib_full(gst_pbutils_sys::gst_pb_utils_get_source_description( protocol.to_glib_none().0, )) + .ok_or_else(|| glib_bool_error!("Failed to get source description")) } } @@ -74,7 +78,7 @@ pub fn plugins_base_version() -> (u32, u32, u32, u32) { } } -pub fn plugins_base_version_string() -> Option { +pub fn plugins_base_version_string() -> GString { assert_initialized_main_thread!(); unsafe { from_glib_full(gst_pbutils_sys::gst_plugins_base_version_string()) } } diff --git a/gstreamer-pbutils/src/auto/versions.txt b/gstreamer-pbutils/src/auto/versions.txt index bb4ffb804..992f7403f 100644 --- a/gstreamer-pbutils/src/auto/versions.txt +++ b/gstreamer-pbutils/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ d1e88f9) -from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) +Generated by gir (https://github.com/gtk-rs/gir @ 5836573) +from gir-files (https://github.com/gtk-rs/gir-files @ c067e63) diff --git a/gstreamer-player/src/auto/versions.txt b/gstreamer-player/src/auto/versions.txt index bb4ffb804..992f7403f 100644 --- a/gstreamer-player/src/auto/versions.txt +++ b/gstreamer-player/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ d1e88f9) -from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) +Generated by gir (https://github.com/gtk-rs/gir @ 5836573) +from gir-files (https://github.com/gtk-rs/gir-files @ c067e63) diff --git a/gstreamer-rtp/src/auto/versions.txt b/gstreamer-rtp/src/auto/versions.txt index bb4ffb804..992f7403f 100644 --- a/gstreamer-rtp/src/auto/versions.txt +++ b/gstreamer-rtp/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ d1e88f9) -from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) +Generated by gir (https://github.com/gtk-rs/gir @ 5836573) +from gir-files (https://github.com/gtk-rs/gir-files @ c067e63) diff --git a/gstreamer-rtp/src/rtp_buffer.rs b/gstreamer-rtp/src/rtp_buffer.rs index 2bd15510d..0baa24375 100644 --- a/gstreamer-rtp/src/rtp_buffer.rs +++ b/gstreamer-rtp/src/rtp_buffer.rs @@ -1,4 +1,4 @@ -use glib::translate::{from_glib, from_glib_full}; +use glib::translate::{from_glib, FromGlibPtrFull}; use std::marker::PhantomData; use std::mem; @@ -94,17 +94,26 @@ impl<'a, T> Drop for RTPBuffer<'a, T> { } pub trait RTPBufferExt { - fn new_rtp_with_sizes(payload_len: u32, pad_len: u8, csrc_count: u8) -> Option; + fn new_rtp_with_sizes( + payload_len: u32, + pad_len: u8, + csrc_count: u8, + ) -> Result; } impl RTPBufferExt for gst::Buffer { - fn new_rtp_with_sizes(payload_len: u32, pad_len: u8, csrc_count: u8) -> Option { + fn new_rtp_with_sizes( + payload_len: u32, + pad_len: u8, + csrc_count: u8, + ) -> Result { unsafe { - from_glib_full(gst_rtp_sys::gst_rtp_buffer_new_allocate( + Option::<_>::from_glib_full(gst_rtp_sys::gst_rtp_buffer_new_allocate( payload_len, pad_len, csrc_count, )) + .ok_or_else(|| glib_bool_error!("Failed to allocate new RTP buffer")) } } } diff --git a/gstreamer-rtsp-server/src/auto/rtsp_address_pool.rs b/gstreamer-rtsp-server/src/auto/rtsp_address_pool.rs index e44a857e0..02ceee5f3 100644 --- a/gstreamer-rtsp-server/src/auto/rtsp_address_pool.rs +++ b/gstreamer-rtsp-server/src/auto/rtsp_address_pool.rs @@ -36,7 +36,11 @@ unsafe impl Sync for RTSPAddressPool {} pub const NONE_RTSP_ADDRESS_POOL: Option<&RTSPAddressPool> = None; pub trait RTSPAddressPoolExt: 'static { - fn acquire_address(&self, flags: RTSPAddressFlags, n_ports: i32) -> Option; + fn acquire_address( + &self, + flags: RTSPAddressFlags, + n_ports: i32, + ) -> Result; fn add_range( &self, @@ -55,13 +59,18 @@ pub trait RTSPAddressPoolExt: 'static { } impl> RTSPAddressPoolExt for O { - fn acquire_address(&self, flags: RTSPAddressFlags, n_ports: i32) -> Option { + fn acquire_address( + &self, + flags: RTSPAddressFlags, + n_ports: i32, + ) -> Result { unsafe { - from_glib_full(gst_rtsp_server_sys::gst_rtsp_address_pool_acquire_address( + Option::<_>::from_glib_full(gst_rtsp_server_sys::gst_rtsp_address_pool_acquire_address( self.as_ref().to_glib_none().0, flags.to_glib(), n_ports, )) + .ok_or_else(|| glib_bool_error!("Failed to acquire address")) } } diff --git a/gstreamer-rtsp-server/src/auto/rtsp_media_factory.rs b/gstreamer-rtsp-server/src/auto/rtsp_media_factory.rs index af3cf9dfa..a43ff5531 100644 --- a/gstreamer-rtsp-server/src/auto/rtsp_media_factory.rs +++ b/gstreamer-rtsp-server/src/auto/rtsp_media_factory.rs @@ -53,9 +53,9 @@ pub const NONE_RTSP_MEDIA_FACTORY: Option<&RTSPMediaFactory> = None; pub trait RTSPMediaFactoryExt: 'static { //fn add_role(&self, role: &str, fieldname: &str, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs); - fn construct(&self, url: &gst_rtsp::RTSPUrl) -> Option; + fn construct(&self, url: &gst_rtsp::RTSPUrl) -> Result; - fn create_element(&self, url: &gst_rtsp::RTSPUrl) -> Option; + fn create_element(&self, url: &gst_rtsp::RTSPUrl) -> Result; fn get_address_pool(&self) -> Option; @@ -238,21 +238,23 @@ impl> RTSPMediaFactoryExt for O { // unsafe { TODO: call gst_rtsp_server_sys:gst_rtsp_media_factory_add_role() } //} - fn construct(&self, url: &gst_rtsp::RTSPUrl) -> Option { + fn construct(&self, url: &gst_rtsp::RTSPUrl) -> Result { unsafe { - from_glib_full(gst_rtsp_server_sys::gst_rtsp_media_factory_construct( + Option::<_>::from_glib_full(gst_rtsp_server_sys::gst_rtsp_media_factory_construct( self.as_ref().to_glib_none().0, url.to_glib_none().0, )) + .ok_or_else(|| glib_bool_error!("Failed to construct media")) } } - fn create_element(&self, url: &gst_rtsp::RTSPUrl) -> Option { + fn create_element(&self, url: &gst_rtsp::RTSPUrl) -> Result { unsafe { - from_glib_none(gst_rtsp_server_sys::gst_rtsp_media_factory_create_element( + Option::<_>::from_glib_none(gst_rtsp_server_sys::gst_rtsp_media_factory_create_element( self.as_ref().to_glib_none().0, url.to_glib_none().0, )) + .ok_or_else(|| glib_bool_error!("Failed to create media element")) } } diff --git a/gstreamer-rtsp-server/src/auto/rtsp_mount_points.rs b/gstreamer-rtsp-server/src/auto/rtsp_mount_points.rs index f3054e7ae..30134be34 100644 --- a/gstreamer-rtsp-server/src/auto/rtsp_mount_points.rs +++ b/gstreamer-rtsp-server/src/auto/rtsp_mount_points.rs @@ -2,6 +2,7 @@ // from gir-files (https://github.com/gtk-rs/gir-files) // DO NOT EDIT +use glib; use glib::object::IsA; use glib::translate::*; use glib::GString; @@ -39,7 +40,7 @@ pub const NONE_RTSP_MOUNT_POINTS: Option<&RTSPMountPoints> = None; pub trait RTSPMountPointsExt: 'static { fn add_factory>(&self, path: &str, factory: &P); - fn make_path(&self, url: &gst_rtsp::RTSPUrl) -> Option; + fn make_path(&self, url: &gst_rtsp::RTSPUrl) -> Result; fn match_(&self, path: &str) -> (RTSPMediaFactory, i32); @@ -57,12 +58,13 @@ impl> RTSPMountPointsExt for O { } } - fn make_path(&self, url: &gst_rtsp::RTSPUrl) -> Option { + fn make_path(&self, url: &gst_rtsp::RTSPUrl) -> Result { unsafe { - from_glib_full(gst_rtsp_server_sys::gst_rtsp_mount_points_make_path( + Option::<_>::from_glib_full(gst_rtsp_server_sys::gst_rtsp_mount_points_make_path( self.as_ref().to_glib_none().0, url.to_glib_none().0, )) + .ok_or_else(|| glib_bool_error!("Failed to make path")) } } diff --git a/gstreamer-rtsp-server/src/auto/rtsp_session.rs b/gstreamer-rtsp-server/src/auto/rtsp_session.rs index 3282c8816..e42ded414 100644 --- a/gstreamer-rtsp-server/src/auto/rtsp_session.rs +++ b/gstreamer-rtsp-server/src/auto/rtsp_session.rs @@ -2,6 +2,7 @@ // from gir-files (https://github.com/gtk-rs/gir-files) // DO NOT EDIT +use glib; use glib::object::Cast; use glib::object::IsA; use glib::signal::connect_raw; @@ -64,7 +65,11 @@ pub trait RTSPSessionExt: 'static { fn is_expired_usec(&self, now: i64) -> bool; - fn manage_media>(&self, path: &str, media: &P) -> Option; + fn manage_media>( + &self, + path: &str, + media: &P, + ) -> Result; //fn next_timeout(&self, now: /*Ignored*/&mut glib::TimeVal) -> i32; @@ -190,13 +195,18 @@ impl> RTSPSessionExt for O { } } - fn manage_media>(&self, path: &str, media: &P) -> Option { + fn manage_media>( + &self, + path: &str, + media: &P, + ) -> Result { unsafe { - from_glib_none(gst_rtsp_server_sys::gst_rtsp_session_manage_media( + Option::<_>::from_glib_none(gst_rtsp_server_sys::gst_rtsp_session_manage_media( self.as_ref().to_glib_none().0, path.to_glib_none().0, media.as_ref().to_glib_full(), )) + .ok_or_else(|| glib_bool_error!("Failed to manage media")) } } diff --git a/gstreamer-rtsp-server/src/auto/rtsp_session_pool.rs b/gstreamer-rtsp-server/src/auto/rtsp_session_pool.rs index de590816a..151396b2a 100644 --- a/gstreamer-rtsp-server/src/auto/rtsp_session_pool.rs +++ b/gstreamer-rtsp-server/src/auto/rtsp_session_pool.rs @@ -44,7 +44,7 @@ pub const NONE_RTSP_SESSION_POOL: Option<&RTSPSessionPool> = None; pub trait RTSPSessionPoolExt: 'static { fn cleanup(&self) -> u32; - fn create(&self) -> Option; + fn create(&self) -> Result; fn filter( &self, @@ -79,11 +79,12 @@ impl> RTSPSessionPoolExt for O { } } - fn create(&self) -> Option { + fn create(&self) -> Result { unsafe { - from_glib_full(gst_rtsp_server_sys::gst_rtsp_session_pool_create( + Option::<_>::from_glib_full(gst_rtsp_server_sys::gst_rtsp_session_pool_create( self.as_ref().to_glib_none().0, )) + .ok_or_else(|| glib_bool_error!("Failed to create session pool")) } } diff --git a/gstreamer-rtsp-server/src/auto/versions.txt b/gstreamer-rtsp-server/src/auto/versions.txt index bb4ffb804..992f7403f 100644 --- a/gstreamer-rtsp-server/src/auto/versions.txt +++ b/gstreamer-rtsp-server/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ d1e88f9) -from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) +Generated by gir (https://github.com/gtk-rs/gir @ 5836573) +from gir-files (https://github.com/gtk-rs/gir-files @ c067e63) diff --git a/gstreamer-rtsp/src/auto/versions.txt b/gstreamer-rtsp/src/auto/versions.txt index bb4ffb804..992f7403f 100644 --- a/gstreamer-rtsp/src/auto/versions.txt +++ b/gstreamer-rtsp/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ d1e88f9) -from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) +Generated by gir (https://github.com/gtk-rs/gir @ 5836573) +from gir-files (https://github.com/gtk-rs/gir-files @ c067e63) diff --git a/gstreamer-sdp/src/auto/versions.txt b/gstreamer-sdp/src/auto/versions.txt index bb4ffb804..992f7403f 100644 --- a/gstreamer-sdp/src/auto/versions.txt +++ b/gstreamer-sdp/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ d1e88f9) -from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) +Generated by gir (https://github.com/gtk-rs/gir @ 5836573) +from gir-files (https://github.com/gtk-rs/gir-files @ c067e63) diff --git a/gstreamer-video/src/auto/versions.txt b/gstreamer-video/src/auto/versions.txt index bb4ffb804..992f7403f 100644 --- a/gstreamer-video/src/auto/versions.txt +++ b/gstreamer-video/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ d1e88f9) -from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) +Generated by gir (https://github.com/gtk-rs/gir @ 5836573) +from gir-files (https://github.com/gtk-rs/gir-files @ c067e63) diff --git a/gstreamer-video/src/auto/video_decoder.rs b/gstreamer-video/src/auto/video_decoder.rs index 8534f61b8..77da5b97e 100644 --- a/gstreamer-video/src/auto/video_decoder.rs +++ b/gstreamer-video/src/auto/video_decoder.rs @@ -2,6 +2,7 @@ // from gir-files (https://github.com/gtk-rs/gir-files) // DO NOT EDIT +use glib; use glib::object::IsA; use glib::translate::*; use gst; @@ -24,7 +25,7 @@ pub const NONE_VIDEO_DECODER: Option<&VideoDecoder> = None; pub trait VideoDecoderExt: 'static { fn add_to_frame(&self, n_bytes: i32); - fn allocate_output_buffer(&self) -> Option; + fn allocate_output_buffer(&self) -> Result; fn get_buffer_pool(&self) -> Option; @@ -64,11 +65,12 @@ impl> VideoDecoderExt for O { } } - fn allocate_output_buffer(&self) -> Option { + fn allocate_output_buffer(&self) -> Result { unsafe { - from_glib_full(gst_video_sys::gst_video_decoder_allocate_output_buffer( + Option::<_>::from_glib_full(gst_video_sys::gst_video_decoder_allocate_output_buffer( self.as_ref().to_glib_none().0, )) + .ok_or_else(|| glib_bool_error!("Failed to allocate output buffer")) } } diff --git a/gstreamer-video/src/auto/video_encoder.rs b/gstreamer-video/src/auto/video_encoder.rs index 65810d46e..7e79472a2 100644 --- a/gstreamer-video/src/auto/video_encoder.rs +++ b/gstreamer-video/src/auto/video_encoder.rs @@ -2,6 +2,7 @@ // from gir-files (https://github.com/gtk-rs/gir-files) // DO NOT EDIT +use glib; use glib::object::Cast; use glib::object::IsA; use glib::signal::connect_raw; @@ -32,7 +33,7 @@ unsafe impl Sync for VideoEncoder {} pub const NONE_VIDEO_ENCODER: Option<&VideoEncoder> = None; pub trait VideoEncoderExt: 'static { - fn allocate_output_buffer(&self, size: usize) -> Option; + fn allocate_output_buffer(&self, size: usize) -> Result; #[cfg(any(feature = "v1_14", feature = "dox"))] fn get_max_encode_time(&self, frame: &VideoCodecFrame) -> gst::ClockTimeDiff; @@ -62,12 +63,13 @@ pub trait VideoEncoderExt: 'static { } impl> VideoEncoderExt for O { - fn allocate_output_buffer(&self, size: usize) -> Option { + fn allocate_output_buffer(&self, size: usize) -> Result { unsafe { - from_glib_full(gst_video_sys::gst_video_encoder_allocate_output_buffer( + Option::<_>::from_glib_full(gst_video_sys::gst_video_encoder_allocate_output_buffer( self.as_ref().to_glib_none().0, size, )) + .ok_or_else(|| glib_bool_error!("Failed to allocate output buffer")) } } diff --git a/gstreamer-video/src/video_format.rs b/gstreamer-video/src/video_format.rs index e59bcc4a1..91320a758 100644 --- a/gstreamer-video/src/video_format.rs +++ b/gstreamer-video/src/video_format.rs @@ -90,9 +90,9 @@ impl ::VideoFormat { } impl str::FromStr for ::VideoFormat { - type Err = (); + type Err = glib::BoolError; - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { assert_initialized_main_thread!(); unsafe { @@ -101,7 +101,7 @@ impl str::FromStr for ::VideoFormat { )); if fmt == ::VideoFormat::Unknown { - Err(()) + Err(glib_bool_error!("Failed to parse video format from string")) } else { Ok(fmt) } diff --git a/gstreamer-video/src/video_format_info.rs b/gstreamer-video/src/video_format_info.rs index 39d1ace34..5a544c865 100644 --- a/gstreamer-video/src/video_format_info.rs +++ b/gstreamer-video/src/video_format_info.rs @@ -344,9 +344,9 @@ impl fmt::Display for VideoFormatInfo { } impl str::FromStr for ::VideoFormatInfo { - type Err = (); + type Err = glib::BoolError; - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { skip_assert_initialized!(); let format = s.parse()?; Ok(VideoFormatInfo::from_format(format)) diff --git a/gstreamer-video/src/video_frame.rs b/gstreamer-video/src/video_frame.rs index 36c8fda7e..0d9e83b71 100644 --- a/gstreamer-video/src/video_frame.rs +++ b/gstreamer-video/src/video_frame.rs @@ -139,9 +139,9 @@ impl VideoFrame { unsafe { gst::BufferRef::from_ptr(self.0.buffer) } } - pub fn plane_data(&self, plane: u32) -> Option<&[u8]> { + pub fn plane_data(&self, plane: u32) -> Result<&[u8], glib::BoolError> { if plane >= self.n_planes() { - return None; + return Err(glib_bool_error!("Plane index higher than number of planes")); } let format_info = self.format_info(); @@ -149,7 +149,7 @@ impl VideoFrame { // Just get the palette if format_info.has_palette() && plane == 1 { unsafe { - return Some(slice::from_raw_parts(self.0.data[1] as *const u8, 256 * 4)); + return Ok(slice::from_raw_parts(self.0.data[1] as *const u8, 256 * 4)); } } @@ -159,7 +159,7 @@ impl VideoFrame { let h = format_info.scale_height(plane as u8, self.height()); unsafe { - Some(slice::from_raw_parts( + Ok(slice::from_raw_parts( self.0.data[plane as usize] as *const u8, (w * h) as usize, )) @@ -306,9 +306,9 @@ impl VideoFrame { unsafe { gst::BufferRef::from_mut_ptr(self.0.buffer) } } - pub fn plane_data_mut(&mut self, plane: u32) -> Option<&mut [u8]> { + pub fn plane_data_mut(&mut self, plane: u32) -> Result<&mut [u8], glib::BoolError> { if plane >= self.n_planes() { - return None; + return Err(glib_bool_error!("Plane index higher than number of planes")); } let format_info = self.format_info(); @@ -316,7 +316,7 @@ impl VideoFrame { // Just get the palette if format_info.has_palette() && plane == 1 { unsafe { - return Some(slice::from_raw_parts_mut( + return Ok(slice::from_raw_parts_mut( self.0.data[1] as *mut u8, 256 * 4, )); @@ -329,7 +329,7 @@ impl VideoFrame { let h = format_info.scale_height(plane as u8, self.height()); unsafe { - Some(slice::from_raw_parts_mut( + Ok(slice::from_raw_parts_mut( self.0.data[plane as usize] as *mut u8, (w * h) as usize, )) @@ -367,7 +367,7 @@ impl<'a> VideoFrameRef<&'a gst::BufferRef> { pub fn from_buffer_ref_readable<'b>( buffer: &'a gst::BufferRef, info: &'b ::VideoInfo, - ) -> Option> { + ) -> Result, glib::BoolError> { skip_assert_initialized!(); unsafe { @@ -380,11 +380,11 @@ impl<'a> VideoFrameRef<&'a gst::BufferRef> { )); if !res { - None + Err(glib_bool_error!("Failed to map VideoFrame")) } else { let frame = frame.assume_init(); let info = ::VideoInfo(ptr::read(&frame.info)); - Some(VideoFrameRef(frame, Some(buffer), info, false)) + Ok(VideoFrameRef(frame, Some(buffer), info, false)) } } } @@ -393,7 +393,7 @@ impl<'a> VideoFrameRef<&'a gst::BufferRef> { buffer: &'a gst::BufferRef, id: i32, info: &'b ::VideoInfo, - ) -> Option> { + ) -> Result, glib::BoolError> { skip_assert_initialized!(); unsafe { @@ -407,11 +407,11 @@ impl<'a> VideoFrameRef<&'a gst::BufferRef> { )); if !res { - None + Err(glib_bool_error!("Failed to map VideoFrame")) } else { let frame = frame.assume_init(); let info = ::VideoInfo(ptr::read(&frame.info)); - Some(VideoFrameRef(frame, Some(buffer), info, false)) + Ok(VideoFrameRef(frame, Some(buffer), info, false)) } } } @@ -519,9 +519,9 @@ impl<'a> VideoFrameRef<&'a gst::BufferRef> { self.1.as_ref().unwrap() } - pub fn plane_data(&self, plane: u32) -> Option<&[u8]> { + pub fn plane_data(&self, plane: u32) -> Result<&[u8], glib::BoolError> { if plane >= self.n_planes() { - return None; + return Err(glib_bool_error!("Plane index higher than number of planes")); } let format_info = self.format_info(); @@ -529,7 +529,7 @@ impl<'a> VideoFrameRef<&'a gst::BufferRef> { // Just get the palette if format_info.has_palette() && plane == 1 { unsafe { - return Some(slice::from_raw_parts(self.0.data[1] as *const u8, 256 * 4)); + return Ok(slice::from_raw_parts(self.0.data[1] as *const u8, 256 * 4)); } } @@ -539,7 +539,7 @@ impl<'a> VideoFrameRef<&'a gst::BufferRef> { let h = format_info.scale_height(plane as u8, self.height()); unsafe { - Some(slice::from_raw_parts( + Ok(slice::from_raw_parts( self.0.data[plane as usize] as *const u8, (w * h) as usize, )) @@ -560,7 +560,7 @@ impl<'a> VideoFrameRef<&'a mut gst::BufferRef> { pub fn from_buffer_ref_writable<'b>( buffer: &'a mut gst::BufferRef, info: &'b ::VideoInfo, - ) -> Option> { + ) -> Result, glib::BoolError> { skip_assert_initialized!(); unsafe { @@ -575,11 +575,11 @@ impl<'a> VideoFrameRef<&'a mut gst::BufferRef> { )); if !res { - None + Err(glib_bool_error!("Failed to map VideoFrame")) } else { let frame = frame.assume_init(); let info = ::VideoInfo(ptr::read(&frame.info)); - Some(VideoFrameRef(frame, Some(buffer), info, false)) + Ok(VideoFrameRef(frame, Some(buffer), info, false)) } } } @@ -588,7 +588,7 @@ impl<'a> VideoFrameRef<&'a mut gst::BufferRef> { buffer: &'a mut gst::BufferRef, id: i32, info: &'b ::VideoInfo, - ) -> Option> { + ) -> Result, glib::BoolError> { skip_assert_initialized!(); unsafe { @@ -604,11 +604,11 @@ impl<'a> VideoFrameRef<&'a mut gst::BufferRef> { )); if !res { - None + Err(glib_bool_error!("Failed to map VideoFrame")) } else { let frame = frame.assume_init(); let info = ::VideoInfo(ptr::read(&frame.info)); - Some(VideoFrameRef(frame, Some(buffer), info, false)) + Ok(VideoFrameRef(frame, Some(buffer), info, false)) } } } @@ -617,9 +617,9 @@ impl<'a> VideoFrameRef<&'a mut gst::BufferRef> { self.1.as_mut().unwrap() } - pub fn plane_data_mut(&mut self, plane: u32) -> Option<&mut [u8]> { + pub fn plane_data_mut(&mut self, plane: u32) -> Result<&mut [u8], glib::BoolError> { if plane >= self.n_planes() { - return None; + return Err(glib_bool_error!("Plane index higher than number of planes")); } let format_info = self.format_info(); @@ -627,7 +627,7 @@ impl<'a> VideoFrameRef<&'a mut gst::BufferRef> { // Just get the palette if format_info.has_palette() && plane == 1 { unsafe { - return Some(slice::from_raw_parts_mut( + return Ok(slice::from_raw_parts_mut( self.0.data[1] as *mut u8, 256 * 4, )); @@ -640,7 +640,7 @@ impl<'a> VideoFrameRef<&'a mut gst::BufferRef> { let h = format_info.scale_height(plane as u8, self.height()); unsafe { - Some(slice::from_raw_parts_mut( + Ok(slice::from_raw_parts_mut( self.0.data[plane as usize] as *mut u8, (w * h) as usize, )) @@ -717,9 +717,9 @@ mod tests { let buffer = gst::Buffer::with_size(info.size()).unwrap(); let frame = VideoFrame::from_buffer_readable(buffer, &info).unwrap(); - assert_ne!(frame.plane_data(0), None); + assert!(frame.plane_data(0).is_ok()); assert_eq!(frame.plane_data(0).unwrap().len(), 320 * 240); - assert_eq!(frame.plane_data(1), None); + assert!(frame.plane_data(1).is_err()); assert!(frame.info() == &info); } @@ -733,9 +733,9 @@ mod tests { let buffer = gst::Buffer::with_size(info.size()).unwrap(); let mut frame = VideoFrame::from_buffer_writable(buffer, &info).unwrap(); - assert_ne!(frame.plane_data_mut(0), None); + assert!(frame.plane_data_mut(0).is_ok()); assert_eq!(frame.plane_data_mut(0).unwrap().len(), 320 * 240); - assert_eq!(frame.plane_data_mut(1), None); + assert!(frame.plane_data_mut(1).is_err()); assert!(frame.info() == &info); } } diff --git a/gstreamer-webrtc/src/auto/versions.txt b/gstreamer-webrtc/src/auto/versions.txt index bb4ffb804..992f7403f 100644 --- a/gstreamer-webrtc/src/auto/versions.txt +++ b/gstreamer-webrtc/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ d1e88f9) -from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) +Generated by gir (https://github.com/gtk-rs/gir @ 5836573) +from gir-files (https://github.com/gtk-rs/gir-files @ c067e63) diff --git a/gstreamer/src/allocator.rs b/gstreamer/src/allocator.rs index d8f7af1e3..1aa6b38a0 100644 --- a/gstreamer/src/allocator.rs +++ b/gstreamer/src/allocator.rs @@ -18,11 +18,19 @@ use Allocator; use Memory; pub trait AllocatorExtManual: 'static { - fn alloc(&self, size: usize, params: Option<&AllocationParams>) -> Option; + fn alloc( + &self, + size: usize, + params: Option<&AllocationParams>, + ) -> Result; } impl> AllocatorExtManual for O { - fn alloc(&self, size: usize, params: Option<&AllocationParams>) -> Option { + fn alloc( + &self, + size: usize, + params: Option<&AllocationParams>, + ) -> Result { unsafe { let ret = gst_sys::gst_allocator_alloc( self.as_ptr() as *mut _, @@ -33,9 +41,9 @@ impl> AllocatorExtManual for O { }, ); if ret.is_null() { - None + Err(glib_bool_error!("Failed to allocate memory")) } else { - Some(from_glib_full(ret)) + Ok(from_glib_full(ret)) } } } diff --git a/gstreamer/src/auto/date_time.rs b/gstreamer/src/auto/date_time.rs index babd88062..f35904e31 100644 --- a/gstreamer/src/auto/date_time.rs +++ b/gstreamer/src/auto/date_time.rs @@ -36,7 +36,7 @@ impl DateTime { } } - pub fn new_from_g_date_time(dt: &glib::DateTime) -> Option { + pub fn new_from_g_date_time(dt: &glib::DateTime) -> DateTime { assert_initialized_main_thread!(); unsafe { from_glib_full(gst_sys::gst_date_time_new_from_g_date_time( @@ -45,12 +45,13 @@ impl DateTime { } } - pub fn new_from_iso8601_string(string: &str) -> Option { + pub fn new_from_iso8601_string(string: &str) -> Result { assert_initialized_main_thread!(); unsafe { - from_glib_full(gst_sys::gst_date_time_new_from_iso8601_string( + Option::<_>::from_glib_full(gst_sys::gst_date_time_new_from_iso8601_string( string.to_glib_none().0, )) + .ok_or_else(|| glib_bool_error!("Failed to create DateTime from ISO-8601 string")) } } @@ -157,15 +158,21 @@ impl DateTime { unsafe { from_glib(gst_sys::gst_date_time_has_year(self.to_glib_none().0)) } } - pub fn to_g_date_time(&self) -> Option { - unsafe { from_glib_full(gst_sys::gst_date_time_to_g_date_time(self.to_glib_none().0)) } - } - - pub fn to_iso8601_string(&self) -> Option { + pub fn to_g_date_time(&self) -> Result { unsafe { - from_glib_full(gst_sys::gst_date_time_to_iso8601_string( + Option::<_>::from_glib_full(gst_sys::gst_date_time_to_g_date_time( self.to_glib_none().0, )) + .ok_or_else(|| glib_bool_error!("Can't create glib::DateTime from DateTime")) + } + } + + pub fn to_iso8601_string(&self) -> Result { + unsafe { + Option::<_>::from_glib_full(gst_sys::gst_date_time_to_iso8601_string( + self.to_glib_none().0, + )) + .ok_or_else(|| glib_bool_error!("Failed to create ISO-8601 string from DateTime")) } } } diff --git a/gstreamer/src/auto/device.rs b/gstreamer/src/auto/device.rs index 87f1933e3..f9e6d7a0b 100644 --- a/gstreamer/src/auto/device.rs +++ b/gstreamer/src/auto/device.rs @@ -32,7 +32,7 @@ unsafe impl Sync for Device {} pub const NONE_DEVICE: Option<&Device> = None; pub trait DeviceExt: 'static { - fn create_element(&self, name: Option<&str>) -> Option; + fn create_element(&self, name: Option<&str>) -> Result; fn get_caps(&self) -> Option; @@ -55,12 +55,13 @@ pub trait DeviceExt: 'static { } impl> DeviceExt for O { - fn create_element(&self, name: Option<&str>) -> Option { + fn create_element(&self, name: Option<&str>) -> Result { unsafe { - from_glib_none(gst_sys::gst_device_create_element( + Option::<_>::from_glib_none(gst_sys::gst_device_create_element( self.as_ref().to_glib_none().0, name.to_glib_none().0, )) + .ok_or_else(|| glib_bool_error!("Failed to create element for device")) } } diff --git a/gstreamer/src/auto/element_factory.rs b/gstreamer/src/auto/element_factory.rs index f45cae210..8270907bf 100644 --- a/gstreamer/src/auto/element_factory.rs +++ b/gstreamer/src/auto/element_factory.rs @@ -61,12 +61,13 @@ impl ElementFactory { } } - pub fn create(&self, name: Option<&str>) -> Option { + pub fn create(&self, name: Option<&str>) -> Result { unsafe { - from_glib_none(gst_sys::gst_element_factory_create( + Option::<_>::from_glib_none(gst_sys::gst_element_factory_create( self.to_glib_none().0, name.to_glib_none().0, )) + .ok_or_else(|| glib_bool_error!("Failed to create element from factory")) } } @@ -173,13 +174,14 @@ impl ElementFactory { } } - pub fn make(factoryname: &str, name: Option<&str>) -> Option { + pub fn make(factoryname: &str, name: Option<&str>) -> Result { assert_initialized_main_thread!(); unsafe { - from_glib_none(gst_sys::gst_element_factory_make( + Option::<_>::from_glib_none(gst_sys::gst_element_factory_make( factoryname.to_glib_none().0, name.to_glib_none().0, )) + .ok_or_else(|| glib_bool_error!("Failed to create element from factory name")) } } } diff --git a/gstreamer/src/auto/functions.rs b/gstreamer/src/auto/functions.rs index a56b500f3..26e637d7d 100644 --- a/gstreamer/src/auto/functions.rs +++ b/gstreamer/src/auto/functions.rs @@ -72,9 +72,12 @@ pub fn debug_get_default_threshold() -> DebugLevel { } #[cfg(any(feature = "v1_12", feature = "dox"))] -pub fn debug_get_stack_trace(flags: StackTraceFlags) -> Option { +pub fn debug_get_stack_trace(flags: StackTraceFlags) -> Result { assert_initialized_main_thread!(); - unsafe { from_glib_full(gst_sys::gst_debug_get_stack_trace(flags.to_glib())) } + unsafe { + Option::<_>::from_glib_full(gst_sys::gst_debug_get_stack_trace(flags.to_glib())) + .ok_or_else(|| glib_bool_error!("Failed to get stack trace")) + } } pub fn debug_is_active() -> bool { @@ -153,9 +156,12 @@ pub fn debug_unset_threshold_for_name(name: &str) { } #[cfg(any(feature = "v1_14", feature = "dox"))] -pub fn get_main_executable_path() -> Option { +pub fn get_main_executable_path() -> Result { assert_initialized_main_thread!(); - unsafe { from_glib_none(gst_sys::gst_get_main_executable_path()) } + unsafe { + Option::<_>::from_glib_none(gst_sys::gst_get_main_executable_path()) + .ok_or_else(|| glib_bool_error!("Failed to get main executable path")) + } } pub fn parse_bin_from_description( diff --git a/gstreamer/src/auto/ghost_pad.rs b/gstreamer/src/auto/ghost_pad.rs index c1f020f96..e27a6aab5 100644 --- a/gstreamer/src/auto/ghost_pad.rs +++ b/gstreamer/src/auto/ghost_pad.rs @@ -22,7 +22,10 @@ glib_wrapper! { } impl GhostPad { - pub fn new_no_target(name: Option<&str>, dir: PadDirection) -> Option { + pub fn new_no_target( + name: Option<&str>, + dir: PadDirection, + ) -> Result { assert_initialized_main_thread!(); unsafe { Option::::from_glib_none(gst_sys::gst_ghost_pad_new_no_target( @@ -30,13 +33,14 @@ impl GhostPad { dir.to_glib(), )) .map(|o| o.unsafe_cast()) + .ok_or_else(|| glib_bool_error!("Failed to create GhostPad")) } } pub fn new_no_target_from_template( name: Option<&str>, templ: &PadTemplate, - ) -> Option { + ) -> Result { skip_assert_initialized!(); unsafe { Option::::from_glib_none(gst_sys::gst_ghost_pad_new_no_target_from_template( @@ -44,6 +48,7 @@ impl GhostPad { templ.to_glib_none().0, )) .map(|o| o.unsafe_cast()) + .ok_or_else(|| glib_bool_error!("Failed to create GhostPad")) } } } diff --git a/gstreamer/src/auto/pad_template.rs b/gstreamer/src/auto/pad_template.rs index 2c1b99d49..6e6651cad 100644 --- a/gstreamer/src/auto/pad_template.rs +++ b/gstreamer/src/auto/pad_template.rs @@ -2,7 +2,6 @@ // from gir-files (https://github.com/gtk-rs/gir-files) // DO NOT EDIT -#[cfg(any(feature = "v1_14", feature = "dox"))] use glib; use glib::object::IsA; use glib::object::ObjectType as ObjectType_; @@ -37,15 +36,16 @@ impl PadTemplate { direction: PadDirection, presence: PadPresence, caps: &Caps, - ) -> Option { + ) -> Result { assert_initialized_main_thread!(); unsafe { - from_glib_none(gst_sys::gst_pad_template_new( + Option::<_>::from_glib_none(gst_sys::gst_pad_template_new( name_template.to_glib_none().0, direction.to_glib(), presence.to_glib(), caps.to_glib_none().0, )) + .ok_or_else(|| glib_bool_error!("Failed to create pad template")) } } @@ -56,16 +56,17 @@ impl PadTemplate { presence: PadPresence, caps: &Caps, pad_type: glib::types::Type, - ) -> Option { + ) -> Result { assert_initialized_main_thread!(); unsafe { - from_glib_none(gst_sys::gst_pad_template_new_with_gtype( + Option::<_>::from_glib_none(gst_sys::gst_pad_template_new_with_gtype( name_template.to_glib_none().0, direction.to_glib(), presence.to_glib(), caps.to_glib_none().0, pad_type.to_glib(), )) + .ok_or_else(|| glib_bool_error!("Failed to create pad template")) } } diff --git a/gstreamer/src/auto/plugin.rs b/gstreamer/src/auto/plugin.rs index 89d4b4560..a4ee5d74f 100644 --- a/gstreamer/src/auto/plugin.rs +++ b/gstreamer/src/auto/plugin.rs @@ -96,13 +96,19 @@ impl Plugin { unsafe { from_glib(gst_sys::gst_plugin_is_loaded(self.to_glib_none().0)) } } - pub fn load(&self) -> Option { - unsafe { from_glib_full(gst_sys::gst_plugin_load(self.to_glib_none().0)) } + pub fn load(&self) -> Result { + unsafe { + Option::<_>::from_glib_full(gst_sys::gst_plugin_load(self.to_glib_none().0)) + .ok_or_else(|| glib_bool_error!("Failed to load plugin")) + } } - pub fn load_by_name(name: &str) -> Option { + pub fn load_by_name(name: &str) -> Result { assert_initialized_main_thread!(); - unsafe { from_glib_full(gst_sys::gst_plugin_load_by_name(name.to_glib_none().0)) } + unsafe { + Option::<_>::from_glib_full(gst_sys::gst_plugin_load_by_name(name.to_glib_none().0)) + .ok_or_else(|| glib_bool_error!("Failed to load plugin")) + } } pub fn load_file>(filename: P) -> Result { diff --git a/gstreamer/src/auto/plugin_feature.rs b/gstreamer/src/auto/plugin_feature.rs index f75544ee8..0a1ef2a51 100644 --- a/gstreamer/src/auto/plugin_feature.rs +++ b/gstreamer/src/auto/plugin_feature.rs @@ -2,6 +2,7 @@ // from gir-files (https://github.com/gtk-rs/gir-files) // DO NOT EDIT +use glib; use glib::object::IsA; use glib::translate::*; use glib::GString; @@ -29,7 +30,7 @@ pub trait PluginFeatureExt: 'static { fn get_plugin_name(&self) -> Option; - fn load(&self) -> Option; + fn load(&self) -> Result; } impl> PluginFeatureExt for O { @@ -60,11 +61,12 @@ impl> PluginFeatureExt for O { } } - fn load(&self) -> Option { + fn load(&self) -> Result { unsafe { - from_glib_full(gst_sys::gst_plugin_feature_load( + Option::<_>::from_glib_full(gst_sys::gst_plugin_feature_load( self.as_ref().to_glib_none().0, )) + .ok_or_else(|| glib_bool_error!("Failed to load plugin feature")) } } } diff --git a/gstreamer/src/auto/versions.txt b/gstreamer/src/auto/versions.txt index bb4ffb804..992f7403f 100644 --- a/gstreamer/src/auto/versions.txt +++ b/gstreamer/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ d1e88f9) -from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) +Generated by gir (https://github.com/gtk-rs/gir @ 5836573) +from gir-files (https://github.com/gtk-rs/gir-files @ c067e63) diff --git a/gstreamer/src/buffer.rs b/gstreamer/src/buffer.rs index 325166422..325ce8949 100644 --- a/gstreamer/src/buffer.rs +++ b/gstreamer/src/buffer.rs @@ -23,7 +23,7 @@ use Memory; use MemoryRef; use glib; -use glib::translate::{from_glib, from_glib_full, FromGlib, ToGlib}; +use glib::translate::{from_glib, from_glib_full, FromGlib, FromGlibPtrFull, ToGlib}; use glib_sys; use gst_sys; @@ -57,15 +57,16 @@ impl Buffer { unsafe { from_glib_full(gst_sys::gst_buffer_new()) } } - pub fn with_size(size: usize) -> Option { + pub fn with_size(size: usize) -> Result { assert_initialized_main_thread!(); unsafe { - from_glib_full(gst_sys::gst_buffer_new_allocate( + Option::<_>::from_glib_full(gst_sys::gst_buffer_new_allocate( ptr::null_mut(), size, ptr::null_mut(), )) + .ok_or_else(|| glib_bool_error!("Failed to allocate buffer")) } } @@ -176,7 +177,7 @@ impl Default for Buffer { } impl BufferRef { - pub fn map_readable(&self) -> Option> { + pub fn map_readable(&self) -> Result, glib::BoolError> { unsafe { let mut map_info = mem::MaybeUninit::zeroed(); let res = gst_sys::gst_buffer_map( @@ -185,18 +186,18 @@ impl BufferRef { gst_sys::GST_MAP_READ, ); if res == glib_sys::GTRUE { - Some(BufferMap { + Ok(BufferMap { buffer: self, map_info: map_info.assume_init(), phantom: PhantomData, }) } else { - None + Err(glib_bool_error!("Failed to map buffer readable")) } } } - pub fn map_writable(&mut self) -> Option> { + pub fn map_writable(&mut self) -> Result, glib::BoolError> { unsafe { let mut map_info = mem::MaybeUninit::zeroed(); let res = gst_sys::gst_buffer_map( @@ -205,13 +206,13 @@ impl BufferRef { gst_sys::GST_MAP_READWRITE, ); if res == glib_sys::GTRUE { - Some(BufferMap { + Ok(BufferMap { buffer: self, map_info: map_info.assume_init(), phantom: PhantomData, }) } else { - None + Err(glib_bool_error!("Failed to map buffer writable")) } } } @@ -221,15 +222,16 @@ impl BufferRef { flags: ::BufferCopyFlags, offset: usize, size: Option, - ) -> Option { + ) -> Result { let size_real = size.unwrap_or(usize::MAX); unsafe { - from_glib_full(gst_sys::gst_buffer_copy_region( + Option::<_>::from_glib_full(gst_sys::gst_buffer_copy_region( self.as_mut_ptr(), flags.to_glib(), offset, size_real, )) + .ok_or_else(|| glib_bool_error!("Failed to copy region of buffer")) } } @@ -296,8 +298,11 @@ impl BufferRef { } } - pub fn copy_deep(&self) -> Option { - unsafe { from_glib_full(gst_sys::gst_buffer_copy_deep(self.as_ptr())) } + pub fn copy_deep(&self) -> Result { + unsafe { + Option::<_>::from_glib_full(gst_sys::gst_buffer_copy_deep(self.as_ptr())) + .ok_or_else(|| glib_bool_error!("Failed to deep copy buffer")) + } } pub fn get_size(&self) -> usize { @@ -695,7 +700,7 @@ impl PartialEq for BufferRef { let other_map = other.map_readable(); match (self_map, other_map) { - (Some(self_map), Some(other_map)) => self_map.as_slice().eq(other_map.as_slice()), + (Ok(self_map), Ok(other_map)) => self_map.as_slice().eq(other_map.as_slice()), _ => false, } } diff --git a/gstreamer/src/buffer_serde.rs b/gstreamer/src/buffer_serde.rs index a7b70784d..3fb054004 100644 --- a/gstreamer/src/buffer_serde.rs +++ b/gstreamer/src/buffer_serde.rs @@ -31,7 +31,7 @@ impl<'a> Serialize for BufferRef { { let data = self .map_readable() - .ok_or_else(|| ser::Error::custom("Couldn't map `buffer` as readable"))?; + .map_err(|_| ser::Error::custom("Couldn't map `buffer` as readable"))?; buffer.serialize_field("buffer", &Bytes::new(data.as_slice()))?; } buffer.end() diff --git a/gstreamer/src/bus.rs b/gstreamer/src/bus.rs index 20d02c0ac..c5db1f30e 100644 --- a/gstreamer/src/bus.rs +++ b/gstreamer/src/bus.rs @@ -108,7 +108,7 @@ impl Bus { } } - pub fn add_watch(&self, func: F) -> Option + pub fn add_watch(&self, func: F) -> Result where F: FnMut(&Bus, &Message) -> Continue + Send + 'static, { @@ -122,14 +122,14 @@ impl Bus { ); if res == 0 { - None + Err(glib_bool_error!("Bus already has a watch")) } else { - Some(from_glib(res)) + Ok(from_glib(res)) } } } - pub fn add_watch_local(&self, func: F) -> Option + pub fn add_watch_local(&self, func: F) -> Result where F: FnMut(&Bus, &Message) -> Continue + 'static, { @@ -145,9 +145,9 @@ impl Bus { ); if res == 0 { - None + Err(glib_bool_error!("Bus already has a watch")) } else { - Some(from_glib(res)) + Ok(from_glib(res)) } } } diff --git a/gstreamer/src/caps.rs b/gstreamer/src/caps.rs index 8da4bae8a..f861fda46 100644 --- a/gstreamer/src/caps.rs +++ b/gstreamer/src/caps.rs @@ -106,13 +106,13 @@ impl Caps { } impl str::FromStr for Caps { - type Err = (); + type Err = glib::BoolError; - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { assert_initialized_main_thread!(); unsafe { - Option::::from_glib_full(gst_sys::gst_caps_from_string(s.to_glib_none().0)) - .ok_or(()) + Option::<_>::from_glib_full(gst_sys::gst_caps_from_string(s.to_glib_none().0)) + .ok_or_else(|| glib_bool_error!("Failed to parse caps from string")) } } } diff --git a/gstreamer/src/caps_features.rs b/gstreamer/src/caps_features.rs index 00c0c1e70..5fef72ebb 100644 --- a/gstreamer/src/caps_features.rs +++ b/gstreamer/src/caps_features.rs @@ -130,14 +130,16 @@ impl fmt::Display for CapsFeatures { } impl str::FromStr for CapsFeatures { - type Err = (); + type Err = glib::BoolError; - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { assert_initialized_main_thread!(); unsafe { let ptr = gst_sys::gst_caps_features_from_string(s.to_glib_none().0); if ptr.is_null() { - return Err(()); + return Err(glib_bool_error!( + "Failed to parse caps features from string" + )); } Ok(CapsFeatures( diff --git a/gstreamer/src/clock.rs b/gstreamer/src/clock.rs index 7033e5070..ed17be595 100644 --- a/gstreamer/src/clock.rs +++ b/gstreamer/src/clock.rs @@ -227,7 +227,11 @@ impl Clock { } pub trait ClockExtManual: 'static { - fn new_periodic_id(&self, start_time: ClockTime, interval: ClockTime) -> Option; + fn new_periodic_id( + &self, + start_time: ClockTime, + interval: ClockTime, + ) -> Result; fn periodic_id_reinit( &self, @@ -236,7 +240,7 @@ pub trait ClockExtManual: 'static { interval: ClockTime, ) -> Result<(), glib::BoolError>; - fn new_single_shot_id(&self, time: ClockTime) -> Option; + fn new_single_shot_id(&self, time: ClockTime) -> Result; fn single_shot_id_reinit(&self, id: &ClockId, time: ClockTime) -> Result<(), glib::BoolError>; @@ -248,13 +252,18 @@ pub trait ClockExtManual: 'static { } impl> ClockExtManual for O { - fn new_periodic_id(&self, start_time: ClockTime, interval: ClockTime) -> Option { + fn new_periodic_id( + &self, + start_time: ClockTime, + interval: ClockTime, + ) -> Result { unsafe { - from_glib_full(gst_sys::gst_clock_new_periodic_id( + Option::<_>::from_glib_full(gst_sys::gst_clock_new_periodic_id( self.as_ref().to_glib_none().0, start_time.to_glib(), interval.to_glib(), )) + .ok_or_else(|| glib_bool_error!("Failed to create new periodic clock id")) } } @@ -280,12 +289,13 @@ impl> ClockExtManual for O { } } - fn new_single_shot_id(&self, time: ClockTime) -> Option { + fn new_single_shot_id(&self, time: ClockTime) -> Result { unsafe { - from_glib_full(gst_sys::gst_clock_new_single_shot_id( + Option::<_>::from_glib_full(gst_sys::gst_clock_new_single_shot_id( self.as_ref().to_glib_none().0, time.to_glib(), )) + .ok_or_else(|| glib_bool_error!("Failed to create new single shot clock id")) } } diff --git a/gstreamer/src/date_time.rs b/gstreamer/src/date_time.rs index 5266a9ffa..aabc2a5e0 100644 --- a/gstreamer/src/date_time.rs +++ b/gstreamer/src/date_time.rs @@ -13,10 +13,10 @@ use DateTime; impl DateTime { /// Get the [`DateTime`](struct.DateTime.html) in UTC - pub fn to_utc(&self) -> Option { + pub fn to_utc(&self) -> Result { if !self.has_time() { // No time => no TZ offset - return Some(self.clone()); + return Ok(self.clone()); } assert!(self.has_year() && self.has_month() && self.has_day() && self.has_time()); @@ -29,7 +29,8 @@ impl DateTime { .expect("DateTime::to_utc: to_g_date_time") .to_utc() .as_ref() - .and_then(DateTime::new_from_g_date_time) + .ok_or_else(|| glib_bool_error!("Can't convert datetime to UTC")) + .map(DateTime::new_from_g_date_time) } else { // It would be cheaper to build a `glib::DateTime` direcly, unfortunetaly // this would require using `glib::TimeZone::new_offset` which is feature-gated @@ -47,6 +48,7 @@ impl DateTime { .to_g_date_time() .expect("DateTime::to_utc: to_g_date_time") .to_utc() + .ok_or_else(|| glib_bool_error!("Can't convert datetime to UTC")) .map(|g_date_time_utc| { DateTime::new( 0f32, // UTC TZ offset @@ -101,7 +103,7 @@ impl cmp::PartialOrd for DateTime { // Normalize to UTC only if both members have time (see note 2). let (self_norm, other_norm) = if self.has_time() && other.has_time() { - (self.to_utc()?, other.to_utc()?) + (self.to_utc().ok()?, other.to_utc().ok()?) } else { (self.clone(), other.clone()) }; @@ -227,7 +229,7 @@ impl fmt::Display for DateTime { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.write_str( self.to_iso8601_string() - .unwrap_or_else(|| "None".into()) + .unwrap_or_else(|_| "None".into()) .as_str(), ) } diff --git a/gstreamer/src/ghost_pad.rs b/gstreamer/src/ghost_pad.rs index 4626f58e7..aeda62e95 100644 --- a/gstreamer/src/ghost_pad.rs +++ b/gstreamer/src/ghost_pad.rs @@ -17,7 +17,7 @@ use PadMode; use PadTemplate; impl GhostPad { - pub fn new>(name: Option<&str>, target: &Q) -> Option { + pub fn new>(name: Option<&str>, target: &Q) -> Result { skip_assert_initialized!(); let name = name.to_glib_none(); unsafe { @@ -26,6 +26,7 @@ impl GhostPad { target.as_ref().to_glib_none().0, )) .map(|o| Cast::unsafe_cast(o)) + .ok_or_else(|| glib_bool_error!("Failed to create GhostPad")) } } @@ -33,7 +34,7 @@ impl GhostPad { name: Option<&str>, target: &Q, templ: &PadTemplate, - ) -> Option { + ) -> Result { skip_assert_initialized!(); let name = name.to_glib_none(); unsafe { @@ -43,6 +44,7 @@ impl GhostPad { templ.to_glib_none().0, )) .map(|o| Cast::unsafe_cast(o)) + .ok_or_else(|| glib_bool_error!("Failed to create GhostPad")) } } diff --git a/gstreamer/src/memory.rs b/gstreamer/src/memory.rs index 1d4c73ba6..64b682511 100644 --- a/gstreamer/src/memory.rs +++ b/gstreamer/src/memory.rs @@ -246,7 +246,7 @@ impl MemoryRef { } } - pub fn map_readable(&self) -> Option> { + pub fn map_readable(&self) -> Result, glib::BoolError> { unsafe { let mut map_info = mem::MaybeUninit::zeroed(); let res = gst_sys::gst_memory_map( @@ -255,18 +255,18 @@ impl MemoryRef { gst_sys::GST_MAP_READ, ); if res == glib_sys::GTRUE { - Some(MemoryMap { + Ok(MemoryMap { memory: self, map_info: map_info.assume_init(), phantom: PhantomData, }) } else { - None + Err(glib_bool_error!("Failed to map memory readable")) } } } - pub fn map_writable(&mut self) -> Option> { + pub fn map_writable(&mut self) -> Result, glib::BoolError> { unsafe { let mut map_info = mem::MaybeUninit::zeroed(); let res = gst_sys::gst_memory_map( @@ -275,13 +275,13 @@ impl MemoryRef { gst_sys::GST_MAP_READWRITE, ); if res == glib_sys::GTRUE { - Some(MemoryMap { + Ok(MemoryMap { memory: self, map_info: map_info.assume_init(), phantom: PhantomData, }) } else { - None + Err(glib_bool_error!("Failed to map memory readable")) } } } diff --git a/gstreamer/src/pad_template.rs b/gstreamer/src/pad_template.rs index c2d6c792e..e56ed022e 100644 --- a/gstreamer/src/pad_template.rs +++ b/gstreamer/src/pad_template.rs @@ -22,15 +22,16 @@ impl PadTemplate { pub fn new_from_static_pad_template_with_gtype( pad_template: &StaticPadTemplate, pad_type: glib::types::Type, - ) -> Option { + ) -> Result { assert_initialized_main_thread!(); unsafe { - from_glib_none( + Option::<_>::from_glib_none( gst_sys::gst_pad_template_new_from_static_pad_template_with_gtype( mut_override(pad_template.to_glib_none().0), pad_type.to_glib(), ), ) + .ok_or_else(|| glib_bool_error!("Failed to create PadTemplate")) } } } diff --git a/gstreamer/src/structure.rs b/gstreamer/src/structure.rs index e0f75e92e..f9da0d662 100644 --- a/gstreamer/src/structure.rs +++ b/gstreamer/src/structure.rs @@ -188,14 +188,14 @@ impl PartialEq for Structure { impl Eq for Structure {} impl str::FromStr for Structure { - type Err = (); + type Err = glib::BoolError; - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { assert_initialized_main_thread!(); unsafe { let structure = gst_sys::gst_structure_from_string(s.to_glib_none().0, ptr::null_mut()); if structure.is_null() { - Err(()) + Err(glib_bool_error!("Failed to parse structure from string")) } else { Ok(Structure( ptr::NonNull::new_unchecked(structure as *mut StructureRef), diff --git a/gstreamer/src/subclass/device.rs b/gstreamer/src/subclass/device.rs index 2263e044e..5b51b178b 100644 --- a/gstreamer/src/subclass/device.rs +++ b/gstreamer/src/subclass/device.rs @@ -21,7 +21,11 @@ use LoggableError; use std::ptr; pub trait DeviceImpl: DeviceImplExt + ObjectImpl + Send + Sync + 'static { - fn create_element(&self, device: &Device, name: Option<&str>) -> Option { + fn create_element( + &self, + device: &Device, + name: Option<&str>, + ) -> Result { self.parent_create_element(device, name) } @@ -31,7 +35,11 @@ pub trait DeviceImpl: DeviceImplExt + ObjectImpl + Send + Sync + 'static { } pub trait DeviceImplExt { - fn parent_create_element(&self, device: &Device, name: Option<&str>) -> Option; + fn parent_create_element( + &self, + device: &Device, + name: Option<&str>, + ) -> Result; fn parent_reconfigure_element( &self, @@ -41,7 +49,11 @@ pub trait DeviceImplExt { } impl DeviceImplExt for T { - fn parent_create_element(&self, device: &Device, name: Option<&str>) -> Option { + fn parent_create_element( + &self, + device: &Device, + name: Option<&str>, + ) -> Result { unsafe { let data = self.get_type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstDeviceClass; @@ -49,9 +61,17 @@ impl DeviceImplExt for T { let ptr = f(device.to_glib_none().0, name.to_glib_none().0); // Don't steal floating reference here but pass it further to the caller - from_glib_full(ptr) + Option::<_>::from_glib_full(ptr).ok_or_else(|| { + gst_loggable_error!( + ::CAT_RUST, + "Failed to create element using the parent function" + ) + }) } else { - None + Err(gst_loggable_error!( + ::CAT_RUST, + "Parent function `create_element` is not defined" + )) } } } @@ -107,7 +127,7 @@ where .as_ref() .map(|s| s.as_str()), ) { - Some(element) => { + Ok(element) => { // The reference we're going to return, the initial reference is going to // be dropped here now let element_ptr = element.to_glib_full(); @@ -116,7 +136,10 @@ where gobject_sys::g_object_force_floating(element_ptr as *mut gobject_sys::GObject); element_ptr } - None => ptr::null_mut(), + Err(err) => { + err.log_with_object(&wrap); + ptr::null_mut() + } } } diff --git a/gstreamer/src/value.rs b/gstreamer/src/value.rs index c6ee52998..2c40d3402 100644 --- a/gstreamer/src/value.rs +++ b/gstreamer/src/value.rs @@ -14,7 +14,7 @@ use std::ops; use std::slice; use glib; -use glib::translate::{from_glib, from_glib_full, ToGlibPtr, ToGlibPtrMut, Uninitialized}; +use glib::translate::{from_glib, FromGlibPtrFull, ToGlibPtr, ToGlibPtrMut, Uninitialized}; use glib::value::{FromValue, FromValueOptional, SetValue, ToSendValue, Value}; use glib_sys; @@ -743,8 +743,8 @@ pub trait GstValueExt: Sized { fn fixate(&self) -> Option; fn is_fixed(&self) -> bool; fn is_subset(&self, superset: &Self) -> bool; - fn serialize(&self) -> Option; - fn deserialize<'a, T: Into<&'a str>>(s: T) -> Option; + fn serialize(&self) -> Result; + fn deserialize<'a, T: Into<&'a str>>(s: T) -> Result; } impl GstValueExt for glib::Value { @@ -877,11 +877,14 @@ impl GstValueExt for glib::Value { } } - fn serialize(&self) -> Option { - unsafe { from_glib_full(gst_sys::gst_value_serialize(self.to_glib_none().0)) } + fn serialize(&self) -> Result { + unsafe { + Option::<_>::from_glib_full(gst_sys::gst_value_serialize(self.to_glib_none().0)) + .ok_or_else(|| glib_bool_error!("Failed to serialize value")) + } } - fn deserialize<'a, T: Into<&'a str>>(s: T) -> Option { + fn deserialize<'a, T: Into<&'a str>>(s: T) -> Result { assert_initialized_main_thread!(); let s = s.into(); @@ -893,9 +896,9 @@ impl GstValueExt for glib::Value { s.to_glib_none().0, )); if ret { - Some(value) + Ok(value) } else { - None + Err(glib_bool_error!("Failed to deserialize value")) } } } diff --git a/tutorials/src/bin/basic-tutorial-12.rs b/tutorials/src/bin/basic-tutorial-12.rs index c35952140..2193fc6c6 100644 --- a/tutorials/src/bin/basic-tutorial-12.rs +++ b/tutorials/src/bin/basic-tutorial-12.rs @@ -76,7 +76,8 @@ fn tutorial_main() -> Result<(), Error> { _ => (), } glib::Continue(true) - }); + }) + .expect("Failed to add bus watch"); main_loop.run(); diff --git a/tutorials/src/bin/basic-tutorial-8.rs b/tutorials/src/bin/basic-tutorial-8.rs index 030f574f9..8636698a7 100644 --- a/tutorials/src/bin/basic-tutorial-8.rs +++ b/tutorials/src/bin/basic-tutorial-8.rs @@ -231,7 +231,7 @@ fn main() { data.appsink.clone() }; - if let Some(_sample) = appsink.pull_sample() { + if let Ok(_sample) = appsink.pull_sample() { use std::io::{self, Write}; // The only thing we do in this example is print a * to indicate a received buffer print!("*"); diff --git a/tutorials/src/bin/basic-tutorial-9.rs b/tutorials/src/bin/basic-tutorial-9.rs index a1a3306ba..735bcd004 100644 --- a/tutorials/src/bin/basic-tutorial-9.rs +++ b/tutorials/src/bin/basic-tutorial-9.rs @@ -17,8 +17,8 @@ mod tutorials_common; fn send_value_as_str(v: &glib::SendValue) -> Option { if let Ok(Some(s)) = v.get::<&str>() { Some(s.to_string()) - } else if let Some(serialized) = v.serialize() { - Some(serialized) + } else if let Ok(serialized) = v.serialize() { + Some(serialized.into()) } else { None }