mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-12-27 02:20:30 +00:00
Add Promise bindings
This commit is contained in:
parent
0112d22804
commit
3a755219f4
5 changed files with 203 additions and 0 deletions
|
@ -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"
|
||||
|
|
|
@ -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<ffi::GstPromiseResult> 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<Self> {
|
||||
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,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
120
gstreamer/src/promise.rs
Normal file
120
gstreamer/src/promise.rs
Normal file
|
@ -0,0 +1,120 @@
|
|||
// Copyright (C) 2018 Sebastian Dröge <sebastian@centricular.com>
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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<ffi::GstPromise>);
|
||||
|
||||
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<F>(func: F) -> Promise
|
||||
where F: FnOnce(&Promise) + Send + 'static {
|
||||
let user_data: Box<Option<Box<F>>> = Box::new(Some(Box::new(func)));
|
||||
|
||||
unsafe extern "C" fn trampoline<F: FnOnce(&Promise) + Send + 'static>(
|
||||
promise: *mut ffi::GstPromise,
|
||||
user_data: glib_ffi::gpointer,
|
||||
) {
|
||||
callback_guard!();
|
||||
let user_data: &mut Option<Box<F>> = &mut *(user_data as *mut _);
|
||||
let callback = user_data.take().unwrap();
|
||||
|
||||
callback(&from_glib_borrow(promise));
|
||||
}
|
||||
|
||||
unsafe extern "C" fn free_user_data<F: FnOnce(&Promise) + Send + 'static>(
|
||||
user_data: glib_ffi::gpointer,
|
||||
) {
|
||||
let _: Box<Option<Box<F>>> = Box::from_raw(user_data as *mut _);
|
||||
}
|
||||
|
||||
let trampoline = trampoline::<F>;
|
||||
let free_user_data = free_user_data::<F>;
|
||||
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 {}
|
Loading…
Reference in a new issue