diff --git a/Gir_Gst.toml b/Gir_Gst.toml index fc0de464b..7964c9bc7 100644 --- a/Gir_Gst.toml +++ b/Gir_Gst.toml @@ -71,6 +71,7 @@ generate = [ "Gst.DateTime", "Gst.TypeFindProbability", "Gst.BufferPoolAcquireFlags", + "Gst.PromiseResult", ] manual = [ @@ -217,6 +218,11 @@ name = "Gst.TocEntry" status = "manual" ref_mode = "ref" +[[object]] +name = "Gst.Promise" +status = "manual" +ref_mode = "ref" + [[object]] name = "Gst.Clock" status = "generate" diff --git a/gstreamer/src/auto/enums.rs b/gstreamer/src/auto/enums.rs index 47eb0a92d..15a5ba18a 100644 --- a/gstreamer/src/auto/enums.rs +++ b/gstreamer/src/auto/enums.rs @@ -1505,6 +1505,76 @@ impl SetValue for ProgressType { } } +#[cfg(any(feature = "v1_14", feature = "dox"))] +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] +pub enum PromiseResult { + Pending, + Interrupted, + Replied, + Expired, + #[doc(hidden)] + __Unknown(i32), +} + +#[cfg(any(feature = "v1_14", feature = "dox"))] +#[doc(hidden)] +impl ToGlib for PromiseResult { + type GlibType = ffi::GstPromiseResult; + + fn to_glib(&self) -> ffi::GstPromiseResult { + match *self { + PromiseResult::Pending => ffi::GST_PROMISE_RESULT_PENDING, + PromiseResult::Interrupted => ffi::GST_PROMISE_RESULT_INTERRUPTED, + PromiseResult::Replied => ffi::GST_PROMISE_RESULT_REPLIED, + PromiseResult::Expired => ffi::GST_PROMISE_RESULT_EXPIRED, + PromiseResult::__Unknown(value) => value + } + } +} + +#[cfg(any(feature = "v1_14", feature = "dox"))] +#[doc(hidden)] +impl FromGlib for PromiseResult { + fn from_glib(value: ffi::GstPromiseResult) -> Self { + skip_assert_initialized!(); + match value { + 0 => PromiseResult::Pending, + 1 => PromiseResult::Interrupted, + 2 => PromiseResult::Replied, + 3 => PromiseResult::Expired, + value => PromiseResult::__Unknown(value), + } + } +} + +#[cfg(any(feature = "v1_14", feature = "dox"))] +impl StaticType for PromiseResult { + fn static_type() -> Type { + unsafe { from_glib(ffi::gst_promise_result_get_type()) } + } +} + +#[cfg(any(feature = "v1_14", feature = "dox"))] +impl<'a> FromValueOptional<'a> for PromiseResult { + unsafe fn from_value_optional(value: &Value) -> Option { + Some(FromValue::from_value(value)) + } +} + +#[cfg(any(feature = "v1_14", feature = "dox"))] +impl<'a> FromValue<'a> for PromiseResult { + unsafe fn from_value(value: &Value) -> Self { + from_glib(gobject_ffi::g_value_get_enum(value.to_glib_none().0)) + } +} + +#[cfg(any(feature = "v1_14", feature = "dox"))] +impl SetValue for PromiseResult { + unsafe fn set_value(value: &mut Value, this: &Self) { + gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, this.to_glib()) + } +} + #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] pub enum QOSType { Overflow, diff --git a/gstreamer/src/auto/mod.rs b/gstreamer/src/auto/mod.rs index 61288c883..62813a8eb 100644 --- a/gstreamer/src/auto/mod.rs +++ b/gstreamer/src/auto/mod.rs @@ -132,6 +132,8 @@ pub use self::enums::PadProbeReturn; pub use self::enums::ParseError; pub use self::enums::PluginError; pub use self::enums::ProgressType; +#[cfg(any(feature = "v1_14", feature = "dox"))] +pub use self::enums::PromiseResult; pub use self::enums::QOSType; pub use self::enums::Rank; pub use self::enums::ResourceError; diff --git a/gstreamer/src/lib.rs b/gstreamer/src/lib.rs index a2d2d22d8..f01040151 100644 --- a/gstreamer/src/lib.rs +++ b/gstreamer/src/lib.rs @@ -94,6 +94,11 @@ pub use static_caps::*; mod static_pad_template; pub use static_pad_template::*; +#[cfg(any(feature = "v1_14", feature = "dox"))] +mod promise; +#[cfg(any(feature = "v1_14", feature = "dox"))] +pub use promise::*; + mod element; mod bin; mod bus; diff --git a/gstreamer/src/promise.rs b/gstreamer/src/promise.rs new file mode 100644 index 000000000..5bd03f6d1 --- /dev/null +++ b/gstreamer/src/promise.rs @@ -0,0 +1,120 @@ +// Copyright (C) 2018 Sebastian Dröge +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use StructureRef; +use Structure; +use ffi; +use glib::translate::*; +use glib_ffi; +use gobject_ffi; +use std::mem; +use std::ptr; +use PromiseResult; + +glib_wrapper! { + pub struct Promise(Shared); + + match fn { + ref => |ptr| ffi::gst_mini_object_ref(ptr as *mut _) as *mut ffi::GstPromise, + unref => |ptr| ffi::gst_mini_object_unref(ptr as *mut _), + get_type => || ffi::gst_promise_get_type(), + } +} + +impl Promise { + #[cfg(any(feature = "v1_14", feature = "dox"))] + pub fn new() -> Promise { + assert_initialized_main_thread!(); + unsafe { + from_glib_full(ffi::gst_promise_new()) + } + } + + #[cfg(any(feature = "v1_14", feature = "dox"))] + pub fn new_with_change_func(func: F) -> Promise + where F: FnOnce(&Promise) + Send + 'static { + let user_data: Box>> = Box::new(Some(Box::new(func))); + + unsafe extern "C" fn trampoline( + promise: *mut ffi::GstPromise, + user_data: glib_ffi::gpointer, + ) { + callback_guard!(); + let user_data: &mut Option> = &mut *(user_data as *mut _); + let callback = user_data.take().unwrap(); + + callback(&from_glib_borrow(promise)); + } + + unsafe extern "C" fn free_user_data( + user_data: glib_ffi::gpointer, + ) { + let _: Box>> = Box::from_raw(user_data as *mut _); + } + + let trampoline = trampoline::; + let free_user_data = free_user_data::; + unsafe { + from_glib_full(ffi::gst_promise_new_with_change_func( + Some(trampoline), + Box::into_raw(user_data) as *mut _, + Some(free_user_data), + )) + } + } + + #[cfg(any(feature = "v1_14", feature = "dox"))] + pub fn expire(&self) { + unsafe { + ffi::gst_promise_expire(self.to_glib_none().0); + } + } + + #[cfg(any(feature = "v1_14", feature = "dox"))] + pub fn get_reply(&self) -> Option<&StructureRef> { + unsafe { + let s = ffi::gst_promise_get_reply(self.to_glib_none().0); + if s.is_null() { + None + } else { + Some(StructureRef::from_glib_borrow(s)) + } + } + } + + #[cfg(any(feature = "v1_14", feature = "dox"))] + pub fn interrupt(&self) { + unsafe { + ffi::gst_promise_interrupt(self.to_glib_none().0); + } + } + + #[cfg(any(feature = "v1_14", feature = "dox"))] + pub fn reply(&self, s: Structure) { + unsafe { + ffi::gst_promise_reply(self.to_glib_none().0, s.into_ptr()); + } + } + + #[cfg(any(feature = "v1_14", feature = "dox"))] + pub fn wait(&self) -> PromiseResult { + unsafe { + from_glib(ffi::gst_promise_wait(self.to_glib_none().0)) + } + } +} + +#[cfg(any(feature = "v1_14", feature = "dox"))] +impl Default for Promise { + fn default() -> Self { + Self::new() + } +} + +unsafe impl Send for Promise {} +unsafe impl Sync for Promise {}