OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 bool H264SpsParser::Parse() { | 28 bool H264SpsParser::Parse() { |
29 // General note: this is based off the 02/2014 version of the H.264 standard. | 29 // General note: this is based off the 02/2014 version of the H.264 standard. |
30 // You can find it on this page: | 30 // You can find it on this page: |
31 // http://www.itu.int/rec/T-REC-H.264 | 31 // http://www.itu.int/rec/T-REC-H.264 |
32 | 32 |
33 const char* sps_bytes = reinterpret_cast<const char*>(sps_); | 33 const char* sps_bytes = reinterpret_cast<const char*>(sps_); |
34 // First, parse out rbsp, which is basically the source buffer minus emulation | 34 // First, parse out rbsp, which is basically the source buffer minus emulation |
35 // bytes (the last byte of a 0x00 0x00 0x03 sequence). RBSP is defined in | 35 // bytes (the last byte of a 0x00 0x00 0x03 sequence). RBSP is defined in |
36 // section 7.3.1 of the H.264 standard. | 36 // section 7.3.1 of the H.264 standard. |
37 rtc::ByteBuffer rbsp_buffer; | 37 rtc::ByteBufferWriter rbsp_buffer; |
38 for (size_t i = 0; i < byte_length_;) { | 38 for (size_t i = 0; i < byte_length_;) { |
39 // Be careful about over/underflow here. byte_length_ - 3 can underflow, and | 39 // Be careful about over/underflow here. byte_length_ - 3 can underflow, and |
40 // i + 3 can overflow, but byte_length_ - i can't, because i < byte_length_ | 40 // i + 3 can overflow, but byte_length_ - i can't, because i < byte_length_ |
41 // above, and that expression will produce the number of bytes left in | 41 // above, and that expression will produce the number of bytes left in |
42 // the stream including the byte at i. | 42 // the stream including the byte at i. |
43 if (byte_length_ - i >= 3 && sps_[i] == 0 && sps_[i + 1] == 0 && | 43 if (byte_length_ - i >= 3 && sps_[i] == 0 && sps_[i + 1] == 0 && |
44 sps_[i + 2] == 3) { | 44 sps_[i + 2] == 3) { |
45 // Two rbsp bytes + the emulation byte. | 45 // Two rbsp bytes + the emulation byte. |
46 rbsp_buffer.WriteBytes(sps_bytes + i, 2); | 46 rbsp_buffer.WriteBytes(sps_bytes + i, 2); |
47 i += 3; | 47 i += 3; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 // Subtract the crop for each dimension. | 223 // Subtract the crop for each dimension. |
224 width -= (frame_crop_left_offset + frame_crop_right_offset); | 224 width -= (frame_crop_left_offset + frame_crop_right_offset); |
225 height -= (frame_crop_top_offset + frame_crop_bottom_offset); | 225 height -= (frame_crop_top_offset + frame_crop_bottom_offset); |
226 | 226 |
227 width_ = width; | 227 width_ = width; |
228 height_ = height; | 228 height_ = height; |
229 return true; | 229 return true; |
230 } | 230 } |
231 | 231 |
232 } // namespace webrtc | 232 } // namespace webrtc |
OLD | NEW |