[maemo-commits] [maemo-commits] r17829 - projects/haf/trunk/hildon-welcome/src

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Fri Mar 27 11:36:59 EET 2009
Author: schulhof
Date: 2009-03-27 11:33:25 +0200 (Fri, 27 Mar 2009)
New Revision: 17829

Added:
   projects/haf/trunk/hildon-welcome/src/tmp.c
Modified:
   projects/haf/trunk/hildon-welcome/src/main.c
Log:
Added tmp.c

Modified: projects/haf/trunk/hildon-welcome/src/main.c
===================================================================
--- projects/haf/trunk/hildon-welcome/src/main.c	2009-03-27 09:15:41 UTC (rev 17828)
+++ projects/haf/trunk/hildon-welcome/src/main.c	2009-03-27 09:33:25 UTC (rev 17829)
@@ -34,8 +34,6 @@
 #endif /* HAVE_MCE */
 #include "conffile.h"
 
-#define KILL_TO_LENGTH_MS 30000
-
 #define DEFAULT_VIDEO_PIPELINE_STR " playbin2 uri=file://%s " /* " flags=99 " <-- doesn't work with still images */
 #define DEFAULT_AUDIO_PIPELINE_STR " filesrc location=%s ! decodebin2 ! autoaudiosink "
 #define DEFAULT_SHUSH_PIPELINE_STR " audiotestsrc ! volume volume=0 ! autoaudiosink "
@@ -44,22 +42,6 @@
 static char *audio_pipeline_str = DEFAULT_AUDIO_PIPELINE_STR;
 static char *shush_pipeline_str = DEFAULT_SHUSH_PIPELINE_STR;
 
-#define TIMEOUT_PARAMS_STATIC_INIT { \
-  .timer = NULL,    \
-  .to_ms = 0,       \
-  .pipeline = NULL, \
-  .timeout_id = 0,  \
-  .error = NULL     }
-
-typedef struct
-{
-  GTimer *timer;
-  guint to_ms;
-  GstElement *pipeline;
-  guint timeout_id;
-  const char *error;
-} TimeoutParams;
-
 static void
 my_log_func(const gchar *log_domain, GLogLevelFlags log_level, const char *message, gpointer null)
 {
@@ -74,174 +56,19 @@
   g_free(new_msg);
 }
 
