Index: gstwavparse.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-good/gst/wavparse/gstwavparse.c,v
retrieving revision 1.102
diff -u -p -r1.102 gstwavparse.c
--- gstwavparse.c	16 Feb 2006 20:30:13 -0000	1.102
+++ gstwavparse.c	23 Feb 2006 11:12:16 -0000
@@ -95,6 +95,7 @@ static GstStaticPadTemplate src_template
         "block_align = (int) [ 1, 8192 ], "
         "rate = (int) [ 8000, 48000 ], " "channels = (int) [ 1, 2 ];"
         "audio/x-vnd.sony.atrac3;"
+        "audio/x-dts;"
         "audio/x-wma, " "wmaversion = (int) [ 1, 2 ]")
     );
 
@@ -885,23 +886,17 @@ gst_wavparse_stream_headers (GstWavParse
   if (!caps)
     goto unknown_format;
 
-  gst_wavparse_create_sourcepad (wav);
-  gst_pad_set_active (wav->srcpad, TRUE);
-  gst_pad_set_caps (wav->srcpad, caps);
-  gst_caps_unref (caps);
-  caps = NULL;
-
-  gst_element_add_pad (GST_ELEMENT (wav), wav->srcpad);
-  gst_element_no_more_pads (GST_ELEMENT (wav));
+  /* create pad later so we can sniff the first few bytes
+   * of the real data and correct our caps if necessary */
+  gst_caps_replace (&wav->caps, caps);
+  gst_caps_replace (&caps, NULL);
 
   if (codec_name) {
-    GstTagList *tags = gst_tag_list_new ();
+    wav->tags = gst_tag_list_new ();
 
-    gst_tag_list_add (tags, GST_TAG_MERGE_REPLACE,
+    gst_tag_list_add (wav->tags, GST_TAG_MERGE_REPLACE,
         GST_TAG_AUDIO_CODEC, codec_name, NULL);
 
-    gst_element_found_tags_for_pad (GST_ELEMENT (wav), wav->srcpad, tags);
-
     g_free (codec_name);
     codec_name = NULL;
   }
@@ -948,10 +943,10 @@ gst_wavparse_stream_headers (GstWavParse
   duration = gst_util_uint64_scale_int (wav->datasize, GST_SECOND, wav->bps);
   gst_segment_set_duration (&wav->segment, GST_FORMAT_TIME, duration);
 
-  gst_pad_push_event (wav->srcpad,
+  wav->newsegment = 
       gst_event_new_new_segment (FALSE, wav->segment.rate,
           wav->segment.format, wav->segment.start,
-          wav->segment.duration, wav->segment.start));
+          wav->segment.duration, wav->segment.start);
 
   return GST_FLOW_OK;
 
@@ -1059,6 +1054,41 @@ gst_wavparse_stream_data (GstWavParse * 
   /* update current running segment position */
   gst_segment_set_last_stop (&wav->segment, GST_FORMAT_TIME, next_timestamp);
 
+  /* first chunk of data? create the source pad. we do this only here so
+   * we can detect broken .wav files with dts disguised as raw PCM (sigh) */
+  if (wav->caps != NULL) {
+    GstStructure *s = gst_caps_get_structure (wav->caps, 0);
+    const guint8 dts_marker[] = { 0xFF, 0x1F, 0x00, 0xE8, 0xF1, 0x07 };
+
+    if (gst_structure_has_name (s, "audio/x-raw-int") &&
+        GST_BUFFER_SIZE (buf) > 6 &&
+        memcmp (GST_BUFFER_DATA (buf), dts_marker, 6) == 0) {
+
+      GST_WARNING_OBJECT (wav, "Found DTS marker in file marked as raw PCM");
+      gst_caps_unref (wav->caps);
+      wav->caps = gst_caps_from_string ("audio/x-dts");
+
+      gst_tag_list_add (wav->tags, GST_TAG_MERGE_REPLACE,
+          GST_TAG_AUDIO_CODEC, "dts", NULL);
+    }
+
+    gst_wavparse_create_sourcepad (wav);
+    gst_pad_set_active (wav->srcpad, TRUE);
+    gst_pad_set_caps (wav->srcpad, wav->caps);
+    gst_caps_replace (&wav->caps, NULL);
+
+    gst_element_add_pad (GST_ELEMENT (wav), wav->srcpad);
+    gst_element_no_more_pads (GST_ELEMENT (wav));
+
+    gst_pad_push_event (wav->srcpad, wav->newsegment);
+    wav->newsegment = NULL;
+
+    if (wav->tags) {
+      gst_element_found_tags_for_pad (GST_ELEMENT (wav), wav->srcpad, wav->tags);
+      wav->tags = NULL;
+    }
+  }
+
   /* don't forget to set the caps on the buffer */
   gst_buffer_set_caps (buf, GST_PAD_CAPS (wav->srcpad));
 
Index: gstwavparse.h
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-good/gst/wavparse/gstwavparse.h,v
retrieving revision 1.29
diff -u -p -r1.29 gstwavparse.h
--- gstwavparse.h	16 Dec 2005 19:32:53 -0000	1.29
+++ gstwavparse.h	23 Feb 2006 11:12:16 -0000
@@ -54,6 +54,12 @@ struct _GstWavParse {
   /* pads */
   GstPad *sinkpad,*srcpad;
 
+  /* for delayed pad creation for when we
+   * have the first chunk of data */
+  GstCaps     *caps;
+  GstTagList  *tags;
+  GstEvent    *newsegment;
+
   /* WAVE decoding state */
   GstWavParseState state;
 
