summaryrefslogtreecommitdiffstats
path: root/tests/examples
diff options
context:
space:
mode:
Diffstat (limited to 'tests/examples')
-rw-r--r--tests/examples/Makefile.am14
-rw-r--r--tests/examples/app/.gitignore6
-rw-r--r--tests/examples/app/Makefile.am32
-rw-r--r--tests/examples/app/appsink-src.c192
-rw-r--r--tests/examples/app/appsrc-ra.c223
-rw-r--r--tests/examples/app/appsrc-seekable.c229
-rw-r--r--tests/examples/app/appsrc-stream.c249
-rw-r--r--tests/examples/app/appsrc-stream2.c219
-rw-r--r--tests/examples/app/appsrc_ex.c89
-rw-r--r--tests/examples/capsfilter/Makefile.am6
-rw-r--r--tests/examples/capsfilter/capsfilter1.c87
-rw-r--r--tests/examples/directfb/.gitignore1
-rw-r--r--tests/examples/directfb/Makefile.am9
-rw-r--r--tests/examples/directfb/decker.ttfbin0 -> 37048 bytes
-rw-r--r--tests/examples/directfb/dfblogo.pngbin0 -> 7722 bytes
-rw-r--r--tests/examples/directfb/gstdfb.c514
-rw-r--r--tests/examples/gob/Makefile.am19
-rw-r--r--tests/examples/gob/gst-identity2.gob141
-rw-r--r--tests/examples/gstplay/.gitignore1
-rw-r--r--tests/examples/gstplay/Makefile.am11
-rw-r--r--tests/examples/gstplay/player.c176
-rw-r--r--tests/examples/indexing/.gitignore1
-rw-r--r--tests/examples/indexing/Makefile.am7
-rw-r--r--tests/examples/indexing/indexmpeg.c321
-rw-r--r--tests/examples/level/Makefile.am11
-rw-r--r--tests/examples/level/README39
-rw-r--r--tests/examples/level/demo.c155
-rw-r--r--tests/examples/level/plot.c124
-rw-r--r--tests/examples/scaletempo/.gitignore1
-rw-r--r--tests/examples/scaletempo/Makefile.am8
-rw-r--r--tests/examples/scaletempo/demo-gui.c1262
-rw-r--r--tests/examples/scaletempo/demo-gui.h60
-rw-r--r--tests/examples/scaletempo/demo-main.c95
-rw-r--r--tests/examples/scaletempo/demo-player.c756
-rw-r--r--tests/examples/scaletempo/demo-player.h71
-rw-r--r--tests/examples/stats/Makefile.am6
-rw-r--r--tests/examples/stats/mp2ogg.c102
-rw-r--r--tests/examples/switch/.gitignore1
-rw-r--r--tests/examples/switch/Makefile.am7
-rw-r--r--tests/examples/switch/switcher.c162
40 files changed, 5407 insertions, 0 deletions
diff --git a/tests/examples/Makefile.am b/tests/examples/Makefile.am
new file mode 100644
index 00000000..323ced50
--- /dev/null
+++ b/tests/examples/Makefile.am
@@ -0,0 +1,14 @@
+if HAVE_GTK
+GTK_EXAMPLES=scaletempo
+else
+GTK_EXAMPLES=
+endif
+
+if USE_DIRECTFB
+DIRECTFB_DIR=directfb
+else
+DIRECTFB_DIR=
+endif
+
+SUBDIRS= $(DIRECTFB_DIR) $(GTK_EXAMPLES) switch
+DIST_SUBDIRS= directfb switch scaletempo
diff --git a/tests/examples/app/.gitignore b/tests/examples/app/.gitignore
new file mode 100644
index 00000000..8a2c7615
--- /dev/null
+++ b/tests/examples/app/.gitignore
@@ -0,0 +1,6 @@
+appsrc_ex
+appsrc-ra
+appsrc-seekable
+appsrc-stream
+appsrc-stream2
+appsink-src
diff --git a/tests/examples/app/Makefile.am b/tests/examples/app/Makefile.am
new file mode 100644
index 00000000..4f3df777
--- /dev/null
+++ b/tests/examples/app/Makefile.am
@@ -0,0 +1,32 @@
+
+noinst_PROGRAMS = appsrc_ex appsrc-stream appsrc-stream2 appsrc-ra \
+ appsrc-seekable appsink-src
+
+appsrc_ex_SOURCES = appsrc_ex.c
+appsrc_ex_CFLAGS = $(GST_CFLAGS) $(GCONF_CFLAGS)
+appsrc_ex_LDFLAGS = \
+ $(GST_LIBS) \
+ $(top_builddir)/gst-libs/gst/app/libgstapp-@GST_MAJORMINOR@.la
+
+appsrc_stream_SOURCES = appsrc-stream.c
+appsrc_stream_CFLAGS = $(GST_CFLAGS) $(GCONF_CFLAGS)
+appsrc_stream_LDFLAGS = $(GST_LIBS)
+
+appsrc_stream2_SOURCES = appsrc-stream2.c
+appsrc_stream2_CFLAGS = $(GST_CFLAGS) $(GCONF_CFLAGS)
+appsrc_stream2_LDFLAGS = $(GST_LIBS)
+
+appsrc_ra_SOURCES = appsrc-ra.c
+appsrc_ra_CFLAGS = $(GST_CFLAGS) $(GCONF_CFLAGS)
+appsrc_ra_LDFLAGS = $(GST_LIBS)
+
+appsrc_seekable_SOURCES = appsrc-seekable.c
+appsrc_seekable_CFLAGS = $(GST_CFLAGS) $(GCONF_CFLAGS)
+appsrc_seekable_LDFLAGS = $(GST_LIBS)
+
+appsink_src_SOURCES = appsink-src.c
+appsink_src_CFLAGS = $(GST_CFLAGS) $(GCONF_CFLAGS)
+appsink_src_LDFLAGS = \
+ $(GST_LIBS) \
+ $(top_builddir)/gst-libs/gst/app/libgstapp-@GST_MAJORMINOR@.la
+
diff --git a/tests/examples/app/appsink-src.c b/tests/examples/app/appsink-src.c
new file mode 100644
index 00000000..a92dfb51
--- /dev/null
+++ b/tests/examples/app/appsink-src.c
@@ -0,0 +1,192 @@
+#include <gst/gst.h>
+
+#include <string.h>
+
+#include <gst/app/gstappsrc.h>
+#include <gst/app/gstappsink.h>
+#include <gst/app/gstappbuffer.h>
+
+/* these are the caps we are going to pass through the appsink and appsrc */
+const gchar *audio_caps =
+ "audio/x-raw-int,channels=1,rate=8000,signed=(boolean)true,width=16,depth=16,endianness=1234";
+
+typedef struct
+{
+ GMainLoop *loop;
+ GstElement *source;
+ GstElement *sink;
+} ProgramData;
+
+/* called when the appsink notifies us that there is a new buffer ready for
+ * processing */
+static void
+on_new_buffer_from_source (GstElement * elt, ProgramData * data)
+{
+ guint size;
+ gpointer raw_buffer;
+ GstBuffer *app_buffer, *buffer;
+ GstElement *source;
+
+ /* get the buffer from appsink */
+ buffer = gst_app_sink_pull_buffer (GST_APP_SINK (elt));
+
+ /* turn it into an app buffer, it's not really needed, we could simply push
+ * the retrieved buffer from appsink into appsrc just fine. */
+ size = GST_BUFFER_SIZE (buffer);
+ g_print ("Pushing a buffer of size %d\n", size);
+ raw_buffer = g_malloc0 (size);
+ memcpy (raw_buffer, GST_BUFFER_DATA (buffer), size);
+ app_buffer = gst_app_buffer_new (raw_buffer, size, g_free, raw_buffer);
+
+ /* newer basesrc will set caps for use automatically but it does not really
+ * hurt to set it on the buffer again */
+ gst_buffer_set_caps (app_buffer, GST_BUFFER_CAPS (buffer));
+
+ /* we don't need the appsink buffer anymore */
+ gst_buffer_unref (buffer);
+
+ /* get source an push new buffer */
+ source = gst_bin_get_by_name (GST_BIN (data->sink), "testsource");
+ gst_app_src_push_buffer (GST_APP_SRC (source), app_buffer);
+}
+
+/* called when we get a GstMessage from the source pipeline when we get EOS, we
+ * notify the appsrc of it. */
+static gboolean
+on_source_message (GstBus * bus, GstMessage * message, ProgramData * data)
+{
+ GstElement *source;
+
+ switch (GST_MESSAGE_TYPE (message)) {
+ case GST_MESSAGE_EOS:
+ g_print ("The source got dry\n");
+ source = gst_bin_get_by_name (GST_BIN (data->sink), "testsource");
+ gst_app_src_end_of_stream (GST_APP_SRC (source));
+ break;
+ case GST_MESSAGE_ERROR:
+ g_print ("Received error\n");
+ g_main_loop_quit (data->loop);
+ break;
+ default:
+ break;
+ }
+ return TRUE;
+}
+
+/* called when we get a GstMessage from the sink pipeline when we get EOS, we
+ * exit the mainloop and this testapp. */
+static gboolean
+on_sink_message (GstBus * bus, GstMessage * message, ProgramData * data)
+{
+ /* nil */
+ switch (GST_MESSAGE_TYPE (message)) {
+ case GST_MESSAGE_EOS:
+ g_print ("Finished playback\n");
+ g_main_loop_quit (data->loop);
+ break;
+ case GST_MESSAGE_ERROR:
+ g_print ("Received error\n");
+ g_main_loop_quit (data->loop);
+ break;
+ default:
+ break;
+ }
+ return TRUE;
+}
+
+int
+main (int argc, char *argv[])
+{
+ gchar *filename = NULL;
+ ProgramData *data = NULL;
+ gchar *string = NULL;
+ GstBus *bus = NULL;
+ GstElement *testsink = NULL;
+ GstElement *testsource = NULL;
+
+ gst_init (&argc, &argv);
+
+ if (argc == 2)
+ filename = g_strdup (argv[1]);
+ else
+ filename = g_strdup ("/usr/share/sounds/ekiga/ring.wav");
+
+ data = g_new0 (ProgramData, 1);
+
+ data->loop = g_main_loop_new (NULL, FALSE);
+
+ /* setting up source pipeline, we read from a file and convert to our desired
+ * caps. */
+ string =
+ g_strdup_printf
+ ("filesrc location=\"%s\" ! wavparse ! audioconvert ! audioresample ! appsink caps=\"%s\" name=testsink",
+ filename, audio_caps);
+ g_free (filename);
+ data->source = gst_parse_launch (string, NULL);
+ g_free (string);
+
+ if (data->source == NULL) {
+ g_print ("Bad source\n");
+ return -1;
+ }
+
+ /* to be notified of messages from this pipeline, mostly EOS */
+ bus = gst_element_get_bus (data->source);
+ gst_bus_add_watch (bus, (GstBusFunc) on_source_message, data);
+ gst_object_unref (bus);
+
+ /* we use appsink in push mode, it sends us a signal when data is available
+ * and we pull out the data in the signal callback. We want the appsink to
+ * push as fast as it can, hence the sync=false */
+ testsink = gst_bin_get_by_name (GST_BIN (data->source), "testsink");
+ g_object_set (G_OBJECT (testsink), "emit-signals", TRUE, "sync", FALSE, NULL);
+ g_signal_connect (testsink, "new-buffer",
+ G_CALLBACK (on_new_buffer_from_source), data);
+ gst_object_unref (testsink);
+
+ /* setting up sink pipeline, we push audio data into this pipeline that will
+ * then play it back using the default audio sink. We have no blocking
+ * behaviour on the src which means that we will push the entire file into
+ * memory. */
+ string =
+ g_strdup_printf ("appsrc name=testsource caps=\"%s\" ! autoaudiosink",
+ audio_caps);
+ data->sink = gst_parse_launch (string, NULL);
+ g_free (string);
+
+ if (data->sink == NULL) {
+ g_print ("Bad sink\n");
+ return -1;
+ }
+
+ testsource = gst_bin_get_by_name (GST_BIN (data->sink), "testsource");
+ /* configure for time-based format */
+ g_object_set (testsource, "format", GST_FORMAT_TIME, NULL);
+ /* uncomment the next line to block when appsrc has buffered enough */
+ /* g_object_set (testsource, "block", TRUE, NULL); */
+ gst_object_unref (testsource);
+
+ bus = gst_element_get_bus (data->sink);
+ gst_bus_add_watch (bus, (GstBusFunc) on_sink_message, data);
+ gst_object_unref (bus);
+
+ /* launching things */
+ gst_element_set_state (data->sink, GST_STATE_PLAYING);
+ gst_element_set_state (data->source, GST_STATE_PLAYING);
+
+ /* let's run !, this loop will quit when the sink pipeline goes EOS or when an
+ * error occurs in the source or sink pipelines. */
+ g_print ("Let's run!\n");
+ g_main_loop_run (data->loop);
+ g_print ("Going out\n");
+
+ gst_element_set_state (data->source, GST_STATE_NULL);
+ gst_element_set_state (data->sink, GST_STATE_NULL);
+
+ gst_object_unref (data->source);
+ gst_object_unref (data->sink);
+ g_main_loop_unref (data->loop);
+ g_free (data);
+
+ return 0;
+}
diff --git a/tests/examples/app/appsrc-ra.c b/tests/examples/app/appsrc-ra.c
new file mode 100644
index 00000000..aa4962fe
--- /dev/null
+++ b/tests/examples/app/appsrc-ra.c
@@ -0,0 +1,223 @@
+/* GStreamer
+ *
+ * appsrc-ra.c: example for using appsrc in random-access mode.
+ *
+ * Copyright (C) 2008 Wim Taymans <wim.taymans@gmail.com>
+ *
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gst/gst.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+GST_DEBUG_CATEGORY (appsrc_playbin_debug);
+#define GST_CAT_DEFAULT appsrc_playbin_debug
+
+/*
+ * an example application of using appsrc in random-access mode. When the
+ * appsrc requests data with the need-data signal, we retrieve a buffer of the
+ * requested size and push it to appsrc.
+ *
+ * This is a good example how one would deal with a local file resource.
+ *
+ * Appsrc in random-access mode needs seeking support and we must thus connect
+ * to the seek signal to perform any seeks when requested.
+ *
+ * In random-access mode we must set the size of the source material.
+ */
+typedef struct _App App;
+
+struct _App
+{
+ GstElement *playbin;
+ GstElement *appsrc;
+
+ GMainLoop *loop;
+
+ GMappedFile *file;
+ guint8 *data;
+ gsize length;
+ guint64 offset;
+};
+
+App s_app;
+
+/* This method is called by the need-data signal callback, we feed data into the
+ * appsrc with the requested size.
+ */
+static void
+feed_data (GstElement * appsrc, guint size, App * app)
+{
+ GstBuffer *buffer;
+ GstFlowReturn ret;
+
+ buffer = gst_buffer_new ();
+
+ if (app->offset >= app->length) {
+ /* we are EOS, send end-of-stream */
+ g_signal_emit_by_name (app->appsrc, "end-of-stream", &ret);
+ return;
+ }
+
+ /* read the amount of data, we are allowed to return less if we are EOS */
+ if (app->offset + size > app->length)
+ size = app->length - app->offset;
+
+ GST_BUFFER_DATA (buffer) = app->data + app->offset;
+ GST_BUFFER_SIZE (buffer) = size;
+ /* we need to set an offset for random access */
+ GST_BUFFER_OFFSET (buffer) = app->offset;
+ GST_BUFFER_OFFSET_END (buffer) = app->offset + size;
+
+ GST_DEBUG ("feed buffer %p, offset %" G_GUINT64_FORMAT "-%u", buffer,
+ app->offset, size);
+ g_signal_emit_by_name (app->appsrc, "push-buffer", buffer, &ret);
+ gst_buffer_unref (buffer);
+
+ app->offset += size;
+
+ return;
+}
+
+/* called when appsrc wants us to return data from a new position with the next
+ * call to push-buffer. */
+static gboolean
+seek_data (GstElement * appsrc, guint64 position, App * app)
+{
+ GST_DEBUG ("seek to offset %" G_GUINT64_FORMAT, position);
+ app->offset = position;
+
+ return TRUE;
+}
+
+/* this callback is called when playbin2 has constructed a source object to read
+ * from. Since we provided the appsrc:// uri to playbin2, this will be the
+ * appsrc that we must handle. We set up some signals to push data into appsrc
+ * and one to perform a seek. */
+static void
+found_source (GObject * object, GObject * orig, GParamSpec * pspec, App * app)
+{
+ /* get a handle to the appsrc */
+ g_object_get (orig, pspec->name, &app->appsrc, NULL);
+
+ GST_DEBUG ("got appsrc %p", app->appsrc);
+
+ /* we can set the length in appsrc. This allows some elements to estimate the
+ * total duration of the stream. It's a good idea to set the property when you
+ * can but it's not required. */
+ g_object_set (app->appsrc, "size", app->length, NULL);
+ g_object_set (app->appsrc, "stream-type", 2, NULL);
+
+ /* configure the appsrc, we will push a buffer to appsrc when it needs more
+ * data */
+ g_signal_connect (app->appsrc, "need-data", G_CALLBACK (feed_data), app);
+ g_signal_connect (app->appsrc, "seek-data", G_CALLBACK (seek_data), app);
+}
+
+static gboolean
+bus_message (GstBus * bus, GstMessage * message, App * app)
+{
+ GST_DEBUG ("got message %s",
+ gst_message_type_get_name (GST_MESSAGE_TYPE (message)));
+
+ switch (GST_MESSAGE_TYPE (message)) {
+ case GST_MESSAGE_ERROR:
+ g_error ("received error");
+ g_main_loop_quit (app->loop);
+ break;
+ case GST_MESSAGE_EOS:
+ g_main_loop_quit (app->loop);
+ break;
+ default:
+ break;
+ }
+ return TRUE;
+}
+
+int
+main (int argc, char *argv[])
+{
+ App *app = &s_app;
+ GError *error = NULL;
+ GstBus *bus;
+
+ gst_init (&argc, &argv);
+
+ GST_DEBUG_CATEGORY_INIT (appsrc_playbin_debug, "appsrc-playbin", 0,
+ "appsrc playbin example");
+
+ if (argc < 2) {
+ g_print ("usage: %s <filename>\n", argv[0]);
+ return -1;
+ }
+
+ /* try to open the file as an mmapped file */
+ app->file = g_mapped_file_new (argv[1], FALSE, &error);
+ if (error) {
+ g_print ("failed to open file: %s\n", error->message);
+ g_error_free (error);
+ return -2;
+ }
+ /* get some vitals, this will be used to read data from the mmapped file and
+ * feed it to appsrc. */
+ app->length = g_mapped_file_get_length (app->file);
+ app->data = (guint8 *) g_mapped_file_get_contents (app->file);
+ app->offset = 0;
+
+ /* create a mainloop to get messages */
+ app->loop = g_main_loop_new (NULL, TRUE);
+
+ app->playbin = gst_element_factory_make ("playbin2", NULL);
+ g_assert (app->playbin);
+
+ bus = gst_pipeline_get_bus (GST_PIPELINE (app->playbin));
+
+ /* add watch for messages */
+ gst_bus_add_watch (bus, (GstBusFunc) bus_message, app);
+
+ /* set to read from appsrc */
+ g_object_set (app->playbin, "uri", "appsrc://", NULL);
+
+ /* get notification when the source is created so that we get a handle to it
+ * and can configure it */
+ g_signal_connect (app->playbin, "deep-notify::source",
+ (GCallback) found_source, app);
+
+ /* go to playing and wait in a mainloop. */
+ gst_element_set_state (app->playbin, GST_STATE_PLAYING);
+
+ /* this mainloop is stopped when we receive an error or EOS */
+ g_main_loop_run (app->loop);
+
+ GST_DEBUG ("stopping");
+
+ gst_element_set_state (app->playbin, GST_STATE_NULL);
+
+ /* free the file */
+ g_mapped_file_free (app->file);
+
+ gst_object_unref (bus);
+ g_main_loop_unref (app->loop);
+
+ return 0;
+}
diff --git a/tests/examples/app/appsrc-seekable.c b/tests/examples/app/appsrc-seekable.c
new file mode 100644
index 00000000..7137d13e
--- /dev/null
+++ b/tests/examples/app/appsrc-seekable.c
@@ -0,0 +1,229 @@
+/* GStreamer
+ *
+ * appsrc-seekable.c: example for using appsrc in seekable mode.
+ *
+ * Copyright (C) 2008 Wim Taymans <wim.taymans@gmail.com>
+ *
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gst/gst.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+GST_DEBUG_CATEGORY (appsrc_playbin_debug);
+#define GST_CAT_DEFAULT appsrc_playbin_debug
+
+/*
+ * an example application of using appsrc in seekable mode. When the
+ * appsrc requests data with the need-data signal, we retrieve a buffer and
+ * push it to appsrc. We can also use the method as demonstrated in
+ * appsrc-stream.c, ie. pushing buffers when we can.
+ *
+ * This is a good example how one would deal with a remote http server that
+ * supports range requests.
+ *
+ * Appsrc in seekable mode needs seeking support and we must thus connect
+ * to the seek signal to perform any seeks when requested.
+ *
+ * In seekable mode we should set the size of the source material.
+ */
+typedef struct _App App;
+
+struct _App
+{
+ GstElement *playbin;
+ GstElement *appsrc;
+
+ GMainLoop *loop;
+
+ GMappedFile *file;
+ guint8 *data;
+ gsize length;
+ guint64 offset;
+};
+
+App s_app;
+
+#define CHUNK_SIZE 4096
+
+/* This method is called by the need-data signal callback, we feed data into the
+ * appsrc with an arbitrary size.
+ */
+static void
+feed_data (GstElement * appsrc, guint size, App * app)
+{
+ GstBuffer *buffer;
+ guint len;
+ GstFlowReturn ret;
+
+ buffer = gst_buffer_new ();
+
+ if (app->offset >= app->length) {
+ /* we are EOS, send end-of-stream */
+ g_signal_emit_by_name (app->appsrc, "end-of-stream", &ret);
+ return;
+ }
+
+ /* read any amount of data, we are allowed to return less if we are EOS */
+ len = CHUNK_SIZE;
+ if (app->offset + len > app->length)
+ len = app->length - app->offset;
+
+ GST_BUFFER_DATA (buffer) = app->data + app->offset;
+ GST_BUFFER_SIZE (buffer) = len;
+
+ GST_DEBUG ("feed buffer %p, offset %" G_GUINT64_FORMAT "-%u", buffer,
+ app->offset, len);
+ g_signal_emit_by_name (app->appsrc, "push-buffer", buffer, &ret);
+ gst_buffer_unref (buffer);
+
+ app->offset += len;
+
+ return;
+}
+
+/* called when appsrc wants us to return data from a new position with the next
+ * call to push-buffer. */
+static gboolean
+seek_data (GstElement * appsrc, guint64 position, App * app)
+{
+ GST_DEBUG ("seek to offset %" G_GUINT64_FORMAT, position);
+ app->offset = position;
+
+ return TRUE;
+}
+
+/* this callback is called when playbin2 has constructed a source object to read
+ * from. Since we provided the appsrc:// uri to playbin2, this will be the
+ * appsrc that we must handle. We set up some signals to push data into appsrc
+ * and one to perform a seek. */
+static void
+found_source (GObject * object, GObject * orig, GParamSpec * pspec, App * app)
+{
+ /* get a handle to the appsrc */
+ g_object_get (orig, pspec->name, &app->appsrc, NULL);
+
+ GST_DEBUG ("got appsrc %p", app->appsrc);
+
+ /* we can set the length in appsrc. This allows some elements to estimate the
+ * total duration of the stream. It's a good idea to set the property when you
+ * can but it's not required. */
+ g_object_set (app->appsrc, "size", app->length, NULL);
+ /* we are seekable in push mode, this means that the element usually pushes
+ * out buffers of an undefined size and that seeks happen only occasionally
+ * and only by request of the user. */
+ g_object_set (app->appsrc, "stream-type", 1, NULL);
+
+ /* configure the appsrc, we will push a buffer to appsrc when it needs more
+ * data */
+ g_signal_connect (app->appsrc, "need-data", G_CALLBACK (feed_data), app);
+ g_signal_connect (app->appsrc, "seek-data", G_CALLBACK (seek_data), app);
+}
+
+static gboolean
+bus_message (GstBus * bus, GstMessage * message, App * app)
+{
+ GST_DEBUG ("got message %s",
+ gst_message_type_get_name (GST_MESSAGE_TYPE (message)));
+
+ switch (GST_MESSAGE_TYPE (message)) {
+ case GST_MESSAGE_ERROR:
+ g_error ("received error");
+ g_main_loop_quit (app->loop);
+ break;
+ case GST_MESSAGE_EOS:
+ g_main_loop_quit (app->loop);
+ break;
+ default:
+ break;
+ }
+ return TRUE;
+}
+
+int
+main (int argc, char *argv[])
+{
+ App *app = &s_app;
+ GError *error = NULL;
+ GstBus *bus;
+
+ gst_init (&argc, &argv);
+
+ GST_DEBUG_CATEGORY_INIT (appsrc_playbin_debug, "appsrc-playbin", 0,
+ "appsrc playbin example");
+
+ if (argc < 2) {
+ g_print ("usage: %s <filename>\n", argv[0]);
+ return -1;
+ }
+
+ /* try to open the file as an mmapped file */
+ app->file = g_mapped_file_new (argv[1], FALSE, &error);
+ if (error) {
+ g_print ("failed to open file: %s\n", error->message);
+ g_error_free (error);
+ return -2;
+ }
+ /* get some vitals, this will be used to read data from the mmapped file and
+ * feed it to appsrc. */
+ app->length = g_mapped_file_get_length (app->file);
+ app->data = (guint8 *) g_mapped_file_get_contents (app->file);
+ app->offset = 0;
+
+ /* create a mainloop to get messages */
+ app->loop = g_main_loop_new (NULL, TRUE);
+
+ app->playbin = gst_element_factory_make ("playbin2", NULL);
+ g_assert (app->playbin);
+
+ bus = gst_pipeline_get_bus (GST_PIPELINE (app->playbin));
+
+ /* add watch for messages */
+ gst_bus_add_watch (bus, (GstBusFunc) bus_message, app);
+
+ /* set to read from appsrc */
+ g_object_set (app->playbin, "uri", "appsrc://", NULL);
+
+ /* get notification when the source is created so that we get a handle to it
+ * and can configure it */
+ g_signal_connect (app->playbin, "deep-notify::source",
+ (GCallback) found_source, app);
+
+ /* go to playing and wait in a mainloop. */
+ gst_element_set_state (app->playbin, GST_STATE_PLAYING);
+
+ /* this mainloop is stopped when we receive an error or EOS */
+ g_main_loop_run (app->loop);
+
+ GST_DEBUG ("stopping");
+
+ gst_element_set_state (app->playbin, GST_STATE_NULL);
+
+ /* free the file */
+ g_mapped_file_free (app->file);
+
+ gst_object_unref (bus);
+ g_main_loop_unref (app->loop);
+
+ return 0;
+}
diff --git a/tests/examples/app/appsrc-stream.c b/tests/examples/app/appsrc-stream.c
new file mode 100644
index 00000000..870d707c
--- /dev/null
+++ b/tests/examples/app/appsrc-stream.c
@@ -0,0 +1,249 @@
+/* GStreamer
+ *
+ * appsrc-stream.c: example for using appsrc in streaming mode.
+ *
+ * Copyright (C) 2008 Wim Taymans <wim.taymans@gmail.com>
+ *
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gst/gst.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+GST_DEBUG_CATEGORY (appsrc_playbin_debug);
+#define GST_CAT_DEFAULT appsrc_playbin_debug
+
+/*
+ * an example application of using appsrc in streaming push mode. We simply push
+ * buffers into appsrc. The size of the buffers we push can be any size we
+ * choose.
+ *
+ * This example is very close to how one would deal with a streaming webserver
+ * that does not support range requests or does not report the total file size.
+ *
+ * Some optimisations are done so that we don't push too much data. We connect
+ * to the need-data and enough-data signals to start/stop sending buffers.
+ *
+ * Appsrc in streaming mode (the default) does not support seeking so we don't
+ * have to handle any seek callbacks.
+ *
+ * Some formats are able to estimate the duration of the media file based on the
+ * file length (mp3, mpeg,..), others report an unknown length (ogg,..).
+ */
+typedef struct _App App;
+
+struct _App
+{
+ GstElement *playbin;
+ GstElement *appsrc;
+
+ GMainLoop *loop;
+ guint sourceid;
+
+ GMappedFile *file;
+ guint8 *data;
+ gsize length;
+ guint64 offset;
+};
+
+App s_app;
+
+#define CHUNK_SIZE 4096
+
+/* This method is called by the idle GSource in the mainloop. We feed CHUNK_SIZE
+ * bytes into appsrc.
+ * The ide handler is added to the mainloop when appsrc requests us to start
+ * sending data (need-data signal) and is removed when appsrc has enough data
+ * (enough-data signal).
+ */
+static gboolean
+read_data (App * app)
+{
+ GstBuffer *buffer;
+ guint len;
+ GstFlowReturn ret;
+
+ buffer = gst_buffer_new ();
+
+ if (app->offset >= app->length) {
+ /* we are EOS, send end-of-stream and remove the source */
+ g_signal_emit_by_name (app->appsrc, "end-of-stream", &ret);
+ return FALSE;
+ }
+
+ /* read the next chunk */
+ len = CHUNK_SIZE;
+ if (app->offset + len > app->length)
+ len = app->length - app->offset;
+
+ GST_BUFFER_DATA (buffer) = app->data + app->offset;
+ GST_BUFFER_SIZE (buffer) = len;
+
+ GST_DEBUG ("feed buffer %p, offset %" G_GUINT64_FORMAT "-%u", buffer,
+ app->offset, len);
+ g_signal_emit_by_name (app->appsrc, "push-buffer", buffer, &ret);
+ gst_buffer_unref (buffer);
+ if (ret != GST_FLOW_OK) {
+ /* some error, stop sending data */
+ return FALSE;
+ }
+
+ app->offset += len;
+
+ return TRUE;
+}
+
+/* This signal callback is called when appsrc needs data, we add an idle handler
+ * to the mainloop to start pushing data into the appsrc */
+static void
+start_feed (GstElement * playbin, guint size, App * app)
+{
+ if (app->sourceid == 0) {
+ GST_DEBUG ("start feeding");
+ app->sourceid = g_idle_add ((GSourceFunc) read_data, app);
+ }
+}
+
+/* This callback is called when appsrc has enough data and we can stop sending.
+ * We remove the idle handler from the mainloop */
+static void
+stop_feed (GstElement * playbin, App * app)
+{
+ if (app->sourceid != 0) {
+ GST_DEBUG ("stop feeding");
+ g_source_remove (app->sourceid);
+ app->sourceid = 0;
+ }
+}
+
+/* this callback is called when playbin2 has constructed a source object to read
+ * from. Since we provided the appsrc:// uri to playbin2, this will be the
+ * appsrc that we must handle. We set up some signals to start and stop pushing
+ * data into appsrc */
+static void
+found_source (GObject * object, GObject * orig, GParamSpec * pspec, App * app)
+{
+ /* get a handle to the appsrc */
+ g_object_get (orig, pspec->name, &app->appsrc, NULL);
+
+ GST_DEBUG ("got appsrc %p", app->appsrc);
+
+ /* we can set the length in appsrc. This allows some elements to estimate the
+ * total duration of the stream. It's a good idea to set the property when you
+ * can but it's not required. */
+ g_object_set (app->appsrc, "size", app->length, NULL);
+
+ /* configure the appsrc, we will push data into the appsrc from the
+ * mainloop. */
+ g_signal_connect (app->appsrc, "need-data", G_CALLBACK (start_feed), app);
+ g_signal_connect (app->appsrc, "enough-data", G_CALLBACK (stop_feed), app);
+}
+
+static gboolean
+bus_message (GstBus * bus, GstMessage * message, App * app)
+{
+ GST_DEBUG ("got message %s",
+ gst_message_type_get_name (GST_MESSAGE_TYPE (message)));
+
+ switch (GST_MESSAGE_TYPE (message)) {
+ case GST_MESSAGE_ERROR:
+ g_error ("received error");
+ g_main_loop_quit (app->loop);
+ break;
+ case GST_MESSAGE_EOS:
+ g_main_loop_quit (app->loop);
+ break;
+ default:
+ break;
+ }
+ return TRUE;
+}
+
+int
+main (int argc, char *argv[])
+{
+ App *app = &s_app;
+ GError *error = NULL;
+ GstBus *bus;
+
+ gst_init (&argc, &argv);
+
+ GST_DEBUG_CATEGORY_INIT (appsrc_playbin_debug, "appsrc-playbin", 0,
+ "appsrc playbin example");
+
+ if (argc < 2) {
+ g_print ("usage: %s <filename>\n", argv[0]);
+ return -1;
+ }
+
+ /* try to open the file as an mmapped file */
+ app->file = g_mapped_file_new (argv[1], FALSE, &error);
+ if (error) {
+ g_print ("failed to open file: %s\n", error->message);
+ g_error_free (error);
+ return -2;
+ }
+ /* get some vitals, this will be used to read data from the mmapped file and
+ * feed it to appsrc. */
+ app->length = g_mapped_file_get_length (app->file);
+ app->data = (guint8 *) g_mapped_file_get_contents (app->file);
+ app->offset = 0;
+
+ /* create a mainloop to get messages and to handle the idle handler that will
+ * feed data to appsrc. */
+ app->loop = g_main_loop_new (NULL, TRUE);
+
+ app->playbin = gst_element_factory_make ("playbin2", NULL);
+ g_assert (app->playbin);
+
+ bus = gst_pipeline_get_bus (GST_PIPELINE (app->playbin));
+
+ /* add watch for messages */
+ gst_bus_add_watch (bus, (GstBusFunc) bus_message, app);
+
+ /* set to read from appsrc */
+ g_object_set (app->playbin, "uri", "appsrc://", NULL);
+
+ /* get notification when the source is created so that we get a handle to it
+ * and can configure it */
+ g_signal_connect (app->playbin, "deep-notify::source",
+ (GCallback) found_source, app);
+
+ /* go to playing and wait in a mainloop. */
+ gst_element_set_state (app->playbin, GST_STATE_PLAYING);
+
+ /* this mainloop is stopped when we receive an error or EOS */
+ g_main_loop_run (app->loop);
+
+ GST_DEBUG ("stopping");
+
+ gst_element_set_state (app->playbin, GST_STATE_NULL);
+
+ /* free the file */
+ g_mapped_file_free (app->file);
+
+ gst_object_unref (bus);
+ g_main_loop_unref (app->loop);
+
+ return 0;
+}
diff --git a/tests/examples/app/appsrc-stream2.c b/tests/examples/app/appsrc-stream2.c
new file mode 100644
index 00000000..866b0504
--- /dev/null
+++ b/tests/examples/app/appsrc-stream2.c
@@ -0,0 +1,219 @@
+/* GStreamer
+ *
+ * appsrc-stream2.c: example for using appsrc in streaming mode.
+ *
+ * Copyright (C) 2008 Wim Taymans <wim.taymans@gmail.com>
+ *
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gst/gst.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+GST_DEBUG_CATEGORY (appsrc_playbin_debug);
+#define GST_CAT_DEFAULT appsrc_playbin_debug
+
+/*
+ * an example application of using appsrc in streaming pull mode. When the
+ * appsrc request data with the need-data signal, we retrieve a buffer of an
+ * arbitrary size and push it to appsrc.
+ *
+ * This example keeps the internal buffer queue of appsrc to a minimal size,
+ * only feeding data to appsrc when needed.
+ *
+ * This is a good example how one would deal with a live resource, such as a udp
+ * socket where one would feed the most recently acquired buffer to appsrc.
+ *
+ * Usually one would timestamp the buffers with the running_time of the
+ * pipeline or configure the appsrc to do timestamping by setting the
+ * do-timestamp property to TRUE.
+ *
+ * Appsrc in streaming mode (the default) does not support seeking so we don't
+ * have to handle any seek callbacks.
+ *
+ * Some formats are able to estimate the duration of the media file based on the
+ * file length (mp3, mpeg,..), others report an unknown length (ogg,..).
+ */
+typedef struct _App App;
+
+struct _App
+{
+ GstElement *playbin;
+ GstElement *appsrc;
+
+ GMainLoop *loop;
+
+ GMappedFile *file;
+ guint8 *data;
+ gsize length;
+ guint64 offset;
+};
+
+App s_app;
+
+#define CHUNK_SIZE 4096
+
+/* This method is called by the need-data signal callback, we feed data into the
+ * appsrc.
+ */
+static void
+feed_data (GstElement * appsrc, guint size, App * app)
+{
+ GstBuffer *buffer;
+ guint len;
+ GstFlowReturn ret;
+
+ buffer = gst_buffer_new ();
+
+ if (app->offset >= app->length) {
+ /* we are EOS, send end-of-stream */
+ g_signal_emit_by_name (app->appsrc, "end-of-stream", &ret);
+ return;
+ }
+
+ /* read the next chunk */
+ len = CHUNK_SIZE;
+ if (app->offset + len > app->length)
+ len = app->length - app->offset;
+
+ GST_BUFFER_DATA (buffer) = app->data + app->offset;
+ GST_BUFFER_SIZE (buffer) = len;
+
+ GST_DEBUG ("feed buffer %p, offset %" G_GUINT64_FORMAT "-%u", buffer,
+ app->offset, len);
+ g_signal_emit_by_name (app->appsrc, "push-buffer", buffer, &ret);
+ gst_buffer_unref (buffer);
+
+ app->offset += len;
+
+ return;
+}
+
+/* this callback is called when playbin2 has constructed a source object to read
+ * from. Since we provided the appsrc:// uri to playbin2, this will be the
+ * appsrc that we must handle. We set up a signals to push data into appsrc. */
+static void
+found_source (GObject * object, GObject * orig, GParamSpec * pspec, App * app)
+{
+ /* get a handle to the appsrc */
+ g_object_get (orig, pspec->name, &app->appsrc, NULL);
+
+ GST_DEBUG ("got appsrc %p", app->appsrc);
+
+ /* we can set the length in appsrc. This allows some elements to estimate the
+ * total duration of the stream. It's a good idea to set the property when you
+ * can but it's not required. */
+ g_object_set (app->appsrc, "size", app->length, NULL);
+
+ /* configure the appsrc, we will push a buffer to appsrc when it needs more
+ * data */
+ g_signal_connect (app->appsrc, "need-data", G_CALLBACK (feed_data), app);
+}
+
+static gboolean
+bus_message (GstBus * bus, GstMessage * message, App * app)
+{
+ GST_DEBUG ("got message %s",
+ gst_message_type_get_name (GST_MESSAGE_TYPE (message)));
+
+ switch (GST_MESSAGE_TYPE (message)) {
+ case GST_MESSAGE_ERROR:
+ g_error ("received error");
+ g_main_loop_quit (app->loop);
+ break;
+ case GST_MESSAGE_EOS:
+ g_main_loop_quit (app->loop);
+ break;
+ default:
+ break;
+ }
+ return TRUE;
+}
+
+int
+main (int argc, char *argv[])
+{
+ App *app = &s_app;
+ GError *error = NULL;
+ GstBus *bus;
+
+ gst_init (&argc, &argv);
+
+ GST_DEBUG_CATEGORY_INIT (appsrc_playbin_debug, "appsrc-playbin", 0,
+ "appsrc playbin example");
+
+ if (argc < 2) {
+ g_print ("usage: %s <filename>\n", argv[0]);
+ return -1;
+ }
+
+ /* try to open the file as an mmapped file */
+ app->file = g_mapped_file_new (argv[1], FALSE, &error);
+ if (error) {
+ g_print ("failed to open file: %s\n", error->message);
+ g_error_free (error);
+ return -2;
+ }
+ /* get some vitals, this will be used to read data from the mmapped file and
+ * feed it to appsrc. */
+ app->length = g_mapped_file_get_length (app->file);
+ app->data = (guint8 *) g_mapped_file_get_contents (app->file);
+ app->offset = 0;
+
+ /* create a mainloop to get messages */
+ app->loop = g_main_loop_new (NULL, TRUE);
+
+ app->playbin = gst_element_factory_make ("playbin2", NULL);
+ g_assert (app->playbin);
+
+ bus = gst_pipeline_get_bus (GST_PIPELINE (app->playbin));
+
+ /* add watch for messages */
+ gst_bus_add_watch (bus, (GstBusFunc) bus_message, app);
+
+ /* set to read from appsrc */
+ g_object_set (app->playbin, "uri", "appsrc://", NULL);
+
+ /* get notification when the source is created so that we get a handle to it
+ * and can configure it */
+ g_signal_connect (app->playbin, "deep-notify::source",
+ (GCallback) found_source, app);
+
+ /* go to playing and wait in a mainloop. */
+ gst_element_set_state (app->playbin, GST_STATE_PLAYING);
+
+ /* this mainloop is stopped when we receive an error or EOS */
+ g_main_loop_run (app->loop);
+
+ GST_DEBUG ("stopping");
+
+ gst_element_set_state (app->playbin, GST_STATE_NULL);
+
+ /* free the file */
+ g_mapped_file_free (app->file);
+
+ gst_object_unref (bus);
+ g_main_loop_unref (app->loop);
+
+ return 0;
+}
diff --git a/tests/examples/app/appsrc_ex.c b/tests/examples/app/appsrc_ex.c
new file mode 100644
index 00000000..bc629fb0
--- /dev/null
+++ b/tests/examples/app/appsrc_ex.c
@@ -0,0 +1,89 @@
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gst/gst.h>
+#include <gst/app/gstappsrc.h>
+#include <gst/app/gstappbuffer.h>
+#include <gst/app/gstappsink.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+
+typedef struct _App App;
+struct _App
+{
+ GstElement *pipe;
+ GstElement *src;
+ GstElement *id;
+ GstElement *sink;
+};
+
+App s_app;
+
+static void dont_eat_my_chicken_wings (void *priv);
+
+int
+main (int argc, char *argv[])
+{
+ App *app = &s_app;
+ int i;
+
+ gst_init (&argc, &argv);
+
+ app->pipe = gst_pipeline_new (NULL);
+ g_assert (app->pipe);
+
+ app->src = gst_element_factory_make ("appsrc", NULL);
+ g_assert (app->src);
+ gst_bin_add (GST_BIN (app->pipe), app->src);
+
+ app->id = gst_element_factory_make ("identity", NULL);
+ g_assert (app->id);
+ gst_bin_add (GST_BIN (app->pipe), app->id);
+
+ app->sink = gst_element_factory_make ("appsink", NULL);
+ g_assert (app->sink);
+ gst_bin_add (GST_BIN (app->pipe), app->sink);
+
+ gst_element_link (app->src, app->id);
+ gst_element_link (app->id, app->sink);
+
+ gst_element_set_state (app->pipe, GST_STATE_PLAYING);
+
+ for (i = 0; i < 10; i++) {
+ GstBuffer *buf;
+ void *data;
+
+ data = malloc (100);
+ memset (data, i, 100);
+
+ buf = gst_app_buffer_new (data, 100, dont_eat_my_chicken_wings, data);
+ printf ("%d: creating buffer for pointer %p, %p\n", i, data, buf);
+ gst_app_src_push_buffer (GST_APP_SRC (app->src), buf);
+ }
+
+ gst_app_src_end_of_stream (GST_APP_SRC (app->src));
+
+ while (!gst_app_sink_is_eos (GST_APP_SINK (app->sink))) {
+ GstBuffer *buf;
+
+ buf = gst_app_sink_pull_buffer (GST_APP_SINK (app->sink));
+ printf ("retrieved buffer %p\n", buf);
+ gst_buffer_unref (buf);
+ }
+ gst_element_set_state (app->pipe, GST_STATE_NULL);
+
+ return 0;
+}
+
+static void
+dont_eat_my_chicken_wings (void *priv)
+{
+ printf ("freeing buffer for pointer %p\n", priv);
+ free (priv);
+}
diff --git a/tests/examples/capsfilter/Makefile.am b/tests/examples/capsfilter/Makefile.am
new file mode 100644
index 00000000..f8562fee
--- /dev/null
+++ b/tests/examples/capsfilter/Makefile.am
@@ -0,0 +1,6 @@
+noinst_PROGRAMS = capsfilter1
+
+LDADD = $(GST_LIBS)
+AM_CFLAGS = $(GST_CFLAGS)
+
+
diff --git a/tests/examples/capsfilter/capsfilter1.c b/tests/examples/capsfilter/capsfilter1.c
new file mode 100644
index 00000000..a59f728e
--- /dev/null
+++ b/tests/examples/capsfilter/capsfilter1.c
@@ -0,0 +1,87 @@
+#include <string.h>
+#include <gst/gst.h>
+
+/* This app uses a filter to connect colorspace and videosink
+ * so that only RGB data can pass the connection, colorspace will use
+ * a converter to convert the I420 data to RGB. Without a filter, this
+ * connection would use the I420 format (assuming Xv is enabled) */
+
+static void
+new_pad_func (GstElement * element, GstPad * newpad, gpointer data)
+{
+ GstElement *pipeline = (GstElement *) data;
+ GstElement *queue = gst_bin_get_by_name (GST_BIN (pipeline), "queue");
+
+ if (!strcmp (gst_pad_get_name (newpad), "video_00")) {
+ gst_element_set_state (pipeline, GST_STATE_PAUSED);
+ gst_pad_link (newpad, gst_element_get_pad (queue, "sink"));
+ gst_element_set_state (pipeline, GST_STATE_PLAYING);
+ }
+}
+
+gint
+main (gint argc, gchar * argv[])
+{
+ GstElement *pipeline;
+ GstElement *filesrc;
+ GstElement *demux;
+ GstElement *thread;
+ GstElement *queue;
+ GstElement *mpeg2dec;
+ GstElement *colorspace;
+ GstElement *videosink;
+ gboolean res;
+
+ gst_init (&argc, &argv);
+
+ if (argc < 2) {
+ g_print ("usage: %s <mpeg1 system stream>\n", argv[0]);
+ return (-1);
+ }
+
+ pipeline = gst_pipeline_new ("main_pipeline");
+ filesrc = gst_element_factory_make ("filesrc", "filesrc");
+ g_return_val_if_fail (filesrc, -1);
+ g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
+ demux = gst_element_factory_make ("mpegdemux", "demux");
+ g_return_val_if_fail (demux, -1);
+ g_signal_connect (G_OBJECT (demux), "new_pad", G_CALLBACK (new_pad_func),
+ pipeline);
+
+ thread = gst_thread_new ("thread");
+ queue = gst_element_factory_make ("queue", "queue");
+ mpeg2dec = gst_element_factory_make ("mpeg2dec", "mpeg2dec");
+ g_return_val_if_fail (mpeg2dec, -1);
+ colorspace = gst_element_factory_make ("ffmpegcolorspace", "colorspace");
+ g_return_val_if_fail (colorspace, -1);
+ videosink = gst_element_factory_make (DEFAULT_VIDEOSINK, "videosink");
+ g_return_val_if_fail (videosink, -1);
+
+ gst_bin_add (GST_BIN (pipeline), filesrc);
+ gst_bin_add (GST_BIN (pipeline), demux);
+
+ gst_bin_add (GST_BIN (thread), queue);
+ gst_bin_add (GST_BIN (thread), mpeg2dec);
+ gst_bin_add (GST_BIN (thread), colorspace);
+ gst_bin_add (GST_BIN (thread), videosink);
+ gst_bin_add (GST_BIN (pipeline), thread);
+
+ gst_element_link_pads (filesrc, "src", demux, "sink");
+ gst_element_link_pads (queue, "src", mpeg2dec, "sink");
+ gst_element_link_pads (mpeg2dec, "src", colorspace, "sink");
+ /* force RGB data passing between colorspace and videosink */
+ res = gst_element_link_pads_filtered (colorspace, "src", videosink, "sink",
+ gst_caps_new_simple ("video/x-raw-rgb", NULL));
+ if (!res) {
+ g_print ("could not connect colorspace and videosink\n");
+ return -1;
+ }
+
+ gst_element_set_state (pipeline, GST_STATE_PLAYING);
+
+ while (gst_bin_iterate (GST_BIN (pipeline)));
+
+ gst_element_set_state (pipeline, GST_STATE_NULL);
+
+ return 0;
+}
diff --git a/tests/examples/directfb/.gitignore b/tests/examples/directfb/.gitignore
new file mode 100644
index 00000000..5faebe91
--- /dev/null
+++ b/tests/examples/directfb/.gitignore
@@ -0,0 +1 @@
+gstdfb
diff --git a/tests/examples/directfb/Makefile.am b/tests/examples/directfb/Makefile.am
new file mode 100644
index 00000000..595a82ff
--- /dev/null
+++ b/tests/examples/directfb/Makefile.am
@@ -0,0 +1,9 @@
+noinst_PROGRAMS = gstdfb
+
+gstdfb_SOURCES = gstdfb.c
+gstdfb_CFLAGS = $(GST_CFLAGS) $(DIRECTFB_CFLAGS)
+gstdfb_LDFLAGS = $(GST_LIBS) $(DIRECTFB_LIBS)
+
+EXTRA_DIST = \
+ decker.ttf dfblogo.png
+
diff --git a/tests/examples/directfb/decker.ttf b/tests/examples/directfb/decker.ttf
new file mode 100644
index 00000000..5e721cfd
--- /dev/null
+++ b/tests/examples/directfb/decker.ttf
Binary files differ
diff --git a/tests/examples/directfb/dfblogo.png b/tests/examples/directfb/dfblogo.png
new file mode 100644
index 00000000..8b7d8833
--- /dev/null
+++ b/tests/examples/directfb/dfblogo.png
Binary files differ
diff --git a/tests/examples/directfb/gstdfb.c b/tests/examples/directfb/gstdfb.c
new file mode 100644
index 00000000..675e5e23
--- /dev/null
+++ b/tests/examples/directfb/gstdfb.c
@@ -0,0 +1,514 @@
+/*
+ (c) Copyright 2000-2002 convergence integrated media GmbH.
+ All rights reserved.
+
+ Written by Denis Oliver Kropp <dok@directfb.org>,
+ Andreas Hundt <andi@fischlustig.de>,
+ Sven Neumann <neo@directfb.org> and
+ Julien Moutte <julien@moutte.net>.
+
+ This file is subject to the terms and conditions of the MIT License:
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the "Software"), to deal in the Software without restriction,
+ including without limitation the rights to use, copy, modify, merge,
+ publish, distribute, sublicense, and/or sell copies of the Software,
+ and to permit persons to whom the Software is furnished to do so,
+ subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <math.h>
+#include <time.h>
+
+#include <directfb.h>
+#include <gst/gst.h>
+#include <string.h>
+
+/* macro for a safe call to DirectFB functions */
+#define DFBCHECK(x...) \
+ { \
+ err = x; \
+ if (err != DFB_OK) { \
+ fprintf( stderr, "%s <%d>:\n\t", __FILE__, __LINE__ ); \
+ DirectFBErrorFatal( #x, err ); \
+ } \
+ }
+
+typedef struct
+{
+ const gchar *padname;
+ GstPad *target;
+ GstElement *bin;
+} dyn_link;
+
+static inline long
+myclock ()
+{
+ struct timeval tv;
+
+ gettimeofday (&tv, NULL);
+ return (tv.tv_sec * 1000 + tv.tv_usec / 1000);
+}
+
+static void
+dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data)
+{
+ dyn_link *connect = (dyn_link *) data;
+
+ if (connect->padname == NULL ||
+ !strcmp (gst_pad_get_name (newpad), connect->padname)) {
+ gst_pad_link (newpad, connect->target);
+ }
+}
+
+static void
+size_changed (GObject * obj, GParamSpec * pspec, IDirectFBWindow * window)
+{
+ GstPad *pad = GST_PAD (obj);
+ GstStructure *s;
+ GstCaps *caps;
+
+ if (!(caps = gst_pad_get_negotiated_caps (pad)))
+ return;
+
+ s = gst_caps_get_structure (caps, 0);
+ if (s) {
+ gint width, height;
+
+ if (!(gst_structure_get_int (s, "width", &width) &&
+ gst_structure_get_int (s, "height", &height)))
+ return;
+
+ window->Resize (window, width, height);
+ }
+}
+
+static void
+setup_dynamic_link (GstElement * element, const gchar * padname,
+ GstPad * target, GstElement * bin)
+{
+ dyn_link *connect;
+
+ connect = g_new0 (dyn_link, 1);
+ connect->padname = g_strdup (padname);
+ connect->target = target;
+ connect->bin = bin;
+
+ g_signal_connect (G_OBJECT (element), "pad-added", G_CALLBACK (dynamic_link),
+ connect);
+}
+
+int
+main (int argc, char *argv[])
+{
+ IDirectFB *dfb;
+ IDirectFBDisplayLayer *layer;
+
+ IDirectFBImageProvider *provider;
+ IDirectFBVideoProvider *video_provider;
+
+ IDirectFBSurface *bgsurface;
+
+ IDirectFBWindow *window1;
+ IDirectFBWindow *window2;
+ IDirectFBWindow *window3;
+ IDirectFBSurface *window_surface1;
+ IDirectFBSurface *window_surface2;
+ IDirectFBSurface *window_surface3;
+
+ GstElement *pipeline;
+
+ IDirectFBEventBuffer *buffer;
+
+ IDirectFBFont *font;
+
+ DFBDisplayLayerConfig layer_config;
+ DFBGraphicsDeviceDescription gdesc;
+ DFBWindowID id1;
+ DFBWindowID id2;
+ DFBWindowID id3;
+
+ int fontheight;
+ int err;
+ int quit = 0;
+
+
+ DFBCHECK (DirectFBInit (&argc, &argv));
+ gst_init (&argc, &argv);
+ DFBCHECK (DirectFBCreate (&dfb));
+
+ dfb->GetDeviceDescription (dfb, &gdesc);
+
+ DFBCHECK (dfb->GetDisplayLayer (dfb, DLID_PRIMARY, &layer));
+
+ layer->SetCooperativeLevel (layer, DLSCL_ADMINISTRATIVE);
+
+ if (!((gdesc.blitting_flags & DSBLIT_BLEND_ALPHACHANNEL) &&
+ (gdesc.blitting_flags & DSBLIT_BLEND_COLORALPHA))) {
+ layer_config.flags = DLCONF_BUFFERMODE;
+ layer_config.buffermode = DLBM_BACKSYSTEM;
+
+ layer->SetConfiguration (layer, &layer_config);
+ }
+
+ layer->GetConfiguration (layer, &layer_config);
+ layer->EnableCursor (layer, 1);
+
+ {
+ DFBFontDescription desc;
+
+ desc.flags = DFDESC_HEIGHT;
+ desc.height = layer_config.width / 50;
+
+ DFBCHECK (dfb->CreateFont (dfb, "decker.ttf", &desc, &font));
+ font->GetHeight (font, &fontheight);
+ }
+
+ if (argc < 2 ||
+ dfb->CreateVideoProvider (dfb, argv[1], &video_provider) != DFB_OK) {
+ video_provider = NULL;
+ }
+
+ {
+ DFBSurfaceDescription desc;
+
+ desc.flags = DSDESC_WIDTH | DSDESC_HEIGHT;
+ desc.width = layer_config.width;
+ desc.height = layer_config.height;
+
+ DFBCHECK (dfb->CreateSurface (dfb, &desc, &bgsurface));
+
+ DFBCHECK (bgsurface->SetFont (bgsurface, font));
+
+ bgsurface->SetColor (bgsurface, 0xCF, 0xCF, 0xFF, 0xFF);
+ bgsurface->DrawString (bgsurface,
+ "Move the mouse over a window to activate it.",
+ -1, 0, 0, DSTF_LEFT | DSTF_TOP);
+
+ bgsurface->SetColor (bgsurface, 0xCF, 0xDF, 0xCF, 0xFF);
+ bgsurface->DrawString (bgsurface,
+ "Press left mouse button and drag to move the window.",
+ -1, 0, fontheight, DSTF_LEFT | DSTF_TOP);
+
+ bgsurface->SetColor (bgsurface, 0xCF, 0xEF, 0x9F, 0xFF);
+ bgsurface->DrawString (bgsurface,
+ "Press middle mouse button to raise/lower the window.",
+ -1, 0, fontheight * 2, DSTF_LEFT | DSTF_TOP);
+
+ bgsurface->SetColor (bgsurface, 0xCF, 0xFF, 0x6F, 0xFF);
+ bgsurface->DrawString (bgsurface,
+ "Press right mouse button when you are done.", -1,
+ 0, fontheight * 3, DSTF_LEFT | DSTF_TOP);
+
+ layer->SetBackgroundImage (layer, bgsurface);
+ layer->SetBackgroundMode (layer, DLBM_IMAGE);
+ }
+
+ {
+ DFBSurfaceDescription sdsc;
+ DFBWindowDescription desc;
+
+ desc.flags = (DWDESC_POSX | DWDESC_POSY | DWDESC_WIDTH | DWDESC_HEIGHT);
+
+ if (!video_provider) {
+ desc.caps = DWCAPS_ALPHACHANNEL;
+ desc.flags |= DWDESC_CAPS;
+
+ sdsc.width = 300;
+ sdsc.height = 200;
+ } else {
+ video_provider->GetSurfaceDescription (video_provider, &sdsc);
+
+ if (sdsc.flags & DSDESC_CAPS) {
+ desc.flags |= DWDESC_SURFACE_CAPS;
+ desc.surface_caps = sdsc.caps;
+ }
+ }
+
+ desc.posx = 20;
+ desc.posy = 120;
+ desc.width = sdsc.width;
+ desc.height = sdsc.height;
+
+ DFBCHECK (layer->CreateWindow (layer, &desc, &window2));
+ window2->GetSurface (window2, &window_surface2);
+
+ window2->SetOpacity (window2, 0xFF);
+
+ window2->GetID (window2, &id2);
+
+ window2->CreateEventBuffer (window2, &buffer);
+
+ if (video_provider) {
+ video_provider->PlayTo (video_provider, window_surface2,
+ NULL, NULL, NULL);
+ } else {
+ window_surface2->SetColor (window_surface2, 0x00, 0x30, 0x10, 0xc0);
+ window_surface2->DrawRectangle (window_surface2,
+ 0, 0, desc.width, desc.height);
+ window_surface2->SetColor (window_surface2, 0x80, 0xa0, 0x00, 0x90);
+ window_surface2->FillRectangle (window_surface2,
+ 1, 1, desc.width - 2, desc.height - 2);
+ }
+
+ window_surface2->Flip (window_surface2, NULL, 0);
+ }
+
+ {
+ DFBWindowDescription desc;
+
+ desc.flags = (DWDESC_POSX | DWDESC_POSY |
+ DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_CAPS);
+ desc.posx = 200;
+ desc.posy = 200;
+ desc.width = 512;
+ desc.height = 145;
+ desc.caps = DWCAPS_ALPHACHANNEL;
+
+ DFBCHECK (layer->CreateWindow (layer, &desc, &window1));
+ window1->GetSurface (window1, &window_surface1);
+
+ DFBCHECK (dfb->CreateImageProvider (dfb, "dfblogo.png", &provider));
+ provider->RenderTo (provider, window_surface1, NULL);
+
+ window_surface1->SetColor (window_surface1, 0xFF, 0x20, 0x20, 0x90);
+ window_surface1->DrawRectangle (window_surface1,
+ 0, 0, desc.width, desc.height);
+
+ window_surface1->Flip (window_surface1, NULL, 0);
+
+ provider->Release (provider);
+
+ window1->AttachEventBuffer (window1, buffer);
+
+ window1->SetOpacity (window1, 0xFF);
+
+ window1->GetID (window1, &id1);
+ }
+
+ {
+ DFBWindowDescription desc;
+ GstElement *src, *decode;
+ GstElement *v_queue, *v_scale, *cs, *v_sink;
+ GstElement *a_queue, *conv, *a_sink;
+ GstPad *v_pad, *a_pad;
+
+ desc.flags = (DWDESC_POSX | DWDESC_POSY |
+ DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_CAPS);
+ desc.posx = 10;
+ desc.posy = 10;
+ desc.width = 100;
+ desc.height = 100;
+ desc.caps = DWCAPS_ALPHACHANNEL;
+
+ DFBCHECK (layer->CreateWindow (layer, &desc, &window3));
+ window3->GetSurface (window3, &window_surface3);
+
+ window3->AttachEventBuffer (window3, buffer);
+
+ window3->SetOpacity (window3, 0xFF);
+
+ window3->GetID (window3, &id3);
+
+ pipeline = gst_pipeline_new ("pipeline");
+
+ src = gst_element_factory_make ("gnomevfssrc", "src");
+ g_object_set (src, "location", argv[1], NULL);
+ decode = gst_element_factory_make ("decodebin", "decode");
+
+ v_queue = gst_element_factory_make ("queue", "v_queue");
+ v_scale = gst_element_factory_make ("videoscale", "v_scale");
+ cs = gst_element_factory_make ("ffmpegcolorspace", "cs");
+ v_sink = gst_element_factory_make ("dfbvideosink", "v_sink");
+ g_object_set (v_sink, "surface", window_surface3, NULL);
+
+ a_queue = gst_element_factory_make ("queue", "a_queue");
+ conv = gst_element_factory_make ("audioconvert", "conv");
+ a_sink = gst_element_factory_make ("alsasink", "a_sink");
+
+ gst_bin_add_many (GST_BIN (pipeline), src, decode, NULL);
+ gst_bin_add_many (GST_BIN (pipeline), v_queue, v_scale, cs, v_sink, NULL);
+ gst_bin_add_many (GST_BIN (pipeline), a_queue, conv, a_sink, NULL);
+
+ gst_element_link (src, decode);
+ gst_element_link_many (v_queue, v_scale, cs, v_sink, NULL);
+ gst_element_link_many (a_queue, conv, a_sink, NULL);
+
+ v_pad = gst_element_get_static_pad (v_queue, "sink");
+ a_pad = gst_element_get_static_pad (a_queue, "sink");
+
+ setup_dynamic_link (decode, NULL, v_pad, NULL);
+ setup_dynamic_link (decode, NULL, a_pad, NULL);
+
+ /* We want to know when the size is defined */
+ g_signal_connect (v_pad, "notify::caps", G_CALLBACK (size_changed),
+ window3);
+
+ gst_object_unref (a_pad);
+ gst_object_unref (v_pad);
+
+ gst_element_set_state (pipeline, GST_STATE_PLAYING);
+ }
+
+ window1->RequestFocus (window1);
+ window1->RaiseToTop (window1);
+
+ while (!quit) {
+ static IDirectFBWindow *active = NULL;
+ static int grabbed = 0;
+ static int startx = 0;
+ static int starty = 0;
+ static int endx = 0;
+ static int endy = 0;
+ DFBWindowEvent evt;
+
+ buffer->WaitForEventWithTimeout (buffer, 0, 10);
+
+ while (buffer->GetEvent (buffer, DFB_EVENT (&evt)) == DFB_OK) {
+ IDirectFBWindow *window;
+
+ if (evt.window_id == id1)
+ window = window1;
+ else if (evt.window_id == id3)
+ window = window3;
+ else
+ window = window2;
+
+ if (evt.type == DWET_GOTFOCUS) {
+ active = window;
+ } else if (active) {
+ switch (evt.type) {
+
+ case DWET_BUTTONDOWN:
+ if (!grabbed && evt.button == DIBI_LEFT) {
+ grabbed = 1;
+ startx = evt.cx;
+ starty = evt.cy;
+ window->GrabPointer (window);
+ }
+ break;
+
+ case DWET_BUTTONUP:
+ switch (evt.button) {
+ case DIBI_LEFT:
+ if (grabbed) {
+ window->UngrabPointer (window);
+ grabbed = 0;
+ }
+ break;
+ case DIBI_MIDDLE:
+ active->RaiseToTop (active);
+ break;
+ case DIBI_RIGHT:
+ quit = DIKS_DOWN;
+ break;
+ default:
+ break;
+ }
+ break;
+
+ case DWET_KEYDOWN:
+ if (grabbed)
+ break;
+ switch (evt.key_id) {
+ case DIKI_RIGHT:
+ active->Move (active, 1, 0);
+ break;
+ case DIKI_LEFT:
+ active->Move (active, -1, 0);
+ break;
+ case DIKI_UP:
+ active->Move (active, 0, -1);
+ break;
+ case DIKI_DOWN:
+ active->Move (active, 0, 1);
+ break;
+ default:
+ break;
+ }
+ break;
+
+ case DWET_LOSTFOCUS:
+ if (!grabbed && active == window)
+ active = NULL;
+ break;
+
+ default:
+ break;
+
+ }
+ }
+
+ switch (evt.type) {
+
+ case DWET_MOTION:
+ endx = evt.cx;
+ endy = evt.cy;
+ break;
+
+ case DWET_KEYDOWN:
+ switch (evt.key_symbol) {
+ case DIKS_ESCAPE:
+ case DIKS_SMALL_Q:
+ case DIKS_CAPITAL_Q:
+ case DIKS_BACK:
+ case DIKS_STOP:
+ quit = 1;
+ break;
+ default:
+ break;
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ if (video_provider)
+ window_surface2->Flip (window_surface2, NULL, 0);
+
+ if (active) {
+ if (grabbed) {
+ active->Move (active, endx - startx, endy - starty);
+ startx = endx;
+ starty = endy;
+ }
+ active->SetOpacity (active, (sin (myclock () / 300.0) * 85) + 170);
+ }
+ }
+
+ if (video_provider)
+ video_provider->Release (video_provider);
+
+ gst_element_set_state (pipeline, GST_STATE_NULL);
+
+ buffer->Release (buffer);
+ font->Release (font);
+ window_surface2->Release (window_surface2);
+ window_surface1->Release (window_surface1);
+ window_surface3->Release (window_surface3);
+ window2->Release (window2);
+ window1->Release (window1);
+ window3->Release (window3);
+ layer->Release (layer);
+ bgsurface->Release (bgsurface);
+ dfb->Release (dfb);
+
+ return 42;
+}
diff --git a/tests/examples/gob/Makefile.am b/tests/examples/gob/Makefile.am
new file mode 100644
index 00000000..7abde4dc
--- /dev/null
+++ b/tests/examples/gob/Makefile.am
@@ -0,0 +1,19 @@
+
+plugin_LTLIBRARIES = libgstidentity2.la
+
+GOB_FILES_ID = gst-identity2.c gst-identity2.h gst-identity2-private.h
+
+BUILT_SOURCES = \
+ $(GOB_FILES_ID)
+
+libgstidentity2_la_SOURCES = gst-identity2.gob $(GOB_FILES_ID)
+libgstidentity2_la_CFLAGS = $(GST_CFLAGS)
+libgstidentity2_la_LIBADD =
+
+%.c %.h %-private.h: %.gob
+ gob $<
+
+CLEANFILES = $(GOB_FILES_ID)
+
+dist-hook:
+ cd $(distdir); rm -f $(CLEANFILES)
diff --git a/tests/examples/gob/gst-identity2.gob b/tests/examples/gob/gst-identity2.gob
new file mode 100644
index 00000000..9c34cb55
--- /dev/null
+++ b/tests/examples/gob/gst-identity2.gob
@@ -0,0 +1,141 @@
+
+%header{
+#include <gst/gst.h>
+#include "gst-identity2.h"
+#include "gst-identity2-private.h"
+%}
+
+class Gst:Identity2 from Gst:Element {
+
+ /* plugin init */
+ private gboolean
+ plugin_init (GModule *module, GstPlugin *plugin)
+ {
+ static GstElementDetails identity2_details = {
+ "GOB Identity",
+ "Filter/Effect",
+ "Does nothing",
+ "1.0",
+ "Wim Taymans <wim.taymans@chello.be>",
+ "(C) 2001",
+ };
+ GstElementFactory *factory;
+
+ factory = gst_elementfactory_new ("identity2", TYPE_SELF,
+ &identity2_details);
+ g_return_val_if_fail (factory != NULL, FALSE);
+
+ gst_plugin_add_feature (plugin, &(factory->feature));
+
+ return TRUE;
+ }
+
+ /* pads FIXME gob oculd be improved here */
+ private GstPad *sinkpad =
+ {
+ gst_pad_new ("sink", GST_PAD_SINK);
+ gst_element_add_pad (GST_ELEMENT (o), o->_priv->sinkpad);
+ gst_pad_set_chain_function (o->_priv->sinkpad, chain);
+ gst_pad_set_bufferpool_function (o->_priv->sinkpad, get_bufferpool);
+ //gst_pad_set_negotiate_function (o->_priv->sinkpad, negotiate_sink);
+ };
+ private GstPad *srcpad =
+ {
+ gst_pad_new ("src", GST_PAD_SRC);
+ gst_element_add_pad (GST_ELEMENT (o), o->_priv->srcpad);
+ //gst_pad_set_negotiate_function (o->_priv->srcpad, negotiate_src);
+ };
+
+ /* arguments */
+ /*
+ private gboolean loop_based = FALSE; argument BOOL loop_based
+ get {
+ ARG = self->_priv->loop_based;
+ }
+ set {
+ self->_priv->loop_based = ARG;
+ if (self->_priv->loop_based) {
+ gst_element_set_loop_function (GST_ELEMENT (self), loop);
+ gst_pad_set_chain_function (self->_priv->sinkpad, NULL);
+ }
+ else {
+ gst_pad_set_chain_function (self->_priv->sinkpad, chain);
+ gst_element_set_loop_function (GST_ELEMENT (self), NULL);
+ }
+ };*/
+ private guint sleep_time = 0; argument UINT sleep_time link;
+ private gboolean silent = FALSE; argument BOOL silent link;
+
+ /* signals */
+ private signal last NONE(NONE) void handoff(self);
+
+ /* core code here */
+ private GstBufferPool*
+ get_bufferpool (GstPad *pad (check null))
+ {
+ Self *self = SELF (gst_pad_get_parent (pad));
+
+ return gst_pad_get_bufferpool (self->_priv->srcpad);
+ }
+
+ /* private GstPadNegotiateReturn
+ negotiate_src (GstPad *pad, GstCaps **caps, gpointer *data)
+ {
+ Self *self = SELF (gst_pad_get_parent (pad));
+
+ return gst_pad_negotiate_proxy (pad, self->_priv->sinkpad, caps);
+ }
+
+ private GstPadNegotiateReturn
+ negotiate_sink (GstPad *pad, GstCaps **caps, gpointer *data)
+ {
+ Self *self = SELF (gst_pad_get_parent (pad));
+
+ return gst_pad_negotiate_proxy (pad, self->_priv->srcpad, caps);
+ } */
+
+ private void
+ chain (GstPad *pad (check null), GstBuffer *buf (check null))
+ {
+ Self *self;
+
+ self = SELF (gst_pad_get_parent (pad));
+
+ if (!self->_priv->silent)
+ g_print("identity2: chain ******* (%s:%s)i \n",GST_DEBUG_PAD_NAME(pad));
+
+ handoff (self);
+ gst_pad_push (self->_priv->srcpad, buf);
+
+ if (self->_priv->sleep_time)
+ usleep (self->_priv->sleep_time);
+ }
+
+ /*private void
+ loop (GstElement *element (check null))
+ {
+ Self *self = SELF (element);
+ GstBuffer *buf;
+
+ do {
+ buf = gst_pad_pull (self->_priv->sinkpad);
+ g_print("identity2: loop ******* (%s:%s)i \n",GST_DEBUG_PAD_NAME(self->_priv->sinkpad));
+
+ handoff (self);
+ gst_pad_push (self->_priv->srcpad, buf);
+
+ if (self->_priv->sleep_time)
+ usleep (self->_priv->sleep_time);
+
+ } while (!GST_ELEMENT_IS_COTHREAD_STOPPING(element));
+ }*/
+}
+
+%{
+GstPluginDesc plugin_desc = {
+ GST_VERSION_MAJOR,
+ GST_VERSION_MINOR,
+ "identity2",
+ gst_identity2_plugin_init
+};
+%}
diff --git a/tests/examples/gstplay/.gitignore b/tests/examples/gstplay/.gitignore
new file mode 100644
index 00000000..a1eb1c43
--- /dev/null
+++ b/tests/examples/gstplay/.gitignore
@@ -0,0 +1 @@
+player
diff --git a/tests/examples/gstplay/Makefile.am b/tests/examples/gstplay/Makefile.am
new file mode 100644
index 00000000..cbae9cbf
--- /dev/null
+++ b/tests/examples/gstplay/Makefile.am
@@ -0,0 +1,11 @@
+
+noinst_PROGRAMS = player
+
+player_SOURCES = player.c
+player_CFLAGS = $(GST_CFLAGS) $(GCONF_CFLAGS)
+player_LDFLAGS = \
+ $(GST_LIBS) \
+ $(top_builddir)/gst-libs/gst/gconf/libgstgconf-@GST_MAJORMINOR@.la \
+ $(top_builddir)/gst-libs/gst/play/libgstplay-@GST_MAJORMINOR@.la \
+ $(top_builddir)/gst-libs/gst/libgstinterfaces-$(GST_MAJORMINOR).la
+
diff --git a/tests/examples/gstplay/player.c b/tests/examples/gstplay/player.c
new file mode 100644
index 00000000..76453785
--- /dev/null
+++ b/tests/examples/gstplay/player.c
@@ -0,0 +1,176 @@
+/* GStreamer
+ * Copyright (C) 2003 Julien Moutte <julien@moutte.net>
+ *
+ * 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 <gst/play/play.h>
+#include <gst/gconf/gconf.h>
+
+static GMainLoop *loop = NULL;
+static gint64 length = 0;
+
+static void
+print_tag (const GstTagList * list, const gchar * tag, gpointer unused)
+{
+ gint i, count;
+
+ count = gst_tag_list_get_tag_size (list, tag);
+
+ for (i = 0; i < count; i++) {
+ gchar *str;
+
+ if (gst_tag_get_type (tag) == G_TYPE_STRING) {
+ if (!gst_tag_list_get_string_index (list, tag, i, &str))
+ g_assert_not_reached ();
+ } else {
+ str =
+ g_strdup_value_contents (gst_tag_list_get_value_index (list, tag, i));
+ }
+
+ if (i == 0) {
+ g_print ("%15s: %s\n", gst_tag_get_nick (tag), str);
+ } else {
+ g_print (" : %s\n", str);
+ }
+
+ g_free (str);
+ }
+}
+
+static void
+got_found_tag (GstPlay * play, GstElement * source, GstTagList * tag_list)
+{
+ gst_tag_list_foreach (tag_list, print_tag, NULL);
+}
+
+static void
+got_time_tick (GstPlay * play, gint64 time_nanos)
+{
+ g_print ("time tick %f\n", time_nanos / (float) GST_SECOND);
+}
+
+static void
+got_stream_length (GstPlay * play, gint64 length_nanos)
+{
+ g_print ("got length %" G_GUINT64_FORMAT "\n", length_nanos);
+ length = length_nanos;
+}
+
+static void
+got_video_size (GstPlay * play, gint width, gint height)
+{
+ g_print ("got video size %d, %d\n", width, height);
+}
+
+static void
+got_eos (GstPlay * play)
+{
+ g_print ("End Of Stream\n");
+ g_main_loop_quit (loop);
+}
+
+static gboolean
+seek_timer (GstPlay * play)
+{
+ gst_play_seek_to_time (play, length / 2);
+ return FALSE;
+}
+
+int
+main (int argc, char *argv[])
+{
+ GstPlay *play;
+ GstElement *data_src, *video_sink, *audio_sink, *vis_element;
+ GError *error = NULL;
+
+ /* Initing GStreamer library */
+ gst_init (&argc, &argv);
+
+ if (argc != 2) {
+ g_print ("usage: %s <video filename>\n", argv[0]);
+ exit (-1);
+ }
+
+ loop = g_main_loop_new (NULL, FALSE);
+
+ /* Creating the GstPlay object */
+ play = gst_play_new (&error);
+ if (error) {
+ g_print ("Error: could not create play object:\n%s\n", error->message);
+ g_error_free (error);
+ return 1;
+ }
+
+ /* Getting default audio and video plugins from GConf */
+ vis_element = gst_element_factory_make ("goom", "vis_element");
+ data_src = gst_element_factory_make ("gnomevfssrc", "source");
+
+ audio_sink = gst_gconf_get_default_audio_sink ();
+ if (!GST_IS_ELEMENT (audio_sink))
+ g_error ("Could not get default audio sink from GConf");
+ video_sink = gst_gconf_get_default_video_sink ();
+ if (!GST_IS_ELEMENT (video_sink))
+ g_error ("Could not get default video sink from GConf");
+
+
+ /* Let's send them to GstPlay object */
+ if (!gst_play_set_audio_sink (play, audio_sink))
+ g_warning ("Could not set audio sink");
+ if (!gst_play_set_video_sink (play, video_sink))
+ g_warning ("Could not set video sink");
+ if (!gst_play_set_data_src (play, data_src))
+ g_warning ("Could not set data src");
+ if (!gst_play_set_visualization (play, vis_element))
+ g_warning ("Could not set visualisation");
+
+ /* Setting location we want to play */
+ if (!gst_play_set_location (play, argv[1]))
+ g_warning ("Could not set location");
+
+ /* Uncomment that line to get an XML dump of the pipeline */
+ /* gst_xml_write_file (GST_ELEMENT (play), stdout); */
+
+ g_signal_connect (G_OBJECT (play), "time_tick",
+ G_CALLBACK (got_time_tick), NULL);
+ g_signal_connect (G_OBJECT (play), "stream_length",
+ G_CALLBACK (got_stream_length), NULL);
+ g_signal_connect (G_OBJECT (play), "have_video_size",
+ G_CALLBACK (got_video_size), NULL);
+ g_signal_connect (G_OBJECT (play), "found_tag",
+ G_CALLBACK (got_found_tag), NULL);
+ g_signal_connect (G_OBJECT (play), "error",
+ G_CALLBACK (gst_element_default_error), NULL);
+ g_signal_connect (G_OBJECT (play), "eos", G_CALLBACK (got_eos), NULL);
+
+ /* Change state to PLAYING */
+ if (gst_element_set_state (GST_ELEMENT (play),
+ GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
+ g_error ("Could not set state to PLAYING");
+
+ g_timeout_add (20000, (GSourceFunc) seek_timer, play);
+
+ g_main_loop_run (loop);
+
+ g_print ("setting pipeline to ready\n");
+
+ gst_element_set_state (GST_ELEMENT (play), GST_STATE_READY);
+
+ /* unref
+ gst_object_unref (GST_OBJECT (play)); */
+
+ exit (0);
+}
diff --git a/tests/examples/indexing/.gitignore b/tests/examples/indexing/.gitignore
new file mode 100644
index 00000000..5ce09473
--- /dev/null
+++ b/tests/examples/indexing/.gitignore
@@ -0,0 +1 @@
+indexmpeg
diff --git a/tests/examples/indexing/Makefile.am b/tests/examples/indexing/Makefile.am
new file mode 100644
index 00000000..022bfc85
--- /dev/null
+++ b/tests/examples/indexing/Makefile.am
@@ -0,0 +1,7 @@
+examples = indexmpeg
+
+noinst_PROGRAMS = $(examples)
+
+# we have nothing but apps here, we can do this safely
+LIBS = $(GST_LIBS) $(GTK_LIBS)
+AM_CFLAGS = $(GST_CFLAGS) $(GTK_CFLAGS)
diff --git a/tests/examples/indexing/indexmpeg.c b/tests/examples/indexing/indexmpeg.c
new file mode 100644
index 00000000..a670ad8a
--- /dev/null
+++ b/tests/examples/indexing/indexmpeg.c
@@ -0,0 +1,321 @@
+/* GStreamer
+ * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
+ *
+ * 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 <string.h>
+#include <gst/gst.h>
+
+static gboolean verbose = FALSE;
+static gboolean quiet = FALSE;
+
+static void
+entry_added (GstIndex * index, GstIndexEntry * entry)
+{
+ switch (entry->type) {
+ case GST_INDEX_ENTRY_ID:
+ g_print ("id %d describes writer %s\n", entry->id,
+ GST_INDEX_ID_DESCRIPTION (entry));
+ break;
+ case GST_INDEX_ENTRY_FORMAT:
+ g_print ("%d: registered format %d for %s\n", entry->id,
+ GST_INDEX_FORMAT_FORMAT (entry), GST_INDEX_FORMAT_KEY (entry));
+ break;
+ case GST_INDEX_ENTRY_ASSOCIATION:
+ {
+ gint i;
+
+ g_print ("%p, %d: %08x ", entry, entry->id,
+ GST_INDEX_ASSOC_FLAGS (entry));
+ for (i = 0; i < GST_INDEX_NASSOCS (entry); i++) {
+ g_print ("%d %" G_GINT64_FORMAT " ", GST_INDEX_ASSOC_FORMAT (entry, i),
+ GST_INDEX_ASSOC_VALUE (entry, i));
+ }
+ g_print ("\n");
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+typedef struct
+{
+ const gchar *padname;
+ GstPad *target;
+ GstElement *bin;
+ GstElement *pipeline;
+ GstIndex *index;
+}
+dyn_link;
+
+static void
+dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data)
+{
+ dyn_link *link = (dyn_link *) data;
+
+ if (!strcmp (gst_pad_get_name (newpad), link->padname)) {
+ gst_element_set_state (link->pipeline, GST_STATE_PAUSED);
+ gst_bin_add (GST_BIN (link->pipeline), link->bin);
+ gst_pad_link (newpad, link->target);
+ gst_element_set_index (link->bin, link->index);
+ gst_element_set_state (link->pipeline, GST_STATE_PLAYING);
+ }
+}
+
+static void
+setup_dynamic_linking (GstElement * pipeline,
+ GstElement * element,
+ const gchar * padname, GstPad * target, GstElement * bin, GstIndex * index)
+{
+ dyn_link *link;
+
+ link = g_new0 (dyn_link, 1);
+ link->padname = g_strdup (padname);
+ link->target = target;
+ link->bin = bin;
+ link->pipeline = pipeline;
+ link->index = index;
+
+ g_signal_connect (G_OBJECT (element), "new_pad", G_CALLBACK (dynamic_link),
+ link);
+}
+
+static GstElement *
+make_mpeg_systems_pipeline (const gchar * path, GstIndex * index)
+{
+ GstElement *pipeline;
+ GstElement *src, *demux;
+
+ pipeline = gst_pipeline_new ("pipeline");
+
+ src = gst_element_factory_make ("filesrc", "src");
+ g_object_set (G_OBJECT (src), "location", path, NULL);
+
+ demux = gst_element_factory_make ("mpegdemux", "demux");
+
+ gst_bin_add (GST_BIN (pipeline), src);
+ gst_bin_add (GST_BIN (pipeline), demux);
+
+ if (index) {
+ gst_element_set_index (pipeline, index);
+ }
+
+ gst_element_link_pads (src, "src", demux, "sink");
+
+ return pipeline;
+}
+
+static GstElement *
+make_mpeg_decoder_pipeline (const gchar * path, GstIndex * index)
+{
+ GstElement *pipeline;
+ GstElement *src, *demux;
+ GstElement *video_bin, *audio_bin;
+ GstElement *video_decoder, *audio_decoder;
+
+ pipeline = gst_pipeline_new ("pipeline");
+
+ src = gst_element_factory_make ("filesrc", "src");
+ g_object_set (G_OBJECT (src), "location", path, NULL);
+
+ demux = gst_element_factory_make ("mpegdemux", "demux");
+
+ gst_bin_add (GST_BIN (pipeline), src);
+ gst_bin_add (GST_BIN (pipeline), demux);
+
+ gst_element_link_pads (src, "src", demux, "sink");
+
+ video_bin = gst_bin_new ("video_bin");
+ video_decoder = gst_element_factory_make ("mpeg2dec", "video_decoder");
+
+ gst_bin_add (GST_BIN (video_bin), video_decoder);
+
+ setup_dynamic_linking (pipeline, demux, "video_00",
+ gst_element_get_pad (video_decoder, "sink"), video_bin, index);
+
+ audio_bin = gst_bin_new ("audio_bin");
+ audio_decoder = gst_element_factory_make ("mad", "audio_decoder");
+
+ setup_dynamic_linking (pipeline, demux, "audio_00",
+ gst_element_get_pad (audio_decoder, "sink"), audio_bin, index);
+
+ gst_bin_add (GST_BIN (audio_bin), audio_decoder);
+
+ if (index) {
+ gst_element_set_index (pipeline, index);
+ }
+
+ return pipeline;
+}
+
+static void
+print_progress (GstPad * pad)
+{
+ gint i = 0;
+ gchar status[53];
+ GstFormat format;
+ gboolean res;
+ gint64 value;
+ gint percent = 0;
+
+ status[0] = '|';
+
+ format = GST_FORMAT_PERCENT;
+ res = gst_pad_query (pad, GST_QUERY_POSITION, &format, &value);
+ if (res) {
+ percent = value / (2 * GST_FORMAT_PERCENT_SCALE);
+ }
+
+ for (i = 0; i < percent; i++) {
+ status[i + 1] = '=';
+ }
+ for (i = percent; i < 50; i++) {
+ status[i + 1] = ' ';
+ }
+ status[51] = '|';
+ status[52] = 0;
+
+ g_print ("%s\r", status);
+}
+
+gint
+main (gint argc, gchar * argv[])
+{
+ GstElement *pipeline;
+ GstElement *src;
+ GstPad *pad;
+ GstIndex *index;
+ gint count = 0;
+ GstEvent *event;
+ gboolean res;
+ GstElement *sink;
+ struct poptOption options[] = {
+ {"verbose", 'v', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &verbose, 0,
+ "Print index entries", NULL},
+ {"quiet", 'q', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &quiet, 0,
+ "don't print progress bar", NULL},
+ POPT_TABLEEND
+ };
+
+ if (!gst_init_check_with_popt_table (&argc, &argv, options) || argc < 3) {
+ g_print ("usage: %s [-v] <type> <filename> \n"
+ " type can be: 0 mpeg_systems\n"
+ " 1 mpeg_decoder\n"
+ " -v : report added index entries\n"
+ " -q : don't print progress\n", argv[0]);
+ return -1;
+ }
+
+ /* create index that elements can fill */
+ index = gst_index_factory_make ("memindex");
+ if (index) {
+ if (verbose)
+ g_signal_connect (G_OBJECT (index), "entry_added",
+ G_CALLBACK (entry_added), NULL);
+
+ g_object_set (G_OBJECT (index), "resolver", 1, NULL);
+ }
+
+ /* construct pipeline */
+ switch (atoi (argv[1])) {
+ case 0:
+ pipeline = make_mpeg_systems_pipeline (argv[2], index);
+ break;
+ case 1:
+ pipeline = make_mpeg_decoder_pipeline (argv[2], index);
+ break;
+ default:
+ g_print ("unknown type %d\n", atoi (argv[1]));
+ return -1;
+ }
+
+ /* setup some default info/error handlers */
+ g_signal_connect (G_OBJECT (pipeline), "deep_notify",
+ G_CALLBACK (gst_element_default_deep_notify), NULL);
+ g_signal_connect (G_OBJECT (pipeline), "error",
+ G_CALLBACK (gst_element_default_error), NULL);
+
+ /* get a pad to perform progress reporting on */
+ src = gst_bin_get_by_name (GST_BIN (pipeline), "src");
+ pad = gst_element_get_pad (src, "src");
+
+ /* prepare for iteration */
+ gst_element_set_state (pipeline, GST_STATE_PLAYING);
+
+ g_print ("indexing %s...\n", argv[2]);
+ /* run through the complete stream to let it generate an index */
+ while (gst_bin_iterate (GST_BIN (pipeline))) {
+ if (!quiet && (count % 1000 == 0)) {
+ print_progress (pad);
+ }
+ count++;
+ }
+ g_print ("\n");
+
+ /* bring to ready to restart the pipeline */
+ gst_element_set_state (pipeline, GST_STATE_READY);
+ gst_element_set_state (pipeline, GST_STATE_PAUSED);
+
+ if (index)
+ GST_OBJECT_FLAG_UNSET (index, GST_INDEX_WRITABLE);
+
+ src = gst_bin_get_by_name (GST_BIN (pipeline), "video_decoder");
+
+ {
+ gint id;
+ GstIndexEntry *entry;
+ gint64 result;
+ gint total_tm;
+
+ gst_index_get_writer_id (index, GST_OBJECT (src), &id);
+
+ entry = gst_index_get_assoc_entry (index, id, GST_INDEX_LOOKUP_BEFORE, 0,
+ GST_FORMAT_TIME, G_MAXINT64);
+ g_assert (entry);
+ gst_index_entry_assoc_map (entry, GST_FORMAT_TIME, &result);
+ total_tm = result * 60 / GST_SECOND;
+ g_print ("total time = %.2fs\n", total_tm / 60.0);
+ }
+
+ pad = gst_element_get_pad (src, "src");
+ sink = gst_element_factory_make ("fakesink", "sink");
+ gst_element_link_pads (src, "src", sink, "sink");
+ gst_bin_add (GST_BIN (pipeline), sink);
+
+ g_print ("seeking %s...\n", argv[2]);
+ event = gst_event_new_seek (GST_FORMAT_TIME |
+ GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH, 5 * GST_SECOND);
+
+ res = gst_pad_send_event (pad, event);
+ if (!res) {
+ g_warning ("seek failed");
+ }
+
+ gst_element_set_state (pipeline, GST_STATE_PLAYING);
+ count = 0;
+ while (gst_bin_iterate (GST_BIN (pipeline))) {
+ if (!quiet && (count % 1000 == 0)) {
+ print_progress (pad);
+ }
+ count++;
+ }
+
+ gst_element_set_state (pipeline, GST_STATE_NULL);
+
+ return 1;
+}
diff --git a/tests/examples/level/Makefile.am b/tests/examples/level/Makefile.am
new file mode 100644
index 00000000..bf76136f
--- /dev/null
+++ b/tests/examples/level/Makefile.am
@@ -0,0 +1,11 @@
+noinst_PROGRAMS = demo plot
+
+demo_SOURCES = demo.c
+demo_CFLAGS = $(GTK_CFLAGS) $(GST_CFLAGS)
+demo_LDFLAGS = $(GTK_LIBS) $(GST_LIBS)
+
+plot_SOURCES = plot.c
+plot_CFLAGS = $(GTK_CFLAGS) $(GST_CFLAGS)
+plot_LDFLAGS = $(GTK_LIBS) $(GST_LIBS)
+
+EXTRA_DIST = README
diff --git a/tests/examples/level/README b/tests/examples/level/README
new file mode 100644
index 00000000..0ae84188
--- /dev/null
+++ b/tests/examples/level/README
@@ -0,0 +1,39 @@
+level plugin by thomas <thomas@apestaart.org>
+
+this plugin signals:
+ - running time since last EOS/start
+ - channel
+ - RMS level
+ - peak level
+ - decaying peak level
+over the given interval.
+
+This is useful for a VU meter display and for plotting out the signal graph.
+The VU meter can either display RMS, or display immediate peak level and
+have the falloff decaying peak level displayed as a line.
+
+The interval for signal emission, ttl of decay peak, and falloff of decay peak
+can all be set.
+
+The element only takes unsigned data in; it could be extended to signed as
+well, if separate fast chain functions are made that displaces the incoming
+data to its midpoint (ie, 0,65535 should be mapped to -32768, 32767)
+
+There are two demo apps, apps and plot. apps will create some GTK sliders
+to display the volume. plot will output data readable by gnuplot.
+
+Here is a sample plot script to plot output of the plot command that was
+stored to plot.dat
+
+set xlabel "Seconds"
+set ylabel "dB"
+set yrange [-60:0]
+plot 'plot.dat' using 1:2 title 'L RMS' with lines, \
+ 'plot.dat' using 1:3 title 'L peak' with lines, \
+ 'plot.dat' using 1:4 title 'L decay' with lines
+
+plot 'plot.dat' using 1:5 title 'R RMS' with lines, \
+ 'plot.dat' using 1:6 title 'R peak' with lines, \
+ 'plot.dat' using 1:7 title 'R decay' with lines
+
+
diff --git a/tests/examples/level/demo.c b/tests/examples/level/demo.c
new file mode 100644
index 00000000..502f50f7
--- /dev/null
+++ b/tests/examples/level/demo.c
@@ -0,0 +1,155 @@
+/* GStreamer
+ * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
+ *
+ * demo.c: sample application to display VU meter-like output of level
+ * Copyright (C) 2003
+ * Thomas Vander Stichele <thomas at apestaart dot org>
+ *
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gst/gst.h>
+#include <gtk/gtk.h>
+
+/* global array for the scale widgets, we'll assume stereo */
+GtkWidget *elapsed;
+GtkWidget *scale[2][3];
+
+static void
+level_callback (GstElement * element, gdouble time, gint channel,
+ gdouble rms, gdouble peak, gdouble decay)
+{
+ gchar *label;
+
+ label = g_strdup_printf ("%.3f", time);
+ gtk_label_set (GTK_LABEL (elapsed), label);
+ g_free (label);
+ gtk_range_set_value (GTK_RANGE (scale[channel][0]), rms);
+ gtk_range_set_value (GTK_RANGE (scale[channel][1]), peak);
+ gtk_range_set_value (GTK_RANGE (scale[channel][2]), decay);
+}
+
+static gboolean
+idler (gpointer data)
+{
+ GstElement *pipeline = GST_ELEMENT (data);
+
+ g_print ("+");
+ if (gst_bin_iterate (GST_BIN (pipeline)))
+ return TRUE;
+ gtk_main_quit ();
+ return FALSE;
+}
+
+static void
+setup_gui ()
+{
+ GtkWidget *window;
+ GtkWidget *vbox;
+ GtkWidget *label, *hbox;
+ int c;
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ g_signal_connect (window, "destroy", gtk_main_quit, NULL);
+
+ vbox = gtk_vbox_new (TRUE, 0);
+ gtk_container_add (GTK_CONTAINER (window), vbox);
+
+ /* elapsed widget */
+ hbox = gtk_hbox_new (TRUE, 0);
+ label = gtk_label_new ("Elapsed");
+ elapsed = gtk_label_new ("0.000");
+ gtk_container_add (GTK_CONTAINER (hbox), label);
+ gtk_container_add (GTK_CONTAINER (hbox), elapsed);
+ gtk_container_add (GTK_CONTAINER (vbox), hbox);
+
+ for (c = 0; c < 2; ++c) {
+ /* RMS */
+ hbox = gtk_hbox_new (TRUE, 0);
+ label = gtk_label_new ("RMS");
+ gtk_container_add (GTK_CONTAINER (hbox), label);
+ scale[c][0] = gtk_hscale_new_with_range (-90.0, 0.0, 0.2);
+ gtk_widget_set_size_request (scale[c][0], 100, -1);
+ gtk_container_add (GTK_CONTAINER (hbox), scale[c][0]);
+ gtk_container_add (GTK_CONTAINER (vbox), hbox);
+ /* peak */
+ hbox = gtk_hbox_new (TRUE, 0);
+ label = gtk_label_new ("peak");
+ gtk_container_add (GTK_CONTAINER (hbox), label);
+ scale[c][1] = gtk_hscale_new_with_range (-90.0, 0.0, 0.2);
+ gtk_widget_set_size_request (scale[c][1], 100, -1);
+ gtk_container_add (GTK_CONTAINER (hbox), scale[c][1]);
+ gtk_container_add (GTK_CONTAINER (vbox), hbox);
+ /* decay */
+ hbox = gtk_hbox_new (TRUE, 0);
+ label = gtk_label_new ("decaying peek");
+ gtk_container_add (GTK_CONTAINER (hbox), label);
+ scale[c][2] = gtk_hscale_new_with_range (-90.0, 0.0, 0.2);
+ gtk_widget_set_size_request (scale[c][2], 100, -1);
+ gtk_container_add (GTK_CONTAINER (hbox), scale[c][2]);
+ gtk_container_add (GTK_CONTAINER (vbox), hbox);
+ }
+
+ gtk_widget_show_all (GTK_WIDGET (window));
+}
+
+int
+main (int argc, char *argv[])
+{
+
+ GstElement *pipeline = NULL;
+ GError *error = NULL;
+ GstElement *level;
+
+ gst_init (&argc, &argv);
+ gtk_init (&argc, &argv);
+
+ pipeline = gst_parse_launchv ((const gchar **) &argv[1], &error);
+ if (error) {
+ g_print ("pipeline could not be constructed: %s\n", error->message);
+ g_print ("Please give a complete pipeline with a 'level' element.\n");
+ g_print ("Example: sinesrc ! level ! %s\n", DEFAULT_AUDIOSINK);
+ g_error_free (error);
+ return 1;
+ }
+
+ level = gst_bin_get_by_name (GST_BIN (pipeline), "level0");
+ if (level == NULL) {
+ g_print ("Please give a pipeline with a 'level' element in it\n");
+ return 1;
+ }
+
+ g_object_set (level, "signal", TRUE, NULL);
+ g_signal_connect (level, "level", G_CALLBACK (level_callback), NULL);
+
+
+ /* setup GUI */
+ setup_gui ();
+
+ /* connect level signal */
+
+ /* go to main loop */
+ gst_element_set_state (pipeline, GST_STATE_PLAYING);
+ g_idle_add (idler, pipeline);
+
+ gtk_main ();
+
+ return 0;
+}
diff --git a/tests/examples/level/plot.c b/tests/examples/level/plot.c
new file mode 100644
index 00000000..44591584
--- /dev/null
+++ b/tests/examples/level/plot.c
@@ -0,0 +1,124 @@
+/* GStreamer
+ * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
+ *
+ * plot.c: output data points to be graphed with gnuplot
+ * Copyright (C) 2003
+ * Thomas Vander Stichele <thomas at apestaart dot org>
+ *
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gst/gst.h>
+#include <gtk/gtk.h>
+
+gboolean got_channel[2] = { FALSE, FALSE }; /* to see if we got the signal for this one yet */
+
+gint channels = 0; /* guess at how many channels there are */
+gdouble last_time = 0.0; /* time of last signal */
+gdouble values[2][3]; /* array of levels from which to print */
+
+static void
+level_callback (GstElement * element, gdouble time, gint channel,
+ gdouble rms, gdouble peak, gdouble decay)
+{
+ int i = 0, j = 0;
+ gboolean got_all = FALSE;
+
+ if (channel + 1 > channels)
+ channels = channel + 1;
+
+ /* reset got_channel if this is a new time point */
+ if (time > last_time) {
+ for (i = 0; i < channels; ++i)
+ got_channel[i] = FALSE;
+ last_time = time;
+ }
+
+ /* store values */
+ got_channel[channel] = TRUE;
+ values[channel][0] = rms;
+ values[channel][1] = peak;
+ values[channel][2] = decay;
+
+ /* check if we have all channels, and output if we do */
+ /* FIXME: this fails on the first, no ? */
+ got_all = TRUE;
+ for (i = 0; i < channels; ++i)
+ if (!got_channel[i])
+ got_all = FALSE;
+ if (got_all) {
+ g_print ("%f ", time);
+ for (i = 0; i < channels; ++i)
+ for (j = 0; j < 3; ++j)
+ g_print ("%f ", values[i][j]);
+ g_print ("\n");
+ }
+}
+
+static gboolean
+idler (gpointer data)
+{
+ GstElement *pipeline = GST_ELEMENT (data);
+
+ if (gst_bin_iterate (GST_BIN (pipeline)))
+ return TRUE;
+
+ gtk_main_quit ();
+ return FALSE;
+}
+
+int
+main (int argc, char *argv[])
+{
+
+ GstElement *pipeline = NULL;
+ GError *error = NULL;
+ GstElement *level;
+
+ gst_init (&argc, &argv);
+ gtk_init (&argc, &argv);
+
+ pipeline = gst_parse_launchv ((const gchar **) &argv[1], &error);
+ if (error) {
+ g_print ("pipeline could not be constructed: %s\n", error->message);
+ g_print ("Please give a complete pipeline with a 'level' element.\n");
+ g_print ("Example: sinesrc ! level ! %s\n", DEFAULT_AUDIOSINK);
+ g_error_free (error);
+ return 1;
+ }
+
+ level = gst_bin_get_by_name (GST_BIN (pipeline), "level0");
+ if (level == NULL) {
+ g_print ("Please give a pipeline with a 'level' element in it\n");
+ return 1;
+ }
+
+ g_object_set (level, "signal", TRUE, NULL);
+ g_signal_connect (level, "level", G_CALLBACK (level_callback), NULL);
+
+
+ /* go to main loop */
+ gst_element_set_state (pipeline, GST_STATE_PLAYING);
+ g_idle_add (idler, pipeline);
+
+ gtk_main ();
+
+ return 0;
+}
diff --git a/tests/examples/scaletempo/.gitignore b/tests/examples/scaletempo/.gitignore
new file mode 100644
index 00000000..1c56e144
--- /dev/null
+++ b/tests/examples/scaletempo/.gitignore
@@ -0,0 +1 @@
+scaletempo-demo
diff --git a/tests/examples/scaletempo/Makefile.am b/tests/examples/scaletempo/Makefile.am
new file mode 100644
index 00000000..5cdf3c7f
--- /dev/null
+++ b/tests/examples/scaletempo/Makefile.am
@@ -0,0 +1,8 @@
+noinst_PROGRAMS = scaletempo-demo
+
+scaletempo_demo_SOURCES = demo-main.c demo-player.c demo-gui.c
+scaletempo_demo_CFLAGS = $(GST_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) $(GTK_CFLAGS)
+scaletempo_demo_LDFLAGS = $(GST_LIBS) $(GST_PLUGINS_BASE_LIBS) $(GTK_LIBS) -lgstinterfaces-@GST_MAJORMINOR@
+
+noinst_HEADERS = demo-player.h demo-gui.h
+
diff --git a/tests/examples/scaletempo/demo-gui.c b/tests/examples/scaletempo/demo-gui.c
new file mode 100644
index 00000000..01df9991
--- /dev/null
+++ b/tests/examples/scaletempo/demo-gui.c
@@ -0,0 +1,1262 @@
+/* demo-gui.c
+ * Copyright (C) 2008 Rov Juvano <rovjuvano@users.sourceforge.net>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gtk/gtk.h>
+#include <glib/gprintf.h>
+#include <math.h>
+#include "demo-gui.h"
+
+#undef G_LOG_DOMAIN
+#define G_LOG_DOMAIN "demo-gui"
+
+#if !GTK_CHECK_VERSION(2,12,0)
+#define gtk_widget_error_bell(w) /* nop */
+#endif
+
+enum
+{
+ SIGNAL_ERROR,
+ SIGNAL_QUITING,
+ LAST_SIGNAL
+};
+static guint demo_gui_signals[LAST_SIGNAL] = { 0 };
+
+enum
+{
+ PROP_0,
+};
+
+typedef struct _DemoGuiPrivate
+{
+ DemoPlayer *player;
+ GList *uris;
+ GList *now_playing;
+ gboolean is_playing;
+ GtkWidget *window;
+ GtkEntry *rate_entry;
+ GtkStatusbar *status_bar;
+ gint position_updater_id;
+ GtkRange *seek_range;
+ GtkLabel *amount_played;
+ GtkLabel *amount_to_play;
+ GtkAction *play_action;
+ GtkAction *pause_action;
+ GtkAction *open_file;
+ GtkAction *playlist_next;
+} DemoGuiPrivate;
+
+#define DEMO_GUI_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DEMO_TYPE_GUI, DemoGuiPrivate))
+
+/* forward declarations */
+static GValueArray *build_gvalue_array (guint n_values, ...);
+
+/* Handlers for status bar and seek bar */
+static int
+pop_status_bar (gpointer data)
+{
+ GValueArray *gvalues = (GValueArray *) data;
+ GtkStatusbar *sb =
+ GTK_STATUSBAR (g_value_get_object (g_value_array_get_nth (gvalues, 0)));
+ guint msg_id = g_value_get_uint (g_value_array_get_nth (gvalues, 1));
+
+ gtk_statusbar_remove (sb, 0, msg_id);
+ return FALSE;
+}
+
+#define DEFAULT_STATUS_BAR_TIMEOUT 2
+static void
+status_bar_printf (GtkStatusbar * sb, guint seconds, gchar const *format, ...)
+{
+ va_list args;
+ gchar msg[80];
+ guint msg_id;
+
+ va_start (args, format);
+ g_vsnprintf (msg, 80, format, args);
+ va_end (args);
+
+ msg_id = gtk_statusbar_push (sb, 0, msg);
+ g_timeout_add (2000, pop_status_bar,
+ build_gvalue_array (2, G_TYPE_OBJECT, sb, G_TYPE_UINT, msg_id));
+}
+
+#define PRINTF_TIME_FORMAT "u:%02u:%02u"
+#define PRINTF_TIME_ARGS(t) \
+ (t >= 0) ? (guint) ((t) / (60 * 60)) : 99, \
+ (t >= 0) ? (guint) (((t) / (60)) % 60) : 99, \
+ (t >= 0) ? (guint) ((t) % 60) : 99
+
+static gchar *
+demo_gui_seek_bar_format (GtkScale * scale, gdouble value, gpointer data)
+{
+ return g_strdup_printf ("%" PRINTF_TIME_FORMAT,
+ PRINTF_TIME_ARGS ((gint64) value));
+}
+
+gboolean
+update_position (gpointer data)
+{
+ DemoGui *gui = DEMO_GUI (data);
+ DemoGuiPrivate *priv = DEMO_GUI_GET_PRIVATE (gui);
+ gchar pos_str[16], dur_str[16];
+ gint pos = demo_player_get_position (priv->player);
+
+ if (pos > 0) {
+ gint dur = demo_player_get_duration (priv->player);
+
+ g_snprintf (pos_str, 16, "%" PRINTF_TIME_FORMAT, PRINTF_TIME_ARGS (pos));
+ if (dur > 0) {
+ g_snprintf (dur_str, 16, "-%" PRINTF_TIME_FORMAT,
+ PRINTF_TIME_ARGS (dur - pos));
+ } else {
+ dur = pos;
+ g_sprintf (dur_str, "-??:??:??");
+ }
+ if (dur > 0)
+ gtk_range_set_range (GTK_RANGE (priv->seek_range), 0, (gdouble) dur);
+ gtk_range_set_value (GTK_RANGE (priv->seek_range), (gdouble) pos);
+ } else {
+ g_sprintf (pos_str, "??:??:??");
+ g_sprintf (dur_str, "-??:??:??");
+ }
+ gtk_label_set_text (GTK_LABEL (priv->amount_played), pos_str);
+ gtk_label_set_text (GTK_LABEL (priv->amount_to_play), dur_str);
+
+ return priv->is_playing;
+}
+
+
+gboolean
+demo_gui_seek_bar_change (GtkRange * range,
+ GtkScrollType scroll, gdouble value, gpointer data)
+{
+ DemoGui *gui = DEMO_GUI (data);
+ DemoGuiPrivate *priv = DEMO_GUI_GET_PRIVATE (gui);
+ gint new_second = (gint) value;
+
+ status_bar_printf (priv->status_bar, DEFAULT_STATUS_BAR_TIMEOUT,
+ "Seeking to %i second", new_second);
+ demo_player_seek_to (priv->player, new_second);
+
+ return FALSE;
+}
+
+
+/* Callbacks for actions */
+static void
+demo_gui_do_change_rate (GtkAction * action, gpointer data)
+{
+ GValueArray *gvalues = (GValueArray *) data;
+ DemoGui *gui = g_value_get_object (g_value_array_get_nth (gvalues, 0));
+ gdouble scale_amount =
+ g_value_get_double (g_value_array_get_nth (gvalues, 1));
+ DemoGuiPrivate *priv = DEMO_GUI_GET_PRIVATE (gui);
+
+ status_bar_printf (priv->status_bar, DEFAULT_STATUS_BAR_TIMEOUT,
+ "Changing rate by %3.2lf", scale_amount);
+
+ demo_player_scale_rate (priv->player, scale_amount);
+}
+
+static void
+demo_gui_do_set_rate (GtkAction * action, gpointer data)
+{
+ GValueArray *gvalues = (GValueArray *) data;
+ DemoGui *gui = g_value_get_object (g_value_array_get_nth (gvalues, 0));
+ gdouble new_rate = g_value_get_double (g_value_array_get_nth (gvalues, 1));
+ DemoGuiPrivate *priv = DEMO_GUI_GET_PRIVATE (gui);
+
+ status_bar_printf (priv->status_bar, DEFAULT_STATUS_BAR_TIMEOUT,
+ "Setting rate to %3.2lf", new_rate);
+
+ demo_player_set_rate (priv->player, new_rate);
+}
+
+static gboolean
+demo_gui_do_rate_entered (GtkWidget * widget, gpointer data)
+{
+ DemoGui *gui = DEMO_GUI (data);
+ DemoGuiPrivate *priv = DEMO_GUI_GET_PRIVATE (gui);
+ gchar *err = NULL;
+ const gchar *text = gtk_entry_get_text (GTK_ENTRY (widget));
+ double new_rate = g_strtod (text, &err);
+
+ if (*err) {
+ gtk_widget_error_bell (priv->window);
+ status_bar_printf (priv->status_bar, DEFAULT_STATUS_BAR_TIMEOUT,
+ "Invalid rate: %s", text);
+ return TRUE;
+ }
+
+ status_bar_printf (priv->status_bar, DEFAULT_STATUS_BAR_TIMEOUT,
+ "Setting rate to %3.2lf", new_rate);
+
+ demo_player_set_rate (priv->player, new_rate);
+ return FALSE;
+}
+
+static void
+demo_gui_do_toggle_advanced (GtkAction * action, gpointer data)
+{
+ GValueArray *gvalues = (GValueArray *) data;
+ DemoGui *gui =
+ DEMO_GUI (g_value_get_object (g_value_array_get_nth (gvalues, 0)));
+ GtkWidget *stride_ui =
+ GTK_WIDGET (g_value_get_object (g_value_array_get_nth (gvalues, 1)));
+ GtkWidget *overlap_ui =
+ GTK_WIDGET (g_value_get_object (g_value_array_get_nth (gvalues, 2)));
+ GtkWidget *search_ui =
+ GTK_WIDGET (g_value_get_object (g_value_array_get_nth (gvalues, 3)));
+ DemoGuiPrivate *priv = DEMO_GUI_GET_PRIVATE (gui);
+ gboolean active;
+
+ status_bar_printf (priv->status_bar, 1, "Toggling advanced mode");
+
+ active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
+ gtk_widget_set_sensitive (stride_ui, active);
+ gtk_widget_set_sensitive (overlap_ui, active);
+ gtk_widget_set_sensitive (search_ui, active);
+}
+
+static void
+demo_gui_do_toggle_disabled (GtkAction * action, gpointer data)
+{
+ GValueArray *gvalues = (GValueArray *) data;
+ DemoGui *gui =
+ DEMO_GUI (g_value_get_object (g_value_array_get_nth (gvalues, 0)));
+ GtkAction *advanced_action =
+ GTK_ACTION (g_value_get_object (g_value_array_get_nth (gvalues, 1)));
+ GtkWidget *advanced_ui =
+ GTK_WIDGET (g_value_get_object (g_value_array_get_nth (gvalues, 2)));
+
+ DemoGuiPrivate *priv = DEMO_GUI_GET_PRIVATE (gui);
+ gboolean active;
+
+ status_bar_printf (priv->status_bar, 1, "Toggling disabled");
+
+ active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
+ gtk_action_set_sensitive (GTK_ACTION (advanced_action), !active);
+ gtk_widget_set_sensitive (GTK_WIDGET (advanced_ui), !active);
+ g_object_set (G_OBJECT (priv->player), "disabled", active, NULL);
+}
+
+static void
+demo_gui_do_seek (GtkAction * action, gpointer data)
+{
+ GValueArray *gvalues = (GValueArray *) data;
+ DemoGui *gui =
+ DEMO_GUI (g_value_get_object (g_value_array_get_nth (gvalues, 0)));
+ gint seconds = g_value_get_int (g_value_array_get_nth (gvalues, 1));
+ DemoGuiPrivate *priv = DEMO_GUI_GET_PRIVATE (gui);
+
+ status_bar_printf (priv->status_bar, DEFAULT_STATUS_BAR_TIMEOUT,
+ "Requesting seek by %i seconds", seconds);
+
+ demo_player_seek_by (priv->player, seconds);
+}
+
+static void
+demo_gui_do_play (GtkAction * action, gpointer data)
+{
+ DemoGui *gui = DEMO_GUI (data);
+ DemoGuiPrivate *priv = DEMO_GUI_GET_PRIVATE (gui);
+
+ if (priv->is_playing) {
+ g_signal_emit (gui, demo_gui_signals[SIGNAL_ERROR], 0, "Already playing");
+ return;
+ }
+
+ status_bar_printf (priv->status_bar, DEFAULT_STATUS_BAR_TIMEOUT,
+ "Requesting playback start");
+
+ demo_player_play (priv->player);
+}
+
+static void
+demo_gui_do_pause (GtkAction * action, gpointer data)
+{
+ DemoGui *gui = DEMO_GUI (data);
+ DemoGuiPrivate *priv = DEMO_GUI_GET_PRIVATE (gui);
+
+ if (!priv->is_playing) {
+ g_signal_emit (gui, demo_gui_signals[SIGNAL_ERROR], 0, "Already paused");
+ return;
+ }
+
+ status_bar_printf (priv->status_bar, DEFAULT_STATUS_BAR_TIMEOUT,
+ "Requesting playback pause");
+
+ demo_player_pause (priv->player);
+}
+
+static void
+demo_gui_do_play_pause (GtkAction * action, gpointer data)
+{
+ DemoGui *gui = DEMO_GUI (data);
+ DemoGuiPrivate *priv = DEMO_GUI_GET_PRIVATE (gui);
+
+ status_bar_printf (priv->status_bar, DEFAULT_STATUS_BAR_TIMEOUT,
+ "Reqesting playback toggle");
+
+ if (priv->is_playing)
+ gtk_action_activate (priv->pause_action);
+ else
+ gtk_action_activate (priv->play_action);
+}
+
+static void
+demo_gui_do_open_file (GtkAction * action, gpointer data)
+{
+ DemoGui *gui = DEMO_GUI (data);
+ DemoGuiPrivate *priv = DEMO_GUI_GET_PRIVATE (gui);
+ GtkWidget *dialog = gtk_file_chooser_dialog_new ("Open File",
+ GTK_WINDOW (priv->window),
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ NULL);
+
+ if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
+ char *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+ GError *err = NULL;
+
+ g_list_free (priv->uris);
+ priv->uris = NULL;
+ priv->now_playing = NULL;
+ demo_player_load_uri (priv->player, g_filename_to_uri (filename, NULL,
+ &err));
+ g_free (filename);
+ }
+ gtk_widget_destroy (dialog);
+}
+
+static void
+demo_gui_do_playlist_prev (GtkAction * action, gpointer data)
+{
+ DemoGui *gui = DEMO_GUI (data);
+ DemoGuiPrivate *priv = DEMO_GUI_GET_PRIVATE (gui);
+
+ if (priv->now_playing) {
+ if (priv->now_playing->prev) {
+ status_bar_printf (priv->status_bar, DEFAULT_STATUS_BAR_TIMEOUT,
+ "Playlist previous");
+ priv->now_playing = priv->now_playing->prev;
+ } else {
+ priv->now_playing = NULL;
+ gtk_widget_error_bell (priv->window);
+ status_bar_printf (priv->status_bar, DEFAULT_STATUS_BAR_TIMEOUT,
+ "Beginning of playlist");
+ return;
+ }
+ } else if (priv->uris) {
+ status_bar_printf (priv->status_bar, DEFAULT_STATUS_BAR_TIMEOUT,
+ "Playlist previous: wrap");
+ priv->now_playing = g_list_last (priv->uris);
+ } else {
+ gtk_action_activate (priv->open_file);
+ return;
+ }
+
+ demo_player_load_uri (priv->player, priv->now_playing->data);
+}
+
+static void
+demo_gui_do_playlist_next (GtkAction * action, gpointer data)
+{
+ DemoGui *gui = DEMO_GUI (data);
+ DemoGuiPrivate *priv = DEMO_GUI_GET_PRIVATE (gui);
+
+ if (priv->now_playing) {
+ if (priv->now_playing->next) {
+ status_bar_printf (priv->status_bar, DEFAULT_STATUS_BAR_TIMEOUT,
+ "Playlist next");
+ priv->now_playing = priv->now_playing->next;
+ } else {
+ priv->now_playing = NULL;
+ gtk_widget_error_bell (priv->window);
+ status_bar_printf (priv->status_bar, DEFAULT_STATUS_BAR_TIMEOUT,
+ "End of playlist");
+ return;
+ }
+ } else if (priv->uris) {
+ status_bar_printf (priv->status_bar, DEFAULT_STATUS_BAR_TIMEOUT,
+ "Playlist next: wrap");
+ priv->now_playing = priv->uris;
+ } else {
+ gtk_action_activate (priv->open_file);
+ return;
+ }
+
+ demo_player_load_uri (priv->player, priv->now_playing->data);
+}
+
+static void
+demo_gui_do_about_dialog (GtkAction * action, gpointer data)
+{
+ static gchar *authors[] =
+ { "Rov Juvano <rovjuvano@users.sourceforge.net>", NULL };
+
+ gtk_show_about_dialog (NULL,
+ "program-name", "gst-scaletempo-demo",
+ "version", VERSION,
+ "authors", authors,
+ "license", "This program is free software: you can redistribute it and/or modify\n\
+it under the terms of the GNU General Public License as published by\n\
+the Free Software Foundation, either version 3 of the License, or\n\
+(at your option) any later version.\n\
+\n\
+This program is distributed in the hope that it will be useful,\n\
+but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
+GNU General Public License for more details.\n\
+\n\
+You should have received a copy of the GNU General Public License\n\
+along with this program. If not, see <http://www.gnu.org/licenses/>.", "title", "About gst-scaletempo-demo", NULL);
+}
+
+static void
+demo_gui_do_quit (gpointer source, gpointer data)
+{
+ gtk_main_quit ();
+ g_signal_emit (DEMO_GUI (data), demo_gui_signals[SIGNAL_QUITING], 0, NULL);
+}
+
+static gboolean
+demo_gui_request_set_stride (GtkSpinButton * spinbutton, gpointer data)
+{
+ DemoGui *gui = DEMO_GUI (data);
+ DemoGuiPrivate *priv = DEMO_GUI_GET_PRIVATE (gui);
+ guint new_stride = gtk_spin_button_get_value_as_int (spinbutton);
+
+ status_bar_printf (priv->status_bar, DEFAULT_STATUS_BAR_TIMEOUT,
+ "Reqesting setting stride to %u ms", new_stride);
+ g_object_set (G_OBJECT (priv->player), "stride", new_stride, NULL);
+ return TRUE;
+}
+
+static gboolean
+demo_gui_request_set_overlap (GtkSpinButton * spinbutton, gpointer data)
+{
+ DemoGui *gui = DEMO_GUI (data);
+ DemoGuiPrivate *priv = DEMO_GUI_GET_PRIVATE (gui);
+ gdouble new_overlap = gtk_spin_button_get_value_as_int (spinbutton);
+
+ status_bar_printf (priv->status_bar, DEFAULT_STATUS_BAR_TIMEOUT,
+ "Requesting setting overlap to %2.0lf%%", new_overlap);
+ g_object_set (G_OBJECT (priv->player), "overlap", new_overlap / 100.0, NULL);
+ return TRUE;
+}
+
+static gboolean
+demo_gui_request_set_search (GtkSpinButton * spinbutton, gpointer data)
+{
+ DemoGui *gui = DEMO_GUI (data);
+ DemoGuiPrivate *priv = DEMO_GUI_GET_PRIVATE (gui);
+ guint new_search = gtk_spin_button_get_value_as_int (spinbutton);
+
+ status_bar_printf (priv->status_bar, DEFAULT_STATUS_BAR_TIMEOUT,
+ "Requesting setting search to %u ms", new_search);
+ g_object_set (G_OBJECT (priv->player), "search", new_search, NULL);
+ return TRUE;
+}
+
+
+/* Callbacks from signals */
+static void
+demo_gui_rate_changed (DemoPlayer * player, gdouble new_rate, gpointer data)
+{
+ DemoGui *gui = DEMO_GUI (data);
+ DemoGuiPrivate *priv = DEMO_GUI_GET_PRIVATE (gui);
+ gchar e[6];
+
+ status_bar_printf (priv->status_bar, DEFAULT_STATUS_BAR_TIMEOUT,
+ "Rate changed to %3.2lf", new_rate);
+
+ g_snprintf (e, 6, "%3.2f", new_rate);
+ gtk_entry_set_text (GTK_ENTRY (priv->rate_entry), e);
+}
+
+static void
+demo_gui_playing_started (DemoPlayer * player, gpointer data)
+{
+ DemoGui *gui = DEMO_GUI (data);
+ DemoGuiPrivate *priv = DEMO_GUI_GET_PRIVATE (gui);
+
+ priv->is_playing = TRUE;
+ status_bar_printf (priv->status_bar, DEFAULT_STATUS_BAR_TIMEOUT,
+ "Playing started");
+
+ gtk_action_set_sensitive (priv->play_action, FALSE);
+ gtk_action_set_sensitive (priv->pause_action, TRUE);
+ gtk_action_set_visible (priv->play_action, FALSE);
+ gtk_action_set_visible (priv->pause_action, TRUE);
+
+ if (priv->position_updater_id) {
+ g_source_remove (priv->position_updater_id);
+ priv->position_updater_id = 0;
+ }
+ update_position (gui);
+ priv->position_updater_id = g_timeout_add (1000, update_position, gui);
+}
+
+static void
+demo_gui_playing_paused (DemoPlayer * player, gpointer data)
+{
+ DemoGui *gui = DEMO_GUI (data);
+ DemoGuiPrivate *priv = DEMO_GUI_GET_PRIVATE (gui);
+
+ gtk_action_set_sensitive (priv->play_action, TRUE);
+ gtk_action_set_sensitive (priv->pause_action, FALSE);
+ gtk_action_set_visible (priv->play_action, TRUE);
+ gtk_action_set_visible (priv->pause_action, FALSE);
+
+ priv->is_playing = FALSE;
+
+ if (priv->position_updater_id)
+ g_source_remove (priv->position_updater_id);
+ priv->position_updater_id = 0;
+ update_position (gui);
+
+ status_bar_printf (priv->status_bar, DEFAULT_STATUS_BAR_TIMEOUT,
+ "Playing paused");
+}
+
+static void
+demo_gui_playing_ended (DemoPlayer * player, gpointer data)
+{
+ DemoGui *gui = DEMO_GUI (data);
+ DemoGuiPrivate *priv = DEMO_GUI_GET_PRIVATE (gui);
+
+ status_bar_printf (priv->status_bar, DEFAULT_STATUS_BAR_TIMEOUT,
+ "Playing ended");
+ gtk_action_activate (priv->playlist_next);
+}
+
+static void
+demo_gui_player_errored (DemoPlayer * player, const gchar * msg, gpointer data)
+{
+ DemoGui *gui = DEMO_GUI (data);
+ DemoGuiPrivate *priv = DEMO_GUI_GET_PRIVATE (gui);
+
+ status_bar_printf (priv->status_bar, 5, msg);
+}
+
+static void
+demo_gui_stride_changed (DemoPlayer * player, GParamSpec * pspec, gpointer data)
+{
+ GValueArray *gvalues = (GValueArray *) data;
+ DemoGui *gui =
+ DEMO_GUI (g_value_get_object (g_value_array_get_nth (gvalues, 0)));
+ GtkEntry *entry =
+ GTK_ENTRY (g_value_get_object (g_value_array_get_nth (gvalues, 1)));
+ DemoGuiPrivate *priv = DEMO_GUI_GET_PRIVATE (gui);
+ guint new_stride;
+ gchar e[6];
+
+ g_object_get (G_OBJECT (player), "stride", &new_stride, NULL);
+ status_bar_printf (priv->status_bar, DEFAULT_STATUS_BAR_TIMEOUT,
+ "Stride changed to %u", new_stride);
+
+ snprintf (e, 6, "%u", new_stride);
+ gtk_entry_set_text (entry, e);
+}
+
+static void
+demo_gui_overlap_changed (DemoPlayer * player,
+ GParamSpec * pspec, gpointer data)
+{
+ GValueArray *gvalues = (GValueArray *) data;
+ DemoGui *gui =
+ DEMO_GUI (g_value_get_object (g_value_array_get_nth (gvalues, 0)));
+ GtkEntry *entry =
+ GTK_ENTRY (g_value_get_object (g_value_array_get_nth (gvalues, 1)));
+ DemoGuiPrivate *priv = DEMO_GUI_GET_PRIVATE (gui);
+ gdouble new_overlap;
+ gchar e[6];
+
+ g_object_get (G_OBJECT (player), "overlap", &new_overlap, NULL);
+ new_overlap *= 100;
+ status_bar_printf (priv->status_bar, DEFAULT_STATUS_BAR_TIMEOUT,
+ "Overlap changed to %2.0lf%%", new_overlap);
+
+ snprintf (e, 6, "%2.0f", new_overlap);
+ gtk_entry_set_text (entry, e);
+}
+
+static void
+demo_gui_search_changed (DemoPlayer * player, GParamSpec * pspec, gpointer data)
+{
+ GValueArray *gvalues = (GValueArray *) data;
+ DemoGui *gui =
+ DEMO_GUI (g_value_get_object (g_value_array_get_nth (gvalues, 0)));
+ GtkEntry *entry =
+ GTK_ENTRY (g_value_get_object (g_value_array_get_nth (gvalues, 1)));
+ DemoGuiPrivate *priv = DEMO_GUI_GET_PRIVATE (gui);
+ guint new_search;
+ gchar e[6];
+
+ g_object_get (G_OBJECT (player), "search", &new_search, NULL);
+ status_bar_printf (priv->status_bar, DEFAULT_STATUS_BAR_TIMEOUT,
+ "Search changed to %u", new_search);
+
+ snprintf (e, 6, "%u", new_search);
+ gtk_entry_set_text (entry, e);
+}
+
+
+/* method implementations */
+static void
+demo_gui_set_player_func (DemoGui * gui, DemoPlayer * player)
+{
+ DemoGuiPrivate *priv = DEMO_GUI_GET_PRIVATE (gui);
+
+ if (priv->player) {
+ g_signal_handlers_disconnect_by_func (G_OBJECT (priv->player),
+ G_CALLBACK (demo_gui_rate_changed), gui);
+ g_signal_handlers_disconnect_by_func (G_OBJECT (priv->player),
+ G_CALLBACK (demo_gui_playing_started), gui);
+ g_signal_handlers_disconnect_by_func (G_OBJECT (priv->player),
+ G_CALLBACK (demo_gui_playing_paused), gui);
+ g_signal_handlers_disconnect_by_func (G_OBJECT (priv->player),
+ G_CALLBACK (demo_gui_playing_ended), gui);
+ g_signal_handlers_disconnect_by_func (G_OBJECT (priv->player),
+ G_CALLBACK (demo_gui_player_errored), gui);
+ g_object_unref (priv->player);
+ }
+ g_object_ref (player);
+ priv->player = player;
+ g_signal_connect (G_OBJECT (priv->player), "error",
+ G_CALLBACK (demo_gui_player_errored), gui);
+ g_signal_connect (G_OBJECT (priv->player), "rate-changed",
+ G_CALLBACK (demo_gui_rate_changed), gui);
+ g_signal_connect (G_OBJECT (priv->player), "playing-started",
+ G_CALLBACK (demo_gui_playing_started), gui);
+ g_signal_connect (G_OBJECT (priv->player), "playing-paused",
+ G_CALLBACK (demo_gui_playing_paused), gui);
+ g_signal_connect (G_OBJECT (priv->player), "playing-ended",
+ G_CALLBACK (demo_gui_playing_ended), gui);
+ priv->is_playing = FALSE;
+}
+
+static void
+demo_gui_set_playlist_func (DemoGui * gui, GList * uris)
+{
+ DemoGuiPrivate *priv = DEMO_GUI_GET_PRIVATE (gui);
+ priv->uris = uris;
+}
+
+typedef struct _ActionEntry
+{
+ GtkAction *action;
+ GtkWidget *button;
+ const gchar *accel;
+ const gchar *name;
+ const gchar *label;
+ const gchar *tooltip;
+ const gchar *stock_id;
+ GtkAccelGroup *accel_group;
+ GtkActionGroup *action_group;
+ GCallback callback;
+ gpointer data;
+} ActionEntry;
+
+static GValueArray *
+build_gvalue_array (guint n_values, ...)
+{
+ va_list args;
+ GValueArray *gva;
+ int i;
+
+ va_start (args, n_values);
+ gva = g_value_array_new (n_values);
+
+ for (i = 0; i < n_values; i++) {
+ GType type = va_arg (args, GType);
+ GValue *gval = g_new0 (GValue, 1);
+ if (type == G_TYPE_INT) {
+ gint value = va_arg (args, gint);
+ g_value_set_int (g_value_init (gval, G_TYPE_INT), value);
+ } else if (type == G_TYPE_UINT) {
+ guint value = va_arg (args, guint);
+ g_value_set_uint (g_value_init (gval, G_TYPE_UINT), value);
+ } else if (type == G_TYPE_DOUBLE) {
+ double value = va_arg (args, double);
+ g_value_set_double (g_value_init (gval, G_TYPE_DOUBLE), value);
+ } else if (type == G_TYPE_OBJECT) {
+ GObject *value = va_arg (args, GObject *);
+ g_value_set_object (g_value_init (gval, G_TYPE_OBJECT), value);
+ } else {
+ g_critical ("build_gvalue_array cannot handle type (%s)",
+ g_type_name (type));
+ va_end (args);
+ return NULL;
+ }
+ g_value_array_append (gva, gval);
+ }
+ va_end (args);
+ return gva;
+}
+
+static void
+create_action (ActionEntry * p)
+{
+ p->action = gtk_action_new (p->name, p->label, p->tooltip, p->stock_id);
+
+ gtk_action_group_add_action_with_accel (p->action_group, p->action, p->accel);
+ gtk_action_set_accel_group (p->action, p->accel_group);
+ gtk_action_connect_accelerator (p->action);
+
+ p->button = gtk_button_new ();
+ gtk_action_connect_proxy (p->action, p->button);
+ gtk_button_set_image (GTK_BUTTON (p->button),
+ gtk_action_create_icon (p->action, GTK_ICON_SIZE_BUTTON));
+ g_signal_connect (G_OBJECT (p->action), "activate", p->callback, p->data);
+}
+
+static void
+demo_gui_show_func (DemoGui * gui)
+{
+ DemoGuiPrivate *priv = DEMO_GUI_GET_PRIVATE (gui);
+ GtkWidget *window;
+ GtkAccelGroup *accel_group;
+ GtkActionGroup *action_group;
+ GtkAction *toggle_advanced, *toggle_disabled;
+ ActionEntry *slower_lg, *slower_sm, *faster_sm, *faster_lg, *normal,
+ *rewind_lg, *rewind_sm, *forward_sm, *forward_lg, *pause, *play,
+ *play_pause, *open_file, *playlist_prev, *playlist_next, *quit, *about;
+ GtkRequisition pause_size;
+ GtkWidget *rate_entry, *rate_label, *toolbox, *stride_ui, *overlap_ui,
+ *search_ui, *propbox, *adv_check, *disabled_check, *media_controls,
+ *amount_played, *amount_to_play, *seek_range, *seek_bar, *status_bar,
+ *file_menu, *file_menu_item, *media_menu_item, *demo_menu,
+ *demo_menu_item, *menu_bar, *toplevel_box, *media_menu;
+ GError *error = NULL;
+
+ gtk_init (NULL, NULL);
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (demo_gui_do_quit),
+ gui);
+
+ accel_group = gtk_accel_group_new ();
+ gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
+ action_group = gtk_action_group_new ("toolbar");
+
+ slower_lg = &(ActionEntry) {
+ NULL, NULL,
+ "braceleft", "slower-large",
+ "2x Slower", "half playback rate",
+ GTK_STOCK_GO_DOWN, accel_group, action_group,
+ G_CALLBACK (demo_gui_do_change_rate),
+ build_gvalue_array (2, G_TYPE_OBJECT, gui, G_TYPE_DOUBLE, 0.5)
+ };
+ create_action (slower_lg);
+
+ slower_sm = &(ActionEntry) {
+ NULL, NULL,
+ "bracketleft", "slower-small",
+ "_Slower", "decrease playback rate",
+ GTK_STOCK_GO_DOWN, accel_group, action_group,
+ G_CALLBACK (demo_gui_do_change_rate),
+ build_gvalue_array (2, G_TYPE_OBJECT, gui, G_TYPE_DOUBLE, pow (2,
+ -1.0 / 12))
+ };
+ create_action (slower_sm);
+
+ faster_sm = &(ActionEntry) {
+ NULL, NULL,
+ "bracketright", "faster-small",
+ "_Faster", "increase playback rate",
+ GTK_STOCK_GO_UP, accel_group, action_group,
+ G_CALLBACK (demo_gui_do_change_rate),
+ build_gvalue_array (2, G_TYPE_OBJECT, gui, G_TYPE_DOUBLE, pow (2,
+ 1.0 / 12))
+ };
+ create_action (faster_sm);
+
+ faster_lg = &(ActionEntry) {
+ NULL, NULL,
+ "braceright", "faster-large",
+ "2X Faster", "double playback rate",
+ GTK_STOCK_GO_UP, accel_group, action_group,
+ G_CALLBACK (demo_gui_do_change_rate),
+ build_gvalue_array (2, G_TYPE_OBJECT, gui, G_TYPE_DOUBLE, 2.0)
+ };
+ create_action (faster_lg);
+
+ normal = &(ActionEntry) {
+ NULL, NULL,
+ "backslash", "normal",
+ "_Normal", "playback normal rate",
+ GTK_STOCK_CLEAR, accel_group, action_group,
+ G_CALLBACK (demo_gui_do_set_rate),
+ build_gvalue_array (2, G_TYPE_OBJECT, gui, G_TYPE_DOUBLE, 1.0)
+ };
+ create_action (normal);
+
+ rewind_lg = &(ActionEntry) {
+ NULL, NULL,
+ "<ctrl><shift>Left", "seek-rewind-large",
+ "Rewind (large)", "seek -30 seconds",
+ GTK_STOCK_MEDIA_REWIND, accel_group, action_group,
+ G_CALLBACK (demo_gui_do_seek),
+ build_gvalue_array (2, G_TYPE_OBJECT, gui, G_TYPE_INT, -30)
+ };
+ create_action (rewind_lg);
+
+ rewind_sm = &(ActionEntry) {
+ NULL, NULL,
+ "<ctrl>Left", "seek-rewind-small",
+ "Rewind", "seek -15 seconds",
+ GTK_STOCK_MEDIA_REWIND, accel_group, action_group,
+ G_CALLBACK (demo_gui_do_seek),
+ build_gvalue_array (2, G_TYPE_OBJECT, gui, G_TYPE_INT, -5)
+ };
+ create_action (rewind_sm);
+
+ forward_sm = &(ActionEntry) {
+ NULL, NULL,
+ "<ctrl>Right", "seek-forward-small",
+ "Forward", "seek +5 seconds",
+ GTK_STOCK_MEDIA_FORWARD, accel_group, action_group,
+ G_CALLBACK (demo_gui_do_seek),
+ build_gvalue_array (2, G_TYPE_OBJECT, gui, G_TYPE_INT, 5)
+ };
+ create_action (forward_sm);
+
+ forward_lg = &(ActionEntry) {
+ NULL, NULL,
+ "<ctrl><shift>Right", "seek-forward-large",
+ "Forward (large)", "seek +30 seconds",
+ GTK_STOCK_MEDIA_FORWARD, accel_group, action_group,
+ G_CALLBACK (demo_gui_do_seek),
+ build_gvalue_array (2, G_TYPE_OBJECT, gui, G_TYPE_INT, 30)
+ };
+ create_action (forward_lg);
+
+ pause = &(ActionEntry) {
+ NULL, NULL,
+ "p", "pause",
+ "Pause", "Pause playback",
+ GTK_STOCK_MEDIA_PAUSE, accel_group, action_group,
+ G_CALLBACK (demo_gui_do_pause), gui};
+ create_action (pause);
+
+ play = &(ActionEntry) {
+ NULL, NULL,
+ "<ctrl>p", "play",
+ "Play", "Start Playback",
+ GTK_STOCK_MEDIA_PLAY, accel_group, action_group,
+ G_CALLBACK (demo_gui_do_play), gui};
+ create_action (play);
+ gtk_widget_size_request (pause->button, &pause_size);
+ gtk_widget_set_size_request (play->button, pause_size.width, -1);
+
+ play_pause = &(ActionEntry) {
+ NULL, NULL,
+ "space", "play-pause",
+ "Play/Pause", "Toggle playback",
+ NULL, accel_group, action_group,
+ G_CALLBACK (demo_gui_do_play_pause), gui};
+ create_action (play_pause);
+
+ open_file = &(ActionEntry) {
+ NULL, NULL,
+ "<ctrl>o", "open-file",
+ "Open File", "Open file for playing",
+ GTK_STOCK_OPEN, accel_group, action_group,
+ G_CALLBACK (demo_gui_do_open_file), gui};
+ create_action (open_file);
+
+ playlist_prev = &(ActionEntry) {
+ NULL, NULL,
+ "less", "playlist-previous",
+ "Previous", "Previous in playlist",
+ GTK_STOCK_MEDIA_PREVIOUS, accel_group, action_group,
+ G_CALLBACK (demo_gui_do_playlist_prev), gui};
+ create_action (playlist_prev);
+
+ playlist_next = &(ActionEntry) {
+ NULL, NULL,
+ "greater", "playlist-next",
+ "Next", "Next in playlist",
+ GTK_STOCK_MEDIA_NEXT, accel_group, action_group,
+ G_CALLBACK (demo_gui_do_playlist_next), gui};
+ create_action (playlist_next);
+
+ quit = &(ActionEntry) {
+ NULL, NULL,
+ "q", "quit",
+ "Quit", "Quit demo",
+ GTK_STOCK_QUIT, accel_group, action_group,
+ G_CALLBACK (demo_gui_do_quit), gui};
+ create_action (quit);
+
+ about = &(ActionEntry) {
+ NULL, NULL,
+ "<ctrl>h", "about",
+ "About", "About gst-scaletemo-demo",
+ GTK_STOCK_ABOUT, accel_group, action_group,
+ G_CALLBACK (demo_gui_do_about_dialog), gui};
+ create_action (about);
+
+ rate_entry = gtk_entry_new ();
+ rate_label = gtk_label_new ("Rate:");
+ gtk_entry_set_max_length (GTK_ENTRY (rate_entry), 5);
+ gtk_entry_set_text (GTK_ENTRY (rate_entry), "1.0");
+ gtk_entry_set_width_chars (GTK_ENTRY (rate_entry), 5);
+ g_signal_connect (G_OBJECT (rate_entry), "activate",
+ G_CALLBACK (demo_gui_do_rate_entered), gui);
+
+ toolbox = gtk_hbox_new (FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (toolbox), slower_sm->button, FALSE, FALSE, 2);
+ gtk_box_pack_start (GTK_BOX (toolbox), rate_label, FALSE, FALSE, 2);
+ gtk_box_pack_start (GTK_BOX (toolbox), rate_entry, FALSE, FALSE, 2);
+ gtk_box_pack_start (GTK_BOX (toolbox), faster_sm->button, FALSE, FALSE, 2);
+ gtk_box_pack_start (GTK_BOX (toolbox), normal->button, FALSE, FALSE, 2);
+
+
+ stride_ui =
+ gtk_spin_button_new (GTK_ADJUSTMENT (gtk_adjustment_new (60, 1, 1000, 1,
+ 10, 0)), 0, 0);
+ overlap_ui =
+ gtk_spin_button_new (GTK_ADJUSTMENT (gtk_adjustment_new (20, 0, 100, 5,
+ 10, .00001)), 0, 0);
+ search_ui =
+ gtk_spin_button_new (GTK_ADJUSTMENT (gtk_adjustment_new (14, 0, 1000, 1,
+ 10, 0)), 0, 0);
+ gtk_widget_set_sensitive (stride_ui, FALSE);
+ gtk_widget_set_sensitive (overlap_ui, FALSE);
+ gtk_widget_set_sensitive (search_ui, FALSE);
+ g_signal_connect (G_OBJECT (stride_ui), "output",
+ G_CALLBACK (demo_gui_request_set_stride), gui);
+ g_signal_connect (G_OBJECT (overlap_ui), "output",
+ G_CALLBACK (demo_gui_request_set_overlap), gui);
+ g_signal_connect (G_OBJECT (search_ui), "output",
+ G_CALLBACK (demo_gui_request_set_search), gui);
+ g_signal_connect (G_OBJECT (priv->player), "notify::stride",
+ G_CALLBACK (demo_gui_stride_changed), build_gvalue_array (2,
+ G_TYPE_OBJECT, gui, G_TYPE_OBJECT, stride_ui));
+ g_signal_connect (G_OBJECT (priv->player), "notify::overlap",
+ G_CALLBACK (demo_gui_overlap_changed), build_gvalue_array (2,
+ G_TYPE_OBJECT, gui, G_TYPE_OBJECT, overlap_ui));
+ g_signal_connect (G_OBJECT (priv->player), "notify::search",
+ G_CALLBACK (demo_gui_search_changed), build_gvalue_array (2,
+ G_TYPE_OBJECT, gui, G_TYPE_OBJECT, search_ui));
+ propbox = gtk_hbox_new (FALSE, 0);
+ adv_check = gtk_check_button_new ();
+ gtk_box_pack_start (GTK_BOX (propbox), gtk_label_new ("stride:"), FALSE,
+ FALSE, 2);
+ gtk_box_pack_start (GTK_BOX (propbox), stride_ui, FALSE, FALSE, 2);
+ gtk_box_pack_start (GTK_BOX (propbox), gtk_label_new ("overlap:"), FALSE,
+ FALSE, 2);
+ gtk_box_pack_start (GTK_BOX (propbox), overlap_ui, FALSE, FALSE, 2);
+ gtk_box_pack_start (GTK_BOX (propbox), gtk_label_new ("search:"), FALSE,
+ FALSE, 2);
+ gtk_box_pack_start (GTK_BOX (propbox), search_ui, FALSE, FALSE, 2);
+ gtk_box_pack_start (GTK_BOX (propbox), adv_check, FALSE, FALSE, 2);
+
+ toggle_advanced =
+ GTK_ACTION (gtk_toggle_action_new ("advanced", "Enable Parameters",
+ "Toggle advanced controls", 0));
+ gtk_action_group_add_action_with_accel (action_group, toggle_advanced,
+ "<ctrl>a");
+ gtk_action_set_accel_group (toggle_advanced, accel_group);
+ gtk_action_connect_accelerator (toggle_advanced);
+ gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (toggle_advanced), FALSE);
+ gtk_action_connect_proxy (toggle_advanced, adv_check);
+ g_signal_connect (G_OBJECT (toggle_advanced), "activate",
+ G_CALLBACK (demo_gui_do_toggle_advanced), build_gvalue_array (4,
+ G_TYPE_OBJECT, gui, G_TYPE_OBJECT, stride_ui, G_TYPE_OBJECT,
+ overlap_ui, G_TYPE_OBJECT, search_ui));
+
+ toggle_disabled =
+ GTK_ACTION (gtk_toggle_action_new ("disabled", "Disable Scaletempo",
+ "Toggle disabling scaletempo", 0));
+ gtk_action_group_add_action_with_accel (action_group, toggle_disabled,
+ "<ctrl>d");
+ gtk_action_set_accel_group (toggle_disabled, accel_group);
+ gtk_action_connect_accelerator (toggle_disabled);
+ gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (toggle_disabled), FALSE);
+ disabled_check = gtk_check_button_new ();
+ gtk_action_connect_proxy (toggle_disabled, disabled_check);
+ g_signal_connect (G_OBJECT (toggle_disabled), "activate",
+ G_CALLBACK (demo_gui_do_toggle_disabled), build_gvalue_array (3,
+ G_TYPE_OBJECT, gui, G_TYPE_OBJECT, toggle_advanced, G_TYPE_OBJECT,
+ propbox));
+ gtk_box_pack_start (GTK_BOX (toolbox), disabled_check, FALSE, FALSE, 2);
+
+
+ media_controls = gtk_hbox_new (FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (media_controls), playlist_prev->button, FALSE,
+ FALSE, 2);
+ gtk_box_pack_start (GTK_BOX (media_controls), rewind_sm->button, FALSE, FALSE,
+ 2);
+ gtk_box_pack_start (GTK_BOX (media_controls), play->button, FALSE, FALSE, 2);
+ gtk_box_pack_start (GTK_BOX (media_controls), pause->button, FALSE, FALSE, 2);
+ gtk_box_pack_start (GTK_BOX (media_controls), forward_sm->button, FALSE,
+ FALSE, 2);
+ gtk_box_pack_start (GTK_BOX (media_controls), playlist_next->button, FALSE,
+ FALSE, 2);
+
+ amount_played = gtk_label_new ("?:??:??");
+ amount_to_play = gtk_label_new ("-?:??:??");
+ gtk_label_set_width_chars (GTK_LABEL (amount_played), 8);
+ gtk_label_set_width_chars (GTK_LABEL (amount_to_play), 8);
+ gtk_misc_set_alignment (GTK_MISC (amount_played), 1, 1);
+ gtk_misc_set_alignment (GTK_MISC (amount_to_play), 0, 1);
+ seek_range =
+ gtk_hscale_new (GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 5.0,
+ 30.0, 0.00)));
+ gtk_range_set_update_policy (GTK_RANGE (seek_range),
+ GTK_UPDATE_DISCONTINUOUS);
+ seek_bar = gtk_hbox_new (FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (seek_bar), amount_played, FALSE, FALSE, 2);
+ gtk_box_pack_start (GTK_BOX (seek_bar), seek_range, TRUE, TRUE, 2);
+ gtk_box_pack_start (GTK_BOX (seek_bar), amount_to_play, FALSE, FALSE, 2);
+ g_signal_connect (G_OBJECT (seek_range), "format-value",
+ G_CALLBACK (demo_gui_seek_bar_format), gui);
+ g_signal_connect (G_OBJECT (seek_range), "change-value",
+ G_CALLBACK (demo_gui_seek_bar_change), gui);
+
+ status_bar = gtk_statusbar_new ();
+
+ /* Menubar */
+ file_menu = gtk_menu_new ();
+ gtk_menu_set_accel_group (GTK_MENU (file_menu), accel_group);
+ gtk_menu_shell_append (GTK_MENU_SHELL (file_menu),
+ gtk_action_create_menu_item (open_file->action));
+ gtk_menu_shell_append (GTK_MENU_SHELL (file_menu),
+ gtk_action_create_menu_item (about->action));
+ gtk_menu_shell_append (GTK_MENU_SHELL (file_menu),
+ gtk_action_create_menu_item (quit->action));
+ file_menu_item = gtk_menu_item_new_with_mnemonic ("_File");
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (file_menu_item), file_menu);
+
+ media_menu = gtk_menu_new ();
+ gtk_menu_set_accel_group (GTK_MENU (media_menu), accel_group);
+ gtk_menu_shell_append (GTK_MENU_SHELL (media_menu),
+ gtk_action_create_menu_item (rewind_lg->action));
+ gtk_menu_shell_append (GTK_MENU_SHELL (media_menu),
+ gtk_action_create_menu_item (rewind_sm->action));
+ gtk_menu_shell_append (GTK_MENU_SHELL (media_menu),
+ gtk_action_create_menu_item (forward_sm->action));
+ gtk_menu_shell_append (GTK_MENU_SHELL (media_menu),
+ gtk_action_create_menu_item (forward_lg->action));
+ gtk_menu_shell_append (GTK_MENU_SHELL (media_menu),
+ gtk_action_create_menu_item (play->action));
+ gtk_menu_shell_append (GTK_MENU_SHELL (media_menu),
+ gtk_action_create_menu_item (pause->action));
+ gtk_menu_shell_append (GTK_MENU_SHELL (media_menu),
+ gtk_action_create_menu_item (play_pause->action));
+ gtk_menu_shell_append (GTK_MENU_SHELL (media_menu),
+ gtk_action_create_menu_item (playlist_prev->action));
+ gtk_menu_shell_append (GTK_MENU_SHELL (media_menu),
+ gtk_action_create_menu_item (playlist_next->action));
+ media_menu_item = gtk_menu_item_new_with_mnemonic ("_Media");
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (media_menu_item), media_menu);
+
+ demo_menu = gtk_menu_new ();
+ gtk_menu_set_accel_group (GTK_MENU (demo_menu), accel_group);
+ gtk_menu_shell_append (GTK_MENU_SHELL (demo_menu),
+ gtk_action_create_menu_item (faster_lg->action));
+ gtk_menu_shell_append (GTK_MENU_SHELL (demo_menu),
+ gtk_action_create_menu_item (faster_sm->action));
+ gtk_menu_shell_append (GTK_MENU_SHELL (demo_menu),
+ gtk_action_create_menu_item (slower_sm->action));
+ gtk_menu_shell_append (GTK_MENU_SHELL (demo_menu),
+ gtk_action_create_menu_item (slower_lg->action));
+ gtk_menu_shell_append (GTK_MENU_SHELL (demo_menu),
+ gtk_action_create_menu_item (normal->action));
+ gtk_menu_shell_append (GTK_MENU_SHELL (demo_menu),
+ gtk_action_create_menu_item (toggle_disabled));
+ gtk_menu_shell_append (GTK_MENU_SHELL (demo_menu),
+ gtk_action_create_menu_item (toggle_advanced));
+ demo_menu_item = gtk_menu_item_new_with_mnemonic ("_Scaletempo");
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (demo_menu_item), demo_menu);
+
+ menu_bar = gtk_menu_bar_new ();
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu_bar), file_menu_item);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu_bar), media_menu_item);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu_bar), demo_menu_item);
+
+ /* Toplevel Window */
+ gtk_window_set_title (GTK_WINDOW (window), "Scaletempo Demo");
+ toplevel_box = gtk_vbox_new (FALSE, 0);
+ gtk_container_set_border_width (GTK_CONTAINER (toplevel_box), 3);
+ gtk_container_add (GTK_CONTAINER (window), toplevel_box);
+ gtk_box_pack_start (GTK_BOX (toplevel_box), menu_bar, FALSE, FALSE, 2);
+ gtk_box_pack_start (GTK_BOX (toplevel_box), media_controls, FALSE, FALSE, 2);
+ gtk_box_pack_start (GTK_BOX (toplevel_box), toolbox, FALSE, FALSE, 2);
+ gtk_box_pack_start (GTK_BOX (toplevel_box), propbox, FALSE, FALSE, 2);
+ gtk_box_pack_start (GTK_BOX (toplevel_box), seek_bar, FALSE, FALSE, 2);
+ gtk_box_pack_start (GTK_BOX (toplevel_box), status_bar, FALSE, FALSE, 2);
+
+ priv->window = window;
+ priv->rate_entry = GTK_ENTRY (rate_entry);
+ priv->status_bar = GTK_STATUSBAR (status_bar);
+ priv->seek_range = GTK_RANGE (seek_range);
+ priv->amount_played = GTK_LABEL (amount_played);
+ priv->amount_to_play = GTK_LABEL (amount_to_play);
+ priv->play_action = GTK_ACTION (play->action);
+ priv->pause_action = GTK_ACTION (pause->action);
+ priv->open_file = GTK_ACTION (open_file->action);
+ priv->playlist_next = GTK_ACTION (playlist_next->action);
+
+ gtk_action_set_sensitive (priv->pause_action, FALSE);
+ gtk_action_set_visible (priv->pause_action, FALSE);
+
+ gtk_widget_show_all (window);
+ gtk_widget_grab_focus (seek_range);
+ gtk_action_activate (priv->playlist_next);
+ status_bar_printf (GTK_STATUSBAR (status_bar), 5,
+ "Welcome to the Scaletempo demo.");
+
+ if (!g_thread_create ((GThreadFunc) gtk_main, NULL, FALSE, &error)) {
+ g_signal_emit (gui, demo_gui_signals[SIGNAL_ERROR], 0, error->message);
+ }
+}
+
+
+/* Method wrappers */
+void
+demo_gui_set_player (DemoGui * gui, DemoPlayer * player)
+{
+ g_return_if_fail (DEMO_IS_GUI (gui));
+ g_return_if_fail (DEMO_IS_PLAYER (player));
+
+ DEMO_GUI_GET_CLASS (gui)->set_player (gui, player);
+}
+
+void
+demo_gui_set_playlist (DemoGui * gui, GList * uris)
+{
+ g_return_if_fail (DEMO_IS_GUI (gui));
+
+ DEMO_GUI_GET_CLASS (gui)->set_playlist (gui, uris);
+}
+
+void
+demo_gui_show (DemoGui * gui)
+{
+ g_return_if_fail (DEMO_IS_GUI (gui));
+
+ DEMO_GUI_GET_CLASS (gui)->show (gui);
+}
+
+
+
+/* GObject overrides */
+static void
+demo_gui_get_property (GObject * object,
+ guint property_id, GValue * value, GParamSpec * pspec)
+{
+ //DemoGui *gui = DEMO_GUI (object);
+ switch (property_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+demo_gui_set_property (GObject * object,
+ guint property_id, const GValue * value, GParamSpec * pspec)
+{
+ //DemoGui *gui = DEMO_GUI (object);
+ switch (property_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+
+/* GTypeInfo functions */
+static void
+demo_gui_init (GTypeInstance * instance, gpointer klass)
+{
+ DemoGui *gui = (DemoGui *) instance;
+
+ DemoGuiPrivate *priv = DEMO_GUI_GET_PRIVATE (gui);
+ priv->player = NULL;
+ priv->uris = NULL;
+ priv->now_playing = NULL;
+ priv->is_playing = FALSE;
+ priv->window = NULL;
+ priv->rate_entry = NULL;
+ priv->position_updater_id = 0;
+ priv->seek_range = NULL;
+ priv->amount_played = NULL;
+ priv->amount_to_play = NULL;
+}
+
+static void
+demo_gui_class_init (gpointer klass, gpointer class_data)
+{
+ DemoGuiClass *gui_class = (DemoGuiClass *) klass;
+ GObjectClass *as_object_class = G_OBJECT_CLASS (klass);
+ GType type;
+
+ g_type_class_add_private (klass, sizeof (DemoGuiPrivate));
+
+ /* DemiPlayer */
+ gui_class->set_player = demo_gui_set_player_func;
+ gui_class->set_playlist = demo_gui_set_playlist_func;
+ gui_class->show = demo_gui_show_func;
+
+ /* GObject */
+ as_object_class->get_property = demo_gui_get_property;
+ as_object_class->set_property = demo_gui_set_property;
+
+ /* Properties */
+
+ /* Signals */
+ type = G_TYPE_FROM_CLASS (klass);
+ demo_gui_signals[SIGNAL_ERROR] = g_signal_new ("error", type,
+ G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
+ g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING);
+
+ demo_gui_signals[SIGNAL_QUITING] = g_signal_new ("quiting", type,
+ G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
+ g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, NULL);
+}
+
+GType
+demo_gui_get_type (void)
+{
+ static GType type = 0;
+ if (G_UNLIKELY (type == 0)) {
+ static const GTypeInfo info = {
+ sizeof /* Class */ (DemoGuiClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) demo_gui_class_init,
+ (GClassFinalizeFunc) NULL,
+ (gconstpointer) NULL, /* class_data */
+ sizeof /* Instance */ (DemoGui),
+ /* n_preallocs */ 0,
+ (GInstanceInitFunc) demo_gui_init,
+ (const GTypeValueTable *) NULL
+ };
+ type = g_type_register_static (G_TYPE_OBJECT, "DemoGui", &info, 0);
+ }
+ return type;
+}
diff --git a/tests/examples/scaletempo/demo-gui.h b/tests/examples/scaletempo/demo-gui.h
new file mode 100644
index 00000000..b447d0d8
--- /dev/null
+++ b/tests/examples/scaletempo/demo-gui.h
@@ -0,0 +1,60 @@
+/* demo-gui.h
+ * Copyright (C) 2008 Rov Juvano <rovjuvano@users.sourceforge.net>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __DEMO_GUI_H_INCLUDED_
+#define __DEMO_GUI_H_INCLUDED_
+
+#include <glib-object.h>
+#include "demo-player.h"
+
+G_BEGIN_DECLS
+
+#define DEMO_TYPE_GUI (demo_gui_get_type())
+#define DEMO_GUI(o) (G_TYPE_CHECK_INSTANCE_CAST((o), DEMO_TYPE_GUI, DemoGui))
+#define DEMO_IS_GUI(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), DEMO_TYPE_GUI))
+#define DEMO_GUI_TYPE(o) (G_TYPE_FROM_INSTANCE (o))
+#define DEMO_GUI_TYPE_NAME(o) (g_type_name (DEMO_GUI_GUI (o)))
+
+#define DEMO_GUI_CLASS(c) (G_TYPE_CHECK_CLASS_CAST((c), DEMO_TYPE_GUI, DemoGuiClass))
+#define DEMO_IS_GUI_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE((c), DEMO_TYPE_GUI))
+#define DEMO_GUI_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), DEMO_TYPE_GUI, DemoGuiClass))
+
+typedef struct _DemoGui DemoGui;
+typedef struct _DemoGuiClass DemoGuiClass;
+
+struct _DemoGui
+{
+ GObject parent;
+};
+
+struct _DemoGuiClass
+{
+ GObjectClass parent;
+ void (*set_player) (DemoGui *gui, DemoPlayer *player);
+ void (*set_playlist) (DemoGui *gui, GList *uris);
+ void (*show) (DemoGui *gui);
+};
+
+GType demo_gui_get_type (void);
+
+void demo_gui_set_player (DemoGui *gui, DemoPlayer *player);
+void demo_gui_set_playlist (DemoGui *gui, GList *uris);
+void demo_gui_show (DemoGui *gui);
+
+G_END_DECLS
+
+#endif /* __DEMO_GUI_H_INCLUDED_ */
diff --git a/tests/examples/scaletempo/demo-main.c b/tests/examples/scaletempo/demo-main.c
new file mode 100644
index 00000000..0902d7b2
--- /dev/null
+++ b/tests/examples/scaletempo/demo-main.c
@@ -0,0 +1,95 @@
+/* main.c
+ * Copyright (C) 2008 Rov Juvano <rovjuvano@users.sourceforge.net>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "demo-player.h"
+#include "demo-gui.h"
+
+extern GOptionGroup *gtk_get_option_group (gboolean);
+extern GOptionGroup *gst_init_get_option_group (void);
+
+static void
+handle_error_message (DemoPlayer * player, const gchar * msg, gpointer data)
+{
+ const gchar *format = (const gchar *) data;
+ g_print (format, msg);
+}
+
+static void
+handle_quit (gpointer source, gpointer data)
+{
+ g_main_loop_quit ((GMainLoop *) data);
+}
+
+
+int
+main (int argc, char *argv[])
+{
+ DemoGui *gui;
+ DemoPlayer *player;
+ gchar **uris = NULL;
+ GOptionContext *ctx;
+ GError *err = NULL;
+ GMainLoop *loop;
+
+ const GOptionEntry entries[] = {
+ {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &uris,
+ "Special option that collects any remaining arguments for us"},
+ {NULL,}
+ };
+
+ if (!g_thread_supported ())
+ g_thread_init (NULL);
+
+ ctx = g_option_context_new ("uri ...");
+ g_option_context_add_group (ctx, gst_init_get_option_group ());
+ g_option_context_add_group (ctx, gtk_get_option_group (FALSE));
+ g_option_context_add_main_entries (ctx, entries, NULL);
+ if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
+ g_print ("Error initializing: %s\n", err->message);
+ g_error_free (err);
+ return -1;
+ }
+ g_option_context_free (ctx);
+
+ gui = g_object_new (DEMO_TYPE_GUI, NULL);
+ player = g_object_new (DEMO_TYPE_PLAYER, NULL);
+ g_signal_connect (player, "error", G_CALLBACK (handle_error_message),
+ "PLAYER ERROR: %s\n");
+ g_signal_connect (gui, "error", G_CALLBACK (handle_error_message),
+ "GUI ERROR: %s\n");
+ demo_gui_set_player (gui, player);
+
+ loop = g_main_loop_new (NULL, FALSE);
+ g_signal_connect (gui, "quiting", G_CALLBACK (handle_quit), loop);
+
+ if (uris != NULL) {
+ int i, num = g_strv_length (uris);
+ GList *uri_list = NULL;
+ for (i = 0; i < num; i++) {
+ uri_list = g_list_append (uri_list, uris[i]);
+ }
+ demo_gui_set_playlist (gui, uri_list);
+ }
+ demo_gui_show (gui);
+ g_main_loop_run (loop);
+
+ return 0;
+}
diff --git a/tests/examples/scaletempo/demo-player.c b/tests/examples/scaletempo/demo-player.c
new file mode 100644
index 00000000..3ed4b718
--- /dev/null
+++ b/tests/examples/scaletempo/demo-player.c
@@ -0,0 +1,756 @@
+/* demo-player.c
+ * Copyright (C) 2008 Rov Juvano <rovjuvano@users.sourceforge.net>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "demo-player.h"
+#include "gst/gst.h"
+
+#undef G_LOG_DOMAIN
+#define G_LOG_DOMAIN "demo-player"
+
+enum
+{
+ SIGNAL_ERROR,
+ SIGNAL_RATE_CHANGE,
+ SIGNAL_PLAYING_STARTED,
+ SIGNAL_PLAYING_PAUSED,
+ SIGNAL_PLAYING_ENDED,
+ LAST_SIGNAL
+};
+static guint demo_player_signals[LAST_SIGNAL] = { 0 };
+
+enum
+{
+ PROP_0,
+ PROP_RATE,
+ PROP_STRIDE,
+ PROP_OVERLAP,
+ PROP_SEARCH,
+ PROP_DISABLED
+};
+
+typedef struct _DemoPlayerPrivate
+{
+ gdouble rate;
+ GstElement *scaletempo;
+ GstElement *pipeline;
+ gboolean is_disabled;
+ GstElement *scaletempo_line;
+ GstElement *scalerate_line;
+ gboolean ignore_state_change;
+} DemoPlayerPrivate;
+
+#define DEMO_PLAYER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DEMO_TYPE_PLAYER, DemoPlayerPrivate))
+
+
+static gboolean
+no_pipeline (DemoPlayer * player)
+{
+ DemoPlayerPrivate *priv = DEMO_PLAYER_GET_PRIVATE (player);
+ if (!priv->pipeline) {
+ g_signal_emit (player, demo_player_signals[SIGNAL_ERROR], 0,
+ "No media loaded");
+ return TRUE;
+ }
+ return FALSE;
+}
+
+static gboolean
+demo_player_event_listener (GstElement * host, GstEvent * event, gpointer data)
+{
+ DemoPlayer *player = DEMO_PLAYER (data);
+ DemoPlayerPrivate *priv = DEMO_PLAYER_GET_PRIVATE (player);
+
+ if (GST_EVENT_TYPE (event) == GST_EVENT_NEWSEGMENT) {
+ gdouble rate, applied_rate;
+ gdouble new_rate;
+
+ gst_event_parse_new_segment_full (event, NULL, &rate, &applied_rate, NULL,
+ NULL, NULL, NULL);
+ new_rate = rate * applied_rate;
+ if (priv->rate != new_rate) {
+ priv->rate = new_rate;
+ g_signal_emit (player, demo_player_signals[SIGNAL_RATE_CHANGE], 0,
+ new_rate);
+ }
+ }
+
+ return TRUE;
+}
+
+static void
+demo_player_state_changed_cb (GstBus * bus, GstMessage * message, gpointer data)
+{
+ DemoPlayer *player = DEMO_PLAYER (data);
+ DemoPlayerPrivate *priv = DEMO_PLAYER_GET_PRIVATE (player);
+ GstState old, new, pending;
+
+ if (GST_ELEMENT (GST_MESSAGE_SRC (message)) != priv->pipeline)
+ return;
+
+ gst_message_parse_state_changed (message, &old, &new, &pending);
+
+ if (pending == GST_STATE_VOID_PENDING) {
+ if (priv->ignore_state_change) {
+ priv->ignore_state_change = FALSE;
+ } else if (new == GST_STATE_PAUSED) {
+ g_signal_emit (player, demo_player_signals[SIGNAL_PLAYING_PAUSED], 0);
+ } else if (new == GST_STATE_PLAYING) {
+ g_signal_emit (player, demo_player_signals[SIGNAL_PLAYING_STARTED], 0);
+ }
+ }
+}
+
+static void
+demo_player_eos_cb (GstBus * bus, GstMessage * message, gpointer data)
+{
+ DemoPlayer *player = DEMO_PLAYER (data);
+ g_signal_emit (player, demo_player_signals[SIGNAL_PLAYING_ENDED], 0);
+}
+
+#define MAKE_ELEMENT(line, var, type, name) \
+ if ( !(var = gst_element_factory_make (type, name) ) ) { \
+ g_print ("element could not be created: %s/%s\n", type, name); \
+ return; \
+ } \
+ if (line) gst_bin_add (GST_BIN (line), var);
+
+#define LINK_ELEMENTS(src, sink) \
+ if (!gst_element_link (src, sink)) { \
+ g_warning ("Failed to link elements: %s -> %s", \
+ GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (sink) ); \
+ return; \
+ }
+
+static void
+demo_player_build_pipeline (DemoPlayer * player)
+{
+ DemoPlayerPrivate *priv = DEMO_PLAYER_GET_PRIVATE (player);
+ GstElement *filter, *playbin, *vsink, *audioline, *format, *resample, *asink;
+ GstPlugin *gconf;
+ GstBus *bus;
+ gboolean has_gconf;
+ const gchar *audiosink_name;
+ GstPad *ghostpad;
+
+ priv->pipeline = NULL;
+ if (!priv->scaletempo) {
+ return;
+ }
+
+ filter = priv->scaletempo;
+
+ MAKE_ELEMENT (NULL, playbin, "playbin", "playbin");
+
+ gconf = gst_default_registry_find_plugin ("gconfelements");
+ has_gconf = (gconf != NULL);
+ gst_object_unref (gconf);
+
+ if (has_gconf) {
+ MAKE_ELEMENT (NULL, vsink, "gconfvideosink", "vsink");
+ g_object_set (G_OBJECT (playbin), "video_sink", vsink, NULL);
+ }
+ audiosink_name = has_gconf ? "gconfaudiosink" : "autoaudiosink";
+
+ audioline = gst_bin_new ("audioline");
+ gst_bin_add (GST_BIN (audioline), filter);
+ MAKE_ELEMENT (audioline, format, "audioconvert", "format");
+ MAKE_ELEMENT (audioline, resample, "audioresample", "resample");
+ MAKE_ELEMENT (audioline, asink, audiosink_name, "audio_sink");
+ LINK_ELEMENTS (filter, format);
+ LINK_ELEMENTS (format, resample);
+ LINK_ELEMENTS (resample, asink);
+
+ gst_pad_add_event_probe (gst_element_get_static_pad (asink, "sink"),
+ G_CALLBACK (demo_player_event_listener), player);
+
+ ghostpad = gst_element_get_static_pad (filter, "sink");
+ gst_element_add_pad (audioline, gst_ghost_pad_new ("sink", ghostpad));
+ gst_object_unref (ghostpad);
+ g_object_set (G_OBJECT (playbin), "audio-sink", audioline, NULL);
+
+ bus = gst_pipeline_get_bus (GST_PIPELINE (playbin));
+ gst_bus_add_signal_watch (bus);
+ g_signal_connect (bus, "message::state-changed",
+ G_CALLBACK (demo_player_state_changed_cb), player);
+ g_signal_connect (bus, "message::eos", G_CALLBACK (demo_player_eos_cb),
+ player);
+ gst_object_unref (bus);
+
+ priv->scaletempo = filter;
+ priv->pipeline = playbin;
+
+ priv->scaletempo_line = audioline;
+ MAKE_ELEMENT (NULL, priv->scalerate_line, "gconfaudiosink",
+ "scaling_audio_sink");
+ gst_pad_add_event_probe (gst_element_get_static_pad (priv->scalerate_line,
+ "sink"), G_CALLBACK (demo_player_event_listener), player);
+ g_object_ref (priv->scaletempo_line);
+ g_object_ref (priv->scalerate_line);
+}
+
+
+/* method implementations */
+static void
+_set_rate (DemoPlayer * player, gdouble new_rate, gint second)
+{
+ DemoPlayerPrivate *priv;
+ gint64 pos;
+ GstSeekType seek_type;
+
+
+ if (new_rate == 0) {
+ g_signal_emit (player, demo_player_signals[SIGNAL_ERROR], 0,
+ "Cannot set playback to zero. Pausing instead.");
+ demo_player_pause (player);
+ }
+
+ priv = DEMO_PLAYER_GET_PRIVATE (player);
+
+ if (second < 0) {
+ GstFormat fmt = GST_FORMAT_TIME;
+ seek_type = GST_SEEK_TYPE_SET;
+ if (!gst_element_query_position (priv->pipeline, &fmt, &pos)) {
+ // This should be the default but too many upstream elements seek anyway
+ pos = GST_CLOCK_TIME_NONE;
+ seek_type = GST_SEEK_TYPE_NONE;
+ }
+ } else {
+ seek_type = GST_SEEK_TYPE_SET;
+ pos = second * GST_SECOND;
+ }
+
+ if (!gst_element_seek (priv->pipeline, new_rate,
+ GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE,
+ seek_type, pos, GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE)) {
+ g_signal_emit (player, demo_player_signals[SIGNAL_ERROR], 0,
+ "Unable to change playback rate");
+ } else {
+ priv->ignore_state_change = TRUE;
+ }
+}
+
+static void
+demo_player_scale_rate_func (DemoPlayer * player, gdouble scale)
+{
+ DemoPlayerPrivate *priv;
+ if (no_pipeline (player))
+ return;
+
+ priv = DEMO_PLAYER_GET_PRIVATE (player);
+
+ if (scale != 1.0) {
+ g_message ("Scaling Rate by: %3.2f", scale);
+ _set_rate (player, priv->rate * scale, -1);
+ }
+}
+
+static void
+demo_player_set_rate_func (DemoPlayer * player, gdouble new_rate)
+{
+ DemoPlayerPrivate *priv;
+
+ if (no_pipeline (player))
+ return;
+
+ priv = DEMO_PLAYER_GET_PRIVATE (player);
+
+ if (priv->rate != new_rate) {
+ g_message ("Setting Rate to: %3.2f", new_rate);
+ _set_rate (player, new_rate, -1);
+ }
+}
+
+static gboolean
+_set_state_and_wait (DemoPlayer * player,
+ GstState new_state, GstClockTime timeout, const gchar * error_msg)
+{
+ DemoPlayerPrivate *priv = DEMO_PLAYER_GET_PRIVATE (player);
+ GstStateChangeReturn ret = gst_element_set_state (priv->pipeline, new_state);
+ if (ret == GST_STATE_CHANGE_ASYNC) {
+ ret = gst_element_get_state (priv->pipeline, NULL, NULL, timeout);
+ }
+ if (ret != GST_STATE_CHANGE_SUCCESS) {
+ g_signal_emit (player, demo_player_signals[SIGNAL_ERROR], 0, error_msg);
+ return FALSE;
+ }
+ return TRUE;
+}
+
+static void
+demo_player_load_uri_func (DemoPlayer * player, gchar * uri)
+{
+ DemoPlayerPrivate *priv = DEMO_PLAYER_GET_PRIVATE (player);
+ GstState end_state;
+ gdouble rate;
+
+ if (!priv->pipeline) {
+ demo_player_build_pipeline (player);
+ if (!priv->pipeline) {
+ g_signal_emit (player, demo_player_signals[SIGNAL_ERROR], 0,
+ "Could not build player");
+ return;
+ }
+ }
+ if (!g_str_has_prefix (uri, "file:///")) {
+ GError *err = NULL;
+ if (g_path_is_absolute (uri)) {
+ uri = g_filename_to_uri (uri, NULL, &err);
+ } else {
+ gchar *curdir = g_get_current_dir ();
+ gchar *absolute_path = g_strconcat (curdir, G_DIR_SEPARATOR_S, uri, NULL);
+ uri = g_filename_to_uri (absolute_path, NULL, &err);
+ g_free (absolute_path);
+ g_free (curdir);
+ }
+ if (err) {
+ gchar *msg = g_strconcat ("Could not load uri: ", err->message, NULL);
+ g_signal_emit (player, demo_player_signals[SIGNAL_ERROR], 0, msg);
+ return;
+ }
+ }
+
+ g_message ("Loading URI: %s", uri);
+
+ end_state =
+ (GST_STATE (priv->pipeline) ==
+ GST_STATE_PLAYING) ? GST_STATE_PLAYING : GST_STATE_PAUSED;
+ if (!_set_state_and_wait (player, GST_STATE_NULL, 10 * GST_SECOND,
+ "Unable to load uri"))
+ return;
+
+ g_object_set (G_OBJECT (priv->pipeline), "uri", uri, NULL);
+
+ rate = priv->rate;
+ if (rate && rate != 1.0) {
+ _set_state_and_wait (player, GST_STATE_PAUSED, 10 * GST_SECOND,
+ "Unable to keep playback rate");
+ _set_rate (player, rate, -1);
+ }
+
+ gst_element_set_state (priv->pipeline, end_state);
+}
+
+static void
+demo_player_play_func (DemoPlayer * player)
+{
+ DemoPlayerPrivate *priv;
+ GstStateChangeReturn ret;
+
+ if (no_pipeline (player))
+ return;
+
+ priv = DEMO_PLAYER_GET_PRIVATE (player);
+
+ if (GST_STATE (priv->pipeline) == GST_STATE_PLAYING) {
+ g_signal_emit (player, demo_player_signals[SIGNAL_ERROR], 0,
+ "Already playing");
+ return;
+ }
+
+ g_debug ("Starting to Play");
+ ret = gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
+ if (ret == GST_STATE_CHANGE_FAILURE) {
+ g_signal_emit (player, demo_player_signals[SIGNAL_ERROR], 0,
+ "Unable to start playback");
+ return;
+ }
+}
+
+static void
+demo_player_pause_func (DemoPlayer * player)
+{
+ DemoPlayerPrivate *priv;
+ GstStateChangeReturn ret;
+
+ if (no_pipeline (player))
+ return;
+
+ priv = DEMO_PLAYER_GET_PRIVATE (player);
+
+ if (GST_STATE (priv->pipeline) == GST_STATE_PAUSED) {
+ g_signal_emit (player, demo_player_signals[SIGNAL_ERROR], 0,
+ "Already paused");
+ return;
+ }
+
+ g_debug ("Starting to Pause");
+ ret = gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
+ if (ret == GST_STATE_CHANGE_FAILURE) {
+ g_signal_emit (player, demo_player_signals[SIGNAL_ERROR], 0,
+ "Unable to pause playback");
+ return;
+ }
+}
+
+static void
+_seek_to (DemoPlayer * player, gint new_second)
+{
+ DemoPlayerPrivate *priv = DEMO_PLAYER_GET_PRIVATE (player);
+ if (!gst_element_seek (priv->pipeline, priv->rate,
+ GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
+ GST_SEEK_TYPE_SET, new_second * GST_SECOND,
+ GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE)) {
+ g_signal_emit (player, demo_player_signals[SIGNAL_ERROR], 0, "Seek failed");
+ return;
+ }
+
+ priv->ignore_state_change = TRUE;
+}
+
+static void
+demo_player_seek_by_func (DemoPlayer * player, gint seconds)
+{
+ gint pos;
+
+ if (no_pipeline (player))
+ return;
+
+ g_debug ("Seeking by: %i", seconds);
+
+ pos = demo_player_get_position (player);
+ if (pos < 0) {
+ g_signal_emit (player, demo_player_signals[SIGNAL_ERROR], 0,
+ "Seek-by failed: could not determine position");
+ return;
+ }
+
+ _seek_to (player, MAX (0, pos + seconds));
+}
+
+static void
+demo_player_seek_to_func (DemoPlayer * player, gint second)
+{
+ gint new_second;
+
+ if (no_pipeline (player))
+ return;
+
+ g_debug ("Seeking to: %i", second);
+
+ if (second < 0) {
+ gint dur = demo_player_get_duration (player);
+ if (dur < 0) {
+ g_signal_emit (player, demo_player_signals[SIGNAL_ERROR], 0,
+ "Seek-to failed: could not determine duration");
+ return;
+ }
+ new_second = MAX (0, dur + second);
+ } else {
+ new_second = second;
+ }
+
+ _seek_to (player, new_second);
+}
+
+static gint
+demo_player_get_position_func (DemoPlayer * player)
+{
+ DemoPlayerPrivate *priv = DEMO_PLAYER_GET_PRIVATE (player);
+ gint64 pos;
+ GstFormat fmt = GST_FORMAT_TIME;
+
+ if (!priv->pipeline)
+ return -1;
+
+ if (!gst_element_query_position (priv->pipeline, &fmt, &pos) || pos < 0) {
+ return -1;
+ }
+
+ return (gint) (pos / GST_SECOND);
+}
+
+static gint
+demo_player_get_duration_func (DemoPlayer * player)
+{
+ DemoPlayerPrivate *priv = DEMO_PLAYER_GET_PRIVATE (player);
+ gint64 dur;
+ GstFormat fmt = GST_FORMAT_TIME;
+
+ if (!priv->pipeline)
+ return -1;
+
+ if (!gst_element_query_duration (priv->pipeline, &fmt, &dur) || dur < 0) {
+ return -1;
+ }
+
+ return (gint) (dur / GST_SECOND);
+}
+
+
+/* Method wrappers */
+void
+demo_player_scale_rate (DemoPlayer * player, gdouble scale)
+{
+ g_return_if_fail (DEMO_IS_PLAYER (player));
+
+ DEMO_PLAYER_GET_CLASS (player)->scale_rate (player, scale);
+}
+
+void
+demo_player_set_rate (DemoPlayer * player, gdouble new_rate)
+{
+ g_return_if_fail (DEMO_IS_PLAYER (player));
+
+ DEMO_PLAYER_GET_CLASS (player)->set_rate (player, new_rate);
+}
+
+void
+demo_player_load_uri (DemoPlayer * player, gchar * uri)
+{
+ g_return_if_fail (DEMO_IS_PLAYER (player));
+
+ DEMO_PLAYER_GET_CLASS (player)->load_uri (player, uri);
+}
+
+void
+demo_player_play (DemoPlayer * player)
+{
+ g_return_if_fail (DEMO_IS_PLAYER (player));
+
+ DEMO_PLAYER_GET_CLASS (player)->play (player);
+}
+
+void
+demo_player_pause (DemoPlayer * player)
+{
+ g_return_if_fail (DEMO_IS_PLAYER (player));
+
+ DEMO_PLAYER_GET_CLASS (player)->pause (player);
+}
+
+void
+demo_player_seek_by (DemoPlayer * player, gint seconds)
+{
+ g_return_if_fail (DEMO_IS_PLAYER (player));
+
+ DEMO_PLAYER_GET_CLASS (player)->seek_by (player, seconds);
+}
+
+void
+demo_player_seek_to (DemoPlayer * player, gint second)
+{
+ g_return_if_fail (DEMO_IS_PLAYER (player));
+
+ DEMO_PLAYER_GET_CLASS (player)->seek_to (player, second);
+}
+
+gint
+demo_player_get_position (DemoPlayer * player)
+{
+ g_return_val_if_fail (DEMO_IS_PLAYER (player), -1);
+
+ return DEMO_PLAYER_GET_CLASS (player)->get_position (player);
+}
+
+gint
+demo_player_get_duration (DemoPlayer * player)
+{
+ g_return_val_if_fail (DEMO_IS_PLAYER (player), -1);
+
+ return DEMO_PLAYER_GET_CLASS (player)->get_duration (player);
+}
+
+/* GObject overrides */
+static void
+demo_player_get_property (GObject * object,
+ guint property_id, GValue * value, GParamSpec * pspec)
+{
+ DemoPlayer *player = DEMO_PLAYER (object);
+ DemoPlayerPrivate *priv = DEMO_PLAYER_GET_PRIVATE (player);
+ switch (property_id) {
+ case PROP_RATE:
+ g_value_set_double (value, priv->rate);
+ break;
+ case PROP_STRIDE:
+ g_object_get_property (G_OBJECT (priv->scaletempo), "stride", value);
+ break;
+ case PROP_OVERLAP:
+ g_object_get_property (G_OBJECT (priv->scaletempo), "overlap", value);
+ break;
+ case PROP_SEARCH:
+ g_object_get_property (G_OBJECT (priv->scaletempo), "search", value);
+ break;
+ case PROP_DISABLED:
+ g_value_set_boolean (value, priv->is_disabled);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+demo_player_set_property (GObject * object,
+ guint property_id, const GValue * value, GParamSpec * pspec)
+{
+ DemoPlayer *player = DEMO_PLAYER (object);
+ DemoPlayerPrivate *priv = DEMO_PLAYER_GET_PRIVATE (player);
+ switch (property_id) {
+ case PROP_STRIDE:
+ g_object_set_property (G_OBJECT (priv->scaletempo), "stride", value);
+ break;
+ case PROP_OVERLAP:
+ g_object_set_property (G_OBJECT (priv->scaletempo), "overlap", value);
+ break;
+ case PROP_SEARCH:
+ g_object_set_property (G_OBJECT (priv->scaletempo), "search", value);
+ break;
+ case PROP_DISABLED:{
+ gdouble rate = priv->rate;
+ gint pos = demo_player_get_position (player);
+ GstState end_state;
+ GstElement *new_sink;
+
+ priv->is_disabled = g_value_get_boolean (value);
+
+ g_debug ("Scaletempo: %s", priv->is_disabled ? "disabled" : "enabled");
+
+ end_state =
+ (GST_STATE (priv->pipeline) ==
+ GST_STATE_PLAYING) ? GST_STATE_PLAYING : GST_STATE_PAUSED;
+ if (!_set_state_and_wait (player, GST_STATE_NULL, 10 * GST_SECOND,
+ "Unable to disable"))
+ break;
+
+ new_sink =
+ (priv->is_disabled) ? priv->scalerate_line : priv->scaletempo_line;
+ g_object_set (G_OBJECT (priv->pipeline), "audio-sink", new_sink, NULL);
+
+ if (pos > 0 || (rate && rate != 1.0)) {
+ _set_state_and_wait (player, GST_STATE_PAUSED, 10 * GST_SECOND,
+ "Unable to keep playback position and rate");
+ _set_rate (player, rate, pos);
+ }
+
+ gst_element_set_state (priv->pipeline, end_state);
+ break;
+ }
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+
+/* GTypeInfo functions */
+static void
+demo_player_init (GTypeInstance * instance, gpointer klass)
+{
+ DemoPlayer *player = (DemoPlayer *) instance;
+ DemoPlayerPrivate *priv = DEMO_PLAYER_GET_PRIVATE (player);
+ priv->scaletempo = gst_element_factory_make ("scaletempo", "scaletempo");
+ if (!priv->scaletempo) {
+ g_error ("Unable to make scaletempo element.");
+ }
+ priv->rate = 1.0;
+ priv->pipeline = NULL;
+ priv->ignore_state_change = FALSE;
+ priv->is_disabled = FALSE;
+}
+
+static void
+demo_player_class_init (gpointer klass, gpointer class_data)
+{
+ DemoPlayerClass *player_class = (DemoPlayerClass *) klass;
+ GObjectClass *as_object_class = G_OBJECT_CLASS (klass);
+ GType type;
+
+ g_type_class_add_private (klass, sizeof (DemoPlayerPrivate));
+
+ /* DemoPlayer */
+ player_class->scale_rate = demo_player_scale_rate_func;
+ player_class->set_rate = demo_player_set_rate_func;
+ player_class->load_uri = demo_player_load_uri_func;
+ player_class->play = demo_player_play_func;
+ player_class->pause = demo_player_pause_func;
+ player_class->seek_by = demo_player_seek_by_func;
+ player_class->seek_to = demo_player_seek_to_func;
+ player_class->get_position = demo_player_get_position_func;
+ player_class->get_duration = demo_player_get_duration_func;
+
+ /* GObject */
+ as_object_class->get_property = demo_player_get_property;
+ as_object_class->set_property = demo_player_set_property;
+
+ /* Properties */
+ g_object_class_install_property (as_object_class, PROP_RATE,
+ g_param_spec_double ("rate", "Rate", "Current playback rate",
+ -128, 128, 1.0, G_PARAM_READABLE));
+
+ g_object_class_install_property (as_object_class, PROP_STRIDE,
+ g_param_spec_uint ("stride", "Stride Length",
+ "Length in milliseconds to output each stride", 1, 10000, 60,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (as_object_class, PROP_OVERLAP,
+ g_param_spec_double ("overlap", "Overlap Length",
+ "Percentage of stride to overlap", 0, 1, .2, G_PARAM_READWRITE));
+
+ g_object_class_install_property (as_object_class, PROP_SEARCH,
+ g_param_spec_uint ("search", "Search Length",
+ "Length in milliseconds to search for best overlap position", 0,
+ 10000, 14, G_PARAM_READWRITE));
+
+ g_object_class_install_property (as_object_class, PROP_DISABLED,
+ g_param_spec_boolean ("disabled", "disable scaletempo",
+ "Disable scaletempo and scale bothe tempo and pitch", FALSE,
+ G_PARAM_READWRITE));
+
+ /* Signals */
+ type = G_TYPE_FROM_CLASS (klass);
+ demo_player_signals[SIGNAL_ERROR] = g_signal_new ("error", type,
+ G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
+ g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING);
+
+ demo_player_signals[SIGNAL_RATE_CHANGE] = g_signal_new ("rate-changed", type,
+ G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
+ g_cclosure_marshal_VOID__DOUBLE, G_TYPE_NONE, 1, G_TYPE_DOUBLE);
+
+ demo_player_signals[SIGNAL_PLAYING_STARTED] =
+ g_signal_new ("playing-started", type, G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
+ g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
+
+ demo_player_signals[SIGNAL_PLAYING_PAUSED] =
+ g_signal_new ("playing-paused", type, G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
+ g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
+
+ demo_player_signals[SIGNAL_PLAYING_ENDED] =
+ g_signal_new ("playing-ended", type, G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
+ g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
+}
+
+GType
+demo_player_get_type (void)
+{
+ static GType type = 0;
+ if (G_UNLIKELY (type == 0)) {
+ static const GTypeInfo info = {
+ sizeof /* Class */ (DemoPlayerClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) demo_player_class_init,
+ (GClassFinalizeFunc) NULL,
+ (gconstpointer) NULL, /* class_data */
+ sizeof /* Instance */ (DemoPlayer),
+ /* n_preallocs */ 0,
+ (GInstanceInitFunc) demo_player_init,
+ (const GTypeValueTable *) NULL
+ };
+ type = g_type_register_static (G_TYPE_OBJECT, "DemoPlayer", &info, 0);
+ }
+ return type;
+}
diff --git a/tests/examples/scaletempo/demo-player.h b/tests/examples/scaletempo/demo-player.h
new file mode 100644
index 00000000..ff521fc7
--- /dev/null
+++ b/tests/examples/scaletempo/demo-player.h
@@ -0,0 +1,71 @@
+/* gui.h
+ * Copyright (C) 2008 Rov Juvano <rovjuvano@users.sourceforge.net>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __DEMO_PLAYER_H_INCLUDED_
+#define __DEMO_PLAYER_H_INCLUDED_
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define DEMO_TYPE_PLAYER (demo_player_get_type())
+#define DEMO_PLAYER(o) (G_TYPE_CHECK_INSTANCE_CAST((o), DEMO_TYPE_PLAYER, DemoPlayer))
+#define DEMO_IS_PLAYER(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), DEMO_TYPE_PLAYER))
+#define DEMO_PLAYER_TYPE(o) (G_TYPE_FROM_INSTANCE (o))
+#define DEMO_PLAYER_TYPE_NAME(o) (g_type_name (DEMO_PLAYER_TYPE (o)))
+
+#define DEMO_PLAYER_CLASS(c) (G_TYPE_CHECK_CLASS_CAST((c), DEMO_TYPE_PLAYER, DemoPlayerClass))
+#define DEMO_IS_PLAYER_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE((c), DEMO_TYPE_PLAYER))
+#define DEMO_PLAYER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), DEMO_TYPE_PLAYER, DemoPlayerClass))
+
+typedef struct _DemoPlayer DemoPlayer;
+typedef struct _DemoPlayerClass DemoPlayerClass;
+
+struct _DemoPlayer
+{
+ GObject parent;
+};
+
+struct _DemoPlayerClass
+{
+ GObjectClass parent;
+ void (*scale_rate) (DemoPlayer *player, gdouble scale);
+ void (*set_rate) (DemoPlayer *player, gdouble new_rate);
+ void (*load_uri) (DemoPlayer *player, gchar *uri);
+ void (*play) (DemoPlayer *player);
+ void (*pause) (DemoPlayer *player);
+ void (*seek_by) (DemoPlayer *player, gint seconds);
+ void (*seek_to) (DemoPlayer *player, gint seconds);
+ gint (*get_position) (DemoPlayer *player);
+ gint (*get_duration) (DemoPlayer *player);
+};
+
+GType demo_player_get_type (void);
+
+void demo_player_scale_rate (DemoPlayer *player, gdouble scale);
+void demo_player_set_rate (DemoPlayer *player, gdouble new_rate);
+void demo_player_load_uri (DemoPlayer *player, gchar *uri);
+void demo_player_play (DemoPlayer *player);
+void demo_player_pause (DemoPlayer *player);
+void demo_player_seek_by (DemoPlayer *player, gint seconds);
+void demo_player_seek_to (DemoPlayer *player, gint second);
+gint demo_player_get_position (DemoPlayer *player);
+gint demo_player_get_duration (DemoPlayer *player);
+
+G_END_DECLS
+
+#endif /* __DEMO_PLAYER_H_INCLUDED_ */
diff --git a/tests/examples/stats/Makefile.am b/tests/examples/stats/Makefile.am
new file mode 100644
index 00000000..0f7d81cf
--- /dev/null
+++ b/tests/examples/stats/Makefile.am
@@ -0,0 +1,6 @@
+noinst_PROGRAMS = mp2ogg
+
+LDADD = $(GST_LIBS)
+AM_CFLAGS = $(GST_CFLAGS)
+
+
diff --git a/tests/examples/stats/mp2ogg.c b/tests/examples/stats/mp2ogg.c
new file mode 100644
index 00000000..fc56d5b5
--- /dev/null
+++ b/tests/examples/stats/mp2ogg.c
@@ -0,0 +1,102 @@
+/* GStreamer
+ * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
+ *
+ * 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 <gst/gst.h>
+
+/* This example app demonstartes the use of pad query and convert to
+ * get useful statistics about a plugin. In this case we monitor the
+ * compression status of mpeg audio to ogg vorbis transcoding.
+ */
+
+gint
+main (gint argc, gchar * argv[])
+{
+ GstElement *pipeline;
+ GError *error = NULL;
+ gchar *description;
+ GstElement *encoder, *decoder;
+ GstPad *dec_sink, *enc_src;
+
+ gst_init (&argc, &argv);
+
+ if (argc < 3) {
+ g_print ("usage: %s <inputfile> <outputfile>\n", argv[0]);
+ return -1;
+ }
+
+ description = g_strdup_printf ("filesrc location=\"%s\" ! mad name=decoder ! "
+ "vorbisenc name=encoder ! filesink location=\"%s\"", argv[1], argv[2]);
+
+ pipeline = GST_ELEMENT (gst_parse_launch (description, &error));
+ if (!pipeline) {
+ if (error)
+ g_print ("ERROR: pipeline could not be constructed: %s\n",
+ error->message);
+ else
+ g_print ("ERROR: pipeline could not be constructed\n");
+ return -1;
+ }
+
+ decoder = gst_bin_get_by_name (GST_BIN (pipeline), "decoder");
+ encoder = gst_bin_get_by_name (GST_BIN (pipeline), "encoder");
+
+ dec_sink = gst_element_get_pad (decoder, "sink");
+ enc_src = gst_element_get_pad (encoder, "src");
+
+ if (gst_element_set_state (pipeline,
+ GST_STATE_PLAYING) != GST_STATE_CHANGE_SUCCESS) {
+ g_print ("pipeline doesn't want to play\n");
+ return -1;
+ }
+
+ while (gst_bin_iterate (GST_BIN (pipeline))) {
+ gint64 position;
+ gint64 duration;
+ gint64 bitrate_enc, bitrate_dec;
+ GstFormat format;
+
+ format = GST_FORMAT_TIME;
+ /* get the position */
+ gst_pad_query (enc_src, GST_QUERY_POSITION, &format, &position);
+
+ /* get the total duration */
+ gst_pad_query (enc_src, GST_QUERY_TOTAL, &format, &duration);
+
+ format = GST_FORMAT_BYTES;
+ /* see how many bytes are genereated per 8 seconds (== bitrate) */
+ gst_pad_convert (enc_src, GST_FORMAT_TIME, 8 * GST_SECOND,
+ &format, &bitrate_enc);
+
+ gst_pad_convert (dec_sink, GST_FORMAT_TIME, 8 * GST_SECOND,
+ &format, &bitrate_dec);
+
+ g_print ("[%2dm %.2ds] of [%2dm %.2ds], "
+ "src avg bitrate: %" G_GINT64_FORMAT ", dest avg birate: %"
+ G_GINT64_FORMAT ", ratio [%02.2f] \r",
+ (gint) (position / (GST_SECOND * 60)),
+ (gint) (position / (GST_SECOND)) % 60,
+ (gint) (duration / (GST_SECOND * 60)),
+ (gint) (duration / (GST_SECOND)) % 60, bitrate_dec, bitrate_enc,
+ (gfloat) bitrate_dec / bitrate_enc);
+ }
+
+ g_print ("\n");
+
+ return 0;
+}
diff --git a/tests/examples/switch/.gitignore b/tests/examples/switch/.gitignore
new file mode 100644
index 00000000..7893c435
--- /dev/null
+++ b/tests/examples/switch/.gitignore
@@ -0,0 +1 @@
+switcher
diff --git a/tests/examples/switch/Makefile.am b/tests/examples/switch/Makefile.am
new file mode 100644
index 00000000..9a706048
--- /dev/null
+++ b/tests/examples/switch/Makefile.am
@@ -0,0 +1,7 @@
+
+noinst_PROGRAMS = switcher
+
+switcher_SOURCES = switcher.c
+switcher_CFLAGS = $(GST_CFLAGS)
+switcher_LDFLAGS = $(GST_LIBS)
+
diff --git a/tests/examples/switch/switcher.c b/tests/examples/switch/switcher.c
new file mode 100644
index 00000000..4742c033
--- /dev/null
+++ b/tests/examples/switch/switcher.c
@@ -0,0 +1,162 @@
+/* GStreamer
+ * Copyright (C) 2003 Julien Moutte <julien@moutte.net>
+ *
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include <string.h>
+#include <stdlib.h>
+
+
+#include <gst/gst.h>
+
+static GMainLoop *loop = NULL;
+
+static gboolean
+my_bus_callback (GstBus * bus, GstMessage * message, gpointer data)
+{
+ g_print ("Got %s message\n", GST_MESSAGE_TYPE_NAME (message));
+
+ switch (GST_MESSAGE_TYPE (message)) {
+ case GST_MESSAGE_ERROR:{
+ GError *err;
+ gchar *debug;
+
+ gst_message_parse_error (message, &err, &debug);
+ g_print ("Error: %s\n", err->message);
+ g_error_free (err);
+ g_free (debug);
+
+ g_main_loop_quit (loop);
+ break;
+ }
+ case GST_MESSAGE_EOS:
+ /* end-of-stream */
+ g_main_loop_quit (loop);
+ break;
+ default:
+ /* unhandled message */
+ break;
+ }
+
+ /* we want to be notified again the next time there is a message
+ * on the bus, so returning TRUE (FALSE means we want to stop watching
+ * for messages on the bus and our callback should not be called again)
+ */
+ return TRUE;
+}
+
+
+
+static gboolean
+switch_timer (GstElement * video_switch)
+{
+ gint nb_sources;
+ GstPad *active_pad, *new_pad;
+ gchar *active_name;
+
+ g_message ("switching");
+ g_object_get (G_OBJECT (video_switch), "n-pads", &nb_sources, NULL);
+ g_object_get (G_OBJECT (video_switch), "active-pad", &active_pad, NULL);
+
+ active_name = gst_pad_get_name (active_pad);
+ if (strcmp (active_name, "sink0") == 0) {
+ new_pad = gst_element_get_static_pad (video_switch, "sink1");
+ } else {
+ new_pad = gst_element_get_static_pad (video_switch, "sink0");
+ }
+ g_object_set (G_OBJECT (video_switch), "active-pad", new_pad, NULL);
+ g_free (active_name);
+ gst_object_unref (new_pad);
+
+ g_message ("current number of sources : %d, active source %s",
+ nb_sources, gst_pad_get_name (active_pad));
+
+ return (GST_STATE (GST_ELEMENT (video_switch)) == GST_STATE_PLAYING);
+}
+
+static void
+last_message_received (GObject * segment)
+{
+ gchar *last_message;
+
+ g_object_get (segment, "last_message", &last_message, NULL);
+ g_print ("last-message: %s\n", last_message);
+ g_free (last_message);
+}
+
+int
+main (int argc, char *argv[])
+{
+ GstElement *pipeline, *src1, *src2, *video_switch, *video_sink, *segment;
+ GstElement *sink1_sync, *sink2_sync, *capsfilter;
+ GstBus *bus;
+
+ /* Initing GStreamer library */
+ gst_init (&argc, &argv);
+
+ loop = g_main_loop_new (NULL, FALSE);
+
+ pipeline = gst_pipeline_new ("pipeline");
+ src1 = gst_element_factory_make ("videotestsrc", "src1");
+ g_object_set (G_OBJECT (src1), "pattern", 0, NULL);
+ src2 = gst_element_factory_make ("videotestsrc", "src2");
+ g_object_set (G_OBJECT (src2), "pattern", 1, NULL);
+ capsfilter = gst_element_factory_make ("capsfilter", "caps0");
+ g_object_set (G_OBJECT (capsfilter), "caps",
+ gst_caps_from_string ("video/x-raw-rgb,width=640,height=480"), NULL);
+ video_switch = gst_element_factory_make ("input-selector", "video_switch");
+ segment = gst_element_factory_make ("identity", "identity-segment");
+ g_object_set (G_OBJECT (segment), "silent", TRUE, NULL);
+ g_signal_connect (G_OBJECT (segment), "notify::last-message",
+ G_CALLBACK (last_message_received), segment);
+ g_object_set (G_OBJECT (segment), "single-segment", TRUE, NULL);
+ video_sink = gst_element_factory_make ("ximagesink", "video_sink");
+ g_object_set (G_OBJECT (video_sink), "sync", FALSE, NULL);
+ sink1_sync = gst_element_factory_make ("identity", "sink0_sync");
+ g_object_set (G_OBJECT (sink1_sync), "sync", TRUE, NULL);
+ sink2_sync = gst_element_factory_make ("identity", "sink1_sync");
+ g_object_set (G_OBJECT (sink2_sync), "sync", TRUE, NULL);
+ gst_bin_add_many (GST_BIN (pipeline), src1, src2, segment, video_switch,
+ video_sink, sink1_sync, sink2_sync, capsfilter, NULL);
+ gst_element_link (src1, sink1_sync);
+ gst_element_link (sink1_sync, video_switch);
+ gst_element_link (src2, capsfilter);
+ gst_element_link (capsfilter, sink2_sync);
+ gst_element_link (sink2_sync, video_switch);
+ gst_element_link (video_switch, segment);
+ gst_element_link (segment, /*scaler);
+ gst_element_link (scaler, */ video_sink);
+
+ bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
+ gst_bus_add_watch (bus, my_bus_callback, NULL);
+ gst_object_unref (bus);
+ gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
+
+ g_timeout_add (200, (GSourceFunc) switch_timer, video_switch);
+
+ g_main_loop_run (loop);
+
+ gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_READY);
+
+ /* unref */
+ gst_object_unref (GST_OBJECT (pipeline));
+
+ exit (0);
+}