diff options
author | Tim-Philipp Müller <tim@centricular.net> | 2007-05-04 17:20:31 +0000 |
---|---|---|
committer | Tim-Philipp Müller <tim@centricular.net> | 2007-05-04 17:20:31 +0000 |
commit | 90c1858b2011602e83e377568b1bf2d2b8e64f33 (patch) | |
tree | 4576505ee792a1a0d841d5ff07b7f4a196d0cc65 | |
parent | e6d666c74737737bb4044f0717bf250e1112d069 (diff) | |
download | gst-plugins-bad-90c1858b2011602e83e377568b1bf2d2b8e64f33.tar.gz gst-plugins-bad-90c1858b2011602e83e377568b1bf2d2b8e64f33.tar.bz2 gst-plugins-bad-90c1858b2011602e83e377568b1bf2d2b8e64f33.zip |
gst/speed/gstspeed.c: Fix event handling a bit by replacing completely dubious code written by someone else with comp...
Original commit message from CVS:
* gst/speed/gstspeed.c: (speed_src_event), (speed_sink_event),
(speed_chain), (speed_change_state):
Fix event handling a bit by replacing completely dubious code
written by someone else with completely dubious code written
by me. Should at least fix #412077 though.
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | gst/speed/gstspeed.c | 135 |
2 files changed, 55 insertions, 88 deletions
@@ -1,5 +1,13 @@ 2007-05-04 Tim-Philipp Müller <tim at centricular dot net> + * gst/speed/gstspeed.c: (speed_src_event), (speed_sink_event), + (speed_chain), (speed_change_state): + Fix event handling a bit by replacing completely dubious code + written by someone else with completely dubious code written + by me. Should at least fix #412077 though. + +2007-05-04 Tim-Philipp Müller <tim at centricular dot net> + * gst/speed/gstspeed.c: (speed_src_query), (speed_chain), (plugin_init): Add debug category; use gst_pad_query_peer_*() utility functions; diff --git a/gst/speed/gstspeed.c b/gst/speed/gstspeed.c index 9bf97c6e..1d65f4f1 100644 --- a/gst/speed/gstspeed.c +++ b/gst/speed/gstspeed.c @@ -221,47 +221,41 @@ static gboolean speed_src_event (GstPad * pad, GstEvent * event) { GstSpeed *filter; - gboolean ret = TRUE; + gboolean ret = FALSE; filter = GST_SPEED (gst_pad_get_parent (pad)); switch (GST_EVENT_TYPE (event)) { - case GST_EVENT_SEEK: - { - + case GST_EVENT_SEEK:{ gdouble rate; GstFormat format; GstSeekFlags flags; GstSeekType start_type, stop_type; gint64 start, stop; - gst_event_parse_seek (event, &rate, &format, &flags, - &start_type, &start, &stop_type, &stop); - switch (format) { - case GST_FORMAT_DEFAULT: - /* fall through */ - case GST_FORMAT_BYTES: - /* fall through */ - case GST_FORMAT_TIME: - gst_event_unref (event); - - if (start_type != GST_SEEK_TYPE_NONE) { - start *= filter->speed; - } + gst_event_parse_seek (event, &rate, &format, &flags, &start_type, &start, + &stop_type, &stop); + gst_event_unref (event); - if (stop_type != GST_SEEK_TYPE_NONE) { - stop *= filter->speed; - } + if (format != GST_FORMAT_TIME) { + GST_DEBUG_OBJECT (filter, "only support seeks in TIME format"); + break; + } - event = gst_event_new_seek (rate, format, flags, start_type, start, - stop_type, stop); + if (start_type != GST_SEEK_TYPE_NONE && start != -1) { + start *= filter->speed; + } - ret = gst_pad_send_event (GST_PAD_PEER (filter->sinkpad), event); - break; - default: - break; + if (stop_type != GST_SEEK_TYPE_NONE && stop != -1) { + stop *= filter->speed; } + event = gst_event_new_seek (rate, format, flags, start_type, start, + stop_type, stop); + + GST_LOG ("sending seek event: %" GST_PTR_FORMAT, event->structure); + + ret = gst_pad_send_event (GST_PAD_PEER (filter->sinkpad), event); break; } default: @@ -589,87 +583,47 @@ speed_chain_float32 (GstSpeed * filter, GstBuffer * in_buf, GstBuffer * out_buf, static gboolean speed_sink_event (GstPad * pad, GstEvent * event) { - - GstSpeed *filter; - gboolean ret; + gboolean ret = FALSE; filter = GST_SPEED (gst_pad_get_parent (pad)); switch (GST_EVENT_TYPE (event)) { - case GST_EVENT_NEWSEGMENT: - { - + case GST_EVENT_NEWSEGMENT:{ gdouble rate; gboolean update = FALSE; - GstFormat format, conv_format; + GstFormat format; gint64 start_value, stop_value, base; gst_event_parse_new_segment (event, &update, &rate, &format, &start_value, &stop_value, &base); - - g_assert (filter->speed > 0); - - start_value /= filter->speed; - stop_value /= filter->speed; - - if (format == GST_FORMAT_TIME) { - - conv_format = GST_FORMAT_BYTES; - - filter->timestamp = start_value; - ret = gst_speed_convert (pad, GST_FORMAT_TIME, filter->timestamp, - &conv_format, &filter->offset); - - - } else if (format == GST_FORMAT_BYTES) { - - conv_format = GST_FORMAT_TIME; - - filter->offset = start_value; - ret = gst_speed_convert (pad, GST_FORMAT_BYTES, filter->offset, - &conv_format, &filter->timestamp); - - - } else if (format == GST_FORMAT_DEFAULT) { - - conv_format = GST_FORMAT_TIME; - - ret = gst_speed_convert (pad, GST_FORMAT_BYTES, start_value, - &conv_format, &filter->timestamp); - - conv_format = GST_FORMAT_BYTES; - - ret = gst_speed_convert (pad, GST_FORMAT_TIME, start_value, - &conv_format, &filter->offset); - - } - gst_event_unref (event); - event = - gst_event_new_new_segment (update, rate, format, start_value, - stop_value, base); - - if (!(ret = gst_pad_event_default (pad, event))) { - gst_event_unref (event); + if (format != GST_FORMAT_TIME) { + GST_WARNING_OBJECT (filter, "newsegment event not in TIME format!"); + break; } - ret = TRUE; - - break; - } + g_assert (filter->speed > 0); - case GST_EVENT_EOS: + if (start_value >= 0) + start_value /= filter->speed; + if (stop_value >= 0) + stop_value /= filter->speed; + base /= filter->speed; - if (!(ret = gst_pad_event_default (pad, event))) { - gst_event_unref (event); - } + /* this would only really be correct if we clipped incoming data */ + filter->timestamp = start_value; - ret = TRUE; + /* set to NONE so it gets reset later based on the timestamp when we have + * 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)); break; - + } default: ret = gst_pad_event_default (pad, event); break; @@ -698,6 +652,11 @@ speed_chain (GstPad * pad, GstBuffer * in_buf) goto done; } + if (G_UNLIKELY (filter->offset == GST_BUFFER_OFFSET_NONE)) { + filter->offset = + gst_util_uint64_scale_int (filter->timestamp, filter->rate, GST_SECOND); + } + /* buffersize has to be aligned by samplesize */ out_size = ceil ((gfloat) GST_BUFFER_SIZE (in_buf) / filter->speed); out_size = ((out_size + filter->sample_size - 1) / filter->sample_size) * @@ -788,7 +747,7 @@ speed_change_state (GstElement * element, GstStateChange transition) switch (transition) { case GST_STATE_CHANGE_READY_TO_PAUSED: - speed->offset = 0; + speed->offset = GST_BUFFER_OFFSET_NONE; speed->timestamp = 0; break; default: |