Promotion of audio-userspace.lnx.2.2-00011.

CRs      Change ID                                   Subject
--------------------------------------------------------------------------------------------------------------
1110957   I880f8c66e6cba65947846dd2fef74a74be125aa9   hal: fix segfalut from call to send audio calibration
1108296   I1314fb8759a59845cd7cba879f829d6fe2a0f53c   hal: Add support for AAC LATM format
1106439   I9f383438c2f10804b093505ff605eee7221a7fb5   hal: Update check to fix incorrect configuration of spea
1108685   Iecb25edc39cccebb75f283efe2be6df84801d55c   msm8998: Add custom config ids

Change-Id: I929584374205bfb9df80aa671edcab0495cce4ad
CRs-Fixed: 1108685, 1110957, 1108296, 1106439
diff --git a/configs/msm8998/sound_trigger_platform_info.xml b/configs/msm8998/sound_trigger_platform_info.xml
index b7ca132..41a41e9 100644
--- a/configs/msm8998/sound_trigger_platform_info.xml
+++ b/configs/msm8998/sound_trigger_platform_info.xml
@@ -67,6 +67,7 @@
             <param detection_event_ids="0x00012C0D, 0x2, 0x00012C29" />
             <param read_cmd_ids="0x00020013, 0x2, 0x00020015" />
             <param read_rsp_ids="0x00020013, 0x2, 0x00020016" />
+            <param custom_config_ids="0x00012C0D, 0x2, 0x00012C20" />
         </gcs_usecase>
         <gcs_usecase>
             <param uid="0x2" />
@@ -75,6 +76,7 @@
             <param detection_event_ids="0x00012C0D, 0x3, 0x00012C29" />
             <param read_cmd_ids="0x00020013, 0x3, 0x00020015" />
             <param read_rsp_ids="0x00020013, 0x3, 0x00020016" />
+            <param custom_config_ids="0x00012C0D, 0x3, 0x00012C20" />
         </gcs_usecase>
         <!-- Module and param ids with which the algorithm is integrated
             in non-graphite firmware (note these must come after gcs params) -->
diff --git a/hal/audio_extn/audio_extn.h b/hal/audio_extn/audio_extn.h
index 659592c..b9402d5 100644
--- a/hal/audio_extn/audio_extn.h
+++ b/hal/audio_extn/audio_extn.h
@@ -83,6 +83,16 @@
                                       AUDIO_FORMAT_AAC_SUB_HE_V2)
 #endif
 
+#ifndef AUDIO_FORMAT_AAC_LATM
+#define AUDIO_FORMAT_AAC_LATM 0x23000000UL
+#define AUDIO_FORMAT_AAC_LATM_LC   (AUDIO_FORMAT_AAC_LATM |\
+                                      AUDIO_FORMAT_AAC_SUB_LC)
+#define AUDIO_FORMAT_AAC_LATM_HE_V1 (AUDIO_FORMAT_AAC_LATM |\
+                                      AUDIO_FORMAT_AAC_SUB_HE_V1)
+#define AUDIO_FORMAT_AAC_LATM_HE_V2  (AUDIO_FORMAT_AAC_LATM |\
+                                      AUDIO_FORMAT_AAC_SUB_HE_V2)
+#endif
+
 #ifndef COMPRESS_METADATA_NEEDED
 #define audio_extn_parse_compress_metadata(out, parms) (0)
 #else
diff --git a/hal/audio_extn/utils.c b/hal/audio_extn/utils.c
index 0ff921d..69a7eec 100644
--- a/hal/audio_extn/utils.c
+++ b/hal/audio_extn/utils.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2016, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2014-2017, The Linux Foundation. All rights reserved.
  * Not a Contribution.
  *
  * Copyright (C) 2014 The Android Open Source Project
@@ -147,6 +147,10 @@
     STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADTS_HE_V1),
     STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADTS_HE_V2),
     STRING_TO_ENUM(AUDIO_FORMAT_DSD),
+    STRING_TO_ENUM(AUDIO_FORMAT_AAC_LATM),
+    STRING_TO_ENUM(AUDIO_FORMAT_AAC_LATM_LC),
+    STRING_TO_ENUM(AUDIO_FORMAT_AAC_LATM_HE_V1),
+    STRING_TO_ENUM(AUDIO_FORMAT_AAC_LATM_HE_V2),
 #endif
 };
 
@@ -1114,6 +1118,9 @@
     case AUDIO_FORMAT_AAC_ADTS:
         id = SND_AUDIOCODEC_AAC;
         break;
