diff --git a/rx.c b/rx.c index e9d2e3c..f09bfd9 100644 --- a/rx.c +++ b/rx.c @@ -87,8 +87,12 @@ static int play_one_frame(void *packet, f = snd_pcm_writei(snd, pcm, r); if (f < 0) { - aerror("snd_pcm_writei", f); - return -1; + f = snd_pcm_recover(snd, f, 0); + if (f < 0) { + aerror("snd_pcm_writei", f); + return -1; + } + return 0; } if (f < r) fprintf(stderr, "Short write %ld\n", f); diff --git a/tx.c b/tx.c index f7e9c6e..a6d027c 100644 --- a/tx.c +++ b/tx.c @@ -71,11 +71,22 @@ static int send_one_frame(snd_pcm_t *snd, f = snd_pcm_readi(snd, pcm, samples); if (f < 0) { - aerror("snd_pcm_readi", f); - return -1; + f = snd_pcm_recover(snd, f, 0); + if (f < 0) { + aerror("snd_pcm_readi", f); + return -1; + } + return 0; } - if (f < samples) + + /* Opus encoder requires a complete frame, so if we xrun + * mid-frame then we discard the incomplete audio. The next + * read will catch the error condition and recover */ + + if (f < samples) { fprintf(stderr, "Short read, %ld\n", f); + return 0; + } z = opus_encode_float(encoder, pcm, samples, packet, bytes_per_frame); if (z < 0) {