audio: hal: App type config changes for transcode loopback

Changes to enable app type config for DSP HW
transcode loopback usecase type.

CRs-Fixed: 2081126
Change-Id: I160038b5aaa404298d08e5d0b32f794531b23a82
diff --git a/hal/audio_extn/utils.c b/hal/audio_extn/utils.c
index 8c4f313..a993d76 100644
--- a/hal/audio_extn/utils.c
+++ b/hal/audio_extn/utils.c
@@ -845,6 +845,19 @@
                                                 &usecase->stream.in->app_type_cfg);
         ALOGV("%s Selected apptype: %d", __func__, usecase->stream.in->app_type_cfg.app_type);
         break;
+    case TRANSCODE_LOOPBACK :
+        audio_extn_utils_update_stream_output_app_type_cfg(adev->platform,
+                                                &adev->streams_output_cfg_list,
+                                                usecase->stream.inout->out_config.devices,
+                                                0,
+                                                usecase->stream.inout->out_config.format,
+                                                usecase->stream.inout->out_config.sample_rate,
+                                                usecase->stream.inout->out_config.bit_width,
+                                                usecase->stream.inout->out_config.channel_mask,
+                                                usecase->stream.inout->profile,
+                                                &usecase->stream.inout->out_app_type_cfg);
+        ALOGV("%s Selected apptype: %d", __func__, usecase->stream.inout->out_app_type_cfg.app_type);
+        break;
     default:
         ALOGE("%s: app type cfg not supported for usecase type (%d)",
             __func__, usecase->type);
@@ -872,7 +885,8 @@
           platform_get_snd_device_name(usecase->in_snd_device),
           platform_get_snd_device_name(split_snd_device));
 
-    if (usecase->type != PCM_PLAYBACK && usecase->type != PCM_CAPTURE) {
+    if (usecase->type != PCM_PLAYBACK && usecase->type != PCM_CAPTURE &&
+        usecase->type != TRANSCODE_LOOPBACK) {
         ALOGE("%s: not a playback/capture path, no need to cfg app type", __func__);
         rc = 0;
         goto exit_send_app_type_cfg;
@@ -882,6 +896,7 @@
         (usecase->id != USECASE_AUDIO_PLAYBACK_MULTI_CH) &&
         (usecase->id != USECASE_AUDIO_PLAYBACK_ULL) &&
         (usecase->id != USECASE_AUDIO_PLAYBACK_VOIP) &&
+        (usecase->id != USECASE_AUDIO_TRANSCODE_LOOPBACK) &&
         (!is_interactive_usecase(usecase->id)) &&
         (!is_offload_usecase(usecase->id)) &&
         (usecase->type != PCM_CAPTURE)) {
@@ -897,7 +912,7 @@
             goto exit_send_app_type_cfg;
     }
 
-    if (usecase->type == PCM_PLAYBACK) {
+    if (usecase->type == PCM_PLAYBACK || usecase->type == TRANSCODE_LOOPBACK) {
         pcm_device_id = platform_get_pcm_device_id(usecase->id, PCM_PLAYBACK);
         snprintf(mixer_ctl_name, sizeof(mixer_ctl_name),
             "Audio Stream %d App Type Cfg", pcm_device_id);
@@ -1006,6 +1021,10 @@
            __func__, app_type, acdb_dev_id, sample_rate, snd_device_be_idx);
     } else {
         app_type = platform_get_default_app_type_v2(adev->platform, usecase->type);
+        if(usecase->type == TRANSCODE_LOOPBACK) {
+            sample_rate = usecase->stream.inout->out_config.sample_rate;
+            app_type = usecase->stream.inout->out_app_type_cfg.app_type;
+        }
         app_type_cfg[len++] = app_type;
         app_type_cfg[len++] = acdb_dev_id;
         app_type_cfg[len++] = sample_rate;
@@ -1015,7 +1034,8 @@
               __func__, app_type, acdb_dev_id, sample_rate, snd_device_be_idx);
     }
 
-    mixer_ctl_set_array(ctl, app_type_cfg, len);
+    if(ctl)
+        mixer_ctl_set_array(ctl, app_type_cfg, len);
     rc = 0;
 exit_send_app_type_cfg:
     return rc;
@@ -1030,6 +1050,7 @@
 
     switch (usecase->type) {
     case PCM_PLAYBACK:
+    case TRANSCODE_LOOPBACK:
         ALOGD("%s: usecase->out_snd_device %s",
               __func__, platform_get_snd_device_name(usecase->out_snd_device));
         /* check for out combo device */
@@ -1369,6 +1390,13 @@
         platform_send_audio_calibration(adev->platform, usecase,
                          platform_get_default_app_type_v2(adev->platform, usecase->type),
                          48000);
+    } else if (type == TRANSCODE_LOOPBACK && usecase->stream.inout != NULL) {
+        int snd_device = usecase->out_snd_device;
+        snd_device = (snd_device == SND_DEVICE_OUT_SPEAKER) ?
+                     platform_get_spkr_prot_snd_device(snd_device) : snd_device;
+        platform_send_audio_calibration(adev->platform, usecase,
+                         platform_get_default_app_type_v2(adev->platform, usecase->type),
+                         usecase->stream.inout->out_config.sample_rate);
     } else {
         /* No need to send audio calibration for voice and voip call usecases */
         if ((type != VOICE_CALL) && (type != VOIP_CALL))
diff --git a/hal/audio_hw.h b/hal/audio_hw.h
index 0a6d85b..ac8a801 100644
--- a/hal/audio_hw.h
+++ b/hal/audio_hw.h
@@ -239,6 +239,8 @@
     pthread_cond_t  cond;
     struct stream_config in_config;
     struct stream_config out_config;
+    struct stream_app_type_cfg out_app_type_cfg;
+    char profile[MAX_STREAM_PROFILE_STR_LEN];
     struct audio_device *dev;
     void *adsp_hdlr_stream_handle;
     void *ip_hdlr_handle;
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index fcc9ade..2d05bed 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -3206,6 +3206,9 @@
         snd_device = voice_get_incall_rec_snd_device(usecase->in_snd_device);
     else if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
         snd_device = usecase->in_snd_device;
+    else if (usecase->type == TRANSCODE_LOOPBACK)
+        snd_device = usecase->out_snd_device;
+
     acdb_dev_id = acdb_device_table[platform_get_spkr_prot_snd_device(snd_device)];
 
     if (platform_split_snd_device(platform, snd_device, &num_devices,
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index f368d17..94fe996 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -2969,6 +2969,8 @@
         snd_device = voice_get_incall_rec_snd_device(usecase->in_snd_device);
     else if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
         snd_device = usecase->in_snd_device;
+    else if (usecase->type == TRANSCODE_LOOPBACK)
+        snd_device = usecase->out_snd_device;
 
     acdb_dev_id = acdb_device_table[platform_get_spkr_prot_snd_device(snd_device)];
     if (acdb_dev_id < 0) {