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
|
|
|
|
2021-04-26 12:15:53 +00:00
|
|
|
use glib::prelude::*;
|
|
|
|
use glib::translate::*;
|
2017-08-17 09:48:54 +00:00
|
|
|
|
|
|
|
use std::ffi::CStr;
|
|
|
|
|
2019-06-04 05:22:58 +00:00
|
|
|
impl DeviceProvider {
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_device_provider_register")]
|
2019-06-04 05:22:58 +00:00
|
|
|
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,
|
2021-04-27 15:15:46 +00:00
|
|
|
rank.into_glib() as u32,
|
|
|
|
type_.into_glib()
|
2019-06-04 05:22:58 +00:00
|
|
|
),
|
|
|
|
"Failed to register device provider factory"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 09:22:42 +00:00
|
|
|
pub trait DeviceProviderExtManual: 'static {
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_metadata")]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_device_provider_class_get_metadata")]
|
2021-04-20 10:23:24 +00:00
|
|
|
fn metadata<'a>(&self, key: &str) -> Option<&'a str>;
|
2021-11-15 09:45:30 +00:00
|
|
|
|
|
|
|
#[doc(alias = "gst_device_provider_get_devices")]
|
|
|
|
#[doc(alias = "get_devices")]
|
|
|
|
fn devices(&self) -> glib::List<crate::Device>;
|
2017-08-17 09:48:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<O: IsA<DeviceProvider>> DeviceProviderExtManual for O {
|
2021-04-20 10:23:24 +00:00
|
|
|
fn 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())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-15 09:45:30 +00:00
|
|
|
|
|
|
|
fn devices(&self) -> glib::List<crate::Device> {
|
|
|
|
unsafe {
|
|
|
|
FromGlibPtrContainer::from_glib_full(ffi::gst_device_provider_get_devices(
|
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
2017-08-17 09:48:54 +00:00
|
|
|
}
|