~ubuntu-branches/ubuntu/natty/gst-entrans/natty

« back to all changes in this revision

Viewing changes to gst/transcode/gstastat.c

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2010-09-13 19:49:29 UTC
  • Revision ID: james.westby@ubuntu.com-20100913194929-qz90a14xyxln9yfz
Tags: upstream-0.10.2
ImportĀ upstreamĀ versionĀ 0.10.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GStreamer Filter
 
2
 * Copyright (C) 2006 Mark Nauwelaerts <mnauw@users.sourceforge.net>
 
3
 *
 
4
 * transcode filter:
 
5
 * Copyright (C) Thomas Oestreich - June 2001
 
6
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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
 
20
 */
 
21
 
 
22
/**
 
23
 * SECTION:element-astat
 
24
 *
 
25
 * <refsect2>
 
26
 * <para>
 
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>&quot;astat&quot;</classname>.
 
31
 * The message's structure contains only one field,
 
32
 * #gdouble <classname>&quot;scale&quot;</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.
 
35
 * </para>
 
36
 * <title>History</title>
 
37
 * <para>
 
38
 * <itemizedlist>
 
39
 * <listitem>
 
40
 * <para>
 
41
 * Transcode astat filter [Thomas Oestreich]
 
42
 * </para>
 
43
 * </listitem>
 
44
 * </itemizedlist>
 
45
 * </para>
 
46
 * </refsect2>
 
47
 *
 
48
 */
 
49
 
 
50
#ifdef HAVE_CONFIG_H
 
51
#include "config.h"
 
52
#endif
 
53
 
 
54
#include "plugin-tc.h"
 
55
 
 
56
#include <string.h>
 
57
 
 
58
 
 
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))
 
69
 
 
70
 
 
71
typedef struct _GstAstat GstAstat;
 
72
typedef struct _GstAstatClass GstAstatClass;
 
73
 
 
74
struct _GstAstat
 
75
{
 
76
  GstBaseTransform parent;
 
77
 
 
78
  gint min, max;
 
79
};
 
80
 
 
81
 
 
82
struct _GstAstatClass
 
83
{
 
84
  GstVideoFilterClass parent_class;
 
85
};
 
86
 
 
87
GST_DEBUG_CATEGORY_STATIC (astat_debug);
 
88
#define GST_CAT_DEFAULT astat_debug
 
89
 
 
90
 
 
91
/* signals and args */
 
92
enum
 
93
{
 
94
  /* FILL ME */
 
95
  LAST_SIGNAL
 
96
};
 
97
 
 
98
enum
 
99
{
 
100
  PROP_0,
 
101
  PROP_SHIFT
 
102
      /* FILL ME */
 
103
};
 
104
 
 
105
#define DEFAULT_SHIFT      0
 
106
 
 
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"
 
112
    "Thomas Oestreich");
 
113
 
 
114
static GstStaticPadTemplate gst_astat_src_template =
 
115
GST_STATIC_PAD_TEMPLATE (GST_BASE_TRANSFORM_SRC_NAME,
 
116
    GST_PAD_SRC,
 
117
    GST_PAD_ALWAYS,
 
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")
 
124
    );
 
125
 
 
126
static GstStaticPadTemplate gst_astat_sink_template =
 
127
GST_STATIC_PAD_TEMPLATE (GST_BASE_TRANSFORM_SINK_NAME,
 
128
    GST_PAD_SINK,
 
129
    GST_PAD_ALWAYS,
 
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")
 
136
    );
 
137
 
 
138
static gboolean gst_astat_sink_event (GstBaseTransform * btrans,
 
139
    GstEvent * event);
 
140
static GstFlowReturn gst_astat_transform_ip (GstBaseTransform * btrans,
 
141
    GstBuffer * in);
 
142
static gboolean gst_astat_start (GstBaseTransform * btrans);
 
143
static gboolean gst_astat_stop (GstBaseTransform * btrans);
 
144
 
 
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);
 
149
 
 
150
GST_BOILERPLATE (GstAstat, gst_astat, GstBaseTransform, GST_TYPE_BASE_TRANSFORM);
 
151
 
 
152
 
 
153
static void
 
154
gst_astat_base_init (gpointer g_class)
 
