Skip to content

fix(hevc): return final parameter sets and isolate appends - #686

Merged
tobbee merged 4 commits into
Eyevinn:masterfrom
perfloop-oss:perfloop-pr-open-jjgn99rrgp
Nov 3, 2026
Merged

tobbee merged 4 commits into
Eyevinn:masterfrom
perfloop-oss:perfloop-pr-open-jjgn99rrgp

Conversation

@perfloop-agent

Copy link
Copy Markdown
Contributor

HEVC parameter-set extraction now returns a complete final unit when an Annex-B stream ends before video. Appending to a returned parameter set no longer overwrites other returned sets.

TestGetParameterSetsFromByteStreamEOF fails without this change and passes with it.

TestGetParameterSetsFromByteStreamAppendIsolation fails without this change and passes with it.

What changed

  • Share type selection, trailing-zero trimming and size accounting between detected boundaries and EOF in hevc/annexb.go.
  • Ignore non-parameter-set units before trimming, including the video NAL where scanning stops.
  • Limit each returned slice's capacity to its length, keeping the shared copy buffer while making append allocate separate storage.

Start-code recognition, per-type order and input-independent copied outputs are unchanged.

Tests

TestGetParameterSetsFromByteStreamEOF uses complete VPS, SPS and PPS units from the existing hevc/testdata/blackframe.265 fixture, with both start-code lengths and padded or unpadded endings. It checks exact output bytes and counts, then modifies the input to check copy ownership.

TestGetParameterSetsFromByteStreamAppendIsolation appends to the first returned VPS, SPS or PPS and checks that every other returned set remains unchanged.

TestGetParameterSetsFromByteStream covers detected boundaries, repeated sets, first-video exclusion and empty or incomplete-header input. These tests live in hevc/annexb_test.go.

3 recorded checks pass with this change.

  • HEVC tests
  • HEVC lint
  • Pre-commit formatting, whitespace and spelling

This does not add HEVC syntax validation. The frequency of affected inputs and downstream failures remains unmeasured; no performance improvement is claimed.

Case and evidence


Generated by Perfloop. Human sponsor: Tomás Senart.

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]>
Signed-off-by: Perfloop Agent <[email protected]>
Signed-off-by: Tomás Senart <[email protected]>
@tsenart

tsenart commented Nov 1, 2026

Copy link
Copy Markdown

Hi, I'm Tomás, I build Perfloop. I approved this contribution and will handle review feedback here.

We found this bug while developing Perfloop's auto-formalization capabilities. We've had Go changes merged in Dolt, Prometheus, Skipper, parquet-go, RoaringBitmap, and more.

If you'd like anything in this patch changed, just let me know and I'll update it.

@tobbee

tobbee commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

@tsenart. Thanks. Looks fine.

@tobbee
tobbee merged commit 89ecfb2 into Eyevinn:master Nov 3, 2026
10 checks passed
tobbee added a commit that referenced this pull request Nov 3, 2026
…yte stream

GetParameterSetsFromByteStream scanned for start codes with i < n-4, so a start code followed by a single byte at the very end was not found. Since the final NAL unit is now returned (#686), the parameter set before it swallowed those bytes: 00 00 01 40 01 09 00 00 01 26 gave the VPS 40 01 09 00 00 01 26 instead of 40 01 09. ExtractNalusOfTypeFromByteStream already scans with i < n-3.

With the wider scan, a final NAL unit can be a single byte. HEVC NAL unit headers are two bytes, so such a unit is skipped rather than returned as a one-byte parameter set; this keeps the existing truncated-header test passing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Claude-Session: https://claude.ai/code/session_01EagxH8eFdCXEeeD3Pb6SyT
tobbee added a commit that referenced this pull request Nov 3, 2026
avc.GetParameterSetsFromByteStream had the two bugs that #686 fixed for HEVC. The NAL unit still open when the data ended was never handled, so a stream that ended with an SPS or PPS and no video lost that set. The returned slices kept the spare capacity of the shared copy buffer, so appending to sps[0] overwrote the first bytes of the next set, e.g. turning the PPS 68 ce 22 into ff ce 22.

Use the same structure as hevc: one addParameterSet closure for both a detected start code and the end of the data, which skips non-parameter-set units before trimming, and full slice expressions that cap each returned set at its length. The scan also uses i < n-3, so a start code followed by one byte at the end is found, as in ExtractNalusOfTypeFromByteStream. An AVC NAL unit header is one byte, so no header-length check is needed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Claude-Session: https://claude.ai/code/session_01EagxH8eFdCXEeeD3Pb6SyT
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.

3 participants