@@ -996,12 +996,24 @@ const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p,
return p;
}
+ /* with memory address increasing left to right, we are looking for (in hexadecimal):
+ * 00 00 01 XX
+ * p points at the address which should have the value of XX
+ */
while (p < end) {
- if (p[-1] > 1 ) p += 3;
- else if (p[-2] ) p += 2;
- else if (p[-3]|(p[-1]-1)) p++;
- else {
+ if (/* UU UU UU */ p[-1] < 1) { // equivalently p[-1] == 0
p++;
+ // could be in a start code, so check next byte
+ }
+ else if (/* UU UU UN */ p[-1] > 1 ||
+ /* UU UU 01 */ p[-2] != 0 ||
+ /* UU 00 01 */ p[-3] != 0) {
+ // start check over with 3 new bytes
+ p += 3;
+ }
+ else { /* 00 00 01 */
+ p++;
+ // p now points at the address following the start code value XX
break;
}
}