Support for parsing CABAC coded bitstreams

Remove check on entropy_coding_mode_flag in PPS parser.
Parse entropy_coding_mode_flag from PPS and store it in the parser struct. Parse out extra data in NALU slices in case of entropy_coding_mode to avoid reporting incorrect QP.

BUG=webrtc:6338

Review-Url: https://codereview.webrtc.org/2373393002
Cr-Commit-Position: refs/heads/master@{#14522}
This commit is contained in:
kthelgason
2016-10-05 02:16:22 -07:00
committed by Commit bot
parent 1f5a368978
commit d020f3fea0
5 changed files with 37 additions and 7 deletions

View File

@ -240,9 +240,11 @@ bool H264BitstreamParser::ParseNonParameterSetNalu(const uint8_t* source,
}
}
}
// cabac not supported: entropy_coding_mode_flag == 0 asserted above.
// if (entropy_coding_mode_flag && slice_type != I && slice_type != SI)
// cabac_init_idc
if (pps_->entropy_coding_mode_flag &&
slice_type != H264::SliceType::kI && slice_type != H264::SliceType::kSi) {
// cabac_init_idc: ue(v)
RETURN_FALSE_ON_FAIL(slice_reader.ReadExponentialGolomb(&golomb_tmp));
}
int32_t last_slice_qp_delta;
RETURN_FALSE_ON_FAIL(
slice_reader.ReadSignedExponentialGolomb(&last_slice_qp_delta));

View File

@ -32,6 +32,18 @@ uint8_t kH264BitstreamNextImageSliceChunk[] = {
0x00, 0x00, 0x00, 0x01, 0x41, 0xe2, 0x01, 0x16, 0x0e, 0x3e, 0x2b, 0x86,
};
uint8_t kH264BitstreamChunkCabac[] = {
0x00, 0x00, 0x00, 0x01, 0x27, 0x64, 0x00, 0x0d, 0xac, 0x52, 0x30, 0x50,
0x7e, 0xc0, 0x5a, 0x81, 0x01, 0x01, 0x18, 0x56, 0xbd, 0xef, 0x80, 0x80,
0x00, 0x00, 0x00, 0x01, 0x28, 0xfe, 0x09, 0x8b,
};
// Contains enough of the image slice to contain slice QP.
uint8_t kH264BitstreamNextImageSliceChunkCabac[] = {
0x00, 0x00, 0x00, 0x01, 0x21, 0xe1, 0x05, 0x11, 0x3f, 0x9a, 0xae, 0x46,
0x70, 0xbf, 0xc1, 0x4a, 0x16, 0x8f, 0x51, 0xf4, 0xca, 0xfb, 0xa3, 0x65,
};
TEST(H264BitstreamParserTest, ReportsNoQpWithoutParsedSlices) {
H264BitstreamParser h264_parser;
int qp;
@ -59,4 +71,18 @@ TEST(H264BitstreamParserTest, ReportsLastSliceQpForImageSlices) {
EXPECT_EQ(37, qp);
}
TEST(H264BitstreamParserTest, ReportsLastSliceQpForCABACImageSlices) {
H264BitstreamParser h264_parser;
h264_parser.ParseBitstream(kH264BitstreamChunkCabac,
sizeof(kH264BitstreamChunkCabac));
int qp;
EXPECT_FALSE(h264_parser.GetLastSliceQp(&qp));
// Parse an additional image slice.
h264_parser.ParseBitstream(kH264BitstreamNextImageSliceChunkCabac,
sizeof(kH264BitstreamNextImageSliceChunkCabac));
ASSERT_TRUE(h264_parser.GetLastSliceQp(&qp));
EXPECT_EQ(24, qp);
}
} // namespace webrtc