Index: gst/playback/gstplaybasebin.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/gst/playback/gstplaybasebin.c,v
retrieving revision 1.109
diff -u -r1.109 gstplaybasebin.c
--- gst/playback/gstplaybasebin.c	11 May 2006 21:01:05 -0000	1.109
+++ gst/playback/gstplaybasebin.c	19 May 2006 16:44:50 -0000
@@ -71,7 +71,8 @@
   ARG_SOURCE,
   ARG_VIDEO,
   ARG_AUDIO,
-  ARG_TEXT
+  ARG_TEXT,
+  ARG_SUBTITLE_ENCODING
 };
 
 static void gst_play_base_bin_class_init (GstPlayBaseBinClass * klass);
@@ -187,6 +188,9 @@
       g_param_spec_int ("current-text", "Current text",
           "Currently playing text stream (-1 = none)",
           -1, G_MAXINT, -1, G_PARAM_READWRITE));
+  g_object_class_install_property (gobject_klass, ARG_SUBTITLE_ENCODING,
+      g_param_spec_string ("subtitle-encoding", "Subtitle Encoding",
+          "Encoding Charset for subtitle", NULL, G_PARAM_READWRITE));
 
   GST_DEBUG_CATEGORY_INIT (gst_play_base_bin_debug, "playbasebin", 0,
       "playbasebin");
@@ -1147,6 +1151,103 @@
   }
 }
 
+static gboolean
+subdecoder_set_encoding (GstBin * subdecoder, const gchar * encoding)
+{
+  GstIterator *elem_it = NULL;
+  gboolean done = FALSE;
+  gboolean rc = FALSE;
+
+  elem_it = gst_bin_iterate_elements (subdecoder);
+  while (!done) {
+    GstElement *subparse;
+
+    switch (gst_iterator_next (elem_it, (gpointer) & subparse)) {
+      case GST_ITERATOR_OK:
+        if (!strncmp ("subparse", gst_element_get_name (subparse), 8)) {
+          GST_DEBUG ("set subparse encoding to %s", encoding);
+          g_object_set (G_OBJECT (subparse), "encoding", encoding, NULL);
+          rc = TRUE;
+          done = TRUE;
+        }
+        gst_object_unref (subparse);
+        break;
+      case GST_ITERATOR_RESYNC:
+        gst_iterator_resync (elem_it);
+        break;
+      case GST_ITERATOR_ERROR:
+        done = TRUE;
+        break;
+      case GST_ITERATOR_DONE:
+        done = TRUE;
+        break;
+    }
+  }
+  gst_iterator_free (elem_it);
+  return rc;
+}
+
+static gboolean
+subbin_set_encoding (GstBin * subbin, const gchar * encoding)
+{
+  GstIterator *elem_it = NULL;
+  GstElement *element = NULL;
+  gboolean done = FALSE;
+  gboolean rc = FALSE;
+
+  if (!subbin) {
+    GST_DEBUG ("subbin is NULL");
+    return FALSE;
+  }
+
+  if (!strncmp ("subtitle-bin", gst_element_get_name (GST_ELEMENT (subbin)),
+          12)) {
+    GST_DEBUG ("subbin is not subtitle bin");
+    return FALSE;
+  }
+
+  elem_it = gst_bin_iterate_elements (subbin);
+  while (!done) {
+    switch (gst_iterator_next (elem_it, (gpointer) & element)) {
+      case GST_ITERATOR_OK:
+        if (!strncmp ("subtitle-decoder", gst_element_get_name (element), 16)) {
+          done = TRUE;
+        } else {
+          gst_object_unref (element);
+          element = NULL;
+        }
+        break;
+      case GST_ITERATOR_RESYNC:
+        gst_iterator_resync (elem_it);
+        break;
+      case GST_ITERATOR_ERROR:
+        done = TRUE;
+        break;
+      case GST_ITERATOR_DONE:
+        done = TRUE;
+        break;
+    }
+  }
+  gst_iterator_free (elem_it);
+  if (!element) {
+    GST_DEBUG ("can't find subtitle-decoder\n");
+    return FALSE;
+  }
+  done = FALSE;
+
+  rc = subdecoder_set_encoding (GST_BIN (element), encoding);
+  gst_object_unref (element);
+  return rc;
+}
+
+static void
+cb_newpad (GstElement * decodebin, GstPad * pad, gboolean last, gpointer data)
+{
+  GstPlayBaseBin *play_base_bin = GST_PLAY_BASE_BIN (data);
+
+  if (subdecoder_set_encoding (GST_BIN (decodebin), play_base_bin->subencoding))
+    play_base_bin->need_rebuild = TRUE;
+}
 
 /*
  * Generate source ! subparse bins.
@@ -1161,9 +1262,11 @@
   if (!source)
     return NULL;
   subparse = gst_element_factory_make ("decodebin", "subtitle-decoder");
-
+  g_signal_connect (subparse, "new-decoded-pad", G_CALLBACK (cb_newpad),
+      play_base_bin);
   subbin = gst_bin_new ("subtitle-bin");
   gst_bin_add_many (GST_BIN (subbin), source, subparse, NULL);
+
   gst_element_link (source, subparse);
 
   /* return the subtitle GstElement object */
@@ -1802,6 +1905,25 @@
           GST_STREAM_TYPE_TEXT, g_value_get_int (value));
       GROUP_UNLOCK (play_base_bin);
       break;
+    case ARG_SUBTITLE_ENCODING:
+    {
+      const gchar *encoding = g_value_get_string (value);
+
+      if (encoding == NULL) {
+        g_warning ("cannot set NULL encoding");
+        return;
+      }
+      if ((!encoding && !play_base_bin->subencoding) ||
+          (encoding && play_base_bin->subencoding &&
+              !strcmp (play_base_bin->subencoding, encoding)))
+        return;
+      g_free (play_base_bin->subencoding);
+      if (subbin_set_encoding (GST_BIN (play_base_bin->subtitle), encoding))
+        play_base_bin->need_rebuild = TRUE;
+
+      play_base_bin->subencoding = g_strdup (encoding);
+      break;
+    }
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -1876,6 +1998,9 @@
               GST_STREAM_TYPE_TEXT));
       GROUP_UNLOCK (play_base_bin);
       break;
+    case ARG_SUBTITLE_ENCODING:
+      g_value_set_string (value, play_base_bin->subencoding);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
Index: gst/playback/gstplaybasebin.h
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/gst/playback/gstplaybasebin.h,v
retrieving revision 1.20
diff -u -r1.20 gstplaybasebin.h
--- gst/playback/gstplaybasebin.h	11 May 2006 21:01:05 -0000	1.20
+++ gst/playback/gstplaybasebin.h	19 May 2006 16:44:50 -0000
@@ -75,7 +75,7 @@
 
   /* currently loaded media */
   gint           current[NUM_TYPES];
-  gchar         *uri, *suburi;
+  gchar         *uri, *suburi, *subencoding;
   gboolean       is_stream;
   GstElement    *source;
   GstElement    *decoder;
