mirror of
https://github.com/mpv-player/mpv
synced 2025-03-11 08:37:59 +00:00
player: refactor: eliminate MPContext.d_audio
This commit is contained in:
parent
fef8b7984b
commit
7bb9203f7f
@ -163,15 +163,19 @@ void update_playback_speed(struct MPContext *mpctx)
|
|||||||
recreate_audio_filters(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)
|
void reset_audio_state(struct MPContext *mpctx)
|
||||||
{
|
{
|
||||||
if (mpctx->d_audio)
|
|
||||||
audio_reset_decoding(mpctx->d_audio);
|
|
||||||
if (mpctx->ao_buffer)
|
if (mpctx->ao_buffer)
|
||||||
mp_audio_buffer_clear(mpctx->ao_buffer);
|
mp_audio_buffer_clear(mpctx->ao_buffer);
|
||||||
if (mpctx->ao_chain) {
|
if (mpctx->ao_chain) {
|
||||||
mpctx->ao_chain->pts = MP_NOPTS_VALUE;
|
audio_reset_decoding(mpctx->ao_chain->audio_src);
|
||||||
af_seek_reset(mpctx->ao_chain->af);
|
ao_chain_reset_state(mpctx->ao_chain);
|
||||||
}
|
}
|
||||||
mpctx->audio_status = mpctx->ao_chain ? STATUS_SYNCING : STATUS_EOF;
|
mpctx->audio_status = mpctx->ao_chain ? STATUS_SYNCING : STATUS_EOF;
|
||||||
mpctx->delay = 0;
|
mpctx->delay = 0;
|
||||||
@ -195,16 +199,28 @@ void uninit_audio_out(struct MPContext *mpctx)
|
|||||||
mpctx->ao_decoder_fmt = NULL;
|
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)
|
void uninit_audio_chain(struct MPContext *mpctx)
|
||||||
{
|
{
|
||||||
if (mpctx->ao_chain) {
|
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);
|
mixer_uninit_audio(mpctx->mixer);
|
||||||
audio_uninit(mpctx->d_audio);
|
|
||||||
mpctx->d_audio = NULL;
|
|
||||||
talloc_free(mpctx->ao_buffer);
|
talloc_free(mpctx->ao_buffer);
|
||||||
mpctx->ao_buffer = NULL;
|
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->ao_chain = NULL;
|
||||||
mpctx->audio_status = STATUS_EOF;
|
mpctx->audio_status = STATUS_EOF;
|
||||||
reselect_demux_streams(mpctx);
|
reselect_demux_streams(mpctx);
|
||||||
@ -227,25 +243,29 @@ void reinit_audio_chain(struct MPContext *mpctx)
|
|||||||
|
|
||||||
struct ao_chain *ao_c = mpctx->ao_chain;
|
struct ao_chain *ao_c = mpctx->ao_chain;
|
||||||
|
|
||||||
if (!mpctx->d_audio) {
|
if (!ao_c) {
|
||||||
assert(!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);
|
ao_c = talloc_zero(NULL, struct ao_chain);
|
||||||
mpctx->ao_chain = ao_c;
|
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 = af_new(mpctx->global);
|
||||||
ao_c->af->replaygain_data = sh->codec->replaygain_data;
|
ao_c->af->replaygain_data = sh->codec->replaygain_data;
|
||||||
ao_c->spdif_passthrough = true;
|
ao_c->spdif_passthrough = true;
|
||||||
ao_c->pts = MP_NOPTS_VALUE;
|
ao_c->pts = MP_NOPTS_VALUE;
|
||||||
ao_c->ao = mpctx->ao;
|
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);
|
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;
|
goto init_error;
|
||||||
reset_audio_state(mpctx);
|
reset_audio_state(mpctx);
|
||||||
|
|
||||||
@ -255,7 +275,6 @@ void reinit_audio_chain(struct MPContext *mpctx)
|
|||||||
mp_audio_buffer_reinit(mpctx->ao_buffer, &fmt);
|
mp_audio_buffer_reinit(mpctx->ao_buffer, &fmt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert(mpctx->d_audio);
|
|
||||||
|
|
||||||
struct mp_audio in_format = ao_c->input_format;
|
struct mp_audio in_format = ao_c->input_format;
|
||||||
|
|
||||||
@ -328,8 +347,8 @@ void reinit_audio_chain(struct MPContext *mpctx)
|
|||||||
if (spdif_fallback) {
|
if (spdif_fallback) {
|
||||||
ao_c->spdif_passthrough = false;
|
ao_c->spdif_passthrough = false;
|
||||||
ao_c->spdif_failed = true;
|
ao_c->spdif_failed = true;
|
||||||
mpctx->d_audio->try_spdif = false;
|
ao_c->audio_src->try_spdif = false;
|
||||||
if (!audio_init_best_codec(mpctx->d_audio))
|
if (!audio_init_best_codec(ao_c->audio_src))
|
||||||
goto init_error;
|
goto init_error;
|
||||||
reset_audio_state(mpctx);
|
reset_audio_state(mpctx);
|
||||||
reinit_audio_chain(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;
|
struct dec_audio *d_audio = ao_c->audio_src;
|
||||||
if (d_audio && ao_c->spdif_failed) {
|
if (d_audio && ao_c->spdif_failed) {
|
||||||
ao_c->spdif_failed = false;
|
ao_c->spdif_failed = false;
|
||||||
mpctx->d_audio->try_spdif = true;
|
d_audio->try_spdif = true;
|
||||||
if (!audio_init_best_codec(mpctx->d_audio)) {
|
if (!audio_init_best_codec(d_audio)) {
|
||||||
MP_ERR(mpctx, "Error reinitializing audio.\n");
|
MP_ERR(mpctx, "Error reinitializing audio.\n");
|
||||||
error_on_track(mpctx, mpctx->current_track[0][STREAM_AUDIO]);
|
error_on_track(mpctx, mpctx->current_track[0][STREAM_AUDIO]);
|
||||||
return;
|
return;
|
||||||
|
@ -536,7 +536,7 @@ static int mp_property_avsync(void *ctx, struct m_property *prop,
|
|||||||
int action, void *arg)
|
int action, void *arg)
|
||||||
{
|
{
|
||||||
MPContext *mpctx = ctx;
|
MPContext *mpctx = ctx;
|
||||||
if (!mpctx->d_audio || !mpctx->vo_chain)
|
if (!mpctx->ao_chain || !mpctx->vo_chain)
|
||||||
return M_PROPERTY_UNAVAILABLE;
|
return M_PROPERTY_UNAVAILABLE;
|
||||||
if (action == M_PROPERTY_PRINT) {
|
if (action == M_PROPERTY_PRINT) {
|
||||||
*(char **)arg = talloc_asprintf(NULL, "%7.3f", mpctx->last_av_difference);
|
*(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)
|
int action, void *arg)
|
||||||
{
|
{
|
||||||
MPContext *mpctx = ctx;
|
MPContext *mpctx = ctx;
|
||||||
if (!mpctx->d_audio || !mpctx->vo_chain)
|
if (!mpctx->ao_chain || !mpctx->vo_chain)
|
||||||
return M_PROPERTY_UNAVAILABLE;
|
return M_PROPERTY_UNAVAILABLE;
|
||||||
if (mpctx->total_avsync_change == MP_NOPTS_VALUE)
|
if (mpctx->total_avsync_change == MP_NOPTS_VALUE)
|
||||||
return M_PROPERTY_UNAVAILABLE;
|
return M_PROPERTY_UNAVAILABLE;
|
||||||
@ -1696,7 +1696,7 @@ static int mp_property_audio_delay(void *ctx, struct m_property *prop,
|
|||||||
int action, void *arg)
|
int action, void *arg)
|
||||||
{
|
{
|
||||||
MPContext *mpctx = ctx;
|
MPContext *mpctx = ctx;
|
||||||
if (!(mpctx->d_audio && mpctx->vo_chain))
|
if (!(mpctx->ao_chain && mpctx->vo_chain))
|
||||||
return M_PROPERTY_UNAVAILABLE;
|
return M_PROPERTY_UNAVAILABLE;
|
||||||
float delay = mpctx->opts->audio_delay;
|
float delay = mpctx->opts->audio_delay;
|
||||||
switch (action) {
|
switch (action) {
|
||||||
@ -1716,7 +1716,8 @@ static int mp_property_audio_codec_name(void *ctx, struct m_property *prop,
|
|||||||
int action, void *arg)
|
int action, void *arg)
|
||||||
{
|
{
|
||||||
MPContext *mpctx = ctx;
|
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);
|
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)
|
int action, void *arg)
|
||||||
{
|
{
|
||||||
MPContext *mpctx = ctx;
|
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);
|
return m_property_strdup_ro(action, arg, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,8 +145,9 @@ struct track {
|
|||||||
// Current subtitle state (or cached state if selected==false).
|
// Current subtitle state (or cached state if selected==false).
|
||||||
struct dec_sub *d_sub;
|
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_video *d_video;
|
||||||
|
struct dec_audio *d_audio;
|
||||||
|
|
||||||
// For external subtitles, which are read fully on init. Do not attempt
|
// For external subtitles, which are read fully on init. Do not attempt
|
||||||
// to read packets from them.
|
// to read packets from them.
|
||||||
@ -287,8 +288,6 @@ typedef struct MPContext {
|
|||||||
// Currently, this is used for the secondary subtitle track only.
|
// Currently, this is used for the secondary subtitle track only.
|
||||||
struct track *current_track[NUM_PTRACKS][STREAM_TYPE_COUNT];
|
struct track *current_track[NUM_PTRACKS][STREAM_TYPE_COUNT];
|
||||||
|
|
||||||
struct dec_audio *d_audio;
|
|
||||||
|
|
||||||
// Uses: accessing metadata (consider ordered chapters case, where the main
|
// Uses: accessing metadata (consider ordered chapters case, where the main
|
||||||
// demuxer defines metadata), or special purpose demuxers like TV.
|
// demuxer defines metadata), or special purpose demuxers like TV.
|
||||||
struct demuxer *master_demuxer;
|
struct demuxer *master_demuxer;
|
||||||
|
@ -195,7 +195,7 @@ static void print_status(struct MPContext *mpctx)
|
|||||||
saddf(&line, "(Paused) ");
|
saddf(&line, "(Paused) ");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mpctx->d_audio)
|
if (mpctx->ao_chain)
|
||||||
saddf(&line, "A");
|
saddf(&line, "A");
|
||||||
if (mpctx->vo_chain)
|
if (mpctx->vo_chain)
|
||||||
saddf(&line, "V");
|
saddf(&line, "V");
|
||||||
@ -217,7 +217,7 @@ static void print_status(struct MPContext *mpctx)
|
|||||||
saddf(&line, " x%4.2f", opts->playback_speed);
|
saddf(&line, " x%4.2f", opts->playback_speed);
|
||||||
|
|
||||||
// A-V sync
|
// 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);
|
saddf(&line, " A-V:%7.3f", mpctx->last_av_difference);
|
||||||
if (fabs(mpctx->total_avsync_change) > 0.05)
|
if (fabs(mpctx->total_avsync_change) > 0.05)
|
||||||
saddf(&line, " ct:%7.3f", mpctx->total_avsync_change);
|
saddf(&line, " ct:%7.3f", mpctx->total_avsync_change);
|
||||||
|
@ -97,7 +97,7 @@ void pause_player(struct MPContext *mpctx)
|
|||||||
mpctx->osd_force_update = true;
|
mpctx->osd_force_update = true;
|
||||||
mpctx->paused_for_cache = false;
|
mpctx->paused_for_cache = false;
|
||||||
|
|
||||||
if (mpctx->ao && mpctx->d_audio)
|
if (mpctx->ao && mpctx->ao_chain)
|
||||||
ao_pause(mpctx->ao);
|
ao_pause(mpctx->ao);
|
||||||
if (mpctx->video_out)
|
if (mpctx->video_out)
|
||||||
vo_set_paused(mpctx->video_out, true);
|
vo_set_paused(mpctx->video_out, true);
|
||||||
@ -122,7 +122,7 @@ void unpause_player(struct MPContext *mpctx)
|
|||||||
mpctx->osd_function = 0;
|
mpctx->osd_function = 0;
|
||||||
mpctx->osd_force_update = true;
|
mpctx->osd_force_update = true;
|
||||||
|
|
||||||
if (mpctx->ao && mpctx->d_audio)
|
if (mpctx->ao && mpctx->ao_chain)
|
||||||
ao_resume(mpctx->ao);
|
ao_resume(mpctx->ao);
|
||||||
if (mpctx->video_out)
|
if (mpctx->video_out)
|
||||||
vo_set_paused(mpctx->video_out, false);
|
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
|
* and video streams to "disabled" at runtime. Handle this by waiting
|
||||||
* rather than immediately stopping playback due to EOF.
|
* 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->audio_status == STATUS_EOF &&
|
||||||
mpctx->video_status == STATUS_EOF)
|
mpctx->video_status == STATUS_EOF)
|
||||||
{
|
{
|
||||||
|
@ -377,7 +377,7 @@ int reinit_video_chain(struct MPContext *mpctx)
|
|||||||
mpctx->sync_audio_to_video = !sh->attached_picture;
|
mpctx->sync_audio_to_video = !sh->attached_picture;
|
||||||
|
|
||||||
// If we switch on video again, ensure audio position matches up.
|
// If we switch on video again, ensure audio position matches up.
|
||||||
if (mpctx->d_audio)
|
if (mpctx->ao_chain)
|
||||||
mpctx->audio_status = STATUS_SYNCING;
|
mpctx->audio_status = STATUS_SYNCING;
|
||||||
|
|
||||||
reset_video_state(mpctx);
|
reset_video_state(mpctx);
|
||||||
|
Loading…
Reference in New Issue
Block a user