hal: Add support for 24 bit through deep buffer

Enable support for 24 bit through deep buffer
path. Remove hardcoding of 16 bit and honor
the format and sample rate set by flinger.
24 bit support includes support for 8_24 and
24 bit packed pcm format.

Change-Id: I2cbc2005b188c3bc21b4e7a7275e9ee21c7b820d
diff --git a/hal/audio_extn/audio_extn.h b/hal/audio_extn/audio_extn.h
index 357f036..fe3fe95 100644
--- a/hal/audio_extn/audio_extn.h
+++ b/hal/audio_extn/audio_extn.h
@@ -532,7 +532,10 @@
 int read_line_from_file(const char *path, char *buf, size_t count);
 int audio_extn_utils_get_codec_version(const char *snd_card_name, int card_num, char *codec_version);
 audio_format_t alsa_format_to_hal(uint32_t alsa_format);
-uint32_t hal_format_to_alsa(audio_format_t pcm_format);
+uint32_t hal_format_to_alsa(audio_format_t hal_format);
+audio_format_t pcm_format_to_hal(uint32_t pcm_format);
+uint32_t hal_format_to_pcm(audio_format_t hal_format);
+
 void audio_extn_utils_update_direct_pcm_fragment_size(struct stream_out *out);
 
 #ifndef KPI_OPTIMIZE_ENABLED
diff --git a/hal/audio_extn/utils.c b/hal/audio_extn/utils.c
index df20120..e3f1b6c 100644
--- a/hal/audio_extn/utils.c
+++ b/hal/audio_extn/utils.c
@@ -96,11 +96,11 @@
 };
 
 const struct string_to_enum s_format_name_to_enum_table[] = {
+    STRING_TO_ENUM(AUDIO_FORMAT_PCM_8_BIT),
     STRING_TO_ENUM(AUDIO_FORMAT_PCM_16_BIT),
     STRING_TO_ENUM(AUDIO_FORMAT_PCM_24_BIT_PACKED),
     STRING_TO_ENUM(AUDIO_FORMAT_PCM_8_24_BIT),
     STRING_TO_ENUM(AUDIO_FORMAT_PCM_32_BIT),
-    STRING_TO_ENUM(AUDIO_FORMAT_PCM_8_BIT),
     STRING_TO_ENUM(AUDIO_FORMAT_MP3),
     STRING_TO_ENUM(AUDIO_FORMAT_AAC),
     STRING_TO_ENUM(AUDIO_FORMAT_VORBIS),
@@ -765,6 +765,60 @@
     return alsa_format;
 }
 
+/*Translates PCM formats to AOSP formats*/
+audio_format_t pcm_format_to_hal(uint32_t pcm_format)
+{
+    audio_format_t format = AUDIO_FORMAT_INVALID;
+
+    switch(pcm_format) {
+    case PCM_FORMAT_S16_LE:
+        format = AUDIO_FORMAT_PCM_16_BIT;
+        break;
+    case PCM_FORMAT_S24_3LE:
+        format = AUDIO_FORMAT_PCM_24_BIT_PACKED;
+        break;
+    case PCM_FORMAT_S24_LE:
+        format = AUDIO_FORMAT_PCM_8_24_BIT;
+        break;
+    case PCM_FORMAT_S32_LE:
+        format = AUDIO_FORMAT_PCM_32_BIT;
+        break;
+    default:
+        ALOGW("Incorrect PCM format");
+        format = AUDIO_FORMAT_INVALID;
+    }
+    return format;
+}
+
+/*Translates hal format (AOSP) to alsa formats*/
+uint32_t hal_format_to_pcm(audio_format_t hal_format)
+{
+    uint32_t pcm_format;
+
+    switch (hal_format) {
+    case AUDIO_FORMAT_PCM_32_BIT:
+    case AUDIO_FORMAT_PCM_8_24_BIT:
+    case AUDIO_FORMAT_PCM_FLOAT: {
+        if (platform_supports_true_32bit())
+            pcm_format = PCM_FORMAT_S32_LE;
+        else
+            pcm_format = PCM_FORMAT_S24_3LE;
+        }
+        break;
+    case AUDIO_FORMAT_PCM_8_BIT:
+        pcm_format = PCM_FORMAT_S8;
+        break;
+    case AUDIO_FORMAT_PCM_24_BIT_PACKED:
+        pcm_format = PCM_FORMAT_S24_3LE;
+        break;
+    default:
+    case AUDIO_FORMAT_PCM_16_BIT:
+        pcm_format = PCM_FORMAT_S16_LE;
+        break;
+    }
+    return pcm_format;
+}
+
 uint32_t get_alsa_fragment_size(uint32_t bytes_per_sample,
                                   uint32_t sample_rate,
                                   uint32_t noOfChannels)
@@ -798,8 +852,8 @@
  */
 void audio_extn_utils_update_direct_pcm_fragment_size(struct stream_out *out)
 {
-    audio_format_t dst_format = out->compr_pcm_config.hal_op_format;
-    audio_format_t src_format = out->compr_pcm_config.hal_ip_format;
+    audio_format_t dst_format = out->hal_op_format;
+    audio_format_t src_format = out->hal_ip_format;
     uint32_t hal_op_bytes_per_sample = audio_bytes_per_sample(dst_format);
     uint32_t hal_ip_bytes_per_sample = audio_bytes_per_sample(src_format);
 
@@ -811,13 +865,13 @@
     if ((src_format != dst_format) &&
          hal_op_bytes_per_sample != hal_ip_bytes_per_sample) {
 
-        out->compr_pcm_config.hal_fragment_size =
+        out->hal_fragment_size =
                   ((out->compr_config.fragment_size * hal_ip_bytes_per_sample) /
                    hal_op_bytes_per_sample);
         ALOGI("enable conversion hal_input_fragment_size is %d src_format %x dst_format %x",
-               out->compr_pcm_config.hal_fragment_size, src_format, dst_format);
+               out->hal_fragment_size, src_format, dst_format);
     } else {
-        out->compr_pcm_config.hal_fragment_size = out->compr_config.fragment_size;
+        out->hal_fragment_size = out->compr_config.fragment_size;
     }
 }