--- gst/mpegaudioparse/gstmpegaudioparse.c	2008-08-11 23:21:43.000000000 +0200
+++ gst/mpegaudioparse/gstmpegaudioparse.c.new	2008-11-24 13:58:27.000000000 +0100
@@ -134,6 +134,10 @@ mp3parse_total_bytes (GstMPEGAudioParse 
 static gboolean
 mp3parse_total_time (GstMPEGAudioParse * mp3parse, GstClockTime * total);
 
+
+static GstPadLinkReturn gst_mp3parse_sink_link (GstPad * pad, GstPad * peer);
+static gboolean gst_mp3parse_sink_set_caps (GstPad * pad, GstCaps * caps);
+
 /* static guint gst_mp3parse_signals[LAST_SIGNAL] = { 0 }; */
 
 GST_BOILERPLATE (GstMPEGAudioParse, gst_mp3parse, GstElement, GST_TYPE_ELEMENT);
@@ -404,6 +408,9 @@ gst_mp3parse_init (GstMPEGAudioParse * m
       gst_pad_new_from_static_template (&mp3_sink_template, "sink");
   gst_pad_set_event_function (mp3parse->sinkpad, gst_mp3parse_sink_event);
   gst_pad_set_chain_function (mp3parse->sinkpad, gst_mp3parse_chain);
+  gst_pad_set_link_function (mp3parse->sinkpad, gst_mp3parse_sink_link);
+  gst_pad_set_setcaps_function (mp3parse->sinkpad, gst_mp3parse_sink_set_caps);
+
   gst_element_add_pad (GST_ELEMENT (mp3parse), mp3parse->sinkpad);
 
   mp3parse->srcpad =
@@ -1968,3 +1975,79 @@ mp3parse_get_query_types (GstPad * pad A
 
   return query_types;
 }
+
+static GstPadLinkReturn
+gst_mp3parse_sink_link (GstPad * pad, GstPad * peer)
+{
+  gboolean ret;
+  GstCaps *src_caps, *peer_caps;
+  GstMPEGAudioParse *mp3parse;
+  GstStructure *structure;
+  gint version, layer, channels, rate;
+
+  mp3parse = GST_MP3PARSE (gst_pad_get_parent (pad));
+  peer_caps = gst_pad_get_caps (peer);
+
+  if (peer_caps) {
+    structure = gst_caps_get_structure (peer_caps, 0);
+    ret = gst_structure_get_int (structure, "mpegversion", &version);
+    ret &= gst_structure_get_int (structure, "layer", &layer);
+    ret &= gst_structure_get_int (structure, "channels", &channels);
+    ret &= gst_structure_get_int (structure, "rate", &rate);
+
+    GST_INFO_OBJECT (mp3parse,
+        "get version %d, layer %d, rate %d, channels %d\n", version, layer,
+        rate, channels);
+    if (ret) {
+      mp3parse->channels = channels;
+      mp3parse->layer = layer;
+      mp3parse->rate = rate;
+      mp3parse->version = version;
+      src_caps = mp3_caps_create (version, layer, channels, rate);
+      gst_pad_set_caps (mp3parse->srcpad, src_caps);
+      gst_caps_unref (src_caps);
+    }
+    gst_caps_unref (peer_caps);
+  }
+
+  g_object_unref (mp3parse);
+
+  return GST_PAD_LINK_OK;
+}
+
+static gboolean
+gst_mp3parse_sink_set_caps (GstPad * pad, GstCaps * caps)
+{
+  gboolean ret;
+  GstCaps *src_caps;
+  GstMPEGAudioParse *mp3parse;
+  GstStructure *structure;
+  gint version, layer, channels, rate;
+
+  mp3parse = GST_MP3PARSE (gst_pad_get_parent (pad));
+
+  if (caps) {
+    structure = gst_caps_get_structure (caps, 0);
+    ret = gst_structure_get_int (structure, "mpegversion", &version);
+    ret &= gst_structure_get_int (structure, "layer", &layer);
+    ret &= gst_structure_get_int (structure, "channels", &channels);
+    ret &= gst_structure_get_int (structure, "rate", &rate);
+
+    GST_INFO_OBJECT (mp3parse,
+        "get version %d, layer %d, rate %d, channels %d\n", version, layer,
+        rate, channels);
+    if (ret) {
+      mp3parse->channels = channels;
+      mp3parse->layer = layer;
+      mp3parse->rate = rate;
+      mp3parse->version = version;
+      src_caps = mp3_caps_create (version, layer, channels, rate);
+      gst_pad_set_caps (mp3parse->srcpad, src_caps);
+      gst_caps_unref (src_caps);
+    }
+  }
+
+  g_object_unref (mp3parse);
+
+  return GST_PAD_LINK_OK;
+}
