Ported speed Plugin to GStreamer 0.9

Original commit message from CVS:
Ported speed Plugin to GStreamer 0.9
This commit is contained in:
Flavio Oliveira 2005-09-08 15:56:38 +00:00
parent 82876ce896
commit 0b31be8a04
5 changed files with 64 additions and 91 deletions

View File

@ -1,5 +1,12 @@
=== release 0.9.1 === === release 0.9.1 ===
2005-09-08 Flavio Oliveira <flavio.oliveira@indt.org.br>
* configure.ac:
* gst/speed/Makefile.am:
* gst/speed/gstspeed.c: Ported to GStreamer 0.9.
* PORTED_09:
2005-09-06 Thomas Vander Stichele <thomas at apestaart dot org> 2005-09-06 Thomas Vander Stichele <thomas at apestaart dot org>
* NEWS: * NEWS:

View File

@ -1,6 +1,7 @@
When porting a plugin start with 0.8 CVS head, not the old code in this module. There are many bugfixes which have gone into 0.8 which you want to keep. When porting a plugin start with 0.8 CVS head, not the old code in this module. There are many bugfixes which have gone into 0.8 which you want to keep.
List of ported plugins (update when you commit a ported plugin): List of ported plugins (update when you commit a ported plugin):
speed (fcarvalho)
gsmenc (fcarvalho) gsmenc (fcarvalho)
faac (fcarvalho) faac (fcarvalho)
wavenc (fcarvalho) wavenc (fcarvalho)

View File

@ -434,6 +434,7 @@ Makefile
gst-plugins-bad.spec gst-plugins-bad.spec
gst/Makefile gst/Makefile
gst/qtdemux/Makefile gst/qtdemux/Makefile
gst/speed/Makefile
sys/Makefile sys/Makefile
ext/Makefile ext/Makefile
ext/faac/Makefile ext/faac/Makefile

View File

@ -8,10 +8,10 @@ libgstspeed_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
noinst_HEADERS = gstspeed.h noinst_HEADERS = gstspeed.h
if HAVE_GTK #if HAVE_GTK
noinst_PROGRAMS = demo-mp3 #noinst_PROGRAMS = demo-mp3
endif #endif
demo_mp3_SOURCES = demo-mp3.c #demo_mp3_SOURCES = demo-mp3.c
demo_mp3_CFLAGS = $(GTK_CFLAGS) $(GST_CFLAGS) #demo_mp3_CFLAGS = $(GTK_CFLAGS) $(GST_CFLAGS)
demo_mp3_LDFLAGS = $(GST_LIBS) $(GTK_LIBS) #demo_mp3_LDFLAGS = $(GST_LIBS) $(GTK_LIBS)

View File

