Add -Wmissing-declarations -Wmissing-prototypes to warning flags
[platform/upstream/gstreamer.git] / gst / playback / gstplaybin.c
index 28caf15..f044c61 100644 (file)
 /**
  * SECTION:element-playbin
  *
- * <refsect2>
- * <para>
  * Playbin provides a stand-alone everything-in-one abstraction for an
  * audio and/or video player.
- * </para>
- * <para>
- * It can handle both audio and video files and features 
+ *
+ * It can handle both audio and video files and features
  * <itemizedlist>
  * <listitem>
  * automatic file type recognition and based on that automatic
  * volume control
  * </listitem>
  * </itemizedlist>
- * </para>
+ *
+ * <refsect2>
  * <title>Usage</title>
  * <para>
  * A playbin element can be created just like any other element using
- * gst_element_factory_make(). The file/URI to play should be set via the "uri"
+ * gst_element_factory_make(). The file/URI to play should be set via the #GstPlayBin:uri
  * property. This must be an absolute URI, relative file paths are not allowed.
  * Example URIs are file:///home/joe/movie.avi or http://www.joedoe.com/foo.ogg
- * </para>
- * <para>
+ *
  * Playbin is a #GstPipeline. It will notify the application of everything
  * that's happening (errors, end of stream, tags found, state changes, etc.)
  * by posting messages on its #GstBus. The application needs to watch the
  * bus.
- * </para>
- * <para>
+ *
  * Playback can be initiated by setting the element to PLAYING state using
  * gst_element_set_state(). Note that the state change will take place in
  * the background in a separate thread, when the function returns playback
  * is probably not happening yet and any errors might not have occured yet.
  * Applications using playbin should ideally be written to deal with things
  * completely asynchroneous.
- * </para>
- * <para>
+ *
  * When playback has finished (an EOS message has been received on the bus)
  * or an error has occured (an ERROR message has been received on the bus) or
  * the user wants to play a different track, playbin should be set back to
- * READY or NULL state, then the "uri" property should be set to the new
- * location and then playbin be set to PLAYING state again.
- * </para>
- * <para>
+ * READY or NULL state, then the #GstPlayBin:uri property should be set to the
+ * new location and then playbin be set to PLAYING state again.
+ *
  * Seeking can be done using gst_element_seek_simple() or gst_element_seek()
  * on the playbin element. Again, the seek will not be executed
  * instantaneously, but will be done in a background thread. When the seek
  * may wait for the seek to finish (or fail) using gst_element_get_state() with
  * -1 as the timeout, but this will block the user interface and is not
  * recommended at all.
- * </para>
- * <para>
+ *
  * Applications may query the current position and duration of the stream
  * via gst_element_query_position() and gst_element_query_duration() and
  * setting the format passed to GST_FORMAT_TIME. If the query was successful,
  * the duration or position will have been returned in units of nanoseconds.
  * </para>
+ * </refsect2>
+ * <refsect2>
  * <title>Advanced Usage: specifying the audio and video sink</title>
  * <para>
  * By default, if no audio sink or video sink has been specified via the
- * "audio-sink" or "video-sink" property, playbin will use the autoaudiosink
- * and autovideosink elements to find the first-best available output method.
+ * #GstPlayBin:audio-sink or #GstPlayBin:video-sink property, playbin will use
+ * the autoaudiosink and autovideosink elements to find the first-best
+ * available output method.
  * This should work in most cases, but is not always desirable. Often either
  * the user or application might want to specify more explicitly what to use
  * for audio and video output.
- * </para>
- * <para>
+ *
  * If the application wants more control over how audio or video should be
  * output, it may create the audio/video sink elements itself (for example
  * using gst_element_factory_make()) and provide them to playbin using the
- * "audio-sink" or "video-sink" property.
- * </para>
- * <para>
+ * #GstPlayBin:audio-sink or #GstPlayBin:video-sink property.
+ *
  * GNOME-based applications, for example, will usually want to create
  * gconfaudiosink and gconfvideosink elements and make playbin use those,
  * so that output happens to whatever the user has configured in the GNOME
  * Multimedia System Selector confinguration dialog.
- * </para>
- * <para>
+ *
  * The sink elements do not necessarily need to be ready-made sinks. It is
  * possible to create container elements that look like a sink to playbin,
  * but in reality contain a number of custom elements linked together. This
  * it to the sink pad of the first element within the bin. This can be used
  * for a number of purposes, for example to force output to a particular
  * format or to modify or observe the data before it is output.
- * </para>
- * <para>
+ *
  * It is also possible to 'suppress' audio and/or video output by using
  * 'fakesink' elements (or capture it from there using the fakesink element's
  * "handoff" signal, which, nota bene, is fired from the streaming thread!).
  * </para>
+ * </refsect2>
+ * <refsect2>
  * <title>Retrieving Tags and Other Meta Data</title>
  * <para>
  * Most of the common meta data (artist, title, etc.) can be retrieved by
  * watching for TAG messages on the pipeline's bus (see above).
- * </para>
- * <para>
+ *
  * Other more specific meta information like width/height/framerate of video
  * streams or samplerate/number of channels of audio streams can be obtained
- * using the "stream-info" property, which will return a GList of stream info
- * objects, one for each stream. These are opaque objects that can only be
- * accessed via the standard GObject property interface, ie. g_object_get().
+ * using the  #GstPlayBaseBin:stream-info property, which will return a GList of
+ * stream info objects, one for each stream. These are opaque objects that can
+ * only be accessed via the standard GObject property interface, ie. g_object_get().
  * Each stream info object has the following properties:
  * <itemizedlist>
  * <listitem>"object" (GstObject) (the decoder source pad usually)</listitem>
  * <listitem>"language-code" (string) (ISO-639 language code for this stream, mostly used for audio/subtitle streams)</listitem>
  * <listitem>"codec" (string) (format this stream was encoded in)</listitem>
  * </itemizedlist>
- * Stream information from the stream-info properties is best queried once
+ * Stream information from the #GstPlayBaseBin:stream-info property is best queried once
  * playbin has changed into PAUSED or PLAYING state (which can be detected
- * via a state-changed message on the bus where old_state=READY and
+ * via a state-changed message on the #GstBus where old_state=READY and
  * new_state=PAUSED), since before that the list might not be complete yet or
  * not contain all available information (like language-codes).
  * </para>
- * <title>Buffering status</title>
- * <para>
- * Playbin handles buffering automatically. When playbin is buffering, it
- * will post BUFFERING messages on the bus with a percentage value that
- * shows the progress of the buffering. Applications may want to show this
- * information to the user in some form or another. Here is how to extract
- * the percentage information from the message:
- * </para>
- * <para>
- * <programlisting>
+ * </refsect2>
+ * <refsect2>
+ * <title>Buffering</title>
+ * Playbin handles buffering automatically for the most part, but applications
+ * need to handle parts of the buffering process as well. Whenever playbin is
+ * buffering, it will post BUFFERING messages on the bus with a percentage
+ * value that shows the progress of the buffering process. Applications need
+ * to set playbin to PLAYING or PAUSED state in response to these messages.
+ * They may also want to convey the buffering progress to the user in some
+ * way. Here is how to extract the percentage information from the message
+ * (requires GStreamer >= 0.10.11):
+ * |[
  * switch (GST_MESSAGE_TYPE (msg)) {
  *   case GST_MESSAGE_BUFFERING: {
  *     gint percent = 0;
- *     gst_structure_get_int (msg-&gt;structure, "buffer-percent", &amp;percent);
+ *     gst_message_parse_buffering (msg, &amp;percent);
  *     g_print ("Buffering (%%u percent done)", percent);
  *     break;
  *   }
  *   ...
  * }
- * </programlisting>
- * Note that application should keep the pipeline in the PAUSED state when a
- * GST_MESSAGE_BUFFERING message is received with a buffer-percent < 100.
- * </para>
+ * ]|
+ * Note that applications should keep/set the pipeline in the PAUSED state when
+ * a BUFFERING message is received with a buffer percent value < 100 and set
+ * the pipeline back to PLAYING state when a BUFFERING message with a value
+ * of 100 percent is received (if PLAYING is the desired state, that is).
+ * </refsect2>
+ * <refsect2>
  * <title>Embedding the video window in your application</title>
- * <para>
  * By default, playbin (or rather the video sinks used) will create their own
  * window. Applications will usually want to force output to a window of their
- * own, however. This can be done using the GstXOverlay interface, which most
+ * own, however. This can be done using the #GstXOverlay interface, which most
  * video sinks implement. See the documentation there for more details.
- * </para>
+ * </refsect2>
+ * <refsect2>
  * <title>Specifying which CD/DVD device to use</title>
- * <para>
  * The device to use for CDs/DVDs needs to be set on the source element
  * playbin creates before it is opened. The only way to do this at the moment
  * is to connect to playbin's "notify::source" signal, which will be emitted
  * property and set it appropriately. In future ways might be added to specify
  * the device as part of the URI, but at the time of writing this is not
  * possible yet.
- * </para>
+ * </refsect2>
+ * <refsect2>
  * <title>Examples</title>
- * <para>
- * Here is a simple pipeline to play back a video or audio file:
- * <programlisting>
+ * |[
  * gst-launch -v playbin uri=file:///path/to/somefile.avi
- * </programlisting>
- * This will play back the given AVI video file, given that the video and
+ * ]| This will play back the given AVI video file, given that the video and
  * audio decoders required to decode the content are installed. Since no
  * special audio sink or video sink is supplied (not possible via gst-launch),
  * playbin will try to find a suitable audio and video sink automatically
  * using the autoaudiosink and autovideosink elements.
- * </para>
- * <para>
- * Here is a another pipeline to play track 4 of an audio CD:
- * <programlisting>
+ * |[
  * gst-launch -v playbin uri=cdda://4
- * </programlisting>
- * This will play back track 4 on an audio CD in your disc drive (assuming
+ * ]| This will play back track 4 on an audio CD in your disc drive (assuming
  * the drive is detected automatically by the plugin).
- * </para>
- * <para>
- * Here is a another pipeline to play title 1 of a DVD:
- * <programlisting>
+ * |[
  * gst-launch -v playbin uri=dvd://1
- * </programlisting>
- * This will play back title 1 of a DVD in your disc drive (assuming
+ * ]| This will play back title 1 of a DVD in your disc drive (assuming
  * the drive is detected automatically by the plugin).
- * </para>
  * </refsect2>
  */
 
 #include <gst/gst.h>
 
 #include <gst/gst-i18n-plugin.h>
