qap: test: Enable ecref path

- For ec-ref path, add new device i.e audio-out-
  proxy and pass over to wrapper.
  In callback function data is written to
  ecref dump file.

Change-Id: I32b35ccf5caf708b73e213b891195db31a497a44
diff --git a/qahw_api/test/qahw_playback_test.c b/qahw_api/test/qahw_playback_test.c
index a5e10ed..648ffe2 100644
--- a/qahw_api/test/qahw_playback_test.c
+++ b/qahw_api/test/qahw_playback_test.c
@@ -2157,6 +2157,7 @@
         {"intr-strm",    required_argument,    0, 'i'},
         {"device-config", required_argument,    0, 'C'},
         {"play-list",    required_argument,    0, 'g'},
+        {"ec-ref",        no_argument,         0, 'L'},
         {"help",          no_argument,          0, 'h'},
         {0, 0, 0, 0}
     };
@@ -2180,7 +2181,7 @@
 
     while ((opt = getopt_long(argc,
                               argv,
-                              "-f:r:c:b:d:s:v:V:l:t:a:w:k:PD:KF:Ee:A:u:m:S:C:p::x:y:qQh:i:h:g:O:",
+                              "-f:r:c:b:d:s:v:V:l:t:a:w:k:PD:KF:Ee:A:u:m:S:C:p::x:y:qQLh:i:h:g:O:",
                               long_options,
                               &option_index)) != -1) {
 
@@ -2377,6 +2378,9 @@
         case 'x':
             render_format = atoi(optarg);
             break;
+        case 'L':
+            ec_ref = true;
+            break;
         case 'y':
             stream_param[i].timestamp_filename = optarg;
             break;
diff --git a/qahw_api/test/qahw_playback_test.h b/qahw_api/test/qahw_playback_test.h
index 6ca6a67..50a6a10 100644
--- a/qahw_api/test/qahw_playback_test.h
+++ b/qahw_api/test/qahw_playback_test.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2016-2017,2019, The Linux Foundation. All rights reserved.
  * Not a Contribution.
  *
  * Copyright (C) 2015 The Android Open Source Project *
@@ -41,6 +41,7 @@
 bool enable_dump;
 float vol_level;
 uint8_t render_format;
+bool ec_ref;
 
 
 enum {
diff --git a/qahw_api/test/qap_wrapper_extn.c b/qahw_api/test/qap_wrapper_extn.c
index a084277..f86908f 100644
--- a/qahw_api/test/qap_wrapper_extn.c
+++ b/qahw_api/test/qap_wrapper_extn.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2016-2017,2019 The Linux Foundation. All rights reserved.
  * Not a Contribution.
  *
  * Copyright (C) 2015 The Android Open Source Project *
@@ -88,6 +88,7 @@
 FILE *fp_output_writer_hp = NULL;
 FILE *fp_output_writer_hdmi = NULL;
 FILE *fp_output_timestamp_file = NULL;
+FILE *fp_ecref = NULL;
 unsigned char data_buf[MAX_BUFFER_SIZE];
 uint32_t output_device_id = 0;
 uint16_t input_streams_count = 0;
@@ -204,6 +205,7 @@
     bool enable_hdmi = false;
     bool combo_enabled = false;
     char dev_kv_pair[16] = {0};
+    bool enable_ecref = false;
 
     ALOGV("%s:%d output device id %d render format = %d", __func__, __LINE__, output_device_id, hdmi_render_format);
 
@@ -214,6 +216,8 @@
         enable_hp = true;
     if (output_device_id & AUDIO_DEVICE_OUT_SPEAKER)
         enable_spk = true;
+    if (ec_ref)
+        enable_ecref = true;
 
     if (enable_hdmi) {
         session_output_config.output_config[session_output_config.num_output].id = AUDIO_DEVICE_OUT_HDMI;
@@ -267,6 +271,20 @@
         session_output_config.num_output++;
     }
 
+    if (enable_ecref) {
+        session_output_config.output_config[session_output_config.num_output].channels = popcount(AUDIO_CHANNEL_OUT_STEREO);
+        session_output_config.output_config[session_output_config.num_output].id = AUDIO_DEVICE_OUT_PROXY;
+        session_output_config.output_config[session_output_config.num_output].sample_rate = smpl_rate;
+        if (bitwidth == PCM_24_BITWIDTH) {
+            session_output_config.output_config[session_output_config.num_output].format = QAP_AUDIO_FORMAT_PCM_24_BIT_PACKED;
+            session_output_config.output_config[session_output_config.num_output].bit_width = PCM_24_BITWIDTH;
+        } else {
+            session_output_config.output_config[session_output_config.num_output].format = QAP_AUDIO_FORMAT_PCM_16_BIT;
+            session_output_config.output_config[session_output_config.num_output].bit_width = PCM_16_BITWIDTH;
+        }
+        session_output_config.num_output++;
+    }
+
     ALOGV("%s:%d num_output = %d", __func__, __LINE__, session_output_config.num_output);
     return;
 }
@@ -1203,6 +1221,20 @@
                              ALOGD("%s::%d Measuring Kpi cold stop %lf", __func__, __LINE__, cold_stop);
                         }
                     }
+                    if (buffer->buffer_parms.output_buf_params.output_id == AUDIO_DEVICE_OUT_PROXY) {
+
+                        if (fp_ecref == NULL) {
+                            fp_ecref = fopen("/data/vendor/misc/audio/ecref", "w+");
+                        }
+
+                        if (fp_ecref) {
+                            ALOGD("%s: write %d bytes to ecref dump",__func__,buffer->common_params.size);
+                            fwrite((unsigned char *)buffer->common_params.data, 1, buffer->common_params.size, fp_ecref);
+                        } else {
+                            ALOGE("%s: failed to open ecref dump file",__func__);
+                        }
+
+                    }
                 }
             }
             break;