-static gboolean
-post_eos(TimeoutParams *tp)
-{
-  if (tp->timer) {
-    double diff_ms = ((double)(tp->to_ms)) - (g_timer_elapsed(tp->timer, NULL) * 1000.0);
-    if (diff_ms > 0) {
-      g_warning("post_eos: False alarm! %lf ms () left\n", diff_ms);
-      tp->timeout_id = g_timeout_add((guint)diff_ms, (GSourceFunc)post_eos, tp);
-      return FALSE;
-    }
-  }
-  if (tp->error)
-    g_error("post_eos: %s", tp->error);
-  gst_bus_post(gst_pipeline_get_bus(GST_PIPELINE(tp->pipeline)), gst_message_new_eos(GST_OBJECT(tp->pipeline)));
-
-  tp->timeout_id = 0;
-  if (tp->timer) {
-    g_timer_destroy(tp->timer);
-    tp->timer = NULL;
-  }
-  return FALSE;
-}
-
-static void
-post_eos_timeout_add(guint to_ms, GstElement *pipeline, char *error, TimeoutParams *params)
-{
-  params->to_ms = to_ms;
-  params->pipeline = pipeline;
-  params->error = error;
-  params->timer = g_timer_new();
-  params->timeout_id = g_timeout_add(to_ms, (GSourceFunc)post_eos, params);
-}
-
-static void
-post_eos_timeout_remove(TimeoutParams *params)
-{
-  if (params->timeout_id) {
-    g_source_remove(params->timeout_id);
-    params->timeout_id = 0;
-  }
-  if (params->timer) {
-    g_timer_destroy(params->timer);
-    params->timer = NULL;
-  }
-}
-
-static void
-wait_for_eos(GstElement *pipeline, Window dst_window, int duration, TimeoutParams *play_to)
-{
-  GError *err = NULL;
-  char *debug = NULL;
-  gboolean keep_looping = TRUE;
-  GstMessage *message = NULL;
-
-  while (keep_looping) {
-    message = gst_bus_poll(gst_pipeline_get_bus(GST_PIPELINE(pipeline)), GST_MESSAGE_ANY, -1);
-    if (!message) break;
-
-    switch(GST_MESSAGE_TYPE(message)) {
-      case GST_MESSAGE_ASYNC_DONE:
-        g_debug("wait_for_eos: Ready to play: duration = %d\n", duration);
-        if ((duration > 500) && !(play_to->timeout_id))
-          post_eos_timeout_add(duration, pipeline, NULL, play_to);
-        break;
-
-      case GST_MESSAGE_ERROR:
-        gst_message_parse_error(message, &err, &debug);
-        g_warning("wait_for_eos: %s: %s %s\n", GST_MESSAGE_TYPE_NAME(message), err ? err->message : "", debug ? debug : "");
-        if (err)
-          g_error_free(err);
-        g_free(debug);
-        /* fall through */
-      case GST_MESSAGE_EOS:
-        keep_looping = FALSE;
-        gst_element_set_state(pipeline, GST_STATE_PAUSED);
-        g_debug("wait_for_eos: Gst message: %s", GST_MESSAGE_TYPE_NAME(message));
-        break;
-
-      case GST_MESSAGE_ELEMENT:
-        if (gst_structure_has_name(message->structure, "prepare-xwindow-id"))
-          gst_x_overlay_set_xwindow_id(GST_X_OVERLAY(GST_MESSAGE_SRC(message)), dst_window);
-        break;
-
-      default:
-        break;
-    }
-    gst_message_unref(message);
-  }
-}
-
-static void
-unblank_screen()
-{
-#ifdef HAVE_MCE
-  DBusConnection *conn = NULL;
-
-  if ((conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL)) != NULL) {
-    DBusMessage *message, *reply;
-
-    if ((message = dbus_message_new_method_call(MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF, MCE_DISPLAY_ON_REQ)) != NULL) {
-      if ((reply = dbus_connection_send_with_reply_and_block(conn, message, -1, NULL)) != NULL)
-        dbus_message_unref(reply);
-      dbus_message_unref(message);
-    }
-  }
-#endif /* HAVE_MCE */
-}
-
 static GstElement *
-play_logo(Window dst_window, char *video, char *audio, int duration)
+create_pipeline(GstElement **p_audio_bin, GstElement **p_video_bin, GstElement **p_shush_bin)
 {
-  GstElement* pipeline = NULL;
-  GString *pipeline_str = g_string_new("");
+  GstElement *pipeline = NULL;
 
-  g_debug("play_logo: playing (video = '%s', audio = '%s', duration = '%d')", video, audio, duration);
+  pipeline = gst_pipeline_new();
 
-  if (video && video[0])
-    g_string_append_printf(pipeline_str, video_pipeline_str, video);
+  (*p_audio_bin) = gst_element_make("playbin2", "audio_bin");
+  (*p_video_bin) = gst_element_make("playbin2", "video_bin");
 
-  if (audio && audio[0]) {
-    if ('s' == audio[0] && 0 == audio[1])
-      g_string_append_printf(pipeline_str, shush_pipeline_str);
-    else
-      g_string_append_printf(pipeline_str, audio_pipeline_str, audio);
-  }
-
-  pipeline = gst_parse_launch(pipeline_str->str, NULL);
-  g_string_free(pipeline_str, TRUE);
-
-  if (pipeline) {
-    TimeoutParams kill_to = TIMEOUT_PARAMS_STATIC_INIT,
-                  play_to = TIMEOUT_PARAMS_STATIC_INIT;
-
-    post_eos_timeout_add(KILL_TO_LENGTH_MS, pipeline, "Absolute timeout reached!\n", &kill_to);
-
-    gst_element_set_state(pipeline, GST_STATE_PLAYING);
-    unblank_screen();
-    wait_for_eos(pipeline, dst_window, duration, &play_to);
-
-    post_eos_timeout_remove(&kill_to);
-    post_eos_timeout_remove(&play_to);
-  }
-
   return pipeline;
 }
 
