Skip to content

fix: improve senc parsing for separate init segments#494

Merged
tobbee merged 2 commits intomasterfrom
issue-492
Apr 6, 2026
Merged

fix: improve senc parsing for separate init segments#494
tobbee merged 2 commits intomasterfrom
issue-492

Conversation

@tobbee
Copy link
Copy Markdown
Collaborator

@tobbee tobbee commented Apr 6, 2026

Summary

Fixes #492

  • senc perSampleIVSize priority chain: seig sample group > tenc from init segment > heuristic with saiz validation
  • New API: Fragment.ParseSenc(init) and MediaSegment.ParseSenc(init) for parsing senc boxes when the init segment is in a separate file
  • Heuristic improvement: candidate IV sizes are validated against saiz sample sizes, preventing incorrect selection (e.g. picking 0 when it should be 8)
  • Heuristic results are replaceable: tracked via isParsedByGuess so authoritative tenc info from a later ParseSenc() call overrides them
  • Code deduplication: DecodeSenc now delegates to DecodeSencSR

Test plan

  • mp4ff-info on media segment without init still shows parsed senc details (heuristic path)
  • mp4ff-decrypt with separate init + media segment works correctly
  • New tests: TestParseSencWithSeparateInit and TestParseSencWithSeig

@tobbee tobbee mentioned this pull request Apr 6, 2026
@tobbee tobbee force-pushed the issue-492 branch 6 times, most recently from 71c1923 to 82aea70 Compare April 6, 2026 19:43
Update actions/checkout v3/v4 to v5 and actions/setup-go v5 to v6
to avoid Node.js 20 deprecation warnings.
@tobbee tobbee force-pushed the issue-492 branch 4 times, most recently from c02fc9e to 279ecd5 Compare April 6, 2026 20:57
Senc perSampleIVSize is now determined with correct priority:
1. seig sample group entry in traf
2. tenc defaultPerSampleIVSize from init segment
3. heuristic with saiz sample size validation

When moov is not available during decode (separate init segment),
the heuristic attempts parsing using saiz to validate candidates.
If an init segment is later provided via the new ParseSenc() methods,
the authoritative tenc value replaces any heuristic result.

Key changes:
- Add Fragment.ParseSenc() and MediaSegment.ParseSenc() for deferred
  senc parsing with a separate init segment
- Add saiz-based validation to reject invalid IV size candidates
- Track heuristic results via isParsedByGuess so they can be replaced
- DecodeSenc now delegates to DecodeSencSR removing duplication
- mp4ff-decrypt calls ParseSenc() when using a separate init file
@tobbee tobbee merged commit 9ff6df1 into master Apr 6, 2026
8 of 9 checks passed
@tobbee tobbee deleted the issue-492 branch April 6, 2026 21:04
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.

Panic when decrypt segment

1 participant