h264: Fix AnnexB parser when NALUs end with a 0 byte #159
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In mediamtx, when using UDP/MPEGTS sources, we were having trouble with WebRTC playback with certain IP cameras such as Wisenet XND-6010.
The playback wasn't starting, due to seemingly missing Picture Parameter Sets. But The Picture Parameter Set was actually there, but mediamtx wasn't able to parse the PPS. The AnnexB parser wasn't able to separate PPS from the SPS, because the SPS NALU was ending with a zero byte. The SPS was ending with a
0
byte, and the NALU separator was0001
.This is valid according to the AnnexB spec, but the parser assumes a NALU cannot end with a 0 byte due to the
zeroCount == 2 || zeroCount == 3
condition. So I made an attempt to rewrite the parser and also correct a test case under "2 or 3 zeros". I also added more test cases.Using this branch of mediacommon in a mediamtx build, we're actually able to watch a stream from that camera over WebRTC and UDP/MPEGTS.