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
This commit is contained in:
Sebastian Dröge 2019-12-17 21:00:42 +02:00
parent 68c48c1984
commit be3c378f28
99 changed files with 916 additions and 445 deletions

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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<ClockSuccess, ClockError>
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<FlowSuccess, FlowError>
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"

View file

@ -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"
bool_return_is_error = "Failed to remove control binding"

View file

@ -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]

View file

@ -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

View file

@ -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"

View file

@ -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"

View file

@ -55,9 +55,9 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
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<gst::Pipeline, Error> {
// 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<gst::Pipeline, Error> {
// 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,

View file

@ -52,11 +52,11 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
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])?;

View file

@ -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)?;

View file

@ -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

View file

@ -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

View file

@ -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::<gst_app::AppSink>()
.expect("Sink element is expected to be an appsink!");

View file

@ -31,7 +31,7 @@ fn create_ui(app: &gtk::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: &gtk::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

View file

@ -248,7 +248,8 @@ fn create_ui(app: &gtk::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

View file

@ -57,7 +57,8 @@ fn example_main() {
};
glib::Continue(true)
});
})
.expect("Failed to add bus watch");
main_loop.run();

View file

@ -78,16 +78,16 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
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])?;

View file

@ -117,7 +117,8 @@ fn example_main() {
};
glib::Continue(true)
});
})
.expect("Failed to add bus watch");
main_loop.run();

View file

@ -50,8 +50,8 @@ fn make_element(
element_name: Option<&str>,
) -> Result<gst::Element, Error> {
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))),
}
}

View file

@ -47,8 +47,8 @@ fn make_element(
element_name: Option<&str>,
) -> Result<gst::Element, Error> {
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))),
}
}

View file

