libgstplay has a new home. it still needs to be packaged though
authorSteve Baker <steve@stevebaker.org>
Sun, 27 Oct 2002 20:59:41 +0000 (20:59 +0000)
committerSteve Baker <steve@stevebaker.org>
Sun, 27 Oct 2002 20:59:41 +0000 (20:59 +0000)
Original commit message from CVS:
libgstplay has a new home. it still needs to be packaged though

gst-libs/gst/Makefile.am
gst-libs/gst/play/Makefile.am [new file with mode: 0644]
gst-libs/gst/play/play.old.c [new file with mode: 0644]
gst-libs/gst/play/play.old.h [new file with mode: 0644]
gst-libs/gst/play/playpipelines.c [new file with mode: 0644]

index d6eaa87..1eeac77 100644 (file)
@@ -4,6 +4,6 @@ else
 GCONF_DIR=
 endif
 
-SUBDIRS = audio idct resample riff floatcast $(GCONF_DIR) video
+SUBDIRS = audio idct resample riff floatcast $(GCONF_DIR) video play
 
-DIST_SUBDIRS = audio idct resample riff floatcast gconf video
+DIST_SUBDIRS = audio idct resample riff floatcast gconf video play
diff --git a/gst-libs/gst/play/Makefile.am b/gst-libs/gst/play/Makefile.am
new file mode 100644 (file)
index 0000000..52b0d15
--- /dev/null
@@ -0,0 +1,13 @@
+librarydir = $(libdir)
+
+library_LTLIBRARIES = libgstplay.la
+
+libgstplay_la_SOURCES = play.c
+
+libgstplayincludedir = $(includedir)/@PACKAGE@-@VERSION@/gst/play
+libgstplayinclude_HEADERS = play.h
+
+libgstplay_la_CFLAGS = $(GST_CFLAGS) $(GST_PLUGINS_CFLAGS)
+libgstplay_la_LIBADD = $(GST_LIBS) $(GST_PLUGINS_LIBS)
+
+noinst_HEADERS = playpipelines.c
diff --git a/gst-libs/gst/play/play.old.c b/gst-libs/gst/play/play.old.c
new file mode 100644 (file)
index 0000000..2d77367
--- /dev/null
@@ -0,0 +1,890 @@
+/* GStreamer
+ * Copyright (C) 1999,2000,2001,2002 Erik Walthinsen <omega@cse.ogi.edu>
+ *                    2000,2001,2002 Wim Taymans <wtay@chello.be>
+ *                              2002 Steve Baker <steve@stevebaker.org>
+ *
+ * play.c: GstPlay object code
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "play.h"
+
+enum {
+       STREAM_END,
+       INFORMATION,
+       STATE_CHANGE,
+       STREAM_LENGTH,
+       TIME_TICK,
+       HAVE_XID,
+       HAVE_VIDEO_SIZE,
+       LAST_SIGNAL,
+};
+
+/* this struct is used to decouple signals coming out of threaded pipelines */
+typedef struct _GstPlaySignal    GstPlaySignal;
+struct _GstPlaySignal
+{
+       gint signal_id;
+       union {
+               struct {
+                       gint width;
+                       gint height;
+               } video_size;
+               struct {
+                       gint xid;
+               } video_xid;
+               struct {
+                       GstElementState old_state;
+                       GstElementState new_state;
+               } state;
+               struct {
+                       GstElement* element;
+                       GParamSpec* param;
+               } info;
+       } signal_data;
+};
+
+enum
+{
+       ARG_0,
+       ARG_LOCATION,
+       ARG_VOLUME,
+       ARG_MUTE,
+       /* FILL ME */
+};
+
+static guint gst_play_signals [LAST_SIGNAL] = { 0 };
+
+static void         gst_play_init                  (GstPlay *play);
+static void         gst_play_class_init                    (GstPlayClass *klass);
+static void         gst_play_dispose               (GObject *object);
+
+static void         gst_play_default_timeout_add    (guint interval, GSourceFunc function, gpointer data);
+static void         gst_play_default_idle_add       (GSourceFunc function, gpointer data);
+
+static void         gst_play_set_property          (GObject *object, guint prop_id, 
+                                                    const GValue *value, GParamSpec *pspec);
+static void         gst_play_get_property          (GObject *object, guint prop_id, 
+                                                    GValue *value, GParamSpec *pspec);
+static void         callback_pipeline_state_change  (GstElement *element, GstElementState old, 
+                                                    GstElementState state, GstPlay *play);
+static void         callback_pipeline_deep_notify   (GstElement *element, GstElement *orig, 
+                                                    GParamSpec *param, GstPlay *play);
+static void         callback_audio_sink_eos         (GstElement *element, GstPlay *play);
+static void         callback_video_have_xid         (GstElement *element, gint xid, GstPlay *play);
+static void         callback_video_have_size        (GstElement *element, gint width, gint height, GstPlay *play);
+
+
+static void         callback_bin_pre_iterate        (GstBin *bin, GMutex *mutex);
+static void         callback_bin_post_iterate       (GstBin *bin, GMutex *mutex);
+
+static gboolean     gst_play_idle_signal            (GstPlay *play);
+static gboolean     gst_play_idle_callback         (GstPlay *play);
+static gboolean     gst_play_get_length_callback    (GstPlay *play);
+static gboolean     gst_play_tick_callback          (GstPlay *play);
+
+GQuark
+gst_play_error_quark (void)
+{
+       static GQuark quark = 0;
+       if (quark == 0) {
+               quark = g_quark_from_static_string ("gst-play-error-quark");
+       }
+
+       return quark;
+}
+
+/* GError creation when plugin is missing */
+/* If we want to make error messages less generic and have more errors
+ * than only plug-ins, move the message creation to the switch */
+static void
+gst_play_error_plugin (GstPlayError type, GError **error)
+{
+        gchar *name;
+
+        if (error == NULL) return;
+
+        switch (type)
+        {
+                case GST_PLAY_ERROR_THREAD:
+                        name = g_strdup ("thread");
+                        break;
+                case GST_PLAY_ERROR_QUEUE:
+                        name = g_strdup ("queue");
+                        break;
+                case GST_PLAY_ERROR_FAKESINK:
+                        name = g_strdup ("fakesink");
+                        break;
+                case GST_PLAY_ERROR_VOLUME:
+                        name = g_strdup ("volume");
+                        break;
+                case GST_PLAY_ERROR_COLORSPACE:
+                        name = g_strdup ("colorspace");
+                        break;
+                case GST_PLAY_ERROR_GNOMEVFSSRC:
+                        name = g_strdup ("gnomevfssrc");
+                        break;
+                default:
+                        name = g_strdup ("unknown");
+                        break;
+        }
+        *error = g_error_new (GST_PLAY_ERROR, type,
+                              "The %s plug-in could not be found. "
+                              "This plug-in is essential for gst-player. "
+                              "Please install it and verify that it works "
+                              "by running 'gst-inspect %s'",
+                              name, name);
+        g_free (name);
+        return;
+}
+
+/* split static pipeline functions to a seperate file */
+#include "playpipelines.c"
+
+static GstElementClass * parent_class = NULL;
+
+GType
+gst_play_get_type (void)
+{
+       static GType play_type = 0;
+       
+       if (!play_type)
+       {
+               static const GTypeInfo play_info = {
+                       sizeof (GstPlayClass),
+                       (GBaseInitFunc) NULL,
+                       (GBaseFinalizeFunc) NULL,
+                       (GClassInitFunc) gst_play_class_init,
+                       NULL, NULL, sizeof (GstPlay),
+                       0, (GInstanceInitFunc) gst_play_init,
+                       NULL
+               };
+      
+               play_type = g_type_register_static (G_TYPE_OBJECT, "GstPlay", &play_info, 0);
+       }
+
+       return play_type;
+}
+
+static void
+gst_play_class_init (GstPlayClass *klass)
+{
+       GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+  
+       parent_class = g_type_class_ref(GST_TYPE_OBJECT);
+
+       klass->information = NULL;
+       klass->state_changed = NULL;
+       klass->stream_end = NULL;
+  
+       gobject_class->dispose = gst_play_dispose;
+       gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_play_set_property);
+       gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_play_get_property);
+
+       g_object_class_install_property (gobject_class, ARG_LOCATION,
+               g_param_spec_string ("location", "location of file", 
+                                    "location of the file to play",
+                                    NULL, G_PARAM_READWRITE));
+       g_object_class_install_property (gobject_class, ARG_VOLUME,
+               g_param_spec_float ("volume", "Playing volume", 
+                                   "Playing volume", 
+                                                            0, 1.0, 0, G_PARAM_READWRITE));
+       g_object_class_install_property (gobject_class, ARG_MUTE,
+                                        g_param_spec_boolean ("mute", "Volume muted", "Playing volume muted",
+                                                              FALSE, G_PARAM_READWRITE));
+  
+       gst_play_signals [INFORMATION] = 
+               g_signal_new ("information", 
+                             G_TYPE_FROM_CLASS (klass), 
+                             G_SIGNAL_RUN_FIRST,
+                             G_STRUCT_OFFSET (GstPlayClass, information), 
+                             NULL, NULL,
+                             gst_marshal_VOID__OBJECT_PARAM, 
+                             G_TYPE_NONE, 2, 
+                             G_TYPE_OBJECT, G_TYPE_PARAM);
+       
+       gst_play_signals [STATE_CHANGE] = 
+               g_signal_new ("state_change", 
+                             G_TYPE_FROM_CLASS (klass), 
+                             G_SIGNAL_RUN_FIRST,
+                             G_STRUCT_OFFSET (GstPlayClass, state_changed), 
+                             NULL, NULL,
+                             gst_marshal_VOID__INT_INT,
+                             G_TYPE_NONE, 2, 
+                             G_TYPE_INT, G_TYPE_INT);
+       
+       gst_play_signals [STREAM_END] =
+               g_signal_new ("stream_end",
+                             G_TYPE_FROM_CLASS (klass),
+                             G_SIGNAL_RUN_FIRST,
+                             G_STRUCT_OFFSET (GstPlayClass, stream_end),
+                             NULL, NULL,
+                             gst_marshal_VOID__VOID,
+                             G_TYPE_NONE, 0);
+
+       gst_play_signals [TIME_TICK] = 
+               g_signal_new ("time_tick", 
+                             G_TYPE_FROM_CLASS (klass), 
+                             G_SIGNAL_RUN_FIRST,
+                             G_STRUCT_OFFSET (GstPlayClass, time_tick), 
+                             NULL, NULL,
+                             gst_marshal_VOID__INT64,
+                             G_TYPE_NONE, 1, 
+                             G_TYPE_INT64);
+
+       gst_play_signals [STREAM_LENGTH] = 
+               g_signal_new ("stream_length", 
+                             G_TYPE_FROM_CLASS (klass), 
+                             G_SIGNAL_RUN_FIRST,
+                             G_STRUCT_OFFSET (GstPlayClass, stream_length), 
+                             NULL, NULL,
+                             gst_marshal_VOID__INT64,
+                             G_TYPE_NONE, 1, 
+                             G_TYPE_INT64);
+
+       gst_play_signals [HAVE_XID] = 
+               g_signal_new ("have_xid", 
+                             G_TYPE_FROM_CLASS (klass), 
+                             G_SIGNAL_RUN_FIRST,
+                             G_STRUCT_OFFSET (GstPlayClass, have_xid), 
+                             NULL, NULL,
+                             gst_marshal_VOID__INT,
+                             G_TYPE_NONE, 1, 
+                             G_TYPE_INT);
+
+       gst_play_signals [HAVE_VIDEO_SIZE] = 
+               g_signal_new ("have_video_size", 
+                             G_TYPE_FROM_CLASS (klass), 
+                             G_SIGNAL_RUN_FIRST,
+                             G_STRUCT_OFFSET (GstPlayClass, have_video_size), 
+                             NULL, NULL,
+                             gst_marshal_VOID__INT_INT,
+                             G_TYPE_NONE, 2, 
+                             G_TYPE_INT, G_TYPE_INT);
+
+       gst_control_init(NULL,NULL);
+}
+
+
+
+static void 
+gst_play_init (GstPlay *play) 
+{
+       play->pipeline     = NULL;
+       play->source       = NULL;
+       play->autoplugger  = NULL;
+       play->audio_sink   = NULL;
+       play->audio_sink_element   = NULL;
+       play->video_sink   = NULL;
+       play->video_sink_element   = NULL;
+       play->volume       = NULL;
+       play->other_elements = g_hash_table_new(g_str_hash, g_str_equal);
+       play->audio_bin_mutex = g_mutex_new();
+       play->video_bin_mutex = g_mutex_new();
+       gst_play_set_idle_timeout_funcs(play, gst_play_default_timeout_add, gst_play_default_idle_add);
+
+}
+
+GstPlay *
+gst_play_new (GstPlayPipeType pipe_type, GError **error)
+{
+       GstPlay *play;
+
+       play = g_object_new (GST_TYPE_PLAY, NULL);
+
+       /* FIXME: looks like only VIDEO ever gets used ! */
+       switch (pipe_type){
+               case GST_PLAY_PIPE_VIDEO:
+                       play->setup_pipeline = gst_play_video_setup;
+                       play->teardown_pipeline = NULL;
+                       play->set_autoplugger = gst_play_video_set_auto;
+                       play->set_video_sink = gst_play_video_set_video;
+                       play->set_audio_sink = gst_play_video_set_audio;
+                       break;
+               case GST_PLAY_PIPE_VIDEO_THREADSAFE:
+                       play->setup_pipeline = gst_play_videots_setup;
+                       play->teardown_pipeline = NULL;
+                       play->set_autoplugger = gst_play_videots_set_auto;
+                       play->set_video_sink = gst_play_videots_set_video;
+                       play->set_audio_sink = gst_play_videots_set_audio;
+                       break;
+               case GST_PLAY_PIPE_AUDIO_THREADED:
+                       play->setup_pipeline = gst_play_audiot_setup;
+                       play->teardown_pipeline = NULL;
+                       play->set_autoplugger = gst_play_audiot_set_auto;
+                       play->set_video_sink = NULL;
+                       play->set_audio_sink = gst_play_audiot_set_audio;
+                       break;
+               case GST_PLAY_PIPE_AUDIO_HYPER_THREADED:
+                       play->setup_pipeline = gst_play_audioht_setup;
+                       play->teardown_pipeline = NULL;
+                       play->set_autoplugger = gst_play_audioht_set_auto;
+                       play->set_video_sink = NULL;
+                       play->set_audio_sink = gst_play_audioht_set_audio;
+                       break;
+               default:
+                       g_warning("unknown pipeline type: %d\n", pipe_type);
+       }
+
+       /* init pipeline */
+       if ((play->setup_pipeline) &&
+           (! play->setup_pipeline (play, error)))
+       {
+               g_object_unref (play);
+               return NULL;
+       }
+
+
+       if (play->pipeline){
+               /* connect to pipeline events */
+               g_signal_connect (G_OBJECT (play->pipeline), "deep_notify", G_CALLBACK (callback_pipeline_deep_notify), play);
+               g_signal_connect (G_OBJECT (play->pipeline), "state_change", G_CALLBACK (callback_pipeline_state_change), play);
+       }
+
+       if (play->volume){
+               play->vol_dpman =  gst_dpman_get_manager(play->volume);
+               play->vol_dparam = gst_dpsmooth_new(G_TYPE_FLOAT);
+  
+               g_object_set(G_OBJECT(play->vol_dparam), "update_period", 2000000LL, NULL);
+  
+               g_object_set(G_OBJECT(play->vol_dparam), "slope_delta_float", 0.1F, NULL);
+               g_object_set(G_OBJECT(play->vol_dparam), "slope_time", 10000000LL, NULL); 
+               if (!gst_dpman_attach_dparam (play->vol_dpman, "volume", play->vol_dparam)){
+                       g_warning("could not attach dparam to volume element\n");
+               }
+               gst_dpman_set_mode(play->vol_dpman, "asynchronous");
+               gst_play_set_volume(play, 0.9);
+       }
+       
+       play->signal_queue = g_async_queue_new();
+
+       return play;
+}
+
+static void
+gst_play_dispose (GObject *object)
+{
+       GstPlay *play = GST_PLAY (object);
+       G_OBJECT_CLASS (parent_class)->dispose (object);
+       g_mutex_free(play->audio_bin_mutex);
+       g_mutex_free(play->video_bin_mutex);
+}
+
+static void
+callback_pipeline_deep_notify (GstElement *element, GstElement *orig, GParamSpec *param, GstPlay* play)
+{
+       GstPlaySignal *signal;
+       signal = g_new0(GstPlaySignal, 1);
+       signal->signal_id = INFORMATION;
+       signal->signal_data.info.element = orig;
+       signal->signal_data.info.param = param;
+       g_async_queue_push(play->signal_queue, signal);
+       play->idle_add_func ((GSourceFunc) gst_play_idle_signal, play);
+}
+
+static void
+callback_pipeline_state_change (GstElement *element, GstElementState old, GstElementState state, GstPlay* play)
+{
+       GstPlaySignal *signal;
+
+       g_return_if_fail (GST_IS_ELEMENT (element));
+       g_return_if_fail (GST_IS_PLAY (play));
+       g_return_if_fail (element == play->pipeline);
+
+       /*g_print ("got state change %s to %s\n", gst_element_state_get_name (old), gst_element_state_get_name (state));*/
+
+       /* do additional stuff depending on state */
+       if (GST_IS_PIPELINE (play->pipeline)){
+               switch (state) {
+               case GST_STATE_PLAYING:
+                       play->idle_add_func ((GSourceFunc) gst_play_idle_callback, play);
+                       play->timeout_add_func (200, (GSourceFunc) gst_play_tick_callback, play);
+                       if (play->length_nanos == 0LL){
+                               /* try to get the length up to 16 times */
+                               play->get_length_attempt = 16;
+                               play->timeout_add_func (200, (GSourceFunc) gst_play_get_length_callback, play);
+                       }
+                       break;
+               default:
+                       break;
+               }
+       }       
+       signal = g_new0(GstPlaySignal, 1);
+       signal->signal_id = STATE_CHANGE;
+       signal->signal_data.state.old_state = old;
+       signal->signal_data.state.new_state = state;
+       g_async_queue_push(play->signal_queue, signal);
+       play->idle_add_func ((GSourceFunc) gst_play_idle_signal, play);
+}
+
+static gboolean
+gst_play_idle_signal (GstPlay *play)
+{
+       GstPlaySignal *signal;
+       gint queue_length;
+
+       signal = g_async_queue_try_pop(play->signal_queue);
+       if (signal == NULL){
+               return FALSE;
+       }
+
+       switch (signal->signal_id){
+       case HAVE_XID:
+               g_signal_emit (G_OBJECT (play), gst_play_signals[HAVE_XID], 0,
+                              signal->signal_data.video_xid.xid);
+               break;
+       case HAVE_VIDEO_SIZE:
+               g_signal_emit (G_OBJECT (play), gst_play_signals[HAVE_VIDEO_SIZE], 0, 
+                              signal->signal_data.video_size.width, signal->signal_data.video_size.height);
+               break;
+       case STATE_CHANGE:
+               g_signal_emit (G_OBJECT (play), gst_play_signals[STATE_CHANGE], 0, 
+                              signal->signal_data.state.old_state, signal->signal_data.state.new_state);
+               break;
+       case INFORMATION:
+               g_signal_emit (G_OBJECT (play), gst_play_signals[INFORMATION], 0, 
+                              signal->signal_data.info.element, signal->signal_data.info.param);
+               break;
+       default:
+               break;
+       }
+
+       g_free(signal);
+       queue_length = g_async_queue_length (play->signal_queue);
+       return (queue_length > 0);
+}
+
+static gboolean
+gst_play_idle_eos (GstPlay* play)
+{
+       g_signal_emit (G_OBJECT (play), gst_play_signals [STREAM_END], 0);
+       return FALSE;
+}
+
+static void
+callback_audio_sink_eos (GstElement *element, GstPlay *play)
+{
+       play->idle_add_func ((GSourceFunc) gst_play_idle_eos, play);
+}
+
+static void
+callback_video_have_xid (GstElement *element, gint xid, GstPlay *play)
+{
+       GstPlaySignal *signal;
+       signal = g_new0(GstPlaySignal, 1);
+       signal->signal_id = HAVE_XID;
+       signal->signal_data.video_xid.xid = xid;
+       g_async_queue_push(play->signal_queue, signal);
+       play->idle_add_func ((GSourceFunc) gst_play_idle_signal, play);
+       /*g_print("have xid %d\n", xid);*/
+}
+
+static void
+callback_video_have_size (GstElement *element, gint width, gint height, GstPlay *play)
+{
+       GstPlaySignal *signal;
+       signal = g_new0(GstPlaySignal, 1);
+       signal->signal_id = HAVE_VIDEO_SIZE;
+       signal->signal_data.video_size.width = width;
+       signal->signal_data.video_size.height = height;
+       g_async_queue_push(play->signal_queue, signal);
+       play->idle_add_func ((GSourceFunc) gst_play_idle_signal, play);
+       /*g_print("have size %d x %d\n", width, height);*/
+}
+
+static void 
+callback_bin_pre_iterate (GstBin *bin, GMutex *mutex)
+{
+       g_mutex_lock(mutex);
+}
+
+static void 
+callback_bin_post_iterate (GstBin *bin, GMutex *mutex)
+{
+       g_mutex_unlock(mutex);
+}
+
+static gboolean
+gst_play_get_length_callback (GstPlay *play)
+{
+       gint64 value;
+       GstFormat format = GST_FORMAT_TIME;
+       gboolean query_worked = FALSE;
+
+       g_print("trying to get length\n");
+       if (play->audio_sink_element != NULL){
+               g_mutex_lock(play->audio_bin_mutex);
+               query_worked = gst_element_query (play->audio_sink_element, GST_PAD_QUERY_TOTAL, &format, &value);
+               g_mutex_unlock(play->audio_bin_mutex);
+       }
+       else if (play->video_sink_element != NULL){
+               g_mutex_lock(play->video_bin_mutex);
+               query_worked = gst_element_query (play->video_sink_element, GST_PAD_QUERY_TOTAL, &format, &value);
+               g_mutex_unlock(play->video_bin_mutex);
+       }
+       if (query_worked){
+               g_print("got length %lld\n", value);
+               g_signal_emit (G_OBJECT (play), gst_play_signals [STREAM_LENGTH], 0, value);
+               play->length_nanos = value;
+               return FALSE;
+       }
+       else {
+               if (play->get_length_attempt-- < 1){
+                       /* we've tried enough times, give up */
+                       return FALSE;
+               }
+       }
+       return (gst_element_get_state(play->pipeline) == GST_STATE_PLAYING);
+}
+
+static gboolean
+gst_play_tick_callback (GstPlay *play)
+{
+       gint secs;
+       play->clock = gst_bin_get_clock (GST_BIN (play->pipeline));
+       play->time_nanos = gst_clock_get_time(play->clock);
+       secs = (gint) (play->time_nanos / GST_SECOND);
+       if (secs != play->time_seconds){
+               play->time_seconds = secs;
+               g_signal_emit (G_OBJECT (play), gst_play_signals [TIME_TICK], 0, play->time_nanos);
+       }
+
+       return (gst_element_get_state(play->pipeline) == GST_STATE_PLAYING);
+}
+
+static gboolean
+gst_play_idle_callback (GstPlay *play)
+{
+       return gst_bin_iterate (GST_BIN (play->pipeline));
+}
+
+static void
+gst_play_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+       GstPlay *play = GST_PLAY (object);
+
+       g_return_if_fail (GST_IS_PLAY (play));
+       
+       switch (prop_id) {
+       case ARG_LOCATION:
+               gst_play_set_location(play, g_value_get_string (value));
+               break;
+       case ARG_VOLUME:
+               gst_play_set_volume(play, g_value_get_float (value));
+               break;
+       case ARG_MUTE:
+               gst_play_set_mute(play, g_value_get_boolean (value));
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+               break;
+       }
+}
+
+static void
+gst_play_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+       GstPlay *play = GST_PLAY (object);
+
+       g_return_if_fail (GST_IS_PLAY (play));
+
+       switch (prop_id) {
+       case ARG_LOCATION:
+               g_value_set_string (value, gst_play_get_location(play));
+               break;
+       case ARG_VOLUME:
+               g_value_set_float(value, gst_play_get_volume(play));
+               break;
+       case ARG_MUTE:
+               g_value_set_boolean (value, gst_play_get_mute(play));
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+               break;
+       }
+}
+
+void
+gst_play_seek_to_time (GstPlay *play, gint64 time_nanos)
+{
+       GstEvent *s_event;
+       gboolean audio_seek_worked = FALSE;
+       gboolean video_seek_worked = FALSE;
+       
+       g_return_if_fail (GST_IS_PLAY (play));
+       if (time_nanos < 0LL){
+               play->seek_time = 0LL;
+       }
+       else if (time_nanos < 0LL){
+               play->seek_time = play->length_nanos;
+       }
+       else {
+               play->seek_time = time_nanos;
+       }
+
+       /*g_print("doing seek to %lld\n", play->seek_time);*/
+       gst_element_set_state(play->pipeline, GST_STATE_PAUSED);
+
+       s_event = gst_event_new_seek (GST_FORMAT_TIME |
+                                     GST_SEEK_METHOD_SET |
+                                     GST_SEEK_FLAG_FLUSH, play->seek_time);
+       if (play->audio_sink_element != NULL){
+               gst_event_ref (s_event);
+               audio_seek_worked = gst_element_send_event (play->audio_sink_element, s_event);
+       }
+       if (play->video_sink_element != NULL){
+               gst_event_ref (s_event);
+               video_seek_worked = gst_element_send_event (play->video_sink_element, s_event);
+       }
+       gst_event_unref (s_event);
+
+       if (audio_seek_worked || video_seek_worked){
+               play->time_nanos = gst_clock_get_time(play->clock);
+               g_signal_emit (G_OBJECT (play), gst_play_signals [TIME_TICK], 0, play->time_nanos);
+       }
+       gst_element_set_state(play->pipeline, GST_STATE_PLAYING);
+}
+
+void
+gst_play_need_new_video_window(GstPlay *play)
+{
+       g_return_if_fail (GST_IS_PLAY (play));
+       if (GST_IS_ELEMENT(play->video_sink_element)){
+               g_object_set(G_OBJECT(play->video_sink_element), "need_new_window", TRUE, NULL);
+       }
+}
+
+static gboolean
+gst_play_default_idle (GstPlayIdleData *idle_data)
+{
+       if(idle_data->func(idle_data->data)){
+               /* call this function again in the future */
+               return TRUE;
+       }
+       /* this function should no longer be called */
+       g_free(idle_data);
+       return FALSE;
+}
+
+static void
+gst_play_default_timeout_add (guint interval, GSourceFunc function, gpointer data)
+{
+       GstPlayIdleData *idle_data = g_new0(GstPlayIdleData, 1);
+       idle_data->func = function;
+       idle_data->data = data;
+       g_timeout_add (interval, (GSourceFunc)gst_play_default_idle, idle_data);
+}
+
+static void
+gst_play_default_idle_add (GSourceFunc function, gpointer data)
+{
+       GstPlayIdleData *idle_data = g_new0(GstPlayIdleData, 1);
+       idle_data->func = function;
+       idle_data->data = data;
+       g_idle_add ((GSourceFunc)gst_play_default_idle, idle_data);
+}
+
+void
+gst_play_set_idle_timeout_funcs (GstPlay *play, GstPlayTimeoutAdd timeout_add_func, GstPlayIdleAdd idle_add_func)
+{
+       g_return_if_fail (GST_IS_PLAY (play));
+       play->timeout_add_func = timeout_add_func;
+       play->idle_add_func = idle_add_func;
+}
+
+GstElement*
+gst_play_get_sink_element (GstPlay *play, GstElement *element){
+       GstPad *pad = NULL;
+       GList *elements = NULL;
+       const GList *pads = NULL;
+       gboolean has_src;
+
+       g_return_val_if_fail (GST_IS_PLAY (play), NULL);
+       g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
+
+       if (!GST_IS_BIN(element)){
+               /* since its not a bin, we'll presume this 
+                * element is a sink element */         
+               return element;
+       }
+
+       elements = (GList *) gst_bin_get_list (GST_BIN(element));
+       /* traverse all elements looking for a src pad */
+       while (elements && pad == NULL) {       
+               element = GST_ELEMENT (elements->data);
+               pads = gst_element_get_pad_list (element);
+               has_src = FALSE;
+               while (pads) {
+                       /* check for src pad */
+                       if (GST_PAD_DIRECTION (GST_PAD (pads->data)) == GST_PAD_SRC) {
+                               has_src = TRUE;
+                               break;
+                       }
+                       pads = g_list_next (pads);
+               }
+               if (!has_src){
+                       return element;
+               }
+               elements = g_list_next (elements);
+       }
+       /* we didn't find a sink element */
+       return NULL;
+}
+
+gboolean
+gst_play_set_video_sink (GstPlay *play, GstElement *video_sink)
+{
+       g_return_val_if_fail (GST_IS_PLAY (play), FALSE);
+       g_return_val_if_fail (GST_IS_ELEMENT (video_sink), FALSE);
+
+       if (gst_play_get_state (play) != GST_STATE_READY){
+               gst_play_set_state (play, GST_STATE_READY);
+       }
+
+       if (play->set_video_sink){
+               return play->set_video_sink(play, video_sink);
+       }
+
+       /* if there is no set_video_sink func, fail quietly */
+       return FALSE;
+}
+
+gboolean
+gst_play_set_audio_sink (GstPlay *play, GstElement *audio_sink)
+{
+       g_return_val_if_fail (GST_IS_PLAY (play), FALSE);
+       g_return_val_if_fail (GST_IS_ELEMENT (audio_sink), FALSE);
+
+       if (gst_play_get_state (play) != GST_STATE_READY){
+               gst_play_set_state (play, GST_STATE_READY);
+       }
+
+       if (play->set_audio_sink){
+               return play->set_audio_sink(play, audio_sink);
+       }
+
+       /* if there is no set_audio_sink func, fail quietly */
+       return FALSE;
+}
+
+GstElementStateReturn
+gst_play_set_state (GstPlay *play, GstElementState state)
+{
+       g_return_val_if_fail (GST_IS_PLAY (play), GST_STATE_FAILURE);
+       g_return_val_if_fail (GST_IS_ELEMENT(play->pipeline), GST_STATE_FAILURE);
+       /*g_print("setting state to %d\n", state);*/
+
+       return gst_element_set_state(play->pipeline, state);
+}
+
+GstElementState
+gst_play_get_state (GstPlay *play)
+{
+       g_return_val_if_fail (GST_IS_PLAY (play), GST_STATE_FAILURE);
+       g_return_val_if_fail (play->pipeline, GST_STATE_FAILURE);
+
+       return gst_element_get_state(play->pipeline);
+}
+
+gboolean
+gst_play_set_location (GstPlay *play, const gchar *location)
+{
+       GstElementState current_state;
+       g_return_val_if_fail (GST_IS_PLAY (play), FALSE);
+       g_return_val_if_fail (location != NULL, FALSE);
+
+       current_state = gst_play_get_state (play);
+       if (current_state != GST_STATE_READY){
+               gst_play_set_state (play, GST_STATE_READY);
+       }
+
+       if (play->set_autoplugger){
+               if (! play->set_autoplugger(play, gst_element_factory_make ("spider", "autoplugger"))){
+                       g_warning ("couldn't replace autoplugger\n");
+                       return FALSE;
+               }
+       }
+
+       /* FIXME check for valid location (somehow) */
+       g_object_set (G_OBJECT (play->source), "location", location, NULL);
+
+       /* reset time/length values */
+       play->time_seconds = 0;
+       play->length_nanos = 0LL;
+       play->time_nanos = 0LL;
+       g_signal_emit (G_OBJECT (play), gst_play_signals [STREAM_LENGTH], 0, 0LL);
+       g_signal_emit (G_OBJECT (play), gst_play_signals [TIME_TICK], 0, 0LL);
+       play->need_stream_length = TRUE;
+
+       return TRUE;
+}
+
+gchar*
+gst_play_get_location (GstPlay *play)
+{
+       gchar* location;
+       g_return_val_if_fail (GST_IS_PLAY (play), NULL);
+       g_return_val_if_fail (GST_IS_ELEMENT(play->source), NULL);
+       g_object_get (G_OBJECT (play->source), "location", &location, NULL);
+       return location;
+}
+
+
+void
+gst_play_set_volume (GstPlay *play, gfloat volume)
+{
+       g_return_if_fail (GST_IS_PLAY (play));
+
+       g_object_set(G_OBJECT(play->vol_dparam), "value_float", volume, NULL);
+}
+
+gfloat
+gst_play_get_volume (GstPlay *play)
+{
+       gfloat volume;
+
+       g_return_val_if_fail (GST_IS_PLAY (play), 0);
+
+       g_object_get(G_OBJECT(play->vol_dparam), "value_float", &volume, NULL);
+
+       return volume;
+}
+
+void
+gst_play_set_mute (GstPlay *play, gboolean mute)
+{
+       g_return_if_fail (GST_IS_PLAY (play));
+
+       g_object_set (G_OBJECT (play->volume), "mute", mute, NULL);
+}
+       
+gboolean
+gst_play_get_mute (GstPlay *play)
+{
+       gboolean mute;
+
+       g_return_val_if_fail (GST_IS_PLAY (play), 0);
+
+       g_object_get (G_OBJECT (play->volume), "mute", &mute, NULL);
+
+       return mute;
+}
+
+/* modelines */
+/* vim:set ts=8:sw=8:noet */
+
diff --git a/gst-libs/gst/play/play.old.h b/gst-libs/gst/play/play.old.h
new file mode 100644 (file)
index 0000000..16fbb00
--- /dev/null
@@ -0,0 +1,176 @@
+/* GStreamer
+ * Copyright (C) 1999,2000,2001,2002 Erik Walthinsen <omega@cse.ogi.edu>
+ *                    2000,2001,2002 Wim Taymans <wtay@chello.be>
+ *                              2002 Steve Baker <steve@stevebaker.org>
+ *
+ * play.h: GstPlay object code
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GSTPLAY_H__
+#define __GSTPLAY_H__
+
+#include <gst/gst.h>
+#include <gst/control/control.h>
+
+/*
+ * GstPlay is a simple class for audio and video playback.
+ * It's job is to get the media (supplied by a URI) played.  
+ * More specific it should get the media from source to the output elements.
+ * How that is done should not be relevant for developers using this class. 
+ * A user using this class should not have to know very much about how
+ * GStreamer works, other than that it plays back media.
+ * Additionally it supplies signals to get information about the current
+ * playing state.
+ */
+
+typedef enum {
+       GST_PLAY_OK,
+       GST_PLAY_UNKNOWN_MEDIA,
+       GST_PLAY_CANNOT_PLAY,
+       GST_PLAY_ERROR,
+} GstPlayReturn;
+
+typedef enum {
+       GST_PLAY_PIPE_AUDIO,
+       GST_PLAY_PIPE_AUDIO_THREADED,
+       GST_PLAY_PIPE_AUDIO_HYPER_THREADED,
+       GST_PLAY_PIPE_VIDEO_THREADSAFE,
+       GST_PLAY_PIPE_VIDEO,
+} GstPlayPipeType;
+
+typedef enum {
+       GST_PLAY_ERROR_FAKESINK,
+       GST_PLAY_ERROR_THREAD,
+       GST_PLAY_ERROR_QUEUE,
+       GST_PLAY_ERROR_GNOMEVFSSRC,
+       GST_PLAY_ERROR_VOLUME,
+       GST_PLAY_ERROR_COLORSPACE,
+       GST_PLAY_ERROR_LAST,
+} GstPlayError;
+
+#define GST_PLAY_ERROR                 gst_play_error_quark ()
+
+#define GST_TYPE_PLAY            (gst_play_get_type())
+#define GST_PLAY(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PLAY, GstPlay))
+#define GST_PLAY_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_PLAY, GstPlayClass))
+#define GST_IS_PLAY(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PLAY))
+#define GST_IS_PLAY_CLASS(obj)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_PLAY))
+#define GST_PLAY_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_PLAY, GstPlayClass))
+
+typedef struct _GstPlay          GstPlay;
+typedef struct _GstPlayClass     GstPlayClass;
+typedef struct _GstPlayIdleData  GstPlayIdleData;
+
+typedef void (*GstPlayTimeoutAdd) (guint interval, GSourceFunc function, gpointer data);
+typedef void (*GstPlayIdleAdd)    (GSourceFunc function, gpointer data);
+
+struct _GstPlay
+{
+       GObject parent;
+       
+       gboolean (*setup_pipeline)     (GstPlay *play, GError **error);
+       void (*teardown_pipeline)  (GstPlay *play);
+       gboolean (*set_autoplugger)  (GstPlay *play, GstElement *autoplugger);
+       gboolean (*set_video_sink)     (GstPlay *play, GstElement *videosink);
+       gboolean (*set_audio_sink)     (GstPlay *play, GstElement *audiosink);
+       
+       /* core elements */
+       GstElement *pipeline;
+       GstElement *volume;
+       GstElement *source;
+       GstElement *autoplugger;
+       GstElement *video_sink;
+       GstElement *video_sink_element;
+       GstElement *audio_sink;
+       GstElement *audio_sink_element;
+
+       GstDParamManager *vol_dpman;
+       GstDParam *vol_dparam;
+       GHashTable *other_elements;
+
+       GstClock *clock;
+
+       GMutex *audio_bin_mutex;
+       GMutex *video_bin_mutex;
+
+       gboolean need_stream_length;
+       gboolean need_seek;
+       gint time_seconds;
+       gint get_length_attempt;
+       gint64 seek_time;
+       gint64 time_nanos;
+       gint64 length_nanos;
+
+       GAsyncQueue *signal_queue;
+
+       GstPlayTimeoutAdd timeout_add_func;
+       GstPlayIdleAdd    idle_add_func;
+};
+
+struct _GstPlayClass
+{
+       GObjectClass parent_class;
+       
+       /* signals */
+       void (*information)    (GstPlay* play, GstElement* element, GParamSpec *param);
+       void (*state_changed)  (GstPlay* play, GstElementState old_state, GstElementState new_state);
+       void (*stream_end)     (GstPlay* play);
+       void (*time_tick)    (GstPlay* play, gint64 time_nanos);
+       void (*stream_length)  (GstPlay* play, gint64 length_nanos);
+       void (*have_xid)  (GstPlay* play, gint xid);
+       void (*have_video_size)  (GstPlay* play, gint width, gint height);
+};
+
+struct _GstPlayIdleData
+{
+       GSourceFunc func;
+       gpointer data;
+};
+
+GType    gst_play_get_type        (void);
+
+GstPlay*  gst_play_new            (GstPlayPipeType pipe_type, GError **error);
+
+void      gst_play_seek_to_time (GstPlay *play, gint64 time_nanos);
+
+GstElement*       gst_play_get_sink_element (GstPlay *play, GstElement *element);
+
+gboolean         gst_play_set_video_sink  (GstPlay *play, GstElement *element);
+gboolean         gst_play_set_audio_sink  (GstPlay *play, GstElement *element);
+void             gst_play_need_new_video_window  (GstPlay *play);
+
+GstElementStateReturn gst_play_set_state       (GstPlay *play, GstElementState state);
+GstElementState gst_play_get_state (GstPlay *play);
+
+gboolean  gst_play_set_location    (GstPlay *play, const gchar *location);
+gchar*    gst_play_get_location    (GstPlay *play);
+
+void      gst_play_set_volume      (GstPlay *play, gfloat volume);
+gfloat     gst_play_get_volume      (GstPlay *play);
+
+void      gst_play_set_mute        (GstPlay *play, gboolean mute);
+gboolean  gst_play_get_mute        (GstPlay *play);
+
+void      gst_play_set_idle_timeout_funcs (GstPlay *play, GstPlayTimeoutAdd timeout_add_func, GstPlayIdleAdd idle_add_func);
+
+#endif /* __GSTPLAY_H__ */
+
+/* modelines */
+/* vim:set ts=8:sw=8:noet */
+
diff --git a/gst-libs/gst/play/playpipelines.c b/gst-libs/gst/play/playpipelines.c
new file mode 100644 (file)
index 0000000..8cc8c31
--- /dev/null
@@ -0,0 +1,752 @@
+/* GStreamer
+ * Copyright (C) 1999,2000,2001,2002 Erik Walthinsen <omega@cse.ogi.edu>
+ *                    2000,2001,2002 Wim Taymans <wtay@chello.be>
+ *                              2002 Steve Baker <steve@stevebaker.org>
+ *
+ * playpipelines.c: Set up pipelines for playback
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+/*
+ *  GST_PLAY_PIPE_AUDIO_THREADED
+ *  { gnomevfssrc ! spider ! volume ! osssink }
+ */
+static gboolean 
+gst_play_audiot_setup (GstPlay *play, GError **error)
+{
+       
+       g_return_val_if_fail (GST_IS_PLAY(play), FALSE);
+       
+       /* creating gst_thread */
+       play->pipeline = gst_thread_new ("main_pipeline");
+       g_return_val_if_fail (GST_IS_THREAD (play->pipeline), FALSE);
+
+       /* create source element */
+       play->source = gst_element_factory_make ("gnomevfssrc", "source");
+       if (!play->source)
+       {
+               gst_play_error_plugin (GST_PLAY_ERROR_GNOMEVFSSRC, error);
+               return FALSE;
+       }
+       
+       /* Adding element to bin */
+       gst_bin_add (GST_BIN (play->pipeline), play->source);
+       
+       /* create audio elements */
+       play->volume = gst_element_factory_make ("volume", "volume");
+       if (!play->volume)
+       {
+               gst_play_error_plugin (GST_PLAY_ERROR_VOLUME, error);
+               return FALSE;
+       }
+
+       /* create audiosink.
+       FIXME : Should use gconf to choose the right one */
+       play->audio_sink = gst_element_factory_make ("osssink", "play_audio");
+       if (!play->audio_sink)
+         g_warning ("You need the osssink element to use this program.");
+       
+       g_object_set (
+                       G_OBJECT (play->audio_sink),
+                       "fragment", 0x00180008, NULL);
+       
+       g_signal_connect (
+                       G_OBJECT (play->audio_sink), "eos",
+                       G_CALLBACK (callback_audio_sink_eos), play);
+
+       gst_bin_add_many (
+                       GST_BIN (play->pipeline), play->volume,
+                       play->audio_sink, NULL);
+       
+       gst_element_connect (play->volume, play->audio_sink);
+       
+       gst_bin_set_pre_iterate_function(
+                       GST_BIN (play->pipeline), 
+                       (GstBinPrePostIterateFunction) callback_bin_pre_iterate,
+                       play->audio_bin_mutex);
+                       
+       gst_bin_set_post_iterate_function(
+                       GST_BIN (play->pipeline), 
+                       (GstBinPrePostIterateFunction) callback_bin_post_iterate,
+                       play->audio_bin_mutex);
+
+       return TRUE;
+}
+
+
+static gboolean
+gst_play_audiot_set_audio (GstPlay *play, GstElement *audio_sink)
+{
+       g_return_val_if_fail (GST_IS_PLAY(play), FALSE);
+       g_return_val_if_fail (GST_IS_ELEMENT (audio_sink), FALSE);
+       
+       if (play->audio_sink)
+       {
+               gst_element_disconnect (play->volume, play->audio_sink);
+               gst_bin_remove (GST_BIN (play->pipeline), play->audio_sink);
+       }
+
+       play->audio_sink = audio_sink;
+       gst_bin_add (GST_BIN (play->pipeline), play->audio_sink);
+       gst_element_connect (play->volume, play->audio_sink);
+
+       return TRUE;
+}
+
+
+static gboolean
+gst_play_audiot_set_auto (GstPlay *play, GstElement *autoplugger)
+{
+
+       g_return_val_if_fail (GST_IS_PLAY(play), FALSE);
+       g_return_val_if_fail (GST_IS_ELEMENT (autoplugger), FALSE);
+       
+       if (play->autoplugger){
+               /* we need to remove the existing autoplugger before creating a new one */
+               gst_element_disconnect (play->autoplugger, play->volume);
+               gst_element_disconnect (play->autoplugger, play->source);
+               gst_bin_remove (GST_BIN (play->pipeline), play->autoplugger);
+       }
+       
+       play->autoplugger = autoplugger;
+       g_return_val_if_fail (play->autoplugger != NULL, FALSE);
+
+       gst_bin_add (GST_BIN (play->pipeline), play->autoplugger);
+       gst_element_connect (play->source, play->autoplugger);
+       gst_element_connect (play->autoplugger, play->volume);
+       return TRUE;
+}
+
+/*
+ *  GST_PLAY_PIPE_AUDIO_HYPER_THREADED
+ *  { gnomevfssrc ! spider ! { queue ! volume ! osssink } }
+ */
+
+static gboolean 
+gst_play_audioht_setup (GstPlay *play, GError **error)
+{
+       GstElement *audio_thread, *audio_queue;
+
+       g_return_val_if_fail (GST_IS_PLAY(play), FALSE);
+       
+/*
+       play->pipeline = gst_thread_new ("main_pipeline");
+       g_return_val_if_fail (GST_IS_THREAD (play->pipeline), FALSE);
+*/
+
+       /* creating pipeline */
+       play->pipeline = gst_pipeline_new ("main_pipeline");
+       g_return_val_if_fail (GST_IS_PIPELINE (play->pipeline), FALSE);
+
+       /* create source element */
+       play->source = gst_element_factory_make ("gnomevfssrc", "source");
+       if (!play->source)
+       {
+               gst_play_error_plugin (GST_PLAY_ERROR_GNOMEVFSSRC, error);
+               return FALSE;
+       }
+       
+       /* Adding element to bin */
+       gst_bin_add (GST_BIN (play->pipeline), play->source);
+
+       /* create audio thread */
+       audio_thread = gst_thread_new ("audio_thread");
+       g_return_val_if_fail (GST_IS_THREAD (audio_thread), FALSE);
+       
+       g_hash_table_insert(play->other_elements, "audio_thread", audio_thread);
+       
+       /* create audio queue */
+       audio_queue = gst_element_factory_make ("queue", "audio_queue");
+       if (!audio_queue)
+       {
+               gst_play_error_plugin (GST_PLAY_ERROR_QUEUE, error);
+               return FALSE;
+       }
+       
+       g_hash_table_insert(play->other_elements, "audio_queue", audio_queue);
+       
+       /* create source element */
+       play->volume = gst_element_factory_make ("volume", "volume");
+       if (!play->volume)
+       {
+               gst_play_error_plugin (GST_PLAY_ERROR_VOLUME, error);
+               return FALSE;
+       }
+
+       /* create audiosink.
+       FIXME : Should use gconf to choose the right one */
+       play->audio_sink = gst_element_factory_make ("osssink", "play_audio");
+       if (!play->audio_sink)
+               g_warning ("You need the osssink element to use this program.\n");
+
+       g_object_set (G_OBJECT (play->audio_sink), "fragment", 0x00180008, NULL);
+       
+       g_signal_connect (G_OBJECT (play->audio_sink), "eos",
+                         G_CALLBACK (callback_audio_sink_eos), play);
+
+       gst_bin_add_many (
+                               GST_BIN (audio_thread), audio_queue, play->volume,
+                               play->audio_sink, NULL);
+       
+       gst_element_connect_many (audio_queue, play->volume, play->audio_sink);
+       
+       gst_element_add_ghost_pad (
+                               audio_thread, gst_element_get_pad (audio_queue, "sink"),
+                          "sink");
+
+       gst_bin_add (GST_BIN (play->pipeline), audio_thread);
+
+       gst_bin_set_pre_iterate_function(
+                               GST_BIN (audio_thread), 
+                               (GstBinPrePostIterateFunction) callback_bin_pre_iterate,
+                               play->audio_bin_mutex);
+       
+       gst_bin_set_post_iterate_function(
+                               GST_BIN (audio_thread), 
+                               (GstBinPrePostIterateFunction) callback_bin_post_iterate,
+                               play->audio_bin_mutex);
+
+       return TRUE;
+}
+
+
+static gboolean
+gst_play_audioht_set_audio (GstPlay *play, GstElement *audio_sink)
+{
+       GstElement *audio_thread;
+       
+       g_return_val_if_fail (GST_IS_PLAY(play), FALSE);
+       g_return_val_if_fail (GST_IS_ELEMENT (audio_sink), FALSE);
+
+       audio_thread = g_hash_table_lookup(play->other_elements, "audio_thread");
+
+       if (play->audio_sink)
+       {
+               gst_element_disconnect (play->volume, play->audio_sink);
+               gst_bin_remove (GST_BIN (audio_thread), play->audio_sink);
+       }
+
+       play->audio_sink = audio_sink;
+       gst_bin_add (GST_BIN (audio_thread), play->audio_sink);
+       gst_element_connect (play->volume, play->audio_sink);
+
+       return TRUE;
+}
+
+
+static gboolean
+gst_play_audioht_set_auto (GstPlay *play, GstElement *autoplugger)
+{
+       GstElement *audio_thread;
+       
+       g_return_val_if_fail (GST_IS_PLAY(play), FALSE);
+       g_return_val_if_fail (GST_IS_ELEMENT (autoplugger), FALSE);
+
+       audio_thread = g_hash_table_lookup(play->other_elements, "audio_thread");
+
+       if (play->autoplugger){
+               /* we need to remove the existing autoplugger before creating a new one */
+               gst_element_disconnect (play->autoplugger, audio_thread);
+               gst_element_disconnect (play->autoplugger, play->source);
+               gst_bin_remove (GST_BIN (play->pipeline), play->autoplugger);
+       }
+       
+       play->autoplugger = autoplugger;
+       g_return_val_if_fail (play->autoplugger != NULL, FALSE);
+
+       gst_bin_add (GST_BIN (play->pipeline), play->autoplugger);
+       gst_element_connect (play->source, play->autoplugger);
+       gst_element_connect (play->autoplugger, audio_thread);
+       return TRUE;
+}
+
+/*
+ * GST_PLAY_PIPE_VIDEO
+ * { gnomevfssrc ! spider ! { queue ! volume ! osssink }
+ * spider0.src2 ! { queue ! colorspace ! (videosink) } }
+ */
+
+static gboolean 
+gst_play_video_setup (GstPlay *play, GError **error)
+{
+       GstElement *audio_bin, *audio_queue;
+       GstElement *video_queue, *video_bin;
+       GstElement *work_thread, *colorspace;
+
+       g_return_val_if_fail (GST_IS_PLAY(play), FALSE);
+       
+       /* creating pipeline */ 
+       play->pipeline = gst_pipeline_new ("main_pipeline");
+       g_return_val_if_fail (GST_IS_PIPELINE (play->pipeline), FALSE);
+
+       /* creating work thread */
+       work_thread = gst_thread_new ("work_thread");
+       g_return_val_if_fail (GST_IS_THREAD (work_thread), FALSE);
+       g_hash_table_insert(play->other_elements, "work_thread", work_thread);
+       
+       gst_bin_add (GST_BIN (play->pipeline), work_thread);
+
+       /* create source element */
+       play->source = gst_element_factory_make ("gnomevfssrc", "source");
+       if (!play->source)
+       {
+               gst_play_error_plugin (GST_PLAY_ERROR_GNOMEVFSSRC, error);
+               return FALSE;
+       }       
+       gst_bin_add (GST_BIN (work_thread), play->source);
+       
+       /* creating volume element */
+       play->volume = gst_element_factory_make ("volume", "volume");
+       if (!play->volume)
+       {
+               gst_play_error_plugin (GST_PLAY_ERROR_VOLUME, error);
+               return FALSE;
+       }
+
+       /* creating audio_sink element */
+       play->audio_sink = gst_element_factory_make ("fakesink", "fake_audio");
+       if (!play->audio_sink)
+       {
+               gst_play_error_plugin (GST_PLAY_ERROR_FAKESINK, error);
+               return FALSE;
+       }
+       play->audio_sink_element = NULL;
+
+       /* creating audio_queue element */
+       audio_queue = gst_element_factory_make ("queue", "audio_queue");
+       if (!audio_queue)
+       {
+               gst_play_error_plugin (GST_PLAY_ERROR_QUEUE, error);
+               return FALSE;
+       }       
+       g_hash_table_insert (play->other_elements, "audio_queue", audio_queue);
+       
+       /* creating audio thread */     
+       audio_bin = gst_thread_new ("audio_bin");
+       if (!audio_bin)
+       {
+               gst_play_error_plugin (GST_PLAY_ERROR_THREAD, error);
+               return FALSE;
+       }
+       g_hash_table_insert (play->other_elements, "audio_bin", audio_bin);
+
+       /* setting up iterate functions */      
+       gst_bin_set_pre_iterate_function (
+               GST_BIN (audio_bin), 
+               (GstBinPrePostIterateFunction) callback_bin_pre_iterate, 
+               play->audio_bin_mutex);
+       gst_bin_set_post_iterate_function (
+               GST_BIN (audio_bin), 
+               (GstBinPrePostIterateFunction) callback_bin_post_iterate, 
+               play->audio_bin_mutex);
+
+       /* adding all that stuff to bin */
+       gst_bin_add_many (
+               GST_BIN (audio_bin), audio_queue, play->volume, 
+               play->audio_sink, NULL);
+       gst_element_connect_many (audio_queue, play->volume,
+               play->audio_sink, NULL);
+       
+       gst_element_add_ghost_pad (
+               audio_bin, 
+               gst_element_get_pad (audio_queue, "sink"),
+               "sink");
+
+       gst_bin_add (GST_BIN (work_thread), audio_bin);
+
+       /* create video elements */
+       play->video_sink = gst_element_factory_make ("fakesink", "fake_show");
+       if (!play->video_sink)
+       {
+               gst_play_error_plugin (GST_PLAY_ERROR_FAKESINK, error);
+               return FALSE;
+       }
+       play->video_sink_element = NULL;
+
+       video_queue = gst_element_factory_make ("queue", "video_queue");
+       if (!video_queue)
+       {
+               gst_play_error_plugin (GST_PLAY_ERROR_QUEUE, error);
+               return FALSE;
+       }
+       g_hash_table_insert (play->other_elements, "video_queue", video_queue);
+
+       colorspace = gst_element_factory_make ("colorspace", "colorspace");
+       if (!colorspace)
+       {
+               gst_play_error_plugin (GST_PLAY_ERROR_COLORSPACE, error);
+               return FALSE;
+       }
+       g_hash_table_insert (play->other_elements, "colorspace", colorspace);
+
+       video_bin = gst_thread_new ("video_bin");
+       if (!video_bin)
+       {
+               gst_play_error_plugin (GST_PLAY_ERROR_THREAD, error);
+               return FALSE;
+       }
+       g_hash_table_insert (play->other_elements, "video_bin", video_bin);
+
+       /* adding all that stuff to bin */
+       gst_bin_add_many (GST_BIN (video_bin), video_queue, colorspace, 
+                       play->video_sink, NULL);
+       
+       gst_element_connect_many (video_queue, colorspace,
+                       play->video_sink, NULL);
+       
+       /* setting up iterate functions */
+       gst_bin_set_pre_iterate_function (
+                       GST_BIN (video_bin), 
+                       (GstBinPrePostIterateFunction) callback_bin_pre_iterate, 
+                       play->video_bin_mutex);
+       gst_bin_set_post_iterate_function (
+                       GST_BIN (video_bin), 
+                       (GstBinPrePostIterateFunction) callback_bin_post_iterate,
+                       play->video_bin_mutex);
+       
+       gst_element_add_ghost_pad (
+                       video_bin, gst_element_get_pad (video_queue, "sink"),
+                       "sink");
+                       
+       gst_bin_add (GST_BIN (work_thread), video_bin);
+
+       return TRUE;
+}
+
+
+static gboolean
+gst_play_video_set_auto (GstPlay *play, GstElement *autoplugger){
+
+       GstElement *audio_bin, *video_bin, *work_thread;
+
+       g_return_val_if_fail (GST_IS_PLAY(play), FALSE);
+       g_return_val_if_fail (GST_IS_ELEMENT (autoplugger), FALSE);
+
+       audio_bin = g_hash_table_lookup(play->other_elements, "audio_bin");
+       video_bin = g_hash_table_lookup(play->other_elements, "video_bin");
+       work_thread = g_hash_table_lookup(play->other_elements, "work_thread");
+
+       if (play->autoplugger){
+               /* we need to remove the existing autoplugger before creating a new one */
+               gst_element_disconnect (play->autoplugger, audio_bin);
+               gst_element_disconnect (play->autoplugger, play->source);
+               gst_element_disconnect (play->autoplugger, video_bin);
+
+               gst_bin_remove (GST_BIN (work_thread), play->autoplugger);
+       }
+       
+       play->autoplugger = autoplugger;
+       g_return_val_if_fail (play->autoplugger != NULL, FALSE);
+
+       gst_bin_add (GST_BIN (work_thread), play->autoplugger);
+       gst_element_connect (play->source, play->autoplugger);
+       gst_element_connect (play->autoplugger, audio_bin);
+       gst_element_connect (play->autoplugger, video_bin);
+
+       return TRUE;
+}
+
+
+static gboolean
+gst_play_video_set_video (GstPlay *play, GstElement *video_sink)
+{
+       GstElement *video_mate, *video_bin;
+       
+       g_return_val_if_fail (GST_IS_PLAY(play), FALSE);
+       g_return_val_if_fail (GST_IS_ELEMENT (video_sink), FALSE);
+
+       video_bin = g_hash_table_lookup(play->other_elements, "video_bin");
+       video_mate = g_hash_table_lookup(play->other_elements, "colorspace");
+
+       if (play->video_sink){
+               gst_element_disconnect (video_mate, play->video_sink);
+               gst_bin_remove (GST_BIN (video_bin), play->video_sink);
+       }
+       play->video_sink = video_sink;
+       gst_bin_add (GST_BIN (video_bin), play->video_sink);
+       gst_element_connect (video_mate, play->video_sink);
+
+       play->video_sink_element = gst_play_get_sink_element (play, video_sink);
+
+       if (play->video_sink_element != NULL){
+               g_signal_connect (G_OBJECT (play->video_sink_element), "have_xid",
+                                 G_CALLBACK (callback_video_have_xid), play);
+               g_signal_connect (G_OBJECT (play->video_sink_element), "have_size",
+                                 G_CALLBACK (callback_video_have_size), play);
+               g_object_set(G_OBJECT(play->video_sink_element), "need_new_window", TRUE, "toplevel", FALSE, NULL);
+       }
+       return TRUE;
+}
+
+
+static gboolean
+gst_play_video_set_audio (GstPlay *play, GstElement *audio_sink)
+{
+       GstElement *audio_bin;
+       
+       g_return_val_if_fail (GST_IS_PLAY(play), FALSE);
+       g_return_val_if_fail (GST_IS_ELEMENT (audio_sink), FALSE);
+       
+       audio_bin = g_hash_table_lookup(play->other_elements, "audio_bin");
+       
+       if (play->audio_sink)
+       {
+               gst_element_disconnect (play->volume, play->audio_sink);
+               gst_bin_remove (GST_BIN (audio_bin), play->audio_sink);
+       }
+
+       play->audio_sink = audio_sink;
+       gst_bin_add (GST_BIN (audio_bin), play->audio_sink);
+       gst_element_connect (play->volume, play->audio_sink);
+
+       play->audio_sink_element = gst_play_get_sink_element (play, audio_sink);
+
+       if (play->audio_sink_element != NULL){
+               g_signal_connect (G_OBJECT (play->audio_sink), "eos",
+                                 G_CALLBACK (callback_audio_sink_eos), play);
+       }
+
+       return TRUE;
+}
+
+/*
+ * GST_PLAY_PIPE_VIDEO_THREADSAFE
+ * { gnomevfssrc ! spider ! { queue ! volume ! osssink } } 
+ * spider0.src2 ! queue ! videosink
+ * (note that the xvideosink is not contained by a thread)
+ */
+
+static gboolean 
+gst_play_videots_setup (GstPlay *play, GError **error)
+{
+       GstElement *audio_bin, *audio_queue, *video_queue, *auto_identity, *work_thread;
+
+       g_return_val_if_fail (GST_IS_PLAY(play), FALSE);
+       
+       /* creating pipeline */
+       play->pipeline = gst_pipeline_new ("main_pipeline");
+       g_return_val_if_fail (GST_IS_PIPELINE (play->pipeline), FALSE);
+
+       /* creating work thread */      
+       work_thread = gst_thread_new ("work_thread");
+       g_return_val_if_fail (GST_IS_THREAD (work_thread), FALSE);
+       g_hash_table_insert(play->other_elements, "work_thread", work_thread);
+       
+       gst_bin_add (GST_BIN (play->pipeline), work_thread);
+
+       /* create source element */
+       play->source = gst_element_factory_make ("gnomevfssrc", "source");
+       if (!play->source)
+       {
+               gst_play_error_plugin (GST_PLAY_ERROR_GNOMEVFSSRC, error);
+               return FALSE;
+       }
+       gst_bin_add (GST_BIN (work_thread), play->source);
+       
+       auto_identity = gst_element_factory_make ("identity", "auto_identity");
+       g_return_val_if_fail (auto_identity != NULL, FALSE);
+       g_hash_table_insert(play->other_elements, "auto_identity", auto_identity);
+
+       gst_bin_add (GST_BIN (work_thread), auto_identity);
+       gst_element_add_ghost_pad (work_thread, 
+                                  gst_element_get_pad (auto_identity, "src"),
+                                  "src");
+       
+       /* create volume elements */
+       play->volume = gst_element_factory_make ("volume", "volume");
+       if (!play->volume)
+       {
+               gst_play_error_plugin (GST_PLAY_ERROR_VOLUME, error);
+               return FALSE;
+       }
+
+       /* create audiosink.
+       FIXME : Should use gconf to choose the right one */
+       play->audio_sink = gst_element_factory_make ("osssink", "play_audio");
+       if (!play->audio_sink)
+               g_warning ("You need the osssink element to use this program.\n");
+       
+       g_object_set (G_OBJECT (play->audio_sink), "fragment", 0x00180008, NULL);
+       g_signal_connect (
+                       G_OBJECT (play->audio_sink), "eos",
+                       G_CALLBACK (callback_audio_sink_eos), play);
+
+       audio_queue = gst_element_factory_make ("queue", "audio_queue");
+       if (!audio_queue)
+       {
+               gst_play_error_plugin (GST_PLAY_ERROR_QUEUE, error);
+               return FALSE;
+       }
+       g_hash_table_insert(play->other_elements, "audio_queue", audio_queue);
+       
+       audio_bin = gst_thread_new ("audio_bin");
+       if (!audio_bin)
+       {
+               gst_play_error_plugin (GST_PLAY_ERROR_THREAD, error);
+               return FALSE;
+       }
+       g_hash_table_insert(play->other_elements, "audio_bin", audio_bin);
+
+       gst_bin_set_pre_iterate_function(
+                       GST_BIN (audio_bin), 
+                       (GstBinPrePostIterateFunction) callback_bin_pre_iterate,
+                       play->audio_bin_mutex);
+       
+       gst_bin_set_post_iterate_function(
+                       GST_BIN (audio_bin), 
+                       (GstBinPrePostIterateFunction) callback_bin_post_iterate,
+                       play->audio_bin_mutex);
+
+       gst_bin_add_many (
+                       GST_BIN (audio_bin), audio_queue,
+                       play->volume, play->audio_sink, NULL);
+       
+       gst_element_connect_many (
+                       audio_queue, play->volume,
+                       play->audio_sink, NULL);
+       
+       gst_element_add_ghost_pad (
+                       audio_bin, 
+                       gst_element_get_pad (audio_queue, "sink"),
+                       "sink");
+
+       gst_bin_add (GST_BIN (work_thread), audio_bin);
+
+       /* create video elements */
+       play->video_sink = gst_element_factory_make ("xvideosink", "show");
+       
+       g_object_set (G_OBJECT (play->video_sink), "toplevel", FALSE, NULL);
+       
+       g_signal_connect (
+                       G_OBJECT (play->video_sink), "have_xid",
+                       G_CALLBACK (callback_video_have_xid), play);
+       
+       g_signal_connect (
+                       G_OBJECT (play->video_sink), "have_size",
+                       G_CALLBACK (callback_video_have_size), play);
+
+       g_return_val_if_fail (play->video_sink != NULL, FALSE);
+       
+       video_queue = gst_element_factory_make ("queue", "video_queue");
+       g_return_val_if_fail (video_queue != NULL, FALSE);
+       g_hash_table_insert(play->other_elements, "video_queue", video_queue);
+       g_object_set (G_OBJECT (video_queue), "block_timeout", 1000, NULL);
+
+       gst_bin_add_many (
+                       GST_BIN (play->pipeline), video_queue,
+                       play->video_sink, NULL);
+                       
+       gst_element_connect (video_queue, play->video_sink);
+       
+       gst_bin_set_pre_iterate_function(
+                       GST_BIN (play->pipeline), 
+                       (GstBinPrePostIterateFunction) callback_bin_pre_iterate,
+                       play->video_bin_mutex);
+                       
+       gst_bin_set_post_iterate_function(
+                       GST_BIN (play->pipeline), 
+                       (GstBinPrePostIterateFunction) callback_bin_post_iterate,
+                       play->video_bin_mutex);
+       
+       gst_element_connect (work_thread, video_queue);
+
+       return TRUE;
+}
+
+
+static gboolean
+gst_play_videots_set_auto (GstPlay *play, GstElement *autoplugger){
+
+       GstElement *audio_bin, *auto_identity, *work_thread;
+
+       g_return_val_if_fail (GST_IS_PLAY(play), FALSE);
+       g_return_val_if_fail (GST_IS_ELEMENT (autoplugger), FALSE);
+       
+       audio_bin = g_hash_table_lookup(play->other_elements, "audio_bin");
+       auto_identity = g_hash_table_lookup(play->other_elements, "auto_identity");
+       work_thread = g_hash_table_lookup(play->other_elements, "work_thread");
+
+       if (play->autoplugger){
+               /* we need to remove the existing autoplugger before creating a new one */
+               gst_element_disconnect (play->autoplugger, audio_bin);
+               gst_element_disconnect (play->autoplugger, play->source);
+               gst_element_disconnect (play->autoplugger, auto_identity);
+
+               gst_bin_remove (GST_BIN (work_thread), play->autoplugger);
+       }
+       
+       play->autoplugger = autoplugger;
+       g_return_val_if_fail (play->autoplugger != NULL, FALSE);
+
+       gst_bin_add (GST_BIN (work_thread), play->autoplugger);
+       gst_element_connect (play->source, play->autoplugger);
+       gst_element_connect (play->autoplugger, audio_bin);
+       gst_element_connect (play->autoplugger, auto_identity);
+
+       return TRUE;
+}
+
+
+static gboolean
+gst_play_videots_set_video (GstPlay *play, GstElement *video_sink)
+{
+       GstElement *video_mate;
+       
+       g_return_val_if_fail (GST_IS_PLAY(play), FALSE);
+       g_return_val_if_fail (GST_IS_ELEMENT (video_sink), FALSE);
+       
+       video_mate = g_hash_table_lookup(play->other_elements, "video_queue");
+
+       if (play->video_sink){
+               gst_element_disconnect (video_mate, play->video_sink);
+               gst_bin_remove (GST_BIN (play->pipeline), play->video_sink);
+       }
+       play->video_sink = video_sink;
+       gst_bin_add (GST_BIN (play->pipeline), play->video_sink);
+       gst_element_connect (video_mate, play->video_sink);
+
+       return TRUE;
+}
+
+
+static gboolean
+gst_play_videots_set_audio (GstPlay *play, GstElement *audio_sink)
+{
+       GstElement *audio_bin;
+       
+       g_return_val_if_fail (GST_IS_PLAY(play), FALSE);
+       g_return_val_if_fail (GST_IS_ELEMENT (audio_sink), FALSE);
+       
+       audio_bin = g_hash_table_lookup(play->other_elements, "audio_bin");
+       
+       if (play->audio_sink)
+       {
+               gst_element_disconnect (play->volume, play->audio_sink);
+               gst_bin_remove (GST_BIN (audio_bin), play->audio_sink);
+       }
+
+       play->audio_sink = audio_sink;
+       gst_bin_add (GST_BIN (audio_bin), play->audio_sink);
+       gst_element_connect (play->volume, play->audio_sink);
+
+
+       return TRUE;
+}
+
+/* modelines */
+/* vim:set ts=8:sw=8:noet */