2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
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., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
25 static GstElementDetails level_details = {
28 "RMS Level indicator for audio/raw",
30 "Thomas <thomas@apestaart.org>",
35 /* Filter signals and args */
45 static GstPadTemplate*
46 level_src_factory (void)
48 static GstPadTemplate *template = NULL;
51 template = gst_padtemplate_new (
59 "channels", GST_PROPS_INT_RANGE (1, 2),
66 static GstPadTemplate*
67 level_sink_factory (void)
69 static GstPadTemplate *template = NULL;
72 template = gst_padtemplate_new (
80 "channels", GST_PROPS_INT_RANGE (1, 2),
87 static void gst_level_class_init (GstLevelClass *klass);
88 static void gst_level_init (GstLevel *filter);
90 static void gst_level_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
91 static void gst_level_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
93 static void gst_level_chain (GstPad *pad, GstBuffer *buf);
94 static void inline gst_level_fast_16bit_chain (gint16* data, gint16** out_data,
96 static void inline gst_level_fast_8bit_chain (gint8* data, gint8** out_data,
99 static GstElementClass *parent_class = NULL;
100 //static guint gst_filter_signals[LAST_SIGNAL] = { 0 };
103 gst_level_get_type(void) {
104 static GType level_type = 0;
107 static const GTypeInfo level_info = {
108 sizeof(GstLevelClass), NULL,
110 (GClassInitFunc)gst_level_class_init,
115 (GInstanceInitFunc)gst_level_init,
117 level_type = g_type_register_static(GST_TYPE_ELEMENT, "GstLevel", &level_info, 0);
123 gst_level_class_init (GstLevelClass *klass)
125 GObjectClass *gobject_class;
126 GstElementClass *gstelement_class;
128 gobject_class = (GObjectClass*)klass;
129 gstelement_class = (GstElementClass*)klass;
131 parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
133 gobject_class->set_property = gst_level_set_property;
134 gobject_class->get_property = gst_level_get_property;
138 gst_level_init (GstLevel *filter)
140 filter->sinkpad = gst_pad_new_from_template(level_sink_factory (),"sink");
141 filter->srcpad = gst_pad_new_from_template(level_src_factory (),"src");
143 gst_element_add_pad(GST_ELEMENT(filter),filter->sinkpad);
144 gst_pad_set_chain_function(filter->sinkpad,gst_level_chain);
145 filter->srcpad = gst_pad_new("src",GST_PAD_SRC);
146 gst_element_add_pad(GST_ELEMENT(filter),filter->srcpad);
150 gst_level_chain (GstPad *pad,GstBuffer *buf)
160 g_return_if_fail(pad != NULL);
161 g_return_if_fail(GST_IS_PAD(pad));
162 g_return_if_fail(buf != NULL);
164 filter = GST_LEVEL(GST_OBJECT_PARENT (pad));
165 g_return_if_fail(filter != NULL);
166 g_return_if_fail(GST_IS_LEVEL(filter));
169 caps = GST_PAD_CAPS(pad);
172 // FIXME : Please change this to a better warning method !
173 printf ("WARNING : chain : Could not get caps of pad !\n");
176 width = gst_caps_get_int(caps, "width");
178 in_data = (gint16 *)GST_BUFFER_DATA(buf);
179 outbuf=gst_buffer_new();
180 GST_BUFFER_DATA(outbuf) = (gchar*)g_new(gint16,GST_BUFFER_SIZE(buf)/2);
181 GST_BUFFER_SIZE(outbuf) = GST_BUFFER_SIZE(buf);
183 out_data = (gint16*)GST_BUFFER_DATA(outbuf);
187 gst_level_fast_16bit_chain(in_data,&out_data,GST_BUFFER_SIZE(buf)/2);
190 gst_level_fast_8bit_chain((gint8*)in_data,(gint8**)&out_data,GST_BUFFER_SIZE(buf));
193 gst_buffer_unref(buf);
194 gst_pad_push(filter->srcpad,outbuf);
198 gst_level_fast_16bit_chain(gint16* in_data, gint16** out_data,
200 #include "filter.func"
203 gst_level_fast_8bit_chain(gint8* in_data, gint8** out_data,
205 #include "filter.func"
208 gst_level_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
212 /* it's not null if we got it, but it might not be ours */
213 g_return_if_fail(GST_IS_LEVEL(object));
214 filter = GST_LEVEL(object);
223 gst_level_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
227 /* it's not null if we got it, but it might not be ours */
228 g_return_if_fail(GST_IS_LEVEL(object));
229 filter = GST_LEVEL(object);
233 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
239 plugin_init (GModule *module, GstPlugin *plugin)
241 GstElementFactory *factory;
243 factory = gst_elementfactory_new("level",GST_TYPE_LEVEL,
245 g_return_val_if_fail(factory != NULL, FALSE);
247 gst_elementfactory_add_padtemplate (factory, level_src_factory ());
248 gst_elementfactory_add_padtemplate (factory, level_sink_factory ());
250 gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
255 GstPluginDesc plugin_desc = {