Merge "post_proc: send ENABLE_FLAG directly to offload effect driver"
diff --git a/hal/Android.mk b/hal/Android.mk
index 1c3f946..32a9ee9 100644
--- a/hal/Android.mk
+++ b/hal/Android.mk
@@ -121,7 +121,8 @@
 	libtinycompress \
 	libaudioroute \
 	libdl \
-	libexpat
+	libexpat \
+        libmdmdetect
 
 LOCAL_C_INCLUDES += \
 	external/tinyalsa/include \
@@ -131,7 +132,8 @@
 	$(call include-path-for, audio-effects) \
 	$(LOCAL_PATH)/$(AUDIO_PLATFORM) \
 	$(LOCAL_PATH)/audio_extn \
-	$(LOCAL_PATH)/voice_extn
+	$(LOCAL_PATH)/voice_extn \
+        $(TARGET_OUT_HEADERS)/libmdmdetect/inc
 
 ifeq ($(strip $(AUDIO_FEATURE_ENABLED_LISTEN)),true)
     LOCAL_CFLAGS += -DAUDIO_LISTEN_ENABLED
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 947e1b6..b26fd1b 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -922,24 +922,30 @@
         send_callback = false;
         switch(cmd->cmd) {
         case OFFLOAD_CMD_WAIT_FOR_BUFFER:
+            ALOGD("copl(%x):calling compress_wait", (unsigned int)out);
             compress_wait(out->compr, -1);
+            ALOGD("copl(%x):out of compress_wait", (unsigned int)out);
             send_callback = true;
             event = STREAM_CBK_EVENT_WRITE_READY;
             break;
         case OFFLOAD_CMD_PARTIAL_DRAIN:
             ret = compress_next_track(out->compr);
-            if(ret == 0)
+            if(ret == 0) {
+                ALOGD("copl(%x):calling compress_partial_drain", (unsigned int)out);
                 compress_partial_drain(out->compr);
+                ALOGD("copl(%x):out of compress_partial_drain", (unsigned int)out);
+            }
             else if(ret == -ETIMEDOUT)
                 compress_drain(out->compr);
             else
                 ALOGE("%s: Next track returned error %d",__func__, ret);
-
             send_callback = true;
             event = STREAM_CBK_EVENT_DRAIN_READY;
             break;
         case OFFLOAD_CMD_DRAIN:
+            ALOGD("copl(%x):calling compress_drain", (unsigned int)out);
             compress_drain(out->compr);
+            ALOGD("copl(%x):calling compress_drain", (unsigned int)out);
             send_callback = true;
             event = STREAM_CBK_EVENT_DRAIN_READY;
             break;
@@ -1117,7 +1123,7 @@
     struct audio_usecase *uc_info;
     struct audio_device *adev = out->dev;
 
-    ALOGV("%s: enter: usecase(%d: %s) devices(%#x)",
+    ALOGD("%s: enter: usecase(%d: %s) devices(%#x)",
           __func__, out->usecase, use_case_table[out->usecase], out->devices);
     out->pcm_device_id = platform_get_pcm_device_id(out->usecase, PCM_PLAYBACK);
     if (out->pcm_device_id < 0) {
@@ -1319,6 +1325,7 @@
                 out->pcm = NULL;
             }
         } else {
+            ALOGD("copl(%x):standby", (unsigned int)out);
             stop_compressed_output_l(out);
             out->gapless_mdata.encoder_delay = 0;
             out->gapless_mdata.encoder_padding = 0;
@@ -1602,9 +1609,9 @@
     }
 
     if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) {
-        ALOGVV("%s: writing buffer (%d bytes) to compress device", __func__, bytes);
+        ALOGD("copl(%x): writing buffer (%d bytes) to compress device", (unsigned int)out, bytes);
         if (out->send_new_metadata) {
-            ALOGVV("send new gapless metadata");
+            ALOGD("copl(%x):send new gapless metadata", (unsigned int)out);
             compress_set_gapless_metadata(out->compr, &out->gapless_mdata);
             out->send_new_metadata = 0;
         }
@@ -1612,6 +1619,7 @@
         ret = compress_write(out->compr, buffer, bytes);
         ALOGVV("%s: writing buffer (%d bytes) to compress device returned %d", __func__, bytes, ret);
         if (ret >= 0 && ret < (ssize_t)bytes) {
+            ALOGD("No space available in compress driver, post msg to cb thread");
             send_offload_cmd_l(out, OFFLOAD_CMD_WAIT_FOR_BUFFER);
         }
         if (!out->playback_started) {
@@ -1744,6 +1752,7 @@
     int status = -ENOSYS;
     ALOGV("%s", __func__);
     if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) {
+        ALOGD("copl(%x):pause compress driver", (unsigned int)out);
         pthread_mutex_lock(&out->lock);
         if (out->compr != NULL && out->offload_state == OFFLOAD_STATE_PLAYING) {
             status = compress_pause(out->compr);
@@ -1760,6 +1769,7 @@
     int status = -ENOSYS;
     ALOGV("%s", __func__);
     if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) {
+        ALOGD("copl(%x):resume compress driver", (unsigned int)out);
         status = 0;
         pthread_mutex_lock(&out->lock);
         if (out->compr != NULL && out->offload_state == OFFLOAD_STATE_PAUSED) {
@@ -1792,9 +1802,11 @@
     struct stream_out *out = (struct stream_out *)stream;
     ALOGV("%s", __func__);
     if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) {
+        ALOGD("copl(%x):calling compress flush", (unsigned int)out);
         pthread_mutex_lock(&out->lock);
         stop_compressed_output_l(out);
         pthread_mutex_unlock(&out->lock);
+        ALOGD("copl(%x):out of compress flush", (unsigned int)out);
         return 0;
     }
     return -ENOSYS;
@@ -2133,6 +2145,9 @@
             goto error_open;
         }
     } else if (out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) {
+        ALOGD("%s: copl(%x): sample_rate(%d) channel_mask(%#x) devices(%#x) flags(%#x)",
+              __func__, (unsigned int)out, config->sample_rate, config->channel_mask, devices, flags);
+
         if (config->offload_info.version != AUDIO_INFO_INITIALIZER.version ||
             config->offload_info.size != AUDIO_INFO_INITIALIZER.size) {
             ALOGE("%s: Unsupported Offload information", __func__);
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index 3f4de55..4161d87 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -32,6 +32,7 @@
 #include "audio_extn.h"
 #include "voice_extn.h"
 #include "sound/compress_params.h"
+#include "mdm_detect.h"
 
 #define MIXER_XML_PATH "/system/etc/mixer_paths.xml"
 #define MIXER_XML_PATH_AUXPCM "/system/etc/mixer_paths_auxpcm.xml"
@@ -539,10 +540,28 @@
     }
 }
 
+static void platform_csd_init(struct platform_data *plat_data)
+{
+    struct dev_info mdm_detect_info;
+    int ret = 0;
+
+    /* Call ESOC API to get the number of modems.
+     * If the number of modems is not zero, load CSD Client specific
+     * symbols. Voice call is handled by MDM and apps processor talks to
+     * MDM through CSD Client
+     */
+    ret = get_system_info(&mdm_detect_info);
+    if (ret > 0) {
+        ALOGE("%s: Failed to get system info, ret %d", __func__, ret);
+    }
+    ALOGD("%s: num_modems %d\n", __func__, mdm_detect_info.num_modems);
+
+    if (mdm_detect_info.num_modems > 0)
+        plat_data->csd = open_csd_client();
+}
+
 void *platform_init(struct audio_device *adev)
 {
-    char platform[PROPERTY_VALUE_MAX];
-    char baseband[PROPERTY_VALUE_MAX];
     char value[PROPERTY_VALUE_MAX];
     struct platform_data *my_data = NULL;
     int retry_num = 0, snd_card_num = 0;
@@ -678,16 +697,8 @@
     /* Initialize ACDB ID's */
     platform_info_init();
 
-    /* If platform is apq8084 and baseband is MDM, load CSD Client specific
-     * symbols. Voice call is handled by MDM and apps processor talks to
-     * MDM through CSD Client
-     */
-    property_get("ro.board.platform", platform, "");
-    property_get("ro.baseband", baseband, "");
-    if (!strncmp("apq8084", platform, sizeof("apq8084")) &&
-        !strncmp("mdm", baseband, sizeof("mdm"))) {
-         my_data->csd = open_csd_client();
-    }
+    /* load csd client */
+    platform_csd_init(my_data);
 
     /* init usb */
     audio_extn_usb_init(adev);