speed: port to 0.11

https://bugzilla.gnome.org/show_bug.cgi?id=683727
This commit is contained in:
Sreerenj Balachandran 2012-09-10 17:16:07 +03:00 committed by Olivier Crête
parent 5111a6ed20
commit 98ffddb0f8
3 changed files with 109 additions and 144 deletions

View file

@ -318,7 +318,7 @@ GST_PLUGINS_NONPORTED=" aiff \
kate librfb \
mpegpsmux mve mxf mythtv nsf nuvdemux \
patchdetect pnm real \
sdi speed subenc stereo tta videofilters \
sdi subenc stereo tta videofilters \
videomeasure videosignal vmnc \
decklink fbdev linsys vcd \
apexsink cdaudio cog dc1394 dirac directfb \

View file

@ -3,7 +3,7 @@ plugin_LTLIBRARIES = libgstspeed.la
libgstspeed_la_SOURCES = gstspeed.c
libgstspeed_la_CFLAGS = $(GST_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS)
libgstspeed_la_LIBADD = $(GST_LIBS) $(GST_PLUGINS_BASE_LIBS) $(LIBM)
libgstspeed_la_LIBADD = $(GST_LIBS) $(GST_PLUGINS_BASE_LIBS) $(LIBM) -lgstaudio-$(GST_API_VERSION)
libgstspeed_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstspeed_la_LIBTOOLFLAGS = --tag=disable-static

View file

