[snappy] snappy: ui updates with DVD segment changes



commit 6d60723066d74b57d35b2419e65c56d4481353d7
Author: Luis de Bethencourt <luis debethencourt com>
Date:   Thu May 17 22:07:36 2012 +0100

    snappy: ui updates with DVD segment changes
    
    When the DVD segment played changes (eg, from menu to movie segment) the ui
    needs to update and adapt to the new duration, both in the text position and
    seekbar. For this the handle_element_message () function has been added in
    gst_engine to handle the GstNavigationMessages, which update the stored media
    duration

 src/gst_engine.c     |   32 ++++++++++++++++++++++++++++++--
 src/gst_engine.h     |    5 +++++
 src/user_interface.c |    8 ++++++--
 src/user_interface.h |    1 +
 4 files changed, 42 insertions(+), 4 deletions(-)
---
diff --git a/src/gst_engine.c b/src/gst_engine.c
index 02caf8d..f83da70 100644
--- a/src/gst_engine.c
+++ b/src/gst_engine.c
@@ -54,6 +54,7 @@ gboolean add_uri_to_history (gchar * uri);
 gboolean add_uri_unfinished_playback (GstEngine * engine, gchar * uri,
     gint64 position);
 gboolean discover (GstEngine * engine, gchar * uri);
+static void handle_element_message (GstEngine * engine, GstMessage * msg);
 gboolean is_stream_seakable (GstEngine * engine);
 gint64 is_uri_unfinished_playback (GstEngine * engine, gchar * uri);
 static void print_tag (const GstTagList * list, const gchar * tag,
@@ -222,8 +223,6 @@ discover (GstEngine * engine, gchar * uri)
     engine->media_width = gst_discoverer_video_info_get_width (v_info);
     engine->media_height = gst_discoverer_video_info_get_height (v_info);
 
-    // g_print ("Found video dimensions: %dx%d\n", engine->media_width,
-    //     engine->media_height);
   } else {
     /* If only audio stream, play visualizations */
     g_object_get (G_OBJECT (engine->player), "flags", &flags, NULL);
@@ -236,6 +235,27 @@ discover (GstEngine * engine, gchar * uri)
   return TRUE;
 }
 
+/* Handle GST_ELEMENT_MESSAGEs */
+static void
+handle_element_message (GstEngine * engine, GstMessage * msg)
+{
+  GstNavigationMessageType nav_msg_type = gst_navigation_message_get_type (msg);
+
+  switch (nav_msg_type) {
+    case GST_NAVIGATION_MESSAGE_COMMANDS_CHANGED:{
+      if (is_stream_seakable (engine)) {
+        update_media_duration (engine);
+      }
+
+      break;
+    }
+
+    default:{
+      break;
+    }
+  }
+}
+
 /* Query if the current stream is seakable */
 gboolean
 is_stream_seakable (GstEngine * engine)
@@ -511,6 +531,12 @@ bus_call (GstBus * bus, GstMessage * msg, gpointer data)
       break;
     }
 
+    case GST_MESSAGE_ELEMENT:
+    {
+      handle_element_message (engine, msg);
+      break;
+    }
+
     case GST_MESSAGE_ERROR:
     {
       /* Parse and share Gst Error */
@@ -647,6 +673,8 @@ engine_init (GstEngine * engine, GstElement * sink)
   g_object_set (G_OBJECT (engine->player), "video-sink", engine->sink, NULL);
   engine->bus = gst_pipeline_get_bus (GST_PIPELINE (engine->player));
 
+  engine->navigation = GST_NAVIGATION (engine->sink);
+
   return TRUE;
 }
 
diff --git a/src/gst_engine.h b/src/gst_engine.h
index 2021d0b..4106a73 100644
--- a/src/gst_engine.h
+++ b/src/gst_engine.h
@@ -25,6 +25,9 @@
 
 #include <gst/gst.h>
 
+/* GStreamer Interfaces */
+#include <gst/interfaces/navigation.h>
+
 G_BEGIN_DECLS
 
 typedef struct _GstEngine GstEngine;
@@ -48,6 +51,8 @@ struct _GstEngine
   GstElement *sink;
 
   GstBus *bus;
+
+  GstNavigation *navigation;
 };
 
 // Declaration of non-static functions
diff --git a/src/user_interface.c b/src/user_interface.c
index 53ddbfd..99f064b 100644
--- a/src/user_interface.c
+++ b/src/user_interface.c
@@ -725,6 +725,11 @@ progress_update_text (gpointer data)
       gchar *duration_str;
       gint64 pos;
 
+      if (ui->media_duration != engine->media_duration) {
+        ui->duration_str = position_ns_to_str (engine->media_duration);
+        progress_timing (ui);
+      }
+
       pos = query_position (engine);
       duration_str = g_strdup_printf ("   %s/%s", position_ns_to_str (pos),
           ui->duration_str);
@@ -746,8 +751,6 @@ progress_update_seekbar (gpointer data)
       gint64 pos;
       gfloat progress = 0.0;
 
-      update_media_duration (engine);
-
       pos = query_position (engine);
       progress = (float) pos / engine->media_duration;
 
@@ -1164,6 +1167,7 @@ interface_start (UserInterface * ui, gchar * uri)
 
   ui->progress_id = -1;
   ui->title_length = TITLE_LENGTH;
+  ui->media_duration = -1;
   ui->duration_str = position_ns_to_str (ui->engine->media_duration);
 
   clutter_stage_set_color (CLUTTER_STAGE (ui->stage), &stage_color);
diff --git a/src/user_interface.h b/src/user_interface.h
index a7525dc..b7f7a28 100644
--- a/src/user_interface.h
+++ b/src/user_interface.h
@@ -81,6 +81,7 @@ struct _UserInterface
   gint title_length, controls_timeout, progress_id;
   guint media_width, media_height;
   guint stage_width, stage_height;
+  gint64 media_duration;
   gfloat seek_width, seek_height;
   gfloat volume_width, volume_height;
 



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