Skip to content

Commit 12c13ca

Browse files
committed
Allow adding additional box decoders in get_boxes
1 parent 257b5c1 commit 12c13ca

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

src/api.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub struct Box {
3131
pub uuid: Option<String>,
3232
/// Version field for FullBox types
3333
pub version: Option<u8>,
34-
/// Flags field for FullBox types
34+
/// Flags field for FullBox types
3535
pub flags: Option<u32>,
3636
/// Box classification: "leaf", "full", "container", or "unknown"
3737
pub kind: String,
@@ -49,7 +49,7 @@ pub struct Box {
4949
///
5050
/// # Parameters
5151
/// - `r`: A reader that implements `Read + Seek` (e.g., `File`, `Cursor<Vec<u8>>`)
52-
/// - `size`: The total size of the MP4 data to parse (typically file length)
52+
/// - `size`: The total size of the MP4 data to parse (typically file length)
5353
/// - `decode`: Whether to decode known box types using the default registry
5454
///
5555
/// # Returns
@@ -66,7 +66,12 @@ pub struct Box {
6666
/// let boxes = get_boxes(&mut file, size, true)?; // decode known boxes
6767
/// # Ok::<(), anyhow::Error>(())
6868
/// ```
69-
pub fn get_boxes<R: Read + Seek>(r: &mut R, size: u64, decode: bool) -> anyhow::Result<Vec<Box>> {
69+
pub fn get_boxes<R: Read + Seek>(
70+
r: &mut R,
71+
size: u64,
72+
decode: bool,
73+
additional_registrations: impl FnOnce(crate::Registry) -> crate::Registry,
74+
) -> anyhow::Result<Vec<Box>> {
7075
// let mut f = File::open(&path)?;
7176
// let file_len = f.metadata()?.len();
7277

@@ -114,7 +119,7 @@ pub fn get_boxes<R: Read + Seek>(r: &mut R, size: u64, decode: bool) -> anyhow::
114119
}
115120

116121
// build JSON tree
117-
let reg = default_registry();
122+
let reg = additional_registrations(default_registry());
118123
let json_boxes = boxes
119124
.iter()
120125
.map(|b| build_box(r, b, decode, &reg))

src/samples.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,13 @@ pub fn track_samples_from_reader<R: Read + Seek>(
153153
let file_size = reader.seek(SeekFrom::End(0))?;
154154
reader.seek(SeekFrom::Start(0))?;
155155

156-
let boxes = crate::get_boxes(&mut reader, file_size, /*decode=*/ true)
157-
.context("getting boxes from reader")?;
156+
let boxes = crate::get_boxes(
157+
&mut reader,
158+
file_size,
159+
/*decode=*/ true,
160+
|registry| registry,
161+
)
162+
.context("getting boxes from reader")?;
158163

159164
let mut result = Vec::new();
160165

0 commit comments

Comments
 (0)