qahw: Add support for new stream APIs

Add support for new APIs to support voice call and
voice call features.

CRs-fixed: 2381271
Change-Id: Id3ba4417f1365018e5a26d243caea83571857f63
diff --git a/qahw/Makefile.am b/qahw/Makefile.am
index b78c9b7..fccf003 100644
--- a/qahw/Makefile.am
+++ b/qahw/Makefile.am
@@ -17,6 +17,10 @@
 AM_CFLAGS += -DSVA_AUDIO_CONC
 endif
 
+if QAHW_V1
+AM_CFLAGS += -DQAHW_V1
+endif
+
 libqahwwrapper_la_CFLAGS  = $(AM_CFLAGS)
 libqahwwrapper_la_CFLAGS += -include stddef.h
 libqahwwrapper_la_CFLAGS += -Dstrlcpy=g_strlcpy $(GLIB_CFLAGS) -include glib.h
diff --git a/qahw/configure.ac b/qahw/configure.ac
index 5bd3a22..94ca645 100644
--- a/qahw/configure.ac
+++ b/qahw/configure.ac
@@ -30,6 +30,7 @@
 PKG_PROG_PKG_CONFIG
 
 AM_CONDITIONAL([SVA_AUDIO_CONCURRENCY],[test x$BOARD_SUPPORTS_SVA_AUDIO_CONCURRENCY = xtrue])
+AM_CONDITIONAL([QAHW_V1], [test x$AUDIO_FEATURE_ENABLED_QAHW_1_0 = xtrue])
 AC_ARG_WITH([glib],
       AC_HELP_STRING([--with-glib],
          [enable glib, Build against glib. Use this when building for HLOS systems which use glib]))
diff --git a/qahw/inc/qahw.h b/qahw/inc/qahw.h
index 5020c8f..dd920e2 100644
--- a/qahw/inc/qahw.h
+++ b/qahw/inc/qahw.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2016-2019, The Linux Foundation. All rights reserved.
  * Not a Contribution.
  *
  * Copyright (C) 2011 The Android Open Source Project *
@@ -45,6 +45,9 @@
 /* First generation of audio devices had version hardcoded to 0. all devices with
  * versions < 1.0 will be considered of first generation API.
  */
+#if QAHW_V1
+#define QAHW_MODULE_API_VERSION_1_0 QAHW_MAKE_API_VERSION(1, 0)
+#endif
 #define QAHW_MODULE_API_VERSION_0_0 QAHW_MAKE_API_VERSION(0, 0)
 
 /* Minimal QTI audio HAL version supported by the audio framework */
diff --git a/qahw/inc/qahw_defs.h b/qahw/inc/qahw_defs.h
index 7d136d2..b0eb332 100644
--- a/qahw/inc/qahw_defs.h
+++ b/qahw/inc/qahw_defs.h
@@ -18,6 +18,7 @@
 
 #include <sys/cdefs.h>
 #include <stdint.h>
+#include <system/audio.h>
 
 #ifndef QTI_AUDIO_HAL_DEFS_H
 #define QTI_AUDIO_HAL_DEFS_H
@@ -171,6 +172,9 @@
 #define QAHW_INPUT_FLAG_TIMESTAMP 0x80000000
 #define QAHW_INPUT_FLAG_COMPRESS  0x40000000
 #define QAHW_INPUT_FLAG_PASSTHROUGH 0x20000000
+#define QAHW_OUTPUT_FLAG_INCALL_MUSIC 0x80000000
+#define QAHW_AUDIO_FLAG_HPCM_TX 0x00020000
+#define QAHW_AUDIO_FLAG_HPCM_RX 0x00040000
 
 /* Query fm volume */
 #define QAHW_PARAMETER_KEY_FM_VOLUME "fm_volume"
@@ -267,6 +271,14 @@
     uint32_t reserved[64]; /*reserved for future */
 } qahw_in_buffer_t;
 
