diff options
author | dvdli <dvdli@google.com> | 2021-05-19 15:33:41 +0800 |
---|---|---|
committer | dvdli <dvdli@google.com> | 2021-05-19 15:33:41 +0800 |
commit | 9b3b4f358a8c613439d391ab416ad137bc482ff4 (patch) | |
tree | 818bffa626ee9d42f0932b3bfc2b936775ec6ad2 /src | |
parent | 515be35688a76edee90b892150ea22fa9516638c (diff) |
add pcm_prepare before pcm_start
Diffstat (limited to 'src')
-rw-r--r-- | src/pcm.c | 24 |
1 files changed, 14 insertions, 10 deletions
@@ -623,6 +623,16 @@ static int pcm_sync_ptr(struct pcm *pcm, int flags) return 0; } +int pcm_state(struct pcm *pcm) +{ + // Update the state only. Do not sync HW sync. + int err = pcm_sync_ptr(pcm, SNDRV_PCM_SYNC_PTR_APPL | SNDRV_PCM_SYNC_PTR_AVAIL_MIN); + if (err < 0) + return err; + + return pcm->mmap_status->state; +} + static int pcm_hw_mmap_status(struct pcm *pcm) { if (pcm->sync_ptr) @@ -1196,6 +1206,10 @@ int pcm_prepare(struct pcm *pcm) */ int pcm_start(struct pcm *pcm) { + if (pcm_state(pcm) == PCM_STATE_SETUP && pcm_prepare(pcm) != 0) { + return -1; + } + /* set appl_ptr and avail_min in kernel */ if (pcm_sync_ptr(pcm, 0) < 0) return -1; @@ -1409,16 +1423,6 @@ again: return 0; } -int pcm_state(struct pcm *pcm) -{ - // Update the state only. Do not sync HW sync. - int err = pcm_sync_ptr(pcm, SNDRV_PCM_SYNC_PTR_APPL | SNDRV_PCM_SYNC_PTR_AVAIL_MIN); - if (err < 0) - return err; - - return pcm->mmap_status->state; -} - /** Waits for frames to be available for read or write operations. * @param pcm A PCM handle. * @param timeout The maximum amount of time to wait for, in terms of milliseconds. |