diff --git a/common_video/h264/h264_common.cc b/common_video/h264/h264_common.cc index 5e58ba62e9..06d94e0305 100644 --- a/common_video/h264/h264_common.cc +++ b/common_video/h264/h264_common.cc @@ -27,22 +27,26 @@ std::vector FindNaluIndices(const uint8_t* buffer, if (buffer_size < kNaluShortStartSequenceSize) return sequences; + static_assert(kNaluShortStartSequenceSize >= 2, + "kNaluShortStartSequenceSize must be larger or equals to 2"); const size_t end = buffer_size - kNaluShortStartSequenceSize; for (size_t i = 0; i < end;) { if (buffer[i + 2] > 1) { i += 3; - } else if (buffer[i + 2] == 1 && buffer[i + 1] == 0 && buffer[i] == 0) { - // We found a start sequence, now check if it was a 3 of 4 byte one. - NaluIndex index = {i, i + 3, 0}; - if (index.start_offset > 0 && buffer[index.start_offset - 1] == 0) - --index.start_offset; + } else if (buffer[i + 2] == 1) { + if (buffer[i + 1] == 0 && buffer[i] == 0) { + // We found a start sequence, now check if it was a 3 of 4 byte one. + NaluIndex index = {i, i + 3, 0}; + if (index.start_offset > 0 && buffer[index.start_offset - 1] == 0) + --index.start_offset; - // Update length of previous entry. - auto it = sequences.rbegin(); - if (it != sequences.rend()) - it->payload_size = index.start_offset - it->payload_start_offset; + // Update length of previous entry. + auto it = sequences.rbegin(); + if (it != sequences.rend()) + it->payload_size = index.start_offset - it->payload_start_offset; - sequences.push_back(index); + sequences.push_back(index); + } i += 3; } else {