Merging gst-docs
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-base / gst / audioresample / gstaudioresample.c
1 /* GStreamer
2  * Copyright (C) 1999 Erik Walthinsen <omega@cse.ogi.edu>
3  * Copyright (C) 2003,2004 David A. Schleef <ds@schleef.org>
4  * Copyright (C) 2007-2008 Sebastian Dröge <sebastian.droege@collabora.co.uk>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21
22 /**
23  * SECTION:element-audioresample
24  * @title: audioresample
25  *
26  * audioresample resamples raw audio buffers to different sample rates using
27  * a configurable windowing function to enhance quality.
28  *
29  * By default, the resampler uses a reduced sinc table, with cubic interpolation filling in
30  * the gaps. This ensures that the table does not become too big. However, the interpolation
31  * increases the CPU usage considerably. As an alternative, a full sinc table can be used.
32  * Doing so can drastically reduce CPU usage (4x faster with 44.1 -> 48 kHz conversions for
33  * example), at the cost of increased memory consumption, plus the sinc table takes longer
34  * to initialize when the element is created. A third mode exists, which uses the full table
35  * unless said table would become too large, in which case the interpolated one is used instead.
36  *
37  * ## Example launch line
38  * |[
39  * gst-launch-1.0 -v uridecodebin uri=file:///path/to/audio.ogg ! audioconvert ! audioresample ! audio/x-raw, rate=8000 ! autoaudiosink
40  * ]|
41  *  Decode an audio file and downsample it to 8Khz and play sound.
42  * To create the Ogg/Vorbis file refer to the documentation of vorbisenc.
43  * This assumes there is an audio sink that will accept/handle 8kHz audio.
44  *
45  */
46
47 /* TODO:
48  *  - Enable SSE/ARM optimizations and select at runtime
49  */
50
51 #ifdef HAVE_CONFIG_H
52 #include "config.h"
53 #endif
54
55 #include <string.h>
56 #include <math.h>
57
58 #include "gstaudioresample.h"
59 #include <gst/gstutils.h>
60 #include <gst/audio/audio.h>
61 #include <gst/base/gstbasetransform.h>
62
63 GST_DEBUG_CATEGORY (audio_resample_debug);
64 #define GST_CAT_DEFAULT audio_resample_debug
65
66 #undef USE_SPEEX
67
68 #define DEFAULT_QUALITY GST_AUDIO_RESAMPLER_QUALITY_DEFAULT
69 #define DEFAULT_RESAMPLE_METHOD GST_AUDIO_RESAMPLER_METHOD_KAISER
70 #define DEFAULT_SINC_FILTER_MODE GST_AUDIO_RESAMPLER_FILTER_MODE_AUTO
71 #define DEFAULT_SINC_FILTER_AUTO_THRESHOLD (1*1048576)
72 #define DEFAULT_SINC_FILTER_INTERPOLATION GST_AUDIO_RESAMPLER_FILTER_INTERPOLATION_CUBIC
73
74 enum
75 {
76   PROP_0,
77   PROP_QUALITY,
78   PROP_RESAMPLE_METHOD,
79   PROP_SINC_FILTER_MODE,
80   PROP_SINC_FILTER_AUTO_THRESHOLD,
81   PROP_SINC_FILTER_INTERPOLATION
82 };
83
84 #define SUPPORTED_CAPS \
85   GST_AUDIO_CAPS_MAKE (GST_AUDIO_FORMATS_ALL) \
86   ", layout = (string) { interleaved, non-interleaved }"
87
88 static GstStaticPadTemplate gst_audio_resample_sink_template =
89 GST_STATIC_PAD_TEMPLATE ("sink",
90     GST_PAD_SINK,
91     GST_PAD_ALWAYS,
92     GST_STATIC_CAPS (SUPPORTED_CAPS));
93
94 static GstStaticPadTemplate gst_audio_resample_src_template =
95 GST_STATIC_PAD_TEMPLATE ("src",
96     GST_PAD_SRC,
97     GST_PAD_ALWAYS,
98     GST_STATIC_CAPS (SUPPORTED_CAPS));
99
100 /* cached quark to avoid contention on the global quark table lock */
101 #define META_TAG_AUDIO meta_tag_audio_quark
102 static GQuark meta_tag_audio_quark;
103
104 static void gst_audio_resample_set_property (GObject * object,
105     guint prop_id, const GValue * value, GParamSpec * pspec);
106 static void gst_audio_resample_get_property (GObject * object,
107     guint prop_id, GValue * value, GParamSpec * pspec);
108
109 /* vmethods */
110 static gboolean gst_audio_resample_get_unit_size (GstBaseTransform * base,
111     GstCaps * caps, gsize * size);
112 static GstCaps *gst_audio_resample_transform_caps (GstBaseTransform * base,
113     GstPadDirection direction, GstCaps * caps, GstCaps * filter);
114 static GstCaps *gst_audio_resample_fixate_caps (GstBaseTransform * base,
115     GstPadDirection direction, GstCaps * caps, GstCaps * othercaps);
116 static gboolean gst_audio_resample_transform_size (GstBaseTransform * trans,
117     GstPadDirection direction, GstCaps * incaps, gsize insize,
118     GstCaps * outcaps, gsize * outsize);
119 static gboolean gst_audio_resample_set_caps (GstBaseTransform * base,
120     GstCaps * incaps, GstCaps * outcaps);
121 static GstFlowReturn gst_audio_resample_transform (GstBaseTransform * base,
122     GstBuffer * inbuf, GstBuffer * outbuf);
123 static gboolean gst_audio_resample_transform_meta (GstBaseTransform * trans,
124     GstBuffer * outbuf, GstMeta * meta, GstBuffer * inbuf);
125 static GstFlowReturn gst_audio_resample_submit_input_buffer (GstBaseTransform *
126     base, gboolean is_discont, GstBuffer * input);
127 static gboolean gst_audio_resample_sink_event (GstBaseTransform * base,
128     GstEvent * event);
129 static gboolean gst_audio_resample_start (GstBaseTransform * base);
130 static gboolean gst_audio_resample_stop (GstBaseTransform * base);
131 static gboolean gst_audio_resample_query (GstPad * pad, GstObject * parent,
132     GstQuery * query);
133
134 static void gst_audio_resample_push_drain (GstAudioResample * resample,
135     guint history_len);
136
137 #define gst_audio_resample_parent_class parent_class
138 G_DEFINE_TYPE (GstAudioResample, gst_audio_resample, GST_TYPE_BASE_TRANSFORM);
139 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (audioresample, "audioresample",
140     GST_RANK_PRIMARY, GST_TYPE_AUDIO_RESAMPLE,
141     GST_DEBUG_CATEGORY_INIT (audio_resample_debug, "audioresample", 0,
142         "audio resampling element"));
143 static void
144 gst_audio_resample_class_init (GstAudioResampleClass * klass)
145 {
146   GObjectClass *gobject_class = (GObjectClass *) klass;
147   GstElementClass *gstelement_class = (GstElementClass *) klass;
148
149   gobject_class->set_property = gst_audio_resample_set_property;
150   gobject_class->get_property = gst_audio_resample_get_property;
151
152   g_object_class_install_property (gobject_class, PROP_QUALITY,
153       g_param_spec_int ("quality", "Quality", "Resample quality with 0 being "
154           "the lowest and 10 being the best",
155           GST_AUDIO_RESAMPLER_QUALITY_MIN, GST_AUDIO_RESAMPLER_QUALITY_MAX,
156           DEFAULT_QUALITY,
157           G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
158
159   g_object_class_install_property (gobject_class, PROP_RESAMPLE_METHOD,
160       g_param_spec_enum ("resample-method", "Resample method to use",
161           "What resample method to use",
162           GST_TYPE_AUDIO_RESAMPLER_METHOD,
163           DEFAULT_RESAMPLE_METHOD, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
164   g_object_class_install_property (gobject_class, PROP_SINC_FILTER_MODE,
165       g_param_spec_enum ("sinc-filter-mode", "Sinc filter table mode",
166           "What sinc filter table mode to use",
167           GST_TYPE_AUDIO_RESAMPLER_FILTER_MODE,
168           DEFAULT_SINC_FILTER_MODE,
169           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
170
171   g_object_class_install_property (gobject_class,
172       PROP_SINC_FILTER_AUTO_THRESHOLD,
173       g_param_spec_uint ("sinc-filter-auto-threshold",
174           "Sinc filter auto mode threshold",
175           "Memory usage threshold to use if sinc filter mode is AUTO, given in bytes",
176           0, G_MAXUINT, DEFAULT_SINC_FILTER_AUTO_THRESHOLD,
177           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
178   g_object_class_install_property (gobject_class,
179       PROP_SINC_FILTER_INTERPOLATION,
180       g_param_spec_enum ("sinc-filter-interpolation",
181           "Sinc filter interpolation",
182           "How to interpolate the sinc filter table",
183           GST_TYPE_AUDIO_RESAMPLER_FILTER_INTERPOLATION,
184           DEFAULT_SINC_FILTER_INTERPOLATION,
185           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
186
187   gst_element_class_add_static_pad_template (gstelement_class,
188       &gst_audio_resample_src_template);
189   gst_element_class_add_static_pad_template (gstelement_class,
190       &gst_audio_resample_sink_template);
191
192   gst_element_class_set_static_metadata (gstelement_class, "Audio resampler",
193       "Filter/Converter/Audio", "Resamples audio",
194       "Sebastian Dröge <sebastian.droege@collabora.co.uk>");
195
196   GST_BASE_TRANSFORM_CLASS (klass)->start =
197       GST_DEBUG_FUNCPTR (gst_audio_resample_start);
198   GST_BASE_TRANSFORM_CLASS (klass)->stop =
199       GST_DEBUG_FUNCPTR (gst_audio_resample_stop);
200   GST_BASE_TRANSFORM_CLASS (klass)->transform_size =
201       GST_DEBUG_FUNCPTR (gst_audio_resample_transform_size);
202   GST_BASE_TRANSFORM_CLASS (klass)->get_unit_size =
203       GST_DEBUG_FUNCPTR (gst_audio_resample_get_unit_size);
204   GST_BASE_TRANSFORM_CLASS (klass)->transform_caps =
205       GST_DEBUG_FUNCPTR (gst_audio_resample_transform_caps);
206   GST_BASE_TRANSFORM_CLASS (klass)->fixate_caps =
207       GST_DEBUG_FUNCPTR (gst_audio_resample_fixate_caps);
208   GST_BASE_TRANSFORM_CLASS (klass)->set_caps =
209       GST_DEBUG_FUNCPTR (gst_audio_resample_set_caps);
210   GST_BASE_TRANSFORM_CLASS (klass)->transform =
211       GST_DEBUG_FUNCPTR (gst_audio_resample_transform);
212   GST_BASE_TRANSFORM_CLASS (klass)->sink_event =
213       GST_DEBUG_FUNCPTR (gst_audio_resample_sink_event);
214   GST_BASE_TRANSFORM_CLASS (klass)->transform_meta =
215       GST_DEBUG_FUNCPTR (gst_audio_resample_transform_meta);
216   GST_BASE_TRANSFORM_CLASS (klass)->submit_input_buffer =
217       GST_DEBUG_FUNCPTR (gst_audio_resample_submit_input_buffer);
218
219   GST_BASE_TRANSFORM_CLASS (klass)->passthrough_on_same_caps = TRUE;
220
221   gst_type_mark_as_plugin_api (GST_TYPE_AUDIO_RESAMPLER_METHOD, 0);
222   gst_type_mark_as_plugin_api (GST_TYPE_AUDIO_RESAMPLER_FILTER_INTERPOLATION,
223       0);
224   gst_type_mark_as_plugin_api (GST_TYPE_AUDIO_RESAMPLER_FILTER_MODE, 0);
225
226   meta_tag_audio_quark = g_quark_from_static_string (GST_META_TAG_AUDIO_STR);
227 }
228
229 static void
230 gst_audio_resample_init (GstAudioResample * resample)
231 {
232   GstBaseTransform *trans = GST_BASE_TRANSFORM (resample);
233
234   resample->method = DEFAULT_RESAMPLE_METHOD;
235   resample->quality = DEFAULT_QUALITY;
236   resample->sinc_filter_mode = DEFAULT_SINC_FILTER_MODE;
237   resample->sinc_filter_auto_threshold = DEFAULT_SINC_FILTER_AUTO_THRESHOLD;
238   resample->sinc_filter_interpolation = DEFAULT_SINC_FILTER_INTERPOLATION;
239
240   gst_base_transform_set_gap_aware (trans, TRUE);
241   gst_pad_set_query_function (trans->srcpad, gst_audio_resample_query);
242 }
243
244 /* vmethods */
245 static gboolean
246 gst_audio_resample_start (GstBaseTransform * base)
247 {
248   GstAudioResample *resample = GST_AUDIO_RESAMPLE (base);
249
250   resample->need_discont = TRUE;
251
252   resample->num_gap_samples = 0;
253   resample->num_nongap_samples = 0;
254   resample->t0 = GST_CLOCK_TIME_NONE;
255   resample->in_offset0 = GST_BUFFER_OFFSET_NONE;
256   resample->out_offset0 = GST_BUFFER_OFFSET_NONE;
257   resample->samples_in = 0;
258   resample->samples_out = 0;
259
260   return TRUE;
261 }
262
263 static gboolean
264 gst_audio_resample_stop (GstBaseTransform * base)
265 {
266   GstAudioResample *resample = GST_AUDIO_RESAMPLE (base);
267
268   if (resample->converter) {
269     gst_audio_converter_free (resample->converter);
270     resample->converter = NULL;
271   }
272   return TRUE;
273 }
274
275 static gboolean
276 gst_audio_resample_get_unit_size (GstBaseTransform * base, GstCaps * caps,
277     gsize * size)
278 {
279   GstAudioInfo info;
280
281   if (!gst_audio_info_from_caps (&info, caps))
282     goto invalid_caps;
283
284   *size = GST_AUDIO_INFO_BPF (&info);
285
286   return TRUE;
287
288   /* ERRORS */
289 invalid_caps:
290   {
291     GST_ERROR_OBJECT (base, "invalid caps");
292     return FALSE;
293   }
294 }
295
296 static GstCaps *
297 gst_audio_resample_transform_caps (GstBaseTransform * base,
298     GstPadDirection direction, GstCaps * caps, GstCaps * filter)
299 {
300   const GValue *val;
301   GstStructure *s;
302   GstCaps *res;
303   gint i, n;
304
305   /* transform single caps into input_caps + input_caps with the rate
306    * field set to our supported range. This ensures that upstream knows
307    * about downstream's preferred rate(s) and can negotiate accordingly. */
308   res = gst_caps_new_empty ();
309   n = gst_caps_get_size (caps);
310   for (i = 0; i < n; i++) {
311     s = gst_caps_get_structure (caps, i);
312
313     /* If this is already expressed by the existing caps
314      * skip this structure */
315     if (i > 0 && gst_caps_is_subset_structure (res, s))
316       continue;
317
318     /* first, however, check if the caps contain a range for the rate field, in
319      * which case that side isn't going to care much about the exact sample rate
320      * chosen and we should just assume things will get fixated to something sane
321      * and we may just as well offer our full range instead of the range in the
322      * caps. If the rate is not an int range value, it's likely to express a
323      * real preference or limitation and we should maintain that structure as
324      * preference by putting it first into the transformed caps, and only add
325      * our full rate range as second option  */
326     s = gst_structure_copy (s);
327     val = gst_structure_get_value (s, "rate");
328     if (val == NULL || GST_VALUE_HOLDS_INT_RANGE (val)) {
329       /* overwrite existing range, or add field if it doesn't exist yet */
330       gst_structure_set (s, "rate", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL);
331     } else {
332       /* append caps with full range to existing caps with non-range rate field */
333       gst_caps_append_structure (res, gst_structure_copy (s));
334       gst_structure_set (s, "rate", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL);
335     }
336     gst_caps_append_structure (res, s);
337   }
338
339   if (filter) {
340     GstCaps *intersection;
341
342     intersection =
343         gst_caps_intersect_full (filter, res, GST_CAPS_INTERSECT_FIRST);
344     gst_caps_unref (res);
345     res = intersection;
346   }
347
348   return res;
349 }
350
351 /* Fixate rate to the allowed rate that has the smallest difference */
352 static GstCaps *
353 gst_audio_resample_fixate_caps (GstBaseTransform * base,
354     GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
355 {
356   GstStructure *s;
357   gint rate;
358
359   s = gst_caps_get_structure (caps, 0);
360   if (G_UNLIKELY (!gst_structure_get_int (s, "rate", &rate)))
361     return othercaps;
362
363   othercaps = gst_caps_truncate (othercaps);
364   othercaps = gst_caps_make_writable (othercaps);
365   s = gst_caps_get_structure (othercaps, 0);
366   gst_structure_fixate_field_nearest_int (s, "rate", rate);
367
368   return gst_caps_fixate (othercaps);
369 }
370
371 static GstStructure *
372 make_options (GstAudioResample * resample, GstAudioInfo * in,
373     GstAudioInfo * out)
374 {
375   GstStructure *options;
376
377   options = gst_structure_new_empty ("resampler-options");
378   if (in != NULL && out != NULL)
379     gst_audio_resampler_options_set_quality (resample->method,
380         resample->quality, in->rate, out->rate, options);
381
382   gst_structure_set (options,
383       GST_AUDIO_CONVERTER_OPT_RESAMPLER_METHOD, GST_TYPE_AUDIO_RESAMPLER_METHOD,
384       resample->method,
385       GST_AUDIO_RESAMPLER_OPT_FILTER_MODE, GST_TYPE_AUDIO_RESAMPLER_FILTER_MODE,
386       resample->sinc_filter_mode, GST_AUDIO_RESAMPLER_OPT_FILTER_MODE_THRESHOLD,
387       G_TYPE_UINT, resample->sinc_filter_auto_threshold,
388       GST_AUDIO_RESAMPLER_OPT_FILTER_INTERPOLATION,
389       GST_TYPE_AUDIO_RESAMPLER_FILTER_INTERPOLATION,
390       resample->sinc_filter_interpolation, NULL);
391
392   return options;
393 }
394
395 static gboolean
396 gst_audio_resample_update_state (GstAudioResample * resample, GstAudioInfo * in,
397     GstAudioInfo * out)
398 {
399   gboolean updated_latency = FALSE;
400   gsize old_latency = -1;
401   GstStructure *options;
402
403   if (resample->converter == NULL && in == NULL && out == NULL)
404     return TRUE;
405
406   options = make_options (resample, in, out);
407
408   if (resample->converter)
409     old_latency = gst_audio_converter_get_max_latency (resample->converter);
410
411   /* if channels and layout changed, destroy existing resampler */
412   if (in != NULL && (in->finfo != resample->in.finfo ||
413           in->channels != resample->in.channels ||
414           in->layout != resample->in.layout) && resample->converter) {
415     gst_audio_converter_free (resample->converter);
416     resample->converter = NULL;
417   }
418   if (resample->converter == NULL) {
419     resample->converter =
420         gst_audio_converter_new (GST_AUDIO_CONVERTER_FLAG_VARIABLE_RATE, in,
421         out, options);
422     if (resample->converter == NULL)
423       goto resampler_failed;
424   } else if (in && out) {
425     gboolean ret;
426
427     ret =
428         gst_audio_converter_update_config (resample->converter, in->rate,
429         out->rate, options);
430     if (!ret)
431       goto update_failed;
432   } else {
433     gst_structure_free (options);
434   }
435   if (old_latency != -1)
436     updated_latency =
437         old_latency !=
438         gst_audio_converter_get_max_latency (resample->converter);
439
440   if (updated_latency)
441     gst_element_post_message (GST_ELEMENT (resample),
442         gst_message_new_latency (GST_OBJECT (resample)));
443
444   return TRUE;
445
446   /* ERRORS */
447 resampler_failed:
448   {
449     GST_ERROR_OBJECT (resample, "failed to create resampler");
450     return FALSE;
451   }
452 update_failed:
453   {
454     GST_ERROR_OBJECT (resample, "failed to update resampler");
455     return FALSE;
456   }
457 }
458
459 static void
460 gst_audio_resample_reset_state (GstAudioResample * resample)
461 {
462   if (resample->converter)
463     gst_audio_converter_reset (resample->converter);
464 }
465
466 static gboolean
467 gst_audio_resample_transform_size (GstBaseTransform * base,
468     GstPadDirection direction, GstCaps * caps, gsize size, GstCaps * othercaps,
469     gsize * othersize)
470 {
471   GstAudioResample *resample = GST_AUDIO_RESAMPLE (base);
472   gboolean ret = TRUE;
473   gint bpf;
474
475   GST_LOG_OBJECT (base, "asked to transform size %" G_GSIZE_FORMAT
476       " in direction %s", size, direction == GST_PAD_SINK ? "SINK" : "SRC");
477
478   /* Number of samples in either buffer is size / (width*channels) ->
479    * calculate the factor */
480   bpf = GST_AUDIO_INFO_BPF (&resample->in);
481
482   /* Convert source buffer size to samples */
483   size /= bpf;
484
485   if (direction == GST_PAD_SINK) {
486     /* asked to convert size of an incoming buffer */
487     *othersize = gst_audio_converter_get_out_frames (resample->converter, size);
488     *othersize *= bpf;
489   } else {
490     /* asked to convert size of an outgoing buffer */
491     *othersize = gst_audio_converter_get_in_frames (resample->converter, size);
492     *othersize *= bpf;
493   }
494
495   GST_LOG_OBJECT (base,
496       "transformed size %" G_GSIZE_FORMAT " to %" G_GSIZE_FORMAT,
497       size * bpf, *othersize);
498
499   return ret;
500 }
501
502 static gboolean
503 gst_audio_resample_set_caps (GstBaseTransform * base, GstCaps * incaps,
504     GstCaps * outcaps)
505 {
506   GstAudioResample *resample = GST_AUDIO_RESAMPLE (base);
507   GstAudioInfo in, out;
508
509   GST_LOG ("incaps %" GST_PTR_FORMAT ", outcaps %"
510       GST_PTR_FORMAT, incaps, outcaps);
511
512   if (!gst_audio_info_from_caps (&in, incaps))
513     goto invalid_incaps;
514   if (!gst_audio_info_from_caps (&out, outcaps))
515     goto invalid_outcaps;
516
517   /* Reset timestamp tracking and drain the resampler if the audio format is
518    * changing. Especially when changing the sample rate our timestamp tracking
519    * will be completely off, but even otherwise we would usually lose the last
520    * few samples if we don't drain here */
521   if (!gst_audio_info_is_equal (&in, &resample->in) ||
522       !gst_audio_info_is_equal (&out, &resample->out)) {
523     if (resample->converter) {
524       gsize latency = gst_audio_converter_get_max_latency (resample->converter);
525       gst_audio_resample_push_drain (resample, latency);
526     }
527     gst_audio_resample_reset_state (resample);
528     resample->num_gap_samples = 0;
529     resample->num_nongap_samples = 0;
530     resample->t0 = GST_CLOCK_TIME_NONE;
531     resample->in_offset0 = GST_BUFFER_OFFSET_NONE;
532     resample->out_offset0 = GST_BUFFER_OFFSET_NONE;
533     resample->samples_in = 0;
534     resample->samples_out = 0;
535     resample->need_discont = TRUE;
536   }
537
538   gst_audio_resample_update_state (resample, &in, &out);
539
540   resample->in = in;
541   resample->out = out;
542
543   return TRUE;
544
545   /* ERROR */
546 invalid_incaps:
547   {
548     GST_ERROR_OBJECT (base, "invalid incaps");
549     return FALSE;
550   }
551 invalid_outcaps:
552   {
553     GST_ERROR_OBJECT (base, "invalid outcaps");
554     return FALSE;
555   }
556 }
557
558 /* Push history_len zeros into the filter, but discard the output. */
559 static void
560 gst_audio_resample_dump_drain (GstAudioResample * resample, guint history_len)
561 {
562   gsize out_len, outsize;
563   GstBuffer *outbuf;
564   GstAudioBuffer abuf;
565
566   out_len =
567       gst_audio_converter_get_out_frames (resample->converter, history_len);
568   if (out_len == 0)
569     return;
570
571   outsize = out_len * resample->out.bpf;
572   outbuf = gst_buffer_new_and_alloc (outsize);
573
574   if (GST_AUDIO_INFO_LAYOUT (&resample->out) ==
575       GST_AUDIO_LAYOUT_NON_INTERLEAVED) {
576     gst_buffer_add_audio_meta (outbuf, &resample->out, out_len, NULL);
577   }
578
579   gst_audio_buffer_map (&abuf, &resample->out, outbuf, GST_MAP_WRITE);
580   gst_audio_converter_samples (resample->converter, 0, NULL, history_len,
581       abuf.planes, out_len);
582   gst_audio_buffer_unmap (&abuf);
583
584   gst_buffer_unref (outbuf);
585 }
586
587 static void
588 gst_audio_resample_push_drain (GstAudioResample * resample, guint history_len)
589 {
590   GstBuffer *outbuf;
591   GstFlowReturn res;
592   gint outsize;
593   gsize out_len;
594   GstAudioBuffer abuf;
595
596   g_assert (resample->converter != NULL);
597
598   /* Don't drain samples if we were reset. */
599   if (!GST_CLOCK_TIME_IS_VALID (resample->t0))
600     return;
601
602   out_len =
603       gst_audio_converter_get_out_frames (resample->converter, history_len);
604   if (out_len == 0)
605     return;
606
607   outsize = out_len * resample->in.bpf;
608   outbuf = gst_buffer_new_and_alloc (outsize);
609
610   if (GST_AUDIO_INFO_LAYOUT (&resample->out) ==
611       GST_AUDIO_LAYOUT_NON_INTERLEAVED) {
612     gst_buffer_add_audio_meta (outbuf, &resample->out, out_len, NULL);
613   }
614
615   gst_audio_buffer_map (&abuf, &resample->out, outbuf, GST_MAP_WRITE);
616   gst_audio_converter_samples (resample->converter, 0, NULL, history_len,
617       abuf.planes, out_len);
618   gst_audio_buffer_unmap (&abuf);
619
620   /* time */
621   if (GST_CLOCK_TIME_IS_VALID (resample->t0)) {
622     GST_BUFFER_TIMESTAMP (outbuf) = resample->t0 +
623         gst_util_uint64_scale_int_round (resample->samples_out, GST_SECOND,
624         resample->out.rate);
625     GST_BUFFER_DURATION (outbuf) = resample->t0 +
626         gst_util_uint64_scale_int_round (resample->samples_out + out_len,
627         GST_SECOND, resample->out.rate) - GST_BUFFER_TIMESTAMP (outbuf);
628   } else {
629     GST_BUFFER_TIMESTAMP (outbuf) = GST_CLOCK_TIME_NONE;
630     GST_BUFFER_DURATION (outbuf) = GST_CLOCK_TIME_NONE;
631   }
632   /* offset */
633   if (resample->out_offset0 != GST_BUFFER_OFFSET_NONE) {
634     GST_BUFFER_OFFSET (outbuf) = resample->out_offset0 + resample->samples_out;
635     GST_BUFFER_OFFSET_END (outbuf) = GST_BUFFER_OFFSET (outbuf) + out_len;
636   } else {
637     GST_BUFFER_OFFSET (outbuf) = GST_BUFFER_OFFSET_NONE;
638     GST_BUFFER_OFFSET_END (outbuf) = GST_BUFFER_OFFSET_NONE;
639   }
640   /* move along */
641   resample->samples_out += out_len;
642   resample->samples_in += history_len;
643
644   GST_LOG_OBJECT (resample,
645       "Pushing drain buffer of %u bytes with timestamp %" GST_TIME_FORMAT
646       " duration %" GST_TIME_FORMAT " offset %" G_GUINT64_FORMAT " offset_end %"
647       G_GUINT64_FORMAT, outsize,
648       GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf)),
649       GST_TIME_ARGS (GST_BUFFER_DURATION (outbuf)), GST_BUFFER_OFFSET (outbuf),
650       GST_BUFFER_OFFSET_END (outbuf));
651
652   res = gst_pad_push (GST_BASE_TRANSFORM_SRC_PAD (resample), outbuf);
653
654   if (G_UNLIKELY (res != GST_FLOW_OK))
655     GST_WARNING_OBJECT (resample, "Failed to push drain: %s",
656         gst_flow_get_name (res));
657
658   return;
659 }
660
661 static gboolean
662 gst_audio_resample_sink_event (GstBaseTransform * base, GstEvent * event)
663 {
664   GstAudioResample *resample = GST_AUDIO_RESAMPLE (base);
665
666   switch (GST_EVENT_TYPE (event)) {
667     case GST_EVENT_FLUSH_STOP:
668       gst_audio_resample_reset_state (resample);
669       resample->num_gap_samples = 0;
670       resample->num_nongap_samples = 0;
671       resample->t0 = GST_CLOCK_TIME_NONE;
672       resample->in_offset0 = GST_BUFFER_OFFSET_NONE;
673       resample->out_offset0 = GST_BUFFER_OFFSET_NONE;
674       resample->samples_in = 0;
675       resample->samples_out = 0;
676       resample->need_discont = TRUE;
677       break;
678     case GST_EVENT_STREAM_START:
679     case GST_EVENT_SEGMENT:
680     case GST_EVENT_EOS:
681       if (resample->converter) {
682         gsize latency =
683             gst_audio_converter_get_max_latency (resample->converter);
684         gst_audio_resample_push_drain (resample, latency);
685       }
686       gst_audio_resample_reset_state (resample);
687       resample->num_gap_samples = 0;
688       resample->num_nongap_samples = 0;
689       resample->t0 = GST_CLOCK_TIME_NONE;
690       resample->in_offset0 = GST_BUFFER_OFFSET_NONE;
691       resample->out_offset0 = GST_BUFFER_OFFSET_NONE;
692       resample->samples_in = 0;
693       resample->samples_out = 0;
694       resample->need_discont = TRUE;
695       break;
696     default:
697       break;
698   }
699
700   return GST_BASE_TRANSFORM_CLASS (parent_class)->sink_event (base, event);
701 }
702
703 static gboolean
704 gst_audio_resample_check_discont (GstAudioResample * resample, GstBuffer * buf)
705 {
706   guint64 offset;
707   guint64 delta;
708
709   /* is the incoming buffer a discontinuity? */
710   if (G_UNLIKELY (GST_BUFFER_IS_DISCONT (buf)))
711     return TRUE;
712
713   /* no valid timestamps or offsets to compare --> no discontinuity */
714   if (G_UNLIKELY (!(GST_BUFFER_TIMESTAMP_IS_VALID (buf) &&
715               GST_CLOCK_TIME_IS_VALID (resample->t0))))
716     return FALSE;
717
718   /* convert the inbound timestamp to an offset. */
719   offset =
720       gst_util_uint64_scale_int_round (GST_BUFFER_TIMESTAMP (buf) -
721       resample->t0, resample->in.rate, GST_SECOND);
722
723   /* many elements generate imperfect streams due to rounding errors, so we
724    * permit a small error (up to one sample) without triggering a filter
725    * flush/restart (if triggered incorrectly, this will be audible) */
726   /* allow even up to more samples, since sink is not so strict anyway,
727    * so give that one a chance to handle this as configured */
728   delta = ABS ((gint64) (offset - resample->samples_in));
729   if (delta <= (resample->in.rate >> 5))
730     return FALSE;
731
732   GST_WARNING_OBJECT (resample,
733       "encountered timestamp discontinuity of %" G_GUINT64_FORMAT " samples = %"
734       GST_TIME_FORMAT, delta,
735       GST_TIME_ARGS (gst_util_uint64_scale_int_round (delta, GST_SECOND,
736               resample->in.rate)));
737   return TRUE;
738 }
739
740 static GstFlowReturn
741 gst_audio_resample_process (GstAudioResample * resample, GstBuffer * inbuf,
742     GstBuffer * outbuf)
743 {
744   GstAudioBuffer srcabuf, dstabuf;
745   gsize outsize;
746   gsize in_len;
747   gsize out_len;
748   guint filt_len =
749       gst_audio_converter_get_max_latency (resample->converter) * 2;
750   gboolean inbuf_writable;
751
752   inbuf_writable = gst_buffer_is_writable (inbuf)
753       && gst_buffer_n_memory (inbuf) == 1
754       && gst_memory_is_writable (gst_buffer_peek_memory (inbuf, 0));
755
756   gst_audio_buffer_map (&srcabuf, &resample->in, inbuf,
757       inbuf_writable ? GST_MAP_READWRITE : GST_MAP_READ);
758
759   in_len = srcabuf.n_samples;
760   out_len = gst_audio_converter_get_out_frames (resample->converter, in_len);
761
762   /* ensure that the output buffer is not bigger than what we need */
763   gst_buffer_set_size (outbuf, out_len * resample->in.bpf);
764
765   if (GST_AUDIO_INFO_LAYOUT (&resample->out) ==
766       GST_AUDIO_LAYOUT_NON_INTERLEAVED) {
767     gst_buffer_add_audio_meta (outbuf, &resample->out, out_len, NULL);
768   }
769
770   gst_audio_buffer_map (&dstabuf, &resample->out, outbuf, GST_MAP_WRITE);
771
772   if (GST_BUFFER_FLAG_IS_SET (inbuf, GST_BUFFER_FLAG_GAP)) {
773     resample->num_nongap_samples = 0;
774     if (resample->num_gap_samples < filt_len) {
775       guint zeros_to_push;
776       if (in_len >= filt_len - resample->num_gap_samples)
777         zeros_to_push = filt_len - resample->num_gap_samples;
778       else
779         zeros_to_push = in_len;
780
781       gst_audio_resample_push_drain (resample, zeros_to_push);
782       in_len -= zeros_to_push;
783       resample->num_gap_samples += zeros_to_push;
784     }
785
786     {
787       guint num, den;
788       gint i;
789
790       num = resample->in.rate;
791       den = resample->out.rate;
792
793       if (resample->samples_in + in_len >= filt_len / 2)
794         out_len =
795             gst_util_uint64_scale_int_ceil (resample->samples_in + in_len -
796             filt_len / 2, den, num) - resample->samples_out;
797       else
798         out_len = 0;
799
800       for (i = 0; i < dstabuf.n_planes; i++)
801         memset (dstabuf.planes[i], 0, GST_AUDIO_BUFFER_PLANE_SIZE (&dstabuf));
802
803       GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_GAP);
804       resample->num_gap_samples += in_len;
805     }
806   } else {                      /* not a gap */
807     if (resample->num_gap_samples > filt_len) {
808       /* push in enough zeros to restore the filter to the right offset */
809       guint num;
810
811       num = resample->in.rate;
812
813       gst_audio_resample_dump_drain (resample,
814           (resample->num_gap_samples - filt_len) % num);
815     }
816     resample->num_gap_samples = 0;
817     if (resample->num_nongap_samples < filt_len) {
818       resample->num_nongap_samples += in_len;
819       if (resample->num_nongap_samples > filt_len)
820         resample->num_nongap_samples = filt_len;
821     }
822     {
823       /* process */
824       GstAudioConverterFlags flags;
825
826       flags = 0;
827       if (inbuf_writable)
828         flags |= GST_AUDIO_CONVERTER_FLAG_IN_WRITABLE;
829
830       gst_audio_converter_samples (resample->converter, flags, srcabuf.planes,
831           in_len, dstabuf.planes, out_len);
832     }
833   }
834
835   /* time */
836   if (GST_CLOCK_TIME_IS_VALID (resample->t0)) {
837     GST_BUFFER_TIMESTAMP (outbuf) = resample->t0 +
838         gst_util_uint64_scale_int_round (resample->samples_out, GST_SECOND,
839         resample->out.rate);
840     GST_BUFFER_DURATION (outbuf) = resample->t0 +
841         gst_util_uint64_scale_int_round (resample->samples_out + out_len,
842         GST_SECOND, resample->out.rate) - GST_BUFFER_TIMESTAMP (outbuf);
843   } else {
844     GST_BUFFER_TIMESTAMP (outbuf) = GST_CLOCK_TIME_NONE;
845     GST_BUFFER_DURATION (outbuf) = GST_CLOCK_TIME_NONE;
846   }
847   /* offset */
848   if (resample->out_offset0 != GST_BUFFER_OFFSET_NONE) {
849     GST_BUFFER_OFFSET (outbuf) = resample->out_offset0 + resample->samples_out;
850     GST_BUFFER_OFFSET_END (outbuf) = GST_BUFFER_OFFSET (outbuf) + out_len;
851   } else {
852     GST_BUFFER_OFFSET (outbuf) = GST_BUFFER_OFFSET_NONE;
853     GST_BUFFER_OFFSET_END (outbuf) = GST_BUFFER_OFFSET_NONE;
854   }
855   /* move along */
856   resample->samples_out += out_len;
857   resample->samples_in += in_len;
858
859   gst_audio_buffer_unmap (&srcabuf);
860   gst_audio_buffer_unmap (&dstabuf);
861
862   outsize = out_len * resample->in.bpf;
863
864   GST_LOG_OBJECT (resample,
865       "Converted to buffer of %" G_GSIZE_FORMAT
866       " samples (%" G_GSIZE_FORMAT " bytes) with timestamp %" GST_TIME_FORMAT
867       ", duration %" GST_TIME_FORMAT ", offset %" G_GUINT64_FORMAT
868       ", offset_end %" G_GUINT64_FORMAT, out_len, outsize,
869       GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf)),
870       GST_TIME_ARGS (GST_BUFFER_DURATION (outbuf)),
871       GST_BUFFER_OFFSET (outbuf), GST_BUFFER_OFFSET_END (outbuf));
872
873   if (outsize == 0)
874     return GST_BASE_TRANSFORM_FLOW_DROPPED;
875   else
876     return GST_FLOW_OK;
877 }
878
879 static GstFlowReturn
880 gst_audio_resample_transform (GstBaseTransform * base, GstBuffer * inbuf,
881     GstBuffer * outbuf)
882 {
883   GstAudioResample *resample = GST_AUDIO_RESAMPLE (base);
884   GstFlowReturn ret;
885
886   GST_LOG_OBJECT (resample, "transforming buffer of %" G_GSIZE_FORMAT " bytes,"
887       " ts %" GST_TIME_FORMAT ", duration %" GST_TIME_FORMAT ", offset %"
888       G_GINT64_FORMAT ", offset_end %" G_GINT64_FORMAT,
889       gst_buffer_get_size (inbuf), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (inbuf)),
890       GST_TIME_ARGS (GST_BUFFER_DURATION (inbuf)),
891       GST_BUFFER_OFFSET (inbuf), GST_BUFFER_OFFSET_END (inbuf));
892
893   /* check for timestamp discontinuities;  flush/reset if needed, and set
894    * flag to resync timestamp and offset counters and send event
895    * downstream */
896   if (G_UNLIKELY (gst_audio_resample_check_discont (resample, inbuf))) {
897     if (resample->converter) {
898       gsize latency = gst_audio_converter_get_max_latency (resample->converter);
899       gst_audio_resample_push_drain (resample, latency);
900     }
901
902     gst_audio_resample_reset_state (resample);
903     resample->need_discont = TRUE;
904   }
905
906   /* handle discontinuity */
907   if (G_UNLIKELY (resample->need_discont)) {
908     resample->num_gap_samples = 0;
909     resample->num_nongap_samples = 0;
910     /* reset */
911     resample->samples_in = 0;
912     resample->samples_out = 0;
913     GST_DEBUG_OBJECT (resample, "found discontinuity; resyncing");
914     /* resync the timestamp and offset counters if possible */
915     if (GST_BUFFER_TIMESTAMP_IS_VALID (inbuf)) {
916       resample->t0 = GST_BUFFER_TIMESTAMP (inbuf);
917     } else {
918       GST_DEBUG_OBJECT (resample, "... but new timestamp is invalid");
919       resample->t0 = GST_CLOCK_TIME_NONE;
920     }
921     if (GST_BUFFER_OFFSET_IS_VALID (inbuf)) {
922       resample->in_offset0 = GST_BUFFER_OFFSET (inbuf);
923       resample->out_offset0 =
924           gst_util_uint64_scale_int_round (resample->in_offset0,
925           resample->out.rate, resample->in.rate);
926     } else {
927       GST_DEBUG_OBJECT (resample, "... but new offset is invalid");
928       resample->in_offset0 = GST_BUFFER_OFFSET_NONE;
929       resample->out_offset0 = GST_BUFFER_OFFSET_NONE;
930     }
931     /* set DISCONT flag on output buffer */
932     GST_DEBUG_OBJECT (resample, "marking this buffer with the DISCONT flag");
933     GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
934     resample->need_discont = FALSE;
935   }
936
937   ret = gst_audio_resample_process (resample, inbuf, outbuf);
938   if (G_UNLIKELY (ret != GST_FLOW_OK))
939     return ret;
940
941   GST_DEBUG_OBJECT (resample, "input = samples [%" G_GUINT64_FORMAT ", %"
942       G_GUINT64_FORMAT ") = [%" G_GUINT64_FORMAT ", %" G_GUINT64_FORMAT
943       ") ns;  output = samples [%" G_GUINT64_FORMAT ", %" G_GUINT64_FORMAT
944       ") = [%" G_GUINT64_FORMAT ", %" G_GUINT64_FORMAT ") ns",
945       GST_BUFFER_OFFSET (inbuf), GST_BUFFER_OFFSET_END (inbuf),
946       GST_BUFFER_TIMESTAMP (inbuf), GST_BUFFER_TIMESTAMP (inbuf) +
947       GST_BUFFER_DURATION (inbuf), GST_BUFFER_OFFSET (outbuf),
948       GST_BUFFER_OFFSET_END (outbuf), GST_BUFFER_TIMESTAMP (outbuf),
949       GST_BUFFER_TIMESTAMP (outbuf) + GST_BUFFER_DURATION (outbuf));
950
951   return GST_FLOW_OK;
952 }
953
954 static gboolean
955 gst_audio_resample_transform_meta (GstBaseTransform * trans, GstBuffer * outbuf,
956     GstMeta * meta, GstBuffer * inbuf)
957 {
958   const GstMetaInfo *info = meta->info;
959   const gchar *const *tags;
960
961   tags = gst_meta_api_type_get_tags (info->api);
962
963   if (!tags || (g_strv_length ((gchar **) tags) == 1
964           && gst_meta_api_type_has_tag (info->api, META_TAG_AUDIO)))
965     return TRUE;
966
967   return FALSE;
968 }
969
970 static GstFlowReturn
971 gst_audio_resample_submit_input_buffer (GstBaseTransform * base,
972     gboolean is_discont, GstBuffer * input)
973 {
974   GstAudioResample *resample = GST_AUDIO_RESAMPLE (base);
975
976   if (base->segment.format == GST_FORMAT_TIME) {
977     input =
978         gst_audio_buffer_clip (input, &base->segment, resample->in.rate,
979         resample->in.bpf);
980
981     if (!input)
982       return GST_FLOW_OK;
983   }
984
985   return GST_BASE_TRANSFORM_CLASS (parent_class)->submit_input_buffer (base,
986       is_discont, input);
987 }
988
989 static gboolean
990 gst_audio_resample_query (GstPad * pad, GstObject * parent, GstQuery * query)
991 {
992   GstAudioResample *resample = GST_AUDIO_RESAMPLE (parent);
993   GstBaseTransform *trans;
994   gboolean res = TRUE;
995
996   trans = GST_BASE_TRANSFORM (resample);
997
998   switch (GST_QUERY_TYPE (query)) {
999     case GST_QUERY_LATENCY:
1000     {
1001       GstClockTime min, max;
1002       gboolean live;
1003       guint64 latency;
1004       gint rate = resample->in.rate;
1005       gint resampler_latency;
1006
1007       if (resample->converter)
1008         resampler_latency =
1009             gst_audio_converter_get_max_latency (resample->converter);
1010       else
1011         resampler_latency = 0;
1012
1013       if (gst_base_transform_is_passthrough (trans))
1014         resampler_latency = 0;
1015
1016       if ((res =
1017               gst_pad_peer_query (GST_BASE_TRANSFORM_SINK_PAD (trans),
1018                   query))) {
1019         gst_query_parse_latency (query, &live, &min, &max);
1020
1021         GST_DEBUG_OBJECT (resample, "Peer latency: min %"
1022             GST_TIME_FORMAT " max %" GST_TIME_FORMAT,
1023             GST_TIME_ARGS (min), GST_TIME_ARGS (max));
1024
1025         /* add our own latency */
1026         if (rate != 0 && resampler_latency != 0)
1027           latency = gst_util_uint64_scale_round (resampler_latency,
1028               GST_SECOND, rate);
1029         else
1030           latency = 0;
1031
1032         GST_DEBUG_OBJECT (resample, "Our latency: %" GST_TIME_FORMAT,
1033             GST_TIME_ARGS (latency));
1034
1035         min += latency;
1036         if (GST_CLOCK_TIME_IS_VALID (max))
1037           max += latency;
1038
1039         GST_DEBUG_OBJECT (resample, "Calculated total latency : min %"
1040             GST_TIME_FORMAT " max %" GST_TIME_FORMAT,
1041             GST_TIME_ARGS (min), GST_TIME_ARGS (max));
1042
1043         gst_query_set_latency (query, live, min, max);
1044       }
1045       break;
1046     }
1047     default:
1048       res = gst_pad_query_default (pad, parent, query);
1049       break;
1050   }
1051   return res;
1052 }
1053
1054 static void
1055 gst_audio_resample_set_property (GObject * object, guint prop_id,
1056     const GValue * value, GParamSpec * pspec)
1057 {
1058   GstAudioResample *resample;
1059
1060   resample = GST_AUDIO_RESAMPLE (object);
1061
1062   switch (prop_id) {
1063     case PROP_QUALITY:
1064       /* FIXME locking! */
1065       resample->quality = g_value_get_int (value);
1066       GST_DEBUG_OBJECT (resample, "new quality %d", resample->quality);
1067       gst_audio_resample_update_state (resample, NULL, NULL);
1068       break;
1069     case PROP_RESAMPLE_METHOD:
1070       resample->method = g_value_get_enum (value);
1071       gst_audio_resample_update_state (resample, NULL, NULL);
1072       break;
1073     case PROP_SINC_FILTER_MODE:
1074       /* FIXME locking! */
1075       resample->sinc_filter_mode = g_value_get_enum (value);
1076       gst_audio_resample_update_state (resample, NULL, NULL);
1077       break;
1078     case PROP_SINC_FILTER_AUTO_THRESHOLD:
1079       /* FIXME locking! */
1080       resample->sinc_filter_auto_threshold = g_value_get_uint (value);
1081       gst_audio_resample_update_state (resample, NULL, NULL);
1082       break;
1083     case PROP_SINC_FILTER_INTERPOLATION:
1084       /* FIXME locking! */
1085       resample->sinc_filter_interpolation = g_value_get_enum (value);
1086       gst_audio_resample_update_state (resample, NULL, NULL);
1087       break;
1088     default:
1089       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1090       break;
1091   }
1092 }
1093
1094 static void
1095 gst_audio_resample_get_property (GObject * object, guint prop_id,
1096     GValue * value, GParamSpec * pspec)
1097 {
1098   GstAudioResample *resample;
1099
1100   resample = GST_AUDIO_RESAMPLE (object);
1101
1102   switch (prop_id) {
1103     case PROP_QUALITY:
1104       g_value_set_int (value, resample->quality);
1105       break;
1106     case PROP_RESAMPLE_METHOD:
1107       g_value_set_enum (value, resample->method);
1108       break;
1109     case PROP_SINC_FILTER_MODE:
1110       g_value_set_enum (value, resample->sinc_filter_mode);
1111       break;
1112     case PROP_SINC_FILTER_AUTO_THRESHOLD:
1113       g_value_set_uint (value, resample->sinc_filter_auto_threshold);
1114       break;
1115     case PROP_SINC_FILTER_INTERPOLATION:
1116       g_value_set_enum (value, resample->sinc_filter_interpolation);
1117       break;
1118     default:
1119       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1120       break;
1121   }
1122 }
1123
1124 static gboolean
1125 plugin_init (GstPlugin * plugin)
1126 {
1127   return GST_ELEMENT_REGISTER (audioresample, plugin);
1128 }
1129
1130 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
1131     GST_VERSION_MINOR,
1132     audioresample,
1133     "Resamples audio", plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME,
1134     GST_PACKAGE_ORIGIN);