From 6c329bb505e05a28e85edda713d20a58ea50008b Mon Sep 17 00:00:00 2001 From: freeforf Date: Tue, 10 Dec 2024 19:03:50 +0800 Subject: [PATCH] Fixed alsa dev read pcm bug --- pjmedia/src/pjmedia-audiodev/alsa_dev.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pjmedia/src/pjmedia-audiodev/alsa_dev.c b/pjmedia/src/pjmedia-audiodev/alsa_dev.c index fd868bd06e..467390063e 100755 --- a/pjmedia/src/pjmedia-audiodev/alsa_dev.c +++ b/pjmedia/src/pjmedia-audiodev/alsa_dev.c @@ -610,7 +610,20 @@ static int ca_thread_func (void *arg) while (!stream->quit) { pjmedia_frame frame; - + + snd_pcm_state_t state; + state = snd_pcm_state(pcm); + if (state == SND_PCM_STATE_PREPARED) { + snd_pcm_start(pcm); + contine; + } else if (state == SND_PCM_STATE_RUNNING) { + snd_pcm_uframes_t avail; + avail = snd_pcm_avail(pcm); + if (avail >= 0 && avail < nframes) { + pj_thread_sleep(5); + continue; + } + } pj_bzero (buf, size); result = snd_pcm_readi (pcm, buf, nframes); if (result == -EPIPE) {