Merge "hal: reset backend sample rate if device backend is not supported"
diff --git a/configs/msm8909/audio_io_policy.conf b/configs/msm8909/audio_io_policy.conf
index dd0f3c1..46cd8cf 100644
--- a/configs/msm8909/audio_io_policy.conf
+++ b/configs/msm8909/audio_io_policy.conf
@@ -94,4 +94,20 @@
     bit_width 16
     app_type 69943
   }
+  record_fluence1 {
+    flags AUDIO_INPUT_FLAG_NONE
+    profile record_fluence
+    formats AUDIO_FORMAT_PCM_16_BIT
+    sampling_rates 16000|48000
+    bit_width 16
+    app_type 69943
+  }
+  record_fluence2 {
+    flags AUDIO_INPUT_FLAG_COMPRESS
+    profile record_fluence
+    formats AUDIO_FORMAT_PCM_16_BIT
+    sampling_rates 16000|48000
+    bit_width 16
+    app_type 69943
+  }
 }
diff --git a/configs/msm8909/msm8909.mk b/configs/msm8909/msm8909.mk
index cef92c3..fcece79 100644
--- a/configs/msm8909/msm8909.mk
+++ b/configs/msm8909/msm8909.mk
@@ -106,7 +106,16 @@
 ro.vendor.audio.sdk.fluencetype=none\
 persist.vendor.audio.fluence.voicecall=true\
 persist.vendor.audio.fluence.voicerec=false\
-persist.vendor.audio.fluence.speaker=true
+persist.vendor.audio.fluence.speaker=true\
+persist.vendor.audio.fluence.audiorec=false
+
+#enable generic handset mic
+PRODUCT_PROPERTY_OVERRIDES += \
+vendor.audio.apptype.multirec.enabled=false
+
+#enable multi record
+PRODUCT_PROPERTY_OVERRIDES += \
+vendor.audio.record.multiple.enabled=true
 
 #disable tunnel encoding
 PRODUCT_PROPERTY_OVERRIDES += \
diff --git a/configs/sdm670/mixer_paths_mtp.xml b/configs/sdm670/mixer_paths_mtp.xml
index 048e039..080459d 100644
--- a/configs/sdm670/mixer_paths_mtp.xml
+++ b/configs/sdm670/mixer_paths_mtp.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="ISO-8859-1"?>
-<!-- Copyright (c) 2015-2017, The Linux Foundation. All rights reserved.    -->
+<!-- Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.    -->
 <!--                                                                        -->
 <!-- Redistribution and use in source and binary forms, with or without     -->
 <!-- modification, are permitted provided that the following conditions are -->
@@ -2451,6 +2451,10 @@
         <ctl name="USB_AUDIO_RX Audio Mixer MultiMedia2" value="1" />
     </path>
 
+    <path name="hifi-record">
+        <ctl name="MultiMedia2 Mixer INT3_MI2S_TX" value="1" />
+    </path>
+
     <path name="hifi-record usb-headset-mic">
         <ctl name="MultiMedia2 Mixer USB_AUDIO_TX" value="1" />
     </path>
diff --git a/configs/sdm670/mixer_paths_skuw.xml b/configs/sdm670/mixer_paths_skuw.xml
index b799532..f1f6990 100644
--- a/configs/sdm670/mixer_paths_skuw.xml
+++ b/configs/sdm670/mixer_paths_skuw.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="ISO-8859-1"?>
-<!-- Copyright (c) 2015-2017, The Linux Foundation. All rights reserved.    -->
+<!-- Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.    -->
 <!--                                                                        -->
 <!-- Redistribution and use in source and binary forms, with or without     -->
 <!-- modification, are permitted provided that the following conditions are -->
@@ -2639,6 +2639,10 @@
         <ctl name="USB_AUDIO_RX Audio Mixer MultiMedia2" value="1" />
     </path>
 
+    <path name="hifi-record">
+        <ctl name="MultiMedia2 Mixer INT3_MI2S_TX" value="1" />
+    </path>
+
     <path name="hifi-record usb-headset-mic">
         <ctl name="MultiMedia2 Mixer USB_AUDIO_TX" value="1" />
     </path>
diff --git a/configs/sdm845/mixer_paths_tavil.xml b/configs/sdm845/mixer_paths_tavil.xml
index 87bdae0..a08ffaf 100644
--- a/configs/sdm845/mixer_paths_tavil.xml
+++ b/configs/sdm845/mixer_paths_tavil.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="ISO-8859-1"?>
-<!-- Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.    -->
+<!-- Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.    -->
 <!--                                                                        -->
 <!-- Redistribution and use in source and binary forms, with or without     -->
 <!-- modification, are permitted provided that the following conditions are -->
