Skip to content

Fix nalu parsing for 3-byte & 4-byte start seqs#301

Merged
Sean-Der merged 1 commit intopion:masterfrom
rileym-arcules:rileym/nalu-parsing-fix
Mar 11, 2025
Merged

Fix nalu parsing for 3-byte & 4-byte start seqs#301
Sean-Der merged 1 commit intopion:masterfrom
rileym-arcules:rileym/nalu-parsing-fix

Conversation

@rileym-arcules
Copy link
Copy Markdown
Contributor

@rileym-arcules rileym-arcules commented Mar 10, 2025

Description

There is an issue in the current emitNalu function where the implementation can skip over 3-byte start sequences.

The emitNalu function was changed in commit bfe92b9 which introduced this regression: bfe92b9#diff-5eca440e933baa4c5491dcd9ccc7c1f4d807994e6c5b54c304228c34fcc3c963L40

From analysis of the current emitNalu function,

func emitNalus(nals []byte, emit func([]byte)) {
start := 0
length := len(nals)
for start < length {
end := bytes.Index(nals[start:], annexbNALUStartCode)
offset := 4
if end == -1 {
end = bytes.Index(nals[start:], naluStartCode)
offset = 3
}
if end == -1 {
emit(nals[start:])
break
}
emit(nals[start : start+end])
// next NAL start position
start += end + offset
}
}

one can observe that NALUs with 3-byte start sequences may be skipped over if it is the first NALU, or if it is between two NALUs with 4-byte start sequences (in this case: at L52 end != -1)

This PR aims to resolve this issue by searching for 3-byte start sequences and accounting for 4-byte sequences afterward.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.76%. Comparing base (ee5524b) to head (5662773).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #301      +/-   ##
==========================================
+ Coverage   86.69%   86.76%   +0.07%     
==========================================
  Files          26       26              
  Lines        3043     3061      +18     
==========================================
+ Hits         2638     2656      +18     
  Misses        348      348              
  Partials       57       57              
Flag Coverage Δ
go 86.76% <100.00%> (+0.07%) ⬆️
wasm 86.21% <100.00%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Sean-Der Sean-Der merged commit 9bbc0f6 into pion:master Mar 11, 2025
14 checks passed
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.

2 participants