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:
@ -82,9 +82,7 @@ rtc::Optional<PpsParser::PpsState> PpsParser::ParseInternal(
|
|||||||
// entropy_coding_mode_flag: u(1)
|
// entropy_coding_mode_flag: u(1)
|
||||||
uint32_t entropy_coding_mode_flag;
|
uint32_t entropy_coding_mode_flag;
|
||||||
RETURN_EMPTY_ON_FAIL(bit_buffer->ReadBits(&entropy_coding_mode_flag, 1));
|
RETURN_EMPTY_ON_FAIL(bit_buffer->ReadBits(&entropy_coding_mode_flag, 1));
|
||||||
// TODO(pbos): Implement CABAC support if spotted in the wild.
|
pps.entropy_coding_mode_flag = entropy_coding_mode_flag != 0;
|
||||||
RTC_CHECK(entropy_coding_mode_flag == 0)
|
|
||||||
<< "Don't know how to parse CABAC streams.";
|
|
||||||
// bottom_field_pic_order_in_frame_present_flag: u(1)
|
// bottom_field_pic_order_in_frame_present_flag: u(1)
|
||||||
uint32_t bottom_field_pic_order_in_frame_present_flag;
|
uint32_t bottom_field_pic_order_in_frame_present_flag;
|
||||||
RETURN_EMPTY_ON_FAIL(
|
RETURN_EMPTY_ON_FAIL(
|
||||||
|
|||||||
@ -30,6 +30,7 @@ class PpsParser {
|
|||||||
|
|
||||||
bool bottom_field_pic_order_in_frame_present_flag = false;
|
bool bottom_field_pic_order_in_frame_present_flag = false;
|
||||||
bool weighted_pred_flag = false;
|
bool weighted_pred_flag = false;
|
||||||
|
bool entropy_coding_mode_flag = false;
|
||||||
uint32_t weighted_bipred_idc = false;
|
uint32_t weighted_bipred_idc = false;
|
||||||
uint32_t redundant_pic_cnt_present_flag = 0;
|
uint32_t redundant_pic_cnt_present_flag = 0;
|
||||||
int pic_init_qp_minus26 = 0;
|
int pic_init_qp_minus26 = 0;
|
||||||
|
|||||||
@ -45,7 +45,7 @@ void WritePps(const PpsParser::PpsState& pps,
|
|||||||
// seq_parameter_set_id: ue(v)
|
// seq_parameter_set_id: ue(v)
|
||||||
bit_buffer.WriteExponentialGolomb(pps.sps_id);
|
bit_buffer.WriteExponentialGolomb(pps.sps_id);
|
||||||
// entropy_coding_mode_flag: u(1)
|
// 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)
|
// bottom_field_pic_order_in_frame_present_flag: u(1)
|
||||||
bit_buffer.WriteBits(pps.bottom_field_pic_order_in_frame_present_flag ? 1 : 0,
|
bit_buffer.WriteBits(pps.bottom_field_pic_order_in_frame_present_flag ? 1 : 0,
|
||||||
1);
|
1);
|
||||||
@ -181,6 +181,8 @@ class PpsParserTest : public ::testing::Test {
|
|||||||
parsed_pps_->bottom_field_pic_order_in_frame_present_flag);
|
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_pred_flag, parsed_pps_->weighted_pred_flag);
|
||||||
EXPECT_EQ(pps.weighted_bipred_idc, parsed_pps_->weighted_bipred_idc);
|
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,
|
EXPECT_EQ(pps.redundant_pic_cnt_present_flag,
|
||||||
parsed_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);
|
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_.redundant_pic_cnt_present_flag = 1; // 1 bit value.
|
||||||
generated_pps_.weighted_bipred_idc = (1 << 2) - 1; // 2 bit value.
|
generated_pps_.weighted_bipred_idc = (1 << 2) - 1; // 2 bit value.
|
||||||
generated_pps_.weighted_pred_flag = true;
|
generated_pps_.weighted_pred_flag = true;
|
||||||
|
generated_pps_.entropy_coding_mode_flag = true;
|
||||||
generated_pps_.id = 2;
|
generated_pps_.id = 2;
|
||||||
generated_pps_.sps_id = 1;
|
generated_pps_.sps_id = 1;
|
||||||
RunTest();
|
RunTest();
|
||||||
|
|||||||
@ -240,9 +240,11 @@ bool H264BitstreamParser::ParseNonParameterSetNalu(const uint8_t* source,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// cabac not supported: entropy_coding_mode_flag == 0 asserted above.
|
if (pps_->entropy_coding_mode_flag &&
|
||||||
// if (entropy_coding_mode_flag && slice_type != I && slice_type != SI)
|
slice_type != H264::SliceType::kI && slice_type != H264::SliceType::kSi) {
|
||||||
// cabac_init_idc
|
// cabac_init_idc: ue(v)
|
||||||
|
RETURN_FALSE_ON_FAIL(slice_reader.ReadExponentialGolomb(&golomb_tmp));
|
||||||
|
}
|
||||||
int32_t last_slice_qp_delta;
|
int32_t last_slice_qp_delta;
|
||||||
RETURN_FALSE_ON_FAIL(
|
RETURN_FALSE_ON_FAIL(
|
||||||
slice_reader.ReadSignedExponentialGolomb(&last_slice_qp_delta));
|
slice_reader.ReadSignedExponentialGolomb(&last_slice_qp_delta));
|
||||||
|
|||||||
@ -32,6 +32,18 @@ uint8_t kH264BitstreamNextImageSliceChunk[] = {
|
|||||||
0x00, 0x00, 0x00, 0x01, 0x41, 0xe2, 0x01, 0x16, 0x0e, 0x3e, 0x2b, 0x86,
|
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) {
|
TEST(H264BitstreamParserTest, ReportsNoQpWithoutParsedSlices) {
|
||||||
H264BitstreamParser h264_parser;
|
H264BitstreamParser h264_parser;
|
||||||
int qp;
|
int qp;
|
||||||
@ -59,4 +71,18 @@ TEST(H264BitstreamParserTest, ReportsLastSliceQpForImageSlices) {
|
|||||||
EXPECT_EQ(37, qp);
|
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
|
} // namespace webrtc
|
||||||
|
|||||||
Reference in New Issue
Block a user