summaryrefslogtreecommitdiffstats
path: root/audio/out/pull.c
diff options
context:
space:
mode:
Diffstat (limited to 'audio/out/pull.c')
-rw-r--r--audio/out/pull.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/audio/out/pull.c b/audio/out/pull.c
index 985d6d9f67..a3d4b024b1 100644
--- a/audio/out/pull.c
+++ b/audio/out/pull.c
@@ -83,9 +83,23 @@ static void set_state(struct ao *ao, int new_state)
}
}
+static void report_underruns(struct ao *ao)
+{
+ struct ao_pull_state *p = ao->api_priv;
+
+ int underflow = atomic_fetch_and(&p->underflow, 0);
+ if (underflow) {
+ if (ao_underrun_event(ao))
+ MP_VERBOSE(ao, "Audio underrun by %d samples.\n", underflow);
+ }
+}
+
static int get_space(struct ao *ao)
{
struct ao_pull_state *p = ao->api_priv;
+
+ report_underruns(ao);
+
// Since the reader will read the last plane last, its free space is the
// minimum free space across all planes.
return mp_ring_available(p->buffers[ao->num_planes - 1]) / ao->sstride;
@@ -119,9 +133,7 @@ static int play(struct ao *ao, void **data, int samples, int flags)
bool draining = write_samples == samples && (flags & AOPLAY_FINAL_CHUNK);
atomic_store(&p->draining, draining);
- int underflow = atomic_fetch_and(&p->underflow, 0);
- if (underflow)
- MP_WARN(ao, "Audio underflow by %d samples.\n", underflow);
+ report_underruns(ao);
return write_samples;
}
@@ -153,13 +165,8 @@ 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)) {
- if (ao->driver->reports_underruns) {
- ao_underrun_event(ao);
- } else {
- atomic_fetch_add(&p->underflow, (full_bytes - bytes) / ao->sstride);
- }
- }
+ if (full_bytes > bytes && !atomic_load(&p->draining))
+ atomic_fetch_add(&p->underflow, (full_bytes - bytes) / ao->sstride);
if (bytes > 0)
atomic_store(&p->end_time_us, out_time_us);