[totem] backend: Split out the subtitle loading



commit 65c83b08732569c619efb6abad3421ab6c37d340
Author: Bastien Nocera <hadess hadess net>
Date:   Fri Apr 20 15:03:57 2012 +0100

    backend: Split out the subtitle loading
    
    Split out the subtitle loading from _open() so it can
    be handled on-the-fly (without reloading the movie itself).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=514050

 browser-plugin/totem-plugin-viewer.c      |    3 +-
 docs/reference/totem-sections.txt         |    1 +
 src/backend/bacon-video-widget-gst-0.10.c |   72 +++++++++++++++++++++++++----
 src/backend/bacon-video-widget.h          |    3 +-
 src/backend/bvw-test.c                    |    2 +-
 src/totem-object.c                        |    8 ++--
 6 files changed, 73 insertions(+), 16 deletions(-)
---
diff --git a/browser-plugin/totem-plugin-viewer.c b/browser-plugin/totem-plugin-viewer.c
index 3d8a8bb..676dae1 100644
--- a/browser-plugin/totem-plugin-viewer.c
+++ b/browser-plugin/totem-plugin-viewer.c
@@ -451,7 +451,8 @@ totem_embedded_open_internal (TotemEmbedded *emb,
 
 	bacon_video_widget_set_logo_mode (emb->bvw, FALSE);
 
-	retval = bacon_video_widget_open (emb->bvw, uri, emb->current_subtitle_uri, NULL);
+	retval = bacon_video_widget_open (emb->bvw, uri, NULL);
+	bacon_video_widget_set_text_subtitle (emb->bvw, emb->current_subtitle_uri);
 	g_free (uri);
 
 	/* FIXME we shouldn't even do that here */
diff --git a/docs/reference/totem-sections.txt b/docs/reference/totem-sections.txt
index d0a9331..b4bb992 100644
--- a/docs/reference/totem-sections.txt
+++ b/docs/reference/totem-sections.txt
@@ -227,6 +227,7 @@ bacon_video_widget_get_stream_length
 bacon_video_widget_get_subtitles
 bacon_video_widget_get_subtitle
 bacon_video_widget_set_subtitle
+bacon_video_widget_set_text_subtitle
 bacon_video_widget_set_subtitle_encoding
 bacon_video_widget_set_subtitle_font
 bacon_video_widget_set_user_agent
diff --git a/src/backend/bacon-video-widget-gst-0.10.c b/src/backend/bacon-video-widget-gst-0.10.c
index daeb60a..1777fa1 100644
--- a/src/backend/bacon-video-widget-gst-0.10.c
+++ b/src/backend/bacon-video-widget-gst-0.10.c
@@ -169,6 +169,7 @@ struct BaconVideoWidgetPrivate
 
   char                        *referrer;
   char                        *mrl;
+  char                        *subtitle_uri;
   BvwAspectRatio               ratio_type;
 
   GstElement                  *play;
@@ -2579,6 +2580,9 @@ bacon_video_widget_finalize (GObject * object)
   g_free (bvw->priv->mrl);
   bvw->priv->mrl = NULL;
 
+  g_free (bvw->priv->subtitle_uri);
+  bvw->priv->subtitle_uri = NULL;
+
   g_free (bvw->priv->vis_element_name);
   bvw->priv->vis_element_name = NULL;
 
@@ -3411,11 +3415,9 @@ bvw_error_from_gst_error (BaconVideoWidget *bvw, GstMessage * err_msg)
  * bacon_video_widget_open:
  * @bvw: a #BaconVideoWidget
  * @mrl: an MRL
- * @subtitle_uri: the URI of a subtitle file, or %NULL
  * @error: a #GError, or %NULL
  *
- * Opens the given @mrl in @bvw for playing. If @subtitle_uri is not %NULL, the given
- * subtitle file is also loaded.
+ * Opens the given @mrl in @bvw for playing.
  *
  * If there was a filesystem error, a %BVW_ERROR_GENERIC error will be returned. Otherwise,
  * more specific #BvwError errors will be returned.
@@ -3426,7 +3428,7 @@ bvw_error_from_gst_error (BaconVideoWidget *bvw, GstMessage * err_msg)
  **/
 gboolean
 bacon_video_widget_open (BaconVideoWidget * bvw,
-                         const gchar * mrl, const gchar *subtitle_uri, GError ** error)
+                         const gchar * mrl, GError ** error)
 {
   GFile *file;
   char *path;
@@ -3441,8 +3443,7 @@ bacon_video_widget_open (BaconVideoWidget * bvw,
   }
   
   GST_DEBUG ("mrl = %s", GST_STR_NULL (mrl));
-  GST_DEBUG ("subtitle_uri = %s", GST_STR_NULL (subtitle_uri));
-  
+
   /* this allows non-URI type of files in the thumbnailer and so on */
   file = g_file_new_for_commandline_arg (mrl);
 
@@ -3486,9 +3487,7 @@ bacon_video_widget_open (BaconVideoWidget * bvw,
   gst_element_set_state (bvw->priv->play, GST_STATE_READY);
   gst_bus_set_flushing (bvw->priv->bus, FALSE);
 
-  g_object_set (bvw->priv->play, "uri", bvw->priv->mrl,
-                "suburi", subtitle_uri, NULL);
-
+  g_object_set (bvw->priv->play, "uri", bvw->priv->mrl, NULL);
 
   bvw->priv->seekable = -1;
   bvw->priv->target_state = GST_STATE_PAUSED;
@@ -3818,6 +3817,8 @@ bacon_video_widget_close (BaconVideoWidget * bvw)
 
   g_free (bvw->priv->mrl);
   bvw->priv->mrl = NULL;
+  g_free (bvw->priv->subtitle_uri);
+  bvw->priv->subtitle_uri = NULL;
   g_free (bvw->priv->user_id);
   bvw->priv->user_id = NULL;
   g_free (bvw->priv->user_pw);
@@ -3859,6 +3860,59 @@ bvw_do_navigation_command (BaconVideoWidget * bvw, GstNavigationCommand command)
 }
 
 /**
+ * bacon_video_widget_set_text_subtitle:
+ * @bvw: a #BaconVideoWidget
+ * @subtitle_uri: (allow-none): the URI of a subtitle file, or %NULL
+ *
+ * Sets the URI for the text subtitle file to be displayed alongside
+ * the current video. Use %NULL if you want to unload the current text subtitle
+ * file being used.
+ */
+void
+bacon_video_widget_set_text_subtitle (BaconVideoWidget * bvw,
+				      const gchar * subtitle_uri)
+{
+  GstState cur_state;
+
+  g_return_if_fail (BACON_IS_VIDEO_WIDGET (bvw));
+  g_return_if_fail (GST_IS_ELEMENT (bvw->priv->play));
+  g_return_if_fail (bvw->priv->mrl != NULL);
+
+  GST_LOG ("Setting subtitle as %s", GST_STR_NULL (subtitle_uri));
+
+  if (subtitle_uri == NULL &&
+      bvw->priv->subtitle_uri == NULL)
+    return;
+
+  /* Wait for the previous state change to finish */
+  gst_element_get_state (bvw->priv->play, NULL, NULL, GST_CLOCK_TIME_NONE);
+
+  /* -> READY */
+  gst_element_get_state (bvw->priv->play, &cur_state, NULL, 0);
+  if (cur_state > GST_STATE_READY) {
+    gst_element_set_state (bvw->priv->play, GST_STATE_READY);
+    /* Block for new state */
+    gst_element_get_state (bvw->priv->play, NULL, NULL, GST_CLOCK_TIME_NONE);
+  }
+
+  g_free (bvw->priv->subtitle_uri);
+  bvw->priv->subtitle_uri = g_strdup (subtitle_uri);
+  g_object_set (G_OBJECT (bvw->priv->play), "suburi", subtitle_uri, NULL);
+
+  /* And back to the original state */
+  if (cur_state > GST_STATE_READY) {
+    gst_element_set_state (bvw->priv->play, cur_state);
+    /* Block for new state */
+    gst_element_get_state (bvw->priv->play, NULL, NULL, GST_CLOCK_TIME_NONE);
+  }
+
+  if (bvw->priv->current_time > 0)
+    bacon_video_widget_seek_time_no_lock (bvw, bvw->priv->current_time,
+					  GST_SEEK_FLAG_ACCURATE, NULL);
+}
+
+
+/**
  * bacon_video_widget_dvd_event:
  * @bvw: a #BaconVideoWidget
  * @type: the type of DVD event to issue
diff --git a/src/backend/bacon-video-widget.h b/src/backend/bacon-video-widget.h
index b98d8c6..91226b8 100644
--- a/src/backend/bacon-video-widget.h
+++ b/src/backend/bacon-video-widget.h
@@ -145,7 +145,6 @@ GtkWidget *bacon_video_widget_new		 (GError **error);
 /* Actions */
 gboolean bacon_video_widget_open		 (BaconVideoWidget *bvw,
 						  const char *mrl,
-						  const char *subtitle_uri,
 						  GError **error);
 gboolean bacon_video_widget_play                 (BaconVideoWidget *bvw,
 						  GError **error);
@@ -179,6 +178,8 @@ void bacon_video_widget_set_volume               (BaconVideoWidget *bvw,
 double bacon_video_widget_get_volume             (BaconVideoWidget *bvw);
 
 /* Properties */
+void bacon_video_widget_set_text_subtitle	(BaconVideoWidget * bvw,
+						 const gchar * subtitle_uri);
 void bacon_video_widget_set_logo		 (BaconVideoWidget *bvw,
 						  const char *name);
 void  bacon_video_widget_set_logo_mode		 (BaconVideoWidget *bvw,
diff --git a/src/backend/bvw-test.c b/src/backend/bvw-test.c
index d73a5fe..d516721 100644
--- a/src/backend/bvw-test.c
+++ b/src/backend/bvw-test.c
@@ -16,7 +16,7 @@ static void
 test_bvw_set_mrl (GtkWidget *bvw, const char *path)
 {
 	mrl = g_strdup (path);
-	bacon_video_widget_open (BACON_VIDEO_WIDGET (bvw), mrl, NULL, NULL);
+	bacon_video_widget_open (BACON_VIDEO_WIDGET (bvw), mrl, NULL);
 }
 
 static void
diff --git a/src/totem-object.c b/src/totem-object.c
index f4cf53f..22f6266 100644
--- a/src/totem-object.c
+++ b/src/totem-object.c
@@ -1689,7 +1689,8 @@ totem_action_set_mrl_with_warning (TotemObject *totem,
 
 		totem_gdk_window_set_waiting_cursor (gtk_widget_get_window (totem->win));
 		totem_try_restore_position (totem, mrl);
-		retval = bacon_video_widget_open (totem->bvw, mrl, subtitle ? subtitle : autoload_sub, &err);
+		retval = bacon_video_widget_open (totem->bvw, mrl, &err);
+		bacon_video_widget_set_text_subtitle (totem->bvw, subtitle ? subtitle : autoload_sub);
 		g_free (autoload_sub);
 		gdk_window_set_cursor (gtk_widget_get_window (totem->win), NULL);
 		totem->mrl = g_strdup (mrl);
@@ -2346,7 +2347,7 @@ on_got_redirect (BaconVideoWidget *bvw, const char *mrl, TotemObject *totem)
 	bacon_video_widget_close (totem->bvw);
 	totem_file_closed (totem);
 	totem_gdk_window_set_waiting_cursor (gtk_widget_get_window (totem->win));
-	bacon_video_widget_open (totem->bvw, new_mrl ? new_mrl : mrl, NULL, NULL);
+	bacon_video_widget_open (totem->bvw, new_mrl ? new_mrl : mrl, NULL);
 	totem_file_opened (totem, new_mrl ? new_mrl : mrl);
 	gdk_window_set_cursor (gtk_widget_get_window (totem->win), NULL);
 	bacon_video_widget_play (bvw, NULL);
@@ -3202,9 +3203,8 @@ subtitle_changed_cb (GtkWidget *playlist, TotemObject *totem)
 {
 	char *mrl, *subtitle;
 
-	totem_action_stop (totem);
 	mrl = totem_playlist_get_current_mrl (totem->playlist, &subtitle);
-	totem_action_set_mrl_and_play (totem, mrl, subtitle);
+	bacon_video_widget_set_text_subtitle (totem->bvw, subtitle);
 
 	g_free (mrl);
 	g_free (subtitle);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]