diff options
author | wm4 <wm4@nowhere> | 2020-06-02 20:30:59 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2020-06-02 20:43:49 +0200 |
commit | 08b198aab49f73829bb02a25bc46bd159b6f9c6e (patch) | |
tree | 7b59350dd20518867f2a4e3c0a826bd25f96b203 /audio/out/buffer.c | |
parent | 0d3474c6c0d3bea20bfd50614ffaa3b21d4538cf (diff) | |
download | mpv-08b198aab49f73829bb02a25bc46bd159b6f9c6e.tar.bz2 mpv-08b198aab49f73829bb02a25bc46bd159b6f9c6e.tar.xz |
audio: further simplify internal audio API somewhat
Instead of the relatively subtle underflow handling, simply signal
whether the stream is in a playing state. Should make it more robust.
Should affect ao_alsa and ao_pulse only (and ao_openal, but it's
broken).
For ao_pulse, I'm just guessing. How the hell do you query whether a
stream is playing? Who knows. Seems to work, judging from very
superficial testing.
Diffstat (limited to 'audio/out/buffer.c')
-rw-r--r-- | audio/out/buffer.c | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/audio/out/buffer.c b/audio/out/buffer.c index 0a13089de9..da0d69f0de 100644 --- a/audio/out/buffer.c +++ b/audio/out/buffer.c @@ -71,7 +71,6 @@ struct buffer_state { bool hw_paused; // driver->set_pause() was used successfully bool recover_pause; // non-hw_paused: needs to recover delay bool draining; - bool had_underrun; bool ao_wait_low_buffer; struct mp_pcm_state prepause_state; pthread_t thread; // thread shoveling data to AO @@ -108,20 +107,8 @@ static void get_dev_state(struct ao *ao, struct mp_pcm_state *state) .free_samples = -1, .queued_samples = -1, .delay = -1, - .underrun = false, }; ao->driver->get_state(ao, state); - - if (state->underrun) { - p->had_underrun = true; - if (p->draining) { - MP_VERBOSE(ao, "underrun signaled for audio end\n"); - p->still_playing = false; - pthread_cond_broadcast(&p->wakeup); - } else { - ao_add_events(ao, AO_EVENT_UNDERRUN); - } - } } static int unlocked_get_space(struct ao *ao) @@ -455,7 +442,7 @@ void ao_drain(struct ao *ao) pthread_mutex_lock(&p->lock); p->final_chunk = true; - while (!p->paused && p->still_playing && !p->had_underrun) { + while (!p->paused && p->still_playing && p->streaming) { if (ao->driver->write) { if (p->draining) { // Wait for EOF signal from AO. @@ -586,16 +573,21 @@ static bool realloc_buf(struct ao *ao, int samples) static void ao_play_data(struct ao *ao) { struct buffer_state *p = ao->buffer_state; + struct mp_pcm_state state; + get_dev_state(ao, &state); + + if (p->streaming && !state.playing && !ao->untimed) { + if (p->draining) { + MP_VERBOSE(ao, "underrun signaled for audio end\n"); + p->still_playing = false; + pthread_cond_broadcast(&p->wakeup); + } else { + ao_add_events(ao, AO_EVENT_UNDERRUN); + } - if (p->had_underrun) { - MP_VERBOSE(ao, "recover underrun\n"); - ao->driver->reset(ao); p->streaming = false; - p->had_underrun = false; } - struct mp_pcm_state state; - get_dev_state(ao, &state); // Round free space to period sizes to reduce number of write() calls. int space = state.free_samples / ao->period_size * ao->period_size; bool play_silence = p->paused || (ao->stream_silence && !p->still_playing); |