hal: fix native DSD issues.

 -Use deafult buffer size of 2MB for native DSD.
 -Enable native DSD and 44.1 playback on line out device.

Change-Id: I96702dd1a4ff77440425fa8bfdd5c6f5f0f16ad3
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index e85e84c..673c17e 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -1234,6 +1234,7 @@
                (DSD_NATIVE_BACKEND == platform_get_backend_index(uc->out_snd_device))) {
             active = true;
             ALOGV("%s:DSD playback is active", __func__);
+            break;
         }
     }
     return active;
@@ -2617,10 +2618,13 @@
 
 static float AmpToDb(float amplification)
 {
-    if (amplification == 0) {
-        return DSD_VOLUME_MIN_DB;
+    float db = DSD_VOLUME_MIN_DB;
+    if (amplification > 0) {
+        db = 20 * log10(amplification);
+        if(db < DSD_VOLUME_MIN_DB)
+            return DSD_VOLUME_MIN_DB;
     }
-    return 20 * log10(amplification);
+    return db;
 }
 
 static int out_set_volume(struct audio_stream_out *stream, float left,
@@ -3785,13 +3789,13 @@
                 __func__, config->offload_info.version,
                 config->offload_info.bit_rate);
 
-        /*Check if DSD audio format is supported in codec
-         *and there is no active native DSD use case
+        /* Check if DSD audio format is supported in codec
+         * and there is no active native DSD use case
          */
 
         if ((config->format == AUDIO_FORMAT_DSD) &&
-               (!platform_check_codec_dsd_support(adev->platform) ||
-               audio_is_dsd_native_stream_active(adev))) {
+                (!platform_check_codec_dsd_support(adev->platform) ||
+                audio_is_dsd_native_stream_active(adev))) {
             ret = -EINVAL;
             goto error_open;
         }
@@ -3802,9 +3806,9 @@
          * Direct PCM playback
          */
         if (audio_extn_passthru_is_passthrough_stream(out) ||
-            (config->format == AUDIO_FORMAT_DSD) ||
-            config->offload_info.has_video ||
-            out->flags & AUDIO_OUTPUT_FLAG_DIRECT_PCM) {
+                (config->format == AUDIO_FORMAT_DSD) ||
+                config->offload_info.has_video ||
+                out->flags & AUDIO_OUTPUT_FLAG_DIRECT_PCM) {
             check_and_set_gapless_mode(adev, false);
         } else
             check_and_set_gapless_mode(adev, true);
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index 7350836..6930286 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -60,7 +60,8 @@
 #define LIB_ACDB_LOADER "libacdbloader.so"
 #define CVD_VERSION_MIXER_CTL "CVD Version"
 
-#define MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE (256 * 1024)
+#define FLAC_COMPRESS_OFFLOAD_FRAGMENT_SIZE (256 * 1024)
+#define MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE (2 * 1024 * 1024)
 #define MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE (2 * 1024)
 #define COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING (2 * 1024)
 #define COMPRESS_OFFLOAD_FRAGMENT_SIZE (32 * 1024)
@@ -2961,7 +2962,8 @@
     }
 
     if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
-        devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
+        devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
+        devices & AUDIO_DEVICE_OUT_LINE) {
         if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET
             && audio_extn_get_anc_enabled()) {
             if (audio_extn_should_use_fb_anc())
@@ -4296,18 +4298,21 @@
         fragment_size = info->offload_buffer_size;
     }
 
-    // For FLAC use max size since it is loss less, and has sampling rates
-    // upto 192kHZ
-    if (info != NULL && !info->has_video &&
-        info->format == AUDIO_FORMAT_FLAC) {
-       fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
-       ALOGV("FLAC fragment size %d", fragment_size);
-    }
-
-    if (info != NULL && info->has_video && info->is_streaming) {
-        fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING;
-        ALOGV("%s: offload fragment size reduced for AV streaming to %d",
-               __func__, fragment_size);
+    if (info != NULL && !info->has_video) {
+        if (info->is_streaming) {
+            fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING;
+            ALOGV("%s: offload fragment size reduced for AV streaming to %d",
+                   __func__, fragment_size);
+        } else if (info->format == AUDIO_FORMAT_FLAC) {
+            fragment_size = FLAC_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
+            ALOGV("FLAC fragment size %d", fragment_size);
+        } else if (info->format == AUDIO_FORMAT_DSD) {
+            fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
+            if((property_get("audio.native.dsd.buffer.size.kb", value, "")) &&
+                    atoi(value))
+                fragment_size =  atoi(value) * 1024;
+            ALOGV("DSD fragment size %d", fragment_size);
+        }
     }
 
     fragment_size = ALIGN( fragment_size, 1024);