diff options
author | Leonardo Boss <leonardoboss2001@gmail.com> | 2024-02-22 14:14:53 -0300 |
---|---|---|
committer | Dudemanguy <random342@airmail.cc> | 2024-02-25 23:57:35 +0000 |
commit | 58ed620c064971535e60778612777750aa5e2f4d (patch) | |
tree | a943bc1cc70f1cd9cdf922639808541a468991a9 /player | |
parent | 2872e23aea5cca8d30d33b3cea897dd1cfd94d05 (diff) | |
download | mpv-58ed620c064971535e60778612777750aa5e2f4d.tar.bz2 mpv-58ed620c064971535e60778612777750aa5e2f4d.tar.xz |
player: add ao-volume option, to set the system volume at startup
closes #12353
Diffstat (limited to 'player')
-rw-r--r-- | player/audio.c | 18 | ||||
-rw-r--r-- | player/command.c | 15 | ||||
-rw-r--r-- | player/core.h | 1 |
3 files changed, 24 insertions, 10 deletions
diff --git a/player/audio.c b/player/audio.c index 344fbdb744..c697142012 100644 --- a/player/audio.c +++ b/player/audio.c @@ -182,6 +182,19 @@ void audio_update_volume(struct MPContext *mpctx) ao_set_gain(ao_c->ao, gain); } +// Called when opts->ao_volume were changed. +void audio_update_ao_volume(struct MPContext *mpctx) +{ + struct MPOpts *opts = mpctx->opts; + struct ao *ao = mpctx->ao; + float vol = opts->ao_volume; + if (!ao || vol < 0) + return; + + ao_control(ao, AOCONTROL_SET_VOLUME, &vol); +} + + // Call this if opts->playback_speed or mpctx->speed_factor_* change. void update_playback_speed(struct MPContext *mpctx) { @@ -335,6 +348,7 @@ static void ao_chain_set_ao(struct ao_chain *ao_c, struct ao *ao) // Make sure filtering never stops with frames stuck in access filter. mp_filter_set_high_priority(ao_c->queue_filter, true); audio_update_volume(ao_c->mpctx); + audio_update_ao_volume(ao_c->mpctx); } if (ao_c->filter->ao_needs_update) @@ -593,8 +607,10 @@ void reinit_audio_chain_src(struct MPContext *mpctx, struct track *track) if (recreate_audio_filters(mpctx) < 0) goto init_error; - if (mpctx->ao) + if (mpctx->ao) { audio_update_volume(mpctx); + audio_update_ao_volume(mpctx); + } mp_wakeup_core(mpctx); return; diff --git a/player/command.c b/player/command.c index a286dc2d4a..3eecdd3915 100644 --- a/player/command.c +++ b/player/command.c @@ -1669,12 +1669,6 @@ static int mp_property_ao_volume(void *ctx, struct m_property *prop, return M_PROPERTY_NOT_IMPLEMENTED; switch (action) { - case M_PROPERTY_SET: { - float vol = *(float *)arg; - if (ao_control(ao, AOCONTROL_SET_VOLUME, &vol) != CONTROL_OK) - return M_PROPERTY_UNAVAILABLE; - return M_PROPERTY_OK; - } case M_PROPERTY_GET: { if (ao_control(ao, AOCONTROL_GET_VOLUME, arg) != CONTROL_OK) return M_PROPERTY_UNAVAILABLE; @@ -3935,7 +3929,7 @@ static const struct m_property mp_properties_base[] = { {"mixer-active", mp_property_mixer_active}, {"volume", mp_property_volume}, {"volume-gain", mp_property_volume_gain}, - {"ao-volume", mp_property_ao_volume}, + {"current-ao-volume", mp_property_ao_volume}, {"ao-mute", mp_property_ao_mute}, {"audio-delay", mp_property_audio_delay}, {"audio-codec-name", mp_property_audio_codec_name}, @@ -4286,8 +4280,8 @@ static const struct property_osd_display { {"volume-gain", "Volume gain", .msg = "Volume gain: ${?volume-gain:${volume-gain} dB ${?mute==yes:(Muted)}}${!volume-gain:${volume-gain}}", .osd_progbar = OSD_VOLUME, .marker = 0}, - {"ao-volume", "AO Volume", - .msg = "AO Volume: ${?ao-volume:${ao-volume}% ${?ao-mute==yes:(Muted)}}${!ao-volume:${ao-volume}}", + {"current-ao-volume", "AO Volume", + .msg = "AO Volume: ${?current-ao-volume:${current-ao-volume}% ${?ao-mute==yes:(Muted)}}${!current-ao-volume:${currene-ao-volume}}", .osd_progbar = OSD_VOLUME, .marker = 100}, {"mute", "Mute"}, {"ao-mute", "AO Mute"}, @@ -7198,6 +7192,9 @@ void mp_option_change_callback(void *ctx, struct m_config_option *co, int flags, mp_wakeup_core(mpctx); } + if (opt_ptr == &opts->ao_volume) + audio_update_ao_volume(mpctx); + if (flags & UPDATE_HWDEC) { struct track *track = mpctx->current_track[0][STREAM_VIDEO]; struct mp_decoder_wrapper *dec = track ? track->dec : NULL; diff --git a/player/core.h b/player/core.h index d995a88366..2fc3c45700 100644 --- a/player/core.h +++ b/player/core.h @@ -487,6 +487,7 @@ void uninit_audio_out(struct MPContext *mpctx); void uninit_audio_chain(struct MPContext *mpctx); void reinit_audio_chain_src(struct MPContext *mpctx, struct track *track); void audio_update_volume(struct MPContext *mpctx); +void audio_update_ao_volume(struct MPContext *mpctx); void reload_audio_output(struct MPContext *mpctx); void audio_start_ao(struct MPContext *mpctx); |