Skip to content

Conversation

@bradh
Copy link
Collaborator

@bradh bradh commented Jan 10, 2026

See ISO/IEC 14496-12:2022 Section 8.8

See ISO/IEC 14496-12:2022 Section 8.8
@coderabbitai
Copy link

coderabbitai bot commented Jan 10, 2026

Walkthrough

This change introduces support for Movie Fragment Random Access (MFRA) box structures in the ISO BMFF format. New modules are added for mfra, mfro, and tfra atoms with complete encoding and decoding implementations. The Mfra struct contains a vector of Tfra entries and an Mfro box. The Tfra implementation includes logic for variable-length field encoding and version selection. The Mfro struct stores a parent size field. Three new enum variants (Mfra, Tfra, Mfro) are added to the Any enum. A MAX constant is added to the u24 type. All implementations include unit tests for round-trip encoding and decoding.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 29.41% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main changes: implementing mfra container with nested tfra and mfro boxes, which matches the comprehensive set of additions across multiple files.
Description check ✅ Passed The description references the relevant ISO standard (ISO/IEC 14496-12:2022 Section 8.8) that governs the mfra, tfra, and mfro box implementations in the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/mfra/tfra.rs (1)

70-95: Minor: Consider renaming parameter for clarity.

The parameter num_bits_minus_one is technically num_bytes_minus_one (values 0-3 map to 1-4 bytes). However, this aligns with how the ISO spec uses "length_size_of_*" fields, so keeping it consistent with the specification terminology is reasonable.

The .expect() on line 89 is safe because determine_required_lengths ensures the value fits within 24 bits before selecting num_bits_minus_one = 2.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 65cf2ea and 76be58b.

📒 Files selected for processing (6)
  • src/any.rs
  • src/lib.rs
  • src/mfra/mfro.rs
  • src/mfra/mod.rs
  • src/mfra/tfra.rs
  • src/types.rs
🧰 Additional context used
📓 Path-based instructions (3)
**/*.rs

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.rs: Code must be clippy-clean (cargo clippy --all-targets --all-features -- -D warnings)
Code must be formatted with rustfmt (cargo fmt) and pass formatting checks (cargo fmt -- --check)
Write unit tests inline within modules using #[cfg(test)]

Files:

  • src/types.rs
  • src/lib.rs
  • src/mfra/mfro.rs
  • src/any.rs
  • src/mfra/mod.rs
  • src/mfra/tfra.rs
src/**/*.rs

📄 CodeRabbit inference engine (CLAUDE.md)

src/**/*.rs: Each MP4 atom type must implement the Atom trait with KIND, decode_body(), and encode_body()
Use Header::read_from() to handle large atoms without loading entire contents into memory
All operations should return Result using custom error types defined in error.rs
Use the custom Buf/BufMut traits for contiguous byte slices instead of ad-hoc buffer handling

Files:

  • src/types.rs
  • src/lib.rs
  • src/mfra/mfro.rs
  • src/any.rs
  • src/mfra/mod.rs
  • src/mfra/tfra.rs
src/any.rs

📄 CodeRabbit inference engine (CLAUDE.md)

Register new atom types in the Any enum (src/any.rs) to enable flexible decoding

Files:

  • src/any.rs
🧠 Learnings (6)
📓 Common learnings
Learnt from: CR
Repo: kixelated/mp4-atom PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-08-31T04:06:57.364Z
Learning: Applies to src/moov/** : Place movie metadata atom implementations under src/moov/ (and its hierarchy: trak/mdia/minf/stbl/stsd)
Learnt from: CR
Repo: kixelated/mp4-atom PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-08-31T04:06:57.364Z
Learning: Applies to src/**/*.rs : Each MP4 atom type must implement the Atom trait with KIND, decode_body(), and encode_body()
Learnt from: CR
Repo: kixelated/mp4-atom PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-08-31T04:06:57.364Z
Learning: Applies to src/moof/** : Place movie fragment atom implementations under src/moof/
Learnt from: CR
Repo: kixelated/mp4-atom PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-08-31T04:06:57.364Z
Learning: Applies to src/any.rs : Register new atom types in the Any enum (src/any.rs) to enable flexible decoding
Learnt from: CR
Repo: kixelated/mp4-atom PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-08-31T04:06:57.364Z
Learning: Place top-level atoms (e.g., ftyp, mdat, free) at the top-level of src/
📚 Learning: 2025-08-31T04:06:57.364Z
Learnt from: CR
Repo: kixelated/mp4-atom PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-08-31T04:06:57.364Z
Learning: Applies to src/moov/** : Place movie metadata atom implementations under src/moov/ (and its hierarchy: trak/mdia/minf/stbl/stsd)

Applied to files:

  • src/lib.rs
  • src/mfra/mod.rs
📚 Learning: 2025-08-31T04:06:57.364Z
Learnt from: CR
Repo: kixelated/mp4-atom PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-08-31T04:06:57.364Z
Learning: Place top-level atoms (e.g., ftyp, mdat, free) at the top-level of src/

Applied to files:

  • src/lib.rs
📚 Learning: 2025-08-31T04:06:57.364Z
Learnt from: CR
Repo: kixelated/mp4-atom PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-08-31T04:06:57.364Z
Learning: Applies to src/moof/** : Place movie fragment atom implementations under src/moof/

Applied to files:

  • src/lib.rs
  • src/mfra/mfro.rs
  • src/mfra/mod.rs
📚 Learning: 2025-08-31T04:06:57.364Z
Learnt from: CR
Repo: kixelated/mp4-atom PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-08-31T04:06:57.364Z
Learning: Applies to src/**/*.rs : Each MP4 atom type must implement the Atom trait with KIND, decode_body(), and encode_body()

