Function that finds the next NALU inside H.264 bitstream data.
/*
* Find next NAL unit from the specified H.264 bitstream data.
*/
static auto find_next_nal_unit(const uint8_t *start, const uint8_t *end) -> const uint8_t *
{
const uint8_t *p = start;
/* Simply lookup "0x000001" pattern */
while (p <= end - 3 && (p[0] || p[1] || p[2] != 1))
++p;
if (p > end - 3)
/* No more NAL unit in this bitstream */
return nullptr;
/* Include 8 bits leading zero */
if (p > start && *(p - 1) == 0)
return (p - 1);
return p;
}