Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed alsa dev read pcm bug #4206

Closed
wants to merge 1 commit into from
Closed

Conversation

freeforf
Copy link

@freeforf freeforf commented Dec 9, 2024

remove sound card device when capture audio data, the alsa audio cache may less than nframes, snd_pcm_readi wait for audio data forever.so when close the audio device ,the ca_thread_func can`t quite.use snd_pcm_avail to make sure audio cache has enough audio data.


snd_pcm_uframes_t avail;
avail = snd_pcm_avail(pcm);
if (avail > 0 && avail <= nframes) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be >=0 and < nframes? We shouldn't need to sleep and continue when we already have nframes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when snd_pcm_prepare called,the snd_pcm_state is SND_PCM_STATE_PREPARED,snd_pcm_avail will return 0 always,need call snd_pcm_readi or snd_pcm_stop to change state to SND_PCM_STATE_RUNNING. i will update code with snd_pcm_state check later.

@trengginas
Copy link
Member

I tried to reproduce it here using a USB/removable sound card during a call/sound card is used, however it doesn't block instead printing this on the log:

ca_thread_func: error reading data!

Any specific scenario to trigger this issue?

@freeforf
Copy link
Author

set playback device plughw:usb sound card,and set capture device default.

@trengginas
Copy link
Member

set playback device plughw:usb sound card,and set capture device default.

Still couldn't reproduce it. Based on the doc the routine waits until all requested frames are filled. In my case, if the sound card is removed, it will return immediately and return error.

@freeforf
Copy link
Author

i insert two same usb soundcard,if it doesn't work too,maybe my soundcard bugs.

@sauwming
Copy link
Member

Perhaps you can consider submitting your issue to https://github.com/alsa-project/alsa-lib/issues (https://www.alsa-project.org/wiki/Bug_Tracking).

@freeforf freeforf closed this Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants