wavparse: detect DTS advertised as PCM correctly in some more cases
authorTim-Philipp Müller <tim.muller@collabora.co.uk>
Fri, 3 Dec 2010 00:22:48 +0000 (00:22 +0000)
committerTim-Philipp Müller <tim.muller@collabora.co.uk>
Fri, 3 Dec 2010 10:18:43 +0000 (10:18 +0000)
The DTS typefinder may return a lower probability for frames that start
at non-zero offsets and where there's no second frame sync in the first
buffer. It's fairly unlikely that we'll acidentally identify PCM data
as DTS, so we don't do additional checks for now.

https://bugzilla.gnome.org/show_bug.cgi?id=636234

gst/wavparse/gstwavparse.c

index ff01168..6e56f8e 100644 (file)
@@ -1723,6 +1723,27 @@ gst_wavparse_send_event (GstElement * element, GstEvent * event)
   return res;
 }
 
+static gboolean
+gst_wavparse_have_dts_caps (const GstCaps * caps, GstTypeFindProbability prob)
+{
+  GstStructure *s;
+
+  s = gst_caps_get_structure (caps, 0);
+  if (!gst_structure_has_name (s, "audio/x-dts"))
+    return FALSE;
+  if (prob >= GST_TYPE_FIND_LIKELY)
+    return TRUE;
+  /* DTS at non-0 offsets and without second sync may yield POSSIBLE .. */
+  if (prob < GST_TYPE_FIND_POSSIBLE)
+    return FALSE;
+  /* .. in which case we want at least a valid-looking rate and channels */
+  if (!gst_structure_has_field (s, "channels"))
+    return FALSE;
+  /* and for extra assurance we could also check the rate from the DTS frame
+   * against the one in the wav header, but for now let's not do that */
+  return gst_structure_has_field (s, "rate");
+}
+
 static void
 gst_wavparse_add_src_pad (GstWavParse * wav, GstBuffer * buf)
 {
@@ -1738,9 +1759,8 @@ gst_wavparse_add_src_pad (GstWavParse * wav, GstBuffer * buf)
 
       tf_caps = gst_type_find_helper_for_buffer (GST_OBJECT (wav), buf, &prob);
       if (tf_caps != NULL) {
-        s = gst_caps_get_structure (tf_caps, 0);
-        if (gst_structure_has_name (s, "audio/x-dts")
-            && prob >= GST_TYPE_FIND_LIKELY) {
+        GST_LOG ("typefind caps = %" GST_PTR_FORMAT ", P=%d", tf_caps, prob);
+        if (gst_wavparse_have_dts_caps (tf_caps, prob)) {
           GST_INFO_OBJECT (wav, "Found DTS marker in file marked as raw PCM");
           gst_caps_unref (wav->caps);
           wav->caps = tf_caps;