+typedef struct {
+    void *buffer;    /* write buffer pointer */
+    size_t size;          /* size of buffer */
+    size_t offset;         /* offset in buffer from where valid byte starts */
+    int64_t *timestamp;    /* timestmap */
+    qahw_meta_data_flags_t flags; /* meta data flags */
+} qahw_buffer_t;
+
 #define MAX_SECTORS 8
 
 struct qahw_source_tracking_param {
@@ -391,6 +403,42 @@
     char license[QAHW_LICENCE_STR_MAX_LENGTH + 1];
 } qahw_license_params_t;
 
+typedef struct qahw_dtmf_gen_params {
+   bool enable;
+   uint16_t low_freq;
+   uint16_t high_freq;
+   uint16_t gain;
+} qahw_dtmf_gen_params_t;
+
+enum {
+    QAHW_TTY_MODE_OFF,
+    QAHW_TTY_MODE_FULL,
+    QAHW_TTY_MODE_VCO,
+    QAHW_TTY_MODE_HCO,
+    QAHW_TTY_MODE_MAX,
+};
+
+typedef struct qahw_tty_params {
+   uint32_t mode;
+} qahw_tty_params_t;
+
+typedef enum {
+    QAHW_HPCM_TAP_POINT_RX = 1,
+    QAHW_HPCM_TAP_POINT_TX = 2,
+    QAHW_HPCM_TAP_POINT_RX_TX = 3,
+} qahw_hpcm_tap_point;
+
+typedef enum {
+    QAHW_HPCM_DIRECTION_OUT,
+    QAHW_HPCM_DIRECTION_IN,
+    QAHW_HPCM_DIRECTION_OUT_IN,
+} qahw_hpcm_direction;
+
+typedef struct qahw_hpcm_params {
+   qahw_hpcm_tap_point tap_point;
+   qahw_hpcm_direction direction;
+} qahw_hpcm_params_t;
+
 typedef union {
     struct qahw_source_tracking_param st_params;
     struct qahw_sound_focus_param sf_params;
@@ -406,6 +454,9 @@
     struct qahw_mix_matrix_params mix_matrix_params;
     struct qahw_license_params license_params;
     struct qahw_out_presentation_position_param pos_param;
+    struct qahw_dtmf_gen_params dtmf_gen_params;
+    struct qahw_tty_params tty_mode_params;
+    struct qahw_hpcm_params hpcm_params;
 } qahw_param_payload;
 
 typedef enum {
@@ -426,6 +477,9 @@
     QAHW_PARAM_CH_MIX_MATRIX_PARAMS,
     QAHW_PARAM_LICENSE_PARAMS,
     QAHW_PARAM_OUT_PRESENTATION_POSITION,
+    QAHW_PARAM_DTMF_GEN,
+    QAHW_PARAM_TTY_MODE,
+    QAHW_PARAM_HPCM,
 } qahw_param_id;
 
 typedef union {
@@ -436,6 +490,94 @@
     QAHW_PARAM_LOOPBACK_RENDER_WINDOW /* PARAM to set render window */
 } qahw_loopback_param_id;
 
