mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-09-08 21:28:45 +00:00
Original commit message from CVS: 2004-02-27 Benjamin Otte <otte@gnome.org> * gst-libs/gst/audio/audio.h: add macro to make sure header isn't included twice * gst/asfdemux/gstasfdemux.c: (gst_asf_demux_process_chunk): don't use gst_buffer_free * gst/playondemand/filter.func: don't usae gst_data_free. Free data only once.
113 lines
3 KiB
C
113 lines
3 KiB
C
/* -*- C -*- */
|
|
|
|
_TYPE_ *data_in, *data_out, *filter_data;
|
|
|
|
filter_data = (_TYPE_ *) filter->buffer;
|
|
num_filter = filter->buffer_bytes / sizeof(_TYPE_);
|
|
|
|
do {
|
|
/* see if we've got any events coming through ... */
|
|
|
|
while (! filter->eos && in != NULL && GST_IS_EVENT (in)) {
|
|
GstEvent *event = GST_EVENT (in);
|
|
if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
|
|
gst_data_unref (in);
|
|
in = NULL;
|
|
filter->eos = TRUE;
|
|
} else if ((GST_EVENT_TYPE (event) == GST_EVENT_DISCONTINUOUS) ||
|
|
(GST_EVENT_TYPE (event) == GST_EVENT_FLUSH)) {
|
|
gst_data_unref (in);
|
|
in = NULL;
|
|
filter->eos = FALSE;
|
|
filter->write = 0;
|
|
} else {
|
|
gst_pad_push(filter->srcpad, in);
|
|
}
|
|
|
|
in = (in == NULL && ! filter->eos) ? gst_pad_pull(filter->sinkpad) : NULL;
|
|
}
|
|
|
|
/* handle data from the input buffer. */
|
|
|
|
if (! filter->eos) {
|
|
register guint j, w = filter->write;
|
|
|
|
data_in = (_TYPE_ *) GST_BUFFER_DATA (GST_BUFFER (in));
|
|
num_in = GST_BUFFER_SIZE (in) / sizeof(_TYPE_);
|
|
|
|
for (j = 0; (j < num_in) && (w+j < num_filter); j++)
|
|
filter_data[w+j] = data_in[j];
|
|
|
|
filter->write += j;
|
|
|
|
if (filter->write >= num_filter) filter->eos = TRUE;
|
|
|
|
out = GST_BUFFER (in);
|
|
} else {
|
|
out = gst_buffer_new_and_alloc (GST_POD_BUFPOOL_SIZE);
|
|
}
|
|
|
|
in = NULL;
|
|
|
|
/* check to see if we have to add new play pointers. */
|
|
|
|
if (filter->clock) {
|
|
register gint t, tick_offset;
|
|
|
|
guint total_ticks = filter->total_ticks;
|
|
guint current_tick = \
|
|
((guint) (gst_clock_get_time(filter->clock) * \
|
|
filter->tick_rate / GST_SECOND)) % total_ticks;
|
|
|
|
tick_offset = current_tick - last_tick;
|
|
if (tick_offset < 0) tick_offset += total_ticks;
|
|
|
|
for (tick_offset -= 1, t = current_tick - tick_offset;
|
|
tick_offset >= 0;
|
|
tick_offset--, t--) {
|
|
|
|
if (t < 0) t += total_ticks;
|
|
|
|
if (filter->ticks[t / 32] & (1 << t % 32))
|
|
play_on_demand_add_play_pointer(
|
|
filter, filter->rate * tick_offset / filter->tick_rate);
|
|
}
|
|
|
|
last_tick = current_tick;
|
|
}
|
|
|
|
/* handle output data. */
|
|
|
|
{
|
|
register guint k, p;
|
|
|
|
data_out = (_TYPE_ *) GST_BUFFER_DATA (out);
|
|
num_out = GST_BUFFER_SIZE (out) / sizeof(_TYPE_);
|
|
|
|
for (k = 0; k < num_out; k++) data_out[k] = zero;
|
|
|
|
for (p = 0; p < filter->max_plays; p++) {
|
|
guint offset = filter->plays[p];
|
|
|
|
if (offset != G_MAXUINT) {
|
|
|
|
/* only copy audio data if the element's not muted. */
|
|
if (! filter->mute)
|
|
for (k = 0; (k < num_out) && (offset+k < num_filter); k++)
|
|
data_out[k] = CLAMP(data_out[k] + filter_data[offset+k], min, max);
|
|
|
|
/* update the play pointer. k > 0 even if the filter is muted. */
|
|
filter->plays[p] = (offset+k >= num_filter) ? G_MAXUINT : offset + k;
|
|
}
|
|
}
|
|
}
|
|
|
|
/* push out the buffer and get a new buffer if we're allowed to loop. */
|
|
|
|
gst_pad_push(filter->srcpad, GST_DATA (out));
|
|
|
|
if (gst_element_interrupt (GST_ELEMENT (filter))) break;
|
|
|
|
in = (in == NULL && ! filter->eos) ? gst_pad_pull(filter->sinkpad) : NULL;
|
|
|
|
} while (TRUE);
|