summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCheng-Yi Chiang <cychiang@chromium.org>2017-01-24 17:20:44 +0800
committerchrome-bot <chrome-bot@chromium.org>2017-02-27 12:03:18 -0800
commit2d7d73485680f773eef56676995729216a6ae47f (patch)
tree038442f0b49b5cca84d4aeb5c2e93096c61dd4e5
parent5528e7442cd3b86037fa84e45ca42cf10b126bdf (diff)
downloadadhd-2d7d73485680f773eef56676995729216a6ae47f.tar.gz
CRAS: system_state - Store target capture gain
System capture gain is subjected to supported gain range. This causes a problem that when desired capture gain is out of supported gain range, it can not be retained after supported gain range is changed because the information is lost. To solve above problem, system state can add a field capture_gain_target to store the desired capture gain. Then, when the supported range is changed, system state can try to re-apply capture_gain_target. Initalize device setting in alsa_iodev_set_active_node so the gain limit and system gain can be adjusted based on the latest active device and active node. BUG=chrome-os-partner:60744, chromium:692187 TEST=make check TEST=on kevin, check cras_test_client --dump_s and see default system gain is 20.0 dB, not 0.0dB. TEST=Use apprtc, switch between internal mic and external mic and see the gain adjusted on one node is retained after switching back to that node. Change-Id: I48653c7d5035ec2ca8a53d300772bfc529c8b7ad Reviewed-on: https://chromium-review.googlesource.com/430527 Commit-Ready: Cheng-Yi Chiang <cychiang@chromium.org> Tested-by: Cheng-Yi Chiang <cychiang@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
-rw-r--r--cras/src/common/cras_types.h7
-rw-r--r--cras/src/server/cras_alsa_io.c1
-rw-r--r--cras/src/server/cras_system_state.c6
-rw-r--r--cras/src/tests/system_state_unittest.cc16
4 files changed, 28 insertions, 2 deletions
diff --git a/cras/src/common/cras_types.h b/cras/src/common/cras_types.h
index 12764db0..8fecbf13 100644
--- a/cras/src/common/cras_types.h
+++ b/cras/src/common/cras_types.h
@@ -254,6 +254,12 @@ struct __attribute__ ((__packed__)) audio_debug_info {
* mute_locked - 0 = unlocked, 1 = locked.
* suspended - 1 = suspended, 0 = resumed.
* capture_gain - Capture gain in dBFS * 100.
+ * capture_gain_target - Target capture gain in dBFS * 100. The actual
+ * capture gain will be subjected to current
+ * supported range. When active device/node changes,
+ * supported range changes accordingly. System state
+ * should try to re-apply target gain subjected to new
+ * range.
* capture_mute - 0 = unmuted, 1 = muted.
* capture_mute_locked - 0 = unlocked, 1 = locked.
* min_capture_gain - Min allowed capture gain in dBFS * 100.
@@ -290,6 +296,7 @@ struct __attribute__ ((packed, aligned(4))) cras_server_state {
int32_t mute_locked;
int32_t suspended;
int32_t capture_gain;
+ int32_t capture_gain_target;
int32_t capture_mute;
int32_t capture_mute_locked;
int32_t min_capture_gain;
diff --git a/cras/src/server/cras_alsa_io.c b/cras/src/server/cras_alsa_io.c
index fe4c1d35..c0434d6b 100644
--- a/cras/src/server/cras_alsa_io.c
+++ b/cras/src/server/cras_alsa_io.c
@@ -2126,6 +2126,7 @@ static int alsa_iodev_set_active_node(struct cras_iodev *iodev,
if (iodev->active_node == ionode) {
enable_active_ucm(aio, dev_enabled);
+ init_device_settings(aio);
return 0;
}
diff --git a/cras/src/server/cras_system_state.c b/cras/src/server/cras_system_state.c
index a51aacd6..3483ebcb 100644
--- a/cras/src/server/cras_system_state.c
+++ b/cras/src/server/cras_system_state.c
@@ -98,6 +98,7 @@ void cras_system_state_init(const char *device_config_dir)
exp_state->mute_locked = 0;
exp_state->suspended = 0;
exp_state->capture_gain = DEFAULT_CAPTURE_GAIN;
+ exp_state->capture_gain_target = DEFAULT_CAPTURE_GAIN;
exp_state->capture_mute = 0;
exp_state->capture_mute_locked = 0;
exp_state->min_volume_dBFS = DEFAULT_MIN_VOLUME_DBFS;
@@ -171,6 +172,7 @@ size_t cras_system_get_volume()
void cras_system_set_capture_gain(long gain)
{
/* Adjust targeted gain to be in supported range. */
+ state.exp_state->capture_gain_target = gain;
gain = MAX(gain, state.exp_state->min_capture_gain);
gain = MIN(gain, state.exp_state->max_capture_gain);
state.exp_state->capture_gain = gain;
@@ -301,8 +303,8 @@ void cras_system_set_capture_gain_limits(long min, long max)
{
state.exp_state->min_capture_gain = MAX(min, DEFAULT_MIN_CAPTURE_GAIN);
state.exp_state->max_capture_gain = max;
- /* Current gain needs to be in the supported range. */
- cras_system_set_capture_gain(state.exp_state->capture_gain);
+ /* Re-apply target gain subjected to the new supported range. */
+ cras_system_set_capture_gain(state.exp_state->capture_gain_target);
}
long cras_system_get_min_capture_gain()
diff --git a/cras/src/tests/system_state_unittest.cc b/cras/src/tests/system_state_unittest.cc
index 8a952110..5816b771 100644
--- a/cras/src/tests/system_state_unittest.cc
+++ b/cras/src/tests/system_state_unittest.cc
@@ -115,6 +115,22 @@ TEST(SystemStateSuite, SetCaptureVolume) {
EXPECT_EQ(3, cras_observer_notify_capture_gain_called);
}
+TEST(SystemStateSuite, SetCaptureVolumeStoreTarget) {
+ cras_system_state_init(device_config_dir);
+ cras_system_set_capture_gain_limits(-2000, 2000);
+ cras_system_set_capture_gain(3000);
+ // Gain is within the limit.
+ EXPECT_EQ(2000, cras_system_get_capture_gain());
+
+ // Assume the range is changed.
+ cras_system_set_capture_gain_limits(-4000, 4000);
+
+ // Gain is also changed because target gain is re-applied.
+ EXPECT_EQ(3000, cras_system_get_capture_gain());
+
+ cras_system_state_deinit();
+}
+
TEST(SystemStateSuite, SetMinMaxCaptureGain) {
cras_system_state_init(device_config_dir);
cras_system_set_capture_gain(3000);