port to new audio caps.

This commit is contained in:
Wim Taymans 2011-08-18 19:21:07 +02:00
parent 44c1589b48
commit 09b15d7dfe
8 changed files with 138 additions and 165 deletions

View file

@ -49,6 +49,12 @@ typedef jack_default_audio_sample_t sample_t;
#define GST_TYPE_JACK_CONNECT (gst_jack_connect_get_type()) #define GST_TYPE_JACK_CONNECT (gst_jack_connect_get_type())
#define GST_TYPE_JACK_CLIENT (gst_jack_client_get_type ()) #define GST_TYPE_JACK_CLIENT (gst_jack_client_get_type ())
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
#define GST_JACK_FORMAT_STR "F32_LE"
#else
#define GST_JACK_FORMAT_STR "F32_BE"
#endif
GType gst_jack_client_get_type(void); GType gst_jack_client_get_type(void);
GType gst_jack_connect_get_type(void); GType gst_jack_connect_get_type(void);

View file

@ -195,7 +195,7 @@ jack_process_cb (jack_nframes_t nframes, void *arg)
buf = GST_RING_BUFFER_CAST (arg); buf = GST_RING_BUFFER_CAST (arg);
sink = GST_JACK_AUDIO_SINK (GST_OBJECT_PARENT (buf)); sink = GST_JACK_AUDIO_SINK (GST_OBJECT_PARENT (buf));
channels = buf->spec.channels; channels = GST_AUDIO_INFO_CHANNELS (&buf->spec.info);
/* get target buffers */ /* get target buffers */
for (i = 0; i < channels; i++) { for (i = 0; i < channels; i++) {
@ -396,7 +396,7 @@ gst_jack_ring_buffer_acquire (GstRingBuffer * buf, GstRingBufferSpec * spec)
GstJackRingBuffer *abuf; GstJackRingBuffer *abuf;
const char **ports; const char **ports;
gint sample_rate, buffer_size; gint sample_rate, buffer_size;
gint i, channels, res; gint i, rate, bpf, channels, res;
jack_client_t *client; jack_client_t *client;
sink = GST_JACK_AUDIO_SINK (GST_OBJECT_PARENT (buf)); sink = GST_JACK_AUDIO_SINK (GST_OBJECT_PARENT (buf));
@ -406,12 +406,15 @@ gst_jack_ring_buffer_acquire (GstRingBuffer * buf, GstRingBufferSpec * spec)
client = gst_jack_audio_client_get_client (sink->client); client = gst_jack_audio_client_get_client (sink->client);
rate = GST_AUDIO_INFO_RATE (&spec->info);
/* sample rate must be that of the server */ /* sample rate must be that of the server */
sample_rate = jack_get_sample_rate (client); sample_rate = jack_get_sample_rate (client);
if (sample_rate != spec->rate) if (sample_rate != rate)
goto wrong_samplerate; goto wrong_samplerate;
channels = spec->channels; channels = GST_AUDIO_INFO_CHANNELS (&spec->info);
bpf = GST_AUDIO_INFO_BPF (&spec->info);
if (!gst_jack_audio_sink_allocate_channels (sink, channels)) if (!gst_jack_audio_sink_allocate_channels (sink, channels))
goto out_of_ports; goto out_of_ports;
@ -422,7 +425,7 @@ gst_jack_ring_buffer_acquire (GstRingBuffer * buf, GstRingBufferSpec * spec)
* for all channels */ * for all channels */
spec->segsize = buffer_size * sizeof (gfloat) * channels; spec->segsize = buffer_size * sizeof (gfloat) * channels;
spec->latency_time = gst_util_uint64_scale (spec->segsize, spec->latency_time = gst_util_uint64_scale (spec->segsize,
(GST_SECOND / GST_USECOND), spec->rate * spec->bytes_per_sample); (GST_SECOND / GST_USECOND), rate * bpf);
/* segtotal based on buffer-time latency */ /* segtotal based on buffer-time latency */
spec->segtotal = spec->buffer_time / spec->latency_time; spec->segtotal = spec->buffer_time / spec->latency_time;
if (spec->segtotal < 2) { if (spec->segtotal < 2) {
@ -482,7 +485,7 @@ done:
abuf->sample_rate = sample_rate; abuf->sample_rate = sample_rate;
abuf->buffer_size = buffer_size; abuf->buffer_size = buffer_size;
abuf->channels = spec->channels; abuf->channels = channels;
return TRUE; return TRUE;
@ -491,7 +494,7 @@ wrong_samplerate:
{ {
GST_ELEMENT_ERROR (sink, RESOURCE, SETTINGS, (NULL), GST_ELEMENT_ERROR (sink, RESOURCE, SETTINGS, (NULL),
("Wrong samplerate, server is running at %d and we received %d", ("Wrong samplerate, server is running at %d and we received %d",
sample_rate, spec->rate)); sample_rate, rate));
return FALSE; return FALSE;
} }
out_of_ports: out_of_ports:
@ -631,9 +634,8 @@ static GstStaticPadTemplate jackaudiosink_sink_factory =
GST_STATIC_PAD_TEMPLATE ("sink", GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK, GST_PAD_SINK,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
GST_STATIC_CAPS ("audio/x-raw-float, " GST_STATIC_CAPS ("audio/x-raw, "
"endianness = (int) BYTE_ORDER, " "format = (string) " GST_JACK_FORMAT_STR ", "
"width = (int) 32, "
"rate = (int) [ 1, MAX ], " "channels = (int) [ 1, MAX ]") "rate = (int) [ 1, MAX ], " "channels = (int) [ 1, MAX ]")
); );
@ -835,9 +837,8 @@ gst_jack_audio_sink_getcaps (GstBaseSink * bsink, GstCaps * filter)
GST_DEBUG_OBJECT (sink, "got %d-%d ports, samplerate: %d", min, max, rate); GST_DEBUG_OBJECT (sink, "got %d-%d ports, samplerate: %d", min, max, rate);
if (!sink->caps) { if (!sink->caps) {
sink->caps = gst_caps_new_simple ("audio/x-raw-float", sink->caps = gst_caps_new_simple ("audio/x-raw",
"endianness", G_TYPE_INT, G_BYTE_ORDER, "format", G_TYPE_STRING, GST_JACK_FORMAT_STR,
"width", G_TYPE_INT, 32,
"rate", G_TYPE_INT, rate, "rate", G_TYPE_INT, rate,
"channels", GST_TYPE_INT_RANGE, min, max, NULL); "channels", GST_TYPE_INT_RANGE, min, max, NULL);
} }

View file

@ -215,7 +215,7 @@ jack_process_cb (jack_nframes_t nframes, void *arg)
buf = GST_RING_BUFFER_CAST (arg); buf = GST_RING_BUFFER_CAST (arg);
src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (buf)); src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (buf));
channels = buf->spec.channels; channels = GST_AUDIO_INFO_CHANNELS (&buf->spec.info);
/* get input buffers */ /* get input buffers */
for (i = 0; i < channels; i++) for (i = 0; i < channels; i++)
@ -404,7 +404,7 @@ gst_jack_ring_buffer_acquire (GstRingBuffer * buf, GstRingBufferSpec * spec)
GstJackRingBuffer *abuf; GstJackRingBuffer *abuf;
const char **ports; const char **ports;
gint sample_rate, buffer_size; gint sample_rate, buffer_size;
gint i, channels, res; gint i, bpf, rate, channels, res;
jack_client_t *client; jack_client_t *client;
src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (buf)); src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (buf));
@ -414,12 +414,15 @@ gst_jack_ring_buffer_acquire (GstRingBuffer * buf, GstRingBufferSpec * spec)
client = gst_jack_audio_client_get_client (src->client); client = gst_jack_audio_client_get_client (src->client);
rate = GST_AUDIO_INFO_RATE (&spec->info);
/* sample rate must be that of the server */ /* sample rate must be that of the server */
sample_rate = jack_get_sample_rate (client); sample_rate = jack_get_sample_rate (client);
if (sample_rate != spec->rate) if (sample_rate != rate)
goto wrong_samplerate; goto wrong_samplerate;
channels = spec->channels; bpf = GST_AUDIO_INFO_BPF (&spec->info);
channels = GST_AUDIO_INFO_CHANNELS (&spec->info);
if (!gst_jack_audio_src_allocate_channels (src, channels)) if (!gst_jack_audio_src_allocate_channels (src, channels))
goto out_of_ports; goto out_of_ports;
@ -432,7 +435,7 @@ gst_jack_ring_buffer_acquire (GstRingBuffer * buf, GstRingBufferSpec * spec)
* for all channels */ * for all channels */
spec->segsize = buffer_size * sizeof (gfloat) * channels; spec->segsize = buffer_size * sizeof (gfloat) * channels;
spec->latency_time = gst_util_uint64_scale (spec->segsize, spec->latency_time = gst_util_uint64_scale (spec->segsize,
(GST_SECOND / GST_USECOND), spec->rate * spec->bytes_per_sample); (GST_SECOND / GST_USECOND), rate * bpf);
/* segtotal based on buffer-time latency */ /* segtotal based on buffer-time latency */
spec->segtotal = spec->buffer_time / spec->latency_time; spec->segtotal = spec->buffer_time / spec->latency_time;
if (spec->segtotal < 2) { if (spec->segtotal < 2) {
@ -494,7 +497,7 @@ done:
abuf->sample_rate = sample_rate; abuf->sample_rate = sample_rate;
abuf->buffer_size = buffer_size; abuf->buffer_size = buffer_size;
abuf->channels = spec->channels; abuf->channels = channels;
return TRUE; return TRUE;
@ -503,7 +506,7 @@ wrong_samplerate:
{ {
GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL), GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
("Wrong samplerate, server is running at %d and we received %d", ("Wrong samplerate, server is running at %d and we received %d",
sample_rate, spec->rate)); sample_rate, rate));
return FALSE; return FALSE;
} }
out_of_ports: out_of_ports:
@ -668,9 +671,8 @@ enum
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC, GST_PAD_SRC,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
GST_STATIC_CAPS ("audio/x-raw-float, " GST_STATIC_CAPS ("audio/x-raw, "
"endianness = (int) BYTE_ORDER, " "format = (string) " GST_JACK_FORMAT_STR ", "
"width = (int) 32, "
"rate = (int) [ 1, MAX ], " "channels = (int) [ 1, MAX ]") "rate = (int) [ 1, MAX ], " "channels = (int) [ 1, MAX ]")
); );
@ -858,9 +860,8 @@ gst_jack_audio_src_getcaps (GstBaseSrc * bsrc, GstCaps * filter)
GST_DEBUG_OBJECT (src, "got %d-%d ports, samplerate: %d", min, max, rate); GST_DEBUG_OBJECT (src, "got %d-%d ports, samplerate: %d", min, max, rate);
if (!src->caps) { if (!src->caps) {
src->caps = gst_caps_new_simple ("audio/x-raw-float", src->caps = gst_caps_new_simple ("audio/x-raw",
"endianness", G_TYPE_INT, G_BYTE_ORDER, "format", G_TYPE_STRING, GST_JACK_FORMAT_STR,
"width", G_TYPE_INT, 32,
"rate", G_TYPE_INT, rate, "rate", G_TYPE_INT, rate,
"channels", GST_TYPE_INT_RANGE, min, max, NULL); "channels", GST_TYPE_INT_RANGE, min, max, NULL);
} }