+#include <gst/pbutils/pbutils.h>
 
 #include "gstplaybasebin.h"
+#include "gstplayback.h"
 
 GST_DEBUG_CATEGORY_STATIC (gst_play_bin_debug);
 #define GST_CAT_DEFAULT gst_play_bin_debug
@@ -254,11 +242,15 @@ GST_DEBUG_CATEGORY_STATIC (gst_play_bin_debug);
 #define GST_IS_PLAY_BIN_CLASS(klass)    (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PLAY_BIN))
 
 #define VOLUME_MAX_DOUBLE 10.0
-#define CONNECTION_SPEED_DEFAULT 0
 
 typedef struct _GstPlayBin GstPlayBin;
 typedef struct _GstPlayBinClass GstPlayBinClass;
 
+/**
+ * GstPlayBin:
+ *
+ * High-level player element
+ */
 struct _GstPlayBin
 {
   GstPlayBaseBin parent;
@@ -271,6 +263,7 @@ struct _GstPlayBin
   GstElement *pending_visualisation;
   GstElement *volume_element;
   GstElement *textoverlay_element;
+  GstElement *spu_element;
   gfloat volume;
 
   /* these are the currently active sinks */
@@ -285,9 +278,6 @@ struct _GstPlayBin
   /* font description */
   gchar *font_desc;
 
-  /* connection speed in bits/sec (0 = unknown) */
-  guint connection_speed;
-
   /* indication if the pipeline is live */
   gboolean is_live;
 };
@@ -306,8 +296,7 @@ enum
   ARG_VIS_PLUGIN,
   ARG_VOLUME,
   ARG_FRAME,
-  ARG_FONT_DESC,
-  ARG_CONNECTION_SPEED
+  ARG_FONT_DESC
 };
 
 /* signals */
@@ -323,6 +312,10 @@ static void gst_play_bin_dispose (GObject * object);
 static gboolean setup_sinks (GstPlayBaseBin * play_base_bin,
     GstPlayBaseGroup * group);
 static void remove_sinks (GstPlayBin * play_bin);
+static void playbin_set_subtitles_visible (GstPlayBaseBin * play_base_bin,
+    gboolean visible);
+static void playbin_set_audio_mute (GstPlayBaseBin * play_base_bin,
+    gboolean mute);
 
 static void gst_play_bin_set_property (GObject * object, guint prop_id,
     const GValue * value, GParamSpec * spec);
@@ -331,8 +324,6 @@ static void gst_play_bin_get_property (GObject * object, guint prop_id,
 
 static gboolean gst_play_bin_send_event (GstElement * element,
     GstEvent * event);
-static gboolean gst_play_bin_set_clock_func (GstElement * element,
-    GstClock * clock);
 static GstStateChangeReturn gst_play_bin_change_state (GstElement * element,
     GstStateChange transition);
 
@@ -346,7 +337,7 @@ static const GstElementDetails gst_play_bin_details =
 GST_ELEMENT_DETAILS ("Player Bin",
     "Generic/Bin/Player",
     "Autoplug and play media from an uri",
-    "Wim Taymans <wim@fluendo.com>");
+    "Wim Taymans <wim.taymans@gmail.com>");
 
 static GType
 gst_play_bin_get_type (void)
@@ -395,52 +386,49 @@ gst_play_bin_class_init (GstPlayBinClass * klass)
   g_object_class_install_property (gobject_klass, ARG_VIDEO_SINK,
       g_param_spec_object ("video-sink", "Video Sink",
           "the video output element to use (NULL = default sink)",
-          GST_TYPE_ELEMENT, G_PARAM_READWRITE));
+          GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
   g_object_class_install_property (gobject_klass, ARG_AUDIO_SINK,
       g_param_spec_object ("audio-sink", "Audio Sink",
           "the audio output element to use (NULL = default sink)",
-          GST_TYPE_ELEMENT, G_PARAM_READWRITE));
+          GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
   g_object_class_install_property (gobject_klass, ARG_VIS_PLUGIN,
       g_param_spec_object ("vis-plugin", "Vis plugin",
           "the visualization element to use (NULL = none)",
-          GST_TYPE_ELEMENT, G_PARAM_READWRITE));
+          GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+  /**
+   * GstPlayBin:volume:
+   *
+   * Get or set the current audio stream volume. 1.0 means 100%,
+   * 0.0 means mute. This uses a linear volume scale.
+   *
+   */
   g_object_class_install_property (gobject_klass, ARG_VOLUME,
       g_param_spec_double ("volume", "volume", "volume",
-          0.0, VOLUME_MAX_DOUBLE, 1.0, G_PARAM_READWRITE));
+          0.0, VOLUME_MAX_DOUBLE, 1.0,
+          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
   g_object_class_install_property (gobject_klass, ARG_FRAME,
       gst_param_spec_mini_object ("frame", "Frame",
-          "The last frame (NULL = no video available)",
-          GST_TYPE_BUFFER, G_PARAM_READABLE));
+          "The last frame (NULL = no video available)", GST_TYPE_BUFFER,
+          G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
   g_object_class_install_property (gobject_klass, ARG_FONT_DESC,
-      g_param_spec_string ("subtitle-font-desc",
-          "Subtitle font description",
-          "Pango font description of font "
-          "to be used for subtitle rendering", NULL, G_PARAM_WRITABLE));
-  /**
-   * GstPlayBin::connection-speed
-   *
-   * Network connection speed in kbps (0 = unknown)
-   *
-   * Since: 0.10.10
-   **/
-  g_object_class_install_property (gobject_klass, ARG_CONNECTION_SPEED,
-      g_param_spec_uint ("connection-speed", "Connection Speed",
-          "Network connection speed in kbps (0 = unknown)",
-          0, G_MAXUINT, CONNECTION_SPEED_DEFAULT, G_PARAM_READWRITE));
+      g_param_spec_string ("subtitle-font-desc", "Subtitle font description",
+          "Pango font description of font " "to be used for subtitle rendering",
+          NULL, G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
 
-  gobject_klass->dispose = GST_DEBUG_FUNCPTR (gst_play_bin_dispose);
+  gobject_klass->dispose = gst_play_bin_dispose;
 
   gst_element_class_set_details (gstelement_klass, &gst_play_bin_details);
 
   gstelement_klass->change_state =
       GST_DEBUG_FUNCPTR (gst_play_bin_change_state);
   gstelement_klass->send_event = GST_DEBUG_FUNCPTR (gst_play_bin_send_event);
-  gstelement_klass->set_clock = GST_DEBUG_FUNCPTR (gst_play_bin_set_clock_func);
 
   gstbin_klass->handle_message =
       GST_DEBUG_FUNCPTR (gst_play_bin_handle_message);
 
   playbasebin_klass->setup_output_pads = setup_sinks;
+  playbasebin_klass->set_subtitles_visible = playbin_set_subtitles_visible;
+  playbasebin_klass->set_audio_mute = playbin_set_audio_mute;
 }
 
 static void