Applied to files:

  • src/lib.rs
  • src/mfra/mfro.rs
  • src/any.rs
  • src/mfra/mod.rs
  • src/mfra/tfra.rs
📚 Learning: 2025-08-31T04:06:57.364Z
Learnt from: CR
Repo: kixelated/mp4-atom PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-08-31T04:06:57.364Z
Learning: Applies to src/any.rs : Register new atom types in the Any enum (src/any.rs) to enable flexible decoding

Applied to files:

  • src/mfra/mfro.rs
  • src/any.rs
🧬 Code graph analysis (3)
src/mfra/mfro.rs (2)
src/types.rs (9)
  • new (18-20)
  • new (193-195)
  • new (304-306)
  • decode (74-76)
  • decode (101-103)
  • decode (144-146)
  • decode (207-212)
  • decode (286-294)
  • decode (325-329)
src/mfra/tfra.rs (2)
  • decode_body_ext (102-127)
  • encode_body_ext (129-159)
src/mfra/mod.rs (1)
src/types.rs (3)
  • new (18-20)
  • new (193-195)
  • new (304-306)
src/mfra/tfra.rs (1)
src/types.rs (9)
  • decode (74-76)
  • decode (101-103)
  • decode (144-146)
  • decode (207-212)
  • decode (286-294)
  • decode (325-329)
  • new (18-20)
  • new (193-195)
  • new (304-306)
🔇 Additional comments (13)
src/types.rs (1)

90-92: LGTM!

The MAX constant correctly represents the maximum 24-bit unsigned value (2²⁴ - 1). This is appropriately used in tfra.rs for determining variable-length field encoding sizes.

src/lib.rs (1)

153-153: LGTM!

The mfra module declaration and public re-export follow the established codebase patterns. Placement at the top-level src/ directory is appropriate for the Movie Fragment Random Access box per the project's conventions for top-level atoms.

Also applies to: 174-174

src/any.rs (1)

336-338: LGTM!

The new Mfra, Tfra, and Mfro atom types are properly registered in the Any enum's basic variants list, enabling flexible decoding and encoding through the common Any interface. Based on learnings, registering new atom types in src/any.rs is required for flexible decoding.

src/mfra/mfro.rs (2)

1-26: LGTM!

The Mfro (MovieFragmentRandomAccessOffsetBox) implementation correctly follows the AtomExt pattern with Ext = () since this box uses the default version 0 with no flags. The parent_size field aligns with ISO/IEC 14496-12:2022 section 8.8.11 specification.


28-41: LGTM!

Good round-trip test coverage for the Mfro atom. The test validates that encoding and decoding produce identical results.

src/mfra/mod.rs (4)

14-17: LGTM!

The Mfra struct correctly models the Movie Fragment Random Access box with a vector of Tfra entries and a single Mfro. The comment on line 19 appropriately explains why the nested! macro cannot be used here—mfro must be written last per the specification.


23-47: LGTM!

The decode_body implementation properly handles:

  • Duplicate mfro detection with Error::DuplicateBox
  • Missing mfro validation with Error::MissingBox
  • Collection of multiple tfra entries
  • Skip/Free boxes with debug logging
  • Unknown boxes via decode_unknown

49-52: LGTM!

The encode_body correctly writes tfra entries before mfro, ensuring mfro is the last box in the container as required by the specification.


55-176: LGTM!

Excellent test coverage using data from the MPEG File Format Conformance suite. The bidirectional round-trip tests (test_mfra_decode and test_mfra_encode) validate both encoding and decoding paths against the conformance data.

src/mfra/tfra.rs (4)

9-24: LGTM!

The FragmentInfo and Tfra structs correctly model the Track Fragment Random Access box per ISO/IEC 14496-12. Using u64 for time and moof_offset accommodates both V0 (32-bit) and V1 (64-bit) versions internally.


25-68: LGTM!

The determine_required_lengths method correctly calculates the minimum encoding sizes for variable-length fields and selects the appropriate version (V0 or V1) based on whether time or moof_offset values exceed 32-bit limits. The determine_required_length helper properly uses u24::MAX for the 24-bit threshold.


97-160: LGTM!

The AtomExt implementation for Tfra correctly handles:

  • Bit-field extraction/packing for the variable-length size indicators
  • Version-dependent encoding of time and moof_offset (64-bit for V1, 32-bit for V0)
  • Defensive capacity allocation (line 111) that doesn't blindly trust the entry count

The encode/decode symmetry is well-maintained.


162-213: LGTM!

Good test organization—V1 format is explicitly tested here while V0 is exercised through the parent mfra module tests using the conformance suite data. The test data includes interesting edge cases like sample_delta: 65535 (requiring 2-byte encoding).

@bradh bradh merged commit caa033a into kixelated:main Jan 10, 2026
1 check passed
@github-actions github-actions bot mentioned this pull request Jan 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants