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