2 * Copyright (C) 2010 David Schleef <ds@schleef.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
25 #include <gst/base/gstbasesink.h>
26 #include "gstdebugutilsbadelements.h"
27 #include "gstchecksumsink.h"
29 static void gst_checksum_sink_set_property (GObject * object, guint prop_id,
30 const GValue * value, GParamSpec * pspec);
31 static void gst_checksum_sink_get_property (GObject * object, guint prop_id,
32 GValue * value, GParamSpec * pspec);
33 static void gst_checksum_sink_dispose (GObject * object);
34 static void gst_checksum_sink_finalize (GObject * object);
36 static gboolean gst_checksum_sink_start (GstBaseSink * sink);
37 static gboolean gst_checksum_sink_stop (GstBaseSink * sink);
39 gst_checksum_sink_render (GstBaseSink * sink, GstBuffer * buffer);
47 static GstStaticPadTemplate gst_checksum_sink_sink_template =
48 GST_STATIC_PAD_TEMPLATE ("sink",
53 /* class initialization */
55 #define GST_TYPE_CHECKSUM_SINK_HASH (gst_checksum_sink_hash_get_type ())
57 gst_checksum_sink_hash_get_type (void)
59 static GType gtype = 0;
62 static const GEnumValue values[] = {
63 {G_CHECKSUM_MD5, "MD5", "md5"},
64 {G_CHECKSUM_SHA1, "SHA-1", "sha1"},
65 {G_CHECKSUM_SHA256, "SHA-256", "sha256"},
66 {G_CHECKSUM_SHA512, "SHA-512", "sha512"},
70 gtype = g_enum_register_static ("GstChecksumSinkHash", values);
75 #define gst_checksum_sink_parent_class parent_class
76 G_DEFINE_TYPE (GstChecksumSink, gst_checksum_sink, GST_TYPE_BASE_SINK);
77 GST_ELEMENT_REGISTER_DEFINE (checksumsink, "checksumsink",
78 GST_RANK_NONE, gst_checksum_sink_get_type ());
81 gst_checksum_sink_class_init (GstChecksumSinkClass * klass)
83 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
84 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
85 GstBaseSinkClass *base_sink_class = GST_BASE_SINK_CLASS (klass);
87 gobject_class->set_property = gst_checksum_sink_set_property;
88 gobject_class->get_property = gst_checksum_sink_get_property;
89 gobject_class->dispose = gst_checksum_sink_dispose;
90 gobject_class->finalize = gst_checksum_sink_finalize;
91 base_sink_class->start = GST_DEBUG_FUNCPTR (gst_checksum_sink_start);
92 base_sink_class->stop = GST_DEBUG_FUNCPTR (gst_checksum_sink_stop);
93 base_sink_class->render = GST_DEBUG_FUNCPTR (gst_checksum_sink_render);
95 gst_element_class_add_static_pad_template (element_class,
96 &gst_checksum_sink_sink_template);
98 g_object_class_install_property (gobject_class, PROP_HASH,
99 g_param_spec_enum ("hash", "Hash", "Checksum type",
100 gst_checksum_sink_hash_get_type (), G_CHECKSUM_SHA1,
101 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
103 gst_element_class_set_static_metadata (element_class, "Checksum sink",
104 "Debug/Sink", "Calculates a checksum for buffers",
105 "David Schleef <ds@schleef.org>");
107 gst_type_mark_as_plugin_api (gst_checksum_sink_hash_get_type (), 0);
111 gst_checksum_sink_init (GstChecksumSink * checksumsink)
113 gst_base_sink_set_sync (GST_BASE_SINK (checksumsink), FALSE);
114 checksumsink->hash = G_CHECKSUM_SHA1;
118 gst_checksum_sink_set_property (GObject * object, guint prop_id,
119 const GValue * value, GParamSpec * pspec)
121 GstChecksumSink *checksumsink = GST_CHECKSUM_SINK (object);
125 checksumsink->hash = g_value_get_enum (value);
128 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
134 gst_checksum_sink_get_property (GObject * object, guint prop_id,
135 GValue * value, GParamSpec * pspec)
137 GstChecksumSink *checksumsink = GST_CHECKSUM_SINK (object);
141 g_value_set_enum (value, checksumsink->hash);
144 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
150 gst_checksum_sink_dispose (GObject * object)
152 G_OBJECT_CLASS (parent_class)->dispose (object);
156 gst_checksum_sink_finalize (GObject * object)
158 G_OBJECT_CLASS (parent_class)->finalize (object);
162 gst_checksum_sink_start (GstBaseSink * sink)
168 gst_checksum_sink_stop (GstBaseSink * sink)
174 gst_checksum_sink_render (GstBaseSink * sink, GstBuffer * buffer)
178 GstChecksumSink *checksumsink;
180 checksumsink = GST_CHECKSUM_SINK (sink);
181 gst_buffer_map (buffer, &map, GST_MAP_READ);
182 s = g_compute_checksum_for_data (checksumsink->hash, map.data, map.size);
183 gst_buffer_unmap (buffer, &map);
184 g_print ("%" GST_TIME_FORMAT " %s\n",
185 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)), s);