audio: Enable secure MS12 playback for LATV

- Fix compilation issues in audio HAL when
  secure MS12 playback feature is enabled.
- Enable Dolby related properties by default.

Change-Id: I5a90d619495c14cbf508a3952ad625db57590234
diff --git a/configs/apq8098_latv/apq8098_latv.mk b/configs/apq8098_latv/apq8098_latv.mk
old mode 100755
new mode 100644
index 7a74e58..61b407a
--- a/configs/apq8098_latv/apq8098_latv.mk
+++ b/configs/apq8098_latv/apq8098_latv.mk
@@ -63,6 +63,9 @@
 AUDIO_FEATURE_ENABLED_GEF_SUPPORT := true
 BOARD_SUPPORTS_QAHW := true
 AUDIO_FEATURE_ENABLED_QAF := true
+AUDIO_FEATURE_IP_HDLR_ENABLED := true
+MM_AUDIO_IP_HDLR_ENABLED := true
+AUDIO_FEATURE_ENABLED_MS12_SECURITY := true
 AUDIO_FEATURE_ENABLED_RAS := true
 AUDIO_FEATURE_ENABLED_DYNAMIC_LOG := true
 AUDIO_FEATURE_ENABLED_SND_MONITOR := true
@@ -144,7 +147,7 @@
 
 #Buffer size in kbytes for compress offload playback
 PRODUCT_PROPERTY_OVERRIDES += \
-vendor.audio.offload.buffer.size.kb=32
+vendor.audio.offload.buffer.size.kb=2
 
 #Enable offload audio video playback by default
 PRODUCT_PROPERTY_OVERRIDES += \
@@ -203,6 +206,30 @@
 PRODUCT_PROPERTY_OVERRIDES += \
 vendor.audio.safx.pbe.enabled=true
 
+#enable QAF
+PRODUCT_PROPERTY_OVERRIDES += \
+vendor.audio.qaf.enabled=true
+
+#QAF Library
+PRODUCT_PROPERTY_OVERRIDES += \
+vendor.audio.qaf.library=/vendor/lib/libdolby_ms12_wrapper.so
+
+#Disable reencode
+PRODUCT_PROPERTY_OVERRIDES += \
+vendor.audio.qaf.reencode=false
+
+#HDMI passthrough out
+PRODUCT_PROPERTY_OVERRIDES += \
+vendor.audio.qaf.hdmi.out=ddp
+
+#AV streaming offload
+PRODUCT_PROPERTY_OVERRIDES += \
+av.streaming.offload.enable=true
+
+#Enable multi offload
+PRODUCT_PROPERTY_OVERRIDES += \
+vendor.audio.offload.multiple.enabled=true
+
 #parser input buffer size(256kb) in byte stream mode
 PRODUCT_PROPERTY_OVERRIDES += \
 vendor.audio.parser.ip.buffer.size=262144
diff --git a/hal/Android.mk b/hal/Android.mk
index cbf766a..42f6ec7 100644
--- a/hal/Android.mk
+++ b/hal/Android.mk
@@ -261,6 +261,11 @@
     LOCAL_SRC_FILES += audio_extn/a2dp.c
 endif
 
+ifeq ($(strip $(AUDIO_FEATURE_IP_HDLR_ENABLED)),true)
+    LOCAL_CFLAGS += -DAUDIO_EXTN_IP_HDLR_ENABLED
+    LOCAL_SRC_FILES += audio_extn/ip_hdlr_intf.c
+endif
+
 ifeq ($(strip $(AUDIO_FEATURE_ENABLED_QAF)),true)
     LOCAL_CFLAGS += -DQAF_EXTN_ENABLED
     LOCAL_C_INCLUDES += $(TARGET_OUT_HEADERS)/mm-audio/qaf/
@@ -363,11 +368,6 @@
     LOCAL_SHARED_LIBRARIES += libaudio_log_utils
 endif
 
-ifeq ($(strip $($AUDIO_FEATURE_IP_HDLR_ENABLED)),true)
-    LOCAL_CFLAGS += -DAUDIO_EXTN_IP_HDLR_ENABLED
-    LOCAL_SRC_FILES += audio_extn/ip_hdlr_intf.c
-endif
-
 ifeq ($(strip $($AUDIO_FEATURE_ENABLED_DYNAMIC_ECNS)),true)
     LOCAL_CFLAGS += -DDYNAMIC_ECNS_ENABLED
 endif
