diff options
author | wm4 <wm4@nowhere> | 2013-07-22 14:43:58 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-07-22 15:11:03 +0200 |
commit | 3b8dfddb4cb6e9431da659b10c5b31a9f17c81b5 (patch) | |
tree | b087f6551fa96a6fbe0f1f2b7f0f951f331eb552 /core/mplayer.c | |
parent | 221ef23d0d4454af974b08e68fad6b898d1d8e12 (diff) | |
download | mpv-3b8dfddb4cb6e9431da659b10c5b31a9f17c81b5.tar.bz2 mpv-3b8dfddb4cb6e9431da659b10c5b31a9f17c81b5.tar.xz |
audio/filter: use new option API
Make the VF/VO/AO option parser available to audio filters. No audio
filter uses this yet, but it's still a quite intrusive change.
In particular, the commands for manipulating filters at runtime
completely change. We delete the old code, and use the same
infrastructure as for video filters. (This forces complete
reinitialization of the filter chain, which hopefully isn't a problem
for any use cases. The old code forced reinitialization too, but it
could potentially allow a filter to cache things; e.g. consider loaded
ladspa plugins and such.)
Diffstat (limited to 'core/mplayer.c')
-rw-r--r-- | core/mplayer.c | 85 |
1 files changed, 52 insertions, 33 deletions
diff --git a/core/mplayer.c b/core/mplayer.c index e54b55444f..d9c03dace5 100644 --- a/core/mplayer.c +++ b/core/mplayer.c @@ -1185,11 +1185,6 @@ static int build_afilter_chain(struct MPContext *mpctx) struct ao *ao = mpctx->ao; struct MPOpts *opts = &mpctx->opts; int new_srate; - int result; - if (!sh_audio) { - mpctx->mixer.afilter = NULL; - return 0; - } if (af_control_any_rev(sh_audio->afilter, AF_CONTROL_PLAYBACK_SPEED | AF_CONTROL_SET, &opts->playback_speed)) @@ -1205,10 +1200,8 @@ static int build_afilter_chain(struct MPContext *mpctx) opts->playback_speed = (float)new_srate / sh_audio->samplerate; } } - result = init_audio_filters(sh_audio, new_srate, - &ao->samplerate, &ao->channels, &ao->format); - mpctx->mixer.afilter = sh_audio->afilter; - return result; + return init_audio_filters(sh_audio, new_srate, + &ao->samplerate, &ao->channels, &ao->format); } @@ -1572,6 +1565,51 @@ static void update_osd_msg(struct MPContext *mpctx) } } +static int recreate_audio_filters(struct MPContext *mpctx) +{ + struct MPOpts *opts = &mpctx->opts; + assert(mpctx->sh_audio); + + // init audio filters: + if (!build_afilter_chain(mpctx)) { + mp_tmsg(MSGT_CPLAYER, MSGL_ERR, + "Couldn't find matching filter/ao format!\n"); + return -1; + } + + mpctx->mixer.afilter = mpctx->sh_audio->afilter; + mpctx->mixer.volstep = opts->volstep; + mpctx->mixer.softvol = opts->softvol; + mpctx->mixer.softvol_max = opts->softvol_max; + 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, + opts->mixer_init_volume); + } + if (opts->mixer_init_mute >= 0) + mixer_setmute(&mpctx->mixer, opts->mixer_init_mute); + mpctx->initialized_flags |= INITIALIZED_VOL; + } + + return 0; +} + +int reinit_audio_filters(struct MPContext *mpctx) +{ + struct sh_audio *sh_audio = mpctx->sh_audio; + if (!sh_audio) + return -2; + + af_uninit(mpctx->sh_audio->afilter); + if (af_init(mpctx->sh_audio->afilter) < 0) + return -1; + if (recreate_audio_filters(mpctx) < 0) + return -1; + + return 0; +} + void reinit_audio_chain(struct MPContext *mpctx) { struct MPOpts *opts = &mpctx->opts; @@ -1603,7 +1641,9 @@ void reinit_audio_chain(struct MPContext *mpctx) } } - // first init to detect best values + // Determine what the filter chain outputs. build_afilter_chain() also + // needs this for testing whether playback speed is changed by resampling + // or using a special filter. if (!init_audio_filters(mpctx->sh_audio, // preliminary init // input: mpctx->sh_audio->samplerate, @@ -1638,25 +1678,9 @@ void reinit_audio_chain(struct MPContext *mpctx) ao->driver->info->comment); } - // init audio filters: - if (!build_afilter_chain(mpctx)) { - mp_tmsg(MSGT_CPLAYER, MSGL_ERR, - "Couldn't find matching filter/ao format!\n"); + if (recreate_audio_filters(mpctx) < 0) goto init_error; - } - mpctx->mixer.volstep = opts->volstep; - mpctx->mixer.softvol = opts->softvol; - mpctx->mixer.softvol_max = opts->softvol_max; - 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, - opts->mixer_init_volume); - } - if (opts->mixer_init_mute >= 0) - mixer_setmute(&mpctx->mixer, opts->mixer_init_mute); - mpctx->initialized_flags |= INITIALIZED_VOL; - } + mpctx->syncing_audio = true; return; @@ -4512,11 +4536,6 @@ static bool handle_help_options(struct MPContext *mpctx) talloc_free(list); opt_exit = 1; } - if (af_cfg.list && strcmp(af_cfg.list[0], "help") == 0) { - af_help(); - mp_msg(MSGT_CPLAYER, MSGL_INFO, "\n"); - opt_exit = 1; - } #ifdef CONFIG_X11 if (opts->vo.fstype_list && strcmp(opts->vo.fstype_list[0], "help") == 0) { fstype_help(); |