| OLD | NEW | 
|    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   std::vector<NaluIndex> sequences; |   24   std::vector<NaluIndex> sequences; | 
|   25   if (buffer_size < kNaluShortStartSequenceSize) |   25   if (buffer_size < kNaluShortStartSequenceSize) | 
|   26     return sequences; |   26     return sequences; | 
 |   27  | 
|   27   const size_t end = buffer_size - kNaluShortStartSequenceSize; |   28   const size_t end = buffer_size - kNaluShortStartSequenceSize; | 
|   28   for (size_t i = 0; i < end;) { |   29   for (size_t i = 0; i < end;) { | 
|   29     if (buffer[i + 2] > 1) { |   30     if (buffer[i + 2] > 1) { | 
|   30       i += 3; |   31       i += 3; | 
|   31     } else if (buffer[i + 2] == 1 && buffer[i + 1] == 0 && buffer[i] == 0) { |   32     } else if (buffer[i + 2] == 1 && buffer[i + 1] == 0 && buffer[i] == 0) { | 
|   32       // We found a start sequence, now check if it was a 3 of 4 byte one. |   33       // We found a start sequence, now check if it was a 3 of 4 byte one. | 
|   33       NaluIndex index = {i, i + 3, 0}; |   34       NaluIndex index = {i, i + 3, 0}; | 
|   34       if (index.start_offset > 0 && buffer[index.start_offset - 1] == 0) |   35       if (index.start_offset > 0 && buffer[index.start_offset - 1] == 0) | 
|   35         --index.start_offset; |   36         --index.start_offset; | 
|   36  |   37  | 
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   99     if (byte == 0) { |  100     if (byte == 0) { | 
|  100       ++num_consecutive_zeros; |  101       ++num_consecutive_zeros; | 
|  101     } else { |  102     } else { | 
|  102       num_consecutive_zeros = 0; |  103       num_consecutive_zeros = 0; | 
|  103     } |  104     } | 
|  104   } |  105   } | 
|  105 } |  106 } | 
|  106  |  107  | 
|  107 }  // namespace H264 |  108 }  // namespace H264 | 
|  108 }  // namespace webrtc |  109 }  // namespace webrtc | 
| OLD | NEW |