CRAS: iodev_list - Do not ramp volume when muted
If volume is changed while muted, volume ramps are still applied.
If audio is playing when these ramps are applied, it is briefly audible
even though the device is supposed to be muted.
To fix this, check that the system is not muted before adding a
volume ramp.
BUG=b:131579153
TEST=set volume to 50%, start audio playback, hit mute key, hit volume
down key. No sound should be heard.
Change-Id: I49ce98b571ec23cb16cb77be0323b6f3f8764a93
Reviewed-on: https://chromium-review.googlesource.com/1625624
Commit-Ready: Fletcher Woodruff <fletcherw@chromium.org>
Tested-by: Fletcher Woodruff <fletcherw@chromium.org>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
diff --git a/cras/src/server/cras_iodev_list.c b/cras/src/server/cras_iodev_list.c
index e2d209a..b6ff86d 100644
--- a/cras/src/server/cras_iodev_list.c
+++ b/cras/src/server/cras_iodev_list.c
@@ -1523,7 +1523,8 @@
if (!node)
return -EINVAL;
- if (iodev->ramp && cras_iodev_software_volume_needed(iodev))
+ if (iodev->ramp && cras_iodev_software_volume_needed(iodev) &&
+ !cras_system_get_mute())
cras_iodev_start_volume_ramp(iodev, node->volume, volume);
node->volume = volume;
diff --git a/cras/src/tests/iodev_list_unittest.cc b/cras/src/tests/iodev_list_unittest.cc
index c5cdbde..07c7c87 100644
--- a/cras/src/tests/iodev_list_unittest.cc
+++ b/cras/src/tests/iodev_list_unittest.cc
@@ -24,6 +24,7 @@
struct cras_server_state server_state_stub;
struct cras_server_state *server_state_update_begin_return;
+int system_get_mute_return;
/* Data for stubs. */
static struct cras_observer_ops *observer_ops;
@@ -192,6 +193,7 @@
loopback_input.supported_channel_counts = channel_counts_;
server_state_update_begin_return = &server_state_stub;
+ system_get_mute_return = false;
/* Reset stub data. */
add_stream_called = 0;
@@ -1196,11 +1198,20 @@
EXPECT_EQ(2, cras_observer_notify_output_node_volume_called);
EXPECT_EQ(0, cras_iodev_start_volume_ramp_called);
- // Ramp starts only when it's non-NULL and software volume is used.
- d1_.ramp = reinterpret_cast<struct cras_ramp*>(0x1);
+ // System mute prevents volume ramp from starting
+ system_get_mute_return = true;
cras_iodev_list_set_node_attr(cras_make_node_id(d1_.info.idx, 1),
IONODE_ATTR_VOLUME, 20);
EXPECT_EQ(3, cras_observer_notify_output_node_volume_called);
+ EXPECT_EQ(0, cras_iodev_start_volume_ramp_called);
+
+ // Ramp starts only when it's non-NULL, software volume is used, and
+ // system is not muted
+ system_get_mute_return = false;
+ d1_.ramp = reinterpret_cast<struct cras_ramp*>(0x1);
+ cras_iodev_list_set_node_attr(cras_make_node_id(d1_.info.idx, 1),
+ IONODE_ATTR_VOLUME, 20);
+ EXPECT_EQ(4, cras_observer_notify_output_node_volume_called);
EXPECT_EQ(1, cras_iodev_start_volume_ramp_called);
d1_.direction = CRAS_STREAM_INPUT;
@@ -1610,6 +1621,10 @@
void cras_system_state_update_complete() {
}
+int cras_system_get_mute() {
+ return system_get_mute_return;
+}
+
struct audio_thread *audio_thread_create() {
return &thread;
}