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" name = "Gst.ElementFactory"
status = "generate" status = "generate"
final_type = true 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]] [[object]]
name = "Gst.TypeFindFactory" name = "Gst.TypeFindFactory"
@ -618,6 +627,11 @@ status = "generate"
[object.function.return] [object.function.return]
bool_return_is_error = "Failed to reconfigure the element to use this device" 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]] [[object]]
name = "Gst.Object" name = "Gst.Object"
# For renaming the trait... # For renaming the trait...
@ -851,6 +865,16 @@ status = "generate"
name = "Gst.PadTemplate" name = "Gst.PadTemplate"
status = "generate" status = "generate"
final_type = true 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]] [[object.function]]
name = "new_from_static_pad_template_with_gtype" name = "new_from_static_pad_template_with_gtype"
# static pad template manual # static pad template manual
@ -872,6 +896,16 @@ status = "generate"
name = "new_from_template" name = "new_from_template"
ignore = true 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]] [[object.function]]
name = "construct" name = "construct"
ignore = true ignore = true
@ -988,6 +1022,16 @@ final_type = true
[object.function.return] [object.function.return]
nullable = false 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]] [[object]]
name = "Gst.PluginFeature" name = "Gst.PluginFeature"
status = "generate" status = "generate"
@ -1007,6 +1051,11 @@ status = "generate"
name = "set_rank" name = "set_rank"
ignore = true ignore = true
[[object.function]]
name = "load"
[object.function.return]
nullable_return_is_error = "Failed to load plugin feature"
[[object]] [[object]]
name = "Gst.Registry" name = "Gst.Registry"
status = "generate" status = "generate"
@ -1338,6 +1387,16 @@ status = "generate"
# Already a Result # Already a Result
nullable = false 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]] [[object]]
name = "Gst.StateChangeReturn" name = "Gst.StateChangeReturn"
status = "generate" status = "generate"
@ -1364,3 +1423,23 @@ status = "generate"
[[object.derive]] [[object.derive]]
# Don't auto-implement traits # Don't auto-implement traits
name = "" 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]] [[object.function]]
name = "set_caps" name = "set_caps"
[[object.function.parameter]] [[object.function.parameter]]
name = "caps" name = "caps"
nullable = true 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]] [[object]]
name = "GstApp.AppSrc" name = "GstApp.AppSrc"

View file

@ -168,6 +168,11 @@ status = "generate"
[object.function.return] [object.function.return]
nullable = false nullable = false
[[object.function]]
name = "allocate_output_buffer"
[object.function.return]
nullable_return_is_error = "Failed to allocate output buffer"
[[object]] [[object]]
name = "GstAudio.AudioEncoder" name = "GstAudio.AudioEncoder"
status = "generate" status = "generate"
@ -196,3 +201,8 @@ status = "generate"
name = "proxy_getcaps" name = "proxy_getcaps"
[object.function.return] [object.function.return]
nullable = false 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 # Useless copying of data
ignore = true 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]] [[object]]
name = "GstBase.FlowCombiner" name = "GstBase.FlowCombiner"
# Manual because ref/unref functions were added much later # Manual because ref/unref functions were added much later
@ -94,6 +129,11 @@ status = "generate"
# Use Result<ClockSuccess, ClockError> # Use Result<ClockSuccess, ClockError>
ignore = true ignore = true
[[object.function]]
name = "query_latency"
# Use Result
ignore = true
[[object]] [[object]]
name = "GstBase.BaseSrc" name = "GstBase.BaseSrc"
status = "generate" status = "generate"
@ -123,6 +163,11 @@ status = "generate"
# Use Result<FlowSuccess, FlowError> # Use Result<FlowSuccess, FlowError>
ignore = true ignore = true
[[object.function]]
name = "query_latency"
# Use Result
ignore = true
[[object]] [[object]]
name = "GstBase.BaseTransform" name = "GstBase.BaseTransform"
status = "generate" status = "generate"
@ -185,6 +230,16 @@ status = "generate"
# broken return value # broken return value
ignore = true 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]] [[object]]
name = "Gst.Structure" name = "Gst.Structure"
status = "manual" status = "manual"

View file

@ -40,11 +40,9 @@ generate = [
"GES.EditMode", "GES.EditMode",
"GES.PipelineFlags", "GES.PipelineFlags",
"GES.Edge", "GES.Edge",
"GES.Effect",
"GES.TrackType", "GES.TrackType",
"GES.BaseEffect", "GES.BaseEffect",
"GES.Group", "GES.Group",
"GES.UriClip",
"GES.UriClipAsset", "GES.UriClipAsset",
"GES.UriSourceAsset", "GES.UriSourceAsset",
] ]
@ -79,6 +77,22 @@ name = "Gst.ClockTime"
status = "manual" status = "manual"
conversion_type = "scalar" 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]] [[object]]
name = "GES.Timeline" name = "GES.Timeline"
status = "generate" status = "generate"
@ -205,6 +219,16 @@ status = "generate"
[object.function.return] [object.function.return]
bool_return_is_error = "Failed to the set top effect priority" 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]] [[object]]
name = "GES.Extractable" name = "GES.Extractable"
status = "generate" status = "generate"
@ -227,6 +251,11 @@ status = "generate"
[object.function.return] [object.function.return]
bool_return_is_error = "Failed to remove clip" 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]] [[object]]
name = "GES.Project" name = "GES.Project"
status = "generate" status = "generate"
@ -281,7 +310,17 @@ status = "generate"
[[object.function]] [[object.function]]
name = "trim" name = "trim"
[object.function.return] [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]] [[object]]
name = "GES.TrackElement" name = "GES.TrackElement"
@ -294,4 +333,4 @@ status = "generate"
[[object.function]] [[object.function]]
name = "remove_control_binding" name = "remove_control_binding"
[object.function.return] [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] [object.function.return]
bool_return_is_error = "Failed to remove window" 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]] [[object]]
name = "GstGL.GLDisplayEGL" name = "GstGL.GLDisplayEGL"
status = "generate" status = "generate"
@ -262,7 +267,6 @@ status = "generate"
name = "GstGL.GLColorConvert" name = "GstGL.GLColorConvert"
status = "generate" status = "generate"
final_type = true final_type = true
[[object.function]] [[object.function]]
name = "set_caps" name = "set_caps"
[object.function.return] [object.function.return]

View file