+    case AUDIO_FORMAT_AAC_LATM:
+        id = SND_AUDIOCODEC_AAC;
+        break;
     case AUDIO_FORMAT_PCM_OFFLOAD:
     case AUDIO_FORMAT_PCM:
         id = SND_AUDIOCODEC_PCM;
@@ -1162,7 +1169,7 @@
 {
     int type = usecase->type;
 
-    if (type == PCM_PLAYBACK) {
+    if (type == PCM_PLAYBACK && usecase->stream.out != NULL) {
         struct stream_out *out = usecase->stream.out;
         int snd_device = usecase->out_snd_device;
         snd_device = (snd_device == SND_DEVICE_OUT_SPEAKER) ?
@@ -1170,7 +1177,7 @@
         platform_send_audio_calibration(adev->platform, usecase,
                                         out->app_type_cfg.app_type,
                                         usecase->stream.out->app_type_cfg.sample_rate);
-    } else if (type == PCM_CAPTURE) {
+    } else if (type == PCM_CAPTURE && usecase->stream.in != NULL) {
         platform_send_audio_calibration(adev->platform, usecase,
                          usecase->stream.in->app_type_cfg.app_type,
                          usecase->stream.in->app_type_cfg.sample_rate);
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 61e9b89..e60ce6e 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2017, The Linux Foundation. All rights reserved.
  * Not a Contribution.
  *
  * Copyright (C) 2013 The Android Open Source Project
@@ -503,6 +503,9 @@
         format == AUDIO_FORMAT_AAC_ADTS_LC ||
         format == AUDIO_FORMAT_AAC_ADTS_HE_V1 ||
         format == AUDIO_FORMAT_AAC_ADTS_HE_V2 ||
+        format == AUDIO_FORMAT_AAC_LATM_LC ||
+        format == AUDIO_FORMAT_AAC_LATM_HE_V1 ||
+        format == AUDIO_FORMAT_AAC_LATM_HE_V2 ||
         format == AUDIO_FORMAT_PCM_24_BIT_PACKED ||
         format == AUDIO_FORMAT_PCM_8_24_BIT ||
         format == AUDIO_FORMAT_PCM_FLOAT ||
@@ -3988,8 +3991,10 @@
 
         if ((config->offload_info.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_AAC)
              out->compr_config.codec->format = SND_AUDIOSTREAMFORMAT_RAW;
-        if ((config->offload_info.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_AAC_ADTS)
+        else if ((config->offload_info.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_AAC_ADTS)
             out->compr_config.codec->format = SND_AUDIOSTREAMFORMAT_MP4ADTS;
+        else if ((config->offload_info.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_AAC_LATM)
+            out->compr_config.codec->format = SND_AUDIOSTREAMFORMAT_MP4LATM;
 
         if ((config->offload_info.format & AUDIO_FORMAT_MAIN_MASK) ==
              AUDIO_FORMAT_PCM) {
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index 5cef2b8..0022996 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -2524,8 +2524,9 @@
         || NATIVE_AUDIO_MODE_MULTIPLE_44_1 == na_mode) {
         na_props.platform_na_prop_enabled = na_props.ui_na_prop_enabled = true;
         na_props.na_mode = na_mode;
-        ALOGD("%s:napb: native audio playback enabled in (%s) mode v2.0", __func__,
-              ((na_mode == NATIVE_AUDIO_MODE_SRC)?"SRC mode":"True 44.1 mode"));
+        ALOGD("%s:napb: native audio playback enabled in (%s) mode", __func__,
+              ((na_mode == NATIVE_AUDIO_MODE_SRC)?"SRC":
+               (na_mode == NATIVE_AUDIO_MODE_TRUE_44_1)?"True":"Multiple"));
     } else {
         na_props.platform_na_prop_enabled = false;
         na_props.na_mode = NATIVE_AUDIO_MODE_INVALID;
@@ -4929,8 +4930,13 @@
             ALOGD("%s:becf: afe: napb not active - set non fractional rate",
                        __func__);
         }
-    } else if ((usecase->devices & AUDIO_DEVICE_OUT_SPEAKER) ||
-               (usecase->devices & AUDIO_DEVICE_OUT_EARPIECE) ) {
+    }
+
+    /*
+     * Check if the device is speaker or handset,assumption handset shares
+     * backend with speaker, and these devices are restricited to 48kHz.
+     */
+    if (platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, snd_device)) {
         sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
 
         if (bit_width >= 24) {
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index f9ee4b1..fd8c773 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2017, The Linux Foundation. All rights reserved.
  * Not a Contribution.
  *
  * Copyright (C) 2013 The Android Open Source Project
@@ -2237,8 +2237,9 @@
         || NATIVE_AUDIO_MODE_MULTIPLE_44_1 == na_mode) {
         na_props.platform_na_prop_enabled = na_props.ui_na_prop_enabled = true;
         na_props.na_mode = na_mode;
-        ALOGD("%s:napb: native audio playback enabled in (%s) mode v2.0", __func__,
-              ((na_mode == NATIVE_AUDIO_MODE_SRC)?"SRC mode":"True 44.1 mode"));
+        ALOGD("%s:napb: native audio playback enabled in (%s) mode", __func__,
+              ((na_mode == NATIVE_AUDIO_MODE_SRC)?"SRC":
+               (na_mode == NATIVE_AUDIO_MODE_TRUE_44_1)?"True":"Multiple"));
     }
     else {
         na_props.platform_na_prop_enabled = false;
@@ -4831,8 +4832,13 @@
             ALOGD("%s:becf: afe: napb not active - set non fractional rate",
                        __func__);
         }
-    } else if ((usecase->devices & AUDIO_DEVICE_OUT_SPEAKER) ||
-               (usecase->devices & AUDIO_DEVICE_OUT_EARPIECE) ) {
+    }
+
+    /*
+     * Check if the device is speaker or handset,assumption handset shares
+     * backend with speaker, and these devices are restricited to 48kHz.
+     */
+    if (platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, snd_device)) {
 
         if (bit_width >= 24) {
             bit_width = platform_get_snd_device_bit_width(SND_DEVICE_OUT_SPEAKER);
diff --git a/qahw_api/test/qahw_playback_test.c b/qahw_api/test/qahw_playback_test.c
index 4590f87..8da62fb 100644
--- a/qahw_api/test/qahw_playback_test.c
+++ b/qahw_api/test/qahw_playback_test.c
@@ -96,6 +96,7 @@
     FILE_VORBIS,
     FILE_WMA,
     FILE_AC3,
+    FILE_AAC_LATM,
     FILE_EAC3,
     FILE_EAC3_JOC,
     FILE_DTS,
@@ -369,6 +370,7 @@
                         qahw_out_drain(out_handle, QAHW_DRAIN_ALL);
                         pthread_cond_wait(&drain_cond, &drain_lock);
                         fprintf(log_file, "Out of compress drain\n");
+                        fprintf(stdout, "Playback completed sucessfully\n");
                         pthread_mutex_unlock(&drain_lock);
                     }
                 } else {
@@ -450,6 +452,20 @@
         default:
             break;
         }
+    } else if (filetype == FILE_AAC_LATM) {
+        switch (format_type) {
+        case AAC_LC:
+            aac_format = AUDIO_FORMAT_AAC_LATM_LC;
+            break;
+        case AAC_HE_V1:
+            aac_format = AUDIO_FORMAT_AAC_LATM_HE_V1;
+            break;
+        case AAC_HE_V2:
+            aac_format = AUDIO_FORMAT_AAC_LATM_HE_V2;
+            break;
+        default:
+            break;
+        }
     } else {
         fprintf(log_file, "Invalid filetype provided %d\n", filetype);
         fprintf(stderr, "Invalid filetype provided %d\n", filetype);
@@ -553,7 +569,7 @@
     printf(" -d  --device <decimal value>              - see system/media/audio/include/system/audio.h for device values\n");
     printf("                                             Optional Argument and Default value is 2, i.e Speaker\n\n");
     printf(" -t  --file-type <file type>               - 1:WAV 2:MP3 3:AAC 4:AAC_ADTS 5:FLAC\n");
-    printf("                                             6:ALAC 7:VORBIS 8:WMA\n");
+    printf("                                             6:ALAC 7:VORBIS 8:WMA 10:AAC_LATM \n");
     printf("                                             Required for non WAV formats\n\n");
     printf(" -a  --aac-type <aac type>                 - Required for AAC streams\n");
     printf("                                             1: LC 2: HE_V1 3: HE_V2\n\n");
@@ -847,6 +863,7 @@
 
         case FILE_AAC:
         case FILE_AAC_ADTS:
+        case FILE_AAC_LATM:
             if (!is_valid_aac_format_type(format_type)) {
                 fprintf(log_file, "Invalid format type for AAC %d\n", format_type);
                 goto EXIT;