+/** stream direction enumeration */
+typedef enum {
+    QAHW_STREAM_INPUT,
+    QAHW_STREAM_OUTPUT,
+    QAHW_STREAM_INPUT_OUTPUT,
+} qahw_stream_direction;
+
+/** stream types */
+typedef enum {
+    QAHW_STREAM_TYPE_INVALID,
+    QAHW_AUDIO_PLAYBACK_LOW_LATENCY,      /**< low latency, higher power*/
+    QAHW_AUDIO_PLAYBACK_DEEP_BUFFER,          /**< low power, higher latency*/
+    QAHW_AUDIO_PLAYBACK_COMPRESSED,           /**< compresssed audio*/
+    QAHW_AUDIO_PLAYBACK_VOIP,                 /**< pcm voip audio*/
+    QAHW_AUDIO_PLAYBACK_VOICE_CALL_MUSIC,     /**< pcm voip audio*/
+
+    QAHW_AUDIO_CAPTURE_LOW_LATENCY,           /**< low latency, higher power*/
+    QAHW_AUDIO_CAPTURE_DEEP_BUFFER,           /**< low power, higher latency*/
+    QAHW_AUDIO_CAPTURE_COMPRESSED,            /**< compresssed audio*/
+    QAHW_AUDIO_CAPTURE_RAW,                   /**< pcm no post processing*/
+    QAHW_AUDIO_CAPTURE_VOIP,                  /**< pcm voip audio*/
+    QAHW_AUDIO_CAPTURE_VOICE_ACTIVATION,      /**< voice activation*/
+    QAHW_AUDIO_CAPTURE_VOICE_CALL_RX,         /**< incall record, downlink */
+    QAHW_AUDIO_CAPTURE_VOICE_CALL_TX,         /**< incall record, uplink */
+    QAHW_AUDIO_CAPTURE_VOICE_CALL_RX_TX,      /**< incall record, uplink & Downlink */
+
+    QAHW_VOICE_CALL,                          /**< voice call */
+
+    QAHW_AUDIO_TRANSCODE,                     /**< audio transcode */
+    QAHW_AUDIO_HOST_PCM_TX,
+    QAHW_AUDIO_HOST_PCM_RX,
+    QAHW_AUDIO_HOST_PCM_TX_RX,
+    QAHW_AUDIO_STREAM_TYPE_MAX,
+} qahw_audio_stream_type;
+
+typedef uint32_t qahw_device_t;
+
+/**< Key value pair to identify the topology of a usecase from default  */
+struct qahw_modifier_kv  {
+    uint32_t key;
+    uint32_t value;
+};
+
+struct qahw_shared_attributes{
+     audio_config_t config;
+};
+struct qahw_voice_attributes{
+     audio_config_t config;
+     const char *vsid;
+};
+
+struct qahw_audio_attributes{
+    audio_config_t config;
+};
+
+typedef union {
+    struct qahw_shared_attributes shared;
+    struct qahw_voice_attributes voice;
+    struct qahw_audio_attributes audio;
+} qahw_stream_attributes_config;
+
+struct qahw_stream_attributes {
+     qahw_audio_stream_type type;
+     qahw_stream_direction direction;
+     qahw_stream_attributes_config attr;
+};
+
+typedef enum {
+    QAHW_CHANNEL_L = 0, /*left channel*/
+    QAHW_CHANNEL_R = 1, /*right channel*/
+    QAHW_CHANNELS_MAX = 2, /*max number of supported streams*/
+} qahw_channel_map;
+
+struct qahw_channel_vol {
+    qahw_channel_map channel;
+    float vol;
+};
+
+struct qahw_volume_data {
+    uint32_t num_of_channels;
+    struct qahw_channel_vol *vol_pair;
+};
+
+struct qahw_mute_data {
+    bool enable;
+    qahw_stream_direction direction;
+};
+
 __END_DECLS
 
 #endif  // QTI_AUDIO_HAL_DEFS_H
diff --git a/qahw/src/qahw.c b/qahw/src/qahw.c
index ceec657..2ae6906 100644
--- a/qahw/src/qahw.c
+++ b/qahw/src/qahw.c
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
+* Copyright (c) 2016-2019, 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
@@ -45,8 +45,13 @@
 
 /*
  * The current HAL API version.
+ * version 1.0 has support for voice only in new stream based APIS
  */
+#ifdef QAHW_MODULE_API_VERSION_1_0
+#define QAHW_MODULE_API_VERSION_CURRENT QAHW_MODULE_API_VERSION_1_0
+#else
 #define QAHW_MODULE_API_VERSION_CURRENT QAHW_MODULE_API_VERSION_0_0
+#endif
 
 
 typedef uint64_t (*qahwi_out_write_v2_t)(audio_stream_out_t *out, const void* buffer,