Optimize FindNaluIndices
We can add i by 3 even if it's not 001, because in any xx1 combination, 1 could not be part of start code. Bug: None Change-Id: Ica653d9e49b9f7c665027b9cf4453753c5fdd3ed Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/159721 Commit-Queue: Kári Helgason <kthelgason@webrtc.org> Reviewed-by: Erik Språng <sprang@webrtc.org> Reviewed-by: Kári Helgason <kthelgason@webrtc.org> Reviewed-by: Tommi <tommi@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30064}
This commit is contained in:
@ -27,11 +27,14 @@ std::vector<NaluIndex> FindNaluIndices(const uint8_t* buffer,
|
|||||||
if (buffer_size < kNaluShortStartSequenceSize)
|
if (buffer_size < kNaluShortStartSequenceSize)
|
||||||
return sequences;
|
return sequences;
|
||||||
|
|
||||||
|
static_assert(kNaluShortStartSequenceSize >= 2,
|
||||||
|
"kNaluShortStartSequenceSize must be larger or equals to 2");
|
||||||
const size_t end = buffer_size - kNaluShortStartSequenceSize;
|
const size_t end = buffer_size - kNaluShortStartSequenceSize;
|
||||||
for (size_t i = 0; i < end;) {
|
for (size_t i = 0; i < end;) {
|
||||||
if (buffer[i + 2] > 1) {
|
if (buffer[i + 2] > 1) {
|
||||||
i += 3;
|
i += 3;
|
||||||
} else if (buffer[i + 2] == 1 && buffer[i + 1] == 0 && buffer[i] == 0) {
|
} 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.
|
// We found a start sequence, now check if it was a 3 of 4 byte one.
|
||||||
NaluIndex index = {i, i + 3, 0};
|
NaluIndex index = {i, i + 3, 0};
|
||||||
if (index.start_offset > 0 && buffer[index.start_offset - 1] == 0)
|
if (index.start_offset > 0 && buffer[index.start_offset - 1] == 0)
|
||||||
@ -43,6 +46,7 @@ std::vector<NaluIndex> FindNaluIndices(const uint8_t* buffer,
|
|||||||
it->payload_size = index.start_offset - it->payload_start_offset;
|
it->payload_size = index.start_offset - it->payload_start_offset;
|
||||||
|
|
||||||
sequences.push_back(index);
|
sequences.push_back(index);
|
||||||
|
}
|
||||||
|
|
||||||
i += 3;
|
i += 3;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user