forked from mirrors/gstreamer-rs
Migrate everything to object lock API instead of custom GMutex
handling
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1212>
This commit is contained in:
parent
3ddbdbd383
commit
91eec7a33f
22 changed files with 51 additions and 166 deletions
|
@ -6,6 +6,7 @@ use glib::object::Cast;
|
||||||
#[cfg(any(feature = "v1_18", feature = "dox"))]
|
#[cfg(any(feature = "v1_18", feature = "dox"))]
|
||||||
use glib::signal::{connect_raw, SignalHandlerId};
|
use glib::signal::{connect_raw, SignalHandlerId};
|
||||||
use glib::{object::IsA, translate::*};
|
use glib::{object::IsA, translate::*};
|
||||||
|
use gst::prelude::*;
|
||||||
|
|
||||||
use crate::auto::{AudioAggregator, AudioAggregatorPad};
|
use crate::auto::{AudioAggregator, AudioAggregatorPad};
|
||||||
|
|
||||||
|
@ -95,7 +96,7 @@ impl<O: IsA<AudioAggregator>> AudioAggregatorExtManual for O {
|
||||||
fn current_caps(&self) -> Option<gst::Caps> {
|
fn current_caps(&self) -> Option<gst::Caps> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = self.as_ptr() as *mut ffi::GstAudioAggregator;
|
let ptr = self.as_ptr() as *mut ffi::GstAudioAggregator;
|
||||||
let _guard = crate::utils::MutexGuard::lock(&(*(ptr as *mut gst::ffi::GstObject)).lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
from_glib_none((*ptr).current_caps)
|
from_glib_none((*ptr).current_caps)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use glib::{object::IsA, translate::*};
|
use glib::{object::IsA, translate::*};
|
||||||
|
use gst::prelude::*;
|
||||||
|
|
||||||
use crate::auto::AudioAggregatorPad;
|
use crate::auto::AudioAggregatorPad;
|
||||||
|
|
||||||
|
@ -10,7 +11,7 @@ impl<O: IsA<AudioAggregatorPad>> AudioAggregatorPadExtManual for O {
|
||||||
fn audio_info(&self) -> Option<crate::AudioInfo> {
|
fn audio_info(&self) -> Option<crate::AudioInfo> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = self.as_ptr() as *mut ffi::GstAudioAggregatorPad;
|
let ptr = self.as_ptr() as *mut ffi::GstAudioAggregatorPad;
|
||||||
let _guard = crate::utils::MutexGuard::lock(&(*(ptr as *mut gst::ffi::GstObject)).lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
|
|
||||||
let info = &(*ptr).info;
|
let info = &(*ptr).info;
|
||||||
|
|
||||||
|
|
|
@ -68,8 +68,6 @@ mod audio_encoder;
|
||||||
mod audio_converter;
|
mod audio_converter;
|
||||||
pub use crate::audio_converter::AudioConverterConfig;
|
pub use crate::audio_converter::AudioConverterConfig;
|
||||||
|
|
||||||
mod utils;
|
|
||||||
|
|
||||||
// Re-export all the traits in a prelude module, so that applications
|
// Re-export all the traits in a prelude module, so that applications
|
||||||
// can always "use gst_audio::prelude::*" without getting conflicts
|
// can always "use gst_audio::prelude::*" without getting conflicts
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
// Take a look at the license at the top of the repository in the LICENSE file.
|
|
||||||
|
|
||||||
use glib::translate::mut_override;
|
|
||||||
|
|
||||||
#[must_use = "if unused the Mutex will immediately unlock"]
|
|
||||||
#[doc(alias = "GMutex")]
|
|
||||||
pub struct MutexGuard<'a>(&'a glib::ffi::GMutex);
|
|
||||||
|
|
||||||
impl<'a> MutexGuard<'a> {
|
|
||||||
#[allow(clippy::trivially_copy_pass_by_ref)]
|
|
||||||
#[allow(dead_code)]
|
|
||||||
#[doc(alias = "g_mutex_lock")]
|
|
||||||
#[inline]
|
|
||||||
pub fn lock(mutex: &'a glib::ffi::GMutex) -> Self {
|
|
||||||
skip_assert_initialized!();
|
|
||||||
unsafe {
|
|
||||||
glib::ffi::g_mutex_lock(mut_override(mutex));
|
|
||||||
}
|
|
||||||
MutexGuard(mutex)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Drop for MutexGuard<'a> {
|
|
||||||
#[inline]
|
|
||||||
fn drop(&mut self) {
|
|
||||||
unsafe {
|
|
||||||
glib::ffi::g_mutex_unlock(mut_override(self.0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -12,7 +12,7 @@ use std::{mem, ptr};
|
||||||
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
|
||||||
use glib::signal::{connect_raw, SignalHandlerId};
|
use glib::signal::{connect_raw, SignalHandlerId};
|
||||||
use glib::{prelude::*, translate::*};
|
use glib::{prelude::*, translate::*};
|
||||||
use gst::format::FormattedValue;
|
use gst::{format::FormattedValue, prelude::*};
|
||||||
|
|
||||||
use crate::Aggregator;
|
use crate::Aggregator;
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ impl<O: IsA<Aggregator>> AggregatorExtManual for O {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr: *mut ffi::GstAggregator = self.as_ref().to_glib_none().0;
|
let ptr: *mut ffi::GstAggregator = self.as_ref().to_glib_none().0;
|
||||||
let ptr = &mut *ptr;
|
let ptr = &mut *ptr;
|
||||||
let _guard = crate::utils::MutexGuard::lock(&ptr.parent.object.lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
|
|
||||||
// gstaggregator.c asserts that the src pad is always of type GST_TYPE_AGGREGATOR_PAD,
|
// gstaggregator.c asserts that the src pad is always of type GST_TYPE_AGGREGATOR_PAD,
|
||||||
// so the pointer cast here should be safe.
|
// so the pointer cast here should be safe.
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// Take a look at the license at the top of the repository in the LICENSE file.
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
||||||
|
|
||||||
use glib::{prelude::*, translate::*};
|
use glib::{prelude::*, translate::*};
|
||||||
|
use gst::prelude::*;
|
||||||
|
|
||||||
use crate::AggregatorPad;
|
use crate::AggregatorPad;
|
||||||
|
|
||||||
|
@ -13,7 +14,7 @@ impl<O: IsA<AggregatorPad>> AggregatorPadExtManual for O {
|
||||||
fn segment(&self) -> gst::Segment {
|
fn segment(&self) -> gst::Segment {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr: &ffi::GstAggregatorPad = &*(self.as_ptr() as *const _);
|
let ptr: &ffi::GstAggregatorPad = &*(self.as_ptr() as *const _);
|
||||||
let _guard = crate::utils::MutexGuard::lock(&ptr.parent.object.lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
from_glib_none(&ptr.segment as *const gst::ffi::GstSegment)
|
from_glib_none(&ptr.segment as *const gst::ffi::GstSegment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
use glib::{prelude::*, translate::*};
|
use glib::{prelude::*, translate::*};
|
||||||
|
use gst::prelude::*;
|
||||||
|
|
||||||
use crate::BaseSink;
|
use crate::BaseSink;
|
||||||
|
|
||||||
|
@ -22,7 +23,7 @@ impl<O: IsA<BaseSink>> BaseSinkExtManual for O {
|
||||||
fn segment(&self) -> gst::Segment {
|
fn segment(&self) -> gst::Segment {
|
||||||
unsafe {
|
unsafe {
|
||||||
let sink: &ffi::GstBaseSink = &*(self.as_ptr() as *const _);
|
let sink: &ffi::GstBaseSink = &*(self.as_ptr() as *const _);
|
||||||
let _guard = crate::utils::MutexGuard::lock(&sink.element.object.lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
from_glib_none(&sink.segment as *const _)
|
from_glib_none(&sink.segment as *const _)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
use std::{mem, ptr};
|
use std::{mem, ptr};
|
||||||
|
|
||||||
use glib::{prelude::*, translate::*};
|
use glib::{prelude::*, translate::*};
|
||||||
|
use gst::prelude::*;
|
||||||
|
|
||||||
use crate::BaseSrc;
|
use crate::BaseSrc;
|
||||||
|
|
||||||
|
@ -44,7 +45,7 @@ impl<O: IsA<BaseSrc>> BaseSrcExtManual for O {
|
||||||
fn segment(&self) -> gst::Segment {
|
fn segment(&self) -> gst::Segment {
|
||||||
unsafe {
|
unsafe {
|
||||||
let src: &ffi::GstBaseSrc = &*(self.as_ptr() as *const _);
|
let src: &ffi::GstBaseSrc = &*(self.as_ptr() as *const _);
|
||||||
let _guard = crate::utils::MutexGuard::lock(&src.element.object.lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
from_glib_none(&src.segment as *const _)
|
from_glib_none(&src.segment as *const _)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
use std::{mem, ptr};
|
use std::{mem, ptr};
|
||||||
|
|
||||||
use glib::{prelude::*, translate::*};
|
use glib::{prelude::*, translate::*};
|
||||||
|
use gst::prelude::*;
|
||||||
|
|
||||||
use crate::BaseTransform;
|
use crate::BaseTransform;
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ impl<O: IsA<BaseTransform>> BaseTransformExtManual for O {
|
||||||
fn segment(&self) -> gst::Segment {
|
fn segment(&self) -> gst::Segment {
|
||||||
unsafe {
|
unsafe {
|
||||||
let trans: &ffi::GstBaseTransform = &*(self.as_ptr() as *const _);
|
let trans: &ffi::GstBaseTransform = &*(self.as_ptr() as *const _);
|
||||||
let _guard = crate::utils::MutexGuard::lock(&trans.element.object.lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
from_glib_none(&trans.segment as *const _)
|
from_glib_none(&trans.segment as *const _)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,4 @@ pub mod prelude {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
mod utils;
|
|
||||||
|
|
||||||
pub mod subclass;
|
pub mod subclass;
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
// Take a look at the license at the top of the repository in the LICENSE file.
|
|
||||||
|
|
||||||
use glib::translate::mut_override;
|
|
||||||
|
|
||||||
#[must_use = "if unused the Mutex will immediately unlock"]
|
|
||||||
#[doc(alias = "GMutex")]
|
|
||||||
pub struct MutexGuard<'a>(&'a glib::ffi::GMutex);
|
|
||||||
|
|
||||||
impl<'a> MutexGuard<'a> {
|
|
||||||
#[allow(clippy::trivially_copy_pass_by_ref)]
|
|
||||||
#[doc(alias = "g_mutex_lock")]
|
|
||||||
#[inline]
|
|
||||||
pub fn lock(mutex: &'a glib::ffi::GMutex) -> Self {
|
|
||||||
skip_assert_initialized!();
|
|
||||||
unsafe {
|
|
||||||
glib::ffi::g_mutex_lock(mut_override(mutex));
|
|
||||||
}
|
|
||||||
MutexGuard(mutex)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Drop for MutexGuard<'a> {
|
|
||||||
#[inline]
|
|
||||||
fn drop(&mut self) {
|
|
||||||
unsafe {
|
|
||||||
glib::ffi::g_mutex_unlock(mut_override(self.0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,37 +1,8 @@
|
||||||
// Take a look at the license at the top of the repository in the LICENSE file.
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
||||||
|
|
||||||
use glib::translate::mut_override;
|
|
||||||
|
|
||||||
pub trait HasStreamLock {
|
pub trait HasStreamLock {
|
||||||
#[doc(alias = "get_stream_lock")]
|
#[doc(alias = "get_stream_lock")]
|
||||||
fn stream_lock(&self) -> *mut glib::ffi::GRecMutex;
|
fn stream_lock(&self) -> *mut glib::ffi::GRecMutex;
|
||||||
#[doc(alias = "get_element_as_ptr")]
|
#[doc(alias = "get_element_as_ptr")]
|
||||||
fn element_as_ptr(&self) -> *const gst::ffi::GstElement;
|
fn element_as_ptr(&self) -> *const gst::ffi::GstElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use = "if unused the Mutex will immediately unlock"]
|
|
||||||
#[doc(alias = "GMutex")]
|
|
||||||
pub struct MutexGuard<'a>(&'a glib::ffi::GMutex);
|
|
||||||
|
|
||||||
impl<'a> MutexGuard<'a> {
|
|
||||||
#[allow(clippy::trivially_copy_pass_by_ref)]
|
|
||||||
#[allow(dead_code)]
|
|
||||||
#[doc(alias = "g_mutex_lock")]
|
|
||||||
#[inline]
|
|
||||||
pub fn lock(mutex: &'a glib::ffi::GMutex) -> Self {
|
|
||||||
skip_assert_initialized!();
|
|
||||||
unsafe {
|
|
||||||
glib::ffi::g_mutex_lock(mut_override(mutex));
|
|
||||||
}
|
|
||||||
MutexGuard(mutex)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Drop for MutexGuard<'a> {
|
|
||||||
#[inline]
|
|
||||||
fn drop(&mut self) {
|
|
||||||
unsafe {
|
|
||||||
glib::ffi::g_mutex_unlock(mut_override(self.0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use glib::{object::IsA, translate::*};
|
use glib::{object::IsA, translate::*};
|
||||||
|
use gst::prelude::*;
|
||||||
|
|
||||||
use crate::auto::VideoAggregator;
|
use crate::auto::VideoAggregator;
|
||||||
|
|
||||||
|
@ -10,7 +11,7 @@ impl<O: IsA<VideoAggregator>> VideoAggregatorExtManual for O {
|
||||||
fn video_info(&self) -> Option<crate::VideoInfo> {
|
fn video_info(&self) -> Option<crate::VideoInfo> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = self.as_ptr() as *mut ffi::GstVideoAggregator;
|
let ptr = self.as_ptr() as *mut ffi::GstVideoAggregator;
|
||||||
let _guard = crate::utils::MutexGuard::lock(&(*(ptr as *mut gst::ffi::GstObject)).lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
|
|
||||||
let info = &(*ptr).info;
|
let info = &(*ptr).info;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use glib::{object::IsA, translate::*};
|
use glib::{object::IsA, translate::*};
|
||||||
|
use gst::prelude::*;
|
||||||
|
|
||||||
use crate::{auto::VideoAggregatorPad, subclass::AggregateFramesToken};
|
use crate::{auto::VideoAggregatorPad, subclass::AggregateFramesToken};
|
||||||
|
|
||||||
|
@ -54,7 +55,7 @@ impl<O: IsA<VideoAggregatorPad>> VideoAggregatorPadExtManual for O {
|
||||||
fn video_info(&self) -> Option<crate::VideoInfo> {
|
fn video_info(&self) -> Option<crate::VideoInfo> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = self.as_ptr() as *mut ffi::GstVideoAggregatorPad;
|
let ptr = self.as_ptr() as *mut ffi::GstVideoAggregatorPad;
|
||||||
let _guard = crate::utils::MutexGuard::lock(&(*(ptr as *mut gst::ffi::GstObject)).lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
|
|
||||||
let info = &(*ptr).info;
|
let info = &(*ptr).info;
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ use glib::{
|
||||||
GString,
|
GString,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{Bin, BinFlags, Element, LoggableError};
|
use crate::{prelude::*, Bin, BinFlags, Element, LoggableError};
|
||||||
|
|
||||||
impl Bin {
|
impl Bin {
|
||||||
// rustdoc-stripper-ignore-next
|
// rustdoc-stripper-ignore-next
|
||||||
|
@ -171,7 +171,7 @@ impl<O: IsA<Bin>> GstBinExtManual for O {
|
||||||
fn children(&self) -> Vec<Element> {
|
fn children(&self) -> Vec<Element> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let bin: &ffi::GstBin = &*(self.as_ptr() as *const _);
|
let bin: &ffi::GstBin = &*(self.as_ptr() as *const _);
|
||||||
let _guard = crate::utils::MutexGuard::lock(&bin.element.object.lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
FromGlibPtrContainer::from_glib_none(bin.children)
|
FromGlibPtrContainer::from_glib_none(bin.children)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -199,7 +199,7 @@ impl<O: IsA<Bin>> GstBinExtManual for O {
|
||||||
fn set_bin_flags(&self, flags: BinFlags) {
|
fn set_bin_flags(&self, flags: BinFlags) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
||||||
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
(*ptr).flags |= flags.into_glib();
|
(*ptr).flags |= flags.into_glib();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -207,7 +207,7 @@ impl<O: IsA<Bin>> GstBinExtManual for O {
|
||||||
fn unset_bin_flags(&self, flags: BinFlags) {
|
fn unset_bin_flags(&self, flags: BinFlags) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
||||||
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
(*ptr).flags &= !flags.into_glib();
|
(*ptr).flags &= !flags.into_glib();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -215,7 +215,7 @@ impl<O: IsA<Bin>> GstBinExtManual for O {
|
||||||
fn bin_flags(&self) -> BinFlags {
|
fn bin_flags(&self) -> BinFlags {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
||||||
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
from_glib((*ptr).flags)
|
from_glib((*ptr).flags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -293,7 +293,6 @@ where
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::prelude::*;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_children() {
|
fn test_get_children() {
|
||||||
|
|
|
@ -17,8 +17,8 @@ use glib::{
|
||||||
use libc::c_void;
|
use libc::c_void;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Clock, ClockEntryType, ClockError, ClockFlags, ClockReturn, ClockSuccess, ClockTime,
|
prelude::*, Clock, ClockEntryType, ClockError, ClockFlags, ClockReturn, ClockSuccess,
|
||||||
ClockTimeDiff,
|
ClockTime, ClockTimeDiff,
|
||||||
};
|
};
|
||||||
|
|
||||||
glib::wrapper! {
|
glib::wrapper! {
|
||||||
|
@ -515,7 +515,7 @@ impl<O: IsA<Clock>> ClockExtManual for O {
|
||||||
fn set_clock_flags(&self, flags: ClockFlags) {
|
fn set_clock_flags(&self, flags: ClockFlags) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
||||||
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
(*ptr).flags |= flags.into_glib();
|
(*ptr).flags |= flags.into_glib();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -523,7 +523,7 @@ impl<O: IsA<Clock>> ClockExtManual for O {
|
||||||
fn unset_clock_flags(&self, flags: ClockFlags) {
|
fn unset_clock_flags(&self, flags: ClockFlags) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
||||||
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
(*ptr).flags &= !flags.into_glib();
|
(*ptr).flags &= !flags.into_glib();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -531,7 +531,7 @@ impl<O: IsA<Clock>> ClockExtManual for O {
|
||||||
fn clock_flags(&self) -> ClockFlags {
|
fn clock_flags(&self) -> ClockFlags {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
||||||
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
from_glib((*ptr).flags)
|
from_glib((*ptr).flags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -541,10 +541,8 @@ impl<O: IsA<Clock>> ClockExtManual for O {
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::sync::mpsc::channel;
|
use std::sync::mpsc::channel;
|
||||||
|
|
||||||
use super::{
|
use super::*;
|
||||||
super::{prelude::*, *},
|
use crate::SystemClock;
|
||||||
*,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_wait() {
|
fn test_wait() {
|
||||||
|
|
|
@ -345,7 +345,7 @@ impl<O: IsA<Element>> ElementExtManual for O {
|
||||||
fn set_element_flags(&self, flags: ElementFlags) {
|
fn set_element_flags(&self, flags: ElementFlags) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
||||||
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
(*ptr).flags |= flags.into_glib();
|
(*ptr).flags |= flags.into_glib();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -353,7 +353,7 @@ impl<O: IsA<Element>> ElementExtManual for O {
|
||||||
fn unset_element_flags(&self, flags: ElementFlags) {
|
fn unset_element_flags(&self, flags: ElementFlags) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
||||||
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
(*ptr).flags &= !flags.into_glib();
|
(*ptr).flags &= !flags.into_glib();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -361,7 +361,7 @@ impl<O: IsA<Element>> ElementExtManual for O {
|
||||||
fn element_flags(&self) -> ElementFlags {
|
fn element_flags(&self) -> ElementFlags {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
||||||
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
from_glib((*ptr).flags)
|
from_glib((*ptr).flags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -483,7 +483,7 @@ impl<O: IsA<Element>> ElementExtManual for O {
|
||||||
fn pads(&self) -> Vec<Pad> {
|
fn pads(&self) -> Vec<Pad> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let elt: &ffi::GstElement = &*(self.as_ptr() as *const _);
|
let elt: &ffi::GstElement = &*(self.as_ptr() as *const _);
|
||||||
let _guard = crate::utils::MutexGuard::lock(&elt.object.lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
FromGlibPtrContainer::from_glib_none(elt.pads)
|
FromGlibPtrContainer::from_glib_none(elt.pads)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -491,7 +491,7 @@ impl<O: IsA<Element>> ElementExtManual for O {
|
||||||
fn sink_pads(&self) -> Vec<Pad> {
|
fn sink_pads(&self) -> Vec<Pad> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let elt: &ffi::GstElement = &*(self.as_ptr() as *const _);
|
let elt: &ffi::GstElement = &*(self.as_ptr() as *const _);
|
||||||
let _guard = crate::utils::MutexGuard::lock(&elt.object.lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
FromGlibPtrContainer::from_glib_none(elt.sinkpads)
|
FromGlibPtrContainer::from_glib_none(elt.sinkpads)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -499,7 +499,7 @@ impl<O: IsA<Element>> ElementExtManual for O {
|
||||||
fn src_pads(&self) -> Vec<Pad> {
|
fn src_pads(&self) -> Vec<Pad> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let elt: &ffi::GstElement = &*(self.as_ptr() as *const _);
|
let elt: &ffi::GstElement = &*(self.as_ptr() as *const _);
|
||||||
let _guard = crate::utils::MutexGuard::lock(&elt.object.lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
FromGlibPtrContainer::from_glib_none(elt.srcpads)
|
FromGlibPtrContainer::from_glib_none(elt.srcpads)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -507,7 +507,7 @@ impl<O: IsA<Element>> ElementExtManual for O {
|
||||||
fn num_pads(&self) -> u16 {
|
fn num_pads(&self) -> u16 {
|
||||||
unsafe {
|
unsafe {
|
||||||
let elt: &ffi::GstElement = &*(self.as_ptr() as *const _);
|
let elt: &ffi::GstElement = &*(self.as_ptr() as *const _);
|
||||||
let _guard = crate::utils::MutexGuard::lock(&elt.object.lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
elt.numpads
|
elt.numpads
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -515,7 +515,7 @@ impl<O: IsA<Element>> ElementExtManual for O {
|
||||||
fn num_sink_pads(&self) -> u16 {
|
fn num_sink_pads(&self) -> u16 {
|
||||||
unsafe {
|
unsafe {
|
||||||
let elt: &ffi::GstElement = &*(self.as_ptr() as *const _);
|
let elt: &ffi::GstElement = &*(self.as_ptr() as *const _);
|
||||||
let _guard = crate::utils::MutexGuard::lock(&elt.object.lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
elt.numsinkpads
|
elt.numsinkpads
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -523,7 +523,7 @@ impl<O: IsA<Element>> ElementExtManual for O {
|
||||||
fn num_src_pads(&self) -> u16 {
|
fn num_src_pads(&self) -> u16 {
|
||||||
unsafe {
|
unsafe {
|
||||||
let elt: &ffi::GstElement = &*(self.as_ptr() as *const _);
|
let elt: &ffi::GstElement = &*(self.as_ptr() as *const _);
|
||||||
let _guard = crate::utils::MutexGuard::lock(&elt.object.lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
elt.numsrcpads
|
elt.numsrcpads
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ impl<O: IsA<crate::Object>> GstObjectExtManual for O {
|
||||||
fn set_object_flags(&self, flags: ObjectFlags) {
|
fn set_object_flags(&self, flags: ObjectFlags) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
||||||
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
(*ptr).flags |= flags.into_glib();
|
(*ptr).flags |= flags.into_glib();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ impl<O: IsA<crate::Object>> GstObjectExtManual for O {
|
||||||
fn unset_object_flags(&self, flags: ObjectFlags) {
|
fn unset_object_flags(&self, flags: ObjectFlags) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
||||||
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
(*ptr).flags &= !flags.into_glib();
|
(*ptr).flags &= !flags.into_glib();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ impl<O: IsA<crate::Object>> GstObjectExtManual for O {
|
||||||
fn object_flags(&self) -> ObjectFlags {
|
fn object_flags(&self) -> ObjectFlags {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
||||||
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
from_glib((*ptr).flags)
|
from_glib((*ptr).flags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -997,7 +997,7 @@ impl<O: IsA<Pad>> PadExtManual for O {
|
||||||
fn set_pad_flags(&self, flags: PadFlags) {
|
fn set_pad_flags(&self, flags: PadFlags) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
||||||
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
(*ptr).flags |= flags.into_glib();
|
(*ptr).flags |= flags.into_glib();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1005,7 +1005,7 @@ impl<O: IsA<Pad>> PadExtManual for O {
|
||||||
fn unset_pad_flags(&self, flags: PadFlags) {
|
fn unset_pad_flags(&self, flags: PadFlags) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
||||||
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
(*ptr).flags &= !flags.into_glib();
|
(*ptr).flags &= !flags.into_glib();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1013,7 +1013,7 @@ impl<O: IsA<Pad>> PadExtManual for O {
|
||||||
fn pad_flags(&self) -> PadFlags {
|
fn pad_flags(&self) -> PadFlags {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
||||||
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
from_glib((*ptr).flags)
|
from_glib((*ptr).flags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use glib::{prelude::*, translate::*};
|
use glib::{prelude::*, translate::*};
|
||||||
|
|
||||||
use crate::{Pipeline, PipelineFlags};
|
use crate::{prelude::*, Pipeline, PipelineFlags};
|
||||||
|
|
||||||
impl Pipeline {
|
impl Pipeline {
|
||||||
// rustdoc-stripper-ignore-next
|
// rustdoc-stripper-ignore-next
|
||||||
|
@ -27,7 +27,7 @@ impl<O: IsA<crate::Pipeline>> GstPipelineExtManual for O {
|
||||||
fn set_pipeline_flags(&self, flags: PipelineFlags) {
|
fn set_pipeline_flags(&self, flags: PipelineFlags) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
||||||
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
(*ptr).flags |= flags.into_glib();
|
(*ptr).flags |= flags.into_glib();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ impl<O: IsA<crate::Pipeline>> GstPipelineExtManual for O {
|
||||||
fn unset_pipeline_flags(&self, flags: PipelineFlags) {
|
fn unset_pipeline_flags(&self, flags: PipelineFlags) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
||||||
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
(*ptr).flags &= !flags.into_glib();
|
(*ptr).flags &= !flags.into_glib();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ impl<O: IsA<crate::Pipeline>> GstPipelineExtManual for O {
|
||||||
fn pipeline_flags(&self) -> PipelineFlags {
|
fn pipeline_flags(&self) -> PipelineFlags {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
||||||
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
|
let _guard = self.as_ref().object_lock();
|
||||||
from_glib((*ptr).flags)
|
from_glib((*ptr).flags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use glib::{prelude::*, translate::*};
|
use glib::{prelude::*, translate::*};
|
||||||
|
|
||||||
use crate::{Plugin, PluginFlags, StructureRef};
|
use crate::{prelude::*, Plugin, PluginFlags, StructureRef};
|
||||||
|
|
||||||
impl Plugin {
|
impl Plugin {
|
||||||
#[doc(alias = "get_cache_data")]
|
#[doc(alias = "get_cache_data")]
|
||||||
|
@ -22,7 +22,7 @@ impl Plugin {
|
||||||
pub fn plugin_flags(&self) -> PluginFlags {
|
pub fn plugin_flags(&self) -> PluginFlags {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
||||||
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
|
let _guard = self.object_lock();
|
||||||
from_glib((*ptr).flags)
|
from_glib((*ptr).flags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,33 +1,5 @@
|
||||||
// Take a look at the license at the top of the repository in the LICENSE file.
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
||||||
|
|
||||||
use glib::translate::mut_override;
|
|
||||||
|
|
||||||
#[must_use = "if unused the Mutex will immediately unlock"]
|
|
||||||
#[doc(alias = "GMutex")]
|
|
||||||
pub struct MutexGuard<'a>(&'a glib::ffi::GMutex);
|
|
||||||
|
|
||||||
impl<'a> MutexGuard<'a> {
|
|
||||||
#[allow(clippy::trivially_copy_pass_by_ref)]
|
|
||||||
#[doc(alias = "g_mutex_lock")]
|
|
||||||
#[inline]
|
|
||||||
pub fn lock(mutex: &'a glib::ffi::GMutex) -> Self {
|
|
||||||
skip_assert_initialized!();
|
|
||||||
unsafe {
|
|
||||||
glib::ffi::g_mutex_lock(mut_override(mutex));
|
|
||||||
}
|
|
||||||
MutexGuard(mutex)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Drop for MutexGuard<'a> {
|
|
||||||
#[inline]
|
|
||||||
fn drop(&mut self) {
|
|
||||||
unsafe {
|
|
||||||
glib::ffi::g_mutex_unlock(mut_override(self.0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// rustdoc-stripper-ignore-next
|
// rustdoc-stripper-ignore-next
|
||||||
/// Trait that allows accessing `Display` implementation on types external to this crate.
|
/// Trait that allows accessing `Display` implementation on types external to this crate.
|
||||||
pub trait Displayable {
|
pub trait Displayable {
|
||||||
|
|
Loading…
Reference in a new issue