mpegvideoparser: Optimize scanning for start code

https://bugzilla.gnome.org/show_bug.cgi?id=672701
This commit is contained in:
Nicolas Dufresne 2012-05-08 16:51:11 -04:00 committed by Mark Nauwelaerts
parent 332f715208
commit 920053dae6

View file

@ -233,8 +233,7 @@ static inline guint
scan_for_start_codes (const GstByteReader * reader, guint offset, guint size) scan_for_start_codes (const GstByteReader * reader, guint offset, guint size)
{ {
const guint8 *data; const guint8 *data;
guint32 state; guint i = 0;
guint i;
g_return_val_if_fail (size > 0, -1); g_return_val_if_fail (size > 0, -1);
g_return_val_if_fail ((guint64) offset + size <= reader->size - reader->byte, g_return_val_if_fail ((guint64) offset + size <= reader->size - reader->byte,
@ -246,34 +245,21 @@ scan_for_start_codes (const GstByteReader * reader, guint offset, guint size)
data = reader->data + reader->byte + offset; data = reader->data + reader->byte + offset;
/* set the state to something that does not match */ while (i < (size - 4)) {
state = 0xffffffff; if (data[i + 2] > 1) {
i += 3;
/* now find data */ } else if (data[i + 1]) {
for (i = 0; i < size; i++) { i += 2;
/* throw away one byte and move in the next byte */ } else if (data[i] || data[i + 2] != 1) {
state = ((state << 8) | data[i]); i++;
if (G_UNLIKELY ((state & 0xffffff00) == 0x00000100)) { } else {
/* we have a match but we need to have skipped at break;
* least 4 bytes to fill the state. */
if (G_LIKELY (i >= 3))
return offset + i - 3;
} }
/* TODO: reimplement making 010001 not detected as a sc
* Accelerate search for start code
* if (data[i] > 1) {
* while (i < (size - 4) && data[i] > 1) {
* if (data[i + 3] > 1)
* i += 4;
* else
* i += 1;
* }
* state = 0x00000100;
*}
*/
} }
if (i < (size - 4))
return offset + i;
/* nothing found */ /* nothing found */
return -1; return -1;
} }