-/* Paint a black filled rectangle over the given window */
-static void
-draw_black(Display *dpy, Window dst_window)
-{
-  XGCValues vals;
-  Window root_window;
-  int x, y;
-  unsigned int cx, cy, cx_border, depth;
-
-  if (!XGetGeometry(dpy, dst_window, &root_window, &x, &y, &cx, &cy, &cx_border, &depth)) {
-     x =   0;  y =   0;
-    cx = 800; cy = 480;
-  }
-
-  vals.foreground = BlackPixel(dpy, 0);
-  vals.background = BlackPixel(dpy, 0);
-  GC gc = XCreateGC(dpy, dst_window, GCForeground | GCBackground, &vals);
-  XFillRectangle(dpy, dst_window, gc, x, y, cx, cy);
-  XFreeGC(dpy, gc);
-  XFlush(dpy);
-}
-
 int
 main(int argc, char **argv)
 {
@@ -283,7 +110,6 @@
   int duration;
   ConfFileIterator *itr;
   Window dst_window = 0, xcomposite_window = 0;
-  GstElement *new_pipeline = NULL, *old_pipeline = NULL;
 
   if (!g_thread_supported ()) g_thread_init(NULL);
 
@@ -308,24 +134,14 @@
 
   if ((itr = conf_file_iterator_new())) {
     while (conf_file_iterator_get(itr, &video, &audio, &duration)) {
-      new_pipeline = play_logo(dst_window, video, audio, duration);
+      g_debug("main: video = %s, audio = %s, duration = %d\n", video, audio, duration);
       g_free(video); video = NULL;
       g_free(audio); audio = NULL;
       duration = 0;
-      if (old_pipeline) {
-        gst_element_set_state(old_pipeline, GST_STATE_NULL);
-        gst_object_unref(old_pipeline);
-      }
-      old_pipeline = new_pipeline;
     }
     conf_file_iterator_destroy(itr);
   }
 
-  /* Prevent the green flash before the application quits */
-  draw_black(display, dst_window);
-  gst_element_set_state(new_pipeline, GST_STATE_NULL);
-  gst_object_unref(new_pipeline);
-
   if (xcomposite_window)
     XCompositeReleaseOverlayWindow(display, xcomposite_window);
 

Added: projects/haf/trunk/hildon-welcome/src/tmp.c
===================================================================
--- projects/haf/trunk/hildon-welcome/src/tmp.c	2009-03-27 09:15:41 UTC (rev 17828)
+++ projects/haf/trunk/hildon-welcome/src/tmp.c	2009-03-27 09:33:25 UTC (rev 17829)
@@ -0,0 +1,136 @@
+#include <stdlib.h>
+#include <gst/gst.h>
+
+#define GST_STATE_NAME(state)             \
+  ((GST_STATE_VOID_PENDING == (state))    \
+    ? "GST_STATE_VOID_PENDING"            \
+    : (GST_STATE_NULL == (state))         \
+      ? "GST_STATE_NULL"                  \
+      : (GST_STATE_READY == (state))      \
+        ? "GST_STATE_READY"               \
+        : (GST_STATE_PAUSED == (state))   \
+          ? "GST_STATE_PAUSED"            \
+          : "GST_STATE_PLAYING")
+
+static void
+play_pipeline(GstElement *pipeline)
+{
+  GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
+
+  gst_element_set_state(pipeline, GST_STATE_PLAYING);
+
+  if (bus) {
+    GstMessage *msg = NULL;
+    gboolean keep_looping = TRUE;
+
+    while (keep_looping) {
+      msg = gst_bus_poll(bus, GST_MESSAGE_ANY, -1);
+      g_print("play_pipeline: Got message %s\n", GST_MESSAGE_TYPE_NAME(msg));
+      if (!msg) break;
+
+      switch(GST_MESSAGE_TYPE(msg)) {
+        case GST_MESSAGE_STATE_CHANGED:
+          if (pipeline == GST_ELEMENT(GST_MESSAGE_SRC(msg)))
+          {
+            GstState oldstate, newstate, pending;
+
+            gst_message_parse_state_changed(msg, &oldstate, &newstate, &pending);
+            g_print("play_pipeline: state-changed: old = %s, new = %s, pending = %s\n", 
+              GST_STATE_NAME(oldstate),
+              GST_STATE_NAME(newstate),
+              GST_STATE_NAME(pending));
+          }
+          break;
+
+        case GST_MESSAGE_ERROR:
+          {
+            GError *err = NULL;
+            char *debug = NULL;
+            gst_message_parse_error(msg, &err, &debug);
+            g_print("play_pipeline: %s: %s %s\n", GST_MESSAGE_TYPE_NAME(msg), err ? err->message : "", debug ? debug : "");
+            if (err)
+              g_error_free(err);
+            g_free(debug);
+          }
+          /* fall through */
+        case GST_MESSAGE_EOS:
+        case GST_MESSAGE_SEGMENT_DONE:
+          g_print("play_pipeline: SEGMENT_DONE received\n");
+          gst_element_set_state(pipeline, GST_STATE_PAUSED);
+          keep_looping = FALSE;
+          break;
+
+        default:
+          break;
+      }
+
+      gst_message_unref(msg);
+    }
+  }
+}
+
+static void
+no_more_pads(GstElement *decodebin2, GstElement *output)
+{
+  g_print("no_more_pads: Linking input to output\n");
+  gst_element_link(decodebin2, output);
+}
+
+static GstElement *
+create_bin(const char *fname, GstElement *output)
+{
+  GstElement *filesrc, *decodebin2, *bin;
+  static int counter = 0;
+  char *name = g_strdup_printf("audio_bin%d", counter++);
+
+  bin = gst_bin_new(name);
+  g_free(name);
+  filesrc = gst_element_factory_make("filesrc", "audio_filesrc");
+  g_object_set(G_OBJECT(filesrc), "location", fname, NULL);
+  decodebin2 = gst_element_factory_make("decodebin2", "audio_decodebin");
+  gst_bin_add_many(GST_BIN(bin), filesrc, decodebin2, NULL);
+  gst_element_link(filesrc, decodebin2);
+
+  g_signal_connect(G_OBJECT(decodebin2), "no-more-pads", (GCallback)no_more_pads, output);
+
+  return bin;
+}
+
+int
+main(int argc, char **argv)
+{
+  GstEvent *seek;
+  int Nix;
+  GstElement *pipeline, *autoaudiosink, *old_bin = NULL, *new_bin = NULL;
+
+  gst_init(&argc, &argv);
+
+  pipeline = gst_pipeline_new("myname");
+  autoaudiosink = gst_element_factory_make("autoaudiosink", "audio_autoaudiosink");
+  seek = gst_event_new_seek(1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_SEGMENT, GST_SEEK_TYPE_SET, G_GUINT64_CONSTANT(0), GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE);
+
+  gst_bin_add(GST_BIN(pipeline), autoaudiosink);
+
+  for (Nix = 1 ; Nix < argc ; Nix++) {
+    g_print("main: playing argv[%d] = %s\n", Nix, argv[Nix]);
+    new_bin = create_bin(argv[Nix], autoaudiosink);
+    if (old_bin) {
+      gst_element_set_locked_state(old_bin, TRUE);
+      gst_element_set_state(old_bin, GST_STATE_NULL);
+      gst_bin_remove(GST_BIN(pipeline), old_bin);
+    }
+    gst_bin_add(GST_BIN(pipeline), new_bin);
+    gst_element_set_state(pipeline, GST_STATE_PAUSED);
+    gst_element_send_event(pipeline, seek);
+    play_pipeline(pipeline);
+    old_bin = new_bin;
+    g_print("main: played argv[%d] = %s\n", Nix, argv[Nix]);
+  }
+
+  gst_element_set_state(pipeline, GST_STATE_NULL);
+  gst_object_unref(pipeline);
+
+  gst_deinit();
+
+  return 0;
+}


More information about the maemo-commits mailing list