From f0ae68d9440e90711c7b547f03d7165357b9c4ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 24 Feb 2009 16:33:51 +0100 Subject: Move examples directory to tests/examples as in every other GStreamer module --- tests/Makefile.am | 13 +- tests/examples/Makefile.am | 14 + tests/examples/app/.gitignore | 6 + tests/examples/app/Makefile.am | 32 + tests/examples/app/appsink-src.c | 192 +++++ tests/examples/app/appsrc-ra.c | 223 ++++++ tests/examples/app/appsrc-seekable.c | 229 ++++++ tests/examples/app/appsrc-stream.c | 249 ++++++ tests/examples/app/appsrc-stream2.c | 219 ++++++ tests/examples/app/appsrc_ex.c | 89 +++ tests/examples/capsfilter/Makefile.am | 6 + tests/examples/capsfilter/capsfilter1.c | 87 +++ tests/examples/directfb/.gitignore | 1 + tests/examples/directfb/Makefile.am | 9 + tests/examples/directfb/decker.ttf | Bin 0 -> 37048 bytes tests/examples/directfb/dfblogo.png | Bin 0 -> 7722 bytes tests/examples/directfb/gstdfb.c | 514 +++++++++++++ tests/examples/gob/Makefile.am | 19 + tests/examples/gob/gst-identity2.gob | 141 ++++ tests/examples/gstplay/.gitignore | 1 + tests/examples/gstplay/Makefile.am | 11 + tests/examples/gstplay/player.c | 176 +++++ tests/examples/indexing/.gitignore | 1 + tests/examples/indexing/Makefile.am | 7 + tests/examples/indexing/indexmpeg.c | 321 ++++++++ tests/examples/level/Makefile.am | 11 + tests/examples/level/README | 39 + tests/examples/level/demo.c | 155 ++++ tests/examples/level/plot.c | 124 +++ tests/examples/scaletempo/.gitignore | 1 + tests/examples/scaletempo/Makefile.am | 8 + tests/examples/scaletempo/demo-gui.c | 1262 +++++++++++++++++++++++++++++++ tests/examples/scaletempo/demo-gui.h | 60 ++ tests/examples/scaletempo/demo-main.c | 95 +++ tests/examples/scaletempo/demo-player.c | 756 ++++++++++++++++++ tests/examples/scaletempo/demo-player.h | 71 ++ tests/examples/stats/Makefile.am | 6 + tests/examples/stats/mp2ogg.c | 102 +++ tests/examples/switch/.gitignore | 1 + tests/examples/switch/Makefile.am | 7 + tests/examples/switch/switcher.c | 162 ++++ 41 files changed, 5418 insertions(+), 2 deletions(-) create mode 100644 tests/examples/Makefile.am create mode 100644 tests/examples/app/.gitignore create mode 100644 tests/examples/app/Makefile.am create mode 100644 tests/examples/app/appsink-src.c create mode 100644 tests/examples/app/appsrc-ra.c create mode 100644 tests/examples/app/appsrc-seekable.c create mode 100644 tests/examples/app/appsrc-stream.c create mode 100644 tests/examples/app/appsrc-stream2.c create mode 100644 tests/examples/app/appsrc_ex.c create mode 100644 tests/examples/capsfilter/Makefile.am create mode 100644 tests/examples/capsfilter/capsfilter1.c create mode 100644 tests/examples/directfb/.gitignore create mode 100644 tests/examples/directfb/Makefile.am create mode 100644 tests/examples/directfb/decker.ttf create mode 100644 tests/examples/directfb/dfblogo.png create mode 100644 tests/examples/directfb/gstdfb.c create mode 100644 tests/examples/gob/Makefile.am create mode 100644 tests/examples/gob/gst-identity2.gob create mode 100644 tests/examples/gstplay/.gitignore create mode 100644 tests/examples/gstplay/Makefile.am create mode 100644 tests/examples/gstplay/player.c create mode 100644 tests/examples/indexing/.gitignore create mode 100644 tests/examples/indexing/Makefile.am create mode 100644 tests/examples/indexing/indexmpeg.c create mode 100644 tests/examples/level/Makefile.am create mode 100644 tests/examples/level/README create mode 100644 tests/examples/level/demo.c create mode 100644 tests/examples/level/plot.c create mode 100644 tests/examples/scaletempo/.gitignore create mode 100644 tests/examples/scaletempo/Makefile.am create mode 100644 tests/examples/scaletempo/demo-gui.c create mode 100644 tests/examples/scaletempo/demo-gui.h create mode 100644 tests/examples/scaletempo/demo-main.c create mode 100644 tests/examples/scaletempo/demo-player.c create mode 100644 tests/examples/scaletempo/demo-player.h create mode 100644 tests/examples/stats/Makefile.am create mode 100644 tests/examples/stats/mp2ogg.c create mode 100644 tests/examples/switch/.gitignore create mode 100644 tests/examples/switch/Makefile.am create mode 100644 tests/examples/switch/switcher.c (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index fb07e8e9..022b8d50 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -4,8 +4,17 @@ else SUBDIRS_CHECK = endif +if BUILD_EXAMPLES +SUBDIRS_EXAMPLES = examples +else +SUBDIRS_EXAMPLES = +endif + SUBDIRS = icles \ - $(SUBDIRS_CHECK) + $(SUBDIRS_CHECK) \ + $(SUBDIRS_EXAMPLES) DIST_SUBDIRS = icles \ - check + check \ + examples + 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 + +#include + +#include +#include +#include + +/* 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 + * + * 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 + +#include +#include +#include + +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 \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 + * + * 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 + +#include +#include +#include + +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 \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 + * + * 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 + +#include +#include +#include + +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 \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 + * + * 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 + +#include +#include +#include + +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 \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 +#include +#include +#include + +#include +#include +#include + + +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 +#include + +/* 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 \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 Binary files /dev/null and b/tests/examples/directfb/decker.ttf differ diff --git a/tests/examples/directfb/dfblogo.png b/tests/examples/directfb/dfblogo.png new file mode 100644 index 00000000..8b7d8833 Binary files /dev/null and b/tests/examples/directfb/dfblogo.png 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 , + Andreas Hundt , + Sven Neumann and + Julien Moutte . + + 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 +#include +#include +#include +#include + +#include +#include +#include + +/* 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 +#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 ", + "(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 + * + * 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 +#include + +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