From 1ca6e2a665a11b7072cfc971d59b298832409ea0 Mon Sep 17 00:00:00 2001 From: Scott Lamb Date: Sat, 9 Jan 2016 21:41:12 -0800 Subject: [PATCH] Bit less string copying in H.264 code. --- src/h264.cc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/h264.cc b/src/h264.cc index d51f530..c5be0ed 100644 --- a/src/h264.cc +++ b/src/h264.cc @@ -48,8 +48,8 @@ const int kNalUnitPicParameterSet = 8; // Parse sequence parameter set and picture parameter set from ffmpeg's // "extra_data". -bool ParseExtraData(re2::StringPiece extra_data, std::string *sps, - std::string *pps, std::string *error_message) { +bool ParseExtraData(re2::StringPiece extra_data, re2::StringPiece *sps, + re2::StringPiece *pps, std::string *error_message) { bool ok = true; internal::NalUnitFunction fn = [&ok, sps, pps, 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. switch (nal_type) { case kNalUnitSeqParameterSet: - *sps = nal_unit.as_string(); + *sps = nal_unit; break; case kNalUnitPicParameterSet: - *pps = nal_unit.as_string(); + *pps = nal_unit; break; default: *error_message = @@ -127,8 +127,8 @@ bool DecodeH264AnnexB(re2::StringPiece data, NalUnitFunction process_nal_unit, bool GetH264SampleEntry(re2::StringPiece extra_data, uint16_t width, uint16_t height, std::string *out, std::string *error_message) { - std::string sps; - std::string pps; + re2::StringPiece sps; + re2::StringPiece pps; if (!ParseExtraData(extra_data, &sps, &pps, error_message)) { 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 avc1_len = 86 + avcc_len; + out->clear(); + out->reserve(avcc_len); + // This is a concatenation of the following boxes/classes. // SampleEntry, ISO/IEC 14496-10 section 8.5.2. uint32_t avc1_len_pos = out->size();