Commit dae84881 authored by Wim Taymans's avatar Wim Taymans

audio: rework audio caps.

Rework the audio caps similar to the video caps. Remove
width/depth/endianness/signed fields and replace with a simple string
format and media type audio/x-raw.
Create a GstAudioInfo and some helper methods to parse caps.
Remove duplicate code from the ringbuffer and replace with audio info.
Use AudioInfo in the base audio filter class.
Port elements to new API.
parent d1a83d7a
......@@ -95,46 +95,13 @@ static gint output_ref; /* 0 */
static snd_output_t *output; /* NULL */
static GStaticMutex output_mutex = G_STATIC_MUTEX_INIT;
#if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
# define ALSA_SINK_FACTORY_ENDIANNESS "LITTLE_ENDIAN, BIG_ENDIAN"
#else
# define ALSA_SINK_FACTORY_ENDIANNESS "BIG_ENDIAN, LITTLE_ENDIAN"
#endif
static GstStaticPadTemplate alsasink_sink_factory =
GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("audio/x-raw-int, "
"endianness = (int) { " ALSA_SINK_FACTORY_ENDIANNESS " }, "
"signed = (boolean) { TRUE, FALSE }, "
"width = (int) 32, "
"depth = (int) 32, "
"rate = (int) [ 1, MAX ], " "channels = (int) [ 1, MAX ]; "
"audio/x-raw-int, "
"endianness = (int) { " ALSA_SINK_FACTORY_ENDIANNESS " }, "
"signed = (boolean) { TRUE, FALSE }, "
"width = (int) 24, "
"depth = (int) 24, "
GST_STATIC_CAPS ("audio/x-raw, "
"formats = (string) " GST_AUDIO_FORMATS_ALL ", "
"rate = (int) [ 1, MAX ], " "channels = (int) [ 1, MAX ]; "
"audio/x-raw-int, "
"endianness = (int) { " ALSA_SINK_FACTORY_ENDIANNESS " }, "
"signed = (boolean) { TRUE, FALSE }, "
"width = (int) 32, "
"depth = (int) 24, "
"rate = (int) [ 1, MAX ], " "channels = (int) [ 1, MAX ]; "
"audio/x-raw-int, "
"endianness = (int) { " ALSA_SINK_FACTORY_ENDIANNESS " }, "
"signed = (boolean) { TRUE, FALSE }, "
"width = (int) 16, "
"depth = (int) 16, "
"rate = (int) [ 1, MAX ], " "channels = (int) [ 1, MAX ]; "
"audio/x-raw-int, "
"signed = (boolean) { TRUE, FALSE }, "
"width = (int) 8, "
"depth = (int) 8, "
"rate = (int) [ 1, MAX ], " "channels = (int) [ 1, MAX ];"
"audio/x-iec958")
);
......@@ -627,26 +594,96 @@ alsasink_parse_spec (GstAlsaSink * alsa, GstRingBufferSpec * spec)
alsa->iec958 = FALSE;
switch (spec->type) {
case GST_BUFTYPE_LINEAR:
GST_DEBUG_OBJECT (alsa,
"Linear format : depth=%d, width=%d, sign=%d, bigend=%d", spec->depth,
spec->width, spec->sign, spec->bigend);
alsa->format = snd_pcm_build_linear_format (spec->depth, spec->width,
spec->sign ? 0 : 1, spec->bigend ? 1 : 0);
break;
case GST_BUFTYPE_FLOAT:
switch (spec->format) {
case GST_FLOAT32_LE:
case GST_BUFTYPE_RAW:
switch (GST_AUDIO_INFO_FORMAT (&spec->info)) {
case GST_AUDIO_FORMAT_U8:
alsa->format = SND_PCM_FORMAT_U8;
break;
case GST_AUDIO_FORMAT_S8:
alsa->format = SND_PCM_FORMAT_S8;
break;
case GST_AUDIO_FORMAT_S16_LE:
alsa->format = SND_PCM_FORMAT_S16_LE;
break;
case GST_AUDIO_FORMAT_S16_BE:
alsa->format = SND_PCM_FORMAT_S16_BE;
break;
case GST_AUDIO_FORMAT_U16_LE:
alsa->format = SND_PCM_FORMAT_U16_LE;
break;
case GST_AUDIO_FORMAT_U16_BE:
alsa->format = SND_PCM_FORMAT_U16_BE;
break;
case GST_AUDIO_FORMAT_S24_LE:
alsa->format = SND_PCM_FORMAT_S24_LE;
break;
case GST_AUDIO_FORMAT_S24_BE:
alsa->format = SND_PCM_FORMAT_S24_BE;
break;
case GST_AUDIO_FORMAT_U24_LE:
alsa->format = SND_PCM_FORMAT_U24_LE;
break;
case GST_AUDIO_FORMAT_U24_BE:
alsa->format = SND_PCM_FORMAT_U24_BE;
break;
case GST_AUDIO_FORMAT_S32_LE:
alsa->format = SND_PCM_FORMAT_S32_LE;
break;
case GST_AUDIO_FORMAT_S32_BE:
alsa->format = SND_PCM_FORMAT_S32_BE;
break;
case GST_AUDIO_FORMAT_U32_LE:
alsa->format = SND_PCM_FORMAT_U32_LE;
break;
case GST_AUDIO_FORMAT_U32_BE:
alsa->format = SND_PCM_FORMAT_U32_BE;
break;
case GST_AUDIO_FORMAT_S24_3LE:
alsa->format = SND_PCM_FORMAT_S24_3LE;
break;
case GST_AUDIO_FORMAT_S24_3BE:
alsa->format = SND_PCM_FORMAT_S24_3BE;
break;
case GST_AUDIO_FORMAT_U24_3LE:
alsa->format = SND_PCM_FORMAT_U24_3LE;
break;
case GST_AUDIO_FORMAT_U24_3BE:
alsa->format = SND_PCM_FORMAT_U24_3BE;
break;
case GST_AUDIO_FORMAT_S20_3LE:
alsa->format = SND_PCM_FORMAT_S20_3LE;
break;
case GST_AUDIO_FORMAT_S20_3BE:
alsa->format = SND_PCM_FORMAT_S20_3BE;
break;
case GST_AUDIO_FORMAT_U20_3LE:
alsa->format = SND_PCM_FORMAT_U20_3LE;
break;
case GST_AUDIO_FORMAT_U20_3BE:
alsa->format = SND_PCM_FORMAT_U20_3BE;
break;
case GST_AUDIO_FORMAT_S18_3LE:
alsa->format = SND_PCM_FORMAT_S18_3LE;
break;
case GST_AUDIO_FORMAT_S18_3BE:
alsa->format = SND_PCM_FORMAT_S18_3BE;
break;
case GST_AUDIO_FORMAT_U18_3LE:
alsa->format = SND_PCM_FORMAT_U18_3LE;
break;
case GST_AUDIO_FORMAT_U18_3BE:
alsa->format = SND_PCM_FORMAT_U18_3BE;
break;
case GST_AUDIO_FORMAT_F32_LE:
alsa->format = SND_PCM_FORMAT_FLOAT_LE;
break;
case GST_FLOAT32_BE:
case GST_AUDIO_FORMAT_F32_BE:
alsa->format = SND_PCM_FORMAT_FLOAT_BE;
break;
case GST_FLOAT64_LE:
case GST_AUDIO_FORMAT_F64_LE:
alsa->format = SND_PCM_FORMAT_FLOAT64_LE;
break;
case GST_FLOAT64_BE:
case GST_AUDIO_FORMAT_F64_BE:
alsa->format = SND_PCM_FORMAT_FLOAT64_BE;
break;
default:
......@@ -667,8 +704,8 @@ alsasink_parse_spec (GstAlsaSink * alsa, GstRingBufferSpec * spec)
goto error;
}
alsa->rate = spec->rate;
alsa->channels = spec->channels;
alsa->rate = GST_AUDIO_INFO_RATE (&spec->info);
alsa->channels = GST_AUDIO_INFO_CHANNELS (&spec->info);
alsa->buffer_time = spec->buffer_time;
alsa->period_time = spec->latency_time;
alsa->access = SND_PCM_ACCESS_RW_INTERLEAVED;
......@@ -724,7 +761,7 @@ gst_alsasink_prepare (GstAudioSink * asink, GstRingBufferSpec * spec)
alsa = GST_ALSA_SINK (asink);
if (spec->format == GST_IEC958) {
if (spec->type == GST_BUFTYPE_IEC958) {
snd_pcm_close (alsa->handle);
alsa->handle = gst_alsa_open_iec958_pcm (GST_OBJECT (alsa));
if (G_UNLIKELY (!alsa->handle)) {
......@@ -738,8 +775,8 @@ gst_alsasink_prepare (GstAudioSink * asink, GstRingBufferSpec * spec)
CHECK (set_hwparams (alsa), hw_params_failed);
CHECK (set_swparams (alsa), sw_params_failed);
alsa->bytes_per_sample = spec->bytes_per_sample;
spec->segsize = alsa->period_size * spec->bytes_per_sample;
alsa->bpf = GST_AUDIO_INFO_BPF (&spec->info);
spec->segsize = alsa->period_size * alsa->bpf;
spec->segtotal = alsa->buffer_size / alsa->period_size;
{
......@@ -867,7 +904,7 @@ gst_alsasink_write (GstAudioSink * asink, gpointer data, guint length)
GST_LOG_OBJECT (asink, "received audio samples buffer of %u bytes", length);
cptr = length / alsa->bytes_per_sample;
cptr = length / alsa->bpf;
GST_ALSA_SINK_LOCK (asink);
while (cptr > 0) {
......@@ -896,7 +933,7 @@ gst_alsasink_write (GstAudioSink * asink, gpointer data, guint length)
}
GST_ALSA_SINK_UNLOCK (asink);
return length - (cptr * alsa->bytes_per_sample);
return length - (cptr * alsa->bpf);
write_error:
{
......
......@@ -61,7 +61,7 @@ struct _GstAlsaSink {
snd_pcm_format_t format;
guint rate;
guint channels;
gint bytes_per_sample;
gint bpf;
gboolean iec958;
gboolean need_swap;
......
......@@ -107,37 +107,11 @@ enum
#endif
static GstStaticPadTemplate alsasrc_src_factory =
GST_STATIC_PAD_TEMPLATE ("src",
GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("audio/x-raw-int, "
"endianness = (int) { " ALSA_SRC_FACTORY_ENDIANNESS " }, "
"signed = (boolean) { TRUE, FALSE }, "
"width = (int) 32, "
"depth = (int) 32, "
"rate = (int) [ 1, MAX ], " "channels = (int) [ 1, MAX ]; "
"audio/x-raw-int, "
"endianness = (int) { " ALSA_SRC_FACTORY_ENDIANNESS " }, "
"signed = (boolean) { TRUE, FALSE }, "
"width = (int) 32, "
"depth = (int) 24, "
"rate = (int) [ 1, MAX ], " "channels = (int) [ 1, MAX ]; "
"audio/x-raw-int, "
"endianness = (int) { " ALSA_SRC_FACTORY_ENDIANNESS " }, "
"signed = (boolean) { TRUE, FALSE }, "
"width = (int) 24, "
"depth = (int) 24, "
"rate = (int) [ 1, MAX ], " "channels = (int) [ 1, MAX ]; "
"audio/x-raw-int, "
"endianness = (int) { " ALSA_SRC_FACTORY_ENDIANNESS " }, "
"signed = (boolean) { TRUE, FALSE }, "
"width = (int) 16, "
"depth = (int) 16, "
"rate = (int) [ 1, MAX ], " "channels = (int) [ 1, MAX ]; "
"audio/x-raw-int, "
"signed = (boolean) { TRUE, FALSE }, "
"width = (int) 8, "
"depth = (int) 8, "
GST_STATIC_CAPS ("audio/x-raw, "
"format = (string) " GST_AUDIO_FORMATS_ALL ", "
"rate = (int) [ 1, MAX ], " "channels = (int) [ 1, MAX ]")
);
......@@ -655,22 +629,96 @@ static gboolean
alsasrc_parse_spec (GstAlsaSrc * alsa, GstRingBufferSpec * spec)
{
switch (spec->type) {
case GST_BUFTYPE_LINEAR:
alsa->format = snd_pcm_build_linear_format (spec->depth, spec->width,
spec->sign ? 0 : 1, spec->bigend ? 1 : 0);
break;
case GST_BUFTYPE_FLOAT:
switch (spec->format) {
case GST_FLOAT32_LE:
case GST_BUFTYPE_RAW:
switch (GST_AUDIO_INFO_FORMAT (&spec->info)) {
case GST_AUDIO_FORMAT_U8:
alsa->format = SND_PCM_FORMAT_U8;
break;
case GST_AUDIO_FORMAT_S8:
alsa->format = SND_PCM_FORMAT_S8;
break;
case GST_AUDIO_FORMAT_S16_LE:
alsa->format = SND_PCM_FORMAT_S16_LE;
break;
case GST_AUDIO_FORMAT_S16_BE:
alsa->format = SND_PCM_FORMAT_S16_BE;
break;
case GST_AUDIO_FORMAT_U16_LE:
alsa->format = SND_PCM_FORMAT_U16_LE;
break;
case GST_AUDIO_FORMAT_U16_BE:
alsa->format = SND_PCM_FORMAT_U16_BE;
break;
case GST_AUDIO_FORMAT_S24_LE:
alsa->format = SND_PCM_FORMAT_S24_LE;
break;
case GST_AUDIO_FORMAT_S24_BE:
alsa->format = SND_PCM_FORMAT_S24_BE;
break;
case GST_AUDIO_FORMAT_U24_LE:
alsa->format = SND_PCM_FORMAT_U24_LE;
break;
case GST_AUDIO_FORMAT_U24_BE:
alsa->format = SND_PCM_FORMAT_U24_BE;
break;
case GST_AUDIO_FORMAT_S32_LE:
alsa->format = SND_PCM_FORMAT_S32_LE;
break;
case GST_AUDIO_FORMAT_S32_BE:
alsa->format = SND_PCM_FORMAT_S32_BE;
break;
case GST_AUDIO_FORMAT_U32_LE:
alsa->format = SND_PCM_FORMAT_U32_LE;
break;
case GST_AUDIO_FORMAT_U32_BE:
alsa->format = SND_PCM_FORMAT_U32_BE;
break;
case GST_AUDIO_FORMAT_S24_3LE:
alsa->format = SND_PCM_FORMAT_S24_3LE;
break;
case GST_AUDIO_FORMAT_S24_3BE:
alsa->format = SND_PCM_FORMAT_S24_3BE;
break;
case GST_AUDIO_FORMAT_U24_3LE:
alsa->format = SND_PCM_FORMAT_U24_3LE;
break;
case GST_AUDIO_FORMAT_U24_3BE:
alsa->format = SND_PCM_FORMAT_U24_3BE;
break;
case GST_AUDIO_FORMAT_S20_3LE:
alsa->format = SND_PCM_FORMAT_S20_3LE;
break;
case GST_AUDIO_FORMAT_S20_3BE:
alsa->format = SND_PCM_FORMAT_S20_3BE;
break;
case GST_AUDIO_FORMAT_U20_3LE:
alsa->format = SND_PCM_FORMAT_U20_3LE;
break;
case GST_AUDIO_FORMAT_U20_3BE:
alsa->format = SND_PCM_FORMAT_U20_3BE;
break;
case GST_AUDIO_FORMAT_S18_3LE:
alsa->format = SND_PCM_FORMAT_S18_3LE;
break;
case GST_AUDIO_FORMAT_S18_3BE:
alsa->format = SND_PCM_FORMAT_S18_3BE;
break;
case GST_AUDIO_FORMAT_U18_3LE:
alsa->format = SND_PCM_FORMAT_U18_3LE;
break;
case GST_AUDIO_FORMAT_U18_3BE:
alsa->format = SND_PCM_FORMAT_U18_3BE;
break;
case GST_AUDIO_FORMAT_F32_LE:
alsa->format = SND_PCM_FORMAT_FLOAT_LE;
break;
case GST_FLOAT32_BE:
case GST_AUDIO_FORMAT_F32_BE:
alsa->format = SND_PCM_FORMAT_FLOAT_BE;
break;
case GST_FLOAT64_LE:
case GST_AUDIO_FORMAT_F64_LE:
alsa->format = SND_PCM_FORMAT_FLOAT64_LE;
break;
case GST_FLOAT64_BE:
case GST_AUDIO_FORMAT_F64_BE:
alsa->format = SND_PCM_FORMAT_FLOAT64_BE;
break;
default:
......@@ -687,8 +735,8 @@ alsasrc_parse_spec (GstAlsaSrc * alsa, GstRingBufferSpec * spec)
goto error;
}
alsa->rate = spec->rate;
alsa->channels = spec->channels;
alsa->rate = GST_AUDIO_INFO_RATE (&spec->info);
alsa->channels = GST_AUDIO_INFO_CHANNELS (&spec->info);
alsa->buffer_time = spec->buffer_time;
alsa->period_time = spec->latency_time;
alsa->access = SND_PCM_ACCESS_RW_INTERLEAVED;
......@@ -753,13 +801,9 @@ gst_alsasrc_prepare (GstAudioSrc * asrc, GstRingBufferSpec * spec)
CHECK (set_swparams (alsa), sw_params_failed);
CHECK (snd_pcm_prepare (alsa->handle), prepare_failed);
alsa->bytes_per_sample = spec->bytes_per_sample;
spec->segsize = alsa->period_size * spec->bytes_per_sample;
alsa->bpf = GST_AUDIO_INFO_BPF (&spec->info);
spec->segsize = alsa->period_size * alsa->bpf;
spec->segtotal = alsa->buffer_size / alsa->period_size;
spec->silence_sample[0] = 0;
spec->silence_sample[1] = 0;
spec->silence_sample[2] = 0;
spec->silence_sample[3] = 0;
return TRUE;
......@@ -869,7 +913,7 @@ gst_alsasrc_read (GstAudioSrc * asrc, gpointer data, guint length)
alsa = GST_ALSA_SRC (asrc);
cptr = length / alsa->bytes_per_sample;
cptr = length / alsa->bpf;
ptr = data;
GST_ALSA_SRC_LOCK (asrc);
......@@ -889,7 +933,7 @@ gst_alsasrc_read (GstAudioSrc * asrc, gpointer data, guint length)
}
GST_ALSA_SRC_UNLOCK (asrc);
return length - (cptr * alsa->bytes_per_sample);
return length - (cptr * alsa->bpf);
read_error:
{
......
......@@ -63,7 +63,7 @@ struct _GstAlsaSrc {
snd_pcm_format_t format;
guint rate;
guint channels;
gint bytes_per_sample;
gint bpf;
gboolean driver_timestamps;
guint buffer_time;
......
......@@ -224,7 +224,7 @@ vorbis_dec_convert (GstPad * pad,
case GST_FORMAT_TIME:
switch (*dest_format) {
case GST_FORMAT_BYTES:
scale = dec->width * dec->vi.channels;
scale = dec->info.bpf;
case GST_FORMAT_DEFAULT:
*dest_value =
scale * gst_util_uint64_scale_int (src_value, dec->vi.rate,
......@@ -237,7 +237,7 @@ vorbis_dec_convert (GstPad * pad,
case GST_FORMAT_DEFAULT:
switch (*dest_format) {
case GST_FORMAT_BYTES:
*dest_value = src_value * dec->width * dec->vi.channels;
*dest_value = src_value * dec->info.bpf;
break;
case GST_FORMAT_TIME:
*dest_value =
......@@ -250,11 +250,11 @@ vorbis_dec_convert (GstPad * pad,
case GST_FORMAT_BYTES:
switch (*dest_format) {
case GST_FORMAT_DEFAULT:
*dest_value = src_value / (dec->width * dec->vi.channels);
*dest_value = src_value / dec->info.bpf;
break;
case GST_FORMAT_TIME:
*dest_value = gst_util_uint64_scale_int (src_value, GST_SECOND,
dec->vi.rate * dec->width * dec->vi.channels);
dec->vi.rate * dec->info.bpf);
break;
default:
res = FALSE;
......@@ -545,10 +545,13 @@ static GstFlowReturn
vorbis_handle_identification_packet (GstVorbisDec * vd)
{
GstCaps *caps;
GstAudioInfo info;
const GstAudioChannelPosition *pos = NULL;
gint width = GST_VORBIS_DEC_DEFAULT_SAMPLE_WIDTH;
switch (vd->vi.channels) {
gst_audio_info_set_format (&info, GST_VORBIS_AUDIO_FORMAT, vd->vi.rate,
vd->vi.channels);
switch (info.channels) {
case 1:
case 2:
/* nothing */
......@@ -559,59 +562,27 @@ vorbis_handle_identification_packet (GstVorbisDec * vd)
case 6:
case 7:
case 8:
pos = gst_vorbis_channel_positions[vd->vi.channels - 1];
pos = gst_vorbis_channel_positions[info.channels - 1];
break;
default:{
gint i;
GstAudioChannelPosition *posn =
g_new (GstAudioChannelPosition, vd->vi.channels);
default:
{
gint i, max_pos = MAX (info.channels, 64);
GST_ELEMENT_WARNING (GST_ELEMENT (vd), STREAM, DECODE,
GST_ELEMENT_WARNING (vd, STREAM, DECODE,
(NULL), ("Using NONE channel layout for more than 8 channels"));
for (i = 0; i < vd->vi.channels; i++)
posn[i] = GST_AUDIO_CHANNEL_POSITION_NONE;
pos = posn;
for (i = 0; i < max_pos; i++)
info.position[i] = GST_AUDIO_CHANNEL_POSITION_NONE;
}
}
/* negotiate width with downstream */
caps = gst_pad_get_allowed_caps (vd->srcpad);
if (caps) {
if (!gst_caps_is_empty (caps)) {
GstStructure *s;
s = gst_caps_get_structure (caps, 0);
/* template ensures 16 or 32 */
gst_structure_get_int (s, "width", &width);
GST_INFO_OBJECT (vd, "using %s with %d channels and %d bit audio depth",
gst_structure_get_name (s), vd->vi.channels, width);
}
gst_caps_unref (caps);
}
vd->width = width >> 3;
caps = gst_audio_info_to_caps (&info);
gst_pad_set_caps (vd->srcpad, caps);
gst_caps_unref (caps);
vd->info = info;
/* select a copy_samples function, this way we can have specialized versions
* for mono/stereo and avoid the depth switch in tremor case */
vd->copy_samples = get_copy_sample_func (vd->vi.channels, vd->width);
caps = gst_caps_make_writable (gst_pad_get_pad_template_caps (vd->srcpad));
gst_caps_set_simple (caps, "rate", G_TYPE_INT, vd->vi.rate,
"channels", G_TYPE_INT, vd->vi.channels,
"width", G_TYPE_INT, width, NULL);
if (pos) {
gst_audio_set_channel_positions (gst_caps_get_structure (caps, 0), pos);
}
if (vd->vi.channels > 8) {
g_free ((GstAudioChannelPosition *) pos);
}
gst_pad_set_caps (vd->srcpad, caps);
gst_caps_unref (caps);
vd->copy_samples = get_copy_sample_func (info.channels);
return GST_FLOW_OK;
}
......@@ -792,7 +763,7 @@ vorbis_dec_push_forward (GstVorbisDec * dec, GstBuffer * buf)
/* clip */
if (!(buf = gst_audio_buffer_clip (buf, &dec->segment, dec->vi.rate,
dec->vi.channels * dec->width))) {
dec->info.bpf))) {
GST_LOG_OBJECT (dec, "clipped buffer");
return GST_FLOW_OK;
}
......@@ -856,9 +827,7 @@ static GstFlowReturn
vorbis_handle_data_packet (GstVorbisDec * vd, ogg_packet * packet,
GstClockTime timestamp, GstClockTime duration)
{
#ifdef USE_TREMOLO
vorbis_sample_t *pcm;
#else
#ifndef USE_TREMOLO
vorbis_sample_t **pcm;
#endif
guint sample_count;
......@@ -899,17 +868,17 @@ vorbis_handle_data_packet (GstVorbisDec * vd, ogg_packet * packet,
#endif
goto done;
size = sample_count * vd->vi.channels * vd->width;
size = sample_count * vd->info.bpf;
GST_LOG_OBJECT (vd, "%d samples ready for reading, size %" G_GSIZE_FORMAT,
sample_count, size);
/* alloc buffer for it */
out = gst_buffer_new_and_alloc (size);
data = gst_buffer_map (out, NULL, NULL, GST_MAP_WRITE);
/* get samples ready for reading now, should be sample_count */
#ifdef USE_TREMOLO
pcm = GST_BUFFER_DATA (out);
if (G_UNLIKELY ((vorbis_dsp_pcmout (&vd->vd, pcm,
if (G_UNLIKELY ((vorbis_dsp_pcmout (&vd->vd, data,
sample_count)) != sample_count))
#else
if (G_UNLIKELY ((vorbis_synthesis_pcmout (&vd->vd, &pcm)) != sample_count))
......@@ -918,9 +887,8 @@ vorbis_handle_data_packet (GstVorbisDec * vd, ogg_packet * packet,
#ifndef USE_TREMOLO
/* copy samples in buffer */
data = gst_buffer_map (out, NULL, NULL, GST_MAP_WRITE);
vd->copy_samples ((vorbis_sample_t *) data, pcm,
sample_count, vd->vi.channels, vd->width);
sample_count, vd->info.channels);
#endif
GST_LOG_OBJECT (vd, "setting output size to %" G_GSIZE_FORMAT, size);
......
......@@ -65,7 +65,7 @@ struct _GstVorbisDec {
#endif
gboolean initialized;
guint width;
GstAudioInfo info;
/* list of buffers that need timestamps */
GList *queued;
......
......@@ -34,14 +34,14 @@
* is allowed, downstream elements are supposed to clip */
static void
copy_samples_m (vorbis_sample_t * out, vorbis_sample_t ** in, guint samples,
gint channels, gint width)
gint channels)
{
memcpy (out, in[0], samples * sizeof (float));
}
static void
copy_samples_s (vorbis_sample_t * out, vorbis_sample_t ** in, guint samples,
gint channels, gint width)
gint channels)
{
#ifdef GST_VORBIS_DEC_SEQUENTIAL
memcpy (out, in[0], samples * sizeof (float));
......@@ -59,7 +59,7 @@ copy_samples_s (vorbis_sample_t * out, vorbis_sample_t ** in, guint samples,
static void
copy_samples (vorbis_sample_t * out, vorbis_sample_t ** in, guint samples,
gint channels, gint width)
gint channels)
{
#ifdef GST_VORBIS_DEC_SEQUENTIAL
gint i;
......@@ -80,12 +80,10 @@ copy_samples (vorbis_sample_t * out, vorbis_sample_t ** in, guint samples,
}
CopySampleFunc
get_copy_sample_func (gint channels, gint width)
get_copy_sample_func (gint channels)
{
CopySampleFunc f = NULL;
g_assert (width == 4);
switch (channels) {
case 1:
f = copy_samples_m;
......@@ -130,51 +128,9 @@ CLIP_TO_15 (ogg_int32_t x)
}
#endif
static void
copy_samples_32_m (vorbis_sample_t * _out, vorbis_sample_t ** _in,
guint samples, gint channels, gint width)
{
gint32 *out = (gint32 *) _out;
ogg_int32_t **in = (ogg_int32_t **) _in;
gint j;
for (j = 0; j < samples; j++) {
*out++ = CLIP_TO_15 (in[0][j] >> 9);
}
}
static void
copy_samples_32_s (vorbis_sample_t * _out, vorbis_sample_t ** _in,
guint samples, gint channels, gint width)
{
gint32 *out = (gint32 *) _out;
ogg_int32_t **in = (ogg_int32_t **) _in;
gint j;
for (j = 0; j < samples; j++) {
*out++ = CLIP_TO_15 (in[0][j] >> 9);
*out++ = CLIP_TO_15 (in[1][j] >> 9);
}
}
static void
copy_samples_32 (vorbis_sample_t * _out, vorbis_sample_t ** _in, guint samples,
gint channels, gint width)
{
gint32 *out = (gint32 *) _out;
ogg_int32_t **in = (ogg_int32_t **) _in;
gint i, j;
for (j = 0; j < samples; j++) {
for (i = 0; i < channels; i++) {
*out++ = CLIP_TO_15 (in[i][j] >> 9);
}
}
}
static void
copy_samples_16_m (vorbis_sample_t * _out, vorbis_sample_t ** _in,
guint samples, gint channels, gint width)
guint samples, gint channels)
{
gint16 *out = (gint16 *) _out;
ogg_int32_t **in = (ogg_int32_t **) _in;
......@@ -187,7 +143,7 @@ copy_samples_16_m (vorbis_sample_t * _out, vorbis_sample_t ** _in,
static void
copy_samples_16_s (vorbis_sample_t * _out, vorbis_sample_t ** _in,
guint samples, gint channels, gint width)
guint samples, gint channels)
{
gint16 *out = (gint16 *) _out;
ogg_int32_t **in = (ogg_int32_t **) _in;
......@@ -201,7 +157,7 @@ copy_samples_16_s (vorbis_sample_t * _out, vorbis_sample_t ** _in,
static void
copy_samples_16 (vorbis_sample_t * _out, vorbis_sample_t ** _in, guint samples,
gint channels, gint width)
gint channels)
{
gint16 *out = (gint16 *) _out;
ogg_int32_t **in = (ogg_int32_t **) _in;
......@@ -215,36 +171,20 @@ copy_samples_16 (vorbis_sample_t * _out, vorbis_sample_t ** _in, guint samples,
}
CopySampleFunc
get_copy_sample_func (gint channels, gint width)
get_copy_sample_func (gint channels)
{
CopySampleFunc f = NULL;
if (width == 4) {
switch (channels) {
case 1:
f = copy_samples_32_m;
break;
case 2:
f = copy_samples_32_s;