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-08-17 09:48:54 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
use crate::DeviceProvider;
|
|
|
|
use crate::Plugin;
|
|
|
|
use crate::Rank;
|
2017-08-17 09:48:54 +00:00
|
|
|
|
2019-01-16 11:32:58 +00:00
|
|
|
use glib::object::IsA;
|
2019-06-04 05:22:58 +00:00
|
|
|
use glib::translate::ToGlib;
|
2017-08-17 09:48:54 +00:00
|
|
|
use glib::translate::ToGlibPtr;
|
|
|
|
|
|
|
|
use std::ffi::CStr;
|
|
|
|
|
2019-06-04 05:22:58 +00:00
|
|
|
impl DeviceProvider {
|
|
|
|
pub fn register(
|
|
|
|
plugin: Option<&Plugin>,
|
|
|
|
name: &str,
|
|
|
|
rank: Rank,
|
|
|
|
type_: glib::types::Type,
|
|
|
|
) -> Result<(), glib::error::BoolError> {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
unsafe {
|
2020-12-17 22:38:06 +00:00
|
|
|
glib::result_from_gboolean!(
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_device_provider_register(
|
2019-06-04 05:22:58 +00:00
|
|
|
plugin.to_glib_none().0,
|
|
|
|
name.to_glib_none().0,
|
|
|
|
rank.to_glib() as u32,
|
|
|
|
type_.to_glib()
|
|
|
|
),
|
|
|
|
"Failed to register device provider factory"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 09:22:42 +00:00
|
|
|
pub trait DeviceProviderExtManual: 'static {
|
2017-09-01 08:40:32 +00:00
|
|
|
fn get_metadata<'a>(&self, key: &str) -> Option<&'a str>;
|
2017-08-17 09:48:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<O: IsA<DeviceProvider>> DeviceProviderExtManual for O {
|
2017-09-01 08:40:32 +00:00
|
|
|
fn get_metadata<'a>(&self, key: &str) -> Option<&'a str> {
|
2017-08-17 09:48:54 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let klass = (*(self.as_ptr() as *mut glib::gobject_ffi::GTypeInstance)).g_class
|
|
|
|
as *mut ffi::GstDeviceProviderClass;
|
2017-08-17 09:48:54 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
let ptr = ffi::gst_device_provider_class_get_metadata(klass, key.to_glib_none().0);
|
2017-08-17 09:48:54 +00:00
|
|
|
|
|
|
|
if ptr.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(CStr::from_ptr(ptr).to_str().unwrap())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|