diff options
author | Ricardo Biehl Pasquali <pasqualirb@gmail.com> | 2019-03-12 16:31:04 -0300 |
---|---|---|
committer | Ricardo Biehl Pasquali <pasqualirb@gmail.com> | 2019-04-24 10:57:57 -0300 |
commit | c6c0d788a835277b190d267fa4d6b338e4bba30e (patch) | |
tree | 1e999eb3ceca6d111dd431f236074030d710381d | |
parent | 1d2302a566935bf213f4f110a7f98c8f8a655d07 (diff) |
pcm: Allow to wait if capture is not running
This allows starting capture from another thread.
See the commit 932a81519572 ("ALSA: pcm: Comment why read
blocks when PCM is not running") in Linux kernel.
Signed-off-by: Ricardo Biehl Pasquali <pasqualirb@gmail.com>
-rw-r--r-- | src/pcm.c | 21 |
1 files changed, 10 insertions, 11 deletions
@@ -1282,17 +1282,16 @@ int pcm_mmap_transfer(struct pcm *pcm, void *buffer, unsigned int frames) return -1; state = pcm->mmap_status->state; - /* start capture if frames >= threshold */ - if (!is_playback && state == PCM_STATE_PREPARED) { - if (frames >= pcm->config.start_threshold) { - err = ioctl(pcm->fd, SNDRV_PCM_IOCTL_START); - if (err == -1) - return -1; - /* state = PCM_STATE_RUNNING */ - } else { - /* nothing to do */ - return 0; - } + /* + * If frames < start_threshold, wait indefinitely. + * Another thread may start capture + */ + if (!is_playback && state == PCM_STATE_PREPARED && + frames >= pcm->config.start_threshold) { + err = ioctl(pcm->fd, SNDRV_PCM_IOCTL_START); + if (err == -1) + return -1; + /* state = PCM_STATE_RUNNING */ } avail = pcm_mmap_avail(pcm); |