@ -60,19 +60,15 @@ enum
/* assumption here: sizeof (gfloat) = 4 */
#define GST_SPEED_AUDIO_CAPS \
"audio/x-raw-float, " \
"audio/x-raw, " \
"format = (string) " GST_AUDIO_NE (F32) ", " \
"rate = (int) [ 8000, MAX ], " \
"channels = (int) [ 1, 2 ]; " \
\
"audio/x-raw, " \
"format = (string) " GST_AUDIO_NE (S16) ", " \
"rate = (int) [ 1, MAX ], " \
"channels = (int) [ 1, MAX ], " \
"endianness = (int) BYTE_ORDER, " \
"width = (int) 32; " \
\
"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"
"channels = (int) [ 1, MAX ]"
static GstStaticPadTemplate gst_speed_sink_template =
GST_STATIC_PAD_TEMPLATE ("sink",
@ -88,10 +84,6 @@ GST_STATIC_PAD_TEMPLATE ("src",
GST_STATIC_CAPS (GST_SPEED_AUDIO_CAPS)
);
static void speed_base_init (gpointer g_class);
static void speed_class_init (GstSpeedClass * klass);
static void speed_init (GstSpeed * filter);
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,
@ -99,60 +91,57 @@ static void speed_get_property (GObject * object, guint prop_id, GValue * value,
static gboolean speed_parse_caps (GstSpeed * filter, const GstCaps * caps);
static GstFlowReturn speed_chain (GstPad * pad, GstBuffer * buf);
static GstFlowReturn speed_chain (GstPad * pad, GstObject * parent,
GstBuffer * buf);
static GstStateChangeReturn speed_change_state (GstElement * element,
GstStateChange transition);
static gboolean speed_sink_event (GstPad * pad, GstEvent * event);
static gboolean speed_src_event (GstPad * pad, GstEvent * event);
static gboolean speed_sink_event (GstPad * pad, GstObject * parent,
GstEvent * event);
static gboolean speed_src_event (GstPad * pad, GstObject * parent,
GstEvent * event);
static GstElementClass *parent_class; /* NULL */
#define gst_speed_parent_class parent_class
G_DEFINE_TYPE (GstSpeed, gst_speed, GST_TYPE_ELEMENT);
static gboolean
speed_setcaps (GstPad * pad, GstCaps * caps)
{
GstSpeed *filter;
GstPad *otherpad;
gboolean ret;
filter = GST_SPEED (gst_pad_get_parent (pad));
otherpad = (pad == filter->srcpad) ? filter->sinkpad : filter->srcpad;
if ((ret = speed_parse_caps (filter, caps)))
ret = gst_pad_set_caps (otherpad, caps);
ret = speed_parse_caps (filter, caps);
gst_object_unref (filter);
return ret;
}
static gboolean
speed_parse_caps (GstSpeed * filter, const GstCaps * caps)
{
GstStructure *structure;
GstAudioInfo info;
gint rate, chans, width;
g_return_val_if_fail (filter != NULL, FALSE);
g_return_val_if_fail (caps != NULL, FALSE);
structure = gst_caps_get_structure (caps, 0);
gst_audio_info_from_caps (&info, caps);
if (gst_structure_has_name (structure, "audio/x-raw-float"))
if (GST_AUDIO_INFO_IS_FLOAT (&info))
filter->format = GST_SPEED_FORMAT_FLOAT;
else if (gst_structure_has_name (structure, "audio/x-raw-int"))
else if (GST_AUDIO_INFO_IS_INTEGER (&info))
filter->format = GST_SPEED_FORMAT_INT;
else
return FALSE;
if (!gst_structure_get_int (structure, "rate", &rate)
|| !gst_structure_get_int (structure, "width", &width)
|| !gst_structure_get_int (structure, "channels", &chans)) {
rate = info.rate;
width = GST_AUDIO_INFO_WIDTH (&info);
chans = info.channels;
if (!rate || !width || !chans)
return FALSE;
}
filter->rate = rate;
filter->width = width;
@ -168,49 +157,13 @@ speed_parse_caps (GstSpeed * filter, const GstCaps * caps)
return TRUE;
}
GType
gst_speed_get_type (void)
{
static GType speed_type = 0;
if (!speed_type) {
static const GTypeInfo speed_info = {
sizeof (GstSpeedClass),
speed_base_init,
NULL,
(GClassInitFunc) speed_class_init,
NULL,
NULL,
sizeof (GstSpeed),
0,
(GInstanceInitFunc) speed_init,
};
speed_type =
g_type_register_static (GST_TYPE_ELEMENT, "GstSpeed", &speed_info, 0);
}
return speed_type;
}
static const GstQueryType *
speed_get_query_types (GstPad * pad)
{
static const GstQueryType src_query_types[] = {
GST_QUERY_POSITION,
GST_QUERY_DURATION,
0
};
return src_query_types;
}
static gboolean
speed_src_event (GstPad * pad, GstEvent * event)
speed_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
{
GstSpeed *filter;
gboolean ret = FALSE;
filter = GST_SPEED (gst_pad_get_parent (pad));
filter = GST_SPEED (parent);
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_SEEK:{
@ -240,19 +193,18 @@ speed_src_event (GstPad * pad, GstEvent * event)
event = gst_event_new_seek (rate, format, flags, start_type, start,
stop_type, stop);
GST_LOG ("sending seek event: %" GST_PTR_FORMAT, event->structure);
GST_LOG ("sending seek event: %" GST_PTR_FORMAT,
gst_event_get_structure (event));
ret = gst_pad_send_event (GST_PAD_PEER (filter->sinkpad), event);
break;
}
default:
ret = gst_pad_event_default (pad, event);
ret = gst_pad_event_default (pad, parent, event);
break;
}
gst_object_unref (filter);
return ret;
}
static gboolean
@ -332,12 +284,12 @@ gst_speed_convert (GstPad * pad, GstFormat src_format, gint64 src_value,
}
static gboolean
speed_src_query (GstPad * pad, GstQuery * query)
speed_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
{
gboolean ret = TRUE;
GstSpeed *filter;
filter = GST_SPEED (gst_pad_get_parent (pad));
filter = GST_SPEED (parent);
switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_POSITION:
@ -353,7 +305,7 @@ speed_src_query (GstPad * pad, GstQuery * query)
/* query peer for current position in time */
gst_query_set_position (query, GST_FORMAT_TIME, -1);
if (!gst_pad_query_peer_position (filter->sinkpad, &rformat, &cur)) {
if (!gst_pad_peer_query_position (filter->sinkpad, rformat, &cur)) {
GST_LOG_OBJECT (filter, "query on peer pad failed");
goto error;
}
@ -400,7 +352,7 @@ speed_src_query (GstPad * pad, GstQuery * query)
/* query peer for total length in time */
gst_query_set_duration (query, GST_FORMAT_TIME, -1);
if (!gst_pad_query_peer_duration (filter->sinkpad, &rformat, &end)) {
if (!gst_pad_peer_query_duration (filter->sinkpad, rformat, &end)) {
GST_LOG_OBJECT (filter, "query on peer pad failed");
goto error;
}
@ -440,7 +392,6 @@ speed_src_query (GstPad * pad, GstQuery * query)
break;
}
gst_object_unref (filter);
return ret;
error:
@ -451,24 +402,7 @@ error:
}
static void
speed_base_init (gpointer g_class)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
gst_element_class_set_details_simple (element_class, "Speed",
"Filter/Effect/Audio",
"Set speed/pitch on audio/raw streams (resampler)",
"Andy Wingo <apwingo@eos.ncsu.edu>, "
"Tim-Philipp Müller <tim@centricular.net>");
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));
}
static void
speed_class_init (GstSpeedClass * klass)
gst_speed_class_init (GstSpeedClass * klass)
{
GObjectClass *gobject_class = (GObjectClass *) klass;
GstElementClass *gstelement_class = (GstElementClass *) klass;
@ -477,32 +411,39 @@ speed_class_init (GstSpeedClass * klass)
gobject_class->get_property = speed_get_property;
gstelement_class->change_state = speed_change_state;
parent_class = g_type_class_peek_parent (klass);
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SPEED,
g_param_spec_float ("speed", "speed", "speed",
0.1, 40.0, 1.0,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
gst_element_class_set_details_simple (gstelement_class, "Speed",
"Filter/Effect/Audio",
"Set speed/pitch on audio/raw streams (resampler)",
"Andy Wingo <apwingo@eos.ncsu.edu>, "
"Tim-Philipp Müller <tim@centricular.net>");
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&gst_speed_src_template));
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&gst_speed_sink_template));
}
static void
speed_init (GstSpeed * filter)
gst_speed_init (GstSpeed * filter)
{
filter->sinkpad =
gst_pad_new_from_static_template (&gst_speed_sink_template, "sink");
gst_pad_set_setcaps_function (filter->sinkpad, speed_setcaps);
gst_pad_set_chain_function (filter->sinkpad, speed_chain);
gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
gst_pad_set_event_function (filter->sinkpad, speed_sink_event);
GST_PAD_SET_PROXY_CAPS (filter->sinkpad);
filter->srcpad =
gst_pad_new_from_static_template (&gst_speed_src_template, "src");
gst_pad_set_setcaps_function (filter->srcpad, speed_setcaps);
gst_pad_set_query_type_function (filter->srcpad, speed_get_query_types);
gst_pad_set_query_function (filter->srcpad, speed_src_query);
gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
gst_pad_set_event_function (filter->srcpad, speed_src_event);
GST_PAD_SET_PROXY_CAPS (filter->srcpad);
filter->offset = 0;
filter->timestamp = 0;
@ -517,9 +458,13 @@ speed_chain_int16 (GstSpeed * filter, GstBuffer * in_buf, GstBuffer * out_buf,
gint16 *in_data, *out_data;
gfloat interp, lower, i_float;
guint i, j;
GstMapInfo in_info, out_info;
in_data = ((gint16 *) GST_BUFFER_DATA (in_buf)) + c;
out_data = ((gint16 *) GST_BUFFER_DATA (out_buf)) + c;
gst_buffer_map (in_buf, &in_info, GST_MAP_READ);
gst_buffer_map (out_buf, &out_info, GST_MAP_WRITE);
in_data = (gint16 *) in_info.data + c;
out_data = (gint16 *) out_info.data + c;
lower = in_data[0];
i_float = 0.5 * (filter->speed - 1.0);
@ -540,6 +485,8 @@ speed_chain_int16 (GstSpeed * filter, GstBuffer * in_buf, GstBuffer * out_buf,
++j;
}
gst_buffer_unmap (in_buf, &in_info);
gst_buffer_unmap (out_buf, &out_info);
return j;
}
@ -550,9 +497,13 @@ speed_chain_float32 (GstSpeed * filter, GstBuffer * in_buf, GstBuffer * out_buf,
gfloat *in_data, *out_data;
gfloat interp, lower, i_float;
guint i, j;
GstMapInfo in_info, out_info;
in_data = ((gfloat *) GST_BUFFER_DATA (in_buf)) + c;
out_data = ((gfloat *) GST_BUFFER_DATA (out_buf)) + c;
gst_buffer_map (in_buf, &in_info, GST_MAP_WRITE);
gst_buffer_map (out_buf, &out_info, GST_MAP_WRITE);
in_data = (gfloat *) in_info.data + c;
out_data = (gfloat *) out_info.data + c;
lower = in_data[0];
i_float = 0.5 * (filter->speed - 1.0);
@ -572,28 +523,36 @@ speed_chain_float32 (GstSpeed * filter, GstBuffer * in_buf, GstBuffer * out_buf,
++j;
}
gst_buffer_unmap (in_buf, &in_info);
gst_buffer_unmap (out_buf, &out_info);
return j;
}
static gboolean
speed_sink_event (GstPad * pad, GstEvent * event)
speed_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
{
GstSpeed *filter;
gboolean ret = FALSE;
filter = GST_SPEED (gst_pad_get_parent (pad));
filter = GST_SPEED (parent);
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_NEWSEGMENT:{
case GST_EVENT_SEGMENT:{
gdouble rate;
gboolean update = FALSE;
GstFormat format;
gint64 start_value, stop_value, base;
const GstSegment *segment;
GstSegment seg;
gst_event_parse_segment (event, &segment);
rate = segment->rate;
format = segment->format;
start_value = segment->start;
stop_value = segment->stop;
base = segment->base;
gst_event_parse_new_segment (event, &update, &rate, &format, &start_value,
&stop_value, &base);
gst_event_unref (event);
if (format != GST_FORMAT_TIME) {
@ -616,33 +575,44 @@ speed_sink_event (GstPad * pad, GstEvent * event)
* the samplerate */
filter->offset = GST_BUFFER_OFFSET_NONE;
ret =
gst_pad_event_default (pad, gst_event_new_new_segment (update, rate,
format, start_value, stop_value, base));
gst_segment_init (&seg, GST_FORMAT_TIME);
seg.rate = rate;
seg.start = start_value;
seg.stop = stop_value;
seg.time = segment->time;
ret = gst_pad_push_event (filter->srcpad, gst_event_new_segment (&seg));
break;
}
case GST_EVENT_CAPS:
{
GstCaps *caps;
gst_event_parse_caps (event, &caps);
ret = speed_setcaps (pad, caps);
if (!ret) {
gst_event_unref (event);
return ret;
}
}
default:
ret = gst_pad_event_default (pad, event);
ret = gst_pad_event_default (pad, parent, event);
break;
}
gst_object_unref (filter);
return ret;
}
static GstFlowReturn
speed_chain (GstPad * pad, GstBuffer * in_buf)
speed_chain (GstPad * pad, GstObject * parent, GstBuffer * in_buf)
{
GstBuffer *out_buf;
GstSpeed *filter;
guint c, in_samples, out_samples, out_size;
GstFlowReturn flow;
gsize size;
filter = GST_SPEED (GST_PAD_PARENT (pad));
filter = GST_SPEED (parent);
if (G_UNLIKELY (filter->sample_size == 0 || filter->rate == 0)) {
flow = GST_FLOW_NOT_NEGOTIATED;
@ -655,18 +625,13 @@ speed_chain (GstPad * pad, GstBuffer * in_buf)
}
/* buffersize has to be aligned by samplesize */
out_size = ceil ((gfloat) GST_BUFFER_SIZE (in_buf) / filter->speed);
out_size = ceil ((gfloat) gst_buffer_get_size (in_buf) / filter->speed);
out_size = ((out_size + filter->sample_size - 1) / filter->sample_size) *
filter->sample_size;
flow =
gst_pad_alloc_buffer_and_set_caps (filter->srcpad, -1, out_size,
GST_PAD_CAPS (filter->srcpad), &out_buf);
out_buf = gst_buffer_new_and_alloc (out_size);
if (flow != GST_FLOW_OK)
goto done;
in_samples = GST_BUFFER_SIZE (in_buf) / filter->sample_size;
in_samples = gst_buffer_get_size (in_buf) / filter->sample_size;
out_samples = 0;
@ -679,19 +644,19 @@ speed_chain (GstPad * pad, GstBuffer * in_buf)
}
}
GST_BUFFER_SIZE (out_buf) = out_samples * filter->sample_size;
size = out_samples * filter->sample_size;
gst_buffer_set_size (out_buf, 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->offset += size / filter->sample_size;
filter->timestamp =
gst_util_uint64_scale_int (filter->offset, GST_SECOND, filter->rate);
/* make sure it's at least nominally a perfect stream */
GST_BUFFER_DURATION (out_buf) =
filter->timestamp - GST_BUFFER_TIMESTAMP (out_buf);
flow = gst_pad_push (filter->srcpad, out_buf);
done: