From 77cb4da32aef7fde336f28d78a4bdbd4ffe36472 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 14 Aug 2017 01:40:43 +0300 Subject: [PATCH] Add ClockId and related waiting API, and SystemClock Fixes https://github.com/sdroege/gstreamer-rs/issues/23 --- Gir_Gst.toml | 11 + gstreamer/src/auto/alias.rs | 3 +- gstreamer/src/auto/bin.rs | 2 +- gstreamer/src/auto/bus.rs | 2 +- gstreamer/src/auto/child_proxy.rs | 2 +- gstreamer/src/auto/clock.rs | 6 +- gstreamer/src/auto/date_time.rs | 2 +- gstreamer/src/auto/device.rs | 2 +- gstreamer/src/auto/device_monitor.rs | 2 +- gstreamer/src/auto/device_provider.rs | 2 +- gstreamer/src/auto/device_provider_factory.rs | 2 +- gstreamer/src/auto/element.rs | 2 +- gstreamer/src/auto/element_factory.rs | 2 +- gstreamer/src/auto/enums.rs | 137 ++++++++++- gstreamer/src/auto/flags.rs | 2 +- gstreamer/src/auto/functions.rs | 2 +- gstreamer/src/auto/ghost_pad.rs | 2 +- gstreamer/src/auto/mod.rs | 10 +- gstreamer/src/auto/object.rs | 2 +- gstreamer/src/auto/pad.rs | 2 +- gstreamer/src/auto/pad_template.rs | 2 +- gstreamer/src/auto/pipeline.rs | 2 +- gstreamer/src/auto/plugin.rs | 2 +- gstreamer/src/auto/preset.rs | 2 +- gstreamer/src/auto/proxy_pad.rs | 2 +- gstreamer/src/auto/stream.rs | 2 +- gstreamer/src/auto/stream_collection.rs | 2 +- gstreamer/src/auto/system_clock.rs | 66 +++++ gstreamer/src/auto/tag_setter.rs | 2 +- gstreamer/src/auto/toc_setter.rs | 2 +- gstreamer/src/auto/u_r_i_handler.rs | 2 +- gstreamer/src/bus.rs | 16 +- gstreamer/src/clock.rs | 232 ++++++++++++++++++ gstreamer/src/lib.rs | 3 + 34 files changed, 497 insertions(+), 37 deletions(-) create mode 100644 gstreamer/src/auto/system_clock.rs create mode 100644 gstreamer/src/clock.rs diff --git a/Gir_Gst.toml b/Gir_Gst.toml index 6304c429c..4d33be4be 100644 --- a/Gir_Gst.toml +++ b/Gir_Gst.toml @@ -15,6 +15,7 @@ external_libraries = [ generate = [ "Gst.ClockTime", + "Gst.ClockTimeDiff", "Gst.Pipeline", "Gst.State", "Gst.StateChangeReturn", @@ -64,6 +65,8 @@ generate = [ "Gst.TocEntryType", "Gst.TocLoopType", "Gst.TocSetter", + "Gst.ClockType", + "Gst.ClockReturn", ] manual = [ @@ -193,6 +196,14 @@ status = "generate" [object.function.return] bool_return_is_error = "Timed out waiting for sync" +[[object]] +name = "Gst.SystemClock" +status = "generate" + [[object.function]] + name = "obtain" + [object.function.return] + nullable = false + [[object]] name = "Gst.Element" status = "generate" diff --git a/gstreamer/src/auto/alias.rs b/gstreamer/src/auto/alias.rs index bf6107c1d..d9b1509de 100644 --- a/gstreamer/src/auto/alias.rs +++ b/gstreamer/src/auto/alias.rs @@ -1,8 +1,9 @@ -// This file was generated by gir (3294959) from gir-files (???) +// This file was generated by gir (cf27827) from gir-files (???) // DO NOT EDIT #[allow(unused_imports)] use auto::*; pub type ClockTime = u64; +pub type ClockTimeDiff = i64; pub type ElementFactoryListType = u64; diff --git a/gstreamer/src/auto/bin.rs b/gstreamer/src/auto/bin.rs index 82a0bf879..6aa2240e3 100644 --- a/gstreamer/src/auto/bin.rs +++ b/gstreamer/src/auto/bin.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (3294959) from gir-files (???) +// This file was generated by gir (cf27827) from gir-files (???) // DO NOT EDIT use ChildProxy; diff --git a/gstreamer/src/auto/bus.rs b/gstreamer/src/auto/bus.rs index df1d445a3..ca6bf9ea8 100644 --- a/gstreamer/src/auto/bus.rs +++ b/gstreamer/src/auto/bus.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (3294959) from gir-files (???) +// This file was generated by gir (cf27827) from gir-files (???) // DO NOT EDIT use ClockTime; diff --git a/gstreamer/src/auto/child_proxy.rs b/gstreamer/src/auto/child_proxy.rs index 20623727d..282a5bfbf 100644 --- a/gstreamer/src/auto/child_proxy.rs +++ b/gstreamer/src/auto/child_proxy.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (3294959) from gir-files (???) +// This file was generated by gir (cf27827) from gir-files (???) // DO NOT EDIT use ffi; diff --git a/gstreamer/src/auto/clock.rs b/gstreamer/src/auto/clock.rs index e46b561fb..b9e84ef2d 100644 --- a/gstreamer/src/auto/clock.rs +++ b/gstreamer/src/auto/clock.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (3294959) from gir-files (???) +// This file was generated by gir (cf27827) from gir-files (???) // DO NOT EDIT use ClockTime; @@ -46,11 +46,11 @@ impl Clock { // unsafe { TODO: call ffi::gst_clock_id_unschedule() } //} - //pub fn id_wait(id: /*Unimplemented*/ClockID) -> (/*Ignored*/ClockReturn, ClockTimeDiff) { + //pub fn id_wait(id: /*Unimplemented*/ClockID) -> (ClockReturn, ClockTimeDiff) { // unsafe { TODO: call ffi::gst_clock_id_wait() } //} - //pub fn id_wait_async>>(id: /*Unimplemented*/ClockID, func: /*Unknown conversion*//*Unimplemented*/ClockCallback, user_data: P, destroy_data: /*Unknown conversion*//*Unimplemented*/DestroyNotify) -> /*Ignored*/ClockReturn { + //pub fn id_wait_async>>(id: /*Unimplemented*/ClockID, func: /*Unknown conversion*//*Unimplemented*/ClockCallback, user_data: P, destroy_data: /*Unknown conversion*//*Unimplemented*/DestroyNotify) -> ClockReturn { // unsafe { TODO: call ffi::gst_clock_id_wait_async() } //} } diff --git a/gstreamer/src/auto/date_time.rs b/gstreamer/src/auto/date_time.rs index 11b7fe597..bf94d57a9 100644 --- a/gstreamer/src/auto/date_time.rs +++ b/gstreamer/src/auto/date_time.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (3294959) from gir-files (???) +// This file was generated by gir (cf27827) from gir-files (???) // DO NOT EDIT use ffi; diff --git a/gstreamer/src/auto/device.rs b/gstreamer/src/auto/device.rs index c90192d5d..13732bca3 100644 --- a/gstreamer/src/auto/device.rs +++ b/gstreamer/src/auto/device.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (3294959) from gir-files (???) +// This file was generated by gir (cf27827) from gir-files (???) // DO NOT EDIT use Caps; diff --git a/gstreamer/src/auto/device_monitor.rs b/gstreamer/src/auto/device_monitor.rs index 7e2142e16..8534dca51 100644 --- a/gstreamer/src/auto/device_monitor.rs +++ b/gstreamer/src/auto/device_monitor.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (3294959) from gir-files (???) +// This file was generated by gir (cf27827) from gir-files (???) // DO NOT EDIT use Bus; diff --git a/gstreamer/src/auto/device_provider.rs b/gstreamer/src/auto/device_provider.rs index 4731a0176..6c2184657 100644 --- a/gstreamer/src/auto/device_provider.rs +++ b/gstreamer/src/auto/device_provider.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (3294959) from gir-files (???) +// This file was generated by gir (cf27827) from gir-files (???) // DO NOT EDIT use Bus; diff --git a/gstreamer/src/auto/device_provider_factory.rs b/gstreamer/src/auto/device_provider_factory.rs index 0361ab066..02c094431 100644 --- a/gstreamer/src/auto/device_provider_factory.rs +++ b/gstreamer/src/auto/device_provider_factory.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (3294959) from gir-files (???) +// This file was generated by gir (cf27827) from gir-files (???) // DO NOT EDIT use DeviceProvider; diff --git a/gstreamer/src/auto/element.rs b/gstreamer/src/auto/element.rs index f2b620b97..46958f5a0 100644 --- a/gstreamer/src/auto/element.rs +++ b/gstreamer/src/auto/element.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (3294959) from gir-files (???) +// This file was generated by gir (cf27827) from gir-files (???) // DO NOT EDIT use Bus; diff --git a/gstreamer/src/auto/element_factory.rs b/gstreamer/src/auto/element_factory.rs index bf113c49d..fee7c381c 100644 --- a/gstreamer/src/auto/element_factory.rs +++ b/gstreamer/src/auto/element_factory.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (3294959) from gir-files (???) +// This file was generated by gir (cf27827) from gir-files (???) // DO NOT EDIT use Caps; diff --git a/gstreamer/src/auto/enums.rs b/gstreamer/src/auto/enums.rs index cbb7f5234..564b7df75 100644 --- a/gstreamer/src/auto/enums.rs +++ b/gstreamer/src/auto/enums.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (3294959) from gir-files (???) +// This file was generated by gir (cf27827) from gir-files (???) // DO NOT EDIT use ffi; @@ -191,6 +191,141 @@ impl SetValue for CapsIntersectMode { } } +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] +pub enum ClockReturn { + Ok, + Early, + Unscheduled, + Busy, + Badtime, + Error, + Unsupported, + Done, + #[doc(hidden)] + __Unknown(i32), +} + +#[doc(hidden)] +impl ToGlib for ClockReturn { + type GlibType = ffi::GstClockReturn; + + fn to_glib(&self) -> ffi::GstClockReturn { + match *self { + ClockReturn::Ok => ffi::GST_CLOCK_OK, + ClockReturn::Early => ffi::GST_CLOCK_EARLY, + ClockReturn::Unscheduled => ffi::GST_CLOCK_UNSCHEDULED, + ClockReturn::Busy => ffi::GST_CLOCK_BUSY, + ClockReturn::Badtime => ffi::GST_CLOCK_BADTIME, + ClockReturn::Error => ffi::GST_CLOCK_ERROR, + ClockReturn::Unsupported => ffi::GST_CLOCK_UNSUPPORTED, + ClockReturn::Done => ffi::GST_CLOCK_DONE, + ClockReturn::__Unknown(value) => unsafe{std::mem::transmute(value)} + } + } +} + +#[doc(hidden)] +impl FromGlib for ClockReturn { + fn from_glib(value: ffi::GstClockReturn) -> Self { + skip_assert_initialized!(); + match value as i32 { + 0 => ClockReturn::Ok, + 1 => ClockReturn::Early, + 2 => ClockReturn::Unscheduled, + 3 => ClockReturn::Busy, + 4 => ClockReturn::Badtime, + 5 => ClockReturn::Error, + 6 => ClockReturn::Unsupported, + 7 => ClockReturn::Done, + value => ClockReturn::__Unknown(value), + } + } +} + +impl StaticType for ClockReturn { + fn static_type() -> Type { + unsafe { from_glib(ffi::gst_clock_return_get_type()) } + } +} + +impl<'a> FromValueOptional<'a> for ClockReturn { + unsafe fn from_value_optional(value: &Value) -> Option { + Some(FromValue::from_value(value)) + } +} + +impl<'a> FromValue<'a> for ClockReturn { + unsafe fn from_value(value: &Value) -> Self { + from_glib(std::mem::transmute::(gobject_ffi::g_value_get_enum(value.to_glib_none().0))) + } +} + +impl SetValue for ClockReturn { + unsafe fn set_value(value: &mut Value, this: &Self) { + gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, this.to_glib() as i32) + } +} + +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] +pub enum ClockType { + Realtime, + Monotonic, + Other, + #[doc(hidden)] + __Unknown(i32), +} + +#[doc(hidden)] +impl ToGlib for ClockType { + type GlibType = ffi::GstClockType; + + fn to_glib(&self) -> ffi::GstClockType { + match *self { + ClockType::Realtime => ffi::GST_CLOCK_TYPE_REALTIME, + ClockType::Monotonic => ffi::GST_CLOCK_TYPE_MONOTONIC, + ClockType::Other => ffi::GST_CLOCK_TYPE_OTHER, + ClockType::__Unknown(value) => unsafe{std::mem::transmute(value)} + } + } +} + +#[doc(hidden)] +impl FromGlib for ClockType { + fn from_glib(value: ffi::GstClockType) -> Self { + skip_assert_initialized!(); + match value as i32 { + 0 => ClockType::Realtime, + 1 => ClockType::Monotonic, + 2 => ClockType::Other, + value => ClockType::__Unknown(value), + } + } +} + +impl StaticType for ClockType { + fn static_type() -> Type { + unsafe { from_glib(ffi::gst_clock_type_get_type()) } + } +} + +impl<'a> FromValueOptional<'a> for ClockType { + unsafe fn from_value_optional(value: &Value) -> Option { + Some(FromValue::from_value(value)) + } +} + +impl<'a> FromValue<'a> for ClockType { + unsafe fn from_value(value: &Value) -> Self { + from_glib(std::mem::transmute::(gobject_ffi::g_value_get_enum(value.to_glib_none().0))) + } +} + +impl SetValue for ClockType { + unsafe fn set_value(value: &mut Value, this: &Self) { + gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, this.to_glib() as i32) + } +} + #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] pub enum CoreError { Failed, diff --git a/gstreamer/src/auto/flags.rs b/gstreamer/src/auto/flags.rs index 45a0ae76a..7eec3417b 100644 --- a/gstreamer/src/auto/flags.rs +++ b/gstreamer/src/auto/flags.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (3294959) from gir-files (???) +// This file was generated by gir (cf27827) from gir-files (???) // DO NOT EDIT use ffi; diff --git a/gstreamer/src/auto/functions.rs b/gstreamer/src/auto/functions.rs index 91e813600..3c5614640 100644 --- a/gstreamer/src/auto/functions.rs +++ b/gstreamer/src/auto/functions.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (3294959) from gir-files (???) +// This file was generated by gir (cf27827) from gir-files (???) // DO NOT EDIT use Bin; diff --git a/gstreamer/src/auto/ghost_pad.rs b/gstreamer/src/auto/ghost_pad.rs index 907e04c74..8597f00ff 100644 --- a/gstreamer/src/auto/ghost_pad.rs +++ b/gstreamer/src/auto/ghost_pad.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (3294959) from gir-files (???) +// This file was generated by gir (cf27827) from gir-files (???) // DO NOT EDIT use Object; diff --git a/gstreamer/src/auto/mod.rs b/gstreamer/src/auto/mod.rs index 544c647fc..da5bff8c8 100644 --- a/gstreamer/src/auto/mod.rs +++ b/gstreamer/src/auto/mod.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (3294959) from gir-files (???) +// This file was generated by gir (cf27827) from gir-files (???) // DO NOT EDIT mod bin; @@ -84,6 +84,10 @@ pub use self::stream_collection::StreamCollection; #[cfg(feature = "v1_10")] pub use self::stream_collection::StreamCollectionExt; +mod system_clock; +pub use self::system_clock::SystemClock; +pub use self::system_clock::SystemClockExt; + mod tag_setter; pub use self::tag_setter::TagSetter; pub use self::tag_setter::TagSetterExt; @@ -103,6 +107,8 @@ mod enums; pub use self::enums::BufferingMode; pub use self::enums::BusSyncReply; pub use self::enums::CapsIntersectMode; +pub use self::enums::ClockReturn; +pub use self::enums::ClockType; pub use self::enums::CoreError; pub use self::enums::EventType; pub use self::enums::FlowReturn; @@ -210,6 +216,7 @@ pub use self::flags::STREAM_TYPE_TEXT; mod alias; pub use self::alias::ClockTime; +pub use self::alias::ClockTimeDiff; pub use self::alias::ElementFactoryListType; pub mod functions; @@ -235,6 +242,7 @@ pub mod traits { pub use super::StreamExt; #[cfg(feature = "v1_10")] pub use super::StreamCollectionExt; + pub use super::SystemClockExt; pub use super::TagSetterExt; pub use super::TocSetterExt; pub use super::URIHandlerExt; diff --git a/gstreamer/src/auto/object.rs b/gstreamer/src/auto/object.rs index 3bbd05ce2..58b74ac82 100644 --- a/gstreamer/src/auto/object.rs +++ b/gstreamer/src/auto/object.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (3294959) from gir-files (???) +// This file was generated by gir (cf27827) from gir-files (???) // DO NOT EDIT use ClockTime; diff --git a/gstreamer/src/auto/pad.rs b/gstreamer/src/auto/pad.rs index 22ec7b8ca..717aacd39 100644 --- a/gstreamer/src/auto/pad.rs +++ b/gstreamer/src/auto/pad.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (3294959) from gir-files (???) +// This file was generated by gir (cf27827) from gir-files (???) // DO NOT EDIT use Caps; diff --git a/gstreamer/src/auto/pad_template.rs b/gstreamer/src/auto/pad_template.rs index 78e85a921..c5d5bc11d 100644 --- a/gstreamer/src/auto/pad_template.rs +++ b/gstreamer/src/auto/pad_template.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (3294959) from gir-files (???) +// This file was generated by gir (cf27827) from gir-files (???) // DO NOT EDIT use Caps; diff --git a/gstreamer/src/auto/pipeline.rs b/gstreamer/src/auto/pipeline.rs index 2ef8d1d2d..ab6ec37a1 100644 --- a/gstreamer/src/auto/pipeline.rs +++ b/gstreamer/src/auto/pipeline.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (3294959) from gir-files (???) +// This file was generated by gir (cf27827) from gir-files (???) // DO NOT EDIT use Bin; diff --git a/gstreamer/src/auto/plugin.rs b/gstreamer/src/auto/plugin.rs index a522dda97..ce012b9d3 100644 --- a/gstreamer/src/auto/plugin.rs +++ b/gstreamer/src/auto/plugin.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (3294959) from gir-files (???) +// This file was generated by gir (cf27827) from gir-files (???) // DO NOT EDIT use Error; diff --git a/gstreamer/src/auto/preset.rs b/gstreamer/src/auto/preset.rs index 62da94e8a..5f24095a0 100644 --- a/gstreamer/src/auto/preset.rs +++ b/gstreamer/src/auto/preset.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (3294959) from gir-files (???) +// This file was generated by gir (cf27827) from gir-files (???) // DO NOT EDIT use ffi; diff --git a/gstreamer/src/auto/proxy_pad.rs b/gstreamer/src/auto/proxy_pad.rs index 4cb4b5a50..3e0700ed0 100644 --- a/gstreamer/src/auto/proxy_pad.rs +++ b/gstreamer/src/auto/proxy_pad.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (3294959) from gir-files (???) +// This file was generated by gir (cf27827) from gir-files (???) // DO NOT EDIT use Iterator; diff --git a/gstreamer/src/auto/stream.rs b/gstreamer/src/auto/stream.rs index 2e6e78944..9d9b04e6b 100644 --- a/gstreamer/src/auto/stream.rs +++ b/gstreamer/src/auto/stream.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (3294959) from gir-files (???) +// This file was generated by gir (cf27827) from gir-files (???) // DO NOT EDIT #[cfg(feature = "v1_10")] diff --git a/gstreamer/src/auto/stream_collection.rs b/gstreamer/src/auto/stream_collection.rs index 5af3013ae..735c25f9f 100644 --- a/gstreamer/src/auto/stream_collection.rs +++ b/gstreamer/src/auto/stream_collection.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (3294959) from gir-files (???) +// This file was generated by gir (cf27827) from gir-files (???) // DO NOT EDIT use Object; diff --git a/gstreamer/src/auto/system_clock.rs b/gstreamer/src/auto/system_clock.rs new file mode 100644 index 000000000..cd0169d3b --- /dev/null +++ b/gstreamer/src/auto/system_clock.rs @@ -0,0 +1,66 @@ +// This file was generated by gir (cf27827) from gir-files (???) +// DO NOT EDIT + +use Clock; +use ClockType; +use Object; +use ffi; +use glib; +use glib::Value; +use glib::object::IsA; +use glib::translate::*; +use glib_ffi; +use gobject_ffi; +use std::mem; +use std::mem::transmute; +use std::ptr; + +glib_wrapper! { + pub struct SystemClock(Object): Clock, Object; + + match fn { + get_type => || ffi::gst_system_clock_get_type(), + } +} + +impl SystemClock { + pub fn obtain() -> Clock { + assert_initialized_main_thread!(); + unsafe { + from_glib_full(ffi::gst_system_clock_obtain()) + } + } + + pub fn set_default>(new_clock: &P) { + skip_assert_initialized!(); + unsafe { + ffi::gst_system_clock_set_default(new_clock.to_glib_none().0); + } + } +} + +unsafe impl Send for SystemClock {} +unsafe impl Sync for SystemClock {} + +pub trait SystemClockExt { + fn get_property_clock_type(&self) -> ClockType; + + fn set_property_clock_type(&self, clock_type: ClockType); +} + +impl + IsA> SystemClockExt for O { + fn get_property_clock_type(&self) -> ClockType { + let mut value = Value::from(&0); + unsafe { + gobject_ffi::g_object_get_property(self.to_glib_none().0, "clock-type".to_glib_none().0, value.to_glib_none_mut().0); + from_glib(transmute(value.get::().unwrap())) + } + } + + fn set_property_clock_type(&self, clock_type: ClockType) { + let clock_type = clock_type.to_glib() as i32; + unsafe { + gobject_ffi::g_object_set_property(self.to_glib_none().0, "clock-type".to_glib_none().0, Value::from(&clock_type).to_glib_none().0); + } + } +} diff --git a/gstreamer/src/auto/tag_setter.rs b/gstreamer/src/auto/tag_setter.rs index 648e9ac92..0c3c3ff4c 100644 --- a/gstreamer/src/auto/tag_setter.rs +++ b/gstreamer/src/auto/tag_setter.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (3294959) from gir-files (???) +// This file was generated by gir (cf27827) from gir-files (???) // DO NOT EDIT use Element; diff --git a/gstreamer/src/auto/toc_setter.rs b/gstreamer/src/auto/toc_setter.rs index a6ff3460a..c999d2c00 100644 --- a/gstreamer/src/auto/toc_setter.rs +++ b/gstreamer/src/auto/toc_setter.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (3294959) from gir-files (???) +// This file was generated by gir (cf27827) from gir-files (???) // DO NOT EDIT use Element; diff --git a/gstreamer/src/auto/u_r_i_handler.rs b/gstreamer/src/auto/u_r_i_handler.rs index 55f2d2377..4fa6239f3 100644 --- a/gstreamer/src/auto/u_r_i_handler.rs +++ b/gstreamer/src/auto/u_r_i_handler.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (3294959) from gir-files (???) +// This file was generated by gir (cf27827) from gir-files (???) // DO NOT EDIT use Error; diff --git a/gstreamer/src/bus.rs b/gstreamer/src/bus.rs index 907d57d52..e47c7782d 100644 --- a/gstreamer/src/bus.rs +++ b/gstreamer/src/bus.rs @@ -26,13 +26,15 @@ unsafe extern "C" fn trampoline_watch( func: gpointer, ) -> gboolean { let _guard = CallbackGuard::new(); - let func: &RefCell Continue + 'static>> = transmute(func); + let func: &RefCell Continue + Send + 'static>> = transmute(func); (&mut *func.borrow_mut())(&from_glib_none(bus), &Message::from_glib_none(msg)).to_glib() } unsafe extern "C" fn destroy_closure_watch(ptr: gpointer) { let _guard = CallbackGuard::new(); - Box:: Continue + 'static>>>::from_raw(ptr as *mut _); + Box:: Continue + Send + 'static>>>::from_raw( + ptr as *mut _, + ); } fn into_raw_watch Continue + Send + 'static>(func: F) -> gpointer { @@ -47,17 +49,19 @@ unsafe extern "C" fn trampoline_sync( func: gpointer, ) -> ffi::GstBusSyncReply { let _guard = CallbackGuard::new(); - let f: &&(Fn(&Bus, &Message) -> BusSyncReply + 'static) = transmute(func); + let f: &&(Fn(&Bus, &Message) -> BusSyncReply + Send + Sync + 'static) = transmute(func); f(&from_glib_none(bus), &Message::from_glib_none(msg)).to_glib() } unsafe extern "C" fn destroy_closure_sync(ptr: gpointer) { let _guard = CallbackGuard::new(); - Box:: BusSyncReply + 'static>>::from_raw(ptr as *mut _); + Box:: BusSyncReply + Send + Sync + 'static>>::from_raw(ptr as *mut _); } -fn into_raw_sync BusSyncReply + Send + 'static>(func: F) -> gpointer { - let func: Box BusSyncReply + Send + 'static>> = +fn into_raw_sync BusSyncReply + Send + Sync + 'static>( + func: F, +) -> gpointer { + let func: Box BusSyncReply + Send + Sync + 'static>> = Box::new(Box::new(func)); Box::into_raw(func) as gpointer } diff --git a/gstreamer/src/clock.rs b/gstreamer/src/clock.rs new file mode 100644 index 000000000..d37448809 --- /dev/null +++ b/gstreamer/src/clock.rs @@ -0,0 +1,232 @@ +// Copyright (C) 2017 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 Clock; +use ClockTime; +use ClockTimeDiff; +use ClockReturn; +use std::mem; +use std::cmp; +use std::ptr; +use std::mem::transmute; +use ffi; +use glib; +use glib::IsA; +use glib::translate::*; +use glib::source::CallbackGuard; +use glib_ffi; +use glib_ffi::{gboolean, gpointer}; +use libc::c_void; + +glib_wrapper! { + pub struct ClockId(Shared); + + match fn { + ref => |ptr| ffi::gst_clock_id_ref(ptr), + unref => |ptr| ffi::gst_clock_id_unref(ptr), + } +} + +unsafe extern "C" fn trampoline_wait_async( + clock: *mut ffi::GstClock, + time: ClockTime, + id: gpointer, + func: gpointer, +) -> gboolean { + let _guard = CallbackGuard::new(); + let f: &&(Fn(&Clock, ClockTime, &ClockId) -> bool + Send + 'static) = transmute(func); + f(&from_glib_none(clock), time, &from_glib_none(id)).to_glib() +} + +unsafe extern "C" fn destroy_closure_wait_async(ptr: gpointer) { + let _guard = CallbackGuard::new(); + Box:: bool + Send + 'static>>::from_raw(ptr as *mut _); +} + +fn into_raw_wait_async bool + Send + 'static>( + func: F, +) -> gpointer { + let func: Box bool + Send + 'static>> = + Box::new(Box::new(func)); + Box::into_raw(func) as gpointer +} + +impl ClockId { + pub fn get_time(&self) -> ClockTime { + unsafe { ffi::gst_clock_id_get_time(self.to_glib_none().0) } + } + + pub fn unschedule(&self) { + unsafe { ffi::gst_clock_id_unschedule(self.to_glib_none().0) } + } + + pub fn wait(&self) -> (ClockReturn, ClockTimeDiff) { + unsafe { + let mut jitter = mem::uninitialized(); + let res = ffi::gst_clock_id_wait(self.to_glib_none().0, &mut jitter); + (from_glib(res), jitter) + } + } + + pub fn wait_async(&self, func: F) -> ClockReturn + where + F: Fn(&Clock, ClockTime, &ClockId) -> bool + Send + 'static, + { + unsafe { + from_glib(ffi::gst_clock_id_wait_async( + self.to_glib_none().0, + Some(trampoline_wait_async), + into_raw_wait_async(func), + Some(destroy_closure_wait_async), + )) + } + } +} + +impl PartialOrd for ClockId { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Ord for ClockId { + fn cmp(&self, other: &Self) -> cmp::Ordering { + unsafe { + let res = ffi::gst_clock_id_compare_func(self.to_glib_none().0, other.to_glib_none().0); + if res < 0 { + cmp::Ordering::Less + } else if res > 0 { + cmp::Ordering::Greater + } else { + cmp::Ordering::Equal + } + } + } +} + +impl PartialEq for ClockId { + fn eq(&self, other: &Self) -> bool { + self.cmp(other) == cmp::Ordering::Equal + } +} + +impl Eq for ClockId {} + +unsafe impl Send for ClockId {} +unsafe impl Sync for ClockId {} + +pub trait ClockExtManual { + fn new_periodic_id(&self, start_time: ClockTime, interval: ClockTime) -> Option; + + fn periodic_id_reinit( + &self, + id: &ClockId, + start_time: ClockTime, + interval: ClockTime, + ) -> Result<(), glib::BoolError>; + + fn new_single_shot_id(&self, time: ClockTime) -> Option; + + fn single_shot_id_reinit(&self, id: &ClockId, time: ClockTime) -> Result<(), glib::BoolError>; +} + +impl + IsA> ClockExtManual for O { + fn new_periodic_id(&self, start_time: ClockTime, interval: ClockTime) -> Option { + unsafe { + from_glib_full(ffi::gst_clock_new_periodic_id( + self.to_glib_none().0, + start_time, + interval, + )) + } + } + + fn periodic_id_reinit( + &self, + id: &ClockId, + start_time: ClockTime, + interval: ClockTime, + ) -> Result<(), glib::BoolError> { + unsafe { + let res: bool = from_glib(ffi::gst_clock_periodic_id_reinit( + self.to_glib_none().0, + id.to_glib_none().0, + start_time, + interval, + )); + if res { + Ok(()) + } else { + Err(glib::BoolError("Failed to reinit periodic clock id")) + } + } + } + + fn new_single_shot_id(&self, time: ClockTime) -> Option { + unsafe { + from_glib_full(ffi::gst_clock_new_single_shot_id( + self.to_glib_none().0, + time, + )) + } + } + + fn single_shot_id_reinit(&self, id: &ClockId, time: ClockTime) -> Result<(), glib::BoolError> { + unsafe { + let res: bool = from_glib(ffi::gst_clock_single_shot_id_reinit( + self.to_glib_none().0, + id.to_glib_none().0, + time, + )); + if res { + Ok(()) + } else { + Err(glib::BoolError("Failed to reinit single shot clock id")) + } + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + use super::super::*; + use std::sync::mpsc::channel; + + #[test] + fn test_wait() { + ::init().unwrap(); + + let clock = SystemClock::obtain(); + let now = clock.get_time(); + let id = clock.new_single_shot_id(now + 20_000_000).unwrap(); + let (res, _) = id.wait(); + + assert!(res == ClockReturn::Ok || res == ClockReturn::Early); + } + + #[test] + fn test_wait_async() { + ::init().unwrap(); + + let (sender, receiver) = channel(); + + let clock = SystemClock::obtain(); + let now = clock.get_time(); + let id = clock.new_single_shot_id(now + 20_000_000).unwrap(); + let res = id.wait_async(move |_, _, _| { + sender.send(()).unwrap(); + + true + }); + + assert!(res == ClockReturn::Ok); + + assert_eq!(receiver.recv(), Ok(())); + } +} diff --git a/gstreamer/src/lib.rs b/gstreamer/src/lib.rs index 4764dd91c..057f527b5 100644 --- a/gstreamer/src/lib.rs +++ b/gstreamer/src/lib.rs @@ -102,6 +102,9 @@ pub use segment::*; pub mod toc; pub use toc::{Toc, TocEntry, TocEntryRef, TocRef}; +mod clock; +pub use clock::{ClockId, ClockExtManual}; + use std::ptr; pub fn init() -> Result<(), glib::Error> {