hal: use AUDIO_TX_MONO_COPP topology for incall record usecases

The Audio COPP topology is hard coded to NULL topology in kernel
for incall recording stream. Remove the hard coding in kernel and
send default input device's audio calibration from audio hal
so that AUDIO_TX_MONO_COPP topology will be used for incall
recording stream.

This change is needed to be able to fine tune audio calibration
data for incall recording stream.

Change-Id: I1680731afb0c0e1c1eedbc9afd56064d856e3940
diff --git a/hal/audio_extn/utils.c b/hal/audio_extn/utils.c
index 8bd98a0..d0a2571 100644
--- a/hal/audio_extn/utils.c
+++ b/hal/audio_extn/utils.c
@@ -33,6 +33,7 @@
 #include "platform.h"
 #include "platform_api.h"
 #include "audio_extn.h"
+#include "voice.h"
 
 #define AUDIO_OUTPUT_POLICY_VENDOR_CONFIG_FILE "/vendor/etc/audio_output_policy.conf"
 
@@ -560,10 +561,18 @@
                                         out->app_type_cfg.sample_rate);
     }
     if ((type == PCM_HFP_CALL) || (type == PCM_CAPTURE)) {
-        /* when app type is default. the sample rate is not used to send cal */
-        platform_send_audio_calibration(adev->platform, usecase->in_snd_device,
-                                        platform_get_default_app_type(adev->platform),
-                                        48000);
+        if ((type == PCM_CAPTURE) & voice_is_in_call_rec_stream(usecase->stream.in)) {
+            snd_device_t incall_record_snd_device =
+                        voice_get_incall_rec_snd_device(usecase->in_snd_device);
+            platform_send_audio_calibration(adev->platform, incall_record_snd_device,
+                                            platform_get_default_app_type(adev->platform),
+                                            48000);
+        } else {
+            /* when app type is default. the sample rate is not used to send cal */
+            platform_send_audio_calibration(adev->platform, usecase->in_snd_device,
+                                            platform_get_default_app_type(adev->platform),
+                                            48000);
+        }
     }
 }
 
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 80fb83b..962a742 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -965,7 +965,8 @@
     if (ret)
         goto error_config;
     else
-        ALOGV("%s: usecase(%d)", __func__, in->usecase);
+        ALOGD("%s: Updated usecase(%d: %s)",
+              __func__, in->usecase, use_case_table[in->usecase]);
 
     in->pcm_device_id = platform_get_pcm_device_id(in->usecase, PCM_CAPTURE);
     if (in->pcm_device_id < 0) {
diff --git a/hal/audio_hw.h b/hal/audio_hw.h
index d05f743..50bb42c 100644
--- a/hal/audio_hw.h
+++ b/hal/audio_hw.h
@@ -52,7 +52,6 @@
 
 #define SND_CARD_STATE_OFFLINE 0
 #define SND_CARD_STATE_ONLINE 1
-typedef int snd_device_t;
 
 /* These are the supported use cases by the hardware.
  * Each usecase is mapped to a specific PCM device.
diff --git a/hal/voice.c b/hal/voice.c
index 964b6f6..cf5ec65 100644
--- a/hal/voice.c
+++ b/hal/voice.c
@@ -309,6 +309,35 @@
     return ret;
 }
 
+snd_device_t voice_get_incall_rec_snd_device(snd_device_t in_snd_device)
+{
+    snd_device_t incall_record_device = in_snd_device;
+
+    /*
+     * For incall recording stream, AUDIO_COPP topology will be picked up
+     * from the calibration data of the input sound device which is nothing
+     * but the voice call's input device. But there are requirements to use
+     * AUDIO_COPP_MONO topology even if the voice call's input device is
+     * different. Hence override the input device with the one which uses
+     * the AUDIO_COPP_MONO topology.
+     */
+    switch(in_snd_device) {
+    case SND_DEVICE_IN_HANDSET_MIC:
+    case SND_DEVICE_IN_VOICE_DMIC:
+    case SND_DEVICE_IN_AANC_HANDSET_MIC:
+        incall_record_device = SND_DEVICE_IN_HANDSET_MIC;
+    case SND_DEVICE_IN_VOICE_SPEAKER_MIC:
+    case SND_DEVICE_IN_VOICE_SPEAKER_DMIC:
+    case SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE:
+    case SND_DEVICE_IN_VOICE_SPEAKER_QMIC:
+        incall_record_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
+    default:
+        incall_record_device = in_snd_device;
+    }
+
+    return incall_record_device;
+}
+
 int voice_check_and_set_incall_music_usecase(struct audio_device *adev,
                                              struct stream_out *out)
 {
diff --git a/hal/voice.h b/hal/voice.h
index 9be8443..5038dfa 100644
--- a/hal/voice.h
+++ b/hal/voice.h
@@ -43,6 +43,7 @@
 struct stream_in;
 struct stream_out;
 typedef int audio_usecase_t;
+typedef int snd_device_t;
 
 struct call_state {
     int current;
@@ -93,4 +94,5 @@
 int voice_check_and_stop_incall_rec_usecase(struct audio_device *adev,
                                             struct stream_in *in);
 void voice_update_devices_for_all_voice_usecases(struct audio_device *adev);
+snd_device_t voice_get_incall_rec_snd_device(snd_device_t in_snd_device);
 #endif //VOICE_H