audio: Add support for DSDS for incall music feature
am: 3ff768954a

Change-Id: Iea8f6b9347cd0527f721f06a4ee9a2d14f9819bb
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 2113c7d..5d611c6 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -315,6 +315,7 @@
     [USECASE_AUDIO_RECORD_VOIP] = "audio-record-voip",
 
     [USECASE_INCALL_MUSIC_UPLINK] = "incall-music-uplink",
+    [USECASE_INCALL_MUSIC_UPLINK2] = "incall-music-uplink2",
 
     [USECASE_AUDIO_A2DP_ABR_FEEDBACK] = "a2dp-abr-feedback",
 };
@@ -1725,7 +1726,8 @@
             out_snd_device = SND_DEVICE_OUT_SPEAKER;
     }
 
-    if (usecase->id == USECASE_INCALL_MUSIC_UPLINK) {
+    if (usecase->id == USECASE_INCALL_MUSIC_UPLINK ||
+        usecase->id == USECASE_INCALL_MUSIC_UPLINK2) {
         out_snd_device = SND_DEVICE_OUT_VOICE_MUSIC_TX;
     }
 
@@ -2338,8 +2340,10 @@
         audio_low_latency_hint_end();
     }
 
-    if (out->usecase == USECASE_INCALL_MUSIC_UPLINK)
+    if (out->usecase == USECASE_INCALL_MUSIC_UPLINK ||
+        out->usecase == USECASE_INCALL_MUSIC_UPLINK2) {
         voice_set_device_mute_flag(adev, false);
+    }
 
     /* 1. Get and set stream specific mixer controls */
     disable_audio_route(adev, uc_info);
@@ -2444,6 +2448,16 @@
         goto error_config;
     }
 
+    //Update incall music usecase to reflect correct voice session
+    if (out->flags & AUDIO_OUTPUT_FLAG_INCALL_MUSIC) {
+        ret = voice_extn_check_and_set_incall_music_usecase(adev, out);
+        if (ret != 0) {
+            ALOGE("%s: Incall music delivery usecase cannot be set error:%d",
+                __func__, ret);
+            goto error_config;
+        }
+    }
+
     if (out->devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
         if (!audio_extn_a2dp_is_ready()) {
             if (out->devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
@@ -2506,8 +2520,10 @@
 
     audio_extn_extspk_update(adev->extspk);
 
-    if (out->usecase == USECASE_INCALL_MUSIC_UPLINK)
+    if (out->usecase == USECASE_INCALL_MUSIC_UPLINK ||
+        out->usecase == USECASE_INCALL_MUSIC_UPLINK2) {
         voice_set_device_mute_flag(adev, true);
+    }
 
     ALOGV("%s: Opening PCM device card_id(%d) device_id(%d) format(%#x)",
           __func__, adev->snd_card, out->pcm_device_id, out->config.format);
@@ -3502,7 +3518,9 @@
             if (out->muted)
                 memset((void *)buffer, 0, bytes);
             // FIXME: this can be removed once audio flinger mixer supports mono output
-            if (out->usecase == USECASE_AUDIO_PLAYBACK_VOIP || out->usecase == USECASE_INCALL_MUSIC_UPLINK) {
+            if (out->usecase == USECASE_AUDIO_PLAYBACK_VOIP ||
+                out->usecase == USECASE_INCALL_MUSIC_UPLINK ||
+                out->usecase == USECASE_INCALL_MUSIC_UPLINK2) {
                 size_t channel_count = audio_channel_count_from_out_mask(out->channel_mask);
                 int16_t *src = (int16_t *)buffer;
                 int16_t *dst = (int16_t *)buffer;
diff --git a/hal/audio_hw.h b/hal/audio_hw.h
index 764093f..54ee72c 100644
--- a/hal/audio_hw.h
+++ b/hal/audio_hw.h
@@ -134,6 +134,7 @@
     USECASE_AUDIO_RECORD_VOIP,
 
     USECASE_INCALL_MUSIC_UPLINK,
+    USECASE_INCALL_MUSIC_UPLINK2,
 
     USECASE_AUDIO_A2DP_ABR_FEEDBACK,
 
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index 4ae5d1c..41d8bd2 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -251,6 +251,8 @@
 
     [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
                                      INCALL_MUSIC_UPLINK_PCM_DEVICE},
+    [USECASE_INCALL_MUSIC_UPLINK2] = {INCALL_MUSIC_UPLINK2_PCM_DEVICE,
+                                     INCALL_MUSIC_UPLINK2_PCM_DEVICE},
 };
 
 /* Array to store sound devices */
@@ -712,6 +714,7 @@
     {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_VOIP)},
     {TO_NAME_INDEX(USECASE_AUDIO_RECORD_VOIP)},
     {TO_NAME_INDEX(USECASE_INCALL_MUSIC_UPLINK)},
+    {TO_NAME_INDEX(USECASE_INCALL_MUSIC_UPLINK2)},
     {TO_NAME_INDEX(USECASE_AUDIO_A2DP_ABR_FEEDBACK)},
 };
 
diff --git a/hal/msm8974/platform.h b/hal/msm8974/platform.h
index c2beec9..3ab3178 100644
--- a/hal/msm8974/platform.h
+++ b/hal/msm8974/platform.h
@@ -336,6 +336,7 @@
 #define AFE_PROXY_RECORD_PCM_DEVICE 8
 
 #define INCALL_MUSIC_UPLINK_PCM_DEVICE 27
+#define INCALL_MUSIC_UPLINK2_PCM_DEVICE 27
 
 #define HFP_PCM_RX 5
 #ifdef PLATFORM_MSM8x26
diff --git a/hal/voice_extn/voice_extn.c b/hal/voice_extn/voice_extn.c
index c4b8cff..5d0596a 100644
--- a/hal/voice_extn/voice_extn.c
+++ b/hal/voice_extn/voice_extn.c
@@ -576,7 +576,16 @@
 int voice_extn_check_and_set_incall_music_usecase(struct audio_device *adev,
                                                   struct stream_out *out)
 {
-    out->usecase = USECASE_INCALL_MUSIC_UPLINK;
+    uint32_t session_id = get_session_id_with_state(adev, CALL_ACTIVE);
+    if (session_id == VOICEMMODE1_VSID)
+        out->usecase = USECASE_INCALL_MUSIC_UPLINK;
+    else if (session_id == VOICEMMODE2_VSID)
+        out->usecase = USECASE_INCALL_MUSIC_UPLINK2;
+    else {
+        ALOGE("%s: Invalid session id %x", __func__, session_id);
+        out->usecase = USECASE_INCALL_MUSIC_UPLINK;
+    }
+
     out->config = pcm_config_incall_music;
     //FIXME: add support for MONO stream configuration when audioflinger mixer supports it
     out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_STEREO;