alsa: Don't ever block in CaptureFromDevice.

This commit is contained in:
Ryan C. Gordon
2023-07-04 19:27:10 -04:00
parent 65d296ef1a
commit 3482d1215a

View File

@@ -405,7 +405,6 @@ static int ALSA_CaptureFromDevice(SDL_AudioDevice *device, void *buffer, int buf
device->spec.channels; device->spec.channels;
const int total_frames = buflen / frame_size; const int total_frames = buflen / frame_size;
snd_pcm_uframes_t frames_left = total_frames; snd_pcm_uframes_t frames_left = total_frames;
snd_pcm_uframes_t wait_time = frame_size / 2;
SDL_assert((buflen % frame_size) == 0); SDL_assert((buflen % frame_size) == 0);
@@ -414,8 +413,7 @@ static int ALSA_CaptureFromDevice(SDL_AudioDevice *device, void *buffer, int buf
sample_buf, frames_left); sample_buf, frames_left);
if (status == -EAGAIN) { if (status == -EAGAIN) {
ALSA_snd_pcm_wait(device->hidden->pcm_handle, wait_time); break; // Can this even happen? Go back to WaitCaptureDevice, where the device lock isn't held.
status = 0;
} else if (status < 0) { } else if (status < 0) {
/*printf("ALSA: capture error %d\n", status);*/ /*printf("ALSA: capture error %d\n", status);*/
status = ALSA_snd_pcm_recover(device->hidden->pcm_handle, status, 0); status = ALSA_snd_pcm_recover(device->hidden->pcm_handle, status, 0);
@@ -426,7 +424,7 @@ static int ALSA_CaptureFromDevice(SDL_AudioDevice *device, void *buffer, int buf
ALSA_snd_strerror(status)); ALSA_snd_strerror(status));
return -1; return -1;
} }
continue; break; // Go back to WaitCaptureDevice, where the device lock isn't held.
} }
/*printf("ALSA: captured %d bytes\n", status * frame_size);*/ /*printf("ALSA: captured %d bytes\n", status * frame_size);*/