@@ -452,6 +440,7 @@ gst_play_bin_init (GstPlayBin * play_bin)
   play_bin->pending_visualisation = NULL;
   play_bin->volume_element = NULL;
   play_bin->textoverlay_element = NULL;
+  play_bin->spu_element = NULL;
   play_bin->volume = 1.0;
   play_bin->sinks = NULL;
   play_bin->frame = NULL;
@@ -497,6 +486,10 @@ gst_play_bin_dispose (GObject * object)
     gst_object_unref (play_bin->textoverlay_element);
     play_bin->textoverlay_element = NULL;
   }
+  if (play_bin->spu_element != NULL) {
+    gst_object_unref (play_bin->spu_element);
+    play_bin->spu_element = NULL;
+  }
   g_free (play_bin->font_desc);
   play_bin->font_desc = NULL;
 
@@ -507,7 +500,11 @@ static void
 gst_play_bin_vis_unblocked (GstPad * tee_pad, gboolean blocked,
     gpointer user_data)
 {
-  /* Unblocked */
+  GstPlayBin *play_bin = GST_PLAY_BIN (user_data);
+
+  if (play_bin->pending_visualisation)
+    gst_pad_set_blocked_async (tee_pad, FALSE, gst_play_bin_vis_unblocked,
+        play_bin);
 }
 
 static void
