diff --git a/gstreamer-base/src/base_sink.rs b/gstreamer-base/src/base_sink.rs new file mode 100644 index 000000000..661e5fb2d --- /dev/null +++ b/gstreamer-base/src/base_sink.rs @@ -0,0 +1,28 @@ +// 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 ffi; +use glib::IsA; +use glib::translate::*; +use gst; +use BaseSink; + +pub trait BaseSinkExtManual { + fn get_segment(&self) -> gst::Segment; +} + +impl> BaseSinkExtManual for O { + fn get_segment(&self) -> gst::Segment { + unsafe { + let stash = self.to_glib_none(); + let sink: &ffi::GstBaseSink = &*stash.0; + ::utils::MutexGuard::lock(&sink.element.object.lock); + from_glib_none(&sink.segment as *const _) + } + } +} diff --git a/gstreamer-base/src/base_src.rs b/gstreamer-base/src/base_src.rs new file mode 100644 index 000000000..17640cefc --- /dev/null +++ b/gstreamer-base/src/base_src.rs @@ -0,0 +1,28 @@ +// 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 ffi; +use glib::IsA; +use glib::translate::*; +use gst; +use BaseSrc; + +pub trait BaseSrcExtManual { + fn get_segment(&self) -> gst::Segment; +} + +impl> BaseSrcExtManual for O { + fn get_segment(&self) -> gst::Segment { + unsafe { + let stash = self.to_glib_none(); + let src: &ffi::GstBaseSrc = &*stash.0; + ::utils::MutexGuard::lock(&src.element.object.lock); + from_glib_none(&src.segment as *const _) + } + } +} diff --git a/gstreamer-base/src/base_transform.rs b/gstreamer-base/src/base_transform.rs new file mode 100644 index 000000000..361f7dc39 --- /dev/null +++ b/gstreamer-base/src/base_transform.rs @@ -0,0 +1,28 @@ +// 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 ffi; +use glib::IsA; +use glib::translate::*; +use gst; +use BaseTransform; + +pub trait BaseTransformExtManual { + fn get_segment(&self) -> gst::Segment; +} + +impl> BaseTransformExtManual for O { + fn get_segment(&self) -> gst::Segment { + unsafe { + let stash = self.to_glib_none(); + let trans: &ffi::GstBaseTransform = &*stash.0; + ::utils::MutexGuard::lock(&trans.element.object.lock); + from_glib_none(&trans.segment as *const _) + } + } +} diff --git a/gstreamer-base/src/lib.rs b/gstreamer-base/src/lib.rs index 5e0318392..8cd32f656 100644 --- a/gstreamer-base/src/lib.rs +++ b/gstreamer-base/src/lib.rs @@ -45,6 +45,9 @@ pub use functions::*; mod adapter; mod flow_combiner; pub use flow_combiner::*; +mod base_src; +mod base_sink; +mod base_transform; // Re-export all the traits in a prelude module, so that applications // can always "use gst::prelude::*" without getting conflicts @@ -53,4 +56,9 @@ pub mod prelude { pub use gst::prelude::*; pub use auto::traits::*; + pub use base_src::BaseSrcExtManual; + pub use base_sink::BaseSinkExtManual; + pub use base_transform::BaseTransformExtManual; } + +mod utils; diff --git a/gstreamer-base/src/utils.rs b/gstreamer-base/src/utils.rs new file mode 100644 index 000000000..f4b3a292d --- /dev/null +++ b/gstreamer-base/src/utils.rs @@ -0,0 +1,29 @@ +// 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 glib::translate::mut_override; +use glib_ffi; + +pub struct MutexGuard<'a>(&'a glib_ffi::GMutex); + +impl<'a> MutexGuard<'a> { + pub fn lock(mutex: &'a glib_ffi::GMutex) -> Self { + unsafe { + glib_ffi::g_mutex_lock(mut_override(mutex)); + } + MutexGuard(mutex) + } +} + +impl<'a> Drop for MutexGuard<'a> { + fn drop(&mut self) { + unsafe { + glib_ffi::g_mutex_unlock(mut_override(self.0)); + } + } +}