CRAS: apm_list - Adopt dev/stream gain if no tuned settings provided

When deploying generic APM to models without tuned settings given,
we should still apply the gain configured by intrinsic sensitivity
and stream gain.

BUG=b:181818480
TEST=Test online voice recorder on 'barla' device. Verify the
recorded volume is higher as usual.

Change-Id: Ib4ddbce3dc23b9dbc8238c5969970a238c37d232
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/adhd/+/2766563
Reviewed-by: Cheng-Yi Chiang <cychiang@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
diff --git a/cras/src/server/cras_apm_list.c b/cras/src/server/cras_apm_list.c
index 264bc85..ab89113 100644
--- a/cras/src/server/cras_apm_list.c
+++ b/cras/src/server/cras_apm_list.c
@@ -61,9 +61,10 @@
  *        stream.
  *    work_queue - A task queue instance created and destroyed by
  *        libwebrtc_apm.
- *    use_tuned_settings - True if this APM uses settings tuned specifically
- *        for this hardware in AEC use case. Otherwise it uses the generic
- *        settings like run inside browser.
+ *    is_aec_use_case - True if the input and output devices pair is in the
+ *        typical AEC use case. This flag decides whether to use settings
+ *        tuned specifically for this hardware if exists. Otherwise it uses
+ *        the generic settings like run inside browser.
  */
 struct cras_apm {
 	webrtc_apm apm_ptr;
@@ -74,7 +75,7 @@
 	struct cras_audio_format fmt;
 	struct cras_audio_area *area;
 	void *work_queue;
-	bool use_tuned_settings;
+	bool is_aec_use_case;
 	struct cras_apm *prev, *next;
 };
 
@@ -289,16 +290,16 @@
 
 	/* Use tuned settings only when the forward dev(capture) and reverse
 	 * dev(playback) both are in typical AEC use case. */
-	apm->use_tuned_settings = is_aec_use_case;
+	apm->is_aec_use_case = is_aec_use_case;
 	if (rmodule->odev) {
-		apm->use_tuned_settings &=
+		apm->is_aec_use_case &=
 			cras_iodev_is_aec_use_case(rmodule->odev->active_node);
 	}
 
 	/* Use the configs tuned specifically for internal device. Otherwise
 	 * just pass NULL so every other settings will be default. */
 	apm->apm_ptr =
-		apm->use_tuned_settings ?
+		apm->is_aec_use_case ?
 			webrtc_apm_create(apm->fmt.num_channels,
 					  apm->fmt.frame_rate, aec_ini,
 					  apm_ini) :
@@ -690,7 +691,9 @@
 
 bool cras_apm_list_get_use_tuned_settings(struct cras_apm *apm)
 {
-	return apm->use_tuned_settings;
+	/* If input and output devices in AEC use case, plus that a
+	 * tuned setting is provided. */
+	return apm->is_aec_use_case && (aec_ini || apm_ini);
 }
 
 void cras_apm_list_set_aec_dump(struct cras_apm_list *list, void *dev_ptr,