From 813a2235b5fca3a8f59438849761689a4f73ce6e Mon Sep 17 00:00:00 2001 From: David Schleef Date: Sun, 5 Sep 2010 22:41:24 -0700 Subject: [PATCH] checksumsink: Add new element --- gst/debugutils/Makefile.am | 9 +- gst/debugutils/debugutilsbad.c | 6 +- gst/debugutils/gstchecksumsink.c | 193 +++++++++++++++++++++++++++++++ gst/debugutils/gstchecksumsink.h | 52 +++++++++ 4 files changed, 257 insertions(+), 3 deletions(-) create mode 100644 gst/debugutils/gstchecksumsink.c create mode 100644 gst/debugutils/gstchecksumsink.h diff --git a/gst/debugutils/Makefile.am b/gst/debugutils/Makefile.am index 70e8400cb63..5da49745727 100644 --- a/gst/debugutils/Makefile.am +++ b/gst/debugutils/Makefile.am @@ -14,10 +14,15 @@ EXTRA_DIST = debugutils-marshal.list plugin_LTLIBRARIES = libgstdebugutilsbad.la -libgstdebugutilsbad_la_SOURCES = fpsdisplaysink.c debugutilsbad.c +libgstdebugutilsbad_la_SOURCES = \ + fpsdisplaysink.c \ + debugutilsbad.c \ + gstchecksumsink.c \ + gstchecksumsink.h nodist_libgstdebugutilsbad_la_SOURCES = $(BUILT_SOURCES) libgstdebugutilsbad_la_CFLAGS = $(GST_CFLAGS) $(GST_BASE_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) -libgstdebugutilsbad_la_LIBADD = $(GST_BASE_LIBS) $(GST_PLUGINS_BASE_LIBS) -lgstinterfaces-$(GST_MAJORMINOR) +libgstdebugutilsbad_la_LIBADD = $(GST_BASE_LIBS) $(GST_PLUGINS_BASE_LIBS) \ + -lgstinterfaces-$(GST_MAJORMINOR) $(GST_LIBS) libgstdebugutilsbad_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) libgstdebugutilsbad_la_LIBTOOLFLAGS = --tag=disable-static diff --git a/gst/debugutils/debugutilsbad.c b/gst/debugutils/debugutilsbad.c index b1fb6e0570e..6f574b077c1 100644 --- a/gst/debugutils/debugutilsbad.c +++ b/gst/debugutils/debugutilsbad.c @@ -23,13 +23,17 @@ #include +GType gst_checksum_sink_get_type (void); GType fps_display_sink_get_type (void); static gboolean plugin_init (GstPlugin * plugin) { - return gst_element_register (plugin, "fpsdisplaysink", GST_RANK_NONE, + gst_element_register (plugin, "checksumsink", GST_RANK_NONE, + gst_checksum_sink_get_type ()); + gst_element_register (plugin, "fpsdisplaysink", GST_RANK_NONE, fps_display_sink_get_type ()); + return TRUE; } GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, diff --git a/gst/debugutils/gstchecksumsink.c b/gst/debugutils/gstchecksumsink.c new file mode 100644 index 00000000000..7e6cb5ed40a --- /dev/null +++ b/gst/debugutils/gstchecksumsink.c @@ -0,0 +1,193 @@ +/* GStreamer + * Copyright (C) 2010 David Schleef + * + * 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 "gstchecksumsink.h" + +/* prototypes */ + + +static void gst_checksum_sink_set_property (GObject * object, + guint property_id, const GValue * value, GParamSpec * pspec); +static void gst_checksum_sink_get_property (GObject * object, + guint property_id, GValue * value, GParamSpec * pspec); +static void gst_checksum_sink_dispose (GObject * object); +static void gst_checksum_sink_finalize (GObject * object); + +static gboolean gst_checksum_sink_start (GstBaseSink * sink); +static gboolean gst_checksum_sink_stop (GstBaseSink * sink); +static GstFlowReturn +gst_checksum_sink_render (GstBaseSink * sink, GstBuffer * buffer); + +enum +{ + PROP_0, + PROP_SYNC +}; + +/* pad templates */ + +static GstStaticPadTemplate gst_checksum_sink_sink_template = +GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS_ANY); + +static GstStaticPadTemplate gst_checksum_sink_src_template = +GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS_ANY); + +/* class initialization */ + +GST_BOILERPLATE (GstChecksumSink, gst_checksum_sink, GstBaseSink, + GST_TYPE_BASE_SINK); + +static void +gst_checksum_sink_base_init (gpointer g_class) +{ + GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); + + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&gst_checksum_sink_src_template)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&gst_checksum_sink_sink_template)); + + gst_element_class_set_details_simple (element_class, "Checksum sink", + "Debug/Sink", "Calculates a checksum for buffers", + "David Schleef "); +} + +static void +gst_checksum_sink_class_init (GstChecksumSinkClass * klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GstBaseSinkClass *base_sink_class = GST_BASE_SINK_CLASS (klass); + + gobject_class->set_property = gst_checksum_sink_set_property; + gobject_class->get_property = gst_checksum_sink_get_property; + gobject_class->dispose = gst_checksum_sink_dispose; + gobject_class->finalize = gst_checksum_sink_finalize; + base_sink_class->start = GST_DEBUG_FUNCPTR (gst_checksum_sink_start); + base_sink_class->stop = GST_DEBUG_FUNCPTR (gst_checksum_sink_stop); + base_sink_class->render = GST_DEBUG_FUNCPTR (gst_checksum_sink_render); +} + +static void +gst_checksum_sink_init (GstChecksumSink * checksumsink, + GstChecksumSinkClass * checksumsink_class) +{ + gst_base_sink_set_sync (GST_BASE_SINK (checksumsink), FALSE); + +} + +void +gst_checksum_sink_set_property (GObject * object, guint property_id, + const GValue * value, GParamSpec * pspec) +{ + GstChecksumSink *checksumsink; + + g_return_if_fail (GST_IS_CHECKSUM_SINK (object)); + checksumsink = GST_CHECKSUM_SINK (object); + + switch (property_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +void +gst_checksum_sink_get_property (GObject * object, guint property_id, + GValue * value, GParamSpec * pspec) +{ + GstChecksumSink *checksumsink; + + g_return_if_fail (GST_IS_CHECKSUM_SINK (object)); + checksumsink = GST_CHECKSUM_SINK (object); + + switch (property_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +void +gst_checksum_sink_dispose (GObject * object) +{ + GstChecksumSink *checksumsink; + + g_return_if_fail (GST_IS_CHECKSUM_SINK (object)); + checksumsink = GST_CHECKSUM_SINK (object); + + /* clean up as possible. may be called multiple times */ + + G_OBJECT_CLASS (parent_class)->dispose (object); +} + +void +gst_checksum_sink_finalize (GObject * object) +{ + GstChecksumSink *checksumsink; + + g_return_if_fail (GST_IS_CHECKSUM_SINK (object)); + checksumsink = GST_CHECKSUM_SINK (object); + + /* clean up object here */ + + G_OBJECT_CLASS (parent_class)->finalize (object); +} + + + +static gboolean +gst_checksum_sink_start (GstBaseSink * sink) +{ + + return TRUE; +} + +static gboolean +gst_checksum_sink_stop (GstBaseSink * sink) +{ + + return TRUE; +} + +static GstFlowReturn +gst_checksum_sink_render (GstBaseSink * sink, GstBuffer * buffer) +{ + gchar *s; + + s = g_compute_checksum_for_data (G_CHECKSUM_SHA1, GST_BUFFER_DATA (buffer), + GST_BUFFER_SIZE (buffer)); + g_print ("%" GST_TIME_FORMAT " %s\n", + GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)), s); + + g_free (s); + + return GST_FLOW_OK; +} diff --git a/gst/debugutils/gstchecksumsink.h b/gst/debugutils/gstchecksumsink.h new file mode 100644 index 00000000000..22d01803761 --- /dev/null +++ b/gst/debugutils/gstchecksumsink.h @@ -0,0 +1,52 @@ +/* GStreamer + * Copyright (C) 2010 REAL_NAME + * + * 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_CHECKSUM_SINK_H_ +#define _GST_CHECKSUM_SINK_H_ + +#include +#include + +G_BEGIN_DECLS + +#define GST_TYPE_CHECKSUM_SINK (gst_checksum_sink_get_type()) +#define GST_CHECKSUM_SINK(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_CHECKSUM_SINK,GstChecksumSink)) +#define GST_CHECKSUM_SINK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_CHECKSUM_SINK,GstChecksumSinkClass)) +#define GST_IS_CHECKSUM_SINK(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_CHECKSUM_SINK)) +#define GST_IS_CHECKSUM_SINK_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_CHECKSUM_SINK)) + +typedef struct _GstChecksumSink GstChecksumSink; +typedef struct _GstChecksumSinkClass GstChecksumSinkClass; + +struct _GstChecksumSink +{ + GstBaseSink base_checksumsink; + +}; + +struct _GstChecksumSinkClass +{ + GstBaseSinkClass base_checksumsink_class; +}; + +GType gst_checksum_sink_get_type (void); + +G_END_DECLS + +#endif