oximedia_plugin/lib.rs
1//! Plugin system for OxiMedia.
2//!
3//! Enables dynamic loading of external codec implementations,
4//! allowing third-party or patent-encumbered codecs to be used
5//! without bundling them in the core library.
6//!
7//! # Architecture
8//!
9//! Plugins implement the [`CodecPlugin`] trait and are loaded from
10//! shared libraries (.so/.dylib/.dll) at runtime. Each plugin
11//! declares its capabilities (which codecs it provides, whether
12//! it can decode/encode), and the central [`PluginRegistry`] manages
13//! discovery, loading, and codec lookup.
14//!
15//! # Feature Gates
16//!
17//! - `dynamic-loading`: Enables loading plugins from shared libraries
18//! (requires libloading). Without this feature, only static plugin
19//! registration is available.
20//!
21//! # Static Plugins
22//!
23//! Even without dynamic loading, you can register plugins statically
24//! using [`StaticPlugin`] and the builder pattern:
25//!
26//! ```rust
27//! use oximedia_plugin::{StaticPlugin, CodecPluginInfo, PluginCapability, PluginRegistry};
28//! use std::sync::Arc;
29//! use std::collections::HashMap;
30//!
31//! let info = CodecPluginInfo {
32//! name: "my-plugin".to_string(),
33//! version: "1.0.0".to_string(),
34//! author: "Test".to_string(),
35//! description: "A test plugin".to_string(),
36//! api_version: oximedia_plugin::PLUGIN_API_VERSION,
37//! license: "MIT".to_string(),
38//! patent_encumbered: false,
39//! };
40//!
41//! let plugin = StaticPlugin::new(info)
42//! .add_capability(PluginCapability {
43//! codec_name: "test-codec".to_string(),
44//! can_decode: true,
45//! can_encode: false,
46//! pixel_formats: vec!["yuv420p".to_string()],
47//! properties: HashMap::new(),
48//! });
49//!
50//! let registry = PluginRegistry::new();
51//! registry.register(Arc::new(plugin)).expect("registration should succeed");
52//! assert_eq!(registry.plugin_count(), 1);
53//! ```
54//!
55//! # Dynamic Plugins (feature = "dynamic-loading")
56//!
57//! With the `dynamic-loading` feature, plugins can be loaded from
58//! shared libraries. The shared library must export two symbols:
59//!
60//! - `oximedia_plugin_api_version() -> u32`
61//! - `oximedia_plugin_create() -> *mut dyn CodecPlugin`
62//!
63//! Use the [`declare_plugin!`] macro to generate these exports.
64
65pub mod error;
66pub mod hot_reload;
67pub mod manifest;
68pub mod registry;
69pub mod sandbox;
70pub mod static_plugin;
71pub mod traits;
72pub mod version_resolver;
73
74#[cfg(feature = "dynamic-loading")]
75pub mod loader;
76
77pub use error::{PluginError, PluginResult};
78pub use hot_reload::{
79 compute_hash, GracefulReload, HotReloadManager, PluginLifecycle, PluginVersion, ReloadPolicy,
80 WatchEntry,
81};
82pub use manifest::{
83 resolve_dependencies, DependencyResolution, ManifestCodec, PluginManifest, SemVer, SemVerOp,
84 SemVerReq,
85};
86pub use registry::PluginRegistry;
87pub use sandbox::{
88 PermissionSet, PluginSandbox, SandboxConfig, SandboxContext, SandboxError, PERM_AUDIO,
89 PERM_FILESYSTEM, PERM_GPU, PERM_MEMORY_LARGE, PERM_NETWORK, PERM_VIDEO,
90};
91pub use static_plugin::StaticPlugin;
92pub use traits::{CodecPlugin, CodecPluginInfo, PluginCapability, PLUGIN_API_VERSION};
93pub use version_resolver::{
94 DependencyResolver, PluginDependency, ResolveError, SemVer as ResolverSemVer, VersionConstraint,
95};