jackaudiosink: Don't call g_alloca() in process_cb

g_alloca() is not RT-safe, so instead we should allocate the
memory needed in advance. Fixes #655866
This commit is contained in:
Tristan Matthews 2011-08-02 22:05:08 -04:00 committed by Sebastian Dröge
parent a1712ad87c
commit c26442a3ba
2 changed files with 10 additions and 7 deletions

View file

@ -83,6 +83,7 @@ gst_jack_audio_sink_allocate_channels (GstJackAudioSink * sink, gint channels)
/* alloc enough output ports */
sink->ports = g_realloc (sink->ports, sizeof (jack_port_t *) * channels);
sink->buffers = g_realloc (sink->buffers, sizeof (sample_t *) * channels);
/* create an output port for each channel */
while (sink->port_count < channels) {
@ -123,6 +124,8 @@ gst_jack_audio_sink_free_channels (GstJackAudioSink * sink)
}
g_free (sink->ports);
sink->ports = NULL;
g_free (sink->buffers);
sink->buffers = NULL;
}
/* ringbuffer abstract base class */
@ -187,19 +190,17 @@ jack_process_cb (jack_nframes_t nframes, void *arg)
gint readseg, len;
guint8 *readptr;
gint i, j, flen, channels;
sample_t **buffers, *data;
sample_t *data;
buf = GST_RING_BUFFER_CAST (arg);
sink = GST_JACK_AUDIO_SINK (GST_OBJECT_PARENT (buf));
channels = buf->spec.channels;
/* alloc pointers to samples */
buffers = g_alloca (sizeof (sample_t *) * channels);
/* get target buffers */
for (i = 0; i < channels; i++) {
buffers[i] = (sample_t *) jack_port_get_buffer (sink->ports[i], nframes);
sink->buffers[i] =
(sample_t *) jack_port_get_buffer (sink->ports[i], nframes);
}
if (gst_ring_buffer_prepare_read (buf, &readseg, &readptr, &len)) {
@ -217,7 +218,7 @@ jack_process_cb (jack_nframes_t nframes, void *arg)
* deinterleave into the jack target buffers */
for (i = 0; i < nframes; i++) {
for (j = 0; j < channels; j++) {
buffers[j][i] = *data++;
sink->buffers[j][i] = *data++;
}
}
@ -231,7 +232,7 @@ jack_process_cb (jack_nframes_t nframes, void *arg)
/* We are not allowed to read from the ringbuffer, write silence to all
* jack output buffers */
for (i = 0; i < channels; i++) {
memset (buffers[i], 0, nframes * sizeof (sample_t));
memset (sink->buffers[i], 0, nframes * sizeof (sample_t));
}
}
return 0;
@ -737,6 +738,7 @@ gst_jack_audio_sink_init (GstJackAudioSink * sink,
sink->jclient = NULL;
sink->ports = NULL;
sink->port_count = 0;
sink->buffers = NULL;
}
static void

View file

@ -65,6 +65,7 @@ struct _GstJackAudioSink {
/* our ports */
jack_port_t **ports;
int port_count;
sample_t **buffers;
};
struct _GstJackAudioSinkClass {