Skip to main content

PluginRegistry

Struct PluginRegistry 

Source
pub struct PluginRegistry { /* private fields */ }
Expand description

Central registry for all loaded codec plugins.

The registry maintains a list of registered plugins ordered by priority (descending) and provides methods to discover codecs, create decoders/encoders, and manage the plugin lifecycle.

§Thread Safety

The registry uses interior mutability (RwLock) so it can be shared across threads. Multiple readers can query the registry concurrently; writes (registration) acquire an exclusive lock.

§Priority

Higher priority values take precedence when multiple plugins provide the same codec. Use register_with_priority to supply a custom priority (default is 0).

§Example

use oximedia_plugin::{PluginRegistry, StaticPlugin, CodecPluginInfo, PluginCapability};
use std::sync::Arc;
use std::collections::HashMap;

let registry = PluginRegistry::new();

let info = CodecPluginInfo {
    name: "example".to_string(),
    version: "0.1.0".to_string(),
    author: "Test".to_string(),
    description: "Example plugin".to_string(),
    api_version: oximedia_plugin::PLUGIN_API_VERSION,
    license: "MIT".to_string(),
    patent_encumbered: false,
};

let plugin = StaticPlugin::new(info)
    .add_capability(PluginCapability {
        codec_name: "test".to_string(),
        can_decode: true,
        can_encode: false,
        pixel_formats: vec![],
        properties: HashMap::new(),
    });

registry.register(Arc::new(plugin)).expect("should register");
assert!(registry.has_codec("test"));

Implementations§

Source§

impl PluginRegistry

Source

pub fn new() -> Self

Create a new empty plugin registry with default search paths.

Source

pub fn empty() -> Self

Create a registry with no search paths (for testing).

Source

pub fn add_search_path(&mut self, path: PathBuf)

Add a directory to search for plugins.

Source

pub fn search_paths(&self) -> &[PathBuf]

Get the list of search paths.

Source

pub fn default_search_paths() -> Vec<PathBuf>

Compute default search paths for plugin discovery.

The following paths are checked (in order):

  1. $OXIMEDIA_PLUGIN_PATH (colon-separated on Unix, semicolon on Windows)
  2. ~/.oximedia/plugins/
  3. /usr/lib/oximedia/plugins/ (Unix only)
  4. /usr/local/lib/oximedia/plugins/ (Unix only)
Source

pub fn register(&self, plugin: Arc<dyn CodecPlugin>) -> PluginResult<()>

Register a static plugin instance with default priority (0).

The plugin is validated (API version check, duplicate name check) before being added to the registry.

§Errors

Returns PluginError::ApiIncompatible if the API version does not match, or PluginError::AlreadyRegistered if a plugin with the same name is already loaded.

Source

pub fn register_with_priority( &self, plugin: Arc<dyn CodecPlugin>, priority: i32, ) -> PluginResult<()>

Register a plugin with an explicit priority.

Plugins with a higher priority value are preferred when multiple plugins provide the same codec. Negative priorities are allowed.

§Errors

Same as register.

Source

pub fn unregister(&self, name: &str) -> PluginResult<()>

Unregister a plugin by name.

§Errors

Returns PluginError::NotFound if no plugin with that name is registered.

Source

pub fn load_plugin(&self, _path: &Path) -> PluginResult<()>

Load a plugin from a shared library file.

This is a stub that returns an error when the dynamic-loading feature is not enabled.

Source

pub fn discover_plugins(&self) -> PluginResult<Vec<CodecPluginInfo>>

Discover plugins stub when dynamic loading is disabled.

Source

pub fn list_plugins(&self) -> Vec<CodecPluginInfo>

List all registered plugins (in priority order, highest first).

Source

pub fn list_codecs(&self) -> Vec<PluginCapability>

List all available codecs across all plugins.

Source

pub fn find_decoder( &self, codec_name: &str, ) -> CodecResult<Box<dyn VideoDecoder>>

Find and create a decoder for a given codec name.

Searches all registered plugins (in priority order) for one that can decode the requested codec, and creates a new decoder instance.

Uses the capability cache for O(1) plugin lookup.

§Errors

Returns error if no plugin supports decoding the given codec.

Source

pub fn find_encoder( &self, codec_name: &str, config: EncoderConfig, ) -> CodecResult<Box<dyn VideoEncoder>>

Find and create an encoder for a given codec name.

Searches all registered plugins (in priority order) for one that can encode the requested codec, and creates a new encoder instance.

Uses the capability cache for O(1) plugin lookup.

§Errors

Returns error if no plugin supports encoding the given codec.

Source

pub fn has_codec(&self, codec_name: &str) -> bool

Check if any plugin provides a given codec (decode or encode).

Source

pub fn has_decoder(&self, codec_name: &str) -> bool

Check if any plugin can decode a given codec.

Source

pub fn has_encoder(&self, codec_name: &str) -> bool

Check if any plugin can encode a given codec.

Source

pub fn plugin_count(&self) -> usize

Get the number of registered plugins.

Source

pub fn clear(&self)

Unload all registered plugins and clear the cache.

Source

pub fn find_plugin_for_codec(&self, codec_name: &str) -> Option<CodecPluginInfo>

Find the plugin that provides a given codec (respects priority ordering).

Source

pub fn plugin_priority(&self, name: &str) -> Option<i32>

Get the priority of a registered plugin by name.

Returns None if no plugin with that name is registered.

Trait Implementations§

Source§

impl Default for PluginRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more