Expose flags on Tkhd#146
Conversation
WalkthroughThe Tkhd struct in src/moov/trak/tkhd.rs was extended with two boolean fields: in_movie and size_is_aspect_ratio. TkhdExt flag mapping was updated and decode/encode logic now reads/writes these flags (track_in_movie and track_size_is_aspect_ratio; track_in_preview is written mirrored from in_movie and ignored on read). Unit tests for Tkhd (32/64) and many codec-specific test fixtures were updated to initialize the new in_movie field. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/moov/trak/tkhd.rs (1)
198-199: Consider adding a direct serialized-flags assertion in unit tests.Current tests are round-trip based; adding one direct assertion on the version+flags word would make bit-position regressions easier to catch.
Suggested test hardening
#[test] fn test_tkhd32() { let expected = Tkhd { creation_time: 100, modification_time: 200, track_id: 1, duration: 634634, layer: 0, alternate_group: 0, volume: 1.into(), matrix: Matrix::default(), width: 512.into(), height: 288.into(), enabled: true, in_movie: true, in_preview: false, }; let mut buf = Vec::new(); expected.encode(&mut buf).unwrap(); + // size(4) + kind(4) + version/flags(4) + assert_eq!(&buf[8..12], &[0x01, 0x00, 0x00, 0x03]); let mut buf = buf.as_ref(); let decoded = Tkhd::decode(&mut buf).unwrap(); assert_eq!(decoded, expected); }Also applies to: 223-224
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/moov/trak/tkhd.rs` around lines 198 - 199, Tests currently only round-trip the TrackHeaderBox; add a direct assertion that the packed version+flags 32-bit word matches the expected literal to catch bit-position regressions. In the unit test for TrackHeaderBox (the case that sets in_movie: true and in_preview: false) call the serializer used (e.g., TrackHeaderBox::to_bytes / write_box / serialize) and extract the first 4 bytes (version+flags) or use the helper that builds the version_and_flags word, then assert equality against the expected u32 constant (computed from version and the flag bits). Reference the fields in_movie and in_preview and the TrackHeaderBox serialization path so the test fails if flag bit positions change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/moov/trak/tkhd.rs`:
- Around line 198-199: Tests currently only round-trip the TrackHeaderBox; add a
direct assertion that the packed version+flags 32-bit word matches the expected
literal to catch bit-position regressions. In the unit test for TrackHeaderBox
(the case that sets in_movie: true and in_preview: false) call the serializer
used (e.g., TrackHeaderBox::to_bytes / write_box / serialize) and extract the
first 4 bytes (version+flags) or use the helper that builds the
version_and_flags word, then assert equality against the expected u32 constant
(computed from version and the flag bits). Reference the fields in_movie and
in_preview and the TrackHeaderBox serialization path so the test fails if flag
bit positions change.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 790684be-dab9-4ba2-ac19-d75021888af0
📒 Files selected for processing (11)
src/moov/mod.rssrc/moov/trak/tkhd.rssrc/test/av1.rssrc/test/bbb.rssrc/test/esds.rssrc/test/flac.rssrc/test/h264.rssrc/test/hevc.rssrc/test/libavif_anim.rssrc/test/uncompressed.rssrc/test/vp9.rs
bradh
left a comment
There was a problem hiding this comment.
LGTM.
A round-trip test would be nice, but I can try to find some time for that later.
Claude is wrong. There are four flags.
What do you need |
|
@bradh Right on, working on tweaks. You're right that |
The spec says:
So on write, that bit position should match |
The tkhd box defines four flag bits (ISO/IEC 14496-12:2022 §8.3.2.3): track_enabled (0x1), track_in_movie (0x2), track_in_preview (0x4), and track_size_is_aspect_ratio (0x8). Previously only track_enabled was exposed as a public field; the others were decoded but discarded and always written as false on encode. Add `in_movie` and `size_is_aspect_ratio` fields to Tkhd so callers can read and write those flags. track_in_preview has no assigned meaning: per the spec it is ignored on read and written as a mirror of track_in_movie, so it is not exposed as a field. Update all test expectations to match the actual flag values in their fixtures. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
622ca7d to
1540386
Compare
|
@bradh Done and rebased per your guidance. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/moov/trak/tkhd.rs (1)
24-24: ⚡ Quick winConsider adding a doc comment for
in_movie.The
size_is_aspect_ratiofield has a helpful doc comment explaining its purpose and citing the spec. Adding a similar comment forin_moviewould improve API documentation consistency and help users understand when to set this flag.📝 Suggested documentation
pub enabled: bool, + /// When set, the track is used in the movie presentation (ISO/IEC 14496-12:2022 §8.3.2.3). pub in_movie: bool,🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/moov/trak/tkhd.rs` at line 24, Add a doc comment for the in_movie field (the pub in_movie: bool in the tkhd.rs struct) similar to the existing size_is_aspect_ratio comment: describe what the flag means (e.g., when true the track is used in the movie vs. only in other contexts), when callers should set it, and, if applicable, cite the relevant spec section or behavior; update the struct field comment above in_movie to match the style and detail of size_is_aspect_ratio for consistent API docs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/moov/trak/tkhd.rs`:
- Line 24: Add a doc comment for the in_movie field (the pub in_movie: bool in
the tkhd.rs struct) similar to the existing size_is_aspect_ratio comment:
describe what the flag means (e.g., when true the track is used in the movie vs.
only in other contexts), when callers should set it, and, if applicable, cite
the relevant spec section or behavior; update the struct field comment above
in_movie to match the style and detail of size_is_aspect_ratio for consistent
API docs.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e6550a8f-2be0-48c0-be6a-5e21a293a3fb
📒 Files selected for processing (11)
src/moov/mod.rssrc/moov/trak/tkhd.rssrc/test/av1.rssrc/test/bbb.rssrc/test/esds.rssrc/test/flac.rssrc/test/h264.rssrc/test/hevc.rssrc/test/libavif_anim.rssrc/test/uncompressed.rssrc/test/vp9.rs
🚧 Files skipped from review as they are similar to previous changes (2)
- src/test/h264.rs
- src/test/bbb.rs
bradh
left a comment
There was a problem hiding this comment.
LGTM. Thanks for the work on this.
Ran into this while working on the MUXL spec; I think having
track_in_movieset is probably a sensible default. Now we can do that!From Claude: