summaryrefslogtreecommitdiffstats
path: root/gst
diff options
context:
space:
mode:
Diffstat (limited to 'gst')
-rw-r--r--gst/audioresample/Makefile.am4
-rw-r--r--gst/audioresample/buffer.c5
-rw-r--r--gst/audioresample/functable.c4
-rw-r--r--gst/audioresample/gstaudioresample.c426
-rw-r--r--gst/audioresample/gstaudioresample.h23
-rw-r--r--gst/audioresample/resample.c16
-rw-r--r--gst/audioresample/resample.h11
-rw-r--r--gst/audioresample/resample_chunk.c6
-rw-r--r--gst/audioresample/resample_functable.c6
-rw-r--r--gst/audioresample/resample_ref.c6
10 files changed, 271 insertions, 236 deletions
diff --git a/gst/audioresample/Makefile.am b/gst/audioresample/Makefile.am
index bff05034..36fd56c5 100644
--- a/gst/audioresample/Makefile.am
+++ b/gst/audioresample/Makefile.am
@@ -15,7 +15,7 @@ resample_SOURCES = \
buffer.h
libgstaudioresample_la_SOURCES = gstaudioresample.c $(resample_SOURCES)
-libgstaudioresample_la_CFLAGS = $(GST_CFLAGS) $(LIBOIL_CFLAGS)
-libgstaudioresample_la_LIBADD = $(LIBOIL_LIBS)
+libgstaudioresample_la_CFLAGS = $(GST_BASE_CFLAGS) $(GST_CFLAGS) $(LIBOIL_CFLAGS)
+libgstaudioresample_la_LIBADD = $(GST_BASE_LIBS) $(GST_LIBS) $(LIBOIL_LIBS)
libgstaudioresample_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
diff --git a/gst/audioresample/buffer.c b/gst/audioresample/buffer.c
index f72e6056..679fa020 100644
--- a/gst/audioresample/buffer.c
+++ b/gst/audioresample/buffer.c
@@ -3,10 +3,11 @@
#include "config.h"
#endif
-#include <audioresample/buffer.h>
#include <glib.h>
#include <string.h>
-#include <audioresample/debug.h>
+
+#include "buffer.h"
+#include "debug.h"
static void audioresample_buffer_free_mem (AudioresampleBuffer * buffer,
void *);
diff --git a/gst/audioresample/functable.c b/gst/audioresample/functable.c
index 41844015..d627361f 100644
--- a/gst/audioresample/functable.c
+++ b/gst/audioresample/functable.c
@@ -26,8 +26,8 @@
#include <stdio.h>
#include <stdlib.h>
-#include <audioresample/functable.h>
-#include <audioresample/debug.h>
+#include "functable.h"
+#include "debug.h"
diff --git a/gst/audioresample/gstaudioresample.c b/gst/audioresample/gstaudioresample.c
index 363acd9b..f2549b28 100644
--- a/gst/audioresample/gstaudioresample.c
+++ b/gst/audioresample/gstaudioresample.c
@@ -1,5 +1,5 @@
/* GStreamer
- * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
+ * Copyright (C) 1999 Erik Walthinsen <omega@cse.ogi.edu>
* Copyright (C) 2003,2004 David A. Schleef <ds@schleef.org>
*
* This library is free software; you can redistribute it and/or
@@ -19,16 +19,17 @@
*/
/* Element-Checklist-Version: 5 */
-
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
+
#include <string.h>
#include <math.h>
/*#define DEBUG_ENABLED */
#include "gstaudioresample.h"
#include <gst/audio/audio.h>
+#include <gst/base/gstbasetransform.h>
GST_DEBUG_CATEGORY_STATIC (audioresample_debug);
#define GST_CAT_DEFAULT audioresample_debug
@@ -40,7 +41,7 @@ GST_ELEMENT_DETAILS ("Audio scaler",
"Resample audio",
"David Schleef <ds@schleef.org>");
-/* Audioresample signals and args */
+/* GstAudioresample signals and args */
enum
{
/* FILL ME */
@@ -79,63 +80,54 @@ enum
GST_PAD_SRC, GST_PAD_ALWAYS, SUPPORTED_CAPS);
static void gst_audioresample_base_init (gpointer g_class);
- static void gst_audioresample_class_init (AudioresampleClass * klass);
- static void gst_audioresample_init (Audioresample * audioresample);
+ static void gst_audioresample_class_init (GstAudioresampleClass * klass);
+ static void gst_audioresample_init (GstAudioresample * audioresample);
static void gst_audioresample_dispose (GObject * object);
- static void gst_audioresample_chain (GstPad * pad, GstData * _data);
-
static void gst_audioresample_set_property (GObject * object,
guint prop_id, const GValue * value, GParamSpec * pspec);
static void gst_audioresample_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec);
- static GstElementClass *parent_class = NULL;
+/* vmethods */
+ gboolean audioresample_get_unit_size (GstBaseTransform * base,
+ GstCaps * caps, guint * size);
+ GstCaps *audioresample_transform_caps (GstBaseTransform * base,
+ GstPadDirection direction, GstCaps * caps);
+ gboolean audioresample_transform_size (GstBaseTransform * trans,
+ GstPadDirection direction, GstCaps * incaps, guint insize,
+ GstCaps * outcaps, guint * outsize);
+ gboolean audioresample_set_caps (GstBaseTransform * base, GstCaps * incaps,
+ GstCaps * outcaps);
+ static GstFlowReturn audioresample_transform (GstBaseTransform * base,
+ GstBuffer * inbuf, GstBuffer * outbuf);
/*static guint gst_audioresample_signals[LAST_SIGNAL] = { 0 }; */
- GType audioresample_get_type (void)
- {
- static GType audioresample_type = 0;
-
- if (!audioresample_type)
- {
- static const GTypeInfo audioresample_info = {
- sizeof (AudioresampleClass),
- gst_audioresample_base_init,
- NULL,
- (GClassInitFunc) gst_audioresample_class_init,
- NULL,
- NULL,
- sizeof (Audioresample), 0,
- (GInstanceInitFunc) gst_audioresample_init,};
-
- audioresample_type =
- g_type_register_static (GST_TYPE_ELEMENT, "Audioresample",
- &audioresample_info, 0);
- }
- return audioresample_type;
- }
+#define DEBUG_INIT(bla) \
+ GST_DEBUG_CATEGORY_INIT (audioresample_debug, "audioresample", 0, "audio resampling element");
-static void gst_audioresample_base_init (gpointer g_class)
-{
- GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
+GST_BOILERPLATE_FULL (GstAudioresample, gst_audioresample, GstBaseTransform,
+ GST_TYPE_BASE_TRANSFORM, DEBUG_INIT);
- gst_element_class_add_pad_template (gstelement_class,
- gst_static_pad_template_get (&gst_audioresample_src_template));
- gst_element_class_add_pad_template (gstelement_class,
- gst_static_pad_template_get (&gst_audioresample_sink_template));
+ static void gst_audioresample_base_init (gpointer g_class)
+ {
+ GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
- gst_element_class_set_details (gstelement_class, &gst_audioresample_details);
-}
+ gst_element_class_add_pad_template (gstelement_class,
+ gst_static_pad_template_get (&gst_audioresample_src_template));
+ gst_element_class_add_pad_template (gstelement_class,
+ gst_static_pad_template_get (&gst_audioresample_sink_template));
-static void gst_audioresample_class_init (AudioresampleClass * klass)
+ gst_element_class_set_details (gstelement_class,
+ &gst_audioresample_details);
+ }
+
+static void gst_audioresample_class_init (GstAudioresampleClass * klass)
{
GObjectClass *gobject_class;
- GstElementClass *gstelement_class;
gobject_class = (GObjectClass *) klass;
- gstelement_class = (GstElementClass *) klass;
gobject_class->set_property = gst_audioresample_set_property;
gobject_class->get_property = gst_audioresample_get_property;
@@ -145,240 +137,270 @@ static void gst_audioresample_class_init (AudioresampleClass * klass)
g_param_spec_int ("filter_length", "filter_length", "filter_length",
0, G_MAXINT, 16, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
- parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
-
- GST_DEBUG_CATEGORY_INIT (audioresample_debug, "audioresample", 0,
- "audioresample element");
+ GST_BASE_TRANSFORM_CLASS (klass)->transform_size =
+ GST_DEBUG_FUNCPTR (audioresample_transform_size);
+ GST_BASE_TRANSFORM_CLASS (klass)->get_unit_size =
+ GST_DEBUG_FUNCPTR (audioresample_get_unit_size);
+ GST_BASE_TRANSFORM_CLASS (klass)->transform_caps =
+ GST_DEBUG_FUNCPTR (audioresample_transform_caps);
+ GST_BASE_TRANSFORM_CLASS (klass)->set_caps =
+ GST_DEBUG_FUNCPTR (audioresample_set_caps);
+ GST_BASE_TRANSFORM_CLASS (klass)->transform =
+ GST_DEBUG_FUNCPTR (audioresample_transform);
}
-static void gst_audioresample_expand_caps (GstCaps * caps)
+static void gst_audioresample_init (GstAudioresample * audioresample)
{
- gint i;
+ ResampleState *r;
- for (i = 0; i < gst_caps_get_size (caps); i++) {
- GstStructure *structure = gst_caps_get_structure (caps, i);
- const GValue *value;
+ r = resample_new ();
+ audioresample->resample = r;
- value = gst_structure_get_value (structure, "rate");
- if (value == NULL) {
- GST_ERROR ("caps structure doesn't have required rate field");
- return;
- }
+ resample_set_filter_length (r, 64);
+ resample_set_format (r, RESAMPLE_FORMAT_S16);
+}
+
+static void gst_audioresample_dispose (GObject * object)
+{
+ GstAudioresample *audioresample = GST_AUDIORESAMPLE (object);
- gst_structure_set (structure, "rate", GST_TYPE_INT_RANGE, 1, G_MAXINT, 0);
+ if (audioresample->resample) {
+ resample_free (audioresample->resample);
+ audioresample->resample = NULL;
}
+
+ G_OBJECT_CLASS (parent_class)->dispose (object);
}
-static GstCaps *gst_audioresample_getcaps (GstPad * pad)
-{
- Audioresample *audioresample;
- GstCaps *caps;
- GstPad *otherpad;
+/* vmethods */
+gboolean
+ audioresample_get_unit_size (GstBaseTransform * base, GstCaps * caps,
+ guint * size) {
+ gint width, channels;
+ GstStructure *structure;
+ gboolean ret;
- audioresample = GST_AUDIORESAMPLE (gst_pad_get_parent (pad));
+ g_return_val_if_fail (size, FALSE);
- otherpad = (pad == audioresample->srcpad) ? audioresample->sinkpad :
- audioresample->srcpad;
- caps = gst_pad_get_allowed_caps (otherpad);
+ /* this works for both float and int */
+ structure = gst_caps_get_structure (caps, 0);
+ ret = gst_structure_get_int (structure, "width", &width);
+ ret &= gst_structure_get_int (structure, "channels", &channels);
+ g_return_val_if_fail (ret, FALSE);
- gst_audioresample_expand_caps (caps);
+ *size = width * channels / 8;
- return caps;
+ return TRUE;
}
-static GstCaps *gst_audioresample_fixate (GstPad * pad, const GstCaps * caps)
+GstCaps *audioresample_transform_caps (GstBaseTransform * base,
+ GstPadDirection direction, GstCaps * caps)
{
- Audioresample *audioresample;
- GstPad *otherpad;
- int rate;
- GstCaps *copy;
+ GstCaps *temp, *res;
+ const GstCaps *templcaps;
GstStructure *structure;
- audioresample = GST_AUDIORESAMPLE (gst_pad_get_parent (pad));
+ temp = gst_caps_copy (caps);
+ structure = gst_caps_get_structure (temp, 0);
+ gst_structure_remove_field (structure, "rate");
+ templcaps = gst_pad_get_pad_template_caps (base->srcpad);
+ res = gst_caps_intersect (templcaps, temp);
+ gst_caps_unref (temp);
- if (pad == audioresample->srcpad) {
- otherpad = audioresample->sinkpad;
- rate = audioresample->i_rate;
- } else
- {
- otherpad = audioresample->srcpad;
- rate = audioresample->o_rate;
- }
- if (!GST_PAD_IS_NEGOTIATING (otherpad))
- return NULL;
- if (gst_caps_get_size (caps) > 1)
- return NULL;
-
- copy = gst_caps_copy (caps);
- structure = gst_caps_get_structure (copy, 0);
- if (rate) {
- if (gst_caps_structure_fixate_field_nearest_int (structure, "rate", rate)) {
- return copy;
- }
- }
- gst_caps_free (copy);
- return NULL;
+ return res;
}
-static GstPadLinkReturn gst_audioresample_link (GstPad * pad,
- const GstCaps * caps)
+static gboolean
+ resample_set_state_from_caps (ResampleState * state, GstCaps * incaps,
+ GstCaps * outcaps, gint * channels, gint * inrate, gint * outrate)
{
- Audioresample *audioresample;
GstStructure *structure;
- int rate;
- int channels;
gboolean ret;
- GstPad *otherpad;
+ gint myinrate, myoutrate;
+ int mychannels;
- audioresample = GST_AUDIORESAMPLE (gst_pad_get_parent (pad));
+ GST_DEBUG ("incaps %" GST_PTR_FORMAT ", outcaps %"
+ GST_PTR_FORMAT, incaps, outcaps);
- otherpad = (pad == audioresample->srcpad) ? audioresample->sinkpad :
- audioresample->srcpad;
+ structure = gst_caps_get_structure (incaps, 0);
- structure = gst_caps_get_structure (caps, 0);
- ret = gst_structure_get_int (structure, "rate", &rate);
- ret &= gst_structure_get_int (structure, "channels", &channels);
- if (!ret)
- {
- return GST_PAD_LINK_REFUSED;
+ /* FIXME: once it does float, set the correct format */
+#if 0
+ if (g_str_equal (gst_structure_get_name (structure), "audio/x-raw-float")) {
+ r->format = GST_RESAMPLE_FLOAT;
+ } else {
+ r->format = GST_RESAMPLE_S16;
}
+#endif
- if (gst_pad_is_negotiated (otherpad))
- {
- GstCaps *othercaps = gst_caps_copy (caps);
- int otherrate;
- GstPadLinkReturn linkret;
+ ret = gst_structure_get_int (structure, "rate", &myinrate);
+ ret &= gst_structure_get_int (structure, "channels", &mychannels);
+ g_return_val_if_fail (ret, FALSE);
- if (pad == audioresample->srcpad) {
- otherrate = audioresample->i_rate;
- } else {
- otherrate = audioresample->o_rate;
- }
- gst_caps_set_simple (othercaps, "rate", G_TYPE_INT, otherrate, NULL);
- linkret = gst_pad_try_set_caps (otherpad, othercaps);
- if (GST_PAD_LINK_FAILED (linkret)) {
- return GST_PAD_LINK_REFUSED;
- }
+ structure = gst_caps_get_structure (outcaps, 0);
+ ret = gst_structure_get_int (structure, "rate", &myoutrate);
+ g_return_val_if_fail (ret, FALSE);
- }
+ if (channels)
+ *channels = mychannels;
+ if (inrate)
+ *inrate = myinrate;
+ if (outrate)
+ *outrate = myoutrate;
- audioresample->channels = channels;
- resample_set_n_channels (audioresample->resample, audioresample->channels);
- if (pad == audioresample->srcpad) {
- audioresample->o_rate = rate;
- resample_set_output_rate (audioresample->resample, audioresample->o_rate);
- GST_DEBUG ("set o_rate to %d", rate);
- } else {
- audioresample->i_rate = rate;
- resample_set_input_rate (audioresample->resample, audioresample->i_rate);
- GST_DEBUG ("set i_rate to %d", rate);
- }
+ resample_set_n_channels (state, mychannels);
+ resample_set_input_rate (state, myinrate);
+ resample_set_output_rate (state, myoutrate);
- return GST_PAD_LINK_OK;
+ return TRUE;
}
-static void gst_audioresample_init (Audioresample * audioresample)
+gboolean audioresample_transform_size (GstBaseTransform * base,
+ GstPadDirection direction, GstCaps * caps, guint size, GstCaps * othercaps,
+ guint * othersize)
{
- ResampleState *r;
+ GstAudioresample *audioresample = GST_AUDIORESAMPLE (base);
+ ResampleState *state;
+ GstCaps *srccaps, *sinkcaps;
+ gboolean use_internal = FALSE; /* whether we use the internal state */
+ gboolean ret = TRUE;
+
+ /* FIXME: make sure incaps/outcaps get renamed to caps/othercaps, since
+ * interpretation depends on the direction */
+ if (direction == GST_PAD_SINK) {
+ sinkcaps = caps;
+ srccaps = othercaps;
+ } else {
+ sinkcaps = othercaps;
+ srccaps = caps;
+ }
- audioresample->sinkpad =
- gst_pad_new_from_template (gst_static_pad_template_get
- (&gst_audioresample_sink_template), "sink");
- gst_element_add_pad (GST_ELEMENT (audioresample), audioresample->sinkpad);
- gst_pad_set_chain_function (audioresample->sinkpad, gst_audioresample_chain);
- gst_pad_set_link_function (audioresample->sinkpad, gst_audioresample_link);
- gst_pad_set_getcaps_function (audioresample->sinkpad,
- gst_audioresample_getcaps);
- gst_pad_set_fixate_function (audioresample->sinkpad,
- gst_audioresample_fixate);
-
- audioresample->srcpad =
- gst_pad_new_from_template (gst_static_pad_template_get
- (&gst_audioresample_src_template), "src");
-
- gst_element_add_pad (GST_ELEMENT (audioresample), audioresample->srcpad);
- gst_pad_set_link_function (audioresample->srcpad, gst_audioresample_link);
- gst_pad_set_getcaps_function (audioresample->srcpad,
- gst_audioresample_getcaps);
- gst_pad_set_fixate_function (audioresample->srcpad, gst_audioresample_fixate);
+ /* if the caps are the ones that _set_caps got called with; we can use
+ * our own state; otherwise we'll have to create a state */
+ if (gst_caps_is_equal (sinkcaps, audioresample->sinkcaps) &&
+ gst_caps_is_equal (srccaps, audioresample->srccaps)) {
+ use_internal = TRUE;
+ state = audioresample->resample;
+ } else {
+ state = resample_new ();
+ resample_set_state_from_caps (state, sinkcaps, srccaps, NULL, NULL, NULL);
+ }
- r = resample_new ();
- audioresample->resample = r;
+ /* we can use our own state to answer the question */
+ if (direction == GST_PAD_SINK) {
+ /* asked to convert size of an incoming buffer */
+ *othersize = resample_get_output_size_for_input (state, size);
+ } else {
+ /* take a best guess, this is called cheating */
+ *othersize = floor (size * state->i_rate / state->o_rate);
+ }
- resample_set_filter_length (r, 64);
- resample_set_format (r, RESAMPLE_FORMAT_S16);
+ if (!use_internal) {
+ resample_free (state);
+ }
+
+ return ret;
}
-static void gst_audioresample_dispose (GObject * object)
+gboolean audioresample_set_caps (GstBaseTransform * base, GstCaps * incaps,
+ GstCaps * outcaps)
{
- Audioresample *audioresample = GST_AUDIORESAMPLE (object);
+ gboolean ret;
+ gint inrate, outrate;
+ int channels;
+ GstAudioresample *audioresample = GST_AUDIORESAMPLE (base);
- if (audioresample->resample) {
- resample_free (audioresample->resample);
- }
+ GST_DEBUG_OBJECT (base, "incaps %" GST_PTR_FORMAT ", outcaps %"
+ GST_PTR_FORMAT, incaps, outcaps);
- G_OBJECT_CLASS (parent_class)->dispose (object);
+ ret = resample_set_state_from_caps (audioresample->resample, incaps, outcaps,
+ &channels, &inrate, &outrate);
+
+ g_return_val_if_fail (ret, FALSE);
+
+ audioresample->channels = channels;
+ GST_DEBUG_OBJECT (audioresample, "set channels to %d", channels);
+ audioresample->i_rate = inrate;
+ GST_DEBUG_OBJECT (audioresample, "set i_rate to %d", inrate);
+ audioresample->o_rate = outrate;
+ GST_DEBUG_OBJECT (audioresample, "set o_rate to %d", outrate);
+
+ /* save caps so we can short-circuit in the size_transform if the caps
+ * are the same */
+ /* FIXME: clean them up in state change ? */
+ gst_caps_ref (incaps);
+ gst_caps_replace (&audioresample->sinkcaps, incaps);
+ gst_caps_ref (outcaps);
+ gst_caps_replace (&audioresample->srccaps, outcaps);
+
+ return TRUE;
}
-static void gst_audioresample_chain (GstPad * pad, GstData * _data)
+static GstFlowReturn
+ audioresample_transform (GstBaseTransform * base, GstBuffer * inbuf,
+ GstBuffer * outbuf)
{
- GstBuffer *buf = GST_BUFFER (_data);
- Audioresample *audioresample;
+ /* FIXME: this-> */
+ GstAudioresample *audioresample = GST_AUDIORESAMPLE (base);
ResampleState *r;
guchar *data;
gulong size;
int outsize;
- GstBuffer *outbuf;
-
- g_return_if_fail (pad != NULL);
- g_return_if_fail (GST_IS_PAD (pad));
- g_return_if_fail (buf != NULL);
-
- audioresample = GST_AUDIORESAMPLE (gst_pad_get_parent (pad));
-
- if (!GST_IS_BUFFER (_data)) {
- gst_pad_push (audioresample->srcpad, _data);
- return;
- }
+ /* FIXME: move to _inplace */
+#if 0
if (audioresample->passthru) {
gst_pad_push (audioresample->srcpad, GST_DATA (buf));
return;
}
+#endif
r = audioresample->resample;
- data = GST_BUFFER_DATA (buf);
- size = GST_BUFFER_SIZE (buf);
+ data = GST_BUFFER_DATA (inbuf);
+ size = GST_BUFFER_SIZE (inbuf);
- GST_DEBUG ("got buffer of %ld bytes", size);
+ GST_DEBUG_OBJECT (audioresample, "got buffer of %ld bytes", size);
- resample_add_input_data (r, data, size, (ResampleCallback) gst_data_unref,
- buf);
+ resample_add_input_data (r, data, size, NULL, NULL);
outsize = resample_get_output_size (r);
- /* FIXME this is audioresample being dumb. dunno why */
- if (outsize == 0) {
- GST_ERROR ("overriding outbuf size");
- outsize = size;
+ if (outsize != GST_BUFFER_SIZE (outbuf)) {
+ GST_WARNING_OBJECT (audioresample,
+ "overriding audioresample's outsize %d with outbuffer's size %d",
+ outsize, GST_BUFFER_SIZE (outbuf));
+ outsize = GST_BUFFER_SIZE (outbuf);
}
- outbuf = gst_buffer_new_and_alloc (outsize);
outsize = resample_get_output_data (r, GST_BUFFER_DATA (outbuf), outsize);
- GST_BUFFER_SIZE (outbuf) = outsize;
-
GST_BUFFER_TIMESTAMP (outbuf) =
audioresample->offset * GST_SECOND / audioresample->o_rate;
audioresample->offset += outsize / sizeof (gint16) / audioresample->channels;
- gst_pad_push (audioresample->srcpad, GST_DATA (outbuf));
+ if (outsize != GST_BUFFER_SIZE (outbuf)) {
+ GST_WARNING_OBJECT (audioresample,
+ "audioresample, you bastard ! you only gave me %d bytes, not %d",
+ outsize, GST_BUFFER_SIZE (outbuf));
+ /* if the size we get is smaller than the buffer, it's still fine; we
+ * just waste a bit of space on the end */
+ if (outsize < GST_BUFFER_SIZE (outbuf)) {
+ GST_BUFFER_SIZE (outbuf) = outsize;
+ return GST_FLOW_OK;
+ } else {
+ /* this is an error that needs fixing in the resample library; we told
+ * it we wanted only GST_BUFFER_SIZE (outbuf), and it gave us more ! */
+ return GST_FLOW_ERROR;
+ }
+ }
+
+ return GST_FLOW_OK;
}
static void
gst_audioresample_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
- Audioresample *audioresample;
+ GstAudioresample *audioresample;
g_return_if_fail (GST_IS_AUDIORESAMPLE (object));
audioresample = GST_AUDIORESAMPLE (object);
@@ -400,7 +422,7 @@ static void
gst_audioresample_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
- Audioresample *audioresample;
+ GstAudioresample *audioresample;
g_return_if_fail (GST_IS_AUDIORESAMPLE (object));
audioresample = GST_AUDIORESAMPLE (object);
@@ -431,4 +453,4 @@ static gboolean plugin_init (GstPlugin * plugin)
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR,
"audioresample",
- "Resamples audio", plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN)
+ "Resamples audio", plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN);
diff --git a/gst/audioresample/gstaudioresample.h b/gst/audioresample/gstaudioresample.h
index fc5115da..99d937bb 100644
--- a/gst/audioresample/gstaudioresample.h
+++ b/gst/audioresample/gstaudioresample.h
@@ -23,31 +23,32 @@
#include <gst/gst.h>
+#include <gst/base/gstbasetransform.h>
-#include <audioresample/resample.h>
+#include "resample.h"
G_BEGIN_DECLS
#define GST_TYPE_AUDIORESAMPLE \
- (audioresample_get_type())
+ (gst_audioresample_get_type())
#define GST_AUDIORESAMPLE(obj) \
- (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AUDIORESAMPLE,Audioresample))
+ (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AUDIORESAMPLE,GstAudioresample))
#define GST_AUDIORESAMPLE_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AUDIORESAMPLE,Audioresample))
+ (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AUDIORESAMPLE,GstAudioresample))
#define GST_IS_AUDIORESAMPLE(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AUDIORESAMPLE))
#define GST_IS_AUDIORESAMPLE_CLASS(obj) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AUDIORESAMPLE))
-typedef struct _Audioresample Audioresample;
-typedef struct _AudioresampleClass AudioresampleClass;
+typedef struct _GstAudioresample GstAudioresample;
+typedef struct _GstAudioresampleClass GstAudioresampleClass;
-struct _Audioresample {
- GstElement element;
+struct _GstAudioresample {
+ GstBaseTransform element;
- GstPad *sinkpad,*srcpad;
+ GstCaps *srccaps, *sinkcaps;
gboolean passthru;
@@ -61,8 +62,8 @@ struct _Audioresample {
ResampleState * resample;
};
-struct _AudioresampleClass {
- GstElementClass parent_class;
+struct _GstAudioresampleClass {
+ GstBaseTransformClass parent_class;
};
GType gst_audioresample_get_type(void);
diff --git a/gst/audioresample/resample.c b/gst/audioresample/resample.c
index 38c6ba84..e8ec45fb 100644
--- a/gst/audioresample/resample.c
+++ b/gst/audioresample/resample.c
@@ -29,9 +29,9 @@
#include <limits.h>
#include <liboil/liboil.h>
-#include <audioresample/resample.h>
-#include <audioresample/buffer.h>
-#include <audioresample/debug.h>
+#include "resample.h"
+#include "buffer.h"
+#include "debug.h"
void resample_scale_ref (ResampleState * r);
void resample_scale_functable (ResampleState * r);
@@ -101,6 +101,10 @@ resample_buffer_free (AudioresampleBuffer * buffer, void *priv)
}
}
+/**
+ * free_func: a function that frees the given closure. If NULL, caller is
+ * responsible for freeing.
+ */
void
resample_add_input_data (ResampleState * r, void *data, int size,
void (*free_func) (void *), void *closure)
@@ -135,6 +139,12 @@ resample_input_eos (ResampleState * r)
}
int
+resample_get_output_size_for_input (ResampleState * r, int size)
+{
+ return floor (size * r->o_rate / r->i_rate);
+}
+
+int
resample_get_output_size (ResampleState * r)
{
return floor (audioresample_buffer_queue_get_depth (r->queue) * r->o_rate /
diff --git a/gst/audioresample/resample.h b/gst/audioresample/resample.h
index 9be54f46..ea4aa305 100644
--- a/gst/audioresample/resample.h
+++ b/gst/audioresample/resample.h
@@ -21,8 +21,8 @@
#ifndef __RESAMPLE_H__
#define __RESAMPLE_H__
-#include <audioresample/functable.h>
-#include <audioresample/buffer.h>
+#include "functable.h"
+#include "buffer.h"
typedef enum {
RESAMPLE_FORMAT_S16 = 0,
@@ -89,8 +89,8 @@ struct _ResampleState {
double *out_tmp;
};
-void resample_init(void);
-void resample_cleanup(void);
+void resample_init (void);
+void resample_cleanup (void);
ResampleState *resample_new (void);
void resample_free (ResampleState *state);
@@ -98,6 +98,8 @@ void resample_free (ResampleState *state);
void resample_add_input_data (ResampleState * r, void *data, int size,
ResampleCallback free_func, void *closure);
void resample_input_eos (ResampleState *r);
+
+int resample_get_output_size_for_input (ResampleState * r, int size);
int resample_get_output_size (ResampleState *r);
int resample_get_output_data (ResampleState *r, void *data, int size);
@@ -109,6 +111,5 @@ void resample_set_format (ResampleState *r, ResampleFormat format);
void resample_set_method (ResampleState *r, int method);
int resample_format_size (ResampleFormat format);
-
#endif /* __RESAMPLE_H__ */
diff --git a/gst/audioresample/resample_chunk.c b/gst/audioresample/resample_chunk.c
index 53755e62..c91e1f2a 100644
--- a/gst/audioresample/resample_chunk.c
+++ b/gst/audioresample/resample_chunk.c
@@ -29,9 +29,9 @@
#include <limits.h>
#include <liboil/liboil.h>
-#include <audioresample/resample.h>
-#include <audioresample/buffer.h>
-#include <audioresample/debug.h>
+#include "resample.h"
+#include "buffer.h"
+#include "debug.h"
static double
diff --git a/gst/audioresample/resample_functable.c b/gst/audioresample/resample_functable.c
index af5f9253..7db06ff8 100644
--- a/gst/audioresample/resample_functable.c
+++ b/gst/audioresample/resample_functable.c
@@ -29,9 +29,9 @@
#include <limits.h>
#include <liboil/liboil.h>
-#include <audioresample/resample.h>
-#include <audioresample/buffer.h>
-#include <audioresample/debug.h>
+#include "resample.h"
+#include "buffer.h"
+#include "debug.h"
static void
func_sinc (double *fx, double *dfx, double x, void *closure)
diff --git a/gst/audioresample/resample_ref.c b/gst/audioresample/resample_ref.c
index a4623e71..6717aa23 100644
--- a/gst/audioresample/resample_ref.c
+++ b/gst/audioresample/resample_ref.c
@@ -29,9 +29,9 @@
#include <limits.h>
#include <liboil/liboil.h>
-#include <audioresample/resample.h>
-#include <audioresample/buffer.h>
-#include <audioresample/debug.h>
+#include "resample.h"
+#include "buffer.h"
+#include "debug.h"
static double