@@ -518,23 +515,29 @@ gst_play_bin_vis_blocked (GstPad * tee_pad, gboolean blocked,
   GstBin *vis_bin = NULL;
   GstPad *vis_sink_pad = NULL, *vis_src_pad = NULL, *vqueue_pad = NULL;
   GstState bin_state;
+  GstElement *pending_visualisation;
+
+  GST_OBJECT_LOCK (play_bin);
+  pending_visualisation = play_bin->pending_visualisation;
+  play_bin->pending_visualisation = NULL;
+  GST_OBJECT_UNLOCK (play_bin);
 
   /* We want to disable visualisation */
-  if (!GST_IS_ELEMENT (play_bin->pending_visualisation)) {
+  if (!GST_IS_ELEMENT (pending_visualisation)) {
     /* Set visualisation element to READY */
     gst_element_set_state (play_bin->visualisation, GST_STATE_READY);
     goto beach;
   }
 
   vis_bin =
-      GST_BIN_CAST (gst_object_get_parent (GST_OBJECT_CAST (play_bin->
-              visualisation)));
+      GST_BIN_CAST (gst_object_get_parent (GST_OBJECT_CAST
+          (play_bin->visualisation)));
 
   if (!GST_IS_BIN (vis_bin) || !GST_IS_PAD (tee_pad)) {
     goto beach;
   }
 
-  vis_src_pad = gst_element_get_pad (play_bin->visualisation, "src");
+  vis_src_pad = gst_element_get_static_pad (play_bin->visualisation, "src");
   vis_sink_pad = gst_pad_get_peer (tee_pad);
 
   /* Can be fakesink */
@@ -569,17 +572,16 @@ gst_play_bin_vis_blocked (GstPad * tee_pad, gboolean blocked,
   /* And loose our ref */
   gst_object_unref (play_bin->visualisation);
 
-  if (play_bin->pending_visualisation) {
+  if (pending_visualisation) {
     /* Ref this new visualisation element before adding to the bin */
-    gst_object_ref (play_bin->pending_visualisation);
+    gst_object_ref (pending_visualisation);
     /* Add the new one */
-    gst_bin_add (vis_bin, play_bin->pending_visualisation);
+    gst_bin_add (vis_bin, pending_visualisation);
     /* Synchronizing state */
-    gst_element_set_state (play_bin->pending_visualisation, bin_state);
+    gst_element_set_state (pending_visualisation, bin_state);
 
-    vis_sink_pad = gst_element_get_pad (play_bin->pending_visualisation,
-        "sink");
-    vis_src_pad = gst_element_get_pad (play_bin->pending_visualisation, "src");
+    vis_sink_pad = gst_element_get_static_pad (pending_visualisation, "sink");
+    vis_src_pad = gst_element_get_static_pad (pending_visualisation, "src");
 
     if (!GST_IS_PAD (vis_sink_pad) || !GST_IS_PAD (vis_src_pad)) {
       goto beach;
@@ -592,8 +594,7 @@ gst_play_bin_vis_blocked (GstPad * tee_pad, gboolean blocked,
 
   /* We are done */
   gst_object_unref (play_bin->visualisation);
-  play_bin->visualisation = play_bin->pending_visualisation;
-  play_bin->pending_visualisation = NULL;
+  play_bin->visualisation = pending_visualisation;
 
 beach:
   if (vis_sink_pad) {
@@ -633,7 +634,7 @@ gst_play_bin_set_property (GObject * object, guint prop_id,
         gst_object_sink (GST_OBJECT_CAST (play_bin->video_sink));
       }
       /* when changing the videosink, we just remove the
-       * video pipeline from the cache so that it will be 
+       * video pipeline from the cache so that it will be
        * regenerated with the new sink element */
       g_hash_table_remove (play_bin->cache, "vbin");
       break;
@@ -650,38 +651,37 @@ gst_play_bin_set_property (GObject * object, guint prop_id,
       break;
     case ARG_VIS_PLUGIN:
     {
+      GstElement *pending_visualisation =
+          GST_ELEMENT_CAST (g_value_get_object (value));
+
+      /* Take ownership */
+      if (pending_visualisation) {
+        gst_object_ref (pending_visualisation);
+        gst_object_sink (pending_visualisation);
+      }
+
       /* Do we already have a visualisation change pending ? */
+      GST_OBJECT_LOCK (play_bin);
       if (play_bin->pending_visualisation) {
         gst_object_unref (play_bin->pending_visualisation);
-        play_bin->pending_visualisation = g_value_get_object (value);
-        /* Take ownership */
-        if (play_bin->pending_visualisation) {
-          gst_object_ref (play_bin->pending_visualisation);
-          gst_object_sink (GST_OBJECT_CAST (play_bin->pending_visualisation));
-        }
+        play_bin->pending_visualisation = pending_visualisation;
+        GST_OBJECT_UNLOCK (play_bin);
       } else {
-        play_bin->pending_visualisation = g_value_get_object (value);
-
-        /* Take ownership */
-        if (play_bin->pending_visualisation) {
-          gst_object_ref (play_bin->pending_visualisation);
-          gst_object_sink (GST_OBJECT_CAST (play_bin->pending_visualisation));
-        }
-
+        GST_OBJECT_UNLOCK (play_bin);
         /* Was there a visualisation already set ? */
         if (play_bin->visualisation != NULL) {
           GstBin *vis_bin = NULL;
 
           vis_bin =
-              GST_BIN_CAST (gst_object_get_parent (GST_OBJECT_CAST (play_bin->
-                      visualisation)));
+              GST_BIN_CAST (gst_object_get_parent (GST_OBJECT_CAST
+                  (play_bin->visualisation)));
 
           /* Check if the visualisation is already in a bin */
           if (GST_IS_BIN (vis_bin)) {
             GstPad *vis_sink_pad = NULL, *tee_pad = NULL;
 
             /* Now get tee pad and block it async */
-            vis_sink_pad = gst_element_get_pad (play_bin->visualisation,
+            vis_sink_pad = gst_element_get_static_pad (play_bin->visualisation,
                 "sink");
             if (!GST_IS_PAD (vis_sink_pad)) {
               goto beach;
@@ -691,6 +691,7 @@ gst_play_bin_set_property (GObject * object, guint prop_id,
               goto beach;
             }
 
+            play_bin->pending_visualisation = pending_visualisation;
             /* Block with callback */
             gst_pad_set_blocked_async (tee_pad, TRUE, gst_play_bin_vis_blocked,
                 play_bin);
@@ -703,12 +704,10 @@ gst_play_bin_set_property (GObject * object, guint prop_id,
             }
             gst_object_unref (vis_bin);
           } else {
-            play_bin->visualisation = play_bin->pending_visualisation;
-            play_bin->pending_visualisation = NULL;
+            play_bin->visualisation = pending_visualisation;
           }
         } else {
-          play_bin->visualisation = play_bin->pending_visualisation;
-          play_bin->pending_visualisation = NULL;
+          play_bin->visualisation = pending_visualisation;
         }
       }
       break;
@@ -728,9 +727,6 @@ gst_play_bin_set_property (GObject * object, guint prop_id,
             "font-desc", g_value_get_string (value), NULL);
       }
       break;
-    case ARG_CONNECTION_SPEED:
-      play_bin->connection_speed = g_value_get_uint (value) * 1000;
-      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -758,12 +754,13 @@ gst_play_bin_get_property (GObject * object, guint prop_id, GValue * value,
     case ARG_VOLUME:
       g_value_set_double (value, play_bin->volume);
       break;
-    case ARG_FRAME:
-      gst_value_set_mini_object (value, GST_MINI_OBJECT (play_bin->frame));
-      break;
-    case ARG_CONNECTION_SPEED:
-      g_value_set_uint (value, play_bin->connection_speed / 1000);
+    case ARG_FRAME:{
+      GstBuffer *cur_frame = NULL;
+
+      gst_buffer_replace (&cur_frame, play_bin->frame);
+      gst_value_take_buffer (value, cur_frame);
       break;
+    }
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -777,21 +774,28 @@ static void
 handoff (GstElement * identity, GstBuffer * frame, gpointer data)
 {
   GstPlayBin *play_bin = GST_PLAY_BIN (data);
-  GstBuffer **frame_p = &play_bin->frame;
-
-  gst_mini_object_replace ((GstMiniObject **) frame_p,
-      GST_MINI_OBJECT_CAST (frame));
 
   /* applications need to know the buffer caps,
    * make sure they are always set on the frame */
-  if (GST_BUFFER_CAPS (play_bin->frame) == NULL) {
+  if (GST_BUFFER_CAPS (frame) == NULL) {
     GstPad *pad;
 
-    if ((pad = gst_element_get_pad (identity, "sink"))) {
-      gst_buffer_set_caps (play_bin->frame, GST_PAD_CAPS (pad));
+    if ((pad = gst_element_get_static_pad (identity, "sink"))) {
+      gst_buffer_set_caps (frame, GST_PAD_CAPS (pad));
       gst_object_unref (pad);
     }
   }
+
+  gst_buffer_replace (&play_bin->frame, frame);
+}
+
+static void
+post_missing_element_message (GstPlayBin * playbin, const gchar * name)
+{
+  GstMessage *msg;
+
+  msg = gst_missing_element_message_new (GST_ELEMENT_CAST (playbin), name);
+  gst_element_post_message (GST_ELEMENT_CAST (playbin), msg);
 }
 
 /* make the element (bin) that contains the elements needed to perform
@@ -865,7 +869,7 @@ gen_video_element (GstPlayBin * play_bin)
   if (!gst_element_link_pads (scale, "src", sink, NULL))
     goto link_failed;
 
-  pad = gst_element_get_pad (identity, "sink");
+  pad = gst_element_get_static_pad (identity, "sink");
   gst_element_add_pad (element, gst_ghost_pad_new ("sink", pad));
   gst_object_unref (pad);
 
@@ -881,8 +885,7 @@ gen_video_element (GstPlayBin * play_bin)
   /* ERRORS */
 no_sinks:
   {
-    /* FIXME: this warrants adding a CORE error category for missing
-     * elements/plugins */
+    post_missing_element_message (play_bin, "autovideosink");
     GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
         (_("Both autovideosink and xvimagesink elements are missing.")),
         (NULL));
@@ -890,6 +893,7 @@ no_sinks:
   }
 no_colorspace:
   {
+    post_missing_element_message (play_bin, "ffmpegcolorspace");
     GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
         (_("Missing element '%s' - check your GStreamer installation."),
             "ffmpegcolorspace"), (NULL));
@@ -899,6 +903,7 @@ no_colorspace:
 
 no_videoscale:
   {
+    post_missing_element_message (play_bin, "videoscale");
     GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
         (_("Missing element '%s' - check your GStreamer installation."),
             "videoscale"), ("possibly a liboil version mismatch?"));
@@ -920,7 +925,7 @@ link_failed:
  *  | tbin                  +-------------+            |
  *  |          +-----+      | textoverlay |   +------+ |
  *  |          | csp | +--video_sink      |   | vbin | |
- * video_sink-sink  src+ +-text_sink     src-sink    | |
+ * video_sink-sink  src+ +-text_sink    src---sink   | |
  *  |          +-----+   |  +-------------+   +------+ |
  * text_sink-------------+                             |
  *  +--------------------------------------------------+
@@ -929,16 +934,11 @@ link_failed:
  *  videosink without the text_sink pad.
  */
 static GstElement *
-gen_text_element (GstPlayBin * play_bin)
+add_text_element (GstPlayBin * play_bin, GstElement * vbin)
 {
-  GstElement *element, *csp, *overlay, *vbin;
+  GstElement *element, *csp, *overlay;
   GstPad *pad;
 
-  /* Create the video rendering bin, error is posted when this fails. */
-  vbin = gen_video_element (play_bin);
-  if (!vbin)
-    return NULL;
-
   /* Text overlay */
   overlay = gst_element_factory_make ("textoverlay", "overlay");
 
@@ -970,14 +970,21 @@ gen_text_element (GstPlayBin * play_bin)
   gst_element_link_pads (overlay, "src", vbin, "sink");
 
   /* Add ghost pads on the subtitle bin */
-  pad = gst_element_get_pad (overlay, "text_sink");
+  pad = gst_element_get_static_pad (overlay, "text_sink");
   gst_element_add_pad (element, gst_ghost_pad_new ("text_sink", pad));
   gst_object_unref (pad);
 
-  pad = gst_element_get_pad (csp, "sink");
+  pad = gst_element_get_static_pad (csp, "sink");
   gst_element_add_pad (element, gst_ghost_pad_new ("sink", pad));
   gst_object_unref (pad);
 
+  /* If the vbin provides a subpicture sink pad, ghost it too */
+  pad = gst_element_get_static_pad (vbin, "subpicture_sink");
+  if (pad) {
+    gst_element_add_pad (element, gst_ghost_pad_new ("subpicture_sink", pad));
+    gst_object_unref (pad);
+  }
+
   /* Set state to READY */
   gst_element_set_state (element, GST_STATE_READY);
 
@@ -986,12 +993,81 @@ gen_text_element (GstPlayBin * play_bin)
   /* ERRORS */
 no_overlay:
   {
+    post_missing_element_message (play_bin, "textoverlay");
     GST_WARNING_OBJECT (play_bin,
         "No overlay (pango) element, subtitles disabled");
     return vbin;
   }
 }
 
+/* make an element for rendering DVD subpictures onto output video
+ *
+ *  +---------------------------------------------+
+ *  | tbin                   +--------+           |
+ *  |          +-----+       |        |  +------+ |
+ *  |          | csp | src-videosink  |  | vbin | |
+ * video_sink-sink  src+     |       src-sink   | |
+ *  |          +-----+   +subpicture  |  +------+ |
+ * subpicture_pad--------+   +--------+           |
+ *  +---------- ----------------------------------+
+ *
+ */
+static GstElement *
+add_spu_element (GstPlayBin * play_bin, GstElement * vbin)
+{
+  GstElement *element, *csp, *overlay;
+  GstPad *pad;
+
+  /* DVD spu overlay */
+  GST_DEBUG_OBJECT (play_bin, "Attempting to insert DVD SPU element");
+
+  overlay = gst_element_factory_make ("dvdspu", "overlay");
+
+  /* If no overlay return the video bin without subpicture support. */
+  if (!overlay)
+    goto no_overlay;
+
+  /* Create our bin */
+  element = gst_bin_new ("spubin");
+
+  /* Take a ref */
+  play_bin->spu_element = GST_ELEMENT_CAST (gst_object_ref (overlay));
+
+  /* we know this will succeed, as the video bin already created one before */
+  csp = gst_element_factory_make ("ffmpegcolorspace", "spucsp");
+
+  /* Add our elements */
+  gst_bin_add_many (GST_BIN_CAST (element), csp, overlay, vbin, NULL);
+
+  /* Link */
+  gst_element_link_pads (csp, "src", overlay, "video");
+  gst_element_link_pads (overlay, "src", vbin, "sink");
+
+  /* Add ghost pad on the subpicture bin so it looks like vbin */
+  pad = gst_element_get_static_pad (csp, "sink");
+  gst_element_add_pad (element, gst_ghost_pad_new ("sink", pad));
+  gst_object_unref (pad);
+
+  pad = gst_element_get_static_pad (overlay, "subpicture");
+  gst_element_add_pad (element, gst_ghost_pad_new ("subpicture_sink", pad));
+  gst_object_unref (pad);
+
+  /* Set state to READY */
+  gst_element_set_state (element, GST_STATE_READY);
+
+  return element;
+
+  /* ERRORS */
+no_overlay:
+  {
+    post_missing_element_message (play_bin, "dvdspu");
+    GST_WARNING_OBJECT (play_bin,
+        "No DVD overlay (dvdspu) element. "
+        "menu highlight/subtitles unavailable");
+    return vbin;
+  }
+}
+
 /* make the element (bin) that contains the elements needed to perform
  * audio playback.
  *
@@ -1049,8 +1125,10 @@ gen_audio_element (GstPlayBin * play_bin)
   gst_bin_add (GST_BIN_CAST (element), scale);
 
   volume = gst_element_factory_make ("volume", "volume");
+  if (volume == NULL)
+    goto no_volume;
   g_object_set (G_OBJECT (volume), "volume", play_bin->volume, NULL);
-  play_bin->volume_element = volume;
+  play_bin->volume_element = GST_ELEMENT_CAST (gst_object_ref (volume));
   gst_bin_add (GST_BIN_CAST (element), volume);
 
   res = gst_element_link_pads (conv, "src", scale, "sink");
@@ -1059,7 +1137,7 @@ gen_audio_element (GstPlayBin * play_bin)
   if (!res)
     goto link_failed;
 
-  pad = gst_element_get_pad (conv, "sink");
+  pad = gst_element_get_static_pad (conv, "sink");
   gst_element_add_pad (element, gst_ghost_pad_new ("sink", pad));
   gst_object_unref (pad);
 
@@ -1075,27 +1153,38 @@ gen_audio_element (GstPlayBin * play_bin)
   /* ERRORS */
 no_sinks:
   {
+    post_missing_element_message (play_bin, "autoaudiosink");
     GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
         (_("Both autoaudiosink and alsasink elements are missing.")), (NULL));
     return NULL;
   }
 no_audioconvert:
   {
+    post_missing_element_message (play_bin, "audioconvert");
     GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
         (_("Missing element '%s' - check your GStreamer installation."),
             "audioconvert"), ("possibly a liboil version mismatch?"));
     gst_object_unref (element);
     return NULL;
   }
-
 no_audioresample:
   {
+    post_missing_element_message (play_bin, "audioresample");
     GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
         (_("Missing element '%s' - check your GStreamer installation."),
             "audioresample"), ("possibly a liboil version mismatch?"));
     gst_object_unref (element);
     return NULL;
   }
+no_volume:
+  {
+    post_missing_element_message (play_bin, "volume");
+    GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
+        (_("Missing element '%s' - check your GStreamer installation."),
+            "volume"), ("possibly a liboil version mismatch?"));
+    gst_object_unref (element);
+    return NULL;
+  }
 link_failed:
   {
     GST_ELEMENT_ERROR (play_bin, CORE, PAD,
@@ -1106,27 +1195,27 @@ link_failed:
 }
 
 /* make the element (bin) that contains the elements needed to perform
- * visualisation ouput.  The idea is to split the audio using tee, then 
+ * visualisation ouput.  The idea is to split the audio using tee, then
  * sending the output to the regular audio bin and the other output to
  * the vis plugin that transforms it into a video that is rendered with the
- * normal video bin. The video bin is run in a thread to make sure it does
- * not block the audio playback pipeline.
+ * normal video bin. The video and audio bins are run in threads to make sure
+ * they don't block eachother.
  *
- *  +--------------------------------------------------------------------+
- *  | visbin                                                             |
- *  |      +------+   +--------+   +----------------+                    |
- *  |      | tee  |   | aqueue |   |   abin ...     |                    |
- *  |   +-sink   src-sink     src-sink              |                    |
- *  |   |  |      |   +--------+   +----------------+                    |
- *  |   |  |      |                                                      |
- *  |   |  |      |   +------+   +---------+   +------+   +-----------+  |
- *  |   |  |      |   |vqueue|   |audioconv|   | vis  |   | vbin ...  |  |
- *  |   |  |     src-sink   src-sink      src-sink   src-sink         |  |
- *  |   |  |      |   +------+   +---------+   +------+   +-----------+  |
- *  |   |  |      |                                                      |
- *  |   |  +------+                                                      |
- * sink-+                                                                |
  +---------------------------------------------------------------------+
+ *  +-----------------------------------------------------------------------+
+ *  | visbin                                                                |
+ *  |      +------+   +--------+   +----------------+                       |
+ *  |      | tee  |   | aqueue |   |   abin ...     |                       |
+ *  |   +-sink   src-sink     src-sink              |                       |
+ *  |   |  |      |   +--------+   +----------------+                       |
+ *  |   |  |      |                                                         |
+ *  |   |  |      |   +------+   +------------+   +------+   +-----------+  |
+ *  |   |  |      |   |vqueue|   | audioconv  |   | vis  |   | vbin ...  |  |
+ *  |   |  |     src-sink   src-sink + samp  src-sink   src-sink         |  |
+ *  |   |  |      |   +------+   +------------+   +------+   +-----------+  |
+ *  |   |  |      |                                                         |
+ *  |   |  +------+                                                         |
+ * sink-+                                                                   |
*  +-----------------------------------------------------------------------+
  */
 static GstElement *
 gen_vis_element (GstPlayBin * play_bin)
@@ -1137,6 +1226,8 @@ gen_vis_element (GstPlayBin * play_bin)
   GstElement *asink;
   GstElement *vsink;
   GstElement *conv;
+  GstElement *resamp;
+  GstElement *conv2;
   GstElement *vis;
   GstElement *vqueue, *aqueue;
   GstPad *pad, *rpad;
@@ -1168,6 +1259,16 @@ gen_vis_element (GstPlayBin * play_bin)
     goto no_audioconvert;
   gst_bin_add (GST_BIN_CAST (element), conv);
 
+  resamp = gst_element_factory_make ("audioresample", "aresamp");
+  if (resamp == NULL)
+    goto no_audioresample;
+  gst_bin_add (GST_BIN_CAST (element), resamp);
+
+  conv2 = gst_element_factory_make ("audioconvert", "aconv2");
+  if (conv2 == NULL)
+    goto no_audioconvert;
+  gst_bin_add (GST_BIN_CAST (element), conv2);
+
   if (play_bin->visualisation) {
     gst_object_ref (play_bin->visualisation);
     vis = play_bin->visualisation;
@@ -1179,25 +1280,27 @@ gen_vis_element (GstPlayBin * play_bin)
   gst_bin_add (GST_BIN_CAST (element), vis);
 
   res = gst_element_link_pads (vqueue, "src", conv, "sink");
-  res &= gst_element_link_pads (conv, "src", vis, "sink");
+  res &= gst_element_link_pads (conv, "src", resamp, "sink");
+  res &= gst_element_link_pads (resamp, "src", conv2, "sink");
+  res &= gst_element_link_pads (conv2, "src", vis, "sink");
   res &= gst_element_link_pads (vis, "src", vsink, "sink");
   if (!res)
     goto link_failed;
 
-  pad = gst_element_get_pad (aqueue, "sink");
+  pad = gst_element_get_static_pad (aqueue, "sink");
   rpad = gst_element_get_request_pad (tee, "src%d");
   gst_pad_link (rpad, pad);
   gst_object_unref (rpad);
   gst_object_unref (pad);
   gst_element_link_pads (aqueue, "src", asink, "sink");
 
-  pad = gst_element_get_pad (vqueue, "sink");
+  pad = gst_element_get_static_pad (vqueue, "sink");
   rpad = gst_element_get_request_pad (tee, "src%d");
   gst_pad_link (rpad, pad);
   gst_object_unref (rpad);
   gst_object_unref (pad);
 
-  pad = gst_element_get_pad (tee, "sink");
+  pad = gst_element_get_static_pad (tee, "sink");
   gst_element_add_pad (element, gst_ghost_pad_new ("sink", pad));
   gst_object_unref (pad);
 
@@ -1206,14 +1309,25 @@ gen_vis_element (GstPlayBin * play_bin)
   /* ERRORS */
 no_audioconvert:
   {
+    post_missing_element_message (play_bin, "audioconvert");
     GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
         (_("Missing element '%s' - check your GStreamer installation."),
             "audioconvert"), ("possibly a liboil version mismatch?"));
     gst_object_unref (element);
     return NULL;
   }
+no_audioresample:
+  {
+    post_missing_element_message (play_bin, "audioresample");
+    GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
+        (_("Missing element '%s' - check your GStreamer installation."),
+            "audioresample"), (NULL));
+    gst_object_unref (element);
+    return NULL;
+  }
 no_goom:
   {
+    post_missing_element_message (play_bin, "goom");
     GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
         (_("Missing element '%s' - check your GStreamer installation."),
             "goom"), (NULL));
@@ -1254,7 +1368,7 @@ remove_sinks (GstPlayBin * play_bin)
       gst_bin_remove (GST_BIN_CAST (parent), element);
       gst_object_unref (parent);
     }
-    pad = gst_element_get_pad (element, "sink");
+    pad = gst_element_get_static_pad (element, "sink");
     if (pad != NULL) {
       peer = gst_pad_get_peer (pad);
       if (peer != NULL) {
@@ -1273,7 +1387,7 @@ remove_sinks (GstPlayBin * play_bin)
       gst_bin_remove (GST_BIN_CAST (parent), element);
       gst_object_unref (parent);
     }
-    pad = gst_element_get_pad (element, "sink");
+    pad = gst_element_get_static_pad (element, "sink");
     if (pad != NULL) {
       peer = gst_pad_get_peer (pad);
       if (peer != NULL) {
@@ -1289,7 +1403,7 @@ remove_sinks (GstPlayBin * play_bin)
     GstPad *pad;
     GstPad *peer;
 
-    pad = gst_element_get_pad (element, "sink");
+    pad = gst_element_get_static_pad (element, "sink");
 
     GST_LOG ("removing sink %p", element);
 
@@ -1329,13 +1443,18 @@ remove_sinks (GstPlayBin * play_bin)
     gst_object_unref (play_bin->textoverlay_element);
     play_bin->textoverlay_element = NULL;
   }
+
+  if (play_bin->volume_element) {
+    gst_object_unref (play_bin->volume_element);
+    play_bin->volume_element = NULL;
+  }
 }
 
 /* loop over the streams and set up the pipeline to play this
  * media file. First we count the number of audio and video streams.
  * If there is no video stream but there exists an audio stream,
  * we install a visualisation pipeline.
- * 
+ *
  * Also make sure to only connect the first audio and video pad. FIXME
  * this should eventually be handled with a tuner interface so that
  * one can switch the streams.
@@ -1354,35 +1473,26 @@ add_sink (GstPlayBin * play_bin, GstElement * sink, GstPad * srcpad,
 
   g_return_val_if_fail (sink != NULL, FALSE);
 
-  /* For live pipelines we need to add the bin in the same state as the 
-   * parent so that it starts as soon as it is prerolled. */
-  if (play_bin->is_live)
-    state = GST_STATE_PLAYING;
-  else
-    state = GST_STATE_PAUSED;
+  state = GST_STATE_PAUSED;
 
   /* this is only for debugging */
   parent = gst_pad_get_parent_element (srcpad);
   if (parent) {
-    GST_DEBUG ("Adding sink with state %d (parent: %d, peer: %d)",
+    GST_DEBUG ("Adding sink %" GST_PTR_FORMAT
+        " with state %d (parent: %d, peer: %d)", sink,
         GST_STATE (sink), GST_STATE (play_bin), GST_STATE (parent));
     gst_object_unref (parent);
   }
   gst_bin_add (GST_BIN_CAST (play_bin), sink);
 
-  /* for live pipelines, disable the sync in the sinks until core handles this
-   * correctly. */
-  if (play_bin->is_live)
-    gst_element_set_clock (sink, NULL);
-
-  /* bring it to the PAUSED state so we can link to the peer without
+  /* bring it to the required state so we can link to the peer without
    * breaking the flow */
   stateret = gst_element_set_state (sink, state);
   if (stateret == GST_STATE_CHANGE_FAILURE)
     goto state_failed;
 
   /* we found a sink for this stream, now try to install it */
-  sinkpad = gst_element_get_pad (sink, "sink");
+  sinkpad = gst_element_get_static_pad (sink, "sink");
   linkres = gst_pad_link (srcpad, sinkpad);
   gst_object_unref (sinkpad);
 
@@ -1391,7 +1501,7 @@ add_sink (GstPlayBin * play_bin, GstElement * sink, GstPad * srcpad,
     goto link_failed;
 
   if (GST_IS_PAD (subtitle_pad)) {
-    sinkpad = gst_element_get_pad (sink, "text_sink");
+    sinkpad = gst_element_get_static_pad (sink, "text_sink");
     linkres = gst_pad_link (subtitle_pad, sinkpad);
     gst_object_unref (sinkpad);
   }
@@ -1436,16 +1546,12 @@ link_failed:
   }
 subtitle_failed:
   {
-    gchar *capsstr;
     GstCaps *caps;
 
     /* could not link this stream */
     caps = gst_pad_get_caps (subtitle_pad);
-    capsstr = gst_caps_to_string (caps);
-    GST_DEBUG_OBJECT (play_bin,
-        "subtitle link failed when adding sink, caps %s, reason %d", capsstr,
-        linkres);
-    g_free (capsstr);
+    GST_WARNING_OBJECT (play_bin, "subtitle link failed when adding sink, "
+        "caps = %" GST_PTR_FORMAT ", reason %d", caps, linkres);
     gst_caps_unref (caps);
 
     /* not fatal */
@@ -1453,14 +1559,20 @@ subtitle_failed:
   }
 }
 
+static void
+dummy_blocked_cb (GstPad * pad, gboolean blocked, gpointer user_data)
+{
+}
+
 static gboolean
 setup_sinks (GstPlayBaseBin * play_base_bin, GstPlayBaseGroup * group)
 {
   GstPlayBin *play_bin = GST_PLAY_BIN (play_base_bin);
-  GList *streaminfo = NULL, *s;
+  gboolean have_video = FALSE;
   gboolean need_vis = FALSE;
   gboolean need_text = FALSE;
-  GstPad *textsrcpad = NULL, *pad = NULL;
+  gboolean need_spu = FALSE;
+  GstPad *textsrcpad = NULL, *pad = NULL, *origtextsrcpad = NULL;
   GstElement *sink;
   gboolean res = TRUE;
 
@@ -1471,25 +1583,18 @@ setup_sinks (GstPlayBaseBin * play_base_bin, GstPlayBaseGroup * group)
   GST_DEBUG_OBJECT (play_base_bin, "setupsinks");
 
   /* find out what to do */
-  if (group->type[GST_STREAM_TYPE_VIDEO - 1].npads > 0 &&
-      group->type[GST_STREAM_TYPE_TEXT - 1].npads > 0) {
+  have_video = (group->type[GST_STREAM_TYPE_VIDEO - 1].npads > 0);
+  need_spu = (group->type[GST_STREAM_TYPE_SUBPICTURE - 1].npads != 0);
+
+  if (have_video && group->type[GST_STREAM_TYPE_TEXT - 1].npads > 0) {
     need_text = TRUE;
-  } else if (group->type[GST_STREAM_TYPE_VIDEO - 1].npads == 0 &&
+  } else if (!have_video &&
       group->type[GST_STREAM_TYPE_AUDIO - 1].npads > 0 &&
       play_bin->visualisation != NULL) {
     need_vis = TRUE;
   }
 
   /* now actually connect everything */
-  g_object_get (G_OBJECT (play_base_bin), "stream-info", &streaminfo, NULL);
-  for (s = streaminfo; s; s = g_list_next (s)) {
-    GObject *obj = G_OBJECT (s->data);
-    gint type;
-    GstObject *object;
-
-    g_object_get (obj, "type", &type, NULL);
-    g_object_get (obj, "object", &object, NULL);
-  }
 
   /* link audio */
   if (group->type[GST_STREAM_TYPE_AUDIO - 1].npads > 0) {
@@ -1501,22 +1606,35 @@ setup_sinks (GstPlayBaseBin * play_base_bin, GstPlayBaseGroup * group)
     if (!sink)
       return FALSE;
 
-    pad = gst_element_get_pad (group->type[GST_STREAM_TYPE_AUDIO - 1].preroll,
-        "src");
+    pad =
+        gst_element_get_static_pad (group->type[GST_STREAM_TYPE_AUDIO -
+            1].preroll, "src");
     res = add_sink (play_bin, sink, pad, NULL);
     gst_object_unref (pad);
   }
 
   /* link video */
-  if (group->type[GST_STREAM_TYPE_VIDEO - 1].npads > 0) {
+  if (have_video) {
+    /* Create the video rendering bin, error is posted when this fails. */
+    sink = gen_video_element (play_bin);
+    if (!sink)
+      return FALSE;
+    if (need_spu) {
+      sink = add_spu_element (play_bin, sink);
+    }
+
     if (need_text) {
       GstObject *parent = NULL, *grandparent = NULL;
       GstPad *ghost = NULL;
 
-      sink = gen_text_element (play_bin);
+      /* Add the subtitle overlay element into the video sink */
+      sink = add_text_element (play_bin, sink);
+
+      /* Link the incoming subtitle stream into the output bin */
       textsrcpad =
-          gst_element_get_pad (group->type[GST_STREAM_TYPE_TEXT - 1].preroll,
-          "src");
+          gst_element_get_static_pad (group->type[GST_STREAM_TYPE_TEXT -
+              1].preroll, "src");
+
       /* This pad is from subtitle-bin, we need to create a ghost pad to have
          common grandparents */
       parent = gst_object_get_parent (GST_OBJECT_CAST (textsrcpad));
@@ -1541,6 +1659,11 @@ setup_sinks (GstPlayBaseBin * play_base_bin, GstPlayBaseGroup * group)
       if (!GST_IS_PLAY_BIN (grandparent)) {
         GST_DEBUG_OBJECT (textsrcpad, "this subtitle pad is from a subtitle "
             "file, ghosting to a suitable hierarchy");
+        /* Block the pad first, because as soon as we add a ghostpad, the queue
+         * will try and start pushing */
+        gst_pad_set_blocked_async (textsrcpad, TRUE, dummy_blocked_cb, NULL);
+        origtextsrcpad = gst_object_ref (textsrcpad);
+
         ghost = gst_ghost_pad_new ("text_src", textsrcpad);
         if (!GST_IS_PAD (ghost)) {
           GST_WARNING_OBJECT (textsrcpad, "failed creating ghost pad for "
@@ -1552,11 +1675,13 @@ setup_sinks (GstPlayBaseBin * play_base_bin, GstPlayBaseGroup * group)
           goto beach;
         }
 
+        gst_pad_set_active (ghost, TRUE);
         if (gst_element_add_pad (GST_ELEMENT_CAST (grandparent), ghost)) {
           gst_object_unref (textsrcpad);
           textsrcpad = gst_object_ref (ghost);
         } else {
           GST_WARNING_OBJECT (ghost, "failed adding ghost pad on subtitle-bin");
+          gst_pad_set_active (ghost, FALSE);
           gst_object_unref (ghost);
           gst_object_unref (textsrcpad);
           textsrcpad = NULL;
@@ -1568,18 +1693,45 @@ setup_sinks (GstPlayBaseBin * play_base_bin, GstPlayBaseGroup * group)
 
       gst_object_unref (parent);
       gst_object_unref (grandparent);
-    } else {
-      sink = gen_video_element (play_bin);
     }
   beach:
     if (!sink)
       return FALSE;
-    pad = gst_element_get_pad (group->type[GST_STREAM_TYPE_VIDEO - 1].preroll,
-        "src");
+    pad =
+        gst_element_get_static_pad (group->type[GST_STREAM_TYPE_VIDEO -
+            1].preroll, "src");
     res = add_sink (play_bin, sink, pad, textsrcpad);
     gst_object_unref (pad);
     if (textsrcpad)
       gst_object_unref (textsrcpad);
+    if (origtextsrcpad) {
+      gst_pad_set_blocked_async (origtextsrcpad, FALSE, dummy_blocked_cb, NULL);
+      gst_object_unref (origtextsrcpad);
+    }
+
+    /* If we have a DVD subpicture stream, link it to the SPU now */
+    if (need_spu) {
+      GstPad *subpic_pad;
+      GstPad *spu_sink_pad;
+
+      subpic_pad =
+          gst_element_get_static_pad (group->type[GST_STREAM_TYPE_SUBPICTURE
+              - 1].preroll, "src");
+      spu_sink_pad = gst_element_get_static_pad (sink, "subpicture_sink");
+      if (subpic_pad && spu_sink_pad) {
+        GST_LOG_OBJECT (play_bin, "Linking DVD subpicture stream onto SPU");
+        gst_pad_set_blocked_async (subpic_pad, TRUE, dummy_blocked_cb, NULL);
+        if (gst_pad_link (subpic_pad, spu_sink_pad) != GST_PAD_LINK_OK) {
+          GST_WARNING_OBJECT (play_bin,
+              "Failed to link DVD subpicture stream onto SPU");
+        }
+        gst_pad_set_blocked_async (subpic_pad, FALSE, dummy_blocked_cb, NULL);
+      }
+      if (subpic_pad)
+        gst_object_unref (subpic_pad);
+      if (spu_sink_pad)
+        gst_object_unref (spu_sink_pad);
+    }
   }
 
   /* remove the sinks now, pipeline get_state will now wait for the
@@ -1593,6 +1745,30 @@ setup_sinks (GstPlayBaseBin * play_base_bin, GstPlayBaseGroup * group)
   return res;
 }
 
+static void
+playbin_set_subtitles_visible (GstPlayBaseBin * play_base_bin, gboolean visible)
+{
+  GstPlayBin *playbin = GST_PLAY_BIN (play_base_bin);
+
+  /* we're ignoring the case of someone setting the 'current-text' property
+   * before textoverlay is set up (which is probably okay, since playbasebin
+   * will just select the first subtitle stream as active stream regardless) */
+  if (playbin->textoverlay_element != NULL) {
+    GST_LOG_OBJECT (playbin, "setting subtitle visibility to %d", visible);
+    g_object_set (playbin->textoverlay_element, "silent", !visible, NULL);
+  }
+}
+
+static void
+playbin_set_audio_mute (GstPlayBaseBin * play_base_bin, gboolean mute)
+{
+  GstPlayBin *playbin = GST_PLAY_BIN (play_base_bin);
+
+  if (playbin->volume_element) {
+    g_object_set (G_OBJECT (playbin->volume_element), "mute", mute, NULL);
+  }
+}
+
 /* Send an event to our sinks until one of them works; don't then send to the
  * remaining sinks (unlike GstBin)
  */
@@ -1622,49 +1798,7 @@ gst_play_bin_send_event_to_sink (GstPlayBin * play_bin, GstEvent * event)
   return res;
 }
 
-static gboolean
-do_playbin_seek (GstElement * element, GstEvent * event)
-{
-  gdouble rate;
-  GstSeekFlags flags;
-  gboolean flush;
-  gboolean was_playing = FALSE;
-  gboolean res;
-
-  gst_event_parse_seek (event, &rate, NULL, &flags, NULL, NULL, NULL, NULL);
-
-  flush = flags & GST_SEEK_FLAG_FLUSH;
-
-  if (flush) {
-    GstState state;
-
-    /* need to call _get_state() since a bin state is only updated
-     * with this call. */
-    gst_element_get_state (element, &state, NULL, 0);
-    was_playing = state == GST_STATE_PLAYING;
-
-    if (was_playing) {
-      gst_element_set_state (element, GST_STATE_PAUSED);
-      gst_element_get_state (element, NULL, NULL, 50 * GST_MSECOND);
-    }
-  }
-
-  GST_DEBUG_OBJECT (element, "Sending seek event to a sink");
-  res = gst_play_bin_send_event_to_sink (GST_PLAY_BIN (element), event);
-
-  if (flush) {
-    /* need to reset the stream time to 0 after a flushing seek */
-    if (res)
-      gst_pipeline_set_new_stream_time (GST_PIPELINE (element), 0);
-
-    if (was_playing)
-      /* and continue playing */
-      gst_element_set_state (element, GST_STATE_PLAYING);
-  }
-  return res;
-}
-
-/* We only want to send the event to a single sink (overriding GstBin's 
+/* We only want to send the event to a single sink (overriding GstBin's
  * behaviour), but we want to keep GstPipeline's behaviour - wrapping seek
  * events appropriately. So, this is a messy duplication of code. */
 static gboolean
@@ -1673,55 +1807,19 @@ gst_play_bin_send_event (GstElement * element, GstEvent * event)
   gboolean res = FALSE;
   GstEventType event_type = GST_EVENT_TYPE (event);
 
-
   switch (event_type) {
     case GST_EVENT_SEEK:
-      res = do_playbin_seek (element, event);
+      GST_DEBUG_OBJECT (element, "Sending seek event to a sink");
+      res = gst_play_bin_send_event_to_sink (GST_PLAY_BIN (element), event);
       break;
     default:
-      res = gst_play_bin_send_event_to_sink (GST_PLAY_BIN (element), event);
+      res = parent_class->send_event (element, event);
       break;
   }
 
   return res;
 }
 
-/* Override the set_clock function, we don't want to set a clock on the sinks
- * when we are live pipeline so that they don't synchronize until this is
- * fixed in core. */
-static gboolean
-gst_play_bin_set_clock_func (GstElement * element, GstClock * clock)
-{
-  GList *children;
-  GstBin *bin;
-  GstPlayBin *play_bin;
-  gboolean res = TRUE;
-  GstElement *asink, *vsink;
-
-  bin = GST_BIN (element);
-  play_bin = GST_PLAY_BIN (element);
-
-  asink = g_hash_table_lookup (play_bin->cache, "audio_sink");
-  vsink = g_hash_table_lookup (play_bin->cache, "video_sink");
-
-  GST_DEBUG_OBJECT (play_bin, "setting clock, is_live %d", play_bin->is_live);
-
-  GST_OBJECT_LOCK (bin);
-  if (element->clock != clock) {
-    for (children = bin->children; children; children = g_list_next (children)) {
-      GstElement *child = GST_ELEMENT (children->data);
-
-      if (play_bin->is_live && (child == asink || child == vsink))
-        res &= gst_element_set_clock (child, NULL);
-      else
-        res &= gst_element_set_clock (child, clock);
-    }
-  }
-  GST_OBJECT_UNLOCK (bin);
-
-  return res;
-}
-
 static void
 value_list_append_structure_list (GValue * list_val, GstStructure ** first,
     GList * structure_list)
@@ -1753,11 +1851,13 @@ gst_play_bin_handle_redirect_message (GstPlayBin * playbin, GstMessage * msg)
   GList *l_good = NULL, *l_neutral = NULL, *l_bad = NULL;
   GValue new_list = { 0, };
   guint size, i;
+  GstPlayBaseBin *playbasebin = GST_PLAY_BASE_BIN (playbin);
+  guint connection_speed = playbasebin->connection_speed;
 
   GST_DEBUG_OBJECT (playbin, "redirect message: %" GST_PTR_FORMAT, msg);
-  GST_DEBUG_OBJECT (playbin, "connection speed: %u", playbin->connection_speed);
+  GST_DEBUG_OBJECT (playbin, "connection speed: %u", connection_speed);
 
-  if (playbin->connection_speed == 0 || msg->structure == NULL)
+  if (connection_speed == 0 || msg->structure == NULL)
     return msg;
 
   locations_list = gst_structure_get_value (msg->structure, "locations");
@@ -1782,10 +1882,10 @@ gst_play_bin_handle_redirect_message (GstPlayBin * playbin, GstMessage * msg)
     if (!gst_structure_get_int (s, "minimum-bitrate", &bitrate) || bitrate <= 0) {
       GST_DEBUG_OBJECT (playbin, "no bitrate: %" GST_PTR_FORMAT, s);
       l_neutral = g_list_append (l_neutral, (gpointer) s);
-    } else if (bitrate > playbin->connection_speed) {
+    } else if (bitrate > connection_speed) {
       GST_DEBUG_OBJECT (playbin, "bitrate too high: %" GST_PTR_FORMAT, s);
       l_bad = g_list_append (l_bad, (gpointer) s);
-    } else if (bitrate <= playbin->connection_speed) {
+    } else if (bitrate <= connection_speed) {
       GST_DEBUG_OBJECT (playbin, "bitrate OK: %" GST_PTR_FORMAT, s);
       l_good = g_list_append (l_good, (gpointer) s);
     }
@@ -1856,6 +1956,7 @@ gst_play_bin_change_state (GstElement * element, GstStateChange transition)
       /* FIXME Release audio device when we implement that */
       break;
     case GST_STATE_CHANGE_PAUSED_TO_READY:
+    case GST_STATE_CHANGE_READY_TO_NULL:
       /* remove sinks we added */
       remove_sinks (play_bin);
       /* and there might be a fakesink we need to clean up now */
@@ -1872,23 +1973,11 @@ gst_play_bin_change_state (GstElement * element, GstStateChange transition)
   return ret;
 }
 
-static gboolean
-plugin_init (GstPlugin * plugin)
+gboolean
+gst_play_bin_plugin_init (GstPlugin * plugin)
 {
   GST_DEBUG_CATEGORY_INIT (gst_play_bin_debug, "playbin", 0, "play bin");
 
-#ifdef ENABLE_NLS
-  GST_DEBUG ("binding text domain %s to locale dir %s", GETTEXT_PACKAGE,
-      LOCALEDIR);
-  bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
-#endif /* ENABLE_NLS */
-
   return gst_element_register (plugin, "playbin", GST_RANK_NONE,
       GST_TYPE_PLAY_BIN);
 }
-
-GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
-    GST_VERSION_MINOR,
-    "playbin",
-    "player bin", plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME,
-    GST_PACKAGE_ORIGIN)