mirror of
https://github.com/mpv-player/mpv
synced 2024-12-27 01:22:30 +00:00
mplayer: simplify AO creation
The AO creation part was split into two separate parts (one calling ao_create and one calling ao_init). This didn't really have good reasons, and obfuscates how AO creation works. Put them together.
This commit is contained in:
parent
c1afd75142
commit
9e1331f7af
@ -1575,46 +1575,55 @@ static void update_osd_msg(struct MPContext *mpctx)
|
||||
void reinit_audio_chain(struct MPContext *mpctx)
|
||||
{
|
||||
struct MPOpts *opts = &mpctx->opts;
|
||||
struct ao *ao;
|
||||
init_demux_stream(mpctx, STREAM_AUDIO);
|
||||
if (!mpctx->sh_audio) {
|
||||
uninit_player(mpctx, INITIALIZED_VOL | INITIALIZED_AO);
|
||||
goto no_audio;
|
||||
}
|
||||
|
||||
if (!(mpctx->initialized_flags & INITIALIZED_ACODEC)) {
|
||||
if (!init_best_audio_codec(mpctx->sh_audio, opts->audio_decoders))
|
||||
goto init_error;
|
||||
mpctx->initialized_flags |= INITIALIZED_ACODEC;
|
||||
}
|
||||
|
||||
if (!(mpctx->initialized_flags & INITIALIZED_AO)) {
|
||||
mpctx->initialized_flags |= INITIALIZED_AO;
|
||||
mpctx->ao = ao_create(opts, mpctx->input);
|
||||
mpctx->ao->samplerate = opts->force_srate;
|
||||
mpctx->ao->format = opts->audio_output_format;
|
||||
int ao_srate = opts->force_srate;
|
||||
int ao_format = opts->audio_output_format;
|
||||
struct mp_chmap ao_channels = {0};
|
||||
if (mpctx->initialized_flags & INITIALIZED_AO) {
|
||||
ao_srate = mpctx->ao->samplerate;
|
||||
ao_format = mpctx->ao->format;
|
||||
ao_channels = mpctx->ao->channels;
|
||||
} else {
|
||||
// Automatic downmix
|
||||
if (mp_chmap_is_stereo(&opts->audio_output_channels) &&
|
||||
!mp_chmap_is_stereo(&mpctx->sh_audio->channels))
|
||||
{
|
||||
mp_chmap_from_channels(&mpctx->ao->channels, 2);
|
||||
mp_chmap_from_channels(&ao_channels, 2);
|
||||
}
|
||||
}
|
||||
ao = mpctx->ao;
|
||||
|
||||
// first init to detect best values
|
||||
if (!init_audio_filters(mpctx->sh_audio, // preliminary init
|
||||
// input:
|
||||
mpctx->sh_audio->samplerate,
|
||||
// output:
|
||||
&ao->samplerate, &ao->channels, &ao->format)) {
|
||||
&ao_srate, &ao_channels, &ao_format)) {
|
||||
mp_tmsg(MSGT_CPLAYER, MSGL_ERR, "Error at audio filter chain "
|
||||
"pre-init!\n");
|
||||
goto init_error;
|
||||
}
|
||||
if (!ao->initialized) {
|
||||
ao->encode_lavc_ctx = mpctx->encode_lavc_ctx;
|
||||
mp_chmap_remove_useless_channels(&ao->channels,
|
||||
|
||||
if (!(mpctx->initialized_flags & INITIALIZED_AO)) {
|
||||
mpctx->initialized_flags |= INITIALIZED_AO;
|
||||
mp_chmap_remove_useless_channels(&ao_channels,
|
||||
&opts->audio_output_channels);
|
||||
mpctx->ao = ao_create(opts, mpctx->input);
|
||||
struct ao *ao = mpctx->ao;
|
||||
ao->samplerate = ao_srate;
|
||||
ao->format = ao_format;
|
||||
ao->channels = ao_channels;
|
||||
ao->encode_lavc_ctx = mpctx->encode_lavc_ctx;
|
||||
ao_init(ao, opts->audio_driver_list);
|
||||
if (!ao->initialized) {
|
||||
mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
|
||||
@ -1642,7 +1651,7 @@ void reinit_audio_chain(struct MPContext *mpctx)
|
||||
mpctx->mixer.volstep = opts->volstep;
|
||||
mpctx->mixer.softvol = opts->softvol;
|
||||
mpctx->mixer.softvol_max = opts->softvol_max;
|
||||
mixer_reinit(&mpctx->mixer, ao);
|
||||
mixer_reinit(&mpctx->mixer, mpctx->ao);
|
||||
if (!(mpctx->initialized_flags & INITIALIZED_VOL)) {
|
||||
if (opts->mixer_init_volume >= 0) {
|
||||
mixer_setvolume(&mpctx->mixer, opts->mixer_init_volume,
|
||||
|
Loading…
Reference in New Issue
Block a user