@ -85,15 +85,15 @@ static void speed_get_property (GObject * object, guint prop_id, GValue * value,
static gboolean speed_parse_caps (GstSpeed * filter, const GstCaps * caps); static gboolean speed_parse_caps (GstSpeed * filter, const GstCaps * caps);
static void speed_chain (GstPad * pad, GstData * data); static GstFlowReturn speed_chain (GstPad * pad, GstBuffer * buf);
static GstStateChangeReturn speed_change_state (GstElement * element, static GstStateChangeReturn speed_change_state (GstElement * element,
GstStateChange transition); GstStateChange transition);
static GstElementClass *parent_class; /* NULL */ static GstElementClass *parent_class; /* NULL */
static GstPadLinkReturn static gboolean
speed_link (GstPad * pad, const GstCaps * caps) gst_speed_setcaps (GstPad * pad, GstCaps * caps)
{ {
GstSpeed *filter; GstSpeed *filter;
GstPad *otherpad; GstPad *otherpad;
@ -106,7 +106,7 @@ speed_link (GstPad * pad, const GstCaps * caps)
if (!speed_parse_caps (filter, caps)) if (!speed_parse_caps (filter, caps))
return GST_PAD_LINK_REFUSED; return GST_PAD_LINK_REFUSED;
return gst_pad_try_set_caps (otherpad, caps); return gst_pad_set_caps (otherpad, caps);
} }
static gboolean static gboolean
@ -174,7 +174,6 @@ static const GstQueryType *
speed_get_query_types (GstPad * pad) speed_get_query_types (GstPad * pad)
{ {
static const GstQueryType src_query_types[] = { static const GstQueryType src_query_types[] = {
GST_QUERY_TOTAL,
GST_QUERY_POSITION, GST_QUERY_POSITION,
0 0
}; };
@ -183,58 +182,17 @@ speed_get_query_types (GstPad * pad)
} }
static gboolean static gboolean
speed_src_query (GstPad * pad, GstQueryType type, speed_src_query (GstPad * pad, GstQuery * query)
GstFormat * format, gint64 * val)
{ {
gboolean res = TRUE; gboolean res = TRUE;
GstSpeed *filter; GstSpeed *filter;
filter = GST_SPEED (gst_pad_get_parent (pad)); filter = GST_SPEED (gst_pad_get_parent (pad));
switch (type) { switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_POSITION: 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; 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; break;
} }
default: default:
@ -279,7 +237,7 @@ speed_init (GstSpeed * filter)
filter->sinkpad = filter->sinkpad =
gst_pad_new_from_template (gst_static_pad_template_get gst_pad_new_from_template (gst_static_pad_template_get
(&gst_speed_sink_template), "sink"); (&gst_speed_sink_template), "sink");
gst_pad_set_link_function (filter->sinkpad, speed_link); gst_pad_set_setcaps_function (filter->sinkpad, gst_speed_setcaps);
gst_pad_set_chain_function (filter->sinkpad, speed_chain); gst_pad_set_chain_function (filter->sinkpad, speed_chain);
gst_pad_set_getcaps_function (filter->sinkpad, gst_pad_proxy_getcaps); gst_pad_set_getcaps_function (filter->sinkpad, gst_pad_proxy_getcaps);
gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad); gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
@ -287,7 +245,8 @@ speed_init (GstSpeed * filter)
filter->srcpad = filter->srcpad =
gst_pad_new_from_template (gst_static_pad_template_get gst_pad_new_from_template (gst_static_pad_template_get
(&gst_speed_src_template), "src"); (&gst_speed_src_template), "src");
gst_pad_set_link_function (filter->srcpad, speed_link); /*gst_pad_set_link_function (filter->srcpad, speed_link); */
gst_pad_set_setcaps_function (filter->srcpad, gst_speed_setcaps);
gst_pad_set_getcaps_function (filter->srcpad, gst_pad_proxy_getcaps); gst_pad_set_getcaps_function (filter->srcpad, gst_pad_proxy_getcaps);
gst_pad_set_query_type_function (filter->srcpad, speed_get_query_types); gst_pad_set_query_type_function (filter->srcpad, speed_get_query_types);
gst_pad_set_query_function (filter->srcpad, speed_src_query); gst_pad_set_query_function (filter->srcpad, speed_src_query);
@ -364,60 +323,64 @@ speed_chain_float32 (GstSpeed * filter, GstBuffer * in_buf, GstBuffer * out_buf,
return j; return j;
} }
static void static GstFlowReturn
speed_chain (GstPad * pad, GstData * data) speed_chain (GstPad * pad, GstBuffer * buf)
{ {
GstBuffer *in_buf, *out_buf; GstBuffer *out_buf;
GstSpeed *filter; GstSpeed *filter;
guint c, in_samples, out_samples, out_size; guint c, in_samples, out_samples, out_size;
GstFlowReturn result = GST_FLOW_OK;
/*
g_return_if_fail (pad != NULL); g_return_if_fail (pad != NULL);
g_return_if_fail (GST_IS_PAD (pad)); g_return_if_fail (GST_IS_PAD (pad));
g_return_if_fail (data != NULL); g_return_if_fail (data != NULL);
*/
filter = GST_SPEED (GST_OBJECT_PARENT (pad)); filter = GST_SPEED (GST_OBJECT_PARENT (pad));
g_return_if_fail (GST_IS_SPEED (filter)); /*g_return_if_fail (GST_IS_SPEED (filter)); */
if (GST_IS_EVENT (data)) { if (GST_IS_EVENT (buf)) {
switch (GST_EVENT_TYPE (GST_EVENT (data))) { switch (GST_EVENT_TYPE (GST_EVENT (buf))) {
case GST_EVENT_DISCONTINUOUS: case GST_EVENT_NEWSEGMENT:
{ { /*
gint64 timestamp, offset; gint64 timestamp, offset;
GstFormat format = GST_FORMAT_UNDEFINED;
gint64 value, end_value;
if (gst_event_discont_get_value (GST_EVENT (data), GST_FORMAT_TIME, gst_event_parse_newsegment (GST_EVENT (buf), NULL, &format, &value, &end_value, NULL);
&timestamp)) {
if (format == GST_FORMAT_TIME) {
filter->timestamp = timestamp; filter->timestamp = timestamp;
filter->offset = timestamp * filter->rate / GST_SECOND; filter->offset = timestamp * filter->rate / GST_SECOND;
} }
if (gst_event_discont_get_value (GST_EVENT (data), GST_FORMAT_BYTES, if (format == GST_FORMAT_BYTES) {
&offset)) {
filter->offset = offset; filter->offset = offset;
filter->timestamp = offset * GST_SECOND / filter->rate; filter->timestamp = offset * GST_SECOND / filter->rate;
} }
*/
break; break;
} }
default: default:
break; break;
} }
gst_pad_event_default (pad, GST_EVENT (data)); gst_pad_event_default (pad, GST_EVENT (buf));
return; return GST_FLOW_OK;
} }
in_buf = GST_BUFFER (data); out_size = ceil ((gfloat) GST_BUFFER_SIZE (buf) / filter->speed);
result =
gst_pad_alloc_buffer (filter->srcpad, -1, out_size,
GST_PAD_CAPS (filter->srcpad), &out_buf);
out_size = ceil ((gfloat) GST_BUFFER_SIZE (in_buf) / filter->speed); in_samples = GST_BUFFER_SIZE (buf) / filter->sample_size;
out_buf = gst_pad_alloc_buffer (filter->srcpad, -1, out_size);
in_samples = GST_BUFFER_SIZE (in_buf) / filter->sample_size;
out_samples = 0; out_samples = 0;
for (c = 0; c < filter->channels; ++c) { for (c = 0; c < filter->channels; ++c) {
if (filter->format == GST_SPEED_FORMAT_INT) { if (filter->format == GST_SPEED_FORMAT_INT) {
out_samples = speed_chain_int16 (filter, in_buf, out_buf, c, in_samples); out_samples = speed_chain_int16 (filter, buf, out_buf, c, in_samples);
} else { } else {
out_samples = out_samples = speed_chain_float32 (filter, buf, out_buf, c, in_samples);
speed_chain_float32 (filter, in_buf, out_buf, c, in_samples);
} }
} }
@ -432,9 +395,10 @@ speed_chain (GstPad * pad, GstData * data)
GST_BUFFER_DURATION (out_buf) = GST_BUFFER_DURATION (out_buf) =
filter->timestamp - GST_BUFFER_TIMESTAMP (out_buf); filter->timestamp - GST_BUFFER_TIMESTAMP (out_buf);
gst_pad_push (filter->srcpad, GST_DATA (out_buf)); gst_pad_push (filter->srcpad, out_buf);
gst_buffer_unref (in_buf); return result;
/*gst_buffer_unref (in_buf); */
} }
static void static void
@ -489,8 +453,8 @@ speed_change_state (GstElement * element, GstStateChange transition)
break; break;
} }
if (parent_class->change_state) if (GST_ELEMENT_CLASS (parent_class)->change_state)
return parent_class->change_state (element, transition); return GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
return GST_STATE_CHANGE_SUCCESS; return GST_STATE_CHANGE_SUCCESS;
} }