[totem] main: Add ability to switch video tracks



commit 1066d8aea423ebc4dbbe3a7e4ec460c93b0237fc
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Apr 6 22:59:48 2011 +0100

    main: Add ability to switch video tracks
    
    We can now switch video tracks, when multiple angles aren't
    available. Also make sure that the Angle menu is only enabled
    when there are multiple video tracks, or angles available.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=613765

 src/backend/bacon-video-widget-gst-0.10.c |   88 +++++++++++++++++++++++++++--
 src/backend/bacon-video-widget.h          |    7 +-
 src/totem-object.c                        |    9 ++-
 3 files changed, 90 insertions(+), 14 deletions(-)
---
diff --git a/src/backend/bacon-video-widget-gst-0.10.c b/src/backend/bacon-video-widget-gst-0.10.c
index aae1060..207f2c2 100644
--- a/src/backend/bacon-video-widget-gst-0.10.c
+++ b/src/backend/bacon-video-widget-gst-0.10.c
@@ -214,6 +214,7 @@ struct BaconVideoWidgetPrivate
   gboolean                     uses_audio_fakesink;
   gdouble                      volume;
   gboolean                     is_menu;
+  gboolean                     has_angles;
   
   gint                         video_width; /* Movie width */
   gint                         video_height; /* Movie height */
@@ -1377,6 +1378,7 @@ bvw_handle_element_message (BaconVideoWidget *bvw, GstMessage *msg)
 
         if (res) {
           gboolean is_menu = FALSE;
+	  gboolean has_angles = FALSE;
           guint i, n;
 
           if (gst_navigation_query_parse_commands_length (cmds_q, &n)) {
@@ -1389,6 +1391,9 @@ bvw_handle_element_message (BaconVideoWidget *bvw, GstMessage *msg)
               is_menu |= (cmd == GST_NAVIGATION_COMMAND_RIGHT);
               is_menu |= (cmd == GST_NAVIGATION_COMMAND_UP);
               is_menu |= (cmd == GST_NAVIGATION_COMMAND_DOWN);
+
+	      has_angles |= (cmd == GST_NAVIGATION_COMMAND_PREV_ANGLE);
+	      has_angles |= (cmd == GST_NAVIGATION_COMMAND_NEXT_ANGLE);
             }
           }
 	  /* Are we in a menu now? */
@@ -1396,6 +1401,11 @@ bvw_handle_element_message (BaconVideoWidget *bvw, GstMessage *msg)
 	    bvw->priv->is_menu = is_menu;
 	    g_object_notify (G_OBJECT (bvw), "seekable");
 	  }
+	  /* Do we have angle switching now? */
+	  if (bvw->priv->has_angles != has_angles) {
+	    bvw->priv->has_angles = has_angles;
+	    g_signal_emit (bvw, bvw_signals[SIGNAL_CHANNELS_CHANGE], 0);
+	  }
         }
 
         gst_query_unref (cmds_q);
@@ -3804,6 +3814,8 @@ bacon_video_widget_close (BaconVideoWidget * bvw)
   bvw->priv->user_pw = NULL;
 
   bvw->priv->is_live = FALSE;
+  bvw->priv->is_menu = FALSE;
+  bvw->priv->has_angles = FALSE;
   bvw->priv->window_resized = FALSE;
   bvw->priv->rate = FORWARD_RATE;
 
@@ -3873,12 +3885,6 @@ bacon_video_widget_dvd_event (BaconVideoWidget * bvw,
     case BVW_DVD_CHAPTER_MENU:
       bvw_do_navigation_command (bvw, GST_NAVIGATION_COMMAND_DVD_CHAPTER_MENU);
       break;
-    case BVW_DVD_NEXT_ANGLE:
-      bvw_do_navigation_command (bvw, GST_NAVIGATION_COMMAND_NEXT_ANGLE);
-      break;
-    case BVW_DVD_PREV_ANGLE:
-      bvw_do_navigation_command (bvw, GST_NAVIGATION_COMMAND_PREV_ANGLE);
-      break;
     case BVW_DVD_ROOT_MENU_UP:
       bvw_do_navigation_command (bvw, GST_NAVIGATION_COMMAND_UP);
       break;
@@ -4941,6 +4947,76 @@ bacon_video_widget_has_menus (BaconVideoWidget *bvw)
     return bvw->priv->is_menu;
 }
 
