summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-10-12 18:28:02 +0200
committerwm4 <wm4@nowhere>2013-10-12 18:57:02 +0200
commit20988ee6076bac53015b6eaab753203ca7dd6a8c (patch)
treee8a7d8b08dca4fac7a860a072d1ffa18769f4186
parent38874b2f2e3a5e0473bada789ef04af632e27ecb (diff)
downloadmpv-20988ee6076bac53015b6eaab753203ca7dd6a8c.tar.bz2
mpv-20988ee6076bac53015b6eaab753203ca7dd6a8c.tar.xz
command: don't allow changing volume if no audio initialized
Changing volume when audio is disabled was a feature request (github issue #215), and was introduced with commit 327a779. But trying to fix github issue #280 (volume is not correct in no-audio mode, and if audio is re-enabled, the volume set in no-audio mode isn't set), I concluded that it's not worth the trouble and the current implementation is questionable all around. (For example, you can't change the real volume in no-audio mode, even if the AO is open - this could happen with gapless audio.) It's hard to get right, and the current mixer code is already hilariously overcomplicated. (Virtually all of mixer.c is an amalgamation of various obscure corner cases.) So just remove this feature again. Note that "options/volume" and "options/mute" still can be used in idle mode to adjust the volume used next time, though these properties can't be used during playback and thus not in audio-only mode. Querying the volume still "works" in audio-only mode, though it can return bogus values.
-rw-r--r--audio/mixer.c5
-rw-r--r--audio/mixer.h1
-rw-r--r--mpvcore/command.c6
3 files changed, 12 insertions, 0 deletions
diff --git a/audio/mixer.c b/audio/mixer.c
index 07ce229f73..f3e9d959aa 100644
--- a/audio/mixer.c
+++ b/audio/mixer.c
@@ -59,6 +59,11 @@ struct mixer *mixer_init(void *talloc_ctx, struct MPOpts *opts)
return mixer;
}
+bool mixer_audio_initialized(struct mixer *mixer)
+{
+ return !!mixer->ao;
+}
+
static void checkvolume(struct mixer *mixer)
{
if (!mixer->ao)
diff --git a/audio/mixer.h b/audio/mixer.h
index 9fbb4bcdca..e2e574c22e 100644
--- a/audio/mixer.h
+++ b/audio/mixer.h
@@ -36,6 +36,7 @@ struct mixer;
struct mixer *mixer_init(void *talloc_ctx, struct MPOpts *opts);
void mixer_reinit_audio(struct mixer *mixer, struct ao *ao, struct af_stream *af);
void mixer_uninit_audio(struct mixer *mixer);
+bool mixer_audio_initialized(struct mixer *mixer);
void mixer_getvolume(struct mixer *mixer, float *l, float *r);
void mixer_setvolume(struct mixer *mixer, float l, float r);
void mixer_incvolume(struct mixer *mixer);
diff --git a/mpvcore/command.c b/mpvcore/command.c
index f16d171bf4..c9eb21dd0b 100644
--- a/mpvcore/command.c
+++ b/mpvcore/command.c
@@ -768,9 +768,13 @@ static int mp_property_volume(m_option_t *prop, int action, void *arg,
mixer_getbothvolume(mpctx->mixer, arg);
return M_PROPERTY_OK;
case M_PROPERTY_SET:
+ if (!mixer_audio_initialized(mpctx->mixer))
+ return M_PROPERTY_ERROR;
mixer_setvolume(mpctx->mixer, *(float *) arg, *(float *) arg);
return M_PROPERTY_OK;
case M_PROPERTY_SWITCH: {
+ if (!mixer_audio_initialized(mpctx->mixer))
+ return M_PROPERTY_ERROR;
struct m_property_switch_arg *sarg = arg;
if (sarg->inc <= 0)
mixer_decvolume(mpctx->mixer);
@@ -788,6 +792,8 @@ static int mp_property_mute(m_option_t *prop, int action, void *arg,
{
switch (action) {
case M_PROPERTY_SET:
+ if (!mixer_audio_initialized(mpctx->mixer))
+ return M_PROPERTY_ERROR;
mixer_setmute(mpctx->mixer, *(int *) arg);
return M_PROPERTY_OK;
case M_PROPERTY_GET: