Bit less string copying in H.264 code.

This commit is contained in:
Scott Lamb 2016-01-09 21:41:12 -08:00
parent 15b1ee54a6
commit 1ca6e2a665

View File

@ -48,8 +48,8 @@ const int kNalUnitPicParameterSet = 8;
// Parse sequence parameter set and picture parameter set from ffmpeg's // Parse sequence parameter set and picture parameter set from ffmpeg's
// "extra_data". // "extra_data".
bool ParseExtraData(re2::StringPiece extra_data, std::string *sps, bool ParseExtraData(re2::StringPiece extra_data, re2::StringPiece *sps,
std::string *pps, std::string *error_message) { re2::StringPiece *pps, std::string *error_message) {
bool ok = true; bool ok = true;
internal::NalUnitFunction fn = [&ok, sps, pps, internal::NalUnitFunction fn = [&ok, sps, pps,
error_message](re2::StringPiece nal_unit) { error_message](re2::StringPiece nal_unit) {
@ -57,10 +57,10 @@ bool ParseExtraData(re2::StringPiece extra_data, std::string *sps,
uint8_t nal_type = nal_unit[0] & 0x1F; // bottom 5 bits of first byte. uint8_t nal_type = nal_unit[0] & 0x1F; // bottom 5 bits of first byte.
switch (nal_type) { switch (nal_type) {
case kNalUnitSeqParameterSet: case kNalUnitSeqParameterSet:
*sps = nal_unit.as_string(); *sps = nal_unit;
break; break;
case kNalUnitPicParameterSet: case kNalUnitPicParameterSet:
*pps = nal_unit.as_string(); *pps = nal_unit;
break; break;
default: default:
*error_message = *error_message =
@ -127,8 +127,8 @@ bool DecodeH264AnnexB(re2::StringPiece data, NalUnitFunction process_nal_unit,
bool GetH264SampleEntry(re2::StringPiece extra_data, uint16_t width, bool GetH264SampleEntry(re2::StringPiece extra_data, uint16_t width,
uint16_t height, std::string *out, uint16_t height, std::string *out,
std::string *error_message) { std::string *error_message) {
std::string sps; re2::StringPiece sps;
std::string pps; re2::StringPiece pps;
if (!ParseExtraData(extra_data, &sps, &pps, error_message)) { if (!ParseExtraData(extra_data, &sps, &pps, error_message)) {
return false; return false;
} }
@ -138,6 +138,9 @@ bool GetH264SampleEntry(re2::StringPiece extra_data, uint16_t width,
uint32_t avcc_len = 19 + sps.size() + pps.size(); uint32_t avcc_len = 19 + sps.size() + pps.size();
uint32_t avc1_len = 86 + avcc_len; uint32_t avc1_len = 86 + avcc_len;
out->clear();
out->reserve(avcc_len);
// This is a concatenation of the following boxes/classes. // This is a concatenation of the following boxes/classes.
// SampleEntry, ISO/IEC 14496-10 section 8.5.2. // SampleEntry, ISO/IEC 14496-10 section 8.5.2.
uint32_t avc1_len_pos = out->size(); uint32_t avc1_len_pos = out->size();