diff options
author | dvdli <70133153+dvdli@users.noreply.github.com> | 2021-05-26 11:38:14 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-26 11:38:14 +0800 |
commit | 36f9078ef5410279725207daa00943ee48b05253 (patch) | |
tree | 20bc341530645b33a4be04b9605dcabc585d19de /src/pcm.c | |
parent | 515be35688a76edee90b892150ea22fa9516638c (diff) | |
parent | 08ec631e68327cb5195a10f3b8ba32a2cc22ff5e (diff) |
Merge pull request #206 from dvdli/tinyalsa-fix-pcm
Fix compatible issue and refine null parameters checking
Diffstat (limited to 'src/pcm.c')
-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. |