pub mod composite;
pub mod dvbsub;
pub mod pgs;
pub mod vobsub;
use oxideav_core::ContainerRegistry;
use oxideav_core::RuntimeContext;
use oxideav_core::{CodecCapabilities, CodecId, MediaType};
use oxideav_core::{CodecInfo, CodecRegistry};
pub const PGS_CODEC_ID: &str = "pgs";
pub const DVBSUB_CODEC_ID: &str = "dvbsub";
pub const VOBSUB_CODEC_ID: &str = "vobsub";
pub fn register_codecs(reg: &mut CodecRegistry) {
for (id, impl_name) in [
(PGS_CODEC_ID, "pgs_sw"),
(DVBSUB_CODEC_ID, "dvbsub_sw"),
(VOBSUB_CODEC_ID, "vobsub_sw"),
] {
let caps = CodecCapabilities {
decode: true,
encode: false,
media_type: MediaType::Subtitle,
intra_only: true,
lossy: false,
lossless: true,
hardware_accelerated: false,
implementation: impl_name.into(),
max_width: None,
max_height: None,
max_bitrate: None,
max_sample_rate: None,
max_channels: None,
priority: 100,
accepted_pixel_formats: Vec::new(),
};
let factory = match id {
PGS_CODEC_ID => pgs::make_decoder,
DVBSUB_CODEC_ID => dvbsub::make_decoder,
VOBSUB_CODEC_ID => vobsub::make_decoder,
_ => unreachable!(),
};
reg.register(
CodecInfo::new(CodecId::new(id))
.capabilities(caps)
.decoder(factory),
);
}
let pgs_enc_caps = CodecCapabilities {
decode: false,
encode: true,
media_type: MediaType::Subtitle,
intra_only: true,
lossy: true,
lossless: false,
hardware_accelerated: false,
implementation: "pgs_sw".into(),
max_width: None,
max_height: None,
max_bitrate: None,
max_sample_rate: None,
max_channels: None,
priority: 100,
accepted_pixel_formats: vec![oxideav_core::PixelFormat::Rgba],
};
reg.register(
CodecInfo::new(CodecId::new(PGS_CODEC_ID))
.capabilities(pgs_enc_caps)
.encoder(pgs::make_encoder),
);
}
pub fn register_containers(reg: &mut ContainerRegistry) {
pgs::register_container(reg);
vobsub::register_container(reg);
}
pub fn register(ctx: &mut RuntimeContext) {
register_codecs(&mut ctx.codecs);
register_containers(&mut ctx.containers);
}
oxideav_core::register!("sub_image", register);
#[cfg(test)]
mod register_tests {
use super::*;
#[test]
fn register_via_runtime_context_installs_both_sides() {
let mut ctx = RuntimeContext::new();
register(&mut ctx);
let id = CodecId::new(PGS_CODEC_ID);
assert!(
ctx.codecs.has_decoder(&id),
"PGS decoder factory not installed via RuntimeContext"
);
assert!(
ctx.codecs.has_encoder(&id),
"PGS encoder factory not installed via RuntimeContext"
);
assert_eq!(
ctx.containers.container_for_extension("sup"),
Some("pgs"),
"PGS container extension not installed via RuntimeContext"
);
}
}