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:
Wim Taymans 2010-05-13 12:55:29 +02:00
parent 7f172b2b96
commit d4f6a94b93

View file

@ -206,32 +206,36 @@ jack_process_cb (jack_nframes_t nframes, void *arg)
{
GstJackAudioSrc *src;
GstRingBuffer *buf;
gint len, givenLen;
gint len;
guint8 *writeptr;
gint writeseg;
gint channels, i, j;
gint channels, i, j, flen;
sample_t *data;
buf = GST_RING_BUFFER_CAST (arg);
src = GST_JACK_AUDIO_SRC (GST_OBJECT_PARENT (buf));
channels = buf->spec.channels;
len = sizeof (sample_t) * nframes * channels;
/* get input buffers */
for (i = 0; i < channels; i++)
src->buffers[i] =
(sample_t *) jack_port_get_buffer (src->ports[i], nframes);
if (gst_ring_buffer_prepare_read (buf, &writeseg, &writeptr, &givenLen)) {
/* the samples in the jack input buffers have to be interleaved into the
* ringbuffer
*/
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
* 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);
@ -239,6 +243,14 @@ jack_process_cb (jack_nframes_t nframes, void *arg)
gst_ring_buffer_advance (buf, 1);
}
return 0;
/* ERRORS */
wrong_size:
{
GST_ERROR_OBJECT (src, "nbytes (%d) != flen (%d)",
(gint) (nframes * sizeof (sample_t)), flen);
return 1;
}
}
/* we error out */