Skip to main content

Crate oximedia_plugin

Crate oximedia_plugin 

Source
Expand description

Plugin system for OxiMedia.

Enables dynamic loading of external codec implementations, allowing third-party or patent-encumbered codecs to be used without bundling them in the core library.

§Architecture

Plugins implement the CodecPlugin trait and are loaded from shared libraries (.so/.dylib/.dll) at runtime. Each plugin declares its capabilities (which codecs it provides, whether it can decode/encode), and the central PluginRegistry manages discovery, loading, and codec lookup.

§Feature Gates

  • dynamic-loading: Enables loading plugins from shared libraries (requires libloading). Without this feature, only static plugin registration is available.

§Static Plugins

Even without dynamic loading, you can register plugins statically using StaticPlugin and the builder pattern:

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

let info = CodecPluginInfo {
    name: "my-plugin".to_string(),
    version: "1.0.0".to_string(),
    author: "Test".to_string(),
    description: "A test 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-codec".to_string(),
        can_decode: true,
        can_encode: false,
        pixel_formats: vec!["yuv420p".to_string()],
        properties: HashMap::new(),
    });

let registry = PluginRegistry::new();
registry.register(Arc::new(plugin)).expect("registration should succeed");
assert_eq!(registry.plugin_count(), 1);

§Dynamic Plugins (feature = “dynamic-loading”)

With the dynamic-loading feature, plugins can be loaded from shared libraries. The shared library must export two symbols:

  • oximedia_plugin_api_version() -> u32
  • oximedia_plugin_create() -> *mut dyn CodecPlugin

Use the declare_plugin! macro to generate these exports.

Re-exports§

pub use error::PluginError;
pub use error::PluginResult;
pub use hot_reload::compute_hash;
pub use hot_reload::GracefulReload;
pub use hot_reload::HotReloadManager;
pub use hot_reload::PluginLifecycle;
pub use hot_reload::PluginVersion;
pub use hot_reload::ReloadPolicy;
pub use hot_reload::WatchEntry;
pub use manifest::resolve_dependencies;
pub use manifest::DependencyResolution;
pub use manifest::ManifestCodec;
pub use manifest::PluginManifest;
pub use manifest::SemVer;
pub use manifest::SemVerOp;
pub use manifest::SemVerReq;
pub use registry::PluginRegistry;
pub use sandbox::PermissionSet;
pub use sandbox::PluginSandbox;
pub use sandbox::SandboxConfig;
pub use sandbox::SandboxContext;
pub use sandbox::SandboxError;
pub use sandbox::PERM_AUDIO;
pub use sandbox::PERM_FILESYSTEM;
pub use sandbox::PERM_GPU;
pub use sandbox::PERM_MEMORY_LARGE;
pub use sandbox::PERM_NETWORK;
pub use sandbox::PERM_VIDEO;
pub use static_plugin::StaticPlugin;
pub use traits::CodecPlugin;
pub use traits::CodecPluginInfo;
pub use traits::PluginCapability;
pub use traits::PLUGIN_API_VERSION;
pub use version_resolver::DependencyResolver;
pub use version_resolver::PluginDependency;
pub use version_resolver::ResolveError;
pub use version_resolver::SemVer as ResolverSemVer;
pub use version_resolver::VersionConstraint;

Modules§

error
Plugin-specific error types.
hot_reload
Hot-reload plugin management.
manifest
Plugin manifest file parsing and validation.
registry
Central plugin registry with priority ordering and capability caching.
sandbox
Plugin sandboxing: permission enforcement, resource limits, and timeout checking.
static_plugin
Static plugin implementation.
traits
Core plugin traits and types.
version_resolver
Plugin version resolution with semver constraint satisfaction and topological dependency ordering.

Macros§

declare_plugin
Macro for defining a plugin entry point in a shared library.