155
{
 
156
  GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
 
157
 
 
158
  gst_element_class_set_details (element_class, &astat_details);
 
159
 
 
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));
 
164
}
 
165
 
 
166
static void
 
167
gst_astat_class_init (GstAstatClass * g_class)
 
168
{
 
169
  GObjectClass *gobject_class;
 
170
  GstBaseTransformClass *trans_class;
 
171
 
 
172
  gobject_class = G_OBJECT_CLASS (g_class);
 
173
  trans_class = GST_BASE_TRANSFORM_CLASS (g_class);
 
174
 
 
175
  GST_DEBUG_CATEGORY_INIT (astat_debug, "astat", 0, "astat");
 
176
 
 
177
  gobject_class->set_property = gst_astat_set_property;
 
178
  gobject_class->get_property = gst_astat_get_property;
 
179
 
 
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));
 
184
 
 
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);
 
190
}
 
191
 
 
192
static void
 
193
gst_astat_init (GstAstat * filter, GstAstatClass * g_class)
 
194
{
 
195
 
 
196
}
 
197
 
 
198
static gboolean
 
199
gst_astat_sink_event (GstBaseTransform * btrans, GstEvent * event)
 
200
{
 
201
  GstAstat *filter;
 
202
 
 
203
  filter = GST_ASTAT (btrans);
 
204
 
 
205
  switch (GST_EVENT_TYPE (event)) {
 
206
    case GST_EVENT_EOS: {
 
207
      gdouble scale;
 
208
      GstMessage *m;
 
209
 
 
210
      scale = MAX (filter->max, ABS (filter->min));
 
211
      if (scale)
 
212
        scale = (double) (-G_MININT16) / scale;
 
213
      else
 
214
        scale = 1.0;
 
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);
 
218
      break;
 
219
    }
 
220
    default:
 
221
      break;
 
222
  }
 
223
 
 
224
  return GST_BASE_TRANSFORM_CLASS (parent_class)->event (btrans, event);
 
225
}
 
226
 
 
227
 
 
228
static GstFlowReturn
 
229
gst_astat_transform_ip (GstBaseTransform * btrans, GstBuffer * in)
 
230
{
 
231
  GstAstat *filter;
 
232
  gint16 *src;
 
233
  guint y;
 
234
 
 
235
  filter = GST_ASTAT (btrans);
 
236
 
 
237
  src = (gint16 *) GST_BUFFER_DATA (in);
 
238
 
 
239
  for (y = 0; y < GST_BUFFER_SIZE (in) >> 1; y++) {
 
240
    if (*src > filter->max)
 
241
      filter->max = *src;
 
242
    else if (*src < filter->min)
 
243
      filter->min = *src;
 
244
  }
 
245
 
 
246
  return GST_FLOW_OK;
 
247
}
 
248
 
 
249
 
 
250
static gboolean
 
251
gst_astat_start (GstBaseTransform * btrans)
 
252
{
 
253
  GstAstat *filter;
 
254
 
 
255
  filter = GST_ASTAT (btrans);
 
256
 
 
257
  filter->max = filter->min = 0;
 
258
 
 
259
  return TRUE;
 
260
}
 
261
 
 
262
static gboolean
 
263
gst_astat_stop (GstBaseTransform * btrans)
 
264
{
 
265
  return TRUE;
 
266
}
 
267
 
 
268
static void
 
269
gst_astat_set_property (GObject * object, guint prop_id,
 
270
    const GValue * value, GParamSpec * pspec)
 
271
{
 
272
  GstAstat *src;
 
273
 
 
274
  g_return_if_fail (GST_IS_ASTAT (object));
 
275
  src = GST_ASTAT (object);
 
276
 
 
277
  switch (prop_id) {
 
278
    default:
 
279
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
280
      break;
 
281
  }
 
282
}
 
283
 
 
284
static void
 
285
gst_astat_get_property (GObject * object, guint prop_id, GValue * value,
 
286
    GParamSpec * pspec)
 
287
{
 
288
  GstAstat *src;
 
289
 
 
290
  g_return_if_fail (GST_IS_ASTAT (object));
 
291
  src = GST_ASTAT (object);
 
292
 
 
293
  switch (prop_id) {
 
294
    default:
 
295
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
296
      break;
 
297
  }
 
298
}