View file

@ -1274,16 +1274,16 @@ server_dead:
G_STMT_START { \ G_STMT_START { \
guint8 *sb = s, *db = d; \ guint8 *sb = s, *db = d; \
while (s <= se && d < de) { \ while (s <= se && d < de) { \
memcpy (d, s, bps); \ memcpy (d, s, bpf); \
s += bps; \ s += bpf; \
*accum += outr; \ *accum += outr; \
if ((*accum << 1) >= inr) { \ if ((*accum << 1) >= inr) { \
*accum -= inr; \ *accum -= inr; \
d += bps; \ d += bpf; \
} \ } \
} \ } \
in_samples -= (s - sb)/bps; \ in_samples -= (s - sb)/bpf; \
out_samples -= (d - db)/bps; \ out_samples -= (d - db)/bpf; \
GST_DEBUG ("fwd_up end %d/%d",*accum,*toprocess); \ GST_DEBUG ("fwd_up end %d/%d",*accum,*toprocess); \
} G_STMT_END } G_STMT_END
@ -1292,16 +1292,16 @@ G_STMT_START { \
G_STMT_START { \ G_STMT_START { \
guint8 *sb = s, *db = d; \ guint8 *sb = s, *db = d; \
while (s <= se && d < de) { \ while (s <= se && d < de) { \
memcpy (d, s, bps); \ memcpy (d, s, bpf); \
d += bps; \ d += bpf; \
*accum += inr; \ *accum += inr; \
if ((*accum << 1) >= outr) { \ if ((*accum << 1) >= outr) { \
*accum -= outr; \ *accum -= outr; \
s += bps; \ s += bpf; \
} \ } \
} \ } \
in_samples -= (s - sb)/bps; \ in_samples -= (s - sb)/bpf; \
out_samples -= (d - db)/bps; \ out_samples -= (d - db)/bpf; \
GST_DEBUG ("fwd_down end %d/%d",*accum,*toprocess); \ GST_DEBUG ("fwd_down end %d/%d",*accum,*toprocess); \
} G_STMT_END } G_STMT_END
@ -1309,16 +1309,16 @@ G_STMT_START { \
G_STMT_START { \ G_STMT_START { \
guint8 *sb = se, *db = d; \ guint8 *sb = se, *db = d; \
while (s <= se && d < de) { \ while (s <= se && d < de) { \
memcpy (d, se, bps); \ memcpy (d, se, bpf); \
se -= bps; \ se -= bpf; \
*accum += outr; \ *accum += outr; \
while (d < de && (*accum << 1) >= inr) { \ while (d < de && (*accum << 1) >= inr) { \
*accum -= inr; \ *accum -= inr; \
d += bps; \ d += bpf; \
} \ } \
} \ } \
in_samples -= (sb - se)/bps; \ in_samples -= (sb - se)/bpf; \
out_samples -= (d - db)/bps; \ out_samples -= (d - db)/bpf; \
GST_DEBUG ("rev_up end %d/%d",*accum,*toprocess); \ GST_DEBUG ("rev_up end %d/%d",*accum,*toprocess); \
} G_STMT_END } G_STMT_END
@ -1326,16 +1326,16 @@ G_STMT_START { \
G_STMT_START { \ G_STMT_START { \
guint8 *sb = se, *db = d; \ guint8 *sb = se, *db = d; \
while (s <= se && d < de) { \ while (s <= se && d < de) { \
memcpy (d, se, bps); \ memcpy (d, se, bpf); \
d += bps; \ d += bpf; \
*accum += inr; \ *accum += inr; \
while (s <= se && (*accum << 1) >= outr) { \ while (s <= se && (*accum << 1) >= outr) { \
*accum -= outr; \ *accum -= outr; \
se -= bps; \ se -= bpf; \
} \ } \
} \ } \
in_samples -= (sb - se)/bps; \ in_samples -= (sb - se)/bpf; \
out_samples -= (d - db)/bps; \ out_samples -= (d - db)/bpf; \
GST_DEBUG ("rev_down end %d/%d",*accum,*toprocess); \ GST_DEBUG ("rev_down end %d/%d",*accum,*toprocess); \
} G_STMT_END } G_STMT_END
@ -1351,7 +1351,7 @@ gst_pulseringbuffer_commit (GstRingBuffer * buf, guint64 * sample,
guint8 *data_end; guint8 *data_end;
gboolean reverse; gboolean reverse;
gint *toprocess; gint *toprocess;
gint inr, outr, bps; gint inr, outr, bpf;
gint64 offset; gint64 offset;
guint bufsize; guint bufsize;
@ -1381,7 +1381,7 @@ gst_pulseringbuffer_commit (GstRingBuffer * buf, guint64 * sample,
GST_DEBUG_OBJECT (psink, "entering commit"); GST_DEBUG_OBJECT (psink, "entering commit");
pbuf->in_commit = TRUE; pbuf->in_commit = TRUE;
bps = buf->spec.bytes_per_sample; bpf = GST_AUDIO_INFO_BPF (&buf->spec.info);
bufsize = buf->spec.segsize * buf->spec.segtotal; bufsize = buf->spec.segsize * buf->spec.segtotal;
/* our toy resampler for trick modes */ /* our toy resampler for trick modes */
@ -1400,7 +1400,7 @@ gst_pulseringbuffer_commit (GstRingBuffer * buf, guint64 * sample,
/* data_end points to the last sample we have to write, not past it. This is /* data_end points to the last sample we have to write, not past it. This is
* needed to properly handle reverse playback: it points to the last sample. */ * needed to properly handle reverse playback: it points to the last sample. */
data_end = data + (bps * inr); data_end = data + (bpf * inr);
#ifdef HAVE_PULSE_1_0 #ifdef HAVE_PULSE_1_0
if (g_atomic_int_get (&psink->format_lost)) { if (g_atomic_int_get (&psink->format_lost)) {
@ -1413,7 +1413,7 @@ gst_pulseringbuffer_commit (GstRingBuffer * buf, guint64 * sample,
goto was_paused; goto was_paused;
/* offset is in bytes */ /* offset is in bytes */
offset = *sample * bps; offset = *sample * bpf;
while (*toprocess > 0) { while (*toprocess > 0) {
size_t avail; size_t avail;
@ -1427,7 +1427,7 @@ gst_pulseringbuffer_commit (GstRingBuffer * buf, guint64 * sample,
GST_LOG_OBJECT (psink, "discontinuity, offset is %" G_GINT64_FORMAT ", " GST_LOG_OBJECT (psink, "discontinuity, offset is %" G_GINT64_FORMAT ", "
"last offset was %" G_GINT64_FORMAT, offset, pbuf->m_lastoffset); "last offset was %" G_GINT64_FORMAT, offset, pbuf->m_lastoffset);
towrite = out_samples * bps; towrite = out_samples * bpf;
/* Only ever write segsize bytes at once. This will /* Only ever write segsize bytes at once. This will
* also limit the PA shm buffer to segsize * also limit the PA shm buffer to segsize
@ -1444,7 +1444,7 @@ gst_pulseringbuffer_commit (GstRingBuffer * buf, guint64 * sample,
GST_LOG_OBJECT (psink, GST_LOG_OBJECT (psink,
"flushing %u samples at offset %" G_GINT64_FORMAT, "flushing %u samples at offset %" G_GINT64_FORMAT,
(guint) pbuf->m_towrite / bps, pbuf->m_offset); (guint) pbuf->m_towrite / bpf, pbuf->m_offset);
if (pa_stream_write (pbuf->stream, (uint8_t *) pbuf->m_data, if (pa_stream_write (pbuf->stream, (uint8_t *) pbuf->m_data,
pbuf->m_towrite, NULL, pbuf->m_offset, PA_SEEK_ABSOLUTE) < 0) { pbuf->m_towrite, NULL, pbuf->m_offset, PA_SEEK_ABSOLUTE) < 0) {
@ -1468,8 +1468,8 @@ gst_pulseringbuffer_commit (GstRingBuffer * buf, guint64 * sample,
if (pbuf->m_writable == (size_t) - 1) if (pbuf->m_writable == (size_t) - 1)
goto writable_size_failed; goto writable_size_failed;
pbuf->m_writable /= bps; pbuf->m_writable /= bpf;
pbuf->m_writable *= bps; /* handle only complete samples */ pbuf->m_writable *= bpf; /* handle only complete samples */
if (pbuf->m_writable >= towrite) if (pbuf->m_writable >= towrite)
break; break;
@ -1518,7 +1518,7 @@ gst_pulseringbuffer_commit (GstRingBuffer * buf, guint64 * sample,
if (pbuf->m_writable < towrite) if (pbuf->m_writable < towrite)
towrite = pbuf->m_writable; towrite = pbuf->m_writable;
avail = towrite / bps; avail = towrite / bpf;
GST_LOG_OBJECT (psink, "writing %u samples at offset %" G_GUINT64_FORMAT, GST_LOG_OBJECT (psink, "writing %u samples at offset %" G_GUINT64_FORMAT,
(guint) avail, offset); (guint) avail, offset);
@ -1569,14 +1569,14 @@ gst_pulseringbuffer_commit (GstRingBuffer * buf, guint64 * sample,
pbuf->m_towrite += towrite; pbuf->m_towrite += towrite;
pbuf->m_writable -= towrite; pbuf->m_writable -= towrite;
avail = towrite / bps; avail = towrite / bpf;
} }
/* flush the buffer if it's full */ /* flush the buffer if it's full */
if ((pbuf->m_data != NULL) && (pbuf->m_towrite > 0) if ((pbuf->m_data != NULL) && (pbuf->m_towrite > 0)
&& (pbuf->m_writable == 0)) { && (pbuf->m_writable == 0)) {
GST_LOG_OBJECT (psink, "flushing %u samples at offset %" G_GINT64_FORMAT, GST_LOG_OBJECT (psink, "flushing %u samples at offset %" G_GINT64_FORMAT,
(guint) pbuf->m_towrite / bps, pbuf->m_offset); (guint) pbuf->m_towrite / bpf, pbuf->m_offset);
if (pa_stream_write (pbuf->stream, (uint8_t *) pbuf->m_data, if (pa_stream_write (pbuf->stream, (uint8_t *) pbuf->m_data,
pbuf->m_towrite, NULL, pbuf->m_offset, PA_SEEK_ABSOLUTE) < 0) { pbuf->m_towrite, NULL, pbuf->m_offset, PA_SEEK_ABSOLUTE) < 0) {
@ -1587,7 +1587,7 @@ gst_pulseringbuffer_commit (GstRingBuffer * buf, guint64 * sample,
} }
*sample += avail; *sample += avail;
offset += avail * bps; offset += avail * bpf;
pbuf->m_lastoffset = offset; pbuf->m_lastoffset = offset;
/* check if we need to uncork after writing the samples */ /* check if we need to uncork after writing the samples */
@ -1615,13 +1615,13 @@ gst_pulseringbuffer_commit (GstRingBuffer * buf, guint64 * sample,
fake_done: fake_done:
#endif #endif
/* we consumed all samples here */ /* we consumed all samples here */
data = data_end + bps; data = data_end + bpf;
pbuf->in_commit = FALSE; pbuf->in_commit = FALSE;
pa_threaded_mainloop_unlock (mainloop); pa_threaded_mainloop_unlock (mainloop);
done: done:
result = inr - ((data_end - data) / bps); result = inr - ((data_end - data) / bpf);
GST_LOG_OBJECT (psink, "wrote %d samples", result); GST_LOG_OBJECT (psink, "wrote %d samples", result);
return result; return result;
@ -1686,12 +1686,12 @@ gst_pulsering_flush (GstPulseRingBuffer * pbuf)
/* flush the buffer if possible */ /* flush the buffer if possible */
if (pbuf->stream && (pbuf->m_data != NULL) && (pbuf->m_towrite > 0)) { if (pbuf->stream && (pbuf->m_data != NULL) && (pbuf->m_towrite > 0)) {
#ifndef GST_DISABLE_GST_DEBUG #ifndef GST_DISABLE_GST_DEBUG
gint bps; gint bpf;
bps = (GST_RING_BUFFER_CAST (pbuf))->spec.bytes_per_sample; bpf = (GST_RING_BUFFER_CAST (pbuf))->spec.info.bpf;
GST_LOG_OBJECT (psink, GST_LOG_OBJECT (psink,
"flushing %u samples at offset %" G_GINT64_FORMAT, "flushing %u samples at offset %" G_GINT64_FORMAT,
(guint) pbuf->m_towrite / bps, pbuf->m_offset); (guint) pbuf->m_towrite / bpf, pbuf->m_offset);
#endif #endif
if (pa_stream_write (pbuf->stream, (uint8_t *) pbuf->m_data, if (pa_stream_write (pbuf->stream, (uint8_t *) pbuf->m_data,
@ -1728,49 +1728,18 @@ static GstStateChangeReturn gst_pulsesink_change_state (GstElement * element,
GstStateChange transition); GstStateChange transition);
#if (G_BYTE_ORDER == G_LITTLE_ENDIAN) #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
# define ENDIANNESS "LITTLE_ENDIAN, BIG_ENDIAN" # define FORMATS "{ S16_LE, S16_BE, F32_LE, F32_BE, S32_LE, S32_BE, " \
"S24_3LE, S24_3BE, S24_LE, S24_BE, S8 }"
#else #else
# define ENDIANNESS "BIG_ENDIAN, LITTLE_ENDIAN" # define FORMATS "{ S16_BE, S16_LE, F32_BE, F32_LE, S32_BE, S32_LE, " \
"S24_3BE, S24_3LE, S24_BE, S24_LE, S8 }"
#endif #endif
static GstStaticPadTemplate pad_template = GST_STATIC_PAD_TEMPLATE ("sink", static GstStaticPadTemplate pad_template = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK, GST_PAD_SINK,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
GST_STATIC_CAPS ("audio/x-raw-int, " GST_STATIC_CAPS ("audio/x-raw, "
"endianness = (int) { " ENDIANNESS " }, " "format = (string) " FORMATS ", "
"signed = (boolean) TRUE, "
"width = (int) 16, "
"depth = (int) 16, "
"rate = (int) [ 1, MAX ], "
"channels = (int) [ 1, 32 ];"
"audio/x-raw-float, "
"endianness = (int) { " ENDIANNESS " }, "
"width = (int) 32, "
"rate = (int) [ 1, MAX ], "
"channels = (int) [ 1, 32 ];"
"audio/x-raw-int, "
"endianness = (int) { " ENDIANNESS " }, "
"signed = (boolean) TRUE, "
"width = (int) 32, "
"depth = (int) 32, "
"rate = (int) [ 1, MAX ], " "channels = (int) [ 1, 32 ];"
"audio/x-raw-int, "
"endianness = (int) { " ENDIANNESS " }, "
"signed = (boolean) TRUE, "
"width = (int) 24, "
"depth = (int) 24, "
"rate = (int) [ 1, MAX ], "
"channels = (int) [ 1, 32 ];"
"audio/x-raw-int, "
"endianness = (int) { " ENDIANNESS " }, "
"signed = (boolean) TRUE, "
"width = (int) 32, "
"depth = (int) 24, "
"rate = (int) [ 1, MAX ], " "channels = (int) [ 1, 32 ];"
"audio/x-raw-int, "
"signed = (boolean) FALSE, "
"width = (int) 8, "
"depth = (int) 8, "
"rate = (int) [ 1, MAX ], " "rate = (int) [ 1, MAX ], "
"channels = (int) [ 1, 32 ];" "channels = (int) [ 1, 32 ];"
"audio/x-alaw, " "audio/x-alaw, "

View file

@ -99,37 +99,16 @@ static GstStateChangeReturn gst_pulsesrc_change_state (GstElement *
element, GstStateChange transition); element, GstStateChange transition);
#if (G_BYTE_ORDER == G_LITTLE_ENDIAN) #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
# define ENDIANNESS "LITTLE_ENDIAN, BIG_ENDIAN" # define FORMATS "{ S16_LE, S16_BE, F32_LE, F32_BE, S32_LE, S32_BE, U8 }"
#else #else
# define ENDIANNESS "BIG_ENDIAN, LITTLE_ENDIAN" # define FORMATS "{ S16_BE, S16_LE, F32_BE, F32_LE, S32_BE, S32_LE, U8 }"
#endif #endif
static GstStaticPadTemplate pad_template = GST_STATIC_PAD_TEMPLATE ("src", static GstStaticPadTemplate pad_template = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC, GST_PAD_SRC,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
GST_STATIC_CAPS ("audio/x-raw-int, " GST_STATIC_CAPS ("audio/x-raw, "
"endianness = (int) { " ENDIANNESS " }, " "format = (string) " FORMATS ", "
"signed = (boolean) TRUE, "
"width = (int) 16, "
"depth = (int) 16, "
"rate = (int) [ 1, MAX ], "
"channels = (int) [ 1, 32 ];"
"audio/x-raw-float, "
"endianness = (int) { " ENDIANNESS " }, "
"width = (int) 32, "
"rate = (int) [ 1, MAX ], "
"channels = (int) [ 1, 32 ];"
"audio/x-raw-int, "
"endianness = (int) { " ENDIANNESS " }, "
"signed = (boolean) TRUE, "
"width = (int) 32, "
"depth = (int) 32, "
"rate = (int) [ 1, MAX ], "
"channels = (int) [ 1, 32 ];"
"audio/x-raw-int, "
"signed = (boolean) FALSE, "
"width = (int) 8, "
"depth = (int) 8, "
"rate = (int) [ 1, MAX ], " "rate = (int) [ 1, MAX ], "
"channels = (int) [ 1, 32 ];" "channels = (int) [ 1, 32 ];"
"audio/x-alaw, " "audio/x-alaw, "
@ -853,9 +832,9 @@ gst_pulsesrc_create_stream (GstPulseSrc * pulsesrc, GstCaps * caps)
s = gst_caps_get_structure (caps, 0); s = gst_caps_get_structure (caps, 0);
if (!gst_structure_has_field (s, "channel-layout") || if (!gst_structure_has_field (s, "channel-layout") ||
!gst_pulse_gst_to_channel_map (&channel_map, &spec)) { !gst_pulse_gst_to_channel_map (&channel_map, &spec)) {
if (spec.channels == 1) if (spec.info.channels == 1)
pa_channel_map_init_mono (&channel_map); pa_channel_map_init_mono (&channel_map);
else if (spec.channels == 2) else if (spec.info.channels == 2)
pa_channel_map_init_stereo (&channel_map); pa_channel_map_init_stereo (&channel_map);
else else
need_channel_layout = TRUE; need_channel_layout = TRUE;

View file

@ -80,37 +80,53 @@ gboolean
gst_pulse_fill_sample_spec (GstRingBufferSpec * spec, pa_sample_spec * ss) gst_pulse_fill_sample_spec (GstRingBufferSpec * spec, pa_sample_spec * ss)
{ {
if (spec->format == GST_MU_LAW && spec->width == 8) if (spec->type == GST_BUFTYPE_RAW) {
switch (GST_AUDIO_INFO_FORMAT (&spec->info)) {
case GST_AUDIO_FORMAT_U8:
ss->format = PA_SAMPLE_U8;
break;
case GST_AUDIO_FORMAT_S16_LE:
ss->format = PA_SAMPLE_S16LE;
break;
case GST_AUDIO_FORMAT_S16_BE:
ss->format = PA_SAMPLE_S16BE;
break;
case GST_AUDIO_FORMAT_F32_LE:
ss->format = PA_SAMPLE_FLOAT32LE;
break;
case GST_AUDIO_FORMAT_F32_BE:
ss->format = PA_SAMPLE_FLOAT32BE;
break;
case GST_AUDIO_FORMAT_S32_LE:
ss->format = PA_SAMPLE_S32LE;
break;
case GST_AUDIO_FORMAT_S32_BE:
ss->format = PA_SAMPLE_S32BE;
break;
case GST_AUDIO_FORMAT_S24_3LE:
ss->format = PA_SAMPLE_S24LE;
break;
case GST_AUDIO_FORMAT_S24_3BE:
ss->format = PA_SAMPLE_S24BE;
break;
case GST_AUDIO_FORMAT_S24_LE:
ss->format = PA_SAMPLE_S24_32LE;
break;
case GST_AUDIO_FORMAT_S24_BE:
ss->format = PA_SAMPLE_S24_32BE;
break;
default:
return FALSE;
}
} else if (spec->type == GST_BUFTYPE_MU_LAW) {
ss->format = PA_SAMPLE_ULAW; ss->format = PA_SAMPLE_ULAW;
else if (spec->format == GST_A_LAW && spec->width == 8) } else if (spec->type == GST_BUFTYPE_A_LAW) {
ss->format = PA_SAMPLE_ALAW; ss->format = PA_SAMPLE_ALAW;
else if (spec->format == GST_U8 && spec->width == 8) } else
ss->format = PA_SAMPLE_U8;
else if (spec->format == GST_S16_LE && spec->width == 16)
ss->format = PA_SAMPLE_S16LE;
else if (spec->format == GST_S16_BE && spec->width == 16)
ss->format = PA_SAMPLE_S16BE;
else if (spec->format == GST_FLOAT32_LE && spec->width == 32)
ss->format = PA_SAMPLE_FLOAT32LE;
else if (spec->format == GST_FLOAT32_BE && spec->width == 32)
ss->format = PA_SAMPLE_FLOAT32BE;
else if (spec->format == GST_S32_LE && spec->width == 32)
ss->format = PA_SAMPLE_S32LE;
else if (spec->format == GST_S32_BE && spec->width == 32)
ss->format = PA_SAMPLE_S32BE;
else if (spec->format == GST_S24_3LE && spec->width == 24)
ss->format = PA_SAMPLE_S24LE;
else if (spec->format == GST_S24_3BE && spec->width == 24)
ss->format = PA_SAMPLE_S24BE;
else if (spec->format == GST_S24_LE && spec->width == 32)
ss->format = PA_SAMPLE_S24_32LE;
else if (spec->format == GST_S24_BE && spec->width == 32)
ss->format = PA_SAMPLE_S24_32BE;
else
return FALSE; return FALSE;
ss->channels = spec->channels; ss->channels = GST_AUDIO_INFO_CHANNELS (&spec->info);
ss->rate = spec->rate; ss->rate = GST_AUDIO_INFO_RATE (&spec->info);
if (!pa_sample_spec_valid (ss)) if (!pa_sample_spec_valid (ss))
return FALSE; return FALSE;
@ -236,7 +252,7 @@ gst_pulse_gst_to_channel_map (pa_channel_map * map,
return NULL; return NULL;
} }
for (i = 0; i < spec->channels; i++) { for (i = 0; i < spec->info.channels; i++) {
if (pos[i] == GST_AUDIO_CHANNEL_POSITION_NONE) { if (pos[i] == GST_AUDIO_CHANNEL_POSITION_NONE) {
/* no valid mappings for these channels */ /* no valid mappings for these channels */
g_free (pos); g_free (pos);
@ -248,7 +264,7 @@ gst_pulse_gst_to_channel_map (pa_channel_map * map,
} }
g_free (pos); g_free (pos);
map->channels = spec->channels; map->channels = spec->info.channels;
if (!pa_channel_map_valid (map)) { if (!pa_channel_map_valid (map)) {
return NULL; return NULL;
@ -264,12 +280,15 @@ gst_pulse_channel_map_to_gst (const pa_channel_map * map,
int i; int i;
GstAudioChannelPosition *pos; GstAudioChannelPosition *pos;
gboolean invalid = FALSE; gboolean invalid = FALSE;
gint channels;
g_return_val_if_fail (map->channels == spec->channels, NULL); channels = GST_AUDIO_INFO_CHANNELS (&spec->info);
pos = g_new0 (GstAudioChannelPosition, spec->channels + 1); g_return_val_if_fail (map->channels == channels, NULL);
for (i = 0; i < spec->channels; i++) { pos = g_new0 (GstAudioChannelPosition, channels + 1);
for (i = 0; i < channels; i++) {
if (map->map[i] == PA_CHANNEL_POSITION_INVALID) { if (map->map[i] == PA_CHANNEL_POSITION_INVALID) {
invalid = TRUE; invalid = TRUE;
break; break;
@ -281,11 +300,11 @@ gst_pulse_channel_map_to_gst (const pa_channel_map * map,
} }
} }
if (!invalid && !gst_audio_check_channel_positions (pos, spec->channels)) if (!invalid && !gst_audio_check_channel_positions (pos, channels))
invalid = TRUE; invalid = TRUE;
if (invalid) { if (invalid) {
for (i = 0; i < spec->channels; i++) for (i = 0; i < channels; i++)
pos[i] = GST_AUDIO_CHANNEL_POSITION_NONE; pos[i] = GST_AUDIO_CHANNEL_POSITION_NONE;
} }

View file

@ -154,8 +154,7 @@ gst_auto_audio_sink_reset (GstAutoAudioSink * sink)
gst_object_unref (targetpad); gst_object_unref (targetpad);
} }
static GstStaticCaps raw_caps = static GstStaticCaps raw_caps = GST_STATIC_CAPS ("audio/x-raw");
GST_STATIC_CAPS ("audio/x-raw-int; audio/x-raw-float");
static void static void
gst_auto_audio_sink_init (GstAutoAudioSink * sink) gst_auto_audio_sink_init (GstAutoAudioSink * sink)

View file

@ -157,8 +157,7 @@ gst_auto_audio_src_reset (GstAutoAudioSrc * src)
gst_object_unref (targetpad); gst_object_unref (targetpad);
} }
static GstStaticCaps raw_caps = static GstStaticCaps raw_caps = GST_STATIC_CAPS ("audio/x-raw");
GST_STATIC_CAPS ("audio/x-raw-int; audio/x-raw-float");
static void static void
gst_auto_audio_src_init (GstAutoAudioSrc * src) gst_auto_audio_src_init (GstAutoAudioSrc * src)