@ -99,6 +99,16 @@ status = "generate"
[object.function.return] [object.function.return]
nullable = false 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]] [[object]]
name = "GstPbutils.DiscovererStreamInfo" name = "GstPbutils.DiscovererStreamInfo"
status = "generate" status = "generate"
@ -180,6 +190,11 @@ status = "generate"
# encodingprofile is immutable after constructed # encodingprofile is immutable after constructed
ignore = true ignore = true
[[object.function]]
name = "from_discoverer"
[object.function.return]
nullable_return_is_error = "Failed to create EncodingProfile from DiscovererInfo"
[[object]] [[object]]
name = "GstPbutils.EncodingContainerProfile" name = "GstPbutils.EncodingContainerProfile"
status = "generate" status = "generate"
@ -292,3 +307,23 @@ status = "generate"
[[object.function]] [[object.function]]
name = "pb_utils_get_encoder_description" name = "pb_utils_get_encoder_description"
ignore = true 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.RTSPAddressPoolResult",
"GstRtspServer.RTSPMediaFactoryURI", "GstRtspServer.RTSPMediaFactoryURI",
"GstRtspServer.RTSPMediaStatus", "GstRtspServer.RTSPMediaStatus",
"GstRtspServer.RTSPMountPoints",
"GstRtspServer.RTSPPublishClockMode", "GstRtspServer.RTSPPublishClockMode",
"GstRtspServer.RTSPSession",
"GstRtspServer.RTSPSuspendMode", "GstRtspServer.RTSPSuspendMode",
"GstRtspServer.RTSPThreadPool", "GstRtspServer.RTSPThreadPool",
"GstRtspServer.RTSPThreadType", "GstRtspServer.RTSPThreadType",
@ -225,6 +223,11 @@ status = "generate"
[object.function.return] [object.function.return]
bool_return_is_error = "Failed to add address range" 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]] [[object.function]]
name = "reserve_address" name = "reserve_address"
ignore = true ignore = true
@ -257,6 +260,16 @@ status = "generate"
# Different structure mutability needed # Different structure mutability needed
ignore = true 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]] [[object]]
name = "GstRtspServer.RTSPSessionMedia" name = "GstRtspServer.RTSPSessionMedia"
status = "generate" status = "generate"
@ -280,10 +293,14 @@ status = "generate"
# GSource return # GSource return
ignore = true ignore = true
[[object.function]]
name = "create"
[object.function.return]
nullable_return_is_error = "Failed to create session pool"
[[object]] [[object]]
name="GstRtspServer.RTSPAuth" name="GstRtspServer.RTSPAuth"
status="generate" status="generate"
[[object.function]] [[object.function]]
name = "check" name = "check"
[object.function.return] [object.function.return]
@ -297,9 +314,26 @@ status="generate"
[[object.function]] [[object.function]]
name = "make_basic" name = "make_basic"
[object.function.return] [object.function.return]
nullable = false nullable = false
[[object.function]] [[object.function]]
name = "set_default_token" name = "set_default_token"
# gir forgets mut # gir forgets mut
ignore = true 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] [object.function.return]
nullable = false nullable = false
[[object.function]]
name = "allocate_output_buffer"
[object.function.return]
nullable_return_is_error = "Failed to allocate output buffer"
[[object]] [[object]]
name = "GstVideo.VideoEncoder" name = "GstVideo.VideoEncoder"
status = "generate" status = "generate"
@ -216,3 +221,8 @@ status = "generate"
name = "proxy_getcaps" name = "proxy_getcaps"
[object.function.return] [object.function.return]
nullable = false 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()?; gst::init()?;
let pipeline = gst::Pipeline::new(None); let pipeline = gst::Pipeline::new(None);
let src = let src = gst::ElementFactory::make("audiotestsrc", None)
gst::ElementFactory::make("audiotestsrc", None).ok_or(MissingElement("audiotestsrc"))?; .map_err(|_| MissingElement("audiotestsrc"))?;
let sink = gst::ElementFactory::make("appsink", None).ok_or(MissingElement("appsink"))?; let sink = gst::ElementFactory::make("appsink", None).map_err(|_| MissingElement("appsink"))?;
pipeline.add_many(&[&src, &sink])?; pipeline.add_many(&[&src, &sink])?;
src.link(&sink)?; src.link(&sink)?;
@ -87,7 +87,7 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
// Add a handler to the "new-sample" signal. // Add a handler to the "new-sample" signal.
.new_sample(|appsink| { .new_sample(|appsink| {
// Pull the sample in question out of the appsink's buffer. // 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(|| { let buffer = sample.get_buffer().ok_or_else(|| {
gst_element_error!( gst_element_error!(
appsink, 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. // 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. // So mapping the buffer makes the underlying memory region accessible to us.
// See: https://gstreamer.freedesktop.org/documentation/plugin-development/advanced/allocation.html // 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!( gst_element_error!(
appsink, appsink,
gst::ResourceError::Failed, gst::ResourceError::Failed,

View file

@ -52,11 +52,11 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
gst::init()?; gst::init()?;
let pipeline = gst::Pipeline::new(None); let pipeline = gst::Pipeline::new(None);
let src = gst::ElementFactory::make("appsrc", None).ok_or(MissingElement("appsrc"))?; let src = gst::ElementFactory::make("appsrc", None).map_err(|_| MissingElement("appsrc"))?;
let videoconvert = let videoconvert = gst::ElementFactory::make("videoconvert", None)
gst::ElementFactory::make("videoconvert", None).ok_or(MissingElement("videoconvert"))?; .map_err(|_| MissingElement("videoconvert"))?;
let sink = let sink = gst::ElementFactory::make("autovideosink", None)
gst::ElementFactory::make("autovideosink", None).ok_or(MissingElement("autovideosink"))?; .map_err(|_| MissingElement("autovideosink"))?;
pipeline.add_many(&[&src, &videoconvert, &sink])?; pipeline.add_many(&[&src, &videoconvert, &sink])?;
gst::Element::link_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 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 = 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 // Tell the filesrc what file to load
src.set_property("location", &uri)?; src.set_property("location", &uri)?;
@ -157,14 +157,14 @@ fn example_main() -> Result<(), Error> {
if is_audio { if is_audio {
// decodebin found a raw audiostream, so we build the follow-up pipeline to // decodebin found a raw audiostream, so we build the follow-up pipeline to
// play it on the default audio playback device (using autoaudiosink). // play it on the default audio playback device (using autoaudiosink).
let queue = let queue = gst::ElementFactory::make("queue", None)
gst::ElementFactory::make("queue", None).ok_or(MissingElement("queue"))?; .map_err(|_| MissingElement("queue"))?;
let convert = gst::ElementFactory::make("audioconvert", None) let convert = gst::ElementFactory::make("audioconvert", None)
.ok_or(MissingElement("audioconvert"))?; .map_err(|_| MissingElement("audioconvert"))?;
let resample = gst::ElementFactory::make("audioresample", None) let resample = gst::ElementFactory::make("audioresample", None)
.ok_or(MissingElement("audioresample"))?; .map_err(|_| MissingElement("audioresample"))?;
let sink = gst::ElementFactory::make("autoaudiosink", None) let sink = gst::ElementFactory::make("autoaudiosink", None)
.ok_or(MissingElement("autoaudiosink"))?; .map_err(|_| MissingElement("autoaudiosink"))?;
let elements = &[&queue, &convert, &resample, &sink]; let elements = &[&queue, &convert, &resample, &sink];
pipeline.add_many(elements)?; pipeline.add_many(elements)?;
@ -185,14 +185,14 @@ fn example_main() -> Result<(), Error> {
} else if is_video { } else if is_video {
// decodebin found a raw videostream, so we build the follow-up pipeline to // decodebin found a raw videostream, so we build the follow-up pipeline to
// display it using the autovideosink. // display it using the autovideosink.
let queue = let queue = gst::ElementFactory::make("queue", None)
gst::ElementFactory::make("queue", None).ok_or(MissingElement("queue"))?; .map_err(|_| MissingElement("queue"))?;
let convert = gst::ElementFactory::make("videoconvert", None) let convert = gst::ElementFactory::make("videoconvert", None)
.ok_or(MissingElement("videoconvert"))?; .map_err(|_| MissingElement("videoconvert"))?;
let scale = gst::ElementFactory::make("videoscale", None) let scale = gst::ElementFactory::make("videoscale", None)
.ok_or(MissingElement("videoscale"))?; .map_err(|_| MissingElement("videoscale"))?;
let sink = gst::ElementFactory::make("autovideosink", None) let sink = gst::ElementFactory::make("autovideosink", None)
.ok_or(MissingElement("autovideosink"))?; .map_err(|_| MissingElement("autovideosink"))?;
let elements = &[&queue, &convert, &scale, &sink]; let elements = &[&queue, &convert, &scale, &sink];
pipeline.add_many(elements)?; pipeline.add_many(elements)?;

View file

@ -117,11 +117,12 @@ fn example_main() -> Result<(), Error> {
}; };
let pipeline = gst::Pipeline::new(None); let pipeline = gst::Pipeline::new(None);
let src = let src = gst::ElementFactory::make("uridecodebin", None)
gst::ElementFactory::make("uridecodebin", None).ok_or(MissingElement("uridecodebin"))?; .map_err(|_| MissingElement("uridecodebin"))?;
let encodebin = let encodebin =
gst::ElementFactory::make("encodebin", None).ok_or(MissingElement("encodebin"))?; gst::ElementFactory::make("encodebin", None).map_err(|_| MissingElement("encodebin"))?;
let sink = gst::ElementFactory::make("filesink", None).ok_or(MissingElement("filesink"))?; let sink =
gst::ElementFactory::make("filesink", None).map_err(|_| MissingElement("filesink"))?;
src.set_property("uri", &uri) src.set_property("uri", &uri)
.expect("setting URI Property failed"); .expect("setting URI Property failed");
@ -188,12 +189,12 @@ fn example_main() -> Result<(), Error> {
let link_to_encodebin = |is_audio, is_video| -> Result<(), Error> { let link_to_encodebin = |is_audio, is_video| -> Result<(), Error> {
if is_audio { if is_audio {
let queue = let queue = gst::ElementFactory::make("queue", None)
gst::ElementFactory::make("queue", None).ok_or(MissingElement("queue"))?; .map_err(|_| MissingElement("queue"))?;
let convert = gst::ElementFactory::make("audioconvert", None) let convert = gst::ElementFactory::make("audioconvert", None)
.ok_or(MissingElement("audioconvert"))?; .map_err(|_| MissingElement("audioconvert"))?;
let resample = gst::ElementFactory::make("audioresample", None) let resample = gst::ElementFactory::make("audioresample", None)
.ok_or(MissingElement("audioresample"))?; .map_err(|_| MissingElement("audioresample"))?;
let elements = &[&queue, &convert, &resample]; let elements = &[&queue, &convert, &resample];
pipeline pipeline
@ -221,12 +222,12 @@ fn example_main() -> Result<(), Error> {
let sink_pad = queue.get_static_pad("sink").expect("queue has no sinkpad"); let sink_pad = queue.get_static_pad("sink").expect("queue has no sinkpad");
dbin_src_pad.link(&sink_pad)?; dbin_src_pad.link(&sink_pad)?;
} else if is_video { } else if is_video {
let queue = let queue = gst::ElementFactory::make("queue", None)
gst::ElementFactory::make("queue", None).ok_or(MissingElement("queue"))?; .map_err(|_| MissingElement("queue"))?;
let convert = gst::ElementFactory::make("videoconvert", None) let convert = gst::ElementFactory::make("videoconvert", None)
.ok_or(MissingElement("videoconvert"))?; .map_err(|_| MissingElement("videoconvert"))?;
let scale = gst::ElementFactory::make("videoscale", None) let scale = gst::ElementFactory::make("videoscale", None)
.ok_or(MissingElement("videoscale"))?; .map_err(|_| MissingElement("videoscale"))?;
let elements = &[&queue, &convert, &scale]; let elements = &[&queue, &convert, &scale];
pipeline pipeline

View file

@ -116,7 +116,8 @@ fn example_main() {
// Tell the mainloop to continue executing this callback. // Tell the mainloop to continue executing this callback.
glib::Continue(true) glib::Continue(true)
}); })
.expect("Failed to add bus watch");
// Operate GStreamer's bus, facilliating GLib's mainloop here. // Operate GStreamer's bus, facilliating GLib's mainloop here.
// This function call will block until you tell the mainloop to quit // This function call will block until you tell the mainloop to quit

View file

@ -484,7 +484,7 @@ impl App {
self.appsink.set_callbacks( self.appsink.set_callbacks(
gst_app::AppSinkCallbacks::new() gst_app::AppSinkCallbacks::new()
.new_sample(move |appsink| { .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(|| { 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> { fn create_pipeline() -> Result<(gst::Pipeline, gst_app::AppSink, gst::Element), Error> {
let pipeline = gst::Pipeline::new(None); let pipeline = gst::Pipeline::new(None);
let src = gst::ElementFactory::make("videotestsrc", None) let src = gst::ElementFactory::make("videotestsrc", None)
.ok_or(MissingElement("videotestsrc"))?; .map_err(|_| MissingElement("videotestsrc"))?;
let sink = let sink = gst::ElementFactory::make("glsinkbin", None)
gst::ElementFactory::make("glsinkbin", None).ok_or(MissingElement("glsinkbin"))?; .map_err(|_| MissingElement("glsinkbin"))?;
pipeline.add_many(&[&src, &sink])?; pipeline.add_many(&[&src, &sink])?;
src.link(&sink)?; src.link(&sink)?;
let appsink = gst::ElementFactory::make("appsink", None) let appsink = gst::ElementFactory::make("appsink", None)
.ok_or(MissingElement("appsink"))? .map_err(|_| MissingElement("appsink"))?
.dynamic_cast::<gst_app::AppSink>() .dynamic_cast::<gst_app::AppSink>()
.expect("Sink element is expected to be an 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. // in the pipeline, and the widget will be embedded in our gui.
// Gstreamer then displays frames in the gtk widget. // 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. // 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 // Using the OpenGL widget succeeded, so we are in for a nice playback experience with
// low cpu usage. :) // low cpu usage. :)
// The gtkglsink essentially allocates an OpenGL texture on the GPU, that it will display. // 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) glib::Continue(true)
}); })
.expect("Failed to add bus watch");
// Pipeline reference is owned by the closure below, so will be // Pipeline reference is owned by the closure below, so will be
// destroyed once the app is destroyed // destroyed once the app is destroyed

View file

@ -248,7 +248,8 @@ fn create_ui(app: &gtk::Application) {
}; };
glib::Continue(true) glib::Continue(true)
}); })
.expect("Failed to add bus watch");
// Pipeline reference is owned by the closure below, so will be // Pipeline reference is owned by the closure below, so will be
// destroyed once the app is destroyed // destroyed once the app is destroyed

View file

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

View file

@ -78,16 +78,16 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
gst::init()?; gst::init()?;
let pipeline = gst::Pipeline::new(None); let pipeline = gst::Pipeline::new(None);
let src = let src = gst::ElementFactory::make("videotestsrc", None)
gst::ElementFactory::make("videotestsrc", None).ok_or(MissingElement("videotestsrc"))?; .map_err(|_| MissingElement("videotestsrc"))?;
let overlay = let overlay = gst::ElementFactory::make("cairooverlay", None)
gst::ElementFactory::make("cairooverlay", None).ok_or(MissingElement("cairooverlay"))?; .map_err(|_| MissingElement("cairooverlay"))?;
let capsfilter = let capsfilter =
gst::ElementFactory::make("capsfilter", None).ok_or(MissingElement("capsfilter"))?; gst::ElementFactory::make("capsfilter", None).map_err(|_| MissingElement("capsfilter"))?;
let videoconvert = let videoconvert = gst::ElementFactory::make("videoconvert", None)
gst::ElementFactory::make("videoconvert", None).ok_or(MissingElement("videoconvert"))?; .map_err(|_| MissingElement("videoconvert"))?;
let sink = let sink = gst::ElementFactory::make("autovideosink", None)
gst::ElementFactory::make("autovideosink", None).ok_or(MissingElement("autovideosink"))?; .map_err(|_| MissingElement("autovideosink"))?;
pipeline.add_many(&[&src, &overlay, &capsfilter, &videoconvert, &sink])?; pipeline.add_many(&[&src, &overlay, &capsfilter, &videoconvert, &sink])?;
gst::Element::link_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) glib::Continue(true)
}); })
.expect("Failed to add bus watch");
main_loop.run(); main_loop.run();

View file

@ -50,8 +50,8 @@ fn make_element(
element_name: Option<&str>, element_name: Option<&str>,
) -> Result<gst::Element, Error> { ) -> Result<gst::Element, Error> {
match gst::ElementFactory::make(factory_name, element_name) { match gst::ElementFactory::make(factory_name, element_name) {
Some(elem) => Ok(elem), Ok(elem) => Ok(elem),
None => Err(Error::from(MissingElement(factory_name))), Err(_) => Err(Error::from(MissingElement(factory_name))),
} }
} }

View file

@ -47,8 +47,8 @@ fn make_element(
element_name: Option<&str>, element_name: Option<&str>,
) -> Result<gst::Element, Error> { ) -> Result<gst::Element, Error> {
match gst::ElementFactory::make(factory_name, element_name) { match gst::ElementFactory::make(factory_name, element_name) {
Some(elem) => Ok(elem), Ok(elem) => Ok(elem),
None => Err(Error::from(MissingElement(factory_name))), Err(_) => Err(Error::from(MissingElement(factory_name))),
} }
} }

View file

@ -209,7 +209,7 @@ mod fir_filter {
} }
// Try mapping the input buffer as writable // 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!( gst_element_error!(
element, element,
gst::CoreError::Failed, gst::CoreError::Failed,
@ -318,13 +318,13 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
// Create our pipeline with the custom element // Create our pipeline with the custom element
let pipeline = gst::Pipeline::new(None); let pipeline = gst::Pipeline::new(None);
let src = let src = gst::ElementFactory::make("audiotestsrc", None)
gst::ElementFactory::make("audiotestsrc", None).ok_or(MissingElement("audiotestsrc"))?; .map_err(|_| MissingElement("audiotestsrc"))?;
let filter = fir_filter::FirFilter::new(None); let filter = fir_filter::FirFilter::new(None);
let conv = let conv = gst::ElementFactory::make("audioconvert", None)
gst::ElementFactory::make("audioconvert", None).ok_or(MissingElement("audioconvert"))?; .map_err(|_| MissingElement("audioconvert"))?;
let sink = let sink = gst::ElementFactory::make("autoaudiosink", None)
gst::ElementFactory::make("autoaudiosink", None).ok_or(MissingElement("autoaudiosink"))?; .map_err(|_| MissingElement("autoaudiosink"))?;
pipeline.add_many(&[&src, filter.upcast_ref(), &conv, &sink])?; pipeline.add_many(&[&src, filter.upcast_ref(), &conv, &sink])?;
src.link(&filter)?; 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) let src = gst::Element::make_from_uri(gst::URIType::Src, uri, None)
.expect("We do not seem to support this uri"); .expect("We do not seem to support this uri");
let typefinder = let typefinder =
gst::ElementFactory::make("typefind", None).ok_or(MissingElement("typefind"))?; gst::ElementFactory::make("typefind", None).map_err(|_| MissingElement("typefind"))?;
let queue = let queue =
gst::ElementFactory::make("multiqueue", None).ok_or(MissingElement("multiqueue"))?; gst::ElementFactory::make("multiqueue", None).map_err(|_| MissingElement("multiqueue"))?;
let muxer = let muxer = gst::ElementFactory::make("matroskamux", None)
gst::ElementFactory::make("matroskamux", None).ok_or(MissingElement("matroskamux"))?; .map_err(|_| MissingElement("matroskamux"))?;
let sink = gst::ElementFactory::make("filesink", None).ok_or(MissingElement("filesink"))?; let sink =
gst::ElementFactory::make("filesink", None).map_err(|_| MissingElement("filesink"))?;
sink.set_property("location", &output_file) sink.set_property("location", &output_file)
.expect("setting location property failed"); .expect("setting location property failed");

View file

@ -2,6 +2,7 @@
// from gir-files (https://github.com/gtk-rs/gir-files) // from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT // DO NOT EDIT
use glib;
use glib::object::ObjectType as ObjectType_; use glib::object::ObjectType as ObjectType_;
use glib::signal::connect_raw; use glib::signal::connect_raw;
use glib::signal::SignalHandlerId; 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)) } 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 { 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, self.to_glib_none().0,
)) ))
.ok_or_else(|| glib_bool_error!("Failed to pull preroll sample"))
} }
} }
pub fn pull_sample(&self) -> Option<gst::Sample> { pub fn pull_sample(&self) -> Result<gst::Sample, glib::BoolError> {
unsafe { from_glib_full(gst_app_sys::gst_app_sink_pull_sample(self.to_glib_none().0)) } 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"))] #[cfg(any(feature = "v1_12", feature = "dox"))]

View file

@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ d1e88f9) Generated by gir (https://github.com/gtk-rs/gir @ 5836573)
from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) from gir-files (https://github.com/gtk-rs/gir-files @ c067e63)

View file

@ -47,9 +47,9 @@ impl ::AudioFormat {
} }
impl str::FromStr for ::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!(); assert_initialized_main_thread!();
unsafe { unsafe {
@ -57,7 +57,7 @@ impl str::FromStr for ::AudioFormat {
s.to_glib_none().0, s.to_glib_none().0,
)); ));
if fmt == ::AudioFormat::Unknown { if fmt == ::AudioFormat::Unknown {
Err(()) Err(glib_bool_error!("Failed to parse audio format from string"))
} else { } else {
Ok(fmt) Ok(fmt)
} }

