summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-10-11 20:01:23 +0200
committerwm4 <wm4@nowhere>2019-10-11 20:02:23 +0200
commitd908fbd5849159509300447e6baa09c58d199169 (patch)
tree24771aeac924516ff2138897df8d5b346d79b064
parent89c717559b4b162fecc581190774907922609e91 (diff)
downloadmpv-d908fbd5849159509300447e6baa09c58d199169.tar.bz2
mpv-d908fbd5849159509300447e6baa09c58d199169.tar.xz
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.
-rw-r--r--audio/out/ao_sdl.c1
-rw-r--r--audio/out/pull.c9
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);