aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordvdli <dvdli@google.com>2021-05-19 15:33:41 +0800
committerdvdli <dvdli@google.com>2021-05-19 15:33:41 +0800
commit9b3b4f358a8c613439d391ab416ad137bc482ff4 (patch)
tree818bffa626ee9d42f0932b3bfc2b936775ec6ad2
parent515be35688a76edee90b892150ea22fa9516638c (diff)
add pcm_prepare before pcm_start
-rw-r--r--src/pcm.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/pcm.c b/src/pcm.c
index 63ca65f..a97d325 100644
--- a/src/pcm.c
+++ b/src/pcm.c
@@ -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.