View file

@ -240,9 +240,9 @@ impl fmt::Display for AudioFormatInfo {
} }
impl str::FromStr 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!(); skip_assert_initialized!();
let format = s.parse()?; let format = s.parse()?;
Ok(AudioFormatInfo::from_format(format)) Ok(AudioFormatInfo::from_format(format))

View file

@ -2,6 +2,7 @@
// from gir-files (https://github.com/gtk-rs/gir-files) // from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT // DO NOT EDIT
use glib;
use glib::object::Cast; use glib::object::Cast;
use glib::object::IsA; use glib::object::IsA;
use glib::signal::connect_raw; use glib::signal::connect_raw;
@ -29,7 +30,7 @@ unsafe impl Sync for AudioDecoder {}
pub const NONE_AUDIO_DECODER: Option<&AudioDecoder> = None; pub const NONE_AUDIO_DECODER: Option<&AudioDecoder> = None;
pub trait AudioDecoderExt: 'static { 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>; fn get_audio_info(&self) -> Option<AudioInfo>;
@ -99,12 +100,13 @@ pub trait AudioDecoderExt: 'static {
} }
impl<O: IsA<AudioDecoder>> AudioDecoderExt for O { 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 { 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, self.as_ref().to_glib_none().0,
size, 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) // from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT // DO NOT EDIT
use glib;
use glib::object::Cast; use glib::object::Cast;
use glib::object::IsA; use glib::object::IsA;
use glib::signal::connect_raw; use glib::signal::connect_raw;
@ -28,7 +29,7 @@ unsafe impl Sync for AudioEncoder {}
pub const NONE_AUDIO_ENCODER: Option<&AudioEncoder> = None; pub const NONE_AUDIO_ENCODER: Option<&AudioEncoder> = None;
pub trait AudioEncoderExt: 'static { 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>; fn get_audio_info(&self) -> Option<AudioInfo>;
@ -105,12 +106,13 @@ pub trait AudioEncoderExt: 'static {
} }
impl<O: IsA<AudioEncoder>> AudioEncoderExt for O { 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 { 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, self.as_ref().to_glib_none().0,
size, 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) Generated by gir (https://github.com/gtk-rs/gir @ 5836573)
from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) from gir-files (https://github.com/gtk-rs/gir-files @ c067e63)

View file

@ -81,7 +81,7 @@ impl UniqueAdapter {
self.0.clear(); 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) self.0.copy_bytes(offset, size)
} }
@ -98,15 +98,15 @@ impl UniqueAdapter {
self.0.flush(flush); 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) 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) 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) self.0.get_buffer_list(nbytes)
} }
@ -159,15 +159,15 @@ impl UniqueAdapter {
self.0.pts_at_discont() 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) 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) 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) 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 { 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, self.to_glib_none().0,
offset, offset,
size, 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 { 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, self.to_glib_none().0,
nbytes, 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 { 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, self.to_glib_none().0,
nbytes, 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 { 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, self.to_glib_none().0,
nbytes, 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 { 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, self.to_glib_none().0,
nbytes, 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 { 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, self.to_glib_none().0,
nbytes, 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 { 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, self.to_glib_none().0,
nbytes, 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;
use gst_base_sys; use gst_base_sys;
use std::boxed::Box as Box_; use std::boxed::Box as Box_;
use std::mem;
use std::mem::transmute; use std::mem::transmute;
glib_wrapper! { glib_wrapper! {
@ -63,8 +62,6 @@ pub trait BaseSinkExt: 'static {
fn is_qos_enabled(&self) -> bool; 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_async_enabled(&self, enabled: bool);
fn set_blocksize(&self, blocksize: u32); 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) { fn set_async_enabled(&self, enabled: bool) {
unsafe { unsafe {
gst_base_sys::gst_base_sink_set_async_enabled( gst_base_sys::gst_base_sink_set_async_enabled(

View file

@ -15,7 +15,6 @@ use gobject_sys;
use gst; use gst;
use gst_base_sys; use gst_base_sys;
use std::boxed::Box as Box_; use std::boxed::Box as Box_;
use std::mem;
use std::mem::transmute; use std::mem::transmute;
glib_wrapper! { glib_wrapper! {
@ -46,8 +45,6 @@ pub trait BaseSrcExt: 'static {
fn new_seamless_segment(&self, start: i64, stop: i64, time: i64) -> bool; 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_async(&self, async: bool);
fn set_automatic_eos(&self, automatic_eos: 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) { fn set_async(&self, async: bool) {
unsafe { unsafe {
gst_base_sys::gst_base_src_set_async(self.as_ref().to_glib_none().0, async.to_glib()); 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) // from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT // DO NOT EDIT
use glib;
use glib::object::IsA; use glib::object::IsA;
use glib::translate::*; use glib::translate::*;
use gst; use gst;
use gst_base_sys; 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!(); assert_initialized_main_thread!();
unsafe { 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, src.as_ref().to_glib_none().0,
size, size,
)) ))
.ok_or_else(|| glib_bool_error!("Could not find type"))
} }
} }
pub fn type_find_helper_for_extension<P: IsA<gst::Object>>( pub fn type_find_helper_for_extension<P: IsA<gst::Object>>(
obj: Option<&P>, obj: Option<&P>,
extension: &str, extension: &str,
) -> Option<gst::Caps> { ) -> Result<gst::Caps, glib::BoolError> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { 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, obj.map(|p| p.as_ref()).to_glib_none().0,
extension.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) Generated by gir (https://github.com/gtk-rs/gir @ 5836573)
from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) 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 glib::translate::*;
use gst; use gst;
use gst_base_sys; use gst_base_sys;
use std::mem;
use BaseSink; use BaseSink;
pub trait BaseSinkExtManual: 'static { pub trait BaseSinkExtManual: 'static {
@ -28,6 +29,10 @@ pub trait BaseSinkExtManual: 'static {
Result<gst::ClockSuccess, gst::ClockError>, Result<gst::ClockSuccess, gst::ClockError>,
gst::ClockTimeDiff, gst::ClockTimeDiff,
); );
fn query_latency(
&self,
) -> Result<(bool, bool, gst::ClockTime, gst::ClockTime), glib::BoolError>;
} }
impl<O: IsA<BaseSink>> BaseSinkExtManual for O { impl<O: IsA<BaseSink>> BaseSinkExtManual for O {
@ -80,4 +85,36 @@ impl<O: IsA<BaseSink>> BaseSinkExtManual for O {
(ret.into_result(), jitter) (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 glib::translate::*;
use gst; use gst;
use gst_base_sys; use gst_base_sys;
use std::mem;
use BaseSrc; use BaseSrc;
pub trait BaseSrcExtManual: 'static { pub trait BaseSrcExtManual: 'static {
@ -20,6 +21,8 @@ pub trait BaseSrcExtManual: 'static {
fn start_wait(&self) -> Result<gst::FlowSuccess, gst::FlowError>; fn start_wait(&self) -> Result<gst::FlowSuccess, gst::FlowError>;
fn wait_playing(&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 { impl<O: IsA<BaseSrc>> BaseSrcExtManual for O {
@ -58,4 +61,30 @@ impl<O: IsA<BaseSrc>> BaseSrcExtManual for O {
}; };
ret.into_result() 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) Generated by gir (https://github.com/gtk-rs/gir @ 5836573)
from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) 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 { 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(), self.0.as_ptr(),
size, 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> { pub fn pull(&mut self) -> Result<gst::Buffer, glib::BoolError> {
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> {
unsafe { 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(), self.0.as_ptr(),
)) ))
.ok_or_else(|| glib_bool_error!("Failed to pull event"))
} }
} }
@ -294,12 +302,13 @@ impl Harness {
ret.into_result() 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 { 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(), self.0.as_ptr(),
buffer.into_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"))] #[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 { 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(), self.0.as_ptr(),
)) ))
.ok_or_else(|| glib_bool_error!("Failed to take all data as buffer"))
} }
} }
#[cfg(any(feature = "v1_14", feature = "dox"))] #[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 { 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(), 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"); h.set_src_caps_str("application/test");
let buf = gst::Buffer::new(); let buf = gst::Buffer::new();
let buf = h.push_and_pull(buf); 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 const NONE_CLIP: Option<&Clip> = None;
pub trait ClipExt: 'static { 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>>( fn find_track_element<P: IsA<Track>>(
&self, &self,
@ -74,7 +74,7 @@ pub trait ClipExt: 'static {
newpriority: u32, newpriority: u32,
) -> Result<(), glib::error::BoolError>; ) -> 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; 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 { 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 { 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, self.as_ref().to_glib_none().0,
asset.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 { 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, self.as_ref().to_glib_none().0,
position, position,
)) ))
.ok_or_else(|| glib_bool_error!("Failed to split clip"))
} }
} }

