Skip to content

Commit

Permalink
Merge pull request #231 from Atlas42/find_h26x_start_code_fix
Browse files Browse the repository at this point in the history
find_h26x_start_code fix
  • Loading branch information
jrsnen authored Nov 14, 2024
2 parents 55dbea4 + 976adc2 commit 63789b5
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions src/formats/h26x.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,6 @@ ssize_t uvgrtp::formats::h26x::find_h26x_start_code(
bool prev_had_zero = false;
bool cur_has_zero = false;
size_t pos = offset;
size_t last_byte_position = len - (len % 8) - 1;

/* We can get rid of the bounds check when looping through
* non-zero 8 byte chunks by setting the last byte to zero.
*
* This added zero will make the last 8 byte zero check to fail
* and when we get out of the loop we can check if we've reached the end */
uint8_t temp_last_byte = data[last_byte_position];
data[last_byte_position] = 0;

uint32_t prev_value32 = UINT32_MAX;
uint32_t cur_value32 = UINT32_MAX;
Expand Down Expand Up @@ -210,7 +201,6 @@ ssize_t uvgrtp::formats::h26x::find_h26x_start_code(
if (((cur_value32 >> 24) & 0xff) == 0x01 && ((prev_value32 >> 0) & 0xffff) == 0) {
start_len = (((prev_value32 >> 0) & 0xffffff) == 0) ? 4 : 3;
#endif
data[last_byte_position] = temp_last_byte;
return pos + 1;
}
}
Expand All @@ -234,7 +224,7 @@ ssize_t uvgrtp::formats::h26x::find_h26x_start_code(
{
--start_len;
}
data[last_byte_position] = temp_last_byte;

return pos + ret;
}

Expand Down Expand Up @@ -274,21 +264,21 @@ ssize_t uvgrtp::formats::h26x::find_h26x_start_code(
if (p4z && c4s) {
// previous dword 0xXXXX0000 and current dword is 0x0001XXXX
start_len = 4;
data[last_byte_position] = temp_last_byte;

return pos + 2;
} else if (p2z) {
// Previous dword was 0xXXXXXX00

if (c6s) {
// Current dword is 0x000001XX
start_len = 4;
data[last_byte_position] = temp_last_byte;

return pos + 3;
}
else if (c4s) {
// Current dword is 0x0001XXXX
start_len = 3;
data[last_byte_position] = temp_last_byte;

return pos + 2;
}
}
Expand All @@ -313,7 +303,6 @@ ssize_t uvgrtp::formats::h26x::find_h26x_start_code(
}
}

data[last_byte_position] = temp_last_byte;
return -1;
}

Expand Down

0 comments on commit 63789b5

Please sign in to comment.