[gst-cvs] gst-plugins-ugly: mpegaudioparse: ensure 2 valid headers in a row when resyncing

Mark Nauwelaerts mnauw at kemper.freedesktop.org
Thu Sep 17 07:29:02 PDT 2009


Module: gst-plugins-ugly
Branch: master
Commit: 57d01c2526c20f3967caf6058e35506f376a90d3
URL:    http://cgit.freedesktop.org/gstreamer/gst-plugins-ugly/commit/?id=57d01c2526c20f3967caf6058e35506f376a90d3

Author: Mark Nauwelaerts <mark.nauwelaerts at collabora.co.uk>
Date:   Thu Sep 17 16:12:29 2009 +0200

mpegaudioparse: ensure 2 valid headers in a row when resyncing

---

 gst/mpegaudioparse/gstmpegaudioparse.c |   26 +++++++++++++++++---------
 1 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/gst/mpegaudioparse/gstmpegaudioparse.c b/gst/mpegaudioparse/gstmpegaudioparse.c
index f7c18a3..6a2836a 100644
--- a/gst/mpegaudioparse/gstmpegaudioparse.c
+++ b/gst/mpegaudioparse/gstmpegaudioparse.c
@@ -1333,23 +1333,31 @@ gst_mp3parse_chain (GstPad * pad, GstBuffer * buf)
                   (0xf <<  4)  /* mode|mode extension */ | \
                   (0xf))        /* copyright|emphasis */
 
-        /* require 2 matching headers in a row */
+        /* require 2 valid matching headers in a row */
         if ((header2 & HDRMASK) != (header & HDRMASK)) {
           GST_DEBUG_OBJECT (mp3parse, "next header doesn't match "
               "(header=%08X (%08X), header2=%08X (%08X), bpf=%d)",
               (guint) header, (guint) header & HDRMASK, (guint) header2,
               (guint) header2 & HDRMASK, bpf);
-          /* This frame is invalid.  Start looking for a valid frame at the 
-           * next position in the stream */
-          mp3parse->resyncing = TRUE;
-          gst_adapter_flush (mp3parse->adapter, 1);
-          if (mp3parse->cur_offset != -1)
-            mp3parse->cur_offset++;
-          mp3parse->tracked_offset++;
-          continue;
+        } else if ((((header2 >> 12) & 0xf) == 0) ||
+            (((header2 >> 12) & 0xf) == 0xf)) {
+          /* optimized validity check for almost equal headers;
+           * only bitrate needs checking */
+          GST_DEBUG_OBJECT (mp3parse, "next header invalid (bitrate)");
+        } else {
+          goto valid;
         }
+        /* This frame is invalid.  Start looking for a valid frame at the
+         * next position in the stream */
+        mp3parse->resyncing = TRUE;
+        gst_adapter_flush (mp3parse->adapter, 1);
+        if (mp3parse->cur_offset != -1)
+          mp3parse->cur_offset++;
+        mp3parse->tracked_offset++;
+        continue;
       }
 
+    valid:
       /* if we don't have the whole frame... */
       if (available < bpf) {
         GST_DEBUG_OBJECT (mp3parse, "insufficient data available, need "





More information about the Gstreamer-commits mailing list