1
0
mirror of http://www.pogo.org.uk/~mark/trx.git synced 2024-11-24 03:15:05 +01:00

Non-fatal handling of xruns

This commit is contained in:
Mark Hills 2014-03-23 14:49:21 -04:00
parent 591a498725
commit 374308b810
2 changed files with 20 additions and 5 deletions

4
rx.c
View File

@ -86,10 +86,14 @@ static int play_one_frame(void *packet,
} }
f = snd_pcm_writei(snd, pcm, r); f = snd_pcm_writei(snd, pcm, r);
if (f < 0) {
f = snd_pcm_recover(snd, f, 0);
if (f < 0) { if (f < 0) {
aerror("snd_pcm_writei", f); aerror("snd_pcm_writei", f);
return -1; return -1;
} }
return 0;
}
if (f < r) if (f < r)
fprintf(stderr, "Short write %ld\n", f); fprintf(stderr, "Short write %ld\n", f);

13
tx.c
View File

@ -70,12 +70,23 @@ static int send_one_frame(snd_pcm_t *snd,
packet = alloca(bytes_per_frame); packet = alloca(bytes_per_frame);
f = snd_pcm_readi(snd, pcm, samples); f = snd_pcm_readi(snd, pcm, samples);
if (f < 0) {
f = snd_pcm_recover(snd, f, 0);
if (f < 0) { if (f < 0) {
aerror("snd_pcm_readi", f); aerror("snd_pcm_readi", f);
return -1; return -1;
} }
if (f < samples) return 0;
}
/* 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); fprintf(stderr, "Short read, %ld\n", f);
return 0;
}
z = opus_encode_float(encoder, pcm, samples, packet, bytes_per_frame); z = opus_encode_float(encoder, pcm, samples, packet, bytes_per_frame);
if (z < 0) { if (z < 0) {