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