mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-30 13:41:48 +00:00
jacksrc: make sure we always read nframes
Error out when we are asked to read a different size that what was configured as the jack period size because that would mean something else is wrong. Fixes #618409
This commit is contained in:
parent
e05b723274
commit
71b06e4957
1 changed files with 20 additions and 8 deletions
|
@ -206,32 +206,36 @@ jack_process_cb (jack_nframes_t nframes, void *arg)
|
||||||
{
|
{
|
||||||
GstJackAudioSrc *src;
|
GstJackAudioSrc *src;
|
||||||
GstRingBuffer *buf;
|
GstRingBuffer *buf;
|
||||||
gint len, givenLen;
|
gint len;
|
||||||
guint8 *writeptr;
|
guint8 *writeptr;
|
||||||
gint writeseg;
|
gint writeseg;
|
||||||
gint channels, i, j;
|
gint channels, i, j, flen;
|
||||||
sample_t *data;
|
sample_t *data;
|
||||||
|
|
||||||
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 = buf->spec.channels;
|
||||||
len = sizeof (sample_t) * nframes * channels;
|
|
||||||
/* get input buffers */
|
/* get input buffers */
|
||||||
for (i = 0; i < channels; i++)
|
for (i = 0; i < channels; i++)
|
||||||
src->buffers[i] =
|
src->buffers[i] =
|
||||||
(sample_t *) jack_port_get_buffer (src->ports[i], nframes);
|
(sample_t *) jack_port_get_buffer (src->ports[i], nframes);
|
||||||
|
|
||||||
if (gst_ring_buffer_prepare_read (buf, &writeseg, &writeptr, &givenLen)) {
|
if (gst_ring_buffer_prepare_read (buf, &writeseg, &writeptr, &len)) {
|
||||||
|
flen = len / channels;
|
||||||
|
|
||||||
|
/* the number of samples must be exactly the segment size */
|
||||||
|
if (nframes * sizeof (sample_t) != flen)
|
||||||
|
goto wrong_size;
|
||||||
|
|
||||||
/* the samples in the jack input buffers have to be interleaved into the
|
/* the samples in the jack input buffers have to be interleaved into the
|
||||||
* ringbuffer
|
* ringbuffer */
|
||||||
*/
|
|
||||||
data = (sample_t *) writeptr;
|
data = (sample_t *) writeptr;
|
||||||
for (i = 0; i < nframes; ++i)
|
for (i = 0; i < nframes; ++i)
|
||||||
for (j = 0; j < channels; ++j)
|
for (j = 0; j < channels; ++j)
|
||||||
*data++ = src->buffers[j][i];
|
*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);
|
||||||
|
|
||||||
|
@ -239,6 +243,14 @@ jack_process_cb (jack_nframes_t nframes, void *arg)
|
||||||
gst_ring_buffer_advance (buf, 1);
|
gst_ring_buffer_advance (buf, 1);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
/* ERRORS */
|
||||||
|
wrong_size:
|
||||||
|
{
|
||||||
|
GST_ERROR_OBJECT (src, "nbytes (%d) != flen (%d)",
|
||||||
|
(gint) (nframes * sizeof (sample_t)), flen);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* we error out */
|
/* we error out */
|
||||||
|
|
Loading…
Reference in a new issue