2020-12-15 10:53:31 +00:00
|
|
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
2017-10-27 21:03:45 +00:00
|
|
|
|
2021-04-26 12:15:53 +00:00
|
|
|
use glib::prelude::*;
|
2018-04-01 08:30:03 +00:00
|
|
|
use glib::signal::SignalHandlerId;
|
2019-05-11 10:13:33 +00:00
|
|
|
use glib::translate::*;
|
2017-10-27 21:03:45 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
use crate::ClockTime;
|
|
|
|
use crate::ObjectFlags;
|
2019-05-11 10:13:33 +00:00
|
|
|
|
2018-12-08 09:22:42 +00:00
|
|
|
pub trait GstObjectExtManual: 'static {
|
2020-11-21 13:46:48 +00:00
|
|
|
fn connect_deep_notify<F: Fn(&Self, &crate::Object, &glib::ParamSpec) + Send + Sync + 'static>(
|
2017-10-27 21:03:45 +00:00
|
|
|
&self,
|
2019-05-23 18:19:24 +00:00
|
|
|
name: Option<&str>,
|
2017-10-27 21:03:45 +00:00
|
|
|
f: F,
|
|
|
|
) -> SignalHandlerId;
|
2019-05-11 10:13:33 +00:00
|
|
|
|
|
|
|
fn set_object_flags(&self, flags: ObjectFlags);
|
|
|
|
|
2019-05-11 12:51:33 +00:00
|
|
|
fn unset_object_flags(&self, flags: ObjectFlags);
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_object_flags")]
|
2021-04-11 19:39:50 +00:00
|
|
|
fn object_flags(&self) -> ObjectFlags;
|
2020-06-09 01:06:49 +00:00
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_g_value_array")]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_object_get_g_value_array")]
|
2021-04-20 10:23:24 +00:00
|
|
|
fn g_value_array(
|
2020-06-09 01:06:49 +00:00
|
|
|
&self,
|
|
|
|
property_name: &str,
|
|
|
|
timestamp: ClockTime,
|
|
|
|
interval: ClockTime,
|
|
|
|
values: &mut [glib::Value],
|
|
|
|
) -> Result<(), glib::error::BoolError>;
|
2017-10-27 21:03:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
impl<O: IsA<crate::Object>> GstObjectExtManual for O {
|
|
|
|
fn connect_deep_notify<
|
|
|
|
F: Fn(&Self, &crate::Object, &glib::ParamSpec) + Send + Sync + 'static,
|
|
|
|
>(
|
2017-10-27 21:03:45 +00:00
|
|
|
&self,
|
2019-05-23 18:19:24 +00:00
|
|
|
name: Option<&str>,
|
2017-10-27 21:03:45 +00:00
|
|
|
f: F,
|
|
|
|
) -> SignalHandlerId {
|
2018-07-09 17:47:15 +00:00
|
|
|
let signal_name = if let Some(name) = name {
|
|
|
|
format!("deep-notify::{}", name)
|
|
|
|
} else {
|
|
|
|
"deep-notify".into()
|
|
|
|
};
|
|
|
|
|
2020-04-05 14:52:56 +00:00
|
|
|
let obj: Borrowed<glib::Object> =
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { from_glib_borrow(self.as_ptr() as *mut glib::gobject_ffi::GObject) };
|
2018-12-08 09:22:42 +00:00
|
|
|
|
|
|
|
obj.connect(signal_name.as_str(), false, move |values| {
|
2019-08-11 07:33:34 +00:00
|
|
|
// It would be nice to display the actual signal name in the panic messages below,
|
|
|
|
// but that would require to copy `signal_name` so as to move it into the closure
|
|
|
|
// which seems too much for the messages of development errors
|
|
|
|
let obj: O = unsafe {
|
|
|
|
values[0]
|
2020-11-21 13:46:48 +00:00
|
|
|
.get::<crate::Object>()
|
2019-08-11 07:33:34 +00:00
|
|
|
.unwrap_or_else(|err| {
|
|
|
|
panic!("Object signal \"deep-notify\": values[0]: {}", err)
|
|
|
|
})
|
|
|
|
.unsafe_cast()
|
|
|
|
};
|
2020-11-21 13:46:48 +00:00
|
|
|
let prop_obj: crate::Object = values[1]
|
2019-08-11 07:33:34 +00:00
|
|
|
.get()
|
2021-04-20 07:19:02 +00:00
|
|
|
.unwrap_or_else(|err| panic!("Object signal \"deep-notify\": values[1]: {}", err));
|
2017-10-27 21:03:45 +00:00
|
|
|
|
2018-07-09 17:47:15 +00:00
|
|
|
let pspec = unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let pspec = glib::gobject_ffi::g_value_get_param(values[2].to_glib_none().0);
|
2018-07-09 17:47:15 +00:00
|
|
|
from_glib_none(pspec)
|
2017-10-27 21:03:45 +00:00
|
|
|
};
|
|
|
|
|
2018-07-09 17:47:15 +00:00
|
|
|
f(&obj, &prop_obj, &pspec);
|
2017-10-27 21:03:45 +00:00
|
|
|
|
|
|
|
None
|
2018-10-08 12:02:23 +00:00
|
|
|
})
|
2017-10-27 21:03:45 +00:00
|
|
|
}
|
2019-05-11 10:13:33 +00:00
|
|
|
|
|
|
|
fn set_object_flags(&self, flags: ObjectFlags) {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
|
|
|
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
|
2021-04-27 15:15:46 +00:00
|
|
|
(*ptr).flags |= flags.into_glib();
|
2019-05-11 10:13:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-11 12:51:33 +00:00
|
|
|
fn unset_object_flags(&self, flags: ObjectFlags) {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
|
|
|
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
|
2021-04-27 15:15:46 +00:00
|
|
|
(*ptr).flags &= !flags.into_glib();
|
2019-05-11 12:51:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
fn object_flags(&self) -> ObjectFlags {
|
2019-05-11 10:13:33 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
|
|
|
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
|
2019-05-11 10:13:33 +00:00
|
|
|
from_glib((*ptr).flags)
|
|
|
|
}
|
|
|
|
}
|
2020-06-09 01:06:49 +00:00
|
|
|
|
2021-04-20 10:23:24 +00:00
|
|
|
fn g_value_array(
|
2020-06-09 01:06:49 +00:00
|
|
|
&self,
|
|
|
|
property_name: &str,
|
|
|
|
timestamp: ClockTime,
|
|
|
|
interval: ClockTime,
|
|
|
|
values: &mut [glib::Value],
|
|
|
|
) -> Result<(), glib::error::BoolError> {
|
|
|
|
let n_values = values.len() as u32;
|
|
|
|
unsafe {
|
2020-12-17 22:38:06 +00:00
|
|
|
glib::result_from_gboolean!(
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_object_get_g_value_array(
|
2020-06-09 01:06:49 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
property_name.to_glib_none().0,
|
2021-04-27 15:15:46 +00:00
|
|
|
timestamp.into_glib(),
|
|
|
|
interval.into_glib(),
|
2020-06-09 01:06:49 +00:00
|
|
|
n_values,
|
2020-11-21 13:46:48 +00:00
|
|
|
values.as_mut_ptr() as *mut glib::gobject_ffi::GValue,
|
2020-06-09 01:06:49 +00:00
|
|
|
),
|
|
|
|
"Failed to get value array"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2017-10-27 21:03:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
2020-11-21 13:46:48 +00:00
|
|
|
use crate::prelude::*;
|
2017-10-27 21:03:45 +00:00
|
|
|
use std::sync::{Arc, Mutex};
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_deep_notify() {
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::init().unwrap();
|
2017-10-27 21:03:45 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
let bin = crate::Bin::new(None);
|
|
|
|
let identity = crate::ElementFactory::make("identity", Some("id")).unwrap();
|
2017-10-27 21:03:45 +00:00
|
|
|
bin.add(&identity).unwrap();
|
|
|
|
|
|
|
|
let notify = Arc::new(Mutex::new(None));
|
|
|
|
let notify_clone = notify.clone();
|
2018-07-09 17:47:15 +00:00
|
|
|
bin.connect_deep_notify(None, move |_, id, prop| {
|
2021-04-11 19:39:50 +00:00
|
|
|
*notify_clone.lock().unwrap() = Some((id.clone(), prop.name()));
|
2017-10-27 21:03:45 +00:00
|
|
|
});
|
|
|
|
|
2021-11-06 17:09:27 +00:00
|
|
|
identity.set_property("silent", false);
|
2017-10-27 21:03:45 +00:00
|
|
|
assert_eq!(
|
|
|
|
*notify.lock().unwrap(),
|
2020-11-21 13:46:48 +00:00
|
|
|
Some((identity.upcast::<crate::Object>(), "silent"))
|
2017-10-27 21:03:45 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|