1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
// This file was generated by gir (https://github.com/gtk-rs/gir) // from gir-files (https://github.com/gtk-rs/gir-files) // DO NOT EDIT use glib; use glib::object::IsA; use glib::object::ObjectType as ObjectType_; use glib::signal::connect_raw; use glib::signal::SignalHandlerId; use glib::translate::*; use glib_sys; use gst_sys; use std; use std::boxed::Box as Box_; use std::mem::transmute; use Object; use Plugin; use PluginFeature; glib_wrapper! { /// One registry holds the metadata of a set of plugins. /// /// <emphasis role="bold">Design:`</emphasis>` /// /// The `Registry` object is a list of plugins and some functions for dealing /// with them. Each `Plugin` is matched 1-1 with a file on disk, and may or may /// not be loaded at a given time. /// /// The primary source, at all times, of plugin information is each plugin file /// itself. Thus, if an application wants information about a particular plugin, /// or wants to search for a feature that satisfies given criteria, the primary /// means of doing so is to load every plugin and look at the resulting /// information that is gathered in the default registry. Clearly, this is a time /// consuming process, so we cache information in the registry file. The format /// and location of the cache file is internal to gstreamer. /// /// On startup, plugins are searched for in the plugin search path. The following /// locations are checked in this order: /// /// * location from --gst-plugin-path commandline option. /// * the GST_PLUGIN_PATH environment variable. /// * the GST_PLUGIN_SYSTEM_PATH environment variable. /// * default locations (if GST_PLUGIN_SYSTEM_PATH is not set). /// Those default locations are: /// `$XDG_DATA_HOME/gstreamer-$GST_API_VERSION/plugins/` /// and `$prefix/libs/gstreamer-$GST_API_VERSION/`. /// [$XDG_DATA_HOME](http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html) defaults to /// `$HOME/.local/share`. /// /// The registry cache file is loaded from /// `$XDG_CACHE_HOME/gstreamer-$GST_API_VERSION/registry-$ARCH.bin` /// (where $XDG_CACHE_HOME defaults to `$HOME/.cache`) or the file listed in the `GST_REGISTRY` /// env var. One reason to change the registry location is for testing. /// /// For each plugin that is found in the plugin search path, there could be 3 /// possibilities for cached information: /// /// * the cache may not contain information about a given file. /// * the cache may have stale information. /// * the cache may have current information. /// /// In the first two cases, the plugin is loaded and the cache updated. In /// addition to these cases, the cache may have entries for plugins that are not /// relevant to the current process. These are marked as not available to the /// current process. If the cache is updated for whatever reason, it is marked /// dirty. /// /// A dirty cache is written out at the end of initialization. Each entry is /// checked to make sure the information is minimally valid. If not, the entry is /// simply dropped. /// /// ## Implementation notes: /// /// The "cache" and "registry" are different concepts and can represent /// different sets of plugins. For various reasons, at init time, the cache is /// stored in the default registry, and plugins not relevant to the current /// process are marked with the `PluginFlags::Cached` bit. These plugins are /// removed at the end of initialization. /// /// # Implements /// /// [`GstObjectExt`](trait.GstObjectExt.html), [`glib::object::ObjectExt`](../glib/object/trait.ObjectExt.html) pub struct Registry(Object<gst_sys::GstRegistry, gst_sys::GstRegistryClass, RegistryClass>) @extends Object; match fn { get_type => || gst_sys::gst_registry_get_type(), } } impl Registry { /// Add the feature to the registry. The feature-added signal will be emitted. /// /// `feature`'s reference count will be incremented, and any floating /// reference will be removed (see `Object::ref_sink`) /// ## `feature` /// the feature to add /// /// # Returns /// /// `true` on success. /// /// MT safe. pub fn add_feature<P: IsA<PluginFeature>>( &self, feature: &P, ) -> Result<(), glib::error::BoolError> { unsafe { glib_result_from_gboolean!( gst_sys::gst_registry_add_feature( self.to_glib_none().0, feature.as_ref().to_glib_none().0 ), "Failed to add feature" ) } } /// Add the plugin to the registry. The plugin-added signal will be emitted. /// /// `plugin`'s reference count will be incremented, and any floating /// reference will be removed (see `Object::ref_sink`) /// ## `plugin` /// the plugin to add /// /// # Returns /// /// `true` on success. /// /// MT safe. pub fn add_plugin(&self, plugin: &Plugin) -> Result<(), glib::error::BoolError> { unsafe { glib_result_from_gboolean!( gst_sys::gst_registry_add_plugin(self.to_glib_none().0, plugin.to_glib_none().0), "Failed to add plugin" ) } } /// Checks whether a plugin feature by the given name exists in /// `self` and whether its version is at least the /// version required. /// ## `feature_name` /// the name of the feature (e.g. "oggdemux") /// ## `min_major` /// the minimum major version number /// ## `min_minor` /// the minimum minor version number /// ## `min_micro` /// the minimum micro version number /// /// # Returns /// /// `true` if the feature could be found and the version is /// the same as the required version or newer, and `false` otherwise. pub fn check_feature_version( &self, feature_name: &str, min_major: u32, min_minor: u32, min_micro: u32, ) -> bool { unsafe { from_glib(gst_sys::gst_registry_check_feature_version( self.to_glib_none().0, feature_name.to_glib_none().0, min_major, min_minor, min_micro, )) } } /// Runs a filter against all features of the plugins in the registry /// and returns a GList with the results. /// If the first flag is set, only the first match is /// returned (as a list with a single object). /// ## `filter` /// the filter to use /// ## `first` /// only return first match /// ## `user_data` /// user data passed to the filter function /// /// # Returns /// /// a `glib::List` of /// `PluginFeature`. Use `PluginFeature::list_free` after usage. /// /// MT safe. pub fn feature_filter<P: FnMut(&PluginFeature) -> bool>( &self, filter: P, first: bool, ) -> Vec<PluginFeature> { let filter_data: P = filter; unsafe extern "C" fn filter_func<P: FnMut(&PluginFeature) -> bool>( feature: *mut gst_sys::GstPluginFeature, user_data: glib_sys::gpointer, ) -> glib_sys::gboolean { let feature = from_glib_borrow(feature); let callback: *mut P = user_data as *const _ as usize as *mut P; let res = (*callback)(&feature); res.to_glib() } let filter = Some(filter_func::<P> as _); let super_callback0: &P = &filter_data; unsafe { FromGlibPtrContainer::from_glib_full(gst_sys::gst_registry_feature_filter( self.to_glib_none().0, filter, first.to_glib(), super_callback0 as *const _ as usize as *mut _, )) } } /// Find the pluginfeature with the given name and type in the registry. /// ## `name` /// the pluginfeature name to find /// ## `type_` /// the pluginfeature type to find /// /// # Returns /// /// the pluginfeature with the /// given name and type or `None` if the plugin was not /// found. `GstObjectExt::unref` after usage. /// /// MT safe. pub fn find_feature(&self, name: &str, type_: glib::types::Type) -> Option<PluginFeature> { unsafe { from_glib_full(gst_sys::gst_registry_find_feature( self.to_glib_none().0, name.to_glib_none().0, type_.to_glib(), )) } } /// Find the plugin with the given name in the registry. /// The plugin will be reffed; caller is responsible for unreffing. /// ## `name` /// the plugin name to find /// /// # Returns /// /// the plugin with the given name /// or `None` if the plugin was not found. `GstObjectExt::unref` after /// usage. /// /// MT safe. pub fn find_plugin(&self, name: &str) -> Option<Plugin> { unsafe { from_glib_full(gst_sys::gst_registry_find_plugin( self.to_glib_none().0, name.to_glib_none().0, )) } } /// Retrieves a `glib::List` of `PluginFeature` of `type_`. /// ## `type_` /// a `glib::Type`. /// /// # Returns /// /// a `glib::List` of /// `PluginFeature` of `type_`. Use `PluginFeature::list_free` after use /// /// MT safe. pub fn get_feature_list(&self, type_: glib::types::Type) -> Vec<PluginFeature> { unsafe { FromGlibPtrContainer::from_glib_full(gst_sys::gst_registry_get_feature_list( self.to_glib_none().0, type_.to_glib(), )) } } /// Retrieves a `glib::List` of features of the plugin with name `name`. /// ## `name` /// a plugin name. /// /// # Returns /// /// a `glib::List` of /// `PluginFeature`. Use `PluginFeature::list_free` after usage. pub fn get_feature_list_by_plugin(&self, name: &str) -> Vec<PluginFeature> { unsafe { FromGlibPtrContainer::from_glib_full(gst_sys::gst_registry_get_feature_list_by_plugin( self.to_glib_none().0, name.to_glib_none().0, )) } } /// Returns the registry's feature list cookie. This changes /// every time a feature is added or removed from the registry. /// /// # Returns /// /// the feature list cookie. pub fn get_feature_list_cookie(&self) -> u32 { unsafe { gst_sys::gst_registry_get_feature_list_cookie(self.to_glib_none().0) } } /// Get a copy of all plugins registered in the given registry. The refcount /// of each element in the list in incremented. /// /// # Returns /// /// a `glib::List` of `Plugin`. /// Use `Plugin::list_free` after usage. /// /// MT safe. pub fn get_plugin_list(&self) -> Vec<Plugin> { unsafe { FromGlibPtrContainer::from_glib_full(gst_sys::gst_registry_get_plugin_list( self.to_glib_none().0, )) } } /// Look up a plugin in the given registry with the given filename. /// If found, plugin is reffed. /// ## `filename` /// the name of the file to look up /// /// # Returns /// /// the `Plugin` if found, or /// `None` if not. `GstObjectExt::unref` after usage. pub fn lookup(&self, filename: &str) -> Option<Plugin> { unsafe { from_glib_full(gst_sys::gst_registry_lookup( self.to_glib_none().0, filename.to_glib_none().0, )) } } /// Find a `PluginFeature` with `name` in `self`. /// ## `name` /// a `PluginFeature` name /// /// # Returns /// /// a `PluginFeature` with its refcount incremented, /// use `GstObjectExt::unref` after usage. /// /// MT safe. pub fn lookup_feature(&self, name: &str) -> Option<PluginFeature> { unsafe { from_glib_full(gst_sys::gst_registry_lookup_feature( self.to_glib_none().0, name.to_glib_none().0, )) } } /// Runs a filter against all plugins in the registry and returns a `glib::List` with /// the results. If the first flag is set, only the first match is /// returned (as a list with a single object). /// Every plugin is reffed; use `Plugin::list_free` after use, which /// will unref again. /// ## `filter` /// the filter to use /// ## `first` /// only return first match /// ## `user_data` /// user data passed to the filter function /// /// # Returns /// /// a `glib::List` of `Plugin`. /// Use `Plugin::list_free` after usage. /// /// MT safe. pub fn plugin_filter<P: FnMut(&Plugin) -> bool>(&self, filter: P, first: bool) -> Vec<Plugin> { let filter_data: P = filter; unsafe extern "C" fn filter_func<P: FnMut(&Plugin) -> bool>( plugin: *mut gst_sys::GstPlugin, user_data: glib_sys::gpointer, ) -> glib_sys::gboolean { let plugin = from_glib_borrow(plugin); let callback: *mut P = user_data as *const _ as usize as *mut P; let res = (*callback)(&plugin); res.to_glib() } let filter = Some(filter_func::<P> as _); let super_callback0: &P = &filter_data; unsafe { FromGlibPtrContainer::from_glib_full(gst_sys::gst_registry_plugin_filter( self.to_glib_none().0, filter, first.to_glib(), super_callback0 as *const _ as usize as *mut _, )) } } /// Remove the feature from the registry. /// /// MT safe. /// ## `feature` /// the feature to remove pub fn remove_feature<P: IsA<PluginFeature>>(&self, feature: &P) { unsafe { gst_sys::gst_registry_remove_feature( self.to_glib_none().0, feature.as_ref().to_glib_none().0, ); } } /// Remove the plugin from the registry. /// /// MT safe. /// ## `plugin` /// the plugin to remove pub fn remove_plugin(&self, plugin: &Plugin) { unsafe { gst_sys::gst_registry_remove_plugin(self.to_glib_none().0, plugin.to_glib_none().0); } } /// Scan the given path for plugins to add to the registry. The syntax of the /// path is specific to the registry. /// ## `path` /// the path to scan /// /// # Returns /// /// `true` if registry changed pub fn scan_path<P: AsRef<std::path::Path>>(&self, path: P) -> bool { unsafe { from_glib(gst_sys::gst_registry_scan_path( self.to_glib_none().0, path.as_ref().to_glib_none().0, )) } } /// Retrieves the singleton plugin registry. The caller does not own a /// reference on the registry, as it is alive as long as GStreamer is /// initialized. /// /// # Returns /// /// the `Registry`. pub fn get() -> Registry { assert_initialized_main_thread!(); unsafe { from_glib_none(gst_sys::gst_registry_get()) } } /// Signals that a feature has been added to the registry (possibly /// replacing a previously-added one by the same name) /// ## `feature` /// the feature that has been added pub fn connect_feature_added<F: Fn(&Registry, &PluginFeature) + Send + Sync + 'static>( &self, f: F, ) -> SignalHandlerId { unsafe extern "C" fn feature_added_trampoline< F: Fn(&Registry, &PluginFeature) + Send + Sync + 'static, >( this: *mut gst_sys::GstRegistry, feature: *mut gst_sys::GstPluginFeature, f: glib_sys::gpointer, ) { let f: &F = &*(f as *const F); f(&from_glib_borrow(this), &from_glib_borrow(feature)) } unsafe { let f: Box_<F> = Box_::new(f); connect_raw( self.as_ptr() as *mut _, b"feature-added\0".as_ptr() as *const _, Some(transmute::<_, unsafe extern "C" fn()>( feature_added_trampoline::<F> as *const (), )), Box_::into_raw(f), ) } } /// Signals that a plugin has been added to the registry (possibly /// replacing a previously-added one by the same name) /// ## `plugin` /// the plugin that has been added pub fn connect_plugin_added<F: Fn(&Registry, &Plugin) + Send + Sync + 'static>( &self, f: F, ) -> SignalHandlerId { unsafe extern "C" fn plugin_added_trampoline< F: Fn(&Registry, &Plugin) + Send + Sync + 'static, >( this: *mut gst_sys::GstRegistry, plugin: *mut gst_sys::GstPlugin, f: glib_sys::gpointer, ) { let f: &F = &*(f as *const F); f(&from_glib_borrow(this), &from_glib_borrow(plugin)) } unsafe { let f: Box_<F> = Box_::new(f); connect_raw( self.as_ptr() as *mut _, b"plugin-added\0".as_ptr() as *const _, Some(transmute::<_, unsafe extern "C" fn()>( plugin_added_trampoline::<F> as *const (), )), Box_::into_raw(f), ) } } } unsafe impl Send for Registry {} unsafe impl Sync for Registry {}