mediaway_container/lib.rs
1//! Container facade — shared traits and Mediaway-typed MP4 surface.
2//!
3//! Pure ISOBMFF lives in [`iso_bmff`]. This crate maps to [`mediaway_common`]
4//! types and exposes [`Mux`] / [`Demux`] / [`DemuxDecrypt`].
5
6#![forbid(unsafe_code)]
7
8pub mod adts;
9pub mod convert;
10pub mod flv;
11pub mod mp3;
12pub mod mp4;
13mod mp4_parser;
14pub mod ogg;
15pub mod ts;
16pub mod wav;
17#[cfg(any(feature = "mux", feature = "demux"))]
18pub mod webm;
19
20use mediaway_common::{Packet, StreamInfo};
21
22/// Pair a muxer and demuxer for one container format.
23pub trait ContainerFormat {
24 /// Muxer type (often a typestate root).
25 type Muxer;
26 /// Demuxer type.
27 type Demuxer;
28
29 /// Empty muxer (track registration / open state).
30 fn muxer() -> Self::Muxer;
31 /// Empty demuxer.
32 fn demuxer() -> Self::Demuxer;
33}
34
35/// Live mux session: packets in → container bytes out.
36pub trait Mux {
37 /// Implementation error type.
38 type Error;
39
40 /// Push one compressed packet.
41 ///
42 /// # Errors
43 ///
44 /// Returns when the packet does not match registered tracks or framing fails.
45 fn push_packet(&mut self, packet: &Packet) -> Result<(), Self::Error>;
46 /// Flush pending fragments / trailers.
47 fn flush(&mut self);
48 /// Append available container bytes into `out`; returns bytes written.
49 fn poll_bytes(&mut self, out: &mut Vec<u8>) -> usize;
50}
51
52/// Demux session: container bytes in → packets out.
53pub trait Demux {
54 /// Feed container bytes (sans-io; caller owns I/O).
55 fn push_bytes(&mut self, chunk: &[u8]);
56 /// Tracks discovered so far (e.g. after `moov`).
57 fn streams(&self) -> &[StreamInfo];
58 /// Next demuxed packet, if any.
59 fn poll_packet(&mut self) -> Option<Packet>;
60}
61
62/// Optional `ClearKey` hook for demuxers that support ISO CENC.
63pub trait DemuxDecrypt: Demux {
64 /// Supply a 128-bit content key for sample decrypt.
65 fn set_decryption_key(&mut self, key: [u8; 16]);
66 /// Drop any previously set key.
67 fn clear_decryption_key(&mut self);
68}