[aravis] gst: basic gstreamer source plugin.



commit 153ba2eed45563baa35b5a54721451bf86a10c2e
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Thu Apr 22 11:19:25 2010 +0200

    gst: basic gstreamer source plugin.

 Makefile.am      |    2 +-
 configure.ac     |   21 ++++-
 gst/Makefile.am  |   28 +++++
 gst/arv-gst-test |    3 +
 gst/arvgst.c     |  316 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 gst/arvgst.h     |   62 +++++++++++
 6 files changed, 430 insertions(+), 2 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 9d226e5..ba93c6f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2,7 +2,7 @@ ACLOCAL_AMFLAGS = -I m4
 
 DISTCHECK_CONFIGURE_FLAGS = --enable-introspection
 
-SUBDIRS = src po
+SUBDIRS = src gst po
 
 aravisdocdir = ${prefix}/doc/aravis
 aravisdoc_DATA = 	\
diff --git a/configure.ac b/configure.ac
index ae54054..b5d46d3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -28,7 +28,14 @@ IT_PROG_INTLTOOL([0.31.2])
 
 LT_INIT()
 
-AC_ARG_ENABLE(cairo, [  --enable-cairo          Enable cairo support], [enable_cairo=$enableval], [enable_cairo=no])
+AC_ARG_ENABLE(cairo,
+	      [  --enable-cairo          Enable cairo support],
+	      [enable_cairo=$enableval],
+	      [enable_cairo=no])
+AC_ARG_ENABLE(gstreamer,
+	      [  --enable-gstreamer      Enable gstreamer support],
+	      [enable_gstreamer=$enableval],
+	      [enable_gstreamer=no])
 
 PKG_PROG_PKG_CONFIG([0.14])
 
@@ -44,6 +51,16 @@ if test "x$enable_cairo" = "xyes"; then
 fi
 AM_CONDITIONAL(ARAVIS_WITH_CAIRO, test "x$with_cairo" = "xyes")
 
+with_gstreamer=no
+if test "x$enable_gstreamer" = "xyes"; then
+	PKG_CHECK_MODULES([GSTREAMER],   [gstreamer-base-0.10 >= 0.10],
+			  [AC_DEFINE([ARAVIS_WITH_GSTREAMER], [1], [Cairo support])
+			  ARAVIS_REQUIRES+=" [gstreamer-base-0.10 >= 0.10]"
+			  with_gstreamer=yes],
+			  [echo -n])
+fi
+AM_CONDITIONAL(ARAVIS_WITH_GSTREAMER, test "x$with_gstreamer" = "xyes")
+
 PKG_CHECK_MODULES(ARAVIS, $ARAVIS_REQUIRES)
 
 AC_SUBST(ARAVIS_CFLAGS)
@@ -56,6 +73,7 @@ GOBJECT_INTROSPECTION_CHECK([0.6.7])
 AC_CONFIG_FILES([
 Makefile
 src/Makefile
+gst/Makefile
 po/Makefile.in
 aravis.pc
 ])
@@ -65,6 +83,7 @@ echo ""
 echo "Configuration:"
 echo ""
 echo "	Cairo support:		$with_cairo"
+echo "	Gstreamer support:	$with_gstreamer"
 echo "	Compiler:		${CC}"
 echo "	Compiler flags:		${ARAVIS_CFLAGS}"
 echo ""
