2
* Copyright (C) 2006 Mark Nauwelaerts <mnauw@users.sourceforge.net>
5
* Copyright (C) Thomas Oestreich - June 2001
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02110-1307 USA
23
* SECTION:element-astat
27
* Determines the maximum audio scale value that can safely be applied
28
* (that is, does not lead to clipping of audio samples).
29
* At EOS (end-of-stream), it generates an element message named
30
* <classname>"astat"</classname>.
31
* The message's structure contains only one field,
32
* #gdouble <classname>"scale"</classname>, which is then the
33
* value to use for the <link linkend="GstVolume--volume">volume</link>
34
* property in the <link linkend="GstVolume">volume</link> element.
36
* <title>History</title>
41
* Transcode astat filter [Thomas Oestreich]
54
#include "plugin-tc.h"
59
#define GST_TYPE_ASTAT \
60
(gst_astat_get_type())
61
#define GST_ASTAT(obj) \
62
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_ASTAT,GstAstat))
63
#define GST_ASTAT_CLASS(klass) \
64
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_ASTAT,GstAstatClass))
65
#define GST_IS_ASTAT(obj) \
66
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_ASTAT))
67
#define GST_IS_ASTAT_CLASS(klass) \
68
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_ASTAT))
71
typedef struct _GstAstat GstAstat;
72
typedef struct _GstAstatClass GstAstatClass;
76
GstBaseTransform parent;
84
GstVideoFilterClass parent_class;
87
GST_DEBUG_CATEGORY_STATIC (astat_debug);
88
#define GST_CAT_DEFAULT astat_debug
91
/* signals and args */
105
#define DEFAULT_SHIFT 0
107
static GstElementDetails astat_details =
108
GST_ELEMENT_DETAILS ("Astat",
109
"Filter/Analyzer/Audio",
110
"Audio statistics plugin",
111
"Mark Nauwelaerts <mnauw@users.sourceforge.net>,\n"
114
static GstStaticPadTemplate gst_astat_src_template =
115
GST_STATIC_PAD_TEMPLATE (GST_BASE_TRANSFORM_SRC_NAME,
118
GST_STATIC_CAPS ("audio/x-raw-int, "
119
"rate = (int) [ 1, MAX ], "
120
"channels = (int) [ 1, MAX ], "
121
"endianness = (int) BYTE_ORDER, "
122
"width = (int) { 16 }, "
123
"depth = (int) { 16 }, " "signed = (boolean) true")
126
static GstStaticPadTemplate gst_astat_sink_template =
127
GST_STATIC_PAD_TEMPLATE (GST_BASE_TRANSFORM_SINK_NAME,
130
GST_STATIC_CAPS ("audio/x-raw-int, "
131
"rate = (int) [ 1, MAX ], "
132
"channels = (int) [ 1, MAX ], "
133
"endianness = (int) BYTE_ORDER, "
134
"width = (int) { 16 }, "
135
"depth = (int) { 16 }, " "signed = (boolean) true")
138
static gboolean gst_astat_sink_event (GstBaseTransform * btrans,
140
static GstFlowReturn gst_astat_transform_ip (GstBaseTransform * btrans,
142
static gboolean gst_astat_start (GstBaseTransform * btrans);
143
static gboolean gst_astat_stop (GstBaseTransform * btrans);
145
static void gst_astat_set_property (GObject * object, guint prop_id,
146
const GValue * value, GParamSpec * pspec);
147
static void gst_astat_get_property (GObject * object, guint prop_id,
148
GValue * value, GParamSpec * pspec);
150
GST_BOILERPLATE (GstAstat, gst_astat, GstBaseTransform, GST_TYPE_BASE_TRANSFORM);
154
gst_astat_base_init (gpointer g_class)
156
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
158
gst_element_class_set_details (element_class, &astat_details);
160
gst_element_class_add_pad_template (element_class,
161
gst_static_pad_template_get (&gst_astat_sink_template));
162
gst_element_class_add_pad_template (element_class,
163
gst_static_pad_template_get (&gst_astat_src_template));
167
gst_astat_class_init (GstAstatClass * g_class)
169
GObjectClass *gobject_class;
170
GstBaseTransformClass *trans_class;
172
gobject_class = G_OBJECT_CLASS (g_class);
173
trans_class = GST_BASE_TRANSFORM_CLASS (g_class);
175
GST_DEBUG_CATEGORY_INIT (astat_debug, "astat", 0, "astat");
177
gobject_class->set_property = gst_astat_set_property;
178
gobject_class->get_property = gst_astat_get_property;
180
// g_object_class_install_property (gobject_class, PROP_LUMA_SPATIAL,
181
// g_param_spec_double ("scale", "scale",
182
// "Current maximum volume scale value",
183
// 0.0, 10.0, 1.0, G_PARAM_READABLE));
185
trans_class->event = GST_DEBUG_FUNCPTR (gst_astat_sink_event);
186
// trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_astat_set_caps);
187
trans_class->transform_ip = GST_DEBUG_FUNCPTR (gst_astat_transform_ip);
188
trans_class->start = GST_DEBUG_FUNCPTR (gst_astat_start);
189
trans_class->stop = GST_DEBUG_FUNCPTR (gst_astat_stop);
193
gst_astat_init (GstAstat * filter, GstAstatClass * g_class)
199
gst_astat_sink_event (GstBaseTransform * btrans, GstEvent * event)
203
filter = GST_ASTAT (btrans);
205
switch (GST_EVENT_TYPE (event)) {
206
case GST_EVENT_EOS: {
210
scale = MAX (filter->max, ABS (filter->min));
212
scale = (double) (-G_MININT16) / scale;
215
m = gst_message_new_element (GST_OBJECT (filter),
216
gst_structure_new ("astat", "scale", G_TYPE_DOUBLE, scale, NULL));
217
gst_element_post_message (GST_ELEMENT (filter), m);
224
return GST_BASE_TRANSFORM_CLASS (parent_class)->event (btrans, event);
229
gst_astat_transform_ip (GstBaseTransform * btrans, GstBuffer * in)
235
filter = GST_ASTAT (btrans);
237
src = (gint16 *) GST_BUFFER_DATA (in);
239
for (y = 0; y < GST_BUFFER_SIZE (in) >> 1; y++) {
240
if (*src > filter->max)
242
else if (*src < filter->min)
251
gst_astat_start (GstBaseTransform * btrans)
255
filter = GST_ASTAT (btrans);
257
filter->max = filter->min = 0;
263
gst_astat_stop (GstBaseTransform * btrans)
269
gst_astat_set_property (GObject * object, guint prop_id,
270
const GValue * value, GParamSpec * pspec)
274
g_return_if_fail (GST_IS_ASTAT (object));
275
src = GST_ASTAT (object);
279
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
285
gst_astat_get_property (GObject * object, guint prop_id, GValue * value,
290
g_return_if_fail (GST_IS_ASTAT (object));
291
src = GST_ASTAT (object);
295
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);