Fix a bug where ISVCDecoder::DecodeFrameNoDelay()
could fail when decoding an H.264 stream encoded by the Apple HWA encoder.
#3787
+1
−1
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.
Let me report a decoding issue and propose a patch to fix it.
I recorded H.264 streams published by Safari and transmitted through a WebRTC SFU server.
When I attempted to decode these streams using
openh264
(commit: 3668daf), the methodISVCDecoder::DecodeFrameNoDelay()
failed with the error code-4
for some of the streams, whereas popular players likeffplay
were able to decode the streams without any errors.The following file contains an H.264 elementary stream of a failed attempt.
input.h264.gz
While I cannot provide the exact steps to reproduce the issue, it has been confirmed that such a stream can be generated by Safari on macOS 15.0 and iPad 17.6.1.
After inserting additional debug prints and examining the
openh264
source code, it was discovered that the error originated from the following code:openh264/codec/decoder/core/src/decoder_core.cpp
Lines 547 to 550 in 3668daf
In the attached .h264 file, the
iMaxLongTermFrameIdx
andpSps->uiLog2MaxFrameNum
had values of13
and12
, respectively. Therefore, the above condition was met, which resulted in the error being returned.However, the H.264 specification says as follows:
Although I am not well-versed in the H.264 specification, it seems that
pSps->iNumRefFrames
should be used in the code above instead ofpSps->uiLog2MaxFrameNum
.In the attached file, the value of
pSps->iNumRefFrames
was15
. After modifying the code to usepSps->iNumRefFrames
(i.e., the code in this PR branch), the decoding process succeeded without any errors.