@ -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<gst::Pipeline, Error> {
// 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)?;

View file

@ -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");

View file

@ -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<gst::Sample> {
pub fn pull_preroll(&self) -> Result<gst::Sample, glib::BoolError> {
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<gst::Sample> {
unsafe { from_glib_full(gst_app_sys::gst_app_sink_pull_sample(self.to_glib_none().0)) }
pub fn pull_sample(&self) -> Result<gst::Sample, glib::BoolError> {
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"))]

View file

@ -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)

View file

@ -47,9 +47,9 @@ impl ::AudioFormat {
}
impl str::FromStr for ::AudioFormat {
type Err = ();
type Err = glib::BoolError;
fn from_str(s: &str) -> Result<Self, ()> {
fn from_str(s: &str) -> Result<Self, glib::BoolError> {
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)
}

View file

@ -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<Self, ()> {
fn from_str(s: &str) -> Result<Self, glib::BoolError> {
skip_assert_initialized!();
let format = s.parse()?;
Ok(AudioFormatInfo::from_format(format))

View file

@ -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<gst::Buffer>;
fn allocate_output_buffer(&self, size: usize) -> Result<gst::Buffer, glib::BoolError>;
fn get_audio_info(&self) -> Option<AudioInfo>;
@ -99,12 +100,13 @@ pub trait AudioDecoderExt: 'static {
}
impl<O: IsA<AudioDecoder>> AudioDecoderExt for O {
fn allocate_output_buffer(&self, size: usize) -> Option<gst::Buffer> {
fn allocate_output_buffer(&self, size: usize) -> Result<gst::Buffer, glib::BoolError> {
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"))
}
}

View file

@ -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<gst::Buffer>;
fn allocate_output_buffer(&self, size: usize) -> Result<gst::Buffer, glib::BoolError>;
fn get_audio_info(&self) -> Option<AudioInfo>;
@ -105,12 +106,13 @@ pub trait AudioEncoderExt: 'static {
}
impl<O: IsA<AudioEncoder>> AudioEncoderExt for O {
fn allocate_output_buffer(&self, size: usize) -> Option<gst::Buffer> {
fn allocate_output_buffer(&self, size: usize) -> Result<gst::Buffer, glib::BoolError> {
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"))
}
}

View file

@ -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)

View file

@ -81,7 +81,7 @@ impl UniqueAdapter {
self.0.clear();
}
pub fn copy_bytes(&self, offset: usize, size: usize) -> Option<glib::Bytes> {
pub fn copy_bytes(&self, offset: usize, size: usize) -> Result<glib::Bytes, glib::BoolError> {
self.0.copy_bytes(offset, size)
}
@ -98,15 +98,15 @@ impl UniqueAdapter {
self.0.flush(flush);
}
pub fn get_buffer(&self, nbytes: usize) -> Option<gst::Buffer> {
pub fn get_buffer(&self, nbytes: usize) -> Result<gst::Buffer, glib::BoolError> {
self.0.get_buffer(nbytes)
}
pub fn get_buffer_fast(&self, nbytes: usize) -> Option<gst::Buffer> {
pub fn get_buffer_fast(&self, nbytes: usize) -> Result<gst::Buffer, glib::BoolError> {
self.0.get_buffer_fast(nbytes)
}
pub fn get_buffer_list(&self, nbytes: usize) -> Option<gst::BufferList> {
pub fn get_buffer_list(&self, nbytes: usize) -> Result<gst::BufferList, glib::BoolError> {
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<gst::Buffer> {
pub fn take_buffer(&mut self, nbytes: usize) -> Result<gst::Buffer, glib::BoolError> {
self.0.take_buffer(nbytes)
}
pub fn take_buffer_fast(&mut self, nbytes: usize) -> Option<gst::Buffer> {
pub fn take_buffer_fast(&mut self, nbytes: usize) -> Result<gst::Buffer, glib::BoolError> {
self.0.take_buffer_fast(nbytes)
}
pub fn take_buffer_list(&mut self, nbytes: usize) -> Option<gst::BufferList> {
pub fn take_buffer_list(&mut self, nbytes: usize) -> Result<gst::BufferList, glib::BoolError> {
self.0.take_buffer_list(nbytes)
}

View file

@ -37,13 +37,14 @@ impl Adapter {
}
}
pub fn copy_bytes(&self, offset: usize, size: usize) -> Option<glib::Bytes> {
pub fn copy_bytes(&self, offset: usize, size: usize) -> Result<glib::Bytes, glib::BoolError> {
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<gst::Buffer> {
pub fn get_buffer(&self, nbytes: usize) -> Result<gst::Buffer, glib::BoolError> {
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<gst::Buffer> {
pub fn get_buffer_fast(&self, nbytes: usize) -> Result<gst::Buffer, glib::BoolError> {
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<gst::BufferList> {
pub fn get_buffer_list(&self, nbytes: usize) -> Result<gst::BufferList, glib::BoolError> {
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<gst::Buffer> {
pub fn take_buffer(&self, nbytes: usize) -> Result<gst::Buffer, glib::BoolError> {
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<gst::Buffer> {
pub fn take_buffer_fast(&self, nbytes: usize) -> Result<gst::Buffer, glib::BoolError> {
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<gst::BufferList> {
pub fn take_buffer_list(&self, nbytes: usize) -> Result<gst::BufferList, glib::BoolError> {
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"))
}
}

View file

@ -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<O: IsA<BaseSink>> 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(

View file

@ -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<O: IsA<BaseSrc>> 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());

View file

@ -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<P: IsA<gst::Pad>>(src: &P, size: u64) -> Option<gst::Caps> {
pub fn type_find_helper<P: IsA<gst::Pad>>(
src: &P,
size: u64,
) -> Result<gst::Caps, glib::BoolError> {
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<P: IsA<gst::Object>>(
obj: Option<&P>,
extension: &str,
) -> Option<gst::Caps> {
) -> Result<gst::Caps, glib::BoolError> {
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"))
}
}

View file

@ -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)

View file

@ -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::ClockSuccess, gst::ClockError>,
gst::ClockTimeDiff,
);
fn query_latency(
&self,
) -> Result<(bool, bool, gst::ClockTime, gst::ClockTime), glib::BoolError>;
}
impl<O: IsA<BaseSink>> BaseSinkExtManual for O {
@ -80,4 +85,36 @@ impl<O: IsA<BaseSink>> 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"))
}
}
}
}

View file

@ -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<gst::FlowSuccess, gst::FlowError>;
fn wait_playing(&self) -> Result<gst::FlowSuccess, gst::FlowError>;
fn query_latency(&self) -> Result<(bool, gst::ClockTime, gst::ClockTime), glib::BoolError>;
}
impl<O: IsA<BaseSrc>> BaseSrcExtManual for O {
@ -58,4 +61,30 @@ impl<O: IsA<BaseSrc>> 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"))
}
}
}
}

View file

@ -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)

View file

@ -197,12 +197,13 @@ impl Harness {
}
}
pub fn create_buffer(&mut self, size: usize) -> Option<gst::Buffer> {
pub fn create_buffer(&mut self, size: usize) -> Result<gst::Buffer, glib::BoolError> {
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<gst::Buffer> {
unsafe { from_glib_full(gst_check_sys::gst_harness_pull(self.0.as_ptr())) }
}
pub fn pull_event(&mut self) -> Option<gst::Event> {
unsafe { from_glib_full(gst_check_sys::gst_harness_pull_event(self.0.as_ptr())) }
}
pub fn pull_upstream_event(&mut self) -> Option<gst::Event> {
pub fn pull(&mut self) -> Result<gst::Buffer, glib::BoolError> {
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<gst::Event, glib::BoolError> {
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<gst::Event, glib::BoolError> {
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<gst::Buffer> {
pub fn push_and_pull(&mut self, buffer: gst::Buffer) -> Result<gst::Buffer, glib::BoolError> {
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<gst::Buffer> {
pub fn take_all_data_as_buffer(&mut self) -> Result<gst::Buffer, glib::BoolError> {
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<glib::Bytes> {
pub fn take_all_data_as_bytes(&mut self) -> Result<glib::Bytes, glib::BoolError> {
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());
}
}

View file

@ -33,7 +33,7 @@ glib_wrapper! {
pub const NONE_CLIP: Option<&Clip> = None;
pub trait ClipExt: 'static {
fn add_asset<P: IsA<Asset>>(&self, asset: &P) -> Option<TrackElement>;
fn add_asset<P: IsA<Asset>>(&self, asset: &P) -> Result<TrackElement, glib::BoolError>;
fn find_track_element<P: IsA<Track>>(
&self,
@ -74,7 +74,7 @@ pub trait ClipExt: 'static {
newpriority: u32,
) -> Result<(), glib::error::BoolError>;
fn split(&self, position: u64) -> Option<Clip>;
fn split(&self, position: u64) -> Result<Clip, glib::BoolError>;
fn connect_property_layer_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
@ -85,12 +85,13 @@ pub trait ClipExt: 'static {
}
impl<O: IsA<Clip>> ClipExt for O {
fn add_asset<P: IsA<Asset>>(&self, asset: &P) -> Option<TrackElement> {
fn add_asset<P: IsA<Asset>>(&self, asset: &P) -> Result<TrackElement, glib::BoolError> {
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<O: IsA<Clip>> ClipExt for O {
}
}
fn split(&self, position: u64) -> Option<Clip> {
fn split(&self, position: u64) -> Result<Clip, glib::BoolError> {
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"))
}
}

View file

@ -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<Effect> {
pub fn new(bin_description: &str) -> Result<Effect, glib::BoolError> {
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"))
}
}
}

View file

@ -50,7 +50,7 @@ pub trait LayerExt: 'static {
inpoint: gst::ClockTime,
duration: gst::ClockTime,
track_types: TrackType,
) -> Option<Clip>;
) -> Result<Clip, glib::BoolError>;
fn add_clip<P: IsA<Clip>>(&self, clip: &P) -> Result<(), glib::error::BoolError>;
@ -98,9 +98,9 @@ impl<O: IsA<Layer>> LayerExt for O {
inpoint: gst::ClockTime,
duration: gst::ClockTime,
track_types: TrackType,
) -> Option<Clip> {
) -> Result<Clip, glib::BoolError> {
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<O: IsA<Layer>> LayerExt for O {
duration.to_glib(),
track_types.to_glib(),
))
.ok_or_else(|| glib_bool_error!("Failed to add asset"))
}
}

View file

@ -34,7 +34,7 @@ pub const NONE_TIMELINE_ELEMENT: Option<&TimelineElement> = None;
pub trait TimelineElementExt: 'static {
//fn add_child_property<P: IsA<glib::Object>>(&self, pspec: /*Ignored*/&glib::ParamSpec, child: &P) -> bool;
fn copy(&self, deep: bool) -> Option<TimelineElement>;
fn copy(&self, deep: bool) -> Result<TimelineElement, glib::BoolError>;
//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<glib::Object>;
fn paste(&self, paste_position: gst::ClockTime) -> Option<TimelineElement>;
fn paste(&self, paste_position: gst::ClockTime) -> Result<TimelineElement, glib::BoolError>;
//fn remove_child_property(&self, pspec: /*Ignored*/&glib::ParamSpec) -> bool;
@ -145,12 +145,13 @@ impl<O: IsA<TimelineElement>> TimelineElementExt for O {
// unsafe { TODO: call ges_sys:ges_timeline_element_add_child_property() }
//}
fn copy(&self, deep: bool) -> Option<TimelineElement> {
fn copy(&self, deep: bool) -> Result<TimelineElement, glib::BoolError> {
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<O: IsA<TimelineElement>> TimelineElementExt for O {
// unsafe { TODO: call ges_sys:ges_timeline_element_lookup_child() }
//}
fn paste(&self, paste_position: gst::ClockTime) -> Option<TimelineElement> {
fn paste(&self, paste_position: gst::ClockTime) -> Result<TimelineElement, glib::BoolError> {
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<O: IsA<TimelineElement>> 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"
)
}
}

View file

@ -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<UriClip> {
pub fn new(uri: &str) -> Result<UriClip, glib::BoolError> {
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"))
}
}
}

View file

@ -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)

View file

@ -53,7 +53,7 @@ pub trait GLDisplayExt: 'static {
other_context: &P,
) -> Result<GLContext, glib::Error>;
fn create_window(&self) -> Option<GLWindow>;
fn create_window(&self) -> Result<GLWindow, glib::BoolError>;
fn filter_gl_api(&self, gl_api: GLAPI);
@ -105,11 +105,12 @@ impl<O: IsA<GLDisplay>> GLDisplayExt for O {
}
}
fn create_window(&self) -> Option<GLWindow> {
fn create_window(&self) -> Result<GLWindow, glib::BoolError> {
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"))
}
}

View file

@ -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)

View file

@ -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::<NativeEndian>().ok()?;
Some(*id)

View file

@ -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)

View file

@ -160,21 +160,26 @@ impl DiscovererInfo {
}
}
pub fn to_variant(&self, flags: DiscovererSerializeFlags) -> Option<glib::Variant> {
pub fn to_variant(
&self,
flags: DiscovererSerializeFlags,
) -> Result<glib::Variant, glib::BoolError> {
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<DiscovererInfo> {
pub fn from_variant(variant: &glib::Variant) -> Result<DiscovererInfo, glib::BoolError> {
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"))
}
}
}

View file

@ -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<EncodingProfile> {
pub fn from_discoverer(info: &DiscovererInfo) -> Result<EncodingProfile, glib::BoolError> {
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"))
}
}
}

View file

@ -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<GString> {
}
}
pub fn pb_utils_get_element_description(factory_name: &str) -> Option<GString> {
pub fn pb_utils_get_element_description(factory_name: &str) -> Result<GString, glib::BoolError> {
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<GString> {
pub fn pb_utils_get_sink_description(protocol: &str) -> Result<GString, glib::BoolError> {
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<GString> {
pub fn pb_utils_get_source_description(protocol: &str) -> Result<GString, glib::BoolError> {
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<GString> {
pub fn plugins_base_version_string() -> GString {
assert_initialized_main_thread!();
unsafe { from_glib_full(gst_pbutils_sys::gst_plugins_base_version_string()) }
}

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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<gst::Buffer>;
fn new_rtp_with_sizes(
payload_len: u32,
pad_len: u8,
csrc_count: u8,
) -> Result<gst::Buffer, glib::BoolError>;
}
impl RTPBufferExt for gst::Buffer {
fn new_rtp_with_sizes(payload_len: u32, pad_len: u8, csrc_count: u8) -> Option<gst::Buffer> {
fn new_rtp_with_sizes(
payload_len: u32,
pad_len: u8,
csrc_count: u8,
) -> Result<gst::Buffer, glib::BoolError> {
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"))
}
}
}

View file

@ -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<RTSPAddress>;
fn acquire_address(
&self,
flags: RTSPAddressFlags,
n_ports: i32,
) -> Result<RTSPAddress, glib::BoolError>;
fn add_range(
&self,
@ -55,13 +59,18 @@ pub trait RTSPAddressPoolExt: 'static {
}
impl<O: IsA<RTSPAddressPool>> RTSPAddressPoolExt for O {
fn acquire_address(&self, flags: RTSPAddressFlags, n_ports: i32) -> Option<RTSPAddress> {
fn acquire_address(
&self,
flags: RTSPAddressFlags,
n_ports: i32,
) -> Result<RTSPAddress, glib::BoolError> {
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"))
}
}

View file

@ -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<RTSPMedia>;
fn construct(&self, url: &gst_rtsp::RTSPUrl) -> Result<RTSPMedia, glib::BoolError>;
fn create_element(&self, url: &gst_rtsp::RTSPUrl) -> Option<gst::Element>;
fn create_element(&self, url: &gst_rtsp::RTSPUrl) -> Result<gst::Element, glib::BoolError>;
fn get_address_pool(&self) -> Option<RTSPAddressPool>;
@ -238,21 +238,23 @@ impl<O: IsA<RTSPMediaFactory>> RTSPMediaFactoryExt for O {
// unsafe { TODO: call gst_rtsp_server_sys:gst_rtsp_media_factory_add_role() }
//}
fn construct(&self, url: &gst_rtsp::RTSPUrl) -> Option<RTSPMedia> {
fn construct(&self, url: &gst_rtsp::RTSPUrl) -> Result<RTSPMedia, glib::BoolError> {
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<gst::Element> {
fn create_element(&self, url: &gst_rtsp::RTSPUrl) -> Result<gst::Element, glib::BoolError> {
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"))
}
}

View file

@ -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<P: IsA<RTSPMediaFactory>>(&self, path: &str, factory: &P);
fn make_path(&self, url: &gst_rtsp::RTSPUrl) -> Option<GString>;
fn make_path(&self, url: &gst_rtsp::RTSPUrl) -> Result<GString, glib::BoolError>;
fn match_(&self, path: &str) -> (RTSPMediaFactory, i32);
@ -57,12 +58,13 @@ impl<O: IsA<RTSPMountPoints>> RTSPMountPointsExt for O {
}
}
fn make_path(&self, url: &gst_rtsp::RTSPUrl) -> Option<GString> {
fn make_path(&self, url: &gst_rtsp::RTSPUrl) -> Result<GString, glib::BoolError> {
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"))
}
}

View file

@ -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<P: IsA<RTSPMedia>>(&self, path: &str, media: &P) -> Option<RTSPSessionMedia>;
fn manage_media<P: IsA<RTSPMedia>>(
&self,
path: &str,
media: &P,
) -> Result<RTSPSessionMedia, glib::BoolError>;
//fn next_timeout(&self, now: /*Ignored*/&mut glib::TimeVal) -> i32;
@ -190,13 +195,18 @@ impl<O: IsA<RTSPSession>> RTSPSessionExt for O {
}
}
fn manage_media<P: IsA<RTSPMedia>>(&self, path: &str, media: &P) -> Option<RTSPSessionMedia> {
fn manage_media<P: IsA<RTSPMedia>>(
&self,
path: &str,
media: &P,
) -> Result<RTSPSessionMedia, glib::BoolError> {
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"))
}
}

View file

@ -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<RTSPSession>;
fn create(&self) -> Result<RTSPSession, glib::BoolError>;
fn filter(
&self,
@ -79,11 +79,12 @@ impl<O: IsA<RTSPSessionPool>> RTSPSessionPoolExt for O {
}
}
fn create(&self) -> Option<RTSPSession> {
fn create(&self) -> Result<RTSPSession, glib::BoolError> {
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"))
}
}

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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<gst::Buffer>;
fn allocate_output_buffer(&self) -> Result<gst::Buffer, glib::BoolError>;
fn get_buffer_pool(&self) -> Option<gst::BufferPool>;
@ -64,11 +65,12 @@ impl<O: IsA<VideoDecoder>> VideoDecoderExt for O {
}
}
fn allocate_output_buffer(&self) -> Option<gst::Buffer> {
fn allocate_output_buffer(&self) -> Result<gst::Buffer, glib::BoolError> {
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"))
}
}

View file

@ -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<gst::Buffer>;
fn allocate_output_buffer(&self, size: usize) -> Result<gst::Buffer, glib::BoolError>;
#[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<O: IsA<VideoEncoder>> VideoEncoderExt for O {
fn allocate_output_buffer(&self, size: usize) -> Option<gst::Buffer> {
fn allocate_output_buffer(&self, size: usize) -> Result<gst::Buffer, glib::BoolError> {
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"))
}
}

View file

@ -90,9 +90,9 @@ impl ::VideoFormat {
}
impl str::FromStr for ::VideoFormat {
type Err = ();
type Err = glib::BoolError;
fn from_str(s: &str) -> Result<Self, ()> {
fn from_str(s: &str) -> Result<Self, glib::BoolError> {
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)
}

View file

@ -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<Self, ()> {
fn from_str(s: &str) -> Result<Self, glib::BoolError> {
skip_assert_initialized!();
let format = s.parse()?;
Ok(VideoFormatInfo::from_format(format))

View file

@ -139,9 +139,9 @@ impl<T> VideoFrame<T> {
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<T> VideoFrame<T> {
// 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<T> VideoFrame<T> {
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<Writable> {
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<Writable> {
// 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<Writable> {
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<VideoFrameRef<&'a gst::BufferRef>> {
) -> Result<VideoFrameRef<&'a gst::BufferRef>, 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<VideoFrameRef<&'a gst::BufferRef>> {
) -> Result<VideoFrameRef<&'a gst::BufferRef>, 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<VideoFrameRef<&'a mut gst::BufferRef>> {
) -> Result<VideoFrameRef<&'a mut gst::BufferRef>, 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<VideoFrameRef<&'a mut gst::BufferRef>> {
) -> Result<VideoFrameRef<&'a mut gst::BufferRef>, 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);
}
}

View file

@ -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)

View file

@ -18,11 +18,19 @@ use Allocator;
use Memory;
pub trait AllocatorExtManual: 'static {
fn alloc(&self, size: usize, params: Option<&AllocationParams>) -> Option<Memory>;
fn alloc(
&self,
size: usize,
params: Option<&AllocationParams>,
) -> Result<Memory, glib::BoolError>;
}
impl<O: IsA<Allocator>> AllocatorExtManual for O {
fn alloc(&self, size: usize, params: Option<&AllocationParams>) -> Option<Memory> {
fn alloc(
&self,
size: usize,
params: Option<&AllocationParams>,
) -> Result<Memory, glib::BoolError> {
unsafe {
let ret = gst_sys::gst_allocator_alloc(
self.as_ptr() as *mut _,
@ -33,9 +41,9 @@ impl<O: IsA<Allocator>> 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))
}
}
}

View file

@ -36,7 +36,7 @@ impl DateTime {
}
}
pub fn new_from_g_date_time(dt: &glib::DateTime) -> Option<DateTime> {
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<DateTime> {
pub fn new_from_iso8601_string(string: &str) -> Result<DateTime, glib::BoolError> {
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<glib::DateTime> {
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<GString> {
pub fn to_g_date_time(&self) -> Result<glib::DateTime, glib::BoolError> {
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<GString, glib::BoolError> {
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"))
}
}
}

View file

@ -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<Element>;
fn create_element(&self, name: Option<&str>) -> Result<Element, glib::BoolError>;
fn get_caps(&self) -> Option<Caps>;
@ -55,12 +55,13 @@ pub trait DeviceExt: 'static {
}
impl<O: IsA<Device>> DeviceExt for O {
fn create_element(&self, name: Option<&str>) -> Option<Element> {
fn create_element(&self, name: Option<&str>) -> Result<Element, glib::BoolError> {
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"))
}
}

View file

@ -61,12 +61,13 @@ impl ElementFactory {
}
}
pub fn create(&self, name: Option<&str>) -> Option<Element> {
pub fn create(&self, name: Option<&str>) -> Result<Element, glib::BoolError> {
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<Element> {
pub fn make(factoryname: &str, name: Option<&str>) -> Result<Element, glib::BoolError> {
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"))
}
}
}

View file

@ -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<GString> {
pub fn debug_get_stack_trace(flags: StackTraceFlags) -> Result<GString, glib::BoolError> {
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<GString> {
pub fn get_main_executable_path() -> Result<GString, glib::BoolError> {
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(

View file

@ -22,7 +22,10 @@ glib_wrapper! {
}
impl GhostPad {
pub fn new_no_target(name: Option<&str>, dir: PadDirection) -> Option<GhostPad> {
pub fn new_no_target(
name: Option<&str>,
dir: PadDirection,
) -> Result<GhostPad, glib::BoolError> {
assert_initialized_main_thread!();
unsafe {
Option::<Pad>::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<GhostPad> {
) -> Result<GhostPad, glib::BoolError> {
skip_assert_initialized!();
unsafe {
Option::<Pad>::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"))
}
}
}

View file

@ -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<PadTemplate> {
) -> Result<PadTemplate, glib::BoolError> {
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<PadTemplate> {
) -> Result<PadTemplate, glib::BoolError> {
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"))
}
}

View file

@ -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<Plugin> {
unsafe { from_glib_full(gst_sys::gst_plugin_load(self.to_glib_none().0)) }
pub fn load(&self) -> Result<Plugin, glib::BoolError> {
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<Plugin> {
pub fn load_by_name(name: &str) -> Result<Plugin, glib::BoolError> {
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<P: AsRef<std::path::Path>>(filename: P) -> Result<Plugin, glib::Error> {

View file

@ -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<GString>;
fn load(&self) -> Option<PluginFeature>;
fn load(&self) -> Result<PluginFeature, glib::BoolError>;
}
impl<O: IsA<PluginFeature>> PluginFeatureExt for O {
@ -60,11 +61,12 @@ impl<O: IsA<PluginFeature>> PluginFeatureExt for O {
}
}
fn load(&self) -> Option<PluginFeature> {
fn load(&self) -> Result<PluginFeature, glib::BoolError> {
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"))
}
}
}

View file

@ -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)

View file

@ -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<Self> {
pub fn with_size(size: usize) -> Result<Self, glib::BoolError> {
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<BufferMap<Readable>> {
pub fn map_readable(&self) -> Result<BufferMap<Readable>, 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<BufferMap<Writable>> {
pub fn map_writable(&mut self) -> Result<BufferMap<Writable>, 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<usize>,
) -> Option<Buffer> {
) -> Result<Buffer, glib::BoolError> {
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<Buffer> {
unsafe { from_glib_full(gst_sys::gst_buffer_copy_deep(self.as_ptr())) }
pub fn copy_deep(&self) -> Result<Buffer, glib::BoolError> {
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,
}
}

View file

@ -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()

View file

@ -108,7 +108,7 @@ impl Bus {
}
}
pub fn add_watch<F>(&self, func: F) -> Option<SourceId>
pub fn add_watch<F>(&self, func: F) -> Result<SourceId, glib::BoolError>
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<F>(&self, func: F) -> Option<SourceId>
pub fn add_watch_local<F>(&self, func: F) -> Result<SourceId, glib::BoolError>
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))
}
}
}

View file

@ -106,13 +106,13 @@ impl Caps {
}
impl str::FromStr for Caps {
type Err = ();
type Err = glib::BoolError;
fn from_str(s: &str) -> Result<Self, ()> {
fn from_str(s: &str) -> Result<Self, glib::BoolError> {
assert_initialized_main_thread!();
unsafe {
Option::<Caps>::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"))
}
}
}

View file

@ -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<Self, ()> {
fn from_str(s: &str) -> Result<Self, glib::BoolError> {
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(

View file

@ -227,7 +227,11 @@ impl Clock {
}
pub trait ClockExtManual: 'static {
fn new_periodic_id(&self, start_time: ClockTime, interval: ClockTime) -> Option<ClockId>;
fn new_periodic_id(
&self,
start_time: ClockTime,
interval: ClockTime,
) -> Result<ClockId, glib::BoolError>;
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<ClockId>;
fn new_single_shot_id(&self, time: ClockTime) -> Result<ClockId, glib::BoolError>;
fn single_shot_id_reinit(&self, id: &ClockId, time: ClockTime) -> Result<(), glib::BoolError>;
@ -248,13 +252,18 @@ pub trait ClockExtManual: 'static {
}
impl<O: IsA<Clock>> ClockExtManual for O {
fn new_periodic_id(&self, start_time: ClockTime, interval: ClockTime) -> Option<ClockId> {
fn new_periodic_id(
&self,
start_time: ClockTime,
interval: ClockTime,
) -> Result<ClockId, glib::BoolError> {
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<O: IsA<Clock>> ClockExtManual for O {
}
}
fn new_single_shot_id(&self, time: ClockTime) -> Option<ClockId> {
fn new_single_shot_id(&self, time: ClockTime) -> Result<ClockId, glib::BoolError> {
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"))
}
}

View file

@ -13,10 +13,10 @@ use DateTime;
impl DateTime {
/// Get the [`DateTime`](struct.DateTime.html) in UTC
pub fn to_utc(&self) -> Option<DateTime> {
pub fn to_utc(&self) -> Result<DateTime, glib::BoolError> {
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(),
)
}

View file

@ -17,7 +17,7 @@ use PadMode;
use PadTemplate;
impl GhostPad {
pub fn new<Q: IsA<Pad>>(name: Option<&str>, target: &Q) -> Option<GhostPad> {
pub fn new<Q: IsA<Pad>>(name: Option<&str>, target: &Q) -> Result<GhostPad, glib::BoolError> {
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<GhostPad> {
) -> Result<GhostPad, glib::BoolError> {
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"))
}
}

View file

@ -246,7 +246,7 @@ impl MemoryRef {
}
}
pub fn map_readable(&self) -> Option<MemoryMap<Readable>> {
pub fn map_readable(&self) -> Result<MemoryMap<Readable>, 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<MemoryMap<Writable>> {
pub fn map_writable(&mut self) -> Result<MemoryMap<Writable>, 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"))
}
}
}

View file

@ -22,15 +22,16 @@ impl PadTemplate {
pub fn new_from_static_pad_template_with_gtype(
pad_template: &StaticPadTemplate,
pad_type: glib::types::Type,
) -> Option<PadTemplate> {
) -> Result<PadTemplate, glib::BoolError> {
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"))
}
}
}

View file

@ -188,14 +188,14 @@ impl PartialEq<StructureRef> for Structure {
impl Eq for Structure {}
impl str::FromStr for Structure {
type Err = ();
type Err = glib::BoolError;
fn from_str(s: &str) -> Result<Self, ()> {
fn from_str(s: &str) -> Result<Self, glib::BoolError> {
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),

View file

@ -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<Element> {
fn create_element(
&self,
device: &Device,
name: Option<&str>,
) -> Result<Element, LoggableError> {
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<Element>;
fn parent_create_element(
&self,
device: &Device,
name: Option<&str>,
) -> Result<Element, LoggableError>;
fn parent_reconfigure_element(
&self,
@ -41,7 +49,11 @@ pub trait DeviceImplExt {
}
impl<T: DeviceImpl + ObjectImpl> DeviceImplExt for T {
fn parent_create_element(&self, device: &Device, name: Option<&str>) -> Option<Element> {
fn parent_create_element(
&self,
device: &Device,
name: Option<&str>,
) -> Result<Element, LoggableError> {
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<T: DeviceImpl + ObjectImpl> 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()
}
}
}

View file

@ -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<Self>;
fn is_fixed(&self) -> bool;
fn is_subset(&self, superset: &Self) -> bool;
fn serialize(&self) -> Option<String>;
fn deserialize<'a, T: Into<&'a str>>(s: T) -> Option<glib::Value>;
fn serialize(&self) -> Result<glib::GString, glib::BoolError>;
fn deserialize<'a, T: Into<&'a str>>(s: T) -> Result<glib::Value, glib::BoolError>;
}
impl GstValueExt for glib::Value {
@ -877,11 +877,14 @@ impl GstValueExt for glib::Value {
}
}
fn serialize(&self) -> Option<String> {
unsafe { from_glib_full(gst_sys::gst_value_serialize(self.to_glib_none().0)) }
fn serialize(&self) -> Result<glib::GString, glib::BoolError> {
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<glib::Value> {
fn deserialize<'a, T: Into<&'a str>>(s: T) -> Result<glib::Value, glib::BoolError> {
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"))
}
}
}

View file

@ -76,7 +76,8 @@ fn tutorial_main() -> Result<(), Error> {
_ => (),
}
glib::Continue(true)
});
})
.expect("Failed to add bus watch");
main_loop.run();

View file

@ -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!("*");

View file

@ -17,8 +17,8 @@ mod tutorials_common;
fn send_value_as_str(v: &glib::SendValue) -> Option<String> {
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
}