mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-20 23:36:38 +00:00
jack: improve process_cb
This commit is contained in:
parent
59fddc9237
commit
7f172b2b96
2 changed files with 17 additions and 24 deletions
|
@ -98,6 +98,7 @@ gst_jack_audio_src_allocate_channels (GstJackAudioSrc * src, gint channels)
|
||||||
|
|
||||||
/* alloc enough input ports */
|
/* alloc enough input ports */
|
||||||
src->ports = g_realloc (src->ports, sizeof (jack_port_t *) * channels);
|
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 */
|
/* create an input port for each channel */
|
||||||
while (src->port_count < channels) {
|
while (src->port_count < channels) {
|
||||||
|
@ -138,6 +139,8 @@ gst_jack_audio_src_free_channels (GstJackAudioSrc * src)
|
||||||
}
|
}
|
||||||
g_free (src->ports);
|
g_free (src->ports);
|
||||||
src->ports = NULL;
|
src->ports = NULL;
|
||||||
|
g_free (src->buffers);
|
||||||
|
src->buffers = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ringbuffer abstract base class */
|
/* ringbuffer abstract base class */
|
||||||
|
@ -203,47 +206,35 @@ jack_process_cb (jack_nframes_t nframes, void *arg)
|
||||||
{
|
{
|
||||||
GstJackAudioSrc *src;
|
GstJackAudioSrc *src;
|
||||||
GstRingBuffer *buf;
|
GstRingBuffer *buf;
|
||||||
GstJackRingBuffer *abuf;
|
|
||||||
gint len, givenLen;
|
gint len, givenLen;
|
||||||
guint8 *writeptr, *dataStart;
|
guint8 *writeptr;
|
||||||
gint writeseg;
|
gint writeseg;
|
||||||
gint channels, i, j;
|
gint channels, i, j;
|
||||||
sample_t **buffers, *data;
|
sample_t *data;
|
||||||
|
|
||||||
buf = GST_RING_BUFFER_CAST (arg);
|
buf = GST_RING_BUFFER_CAST (arg);
|
||||||
abuf = GST_JACK_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 = buf->spec.channels;
|
||||||
len = sizeof (sample_t) * nframes * 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 */
|
/* get input buffers */
|
||||||
for (i = 0; i < channels; i++)
|
for (i = 0; i < channels; i++)
|
||||||
buffers[i] = (sample_t *) jack_port_get_buffer (src->ports[i], nframes);
|
src->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];
|
|
||||||
|
|
||||||
if (gst_ring_buffer_prepare_read (buf, &writeseg, &writeptr, &givenLen)) {
|
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,
|
GST_DEBUG ("copy %d frames: %p, %d bytes, %d channels", nframes, writeptr,
|
||||||
len / channels, channels);
|
len / channels, channels);
|
||||||
|
|
||||||
/* clear written samples in the ringbuffer */
|
|
||||||
// gst_ring_buffer_clear(buf, 0);
|
|
||||||
|
|
||||||
/* we wrote one segment */
|
/* we wrote one segment */
|
||||||
gst_ring_buffer_advance (buf, 1);
|
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->server = g_strdup (DEFAULT_PROP_SERVER);
|
||||||
src->ports = NULL;
|
src->ports = NULL;
|
||||||
src->port_count = 0;
|
src->port_count = 0;
|
||||||
|
src->buffers = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -81,6 +81,7 @@ struct _GstJackAudioSrc
|
||||||
/* our ports */
|
/* our ports */
|
||||||
jack_port_t **ports;
|
jack_port_t **ports;
|
||||||
int port_count;
|
int port_count;
|
||||||
|
sample_t **buffers;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstJackAudioSrcClass
|
struct _GstJackAudioSrcClass
|
||||||
|
|
Loading…
Reference in a new issue