diff --git a/hal/audio_extn/ip_hdlr_intf.c b/hal/audio_extn/ip_hdlr_intf.c
index a94e6de..1f5103c 100644
--- a/hal/audio_extn/ip_hdlr_intf.c
+++ b/hal/audio_extn/ip_hdlr_intf.c
@@ -48,6 +48,7 @@
 #include <dlfcn.h>
 #include <cutils/log.h>
 #include <sound/asound.h>
+#include <cutils/properties.h>
 
 #include "audio_hw.h"
 #include "audio_defs.h"
@@ -136,7 +137,7 @@
         return false;
 }
 
-int audio_extn_ip_hdlr_intf_event(void *stream_handle, void *payload, void *ip_hdlr_handle)
+int audio_extn_ip_hdlr_intf_event(void *stream_handle __unused, void *payload, void *ip_hdlr_handle )
 {
     ALOGVV("%s:[%d] handle = %p",__func__, ip_hdlr->ref_cnt, ip_hdlr_handle);
 
@@ -149,7 +150,6 @@
     int ret = 0;
     int pcm_device_id = 0;
     struct mixer_ctl *ctl = NULL;
-    struct stream_out *out = (struct stream_out *)aud_sess_handle;
     struct rtic_ack_param param;
     struct listnode *node, *tempnode;
     struct ip_hdlr_stream *stream_info;
@@ -234,7 +234,7 @@
             pthread_mutex_unlock(&inout->pre_lock);
             ALOGVV("%s:[%d] calling client callback", __func__, ip_hdlr->ref_cnt);
             if (inout && inout->client_callback)
-                inout->client_callback(AUDIO_EXTN_STREAM_CBK_EVENT_ERROR, NULL, inout->client_cookie);
+                inout->client_callback((stream_callback_event_t)AUDIO_EXTN_STREAM_CBK_EVENT_ERROR, NULL, inout->client_cookie);
             pthread_mutex_unlock(&inout->lock);
             break;
         } else if (stream_info->stream == aud_sess_handle) {
@@ -244,7 +244,7 @@
             pthread_mutex_unlock(&out->pre_lock);
             ALOGVV("%s:[%d] calling client callback", __func__, ip_hdlr->ref_cnt);
             if (out && out->client_callback)
-                out->client_callback(AUDIO_EXTN_STREAM_CBK_EVENT_ERROR, NULL, out->client_cookie);
+                out->client_callback((stream_callback_event_t)AUDIO_EXTN_STREAM_CBK_EVENT_ERROR, NULL, out->client_cookie);
             pthread_mutex_unlock(&out->lock);
             break;
         }
@@ -259,8 +259,6 @@
     int ret = 0, fd = 0, pcm_device_id = 0;
     struct audio_adsp_event *param;
     struct reg_event *reg_ev;
-    size_t shm_size;
-    void  *shm_buf;;
     struct stream_out *out;
     struct stream_inout *inout;
     void *adsp_hdlr_stream_handle;
@@ -302,7 +300,7 @@
                                                      audio_extn_ip_hdlr_intf_event,
                                                      handle);
     if (ret < 0) {
-        ALOGE("%s:[%d] failed to register event",__func__, ip_hdlr->ref_cnt, ret);
+        ALOGE("%s:[%d] failed to register event %d",__func__, ip_hdlr->ref_cnt, ret);
         goto done;
     }
 
@@ -313,7 +311,7 @@
     ret = snprintf(mixer_ctl_name, sizeof(mixer_ctl_name),
                    "Playback ION FD %d", pcm_device_id);
     if (ret < 0) {
-        ALOGE("%s:[%d] snprintf failed",__func__, ip_hdlr->ref_cnt, ret);
+        ALOGE("%s:[%d] snprintf failed %d",__func__, ip_hdlr->ref_cnt, ret);
         goto done;
     }
     ALOGV("%s: fd = %d  pcm_id = %d", __func__, fd, pcm_device_id);
@@ -371,11 +369,11 @@
     pthread_mutex_lock(&ip_hdlr->stream_list_lock);
     list_add_tail(&ip_hdlr->stream_list, &stream_info->list);
     pthread_mutex_unlock(&ip_hdlr->stream_list_lock);
-done:
+
     return ret;
 }
 
