summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDavid Schleef <ds@schleef.org>2007-03-11 00:48:26 +0000
committerDavid Schleef <ds@schleef.org>2007-03-11 00:48:26 +0000
commit25c51917b442748b9862528b736f8562bf9a5a89 (patch)
tree6900dfb21e3ad536dfa15e2d5257839c5c14b1b0 /examples
parent4300e22d54d459ee17025207acc2ad627dff064e (diff)
downloadgstreamer-plugins-bad-25c51917b442748b9862528b736f8562bf9a5a89.tar.gz
Add appsrc/appsink example.
Original commit message from CVS: * configure.ac: * examples/Makefile.am: * examples/app/Makefile.am: * examples/app/appsrc_ex.c: Add appsrc/appsink example. * gst-libs/gst/app/Makefile.am: * gst-libs/gst/app/gstapp.c: * gst-libs/gst/app/gstappsink.c: * gst-libs/gst/app/gstappsink.h: * gst/app/gstapp.c: Add appsink.
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile.am4
-rw-r--r--examples/app/Makefile.am9
-rw-r--r--examples/app/appsrc_ex.c86
3 files changed, 97 insertions, 2 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 1ad7b1418..8b069d81e 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -5,5 +5,5 @@ else
DIRECTFB_DIR=
endif
-SUBDIRS= $(DIRECTFB_DIR)
-DIST_SUBDIRS= directfb
+SUBDIRS= $(DIRECTFB_DIR) app
+DIST_SUBDIRS= directfb app
diff --git a/examples/app/Makefile.am b/examples/app/Makefile.am
new file mode 100644
index 000000000..0b950515a
--- /dev/null
+++ b/examples/app/Makefile.am
@@ -0,0 +1,9 @@
+
+noinst_PROGRAMS = appsrc_ex
+
+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
+
diff --git a/examples/app/appsrc_ex.c b/examples/app/appsrc_ex.c
new file mode 100644
index 000000000..170001d27
--- /dev/null
+++ b/examples/app/appsrc_ex.c
@@ -0,0 +1,86 @@
+
+
+#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>
+
+
+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);
+
+ printf ("%d: creating buffer for pointer %p\n", i, data);
+ buf = gst_app_buffer_new (data, 100, dont_eat_my_chicken_wings, data);
+ 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_end_of_stream (GST_APP_SINK (app->sink))) {
+ GstBuffer *buf;
+
+ buf = gst_app_sink_pull_buffer (GST_APP_SINK (app->sink));
+ gst_buffer_unref (buf);
+ }
+
+ return 0;
+}
+
+static void
+dont_eat_my_chicken_wings (void *priv)
+{
+ printf ("freeing buffer for pointer %p\n", priv);
+ free (priv);
+}