mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-25 11:01:10 +00:00
Update functions returning bool to use Result<(), glib::BoolError>
See https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/issues/171
This commit is contained in:
parent
ee87f286a0
commit
333d71f92b
20 changed files with 229 additions and 110 deletions
32
Gir_Gst.toml
32
Gir_Gst.toml
|
@ -86,6 +86,11 @@ name = "Gst.Bin"
|
|||
subclassing = true
|
||||
status = "generate"
|
||||
trait_name = "GstBinExt"
|
||||
[[object.signal]]
|
||||
name = "do-latency"
|
||||
# Use Result<(), glib::BoolError>
|
||||
ignore = true
|
||||
|
||||
[[object.function]]
|
||||
name = "add"
|
||||
[object.function.return]
|
||||
|
@ -133,6 +138,11 @@ trait = false
|
|||
# More convenient manual implementation
|
||||
ignore = true
|
||||
|
||||
[[object.function]]
|
||||
name = "remove_watch"
|
||||
[object.function.return]
|
||||
bool_return_is_error = "Bus has no event source"
|
||||
|
||||
[[object.signal]]
|
||||
name = "message"
|
||||
concurrency = "send"
|
||||
|
@ -547,6 +557,11 @@ status = "generate"
|
|||
[object.function.return]
|
||||
bool_return_is_error = "Failed to start"
|
||||
|
||||
[[object.function]]
|
||||
name = "remove_filter"
|
||||
[object.function.return]
|
||||
bool_return_is_error = "Failed to remove the filter"
|
||||
|
||||
[[object]]
|
||||
name = "Gst.Device"
|
||||
status = "generate"
|
||||
|
@ -560,6 +575,11 @@ status = "generate"
|
|||
[object.function.return]
|
||||
nullable = false
|
||||
|
||||
[[object.function]]
|
||||
name = "reconfigure_element"
|
||||
[object.function.return]
|
||||
bool_return_is_error = "Failed to reconfigure the element to use this device"
|
||||
|
||||
[[object]]
|
||||
name = "Gst.Object"
|
||||
# For renaming the trait...
|
||||
|
@ -603,7 +623,12 @@ status = "generate"
|
|||
[[object.function]]
|
||||
name = "link_maybe_ghosting"
|
||||
[object.function.return]
|
||||
bool_return_is_error = "Failed to link pad, possibly ghosting"
|
||||
bool_return_is_error = "Failed to link pads, possibly ghosting"
|
||||
|
||||
[[object.function]]
|
||||
name = "link_maybe_ghosting_full"
|
||||
[object.function.return]
|
||||
bool_return_is_error = "Failed to link pads, possibly ghosting"
|
||||
|
||||
[[object.function]]
|
||||
name = "unlink"
|
||||
|
@ -1187,6 +1212,11 @@ status = "generate"
|
|||
# wrong mutable for context parameter
|
||||
ignore = true
|
||||
|
||||
[[object.function]]
|
||||
name = "update_registry"
|
||||
[object.function.return]
|
||||
bool_return_is_error = "Failed to update the registry"
|
||||
|
||||
[[object.function]]
|
||||
name = "util_group_id_next"
|
||||
# newtype wrapper
|
||||
|
|
|
@ -130,7 +130,7 @@ fn example_main() {
|
|||
// Remove the watch function from the bus.
|
||||
// Again: There can always only be one watch function.
|
||||
// Thus we don't have to tell him which function to remove.
|
||||
bus.remove_watch();
|
||||
bus.remove_watch().unwrap();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -146,7 +146,7 @@ fn create_ui(app: >k::Application) {
|
|||
.set_state(gst::State::Null)
|
||||
.expect("Unable to set the pipeline to the `Null` state");
|
||||
|
||||
bus.remove_watch();
|
||||
bus.remove_watch().unwrap();
|
||||
if let Some(timeout_id) = timeout_id.borrow_mut().take() {
|
||||
glib::source_remove(timeout_id);
|
||||
}
|
||||
|
|
|
@ -249,7 +249,7 @@ fn create_ui(app: >k::Application) {
|
|||
.set_state(gst::State::Null)
|
||||
.expect("Unable to set the pipeline to the `Null` state");
|
||||
|
||||
bus.remove_watch();
|
||||
bus.remove_watch().unwrap();
|
||||
if let Some(timeout_id) = timeout_id.borrow_mut().take() {
|
||||
glib::source_remove(timeout_id);
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ fn example_main() {
|
|||
// Here we remove the bus watch we added above. This avoids a memory leak, that might
|
||||
// otherwise happen because we moved a strong reference (clone of main_loop) into the
|
||||
// callback closure above.
|
||||
bus.remove_watch();
|
||||
bus.remove_watch().unwrap();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -124,7 +124,7 @@ fn example_main() {
|
|||
.set_state(gst::State::Null)
|
||||
.expect("Unable to set the pipeline to the `Null` state");
|
||||
|
||||
bus.remove_watch();
|
||||
bus.remove_watch().unwrap();
|
||||
glib::source_remove(timeout_id);
|
||||
}
|
||||
|
||||
|
|
|
@ -99,8 +99,6 @@ pub trait GstBinExt: 'static {
|
|||
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
||||
fn connect_deep_element_removed<F: Fn(&Self, &Bin, &Element) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;
|
||||
|
||||
fn connect_do_latency<F: Fn(&Self) -> bool + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;
|
||||
|
||||
fn connect_element_added<F: Fn(&Self, &Element) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;
|
||||
|
||||
fn connect_element_removed<F: Fn(&Self, &Element) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;
|
||||
|
@ -251,14 +249,6 @@ impl<O: IsA<Bin>> GstBinExt for O {
|
|||
}
|
||||
}
|
||||
|
||||
fn connect_do_latency<F: Fn(&Self) -> bool + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
|
||||
unsafe {
|
||||
let f: Box_<Box_<Fn(&Self) -> bool + Send + Sync + 'static>> = Box_::new(Box_::new(f));
|
||||
connect_raw(self.as_ptr() as *mut _, b"do-latency\0".as_ptr() as *const _,
|
||||
transmute(do_latency_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
|
||||
}
|
||||
}
|
||||
|
||||
fn connect_element_added<F: Fn(&Self, &Element) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
|
||||
unsafe {
|
||||
let f: Box_<Box_<Fn(&Self, &Element) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
|
||||
|
@ -306,12 +296,6 @@ where P: IsA<Bin> {
|
|||
f(&Bin::from_glib_borrow(this).unsafe_cast(), &from_glib_borrow(sub_bin), &from_glib_borrow(element))
|
||||
}
|
||||
|
||||
unsafe extern "C" fn do_latency_trampoline<P>(this: *mut ffi::GstBin, f: glib_ffi::gpointer) -> glib_ffi::gboolean
|
||||
where P: IsA<Bin> {
|
||||
let f: &&(Fn(&P) -> bool + Send + Sync + 'static) = transmute(f);
|
||||
f(&Bin::from_glib_borrow(this).unsafe_cast()).to_glib()
|
||||
}
|
||||
|
||||
unsafe extern "C" fn element_added_trampoline<P>(this: *mut ffi::GstBin, element: *mut ffi::GstElement, f: glib_ffi::gpointer)
|
||||
where P: IsA<Bin> {
|
||||
let f: &&(Fn(&P, &Element) + Send + Sync + 'static) = transmute(f);
|
||||
|
|
|
@ -96,9 +96,9 @@ impl Bus {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn remove_watch(&self) -> bool {
|
||||
pub fn remove_watch(&self) -> Result<(), glib::error::BoolError> {
|
||||
unsafe {
|
||||
from_glib(ffi::gst_bus_remove_watch(self.to_glib_none().0))
|
||||
glib_result_from_gboolean!(ffi::gst_bus_remove_watch(self.to_glib_none().0), "Bus has no event source")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ use Element;
|
|||
use Object;
|
||||
use Structure;
|
||||
use ffi;
|
||||
use glib;
|
||||
use glib::GString;
|
||||
use glib::object::Cast;
|
||||
use glib::object::IsA;
|
||||
|
@ -45,7 +46,7 @@ pub trait DeviceExt: 'static {
|
|||
|
||||
fn has_classesv(&self, classes: &[&str]) -> bool;
|
||||
|
||||
fn reconfigure_element<P: IsA<Element>>(&self, element: &P) -> bool;
|
||||
fn reconfigure_element<P: IsA<Element>>(&self, element: &P) -> Result<(), glib::error::BoolError>;
|
||||
|
||||
fn connect_removed<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;
|
||||
}
|
||||
|
@ -94,9 +95,9 @@ impl<O: IsA<Device>> DeviceExt for O {
|
|||
}
|
||||
}
|
||||
|
||||
fn reconfigure_element<P: IsA<Element>>(&self, element: &P) -> bool {
|
||||
fn reconfigure_element<P: IsA<Element>>(&self, element: &P) -> Result<(), glib::error::BoolError> {
|
||||
unsafe {
|
||||
from_glib(ffi::gst_device_reconfigure_element(self.as_ref().to_glib_none().0, element.as_ref().to_glib_none().0))
|
||||
glib_result_from_gboolean!(ffi::gst_device_reconfigure_element(self.as_ref().to_glib_none().0, element.as_ref().to_glib_none().0), "Failed to reconfigure the element to use this device")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ pub trait DeviceMonitorExt: 'static {
|
|||
|
||||
fn get_show_all_devices(&self) -> bool;
|
||||
|
||||
fn remove_filter(&self, filter_id: u32) -> bool;
|
||||
fn remove_filter(&self, filter_id: u32) -> Result<(), glib::error::BoolError>;
|
||||
|
||||
fn set_show_all_devices(&self, show_all: bool);
|
||||
|
||||
|
@ -93,9 +93,9 @@ impl<O: IsA<DeviceMonitor>> DeviceMonitorExt for O {
|
|||
}
|
||||
}
|
||||
|
||||
fn remove_filter(&self, filter_id: u32) -> bool {
|
||||
fn remove_filter(&self, filter_id: u32) -> Result<(), glib::error::BoolError> {
|
||||
unsafe {
|
||||
from_glib(ffi::gst_device_monitor_remove_filter(self.as_ref().to_glib_none().0, filter_id))
|
||||
glib_result_from_gboolean!(ffi::gst_device_monitor_remove_filter(self.as_ref().to_glib_none().0, filter_id), "Failed to remove the filter")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ use Error;
|
|||
#[cfg(any(feature = "v1_12", feature = "dox"))]
|
||||
use StackTraceFlags;
|
||||
use ffi;
|
||||
use glib;
|
||||
use glib::GString;
|
||||
use glib::object::IsA;
|
||||
use glib::translate::*;
|
||||
|
@ -177,10 +178,10 @@ pub fn parse_launchv(argv: &[&str]) -> Result<Element, Error> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn update_registry() -> bool {
|
||||
pub fn update_registry() -> Result<(), glib::error::BoolError> {
|
||||
assert_initialized_main_thread!();
|
||||
unsafe {
|
||||
from_glib(ffi::gst_update_registry())
|
||||
glib_result_from_gboolean!(ffi::gst_update_registry(), "Failed to update the registry")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -125,7 +125,7 @@ pub trait PadExt: 'static {
|
|||
fn link_maybe_ghosting<P: IsA<Pad>>(&self, sink: &P) -> Result<(), glib::error::BoolError>;
|
||||
|
||||
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
||||
fn link_maybe_ghosting_full<P: IsA<Pad>>(&self, sink: &P, flags: PadLinkCheck) -> bool;
|
||||
fn link_maybe_ghosting_full<P: IsA<Pad>>(&self, sink: &P, flags: PadLinkCheck) -> Result<(), glib::error::BoolError>;
|
||||
|
||||
fn mark_reconfigure(&self);
|
||||
|
||||
|
@ -357,14 +357,14 @@ impl<O: IsA<Pad>> PadExt for O {
|
|||
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
||||
fn link_maybe_ghosting<P: IsA<Pad>>(&self, sink: &P) -> Result<(), glib::error::BoolError> {
|
||||
unsafe {
|
||||
glib_result_from_gboolean!(ffi::gst_pad_link_maybe_ghosting(self.as_ref().to_glib_none().0, sink.as_ref().to_glib_none().0), "Failed to link pad, possibly ghosting")
|
||||
glib_result_from_gboolean!(ffi::gst_pad_link_maybe_ghosting(self.as_ref().to_glib_none().0, sink.as_ref().to_glib_none().0), "Failed to link pads, possibly ghosting")
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
||||
fn link_maybe_ghosting_full<P: IsA<Pad>>(&self, sink: &P, flags: PadLinkCheck) -> bool {
|
||||
fn link_maybe_ghosting_full<P: IsA<Pad>>(&self, sink: &P, flags: PadLinkCheck) -> Result<(), glib::error::BoolError> {
|
||||
unsafe {
|
||||
from_glib(ffi::gst_pad_link_maybe_ghosting_full(self.as_ref().to_glib_none().0, sink.as_ref().to_glib_none().0, flags.to_glib()))
|
||||
glib_result_from_gboolean!(ffi::gst_pad_link_maybe_ghosting_full(self.as_ref().to_glib_none().0, sink.as_ref().to_glib_none().0, flags.to_glib()), "Failed to link pads, possibly ghosting")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,18 +10,28 @@ use Bin;
|
|||
use Element;
|
||||
|
||||
use glib;
|
||||
use glib::object::Cast;
|
||||
use glib::object::IsA;
|
||||
use glib::translate::{from_glib, from_glib_full, FromGlibPtrContainer, ToGlib, ToGlibPtr};
|
||||
use glib::signal::connect_raw;
|
||||
use glib::signal::SignalHandlerId;
|
||||
use glib::translate::*;
|
||||
use glib::GString;
|
||||
|
||||
use ffi;
|
||||
|
||||
use std::boxed::Box as Box_;
|
||||
use std::mem::transmute;
|
||||
use std::path;
|
||||
|
||||
pub trait GstBinExtManual: 'static {
|
||||
fn add_many<E: IsA<Element>>(&self, elements: &[&E]) -> Result<(), glib::BoolError>;
|
||||
fn remove_many<E: IsA<Element>>(&self, elements: &[&E]) -> Result<(), glib::BoolError>;
|
||||
|
||||
fn connect_do_latency<F: Fn(&Self) -> Result<(), glib::BoolError> + Send + Sync + 'static>(
|
||||
&self,
|
||||
f: F,
|
||||
) -> SignalHandlerId;
|
||||
|
||||
fn iterate_all_by_interface(&self, iface: glib::types::Type) -> ::Iterator<Element>;
|
||||
fn iterate_elements(&self) -> ::Iterator<Element>;
|
||||
fn iterate_recurse(&self) -> ::Iterator<Element>;
|
||||
|
@ -64,7 +74,7 @@ impl<O: IsA<Bin>> GstBinExtManual for O {
|
|||
e.as_ref().to_glib_none().0,
|
||||
));
|
||||
if !ret {
|
||||
return Err(glib_bool_error!("Failed to add elements"));
|
||||
return Err(glib_bool_error!("Failed to remove elements"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -72,6 +82,22 @@ impl<O: IsA<Bin>> GstBinExtManual for O {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn connect_do_latency<F: Fn(&Self) -> Result<(), glib::BoolError> + Send + Sync + 'static>(
|
||||
&self,
|
||||
f: F,
|
||||
) -> SignalHandlerId {
|
||||
unsafe {
|
||||
let f: Box_<Box_<Fn(&Self) -> Result<(), glib::BoolError> + Send + Sync + 'static>> =
|
||||
Box_::new(Box_::new(f));
|
||||
connect_raw(
|
||||
self.as_ptr() as *mut _,
|
||||
b"do-latency\0".as_ptr() as *const _,
|
||||
transmute(do_latency_trampoline::<Self> as usize),
|
||||
Box_::into_raw(f) as *mut _,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn iterate_all_by_interface(&self, iface: glib::types::Type) -> ::Iterator<Element> {
|
||||
unsafe {
|
||||
from_glib_full(ffi::gst_bin_iterate_all_by_interface(
|
||||
|
@ -130,6 +156,24 @@ impl<O: IsA<Bin>> GstBinExtManual for O {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe extern "C" fn do_latency_trampoline<P>(
|
||||
this: *mut ffi::GstBin,
|
||||
f: glib_ffi::gpointer,
|
||||
) -> glib_ffi::gboolean
|
||||
where
|
||||
P: IsA<Bin>,
|
||||
{
|
||||
let f: &&(Fn(&P) -> Result<(), glib::BoolError> + Send + Sync + 'static) = transmute(f);
|
||||
match f(&Bin::from_glib_borrow(this).unsafe_cast()) {
|
||||
Ok(()) => true,
|
||||
Err(err) => {
|
||||
gst_error!(::CAT_RUST, obj: &Bin::from_glib_borrow(this), "{}", err);
|
||||
false
|
||||
}
|
||||
}
|
||||
.to_glib()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
|
@ -131,17 +131,20 @@ impl BufferPoolConfig {
|
|||
size: u32,
|
||||
min_buffers: u32,
|
||||
max_buffers: u32,
|
||||
) -> bool {
|
||||
) -> Result<(), glib::BoolError> {
|
||||
let caps = caps.into();
|
||||
|
||||
unsafe {
|
||||
from_glib(ffi::gst_buffer_pool_config_validate_params(
|
||||
self.0.to_glib_none().0,
|
||||
caps.to_glib_none().0,
|
||||
size,
|
||||
min_buffers,
|
||||
max_buffers,
|
||||
))
|
||||
glib_result_from_gboolean!(
|
||||
ffi::gst_buffer_pool_config_validate_params(
|
||||
self.0.to_glib_none().0,
|
||||
caps.to_glib_none().0,
|
||||
size,
|
||||
min_buffers,
|
||||
max_buffers,
|
||||
),
|
||||
"Parameters are not valid in this context"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -58,16 +58,19 @@ impl GhostPad {
|
|||
parent: R,
|
||||
mode: PadMode,
|
||||
active: bool,
|
||||
) -> bool {
|
||||
) -> Result<(), glib::BoolError> {
|
||||
skip_assert_initialized!();
|
||||
let parent = parent.into();
|
||||
unsafe {
|
||||
from_glib(ffi::gst_ghost_pad_activate_mode_default(
|
||||
pad.to_glib_none().0 as *mut ffi::GstPad,
|
||||
parent.map(|p| p.as_ref()).to_glib_none().0,
|
||||
mode.to_glib(),
|
||||
active.to_glib(),
|
||||
))
|
||||
glib_result_from_gboolean!(
|
||||
ffi::gst_ghost_pad_activate_mode_default(
|
||||
pad.to_glib_none().0 as *mut ffi::GstPad,
|
||||
parent.map(|p| p.as_ref()).to_glib_none().0,
|
||||
mode.to_glib(),
|
||||
active.to_glib(),
|
||||
),
|
||||
"Failed to invoke the default activate mode function of the ghost pad"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,16 +84,22 @@ impl GhostPad {
|
|||
parent: R,
|
||||
mode: PadMode,
|
||||
active: bool,
|
||||
) -> bool {
|
||||
) -> Result<(), glib::BoolError> {
|
||||
skip_assert_initialized!();
|
||||
let parent = parent.into();
|
||||
unsafe {
|
||||
from_glib(ffi::gst_ghost_pad_internal_activate_mode_default(
|
||||
pad.to_glib_none().0 as *mut ffi::GstPad,
|
||||
parent.map(|p| p.as_ref()).to_glib_none().0,
|
||||
mode.to_glib(),
|
||||
active.to_glib(),
|
||||
))
|
||||
glib_result_from_gboolean!(
|
||||
ffi::gst_ghost_pad_internal_activate_mode_default(
|
||||
pad.to_glib_none().0 as *mut ffi::GstPad,
|
||||
parent.map(|p| p.as_ref()).to_glib_none().0,
|
||||
mode.to_glib(),
|
||||
active.to_glib(),
|
||||
),
|
||||
concat!(
|
||||
"Failed to invoke the default activate mode function of a proxy pad ",
|
||||
"that is owned by the ghost pad"
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -161,11 +161,14 @@ pub trait PadExtManual: 'static {
|
|||
|
||||
fn set_activate_function<F>(&self, func: F)
|
||||
where
|
||||
F: Fn(&Pad, &Option<::Object>) -> bool + Send + Sync + 'static;
|
||||
F: Fn(&Pad, &Option<::Object>) -> Result<(), glib::BoolError> + Send + Sync + 'static;
|
||||
|
||||
fn set_activatemode_function<F>(&self, func: F)
|
||||
where
|
||||
F: Fn(&Pad, &Option<::Object>, ::PadMode, bool) -> bool + Send + Sync + 'static;
|
||||
F: Fn(&Pad, &Option<::Object>, ::PadMode, bool) -> Result<(), glib::BoolError>
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static;
|
||||
|
||||
fn set_chain_function<F>(&self, func: F)
|
||||
where
|
||||
|
@ -510,12 +513,13 @@ impl<O: IsA<Pad>> PadExtManual for O {
|
|||
|
||||
fn set_activate_function<F>(&self, func: F)
|
||||
where
|
||||
F: Fn(&Pad, &Option<::Object>) -> bool + Send + Sync + 'static,
|
||||
F: Fn(&Pad, &Option<::Object>) -> Result<(), glib::BoolError> + Send + Sync + 'static,
|
||||
{
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
|
||||
unsafe {
|
||||
let func_box: Box<Fn(&Pad, &Option<::Object>) -> bool + Send + Sync + 'static> =
|
||||
Box::new(func);
|
||||
let func_box: Box<
|
||||
Fn(&Pad, &Option<::Object>) -> Result<(), glib::BoolError> + Send + Sync + 'static,
|
||||
> = Box::new(func);
|
||||
ffi::gst_pad_set_activate_function_full(
|
||||
self.as_ref().to_glib_none().0,
|
||||
Some(trampoline_activate_function),
|
||||
|
@ -527,12 +531,18 @@ impl<O: IsA<Pad>> PadExtManual for O {
|
|||
|
||||
fn set_activatemode_function<F>(&self, func: F)
|
||||
where
|
||||
F: Fn(&Pad, &Option<::Object>, ::PadMode, bool) -> bool + Send + Sync + 'static,
|
||||
F: Fn(&Pad, &Option<::Object>, ::PadMode, bool) -> Result<(), glib::BoolError>
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static,
|
||||
{
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
|
||||
unsafe {
|
||||
let func_box: Box<
|
||||
Fn(&Pad, &Option<::Object>, ::PadMode, bool) -> bool + Send + Sync + 'static,
|
||||
Fn(&Pad, &Option<::Object>, ::PadMode, bool) -> Result<(), glib::BoolError>
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static,
|
||||
> = Box::new(func);
|
||||
ffi::gst_pad_set_activatemode_function_full(
|
||||
self.as_ref().to_glib_none().0,
|
||||
|
@ -1106,10 +1116,20 @@ unsafe extern "C" fn trampoline_activate_function(
|
|||
parent: *mut ffi::GstObject,
|
||||
) -> glib_ffi::gboolean {
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
||||
let func: &&(Fn(&Pad, &Option<::Object>) -> bool + Send + Sync + 'static) =
|
||||
transmute((*pad).activatedata);
|
||||
let func: &&(Fn(&Pad, &Option<::Object>) -> Result<(), glib::BoolError>
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static) = transmute((*pad).activatedata);
|
||||
|
||||
func(&from_glib_borrow(pad), &from_glib_borrow(parent)).to_glib()
|
||||
let pad: Pad = from_glib_borrow(pad);
|
||||
match func(&pad, &from_glib_borrow(parent)) {
|
||||
Ok(()) => true,
|
||||
Err(err) => {
|
||||
gst_error!(::CAT_RUST, obj: &pad, "{}", err);
|
||||
false
|
||||
}
|
||||
}
|
||||
.to_glib()
|
||||
}
|
||||
|
||||
unsafe extern "C" fn trampoline_activatemode_function(
|
||||
|
|
|
@ -171,13 +171,16 @@ impl<T: FormattedValue> FormattedSegment<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn offset_running_time(&mut self, offset: i64) -> bool {
|
||||
pub fn offset_running_time(&mut self, offset: i64) -> Result<(), glib::BoolError> {
|
||||
unsafe {
|
||||
from_glib(ffi::gst_segment_offset_running_time(
|
||||
&mut self.0,
|
||||
self.get_format().to_glib(),
|
||||
offset,
|
||||
))
|
||||
glib_result_from_gboolean!(
|
||||
ffi::gst_segment_offset_running_time(
|
||||
&mut self.0,
|
||||
self.get_format().to_glib(),
|
||||
offset,
|
||||
),
|
||||
"Offset is not in the segment"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -257,7 +260,7 @@ impl<T: FormattedValue> FormattedSegment<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn set_running_time<V: Into<T>>(&mut self, running_time: V) -> bool {
|
||||
pub fn set_running_time<V: Into<T>>(&mut self, running_time: V) -> Result<(), glib::BoolError> {
|
||||
let running_time = running_time.into();
|
||||
|
||||
if T::get_default_format() == Format::Undefined {
|
||||
|
@ -265,11 +268,14 @@ impl<T: FormattedValue> FormattedSegment<T> {
|
|||
}
|
||||
|
||||
unsafe {
|
||||
from_glib(ffi::gst_segment_set_running_time(
|
||||
&mut self.0,
|
||||
self.get_format().to_glib(),
|
||||
running_time.to_raw_value() as u64,
|
||||
))
|
||||
glib_result_from_gboolean!(
|
||||
ffi::gst_segment_set_running_time(
|
||||
&mut self.0,
|
||||
self.get_format().to_glib(),
|
||||
running_time.to_raw_value() as u64,
|
||||
),
|
||||
"Running time is not in the segment"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,11 +20,11 @@ use Element;
|
|||
use Message;
|
||||
|
||||
pub trait BinImpl: ElementImpl + Send + Sync + 'static {
|
||||
fn add_element(&self, bin: &Bin, element: &Element) -> bool {
|
||||
fn add_element(&self, bin: &Bin, element: &Element) -> Result<(), glib::BoolError> {
|
||||
self.parent_add_element(bin, element)
|
||||
}
|
||||
|
||||
fn remove_element(&self, bin: &Bin, element: &Element) -> bool {
|
||||
fn remove_element(&self, bin: &Bin, element: &Element) -> Result<(), glib::BoolError> {
|
||||
self.parent_remove_element(bin, element)
|
||||
}
|
||||
|
||||
|
@ -32,25 +32,31 @@ pub trait BinImpl: ElementImpl + Send + Sync + 'static {
|
|||
self.parent_handle_message(bin, message)
|
||||
}
|
||||
|
||||
fn parent_add_element(&self, bin: &Bin, element: &Element) -> bool {
|
||||
fn parent_add_element(&self, bin: &Bin, element: &Element) -> Result<(), glib::BoolError> {
|
||||
unsafe {
|
||||
let data = self.get_type_data();
|
||||
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstBinClass;
|
||||
(*parent_class)
|
||||
let f = (*parent_class)
|
||||
.add_element
|
||||
.map(|f| from_glib(f(bin.to_glib_none().0, element.to_glib_none().0)))
|
||||
.unwrap_or(false)
|
||||
.ok_or_else(|| glib_bool_error!("Parent function `add_element` is not defined"))?;
|
||||
glib_result_from_gboolean!(
|
||||
f(bin.to_glib_none().0, element.to_glib_none().0),
|
||||
"Failed to add the element using the parent function"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn parent_remove_element(&self, bin: &Bin, element: &Element) -> bool {
|
||||
fn parent_remove_element(&self, bin: &Bin, element: &Element) -> Result<(), glib::BoolError> {
|
||||
unsafe {
|
||||
let data = self.get_type_data();
|
||||
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstBinClass;
|
||||
(*parent_class)
|
||||
.remove_element
|
||||
.map(|f| from_glib(f(bin.to_glib_none().0, element.to_glib_none().0)))
|
||||
.unwrap_or(false)
|
||||
let f = (*parent_class).remove_element.ok_or_else(|| {
|
||||
glib_bool_error!("Parent function `remove_element` is not defined")
|
||||
})?;
|
||||
glib_result_from_gboolean!(
|
||||
f(bin.to_glib_none().0, element.to_glib_none().0),
|
||||
"Failed to remove the element using the parent function"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,7 +100,13 @@ where
|
|||
let wrap: Bin = from_glib_borrow(ptr);
|
||||
|
||||
gst_panic_to_error!(&wrap, &instance.panicked(), false, {
|
||||
imp.add_element(&wrap, &from_glib_borrow(element))
|
||||
match imp.add_element(&wrap, &from_glib_borrow(element)) {
|
||||
Ok(()) => true,
|
||||
Err(err) => {
|
||||
gst_error!(::CAT_RUST, obj: &wrap, "{}", err);
|
||||
false
|
||||
}
|
||||
}
|
||||
})
|
||||
.to_glib()
|
||||
}
|
||||
|
@ -113,7 +125,13 @@ where
|
|||
let wrap: Bin = from_glib_borrow(ptr);
|
||||
|
||||
gst_panic_to_error!(&wrap, &instance.panicked(), false, {
|
||||
imp.remove_element(&wrap, &from_glib_borrow(element))
|
||||
match imp.remove_element(&wrap, &from_glib_borrow(element)) {
|
||||
Ok(()) => true,
|
||||
Err(err) => {
|
||||
gst_error!(::CAT_RUST, obj: &wrap, "{}", err);
|
||||
false
|
||||
}
|
||||
}
|
||||
})
|
||||
.to_glib()
|
||||
}
|
||||
|
|
|
@ -48,20 +48,23 @@ macro_rules! gst_plugin_define(
|
|||
_gst_reserved: [0 as $crate::glib_ffi::gpointer; 4],
|
||||
});
|
||||
|
||||
pub fn plugin_register_static() -> bool {
|
||||
pub fn plugin_register_static() -> Result<(), glib::BoolError> {
|
||||
unsafe {
|
||||
from_glib($crate::ffi::gst_plugin_register_static(
|
||||
$crate::subclass::plugin::MAJOR_VERSION,
|
||||
$crate::subclass::plugin::MINOR_VERSION,
|
||||
concat!($name, "\0") as *const str as *const _,
|
||||
concat!($description, "\0") as *const str as _,
|
||||
Some(plugin_init_trampoline),
|
||||
concat!($version, "\0") as *const str as *const _,
|
||||
concat!($license, "\0") as *const str as *const _,
|
||||
concat!($source, "\0") as *const str as *const _,
|
||||
concat!($package, "\0") as *const str as *const _,
|
||||
concat!($origin, "\0") as *const str as *const _,
|
||||
))
|
||||
glib_result_from_gboolean!(
|
||||
$crate::ffi::gst_plugin_register_static(
|
||||
$crate::subclass::plugin::MAJOR_VERSION,
|
||||
$crate::subclass::plugin::MINOR_VERSION,
|
||||
concat!($name, "\0") as *const str as *const _,
|
||||
concat!($description, "\0") as *const str as _,
|
||||
Some(plugin_init_trampoline),
|
||||
concat!($version, "\0") as *const str as *const _,
|
||||
concat!($license, "\0") as *const str as *const _,
|
||||
concat!($source, "\0") as *const str as *const _,
|
||||
concat!($package, "\0") as *const str as *const _,
|
||||
concat!($origin, "\0") as *const str as *const _,
|
||||
),
|
||||
"Failed to register the plugin"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -80,8 +80,8 @@ fn tutorial_main() -> Result<(), Error> {
|
|||
|
||||
main_loop.run();
|
||||
|
||||
bus.remove_watch();
|
||||
let _ = pipeline.set_state(gst::State::Null);
|
||||
bus.remove_watch()?;
|
||||
pipeline.set_state(gst::State::Null)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue