ext/soundtouch/gstpitch.cc: Allow seeking only in TIME and DEFAULT format, other formats will not work as expected. A...
Original commit message from CVS: * ext/soundtouch/gstpitch.cc: Allow seeking only in TIME and DEFAULT format, other formats will not work as expected. Also handle a stop position of -1 correctly for seeks, newsegment events and the queries. This fixes playback with the pitch element if upstream doesn't know the duration or has -1 as stop position in NEWSEGMENT events for other reasons. Before simply nothing was played as the segment was going from 0 to 0. Send a GST_MESSAGE_DURATION whenever the rate or tempo is changed so applications can update their cached duration. Fixes bug #503308. Some random cleanup and memory leak closing.
This commit is contained in:
parent
82dc68af48
commit
b05b9d04d6
15
ChangeLog
15
ChangeLog
@ -1,3 +1,18 @@
|
|||||||
|
2008-01-26 Sebastian Dröge <slomo@circular-chaos.org>
|
||||||
|
|
||||||
|
* ext/soundtouch/gstpitch.cc:
|
||||||
|
Allow seeking only in TIME and DEFAULT format, other formats will
|
||||||
|
not work as expected. Also handle a stop position of -1 correctly
|
||||||
|
for seeks, newsegment events and the queries. This fixes playback
|
||||||
|
with the pitch element if upstream doesn't know the duration or has
|
||||||
|
-1 as stop position in NEWSEGMENT events for other reasons. Before
|
||||||
|
simply nothing was played as the segment was going from 0 to 0.
|
||||||
|
|
||||||
|
Send a GST_MESSAGE_DURATION whenever the rate or tempo is changed
|
||||||
|
so applications can update their cached duration. Fixes bug #503308.
|
||||||
|
|
||||||
|
Some random cleanup and memory leak closing.
|
||||||
|
|
||||||
2008-01-26 Sebastian Dröge <slomo@circular-chaos.org>
|
2008-01-26 Sebastian Dröge <slomo@circular-chaos.org>
|
||||||
|
|
||||||
* ext/musepack/gstmusepackdec.h:
|
* ext/musepack/gstmusepackdec.h:
|
||||||
|
@ -38,13 +38,6 @@
|
|||||||
#include "gstpitch.hh"
|
#include "gstpitch.hh"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
/* wtf ?
|
|
||||||
#ifdef G_PARAM_READWRITE
|
|
||||||
# undef G_PARAM_READWRITE
|
|
||||||
#endif
|
|
||||||
#define G_PARAM_READWRITE ((GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE))
|
|
||||||
*/
|
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY_STATIC (pitch_debug);
|
GST_DEBUG_CATEGORY_STATIC (pitch_debug);
|
||||||
#define GST_CAT_DEFAULT pitch_debug
|
#define GST_CAT_DEFAULT pitch_debug
|
||||||
|
|
||||||
@ -215,6 +208,15 @@ gst_pitch_dispose (GObject * object)
|
|||||||
G_OBJECT_CLASS (parent_class)->dispose (object);
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_pitch_update_duration (GstPitch * pitch)
|
||||||
|
{
|
||||||
|
GstMessage *m;
|
||||||
|
|
||||||
|
m = gst_message_new_duration (GST_OBJECT (pitch), GST_FORMAT_TIME, -1);
|
||||||
|
gst_element_post_message (GST_ELEMENT (pitch), m);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_pitch_set_property (GObject * object, guint prop_id,
|
gst_pitch_set_property (GObject * object, guint prop_id,
|
||||||
const GValue * value, GParamSpec * pspec)
|
const GValue * value, GParamSpec * pspec)
|
||||||
@ -227,21 +229,26 @@ gst_pitch_set_property (GObject * object, guint prop_id,
|
|||||||
pitch->tempo = g_value_get_float (value);
|
pitch->tempo = g_value_get_float (value);
|
||||||
pitch->priv->stream_time_ratio = pitch->tempo * pitch->rate;
|
pitch->priv->stream_time_ratio = pitch->tempo * pitch->rate;
|
||||||
pitch->priv->st->setTempo (pitch->tempo);
|
pitch->priv->st->setTempo (pitch->tempo);
|
||||||
|
GST_OBJECT_UNLOCK (pitch);
|
||||||
|
gst_pitch_update_duration (pitch);
|
||||||
break;
|
break;
|
||||||
case ARG_RATE:
|
case ARG_RATE:
|
||||||
pitch->rate = g_value_get_float (value);
|
pitch->rate = g_value_get_float (value);
|
||||||
pitch->priv->stream_time_ratio = pitch->tempo * pitch->rate;
|
pitch->priv->stream_time_ratio = pitch->tempo * pitch->rate;
|
||||||
pitch->priv->st->setRate (pitch->rate);
|
pitch->priv->st->setRate (pitch->rate);
|
||||||
|
GST_OBJECT_UNLOCK (pitch);
|
||||||
|
gst_pitch_update_duration (pitch);
|
||||||
break;
|
break;
|
||||||
case ARG_PITCH:
|
case ARG_PITCH:
|
||||||
pitch->pitch = g_value_get_float (value);
|
pitch->pitch = g_value_get_float (value);
|
||||||
pitch->priv->st->setPitch (pitch->pitch);
|
pitch->priv->st->setPitch (pitch->pitch);
|
||||||
|
GST_OBJECT_UNLOCK (pitch);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
GST_OBJECT_UNLOCK (pitch);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
GST_OBJECT_UNLOCK (pitch);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -324,8 +331,6 @@ gst_pitch_forward_buffer (GstPitch * pitch, GstBuffer * buffer)
|
|||||||
pitch->next_buffer_offset += samples;
|
pitch->next_buffer_offset += samples;
|
||||||
GST_BUFFER_OFFSET_END (buffer) = pitch->next_buffer_offset;
|
GST_BUFFER_OFFSET_END (buffer) = pitch->next_buffer_offset;
|
||||||
|
|
||||||
gst_buffer_set_caps (buffer, GST_PAD_CAPS (pitch->srcpad));
|
|
||||||
|
|
||||||
GST_LOG ("pushing buffer [%" GST_TIME_FORMAT "]-[%" GST_TIME_FORMAT
|
GST_LOG ("pushing buffer [%" GST_TIME_FORMAT "]-[%" GST_TIME_FORMAT
|
||||||
"] (%d samples)", GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)),
|
"] (%d samples)", GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)),
|
||||||
GST_TIME_ARGS (pitch->next_buffer_time), samples);
|
GST_TIME_ARGS (pitch->next_buffer_time), samples);
|
||||||
@ -347,14 +352,22 @@ gst_pitch_prepare_buffer (GstPitch * pitch)
|
|||||||
|
|
||||||
samples = pitch->priv->st->numSamples ();
|
samples = pitch->priv->st->numSamples ();
|
||||||
if (samples == 0)
|
if (samples == 0)
|
||||||
return NULL;;
|
return NULL;
|
||||||
|
|
||||||
|
if (gst_pad_alloc_buffer_and_set_caps (pitch->srcpad, GST_BUFFER_OFFSET_NONE,
|
||||||
|
samples * pitch->sample_size, GST_PAD_CAPS (pitch->srcpad), &buffer)
|
||||||
|
!= GST_FLOW_OK) {
|
||||||
|
buffer = gst_buffer_new_and_alloc (samples * pitch->sample_size);
|
||||||
|
gst_buffer_set_caps (buffer, GST_PAD_CAPS (pitch->srcpad));
|
||||||
|
}
|
||||||
|
|
||||||
buffer = gst_buffer_new_and_alloc (samples * pitch->sample_size);
|
|
||||||
samples =
|
samples =
|
||||||
priv->st->receiveSamples ((gfloat *) GST_BUFFER_DATA (buffer), samples);
|
priv->st->receiveSamples ((gfloat *) GST_BUFFER_DATA (buffer), samples);
|
||||||
|
|
||||||
if (samples <= 0)
|
if (samples <= 0) {
|
||||||
|
gst_buffer_unref (buffer);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
GST_BUFFER_DURATION (buffer) = samples * pitch->sample_duration;
|
GST_BUFFER_DURATION (buffer) = samples * pitch->sample_duration;
|
||||||
/* temporary store samples here, to avoid having to recalculate this */
|
/* temporary store samples here, to avoid having to recalculate this */
|
||||||
@ -415,15 +428,22 @@ gst_pitch_src_event (GstPad * pad, GstEvent * event)
|
|||||||
gst_event_parse_seek (event, &rate, &format, &flags,
|
gst_event_parse_seek (event, &rate, &format, &flags,
|
||||||
&cur_type, &cur, &stop_type, &stop);
|
&cur_type, &cur, &stop_type, &stop);
|
||||||
|
|
||||||
cur = (gint64) (cur * stream_time_ratio);
|
|
||||||
stop = (gint64) (stop * stream_time_ratio);
|
|
||||||
|
|
||||||
gst_event_unref (event);
|
gst_event_unref (event);
|
||||||
|
|
||||||
event = gst_event_new_seek (rate, format, flags,
|
if (format == GST_FORMAT_TIME || format == GST_FORMAT_DEFAULT) {
|
||||||
cur_type, cur, stop_type, stop);
|
cur = (gint64) (cur * stream_time_ratio);
|
||||||
|
if (stop != -1)
|
||||||
|
stop = (gint64) (stop * stream_time_ratio);
|
||||||
|
|
||||||
|
event = gst_event_new_seek (rate, format, flags,
|
||||||
|
cur_type, cur, stop_type, stop);
|
||||||
|
res = gst_pad_event_default (pad, event);
|
||||||
|
} else {
|
||||||
|
GST_WARNING_OBJECT (pitch,
|
||||||
|
"Seeking only supported in TIME or DEFAULT format");
|
||||||
|
res = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
res = gst_pad_event_default (pad, event);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -459,7 +479,7 @@ gst_pitch_convert (GstPitch * pitch,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (src_format == *dst_format) {
|
if (src_format == *dst_format || src_value == -1) {
|
||||||
*dst_value = src_value;
|
*dst_value = src_value;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -534,11 +554,13 @@ gst_pitch_src_query (GstPad * pad, GstQuery * query)
|
|||||||
gboolean res = FALSE;
|
gboolean res = FALSE;
|
||||||
gfloat stream_time_ratio;
|
gfloat stream_time_ratio;
|
||||||
gint64 next_buffer_offset;
|
gint64 next_buffer_offset;
|
||||||
|
GstClockTime next_buffer_time;
|
||||||
|
|
||||||
pitch = GST_PITCH (gst_pad_get_parent (pad));
|
pitch = GST_PITCH (gst_pad_get_parent (pad));
|
||||||
GST_LOG ("%s query", GST_QUERY_TYPE_NAME (query));
|
GST_LOG ("%s query", GST_QUERY_TYPE_NAME (query));
|
||||||
GST_OBJECT_LOCK (pitch);
|
GST_OBJECT_LOCK (pitch);
|
||||||
stream_time_ratio = pitch->priv->stream_time_ratio;
|
stream_time_ratio = pitch->priv->stream_time_ratio;
|
||||||
|
next_buffer_time = pitch->next_buffer_time;
|
||||||
next_buffer_offset = pitch->next_buffer_offset;
|
next_buffer_offset = pitch->next_buffer_offset;
|
||||||
GST_OBJECT_UNLOCK (pitch);
|
GST_OBJECT_UNLOCK (pitch);
|
||||||
|
|
||||||
@ -576,9 +598,9 @@ gst_pitch_src_query (GstPad * pad, GstQuery * query)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dst_format != GST_FORMAT_DEFAULT) {
|
if (dst_format == GST_FORMAT_TIME) {
|
||||||
res = gst_pitch_convert (pitch, GST_FORMAT_DEFAULT,
|
dst_value = next_buffer_time;
|
||||||
next_buffer_offset, &dst_format, &dst_value);
|
res = TRUE;
|
||||||
} else {
|
} else {
|
||||||
dst_value = next_buffer_offset;
|
dst_value = next_buffer_offset;
|
||||||
res = TRUE;
|
res = TRUE;
|
||||||
@ -640,6 +662,18 @@ gst_pitch_process_segment (GstPitch * pitch, GstEvent ** event)
|
|||||||
gst_event_parse_new_segment (*event, &update, &rate, &format, &start_value,
|
gst_event_parse_new_segment (*event, &update, &rate, &format, &start_value,
|
||||||
&stop_value, &base);
|
&stop_value, &base);
|
||||||
|
|
||||||
|
if (format != GST_FORMAT_TIME && format != GST_FORMAT_DEFAULT) {
|
||||||
|
GST_WARNING_OBJECT (pitch,
|
||||||
|
"Only NEWSEGMENT in TIME or DEFAULT format supported, sending"
|
||||||
|
"open ended NEWSEGMENT in TIME format.");
|
||||||
|
gst_event_unref (*event);
|
||||||
|
*event =
|
||||||
|
gst_event_new_new_segment (update, rate, GST_FORMAT_TIME, 0, -1, 0);
|
||||||
|
start_value = 0;
|
||||||
|
stop_value = -1;
|
||||||
|
base = 0;
|
||||||
|
}
|
||||||
|
|
||||||
GST_LOG_OBJECT (pitch->sinkpad, "segment %lld - %lld (%d)", start_value,
|
GST_LOG_OBJECT (pitch->sinkpad, "segment %lld - %lld (%d)", start_value,
|
||||||
stop_value, format);
|
stop_value, format);
|
||||||
|
|
||||||
@ -649,7 +683,8 @@ gst_pitch_process_segment (GstPitch * pitch, GstEvent ** event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
start_value = (gint64) (start_value / stream_time_ratio);
|
start_value = (gint64) (start_value / stream_time_ratio);
|
||||||
stop_value = (gint64) (stop_value / stream_time_ratio);
|
if (stop_value != -1)
|
||||||
|
stop_value = (gint64) (stop_value / stream_time_ratio);
|
||||||
base = (gint64) (base / stream_time_ratio);
|
base = (gint64) (base / stream_time_ratio);
|
||||||
|
|
||||||
conv_format = GST_FORMAT_TIME;
|
conv_format = GST_FORMAT_TIME;
|
||||||
@ -758,7 +793,8 @@ gst_pitch_chain (GstPad * pad, GstBuffer * buffer)
|
|||||||
GstBuffer *out_buffer;
|
GstBuffer *out_buffer;
|
||||||
|
|
||||||
out_buffer = gst_pitch_prepare_buffer (pitch);
|
out_buffer = gst_pitch_prepare_buffer (pitch);
|
||||||
return gst_pitch_forward_buffer (pitch, out_buffer);
|
if (out_buffer)
|
||||||
|
return gst_pitch_forward_buffer (pitch, out_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
return GST_FLOW_OK;
|
return GST_FLOW_OK;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user