]> git.alsa-project.org Git - alsa-plugins.git/commitdiff
jack: Write only valid values to the internal hw_ptr
authorTimo Wischer <twischer@de.adit-jv.com>
Mon, 22 Jan 2018 08:37:20 +0000 (09:37 +0100)
committerJaroslav Kysela <perex@perex.cz>
Thu, 8 Feb 2018 10:53:08 +0000 (11:53 +0100)
Otherwise the ALSA thread could for example read a hw_ptr >
buffer_size

Signed-off-by: Timo Wischer <twischer@de.adit-jv.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
jack/pcm_jack.c

index 4468edeadf86d5635d5900027d89030ec4ff62a6..3aed3327d2120f76536b070c3b7138f73d3e80a7 100644 (file)
@@ -137,6 +137,7 @@ static int
 snd_pcm_jack_process_cb(jack_nframes_t nframes, snd_pcm_ioplug_t *io)
 {
        snd_pcm_jack_t *jack = io->private_data;
+       snd_pcm_uframes_t hw_ptr;
        const snd_pcm_channel_area_t *areas;
        snd_pcm_uframes_t xfer = 0;
        unsigned int channel;
@@ -155,12 +156,13 @@ snd_pcm_jack_process_cb(jack_nframes_t nframes, snd_pcm_ioplug_t *io)
                        return 0;
                }
        }
-       
+
+       hw_ptr = jack->hw_ptr;
        areas = snd_pcm_ioplug_mmap_areas(io);
 
        while (xfer < nframes) {
                snd_pcm_uframes_t frames = nframes - xfer;
-               snd_pcm_uframes_t offset = jack->hw_ptr;
+               snd_pcm_uframes_t offset = hw_ptr;
                snd_pcm_uframes_t cont = io->buffer_size - offset;
 
                if (cont < frames)
@@ -173,10 +175,11 @@ snd_pcm_jack_process_cb(jack_nframes_t nframes, snd_pcm_ioplug_t *io)
                                snd_pcm_area_copy(&areas[channel], offset, &jack->areas[channel], xfer, frames, io->format);
                }
                
-               jack->hw_ptr += frames;
-               jack->hw_ptr %= io->buffer_size;
+               hw_ptr += frames;
+               hw_ptr %= io->buffer_size;
                xfer += frames;
        }
+       jack->hw_ptr = hw_ptr;
 
        pcm_poll_unblock_check(io); /* unblock socket for polling if needed */