Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(573)

Side by Side Diff: webrtc/common_video/h264/h264_common.cc

Issue 2356793002: Add support for 3-byte headers in VideoToolbox NALU parser. (Closed)
Patch Set: rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_nalu.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 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
11 #include "webrtc/common_video/h264/h264_common.h" 11 #include "webrtc/common_video/h264/h264_common.h"
12 12
13 namespace webrtc { 13 namespace webrtc {
14 namespace H264 { 14 namespace H264 {
15 15
16 const uint8_t kNaluTypeMask = 0x1F; 16 const uint8_t kNaluTypeMask = 0x1F;
17 17
18 std::vector<NaluIndex> FindNaluIndices(const uint8_t* buffer, 18 std::vector<NaluIndex> FindNaluIndices(const uint8_t* buffer,
19 size_t buffer_size) { 19 size_t buffer_size) {
20 // This is sorta like Boyer-Moore, but with only the first optimization step: 20 // This is sorta like Boyer-Moore, but with only the first optimization step:
21 // given a 3-byte sequence we're looking at, if the 3rd byte isn't 1 or 0, 21 // given a 3-byte sequence we're looking at, if the 3rd byte isn't 1 or 0,
22 // skip ahead to the next 3-byte sequence. 0s and 1s are relatively rare, so 22 // skip ahead to the next 3-byte sequence. 0s and 1s are relatively rare, so
23 // this will skip the majority of reads/checks. 23 // this will skip the majority of reads/checks.
24 RTC_CHECK_GE(buffer_size, kNaluShortStartSequenceSize);
25 std::vector<NaluIndex> sequences; 24 std::vector<NaluIndex> sequences;
25 if (buffer_size < kNaluShortStartSequenceSize)
26 return sequences;
26 const size_t end = buffer_size - kNaluShortStartSequenceSize; 27 const size_t end = buffer_size - kNaluShortStartSequenceSize;
27 for (size_t i = 0; i < end;) { 28 for (size_t i = 0; i < end;) {
28 if (buffer[i + 2] > 1) { 29 if (buffer[i + 2] > 1) {
29 i += 3; 30 i += 3;
30 } else if (buffer[i + 2] == 1 && buffer[i + 1] == 0 && buffer[i] == 0) { 31 } else if (buffer[i + 2] == 1 && buffer[i + 1] == 0 && buffer[i] == 0) {
31 // We found a start sequence, now check if it was a 3 of 4 byte one. 32 // We found a start sequence, now check if it was a 3 of 4 byte one.
32 NaluIndex index = {i, i + 3, 0}; 33 NaluIndex index = {i, i + 3, 0};
33 if (index.start_offset > 0 && buffer[index.start_offset - 1] == 0) 34 if (index.start_offset > 0 && buffer[index.start_offset - 1] == 0)
34 --index.start_offset; 35 --index.start_offset;
35 36
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 if (byte == 0) { 99 if (byte == 0) {
99 ++num_consecutive_zeros; 100 ++num_consecutive_zeros;
100 } else { 101 } else {
101 num_consecutive_zeros = 0; 102 num_consecutive_zeros = 0;
102 } 103 }
103 } 104 }
104 } 105 }
105 106
106 } // namespace H264 107 } // namespace H264
107 } // namespace webrtc 108 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_nalu.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698