[snappy] snappy: cycle through subtitle streams



commit 22bd1cdb3a064212db6ebb789c650c478d5fe833
Author: Luis de Bethencourt <luis debethencourt com>
Date:   Sat Apr 28 10:36:02 2012 +0100

    snappy: cycle through subtitle streams

 docs/keyboard_controls |    3 ++-
 src/gst_engine.c       |   30 +++++++++++++++++++-----------
 src/gst_engine.h       |    2 +-
 src/user_interface.c   |   23 +++++++++++++++--------
 src/user_interface.h   |    7 +++++++
 5 files changed, 44 insertions(+), 21 deletions(-)
---
diff --git a/docs/keyboard_controls b/docs/keyboard_controls
index 23244e3..d2a9e9e 100644
--- a/docs/keyboard_controls
+++ b/docs/keyboard_controls
@@ -20,8 +20,9 @@ right      - seek 10 seconds foward
 c          - show/hide visual controls
 
 v          - toggle subtitles
-_          - cycle through available video streams
 #          - cycle through available audio streams
+_          - cycle through available video streams
+j          - cycle through available subtitle streams
 
 r          - rotate video
 
diff --git a/src/gst_engine.c b/src/gst_engine.c
index 9c9e831..b14da55 100644
--- a/src/gst_engine.c
+++ b/src/gst_engine.c
@@ -755,19 +755,23 @@ set_subtitle_uri (GstEngine * engine, gchar * suburi)
 
 /*                  Toggle streams               */
 gboolean
-toggle_streams (GstEngine * engine, gboolean video_stream)
+toggle_streams (GstEngine * engine, guint streamid)
 {
+  gboolean last_stream = FALSE;
   gint current;
   gint streams;
   gchar *n;
   gchar *c;
 
-  if (video_stream) {
-    n = "n-video";
-    c = "current-video";
-  } else {
+  if (streamid == STREAM_AUDIO) {
     n = "n-audio";
     c = "current-audio";
+   } else if (streamid == STREAM_TEXT) {
+    n = "n-text";
+    c = "current-text";
+  } else if (streamid == STREAM_VIDEO) {
+    n = "n-video";
+    c = "current-video";
   }
 
   g_object_get (G_OBJECT (engine->player), n, &streams, NULL);
@@ -777,6 +781,7 @@ toggle_streams (GstEngine * engine, gboolean video_stream)
     current++;
   } else {
     current = 0;
+    last_stream = TRUE;
   }
 
   g_object_set (G_OBJECT (engine->player), c, current, NULL);
@@ -794,13 +799,16 @@ toggle_subtitles (GstEngine * engine)
   g_object_get (G_OBJECT (engine->player), "flags", &flags, NULL);
   sub_state = flags & (1 << 2);
 
-  if (sub_state) {
-    flags &= ~(1 << 2);         //GST_PLAY_FLAG_TEXT off
-  } else {
-    flags |= (1 << 2);          //GST_PLAY_FLAG_TEXT on
-  }
+  if (sub_state) {        // If subtitles on, cycle streams and if last turn off
+    if (toggle_streams (engine, STREAM_TEXT)) {
+      flags &= ~(1 << 2);
+      g_object_set (G_OBJECT (engine->player), "flags", flags, NULL);
+    }
 
-  g_object_set (G_OBJECT (engine->player), "flags", flags, NULL);
+  } else {                // If subtitles off, turn them on
+    flags |= (1 << 2);
+    g_object_set (G_OBJECT (engine->player), "flags", flags, NULL);
+  }
 
   return TRUE;
 }
diff --git a/src/gst_engine.h b/src/gst_engine.h
index 603dfef..11f2e63 100644
--- a/src/gst_engine.h
+++ b/src/gst_engine.h
@@ -67,7 +67,7 @@ gchar **get_recently_viewed ();
 GstState get_state (GstEngine * engine);
 gint64 query_position (GstEngine * engine);
 gboolean set_subtitle_uri (GstEngine * engine, gchar *suburi);
-gboolean toggle_streams (GstEngine * engine, gboolean video_stream);
+gboolean toggle_streams (GstEngine * engine, guint streamid);
 gboolean toggle_subtitles (GstEngine * engine);
 gboolean update_media_duration (GstEngine * engine);
 
diff --git a/src/user_interface.c b/src/user_interface.c
index b3d59a0..54f280e 100644
--- a/src/user_interface.c
+++ b/src/user_interface.c
@@ -254,12 +254,19 @@ event_cb (ClutterStage * stage, ClutterEvent * event, UserInterface * ui)
 
         case CLUTTER_numbersign:
         case CLUTTER_underscore:
+        case CLUTTER_j:
         {
-          // cycle through available audio/video streams
-          gboolean video_stream;
+          // cycle through available audio/text/video streams
+          guint streamid;
 
-          video_stream = (keyval == CLUTTER_underscore);
-          toggle_streams (ui->engine, video_stream);
+          if (keyval == CLUTTER_numbersign)
+            streamid = STREAM_AUDIO;
+          else if (keyval == CLUTTER_j)
+            streamid = STREAM_TEXT;
+          else if (keyval == CLUTTER_underscore)
+            streamid = STREAM_VIDEO;
+
+          toggle_streams (ui->engine, streamid);
 
           handled = TRUE;
           break;
@@ -332,14 +339,14 @@ event_cb (ClutterStage * stage, ClutterEvent * event, UserInterface * ui)
             show_controls (ui, FALSE);
           }
 
+        } else if (actor == ui->audio_stream_toggle) {
+          toggle_streams (ui->engine, STREAM_AUDIO);
+
         } else if (actor == ui->subtitle_toggle) {
           toggle_subtitles (ui->engine);
 
         } else if (actor == ui->video_stream_toggle) {
-          toggle_streams (ui->engine, TRUE);
-
-        } else if (actor == ui->audio_stream_toggle) {
-          toggle_streams (ui->engine, FALSE);
+          toggle_streams (ui->engine, STREAM_VIDEO);
         }
       }
 
diff --git a/src/user_interface.h b/src/user_interface.h
index c335a27..3a19df0 100644
--- a/src/user_interface.h
+++ b/src/user_interface.h
@@ -67,6 +67,13 @@
 
 G_BEGIN_DECLS
 
+enum
+{
+  STREAM_AUDIO,
+  STREAM_TEXT,
+  STREAM_VIDEO
+};
+
 typedef struct _UserInterface UserInterface;
 
 struct _UserInterface



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