Only parse PPS up to PPS and SPS ids in the depacketizater.
BUG= R=danilchap@webrtc.org Review URL: https://codereview.webrtc.org/2316993002 . Cr-Commit-Position: refs/heads/master@{#14100}
This commit is contained in:
parent
d4626e5f1e
commit
126ee727a0
@ -38,6 +38,20 @@ rtc::Optional<PpsParser::PpsState> PpsParser::ParsePps(const uint8_t* data,
|
||||
return ParseInternal(&bit_buffer);
|
||||
}
|
||||
|
||||
bool PpsParser::ParsePpsIds(const uint8_t* data,
|
||||
size_t length,
|
||||
uint32_t* pps_id,
|
||||
uint32_t* sps_id) {
|
||||
RTC_DCHECK(pps_id);
|
||||
RTC_DCHECK(sps_id);
|
||||
// First, parse out rbsp, which is basically the source buffer minus emulation
|
||||
// bytes (the last byte of a 0x00 0x00 0x03 sequence). RBSP is defined in
|
||||
// section 7.3.1 of the H.264 standard.
|
||||
std::unique_ptr<rtc::Buffer> unpacked_buffer = H264::ParseRbsp(data, length);
|
||||
rtc::BitBuffer bit_buffer(unpacked_buffer->data(), unpacked_buffer->size());
|
||||
return ParsePpsIdsInternal(&bit_buffer, pps_id, sps_id);
|
||||
}
|
||||
|
||||
rtc::Optional<uint32_t> PpsParser::ParsePpsIdFromSlice(const uint8_t* data,
|
||||
size_t length) {
|
||||
std::unique_ptr<rtc::Buffer> slice_rbsp(H264::ParseRbsp(data, length));
|
||||
@ -61,12 +75,10 @@ rtc::Optional<PpsParser::PpsState> PpsParser::ParseInternal(
|
||||
rtc::BitBuffer* bit_buffer) {
|
||||
PpsState pps;
|
||||
|
||||
RETURN_EMPTY_ON_FAIL(ParsePpsIdsInternal(bit_buffer, &pps.id, &pps.sps_id));
|
||||
|
||||
uint32_t bits_tmp;
|
||||
uint32_t golomb_ignored;
|
||||
// pic_parameter_set_id: ue(v)
|
||||
RETURN_EMPTY_ON_FAIL(bit_buffer->ReadExponentialGolomb(&pps.id));
|
||||
// seq_parameter_set_id: ue(v)
|
||||
RETURN_EMPTY_ON_FAIL(bit_buffer->ReadExponentialGolomb(&pps.sps_id));
|
||||
// entropy_coding_mode_flag: u(1)
|
||||
uint32_t entropy_coding_mode_flag;
|
||||
RETURN_EMPTY_ON_FAIL(bit_buffer->ReadBits(&entropy_coding_mode_flag, 1));
|
||||
@ -166,4 +178,16 @@ rtc::Optional<PpsParser::PpsState> PpsParser::ParseInternal(
|
||||
return rtc::Optional<PpsParser::PpsState>(pps);
|
||||
}
|
||||
|
||||
bool PpsParser::ParsePpsIdsInternal(rtc::BitBuffer* bit_buffer,
|
||||
uint32_t* pps_id,
|
||||
uint32_t* sps_id) {
|
||||
// pic_parameter_set_id: ue(v)
|
||||
if (!bit_buffer->ReadExponentialGolomb(pps_id))
|
||||
return false;
|
||||
// seq_parameter_set_id: ue(v)
|
||||
if (!bit_buffer->ReadExponentialGolomb(sps_id))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -40,6 +40,11 @@ class PpsParser {
|
||||
// Unpack RBSP and parse PPS state from the supplied buffer.
|
||||
static rtc::Optional<PpsState> ParsePps(const uint8_t* data, size_t length);
|
||||
|
||||
static bool ParsePpsIds(const uint8_t* data,
|
||||
size_t length,
|
||||
uint32_t* pps_id,
|
||||
uint32_t* sps_id);
|
||||
|
||||
static rtc::Optional<uint32_t> ParsePpsIdFromSlice(const uint8_t* data,
|
||||
size_t length);
|
||||
|
||||
@ -47,6 +52,9 @@ class PpsParser {
|
||||
// Parse the PPS state, for a bit buffer where RBSP decoding has already been
|
||||
// performed.
|
||||
static rtc::Optional<PpsState> ParseInternal(rtc::BitBuffer* bit_buffer);
|
||||
static bool ParsePpsIdsInternal(rtc::BitBuffer* bit_buffer,
|
||||
uint32_t* pps_id,
|
||||
uint32_t* sps_id);
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -489,11 +489,16 @@ bool RtpDepacketizerH264::ProcessStapAOrSingleNalu(
|
||||
break;
|
||||
}
|
||||
case H264::NaluType::kPps: {
|
||||
rtc::Optional<PpsParser::PpsState> pps = PpsParser::ParsePps(
|
||||
&payload_data[start_offset], end_offset - start_offset);
|
||||
if (pps) {
|
||||
nalu.sps_id = pps->sps_id;
|
||||
nalu.pps_id = pps->id;
|
||||
uint32_t pps_id;
|
||||
uint32_t sps_id;
|
||||
if (PpsParser::ParsePpsIds(&payload_data[start_offset],
|
||||
end_offset - start_offset, &pps_id,
|
||||
&sps_id)) {
|
||||
nalu.pps_id = pps_id;
|
||||
nalu.sps_id = sps_id;
|
||||
} else {
|
||||
LOG(LS_WARNING)
|
||||
<< "Failed to parse PPS id and SPS id from PPS slice.";
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user