codecparsers: jpeg: fix and optimize scan for next marker code.
authorGwenole Beauchesne <gwenole.beauchesne@intel.com>
Tue, 24 Sep 2013 14:10:45 +0000 (16:10 +0200)
committerTim-Philipp Müller <tim@centricular.com>
Sun, 21 Jun 2015 10:28:38 +0000 (11:28 +0100)
Fix scan for next marker code when there is an odd number of filler
(0xff) bytes before the actual marker code. Also optimize the loop
to execute with fewer instructions (~10%).

This fixes parsing for Spectralfan.mov.

gst-libs/gst/codecparsers/gstjpegparser.c

index ac1ba9a..30c67f3 100644 (file)
@@ -232,17 +232,16 @@ gst_jpeg_scan_for_marker_code (const guint8 * data, gsize size, guint offset)
   guint i;
 
   g_return_val_if_fail (data != NULL, -1);
-  g_return_val_if_fail (size > offset, -1);
 
-  for (i = offset; i < size - 1;) {
-    if (data[i] != 0xff)
-      i++;
-    else {
-      const guint8 v = data[i + 1];
-      if (v >= 0xc0 && v <= 0xfe)
-        return i;
+  i = offset + 1;
+  while (i < size) {
+    const guint8 v = data[i];
+    if (v < 0xc0)
       i += 2;
-    }
+    else if (v < 0xff && data[i - 1] == 0xff)
+      return i - 1;
+    else
+      i++;
   }
   return -1;
 }