gstreamer-rs/gstreamer/src/device_provider_factory.rs
Sebastian Dröge 003554876c Update various APIs to use glib::GStr
Currently only covers what is needed to keep code compiling, plus
everything caps/structure/tags related.

This avoids unnecessary heap allocations for adding the NUL-terminator
of C strings, and especially makes caps/structure handling as efficient
as in C.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1190>
2023-01-15 21:05:57 +02:00

77 lines
2.4 KiB
Rust

// Take a look at the license at the top of the repository in the LICENSE file.
use std::ffi::CStr;
use glib::translate::*;
use crate::{
DeviceProviderFactory, ELEMENT_METADATA_AUTHOR, ELEMENT_METADATA_DESCRIPTION,
ELEMENT_METADATA_DOC_URI, ELEMENT_METADATA_ICON_NAME, ELEMENT_METADATA_KLASS,
ELEMENT_METADATA_LONGNAME,
};
impl DeviceProviderFactory {
#[doc(alias = "gst_device_provider_factory_list_get_device_providers")]
pub fn factories(minrank: crate::Rank) -> glib::List<DeviceProviderFactory> {
assert_initialized_main_thread!();
unsafe {
FromGlibPtrContainer::from_glib_full(
ffi::gst_device_provider_factory_list_get_device_providers(minrank.into_glib()),
)
}
}
#[doc(alias = "gst_device_provider_factory_get_metadata")]
#[doc(alias = "get_metadata")]
pub fn metadata(&self, key: &str) -> Option<&str> {
unsafe {
let ptr = ffi::gst_device_provider_factory_get_metadata(
self.to_glib_none().0,
key.to_glib_none().0,
);
if ptr.is_null() {
None
} else {
Some(CStr::from_ptr(ptr).to_str().unwrap())
}
}
}
#[doc(alias = "get_longname")]
#[doc(alias = "gst_device_provider_factory_get_longname")]
pub fn longname(&self) -> &str {
self.metadata(ELEMENT_METADATA_LONGNAME).unwrap()
}
#[doc(alias = "get_klass")]
#[doc(alias = "gst_device_provider_factory_get_klass")]
pub fn klass(&self) -> &str {
self.metadata(ELEMENT_METADATA_KLASS).unwrap()
}
#[doc(alias = "get_description")]
#[doc(alias = "gst_device_provider_factory_get_description")]
pub fn description(&self) -> &str {
self.metadata(ELEMENT_METADATA_DESCRIPTION).unwrap()
}
#[doc(alias = "get_author")]
#[doc(alias = "gst_device_provider_factory_get_author")]
pub fn author(&self) -> &str {
self.metadata(ELEMENT_METADATA_AUTHOR).unwrap()
}
#[doc(alias = "get_documentation_uri")]
#[doc(alias = "gst_device_provider_factory_get_documentation_uri")]
pub fn documentation_uri(&self) -> Option<&str> {
self.metadata(ELEMENT_METADATA_DOC_URI)
}
#[doc(alias = "get_icon_name")]
#[doc(alias = "gst_device_provider_factory_get_icon_name")]
pub fn icon_name(&self) -> Option<&str> {
self.metadata(ELEMENT_METADATA_ICON_NAME)
}
}