gstreamer/auto/
registry.rs1use crate::{Object, Plugin, PluginFeature, ffi};
7use glib::{
8 object::ObjectType as _,
9 prelude::*,
10 signal::{SignalHandlerId, connect_raw},
11 translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16 #[doc(alias = "GstRegistry")]
17 pub struct Registry(Object<ffi::GstRegistry, ffi::GstRegistryClass>) @extends Object;
18
19 match fn {
20 type_ => || ffi::gst_registry_get_type(),
21 }
22}
23
24impl Registry {
25 #[doc(alias = "gst_registry_add_feature")]
26 pub fn add_feature(
27 &self,
28 feature: &impl IsA<PluginFeature>,
29 ) -> Result<(), glib::error::BoolError> {
30 unsafe {
31 glib::result_from_gboolean!(
32 ffi::gst_registry_add_feature(
33 self.to_glib_none().0,
34 feature.as_ref().to_glib_none().0
35 ),
36 "Failed to add feature"
37 )
38 }
39 }
40
41 #[doc(alias = "gst_registry_add_plugin")]
42 pub fn add_plugin(&self, plugin: &Plugin) -> Result<(), glib::error::BoolError> {
43 unsafe {
44 glib::result_from_gboolean!(
45 ffi::gst_registry_add_plugin(self.to_glib_none().0, plugin.to_glib_none().0),
46 "Failed to add plugin"
47 )
48 }
49 }
50
51 #[doc(alias = "gst_registry_check_feature_version")]
52 pub fn check_feature_version(
53 &self,
54 feature_name: &str,
55 min_major: u32,
56 min_minor: u32,
57 min_micro: u32,
58 ) -> bool {
59 unsafe {
60 from_glib(ffi::gst_registry_check_feature_version(
61 self.to_glib_none().0,
62 feature_name.to_glib_none().0,
63 min_major,
64 min_minor,
65 min_micro,
66 ))
67 }
68 }
69
70 #[doc(alias = "gst_registry_find_feature")]
71 pub fn find_feature(&self, name: &str, type_: glib::types::Type) -> Option<PluginFeature> {
72 unsafe {
73 from_glib_full(ffi::gst_registry_find_feature(
74 self.to_glib_none().0,
75 name.to_glib_none().0,
76 type_.into_glib(),
77 ))
78 }
79 }
80
81 #[doc(alias = "gst_registry_find_plugin")]
82 pub fn find_plugin(&self, name: &str) -> Option<Plugin> {
83 unsafe {
84 from_glib_full(ffi::gst_registry_find_plugin(
85 self.to_glib_none().0,
86 name.to_glib_none().0,
87 ))
88 }
89 }
90
91 #[doc(alias = "gst_registry_get_feature_list_cookie")]
92 #[doc(alias = "get_feature_list_cookie")]
93 pub fn feature_list_cookie(&self) -> u32 {
94 unsafe { ffi::gst_registry_get_feature_list_cookie(self.to_glib_none().0) }
95 }
96
97 #[doc(alias = "gst_registry_lookup")]
98 pub fn lookup(&self, filename: &str) -> Option<Plugin> {
99 unsafe {
100 from_glib_full(ffi::gst_registry_lookup(
101 self.to_glib_none().0,
102 filename.to_glib_none().0,
103 ))
104 }
105 }
106
107 #[doc(alias = "gst_registry_lookup_feature")]
108 pub fn lookup_feature(&self, name: &str) -> Option<PluginFeature> {
109 unsafe {
110 from_glib_full(ffi::gst_registry_lookup_feature(
111 self.to_glib_none().0,
112 name.to_glib_none().0,
113 ))
114 }
115 }
116
117 #[doc(alias = "gst_registry_remove_feature")]
118 pub fn remove_feature(&self, feature: &impl IsA<PluginFeature>) {
119 unsafe {
120 ffi::gst_registry_remove_feature(
121 self.to_glib_none().0,
122 feature.as_ref().to_glib_none().0,
123 );
124 }
125 }
126
127 #[doc(alias = "gst_registry_remove_plugin")]
128 pub fn remove_plugin(&self, plugin: &Plugin) {
129 unsafe {
130 ffi::gst_registry_remove_plugin(self.to_glib_none().0, plugin.to_glib_none().0);
131 }
132 }
133
134 #[doc(alias = "gst_registry_scan_path")]
135 pub fn scan_path(&self, path: impl AsRef<std::path::Path>) -> bool {
136 unsafe {
137 from_glib(ffi::gst_registry_scan_path(
138 self.to_glib_none().0,
139 path.as_ref().to_glib_none().0,
140 ))
141 }
142 }
143
144 #[doc(alias = "gst_registry_get")]
145 pub fn get() -> Registry {
146 assert_initialized_main_thread!();
147 unsafe { from_glib_none(ffi::gst_registry_get()) }
148 }
149
150 #[doc(alias = "feature-added")]
151 pub fn connect_feature_added<F: Fn(&Self, &PluginFeature) + Send + Sync + 'static>(
152 &self,
153 f: F,
154 ) -> SignalHandlerId {
155 unsafe extern "C" fn feature_added_trampoline<
156 F: Fn(&Registry, &PluginFeature) + Send + Sync + 'static,
157 >(
158 this: *mut ffi::GstRegistry,
159 feature: *mut ffi::GstPluginFeature,
160 f: glib::ffi::gpointer,
161 ) {
162 unsafe {
163 let f: &F = &*(f as *const F);
164 f(&from_glib_borrow(this), &from_glib_borrow(feature))
165 }
166 }
167 unsafe {
168 let f: Box_<F> = Box_::new(f);
169 connect_raw(
170 self.as_ptr() as *mut _,
171 c"feature-added".as_ptr(),
172 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
173 feature_added_trampoline::<F> as *const (),
174 )),
175 Box_::into_raw(f),
176 )
177 }
178 }
179
180 #[doc(alias = "plugin-added")]
181 pub fn connect_plugin_added<F: Fn(&Self, &Plugin) + Send + Sync + 'static>(
182 &self,
183 f: F,
184 ) -> SignalHandlerId {
185 unsafe extern "C" fn plugin_added_trampoline<
186 F: Fn(&Registry, &Plugin) + Send + Sync + 'static,
187 >(
188 this: *mut ffi::GstRegistry,
189 plugin: *mut ffi::GstPlugin,
190 f: glib::ffi::gpointer,
191 ) {
192 unsafe {
193 let f: &F = &*(f as *const F);
194 f(&from_glib_borrow(this), &from_glib_borrow(plugin))
195 }
196 }
197 unsafe {
198 let f: Box_<F> = Box_::new(f);
199 connect_raw(
200 self.as_ptr() as *mut _,
201 c"plugin-added".as_ptr(),
202 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
203 plugin_added_trampoline::<F> as *const (),
204 )),
205 Box_::into_raw(f),
206 )
207 }
208 }
209}
210
211unsafe impl Send for Registry {}
212unsafe impl Sync for Registry {}