Index: gstwavpackdec.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-bad/ext/wavpack/gstwavpackdec.c,v
retrieving revision 1.14
diff -u -p -u -r1.14 gstwavpackdec.c
--- gstwavpackdec.c	23 Aug 2006 08:52:50 -0000	1.14
+++ gstwavpackdec.c	23 Aug 2006 12:19:29 -0000
@@ -236,6 +236,34 @@ gst_wavpack_dec_clip_outgoing_buffer (Gs
   return TRUE;
 }
 
+static void
+gst_wavpack_dec_post_tags (GstWavpackDec * dec, WavpackHeader * wph)
+{
+  GstTagList *list;
+  GstFormat format_time = GST_FORMAT_TIME, format_bytes = GST_FORMAT_BYTES;
+  gint64 duration, size;
+
+  list = gst_tag_list_new ();
+
+  gst_tag_list_add (list, GST_TAG_MERGE_REPLACE,
+      GST_TAG_AUDIO_CODEC,
+      (wph->flags & HYBRID_FLAG) ? "Wavpack Lossy" : "Wavpack Lossless", NULL);
+
+  /* try to estimate the average bitrate by querying upstream for duration
+   * in bytes and time */
+  if (gst_pad_query_peer_duration (dec->sinkpad, &format_bytes, &size) &&
+      gst_pad_query_peer_duration (dec->sinkpad, &format_time, &duration) &&
+      size > 0 && duration > 0) {
+    duration = gst_util_uint64_scale (duration, 1, GST_SECOND);
+    if (duration > 0)
+      gst_tag_list_add (list, GST_TAG_MERGE_REPLACE,
+          GST_TAG_BITRATE, gst_util_uint64_scale_int (size, 8, duration), NULL);
+  }
+
+  gst_element_post_message (GST_ELEMENT (dec),
+      gst_message_new_tag (GST_OBJECT (dec), list));
+}
+
 static GstFlowReturn
 gst_wavpack_dec_chain (GstPad * pad, GstBuffer * buf)
 {
@@ -314,6 +342,10 @@ gst_wavpack_dec_chain (GstPad * pad, Gst
     /* should always succeed */
     gst_pad_set_caps (dec->srcpad, caps);
     gst_caps_unref (caps);
+
+    /* send GST_TAG_AUDIO_CODEC and GST_TAG_BITRATE tags before something
+     * is decoded or after the format has changed */
+    gst_wavpack_dec_post_tags (dec, &wph);
   }
 
   unpacked_size = wph.block_samples * (dec->width / 8) * dec->channels;
Index: gstwavpackparse.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-bad/ext/wavpack/gstwavpackparse.c,v
retrieving revision 1.15
diff -u -p -u -r1.15 gstwavpackparse.c
--- gstwavpackparse.c	23 Aug 2006 10:30:31 -0000	1.15
+++ gstwavpackparse.c	23 Aug 2006 12:19:29 -0000
@@ -97,7 +97,8 @@ gst_wavpack_parse_base_init (gpointer kl
       GST_ELEMENT_DETAILS ("WavePack parser",
       "Codec/Demuxer/Audio",
       "Parses Wavpack files",
-      "Arwed v. Merkatz <v.merkatz@gmx.net>");
+      "Arwed v. Merkatz <v.merkatz@gmx.net>, "
+      "Sebastian Dröge <slomo@circular-chaos.org>");
   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
 
   gst_element_class_add_pad_template (element_class,
@@ -292,7 +293,8 @@ gst_wavpack_parse_src_query (GstPad * pa
           break;
         default:
           GST_DEBUG_OBJECT (parse, "cannot handle position query in "
-              "%s format", gst_format_get_name (format));
+              "%s format Forwarding upstream.", gst_format_get_name (format));
+          ret = gst_pad_query_default (pad, query);
           break;
       }
       break;
@@ -327,7 +329,8 @@ gst_wavpack_parse_src_query (GstPad * pa
           break;
         default:
           GST_DEBUG_OBJECT (parse, "cannot handle duration query in "
-              "%s format", gst_format_get_name (format));
+              "%s format. Forwarding upstream.", gst_format_get_name (format));
+          ret = gst_pad_query_default (pad, query);
           break;
       }
       break;
