From 2830145a7121d3c464a82be356d0fe33e3164dd4 Mon Sep 17 00:00:00 2001 From: Scott D Phillips Date: Tue, 1 Mar 2016 14:54:01 -0800 Subject: [PATCH] checksumsink: add "hash" property and allow more checksum types Now any GChecksumType can be used by GstChecksumSink, adding support for MD5, SHA-256 and SHA-512 in addition to SHA-1. https://bugzilla.gnome.org/show_bug.cgi?id=763006 --- gst/debugutils/gstchecksumsink.c | 78 ++++++++++++++++++++++++++++++++++++++-- gst/debugutils/gstchecksumsink.h | 2 +- 2 files changed, 76 insertions(+), 4 deletions(-) diff --git a/gst/debugutils/gstchecksumsink.c b/gst/debugutils/gstchecksumsink.c index 5a41035..5560a14 100644 --- a/gst/debugutils/gstchecksumsink.c +++ b/gst/debugutils/gstchecksumsink.c @@ -25,6 +25,10 @@ #include #include "gstchecksumsink.h" +static void gst_checksum_sink_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_checksum_sink_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); static void gst_checksum_sink_dispose (GObject * object); static void gst_checksum_sink_finalize (GObject * object); @@ -33,6 +37,12 @@ static gboolean gst_checksum_sink_stop (GstBaseSink * sink); static GstFlowReturn gst_checksum_sink_render (GstBaseSink * sink, GstBuffer * buffer); +enum +{ + PROP_0, + PROP_HASH, +}; + static GstStaticPadTemplate gst_checksum_sink_sink_template = GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, @@ -47,6 +57,26 @@ GST_STATIC_PAD_TEMPLATE ("src", /* class initialization */ +#define GST_TYPE_CHECKSUM_SINK_HASH (gst_checksum_sink_hash_get_type ()) +static GType +gst_checksum_sink_hash_get_type (void) +{ + static GType gtype = 0; + + if (gtype == 0) { + static const GEnumValue values[] = { + {G_CHECKSUM_MD5, "MD5", "md5"}, + {G_CHECKSUM_SHA1, "SHA-1", "sha1"}, + {G_CHECKSUM_SHA256, "SHA-256", "sha256"}, + {G_CHECKSUM_SHA512, "SHA-512", "sha512"}, + {0, NULL, NULL}, + }; + + gtype = g_enum_register_static ("GstChecksumSinkHash", values); + } + return gtype; +} + #define gst_checksum_sink_parent_class parent_class G_DEFINE_TYPE (GstChecksumSink, gst_checksum_sink, GST_TYPE_BASE_SINK); @@ -57,6 +87,8 @@ gst_checksum_sink_class_init (GstChecksumSinkClass * klass) GstElementClass *element_class = GST_ELEMENT_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); @@ -68,6 +100,11 @@ gst_checksum_sink_class_init (GstChecksumSinkClass * klass) gst_element_class_add_static_pad_template (element_class, &gst_checksum_sink_sink_template); + g_object_class_install_property (gobject_class, PROP_HASH, + g_param_spec_enum ("hash", "Hash", "Checksum type", + gst_checksum_sink_hash_get_type (), G_CHECKSUM_SHA1, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + gst_element_class_set_static_metadata (element_class, "Checksum sink", "Debug/Sink", "Calculates a checksum for buffers", "David Schleef "); @@ -77,15 +114,48 @@ static void gst_checksum_sink_init (GstChecksumSink * checksumsink) { gst_base_sink_set_sync (GST_BASE_SINK (checksumsink), FALSE); + checksumsink->hash = G_CHECKSUM_SHA1; +} + +static void +gst_checksum_sink_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) +{ + GstChecksumSink *checksumsink = GST_CHECKSUM_SINK (object); + + switch (prop_id) { + case PROP_HASH: + checksumsink->hash = g_value_get_enum (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gst_checksum_sink_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec) +{ + GstChecksumSink *checksumsink = GST_CHECKSUM_SINK (object); + + switch (prop_id) { + case PROP_HASH: + g_value_set_enum (value, checksumsink->hash); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } -void +static void gst_checksum_sink_dispose (GObject * object) { G_OBJECT_CLASS (parent_class)->dispose (object); } -void +static void gst_checksum_sink_finalize (GObject * object) { G_OBJECT_CLASS (parent_class)->finalize (object); @@ -108,9 +178,11 @@ gst_checksum_sink_render (GstBaseSink * sink, GstBuffer * buffer) { gchar *s; GstMapInfo map; + GstChecksumSink *checksumsink; + checksumsink = GST_CHECKSUM_SINK (sink); gst_buffer_map (buffer, &map, GST_MAP_READ); - s = g_compute_checksum_for_data (G_CHECKSUM_SHA1, map.data, map.size); + s = g_compute_checksum_for_data (checksumsink->hash, map.data, map.size); gst_buffer_unmap (buffer, &map); g_print ("%" GST_TIME_FORMAT " %s\n", GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)), s); diff --git a/gst/debugutils/gstchecksumsink.h b/gst/debugutils/gstchecksumsink.h index d714628..d86ced4 100644 --- a/gst/debugutils/gstchecksumsink.h +++ b/gst/debugutils/gstchecksumsink.h @@ -37,7 +37,7 @@ typedef struct _GstChecksumSinkClass GstChecksumSinkClass; struct _GstChecksumSink { GstBaseSink base_checksumsink; - + GChecksumType hash; }; struct _GstChecksumSinkClass -- 2.7.4