oxideav_avi/lib.rs
1//! Pure-Rust AVI (RIFF/AVI) container: demuxer + muxer.
2//!
3//! AVI is Microsoft's legacy RIFF-based container, still ubiquitous for
4//! Motion-JPEG output from security cameras and older capture hardware. This
5//! crate parses and emits AVI 1.0 files. OpenDML extensions (`ix##`,
6//! super-index, files > 2 GiB) are explicitly out of scope — see
7//! `muxer::write_packet` which returns an error if the output approaches
8//! 2 GiB.
9
10pub mod demuxer;
11pub mod muxer;
12pub(crate) mod packaging;
13pub mod riff;
14pub mod stream_format;
15
16use oxideav_core::ContainerRegistry;
17
18pub fn register_containers(reg: &mut ContainerRegistry) {
19 reg.register_demuxer("avi", demuxer::open);
20 reg.register_muxer("avi", muxer::open);
21 reg.register_extension("avi", "avi");
22 reg.register_probe("avi", probe);
23}
24
25/// Install the AVI container into a [`oxideav_core::RuntimeContext`].
26///
27/// Convenience wrapper around [`register_containers`] that matches the
28/// uniform `register(&mut RuntimeContext)` entry point every sibling
29/// crate exposes.
30///
31/// Also wired into [`oxideav_meta::register_all`] via the
32/// [`oxideav_core::register!`] macro below.
33pub fn register(ctx: &mut oxideav_core::RuntimeContext) {
34 register_containers(&mut ctx.containers);
35}
36
37oxideav_core::register!("avi", register);
38
39/// `RIFF....AVI ` — RIFF chunk with form type AVI (note the trailing space).
40fn probe(p: &oxideav_core::ProbeData) -> u8 {
41 if p.buf.len() >= 12 && &p.buf[0..4] == b"RIFF" && &p.buf[8..12] == b"AVI " {
42 100
43 } else {
44 0
45 }
46}
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn register_via_runtime_context_installs_container() {
54 let mut ctx = oxideav_core::RuntimeContext::new();
55 register(&mut ctx);
56 assert_eq!(ctx.containers.container_for_extension("avi"), Some("avi"));
57 }
58}