Expand description
Hand-rolled MP4/M4A box layer: parse the structure, read iTunes metadata, and
regenerate moov (with patched chunk offsets) to synthesize a re-tagged file
whose mdat audio payload is served verbatim. Strict: anything outside the
supported shape (single audio track, one mdat, non-fragmented) is rejected.
Structs§
- BoxHeader
- A parsed box header (the payload need not be in memory). Public so the core reader can reason about box bounds while seeking.
- Mp4Bounds
- Audio payload bounds within the backing file (the verbatim
mdatpayload). - Mp4Scan
- Everything
synthesize_layoutneeds, read from the backing file once. - Oversize
Drop - An embedded
covrimage or binary----payload that a reader skipped because it exceeded the caller’s size cap. Carries only a descriptor and the payload’s byte size — never the bytes themselves — so the caller can log the lossy drop (the format layer has no logging facade) without materializing the oversized item out of a potentially largemoov(#343).
Enums§
- Mp4Scan
Error - Error from the seeking MP4 reader: an IO failure reading the file, or a
structural/format problem. Kept distinct so the core layer can map IO to
CoreError::Io(preserving errno) and format toCoreError::Format.
Functions§
- box_
header - Parse a box header from
hdr(>= 8 bytes; >= 16 if it uses a 64-bit largesize).remainingis the byte count from this box’s start to EOF, used to resolve asize == 0(“extends to end”) box. - locate_
audio - Parse the file and return the
mdatpayload bounds, or an error to skip it. - read_
binary_ tags - Extract opaque (non-text) MP4
----freeform atoms for binary-tag passthrough. OneEmbeddedBinaryTagper binary-typed (type code != 1)datasub-box of each----atom: key----:<mean>:<name>, payload thedatavalue bytes (after the 8-byte[type][locale]header). Text freeform atoms (type 1) are handled byread_tags, so the two paths never double-store. Lenient: malformed atoms are skipped. Everydatasub-box is inspected, so a mixed atom carrying both a text and a binary value recovers the binary one. - read_
binary_ tags_ reporting - Like
read_binary_tags, but also returns the oversized----values skipped overmax_binary_tag_bytes, so the caller can log each lossy drop. The size check still happens before any copy — an oversized value is described, never materialized. SeeOversizeDrop. - read_
pictures - Lenient: returns empty / skips any malformed atom and never errors — this only
seeds cover art from existing files, so a missing or garbled picture must simply be absent.
Every
datachild of everycovratom yields one picture (the iTunes multiple-artwork convention); non-datachildren are skipped. - read_
pictures_ reporting - Like
read_pictures, but also returns the oversizedcovrimages skipped overmax_art_bytes, so the caller can log each lossy drop. The size check still happens before any copy — an oversized image is described, never materialized. SeeOversizeDrop. - read_
structure - read_
structure_ from - Read the structural boxes (
ftyp,moov, and themdatheader) by seeking, never reading themdatpayload — for audiobooks that payload is hundreds of MB and is served from the backing file at read time. Produces anMp4Scanbyte-identical toread_structureon the same file, so synthesis is unchanged. - read_
tags - Lenient: returns empty / skips any malformed atom and never errors — this only
seeds metadata from existing files, so a missing or garbled tag must simply be
absent. Text atoms map via the vocabulary;
trkn/diskyield track/disc numbers as"N"/"N/M";----freeform atoms key on their name (folded when known). Everydatasub-box of an atom is read, so multi-value atoms recover all their values. Other atoms are skipped. - synthesize_
layout - Regenerate a re-tagged
moovand produce the serving layout[ftyp][regenerated moov][mdat header][mdat payload]. The mdat payload is served verbatim, merely relocated, so every chunk offset shifts by a constantdelta. Patching only offset VALUES (never box sizes) meansnew_moov_sizeis computable beforedelta— no circular dependency. Cover art (every non-empty art row, in input order) and opaque----binary tags stream from the DB at read time, splicing into the layout.