diff --git a/webrtc/common_video/h264/pps_parser.cc b/webrtc/common_video/h264/pps_parser.cc index a48d27bfc7..0215549959 100644 --- a/webrtc/common_video/h264/pps_parser.cc +++ b/webrtc/common_video/h264/pps_parser.cc @@ -82,9 +82,7 @@ rtc::Optional PpsParser::ParseInternal( // entropy_coding_mode_flag: u(1) uint32_t entropy_coding_mode_flag; RETURN_EMPTY_ON_FAIL(bit_buffer->ReadBits(&entropy_coding_mode_flag, 1)); - // TODO(pbos): Implement CABAC support if spotted in the wild. - RTC_CHECK(entropy_coding_mode_flag == 0) - << "Don't know how to parse CABAC streams."; + pps.entropy_coding_mode_flag = entropy_coding_mode_flag != 0; // bottom_field_pic_order_in_frame_present_flag: u(1) uint32_t bottom_field_pic_order_in_frame_present_flag; RETURN_EMPTY_ON_FAIL( diff --git a/webrtc/common_video/h264/pps_parser.h b/webrtc/common_video/h264/pps_parser.h index 6c896fe8ea..d49654e085 100644 --- a/webrtc/common_video/h264/pps_parser.h +++ b/webrtc/common_video/h264/pps_parser.h @@ -30,6 +30,7 @@ class PpsParser { bool bottom_field_pic_order_in_frame_present_flag = false; bool weighted_pred_flag = false; + bool entropy_coding_mode_flag = false; uint32_t weighted_bipred_idc = false; uint32_t redundant_pic_cnt_present_flag = 0; int pic_init_qp_minus26 = 0; diff --git a/webrtc/common_video/h264/pps_parser_unittest.cc b/webrtc/common_video/h264/pps_parser_unittest.cc index 9a650e8be0..b9ec92ba25 100644 --- a/webrtc/common_video/h264/pps_parser_unittest.cc +++ b/webrtc/common_video/h264/pps_parser_unittest.cc @@ -45,7 +45,7 @@ void WritePps(const PpsParser::PpsState& pps, // seq_parameter_set_id: ue(v) bit_buffer.WriteExponentialGolomb(pps.sps_id); // entropy_coding_mode_flag: u(1) - bit_buffer.WriteBits(kIgnored, 1); + bit_buffer.WriteBits(pps.entropy_coding_mode_flag, 1); // bottom_field_pic_order_in_frame_present_flag: u(1) bit_buffer.WriteBits(pps.bottom_field_pic_order_in_frame_present_flag ? 1 : 0, 1); @@ -181,6 +181,8 @@ class PpsParserTest : public ::testing::Test { parsed_pps_->bottom_field_pic_order_in_frame_present_flag); EXPECT_EQ(pps.weighted_pred_flag, parsed_pps_->weighted_pred_flag); EXPECT_EQ(pps.weighted_bipred_idc, parsed_pps_->weighted_bipred_idc); + EXPECT_EQ(pps.entropy_coding_mode_flag, + parsed_pps_->entropy_coding_mode_flag); EXPECT_EQ(pps.redundant_pic_cnt_present_flag, parsed_pps_->redundant_pic_cnt_present_flag); EXPECT_EQ(pps.pic_init_qp_minus26, parsed_pps_->pic_init_qp_minus26); @@ -203,6 +205,7 @@ TEST_F(PpsParserTest, MaxPps) { generated_pps_.redundant_pic_cnt_present_flag = 1; // 1 bit value. generated_pps_.weighted_bipred_idc = (1 << 2) - 1; // 2 bit value. generated_pps_.weighted_pred_flag = true; + generated_pps_.entropy_coding_mode_flag = true; generated_pps_.id = 2; generated_pps_.sps_id = 1; RunTest(); diff --git a/webrtc/modules/video_coding/utility/h264_bitstream_parser.cc b/webrtc/modules/video_coding/utility/h264_bitstream_parser.cc index 97cd003869..92b2935a32 100644 --- a/webrtc/modules/video_coding/utility/h264_bitstream_parser.cc +++ b/webrtc/modules/video_coding/utility/h264_bitstream_parser.cc @@ -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)); diff --git a/webrtc/modules/video_coding/utility/h264_bitstream_parser_unittest.cc b/webrtc/modules/video_coding/utility/h264_bitstream_parser_unittest.cc index fbacd3b9ed..676cee631b 100644 --- a/webrtc/modules/video_coding/utility/h264_bitstream_parser_unittest.cc +++ b/webrtc/modules/video_coding/utility/h264_bitstream_parser_unittest.cc @@ -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