clock: Add support for setting/getting/unsetting clock flags

This commit is contained in:
Sebastian Dröge 2019-09-25 16:46:46 +03:00
parent 1faf41986b
commit 4e60a0aea4

View file

@ -18,6 +18,7 @@ use std::cmp;
use std::ptr; use std::ptr;
use Clock; use Clock;
use ClockError; use ClockError;
use ClockFlags;
use ClockReturn; use ClockReturn;
use ClockSuccess; use ClockSuccess;
use ClockTime; use ClockTime;
@ -183,6 +184,12 @@ pub trait ClockExtManual: 'static {
fn new_single_shot_id(&self, time: ClockTime) -> Option<ClockId>; fn new_single_shot_id(&self, time: ClockTime) -> Option<ClockId>;
fn single_shot_id_reinit(&self, id: &ClockId, time: ClockTime) -> Result<(), glib::BoolError>; fn single_shot_id_reinit(&self, id: &ClockId, time: ClockTime) -> Result<(), glib::BoolError>;
fn set_clock_flags(&self, flags: ClockFlags);
fn unset_clock_flags(&self, flags: ClockFlags);
fn get_clock_flags(&self) -> ClockFlags;
} }
impl<O: IsA<Clock>> ClockExtManual for O { impl<O: IsA<Clock>> ClockExtManual for O {
@ -241,6 +248,30 @@ impl<O: IsA<Clock>> ClockExtManual for O {
} }
} }
} }
fn set_clock_flags(&self, flags: ClockFlags) {
unsafe {
let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _;
let _guard = ::utils::MutexGuard::lock(&(*ptr).lock);
(*ptr).flags |= flags.to_glib();
}
}
fn unset_clock_flags(&self, flags: ClockFlags) {
unsafe {
let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _;
let _guard = ::utils::MutexGuard::lock(&(*ptr).lock);
(*ptr).flags &= !flags.to_glib();
}
}
fn get_clock_flags(&self) -> ClockFlags {
unsafe {
let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _;
let _guard = ::utils::MutexGuard::lock(&(*ptr).lock);
from_glib((*ptr).flags)
}
}
} }
#[cfg(test)] #[cfg(test)]