View file

@ -3,6 +3,7 @@
// DO NOT EDIT // DO NOT EDIT
use ges_sys; use ges_sys;
use glib;
use glib::object::IsA; use glib::object::IsA;
use glib::translate::*; use glib::translate::*;
use glib::GString; use glib::GString;
@ -23,9 +24,12 @@ glib_wrapper! {
} }
impl Effect { impl Effect {
pub fn new(bin_description: &str) -> Option<Effect> { pub fn new(bin_description: &str) -> Result<Effect, glib::BoolError> {
assert_initialized_main_thread!(); 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, inpoint: gst::ClockTime,
duration: gst::ClockTime, duration: gst::ClockTime,
track_types: TrackType, track_types: TrackType,
) -> Option<Clip>; ) -> Result<Clip, glib::BoolError>;
fn add_clip<P: IsA<Clip>>(&self, clip: &P) -> Result<(), glib::error::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, inpoint: gst::ClockTime,
duration: gst::ClockTime, duration: gst::ClockTime,
track_types: TrackType, track_types: TrackType,
) -> Option<Clip> { ) -> Result<Clip, glib::BoolError> {
unsafe { 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, self.as_ref().to_glib_none().0,
asset.as_ref().to_glib_none().0, asset.as_ref().to_glib_none().0,
start.to_glib(), start.to_glib(),
@ -108,6 +108,7 @@ impl<O: IsA<Layer>> LayerExt for O {
duration.to_glib(), duration.to_glib(),
track_types.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 { pub trait TimelineElementExt: 'static {
//fn add_child_property<P: IsA<glib::Object>>(&self, pspec: /*Ignored*/&glib::ParamSpec, child: &P) -> bool; //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); //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 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; //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() } // 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 { 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, self.as_ref().to_glib_none().0,
deep.to_glib(), 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() } // 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 { 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, self.as_ref().to_glib_none().0,
paste_position.to_glib(), 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 { unsafe {
glib_result_from_gboolean!( glib_result_from_gboolean!(
ges_sys::ges_timeline_element_trim(self.as_ref().to_glib_none().0, start.to_glib()), 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 // DO NOT EDIT
use ges_sys; use ges_sys;
use glib;
use glib::object::Cast; use glib::object::Cast;
use glib::object::IsA; use glib::object::IsA;
use glib::signal::connect_raw; use glib::signal::connect_raw;
@ -29,9 +30,12 @@ glib_wrapper! {
} }
impl UriClip { impl UriClip {
pub fn new(uri: &str) -> Option<UriClip> { pub fn new(uri: &str) -> Result<UriClip, glib::BoolError> {
assert_initialized_main_thread!(); 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) Generated by gir (https://github.com/gtk-rs/gir @ 5836573)
from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) from gir-files (https://github.com/gtk-rs/gir-files @ c067e63)

View file

@ -53,7 +53,7 @@ pub trait GLDisplayExt: 'static {
other_context: &P, other_context: &P,
) -> Result<GLContext, glib::Error>; ) -> 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); 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 { 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, 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) Generated by gir (https://github.com/gtk-rs/gir @ 5836573)
from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) 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; return None;
} }
let mut data = self.plane_data(idx)?; let mut data = self.plane_data(idx).ok()?;
let id = &data.read_u32::<NativeEndian>().ok()?; let id = &data.read_u32::<NativeEndian>().ok()?;
Some(*id) Some(*id)

View file

@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ d1e88f9) Generated by gir (https://github.com/gtk-rs/gir @ 5836573)
from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) 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 { 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, self.to_glib_none().0,
flags.to_glib(), 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!(); assert_initialized_main_thread!();
unsafe { 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, 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) // from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT // DO NOT EDIT
use glib;
use glib::object::IsA; use glib::object::IsA;
use glib::translate::*; use glib::translate::*;
use glib::GString; 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!(); skip_assert_initialized!();
unsafe { 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, 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) // from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT // DO NOT EDIT
use glib;
use glib::translate::*; use glib::translate::*;
use glib::GString; use glib::GString;
use gst_pbutils_sys; 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!(); assert_initialized_main_thread!();
unsafe { 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, 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!(); assert_initialized_main_thread!();
unsafe { 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, 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!(); assert_initialized_main_thread!();
unsafe { 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, 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!(); assert_initialized_main_thread!();
unsafe { from_glib_full(gst_pbutils_sys::gst_plugins_base_version_string()) } 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) Generated by gir (https://github.com/gtk-rs/gir @ 5836573)
from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) 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) Generated by gir (https://github.com/gtk-rs/gir @ 5836573)
from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) 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) Generated by gir (https://github.com/gtk-rs/gir @ 5836573)
from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) 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::marker::PhantomData;
use std::mem; use std::mem;
@ -94,17 +94,26 @@ impl<'a, T> Drop for RTPBuffer<'a, T> {
} }
pub trait RTPBufferExt { 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 { 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 { 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, payload_len,
pad_len, pad_len,
csrc_count, 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 const NONE_RTSP_ADDRESS_POOL: Option<&RTSPAddressPool> = None;
pub trait RTSPAddressPoolExt: 'static { 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( fn add_range(
&self, &self,
@ -55,13 +59,18 @@ pub trait RTSPAddressPoolExt: 'static {
} }
impl<O: IsA<RTSPAddressPool>> RTSPAddressPoolExt for O { 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 { 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, self.as_ref().to_glib_none().0,
flags.to_glib(), flags.to_glib(),
n_ports, 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 { pub trait RTSPMediaFactoryExt: 'static {
//fn add_role(&self, role: &str, fieldname: &str, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs); //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>; 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() } // 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 { 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, self.as_ref().to_glib_none().0,
url.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 { 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, self.as_ref().to_glib_none().0,
url.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) // from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT // DO NOT EDIT
use glib;
use glib::object::IsA; use glib::object::IsA;
use glib::translate::*; use glib::translate::*;
use glib::GString; use glib::GString;
@ -39,7 +40,7 @@ pub const NONE_RTSP_MOUNT_POINTS: Option<&RTSPMountPoints> = None;
pub trait RTSPMountPointsExt: 'static { pub trait RTSPMountPointsExt: 'static {
fn add_factory<P: IsA<RTSPMediaFactory>>(&self, path: &str, factory: &P); 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); 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 { 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, self.as_ref().to_glib_none().0,
url.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) // from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT // DO NOT EDIT
use glib;
use glib::object::Cast; use glib::object::Cast;
use glib::object::IsA; use glib::object::IsA;
use glib::signal::connect_raw; use glib::signal::connect_raw;
@ -64,7 +65,11 @@ pub trait RTSPSessionExt: 'static {
fn is_expired_usec(&self, now: i64) -> bool; 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; //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 { 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, self.as_ref().to_glib_none().0,
path.to_glib_none().0, path.to_glib_none().0,
media.as_ref().to_glib_full(), 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 { pub trait RTSPSessionPoolExt: 'static {
fn cleanup(&self) -> u32; fn cleanup(&self) -> u32;
fn create(&self) -> Option<RTSPSession>; fn create(&self) -> Result<RTSPSession, glib::BoolError>;
fn filter( fn filter(
&self, &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 { 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, 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) Generated by gir (https://github.com/gtk-rs/gir @ 5836573)
from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) 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) Generated by gir (https://github.com/gtk-rs/gir @ 5836573)
from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) 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) Generated by gir (https://github.com/gtk-rs/gir @ 5836573)
from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) 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) Generated by gir (https://github.com/gtk-rs/gir @ 5836573)
from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) 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) // from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT // DO NOT EDIT
use glib;
use glib::object::IsA; use glib::object::IsA;
use glib::translate::*; use glib::translate::*;
use gst; use gst;
@ -24,7 +25,7 @@ pub const NONE_VIDEO_DECODER: Option<&VideoDecoder> = None;
pub trait VideoDecoderExt: 'static { pub trait VideoDecoderExt: 'static {
fn add_to_frame(&self, n_bytes: i32); 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>; 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 { 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, 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) // from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT // DO NOT EDIT
use glib;
use glib::object::Cast; use glib::object::Cast;
use glib::object::IsA; use glib::object::IsA;
use glib::signal::connect_raw; use glib::signal::connect_raw;
@ -32,7 +33,7 @@ unsafe impl Sync for VideoEncoder {}
pub const NONE_VIDEO_ENCODER: Option<&VideoEncoder> = None; pub const NONE_VIDEO_ENCODER: Option<&VideoEncoder> = None;
pub trait VideoEncoderExt: 'static { 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"))] #[cfg(any(feature = "v1_14", feature = "dox"))]
fn get_max_encode_time(&self, frame: &VideoCodecFrame) -> gst::ClockTimeDiff; 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 { 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 { 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, self.as_ref().to_glib_none().0,
size, 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 { 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!(); assert_initialized_main_thread!();
unsafe { unsafe {
@ -101,7 +101,7 @@ impl str::FromStr for ::VideoFormat {
)); ));
if fmt == ::VideoFormat::Unknown { if fmt == ::VideoFormat::Unknown {
Err(()) Err(glib_bool_error!("Failed to parse video format from string"))
} else { } else {
Ok(fmt) Ok(fmt)
} }

View file

@ -344,9 +344,9 @@ impl fmt::Display for VideoFormatInfo {
} }
impl str::FromStr 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!(); skip_assert_initialized!();
let format = s.parse()?; let format = s.parse()?;
Ok(VideoFormatInfo::from_format(format)) Ok(VideoFormatInfo::from_format(format))

View file

@ -139,9 +139,9 @@ impl<T> VideoFrame<T> {
unsafe { gst::BufferRef::from_ptr(self.0.buffer) } 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() { 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(); let format_info = self.format_info();
@ -149,7 +149,7 @@ impl<T> VideoFrame<T> {
// Just get the palette // Just get the palette
if format_info.has_palette() && plane == 1 { if format_info.has_palette() && plane == 1 {
unsafe { 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()); let h = format_info.scale_height(plane as u8, self.height());
unsafe { unsafe {
Some(slice::from_raw_parts( Ok(slice::from_raw_parts(
self.0.data[plane as usize] as *const u8, self.0.data[plane as usize] as *const u8,
(w * h) as usize, (w * h) as usize,
)) ))
@ -306,9 +306,9 @@ impl VideoFrame<Writable> {
unsafe { gst::BufferRef::from_mut_ptr(self.0.buffer) } 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() { 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(); let format_info = self.format_info();
@ -316,7 +316,7 @@ impl VideoFrame<Writable> {
// Just get the palette // Just get the palette
if format_info.has_palette() && plane == 1 { if format_info.has_palette() && plane == 1 {
unsafe { unsafe {
return Some(slice::from_raw_parts_mut( return Ok(slice::from_raw_parts_mut(
self.0.data[1] as *mut u8, self.0.data[1] as *mut u8,
256 * 4, 256 * 4,
)); ));
@ -329,7 +329,7 @@ impl VideoFrame<Writable> {
let h = format_info.scale_height(plane as u8, self.height()); let h = format_info.scale_height(plane as u8, self.height());
unsafe { unsafe {
Some(slice::from_raw_parts_mut( Ok(slice::from_raw_parts_mut(
self.0.data[plane as usize] as *mut u8, self.0.data[plane as usize] as *mut u8,
(w * h) as usize, (w * h) as usize,
)) ))
@ -367,7 +367,7 @@ impl<'a> VideoFrameRef<&'a gst::BufferRef> {
pub fn from_buffer_ref_readable<'b>( pub fn from_buffer_ref_readable<'b>(
buffer: &'a gst::BufferRef, buffer: &'a gst::BufferRef,
info: &'b ::VideoInfo, info: &'b ::VideoInfo,
) -> Option<VideoFrameRef<&'a gst::BufferRef>> { ) -> Result<VideoFrameRef<&'a gst::BufferRef>, glib::BoolError> {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
@ -380,11 +380,11 @@ impl<'a> VideoFrameRef<&'a gst::BufferRef> {
)); ));
if !res { if !res {
None Err(glib_bool_error!("Failed to map VideoFrame"))
} else { } else {
let frame = frame.assume_init(); let frame = frame.assume_init();
let info = ::VideoInfo(ptr::read(&frame.info)); 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, buffer: &'a gst::BufferRef,
id: i32, id: i32,
info: &'b ::VideoInfo, info: &'b ::VideoInfo,
) -> Option<VideoFrameRef<&'a gst::BufferRef>> { ) -> Result<VideoFrameRef<&'a gst::BufferRef>, glib::BoolError> {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
@ -407,11 +407,11 @@ impl<'a> VideoFrameRef<&'a gst::BufferRef> {
)); ));
if !res { if !res {
None Err(glib_bool_error!("Failed to map VideoFrame"))
} else { } else {
let frame = frame.assume_init(); let frame = frame.assume_init();
let info = ::VideoInfo(ptr::read(&frame.info)); 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() 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() { 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(); let format_info = self.format_info();
@ -529,7 +529,7 @@ impl<'a> VideoFrameRef<&'a gst::BufferRef> {
// Just get the palette // Just get the palette
if format_info.has_palette() && plane == 1 { if format_info.has_palette() && plane == 1 {
unsafe { 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()); let h = format_info.scale_height(plane as u8, self.height());
unsafe { unsafe {
Some(slice::from_raw_parts( Ok(slice::from_raw_parts(
self.0.data[plane as usize] as *const u8, self.0.data[plane as usize] as *const u8,
(w * h) as usize, (w * h) as usize,
)) ))
@ -560,7 +560,7 @@ impl<'a> VideoFrameRef<&'a mut gst::BufferRef> {
pub fn from_buffer_ref_writable<'b>( pub fn from_buffer_ref_writable<'b>(
buffer: &'a mut gst::BufferRef, buffer: &'a mut gst::BufferRef,
info: &'b ::VideoInfo, info: &'b ::VideoInfo,
) -> Option<VideoFrameRef<&'a mut gst::BufferRef>> { ) -> Result<VideoFrameRef<&'a mut gst::BufferRef>, glib::BoolError> {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
@ -575,11 +575,11 @@ impl<'a> VideoFrameRef<&'a mut gst::BufferRef> {
)); ));
if !res { if !res {
None Err(glib_bool_error!("Failed to map VideoFrame"))
} else { } else {
let frame = frame.assume_init(); let frame = frame.assume_init();
let info = ::VideoInfo(ptr::read(&frame.info)); 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, buffer: &'a mut gst::BufferRef,
id: i32, id: i32,
info: &'b ::VideoInfo, info: &'b ::VideoInfo,
) -> Option<VideoFrameRef<&'a mut gst::BufferRef>> { ) -> Result<VideoFrameRef<&'a mut gst::BufferRef>, glib::BoolError> {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
@ -604,11 +604,11 @@ impl<'a> VideoFrameRef<&'a mut gst::BufferRef> {
)); ));
if !res { if !res {
None Err(glib_bool_error!("Failed to map VideoFrame"))
} else { } else {
let frame = frame.assume_init(); let frame = frame.assume_init();
let info = ::VideoInfo(ptr::read(&frame.info)); 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() 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() { 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(); let format_info = self.format_info();
@ -627,7 +627,7 @@ impl<'a> VideoFrameRef<&'a mut gst::BufferRef> {
// Just get the palette // Just get the palette
if format_info.has_palette() && plane == 1 { if format_info.has_palette() && plane == 1 {
unsafe { unsafe {
return Some(slice::from_raw_parts_mut( return Ok(slice::from_raw_parts_mut(
self.0.data[1] as *mut u8, self.0.data[1] as *mut u8,
256 * 4, 256 * 4,
)); ));
@ -640,7 +640,7 @@ impl<'a> VideoFrameRef<&'a mut gst::BufferRef> {
let h = format_info.scale_height(plane as u8, self.height()); let h = format_info.scale_height(plane as u8, self.height());
unsafe { unsafe {
Some(slice::from_raw_parts_mut( Ok(slice::from_raw_parts_mut(
self.0.data[plane as usize] as *mut u8, self.0.data[plane as usize] as *mut u8,
(w * h) as usize, (w * h) as usize,
)) ))
@ -717,9 +717,9 @@ mod tests {
let buffer = gst::Buffer::with_size(info.size()).unwrap(); let buffer = gst::Buffer::with_size(info.size()).unwrap();
let frame = VideoFrame::from_buffer_readable(buffer, &info).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(0).unwrap().len(), 320 * 240);
assert_eq!(frame.plane_data(1), None); assert!(frame.plane_data(1).is_err());
assert!(frame.info() == &info); assert!(frame.info() == &info);
} }
@ -733,9 +733,9 @@ mod tests {
let buffer = gst::Buffer::with_size(info.size()).unwrap(); let buffer = gst::Buffer::with_size(info.size()).unwrap();
let mut frame = VideoFrame::from_buffer_writable(buffer, &info).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(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); assert!(frame.info() == &info);
} }
} }

View file

@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ d1e88f9) Generated by gir (https://github.com/gtk-rs/gir @ 5836573)
from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) from gir-files (https://github.com/gtk-rs/gir-files @ c067e63)

View file

@ -18,11 +18,19 @@ use Allocator;
use Memory; use Memory;
pub trait AllocatorExtManual: 'static { 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 { 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 { unsafe {
let ret = gst_sys::gst_allocator_alloc( let ret = gst_sys::gst_allocator_alloc(
self.as_ptr() as *mut _, self.as_ptr() as *mut _,
@ -33,9 +41,9 @@ impl<O: IsA<Allocator>> AllocatorExtManual for O {
}, },
); );
if ret.is_null() { if ret.is_null() {
None Err(glib_bool_error!("Failed to allocate memory"))
} else { } 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!(); assert_initialized_main_thread!();
unsafe { unsafe {
from_glib_full(gst_sys::gst_date_time_new_from_g_date_time( 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!(); assert_initialized_main_thread!();
unsafe { 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, 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)) } 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> { pub fn to_g_date_time(&self) -> Result<glib::DateTime, glib::BoolError> {
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> {
unsafe { 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, 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 const NONE_DEVICE: Option<&Device> = None;
pub trait DeviceExt: 'static { 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>; fn get_caps(&self) -> Option<Caps>;
@ -55,12 +55,13 @@ pub trait DeviceExt: 'static {
} }
impl<O: IsA<Device>> DeviceExt for O { 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 { 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, self.as_ref().to_glib_none().0,
name.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 { 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, self.to_glib_none().0,
name.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!(); assert_initialized_main_thread!();
unsafe { 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, factoryname.to_glib_none().0,
name.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"))] #[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!(); 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 { 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"))] #[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!(); 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( pub fn parse_bin_from_description(

View file

@ -22,7 +22,10 @@ glib_wrapper! {
} }
impl GhostPad { 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!(); assert_initialized_main_thread!();
unsafe { unsafe {
Option::<Pad>::from_glib_none(gst_sys::gst_ghost_pad_new_no_target( Option::<Pad>::from_glib_none(gst_sys::gst_ghost_pad_new_no_target(
@ -30,13 +33,14 @@ impl GhostPad {
dir.to_glib(), dir.to_glib(),
)) ))
.map(|o| o.unsafe_cast()) .map(|o| o.unsafe_cast())
.ok_or_else(|| glib_bool_error!("Failed to create GhostPad"))
} }
} }
pub fn new_no_target_from_template( pub fn new_no_target_from_template(
name: Option<&str>, name: Option<&str>,
templ: &PadTemplate, templ: &PadTemplate,
) -> Option<GhostPad> { ) -> Result<GhostPad, glib::BoolError> {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
Option::<Pad>::from_glib_none(gst_sys::gst_ghost_pad_new_no_target_from_template( 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, templ.to_glib_none().0,
)) ))
.map(|o| o.unsafe_cast()) .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) // from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT // DO NOT EDIT
#[cfg(any(feature = "v1_14", feature = "dox"))]
use glib; use glib;
use glib::object::IsA; use glib::object::IsA;
use glib::object::ObjectType as ObjectType_; use glib::object::ObjectType as ObjectType_;
@ -37,15 +36,16 @@ impl PadTemplate {
direction: PadDirection, direction: PadDirection,
presence: PadPresence, presence: PadPresence,
caps: &Caps, caps: &Caps,
) -> Option<PadTemplate> { ) -> Result<PadTemplate, glib::BoolError> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { 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, name_template.to_glib_none().0,
direction.to_glib(), direction.to_glib(),
presence.to_glib(), presence.to_glib(),
caps.to_glib_none().0, caps.to_glib_none().0,
)) ))
.ok_or_else(|| glib_bool_error!("Failed to create pad template"))
} }
} }
@ -56,16 +56,17 @@ impl PadTemplate {
presence: PadPresence, presence: PadPresence,
caps: &Caps, caps: &Caps,
pad_type: glib::types::Type, pad_type: glib::types::Type,
) -> Option<PadTemplate> { ) -> Result<PadTemplate, glib::BoolError> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { 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, name_template.to_glib_none().0,
direction.to_glib(), direction.to_glib(),
presence.to_glib(), presence.to_glib(),
caps.to_glib_none().0, caps.to_glib_none().0,
pad_type.to_glib(), 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)) } unsafe { from_glib(gst_sys::gst_plugin_is_loaded(self.to_glib_none().0)) }
} }
pub fn load(&self) -> Option<Plugin> { pub fn load(&self) -> Result<Plugin, glib::BoolError> {
unsafe { from_glib_full(gst_sys::gst_plugin_load(self.to_glib_none().0)) } 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!(); 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> { 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) // from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT // DO NOT EDIT
use glib;
use glib::object::IsA; use glib::object::IsA;
use glib::translate::*; use glib::translate::*;
use glib::GString; use glib::GString;
@ -29,7 +30,7 @@ pub trait PluginFeatureExt: 'static {
fn get_plugin_name(&self) -> Option<GString>; 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 { 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 { 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, 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) Generated by gir (https://github.com/gtk-rs/gir @ 5836573)
from gir-files (https://github.com/gtk-rs/gir-files @ 653b7f1) from gir-files (https://github.com/gtk-rs/gir-files @ c067e63)

View file

@ -23,7 +23,7 @@ use Memory;
use MemoryRef; use MemoryRef;
use glib; 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 glib_sys;
use gst_sys; use gst_sys;
@ -57,15 +57,16 @@ impl Buffer {
unsafe { from_glib_full(gst_sys::gst_buffer_new()) } 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!(); assert_initialized_main_thread!();
unsafe { unsafe {
from_glib_full(gst_sys::gst_buffer_new_allocate( Option::<_>::from_glib_full(gst_sys::gst_buffer_new_allocate(
ptr::null_mut(), ptr::null_mut(),
size, size,
ptr::null_mut(), ptr::null_mut(),
)) ))
.ok_or_else(|| glib_bool_error!("Failed to allocate buffer"))
} }
} }
@ -176,7 +177,7 @@ impl Default for Buffer {
} }
impl BufferRef { impl BufferRef {
pub fn map_readable(&self) -> Option<BufferMap<Readable>> { pub fn map_readable(&self) -> Result<BufferMap<Readable>, glib::BoolError> {
unsafe { unsafe {
let mut map_info = mem::MaybeUninit::zeroed(); let mut map_info = mem::MaybeUninit::zeroed();
let res = gst_sys::gst_buffer_map( let res = gst_sys::gst_buffer_map(
@ -185,18 +186,18 @@ impl BufferRef {
gst_sys::GST_MAP_READ, gst_sys::GST_MAP_READ,
); );
if res == glib_sys::GTRUE { if res == glib_sys::GTRUE {
Some(BufferMap { Ok(BufferMap {
buffer: self, buffer: self,
map_info: map_info.assume_init(), map_info: map_info.assume_init(),
phantom: PhantomData, phantom: PhantomData,
}) })
} else { } 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 { unsafe {
let mut map_info = mem::MaybeUninit::zeroed(); let mut map_info = mem::MaybeUninit::zeroed();
let res = gst_sys::gst_buffer_map( let res = gst_sys::gst_buffer_map(
@ -205,13 +206,13 @@ impl BufferRef {
gst_sys::GST_MAP_READWRITE, gst_sys::GST_MAP_READWRITE,
); );
if res == glib_sys::GTRUE { if res == glib_sys::GTRUE {
Some(BufferMap { Ok(BufferMap {
buffer: self, buffer: self,
map_info: map_info.assume_init(), map_info: map_info.assume_init(),
phantom: PhantomData, phantom: PhantomData,
}) })
} else { } else {
None Err(glib_bool_error!("Failed to map buffer writable"))
} }
} }
} }
@ -221,15 +222,16 @@ impl BufferRef {
flags: ::BufferCopyFlags, flags: ::BufferCopyFlags,
offset: usize, offset: usize,
size: Option<usize>, size: Option<usize>,
) -> Option<Buffer> { ) -> Result<Buffer, glib::BoolError> {
let size_real = size.unwrap_or(usize::MAX); let size_real = size.unwrap_or(usize::MAX);
unsafe { unsafe {
from_glib_full(gst_sys::gst_buffer_copy_region( Option::<_>::from_glib_full(gst_sys::gst_buffer_copy_region(
self.as_mut_ptr(), self.as_mut_ptr(),
flags.to_glib(), flags.to_glib(),
offset, offset,
size_real, 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> { pub fn copy_deep(&self) -> Result<Buffer, glib::BoolError> {
unsafe { from_glib_full(gst_sys::gst_buffer_copy_deep(self.as_ptr())) } 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 { pub fn get_size(&self) -> usize {
@ -695,7 +700,7 @@ impl PartialEq for BufferRef {
let other_map = other.map_readable(); let other_map = other.map_readable();
match (self_map, other_map) { 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, _ => false,
} }
} }

View file

@ -31,7 +31,7 @@ impl<'a> Serialize for BufferRef {
{ {
let data = self let data = self
.map_readable() .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.serialize_field("buffer", &Bytes::new(data.as_slice()))?;
} }
buffer.end() 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 where
F: FnMut(&Bus, &Message) -> Continue + Send + 'static, F: FnMut(&Bus, &Message) -> Continue + Send + 'static,
{ {
@ -122,14 +122,14 @@ impl Bus {
); );
if res == 0 { if res == 0 {
None Err(glib_bool_error!("Bus already has a watch"))
} else { } 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 where
F: FnMut(&Bus, &Message) -> Continue + 'static, F: FnMut(&Bus, &Message) -> Continue + 'static,
{ {
@ -145,9 +145,9 @@ impl Bus {
); );
if res == 0 { if res == 0 {
None Err(glib_bool_error!("Bus already has a watch"))
} else { } else {
Some(from_glib(res)) Ok(from_glib(res))
} }
} }
} }

View file

@ -106,13 +106,13 @@ impl Caps {
} }
impl str::FromStr for 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!(); assert_initialized_main_thread!();
unsafe { unsafe {
Option::<Caps>::from_glib_full(gst_sys::gst_caps_from_string(s.to_glib_none().0)) Option::<_>::from_glib_full(gst_sys::gst_caps_from_string(s.to_glib_none().0))
.ok_or(()) .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 { 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!(); assert_initialized_main_thread!();
unsafe { unsafe {
let ptr = gst_sys::gst_caps_features_from_string(s.to_glib_none().0); let ptr = gst_sys::gst_caps_features_from_string(s.to_glib_none().0);
if ptr.is_null() { if ptr.is_null() {
return Err(()); return Err(glib_bool_error!(
"Failed to parse caps features from string"
));
} }
Ok(CapsFeatures( Ok(CapsFeatures(

View file

@ -227,7 +227,11 @@ impl Clock {
} }
pub trait ClockExtManual: 'static { 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( fn periodic_id_reinit(
&self, &self,
@ -236,7 +240,7 @@ pub trait ClockExtManual: 'static {
interval: ClockTime, interval: ClockTime,
) -> Result<(), glib::BoolError>; ) -> 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>; 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 { 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 { 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, self.as_ref().to_glib_none().0,
start_time.to_glib(), start_time.to_glib(),
interval.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 { 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, self.as_ref().to_glib_none().0,
time.to_glib(), 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 { impl DateTime {
/// Get the [`DateTime`](struct.DateTime.html) in UTC /// 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() { if !self.has_time() {
// No time => no TZ offset // 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()); 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") .expect("DateTime::to_utc: to_g_date_time")
.to_utc() .to_utc()
.as_ref() .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 { } else {
// It would be cheaper to build a `glib::DateTime` direcly, unfortunetaly // It would be cheaper to build a `glib::DateTime` direcly, unfortunetaly
// this would require using `glib::TimeZone::new_offset` which is feature-gated // this would require using `glib::TimeZone::new_offset` which is feature-gated
@ -47,6 +48,7 @@ impl DateTime {
.to_g_date_time() .to_g_date_time()
.expect("DateTime::to_utc: to_g_date_time") .expect("DateTime::to_utc: to_g_date_time")
.to_utc() .to_utc()
.ok_or_else(|| glib_bool_error!("Can't convert datetime to UTC"))
.map(|g_date_time_utc| { .map(|g_date_time_utc| {
DateTime::new( DateTime::new(
0f32, // UTC TZ offset 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). // Normalize to UTC only if both members have time (see note 2).
let (self_norm, other_norm) = if self.has_time() && other.has_time() { 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 { } else {
(self.clone(), other.clone()) (self.clone(), other.clone())
}; };
@ -227,7 +229,7 @@ impl fmt::Display for DateTime {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str( f.write_str(
self.to_iso8601_string() self.to_iso8601_string()
.unwrap_or_else(|| "None".into()) .unwrap_or_else(|_| "None".into())
.as_str(), .as_str(),
) )
} }

View file

@ -17,7 +17,7 @@ use PadMode;
use PadTemplate; use PadTemplate;
impl GhostPad { 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!(); skip_assert_initialized!();
let name = name.to_glib_none(); let name = name.to_glib_none();
unsafe { unsafe {
@ -26,6 +26,7 @@ impl GhostPad {
target.as_ref().to_glib_none().0, target.as_ref().to_glib_none().0,
)) ))
.map(|o| Cast::unsafe_cast(o)) .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>, name: Option<&str>,
target: &Q, target: &Q,
templ: &PadTemplate, templ: &PadTemplate,
) -> Option<GhostPad> { ) -> Result<GhostPad, glib::BoolError> {
skip_assert_initialized!(); skip_assert_initialized!();
let name = name.to_glib_none(); let name = name.to_glib_none();
unsafe { unsafe {
@ -43,6 +44,7 @@ impl GhostPad {
templ.to_glib_none().0, templ.to_glib_none().0,
)) ))
.map(|o| Cast::unsafe_cast(o)) .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 { unsafe {
let mut map_info = mem::MaybeUninit::zeroed(); let mut map_info = mem::MaybeUninit::zeroed();
let res = gst_sys::gst_memory_map( let res = gst_sys::gst_memory_map(
@ -255,18 +255,18 @@ impl MemoryRef {
gst_sys::GST_MAP_READ, gst_sys::GST_MAP_READ,
); );
if res == glib_sys::GTRUE { if res == glib_sys::GTRUE {
Some(MemoryMap { Ok(MemoryMap {
memory: self, memory: self,
map_info: map_info.assume_init(), map_info: map_info.assume_init(),
phantom: PhantomData, phantom: PhantomData,
}) })
} else { } 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 { unsafe {
let mut map_info = mem::MaybeUninit::zeroed(); let mut map_info = mem::MaybeUninit::zeroed();
let res = gst_sys::gst_memory_map( let res = gst_sys::gst_memory_map(
@ -275,13 +275,13 @@ impl MemoryRef {
gst_sys::GST_MAP_READWRITE, gst_sys::GST_MAP_READWRITE,
); );
if res == glib_sys::GTRUE { if res == glib_sys::GTRUE {
Some(MemoryMap { Ok(MemoryMap {
memory: self, memory: self,
map_info: map_info.assume_init(), map_info: map_info.assume_init(),
phantom: PhantomData, phantom: PhantomData,
}) })
} else { } 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( pub fn new_from_static_pad_template_with_gtype(
pad_template: &StaticPadTemplate, pad_template: &StaticPadTemplate,
pad_type: glib::types::Type, pad_type: glib::types::Type,
) -> Option<PadTemplate> { ) -> Result<PadTemplate, glib::BoolError> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
from_glib_none( Option::<_>::from_glib_none(
gst_sys::gst_pad_template_new_from_static_pad_template_with_gtype( gst_sys::gst_pad_template_new_from_static_pad_template_with_gtype(
mut_override(pad_template.to_glib_none().0), mut_override(pad_template.to_glib_none().0),
pad_type.to_glib(), 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 Eq for Structure {}
impl str::FromStr 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!(); assert_initialized_main_thread!();
unsafe { unsafe {
let structure = gst_sys::gst_structure_from_string(s.to_glib_none().0, ptr::null_mut()); let structure = gst_sys::gst_structure_from_string(s.to_glib_none().0, ptr::null_mut());
if structure.is_null() { if structure.is_null() {
Err(()) Err(glib_bool_error!("Failed to parse structure from string"))
} else { } else {
Ok(Structure( Ok(Structure(
ptr::NonNull::new_unchecked(structure as *mut StructureRef), ptr::NonNull::new_unchecked(structure as *mut StructureRef),

View file

@ -21,7 +21,11 @@ use LoggableError;
use std::ptr; use std::ptr;
pub trait DeviceImpl: DeviceImplExt + ObjectImpl + Send + Sync + 'static { 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) self.parent_create_element(device, name)
} }
@ -31,7 +35,11 @@ pub trait DeviceImpl: DeviceImplExt + ObjectImpl + Send + Sync + 'static {
} }
pub trait DeviceImplExt { 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( fn parent_reconfigure_element(
&self, &self,
@ -41,7 +49,11 @@ pub trait DeviceImplExt {
} }
impl<T: DeviceImpl + ObjectImpl> DeviceImplExt for T { 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 { unsafe {
let data = self.get_type_data(); let data = self.get_type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstDeviceClass; 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); 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 // 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 { } else {
None Err(gst_loggable_error!(
::CAT_RUST,
"Parent function `create_element` is not defined"
))
} }
} }
} }
@ -107,7 +127,7 @@ where
.as_ref() .as_ref()
.map(|s| s.as_str()), .map(|s| s.as_str()),
) { ) {
Some(element) => { Ok(element) => {
// The reference we're going to return, the initial reference is going to // The reference we're going to return, the initial reference is going to
// be dropped here now // be dropped here now
let element_ptr = element.to_glib_full(); 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); gobject_sys::g_object_force_floating(element_ptr as *mut gobject_sys::GObject);
element_ptr 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 std::slice;
use glib; 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::value::{FromValue, FromValueOptional, SetValue, ToSendValue, Value};
use glib_sys; use glib_sys;
@ -743,8 +743,8 @@ pub trait GstValueExt: Sized {
fn fixate(&self) -> Option<Self>; fn fixate(&self) -> Option<Self>;
fn is_fixed(&self) -> bool; fn is_fixed(&self) -> bool;
fn is_subset(&self, superset: &Self) -> bool; fn is_subset(&self, superset: &Self) -> bool;
fn serialize(&self) -> Option<String>; fn serialize(&self) -> Result<glib::GString, glib::BoolError>;
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>;
} }
impl GstValueExt for glib::Value { impl GstValueExt for glib::Value {
@ -877,11 +877,14 @@ impl GstValueExt for glib::Value {
} }
} }
fn serialize(&self) -> Option<String> { fn serialize(&self) -> Result<glib::GString, glib::BoolError> {
unsafe { from_glib_full(gst_sys::gst_value_serialize(self.to_glib_none().0)) } 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!(); assert_initialized_main_thread!();
let s = s.into(); let s = s.into();
@ -893,9 +896,9 @@ impl GstValueExt for glib::Value {
s.to_glib_none().0, s.to_glib_none().0,
)); ));
if ret { if ret {
Some(value) Ok(value)
} else { } else {
None Err(glib_bool_error!("Failed to deserialize value"))
} }
} }
} }

View file

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

View file

@ -231,7 +231,7 @@ fn main() {
data.appsink.clone() data.appsink.clone()
}; };
if let Some(_sample) = appsink.pull_sample() { if let Ok(_sample) = appsink.pull_sample() {
use std::io::{self, Write}; use std::io::{self, Write};
// The only thing we do in this example is print a * to indicate a received buffer // The only thing we do in this example is print a * to indicate a received buffer
print!("*"); print!("*");

View file

@ -17,8 +17,8 @@ mod tutorials_common;
fn send_value_as_str(v: &glib::SendValue) -> Option<String> { fn send_value_as_str(v: &glib::SendValue) -> Option<String> {
if let Ok(Some(s)) = v.get::<&str>() { if let Ok(Some(s)) = v.get::<&str>() {
Some(s.to_string()) Some(s.to_string())
} else if let Some(serialized) = v.serialize() { } else if let Ok(serialized) = v.serialize() {
Some(serialized) Some(serialized.into())
} else { } else {
None None
} }