diff --git a/gst/Makefile.am b/gst/Makefile.am
new file mode 100644
index 0000000..bd8ffc8
--- /dev/null
+++ b/gst/Makefile.am
@@ -0,0 +1,28 @@
+INCLUDES = \
+	-DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
+	-DPACKAGE_SRC_DIR=\""$(srcdir)"\" \
+	-DPACKAGE_DATA_DIR=\""$(datadir)"\" $(ARAVIS_CFLAGS) \
+	-DG_LOG_DOMAIN=\"Aravis\"
+
+AM_CFLAGS =\
+	 -Wall\
+	 -Werror \
+	 -g \
+	 -O0
+
+if ARAVIS_WITH_GSTREAMER
+
+lib_LTLIBRARIES = libaravis-gst.la
+
+libaravis_gst_la_LIBADD =			\
+	$(ARAVIS_LIBS)
+
+libaravis_gst_la_SOURCES =			\
+	arvgst.c
+
+libaravis_gst_la_HEADERS =			\
+	arvgst.h
+
+libaravis_gst_ladir = $(includedir)/aravis
+
+endif
diff --git a/gst/arv-gst-test b/gst/arv-gst-test
new file mode 100755
index 0000000..7098c7f
--- /dev/null
+++ b/gst/arv-gst-test
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+LD_PRELOAD=../src/.libs/libaravis.so gst-launch-0.10 --gst-plugin-load=.libs/libaravis-gst.so -v aravissrc width=512 height=512 ! ffmpegcolorspace ! autovideosink
diff --git a/gst/arvgst.c b/gst/arvgst.c
new file mode 100644
index 0000000..162a9a4
--- /dev/null
+++ b/gst/arvgst.c
@@ -0,0 +1,316 @@
+/*
+ * Copyright © 2006 Eric Jonas <jonas mit edu>
+ * Copyright © 2006 Antoine Tremblay <hexa00 gmail com>
+ * Copyright © 2010 United States Government, Joshua M. Doe <joshua doe us army mil>
+ * Copyright © 2010 Emmanuel Pacaud <emmanuel gnome 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.
+ */
+
+/**
+ * SECTION:element-aravissrc
+ *
+ * Source using the Aravis vision library (GigE Vision cameras)
+ * 
+ * <refsect2>
+ * <title>Example launch line</title>
+ * |[
+ * gst-launch -v aravissrc ! ffmpegcolorspace ! autovideosink
+ * ]|
+ * </refsect2>
+ */
+
+#include <arvgst.h>
+#include <time.h>
+#include <string.h>
+
+#define GST_ARAVIS_N_BUFFERS	50
+
+GST_DEBUG_CATEGORY_STATIC (aravis_debug);
+#define GST_CAT_DEFAULT aravis_debug
+
+static GstElementDetails aravis_details =
+GST_ELEMENT_DETAILS ("Aravis Video Source",
+		     "Source/Video",
+		     "Aravis based source, supports GigE Vision cameras",
+		     "Emmanuel Pacaud <emmanuel gnome org>");
+
+enum
+{
+  PROP_0,
+  PROP_WIDTH,
+  PROP_HEIGHT
+};
+
+GST_BOILERPLATE (GstAravis, gst_aravis, GstPushSrc, GST_TYPE_PUSH_SRC);
+
+static GstStaticPadTemplate aravis_src_template = GST_STATIC_PAD_TEMPLATE ("src",
+									   GST_PAD_SRC,
+									   GST_PAD_ALWAYS,
+									   GST_STATIC_CAPS ("ANY"));
+
+GstCaps *
+gst_aravis_get_camera_caps (GstAravis *gst_aravis)
+{
+	GstCaps *gcaps = NULL;
+	GstStructure *gs;
+
+	GST_LOG_OBJECT (gst_aravis, "Get camera caps");
+
+	gcaps = gst_caps_new_empty ();
+
+	gs = gst_structure_empty_new ("video");
+	gst_structure_set_name (gs, "video/x-raw-gray");
+	gst_structure_set (gs,
+			   "bpp", G_TYPE_INT, 8,
+			   "depth", G_TYPE_INT, 8,
+			   "width", G_TYPE_INT, gst_aravis->width,
+			   "height", G_TYPE_INT, gst_aravis->height,
+			   NULL);
+
+	gst_structure_set(gs, "framerate", GST_TYPE_FRACTION, 50, 1, NULL);
+	gst_caps_append_structure (gcaps, gs);
+
+	return gcaps;
+}
+
+static GstCaps *
+gst_aravis_get_caps (GstBaseSrc * src)
+{
+	GstAravis* gst_aravis = GST_ARAVIS(src);
+
+	if (gst_aravis->caps != NULL)
+		return gst_caps_copy (gst_aravis->caps);
+
+	return gst_caps_new_any ();
+}
+
+static gboolean
+gst_aravis_start (GstBaseSrc *src)
+{
+	GstAravis* gst_aravis = GST_ARAVIS(src);
+	int i;
+
+	g_message ("start");
+
+	GST_LOG_OBJECT (gst_aravis, "Opening first available camera");
+
+	if (gst_aravis->camera != NULL)
+		g_object_unref (gst_aravis->camera);
+	if (gst_aravis->stream != NULL)
+		g_object_unref (gst_aravis->stream);
+
+	gst_aravis->camera = arv_camera_new (NULL);
+	gst_aravis->stream = arv_camera_new_stream (gst_aravis->camera, NULL, NULL);
+	gst_aravis->caps = gst_aravis_get_camera_caps (gst_aravis);
+
+	arv_camera_set_region (gst_aravis->camera, 0, 0, gst_aravis->width, gst_aravis->height);
+	gst_aravis->payload = arv_camera_get_payload (gst_aravis->camera);
+
+	for (i = 0; i < GST_ARAVIS_N_BUFFERS; i++)
+		arv_stream_push_buffer (gst_aravis->stream,
+					arv_buffer_new (gst_aravis->payload, NULL));
+
+	GST_LOG_OBJECT (gst_aravis, "Starting acquisition");
+
+	arv_camera_start_acquisition (gst_aravis->camera);
+
+	return TRUE;
+}
+
+
+gboolean gst_aravis_stop( GstBaseSrc * src )
+{
+        GstAravis* gst_aravis = GST_ARAVIS(src);
+
+	arv_camera_stop_acquisition (gst_aravis->camera);
+
+	g_object_unref (gst_aravis->stream);
+	g_object_unref (gst_aravis->camera);
+	gst_caps_unref (gst_aravis->caps);
+
+	gst_aravis->camera = NULL;
+	gst_aravis->stream = NULL;
+	gst_aravis->caps = NULL;
+
+        GST_DEBUG_OBJECT (gst_aravis, "Capture stoped");
+
+        return TRUE;
+}
+
+static GstFlowReturn
+gst_aravis_create (GstPushSrc * push_src, GstBuffer ** buffer)
+{
+	GstAravis *gst_aravis;
+	ArvBuffer *arv_buffer;
+
+	gst_aravis = GST_ARAVIS (push_src);
+
+	*buffer = gst_buffer_new ();
+	do {
+		arv_buffer = arv_stream_pop_buffer (gst_aravis->stream);
+		if (arv_buffer == NULL)
+			g_usleep (20000);
+	} while (arv_buffer == NULL);
+	GST_BUFFER_DATA (*buffer) = arv_buffer->data;
+	GST_BUFFER_MALLOCDATA (*buffer) = NULL;
+	GST_BUFFER_SIZE (*buffer) = gst_aravis->payload;
+
+	arv_stream_push_buffer (gst_aravis->stream, arv_buffer);
+
+	gst_buffer_set_caps (*buffer, gst_aravis->caps);
+
+	return GST_FLOW_OK;
+}
+
+
+static void
+gst_aravis_init (GstAravis *gst_aravis, GstAravisClass *g_class)
+{
+	gst_base_src_set_live (GST_BASE_SRC (gst_aravis), TRUE);
+
+	gst_aravis->width = 320;
+	gst_aravis->height = 200;
+	gst_aravis->payload = 0;
+
+	gst_aravis->camera = NULL;
+	gst_aravis->stream = NULL;
+
+	gst_aravis->caps = NULL;
+}
+
+static void
+gst_aravis_finalize (GObject * object)
+{
+        GstAravis *gst_aravis = GST_ARAVIS (object);
+
+	if (gst_aravis->camera != NULL) {
+		g_object_unref (gst_aravis->camera);
+		gst_aravis->camera = NULL;
+	}
+	if (gst_aravis->stream != NULL) {
+		g_object_unref (gst_aravis->stream);
+		gst_aravis->stream = NULL;
+	}
+	if (gst_aravis->caps != NULL) {
+		gst_caps_unref (gst_aravis->caps);
+		gst_aravis->caps = NULL;
+	}
+
+        G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+gst_aravis_set_property (GObject * object, guint prop_id,
+			 const GValue * value, GParamSpec * pspec)
+{
+	GstAravis *gst_aravis = GST_ARAVIS (object);
+
+	switch (prop_id) {
+		case PROP_WIDTH:
+			gst_aravis->width = g_value_get_int (value);
+			break;
+		case PROP_HEIGHT:
+			gst_aravis->height = g_value_get_int (value);
+			break;
+		default:
+			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+			break;
+	}
+}
+
+static void
+gst_aravis_get_property (GObject * object, guint prop_id, GValue * value,
+			 GParamSpec * pspec)
+{
+	GstAravis *gst_aravis = GST_ARAVIS (object);
+
+	switch (prop_id) {
+		case PROP_WIDTH:
+			g_value_set_int (value, gst_aravis->width);
+			break;
+		case PROP_HEIGHT:
+			g_value_set_int (value, gst_aravis->height);
+			break;
+		default:
+			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+			break;
+	}
+}
+
+static void
+gst_aravis_base_init (gpointer g_class)
+{
+	GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
+
+	gst_element_class_set_details (element_class, &aravis_details);
+
+	gst_element_class_add_pad_template (element_class,
+					    gst_static_pad_template_get (&aravis_src_template));
+}
+
+static void
+gst_aravis_class_init (GstAravisClass * klass)
+{
+	GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+	GstBaseSrcClass *gstbasesrc_class = GST_BASE_SRC_CLASS (klass);
+	GstPushSrcClass *gstpushsrc_class = GST_PUSH_SRC_CLASS (klass);
+
+	gobject_class->finalize = gst_aravis_finalize;
+	gobject_class->set_property = gst_aravis_set_property;
+	gobject_class->get_property = gst_aravis_get_property;
+
+	g_object_class_install_property
+		(gobject_class,
+		 PROP_WIDTH,
+		 g_param_spec_int ("width",
+				   "Image width",
+				   "Image width (in pixels)",
+				   1, G_MAXINT, 320,
+				   G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+	g_object_class_install_property
+		(gobject_class,
+		 PROP_HEIGHT,
+		 g_param_spec_int ("height",
+				   "Image height",
+				   "Image height (in pixels)",
+				   1, G_MAXINT, 320,
+				   G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+        GST_DEBUG_CATEGORY_INIT (aravis_debug, "aravis", 0, "Aravis interface");
+
+	gstbasesrc_class->get_caps = gst_aravis_get_caps;
+	gstbasesrc_class->start = gst_aravis_start;
+	gstbasesrc_class->stop = gst_aravis_stop;
+
+	gstpushsrc_class->create = gst_aravis_create;
+}
+
+static gboolean
+plugin_init (GstPlugin * plugin)
+{
+        return gst_element_register (plugin, "aravissrc", GST_RANK_NONE, GST_TYPE_ARAVIS);
+}
+
+GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
+		   GST_VERSION_MINOR,
+		   "aravissrc",
+		   "Aravis Video Source",
+		   plugin_init,
+		   VERSION,
+		   "LGPL",
+		   PACKAGE_NAME,
+		   "http://blogs.gnome.org/emmanuel";)
diff --git a/gst/arvgst.h b/gst/arvgst.h
new file mode 100644
index 0000000..3c33c99
--- /dev/null
+++ b/gst/arvgst.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright © 2006 Eric Jonas <jonas mit edu>
+ * Copyright © 2006 Antoine Tremblay <hexa00 gmail com>
+ * Copyright © 2010 United States Government, Joshua M. Doe <joshua doe us army mil>
+ * Copyright © 2010 Emmanuel Pacaud <emmanuel gnome 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 ARV_GST_H
+#define ARV_GST_H
+
+#include <gst/gst.h>
+#include <gst/base/gstpushsrc.h>
+#include <arv.h>
+
+G_BEGIN_DECLS
+
+#define GST_TYPE_ARAVIS 		(gst_aravis_get_type())
+#define GST_ARAVIS(obj)			(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_ARAVIS,GstAravis))
+#define GST_ARAVIS_CLASS(klass) 	(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_ARAVIS,GstAravis))
+#define GST_IS_ARAVIS(obj) 		(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_ARAVIS))
+#define GST_IS_ARAVIS_CLASS(obj)	(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_ARAVIS))
+
+typedef struct _GstAravis GstAravis;
+typedef struct _GstAravisClass GstAravisClass;
+
+struct _GstAravis {
+	GstPushSrc element;
+
+	gint width;
+	gint height;
+	gint payload;
+
+	ArvCamera *camera;
+	ArvStream *stream;
+
+	GstCaps *caps;
+};
+
+struct _GstAravisClass {
+	GstPushSrcClass parent_class;
+};
+
+GType gst_aravis_get_type (void);
+
+G_END_DECLS
+
+#endif



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]