audio/out: prevent underruns with spdif under certain conditions

The player tries to avoid splitting frames with spdif (sample alignment
stuff). This can in certain corner cases with certain drivers lead to
the situation that ao_get_space() returns a number higher than 0 and
lower than the audio frame size. The playloop will round this down to 0
bytes and do nothing, leading to a missed wakeup. This can lead to
underruns or playback completely getting stuck.

It can be reproduced by playing AC3 passthrough with no video and:

    --ao=null --ao-null-buffer=0.256 --ao-null-outburst=6100

This commit attempts to fix it by allowing the playloop to write some
additional data (to get a complete frame), that will be buffered within
the AO ringbuffer even if the audio device doesn't want it.
This commit is contained in:
wm4 2016-10-04 19:31:17 +02:00
parent 13dcf82a96
commit 39f515cb6a
1 changed files with 2 additions and 0 deletions

View File

@ -182,6 +182,7 @@ static int unlocked_get_space(struct ao *ao)
struct ao_push_state *p = ao->api_priv;
int space = mp_audio_buffer_get_write_available(p->buffer);
if (ao->driver->get_space) {
int align = af_format_sample_alignment(ao->format);
// The following code attempts to keep the total buffered audio to
// ao->buffer in order to improve latency.
int device_space = ao->driver->get_space(ao);
@ -191,6 +192,7 @@ static int unlocked_get_space(struct ao *ao)
// byte based and doesn't do proper chunked processing.
int min_buffer = ao->buffer + 64;
int missing = min_buffer - device_buffered - soft_buffered;
missing = (missing + align - 1) / align * align;
// But always keep the device's buffer filled as much as we can.
int device_missing = device_space - soft_buffered;
missing = MPMAX(missing, device_missing);