gstreamer/
device_provider_factory.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::ffi::CStr;
4
5use glib::translate::*;
6
7use crate::{
8    ffi, DeviceProviderFactory, ELEMENT_METADATA_AUTHOR, ELEMENT_METADATA_DESCRIPTION,
9    ELEMENT_METADATA_DOC_URI, ELEMENT_METADATA_ICON_NAME, ELEMENT_METADATA_KLASS,
10    ELEMENT_METADATA_LONGNAME,
11};
12
13impl DeviceProviderFactory {
14    /// Get a list of factories with a rank greater or equal to `minrank`.
15    /// The list of factories is returned by decreasing rank.
16    /// ## `minrank`
17    /// Minimum rank
18    ///
19    /// # Returns
20    ///
21    ///
22    /// a `GList` of [`DeviceProviderFactory`][crate::DeviceProviderFactory] device providers. Use
23    /// `gst_plugin_feature_list_free()` after usage.
24    #[doc(alias = "gst_device_provider_factory_list_get_device_providers")]
25    pub fn factories(minrank: crate::Rank) -> glib::List<DeviceProviderFactory> {
26        assert_initialized_main_thread!();
27        unsafe {
28            FromGlibPtrContainer::from_glib_full(
29                ffi::gst_device_provider_factory_list_get_device_providers(minrank.into_glib()),
30            )
31        }
32    }
33
34    /// Get the metadata on `self` with `key`.
35    /// ## `key`
36    /// a key
37    ///
38    /// # Returns
39    ///
40    /// the metadata with `key` on `self` or [`None`]
41    /// when there was no metadata with the given `key`.
42    #[doc(alias = "gst_device_provider_factory_get_metadata")]
43    #[doc(alias = "get_metadata")]
44    pub fn metadata(&self, key: &str) -> Option<&str> {
45        unsafe {
46            let ptr = ffi::gst_device_provider_factory_get_metadata(
47                self.to_glib_none().0,
48                key.to_glib_none().0,
49            );
50
51            if ptr.is_null() {
52                None
53            } else {
54                Some(CStr::from_ptr(ptr).to_str().unwrap())
55            }
56        }
57    }
58
59    #[doc(alias = "get_longname")]
60    #[doc(alias = "gst_device_provider_factory_get_longname")]
61    pub fn longname(&self) -> &str {
62        self.metadata(ELEMENT_METADATA_LONGNAME).unwrap()
63    }
64
65    #[doc(alias = "get_klass")]
66    #[doc(alias = "gst_device_provider_factory_get_klass")]
67    pub fn klass(&self) -> &str {
68        self.metadata(ELEMENT_METADATA_KLASS).unwrap()
69    }
70
71    #[doc(alias = "get_description")]
72    #[doc(alias = "gst_device_provider_factory_get_description")]
73    pub fn description(&self) -> &str {
74        self.metadata(ELEMENT_METADATA_DESCRIPTION).unwrap()
75    }
76
77    #[doc(alias = "get_author")]
78    #[doc(alias = "gst_device_provider_factory_get_author")]
79    pub fn author(&self) -> &str {
80        self.metadata(ELEMENT_METADATA_AUTHOR).unwrap()
81    }
82
83    #[doc(alias = "get_documentation_uri")]
84    #[doc(alias = "gst_device_provider_factory_get_documentation_uri")]
85    pub fn documentation_uri(&self) -> Option<&str> {
86        self.metadata(ELEMENT_METADATA_DOC_URI)
87    }
88
89    #[doc(alias = "get_icon_name")]
90    #[doc(alias = "gst_device_provider_factory_get_icon_name")]
91    pub fn icon_name(&self) -> Option<&str> {
92        self.metadata(ELEMENT_METADATA_ICON_NAME)
93    }
94}