From: Tristan Matthews Date: Tue, 11 May 2010 21:56:31 +0000 (-0400) Subject: jack: improve process_cb X-Git-Tag: RELEASE-0.10.27~51 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e05b723274a24aa20c599eedfc179648306db851;p=platform%2Fupstream%2Fgst-plugins-good.git jack: improve process_cb --- diff --git a/ext/jack/gstjackaudiosrc.c b/ext/jack/gstjackaudiosrc.c index f140206..d5483de 100644 --- a/ext/jack/gstjackaudiosrc.c +++ b/ext/jack/gstjackaudiosrc.c @@ -98,6 +98,7 @@ gst_jack_audio_src_allocate_channels (GstJackAudioSrc * src, gint channels) /* alloc enough input ports */ src->ports = g_realloc (src->ports, sizeof (jack_port_t *) * channels); + src->buffers = g_realloc (src->buffers, sizeof (sample_t *) * channels); /* create an input port for each channel */ while (src->port_count < channels) { @@ -138,6 +139,8 @@ gst_jack_audio_src_free_channels (GstJackAudioSrc * src) } g_free (src->ports); src->ports = NULL; + g_free (src->buffers); + src->buffers = NULL; } /* ringbuffer abstract base class */ @@ -203,47 +206,35 @@ jack_process_cb (jack_nframes_t nframes, void *arg) { GstJackAudioSrc *src; GstRingBuffer *buf; - GstJackRingBuffer *abuf; gint len, givenLen; - guint8 *writeptr, *dataStart; + guint8 *writeptr; gint writeseg; gint channels, i, j; - sample_t **buffers, *data; + sample_t *data; buf = GST_RING_BUFFER_CAST (arg); - abuf = GST_JACK_RING_BUFFER_CAST (arg); src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (buf)); channels = buf->spec.channels; len = sizeof (sample_t) * nframes * channels; - - /* alloc pointers to samples */ - buffers = g_alloca (sizeof (sample_t *) * channels); - data = g_alloca (len); - /* get input buffers */ for (i = 0; i < channels; i++) - buffers[i] = (sample_t *) jack_port_get_buffer (src->ports[i], nframes); - - //writeptr = data; - dataStart = (guint8 *) data; - - /* the samples in the jack input buffers have to be interleaved into the - * ringbuffer - */ - for (i = 0; i < nframes; ++i) - for (j = 0; j < channels; ++j) - *data++ = buffers[j][i]; + src->buffers[i] = + (sample_t *) jack_port_get_buffer (src->ports[i], nframes); if (gst_ring_buffer_prepare_read (buf, &writeseg, &writeptr, &givenLen)) { - memcpy (writeptr, (char *) dataStart, givenLen); + /* the samples in the jack input buffers have to be interleaved into the + * ringbuffer + */ + data = (sample_t *) writeptr; + for (i = 0; i < nframes; ++i) + for (j = 0; j < channels; ++j) + *data++ = src->buffers[j][i]; + GST_DEBUG ("copy %d frames: %p, %d bytes, %d channels", nframes, writeptr, len / channels, channels); - /* clear written samples in the ringbuffer */ - // gst_ring_buffer_clear(buf, 0); - /* we wrote one segment */ gst_ring_buffer_advance (buf, 1); } @@ -728,6 +719,7 @@ gst_jack_audio_src_init (GstJackAudioSrc * src, GstJackAudioSrcClass * gclass) src->server = g_strdup (DEFAULT_PROP_SERVER); src->ports = NULL; src->port_count = 0; + src->buffers = NULL; } static void diff --git a/ext/jack/gstjackaudiosrc.h b/ext/jack/gstjackaudiosrc.h index b8d451a..e81b421 100644 --- a/ext/jack/gstjackaudiosrc.h +++ b/ext/jack/gstjackaudiosrc.h @@ -81,6 +81,7 @@ struct _GstJackAudioSrc /* our ports */ jack_port_t **ports; int port_count; + sample_t **buffers; }; struct _GstJackAudioSrcClass