-int audio_extn_ip_hdlr_intf_close(void *handle, bool is_dsp_decode, void *aud_sess_handle)
+int audio_extn_ip_hdlr_intf_close(void *handle, bool is_dsp_decode, void *aud_sess_handle __unused)
 {
     struct audio_adsp_event param;
     void *adsp_hdlr_stream_handle;
diff --git a/hal/audio_extn/qaf.c b/hal/audio_extn/qaf.c
index 20d0ae4..81c99db 100644
--- a/hal/audio_extn/qaf.c
+++ b/hal/audio_extn/qaf.c
@@ -115,6 +115,7 @@
 #include "audio_extn.h"
 #include <qti_audio.h>
 #include "sound/compress_params.h"
+#include "ip_hdlr_intf.h"
 
 #ifdef DYNAMIC_LOG_ENABLED
 #include <log_xml_parser.h>
@@ -936,14 +937,20 @@
     if ((qaf_mod->stream_out[QAF_OUT_OFFLOAD] != NULL)
         || (qaf_mod->stream_out[QAF_OUT_OFFLOAD_MCH] != NULL)) {
         unsigned int sample_rate = 0;
+        audio_usecase_t platform_latency = 0;
 
         if (qaf_mod->stream_out[QAF_OUT_OFFLOAD])
             sample_rate = qaf_mod->stream_out[QAF_OUT_OFFLOAD]->sample_rate;
         else if (qaf_mod->stream_out[QAF_OUT_OFFLOAD_MCH])
             sample_rate = qaf_mod->stream_out[QAF_OUT_OFFLOAD_MCH]->sample_rate;
 
-        audio_usecase_t platform_latency =
+        if (qaf_mod->stream_out[QAF_OUT_OFFLOAD])
+            platform_latency =
                 platform_render_latency(qaf_mod->stream_out[QAF_OUT_OFFLOAD]->usecase);
+        else
+            platform_latency =
+                platform_render_latency(qaf_mod->stream_out[QAF_OUT_OFFLOAD_MCH]->usecase);
+
         dsp_latency = (platform_latency * sample_rate) / 1000000LL;
     } else if (qaf_mod->stream_out[QAF_OUT_TRANSCODE_PASSTHROUGH] != NULL) {
         unsigned int sample_rate = 0;
@@ -1283,7 +1290,7 @@
     config.offload_info.channel_mask = config.channel_mask = AUDIO_CHANNEL_OUT_STEREO;
 
     if (event_id == AUDIO_SEC_FAIL_EVENT) {
-        DEBUG_MSG("%s Security failed, closing session");
+        DEBUG_MSG("%s Security failed, closing session", __func__);
         qaf_session_close(qaf_mod);
         pthread_mutex_unlock(&p_qaf->lock);
         return;
@@ -1857,9 +1864,9 @@
 {
     ALOGV("%s %d", __func__, __LINE__);
     unsigned char* license_data = NULL;
-    device_license_config_t lic_config = {NULL, 0, 0};
-    int ret = -ENOSYS, size = 0;
-    char value[PROPERTY_VALUE_MAX] = {0};
+    device_license_config_t lic_config = {0};
+    int ret = -ENOSYS;
+
     struct qaf_module *qaf_mod = NULL;
 
     if (mod_type >= MAX_MM_MODULE_TYPE || !(p_qaf->qaf_mod[mod_type].qaf_audio_session_open))
@@ -1877,6 +1884,9 @@
     }
 
 #ifndef AUDIO_EXTN_IP_HDLR_ENABLED
+ {
+    int size=0;
+    char value[PROPERTY_VALUE_MAX] = {0};
     if (mod_type == MS12) {
         //Getting the license
         license_data = platform_get_license((struct audio_hw_device *)(p_qaf->adev->platform),
@@ -1905,6 +1915,7 @@
             goto exit;
         }
     }
+}
 #endif
 
     ret = qaf_mod->qaf_audio_session_open(&qaf_mod->session_handle,
@@ -1934,7 +1945,7 @@
     if (mod_type == MS12) {
         ret = audio_extn_ip_hdlr_intf_open(qaf_mod->ip_hdlr_hdl, false, qaf_mod->session_handle, out->usecase);
         if (ret < 0) {
-            ERROR_MSG("audio_extn_ip_hdlr_intf_open failed, ret = %d", __func__, ret);
+            ERROR_MSG("%s audio_extn_ip_hdlr_intf_open failed, ret = %d", __func__, ret);
             goto exit;
         }
     }
@@ -2921,7 +2932,7 @@
         }
 }
 #else
-        qaf_mod->qaf_lib = dlopen(lib_name, RTLD_NOW);
+       qaf_mod->qaf_lib = dlopen(lib_name, RTLD_NOW);
         if (qaf_mod->qaf_lib == NULL) {
             ERROR_MSG("DLOPEN failed for %s", lib_name);
             continue;
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index be65139..8d9c12b 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -74,6 +74,7 @@
 #include <platform.h>
 #include "audio_extn.h"
 #include "voice_extn.h"
+#include "ip_hdlr_intf.h"
 
 #include "sound/compress_params.h"
 #include "sound/asound.h"