Improve ALSA underrun error recovery

Fixes lack of audio on Vero 4K
This commit is contained in:
Cameron Gutman 2022-10-31 22:19:34 -05:00
parent 58958ca32a
commit cb4b5d55b5

View File

@ -115,14 +115,17 @@ static void alsa_renderer_decode_and_play_sample(char* data, int length) {
int decodeLen = opus_multistream_decode(decoder, data, length, pcmBuffer, samplesPerFrame, 0); int decodeLen = opus_multistream_decode(decoder, data, length, pcmBuffer, samplesPerFrame, 0);
if (decodeLen > 0) { if (decodeLen > 0) {
int rc = snd_pcm_writei(handle, pcmBuffer, decodeLen); int rc = snd_pcm_writei(handle, pcmBuffer, decodeLen);
if (rc == -EPIPE) if (rc < 0) {
snd_pcm_recover(handle, rc, 1); rc = snd_pcm_recover(handle, rc, 0);
if (rc == 0)
rc = snd_pcm_writei(handle, pcmBuffer, decodeLen);
}
if (rc<0) if (rc<0)
printf("Alsa error from writei: %d\n", rc); printf("Alsa error from writei: %d\n", rc);
else if (decodeLen != rc) else if (decodeLen != rc)
printf("Alsa shortm write, write %d frames\n", rc); printf("Alsa shortm write, write %d frames\n", rc);
} else { } else if (decodeLen < 0) {
printf("Opus error from decode: %d\n", decodeLen); printf("Opus error from decode: %d\n", decodeLen);
} }
} }