2001-12-22 23:26:33 +00:00
|
|
|
/* -*- c-basic-offset: 2 -*-
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 1999-2001 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2003-06-29 19:46:13 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2003-10-08 07:50:58 +00:00
|
|
|
# include "config.h"
|
2003-06-29 19:46:13 +00:00
|
|
|
#endif
|
2003-10-08 07:50:58 +00:00
|
|
|
|
2001-12-22 23:26:33 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
2003-10-08 07:50:58 +00:00
|
|
|
#include <gst/gst.h>
|
2001-12-23 12:18:18 +00:00
|
|
|
#include <gst/audio/audio.h>
|
2003-10-08 07:50:58 +00:00
|
|
|
|
2001-12-22 23:26:33 +00:00
|
|
|
#include "gstspeed.h"
|
|
|
|
|
2002-09-18 19:02:52 +00:00
|
|
|
/* elementfactory information */
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstElementDetails speed_details = GST_ELEMENT_DETAILS ("Speed",
|
|
|
|
"Filter/Effect/Audio",
|
|
|
|
"Set speed/pitch on audio/raw streams (resampler)",
|
2005-02-10 15:06:13 +00:00
|
|
|
"Andy Wingo <apwingo@eos.ncsu.edu>, "
|
|
|
|
"Tim-Philipp Müller <tim@centricular.net>");
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-12-22 23:26:33 +00:00
|
|
|
ARG_0,
|
|
|
|
ARG_SPEED
|
|
|
|
};
|
|
|
|
|
2005-02-10 15:06:13 +00:00
|
|
|
/* assumption here: sizeof (gfloat) = 4 */
|
|
|
|
#define GST_SPEED_AUDIO_CAPS \
|
|
|
|
"audio/x-raw-float, " \
|
|
|
|
"rate = (int) [ 1, MAX ], " \
|
|
|
|
"channels = (int) [ 1, MAX ], " \
|
|
|
|
"endianness = (int) BYTE_ORDER, " \
|
|
|
|
"width = (int) 32, " \
|
|
|
|
"buffer-frames = (int) 0; " \
|
|
|
|
\
|
|
|
|
"audio/x-raw-int, " \
|
|
|
|
"rate = (int) [ 1, MAX ], " \
|
|
|
|
"channels = (int) [ 1, MAX ], " \
|
|
|
|
"endianness = (int) BYTE_ORDER, " \
|
|
|
|
"width = (int) 16, " \
|
|
|
|
"depth = (int) 16, " \
|
|
|
|
"signed = (boolean) true"
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
static GstStaticPadTemplate gst_speed_sink_template =
|
2005-02-10 15:06:13 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
2003-12-22 01:47:09 +00:00
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2005-02-10 15:06:13 +00:00
|
|
|
GST_STATIC_CAPS (GST_SPEED_AUDIO_CAPS)
|
2004-03-14 22:34:33 +00:00
|
|
|
);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
static GstStaticPadTemplate gst_speed_src_template =
|
2005-02-10 15:06:13 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
2003-12-22 01:47:09 +00:00
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2005-02-10 15:06:13 +00:00
|
|
|
GST_STATIC_CAPS (GST_SPEED_AUDIO_CAPS)
|
2004-03-14 22:34:33 +00:00
|
|
|
);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void speed_base_init (gpointer g_class);
|
|
|
|
static void speed_class_init (GstSpeedClass * klass);
|
|
|
|
static void speed_init (GstSpeed * filter);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void speed_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void speed_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static gboolean speed_parse_caps (GstSpeed * filter, const GstCaps * caps);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2005-02-10 15:06:13 +00:00
|
|
|
static void speed_chain (GstPad * pad, GstData * data);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2005-02-10 15:06:13 +00:00
|
|
|
static GstElementStateReturn speed_change_state (GstElement * element);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2005-02-10 15:06:13 +00:00
|
|
|
static GstElementClass *parent_class; /* NULL */
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2003-01-10 13:38:32 +00:00
|
|
|
static GstPadLinkReturn
|
2004-03-14 22:34:33 +00:00
|
|
|
speed_link (GstPad * pad, const GstCaps * caps)
|
2001-12-22 23:26:33 +00:00
|
|
|
{
|
2002-02-17 17:34:23 +00:00
|
|
|
GstSpeed *filter;
|
2002-02-19 05:59:06 +00:00
|
|
|
GstPad *otherpad;
|
2003-10-08 07:50:58 +00:00
|
|
|
|
2002-02-17 17:34:23 +00:00
|
|
|
filter = GST_SPEED (gst_pad_get_parent (pad));
|
2003-01-10 10:22:25 +00:00
|
|
|
g_return_val_if_fail (filter != NULL, GST_PAD_LINK_REFUSED);
|
|
|
|
g_return_val_if_fail (GST_IS_SPEED (filter), GST_PAD_LINK_REFUSED);
|
2005-02-10 15:06:13 +00:00
|
|
|
otherpad = (pad == filter->srcpad) ? filter->sinkpad : filter->srcpad;
|
2003-10-08 07:50:58 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (!speed_parse_caps (filter, caps))
|
|
|
|
return GST_PAD_LINK_REFUSED;
|
2003-10-08 07:50:58 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
return gst_pad_try_set_caps (otherpad, caps);
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
|
|
|
|
2002-02-17 17:34:23 +00:00
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
speed_parse_caps (GstSpeed * filter, const GstCaps * caps)
|
2001-12-22 23:26:33 +00:00
|
|
|
{
|
2003-07-06 20:49:52 +00:00
|
|
|
const gchar *mimetype;
|
2003-12-22 01:47:09 +00:00
|
|
|
GstStructure *structure;
|
|
|
|
gboolean ret;
|
2003-07-19 23:47:42 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
g_return_val_if_fail (filter != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (caps != NULL, FALSE);
|
2003-07-19 23:47:42 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
|
2005-02-10 15:06:13 +00:00
|
|
|
mimetype = gst_structure_get_name (structure);
|
|
|
|
if (strcmp (mimetype, "audio/x-raw-float") == 0)
|
|
|
|
filter->format = GST_SPEED_FORMAT_FLOAT;
|
|
|
|
else if (strcmp (mimetype, "audio/x-raw-int") == 0)
|
|
|
|
filter->format = GST_SPEED_FORMAT_INT;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
ret = gst_structure_get_int (structure, "rate", &filter->rate);
|
|
|
|
ret &= gst_structure_get_int (structure, "channels", &filter->channels);
|
|
|
|
ret &= gst_structure_get_int (structure, "width", &filter->width);
|
2004-04-29 03:38:16 +00:00
|
|
|
|
|
|
|
filter->buffer_frames = 0;
|
|
|
|
gst_structure_get_int (structure, "buffer-frames", &filter->buffer_frames);
|
2003-10-08 07:50:58 +00:00
|
|
|
|
2005-02-10 15:06:13 +00:00
|
|
|
if (filter->format == GST_SPEED_FORMAT_FLOAT) {
|
|
|
|
filter->sample_size = filter->channels * filter->width / 8;
|
2004-03-14 22:34:33 +00:00
|
|
|
} else {
|
2005-02-10 15:06:13 +00:00
|
|
|
/* our caps only allow width == depth for now */
|
|
|
|
filter->sample_size = filter->channels * filter->width / 8;
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
2005-02-10 15:06:13 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
return ret;
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GType
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_speed_get_type (void)
|
|
|
|
{
|
2001-12-22 23:26:33 +00:00
|
|
|
static GType speed_type = 0;
|
|
|
|
|
|
|
|
if (!speed_type) {
|
|
|
|
static const GTypeInfo speed_info = {
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstSpeedClass),
|
2003-11-02 22:34:11 +00:00
|
|
|
speed_base_init,
|
2001-12-22 23:26:33 +00:00
|
|
|
NULL,
|
2004-03-14 22:34:33 +00:00
|
|
|
(GClassInitFunc) speed_class_init,
|
2001-12-22 23:26:33 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstSpeed),
|
2001-12-22 23:26:33 +00:00
|
|
|
0,
|
2004-03-14 22:34:33 +00:00
|
|
|
(GInstanceInitFunc) speed_init,
|
2001-12-22 23:26:33 +00:00
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
speed_type =
|
2004-03-15 19:32:27 +00:00
|
|
|
g_type_register_static (GST_TYPE_ELEMENT, "GstSpeed", &speed_info, 0);
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
|
|
|
return speed_type;
|
|
|
|
}
|
|
|
|
|
2005-02-15 11:05:35 +00:00
|
|
|
static const GstQueryType *
|
|
|
|
speed_get_query_types (GstPad * pad)
|
|
|
|
{
|
|
|
|
static const GstQueryType src_query_types[] = {
|
|
|
|
GST_QUERY_TOTAL,
|
|
|
|
GST_QUERY_POSITION,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
return src_query_types;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
speed_src_query (GstPad * pad, GstQueryType type,
|
|
|
|
GstFormat * format, gint64 * val)
|
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
GstSpeed *filter;
|
|
|
|
|
|
|
|
filter = GST_SPEED (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case GST_QUERY_POSITION:
|
|
|
|
case GST_QUERY_TOTAL:
|
|
|
|
{
|
|
|
|
switch (*format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
case GST_FORMAT_DEFAULT:
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
{
|
|
|
|
gint64 peer_value;
|
|
|
|
const GstFormat *peer_formats;
|
|
|
|
|
|
|
|
res = FALSE;
|
|
|
|
|
|
|
|
peer_formats = gst_pad_get_formats (GST_PAD_PEER (filter->sinkpad));
|
|
|
|
|
|
|
|
while (peer_formats && *peer_formats && !res) {
|
|
|
|
|
|
|
|
GstFormat peer_format = *peer_formats;
|
|
|
|
|
|
|
|
/* do the probe */
|
|
|
|
if (gst_pad_query (GST_PAD_PEER (filter->sinkpad), type,
|
|
|
|
&peer_format, &peer_value)) {
|
|
|
|
GstFormat conv_format;
|
|
|
|
|
|
|
|
/* convert to TIME */
|
|
|
|
conv_format = GST_FORMAT_TIME;
|
|
|
|
res = gst_pad_convert (filter->sinkpad,
|
|
|
|
peer_format, peer_value, &conv_format, val);
|
|
|
|
|
|
|
|
/* adjust for speed factor */
|
|
|
|
*val = (gint64) (((gdouble) * val) / filter->speed);
|
|
|
|
|
|
|
|
/* and to final format */
|
|
|
|
res &= gst_pad_convert (pad, GST_FORMAT_TIME, *val, format, val);
|
|
|
|
}
|
|
|
|
peer_formats++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2003-11-02 22:34:11 +00:00
|
|
|
static void
|
|
|
|
speed_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
|
|
|
gst_element_class_set_details (element_class, &speed_details);
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&gst_speed_src_template));
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&gst_speed_sink_template));
|
2003-11-02 22:34:11 +00:00
|
|
|
}
|
2001-12-22 23:26:33 +00:00
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
speed_class_init (GstSpeedClass * klass)
|
2001-12-22 23:26:33 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
2005-02-10 15:06:13 +00:00
|
|
|
GstElementClass *gstelement_class = (GstElementClass *) klass;
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2003-10-08 07:50:58 +00:00
|
|
|
gobject_class->set_property = speed_set_property;
|
|
|
|
gobject_class->get_property = speed_get_property;
|
2005-02-10 15:06:13 +00:00
|
|
|
gstelement_class->change_state = speed_change_state;
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2005-02-10 15:06:13 +00:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SPEED,
|
|
|
|
g_param_spec_float ("speed", "speed", "speed",
|
2004-03-15 19:32:27 +00:00
|
|
|
0.1, 40.0, 1.0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
speed_init (GstSpeed * filter)
|
2001-12-22 23:26:33 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
filter->sinkpad =
|
|
|
|
gst_pad_new_from_template (gst_static_pad_template_get
|
|
|
|
(&gst_speed_sink_template), "sink");
|
|
|
|
gst_pad_set_link_function (filter->sinkpad, speed_link);
|
2005-02-10 15:06:13 +00:00
|
|
|
gst_pad_set_chain_function (filter->sinkpad, speed_chain);
|
|
|
|
gst_pad_set_getcaps_function (filter->sinkpad, gst_pad_proxy_getcaps);
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
|
|
|
|
|
|
|
|
filter->srcpad =
|
|
|
|
gst_pad_new_from_template (gst_static_pad_template_get
|
|
|
|
(&gst_speed_src_template), "src");
|
|
|
|
gst_pad_set_link_function (filter->srcpad, speed_link);
|
2005-02-10 15:06:13 +00:00
|
|
|
gst_pad_set_getcaps_function (filter->srcpad, gst_pad_proxy_getcaps);
|
2005-02-15 11:05:35 +00:00
|
|
|
gst_pad_set_query_type_function (filter->srcpad, speed_get_query_types);
|
|
|
|
gst_pad_set_query_function (filter->srcpad, speed_src_query);
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
|
|
|
|
|
2005-02-10 15:06:13 +00:00
|
|
|
filter->offset = 0;
|
|
|
|
filter->timestamp = 0;
|
|
|
|
filter->sample_size = 0;
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
|
|
|
|
2005-02-10 15:06:13 +00:00
|
|
|
static inline guint
|
|
|
|
speed_chain_int16 (GstSpeed * filter, GstBuffer * in_buf, GstBuffer * out_buf,
|
|
|
|
guint c, guint in_samples)
|
2001-12-22 23:26:33 +00:00
|
|
|
{
|
2005-02-10 15:06:13 +00:00
|
|
|
gint16 *in_data, *out_data;
|
|
|
|
gfloat interp, lower, i_float;
|
|
|
|
guint i, j;
|
2003-10-08 07:50:58 +00:00
|
|
|
|
2005-02-10 15:06:13 +00:00
|
|
|
in_data = ((gint16 *) GST_BUFFER_DATA (in_buf)) + c;
|
|
|
|
out_data = ((gint16 *) GST_BUFFER_DATA (out_buf)) + c;
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2005-02-10 15:06:13 +00:00
|
|
|
lower = in_data[0];
|
|
|
|
i_float = 0.5 * (filter->speed - 1.0);
|
|
|
|
i = (guint) ceil (i_float);
|
|
|
|
j = 0;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2005-02-10 15:06:13 +00:00
|
|
|
while (i < in_samples) {
|
|
|
|
interp = i_float - floor (i_float);
|
2003-10-08 07:50:58 +00:00
|
|
|
|
2005-02-10 15:06:13 +00:00
|
|
|
out_data[j * filter->channels] =
|
|
|
|
lower * (1 - interp) + in_data[i * filter->channels] * interp;
|
|
|
|
|
|
|
|
lower = in_data[i * filter->channels];
|
|
|
|
|
|
|
|
i_float += filter->speed;
|
|
|
|
i = (guint) ceil (i_float);
|
|
|
|
|
|
|
|
++j;
|
2002-05-30 19:08:04 +00:00
|
|
|
}
|
2003-10-08 07:50:58 +00:00
|
|
|
|
2005-02-10 15:06:13 +00:00
|
|
|
return j;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline guint
|
|
|
|
speed_chain_float32 (GstSpeed * filter, GstBuffer * in_buf, GstBuffer * out_buf,
|
|
|
|
guint c, guint in_samples)
|
|
|
|
{
|
|
|
|
gfloat *in_data, *out_data;
|
|
|
|
gfloat interp, lower, i_float;
|
|
|
|
guint i, j;
|
|
|
|
|
|
|
|
in_data = ((gfloat *) GST_BUFFER_DATA (in_buf)) + c;
|
|
|
|
out_data = ((gfloat *) GST_BUFFER_DATA (out_buf)) + c;
|
|
|
|
|
|
|
|
lower = in_data[0];
|
|
|
|
i_float = 0.5 * (filter->speed - 1.0);
|
|
|
|
i = (guint) ceil (i_float);
|
|
|
|
j = 0;
|
|
|
|
|
|
|
|
while (i < in_samples) {
|
|
|
|
interp = i_float - floor (i_float);
|
|
|
|
|
|
|
|
out_data[j * filter->channels] =
|
|
|
|
lower * (1 - interp) + in_data[i * filter->channels] * interp;
|
|
|
|
|
|
|
|
lower = in_data[i * filter->channels];
|
|
|
|
|
|
|
|
i_float += filter->speed;
|
|
|
|
i = (guint) ceil (i_float);
|
|
|
|
|
|
|
|
++j;
|
2002-05-27 04:17:57 +00:00
|
|
|
}
|
|
|
|
|
2005-02-10 15:06:13 +00:00
|
|
|
return j;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
speed_chain (GstPad * pad, GstData * data)
|
|
|
|
{
|
|
|
|
GstBuffer *in_buf, *out_buf;
|
|
|
|
GstSpeed *filter;
|
|
|
|
guint c, in_samples, out_samples, out_size;
|
|
|
|
|
|
|
|
g_return_if_fail (pad != NULL);
|
|
|
|
g_return_if_fail (GST_IS_PAD (pad));
|
|
|
|
g_return_if_fail (data != NULL);
|
|
|
|
|
|
|
|
filter = GST_SPEED (GST_OBJECT_PARENT (pad));
|
|
|
|
g_return_if_fail (GST_IS_SPEED (filter));
|
|
|
|
|
|
|
|
if (GST_IS_EVENT (data)) {
|
|
|
|
switch (GST_EVENT_TYPE (GST_EVENT (data))) {
|
|
|
|
case GST_EVENT_DISCONTINUOUS:
|
|
|
|
{
|
|
|
|
gint64 timestamp, offset;
|
|
|
|
|
2005-02-15 11:05:35 +00:00
|
|
|
if (gst_event_discont_get_value (GST_EVENT (data), GST_FORMAT_TIME,
|
|
|
|
×tamp)) {
|
|
|
|
filter->timestamp = timestamp;
|
|
|
|
filter->offset = timestamp * filter->rate / GST_SECOND;
|
|
|
|
}
|
2005-02-10 15:06:13 +00:00
|
|
|
if (gst_event_discont_get_value (GST_EVENT (data), GST_FORMAT_BYTES,
|
|
|
|
&offset)) {
|
|
|
|
filter->offset = offset;
|
2005-02-15 11:05:35 +00:00
|
|
|
filter->timestamp = offset * GST_SECOND / filter->rate;
|
2005-02-10 15:06:13 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
gst_pad_event_default (pad, GST_EVENT (data));
|
|
|
|
return;
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
2005-02-10 15:06:13 +00:00
|
|
|
|
|
|
|
in_buf = GST_BUFFER (data);
|
|
|
|
|
|
|
|
out_size = ceil ((gfloat) GST_BUFFER_SIZE (in_buf) / filter->speed);
|
|
|
|
out_buf = gst_pad_alloc_buffer (filter->srcpad, -1, out_size);
|
|
|
|
|
|
|
|
in_samples = GST_BUFFER_SIZE (in_buf) / filter->sample_size;
|
|
|
|
|
|
|
|
out_samples = 0;
|
|
|
|
|
|
|
|
for (c = 0; c < filter->channels; ++c) {
|
|
|
|
if (filter->format == GST_SPEED_FORMAT_INT) {
|
|
|
|
out_samples = speed_chain_int16 (filter, in_buf, out_buf, c, in_samples);
|
|
|
|
} else {
|
|
|
|
out_samples =
|
|
|
|
speed_chain_float32 (filter, in_buf, out_buf, c, in_samples);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_BUFFER_SIZE (out_buf) = out_samples * filter->sample_size;
|
|
|
|
|
|
|
|
GST_BUFFER_OFFSET (out_buf) = filter->offset;
|
|
|
|
GST_BUFFER_TIMESTAMP (out_buf) = filter->timestamp;
|
|
|
|
|
|
|
|
filter->offset += GST_BUFFER_SIZE (out_buf) / filter->sample_size;
|
|
|
|
filter->timestamp = filter->offset * GST_SECOND / filter->rate;
|
|
|
|
|
|
|
|
GST_BUFFER_DURATION (out_buf) =
|
|
|
|
filter->timestamp - GST_BUFFER_TIMESTAMP (out_buf);
|
|
|
|
|
|
|
|
gst_pad_push (filter->srcpad, GST_DATA (out_buf));
|
|
|
|
|
|
|
|
gst_buffer_unref (in_buf);
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
speed_set_property (GObject * object, guint prop_id, const GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2001-12-22 23:26:33 +00:00
|
|
|
{
|
2005-02-10 15:06:13 +00:00
|
|
|
GstSpeed *filter = (GstSpeed *) object;
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
g_return_if_fail (GST_IS_SPEED (object));
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
switch (prop_id) {
|
2001-12-22 23:26:33 +00:00
|
|
|
case ARG_SPEED:
|
|
|
|
filter->speed = g_value_get_float (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
speed_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2001-12-22 23:26:33 +00:00
|
|
|
{
|
2005-02-10 15:06:13 +00:00
|
|
|
GstSpeed *filter = (GstSpeed *) object;
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
g_return_if_fail (GST_IS_SPEED (object));
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_SPEED:
|
|
|
|
g_value_set_float (value, filter->speed);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-10 15:06:13 +00:00
|
|
|
static GstElementStateReturn
|
|
|
|
speed_change_state (GstElement * element)
|
|
|
|
{
|
|
|
|
GstSpeed *speed = GST_SPEED (element);
|
|
|
|
|
|
|
|
switch (GST_STATE_TRANSITION (element)) {
|
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_PAUSED:
|
|
|
|
speed->offset = 0;
|
|
|
|
speed->timestamp = 0;
|
|
|
|
speed->sample_size = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parent_class->change_state)
|
|
|
|
return parent_class->change_state (element);
|
|
|
|
|
|
|
|
return GST_STATE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2001-12-22 23:26:33 +00:00
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
plugin_init (GstPlugin * plugin)
|
2001-12-22 23:26:33 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
return gst_element_register (plugin, "speed", GST_RANK_NONE, GST_TYPE_SPEED);
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"speed",
|
|
|
|
"Set speed/pitch on audio/raw streams (resampler)",
|
|
|
|
plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN)
|