--- old-argh/metadata/rb-metadata-gst.c	2006-03-14 19:05:16.000000000 +1000
+++ new-argh/metadata/rb-metadata-gst.c	2006-03-14 19:05:16.000000000 +1000
@@ -75,6 +75,7 @@ struct RBMetaDataPrivate
 	GstElement *pipeline;
 	GstElement *sink;
 	gulong typefind_cb_id;
+	GstPad *decoder_sink_pad;
 
 	/* Array of RBMetadataGstType */
 	GPtrArray *supported_types;
@@ -285,6 +286,9 @@ rb_metadata_finalize (GObject *object)
 	if (md->priv->metadata)
 		g_hash_table_destroy (md->priv->metadata);
 
+	if (md->priv->decoder_sink_pad)
+		gst_object_unref (GST_OBJECT (md->priv->decoder_sink_pad));
+	
 	if (md->priv->pipeline)
 		gst_object_unref (GST_OBJECT (md->priv->pipeline));
 
@@ -585,6 +589,15 @@ rb_metadata_gst_typefind_cb (GstElement 
 
 
 static void
+get_decoder_sink_pad (GstPad *pad, RBMetaData *md)
+{
+	if (md->priv->decoder_sink_pad == NULL)
+		md->priv->decoder_sink_pad = pad;
+	else
+		gst_object_unref (pad);
+}
+
+static void
 rb_metadata_gst_new_decoded_pad_cb (GstElement *decodebin, GstPad *pad, gboolean last, RBMetaData *md)
 {
 	GstCaps *caps;
@@ -606,6 +619,7 @@ rb_metadata_gst_new_decoded_pad_cb (GstE
 		if (g_str_has_prefix (mimetype, "audio/x-raw")) {
 			/* link this to the fake sink */
 			GstPad *sink_pad;
+			GstElement *decoder;
 			rb_debug ("linking new decoded pad of type %s to fakesink", mimetype);
 			sink_pad = gst_element_get_pad (md->priv->sink, "sink");
 			gst_pad_link (pad, sink_pad);
@@ -613,6 +627,28 @@ rb_metadata_gst_new_decoded_pad_cb (GstE
 			/* what happens if we get two audio pads from the same stream? 
 			 * can this happen?
 			 */
+
+			/*
+			 * find the element that created the pad, and get its sink pad.
+			 * later on we can use this to determine the actual type of the
+			 * stream.
+			 */
+			if (GST_IS_GHOST_PAD (pad)) {
+				GstPad *real = gst_ghost_pad_get_target (GST_GHOST_PAD (pad));
+				decoder = GST_PAD_PARENT (real);
+				gst_object_unref (real);
+			} else {
+				decoder = GST_PAD_PARENT (pad);
+			}
+			if (decoder) {
+				GstIterator *sinkpads;
+
+				sinkpads = gst_element_iterate_sink_pads (decoder);
+				gst_iterator_foreach (sinkpads, (GFunc) get_decoder_sink_pad, md);
+				gst_iterator_free (sinkpads);
+			}
+
+			
 		} else if (g_str_has_prefix (mimetype, "video/")) {
 			rb_debug ("got decoded video pad of type %s", mimetype);
 			md->priv->non_audio = TRUE;
@@ -918,6 +954,28 @@ rb_metadata_load (RBMetaData *md,
 				rb_debug ("duration query failed!");
 			}
 		}
+
+		/*
+		 * If we managed to find the decoder's sink pad, the caps on it
+		 * may tell us the actual type of the stream, rather than just the
+		 * container type.
+		 */
+		if (md->priv->decoder_sink_pad) {
+			GstCaps *caps = GST_PAD_CAPS (md->priv->decoder_sink_pad);
+			if (caps) {
+				GstStructure *structure = gst_caps_get_structure (caps, 0);
+				const gchar *realtype = gst_structure_get_name (structure);
+
+				if (realtype != NULL) {
+					if (md->priv->type != NULL)
+						g_free (md->priv->type);
+					md->priv->type = g_strdup (realtype);
+				}
+			}
+
+			gst_object_unref (md->priv->decoder_sink_pad);
+			md->priv->decoder_sink_pad = NULL;
+		}
 	}
 #ifdef HAVE_GSTREAMER_0_8
 	else if (md->priv->eos) {

