Repository navigation
fix(hevc): derive inter-predicted short-term reference picture sets - #705
Conversation
Signed-off-by: Perfloop Agent <[email protected]> Signed-off-by: Tomás Senart <[email protected]>
Signed-off-by: Perfloop Agent <[email protected]> Signed-off-by: Tomás Senart <[email protected]>
Signed-off-by: Perfloop Agent <[email protected]> Signed-off-by: Tomás Senart <[email protected]>
|
@perfloop-agent Why is this an issue that is worth fixing? This is not a proper HEVC parser. What is your use case? |
|
A real producer: Intel Quick Sync (hevc_qsv/oneVPL) writes inter-RPS prediction in the SPS and in slice headers and sets lists_modification_present_flag=1. MediaMTX hit the missing derivation with QSV streams (bluenviron/mediamtx#3285, fixed in bluenviron/mediacommon#128). On those QSV headers, master derives empty used-picture lists and skips the list-modification syntax; with this PR both are correct. In the QSV samples we checked, header size and cbcs clear ranges did not change, so we have not shown a cbcs failure. If correct RPS state is out of scope for mp4ff, please close the PR. |
|
@tsenart Thanks for the context about where such streams appear. I think it is worth adding this. |
|
@tsenart Thanks for this fix, and for the context about the Quick Sync streams. I checked the derivation against the JCT-VC conformance streams and FFmpeg's
The first commit adds tests that fail until the fix commit, so I'm squashing the PR into a single commit on master. |
Derive inter-predicted HEVC short-term reference-picture lists and used flags instead of keeping just their count. On master, conformance slice headers exercised by
hevc/rps_test.gofail to parse or return wrong reference picture sets and reference-list entries. The corrected picture state propagates through SPS prediction chains and slice-local prediction, allowing reference-list modifications and subsequent header fields to consume the right bits.Reach: streams that predict a short-term reference picture set from another set, as HM-style encoders do (x265 does not). The reference-list-modification header-size fix, and so its cbcs protection-range correction, also requires PPS
lists_modification_present_flag.Derivation shares backing arrays across predicted sets within an SPS, with capped sub-slices; a slice-local prediction uses its own pair. A new pair is allocated if later sets outgrow the reserve. Fixed per-set work (copying the reference set, clearing scratch arrays and the selection passes) also runs for empty predicted sets, without extra allocations. Slice parsing additionally reads reference-list modifications enabled by the corrected picture count.
Paired parsing-time medians:
SPS allocations rise 9→11 (1808→2000 B/op); slice allocations rise 2→6 (400→480 B/op): two allocations for the derived set, and two for the reference-list modification entries that master skipped. Correct picture lists and header boundaries outweigh these costs. Empty-SPS timing is inconclusive, with paired improvement bounds of −192.4 to 54.8 ns/op.
Slice parsing now rejects a hand-built SPS with inconsistent reference sets.
Regression coverage and validation
The two tests in
hevc/rps_test.gocheck conformance header excerpts and prediction chains, both shift signs, retained-but-unused pictures, zero cancellation and empty selection. They check picture state, reference-list modifications, QP deltas and aligned header sizes; fixtures omit slice payloads. No benchmark is added to the contribution.The public unsigned-distance representation and intra-coded RPS parsing are unchanged. Unrepresentable derived distances return an error.
Go tests for HEVC SPS/slice parsing and HEVC cbcs protection ranges pass.
make build,make testandmake checkpass.Case and evidence
Made by Perfloop. Human sponsor: Tomás Senart.