-
Notifications
You must be signed in to change notification settings - Fork 55
[BUG] Wrong value of max_sub_layers_minus1 in HEVC SPS Parser #270
Description
Logging
sps: 42 01 01 01 60 00 00 00 00 00 00 00 00 00 96 a0 03 c0 80 10 e5 8d ae 49 32 6b 96 70 08 00 00 1f 48 00 03 0e 08 40 b1 b6 30 00
pos: 4, sps_video_parameter_set_id = 4
pos: 7, sps_max_sub_layers_minus1 = 1
Describe the bug
When I refer to the code parseH265Sps, I found the extracted value of max_sub_layers_minus1 should be 0 instead of 1. But the later parameters of width and height are correct.
The parameter was incorrectly read from NAL header which is "0x42 0x01".
Compare to the the parser of H264, I think it's missing to read the nalu header like CHK_STATUS(bitReaderReadBits(&bitReader, 16, &read));
amazon-kinesis-video-streams-pic/src/mkvgen/src/SpsParser.c
Lines 218 to 223 in c98c2a2
| // Create a bit reader on top of the SPS | |
| CHK_STATUS(bitReaderReset(&bitReader, pSps, spsSize * 8)); | |
| // Read the SPS Nalu | |
| CHK_STATUS(bitReaderReadBits(&bitReader, 8, &read)); | |
| CHK(((read & 0x80) == 0) && ((read & 0x60) != 0) && ((read & 0x1f) == SPS_NALU_TYPE), STATUS_MKV_INVALID_H264_H265_SPS_NALU); |
Since the wrong value of sps_max_sub_layers_minus1, it read more 2 bytes of the nalu, leading to getting parameters width and height in the correct position.
amazon-kinesis-video-streams-pic/src/mkvgen/src/SpsParser.c
Lines 657 to 673 in c98c2a2
| for (i = 0; i < pSpsInfo->max_sub_layers_minus1; i++) { | |
| // Read the sub_layer_profile_present_flag[i] | |
| CHK_STATUS(bitReaderReadBits(pBitReader, 1, &read)); | |
| subLayerProfilePresentFlags[i] = (read != 0); | |
| // Read the sub_layer_level_present_flag[i] | |
| CHK_STATUS(bitReaderReadBits(pBitReader, 1, &read)); | |
| subLayerLevelPresentFlags[i] = (read != 0); | |
| } | |
| if (pSpsInfo->max_sub_layers_minus1 > 0) { | |
| for (i = pSpsInfo->max_sub_layers_minus1; i < 8; i++) { | |
| // Read the reserved_zero_2bits[i] | |
| CHK_STATUS(bitReaderReadBits(pBitReader, 2, &read)); | |
| // CHK(0 == read, STATUS_MKV_INVALID_HEVC_SPS_RESERVED); | |
| } | |
| } |
SDK version number
1.2.0

