diff options
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | examples/Makefile.am | 4 | ||||
-rw-r--r-- | examples/app/Makefile.am | 9 | ||||
-rw-r--r-- | examples/app/appsrc_ex.c | 86 | ||||
-rw-r--r-- | gst-libs/gst/app/Makefile.am | 5 | ||||
-rw-r--r-- | gst-libs/gst/app/gstapp.c | 41 | ||||
-rw-r--r-- | gst-libs/gst/app/gstappsink.c | 269 | ||||
-rw-r--r-- | gst-libs/gst/app/gstappsink.h | 71 | ||||
-rw-r--r-- | gst/app/gstapp.c | 7 |
10 files changed, 459 insertions, 48 deletions
@@ -1,3 +1,17 @@ +2007-03-10 David Schleef <ds@schleef.org> + + * 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. + 2007-03-10 Tim-Philipp Müller <tim at centricular dot net> * ext/nas/nassink.c: (NAS_createFlow): diff --git a/configure.ac b/configure.ac index 3b59628a..bb64a606 100644 --- a/configure.ac +++ b/configure.ac @@ -1088,6 +1088,7 @@ sys/directdraw/Makefile sys/directsound/Makefile sys/osxvideo/Makefile examples/Makefile +examples/app/Makefile examples/directfb/Makefile ext/amrwb/Makefile ext/alsaspdif/Makefile diff --git a/examples/Makefile.am b/examples/Makefile.am index 1ad7b141..8b069d81 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 00000000..0b950515 --- /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 00000000..170001d2 --- /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); +} diff --git a/gst-libs/gst/app/Makefile.am b/gst-libs/gst/app/Makefile.am index dae1be50..4a64f74a 100644 --- a/gst-libs/gst/app/Makefile.am +++ b/gst-libs/gst/app/Makefile.am @@ -1,6 +1,6 @@ lib_LTLIBRARIES = libgstapp-@GST_MAJORMINOR@.la -libgstapp_@GST_MAJORMINOR@_la_SOURCES = gstappsrc.c gstappbuffer.c +libgstapp_@GST_MAJORMINOR@_la_SOURCES = gstappsrc.c gstappbuffer.c gstappsink.c libgstapp_@GST_MAJORMINOR@_la_CFLAGS = $(GST_CFLAGS) $(GST_BASE_CFLAGS) \ $(GST_PLUGINS_BASE_CFLAGS) libgstapp_@GST_MAJORMINOR@_la_LIBADD = $(GST_BASE_LIBS) @@ -9,5 +9,6 @@ libgstapp_@GST_MAJORMINOR@_la_LDFLAGS = $(GST_LDFLAGS) libgstapp_@GST_MAJORMINOR@includedir = $(includedir)/gstreamer-@GST_MAJORMINOR@/gst/app libgstapp_@GST_MAJORMINOR@include_HEADERS = \ gstappsrc.h \ - gstappbuffer.h + gstappbuffer.h \ + gstappsink.h diff --git a/gst-libs/gst/app/gstapp.c b/gst-libs/gst/app/gstapp.c deleted file mode 100644 index 077c8707..00000000 --- a/gst-libs/gst/app/gstapp.c +++ /dev/null @@ -1,41 +0,0 @@ -/* GStreamer - * Copyright (C) 2007 David Schleef <ds@schleef.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 "gstappsrc.h" - -static gboolean -plugin_init (GstPlugin * plugin) -{ - GST_DEBUG_CATEGORY_INIT (app_src_debug, "appsrc", 0, "appsrc"); - - return gst_element_register (plugin, "appsrc", GST_RANK_NONE, - GST_TYPE_APP_SRC); -} - -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "app", - "Elements used to communicate with applications", - plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN) diff --git a/gst-libs/gst/app/gstappsink.c b/gst-libs/gst/app/gstappsink.c new file mode 100644 index 00000000..0d94a627 --- /dev/null +++ b/gst-libs/gst/app/gstappsink.c @@ -0,0 +1,269 @@ +/* GStreamer + * Copyright (C) 2007 David Schleef <ds@schleef.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 <gst/base/gstbasesink.h> + +#include <string.h> + +#include "gstappsink.h" + + +GST_DEBUG_CATEGORY (app_sink_debug); +#define GST_CAT_DEFAULT app_sink_debug + +static const GstElementDetails app_sink_details = +GST_ELEMENT_DETAILS ("AppSink", + "FIXME", + "FIXME", + "autogenerated by makefilter"); + +enum +{ + PROP_0 +}; + +static GstStaticPadTemplate gst_app_sink_template = +GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS_ANY); + +static void gst_app_sink_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_app_sink_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); +static void gst_app_sink_dispose (GObject * object); +static gboolean gst_app_sink_start (GstBaseSink * psink); +static gboolean gst_app_sink_stop (GstBaseSink * psink); +static gboolean gst_app_sink_event (GstBaseSink * sink, GstEvent * event); +static GstFlowReturn gst_app_sink_render (GstBaseSink * psink, + GstBuffer * buffer); + +GST_BOILERPLATE (GstAppSink, gst_app_sink, GstBaseSink, GST_TYPE_BASE_SINK); + +static void +gst_app_sink_base_init (gpointer g_class) +{ + GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); + + //GObjectClass *gobject_class = G_OBJECT_CLASS (g_class); + + GST_DEBUG_CATEGORY_INIT (app_sink_debug, "appsink", 0, "appsink element"); + + gst_element_class_set_details (element_class, &app_sink_details); + + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&gst_app_sink_template)); + +} + +static void +gst_app_sink_class_init (GstAppSinkClass * klass) +{ + GObjectClass *gobject_class = (GObjectClass *) klass; + GstBaseSinkClass *basesink_class = (GstBaseSinkClass *) klass; + + gobject_class->set_property = gst_app_sink_set_property; + gobject_class->get_property = gst_app_sink_get_property; + gobject_class->dispose = gst_app_sink_dispose; + + basesink_class->start = gst_app_sink_start; + basesink_class->stop = gst_app_sink_stop; + basesink_class->event = gst_app_sink_event; + basesink_class->render = gst_app_sink_render; +} + +static void +gst_app_sink_dispose (GObject * obj) +{ + GstAppSink *appsink = GST_APP_SINK (obj); + + if (appsink->caps) { + gst_caps_unref (appsink->caps); + appsink->caps = NULL; + } + if (appsink->mutex) { + g_mutex_free (appsink->mutex); + appsink->mutex = NULL; + } + if (appsink->cond) { + g_cond_free (appsink->cond); + appsink->cond = NULL; + } + if (appsink->queue) { + g_queue_free (appsink->queue); + appsink->queue = NULL; + } + + G_OBJECT_CLASS (parent_class)->dispose (obj); +} + +static void +gst_app_sink_init (GstAppSink * appsink, GstAppSinkClass * klass) +{ + appsink->mutex = g_mutex_new (); + appsink->cond = g_cond_new (); + appsink->queue = g_queue_new (); +} + +static void +gst_app_sink_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) +{ + GstAppSink *appsink = GST_APP_SINK (object); + + GST_OBJECT_LOCK (appsink); + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } + GST_OBJECT_UNLOCK (appsink); +} + +static void +gst_app_sink_get_property (GObject * object, guint prop_id, GValue * value, + GParamSpec * pspec) +{ + GstAppSink *appsink = GST_APP_SINK (object); + + GST_OBJECT_LOCK (appsink); + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } + GST_OBJECT_UNLOCK (appsink); +} + +static gboolean +gst_app_sink_start (GstBaseSink * psink) +{ + GstAppSink *appsink = GST_APP_SINK (psink); + + appsink->end_of_stream = FALSE; + + return TRUE; +} + +static gboolean +gst_app_sink_stop (GstBaseSink * psink) +{ + //GstAppSink *appsink = GST_APP_SINK(psink); + + return TRUE; +} + +static gboolean +gst_app_sink_event (GstBaseSink * sink, GstEvent * event) +{ + GstAppSink *appsink = GST_APP_SINK (sink); + + switch (event->type) { + case GST_EVENT_EOS: + appsink->end_of_stream = TRUE; + break; + default: + break; + } + + gst_object_unref (sink); + return FALSE; +} + +static GstFlowReturn +gst_app_sink_render (GstBaseSink * psink, GstBuffer * buffer) +{ + GstAppSink *appsink = GST_APP_SINK (psink); + + g_mutex_lock (appsink->mutex); + g_queue_push_tail (appsink->queue, gst_buffer_ref (buffer)); + g_cond_signal (appsink->cond); + g_mutex_unlock (appsink->mutex); + + return GST_FLOW_OK; +} + + + + +/* external API */ + +/** + * gst_app_sink_set_caps: + * @appsink: + * @caps: + * + * Set the capabilities on the appsink element. This function takes + * ownership of the caps structure. + */ +void +gst_app_sink_set_caps (GstAppSink * appsink, GstCaps * caps) +{ + g_return_if_fail (appsink != NULL); + g_return_if_fail (GST_IS_APP_SINK (appsink)); + + gst_caps_replace (&appsink->caps, caps); +} + +gboolean +gst_app_sink_end_of_stream (GstAppSink * appsink) +{ + gboolean ret; + + g_return_val_if_fail (appsink != NULL, FALSE); + g_return_val_if_fail (GST_IS_APP_SINK (appsink), FALSE); + + g_mutex_lock (appsink->mutex); + if (appsink->end_of_stream && g_queue_is_empty (appsink->queue)) { + ret = TRUE; + } else { + ret = FALSE; + } + g_mutex_unlock (appsink->mutex); + + return ret; +} + +GstBuffer * +gst_app_sink_pull_buffer (GstAppSink * appsink) +{ + GstBuffer *buf = NULL; + + g_return_val_if_fail (appsink != NULL, NULL); + g_return_val_if_fail (GST_IS_APP_SINK (appsink), NULL); + + g_mutex_lock (appsink->mutex); + while (g_queue_is_empty (appsink->queue)) { + if (appsink->end_of_stream) + goto out; + + g_cond_wait (appsink->cond, appsink->mutex); + } + buf = g_queue_pop_head (appsink->queue); +out: + g_mutex_unlock (appsink->mutex); + + return buf; +} diff --git a/gst-libs/gst/app/gstappsink.h b/gst-libs/gst/app/gstappsink.h new file mode 100644 index 00000000..2873e363 --- /dev/null +++ b/gst-libs/gst/app/gstappsink.h @@ -0,0 +1,71 @@ +/* GStreamer + * Copyright (C) 2007 David Schleef <ds@schleef.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. + */ + +#ifndef _GST_APP_SINK_H_ +#define _GST_APP_SINK_H_ + +#include <gst/gst.h> +#include <gst/base/gstbasesink.h> + +G_BEGIN_DECLS + +#define GST_TYPE_APP_SINK \ + (gst_app_sink_get_type()) +#define GST_APP_SINK(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_APP_SINK,GstAppSink)) +#define GST_APP_SINK_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_APP_SINK,GstAppSinkClass)) +#define GST_IS_APP_SINK(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_APP_SINK)) +#define GST_IS_APP_SINK_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_APP_SINK)) + +typedef struct _GstAppSink GstAppSink; +typedef struct _GstAppSinkClass GstAppSinkClass; + +struct _GstAppSink +{ + GstBaseSink basesink; + + /*< private >*/ + GstCaps *caps; + + GCond *cond; + GMutex *mutex; + GQueue *queue; + gboolean end_of_stream; +}; + +struct _GstAppSinkClass +{ + GstBaseSinkClass basesink_class; +}; + +GType gst_app_sink_get_type(void); + +GST_DEBUG_CATEGORY_EXTERN (app_sink_debug); + +void gst_app_sink_set_caps (GstAppSink *appsink, GstCaps *caps); +gboolean gst_app_sink_end_of_stream (GstAppSink *appsink); +GstBuffer *gst_app_sink_pull_buffer (GstAppSink *appsink); + +G_END_DECLS + +#endif + diff --git a/gst/app/gstapp.c b/gst/app/gstapp.c index 6619dfac..098fbdd2 100644 --- a/gst/app/gstapp.c +++ b/gst/app/gstapp.c @@ -24,14 +24,15 @@ #include <gst/gst.h> #include <gst/app/gstappsrc.h> +#include <gst/app/gstappsink.h> static gboolean plugin_init (GstPlugin * plugin) { - GST_DEBUG_CATEGORY_INIT (app_src_debug, "appsrc", 0, "appsrc"); + gst_element_register (plugin, "appsrc", GST_RANK_NONE, GST_TYPE_APP_SRC); + gst_element_register (plugin, "appsink", GST_RANK_NONE, GST_TYPE_APP_SINK); - return gst_element_register (plugin, "appsrc", GST_RANK_NONE, - GST_TYPE_APP_SRC); + return TRUE; } GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, |