From d908fbd5849159509300447e6baa09c58d199169 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 11 Oct 2019 20:01:23 +0200 Subject: audio/out/pull, ao_sdl: implement new underrun reporting See previous commits. ao_sdl is worthless, but it might be a good test for pull-based AOs. This stops using the old underrun reporting if the new one is enabled. Also, since the AO's behavior can in theory not be according to expectations, this needs to be enabled for every single pull AO separately. For some reason, in certain cases I get multiple underrun warnings while cache-pausing is active. It fills the cache, restarts the AO, immediately underruns again, and then fills the cache again. I'm not sure why this happens; maybe ao_sdl tries to catch up when it shouldn't. Who knows. --- audio/out/ao_sdl.c | 1 + audio/out/pull.c | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/audio/out/ao_sdl.c b/audio/out/ao_sdl.c index 6144918dfe..1390eb64d0 100644 --- a/audio/out/ao_sdl.c +++ b/audio/out/ao_sdl.c @@ -205,6 +205,7 @@ const struct ao_driver audio_out_sdl = { .uninit = uninit, .reset = reset, .resume = resume, + .reports_underruns = true, .priv_size = sizeof(struct priv), .priv_defaults = &(const struct priv) { .buflen = 0, // use SDL default diff --git a/audio/out/pull.c b/audio/out/pull.c index c6125bd8bc..985d6d9f67 100644 --- a/audio/out/pull.c +++ b/audio/out/pull.c @@ -153,8 +153,13 @@ int ao_read_data(struct ao *ao, void **data, int samples, int64_t out_time_us) int buffered_bytes = mp_ring_buffered(p->buffers[0]); bytes = MPMIN(buffered_bytes, full_bytes); - if (full_bytes > bytes && !atomic_load(&p->draining)) - atomic_fetch_add(&p->underflow, (full_bytes - bytes) / ao->sstride); + if (full_bytes > bytes && !atomic_load(&p->draining)) { + if (ao->driver->reports_underruns) { + ao_underrun_event(ao); + } else { + atomic_fetch_add(&p->underflow, (full_bytes - bytes) / ao->sstride); + } + } if (bytes > 0) atomic_store(&p->end_time_us, out_time_us); -- cgit v1.2.3