+/**
+ * bacon_video_widget_has_angles:
+ * @bvw: a #BaconVideoWidget
+ *
+ * Returns whether the widget is currently playing a stream with
+ * multiple angles.
+ *
+ * Return value: %TRUE if the current video stream has multiple
+ * angles, %FALSE otherwise
+ **/
+gboolean
+bacon_video_widget_has_angles (BaconVideoWidget *bvw)
+{
+    guint n_video;
+
+    g_return_val_if_fail (bvw != NULL, FALSE);
+    g_return_val_if_fail (BACON_IS_VIDEO_WIDGET (bvw), FALSE);
+
+    if (bacon_video_widget_is_playing (bvw) == FALSE)
+        return FALSE;
+
+    if (bvw->priv->has_angles)
+        return TRUE;
+
+    g_object_get (G_OBJECT (bvw->priv->play), "n-video", &n_video, NULL);
+
+    return n_video > 1;
+}
+
+/**
+ * bacon_video_widget_set_next_angle:
+ * @bvw: a #BaconVideoWidget
+ *
+ * Select the next angle, or video track in the playing stream.
+ **/
+void
+bacon_video_widget_set_next_angle (BaconVideoWidget *bvw)
+{
+    guint n_video, current_video;
+
+    g_return_if_fail (bvw != NULL);
+    g_return_if_fail (BACON_IS_VIDEO_WIDGET (bvw));
+
+    if (bacon_video_widget_is_playing (bvw) == FALSE)
+        return;
+
+    if (bvw->priv->has_angles) {
+        GST_DEBUG ("Sending event 'next-angle'");
+        bvw_do_navigation_command (bvw, GST_NAVIGATION_COMMAND_NEXT_ANGLE);
+        return;
+    }
+
+    g_object_get (G_OBJECT (bvw->priv->play),
+		  "current-video", &current_video,
+		  "n-video", &n_video,
+		  NULL);
+
+    if (n_video <= 1) {
+        GST_DEBUG ("Not setting next video stream, we have %d video streams", n_video);
+	return;
+    }
+
+    current_video++;
+    if (current_video == n_video)
+      current_video = 0;
+
+    GST_DEBUG ("Setting current-video to %d/%d", current_video, n_video);
+    g_object_set (G_OBJECT (bvw->priv->play), "current-video", current_video, NULL);
+}
+
 static gboolean
 notify_volume_idle_cb (BaconVideoWidget *bvw)
 {
diff --git a/src/backend/bacon-video-widget.h b/src/backend/bacon-video-widget.h
index b24e16c..7806351 100644
--- a/src/backend/bacon-video-widget.h
+++ b/src/backend/bacon-video-widget.h
@@ -404,7 +404,10 @@ void bacon_video_widget_set_video_property       (BaconVideoWidget *bvw,
 						  BvwVideoProperty type,
 						  int value);
 
+void bacon_video_widget_set_next_angle           (BaconVideoWidget *bvw);
+
 gboolean bacon_video_widget_has_menus            (BaconVideoWidget *bvw);
+gboolean bacon_video_widget_has_angles           (BaconVideoWidget *bvw);
 
 /* DVD functions */
 /**
@@ -419,8 +422,6 @@ gboolean bacon_video_widget_has_menus            (BaconVideoWidget *bvw);
  * @BVW_DVD_PREV_CHAPTER: the previous chapter
  * @BVW_DVD_NEXT_TITLE: the next title in the current chapter
  * @BVW_DVD_PREV_TITLE: the previous title in the current chapter
- * @BVW_DVD_NEXT_ANGLE: the next angle
- * @BVW_DVD_PREV_ANGLE: the previous angle
  * @BVW_DVD_ROOT_MENU_UP: go up in the menu
  * @BVW_DVD_ROOT_MENU_DOWN: go down in the menu
  * @BVW_DVD_ROOT_MENU_LEFT: go left in the menu
@@ -441,8 +442,6 @@ typedef enum {
 	BVW_DVD_PREV_CHAPTER,
 	BVW_DVD_NEXT_TITLE,
 	BVW_DVD_PREV_TITLE,
-	BVW_DVD_NEXT_ANGLE,
-	BVW_DVD_PREV_ANGLE,
 	BVW_DVD_ROOT_MENU_UP,
 	BVW_DVD_ROOT_MENU_DOWN,
 	BVW_DVD_ROOT_MENU_LEFT,
diff --git a/src/totem-object.c b/src/totem-object.c
index 874d920..0b14197 100644
--- a/src/totem-object.c
+++ b/src/totem-object.c
@@ -2429,6 +2429,7 @@ on_channels_change_event (BaconVideoWidget *bvw, TotemObject *totem)
 	gchar *name;
 
 	totem_sublang_update (totem);
+	update_media_menu_items (totem);
 
 	/* updated stream info (new song) */
 	name = totem_get_nice_name_for_stream (totem);
@@ -2951,8 +2952,7 @@ totem_action_toggle_controls (TotemObject *totem)
 void
 totem_action_next_angle (TotemObject *totem)
 {
-	if (totem_playing_dvd (totem->mrl) != FALSE)
-		bacon_video_widget_dvd_event (totem->bvw, BVW_DVD_NEXT_ANGLE);
+	bacon_video_widget_set_next_angle (totem->bvw);
 }
 
 /**
@@ -3893,8 +3893,9 @@ update_media_menu_items (TotemObject *totem)
 	totem_action_set_sensitivity ("dvd-audio-menu", playing);
 	totem_action_set_sensitivity ("dvd-angle-menu", playing);
 	totem_action_set_sensitivity ("dvd-chapter-menu", playing);
-	/* FIXME we should only show that if we have multiple angles */
-	totem_action_set_sensitivity ("next-angle", playing);
+
+	totem_action_set_sensitivity ("next-angle",
+				      bacon_video_widget_has_angles (totem->bvw));
 
 	mount = totem_get_mount_for_media (totem->mrl);
 	totem_action_set_sensitivity ("eject", mount != NULL);



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