Chromium Code Reviews| Index: webrtc/common_video/h264/h264_common.cc |
| diff --git a/webrtc/common_video/h264/h264_common.cc b/webrtc/common_video/h264/h264_common.cc |
| index a9cc6a25e62882e8619ed627aeb9cefee67e248f..4af434988dd784c54d982685942c37c306bb0a49 100644 |
| --- a/webrtc/common_video/h264/h264_common.cc |
| +++ b/webrtc/common_video/h264/h264_common.cc |
| @@ -61,25 +61,27 @@ NaluType ParseNaluType(uint8_t data) { |
| } |
| std::unique_ptr<rtc::Buffer> ParseRbsp(const uint8_t* data, size_t length) { |
| - std::unique_ptr<rtc::Buffer> rbsp_buffer(new rtc::Buffer(0, length)); |
| - const char* sps_bytes = reinterpret_cast<const char*>(data); |
| - for (size_t i = 0; i < length;) { |
| + std::unique_ptr<uint8_t[]> out(new uint8_t[length]); |
|
magjed_webrtc
2017/03/03 13:14:14
I think it would be better with an std::vector<uin
|
| + |
| + size_t j, i; |
| + for (i = j = 0; i < length;) { |
| + uint8_t* dst = out.get(); |
| // Be careful about over/underflow here. byte_length_ - 3 can underflow, and |
| // i + 3 can overflow, but byte_length_ - i can't, because i < byte_length_ |
| // above, and that expression will produce the number of bytes left in |
| // the stream including the byte at i. |
| - if (length - i >= 3 && data[i] == 0 && data[i + 1] == 0 && |
| - data[i + 2] == 3) { |
| - // Two rbsp bytes + the emulation byte. |
| - rbsp_buffer->AppendData(sps_bytes + i, 2); |
| - i += 3; |
| + if (length - i >= 3 && !data[i] && !data[i + 1] && data[i + 2] == 3) { |
| + // Two rbsp bytes. |
| + dst[j++] = data[i++]; |
| + dst[j++] = data[i++]; |
| + // Skip the emulation byte. |
| + i++; |
| } else { |
| // Single rbsp byte. |
| - rbsp_buffer->AppendData(sps_bytes[i]); |
| - ++i; |
| + dst[j++] = data[i++]; |
| } |
| } |
| - return rbsp_buffer; |
| + return std::unique_ptr<rtc::Buffer>(new rtc::Buffer(out.get(), j)); |
| } |
| void WriteRbsp(const uint8_t* bytes, size_t length, rtc::Buffer* destination) { |