插件系统
Monibuca V6 采用插件化架构,所有协议支持和扩展功能都以插件形式实现。引擎本身只提供核心的流管理、帧分发和配置框架,协议编解码和业务逻辑由插件完成。
三种插件模式
Section titled “三种插件模式”静态编译(Static Plugins)
Section titled “静态编译(Static Plugins)”插件在编译时直接链接到主引擎二进制中。这是默认模式,提供最佳性能。预编译二进制和 Docker 镜像使用此模式,已包含全部官方插件。
优点: 无运行时开销,编译器可跨 crate 优化,LTO 优化效果最好
动态加载(Dynamic Plugins)
Section titled “动态加载(Dynamic Plugins)”插件编译为共享库(.so/.dylib/.dll),在运行时加载。
[features]dynamic-plugins = []优点: 无需重新编译主程序即可添加/更新插件
适用场景: 需要热更新插件,或由第三方提供插件的部署场景
WASM 沙箱(WASM Plugins)
Section titled “WASM 沙箱(WASM Plugins)”插件编译为 WebAssembly 模块,在 WASM 运行时中隔离执行。
优点: 最高安全性,插件不能访问主机内存
适用场景: 执行不受信任的第三方插件
内置插件列表
Section titled “内置插件列表”Monibuca V6 使用 Feature Flags 精细控制编译内容。预编译二进制默认包含全部插件,可通过配置文件按需启用或禁用。
| Feature | 插件 | 说明 |
|---|---|---|
rtmp | plugin-rtmp | RTMP/RTMPS 推拉流 |
rtsp | plugin-rtsp | RTSP/RTSPS 推拉流 |
flv | plugin-flv | HTTP-FLV 拉流 |
hls | plugin-hls | HLS 切片输出 |
webrtc | plugin-webrtc | WebRTC 推拉流 |
srt | plugin-srt | SRT 推拉流 |
webtransport | plugin-webtransport | WebTransport/QUIC |
gb28181 | plugin-gb28181 | GB/T 28181 国标设备接入 |
| Feature | 插件 | 说明 |
|---|---|---|
mp4 | plugin-mp4 | MP4 录制 |
snap | plugin-snap | 截图服务 |
ffmpeg_transcode | plugin-transcode | FFmpeg 转码 |
logrotate | plugin-logrotate | 日志轮转 |
debug | plugin-debug | 调试工具 |
sei | plugin-sei | SEI 数据注入/提取 |
crontab | plugin-crontab | 定时任务 |
report | plugin-report | 数据上报 |
mix | plugin-mix | 混流 |
crypto | plugin-crypto | 流加密 |
transcode | — | 内置 Opus↔AAC 转码(codec crate feature) |
| Feature | 插件 | 说明 |
|---|---|---|
onvif | plugin-onvif | ONVIF 设备发现与管理 |
v4l2 | plugin-v4l2 | V4L2 摄像头采集(Linux) |
alsa | plugin-alsa | ALSA 音频采集(Linux) |
homekit | plugin-homekit | HomeKit 相机模拟 |
房间/互动插件
Section titled “房间/互动插件”| Feature | 插件 | 说明 |
|---|---|---|
live | plugin-live | 直播间 |
meeting | plugin-meeting | 会议室 |
| — | 内置 room | 房间服务(引擎内置,非插件) |
| Feature | 插件 | 说明 |
|---|---|---|
cluster | plugin-cluster | 集群部署 |
auth | — | 认证鉴权 |
license | — | License 管理 |
预编译版本和 Docker 镜像已包含以上全部插件。通过配置文件中的 enable: true/false 按需启用:
rtmp: enable: truertsp: enable: truewebrtc: enable: truehls: enable: false # 不需要的插件设为 false完整插件列表
Section titled “完整插件列表”Monibuca V6 共有 25 个独立插件 crate,加上 1 个内置房间服务:
plugins/├── 协议类 (8)│ ├── rtmp/ RTMP/RTMPS│ ├── rtsp/ RTSP/RTSPS│ ├── flv/ HTTP-FLV│ ├── hls/ HLS│ ├── webrtc/ WebRTC│ ├── srt/ SRT│ ├── webtransport/ WebTransport│ └── gb28181/ GB/T 28181│├── 功能类 (10)│ ├── mp4/ MP4 录制│ ├── snap/ 截图│ ├── transcode/ FFmpeg 转码│ ├── logrotate/ 日志轮转│ ├── debug/ 调试│ ├── sei/ SEI│ ├── crontab/ 定时任务│ ├── report/ 上报│ ├── crypto/ 加密│ └── mix/ 混流│├── 设备类 (4)│ ├── onvif/ ONVIF│ ├── v4l2/ V4L2│ ├── alsa/ ALSA│ └── homekit/ HomeKit│├── 房间/互动类 (2)│ ├── live/ 直播间│ └── meeting/ 会议室│└── 测试/开发 (1) └── test/ 测试插件
内置服务:└── src/room/ 房间服务 (RoomService)插件只依赖开源的 SDK crate,不直接依赖引擎内部实现:
你的自定义插件 │ └──▶ sdk (monibuca-sdk) ← 开源 │ └──▶ codec (monibuca-codec)插件 Cargo.toml 示例
Section titled “插件 Cargo.toml 示例”[package]name = "plugin-xxx"version = "0.1.0"edition = "2024"
[dependencies]sdk = { git = "https://github.com/langhuihui/monibuca-sdk" }静态插件通过 pub use 在主 crate 中注册:
#[cfg(feature = "rtmp")]pub use plugin_rtmp as rtmp;
#[cfg(feature = "rtsp")]pub use plugin_rtsp as rtsp;
#[cfg(feature = "webrtc")]pub use plugin_webrtc as webrtc;ConfigSchema 宏
Section titled “ConfigSchema 宏”插件配置使用 ConfigSchema derive 宏,需要指定 sdk_path:
use sdk::ConfigSchema;
#[derive(ConfigSchema)]#[config_schema(sdk_path = "sdk")]pub struct MyPluginConfig { /// 监听端口 #[schema(default = 1935)] pub port: u16,
/// 超时时间(秒) #[schema(default = 30)] pub timeout: u32,}EngineContext(IoC 容器)
Section titled “EngineContext(IoC 容器)”插件通过 EngineContext 获取引擎能力,而不是直接依赖引擎内部类型:
pub struct EngineContext { // 必有能力 pub stream_manager: Arc<dyn StreamManagerApi>,
// 可选能力 pub database: Option<Arc<dyn DatabaseApi>>, pub transform: Option<Arc<dyn TransformApi>>, pub playback: Option<Arc<dyn PlaybackApi>>,}引擎在 PluginManager::init_all() 时构造 EngineContext 并注入到每个插件。
联系我们
微信公众号:不卡科技
腾讯频道:流媒体技术
QQ 频道:p0qq0crz08
QQ 群:751639168