Repository navigation
fix(mp4): separate sample duration defaults from run agreement - #729
Conversation
tobbee
left a comment
There was a problem hiding this comment.
Thanks for this. The fix in Fragment.CommonSampleDuration is right: the precedence is now trex, then a flagged tfhd default, then explicit trun durations, and a previous run's duration no longer leaks into the next run as its default. I ran the new tests against master's code to see what they catch. The points below are what I would like changed before merging.
Code
-
Drop the change to
TrunBox.CommonSampleDuration. It is not needed for the fix: with master'smp4/trun.goand this PR'smp4/fragment.go, every case inTestFragmentCommonSampleDurationDefaultspasses, since the fragment loop already skips empty runs. It changes the result of a public method for an empty run without the sample-duration flag, and I see no reason for that. Please revertmp4/trun.go, the two cases added toTestCommonDuration, and the second half of the changelog entry. -
Say in the changelog entry that a fragment without samples now gives an error. A traf with no runs, or with only empty runs, used to return the header default and now returns "no common sample duration". That is fine, but users of
MediaSegment.CommonSampleDurationwill notice it, since one such fragment fails the whole segment.
Tests
Of the 18 fragment cases, 8 fail on master and 10 pass both before and after the change. Some of those 10 are worth keeping as precedence checks, but the table can be about half as long.
-
"unflagged tfhd ignored" does not test what its name says. The tfhd value 2 is set without the flag, so
Encodedoes not write it and the decoded tfhd holds 0. The case only tests that trex is used. -
The byte comparison after the lookup cannot fail for the mutation it guards against. Filling defaults into
trun.Samples, asAddSampleDefaultValuesdoes, leaves the encoded bytes unchanged, because fields without their flag are not written. Please remove it, or compare the samples instead. -
Build the fragment in memory instead of encoding and decoding it. The round trip is most of the test body, it is not what is being tested, and it causes point 3.
-
Keep one run order per pair, except where the order mattered. Only "explicit then inherited zero" depended on the order in the old code. "inherited zero then explicit", one of the two "equal" cases, one of the two "different" cases and "inherited then empty" add nothing.
-
Leave run-level behaviour to
TestCommonDuration. "differing explicit durations" is already covered there, and "explicit zero" is the same kind of check. -
Add a case with two fragments.
MediaSegment.CommonSampleDurationis the function the tests call, but no case has more than one fragment. One segment where the fragments reach the same duration in different ways (a tfhd default in one, explicit durations in the other), and one where they differ, would cover it.
A set like this would be enough: explicit over trex, explicit over tfhd, tfhd over trex, flagged tfhd 0 over trex, trex only, explicit then inherited zero, explicit and inherited that differ, an empty run together with a non-empty one, only empty runs, plus the two-fragment cases.
Commits
- The test commit comes before the fix and fails on its own. Pull requests are rebase-merged here, so please squash the two commits or put the fix first.
Signed-off-by: Perfloop Agent <[email protected]>
80b20cf to
25d1645
Compare
|
Reverted the run-level change and replaced the round trips with the compact in-memory cases you described. The tests now compare sample fields, keep a nonzero unflagged tfhd value, and cover agreeing and differing two-fragment segments; the changelog names the sample-less fragment error and its propagation. The contribution is squashed into one passing commit. |
tobbee
left a comment
There was a problem hiding this comment.
Thanks, all points are addressed. I ran the tests against master's code and against mutants of the fix: every case that should fail does, including the sample comparison and the two-fragment cases.
Common-duration lookup can reject uniformly timed samples when their explicit duration differs from a header default. It can also reuse a previous run's observed duration as an inherited default, accepting samples with different effective durations. Empty runs can make a valid fragment fail or report a duration without any samples.
Keep the header fallback separate from agreement between nonempty runs in
Fragment.CommonSampleDuration. Explicit sample durations take precedence; a flagged tfhd default, including zero, takes precedence over trex. Empty runs are ignored when combining runs. A fragment without samples returns an error, which propagates throughMediaSegment.CommonSampleDurationand fails the whole segment. Zero or differing effective durations still produce an error at fragment level.A public caller is DASH-IF livesim2's
RepData.readMP4Segment:s.CommonSampleDuration(r.initSeg.Moov.Mvex.Trex). It stores the duration when the call succeeds.The tests in
mp4/fragment_test.gobuild fragments in memory, then check the public segment lookup and unchanged sample fields. They cover header precedence, including a nonzero unflagged tfhd value, the explicit-then-inherited-zero order, empty runs, and agreeing or differing two-fragment segments.Go duration and fragment-interval tests pass. Scoped static analysis and changed-file validators pass.
make build,make testandmake checkwere not run for this change.Case and evidence
Made by Perfloop. Human sponsor: Tomás Senart.