From 6fb12a5fdaf95bf5ded286c8db18a30e392964e1 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 5 Oct 2016 16:42:43 +0200 Subject: audio: move some fallback handling to common AO reload function Now a reload requested by an AO behaves in exactly the same way as changing an AO-related options (like --audio-channels or --audio-exclusive). This is good for testing and uniform behavior. (You could go as far as saying it's a necessity, because the spotty and obscure AO reload behavior is hard to reproduce and thus hard to test at all.) --- player/audio.c | 52 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 19 deletions(-) (limited to 'player/audio.c') diff --git a/player/audio.c b/player/audio.c index 29ad44e5ed..3f173f140d 100644 --- a/player/audio.c +++ b/player/audio.c @@ -861,33 +861,47 @@ static int filter_audio(struct MPContext *mpctx, struct mp_audio_buffer *outbuf, return res; } +void reload_audio_output(struct MPContext *mpctx) +{ + if (!mpctx->ao) + return; + + ao_reset(mpctx->ao); + uninit_audio_out(mpctx); + reinit_audio_filters(mpctx); // mostly to issue refresh seek + + // Whether we can use spdif might have changed. If we failed to use spdif + // in the previous initialization, try it with spdif again (we'll fallback + // to PCM again if necessary). + struct ao_chain *ao_c = mpctx->ao_chain; + if (ao_c) { + struct dec_audio *d_audio = ao_c->audio_src; + if (d_audio && ao_c->spdif_failed) { + ao_c->spdif_passthrough = true; + ao_c->spdif_failed = false; + d_audio->try_spdif = true; + ao_c->af->initialized = 0; + if (!audio_init_best_codec(d_audio)) { + MP_ERR(mpctx, "Error reinitializing audio.\n"); + error_on_track(mpctx, ao_c->track); + } + } + } + + mp_wakeup_core(mpctx); +} + void fill_audio_out_buffers(struct MPContext *mpctx) { struct MPOpts *opts = mpctx->opts; - struct ao_chain *ao_c = mpctx->ao_chain; bool was_eof = mpctx->audio_status == STATUS_EOF; dump_audio_stats(mpctx); - if (mpctx->ao && ao_query_and_reset_events(mpctx->ao, AO_EVENT_RELOAD)) { - ao_reset(mpctx->ao); - uninit_audio_out(mpctx); - if (ao_c) { - struct dec_audio *d_audio = ao_c->audio_src; - if (d_audio && ao_c->spdif_failed) { - ao_c->spdif_failed = false; - d_audio->try_spdif = true; - if (!audio_init_best_codec(d_audio)) { - MP_ERR(mpctx, "Error reinitializing audio.\n"); - error_on_track(mpctx, ao_c->track); - return; - } - } - reinit_audio_filters_and_output(mpctx); - ao_c = mpctx->ao_chain; - } - } + if (mpctx->ao && ao_query_and_reset_events(mpctx->ao, AO_EVENT_RELOAD)) + reload_audio_output(mpctx); + struct ao_chain *ao_c = mpctx->ao_chain; if (!ao_c) return; -- cgit v1.2.3