From 7bb9203f7fec1ad4e40a7ae58d68b604c0a4565e Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 21 Jan 2016 22:24:20 +0100 Subject: player: refactor: eliminate MPContext.d_audio --- player/audio.c | 65 +++++++++++++++++++++++++++++++++++-------------------- player/command.c | 12 +++++----- player/core.h | 5 ++--- player/osd.c | 4 ++-- player/playloop.c | 6 ++--- player/video.c | 2 +- 6 files changed, 57 insertions(+), 37 deletions(-) diff --git a/player/audio.c b/player/audio.c index fb1398c597..5675d66598 100644 --- a/player/audio.c +++ b/player/audio.c @@ -163,15 +163,19 @@ void update_playback_speed(struct MPContext *mpctx) recreate_audio_filters(mpctx); } +static void ao_chain_reset_state(struct ao_chain *ao_c) +{ + ao_c->pts = MP_NOPTS_VALUE; + af_seek_reset(ao_c->af); +} + void reset_audio_state(struct MPContext *mpctx) { - if (mpctx->d_audio) - audio_reset_decoding(mpctx->d_audio); if (mpctx->ao_buffer) mp_audio_buffer_clear(mpctx->ao_buffer); if (mpctx->ao_chain) { - mpctx->ao_chain->pts = MP_NOPTS_VALUE; - af_seek_reset(mpctx->ao_chain->af); + audio_reset_decoding(mpctx->ao_chain->audio_src); + ao_chain_reset_state(mpctx->ao_chain); } mpctx->audio_status = mpctx->ao_chain ? STATUS_SYNCING : STATUS_EOF; mpctx->delay = 0; @@ -195,16 +199,28 @@ void uninit_audio_out(struct MPContext *mpctx) mpctx->ao_decoder_fmt = NULL; } +static void ao_chain_uninit(struct ao_chain *ao_c) +{ + af_destroy(ao_c->af); + talloc_free(ao_c); +} + void uninit_audio_chain(struct MPContext *mpctx) { if (mpctx->ao_chain) { + struct track *track = mpctx->current_track[0][STREAM_AUDIO]; + assert(track); + assert(track->d_audio == mpctx->ao_chain->audio_src); + mixer_uninit_audio(mpctx->mixer); - audio_uninit(mpctx->d_audio); - mpctx->d_audio = NULL; talloc_free(mpctx->ao_buffer); mpctx->ao_buffer = NULL; - af_destroy(mpctx->ao_chain->af); - talloc_free(mpctx->ao_chain); + + audio_uninit(track->d_audio); + track->d_audio = NULL; + mpctx->ao_chain->audio_src = NULL; + + ao_chain_uninit(mpctx->ao_chain); mpctx->ao_chain = NULL; mpctx->audio_status = STATUS_EOF; reselect_demux_streams(mpctx); @@ -227,25 +243,29 @@ void reinit_audio_chain(struct MPContext *mpctx) struct ao_chain *ao_c = mpctx->ao_chain; - if (!mpctx->d_audio) { + if (!ao_c) { assert(!ao_c); - mpctx->d_audio = talloc_zero(NULL, struct dec_audio); - mpctx->d_audio->log = mp_log_new(mpctx->d_audio, mpctx->log, "!ad"); - mpctx->d_audio->global = mpctx->global; - mpctx->d_audio->opts = opts; - mpctx->d_audio->header = sh; ao_c = talloc_zero(NULL, struct ao_chain); mpctx->ao_chain = ao_c; - ao_c->log = mpctx->d_audio->log; + ao_c->log = mpctx->log; ao_c->af = af_new(mpctx->global); ao_c->af->replaygain_data = sh->codec->replaygain_data; ao_c->spdif_passthrough = true; ao_c->pts = MP_NOPTS_VALUE; ao_c->ao = mpctx->ao; - ao_c->audio_src = mpctx->d_audio; - mpctx->d_audio->try_spdif = ao_c->spdif_passthrough; + + struct dec_audio *d_audio = talloc_zero(NULL, struct dec_audio); + d_audio->log = mp_log_new(d_audio, mpctx->log, "!ad"); + d_audio->global = mpctx->global; + d_audio->opts = opts; + d_audio->header = sh; + + track->d_audio = d_audio; + ao_c->audio_src = d_audio; + + d_audio->try_spdif = ao_c->spdif_passthrough; mpctx->ao_buffer = mp_audio_buffer_create(NULL); - if (!audio_init_best_codec(mpctx->d_audio)) + if (!audio_init_best_codec(d_audio)) goto init_error; reset_audio_state(mpctx); @@ -255,7 +275,6 @@ void reinit_audio_chain(struct MPContext *mpctx) mp_audio_buffer_reinit(mpctx->ao_buffer, &fmt); } } - assert(mpctx->d_audio); struct mp_audio in_format = ao_c->input_format; @@ -328,8 +347,8 @@ void reinit_audio_chain(struct MPContext *mpctx) if (spdif_fallback) { ao_c->spdif_passthrough = false; ao_c->spdif_failed = true; - mpctx->d_audio->try_spdif = false; - if (!audio_init_best_codec(mpctx->d_audio)) + ao_c->audio_src->try_spdif = false; + if (!audio_init_best_codec(ao_c->audio_src)) goto init_error; reset_audio_state(mpctx); reinit_audio_chain(mpctx); @@ -612,8 +631,8 @@ void fill_audio_out_buffers(struct MPContext *mpctx, double endpts) struct dec_audio *d_audio = ao_c->audio_src; if (d_audio && ao_c->spdif_failed) { ao_c->spdif_failed = false; - mpctx->d_audio->try_spdif = true; - if (!audio_init_best_codec(mpctx->d_audio)) { + d_audio->try_spdif = true; + if (!audio_init_best_codec(d_audio)) { MP_ERR(mpctx, "Error reinitializing audio.\n"); error_on_track(mpctx, mpctx->current_track[0][STREAM_AUDIO]); return; diff --git a/player/command.c b/player/command.c index 52f0b1830f..5be8c2d120 100644 --- a/player/command.c +++ b/player/command.c @@ -536,7 +536,7 @@ static int mp_property_avsync(void *ctx, struct m_property *prop, int action, void *arg) { MPContext *mpctx = ctx; - if (!mpctx->d_audio || !mpctx->vo_chain) + if (!mpctx->ao_chain || !mpctx->vo_chain) return M_PROPERTY_UNAVAILABLE; if (action == M_PROPERTY_PRINT) { *(char **)arg = talloc_asprintf(NULL, "%7.3f", mpctx->last_av_difference); @@ -549,7 +549,7 @@ static int mp_property_total_avsync_change(void *ctx, struct m_property *prop, int action, void *arg) { MPContext *mpctx = ctx; - if (!mpctx->d_audio || !mpctx->vo_chain) + if (!mpctx->ao_chain || !mpctx->vo_chain) return M_PROPERTY_UNAVAILABLE; if (mpctx->total_avsync_change == MP_NOPTS_VALUE) return M_PROPERTY_UNAVAILABLE; @@ -1696,7 +1696,7 @@ static int mp_property_audio_delay(void *ctx, struct m_property *prop, int action, void *arg) { MPContext *mpctx = ctx; - if (!(mpctx->d_audio && mpctx->vo_chain)) + if (!(mpctx->ao_chain && mpctx->vo_chain)) return M_PROPERTY_UNAVAILABLE; float delay = mpctx->opts->audio_delay; switch (action) { @@ -1716,7 +1716,8 @@ static int mp_property_audio_codec_name(void *ctx, struct m_property *prop, int action, void *arg) { MPContext *mpctx = ctx; - const char *c = mpctx->d_audio ? mpctx->d_audio->header->codec->codec : NULL; + struct track *track = mpctx->current_track[0][STREAM_AUDIO]; + const char *c = track && track->stream ? track->stream->codec->codec : NULL; return m_property_strdup_ro(action, arg, c); } @@ -1725,7 +1726,8 @@ static int mp_property_audio_codec(void *ctx, struct m_property *prop, int action, void *arg) { MPContext *mpctx = ctx; - const char *c = mpctx->d_audio ? mpctx->d_audio->decoder_desc : NULL; + struct track *track = mpctx->current_track[0][STREAM_AUDIO]; + const char *c = track && track->d_audio ? track->d_audio->decoder_desc : NULL; return m_property_strdup_ro(action, arg, c); } diff --git a/player/core.h b/player/core.h index 00d1c81460..dc6c1f3e2b 100644 --- a/player/core.h +++ b/player/core.h @@ -145,8 +145,9 @@ struct track { // Current subtitle state (or cached state if selected==false). struct dec_sub *d_sub; - // Current video decoding state (NULL if selected==false) + // Current decoding state (NULL if selected==false) struct dec_video *d_video; + struct dec_audio *d_audio; // For external subtitles, which are read fully on init. Do not attempt // to read packets from them. @@ -287,8 +288,6 @@ typedef struct MPContext { // Currently, this is used for the secondary subtitle track only. struct track *current_track[NUM_PTRACKS][STREAM_TYPE_COUNT]; - struct dec_audio *d_audio; - // Uses: accessing metadata (consider ordered chapters case, where the main // demuxer defines metadata), or special purpose demuxers like TV. struct demuxer *master_demuxer; diff --git a/player/osd.c b/player/osd.c index 9ee7ea7576..45db9b2c77 100644 --- a/player/osd.c +++ b/player/osd.c @@ -195,7 +195,7 @@ static void print_status(struct MPContext *mpctx) saddf(&line, "(Paused) "); } - if (mpctx->d_audio) + if (mpctx->ao_chain) saddf(&line, "A"); if (mpctx->vo_chain) saddf(&line, "V"); @@ -217,7 +217,7 @@ static void print_status(struct MPContext *mpctx) saddf(&line, " x%4.2f", opts->playback_speed); // A-V sync - if (mpctx->d_audio && mpctx->vo_chain && mpctx->sync_audio_to_video) { + if (mpctx->ao_chain && mpctx->vo_chain && mpctx->sync_audio_to_video) { saddf(&line, " A-V:%7.3f", mpctx->last_av_difference); if (fabs(mpctx->total_avsync_change) > 0.05) saddf(&line, " ct:%7.3f", mpctx->total_avsync_change); diff --git a/player/playloop.c b/player/playloop.c index 761fb21c11..6f4521b32a 100644 --- a/player/playloop.c +++ b/player/playloop.c @@ -97,7 +97,7 @@ void pause_player(struct MPContext *mpctx) mpctx->osd_force_update = true; mpctx->paused_for_cache = false; - if (mpctx->ao && mpctx->d_audio) + if (mpctx->ao && mpctx->ao_chain) ao_pause(mpctx->ao); if (mpctx->video_out) vo_set_paused(mpctx->video_out, true); @@ -122,7 +122,7 @@ void unpause_player(struct MPContext *mpctx) mpctx->osd_function = 0; mpctx->osd_force_update = true; - if (mpctx->ao && mpctx->d_audio) + if (mpctx->ao && mpctx->ao_chain) ao_resume(mpctx->ao); if (mpctx->video_out) vo_set_paused(mpctx->video_out, false); @@ -905,7 +905,7 @@ static void handle_segment_switch(struct MPContext *mpctx, bool end_is_new_segme * and video streams to "disabled" at runtime. Handle this by waiting * rather than immediately stopping playback due to EOF. */ - if ((mpctx->d_audio || mpctx->vo_chain) && !prevent_eof && + if ((mpctx->ao_chain || mpctx->vo_chain) && !prevent_eof && mpctx->audio_status == STATUS_EOF && mpctx->video_status == STATUS_EOF) { diff --git a/player/video.c b/player/video.c index 18a7ef53ec..8b766eac47 100644 --- a/player/video.c +++ b/player/video.c @@ -377,7 +377,7 @@ int reinit_video_chain(struct MPContext *mpctx) mpctx->sync_audio_to_video = !sh->attached_picture; // If we switch on video again, ensure audio position matches up. - if (mpctx->d_audio) + if (mpctx->ao_chain) mpctx->audio_status = STATUS_SYNCING; reset_video_state(mpctx); -- cgit v1.2.3