Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1 | /* |
Revathi Uddaraju | 1eac8b0 | 2017-05-18 17:13:33 +0530 | [diff] [blame] | 2 | * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above |
| 10 | * copyright notice, this list of conditions and the following |
| 11 | * disclaimer in the documentation and/or other materials provided |
| 12 | * with the distribution. |
| 13 | * * Neither the name of The Linux Foundation nor the names of its |
| 14 | * contributors may be used to endorse or promote products derived |
| 15 | * from this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 24 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 26 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 27 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | #define LOG_TAG "audio_hw_qaf" |
| 31 | /*#define LOG_NDEBUG 0*/ |
| 32 | /*#define VERY_VERY_VERBOSE_LOGGING*/ |
| 33 | #ifdef VERY_VERY_VERBOSE_LOGGING |
| 34 | #define ALOGVV ALOGV |
| 35 | #else |
| 36 | #define ALOGVV(a...) do { } while(0) |
| 37 | #endif |
| 38 | |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 39 | #define DEBUG_MSG_VV(arg,...) ALOGVV("%s: %d: " arg, __func__, __LINE__, ##__VA_ARGS__) |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 40 | #define DEBUG_MSG(arg,...) ALOGV("%s: %d: " arg, __func__, __LINE__, ##__VA_ARGS__) |
| 41 | #define ERROR_MSG(arg,...) ALOGE("%s: %d: " arg, __func__, __LINE__, ##__VA_ARGS__) |
| 42 | |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 43 | #define COMPRESS_OFFLOAD_NUM_FRAGMENTS 2 |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 44 | #define COMPRESS_PASSTHROUGH_DDP_FRAGMENT_SIZE 4608 |
| 45 | |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 46 | #define QAF_DEFAULT_COMPR_AUDIO_HANDLE 1001 |
| 47 | #define QAF_DEFAULT_COMPR_PASSTHROUGH_HANDLE 1002 |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 48 | #define QAF_DEFAULT_PASSTHROUGH_HANDLE 1003 |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 49 | |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 50 | #define COMPRESS_OFFLOAD_PLAYBACK_LATENCY 300 |
Varun B | 34da7a4 | 2017-02-13 16:16:53 +0530 | [diff] [blame] | 51 | |
Varun B | 34da7a4 | 2017-02-13 16:16:53 +0530 | [diff] [blame] | 52 | #define MIN_PCM_OFFLOAD_FRAGMENT_SIZE 512 |
| 53 | #define MAX_PCM_OFFLOAD_FRAGMENT_SIZE (240 * 1024) |
| 54 | |
| 55 | #define DIV_ROUND_UP(x, y) (((x) + (y) - 1)/(y)) |
| 56 | #define ALIGN(x, y) ((y) * DIV_ROUND_UP((x), (y))) |
| 57 | |
| 58 | /* Pcm input node buffer size is 6144 bytes, i.e, 32msec for 48000 samplerate */ |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 59 | #define QAF_MODULE_PCM_INPUT_BUFFER_LATENCY 32 |
Varun B | 34da7a4 | 2017-02-13 16:16:53 +0530 | [diff] [blame] | 60 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 61 | #define MS12_PCM_OUT_FRAGMENT_SIZE 1536 //samples |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 62 | #define MS12_PCM_IN_FRAGMENT_SIZE 1536 //samples |
Varun B | 34da7a4 | 2017-02-13 16:16:53 +0530 | [diff] [blame] | 63 | |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 64 | #define DD_FRAME_SIZE 1536 |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 65 | #define DDP_FRAME_SIZE DD_FRAME_SIZE |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 66 | /* |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 67 | * DD encoder output size for one frame. |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 68 | */ |
| 69 | #define DD_ENCODER_OUTPUT_SIZE 2560 |
| 70 | /* |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 71 | * DDP encoder output size for one frame. |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 72 | */ |
| 73 | #define DDP_ENCODER_OUTPUT_SIZE 4608 |
| 74 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 75 | /*********TODO Need to get correct values.*************************/ |
| 76 | |
| 77 | #define DTS_PCM_OUT_FRAGMENT_SIZE 1024 //samples |
| 78 | |
| 79 | #define DTS_FRAME_SIZE 1536 |
| 80 | #define DTSHD_FRAME_SIZE DTS_FRAME_SIZE |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 81 | /* |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 82 | * DTS encoder output size for one frame. |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 83 | */ |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 84 | #define DTS_ENCODER_OUTPUT_SIZE 2560 |
| 85 | /* |
| 86 | * DTSHD encoder output size for one frame. |
| 87 | */ |
| 88 | #define DTSHD_ENCODER_OUTPUT_SIZE 4608 |
| 89 | /******************************************************************/ |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 90 | |
Bharath Gopal | 01310bb | 2016-12-05 15:39:32 +0530 | [diff] [blame] | 91 | /* |
| 92 | * QAF Latency to process buffers since out_write from primary HAL |
| 93 | */ |
| 94 | #define QAF_COMPRESS_OFFLOAD_PROCESSING_LATENCY 18 |
| 95 | #define QAF_PCM_OFFLOAD_PROCESSING_LATENCY 48 |
| 96 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 97 | //TODO: Need to handle for DTS |
Varun B | 34da7a4 | 2017-02-13 16:16:53 +0530 | [diff] [blame] | 98 | #define QAF_DEEP_BUFFER_OUTPUT_PERIOD_SIZE 1536 |
| 99 | |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 100 | #include <stdlib.h> |
| 101 | #include <pthread.h> |
| 102 | #include <errno.h> |
| 103 | #include <dlfcn.h> |
| 104 | #include <sys/resource.h> |
| 105 | #include <sys/prctl.h> |
| 106 | #include <cutils/properties.h> |
| 107 | #include <cutils/str_parms.h> |
| 108 | #include <cutils/log.h> |
| 109 | #include <cutils/atomic.h> |
| 110 | #include "audio_utils/primitives.h" |
| 111 | #include "audio_hw.h" |
| 112 | #include "platform_api.h" |
| 113 | #include <platform.h> |
| 114 | #include <system/thread_defs.h> |
| 115 | #include <cutils/sched_policy.h> |
| 116 | #include "audio_extn.h" |
| 117 | #include <qti_audio.h> |
| 118 | #include "sound/compress_params.h" |
| 119 | |
Revathi Uddaraju | 1eac8b0 | 2017-05-18 17:13:33 +0530 | [diff] [blame] | 120 | #ifdef DYNAMIC_LOG_ENABLED |
| 121 | #include <log_xml_parser.h> |
| 122 | #define LOG_MASK HAL_MOD_FILE_QAF |
| 123 | #include <log_utils.h> |
| 124 | #endif |
| 125 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 126 | //TODO: Need to remove this. |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 127 | #define QAF_OUTPUT_SAMPLING_RATE 48000 |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 128 | |
| 129 | #ifdef QAF_DUMP_ENABLED |
| 130 | FILE *fp_output_writer_hdmi = NULL; |
| 131 | #endif |
| 132 | |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 133 | struct qaf_adsp_hdlr_config_state { |
| 134 | struct audio_adsp_event event_params; |
| 135 | /* For holding client audio_adsp_event payload */ |
| 136 | uint8_t event_payload[AUDIO_MAX_ADSP_STREAM_CMD_PAYLOAD_LEN]; |
| 137 | bool adsp_hdlr_config_valid; |
| 138 | }; |
| 139 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 140 | //Types of MM module, currently supported by QAF. |
| 141 | typedef enum { |
| 142 | MS12, |
| 143 | DTS_M8, |
| 144 | MAX_MM_MODULE_TYPE, |
| 145 | INVALID_MM_MODULE |
| 146 | } mm_module_type; |
| 147 | |
| 148 | typedef enum { |
| 149 | QAF_OUT_TRANSCODE_PASSTHROUGH = 0, /* Transcode passthrough via MM module*/ |
| 150 | QAF_OUT_OFFLOAD_MCH, /* Multi-channel PCM offload*/ |
| 151 | QAF_OUT_OFFLOAD, /* PCM offload */ |
| 152 | |
| 153 | MAX_QAF_MODULE_OUT |
| 154 | } mm_module_output_type; |
| 155 | |
| 156 | typedef enum { |
| 157 | QAF_IN_MAIN = 0, /* Single PID Main/Primary or Dual-PID stream */ |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 158 | QAF_IN_ASSOC, /* Associated/Secondary stream */ |
| 159 | QAF_IN_PCM, /* PCM stream. */ |
| 160 | QAF_IN_MAIN_2, /* Single PID Main2 stream */ |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 161 | MAX_QAF_MODULE_IN |
| 162 | } mm_module_input_type; |
| 163 | |
| 164 | struct qaf_module { |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 165 | audio_session_handle_t session_handle; |
| 166 | void *qaf_lib; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 167 | int (*qaf_audio_session_open)(audio_session_handle_t* session_handle, |
| 168 | void *p_data, |
| 169 | void* license_data); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 170 | int (*qaf_audio_session_close)(audio_session_handle_t session_handle); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 171 | int (*qaf_audio_stream_open)(audio_session_handle_t session_handle, |
| 172 | audio_stream_handle_t* stream_handle, |
| 173 | audio_stream_config_t input_config, |
| 174 | audio_devices_t devices, |
| 175 | stream_type_t flags); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 176 | int (*qaf_audio_stream_close)(audio_stream_handle_t stream_handle); |
| 177 | int (*qaf_audio_stream_set_param)(audio_stream_handle_t stream_handle, const char* kv_pairs); |
| 178 | int (*qaf_audio_session_set_param)(audio_session_handle_t handle, const char* kv_pairs); |
| 179 | char* (*qaf_audio_stream_get_param)(audio_stream_handle_t stream_handle, const char* key); |
| 180 | char* (*qaf_audio_session_get_param)(audio_session_handle_t handle, const char* key); |
| 181 | int (*qaf_audio_stream_start)(audio_stream_handle_t handle); |
| 182 | int (*qaf_audio_stream_stop)(audio_stream_handle_t stream_handle); |
| 183 | int (*qaf_audio_stream_pause)(audio_stream_handle_t stream_handle); |
| 184 | int (*qaf_audio_stream_flush)(audio_stream_handle_t stream_handle); |
| 185 | int (*qaf_audio_stream_write)(audio_stream_handle_t stream_handle, const void* buf, int size); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 186 | void (*qaf_register_event_callback)(audio_session_handle_t session_handle, |
| 187 | void *priv_data, |
| 188 | notify_event_callback_t event_callback, |
| 189 | audio_event_id_t event_id); |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 190 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 191 | /*Input stream of MM module */ |
| 192 | struct stream_out *stream_in[MAX_QAF_MODULE_IN]; |
| 193 | /*Output Stream from MM module */ |
| 194 | struct stream_out *stream_out[MAX_QAF_MODULE_OUT]; |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 195 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 196 | struct qaf_adsp_hdlr_config_state adsp_hdlr_config[MAX_QAF_MODULE_IN]; |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 197 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 198 | //BT session handle. |
Bharath Gopal | 01310bb | 2016-12-05 15:39:32 +0530 | [diff] [blame] | 199 | void *bt_hdl; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 200 | |
Deepak Agarwal | 1e42b85 | 2017-02-11 17:57:04 +0530 | [diff] [blame] | 201 | float vol_left; |
| 202 | float vol_right; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 203 | bool is_vol_set; |
| 204 | bool drain_received[MAX_QAF_MODULE_IN]; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 205 | }; |
| 206 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 207 | struct qaf { |
| 208 | struct audio_device *adev; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 209 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 210 | pthread_mutex_t lock; |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 211 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 212 | bool hdmi_connect; |
| 213 | int hdmi_sink_channels; |
| 214 | |
| 215 | //Flag to indicate if QAF transcode output stream is enabled from any mm module. |
| 216 | bool passthrough_enabled; |
| 217 | //Flag to indicate if QAF mch pcm output stream is enabled from any mm module. |
| 218 | bool mch_pcm_hdmi_enabled; |
| 219 | |
| 220 | //Flag to indicate if msmd is supported. |
| 221 | bool qaf_msmd_enabled; |
| 222 | |
| 223 | //Handle of QAF input stream, which is routed as QAF passthrough. |
| 224 | struct stream_out *passthrough_in; |
| 225 | //Handle of QAF passthrough stream. |
| 226 | struct stream_out *passthrough_out; |
| 227 | |
| 228 | struct qaf_module qaf_mod[MAX_MM_MODULE_TYPE]; |
| 229 | }; |
| 230 | |
| 231 | static int qaf_out_pause(struct audio_stream_out* stream); |
| 232 | static int qaf_out_flush(struct audio_stream_out* stream); |
| 233 | static int qaf_out_drain(struct audio_stream_out* stream, audio_drain_type_t type); |
| 234 | |
| 235 | //Global handle of QAF. Access to this should be protected by mutex lock. |
| 236 | static struct qaf *p_qaf = NULL; |
| 237 | |
| 238 | /* Gets the pointer to qaf module for the qaf input stream. */ |
| 239 | static struct qaf_module* get_qaf_module_for_input_stream(struct stream_out *out) |
Deepak Agarwal | 1e42b85 | 2017-02-11 17:57:04 +0530 | [diff] [blame] | 240 | { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 241 | struct qaf_module *qaf_mod = NULL; |
| 242 | int i, j; |
| 243 | if (!p_qaf) return NULL; |
Deepak Agarwal | 1e42b85 | 2017-02-11 17:57:04 +0530 | [diff] [blame] | 244 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 245 | for (i = 0; i < MAX_MM_MODULE_TYPE; i++) { |
| 246 | for (j = 0; j < MAX_QAF_MODULE_IN; j++) { |
| 247 | if (p_qaf->qaf_mod[i].stream_in[j] == out) { |
| 248 | qaf_mod = &(p_qaf->qaf_mod[i]); |
| 249 | break; |
| 250 | } |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | return qaf_mod; |
Deepak Agarwal | 1e42b85 | 2017-02-11 17:57:04 +0530 | [diff] [blame] | 255 | } |
| 256 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 257 | /* Finds the mm module input stream index for the QAF input stream. */ |
| 258 | static int get_input_stream_index(struct stream_out *out) |
| 259 | { |
| 260 | int index = -1, j; |
| 261 | struct qaf_module* qaf_mod = NULL; |
| 262 | |
| 263 | qaf_mod = get_qaf_module_for_input_stream(out); |
| 264 | if (!qaf_mod) return index; |
| 265 | |
| 266 | for (j = 0; j < MAX_QAF_MODULE_IN; j++) { |
| 267 | if (qaf_mod->stream_in[j] == out) { |
| 268 | index = j; |
| 269 | break; |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | return index; |
| 274 | } |
| 275 | |
| 276 | /* Finds the right mm module for the QAF input stream format. */ |
| 277 | static mm_module_type get_mm_module_for_format(audio_format_t format) |
| 278 | { |
| 279 | int j; |
| 280 | |
| 281 | DEBUG_MSG("Format 0x%x", format); |
| 282 | |
| 283 | if (format == AUDIO_FORMAT_PCM_16_BIT) { |
| 284 | //If dts is not supported then alway support pcm with MS12 |
Aniket Kumar Lata | 8fc67e6 | 2017-05-02 12:33:46 -0700 | [diff] [blame] | 285 | if (!property_get_bool("vendor.audio.qaf.dts_m8", false)) { //TODO: Need to add this property for DTS. |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 286 | return MS12; |
| 287 | } |
| 288 | |
| 289 | //If QAF passthrough is active then send the PCM stream to primary HAL. |
| 290 | if (!p_qaf->passthrough_out) { |
| 291 | /* Iff any stream is active in MS12 module then route PCM stream to it. */ |
| 292 | for (j = 0; j < MAX_QAF_MODULE_IN; j++) { |
| 293 | if (p_qaf->qaf_mod[MS12].stream_in[j]) { |
| 294 | return MS12; |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | return INVALID_MM_MODULE; |
| 299 | } |
| 300 | |
| 301 | switch (format & AUDIO_FORMAT_MAIN_MASK) { |
| 302 | case AUDIO_FORMAT_AC3: |
| 303 | case AUDIO_FORMAT_E_AC3: |
| 304 | case AUDIO_FORMAT_AAC: |
| 305 | case AUDIO_FORMAT_AAC_ADTS: |
| 306 | case AUDIO_FORMAT_AC4: |
| 307 | return MS12; |
| 308 | case AUDIO_FORMAT_DTS: |
| 309 | case AUDIO_FORMAT_DTS_HD: |
| 310 | return DTS_M8; |
| 311 | default: |
| 312 | return INVALID_MM_MODULE; |
| 313 | } |
| 314 | } |
| 315 | |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 316 | static bool is_main_active(struct qaf_module* qaf_mod) |
| 317 | { |
| 318 | return (qaf_mod->stream_in[QAF_IN_MAIN] || qaf_mod->stream_in[QAF_IN_MAIN_2]); |
| 319 | } |
| 320 | |
| 321 | static bool is_dual_main_active(struct qaf_module* qaf_mod) |
| 322 | { |
| 323 | return (qaf_mod->stream_in[QAF_IN_MAIN] && qaf_mod->stream_in[QAF_IN_MAIN_2]); |
| 324 | } |
| 325 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 326 | /* Gets the pcm output buffer size(in samples) for the mm module. */ |
| 327 | static uint32_t get_pcm_output_buffer_size_samples(struct qaf_module *qaf_mod) |
| 328 | { |
| 329 | uint32_t pcm_output_buffer_size = 0; |
| 330 | |
| 331 | if (qaf_mod == &p_qaf->qaf_mod[MS12]) { |
| 332 | pcm_output_buffer_size = MS12_PCM_OUT_FRAGMENT_SIZE; |
| 333 | } else if (qaf_mod == &p_qaf->qaf_mod[DTS_M8]) { |
| 334 | pcm_output_buffer_size = DTS_PCM_OUT_FRAGMENT_SIZE; |
| 335 | } |
| 336 | |
| 337 | return pcm_output_buffer_size; |
| 338 | } |
| 339 | |
| 340 | /* Acquire Mutex lock on output stream */ |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 341 | static void lock_output_stream(struct stream_out *out) |
| 342 | { |
| 343 | pthread_mutex_lock(&out->pre_lock); |
| 344 | pthread_mutex_lock(&out->lock); |
| 345 | pthread_mutex_unlock(&out->pre_lock); |
| 346 | } |
| 347 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 348 | /* Release Mutex lock on output stream */ |
| 349 | static void unlock_output_stream(struct stream_out *out) |
| 350 | { |
| 351 | pthread_mutex_unlock(&out->lock); |
| 352 | } |
| 353 | |
| 354 | /* Checks if stream can be routed as QAF passthrough or not. */ |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 355 | static bool audio_extn_qaf_passthrough_enabled(struct stream_out *out) |
| 356 | { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 357 | DEBUG_MSG("Format 0x%x", out->format); |
| 358 | bool is_enabled = false; |
| 359 | |
| 360 | if (!p_qaf) return false; |
| 361 | |
Aniket Kumar Lata | 8fc67e6 | 2017-05-02 12:33:46 -0700 | [diff] [blame] | 362 | if ((!property_get_bool("vendor.audio.qaf.reencode", false)) |
| 363 | && property_get_bool("vendor.audio.qaf.passthrough", false)) { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 364 | |
| 365 | if ((out->format == AUDIO_FORMAT_PCM_16_BIT) && (popcount(out->channel_mask) > 2)) { |
| 366 | is_enabled = true; |
Aniket Kumar Lata | 8fc67e6 | 2017-05-02 12:33:46 -0700 | [diff] [blame] | 367 | } else if (property_get_bool("vendor.audio.offload.passthrough", false)) { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 368 | switch (out->format) { |
| 369 | case AUDIO_FORMAT_AC3: |
| 370 | case AUDIO_FORMAT_E_AC3: |
| 371 | case AUDIO_FORMAT_DTS: |
Ben Romberger | 1aaaf86 | 2017-04-06 17:49:46 -0700 | [diff] [blame] | 372 | case AUDIO_FORMAT_DTS_HD: |
Naresh Tanniru | 928f086 | 2017-04-07 16:44:23 -0700 | [diff] [blame] | 373 | case AUDIO_FORMAT_DOLBY_TRUEHD: |
| 374 | case AUDIO_FORMAT_IEC61937: { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 375 | is_enabled = true; |
| 376 | break; |
| 377 | } |
| 378 | default: |
| 379 | is_enabled = false; |
| 380 | break; |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 381 | } |
| 382 | } |
| 383 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 384 | |
| 385 | return is_enabled; |
| 386 | } |
| 387 | |
| 388 | /*Closes all pcm hdmi output from QAF. */ |
| 389 | static void close_all_pcm_hdmi_output() |
| 390 | { |
| 391 | int i; |
| 392 | //Closing all the PCM HDMI output stream from QAF. |
| 393 | for (i = 0; i < MAX_MM_MODULE_TYPE; i++) { |
| 394 | if (p_qaf->qaf_mod[i].stream_out[QAF_OUT_OFFLOAD_MCH]) { |
| 395 | adev_close_output_stream((struct audio_hw_device *)p_qaf->adev, |
| 396 | (struct audio_stream_out *)(p_qaf->qaf_mod[i].stream_out[QAF_OUT_OFFLOAD_MCH])); |
| 397 | p_qaf->qaf_mod[i].stream_out[QAF_OUT_OFFLOAD_MCH] = NULL; |
| 398 | } |
| 399 | |
| 400 | if ((p_qaf->qaf_mod[i].stream_out[QAF_OUT_OFFLOAD]) |
| 401 | && (p_qaf->qaf_mod[i].stream_out[QAF_OUT_OFFLOAD]->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL)) { |
| 402 | adev_close_output_stream((struct audio_hw_device *)p_qaf->adev, |
| 403 | (struct audio_stream_out *)(p_qaf->qaf_mod[i].stream_out[QAF_OUT_OFFLOAD])); |
| 404 | p_qaf->qaf_mod[i].stream_out[QAF_OUT_OFFLOAD] = NULL; |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | p_qaf->mch_pcm_hdmi_enabled = 0; |
| 409 | } |
| 410 | |
| 411 | static void close_all_hdmi_output() |
| 412 | { |
| 413 | int k; |
| 414 | for (k = 0; k < MAX_MM_MODULE_TYPE; k++) { |
| 415 | if (p_qaf->qaf_mod[k].stream_out[QAF_OUT_TRANSCODE_PASSTHROUGH]) { |
| 416 | adev_close_output_stream((struct audio_hw_device *)p_qaf->adev, |
| 417 | (struct audio_stream_out *)(p_qaf->qaf_mod[k].stream_out[QAF_OUT_TRANSCODE_PASSTHROUGH])); |
| 418 | p_qaf->qaf_mod[k].stream_out[QAF_OUT_TRANSCODE_PASSTHROUGH] = NULL; |
| 419 | } |
| 420 | } |
| 421 | p_qaf->passthrough_enabled = 0; |
| 422 | |
| 423 | close_all_pcm_hdmi_output(); |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | static int qaf_out_callback(stream_callback_event_t event, void *param __unused, void *cookie) |
| 427 | { |
| 428 | struct stream_out *out = (struct stream_out *)cookie; |
| 429 | |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 430 | out->client_callback(event, NULL, out->client_cookie); |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 431 | return 0; |
| 432 | } |
| 433 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 434 | /* Creates the QAF passthrough output stream. */ |
| 435 | static int create_qaf_passthrough_stream() |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 436 | { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 437 | DEBUG_MSG(); |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 438 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 439 | int ret = 0, k; |
| 440 | struct stream_out *out = p_qaf->passthrough_in; |
| 441 | |
| 442 | if (!out) return -EINVAL; |
| 443 | |
| 444 | pthread_mutex_lock(&p_qaf->lock); |
| 445 | lock_output_stream(out); |
| 446 | |
| 447 | //Creating QAF passthrough output stream. |
| 448 | if (NULL == p_qaf->passthrough_out) { |
| 449 | audio_output_flags_t flags; |
| 450 | struct audio_config config; |
| 451 | audio_devices_t devices; |
| 452 | |
| 453 | config.sample_rate = config.offload_info.sample_rate = out->sample_rate; |
| 454 | config.offload_info.version = AUDIO_INFO_INITIALIZER.version; |
| 455 | config.offload_info.size = AUDIO_INFO_INITIALIZER.size; |
| 456 | config.offload_info.format = out->format; |
| 457 | config.offload_info.bit_width = out->bit_width; |
| 458 | config.format = out->format; |
| 459 | config.offload_info.channel_mask = config.channel_mask = out->channel_mask; |
| 460 | |
| 461 | //Device is copied from the QAF passthrough input stream. |
| 462 | devices = out->devices; |
| 463 | flags = out->flags; |
| 464 | |
| 465 | ret = adev_open_output_stream((struct audio_hw_device *)p_qaf->adev, |
| 466 | QAF_DEFAULT_PASSTHROUGH_HANDLE, |
| 467 | devices, |
| 468 | flags, |
| 469 | &config, |
| 470 | (struct audio_stream_out **)&(p_qaf->passthrough_out), |
| 471 | NULL); |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 472 | if (ret < 0) { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 473 | ERROR_MSG("adev_open_output_stream failed with ret = %d!", ret); |
| 474 | unlock_output_stream(out); |
| 475 | return ret; |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 476 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 477 | p_qaf->passthrough_in = out; |
| 478 | p_qaf->passthrough_out->stream.set_callback((struct audio_stream_out *)p_qaf->passthrough_out, |
| 479 | (stream_callback_t) qaf_out_callback, out); |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 480 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 481 | |
| 482 | unlock_output_stream(out); |
| 483 | |
| 484 | //Since QAF-Passthrough is created, close other HDMI outputs. |
| 485 | close_all_hdmi_output(); |
| 486 | |
| 487 | pthread_mutex_unlock(&p_qaf->lock); |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 488 | return ret; |
| 489 | } |
| 490 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 491 | /* Closes the QAF passthrough output stream. */ |
| 492 | static void close_qaf_passthrough_stream() |
| 493 | { |
| 494 | if (p_qaf->passthrough_out != NULL) { //QAF pasthroug is enabled. Close it. |
| 495 | pthread_mutex_lock(&p_qaf->lock); |
| 496 | adev_close_output_stream((struct audio_hw_device *)p_qaf->adev, |
| 497 | (struct audio_stream_out *)(p_qaf->passthrough_out)); |
| 498 | p_qaf->passthrough_out = NULL; |
| 499 | pthread_mutex_unlock(&p_qaf->lock); |
| 500 | |
| 501 | if (p_qaf->passthrough_in->qaf_stream_handle) { |
| 502 | qaf_out_pause((struct audio_stream_out*)p_qaf->passthrough_in); |
| 503 | qaf_out_flush((struct audio_stream_out*)p_qaf->passthrough_in); |
| 504 | qaf_out_drain((struct audio_stream_out*)p_qaf->passthrough_in, |
| 505 | (audio_drain_type_t)STREAM_CBK_EVENT_DRAIN_READY); |
| 506 | } |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | /* Sends a command to output stream offload thread. */ |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 511 | static int qaf_send_offload_cmd_l(struct stream_out* out, int command) |
| 512 | { |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 513 | DEBUG_MSG_VV("command is %d", command); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 514 | |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 515 | struct offload_cmd *cmd = (struct offload_cmd *)calloc(1, sizeof(struct offload_cmd)); |
| 516 | |
| 517 | if (!cmd) { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 518 | ERROR_MSG("failed to allocate mem for command 0x%x", command); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 519 | return -ENOMEM; |
| 520 | } |
| 521 | |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 522 | cmd->cmd = command; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 523 | |
| 524 | lock_output_stream(out); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 525 | list_add_tail(&out->qaf_offload_cmd_list, &cmd->node); |
| 526 | pthread_cond_signal(&out->qaf_offload_cond); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 527 | unlock_output_stream(out); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 528 | return 0; |
| 529 | } |
| 530 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 531 | /* Stops a QAF module stream.*/ |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 532 | static int audio_extn_qaf_stream_stop(struct stream_out *out) |
| 533 | { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 534 | int ret = 0; |
| 535 | DEBUG_MSG("Output Stream 0x%x", out); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 536 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 537 | struct qaf_module *qaf_mod = get_qaf_module_for_input_stream(out); |
| 538 | if ((!qaf_mod) || (!qaf_mod->qaf_audio_stream_stop)) { |
| 539 | return ret; |
| 540 | } |
| 541 | |
| 542 | if (out->qaf_stream_handle) { |
| 543 | ret = qaf_mod->qaf_audio_stream_stop(out->qaf_stream_handle); |
| 544 | } |
| 545 | |
| 546 | return ret; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 547 | } |
| 548 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 549 | /* Puts a QAF module stream in standby. */ |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 550 | static int qaf_out_standby(struct audio_stream *stream) |
| 551 | { |
| 552 | struct stream_out *out = (struct stream_out *)stream; |
| 553 | int status = 0; |
| 554 | |
| 555 | ALOGD("%s: enter: stream (%p) usecase(%d: %s)", __func__, |
| 556 | stream, out->usecase, use_case_table[out->usecase]); |
| 557 | |
| 558 | lock_output_stream(out); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 559 | |
| 560 | //If QAF passthrough is active then block standby on all the input streams of QAF mm modules. |
| 561 | if (p_qaf->passthrough_out) { |
| 562 | //If standby is received on QAF passthrough stream then forward it to primary HAL. |
| 563 | if (p_qaf->passthrough_in == out) { |
| 564 | status = p_qaf->passthrough_out->stream.common.standby( |
| 565 | (struct audio_stream *)p_qaf->passthrough_out); |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 566 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 567 | } else { |
| 568 | //If QAF passthrough stream is not active then stop the QAF module stream. |
| 569 | status = audio_extn_qaf_stream_stop(out); |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 570 | } |
| 571 | |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 572 | if (!out->standby) { |
| 573 | out->standby = true; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 574 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 575 | |
| 576 | unlock_output_stream(out); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 577 | return status; |
| 578 | } |
| 579 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 580 | /* Sets the volume to PCM output stream. */ |
| 581 | static int qaf_out_set_volume(struct audio_stream_out *stream, float left, float right) |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 582 | { |
| 583 | int ret = 0; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 584 | struct stream_out *out = (struct stream_out *)stream; |
| 585 | struct qaf_module *qaf_mod = NULL; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 586 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 587 | DEBUG_MSG("Left %f, Right %f", left, right); |
| 588 | |
| 589 | qaf_mod = get_qaf_module_for_input_stream(out); |
| 590 | if (!qaf_mod) { |
| 591 | return -EINVAL; |
| 592 | } |
| 593 | |
| 594 | pthread_mutex_lock(&p_qaf->lock); |
| 595 | qaf_mod->vol_left = left; |
| 596 | qaf_mod->vol_right = right; |
| 597 | qaf_mod->is_vol_set = true; |
| 598 | pthread_mutex_unlock(&p_qaf->lock); |
| 599 | |
| 600 | if (qaf_mod->stream_out[QAF_OUT_OFFLOAD] != NULL) { |
| 601 | ret = qaf_mod->stream_out[QAF_OUT_OFFLOAD]->stream.set_volume( |
| 602 | (struct audio_stream_out *)qaf_mod->stream_out[QAF_OUT_OFFLOAD], left, right); |
| 603 | } |
| 604 | |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 605 | return ret; |
| 606 | } |
| 607 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 608 | /* Starts a QAF module stream. */ |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 609 | static int qaf_stream_start(struct stream_out *out) |
| 610 | { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 611 | int ret = -EINVAL; |
| 612 | struct qaf_module *qaf_mod = NULL; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 613 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 614 | DEBUG_MSG("Output Stream = %p", out); |
| 615 | |
| 616 | qaf_mod = get_qaf_module_for_input_stream(out); |
| 617 | if ((!qaf_mod) || (!qaf_mod->qaf_audio_stream_start)) { |
| 618 | return -EINVAL; |
| 619 | } |
| 620 | |
| 621 | if (out->qaf_stream_handle) { |
| 622 | ret = qaf_mod->qaf_audio_stream_start(out->qaf_stream_handle); |
| 623 | } |
| 624 | |
| 625 | return ret; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | static int qaf_start_output_stream(struct stream_out *out) |
| 629 | { |
| 630 | int ret = 0; |
| 631 | struct audio_device *adev = out->dev; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 632 | |
| 633 | if ((out->usecase < 0) || (out->usecase >= AUDIO_USECASE_MAX)) { |
| 634 | ret = -EINVAL; |
| 635 | usleep(50000); |
| 636 | return ret; |
| 637 | } |
| 638 | |
| 639 | ALOGD("%s: enter: stream(%p)usecase(%d: %s) devices(%#x)", |
| 640 | __func__, &out->stream, out->usecase, use_case_table[out->usecase], |
| 641 | out->devices); |
| 642 | |
Dhananjay Kumar | e6293dd | 2017-05-25 17:25:30 +0530 | [diff] [blame] | 643 | if (CARD_STATUS_OFFLINE == out->card_status || |
| 644 | CARD_STATUS_OFFLINE == adev->card_status) { |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 645 | ALOGE("%s: sound card is not active/SSR returning error", __func__); |
| 646 | ret = -EIO; |
| 647 | usleep(50000); |
| 648 | return ret; |
| 649 | } |
| 650 | |
| 651 | return qaf_stream_start(out); |
| 652 | } |
| 653 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 654 | /* Sends input buffer to the QAF MM module. */ |
| 655 | static int qaf_module_write_input_buffer(struct stream_out *out, const void *buffer, int bytes) |
| 656 | { |
| 657 | int ret = -EINVAL; |
| 658 | struct qaf_module *qaf_mod = NULL; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 659 | |
| 660 | qaf_mod = get_qaf_module_for_input_stream(out); |
| 661 | if ((!qaf_mod) || (!qaf_mod->qaf_audio_stream_write)) { |
| 662 | return ret; |
| 663 | } |
| 664 | |
| 665 | if (out->qaf_stream_handle) { |
| 666 | ret = qaf_mod->qaf_audio_stream_write(out->qaf_stream_handle, buffer, bytes); |
| 667 | } |
| 668 | return ret; |
| 669 | } |
| 670 | |
| 671 | /* Writes buffer to QAF input stream. */ |
| 672 | static ssize_t qaf_out_write(struct audio_stream_out *stream, const void *buffer, size_t bytes) |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 673 | { |
| 674 | struct stream_out *out = (struct stream_out *)stream; |
| 675 | struct audio_device *adev = out->dev; |
| 676 | ssize_t ret = 0; |
| 677 | |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 678 | DEBUG_MSG_VV("bytes = %d, usecase[%d] and flags[%x] for handle[%p]", |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 679 | (int)bytes, out->usecase, out->flags, out); |
| 680 | |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 681 | lock_output_stream(out); |
| 682 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 683 | // If QAF passthrough is active then block writing data to QAF mm module. |
| 684 | if (p_qaf->passthrough_out) { |
| 685 | //If write is received for the QAF passthrough stream then send the buffer to primary HAL. |
| 686 | if (p_qaf->passthrough_in == out) { |
| 687 | ret = p_qaf->passthrough_out->stream.write( |
| 688 | (struct audio_stream_out *)(p_qaf->passthrough_out), |
| 689 | buffer, |
| 690 | bytes); |
| 691 | if (ret > 0) out->standby = false; |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 692 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 693 | unlock_output_stream(out); |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 694 | return ret; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 695 | } else if (out->standby) { |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 696 | pthread_mutex_lock(&adev->lock); |
| 697 | ret = qaf_start_output_stream(out); |
| 698 | pthread_mutex_unlock(&adev->lock); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 699 | if (ret == 0) { |
| 700 | out->standby = false; |
| 701 | } else { |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 702 | goto exit; |
| 703 | } |
| 704 | } |
| 705 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 706 | if ((adev->is_channel_status_set == false) && (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL)) { |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 707 | audio_utils_set_hdmi_channel_status(out, (char *)buffer, bytes); |
| 708 | adev->is_channel_status_set = true; |
| 709 | } |
| 710 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 711 | ret = qaf_module_write_input_buffer(out, buffer, bytes); |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 712 | DEBUG_MSG_VV("ret [%d]", (int)ret); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 713 | |
| 714 | if (ret >= 0) { |
| 715 | bytes = ret; |
| 716 | out->written += bytes / ((popcount(out->channel_mask) * sizeof(short))); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 717 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 718 | |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 719 | |
| 720 | exit: |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 721 | unlock_output_stream(out); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 722 | |
| 723 | if (ret < 0) { |
| 724 | if (ret == -EAGAIN) { |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 725 | DEBUG_MSG_VV("No space available in mm module, post msg to cb thread"); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 726 | ret = qaf_send_offload_cmd_l(out, OFFLOAD_CMD_WAIT_FOR_BUFFER); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 727 | bytes = 0; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 728 | } else if (ret == -ENOMEM || ret == -EPERM) { |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 729 | if (out->pcm) |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 730 | ERROR_MSG("error %d, %s", (int)ret, pcm_get_error(out->pcm)); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 731 | qaf_out_standby(&out->stream.common); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 732 | usleep(bytes * 1000000 |
| 733 | / audio_stream_out_frame_size(stream) |
| 734 | / out->stream.common.get_sample_rate(&out->stream.common)); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 735 | } |
| 736 | } |
| 737 | return bytes; |
| 738 | } |
| 739 | |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 740 | /* Gets PCM offload buffer size for a given config. */ |
| 741 | static uint32_t qaf_get_pcm_offload_buffer_size(audio_offload_info_t* info, |
| 742 | uint32_t samples_per_frame) |
Varun B | 34da7a4 | 2017-02-13 16:16:53 +0530 | [diff] [blame] | 743 | { |
| 744 | uint32_t fragment_size = 0; |
Varun B | 34da7a4 | 2017-02-13 16:16:53 +0530 | [diff] [blame] | 745 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 746 | fragment_size = (samples_per_frame * (info->bit_width >> 3) * popcount(info->channel_mask)); |
| 747 | |
| 748 | if (fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE) |
Varun B | 34da7a4 | 2017-02-13 16:16:53 +0530 | [diff] [blame] | 749 | fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 750 | else if (fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE) |
Varun B | 34da7a4 | 2017-02-13 16:16:53 +0530 | [diff] [blame] | 751 | fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 752 | |
Varun B | 34da7a4 | 2017-02-13 16:16:53 +0530 | [diff] [blame] | 753 | // To have same PCM samples for all channels, the buffer size requires to |
| 754 | // be multiple of (number of channels * bytes per sample) |
| 755 | // For writes to succeed, the buffer must be written at address which is multiple of 32 |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 756 | fragment_size = ALIGN(fragment_size, |
| 757 | ((info->bit_width >> 3) * popcount(info->channel_mask) * 32)); |
Varun B | 34da7a4 | 2017-02-13 16:16:53 +0530 | [diff] [blame] | 758 | |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 759 | ALOGI("Qaf PCM offload Fragment size is %d bytes", fragment_size); |
Varun B | 34da7a4 | 2017-02-13 16:16:53 +0530 | [diff] [blame] | 760 | |
| 761 | return fragment_size; |
| 762 | } |
| 763 | |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 764 | static uint32_t qaf_get_pcm_offload_input_buffer_size(info) |
| 765 | { |
| 766 | return qaf_get_pcm_offload_buffer_size(info, MS12_PCM_IN_FRAGMENT_SIZE); |
| 767 | } |
| 768 | |
| 769 | static uint32_t qaf_get_pcm_offload_output_buffer_size(struct qaf_module *qaf_mod, |
| 770 | audio_offload_info_t* info) |
| 771 | { |
| 772 | return qaf_get_pcm_offload_buffer_size(info, get_pcm_output_buffer_size_samples(qaf_mod)); |
| 773 | } |
| 774 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 775 | /* Gets buffer latency in samples. */ |
| 776 | static int get_buffer_latency(struct stream_out *out, uint32_t buffer_size, uint32_t *latency) |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 777 | { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 778 | unsigned long int samples_in_one_encoded_frame; |
| 779 | unsigned long int size_of_one_encoded_frame; |
| 780 | |
| 781 | switch (out->format) { |
| 782 | case AUDIO_FORMAT_AC3: |
| 783 | samples_in_one_encoded_frame = DD_FRAME_SIZE; |
| 784 | size_of_one_encoded_frame = DD_ENCODER_OUTPUT_SIZE; |
| 785 | break; |
| 786 | case AUDIO_FORMAT_E_AC3: |
| 787 | samples_in_one_encoded_frame = DDP_FRAME_SIZE; |
| 788 | size_of_one_encoded_frame = DDP_ENCODER_OUTPUT_SIZE; |
| 789 | break; |
| 790 | case AUDIO_FORMAT_DTS: |
| 791 | samples_in_one_encoded_frame = DTS_FRAME_SIZE; |
| 792 | size_of_one_encoded_frame = DTS_ENCODER_OUTPUT_SIZE; |
| 793 | break; |
| 794 | case AUDIO_FORMAT_DTS_HD: |
| 795 | samples_in_one_encoded_frame = DTSHD_FRAME_SIZE; |
| 796 | size_of_one_encoded_frame = DTSHD_ENCODER_OUTPUT_SIZE; |
| 797 | break; |
| 798 | case AUDIO_FORMAT_PCM_16_BIT: |
| 799 | samples_in_one_encoded_frame = 1; |
| 800 | size_of_one_encoded_frame = ((out->bit_width) >> 3) * popcount(out->channel_mask); |
| 801 | break; |
| 802 | default: |
| 803 | *latency = 0; |
| 804 | return (-EINVAL); |
| 805 | } |
| 806 | |
| 807 | *latency = ((buffer_size * samples_in_one_encoded_frame) / size_of_one_encoded_frame); |
| 808 | return 0; |
| 809 | } |
| 810 | |
| 811 | /* Returns the number of frames rendered to outside observer. */ |
| 812 | static int qaf_get_rendered_frames(struct stream_out *out, uint64_t *frames) |
| 813 | { |
| 814 | int ret = 0, i; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 815 | struct str_parms *parms; |
| 816 | int value = 0; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 817 | int module_latency = 0; |
| 818 | uint32_t kernel_latency = 0; |
| 819 | uint32_t dsp_latency = 0; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 820 | int signed_frames = 0; |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 821 | char* kvpairs = NULL; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 822 | struct qaf_module *qaf_mod = NULL; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 823 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 824 | DEBUG_MSG("Output Format %d", out->format); |
| 825 | |
| 826 | qaf_mod = get_qaf_module_for_input_stream(out); |
| 827 | if ((!qaf_mod) || (!qaf_mod->qaf_audio_stream_get_param)) { |
| 828 | return -EINVAL; |
| 829 | } |
| 830 | |
| 831 | //Get MM module latency. |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 832 | kvpairs = qaf_mod->qaf_audio_stream_get_param(out->qaf_stream_handle, "get_latency"); |
| 833 | if (kvpairs) { |
| 834 | parms = str_parms_create_str(kvpairs); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 835 | ret = str_parms_get_int(parms, "get_latency", &module_latency); |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 836 | if (ret >= 0) { |
| 837 | str_parms_destroy(parms); |
| 838 | parms = NULL; |
| 839 | } |
| 840 | free(kvpairs); |
| 841 | kvpairs = NULL; |
| 842 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 843 | |
| 844 | //Get kernel Latency |
| 845 | for (i = MAX_QAF_MODULE_OUT - 1; i >= 0; i--) { |
| 846 | if (qaf_mod->stream_out[i] == NULL) { |
| 847 | continue; |
| 848 | } else { |
| 849 | unsigned int num_fragments = qaf_mod->stream_out[i]->compr_config.fragments; |
| 850 | uint32_t fragment_size = qaf_mod->stream_out[i]->compr_config.fragment_size; |
| 851 | uint32_t kernel_buffer_size = num_fragments * fragment_size; |
| 852 | get_buffer_latency(qaf_mod->stream_out[i], kernel_buffer_size, &kernel_latency); |
| 853 | break; |
| 854 | } |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 855 | } |
| 856 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 857 | //Get DSP latency |
| 858 | if ((qaf_mod->stream_out[QAF_OUT_OFFLOAD] != NULL) |
| 859 | || (qaf_mod->stream_out[QAF_OUT_OFFLOAD_MCH] != NULL)) { |
| 860 | unsigned int sample_rate = 0; |
| 861 | |
| 862 | if (qaf_mod->stream_out[QAF_OUT_OFFLOAD]) |
| 863 | sample_rate = qaf_mod->stream_out[QAF_OUT_OFFLOAD]->sample_rate; |
| 864 | else if (qaf_mod->stream_out[QAF_OUT_OFFLOAD_MCH]) |
| 865 | sample_rate = qaf_mod->stream_out[QAF_OUT_OFFLOAD_MCH]->sample_rate; |
| 866 | |
| 867 | audio_usecase_t platform_latency = |
| 868 | platform_render_latency(qaf_mod->stream_out[QAF_OUT_OFFLOAD]->usecase); |
| 869 | dsp_latency = (platform_latency * sample_rate) / 1000000LL; |
| 870 | } else if (qaf_mod->stream_out[QAF_OUT_TRANSCODE_PASSTHROUGH] != NULL) { |
| 871 | unsigned int sample_rate = 0; |
| 872 | |
| 873 | sample_rate = qaf_mod->stream_out[QAF_OUT_TRANSCODE_PASSTHROUGH]->sample_rate; //TODO: How this sample rate can be used? |
| 874 | dsp_latency = (COMPRESS_OFFLOAD_PLAYBACK_LATENCY * sample_rate) / 1000; |
| 875 | } |
| 876 | |
| 877 | // MM Module Latency + Kernel Latency + DSP Latency |
| 878 | if ( audio_extn_bt_hal_get_output_stream(qaf_mod->bt_hdl) != NULL) { |
| 879 | out->platform_latency = module_latency + audio_extn_bt_hal_get_latency(qaf_mod->bt_hdl); |
| 880 | } else { |
| 881 | out->platform_latency = (uint32_t)module_latency + kernel_latency + dsp_latency; |
| 882 | } |
| 883 | |
| 884 | if (out->format & AUDIO_FORMAT_PCM_16_BIT) { |
| 885 | *frames = 0; |
| 886 | signed_frames = out->written - out->platform_latency; |
| 887 | // It would be unusual for this value to be negative, but check just in case ... |
| 888 | if (signed_frames >= 0) { |
| 889 | *frames = signed_frames; |
| 890 | } |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 891 | } else if (qaf_mod->qaf_audio_stream_get_param) { |
| 892 | kvpairs = qaf_mod->qaf_audio_stream_get_param(out->qaf_stream_handle, "position"); |
| 893 | if (kvpairs) { |
| 894 | parms = str_parms_create_str(kvpairs); |
| 895 | ret = str_parms_get_int(parms, "position", &value); |
| 896 | if (ret >= 0) { |
| 897 | *frames = value; |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 898 | signed_frames = value - out->platform_latency; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 899 | // It would be unusual for this value to be negative, but check just in case ... |
| 900 | if (signed_frames >= 0) { |
| 901 | *frames = signed_frames; |
| 902 | } |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 903 | } |
| 904 | str_parms_destroy(parms); |
| 905 | } |
| 906 | } else { |
| 907 | ret = -EINVAL; |
| 908 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 909 | |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 910 | return ret; |
| 911 | } |
| 912 | |
| 913 | static int qaf_out_get_presentation_position(const struct audio_stream_out *stream, |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 914 | uint64_t *frames, |
| 915 | struct timespec *timestamp) |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 916 | { |
| 917 | struct stream_out *out = (struct stream_out *)stream; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 918 | int ret = 0; |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 919 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 920 | DEBUG_MSG("Output Stream %p", stream); |
| 921 | |
| 922 | //If QAF passthorugh output stream is active. |
| 923 | if (p_qaf->passthrough_out) { |
| 924 | if (p_qaf->passthrough_in == out) { |
| 925 | //If api is called for QAF passthorugh stream then call the primary HAL api to get the position. |
| 926 | pthread_mutex_lock(&p_qaf->lock); |
| 927 | ret = p_qaf->passthrough_out->stream.get_presentation_position( |
| 928 | (struct audio_stream_out *)p_qaf->passthrough_out, |
| 929 | frames, |
| 930 | timestamp); |
| 931 | pthread_mutex_unlock(&p_qaf->lock); |
| 932 | } else { |
| 933 | //If api is called for other stream then return zero frames. |
| 934 | *frames = 0; |
| 935 | clock_gettime(CLOCK_MONOTONIC, timestamp); |
| 936 | } |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 937 | return ret; |
| 938 | } |
| 939 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 940 | ret = qaf_get_rendered_frames(out, frames); |
| 941 | clock_gettime(CLOCK_MONOTONIC, timestamp); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 942 | |
| 943 | return ret; |
| 944 | } |
| 945 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 946 | /* Pause the QAF module input stream. */ |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 947 | static int qaf_stream_pause(struct stream_out *out) |
| 948 | { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 949 | struct qaf_module *qaf_mod = NULL; |
| 950 | int ret = -EINVAL; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 951 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 952 | qaf_mod = get_qaf_module_for_input_stream(out); |
| 953 | if (!qaf_mod || !qaf_mod->qaf_audio_stream_pause) { |
| 954 | return -EINVAL; |
| 955 | } |
| 956 | |
| 957 | if (out->qaf_stream_handle) |
| 958 | ret = qaf_mod->qaf_audio_stream_pause(out->qaf_stream_handle); |
| 959 | |
| 960 | return ret; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 961 | } |
| 962 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 963 | /* Pause a QAF input stream. */ |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 964 | static int qaf_out_pause(struct audio_stream_out* stream) |
| 965 | { |
| 966 | struct stream_out *out = (struct stream_out *)stream; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 967 | int status = 0; |
| 968 | DEBUG_MSG("Output Stream %p", out); |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 969 | |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 970 | lock_output_stream(out); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 971 | |
| 972 | //If QAF passthrough is enabled then block the pause on module stream. |
| 973 | if (p_qaf->passthrough_out) { |
| 974 | pthread_mutex_lock(&p_qaf->lock); |
| 975 | //If pause is received for QAF passthorugh stream then call the primary HAL api. |
| 976 | if (p_qaf->passthrough_in == out) { |
| 977 | status = p_qaf->passthrough_out->stream.pause( |
| 978 | (struct audio_stream_out *)p_qaf->passthrough_out); |
| 979 | out->offload_state = OFFLOAD_STATE_PAUSED; |
| 980 | } |
| 981 | pthread_mutex_unlock(&p_qaf->lock); |
| 982 | } else { |
| 983 | //Pause the module input stream. |
| 984 | status = qaf_stream_pause(out); |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 985 | } |
| 986 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 987 | unlock_output_stream(out); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 988 | return status; |
| 989 | } |
| 990 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 991 | /* Drains a qaf input stream. */ |
| 992 | static int qaf_out_drain(struct audio_stream_out* stream, audio_drain_type_t type) |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 993 | { |
| 994 | struct stream_out *out = (struct stream_out *)stream; |
| 995 | int status = 0; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 996 | DEBUG_MSG("Output Stream %p", out); |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 997 | |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 998 | lock_output_stream(out); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 999 | |
| 1000 | //If QAF passthrough is enabled then block the drain on module stream. |
| 1001 | if (p_qaf->passthrough_out) { |
| 1002 | pthread_mutex_lock(&p_qaf->lock); |
| 1003 | //If drain is received for QAF passthorugh stream then call the primary HAL api. |
| 1004 | if (p_qaf->passthrough_in == out) { |
| 1005 | status = p_qaf->passthrough_out->stream.drain( |
| 1006 | (struct audio_stream_out *)p_qaf->passthrough_out, type); |
| 1007 | } |
| 1008 | pthread_mutex_unlock(&p_qaf->lock); |
| 1009 | } else { |
| 1010 | //Drain the module input stream. |
| 1011 | /* Stream stop will trigger EOS and on EOS_EVENT received |
| 1012 | from callback DRAIN_READY command is sent */ |
| 1013 | status = audio_extn_qaf_stream_stop(out); |
| 1014 | |
| 1015 | if (status == 0) { |
| 1016 | struct qaf_module *qaf_mod = get_qaf_module_for_input_stream(out); |
| 1017 | int index = get_input_stream_index(out); |
| 1018 | if (qaf_mod && index >= 0) qaf_mod->drain_received[index] = true; |
| 1019 | } |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 1020 | } |
| 1021 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1022 | unlock_output_stream(out); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1023 | return status; |
| 1024 | } |
| 1025 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1026 | /* Flush the QAF module input stream. */ |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1027 | static int audio_extn_qaf_stream_flush(struct stream_out *out) |
| 1028 | { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1029 | DEBUG_MSG("Output Stream %p", out); |
| 1030 | int ret = -EINVAL; |
| 1031 | struct qaf_module *qaf_mod = NULL; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1032 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1033 | qaf_mod = get_qaf_module_for_input_stream(out); |
| 1034 | if ((!qaf_mod) || (!qaf_mod->qaf_audio_stream_flush)) { |
| 1035 | return -EINVAL; |
| 1036 | } |
| 1037 | |
| 1038 | if (out->qaf_stream_handle) |
| 1039 | ret = qaf_mod->qaf_audio_stream_flush(out->qaf_stream_handle); |
| 1040 | |
| 1041 | return ret; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1042 | } |
| 1043 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1044 | /* Flush the QAF input stream. */ |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1045 | static int qaf_out_flush(struct audio_stream_out* stream) |
| 1046 | { |
| 1047 | struct stream_out *out = (struct stream_out *)stream; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1048 | int status = 0; |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 1049 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1050 | DEBUG_MSG("Output Stream %p", out); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1051 | lock_output_stream(out); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1052 | |
| 1053 | //If QAF passthrough is active then block the flush on module input streams. |
| 1054 | if (p_qaf->passthrough_out) { |
| 1055 | pthread_mutex_lock(&p_qaf->lock); |
| 1056 | //If flush is received for the QAF passthrough stream then call the primary HAL api. |
| 1057 | if (p_qaf->passthrough_in == out) { |
| 1058 | status = p_qaf->passthrough_out->stream.flush( |
| 1059 | (struct audio_stream_out *)p_qaf->passthrough_out); |
| 1060 | out->offload_state = OFFLOAD_STATE_IDLE; |
| 1061 | } |
| 1062 | pthread_mutex_unlock(&p_qaf->lock); |
| 1063 | } else { |
| 1064 | //Flush the module input stream. |
| 1065 | status = audio_extn_qaf_stream_flush(out); |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 1066 | } |
| 1067 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1068 | unlock_output_stream(out); |
| 1069 | DEBUG_MSG("Exit"); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1070 | return status; |
| 1071 | } |
| 1072 | |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 1073 | static uint32_t qaf_out_get_latency(const struct audio_stream_out *stream) |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1074 | { |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 1075 | struct stream_out *out = (struct stream_out *)stream; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1076 | uint32_t latency = 0; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1077 | struct qaf_module *qaf_mod = NULL; |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 1078 | DEBUG_MSG_VV("Output Stream %p", out); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1079 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1080 | qaf_mod = get_qaf_module_for_input_stream(out); |
| 1081 | if (!qaf_mod) { |
| 1082 | return 0; |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 1083 | } |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 1084 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1085 | //If QAF passthrough is active then block the get latency on module input streams. |
| 1086 | if (p_qaf->passthrough_out) { |
| 1087 | pthread_mutex_lock(&p_qaf->lock); |
| 1088 | //If get latency is called for the QAF passthrough stream then call the primary HAL api. |
| 1089 | if (p_qaf->passthrough_in == out) { |
| 1090 | latency = p_qaf->passthrough_out->stream.get_latency( |
| 1091 | (struct audio_stream_out *)p_qaf->passthrough_out); |
| 1092 | } |
| 1093 | pthread_mutex_unlock(&p_qaf->lock); |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 1094 | } else { |
Bharath Gopal | 01310bb | 2016-12-05 15:39:32 +0530 | [diff] [blame] | 1095 | if (is_offload_usecase(out->usecase)) { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1096 | latency = COMPRESS_OFFLOAD_PLAYBACK_LATENCY; |
Bharath Gopal | 01310bb | 2016-12-05 15:39:32 +0530 | [diff] [blame] | 1097 | } else { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1098 | uint32_t sample_rate = 0; |
| 1099 | latency = QAF_MODULE_PCM_INPUT_BUFFER_LATENCY; //Input latency |
| 1100 | |
| 1101 | if (qaf_mod->stream_out[QAF_OUT_OFFLOAD]) |
| 1102 | sample_rate = qaf_mod->stream_out[QAF_OUT_OFFLOAD]->sample_rate; |
| 1103 | else if (qaf_mod->stream_out[QAF_OUT_OFFLOAD_MCH]) |
| 1104 | sample_rate = qaf_mod->stream_out[QAF_OUT_OFFLOAD_MCH]->sample_rate; |
| 1105 | |
| 1106 | if (sample_rate) { |
| 1107 | latency += (get_pcm_output_buffer_size_samples(qaf_mod) * 1000) / out->sample_rate; |
| 1108 | } |
| 1109 | } |
| 1110 | |
| 1111 | if ( audio_extn_bt_hal_get_output_stream(qaf_mod->bt_hdl) != NULL) { |
| 1112 | if (is_offload_usecase(out->usecase)) { |
| 1113 | latency = audio_extn_bt_hal_get_latency(qaf_mod->bt_hdl) + |
| 1114 | QAF_COMPRESS_OFFLOAD_PROCESSING_LATENCY; |
| 1115 | } else { |
| 1116 | latency = audio_extn_bt_hal_get_latency(qaf_mod->bt_hdl) + |
| 1117 | QAF_PCM_OFFLOAD_PROCESSING_LATENCY; |
| 1118 | } |
Bharath Gopal | 01310bb | 2016-12-05 15:39:32 +0530 | [diff] [blame] | 1119 | } |
| 1120 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1121 | |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 1122 | DEBUG_MSG_VV("Latency %d", latency); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1123 | return latency; |
| 1124 | } |
| 1125 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1126 | static bool check_and_get_compressed_device_format(int device, int *format) |
| 1127 | { |
| 1128 | switch (device) { |
| 1129 | case (AUDIO_DEVICE_OUT_AUX_DIGITAL | AUDIO_COMPRESSED_OUT_DD): |
| 1130 | *format = AUDIO_FORMAT_AC3; |
| 1131 | return true; |
| 1132 | case (AUDIO_DEVICE_OUT_AUX_DIGITAL | AUDIO_COMPRESSED_OUT_DDP): |
| 1133 | *format = AUDIO_FORMAT_E_AC3; |
| 1134 | return true; |
| 1135 | case (AUDIO_DEVICE_OUT_AUX_DIGITAL | AUDIO_FORMAT_DTS): |
| 1136 | *format = AUDIO_FORMAT_DTS; |
| 1137 | return true; |
| 1138 | case (AUDIO_DEVICE_OUT_AUX_DIGITAL | AUDIO_FORMAT_DTS_HD): |
| 1139 | *format = AUDIO_FORMAT_DTS_HD; |
| 1140 | return true; |
| 1141 | default: |
| 1142 | return false; |
| 1143 | } |
| 1144 | } |
| 1145 | |
| 1146 | /* Call back function for mm module. */ |
| 1147 | static void notify_event_callback(audio_session_handle_t session_handle /*__unused*/, |
| 1148 | void *prv_data, |
| 1149 | void *buf, |
| 1150 | audio_event_id_t event_id, |
| 1151 | int size, |
| 1152 | int device) //TODO: add media format as well. |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1153 | { |
| 1154 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1155 | /* |
| 1156 | For SPKR: |
| 1157 | 1. Open pcm device if device_id passed to it SPKR and write the data to |
| 1158 | pcm device |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1159 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1160 | For HDMI |
| 1161 | 1.Open compress device for HDMI(PCM or AC3) based on current hdmi o/p format and write |
| 1162 | data to the HDMI device. |
| 1163 | */ |
| 1164 | int ret, i; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1165 | audio_output_flags_t flags; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1166 | struct qaf_module* qaf_mod = (struct qaf_module*)prv_data; |
Bharath Gopal | 01310bb | 2016-12-05 15:39:32 +0530 | [diff] [blame] | 1167 | struct audio_stream_out *bt_stream = NULL; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1168 | int format; |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 1169 | |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 1170 | DEBUG_MSG_VV("Device 0x%X, Event = 0x%X, Bytes to write %d", device, event_id, size); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1171 | pthread_mutex_lock(&p_qaf->lock); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1172 | |
| 1173 | if (event_id == AUDIO_DATA_EVENT) { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1174 | if (p_qaf->passthrough_out != NULL) { |
| 1175 | //If QAF passthrough is active then all the module output will be dropped. |
| 1176 | pthread_mutex_unlock(&p_qaf->lock); |
| 1177 | DEBUG_MSG("QAF-PSTH is active, DROPPING DATA!"); |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 1178 | return; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1179 | } |
| 1180 | |
| 1181 | if (check_and_get_compressed_device_format(device, &format)) { |
| 1182 | /* |
| 1183 | * CASE 1: Transcoded output of mm module. |
| 1184 | * If HDMI is not connected then drop the data. |
| 1185 | * Only one HDMI output can be supported from all the mm modules of QAF. |
| 1186 | * Multi-Channel PCM HDMI output streams will be closed from all the mm modules. |
| 1187 | * If transcoded output of other module is already enabled then this data will be dropped. |
| 1188 | */ |
| 1189 | |
| 1190 | if (!p_qaf->hdmi_connect) { |
| 1191 | DEBUG_MSG("HDMI not connected, DROPPING DATA!"); |
| 1192 | pthread_mutex_unlock(&p_qaf->lock); |
| 1193 | return; |
| 1194 | } |
| 1195 | |
| 1196 | //Closing all the PCM HDMI output stream from QAF. |
| 1197 | close_all_pcm_hdmi_output(); |
| 1198 | |
| 1199 | if (!p_qaf->passthrough_enabled |
| 1200 | && !(qaf_mod->stream_out[QAF_OUT_TRANSCODE_PASSTHROUGH])) { |
| 1201 | |
| 1202 | struct audio_config config; |
| 1203 | audio_devices_t devices; |
| 1204 | |
| 1205 | //TODO: need to update the actual sample rate. |
| 1206 | config.sample_rate = config.offload_info.sample_rate = |
| 1207 | QAF_OUTPUT_SAMPLING_RATE; |
| 1208 | config.offload_info.version = AUDIO_INFO_INITIALIZER.version; |
| 1209 | config.offload_info.size = AUDIO_INFO_INITIALIZER.size; |
| 1210 | config.format = config.offload_info.format = format; |
| 1211 | //TODO: need to update the actual bit width. |
| 1212 | config.offload_info.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH; |
| 1213 | //TODO: What is the relevance of num of channels. |
| 1214 | config.offload_info.channel_mask = config.channel_mask = AUDIO_CHANNEL_OUT_5POINT1; |
| 1215 | |
| 1216 | flags = (AUDIO_OUTPUT_FLAG_NON_BLOCKING |
| 1217 | | AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD |
| 1218 | | AUDIO_OUTPUT_FLAG_DIRECT); |
| 1219 | devices = AUDIO_DEVICE_OUT_AUX_DIGITAL; |
| 1220 | |
| 1221 | ret = adev_open_output_stream((struct audio_hw_device *)p_qaf->adev, |
| 1222 | QAF_DEFAULT_COMPR_PASSTHROUGH_HANDLE, |
| 1223 | devices, |
| 1224 | flags, |
| 1225 | &config, |
| 1226 | (struct audio_stream_out **)&(qaf_mod->stream_out[QAF_OUT_TRANSCODE_PASSTHROUGH]), |
| 1227 | NULL); |
| 1228 | if (ret < 0) { |
| 1229 | ERROR_MSG("adev_open_output_stream failed with ret = %d!", ret); |
| 1230 | pthread_mutex_unlock(&p_qaf->lock); |
| 1231 | return; |
| 1232 | } |
| 1233 | |
| 1234 | if (format & AUDIO_COMPRESSED_OUT_DDP) { |
| 1235 | qaf_mod->stream_out[QAF_OUT_TRANSCODE_PASSTHROUGH]->compr_config.fragment_size = |
| 1236 | COMPRESS_PASSTHROUGH_DDP_FRAGMENT_SIZE; |
| 1237 | } |
| 1238 | qaf_mod->stream_out[QAF_OUT_TRANSCODE_PASSTHROUGH]->compr_config.fragments = |
| 1239 | COMPRESS_OFFLOAD_NUM_FRAGMENTS; |
| 1240 | |
| 1241 | p_qaf->passthrough_enabled = true; |
| 1242 | } |
| 1243 | |
| 1244 | if (qaf_mod->stream_out[QAF_OUT_TRANSCODE_PASSTHROUGH]) { |
| 1245 | ret = qaf_mod->stream_out[QAF_OUT_TRANSCODE_PASSTHROUGH]->stream.write( |
| 1246 | (struct audio_stream_out *)qaf_mod->stream_out[QAF_OUT_TRANSCODE_PASSTHROUGH], |
| 1247 | buf, |
| 1248 | size); |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 1249 | } |
| 1250 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1251 | else if ((device & AUDIO_DEVICE_OUT_AUX_DIGITAL) |
| 1252 | && (p_qaf->hdmi_connect) |
| 1253 | && (p_qaf->hdmi_sink_channels > 2)) { |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1254 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1255 | /* CASE 2: Multi-Channel PCM output to HDMI. |
| 1256 | * If any other HDMI output is already enabled then this has to be dropped. |
| 1257 | */ |
| 1258 | bool create_mch_out_stream = false; |
| 1259 | |
| 1260 | if (p_qaf->passthrough_enabled) { |
| 1261 | //Closing all the multi-Channel PCM HDMI output stream from QAF. |
| 1262 | close_all_pcm_hdmi_output(); |
| 1263 | |
| 1264 | //If passthrough is active then pcm hdmi output has to be dropped. |
| 1265 | pthread_mutex_unlock(&p_qaf->lock); |
| 1266 | DEBUG_MSG("Compressed passthrough enabled, DROPPING DATA!"); |
| 1267 | return; |
| 1268 | } |
| 1269 | |
| 1270 | if (!p_qaf->mch_pcm_hdmi_enabled && !(qaf_mod->stream_out[QAF_OUT_OFFLOAD_MCH])) { |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1271 | struct audio_config config; |
| 1272 | audio_devices_t devices; |
| 1273 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1274 | //TODO: need to update the actual sample rate. |
Varun B | 34da7a4 | 2017-02-13 16:16:53 +0530 | [diff] [blame] | 1275 | config.sample_rate = config.offload_info.sample_rate = |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1276 | QAF_OUTPUT_SAMPLING_RATE; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1277 | config.offload_info.version = AUDIO_INFO_INITIALIZER.version; |
| 1278 | config.offload_info.size = AUDIO_INFO_INITIALIZER.size; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1279 | config.offload_info.format = config.format = AUDIO_FORMAT_PCM_16_BIT; |
| 1280 | //TODO: need to update the actual bit width. |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1281 | config.offload_info.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1282 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1283 | if (p_qaf->hdmi_sink_channels == 8) { |
Varun B | 34da7a4 | 2017-02-13 16:16:53 +0530 | [diff] [blame] | 1284 | config.offload_info.channel_mask = config.channel_mask = |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1285 | AUDIO_CHANNEL_OUT_7POINT1; |
| 1286 | } else if (p_qaf->hdmi_sink_channels == 6) { |
Varun B | 34da7a4 | 2017-02-13 16:16:53 +0530 | [diff] [blame] | 1287 | config.offload_info.channel_mask = config.channel_mask = |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1288 | AUDIO_CHANNEL_OUT_5POINT1; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1289 | } else { |
Varun B | 34da7a4 | 2017-02-13 16:16:53 +0530 | [diff] [blame] | 1290 | config.offload_info.channel_mask = config.channel_mask = |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1291 | AUDIO_CHANNEL_OUT_STEREO; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1292 | } |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 1293 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1294 | devices = AUDIO_DEVICE_OUT_AUX_DIGITAL; |
| 1295 | flags = (AUDIO_OUTPUT_FLAG_DIRECT | AUDIO_OUTPUT_FLAG_DIRECT_PCM); |
| 1296 | |
| 1297 | ret = adev_open_output_stream((struct audio_hw_device *)p_qaf->adev, |
| 1298 | QAF_DEFAULT_COMPR_AUDIO_HANDLE, |
| 1299 | devices, |
| 1300 | flags, |
| 1301 | &config, |
| 1302 | (struct audio_stream_out **)&(qaf_mod->stream_out[QAF_OUT_OFFLOAD_MCH]), |
| 1303 | NULL); |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 1304 | if (ret < 0) { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1305 | ERROR_MSG("adev_open_output_stream failed with ret = %d!", ret); |
| 1306 | pthread_mutex_unlock(&p_qaf->lock); |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 1307 | return; |
| 1308 | } |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 1309 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1310 | qaf_mod->stream_out[QAF_OUT_OFFLOAD_MCH]->compr_config.fragments = |
| 1311 | COMPRESS_OFFLOAD_NUM_FRAGMENTS; |
| 1312 | qaf_mod->stream_out[QAF_OUT_OFFLOAD_MCH]->compr_config.fragment_size = |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 1313 | qaf_get_pcm_offload_output_buffer_size(qaf_mod, &config.offload_info); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1314 | |
| 1315 | p_qaf->mch_pcm_hdmi_enabled = true; |
| 1316 | |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 1317 | if ((qaf_mod->stream_in[QAF_IN_MAIN] |
| 1318 | && qaf_mod->stream_in[QAF_IN_MAIN]->client_callback != NULL) || |
| 1319 | (qaf_mod->stream_in[QAF_IN_MAIN_2] |
| 1320 | && qaf_mod->stream_in[QAF_IN_MAIN_2]->client_callback != NULL)) { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1321 | |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 1322 | if (qaf_mod->stream_in[QAF_IN_MAIN]) { |
| 1323 | qaf_mod->stream_out[QAF_OUT_OFFLOAD_MCH]->stream.set_callback( |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1324 | (struct audio_stream_out *)qaf_mod->stream_out[QAF_OUT_OFFLOAD_MCH], |
| 1325 | qaf_mod->stream_in[QAF_IN_MAIN]->client_callback, |
| 1326 | qaf_mod->stream_in[QAF_IN_MAIN]->client_cookie); |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 1327 | } |
| 1328 | if (qaf_mod->stream_in[QAF_IN_MAIN_2]) { |
| 1329 | qaf_mod->stream_out[QAF_OUT_OFFLOAD_MCH]->stream.set_callback( |
| 1330 | (struct audio_stream_out *)qaf_mod->stream_out[QAF_OUT_OFFLOAD_MCH], |
| 1331 | qaf_mod->stream_in[QAF_IN_MAIN_2]->client_callback, |
| 1332 | qaf_mod->stream_in[QAF_IN_MAIN_2]->client_cookie); |
| 1333 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1334 | } else if (qaf_mod->stream_in[QAF_IN_PCM] |
| 1335 | && qaf_mod->stream_in[QAF_IN_PCM]->client_callback != NULL) { |
| 1336 | |
| 1337 | qaf_mod->stream_out[QAF_OUT_OFFLOAD_MCH]->stream.set_callback( |
| 1338 | (struct audio_stream_out *)qaf_mod->stream_out[QAF_OUT_OFFLOAD_MCH], |
| 1339 | qaf_mod->stream_in[QAF_IN_PCM]->client_callback, |
| 1340 | qaf_mod->stream_in[QAF_IN_PCM]->client_cookie); |
| 1341 | } |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 1342 | |
| 1343 | int index = -1; |
| 1344 | if (qaf_mod->adsp_hdlr_config[QAF_IN_MAIN].adsp_hdlr_config_valid) |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1345 | index = (int) QAF_IN_MAIN; |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 1346 | else if (qaf_mod->adsp_hdlr_config[QAF_IN_MAIN_2].adsp_hdlr_config_valid) |
| 1347 | index = (int) QAF_IN_MAIN_2; |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 1348 | else if (qaf_mod->adsp_hdlr_config[QAF_IN_PCM].adsp_hdlr_config_valid) |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1349 | index = (int) QAF_IN_PCM; |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 1350 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1351 | if (index >= 0) { |
| 1352 | if (qaf_mod->stream_out[QAF_OUT_OFFLOAD_MCH]->standby) |
| 1353 | qaf_mod->stream_out[QAF_OUT_OFFLOAD_MCH]->stream.write( |
| 1354 | (struct audio_stream_out *)qaf_mod->stream_out[QAF_OUT_OFFLOAD_MCH], NULL, 0); |
| 1355 | |
| 1356 | lock_output_stream(qaf_mod->stream_out[QAF_OUT_OFFLOAD_MCH]); |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 1357 | ret = audio_extn_out_set_param_data( |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1358 | qaf_mod->stream_out[QAF_OUT_OFFLOAD_MCH], |
| 1359 | AUDIO_EXTN_PARAM_ADSP_STREAM_CMD, |
| 1360 | (audio_extn_param_payload *)&qaf_mod->adsp_hdlr_config[index].event_params); |
| 1361 | unlock_output_stream(qaf_mod->stream_out[QAF_OUT_OFFLOAD_MCH]); |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 1362 | |
| 1363 | } |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 1364 | } |
| 1365 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1366 | if (qaf_mod->stream_out[QAF_OUT_OFFLOAD_MCH]) { |
| 1367 | ret = qaf_mod->stream_out[QAF_OUT_OFFLOAD_MCH]->stream.write( |
| 1368 | (struct audio_stream_out *)qaf_mod->stream_out[QAF_OUT_OFFLOAD_MCH], |
| 1369 | buf, |
| 1370 | size); |
Varun B | 34da7a4 | 2017-02-13 16:16:53 +0530 | [diff] [blame] | 1371 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1372 | } |
| 1373 | else { |
| 1374 | /* CASE 3: PCM output. |
| 1375 | */ |
Bharath Gopal | 01310bb | 2016-12-05 15:39:32 +0530 | [diff] [blame] | 1376 | bt_stream = audio_extn_bt_hal_get_output_stream(qaf_mod->bt_hdl); |
| 1377 | if (bt_stream != NULL) { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1378 | if (qaf_mod->stream_out[QAF_OUT_OFFLOAD]) { |
| 1379 | adev_close_output_stream((struct audio_hw_device *)p_qaf->adev, |
| 1380 | (struct audio_stream_out *)(qaf_mod->stream_out[QAF_OUT_OFFLOAD])); |
| 1381 | qaf_mod->stream_out[QAF_OUT_OFFLOAD] = NULL; |
Bharath Gopal | 01310bb | 2016-12-05 15:39:32 +0530 | [diff] [blame] | 1382 | } |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 1383 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1384 | audio_extn_bt_hal_out_write(p_qaf->bt_hdl, buf, size); |
| 1385 | } else if (NULL == qaf_mod->stream_out[QAF_OUT_OFFLOAD]) { |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 1386 | struct audio_config config; |
| 1387 | audio_devices_t devices; |
| 1388 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1389 | //TODO: need to update the actual sample rate. |
Varun B | 34da7a4 | 2017-02-13 16:16:53 +0530 | [diff] [blame] | 1390 | config.sample_rate = config.offload_info.sample_rate = |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1391 | QAF_OUTPUT_SAMPLING_RATE; |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 1392 | config.offload_info.version = AUDIO_INFO_INITIALIZER.version; |
| 1393 | config.offload_info.size = AUDIO_INFO_INITIALIZER.size; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1394 | config.offload_info.format = config.format = AUDIO_FORMAT_PCM_16_BIT; |
| 1395 | //TODO: need to update the actual bit width. |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 1396 | config.offload_info.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1397 | //TODO: need to update the actual num channels. |
| 1398 | config.offload_info.channel_mask = config.channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1399 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1400 | if (qaf_mod->stream_in[QAF_IN_MAIN]) |
| 1401 | devices = qaf_mod->stream_in[QAF_IN_MAIN]->devices; |
| 1402 | else |
| 1403 | devices = qaf_mod->stream_in[QAF_IN_PCM]->devices; |
| 1404 | |
| 1405 | //If multi channel pcm or passthrough is already enabled then remove the hdmi flag from device. |
| 1406 | if (p_qaf->mch_pcm_hdmi_enabled || p_qaf->passthrough_enabled) { |
| 1407 | if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) |
| 1408 | devices ^= AUDIO_DEVICE_OUT_AUX_DIGITAL; |
| 1409 | } |
| 1410 | if (devices == 0) { |
| 1411 | devices = device; |
| 1412 | } |
| 1413 | |
| 1414 | flags = (AUDIO_OUTPUT_FLAG_DIRECT | AUDIO_OUTPUT_FLAG_DIRECT_PCM); |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 1415 | |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1416 | /* TODO:: Need to Propagate errors to framework */ |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1417 | ret = adev_open_output_stream((struct audio_hw_device *)p_qaf->adev, |
| 1418 | QAF_DEFAULT_COMPR_AUDIO_HANDLE, |
| 1419 | devices, |
| 1420 | flags, |
| 1421 | &config, |
| 1422 | (struct audio_stream_out **)&(qaf_mod->stream_out[QAF_OUT_OFFLOAD]), |
| 1423 | NULL); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1424 | if (ret < 0) { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1425 | ERROR_MSG("adev_open_output_stream failed with ret = %d!", ret); |
| 1426 | pthread_mutex_unlock(&p_qaf->lock); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1427 | return; |
| 1428 | } |
Deepak Agarwal | 1e42b85 | 2017-02-11 17:57:04 +0530 | [diff] [blame] | 1429 | |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 1430 | if ((qaf_mod->stream_in[QAF_IN_MAIN] |
| 1431 | && qaf_mod->stream_in[QAF_IN_MAIN]->client_callback != NULL) || |
| 1432 | (qaf_mod->stream_in[QAF_IN_MAIN_2] |
| 1433 | && qaf_mod->stream_in[QAF_IN_MAIN_2]->client_callback != NULL)) { |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 1434 | |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 1435 | if (qaf_mod->stream_in[QAF_IN_MAIN]) { |
| 1436 | qaf_mod->stream_out[QAF_OUT_OFFLOAD]->stream.set_callback( |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1437 | (struct audio_stream_out *)qaf_mod->stream_out[QAF_OUT_OFFLOAD], |
| 1438 | qaf_mod->stream_in[QAF_IN_MAIN]->client_callback, |
| 1439 | qaf_mod->stream_in[QAF_IN_MAIN]->client_cookie); |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 1440 | } |
| 1441 | if (qaf_mod->stream_in[QAF_IN_MAIN_2]) { |
| 1442 | qaf_mod->stream_out[QAF_OUT_OFFLOAD]->stream.set_callback( |
| 1443 | (struct audio_stream_out *)qaf_mod->stream_out[QAF_OUT_OFFLOAD], |
| 1444 | qaf_mod->stream_in[QAF_IN_MAIN_2]->client_callback, |
| 1445 | qaf_mod->stream_in[QAF_IN_MAIN_2]->client_cookie); |
| 1446 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1447 | } else if (qaf_mod->stream_in[QAF_IN_PCM] |
| 1448 | && qaf_mod->stream_in[QAF_IN_PCM]->client_callback != NULL) { |
| 1449 | |
| 1450 | qaf_mod->stream_out[QAF_OUT_OFFLOAD]->stream.set_callback( |
| 1451 | (struct audio_stream_out *)qaf_mod->stream_out[QAF_OUT_OFFLOAD], |
| 1452 | qaf_mod->stream_in[QAF_IN_PCM]->client_callback, |
| 1453 | qaf_mod->stream_in[QAF_IN_PCM]->client_cookie); |
| 1454 | } |
| 1455 | |
| 1456 | qaf_mod->stream_out[QAF_OUT_OFFLOAD]->compr_config.fragments = |
| 1457 | COMPRESS_OFFLOAD_NUM_FRAGMENTS; |
| 1458 | qaf_mod->stream_out[QAF_OUT_OFFLOAD]->compr_config.fragment_size = |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 1459 | qaf_get_pcm_offload_output_buffer_size(qaf_mod, &config.offload_info); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1460 | |
| 1461 | if (qaf_mod->is_vol_set) { |
| 1462 | DEBUG_MSG("Setting Volume Left[%f], Right[%f]", qaf_mod->vol_left, qaf_mod->vol_right); |
| 1463 | qaf_mod->stream_out[QAF_OUT_OFFLOAD]->stream.set_volume( |
| 1464 | (struct audio_stream_out *)qaf_mod->stream_out[QAF_OUT_OFFLOAD], |
| 1465 | qaf_mod->vol_left, |
| 1466 | qaf_mod->vol_right); |
| 1467 | } |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 1468 | |
| 1469 | int index = -1; |
| 1470 | if (qaf_mod->adsp_hdlr_config[QAF_IN_MAIN].adsp_hdlr_config_valid) |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1471 | index = (int) QAF_IN_MAIN; |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 1472 | else if (qaf_mod->adsp_hdlr_config[QAF_IN_MAIN_2].adsp_hdlr_config_valid) |
| 1473 | index = (int) QAF_IN_MAIN_2; |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 1474 | else if (qaf_mod->adsp_hdlr_config[QAF_IN_PCM].adsp_hdlr_config_valid) |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1475 | index = (int) QAF_IN_PCM; |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 1476 | if (index >= 0) { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1477 | if (qaf_mod->stream_out[QAF_OUT_OFFLOAD]->standby) { |
| 1478 | qaf_mod->stream_out[QAF_OUT_OFFLOAD]->stream.write( |
| 1479 | (struct audio_stream_out *)qaf_mod->stream_out[QAF_OUT_OFFLOAD], NULL, 0); |
| 1480 | } |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 1481 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1482 | lock_output_stream(qaf_mod->stream_out[QAF_OUT_OFFLOAD]); |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 1483 | ret = audio_extn_out_set_param_data( |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1484 | qaf_mod->stream_out[QAF_OUT_OFFLOAD], |
| 1485 | AUDIO_EXTN_PARAM_ADSP_STREAM_CMD, |
| 1486 | (audio_extn_param_payload *)&qaf_mod->adsp_hdlr_config[index].event_params); |
| 1487 | unlock_output_stream(qaf_mod->stream_out[QAF_OUT_OFFLOAD]); |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 1488 | } |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | /* |
| 1492 | * TODO:: Since this is mixed data, |
| 1493 | * need to identify to which stream the error should be sent |
| 1494 | */ |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1495 | if (qaf_mod->stream_out[QAF_OUT_OFFLOAD]) { |
| 1496 | ret = qaf_mod->stream_out[QAF_OUT_OFFLOAD]->stream.write( |
| 1497 | (struct audio_stream_out *)qaf_mod->stream_out[QAF_OUT_OFFLOAD], |
| 1498 | buf, |
| 1499 | size); |
Varun B | 34da7a4 | 2017-02-13 16:16:53 +0530 | [diff] [blame] | 1500 | } |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1501 | } |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 1502 | DEBUG_MSG_VV("Bytes written = %d", ret); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1503 | } |
| 1504 | else if (event_id == AUDIO_EOS_MAIN_DD_DDP_EVENT |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 1505 | || event_id == AUDIO_EOS_MAIN_2_DD_DDP_EVENT |
Varun B | 34da7a4 | 2017-02-13 16:16:53 +0530 | [diff] [blame] | 1506 | || event_id == AUDIO_EOS_MAIN_AAC_EVENT |
| 1507 | || event_id == AUDIO_EOS_MAIN_AC4_EVENT |
| 1508 | || event_id == AUDIO_EOS_ASSOC_DD_DDP_EVENT) { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1509 | struct stream_out *out = qaf_mod->stream_in[QAF_IN_MAIN]; |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 1510 | struct stream_out *out_main2 = qaf_mod->stream_in[QAF_IN_MAIN_2]; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1511 | struct stream_out *out_assoc = qaf_mod->stream_in[QAF_IN_ASSOC]; |
| 1512 | bool *main_drain_received = &qaf_mod->drain_received[QAF_IN_MAIN]; |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 1513 | bool *main2_drain_received = &qaf_mod->drain_received[QAF_IN_MAIN_2]; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1514 | bool *assoc_drain_received = &qaf_mod->drain_received[QAF_IN_ASSOC]; |
Varun B | 34da7a4 | 2017-02-13 16:16:53 +0530 | [diff] [blame] | 1515 | |
| 1516 | /** |
| 1517 | * TODO:: Only DD/DDP Associate Eos is handled, need to add support |
| 1518 | * for other formats. |
| 1519 | */ |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1520 | if (event_id == AUDIO_EOS_ASSOC_DD_DDP_EVENT |
| 1521 | && (out_assoc != NULL) |
| 1522 | && (*assoc_drain_received)) { |
| 1523 | |
Varun B | 34da7a4 | 2017-02-13 16:16:53 +0530 | [diff] [blame] | 1524 | lock_output_stream(out_assoc); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1525 | out_assoc->client_callback(STREAM_CBK_EVENT_DRAIN_READY, NULL, out_assoc->client_cookie); |
| 1526 | *assoc_drain_received = false; |
| 1527 | unlock_output_stream(out_assoc); |
| 1528 | DEBUG_MSG("sent associated DRAIN_READY"); |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 1529 | } else if (event_id == AUDIO_EOS_MAIN_2_DD_DDP_EVENT |
| 1530 | && (out_main2 != NULL) |
| 1531 | && (*main2_drain_received)) { |
| 1532 | |
| 1533 | lock_output_stream(out_main2); |
| 1534 | out_main2->client_callback(STREAM_CBK_EVENT_DRAIN_READY, NULL, out_main2->client_cookie); |
| 1535 | *main2_drain_received = false; |
| 1536 | unlock_output_stream(out_main2); |
| 1537 | DEBUG_MSG("sent main2 DRAIN_READY"); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1538 | } else if ((out != NULL) && (*main_drain_received)) { |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1539 | lock_output_stream(out); |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 1540 | out->client_callback(STREAM_CBK_EVENT_DRAIN_READY, NULL, out->client_cookie); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1541 | *main_drain_received = false; |
| 1542 | unlock_output_stream(out); |
| 1543 | DEBUG_MSG("sent main DRAIN_READY"); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1544 | } |
| 1545 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1546 | #if 0 |
| 1547 | else if (event_id == AUDIO_MAIN_EOS_EVENT || event_id == AUDIO_ASSOC_EOS_EVENT) { //TODO: For DTS |
| 1548 | struct stream_out *out = NULL; |
| 1549 | bool *drain_received = NULL; |
| 1550 | |
| 1551 | if (event_id == AUDIO_MAIN_EOS_EVENT) { |
| 1552 | out = qaf_mod->stream_in[QAF_IN_MAIN]; |
| 1553 | drain_received = &qaf_mod->drain_received[QAF_IN_MAIN]; |
| 1554 | } else { |
| 1555 | out = qaf_mod->stream_in[QAF_IN_ASSOC]; |
| 1556 | drain_received = &qaf_mod->drain_received[QAF_IN_ASSOC]; |
| 1557 | } |
| 1558 | |
| 1559 | if ((out != NULL) && (*drain_received)) { |
| 1560 | lock_output_stream(out); |
| 1561 | out->client_callback(STREAM_CBK_EVENT_DRAIN_READY, NULL, out->client_cookie); |
| 1562 | *drain_received = false; |
| 1563 | unlock_output_stream(out); |
| 1564 | DEBUG_MSG("sent DRAIN_READY"); |
| 1565 | } |
| 1566 | } |
| 1567 | #endif |
| 1568 | |
| 1569 | pthread_mutex_unlock(&p_qaf->lock); |
| 1570 | return; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1571 | } |
| 1572 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1573 | /* Close the mm module session. */ |
| 1574 | static int qaf_session_close(struct qaf_module* qaf_mod) |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1575 | { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1576 | int j; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1577 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1578 | //Check if all streams are closed or not. |
| 1579 | for (j = 0; j < MAX_QAF_MODULE_IN; j++) { |
| 1580 | if (qaf_mod->stream_in[j] != NULL) { |
| 1581 | break; |
| 1582 | } |
| 1583 | } |
| 1584 | if (j != MAX_QAF_MODULE_IN) { |
| 1585 | return 0; //Some stream is already active, Can not close session. |
| 1586 | } |
| 1587 | |
| 1588 | if (qaf_mod->session_handle != NULL && qaf_mod->qaf_audio_session_close) { |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1589 | qaf_mod->qaf_audio_session_close(qaf_mod->session_handle); |
| 1590 | qaf_mod->session_handle = NULL; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1591 | qaf_mod->is_vol_set = false; |
| 1592 | memset(qaf_mod->drain_received, 0, sizeof(qaf_mod->drain_received)); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1593 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1594 | |
| 1595 | for (j = 0; j < MAX_QAF_MODULE_OUT; j++) { |
| 1596 | if (qaf_mod->stream_out[j]) { |
| 1597 | adev_close_output_stream((struct audio_hw_device *)p_qaf->adev, |
| 1598 | (struct audio_stream_out *)(qaf_mod->stream_out[j])); |
| 1599 | qaf_mod->stream_out[j] = NULL; |
| 1600 | } |
| 1601 | } |
| 1602 | |
| 1603 | DEBUG_MSG("Session Closed."); |
| 1604 | |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1605 | return 0; |
| 1606 | } |
| 1607 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1608 | /* Close the stream of QAF module. */ |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1609 | static int qaf_stream_close(struct stream_out *out) |
| 1610 | { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1611 | int ret = -EINVAL; |
| 1612 | struct qaf_module *qaf_mod = NULL; |
| 1613 | int index = -1; |
| 1614 | DEBUG_MSG("Flag [0x%x], Stream handle [%p]", out->flags, out->qaf_stream_handle); |
| 1615 | |
| 1616 | qaf_mod = get_qaf_module_for_input_stream(out); |
| 1617 | index = get_input_stream_index(out); |
| 1618 | |
| 1619 | if (!qaf_mod || !qaf_mod->qaf_audio_stream_close || index < 0) { |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1620 | return -EINVAL; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1621 | } |
| 1622 | |
| 1623 | qaf_mod->stream_in[index] = NULL; |
| 1624 | memset(&qaf_mod->adsp_hdlr_config[index], 0, sizeof(struct qaf_adsp_hdlr_config_state)); |
| 1625 | |
| 1626 | lock_output_stream(out); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1627 | if (out->qaf_stream_handle) { |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1628 | ret = qaf_mod->qaf_audio_stream_close(out->qaf_stream_handle); |
| 1629 | out->qaf_stream_handle = NULL; |
| 1630 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1631 | unlock_output_stream(out); |
| 1632 | |
| 1633 | //If all streams are closed then close the session. |
| 1634 | qaf_session_close(qaf_mod); |
| 1635 | |
| 1636 | DEBUG_MSG(); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1637 | return ret; |
| 1638 | } |
| 1639 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1640 | /* Open a MM module session with QAF. */ |
| 1641 | static int audio_extn_qaf_session_open(mm_module_type mod_type) |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1642 | { |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1643 | ALOGV("%s %d", __func__, __LINE__); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1644 | unsigned char* license_data = NULL; |
| 1645 | device_license_config_t lic_config = {0}; |
| 1646 | int ret = -ENOSYS, size = 0; |
| 1647 | char value[PROPERTY_VALUE_MAX] = {0}; |
| 1648 | struct qaf_module *qaf_mod = NULL; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1649 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1650 | if (mod_type >= MAX_MM_MODULE_TYPE || !(p_qaf->qaf_mod[mod_type].qaf_audio_session_open)) |
| 1651 | return -ENOTSUP; //Not supported by QAF module. |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1652 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1653 | pthread_mutex_lock(&p_qaf->lock); |
| 1654 | |
| 1655 | qaf_mod = &(p_qaf->qaf_mod[mod_type]); |
| 1656 | |
| 1657 | //If session is already opened then return. |
| 1658 | if (qaf_mod->session_handle) { |
| 1659 | DEBUG_MSG("Session is already opened."); |
| 1660 | pthread_mutex_unlock(&p_qaf->lock); |
| 1661 | return 0; |
| 1662 | } |
| 1663 | |
| 1664 | if (mod_type == MS12) { |
| 1665 | //Getting the license |
| 1666 | license_data = platform_get_license((struct audio_hw_device *)(p_qaf->adev->platform), |
| 1667 | &size); |
| 1668 | if (!license_data) { |
| 1669 | ERROR_MSG("License data is not present."); |
| 1670 | pthread_mutex_unlock(&p_qaf->lock); |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 1671 | return -EINVAL; |
| 1672 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1673 | |
| 1674 | lic_config.p_license = (unsigned char*)calloc(1, size); |
| 1675 | if (lic_config.p_license == NULL) { |
| 1676 | ERROR_MSG("Out of Memory"); |
| 1677 | ret = -ENOMEM; |
| 1678 | goto exit; |
| 1679 | } |
| 1680 | |
| 1681 | lic_config.l_size = size; |
| 1682 | memcpy(lic_config.p_license, license_data, size); |
| 1683 | |
Aniket Kumar Lata | 8fc67e6 | 2017-05-02 12:33:46 -0700 | [diff] [blame] | 1684 | if (property_get("vendor.audio.qaf.manufacturer", value, "") && atoi(value)) { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1685 | lic_config.manufacturer_id = (unsigned long)atoi(value); |
| 1686 | } else { |
Aniket Kumar Lata | 8fc67e6 | 2017-05-02 12:33:46 -0700 | [diff] [blame] | 1687 | ERROR_MSG("vendor.audio.qaf.manufacturer id is not set"); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1688 | ret = -EINVAL; |
| 1689 | goto exit; |
| 1690 | } |
| 1691 | } |
| 1692 | |
| 1693 | ret = qaf_mod->qaf_audio_session_open(&qaf_mod->session_handle, |
| 1694 | (void *)(qaf_mod), |
| 1695 | (void *)&lic_config); |
| 1696 | if (ret < 0) { |
| 1697 | ERROR_MSG("Error in session open %d", ret); |
| 1698 | goto exit; |
| 1699 | } |
| 1700 | |
| 1701 | if (qaf_mod->session_handle == NULL) { |
| 1702 | ERROR_MSG("Session handle is NULL."); |
| 1703 | ret = -ENOMEM; |
| 1704 | goto exit; |
| 1705 | } |
| 1706 | |
| 1707 | if (qaf_mod->qaf_register_event_callback) |
| 1708 | qaf_mod->qaf_register_event_callback(qaf_mod->session_handle, |
| 1709 | qaf_mod, |
| 1710 | ¬ify_event_callback, |
| 1711 | AUDIO_DATA_EVENT); |
| 1712 | |
| 1713 | set_hdmi_configuration_to_module(); |
| 1714 | |
| 1715 | exit: |
| 1716 | if (license_data != NULL) { |
| 1717 | free(license_data); |
| 1718 | license_data = NULL; |
| 1719 | } |
| 1720 | if (lic_config.p_license != NULL) { |
| 1721 | free(lic_config.p_license); |
| 1722 | lic_config.p_license = NULL; |
| 1723 | } |
| 1724 | |
| 1725 | pthread_mutex_unlock(&p_qaf->lock); |
| 1726 | return ret; |
| 1727 | } |
| 1728 | |
| 1729 | /* opens a stream in QAF module. */ |
| 1730 | static int qaf_stream_open(struct stream_out *out, |
| 1731 | struct audio_config *config, |
| 1732 | audio_output_flags_t flags, |
| 1733 | audio_devices_t devices) |
| 1734 | { |
| 1735 | int status = -EINVAL; |
| 1736 | mm_module_type mmtype = get_mm_module_for_format(config->format); |
| 1737 | struct qaf_module* qaf_mod = NULL; |
| 1738 | DEBUG_MSG("Flags 0x%x, Device 0x%x", flags, devices); |
| 1739 | |
| 1740 | if (mmtype >= MAX_MM_MODULE_TYPE |
| 1741 | || p_qaf->qaf_mod[mmtype].qaf_audio_session_open == NULL |
| 1742 | || p_qaf->qaf_mod[mmtype].qaf_audio_stream_open == NULL) { |
| 1743 | ERROR_MSG("Unsupported Stream"); |
| 1744 | return -ENOTSUP; |
| 1745 | } |
| 1746 | |
| 1747 | //Open the module session, if not opened already. |
| 1748 | status = audio_extn_qaf_session_open(mmtype); |
| 1749 | qaf_mod = &(p_qaf->qaf_mod[mmtype]); |
| 1750 | |
| 1751 | if ((status != 0) || (qaf_mod->session_handle == NULL)) { |
| 1752 | ERROR_MSG("Failed to open session."); |
| 1753 | return status; |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 1754 | } |
| 1755 | |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1756 | audio_stream_config_t input_config; |
| 1757 | input_config.sample_rate = config->sample_rate; |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 1758 | input_config.channels = popcount(config->channel_mask); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1759 | input_config.format = config->format; |
| 1760 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1761 | if (input_config.format != AUDIO_FORMAT_PCM_16_BIT) { |
| 1762 | input_config.format &= AUDIO_FORMAT_MAIN_MASK; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1763 | } |
| 1764 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1765 | DEBUG_MSG("stream_open sample_rate(%d) channels(%d) devices(%#x) flags(%#x) format(%#x)", |
| 1766 | input_config.sample_rate, input_config.channels, devices, flags, input_config.format); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1767 | |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1768 | if (input_config.format == AUDIO_FORMAT_PCM_16_BIT) { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1769 | //If PCM stream is already opened then fail this stream open. |
| 1770 | if (qaf_mod->stream_in[QAF_IN_PCM]) { |
| 1771 | ERROR_MSG("PCM input is already active."); |
| 1772 | return -ENOTSUP; |
| 1773 | } |
| 1774 | |
| 1775 | //TODO: Flag can be system tone or external associated PCM. |
| 1776 | status = qaf_mod->qaf_audio_stream_open(qaf_mod->session_handle, |
| 1777 | &out->qaf_stream_handle, |
| 1778 | input_config, |
| 1779 | devices, |
| 1780 | AUDIO_STREAM_SYSTEM_TONE); |
| 1781 | qaf_mod->stream_in[QAF_IN_PCM] = out; |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 1782 | } else if ((flags & AUDIO_OUTPUT_FLAG_MAIN) && (flags & AUDIO_OUTPUT_FLAG_ASSOCIATED)) { |
| 1783 | if (is_main_active(qaf_mod) || is_dual_main_active(qaf_mod)) { |
| 1784 | ERROR_MSG("Dual Main or Main already active. So, Cannot open main and associated stream"); |
| 1785 | return -EINVAL; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1786 | } else { |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 1787 | status = qaf_mod->qaf_audio_stream_open(qaf_mod->session_handle, &out->qaf_stream_handle, input_config, devices, /*flags*/AUDIO_STREAM_MAIN); |
| 1788 | if (status == 0) { |
| 1789 | DEBUG_MSG("Open stream for Input with both Main and Associated stream contents with flag(%x) and stream_handle(%p)", flags, out->qaf_stream_handle); |
| 1790 | qaf_mod->stream_in[QAF_IN_MAIN] = out; |
| 1791 | } else { |
| 1792 | ERROR_MSG("Stream Open FAILED !!!"); |
| 1793 | } |
| 1794 | } |
Naresh Tanniru | 908d9a0 | 2017-05-17 14:12:48 +0530 | [diff] [blame] | 1795 | } else if ((flags & AUDIO_OUTPUT_FLAG_MAIN) || ((!(flags & AUDIO_OUTPUT_FLAG_MAIN)) && (!(flags & AUDIO_OUTPUT_FLAG_ASSOCIATED)))) { |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 1796 | /* Assume Main if no flag is set */ |
| 1797 | if (is_dual_main_active(qaf_mod)) { |
| 1798 | ERROR_MSG("Dual Main already active. So, Cannot open main stream"); |
| 1799 | return -EINVAL; |
| 1800 | } else if (is_main_active(qaf_mod) && qaf_mod->stream_in[QAF_IN_ASSOC]) { |
| 1801 | ERROR_MSG("Main and Associated already active. So, Cannot open main stream"); |
| 1802 | return -EINVAL; |
| 1803 | } else if (is_main_active(qaf_mod) && (mmtype != MS12)) { |
| 1804 | ERROR_MSG("Main already active and Not an MS12 format. So, Cannot open another main stream"); |
| 1805 | return -EINVAL; |
| 1806 | } else { |
| 1807 | status = qaf_mod->qaf_audio_stream_open(qaf_mod->session_handle, &out->qaf_stream_handle, input_config, devices, /*flags*/AUDIO_STREAM_MAIN); |
| 1808 | if (status == 0) { |
| 1809 | DEBUG_MSG("Open stream for Input with only Main flag(%x) stream_handle(%p)", flags, out->qaf_stream_handle); |
| 1810 | if(qaf_mod->stream_in[QAF_IN_MAIN]) { |
| 1811 | qaf_mod->stream_in[QAF_IN_MAIN_2] = out; |
| 1812 | } else { |
| 1813 | qaf_mod->stream_in[QAF_IN_MAIN] = out; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1814 | } |
| 1815 | } else { |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 1816 | ERROR_MSG("Stream Open FAILED !!!"); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1817 | } |
| 1818 | } |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 1819 | } else if ((flags & AUDIO_OUTPUT_FLAG_ASSOCIATED)) { |
| 1820 | if (is_dual_main_active(qaf_mod)) { |
| 1821 | ERROR_MSG("Dual Main already active. So, Cannot open associated stream"); |
| 1822 | return -EINVAL; |
| 1823 | } else if (!is_main_active(qaf_mod)) { |
| 1824 | ERROR_MSG("Main not active. So, Cannot open associated stream"); |
| 1825 | return -EINVAL; |
| 1826 | } else if (qaf_mod->stream_in[QAF_IN_ASSOC]) { |
| 1827 | ERROR_MSG("Associated already active. So, Cannot open associated stream"); |
| 1828 | return -EINVAL; |
| 1829 | } |
| 1830 | status = qaf_mod->qaf_audio_stream_open(qaf_mod->session_handle, &out->qaf_stream_handle, input_config, devices, /*flags*/AUDIO_STREAM_ASSOCIATED); |
| 1831 | if (status == 0) { |
| 1832 | DEBUG_MSG("Open stream for Input with only Associated flag(%x) stream handle(%p)", flags, out->qaf_stream_handle); |
| 1833 | qaf_mod->stream_in[QAF_IN_ASSOC] = out; |
| 1834 | } else { |
| 1835 | ERROR_MSG("Stream Open FAILED !!!"); |
| 1836 | } |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1837 | } |
| 1838 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1839 | if (status != 0) { |
| 1840 | //If no stream is active then close the session. |
| 1841 | qaf_session_close(qaf_mod); |
| 1842 | return status; |
| 1843 | } |
| 1844 | |
| 1845 | //If Device is HDMI, QAF passthrough is enabled and there is no previous QAF passthrough input stream. |
| 1846 | if ((!p_qaf->passthrough_in) |
| 1847 | && (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) |
| 1848 | && audio_extn_qaf_passthrough_enabled(out)) { |
| 1849 | //Assign the QAF passthrough input stream. |
| 1850 | p_qaf->passthrough_in = out; |
| 1851 | |
| 1852 | //If HDMI is connected and format is supported by HDMI then create QAF passthrough output stream. |
| 1853 | if (p_qaf->hdmi_connect |
| 1854 | && platform_is_edid_supported_format(p_qaf->adev->platform, out->format)) { |
| 1855 | status = create_qaf_passthrough_stream(); |
| 1856 | if (status < 0) { |
| 1857 | qaf_stream_close(out); |
| 1858 | ERROR_MSG("QAF passthrough stream creation failed with error %d", status); |
| 1859 | return status; |
| 1860 | } |
| 1861 | } |
| 1862 | /*Else: since QAF passthrough input stream is already initialized, |
| 1863 | * when hdmi is connected |
| 1864 | * then qaf passthrough output stream will be created. |
| 1865 | */ |
| 1866 | } |
| 1867 | |
| 1868 | DEBUG_MSG(); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1869 | return status; |
| 1870 | } |
| 1871 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1872 | /* Resume a QAF stream. */ |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 1873 | static int qaf_out_resume(struct audio_stream_out* stream) |
| 1874 | { |
| 1875 | struct stream_out *out = (struct stream_out *)stream; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1876 | int status = 0; |
| 1877 | DEBUG_MSG("Output Stream %p", out); |
| 1878 | |
| 1879 | |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 1880 | lock_output_stream(out); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1881 | |
| 1882 | //If QAF passthrough is active then block the resume on module input streams. |
| 1883 | if (p_qaf->passthrough_out) { |
| 1884 | //If resume is received for the QAF passthrough stream then call the primary HAL api. |
| 1885 | pthread_mutex_lock(&p_qaf->lock); |
| 1886 | if (p_qaf->passthrough_in == out) { |
| 1887 | status = p_qaf->passthrough_out->stream.resume( |
| 1888 | (struct audio_stream_out*)p_qaf->passthrough_out); |
| 1889 | if (!status) out->offload_state = OFFLOAD_STATE_PLAYING; |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 1890 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1891 | pthread_mutex_unlock(&p_qaf->lock); |
| 1892 | } else { |
| 1893 | //Flush the module input stream. |
| 1894 | status = qaf_stream_start(out); |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 1895 | } |
| 1896 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1897 | unlock_output_stream(out); |
| 1898 | |
| 1899 | DEBUG_MSG(); |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 1900 | return status; |
| 1901 | } |
| 1902 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1903 | /* Offload thread for QAF output streams. */ |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1904 | static void *qaf_offload_thread_loop(void *context) |
| 1905 | { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1906 | struct stream_out *out = (struct stream_out *)context; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1907 | struct listnode *item; |
| 1908 | int ret = 0; |
| 1909 | struct str_parms *parms = NULL; |
| 1910 | int value = 0; |
| 1911 | char* kvpairs = NULL; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1912 | struct qaf_module *qaf_mod = NULL; |
| 1913 | |
| 1914 | qaf_mod = get_qaf_module_for_input_stream(out); |
| 1915 | |
| 1916 | if (!qaf_mod) return NULL; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1917 | |
| 1918 | setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_AUDIO); |
| 1919 | set_sched_policy(0, SP_FOREGROUND); |
| 1920 | prctl(PR_SET_NAME, (unsigned long)"Offload Callback", 0, 0, 0); |
| 1921 | |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1922 | lock_output_stream(out); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1923 | |
| 1924 | DEBUG_MSG(); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1925 | for (;;) { |
| 1926 | struct offload_cmd *cmd = NULL; |
| 1927 | stream_callback_event_t event; |
| 1928 | bool send_callback = false; |
| 1929 | |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 1930 | DEBUG_MSG_VV("List Empty %d (1:TRUE, 0:FALSE)", list_empty(&out->qaf_offload_cmd_list)); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1931 | if (list_empty(&out->qaf_offload_cmd_list)) { |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 1932 | DEBUG_MSG_VV("SLEEPING"); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1933 | pthread_cond_wait(&out->qaf_offload_cond, &out->lock); |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 1934 | DEBUG_MSG_VV("RUNNING"); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1935 | continue; |
| 1936 | } |
| 1937 | |
| 1938 | item = list_head(&out->qaf_offload_cmd_list); |
| 1939 | cmd = node_to_item(item, struct offload_cmd, node); |
| 1940 | list_remove(item); |
| 1941 | |
| 1942 | if (cmd->cmd == OFFLOAD_CMD_EXIT) { |
| 1943 | free(cmd); |
| 1944 | break; |
| 1945 | } |
| 1946 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1947 | unlock_output_stream(out); |
| 1948 | |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1949 | send_callback = false; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1950 | switch (cmd->cmd) { |
| 1951 | case OFFLOAD_CMD_WAIT_FOR_BUFFER: { |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 1952 | DEBUG_MSG_VV("wait for buffer availability"); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1953 | |
| 1954 | while (1) { |
| 1955 | kvpairs = qaf_mod->qaf_audio_stream_get_param(out->qaf_stream_handle, |
| 1956 | "buf_available"); |
| 1957 | if (kvpairs) { |
| 1958 | parms = str_parms_create_str(kvpairs); |
| 1959 | ret = str_parms_get_int(parms, "buf_available", &value); |
| 1960 | if (ret >= 0) { |
| 1961 | if (value >= (int)out->compr_config.fragment_size) { |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 1962 | DEBUG_MSG_VV("buffer available"); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1963 | str_parms_destroy(parms); |
| 1964 | parms = NULL; |
| 1965 | break; |
| 1966 | } else { |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 1967 | DEBUG_MSG_VV("sleep"); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1968 | str_parms_destroy(parms); |
| 1969 | parms = NULL; |
| 1970 | usleep(10000); |
| 1971 | } |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1972 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1973 | free(kvpairs); |
| 1974 | kvpairs = NULL; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1975 | } |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1976 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1977 | send_callback = true; |
| 1978 | event = STREAM_CBK_EVENT_WRITE_READY; |
| 1979 | break; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1980 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1981 | default: |
| 1982 | DEBUG_MSG("unknown command received: %d", cmd->cmd); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1983 | break; |
| 1984 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1985 | |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1986 | lock_output_stream(out); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1987 | |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 1988 | if (send_callback && out->client_callback) { |
| 1989 | out->client_callback(event, NULL, out->client_cookie); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1990 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1991 | |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1992 | free(cmd); |
| 1993 | } |
| 1994 | |
| 1995 | while (!list_empty(&out->qaf_offload_cmd_list)) { |
| 1996 | item = list_head(&out->qaf_offload_cmd_list); |
| 1997 | list_remove(item); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 1998 | free (node_to_item( item, struct offload_cmd, node)); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 1999 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2000 | unlock_output_stream(out); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2001 | |
| 2002 | return NULL; |
| 2003 | } |
| 2004 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2005 | /* Create the offload callback thread for QAF output stream. */ |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2006 | static int qaf_create_offload_callback_thread(struct stream_out *out) |
| 2007 | { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2008 | DEBUG_MSG("Output Stream %p", out); |
| 2009 | lock_output_stream(out); |
| 2010 | pthread_cond_init(&out->qaf_offload_cond, (const pthread_condattr_t *)NULL); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2011 | list_init(&out->qaf_offload_cmd_list); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2012 | pthread_create(&out->qaf_offload_thread, |
| 2013 | (const pthread_attr_t *)NULL, |
| 2014 | qaf_offload_thread_loop, |
| 2015 | out); |
| 2016 | unlock_output_stream(out); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2017 | return 0; |
| 2018 | } |
| 2019 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2020 | /* Destroy the offload callback thread of QAF output stream. */ |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2021 | static int qaf_destroy_offload_callback_thread(struct stream_out *out) |
| 2022 | { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2023 | DEBUG_MSG("Output Stream %p", out); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2024 | qaf_send_offload_cmd_l(out, OFFLOAD_CMD_EXIT); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2025 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2026 | pthread_join(out->qaf_offload_thread, (void **)NULL); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2027 | pthread_cond_destroy(&out->qaf_offload_cond); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2028 | return 0; |
| 2029 | } |
| 2030 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2031 | /* Sets the stream set parameters (device routing information). */ |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 2032 | static int qaf_out_set_parameters(struct audio_stream *stream, const char *kvpairs) |
| 2033 | { |
| 2034 | struct str_parms *parms, *new_parms; |
| 2035 | char value[32]; |
| 2036 | char *new_kv_pairs; |
| 2037 | int val = 0; |
| 2038 | struct stream_out *out = (struct stream_out *)stream; |
| 2039 | int ret = 0; |
| 2040 | int err = 0; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2041 | struct qaf_module *qaf_mod = NULL; |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 2042 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2043 | DEBUG_MSG("usecase(%d: %s) kvpairs: %s", out->usecase, use_case_table[out->usecase], kvpairs); |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 2044 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2045 | parms = str_parms_create_str(kvpairs); |
| 2046 | err = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, value, sizeof(value)); |
| 2047 | if (err < 0) |
| 2048 | return err; |
| 2049 | val = atoi(value); |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 2050 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2051 | qaf_mod = get_qaf_module_for_input_stream(out); |
| 2052 | if (!qaf_mod) return (-EINVAL); |
| 2053 | |
| 2054 | //TODO: HDMI is connected but user doesn't want HDMI output, close both HDMI outputs. |
| 2055 | |
| 2056 | /* Setting new device information to the mm module input streams. |
| 2057 | * This is needed if QAF module output streams are not created yet. |
| 2058 | */ |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 2059 | out->devices = val; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2060 | |
| 2061 | if (val == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP) { |
| 2062 | //If device is BT then open the BT stream if not already opened. |
| 2063 | if ( audio_extn_bt_hal_get_output_stream(qaf_mod->bt_hdl) == NULL |
| 2064 | && audio_extn_bt_hal_get_device(qaf_mod->bt_hdl) != NULL) { |
| 2065 | ret = audio_extn_bt_hal_open_output_stream(qaf_mod->bt_hdl, |
| 2066 | QAF_OUTPUT_SAMPLING_RATE, |
| 2067 | AUDIO_CHANNEL_OUT_STEREO, |
| 2068 | CODEC_BACKEND_DEFAULT_BIT_WIDTH); |
| 2069 | if (ret != 0) { |
| 2070 | ERROR_MSG("BT Output stream open failure!"); |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 2071 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2072 | } |
| 2073 | } else if (val != 0) { |
| 2074 | //If device is not BT then close the BT stream if already opened. |
| 2075 | if ( audio_extn_bt_hal_get_output_stream(qaf_mod->bt_hdl) != NULL) { |
| 2076 | audio_extn_bt_hal_close_output_stream(qaf_mod->bt_hdl); |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 2077 | } |
| 2078 | } |
| 2079 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2080 | if (p_qaf->passthrough_in == out) { //Device routing is received for QAF passthrough stream. |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 2081 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2082 | if (!(val & AUDIO_DEVICE_OUT_AUX_DIGITAL)) { //HDMI route is disabled. |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 2083 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2084 | //If QAF pasthrough output is enabled. Close it. |
| 2085 | close_qaf_passthrough_stream(); |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 2086 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2087 | //Send the routing information to mm module pcm output. |
| 2088 | if (qaf_mod->stream_out[QAF_OUT_OFFLOAD]) { |
| 2089 | ret = qaf_mod->stream_out[QAF_OUT_OFFLOAD]->stream.common.set_parameters( |
| 2090 | (struct audio_stream *)qaf_mod->stream_out[QAF_OUT_OFFLOAD], kvpairs); |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 2091 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2092 | //else: device info is updated in the input streams. |
| 2093 | } else { //HDMI route is enabled. |
| 2094 | |
| 2095 | //create the QAf passthrough stream, if not created already. |
| 2096 | ret = create_qaf_passthrough_stream(); |
| 2097 | |
| 2098 | if (p_qaf->passthrough_out != NULL) { //If QAF passthrough out is enabled then send routing information. |
| 2099 | ret = p_qaf->passthrough_out->stream.common.set_parameters( |
| 2100 | (struct audio_stream *)p_qaf->passthrough_out, kvpairs); |
| 2101 | } |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 2102 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2103 | } else { |
| 2104 | //Send the routing information to mm module pcm output. |
| 2105 | if (qaf_mod->stream_out[QAF_OUT_OFFLOAD]) { |
| 2106 | ret = qaf_mod->stream_out[QAF_OUT_OFFLOAD]->stream.common.set_parameters( |
| 2107 | (struct audio_stream *)qaf_mod->stream_out[QAF_OUT_OFFLOAD], kvpairs); |
| 2108 | } |
| 2109 | //else: device info is updated in the input streams. |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 2110 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2111 | str_parms_destroy(parms); |
| 2112 | |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 2113 | return ret; |
| 2114 | } |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 2115 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2116 | /* Checks if a stream is QAF stream or not. */ |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 2117 | bool audio_extn_is_qaf_stream(struct stream_out *out) |
| 2118 | { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2119 | struct qaf_module *qaf_mod = get_qaf_module_for_input_stream(out); |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 2120 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2121 | if (qaf_mod) { |
| 2122 | return true; |
| 2123 | } |
| 2124 | return false; |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 2125 | } |
| 2126 | |
| 2127 | /* API to send playback stream specific config parameters */ |
| 2128 | int audio_extn_qaf_out_set_param_data(struct stream_out *out, |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2129 | audio_extn_param_id param_id, |
| 2130 | audio_extn_param_payload *payload) |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 2131 | { |
| 2132 | int ret = -EINVAL; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2133 | int index; |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 2134 | struct stream_out *new_out = NULL; |
| 2135 | struct audio_adsp_event *adsp_event; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2136 | struct qaf_module *qaf_mod = get_qaf_module_for_input_stream(out); |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 2137 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2138 | if (!out || !qaf_mod || !payload) { |
| 2139 | ERROR_MSG("Invalid Param"); |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 2140 | return ret; |
| 2141 | } |
| 2142 | |
| 2143 | /* In qaf output render session may not be opened at this time. |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2144 | to handle it store adsp_hdlr param info so that it can be |
| 2145 | applied later after opening render session from ms12 callback |
| 2146 | */ |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 2147 | if (param_id == AUDIO_EXTN_PARAM_ADSP_STREAM_CMD) { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2148 | index = get_input_stream_index(out); |
| 2149 | if (index < 0) { |
| 2150 | ERROR_MSG("Invalid stream"); |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 2151 | return ret; |
| 2152 | } |
| 2153 | adsp_event = (struct audio_adsp_event *)payload; |
| 2154 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2155 | if (payload->adsp_event_params.payload_length <= AUDIO_MAX_ADSP_STREAM_CMD_PAYLOAD_LEN) { |
| 2156 | pthread_mutex_lock(&p_qaf->lock); |
| 2157 | memcpy(qaf_mod->adsp_hdlr_config[index].event_payload, |
| 2158 | adsp_event->payload, |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 2159 | adsp_event->payload_length); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2160 | qaf_mod->adsp_hdlr_config[index].event_params.payload = |
| 2161 | qaf_mod->adsp_hdlr_config[index].event_payload; |
| 2162 | qaf_mod->adsp_hdlr_config[index].event_params.payload_length = |
| 2163 | adsp_event->payload_length; |
| 2164 | qaf_mod->adsp_hdlr_config[index].adsp_hdlr_config_valid = true; |
| 2165 | pthread_mutex_unlock(&p_qaf->lock); |
| 2166 | } else { |
| 2167 | ERROR_MSG("Invalid adsp event length %d", adsp_event->payload_length); |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 2168 | return ret; |
| 2169 | } |
| 2170 | ret = 0; |
| 2171 | } |
| 2172 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2173 | /* apply param for all active out sessions */ |
| 2174 | for (index = 0; index < MAX_QAF_MODULE_OUT; index++) { |
| 2175 | new_out = qaf_mod->stream_out[index]; |
| 2176 | if (!new_out) continue; |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 2177 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2178 | /*ADSP event is not supported for passthrough*/ |
| 2179 | if ((param_id == AUDIO_EXTN_PARAM_ADSP_STREAM_CMD) |
| 2180 | && !(new_out->flags & AUDIO_OUTPUT_FLAG_DIRECT_PCM)) continue; |
| 2181 | if (new_out->standby) |
| 2182 | new_out->stream.write((struct audio_stream_out *)new_out, NULL, 0); |
| 2183 | lock_output_stream(new_out); |
| 2184 | ret = audio_extn_out_set_param_data(new_out, param_id, payload); |
| 2185 | if (ret) |
| 2186 | ERROR_MSG("audio_extn_out_set_param_data error %d", ret); |
| 2187 | unlock_output_stream(new_out); |
| 2188 | } |
| 2189 | return ret; |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 2190 | } |
| 2191 | |
| 2192 | int audio_extn_qaf_out_get_param_data(struct stream_out *out, |
| 2193 | audio_extn_param_id param_id, |
| 2194 | audio_extn_param_payload *payload) |
| 2195 | { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2196 | int ret = -EINVAL, i; |
| 2197 | struct stream_out *new_out; |
| 2198 | struct audio_usecase *uc_info; |
| 2199 | struct qaf_module *qaf_mod = get_qaf_module_for_input_stream(out); |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 2200 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2201 | if (!out || !qaf_mod || !payload) { |
| 2202 | ERROR_MSG("Invalid Param"); |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 2203 | return ret; |
| 2204 | } |
| 2205 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2206 | if (!p_qaf->hdmi_connect) { |
| 2207 | ERROR_MSG("hdmi not connected"); |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 2208 | return ret; |
| 2209 | } |
| 2210 | |
| 2211 | /* get session which is routed to hdmi*/ |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2212 | if (p_qaf->passthrough_out) |
| 2213 | new_out = p_qaf->passthrough_out; |
| 2214 | else { |
| 2215 | for (i = 0; i < MAX_QAF_MODULE_OUT; i++) { |
| 2216 | if (qaf_mod->stream_out[i]) { |
| 2217 | new_out = qaf_mod->stream_out[i]; |
| 2218 | break; |
| 2219 | } |
| 2220 | } |
| 2221 | } |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 2222 | |
| 2223 | if (!new_out) { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2224 | ERROR_MSG("No stream active."); |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 2225 | return ret; |
| 2226 | } |
| 2227 | |
| 2228 | if (new_out->standby) |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2229 | new_out->stream.write((struct audio_stream_out *)new_out, NULL, 0); |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 2230 | |
| 2231 | lock_output_stream(new_out); |
| 2232 | ret = audio_extn_out_get_param_data(new_out, param_id, payload); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2233 | if (ret) |
| 2234 | ERROR_MSG("audio_extn_out_get_param_data error %d", ret); |
| 2235 | unlock_output_stream(new_out); |
| 2236 | |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 2237 | return ret; |
| 2238 | } |
| 2239 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2240 | /* To open a stream with QAF. */ |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2241 | int audio_extn_qaf_open_output_stream(struct audio_hw_device *dev, |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2242 | audio_io_handle_t handle, |
| 2243 | audio_devices_t devices, |
| 2244 | audio_output_flags_t flags, |
| 2245 | struct audio_config *config, |
| 2246 | struct audio_stream_out **stream_out, |
| 2247 | const char *address) |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2248 | { |
| 2249 | int ret = 0; |
| 2250 | struct stream_out *out; |
| 2251 | |
| 2252 | ret = adev_open_output_stream(dev, handle, devices, flags, config, stream_out, address); |
| 2253 | if (*stream_out == NULL) { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2254 | ERROR_MSG("Stream open failed %d", ret); |
Deepak Agarwal | 1e42b85 | 2017-02-11 17:57:04 +0530 | [diff] [blame] | 2255 | return ret; |
| 2256 | } |
| 2257 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2258 | out = (struct stream_out *)*stream_out; |
| 2259 | |
| 2260 | ret = qaf_stream_open(out, config, flags, devices); |
| 2261 | if (ret == -ENOTSUP) { |
| 2262 | //Stream not supported by QAF, Bypass QAF. |
| 2263 | return 0; |
| 2264 | } else if (ret < 0) { |
| 2265 | ERROR_MSG("Error opening QAF stream err[%d]!", ret); |
| 2266 | adev_close_output_stream(dev, *stream_out); |
| 2267 | return ret; |
| 2268 | } |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2269 | |
| 2270 | /* Override function pointers based on qaf definitions */ |
| 2271 | out->stream.set_volume = qaf_out_set_volume; |
| 2272 | out->stream.pause = qaf_out_pause; |
| 2273 | out->stream.resume = qaf_out_resume; |
| 2274 | out->stream.drain = qaf_out_drain; |
| 2275 | out->stream.flush = qaf_out_flush; |
| 2276 | |
| 2277 | out->stream.common.standby = qaf_out_standby; |
| 2278 | out->stream.common.set_parameters = qaf_out_set_parameters; |
| 2279 | out->stream.get_latency = qaf_out_get_latency; |
| 2280 | out->stream.write = qaf_out_write; |
| 2281 | out->stream.get_presentation_position = qaf_out_get_presentation_position; |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 2282 | out->platform_latency = 0; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2283 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2284 | /*TODO: Need to handle this for DTS*/ |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2285 | if (out->usecase == USECASE_AUDIO_PLAYBACK_LOW_LATENCY) { |
| 2286 | out->usecase = USECASE_AUDIO_PLAYBACK_DEEP_BUFFER; |
Varun B | 34da7a4 | 2017-02-13 16:16:53 +0530 | [diff] [blame] | 2287 | out->config.period_size = QAF_DEEP_BUFFER_OUTPUT_PERIOD_SIZE; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2288 | out->config.period_count = DEEP_BUFFER_OUTPUT_PERIOD_COUNT; |
Varun B | 34da7a4 | 2017-02-13 16:16:53 +0530 | [diff] [blame] | 2289 | out->config.start_threshold = QAF_DEEP_BUFFER_OUTPUT_PERIOD_SIZE / 4; |
| 2290 | out->config.avail_min = QAF_DEEP_BUFFER_OUTPUT_PERIOD_SIZE / 4; |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 2291 | } else if(out->flags & AUDIO_OUTPUT_FLAG_DIRECT_PCM) { |
| 2292 | out->compr_config.fragment_size = qaf_get_pcm_offload_input_buffer_size(&(config->offload_info)); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2293 | } |
Satish Babu Patakokila | a8c136d | 2017-04-21 12:48:19 +0530 | [diff] [blame] | 2294 | |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2295 | *stream_out = &out->stream; |
| 2296 | if (out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) { |
| 2297 | qaf_create_offload_callback_thread(out); |
| 2298 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2299 | |
| 2300 | DEBUG_MSG("Exit"); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2301 | return 0; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2302 | } |
| 2303 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2304 | /* Close a QAF stream. */ |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2305 | void audio_extn_qaf_close_output_stream(struct audio_hw_device *dev, |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2306 | struct audio_stream_out *stream) |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2307 | { |
| 2308 | struct stream_out *out = (struct stream_out *)stream; |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2309 | struct qaf_module* qaf_mod = get_qaf_module_for_input_stream(out); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2310 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2311 | if (!qaf_mod) return; |
| 2312 | |
| 2313 | DEBUG_MSG("stream_handle(%p) format = %x", out, out->format); |
| 2314 | |
| 2315 | //If close is received for QAF passthrough stream then close the QAF passthrough output. |
| 2316 | if (p_qaf->passthrough_in == out) { |
| 2317 | if (p_qaf->passthrough_out) { |
| 2318 | ALOGD("%s %d closing stream handle %p", __func__, __LINE__, p_qaf->passthrough_out); |
| 2319 | pthread_mutex_lock(&p_qaf->lock); |
| 2320 | adev_close_output_stream((struct audio_hw_device *)p_qaf->adev, |
| 2321 | (struct audio_stream_out *)(p_qaf->passthrough_out)); |
| 2322 | pthread_mutex_unlock(&p_qaf->lock); |
| 2323 | p_qaf->passthrough_out = NULL; |
| 2324 | } |
| 2325 | |
| 2326 | p_qaf->passthrough_in = NULL; |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 2327 | } |
| 2328 | |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2329 | if (out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) { |
| 2330 | qaf_destroy_offload_callback_thread(out); |
| 2331 | } |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 2332 | |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2333 | qaf_stream_close(out); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2334 | |
| 2335 | adev_close_output_stream(dev, stream); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2336 | |
| 2337 | DEBUG_MSG("Exit"); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2338 | } |
| 2339 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2340 | /* Check if QAF is supported or not. */ |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2341 | bool audio_extn_qaf_is_enabled() |
| 2342 | { |
| 2343 | bool prop_enabled = false; |
| 2344 | char value[PROPERTY_VALUE_MAX] = {0}; |
Aniket Kumar Lata | 8fc67e6 | 2017-05-02 12:33:46 -0700 | [diff] [blame] | 2345 | property_get("vendor.audio.qaf.enabled", value, NULL); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2346 | prop_enabled = atoi(value) || !strncmp("true", value, 4); |
| 2347 | return (prop_enabled); |
| 2348 | } |
| 2349 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2350 | /* Query HDMI EDID and sets module output accordingly.*/ |
| 2351 | void set_hdmi_configuration_to_module() |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2352 | { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2353 | int channels = 0; |
| 2354 | char *format_params; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2355 | struct str_parms *qaf_params; |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 2356 | char prop_value[PROPERTY_VALUE_MAX]; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2357 | bool passth_support = false; |
| 2358 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2359 | DEBUG_MSG("Entry"); |
| 2360 | |
| 2361 | if (!p_qaf) { |
| 2362 | return; |
| 2363 | } |
| 2364 | |
| 2365 | if (!p_qaf->hdmi_connect) { |
| 2366 | DEBUG_MSG("HDMI is not connected."); |
| 2367 | return; |
| 2368 | } |
| 2369 | |
| 2370 | p_qaf->hdmi_sink_channels = 0; |
| 2371 | |
| 2372 | //QAF re-encoding and DSP offload passthrough is supported. |
Aniket Kumar Lata | 8fc67e6 | 2017-05-02 12:33:46 -0700 | [diff] [blame] | 2373 | if (property_get_bool("vendor.audio.offload.passthrough", false) |
| 2374 | && property_get_bool("vendor.audio.qaf.reencode", false)) { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2375 | |
| 2376 | //If MS12 session is active. |
| 2377 | if (p_qaf->qaf_mod[MS12].session_handle && p_qaf->qaf_mod[MS12].qaf_audio_session_set_param) { |
| 2378 | |
| 2379 | bool do_setparam = false; |
| 2380 | qaf_params = str_parms_create(); |
Aniket Kumar Lata | 8fc67e6 | 2017-05-02 12:33:46 -0700 | [diff] [blame] | 2381 | property_get("vendor.audio.qaf.hdmi.out", prop_value, NULL); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2382 | |
| 2383 | if (platform_is_edid_supported_format(p_qaf->adev->platform, AUDIO_FORMAT_E_AC3) |
| 2384 | && (strncmp(prop_value, "ddp", 3) == 0)) { |
| 2385 | do_setparam = true; |
| 2386 | if (qaf_params) { |
| 2387 | str_parms_add_str(qaf_params, |
| 2388 | AUDIO_QAF_PARAMETER_KEY_RENDER_FORMAT, |
| 2389 | AUDIO_QAF_PARAMETER_VALUE_REENCODE_EAC3); |
| 2390 | } |
| 2391 | } else if (platform_is_edid_supported_format(p_qaf->adev->platform, AUDIO_FORMAT_AC3)) { |
| 2392 | do_setparam = true; |
| 2393 | if (qaf_params) { |
| 2394 | str_parms_add_str(qaf_params, |
| 2395 | AUDIO_QAF_PARAMETER_KEY_RENDER_FORMAT, |
| 2396 | AUDIO_QAF_PARAMETER_VALUE_REENCODE_AC3); |
| 2397 | } |
| 2398 | } |
| 2399 | |
| 2400 | if (do_setparam) { |
| 2401 | if (p_qaf->qaf_msmd_enabled) { |
| 2402 | str_parms_add_str(qaf_params, |
| 2403 | AUDIO_QAF_PARAMETER_KEY_DEVICE, |
| 2404 | AUDIO_QAF_PARAMETER_VALUE_DEVICE_HDMI_AND_SPK); //TODO: Need enhancement. |
| 2405 | } else { |
| 2406 | str_parms_add_str(qaf_params, |
| 2407 | AUDIO_QAF_PARAMETER_KEY_DEVICE, |
| 2408 | AUDIO_QAF_PARAMETER_VALUE_DEVICE_HDMI); |
| 2409 | } |
| 2410 | format_params = str_parms_to_str(qaf_params); |
| 2411 | |
| 2412 | p_qaf->qaf_mod[MS12].qaf_audio_session_set_param(p_qaf->qaf_mod[MS12].session_handle, |
| 2413 | format_params); |
| 2414 | |
| 2415 | passth_support = true; |
| 2416 | } |
| 2417 | str_parms_destroy(qaf_params); |
| 2418 | } |
| 2419 | |
| 2420 | //DTS_M8 session is active. |
| 2421 | if (p_qaf->qaf_mod[DTS_M8].session_handle |
| 2422 | && p_qaf->qaf_mod[DTS_M8].qaf_audio_session_set_param) { |
| 2423 | |
| 2424 | bool do_setparam = false; |
| 2425 | qaf_params = str_parms_create(); |
| 2426 | #if 0 //TODO: Need to enable with DTS_M8 wrapper. |
| 2427 | if (platform_is_edid_supported_format(p_qaf->adev->platform, AUDIO_FORMAT_DTS)) { |
| 2428 | do_setparam = true; |
| 2429 | if (qaf_params) { |
| 2430 | str_parms_add_str(qaf_params, |
| 2431 | AUDIO_QAF_PARAMETER_KEY_RENDER_FORMAT, |
| 2432 | AUDIO_QAF_PARAMETER_VALUE_REENCODE_DTS); |
| 2433 | } |
| 2434 | } |
| 2435 | #endif |
| 2436 | |
| 2437 | if (do_setparam) { |
| 2438 | if (p_qaf->qaf_msmd_enabled) { |
| 2439 | str_parms_add_str(qaf_params, |
| 2440 | AUDIO_QAF_PARAMETER_KEY_DEVICE, |
| 2441 | AUDIO_QAF_PARAMETER_VALUE_DEVICE_HDMI_AND_SPK); //TODO: Need enhancement. |
| 2442 | } else { |
| 2443 | str_parms_add_str(qaf_params, |
| 2444 | AUDIO_QAF_PARAMETER_KEY_DEVICE, |
| 2445 | AUDIO_QAF_PARAMETER_VALUE_DEVICE_HDMI); |
| 2446 | } |
| 2447 | format_params = str_parms_to_str(qaf_params); |
| 2448 | |
| 2449 | p_qaf->qaf_mod[DTS_M8].qaf_audio_session_set_param(p_qaf->qaf_mod[DTS_M8].session_handle, |
| 2450 | format_params); |
| 2451 | |
| 2452 | passth_support = true; |
| 2453 | } |
| 2454 | str_parms_destroy(qaf_params); |
| 2455 | } |
| 2456 | } |
| 2457 | |
| 2458 | //Compressed passthrough is not enabled. |
| 2459 | if (!passth_support) { |
| 2460 | |
| 2461 | channels = platform_edid_get_max_channels(p_qaf->adev->platform); |
| 2462 | |
| 2463 | qaf_params = str_parms_create(); |
| 2464 | switch (channels) { |
| 2465 | case 8: |
| 2466 | DEBUG_MSG("Switching Qaf output to 7.1 channels"); |
| 2467 | str_parms_add_str(qaf_params, |
| 2468 | AUDIO_QAF_PARAMETER_KEY_CHANNELS, |
| 2469 | AUDIO_QAF_PARAMETER_VALUE_8_CHANNELS); |
| 2470 | if (p_qaf->qaf_msmd_enabled) { |
| 2471 | str_parms_add_str(qaf_params, |
| 2472 | AUDIO_QAF_PARAMETER_KEY_DEVICE, |
| 2473 | AUDIO_QAF_PARAMETER_VALUE_DEVICE_HDMI_AND_SPK); |
| 2474 | } else { |
| 2475 | str_parms_add_str(qaf_params, |
| 2476 | AUDIO_QAF_PARAMETER_KEY_DEVICE, |
| 2477 | AUDIO_QAF_PARAMETER_VALUE_DEVICE_HDMI); |
| 2478 | } |
| 2479 | p_qaf->hdmi_sink_channels = channels; |
| 2480 | break; |
| 2481 | case 6: |
| 2482 | DEBUG_MSG("Switching Qaf output to 5.1 channels"); |
| 2483 | str_parms_add_str(qaf_params, |
| 2484 | AUDIO_QAF_PARAMETER_KEY_CHANNELS, |
| 2485 | AUDIO_QAF_PARAMETER_VALUE_6_CHANNELS); |
| 2486 | if (p_qaf->qaf_msmd_enabled) { |
| 2487 | str_parms_add_str(qaf_params, |
| 2488 | AUDIO_QAF_PARAMETER_KEY_DEVICE, |
| 2489 | AUDIO_QAF_PARAMETER_VALUE_DEVICE_HDMI_AND_SPK); |
| 2490 | } else { |
| 2491 | str_parms_add_str(qaf_params, |
| 2492 | AUDIO_QAF_PARAMETER_KEY_DEVICE, |
| 2493 | AUDIO_QAF_PARAMETER_VALUE_DEVICE_HDMI); |
| 2494 | } |
| 2495 | p_qaf->hdmi_sink_channels = channels; |
| 2496 | break; |
| 2497 | default: |
| 2498 | DEBUG_MSG("Switching Qaf output to default channels"); |
| 2499 | str_parms_add_str(qaf_params, |
| 2500 | AUDIO_QAF_PARAMETER_KEY_CHANNELS, |
| 2501 | AUDIO_QAF_PARAMETER_VALUE_DEFAULT_CHANNELS); |
| 2502 | if (p_qaf->qaf_msmd_enabled) { |
| 2503 | str_parms_add_str(qaf_params, |
| 2504 | AUDIO_QAF_PARAMETER_KEY_DEVICE, |
| 2505 | AUDIO_QAF_PARAMETER_VALUE_DEVICE_HDMI_AND_SPK); |
| 2506 | } else { |
| 2507 | str_parms_add_str(qaf_params, |
| 2508 | AUDIO_QAF_PARAMETER_KEY_DEVICE, |
| 2509 | AUDIO_QAF_PARAMETER_VALUE_DEVICE_SPEAKER); |
| 2510 | } |
| 2511 | p_qaf->hdmi_sink_channels = 2; |
| 2512 | break; |
| 2513 | } |
| 2514 | |
| 2515 | format_params = str_parms_to_str(qaf_params); |
| 2516 | |
| 2517 | if (p_qaf->qaf_mod[MS12].session_handle && p_qaf->qaf_mod[MS12].qaf_audio_session_set_param) { |
| 2518 | p_qaf->qaf_mod[MS12].qaf_audio_session_set_param(p_qaf->qaf_mod[MS12].session_handle, |
| 2519 | format_params); |
| 2520 | } |
| 2521 | if (p_qaf->qaf_mod[DTS_M8].session_handle |
| 2522 | && p_qaf->qaf_mod[DTS_M8].qaf_audio_session_set_param) { |
| 2523 | p_qaf->qaf_mod[DTS_M8].qaf_audio_session_set_param(p_qaf->qaf_mod[DTS_M8].session_handle, |
| 2524 | format_params); |
| 2525 | } |
| 2526 | |
| 2527 | str_parms_destroy(qaf_params); |
| 2528 | } |
| 2529 | DEBUG_MSG("Exit"); |
| 2530 | } |
| 2531 | |
| 2532 | /* QAF set parameter function. For Device connect and disconnect. */ |
| 2533 | int audio_extn_qaf_set_parameters(struct audio_device *adev, struct str_parms *parms) |
| 2534 | { |
| 2535 | int status = 0, val = 0, k; |
| 2536 | char *format_params, *kv_parirs; |
| 2537 | struct str_parms *qaf_params; |
| 2538 | char value[32]; |
| 2539 | |
| 2540 | DEBUG_MSG("Entry"); |
| 2541 | |
| 2542 | if (!p_qaf) { |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2543 | return -EINVAL; |
| 2544 | } |
| 2545 | |
| 2546 | status = str_parms_get_str(parms, AUDIO_PARAMETER_DEVICE_CONNECT, value, sizeof(value)); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2547 | |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2548 | if (status >= 0) { |
| 2549 | val = atoi(value); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2550 | if (val & AUDIO_DEVICE_OUT_AUX_DIGITAL) { //HDMI is connected. |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2551 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2552 | p_qaf->hdmi_connect = 1; |
| 2553 | p_qaf->hdmi_sink_channels = 0; |
| 2554 | |
| 2555 | if (p_qaf->passthrough_in) { //If QAF passthrough is already initialized. |
| 2556 | lock_output_stream(p_qaf->passthrough_in); |
| 2557 | if (platform_is_edid_supported_format(adev->platform, |
| 2558 | p_qaf->passthrough_in->format)) { |
| 2559 | //If passthrough format is supported by HDMI then create the QAF passthrough output if not created already. |
| 2560 | create_qaf_passthrough_stream(); |
| 2561 | //Ignoring the returned error, If error then QAF passthrough is disabled. |
| 2562 | } else { |
| 2563 | //If passthrough format is not supported by HDMI then close the QAF passthrough output if already created. |
| 2564 | close_qaf_passthrough_stream(); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2565 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2566 | unlock_output_stream(p_qaf->passthrough_in); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2567 | } |
| 2568 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2569 | set_hdmi_configuration_to_module(); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2570 | |
Bharath Gopal | 01310bb | 2016-12-05 15:39:32 +0530 | [diff] [blame] | 2571 | } else if (val & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP) { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2572 | for (k = 0; k < MAX_MM_MODULE_TYPE; k++) { |
| 2573 | if (!p_qaf->qaf_mod[k].bt_hdl) { |
| 2574 | DEBUG_MSG("Opening a2dp output..."); |
| 2575 | status = audio_extn_bt_hal_load(&p_qaf->qaf_mod[k].bt_hdl); |
| 2576 | if (status != 0) { |
| 2577 | ERROR_MSG("Error opening BT module"); |
| 2578 | return status; |
| 2579 | } |
| 2580 | } |
Bharath Gopal | 01310bb | 2016-12-05 15:39:32 +0530 | [diff] [blame] | 2581 | } |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2582 | } |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2583 | //TODO else if: Need to consider other devices. |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2584 | } |
| 2585 | |
| 2586 | status = str_parms_get_str(parms, AUDIO_PARAMETER_DEVICE_DISCONNECT, value, sizeof(value)); |
| 2587 | if (status >= 0) { |
| 2588 | val = atoi(value); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2589 | if (val & AUDIO_DEVICE_OUT_AUX_DIGITAL) { //HDMI is disconnected. |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2590 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2591 | qaf_params = str_parms_create(); |
| 2592 | str_parms_add_str(qaf_params, |
| 2593 | AUDIO_QAF_PARAMETER_KEY_DEVICE, |
| 2594 | AUDIO_QAF_PARAMETER_VALUE_DEVICE_SPEAKER); |
| 2595 | str_parms_add_str(qaf_params, |
| 2596 | AUDIO_QAF_PARAMETER_KEY_RENDER_FORMAT, |
| 2597 | AUDIO_QAF_PARAMETER_VALUE_PCM); |
| 2598 | p_qaf->hdmi_sink_channels = 0; |
| 2599 | |
| 2600 | p_qaf->passthrough_enabled = 0; |
| 2601 | p_qaf->mch_pcm_hdmi_enabled = 0; |
| 2602 | p_qaf->hdmi_connect = 0; |
| 2603 | |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2604 | format_params = str_parms_to_str(qaf_params); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2605 | |
| 2606 | for (k = 0; k < MAX_MM_MODULE_TYPE; k++) { |
| 2607 | if (p_qaf->qaf_mod[k].session_handle |
| 2608 | && p_qaf->qaf_mod[k].qaf_audio_session_set_param) { |
| 2609 | p_qaf->qaf_mod[k].qaf_audio_session_set_param( |
| 2610 | p_qaf->qaf_mod[k].session_handle, format_params); |
| 2611 | } |
| 2612 | } |
| 2613 | close_all_hdmi_output(); |
| 2614 | |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2615 | str_parms_destroy(qaf_params); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2616 | close_qaf_passthrough_stream(); |
Bharath Gopal | 01310bb | 2016-12-05 15:39:32 +0530 | [diff] [blame] | 2617 | } else if (val & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP) { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2618 | DEBUG_MSG("Closing a2dp output..."); |
| 2619 | for (k = 0; k < MAX_MM_MODULE_TYPE; k++) { |
| 2620 | if (p_qaf->qaf_mod[k].bt_hdl) { |
| 2621 | audio_extn_bt_hal_unload(p_qaf->qaf_mod[k].bt_hdl); |
| 2622 | p_qaf->qaf_mod[k].bt_hdl = NULL; |
| 2623 | } |
| 2624 | } |
| 2625 | } |
| 2626 | //TODO else if: Need to consider other devices. |
| 2627 | } |
| 2628 | |
| 2629 | for (k = 0; k < MAX_MM_MODULE_TYPE; k++) { |
| 2630 | kv_parirs = str_parms_to_str(parms); |
| 2631 | if (p_qaf->qaf_mod[k].session_handle && p_qaf->qaf_mod[k].qaf_audio_session_set_param) { |
| 2632 | p_qaf->qaf_mod[k].qaf_audio_session_set_param( |
| 2633 | p_qaf->qaf_mod[k].session_handle, kv_parirs); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2634 | } |
| 2635 | } |
| 2636 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2637 | DEBUG_MSG("Exit"); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2638 | return status; |
| 2639 | } |
| 2640 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2641 | /* Create the QAF. */ |
| 2642 | int audio_extn_qaf_init(struct audio_device *adev) |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2643 | { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2644 | DEBUG_MSG("Entry"); |
| 2645 | |
| 2646 | p_qaf = calloc(1, sizeof(struct qaf)); |
| 2647 | if (p_qaf == NULL) { |
| 2648 | ERROR_MSG("Out of memory"); |
| 2649 | return -ENOMEM; |
| 2650 | } |
| 2651 | |
| 2652 | p_qaf->adev = adev; |
| 2653 | |
Aniket Kumar Lata | 8fc67e6 | 2017-05-02 12:33:46 -0700 | [diff] [blame] | 2654 | if (property_get_bool("vendor.audio.qaf.msmd", false)) { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2655 | p_qaf->qaf_msmd_enabled = 1; |
| 2656 | } |
| 2657 | pthread_mutex_init(&p_qaf->lock, (const pthread_mutexattr_t *) NULL); |
| 2658 | |
| 2659 | int i = 0; |
| 2660 | |
| 2661 | for (i = 0; i < MAX_MM_MODULE_TYPE; i++) { |
| 2662 | char value[PROPERTY_VALUE_MAX] = {0}; |
| 2663 | char lib_name[PROPERTY_VALUE_MAX] = {0}; |
| 2664 | struct qaf_module *qaf_mod = &(p_qaf->qaf_mod[i]); |
| 2665 | |
| 2666 | if (i == MS12) { |
Aniket Kumar Lata | 8fc67e6 | 2017-05-02 12:33:46 -0700 | [diff] [blame] | 2667 | property_get("vendor.audio.qaf.library", value, NULL); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2668 | } else if (i == DTS_M8) { |
Aniket Kumar Lata | 8fc67e6 | 2017-05-02 12:33:46 -0700 | [diff] [blame] | 2669 | property_get("vendor.audio.qaf.m8.library", value, NULL); |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2670 | } else { |
| 2671 | continue; |
| 2672 | } |
| 2673 | |
| 2674 | snprintf(lib_name, PROPERTY_VALUE_MAX, "%s", value); |
| 2675 | |
| 2676 | qaf_mod->qaf_lib = dlopen(lib_name, RTLD_NOW); |
| 2677 | if (qaf_mod->qaf_lib == NULL) { |
| 2678 | ERROR_MSG("DLOPEN failed for %s", lib_name); |
| 2679 | continue; |
| 2680 | } |
| 2681 | |
| 2682 | DEBUG_MSG("DLOPEN successful for %s", lib_name); |
| 2683 | qaf_mod->qaf_audio_session_open = |
| 2684 | (int (*)(audio_session_handle_t* session_handle, void *p_data, void* license_data))dlsym(qaf_mod->qaf_lib, |
| 2685 | "audio_session_open"); |
| 2686 | qaf_mod->qaf_audio_session_close = |
| 2687 | (int (*)(audio_session_handle_t session_handle))dlsym(qaf_mod->qaf_lib, |
| 2688 | "audio_session_close"); |
| 2689 | qaf_mod->qaf_audio_stream_open = |
| 2690 | (int (*)(audio_session_handle_t session_handle, audio_stream_handle_t* stream_handle, |
| 2691 | audio_stream_config_t input_config, audio_devices_t devices, stream_type_t flags))dlsym(qaf_mod->qaf_lib, |
| 2692 | "audio_stream_open"); |
| 2693 | qaf_mod->qaf_audio_stream_close = |
| 2694 | (int (*)(audio_stream_handle_t stream_handle))dlsym(qaf_mod->qaf_lib, |
| 2695 | "audio_stream_close"); |
| 2696 | qaf_mod->qaf_audio_stream_set_param = |
| 2697 | (int (*)(audio_stream_handle_t stream_handle, const char* kv_pairs))dlsym(qaf_mod->qaf_lib, |
| 2698 | "audio_stream_set_param"); |
| 2699 | qaf_mod->qaf_audio_session_set_param = |
| 2700 | (int (*)(audio_session_handle_t handle, const char* kv_pairs))dlsym(qaf_mod->qaf_lib, |
| 2701 | "audio_session_set_param"); |
| 2702 | qaf_mod->qaf_audio_stream_get_param = |
| 2703 | (char* (*)(audio_stream_handle_t stream_handle, const char* key))dlsym(qaf_mod->qaf_lib, |
| 2704 | "audio_stream_get_param"); |
| 2705 | qaf_mod->qaf_audio_session_get_param = |
| 2706 | (char* (*)(audio_session_handle_t handle, const char* key))dlsym(qaf_mod->qaf_lib, |
| 2707 | "audio_session_get_param"); |
| 2708 | qaf_mod->qaf_audio_stream_start = |
| 2709 | (int (*)(audio_stream_handle_t stream_handle))dlsym(qaf_mod->qaf_lib, |
| 2710 | "audio_stream_start"); |
| 2711 | qaf_mod->qaf_audio_stream_stop = |
| 2712 | (int (*)(audio_stream_handle_t stream_handle))dlsym(qaf_mod->qaf_lib, |
| 2713 | "audio_stream_stop"); |
| 2714 | qaf_mod->qaf_audio_stream_pause = |
| 2715 | (int (*)(audio_stream_handle_t stream_handle))dlsym(qaf_mod->qaf_lib, |
| 2716 | "audio_stream_pause"); |
| 2717 | qaf_mod->qaf_audio_stream_flush = |
| 2718 | (int (*)(audio_stream_handle_t stream_handle))dlsym(qaf_mod->qaf_lib, |
| 2719 | "audio_stream_flush"); |
| 2720 | qaf_mod->qaf_audio_stream_write = |
| 2721 | (int (*)(audio_stream_handle_t stream_handle, const void* buf, int size))dlsym(qaf_mod->qaf_lib, |
| 2722 | "audio_stream_write"); |
| 2723 | qaf_mod->qaf_register_event_callback = |
| 2724 | (void (*)(audio_session_handle_t session_handle, void *priv_data, notify_event_callback_t event_callback, |
| 2725 | audio_event_id_t event_id))dlsym(qaf_mod->qaf_lib, |
| 2726 | "register_event_callback"); |
| 2727 | } |
| 2728 | |
| 2729 | DEBUG_MSG("Exit"); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2730 | return 0; |
| 2731 | } |
| 2732 | |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2733 | /* Tear down the qaf extension. */ |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2734 | void audio_extn_qaf_deinit() |
| 2735 | { |
Harsh Bansal | 28718c5 | 2017-04-20 13:47:12 +0530 | [diff] [blame] | 2736 | int i; |
| 2737 | DEBUG_MSG("Entry"); |
| 2738 | |
| 2739 | if (p_qaf != NULL) { |
| 2740 | for (i = 0; i < MAX_MM_MODULE_TYPE; i++) { |
| 2741 | qaf_session_close(&p_qaf->qaf_mod[i]); |
| 2742 | |
| 2743 | if (p_qaf->qaf_mod[i].qaf_lib != NULL) { |
| 2744 | dlclose(p_qaf->qaf_mod[i].qaf_lib); |
| 2745 | p_qaf->qaf_mod[i].qaf_lib = NULL; |
| 2746 | } |
| 2747 | } |
| 2748 | if (p_qaf->passthrough_out) { |
| 2749 | adev_close_output_stream((struct audio_hw_device *)p_qaf->adev, |
| 2750 | (struct audio_stream_out *)(p_qaf->passthrough_out)); |
| 2751 | p_qaf->passthrough_out = NULL; |
| 2752 | } |
| 2753 | |
| 2754 | pthread_mutex_destroy(&p_qaf->lock); |
| 2755 | free(p_qaf); |
| 2756 | p_qaf = NULL; |
| 2757 | } |
| 2758 | DEBUG_MSG("Exit"); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 2759 | } |