@@ -2743,6 +2743,10 @@
         <ctl name="USB_AUDIO_RX Audio Mixer MultiMedia2" value="1" />
     </path>
 
+    <path name="hifi-record">
+        <ctl name="MultiMedia2 Mixer SLIM_0_TX" value="1" />
+    </path>
+
     <path name="hifi-record usb-headset-mic">
         <ctl name="MultiMedia2 Mixer USB_AUDIO_TX" value="1" />
     </path>
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 0d919ec..cef64a7 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -2496,7 +2496,7 @@
             in->pcm = pcm_open(adev->snd_card, in->pcm_device_id,
                                flags, &config);
             ATRACE_END();
-            if (errno == ENETRESET) {
+            if (errno == ENETRESET && !pcm_is_ready(in->pcm)) {
                 ALOGE("%s: pcm_open failed errno:%d\n", __func__, errno);
                 adev->card_status = CARD_STATUS_OFFLINE;
                 in->card_status = CARD_STATUS_OFFLINE;
@@ -3090,7 +3090,7 @@
             out->pcm = pcm_open(adev->snd_card, out->pcm_device_id,
                                flags, &out->config);
             ATRACE_END();
-            if (errno == ENETRESET) {
+            if (errno == ENETRESET && !pcm_is_ready(out->pcm)) {
                 ALOGE("%s: pcm_open failed errno:%d\n", __func__, errno);
                 out->card_status = CARD_STATUS_OFFLINE;
                 adev->card_status = CARD_STATUS_OFFLINE;
@@ -3144,7 +3144,7 @@
                                    out->pcm_device_id,
                                    COMPRESS_IN, &out->compr_config);
         ATRACE_END();
-        if (errno == ENETRESET) {
+        if (errno == ENETRESET && !is_compress_ready(out->compr)) {
                 ALOGE("%s: compress_open failed errno:%d\n", __func__, errno);
                 adev->card_status = CARD_STATUS_OFFLINE;
                 out->card_status = CARD_STATUS_OFFLINE;
@@ -4968,7 +4968,7 @@
           __func__, adev->snd_card, out->pcm_device_id, out->config.channels);
     out->pcm = pcm_open(adev->snd_card, out->pcm_device_id,
                         (PCM_OUT | PCM_MMAP | PCM_NOIRQ | PCM_MONOTONIC), &out->config);
-    if (errno == ENETRESET) {
+    if (errno == ENETRESET && !pcm_is_ready(out->pcm)) {
         ALOGE("%s: pcm_open failed errno:%d\n", __func__, errno);
         out->card_status = CARD_STATUS_OFFLINE;
         adev->card_status = CARD_STATUS_OFFLINE;
@@ -5590,7 +5590,7 @@
           __func__, adev->snd_card, in->pcm_device_id, in->config.channels);
     in->pcm = pcm_open(adev->snd_card, in->pcm_device_id,
                         (PCM_IN | PCM_MMAP | PCM_NOIRQ | PCM_MONOTONIC), &in->config);
-    if (errno == ENETRESET) {
+    if (errno == ENETRESET && !pcm_is_ready(in->pcm)) {
         ALOGE("%s: pcm_open failed errno:%d\n", __func__, errno);
         in->card_status = CARD_STATUS_OFFLINE;
         adev->card_status = CARD_STATUS_OFFLINE;
@@ -5685,6 +5685,13 @@
                       (devices != AUDIO_DEVICE_OUT_USB_ACCESSORY);
     bool direct_dev = is_hdmi || is_usb_dev;
 
+    if (is_usb_dev && (!audio_extn_usb_connected(NULL))) {
+        is_usb_dev = false;
+        devices = AUDIO_DEVICE_OUT_SPEAKER;
+        ALOGW("%s: ignore set device to non existing USB card, use output device(%#x)",
+              __func__, devices);
+    }
+
     *stream_out = NULL;
 
     out = (struct stream_out *)calloc(1, sizeof(struct stream_out));
@@ -6786,6 +6793,13 @@
                                                             flags,
                                                             source);
 
+    if (is_usb_dev && (!audio_extn_usb_connected(NULL))) {
+        is_usb_dev = false;
+        devices = AUDIO_DEVICE_IN_BUILTIN_MIC;
+        ALOGW("%s: ignore set device to non existing USB card, use input device(%#x)",
+              __func__, devices);
+    }
+
     *stream_in = NULL;
 
     if (!(is_usb_dev && may_use_hifi_record)) {
diff --git a/qahw_api/test/qahw_playback_test.c b/qahw_api/test/qahw_playback_test.c
index 8834252..b410006 100644
--- a/qahw_api/test/qahw_playback_test.c
+++ b/qahw_api/test/qahw_playback_test.c
@@ -161,6 +161,18 @@
                    "music_offload_wma_encode_option2=%d;" \
                    "music_offload_wma_format_tag=%d;"
 
+#define APE_KVPAIR "music_offload_ape_bits_per_sample=%d;" \
+                   "music_offload_ape_blocks_per_frame=%d;" \
+                   "music_offload_ape_compatible_version=%d;" \
+                   "music_offload_ape_compression_level=%d;" \
+                   "music_offload_ape_final_frame_blocks=%d;" \
+                   "music_offload_ape_format_flags=%d;" \
+                   "music_offload_ape_num_channels=%d;" \
+                   "music_offload_ape_sample_rate=%d;" \
+                   "music_offload_ape_total_frames=%d;" \
+                   "music_offload_sample_rate=%d;" \
+                   "music_offload_seek_table_present=%d;"
+
 #ifndef AUDIO_OUTPUT_FLAG_ASSOCIATED
 #define AUDIO_OUTPUT_FLAG_ASSOCIATED 0x10000000
 #endif
@@ -303,6 +315,9 @@
     case FILE_WMA:
         kvpair_type = WMA_KVPAIR;
         break;
+    case FILE_APE:
+        kvpair_type = APE_KVPAIR;
+        break;
     default:
         break;
     }
@@ -648,6 +663,7 @@
         case FILE_VORBIS:
         case FILE_ALAC:
         case FILE_FLAC:
+        case FILE_APE:
             fprintf(log_file, "%s:calling setparam for kvpairs\n", __func__);
             if (!(params->kvpair_values)) {
                fprintf(log_file, "stream %d: error!!No metadata for the clip\n", params->stream_index);
@@ -1118,6 +1134,9 @@
         case FILE_IEC61937:
             stream_info->config.offload_info.format = AUDIO_FORMAT_IEC61937;
             break;
+        case FILE_APE:
+            stream_info->config.offload_info.format = AUDIO_FORMAT_APE;
+            break;
         default:
            fprintf(log_file, "Does not support given filetype\n");
            fprintf(stderr, "Does not support given filetype\n");
@@ -1638,6 +1657,9 @@
     printf("                                          ->Note:all the USB device commmands(above) should be accompanied with the host side commands\n\n");
     printf("hal_play_test -f interactive_audio.wav -d 2 -l out.txt -k \"mixer_ctrl=pan_scale;c=1;o=6;I=fc;O=fl,fr,fc,lfe,bl,br;M=0.5,0.5,0,0,0,0\" -i 1\n");
     printf("                                          ->kv_pair for downmix or pan_scale should folow the above sequence, one can pass downmix & pan_scale params/coeff matrices. For each control params should be sent separately \n");
+    printf("hal_play_test -f /data/ape_dsp.isf.0x152E.bitstream.0x10100400.0x2.0x12F32.rx.bin -k 16,73728,3990,2000,53808,32,2,44100,157,44100,1 -t 18 -r 48000 -c 2 -v 0.5 -d 131072");
+    printf("                                          -> kvpair(-k) values represent media-info of clip & values should be in below mentioned sequence\n");
+    printf("                                          ->bits_per_sample,blocks_per_frame,compatible_version,compression_level,final_frame_blocks,format_flags,num_channels,sample_rate,total_frames,sample_rate,seek_table_present \n");
 }
 
 int get_wav_header_length (FILE* file_stream)
diff --git a/qahw_api/test/qahw_playback_test.h b/qahw_api/test/qahw_playback_test.h
index b8bddbc..0ac51df 100644
--- a/qahw_api/test/qahw_playback_test.h
+++ b/qahw_api/test/qahw_playback_test.h
@@ -60,7 +60,8 @@
     FILE_MP2,
     FILE_APTX,
     FILE_TRUEHD,
-    FILE_IEC61937
+    FILE_IEC61937,
+    FILE_APE
 };
 
 typedef enum {