Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1 | /* |
vivek mehta | a51fd40 | 2016-02-04 19:49:33 -0800 | [diff] [blame] | 2 | * Copyright (C) 2013-2016 The Android Open Source Project |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "audio_hw_primary" |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 18 | #define ATRACE_TAG ATRACE_TAG_AUDIO |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 19 | /*#define LOG_NDEBUG 0*/ |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 20 | /*#define VERY_VERY_VERBOSE_LOGGING*/ |
| 21 | #ifdef VERY_VERY_VERBOSE_LOGGING |
| 22 | #define ALOGVV ALOGV |
| 23 | #else |
| 24 | #define ALOGVV(a...) do { } while(0) |
| 25 | #endif |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 26 | |
| 27 | #include <errno.h> |
| 28 | #include <pthread.h> |
| 29 | #include <stdint.h> |
| 30 | #include <sys/time.h> |
| 31 | #include <stdlib.h> |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 32 | #include <math.h> |
Eric Laurent | c4aef75 | 2013-09-12 17:45:53 -0700 | [diff] [blame] | 33 | #include <dlfcn.h> |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 34 | #include <sys/resource.h> |
| 35 | #include <sys/prctl.h> |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 36 | |
| 37 | #include <cutils/log.h> |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 38 | #include <cutils/trace.h> |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 39 | #include <cutils/str_parms.h> |
| 40 | #include <cutils/properties.h> |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 41 | #include <cutils/atomic.h> |
| 42 | #include <cutils/sched_policy.h> |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 43 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 44 | #include <hardware/audio_effect.h> |
Andy Hung | 31aca91 | 2014-03-20 17:14:59 -0700 | [diff] [blame] | 45 | #include <hardware/audio_alsaops.h> |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 46 | #include <system/thread_defs.h> |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 47 | #include <audio_effects/effect_aec.h> |
| 48 | #include <audio_effects/effect_ns.h> |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 49 | #include "audio_hw.h" |
Ravi Kumar Alamanda | 8e6e98f | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 50 | #include "audio_extn.h" |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 51 | #include "platform_api.h" |
| 52 | #include <platform.h> |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 53 | #include "voice_extn.h" |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 54 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 55 | #include "sound/compress_params.h" |
| 56 | |
Eric Laurent | 397db57 | 2016-05-11 11:31:47 -0700 | [diff] [blame] | 57 | /* COMPRESS_OFFLOAD_FRAGMENT_SIZE must be more than 8KB and a multiple of 32KB if more than 32KB. |
| 58 | * COMPRESS_OFFLOAD_FRAGMENT_SIZE * COMPRESS_OFFLOAD_NUM_FRAGMENTS must be less than 8MB. */ |
Marco Nelissen | 32093f5 | 2015-04-08 15:14:02 -0700 | [diff] [blame] | 59 | #define COMPRESS_OFFLOAD_FRAGMENT_SIZE (256 * 1024) |
Marco Nelissen | 94c33a0 | 2015-05-12 09:11:34 -0700 | [diff] [blame] | 60 | // 2 buffers causes problems with high bitrate files |
| 61 | #define COMPRESS_OFFLOAD_NUM_FRAGMENTS 3 |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 62 | /* ToDo: Check and update a proper value in msec */ |
| 63 | #define COMPRESS_OFFLOAD_PLAYBACK_LATENCY 96 |
| 64 | #define COMPRESS_PLAYBACK_VOLUME_MAX 0x2000 |
| 65 | |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 66 | #define PROXY_OPEN_RETRY_COUNT 100 |
| 67 | #define PROXY_OPEN_WAIT_TIME 20 |
| 68 | |
vivek mehta | dae4471 | 2015-07-27 14:13:18 -0700 | [diff] [blame] | 69 | #define MIN_CHANNEL_COUNT 1 |
| 70 | #define DEFAULT_CHANNEL_COUNT 2 |
| 71 | |
Jean-Michel Trivi | c075069 | 2015-10-12 12:12:32 -0700 | [diff] [blame] | 72 | #ifndef MAX_TARGET_SPECIFIC_CHANNEL_CNT |
| 73 | #define MAX_CHANNEL_COUNT 1 |
| 74 | #else |
vivek mehta | dae4471 | 2015-07-27 14:13:18 -0700 | [diff] [blame] | 75 | #define MAX_CHANNEL_COUNT atoi(XSTR(MAX_TARGET_SPECIFIC_CHANNEL_CNT)) |
| 76 | #define XSTR(x) STR(x) |
| 77 | #define STR(x) #x |
Jean-Michel Trivi | c075069 | 2015-10-12 12:12:32 -0700 | [diff] [blame] | 78 | #endif |
vivek mehta | dae4471 | 2015-07-27 14:13:18 -0700 | [diff] [blame] | 79 | |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 80 | #define ULL_PERIOD_SIZE (DEFAULT_OUTPUT_SAMPLING_RATE/1000) |
| 81 | |
Glenn Kasten | 4f99339 | 2014-05-14 07:30:48 -0700 | [diff] [blame] | 82 | static unsigned int configured_low_latency_capture_period_size = |
| 83 | LOW_LATENCY_CAPTURE_PERIOD_SIZE; |
| 84 | |
Andy Hung | 31aca91 | 2014-03-20 17:14:59 -0700 | [diff] [blame] | 85 | /* This constant enables extended precision handling. |
| 86 | * TODO The flag is off until more testing is done. |
| 87 | */ |
| 88 | static const bool k_enable_extended_precision = false; |
| 89 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 90 | struct pcm_config pcm_config_deep_buffer = { |
vivek mehta | dae4471 | 2015-07-27 14:13:18 -0700 | [diff] [blame] | 91 | .channels = DEFAULT_CHANNEL_COUNT, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 92 | .rate = DEFAULT_OUTPUT_SAMPLING_RATE, |
| 93 | .period_size = DEEP_BUFFER_OUTPUT_PERIOD_SIZE, |
| 94 | .period_count = DEEP_BUFFER_OUTPUT_PERIOD_COUNT, |
| 95 | .format = PCM_FORMAT_S16_LE, |
| 96 | .start_threshold = DEEP_BUFFER_OUTPUT_PERIOD_SIZE / 4, |
| 97 | .stop_threshold = INT_MAX, |
| 98 | .avail_min = DEEP_BUFFER_OUTPUT_PERIOD_SIZE / 4, |
| 99 | }; |
| 100 | |
| 101 | struct pcm_config pcm_config_low_latency = { |
vivek mehta | dae4471 | 2015-07-27 14:13:18 -0700 | [diff] [blame] | 102 | .channels = DEFAULT_CHANNEL_COUNT, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 103 | .rate = DEFAULT_OUTPUT_SAMPLING_RATE, |
| 104 | .period_size = LOW_LATENCY_OUTPUT_PERIOD_SIZE, |
| 105 | .period_count = LOW_LATENCY_OUTPUT_PERIOD_COUNT, |
| 106 | .format = PCM_FORMAT_S16_LE, |
| 107 | .start_threshold = LOW_LATENCY_OUTPUT_PERIOD_SIZE / 4, |
| 108 | .stop_threshold = INT_MAX, |
| 109 | .avail_min = LOW_LATENCY_OUTPUT_PERIOD_SIZE / 4, |
| 110 | }; |
| 111 | |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 112 | static int af_period_multiplier = 4; |
| 113 | struct pcm_config pcm_config_rt = { |
| 114 | .channels = DEFAULT_CHANNEL_COUNT, |
| 115 | .rate = DEFAULT_OUTPUT_SAMPLING_RATE, |
| 116 | .period_size = ULL_PERIOD_SIZE, //1 ms |
| 117 | .period_count = 512, //=> buffer size is 512ms |
| 118 | .format = PCM_FORMAT_S16_LE, |
| 119 | .start_threshold = ULL_PERIOD_SIZE*8, //8ms |
| 120 | .stop_threshold = INT_MAX, |
| 121 | .silence_threshold = 0, |
| 122 | .silence_size = 0, |
| 123 | .avail_min = ULL_PERIOD_SIZE, //1 ms |
| 124 | }; |
| 125 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 126 | struct pcm_config pcm_config_hdmi_multi = { |
| 127 | .channels = HDMI_MULTI_DEFAULT_CHANNEL_COUNT, /* changed when the stream is opened */ |
| 128 | .rate = DEFAULT_OUTPUT_SAMPLING_RATE, /* changed when the stream is opened */ |
| 129 | .period_size = HDMI_MULTI_PERIOD_SIZE, |
| 130 | .period_count = HDMI_MULTI_PERIOD_COUNT, |
| 131 | .format = PCM_FORMAT_S16_LE, |
| 132 | .start_threshold = 0, |
| 133 | .stop_threshold = INT_MAX, |
| 134 | .avail_min = 0, |
| 135 | }; |
| 136 | |
| 137 | struct pcm_config pcm_config_audio_capture = { |
vivek mehta | dae4471 | 2015-07-27 14:13:18 -0700 | [diff] [blame] | 138 | .channels = DEFAULT_CHANNEL_COUNT, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 139 | .period_count = AUDIO_CAPTURE_PERIOD_COUNT, |
| 140 | .format = PCM_FORMAT_S16_LE, |
Eric Laurent | e2d2d1d | 2015-07-06 17:54:15 -0700 | [diff] [blame] | 141 | .stop_threshold = INT_MAX, |
| 142 | .avail_min = 0, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 143 | }; |
| 144 | |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 145 | struct pcm_config pcm_config_audio_capture_rt = { |
| 146 | .channels = DEFAULT_CHANNEL_COUNT, |
| 147 | .rate = DEFAULT_OUTPUT_SAMPLING_RATE, |
| 148 | .period_size = ULL_PERIOD_SIZE, |
| 149 | .period_count = 512, |
| 150 | .format = PCM_FORMAT_S16_LE, |
| 151 | .start_threshold = 0, |
| 152 | .stop_threshold = INT_MAX, |
| 153 | .silence_threshold = 0, |
| 154 | .silence_size = 0, |
| 155 | .avail_min = ULL_PERIOD_SIZE, //1 ms |
| 156 | }; |
| 157 | |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 158 | #define AFE_PROXY_CHANNEL_COUNT 2 |
| 159 | #define AFE_PROXY_SAMPLING_RATE 48000 |
| 160 | |
| 161 | #define AFE_PROXY_PLAYBACK_PERIOD_SIZE 768 |
| 162 | #define AFE_PROXY_PLAYBACK_PERIOD_COUNT 4 |
| 163 | |
| 164 | struct pcm_config pcm_config_afe_proxy_playback = { |
| 165 | .channels = AFE_PROXY_CHANNEL_COUNT, |
| 166 | .rate = AFE_PROXY_SAMPLING_RATE, |
| 167 | .period_size = AFE_PROXY_PLAYBACK_PERIOD_SIZE, |
| 168 | .period_count = AFE_PROXY_PLAYBACK_PERIOD_COUNT, |
| 169 | .format = PCM_FORMAT_S16_LE, |
| 170 | .start_threshold = AFE_PROXY_PLAYBACK_PERIOD_SIZE, |
| 171 | .stop_threshold = INT_MAX, |
| 172 | .avail_min = AFE_PROXY_PLAYBACK_PERIOD_SIZE, |
| 173 | }; |
| 174 | |
| 175 | #define AFE_PROXY_RECORD_PERIOD_SIZE 768 |
| 176 | #define AFE_PROXY_RECORD_PERIOD_COUNT 4 |
| 177 | |
| 178 | struct pcm_config pcm_config_afe_proxy_record = { |
| 179 | .channels = AFE_PROXY_CHANNEL_COUNT, |
| 180 | .rate = AFE_PROXY_SAMPLING_RATE, |
| 181 | .period_size = AFE_PROXY_RECORD_PERIOD_SIZE, |
| 182 | .period_count = AFE_PROXY_RECORD_PERIOD_COUNT, |
| 183 | .format = PCM_FORMAT_S16_LE, |
| 184 | .start_threshold = AFE_PROXY_RECORD_PERIOD_SIZE, |
| 185 | .stop_threshold = INT_MAX, |
| 186 | .avail_min = AFE_PROXY_RECORD_PERIOD_SIZE, |
| 187 | }; |
| 188 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 189 | const char * const use_case_table[AUDIO_USECASE_MAX] = { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 190 | [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = "deep-buffer-playback", |
| 191 | [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = "low-latency-playback", |
| 192 | [USECASE_AUDIO_PLAYBACK_MULTI_CH] = "multi-channel-playback", |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 193 | [USECASE_AUDIO_PLAYBACK_OFFLOAD] = "compress-offload-playback", |
Ravi Kumar Alamanda | f78a4d9 | 2015-04-24 15:18:23 -0700 | [diff] [blame] | 194 | [USECASE_AUDIO_PLAYBACK_TTS] = "audio-tts-playback", |
Ravi Kumar Alamanda | 2bc7b02 | 2015-06-25 20:08:01 -0700 | [diff] [blame] | 195 | [USECASE_AUDIO_PLAYBACK_ULL] = "audio-ull-playback", |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 196 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 197 | [USECASE_AUDIO_RECORD] = "audio-record", |
| 198 | [USECASE_AUDIO_RECORD_LOW_LATENCY] = "low-latency-record", |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 199 | |
Ravi Kumar Alamanda | 8e6e98f | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 200 | [USECASE_AUDIO_HFP_SCO] = "hfp-sco", |
| 201 | [USECASE_AUDIO_HFP_SCO_WB] = "hfp-sco-wb", |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 202 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 203 | [USECASE_VOICE_CALL] = "voice-call", |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 204 | [USECASE_VOICE2_CALL] = "voice2-call", |
| 205 | [USECASE_VOLTE_CALL] = "volte-call", |
| 206 | [USECASE_QCHAT_CALL] = "qchat-call", |
| 207 | [USECASE_VOWLAN_CALL] = "vowlan-call", |
vivek mehta | a51fd40 | 2016-02-04 19:49:33 -0800 | [diff] [blame] | 208 | [USECASE_VOICEMMODE1_CALL] = "voicemmode1-call", |
| 209 | [USECASE_VOICEMMODE2_CALL] = "voicemmode2-call", |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 210 | |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 211 | [USECASE_AUDIO_SPKR_CALIB_RX] = "spkr-rx-calib", |
| 212 | [USECASE_AUDIO_SPKR_CALIB_TX] = "spkr-vi-record", |
| 213 | |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 214 | [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = "afe-proxy-playback", |
| 215 | [USECASE_AUDIO_RECORD_AFE_PROXY] = "afe-proxy-record", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 216 | }; |
| 217 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 218 | |
| 219 | #define STRING_TO_ENUM(string) { #string, string } |
| 220 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 221 | struct string_to_enum { |
| 222 | const char *name; |
| 223 | uint32_t value; |
| 224 | }; |
| 225 | |
| 226 | static const struct string_to_enum out_channels_name_to_enum_table[] = { |
| 227 | STRING_TO_ENUM(AUDIO_CHANNEL_OUT_STEREO), |
| 228 | STRING_TO_ENUM(AUDIO_CHANNEL_OUT_5POINT1), |
| 229 | STRING_TO_ENUM(AUDIO_CHANNEL_OUT_7POINT1), |
| 230 | }; |
| 231 | |
Haynes Mathew George | 5191a85 | 2013-09-11 14:19:36 -0700 | [diff] [blame] | 232 | static int set_voice_volume_l(struct audio_device *adev, float volume); |
vivek mehta | 1a9b7c0 | 2015-06-25 11:49:38 -0700 | [diff] [blame] | 233 | static struct audio_device *adev = NULL; |
| 234 | static pthread_mutex_t adev_init_lock; |
| 235 | static unsigned int audio_device_ref_count; |
| 236 | |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 237 | static bool may_use_noirq_mode(struct audio_device *adev, audio_usecase_t uc_id, |
| 238 | int flags __unused) |
| 239 | { |
| 240 | int dir = 0; |
| 241 | switch (uc_id) { |
| 242 | case USECASE_AUDIO_RECORD_LOW_LATENCY: |
| 243 | dir = 1; |
| 244 | case USECASE_AUDIO_PLAYBACK_ULL: |
| 245 | break; |
| 246 | default: |
| 247 | return false; |
| 248 | } |
| 249 | |
| 250 | int dev_id = platform_get_pcm_device_id(uc_id, dir == 0 ? |
| 251 | PCM_PLAYBACK : PCM_CAPTURE); |
| 252 | if (adev->adm_is_noirq_avail) |
| 253 | return adev->adm_is_noirq_avail(adev->adm_data, |
| 254 | adev->snd_card, dev_id, dir); |
| 255 | return false; |
| 256 | } |
| 257 | |
| 258 | static void register_out_stream(struct stream_out *out) |
| 259 | { |
| 260 | struct audio_device *adev = out->dev; |
| 261 | if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) |
| 262 | return; |
| 263 | |
| 264 | if (!adev->adm_register_output_stream) |
| 265 | return; |
| 266 | |
| 267 | adev->adm_register_output_stream(adev->adm_data, |
| 268 | out->handle, |
| 269 | out->flags); |
| 270 | |
| 271 | if (!adev->adm_set_config) |
| 272 | return; |
| 273 | |
| 274 | if (out->realtime) { |
| 275 | adev->adm_set_config(adev->adm_data, |
| 276 | out->handle, |
| 277 | out->pcm, &out->config); |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | static void register_in_stream(struct stream_in *in) |
| 282 | { |
| 283 | struct audio_device *adev = in->dev; |
| 284 | if (!adev->adm_register_input_stream) |
| 285 | return; |
| 286 | |
| 287 | adev->adm_register_input_stream(adev->adm_data, |
| 288 | in->capture_handle, |
| 289 | in->flags); |
| 290 | |
| 291 | if (!adev->adm_set_config) |
| 292 | return; |
| 293 | |
| 294 | if (in->realtime) { |
| 295 | adev->adm_set_config(adev->adm_data, |
| 296 | in->capture_handle, |
| 297 | in->pcm, |
| 298 | &in->config); |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | static void request_out_focus(struct stream_out *out, long ns) |
| 303 | { |
| 304 | struct audio_device *adev = out->dev; |
| 305 | |
| 306 | if (out->routing_change) { |
| 307 | out->routing_change = false; |
| 308 | if (adev->adm_on_routing_change) |
| 309 | adev->adm_on_routing_change(adev->adm_data, out->handle); |
| 310 | } |
| 311 | |
| 312 | if (adev->adm_request_focus_v2) { |
| 313 | adev->adm_request_focus_v2(adev->adm_data, out->handle, ns); |
| 314 | } else if (adev->adm_request_focus) { |
| 315 | adev->adm_request_focus(adev->adm_data, out->handle); |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | static void request_in_focus(struct stream_in *in, long ns) |
| 320 | { |
| 321 | struct audio_device *adev = in->dev; |
| 322 | |
| 323 | if (in->routing_change) { |
| 324 | in->routing_change = false; |
| 325 | if (adev->adm_on_routing_change) |
| 326 | adev->adm_on_routing_change(adev->adm_data, in->capture_handle); |
| 327 | } |
| 328 | |
| 329 | if (adev->adm_request_focus_v2) { |
| 330 | adev->adm_request_focus_v2(adev->adm_data, in->capture_handle, ns); |
| 331 | } else if (adev->adm_request_focus) { |
| 332 | adev->adm_request_focus(adev->adm_data, in->capture_handle); |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | static void release_out_focus(struct stream_out *out, long ns __unused) |
| 337 | { |
| 338 | struct audio_device *adev = out->dev; |
| 339 | |
| 340 | if (adev->adm_abandon_focus) |
| 341 | adev->adm_abandon_focus(adev->adm_data, out->handle); |
| 342 | } |
| 343 | |
| 344 | static void release_in_focus(struct stream_in *in, long ns __unused) |
| 345 | { |
| 346 | struct audio_device *adev = in->dev; |
| 347 | if (adev->adm_abandon_focus) |
| 348 | adev->adm_abandon_focus(adev->adm_data, in->capture_handle); |
| 349 | } |
| 350 | |
Haynes Mathew George | c735fb0 | 2016-06-30 18:00:28 -0700 | [diff] [blame] | 351 | static int parse_snd_card_status(struct str_parms * parms, int * card, |
| 352 | card_status_t * status) |
| 353 | { |
| 354 | char value[32]={0}; |
| 355 | char state[32]={0}; |
| 356 | |
| 357 | int ret = str_parms_get_str(parms, "SND_CARD_STATUS", value, sizeof(value)); |
| 358 | |
| 359 | if (ret < 0) |
| 360 | return -1; |
| 361 | |
| 362 | // sscanf should be okay as value is of max length 32. |
| 363 | // same as sizeof state. |
| 364 | if (sscanf(value, "%d,%s", card, state) < 2) |
| 365 | return -1; |
| 366 | |
| 367 | *status = !strcmp(state, "ONLINE") ? CARD_STATUS_ONLINE : |
| 368 | CARD_STATUS_OFFLINE; |
| 369 | return 0; |
| 370 | } |
| 371 | |
vivek mehta | 1a9b7c0 | 2015-06-25 11:49:38 -0700 | [diff] [blame] | 372 | __attribute__ ((visibility ("default"))) |
| 373 | bool audio_hw_send_gain_dep_calibration(int level) { |
| 374 | bool ret_val = false; |
| 375 | ALOGV("%s: enter ... ", __func__); |
| 376 | |
| 377 | pthread_mutex_lock(&adev_init_lock); |
| 378 | |
| 379 | if (adev != NULL && adev->platform != NULL) { |
| 380 | pthread_mutex_lock(&adev->lock); |
| 381 | ret_val = platform_send_gain_dep_cal(adev->platform, level); |
| 382 | pthread_mutex_unlock(&adev->lock); |
| 383 | } else { |
| 384 | ALOGE("%s: %s is NULL", __func__, adev == NULL ? "adev" : "adev->platform"); |
| 385 | } |
| 386 | |
| 387 | pthread_mutex_unlock(&adev_init_lock); |
| 388 | |
| 389 | ALOGV("%s: exit with ret_val %d ", __func__, ret_val); |
| 390 | return ret_val; |
| 391 | } |
Haynes Mathew George | 5191a85 | 2013-09-11 14:19:36 -0700 | [diff] [blame] | 392 | |
vivek mehta | a8d7c92 | 2016-05-25 14:40:44 -0700 | [diff] [blame] | 393 | __attribute__ ((visibility ("default"))) |
| 394 | int audio_hw_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl, |
| 395 | int table_size) { |
| 396 | int ret_val = 0; |
| 397 | ALOGV("%s: enter ... ", __func__); |
| 398 | |
| 399 | pthread_mutex_lock(&adev_init_lock); |
| 400 | if (adev == NULL) { |
| 401 | ALOGW("%s: adev is NULL .... ", __func__); |
| 402 | goto done; |
| 403 | } |
| 404 | |
| 405 | pthread_mutex_lock(&adev->lock); |
| 406 | ret_val = platform_get_gain_level_mapping(mapping_tbl, table_size); |
| 407 | pthread_mutex_unlock(&adev->lock); |
| 408 | done: |
| 409 | pthread_mutex_unlock(&adev_init_lock); |
| 410 | ALOGV("%s: exit ... ", __func__); |
| 411 | return ret_val; |
| 412 | } |
| 413 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 414 | static bool is_supported_format(audio_format_t format) |
| 415 | { |
Eric Laurent | 8251ac8 | 2014-07-23 11:00:25 -0700 | [diff] [blame] | 416 | switch (format) { |
| 417 | case AUDIO_FORMAT_MP3: |
| 418 | case AUDIO_FORMAT_AAC_LC: |
| 419 | case AUDIO_FORMAT_AAC_HE_V1: |
| 420 | case AUDIO_FORMAT_AAC_HE_V2: |
| 421 | return true; |
| 422 | default: |
| 423 | break; |
| 424 | } |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 425 | return false; |
| 426 | } |
| 427 | |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 428 | static inline bool is_mmap_usecase(audio_usecase_t uc_id) |
| 429 | { |
| 430 | return (uc_id == USECASE_AUDIO_RECORD_AFE_PROXY) || |
| 431 | (uc_id == USECASE_AUDIO_PLAYBACK_AFE_PROXY); |
| 432 | } |
| 433 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 434 | static int get_snd_codec_id(audio_format_t format) |
| 435 | { |
| 436 | int id = 0; |
| 437 | |
Eric Laurent | 8251ac8 | 2014-07-23 11:00:25 -0700 | [diff] [blame] | 438 | switch (format & AUDIO_FORMAT_MAIN_MASK) { |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 439 | case AUDIO_FORMAT_MP3: |
| 440 | id = SND_AUDIOCODEC_MP3; |
| 441 | break; |
| 442 | case AUDIO_FORMAT_AAC: |
| 443 | id = SND_AUDIOCODEC_AAC; |
| 444 | break; |
| 445 | default: |
| 446 | ALOGE("%s: Unsupported audio format", __func__); |
| 447 | } |
| 448 | |
| 449 | return id; |
| 450 | } |
Ravi Kumar Alamanda | f996704 | 2013-02-14 19:35:14 -0800 | [diff] [blame] | 451 | |
Ravi Kumar Alamanda | 8e6e98f | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 452 | int enable_audio_route(struct audio_device *adev, |
| 453 | struct audio_usecase *usecase) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 454 | { |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 455 | snd_device_t snd_device; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 456 | char mixer_path[50]; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 457 | |
| 458 | if (usecase == NULL) |
| 459 | return -EINVAL; |
| 460 | |
| 461 | ALOGV("%s: enter: usecase(%d)", __func__, usecase->id); |
| 462 | |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 463 | if (usecase->type == PCM_CAPTURE) |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 464 | snd_device = usecase->in_snd_device; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 465 | else |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 466 | snd_device = usecase->out_snd_device; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 467 | |
| 468 | strcpy(mixer_path, use_case_table[usecase->id]); |
Ravi Kumar Alamanda | 299760a | 2013-11-01 17:29:09 -0500 | [diff] [blame] | 469 | platform_add_backend_name(adev->platform, mixer_path, snd_device); |
Eric Laurent | 2e140aa | 2016-06-30 17:14:46 -0700 | [diff] [blame] | 470 | ALOGD("%s: usecase(%d) apply and update mixer path: %s", __func__, usecase->id, mixer_path); |
Ravi Kumar Alamanda | c38e452 | 2014-04-14 11:46:35 -0700 | [diff] [blame] | 471 | audio_route_apply_and_update_path(adev->audio_route, mixer_path); |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 472 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 473 | ALOGV("%s: exit", __func__); |
| 474 | return 0; |
| 475 | } |
| 476 | |
Ravi Kumar Alamanda | 8e6e98f | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 477 | int disable_audio_route(struct audio_device *adev, |
| 478 | struct audio_usecase *usecase) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 479 | { |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 480 | snd_device_t snd_device; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 481 | char mixer_path[50]; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 482 | |
| 483 | if (usecase == NULL) |
| 484 | return -EINVAL; |
| 485 | |
| 486 | ALOGV("%s: enter: usecase(%d)", __func__, usecase->id); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 487 | if (usecase->type == PCM_CAPTURE) |
| 488 | snd_device = usecase->in_snd_device; |
| 489 | else |
| 490 | snd_device = usecase->out_snd_device; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 491 | strcpy(mixer_path, use_case_table[usecase->id]); |
Ravi Kumar Alamanda | 299760a | 2013-11-01 17:29:09 -0500 | [diff] [blame] | 492 | platform_add_backend_name(adev->platform, mixer_path, snd_device); |
Eric Laurent | 2e140aa | 2016-06-30 17:14:46 -0700 | [diff] [blame] | 493 | ALOGD("%s: usecase(%d) reset and update mixer path: %s", __func__, usecase->id, mixer_path); |
Ravi Kumar Alamanda | c38e452 | 2014-04-14 11:46:35 -0700 | [diff] [blame] | 494 | audio_route_reset_and_update_path(adev->audio_route, mixer_path); |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 495 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 496 | ALOGV("%s: exit", __func__); |
| 497 | return 0; |
| 498 | } |
| 499 | |
Ravi Kumar Alamanda | 8e6e98f | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 500 | int enable_snd_device(struct audio_device *adev, |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 501 | snd_device_t snd_device) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 502 | { |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 503 | int i, num_devices = 0; |
| 504 | snd_device_t new_snd_devices[2]; |
vivek mehta | de4849c | 2016-03-03 17:23:38 -0800 | [diff] [blame] | 505 | int ret_val = -EINVAL; |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 506 | if (snd_device < SND_DEVICE_MIN || |
| 507 | snd_device >= SND_DEVICE_MAX) { |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 508 | ALOGE("%s: Invalid sound device %d", __func__, snd_device); |
vivek mehta | de4849c | 2016-03-03 17:23:38 -0800 | [diff] [blame] | 509 | goto on_error; |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 510 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 511 | |
Ravi Kumar Alamanda | 5a95ff6 | 2015-08-31 17:42:44 -0700 | [diff] [blame] | 512 | platform_send_audio_calibration(adev->platform, snd_device); |
| 513 | |
vivek mehta | de4849c | 2016-03-03 17:23:38 -0800 | [diff] [blame] | 514 | if (adev->snd_dev_ref_cnt[snd_device] >= 1) { |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 515 | ALOGV("%s: snd_device(%d: %s) is already active", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 516 | __func__, snd_device, platform_get_snd_device_name(snd_device)); |
vivek mehta | de4849c | 2016-03-03 17:23:38 -0800 | [diff] [blame] | 517 | goto on_success; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 518 | } |
| 519 | |
Ravi Kumar Alamanda | a417cc5 | 2015-05-01 16:41:56 -0700 | [diff] [blame] | 520 | /* due to the possibility of calibration overwrite between listen |
| 521 | and audio, notify sound trigger hal before audio calibration is sent */ |
| 522 | audio_extn_sound_trigger_update_device_status(snd_device, |
| 523 | ST_EVENT_SND_DEVICE_BUSY); |
| 524 | |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 525 | if (audio_extn_spkr_prot_is_enabled()) |
| 526 | audio_extn_spkr_prot_calib_cancel(adev); |
| 527 | |
zhaoyang yin | 4211fad | 2015-06-04 21:13:25 +0800 | [diff] [blame] | 528 | audio_extn_dsm_feedback_enable(adev, snd_device, true); |
| 529 | |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 530 | if ((snd_device == SND_DEVICE_OUT_SPEAKER || |
| 531 | snd_device == SND_DEVICE_OUT_VOICE_SPEAKER) && |
| 532 | audio_extn_spkr_prot_is_enabled()) { |
| 533 | if (audio_extn_spkr_prot_get_acdb_id(snd_device) < 0) { |
vivek mehta | de4849c | 2016-03-03 17:23:38 -0800 | [diff] [blame] | 534 | goto on_error; |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 535 | } |
| 536 | if (audio_extn_spkr_prot_start_processing(snd_device)) { |
| 537 | ALOGE("%s: spkr_start_processing failed", __func__); |
vivek mehta | de4849c | 2016-03-03 17:23:38 -0800 | [diff] [blame] | 538 | goto on_error; |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 539 | } |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 540 | } else if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices)) { |
| 541 | for (i = 0; i < num_devices; i++) { |
| 542 | enable_snd_device(adev, new_snd_devices[i]); |
| 543 | } |
vivek mehta | b650641 | 2015-08-07 16:55:17 -0700 | [diff] [blame] | 544 | platform_set_speaker_gain_in_combo(adev, snd_device, true); |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 545 | } else { |
vivek mehta | de4849c | 2016-03-03 17:23:38 -0800 | [diff] [blame] | 546 | char device_name[DEVICE_NAME_MAX_SIZE] = {0}; |
| 547 | if (platform_get_snd_device_name_extn(adev->platform, snd_device, device_name) < 0 ) { |
| 548 | ALOGE(" %s: Invalid sound device returned", __func__); |
| 549 | goto on_error; |
| 550 | } |
Ed Tam | 70b5c14 | 2016-03-21 19:14:29 -0700 | [diff] [blame] | 551 | |
Eric Laurent | 2e140aa | 2016-06-30 17:14:46 -0700 | [diff] [blame] | 552 | ALOGD("%s: snd_device(%d: %s)", __func__, snd_device, device_name); |
vivek mehta | de4849c | 2016-03-03 17:23:38 -0800 | [diff] [blame] | 553 | audio_route_apply_and_update_path(adev->audio_route, device_name); |
| 554 | } |
| 555 | on_success: |
| 556 | adev->snd_dev_ref_cnt[snd_device]++; |
| 557 | ret_val = 0; |
| 558 | on_error: |
| 559 | return ret_val; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 560 | } |
| 561 | |
Ravi Kumar Alamanda | 8e6e98f | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 562 | int disable_snd_device(struct audio_device *adev, |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 563 | snd_device_t snd_device) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 564 | { |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 565 | int i, num_devices = 0; |
| 566 | snd_device_t new_snd_devices[2]; |
| 567 | |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 568 | if (snd_device < SND_DEVICE_MIN || |
| 569 | snd_device >= SND_DEVICE_MAX) { |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 570 | ALOGE("%s: Invalid sound device %d", __func__, snd_device); |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 571 | return -EINVAL; |
| 572 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 573 | if (adev->snd_dev_ref_cnt[snd_device] <= 0) { |
| 574 | ALOGE("%s: device ref cnt is already 0", __func__); |
| 575 | return -EINVAL; |
| 576 | } |
| 577 | adev->snd_dev_ref_cnt[snd_device]--; |
| 578 | if (adev->snd_dev_ref_cnt[snd_device] == 0) { |
zhaoyang yin | 4211fad | 2015-06-04 21:13:25 +0800 | [diff] [blame] | 579 | audio_extn_dsm_feedback_enable(adev, snd_device, false); |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 580 | if ((snd_device == SND_DEVICE_OUT_SPEAKER || |
| 581 | snd_device == SND_DEVICE_OUT_VOICE_SPEAKER) && |
| 582 | audio_extn_spkr_prot_is_enabled()) { |
| 583 | audio_extn_spkr_prot_stop_processing(snd_device); |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 584 | } else if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices)) { |
| 585 | for (i = 0; i < num_devices; i++) { |
| 586 | disable_snd_device(adev, new_snd_devices[i]); |
| 587 | } |
vivek mehta | b650641 | 2015-08-07 16:55:17 -0700 | [diff] [blame] | 588 | platform_set_speaker_gain_in_combo(adev, snd_device, false); |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 589 | } else { |
vivek mehta | de4849c | 2016-03-03 17:23:38 -0800 | [diff] [blame] | 590 | char device_name[DEVICE_NAME_MAX_SIZE] = {0}; |
| 591 | if (platform_get_snd_device_name_extn(adev->platform, snd_device, device_name) < 0 ) { |
| 592 | ALOGE(" %s: Invalid sound device returned", __func__); |
| 593 | return -EINVAL; |
| 594 | } |
| 595 | |
Eric Laurent | 2e140aa | 2016-06-30 17:14:46 -0700 | [diff] [blame] | 596 | ALOGD("%s: snd_device(%d: %s)", __func__, snd_device, device_name); |
vivek mehta | de4849c | 2016-03-03 17:23:38 -0800 | [diff] [blame] | 597 | audio_route_reset_and_update_path(adev->audio_route, device_name); |
Ravi Kumar Alamanda | 6386300 | 2015-04-22 11:15:25 -0700 | [diff] [blame] | 598 | } |
Ravi Kumar Alamanda | a417cc5 | 2015-05-01 16:41:56 -0700 | [diff] [blame] | 599 | audio_extn_sound_trigger_update_device_status(snd_device, |
| 600 | ST_EVENT_SND_DEVICE_FREE); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 601 | } |
vivek mehta | b650641 | 2015-08-07 16:55:17 -0700 | [diff] [blame] | 602 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 603 | return 0; |
| 604 | } |
| 605 | |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 606 | static void check_and_route_playback_usecases(struct audio_device *adev, |
| 607 | struct audio_usecase *uc_info, |
| 608 | snd_device_t snd_device) |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 609 | { |
| 610 | struct listnode *node; |
| 611 | struct audio_usecase *usecase; |
| 612 | bool switch_device[AUDIO_USECASE_MAX]; |
| 613 | int i, num_uc_to_switch = 0; |
| 614 | |
| 615 | /* |
| 616 | * This function is to make sure that all the usecases that are active on |
| 617 | * the hardware codec backend are always routed to any one device that is |
| 618 | * handled by the hardware codec. |
| 619 | * For example, if low-latency and deep-buffer usecases are currently active |
| 620 | * on speaker and out_set_parameters(headset) is received on low-latency |
| 621 | * output, then we have to make sure deep-buffer is also switched to headset, |
| 622 | * because of the limitation that both the devices cannot be enabled |
| 623 | * at the same time as they share the same backend. |
| 624 | */ |
| 625 | /* Disable all the usecases on the shared backend other than the |
| 626 | specified usecase */ |
| 627 | for (i = 0; i < AUDIO_USECASE_MAX; i++) |
| 628 | switch_device[i] = false; |
| 629 | |
| 630 | list_for_each(node, &adev->usecase_list) { |
| 631 | usecase = node_to_item(node, struct audio_usecase, list); |
| 632 | if (usecase->type != PCM_CAPTURE && |
| 633 | usecase != uc_info && |
| 634 | usecase->out_snd_device != snd_device && |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 635 | usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND && |
| 636 | platform_check_backends_match(snd_device, usecase->out_snd_device)) { |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 637 | ALOGV("%s: Usecase (%s) is active on (%s) - disabling ..", |
| 638 | __func__, use_case_table[usecase->id], |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 639 | platform_get_snd_device_name(usecase->out_snd_device)); |
Ravi Kumar Alamanda | c38e452 | 2014-04-14 11:46:35 -0700 | [diff] [blame] | 640 | disable_audio_route(adev, usecase); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 641 | switch_device[usecase->id] = true; |
| 642 | num_uc_to_switch++; |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | if (num_uc_to_switch) { |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 647 | list_for_each(node, &adev->usecase_list) { |
| 648 | usecase = node_to_item(node, struct audio_usecase, list); |
| 649 | if (switch_device[usecase->id]) { |
Ravi Kumar Alamanda | c38e452 | 2014-04-14 11:46:35 -0700 | [diff] [blame] | 650 | disable_snd_device(adev, usecase->out_snd_device); |
sangwon.jeon | 866d5ff | 2013-10-17 21:42:50 +0900 | [diff] [blame] | 651 | } |
| 652 | } |
| 653 | |
| 654 | list_for_each(node, &adev->usecase_list) { |
| 655 | usecase = node_to_item(node, struct audio_usecase, list); |
| 656 | if (switch_device[usecase->id]) { |
Ravi Kumar Alamanda | c38e452 | 2014-04-14 11:46:35 -0700 | [diff] [blame] | 657 | enable_snd_device(adev, snd_device); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 658 | } |
| 659 | } |
| 660 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 661 | /* Re-route all the usecases on the shared backend other than the |
| 662 | specified usecase to new snd devices */ |
| 663 | list_for_each(node, &adev->usecase_list) { |
| 664 | usecase = node_to_item(node, struct audio_usecase, list); |
| 665 | /* Update the out_snd_device only before enabling the audio route */ |
| 666 | if (switch_device[usecase->id] ) { |
| 667 | usecase->out_snd_device = snd_device; |
Ravi Kumar Alamanda | c38e452 | 2014-04-14 11:46:35 -0700 | [diff] [blame] | 668 | enable_audio_route(adev, usecase); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 669 | } |
| 670 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 671 | } |
| 672 | } |
| 673 | |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 674 | static void check_and_route_capture_usecases(struct audio_device *adev, |
| 675 | struct audio_usecase *uc_info, |
| 676 | snd_device_t snd_device) |
| 677 | { |
| 678 | struct listnode *node; |
| 679 | struct audio_usecase *usecase; |
| 680 | bool switch_device[AUDIO_USECASE_MAX]; |
| 681 | int i, num_uc_to_switch = 0; |
| 682 | |
vivek mehta | 4ed66e6 | 2016-04-15 23:33:34 -0700 | [diff] [blame] | 683 | platform_check_and_set_capture_backend_cfg(adev, uc_info, snd_device); |
| 684 | |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 685 | /* |
| 686 | * This function is to make sure that all the active capture usecases |
| 687 | * are always routed to the same input sound device. |
| 688 | * For example, if audio-record and voice-call usecases are currently |
| 689 | * active on speaker(rx) and speaker-mic (tx) and out_set_parameters(earpiece) |
| 690 | * is received for voice call then we have to make sure that audio-record |
| 691 | * usecase is also switched to earpiece i.e. voice-dmic-ef, |
| 692 | * because of the limitation that two devices cannot be enabled |
| 693 | * at the same time if they share the same backend. |
| 694 | */ |
| 695 | for (i = 0; i < AUDIO_USECASE_MAX; i++) |
| 696 | switch_device[i] = false; |
| 697 | |
| 698 | list_for_each(node, &adev->usecase_list) { |
| 699 | usecase = node_to_item(node, struct audio_usecase, list); |
| 700 | if (usecase->type != PCM_PLAYBACK && |
| 701 | usecase != uc_info && |
Anish Kumar | ff86471 | 2015-06-03 13:35:11 -0700 | [diff] [blame] | 702 | usecase->in_snd_device != snd_device && |
| 703 | (usecase->id != USECASE_AUDIO_SPKR_CALIB_TX)) { |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 704 | ALOGV("%s: Usecase (%s) is active on (%s) - disabling ..", |
| 705 | __func__, use_case_table[usecase->id], |
Devin Kim | 1e5f353 | 2013-08-09 07:48:29 -0700 | [diff] [blame] | 706 | platform_get_snd_device_name(usecase->in_snd_device)); |
Ravi Kumar Alamanda | c38e452 | 2014-04-14 11:46:35 -0700 | [diff] [blame] | 707 | disable_audio_route(adev, usecase); |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 708 | switch_device[usecase->id] = true; |
| 709 | num_uc_to_switch++; |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | if (num_uc_to_switch) { |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 714 | list_for_each(node, &adev->usecase_list) { |
| 715 | usecase = node_to_item(node, struct audio_usecase, list); |
| 716 | if (switch_device[usecase->id]) { |
Ravi Kumar Alamanda | c38e452 | 2014-04-14 11:46:35 -0700 | [diff] [blame] | 717 | disable_snd_device(adev, usecase->in_snd_device); |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 718 | } |
| 719 | } |
| 720 | |
| 721 | list_for_each(node, &adev->usecase_list) { |
| 722 | usecase = node_to_item(node, struct audio_usecase, list); |
| 723 | if (switch_device[usecase->id]) { |
Ravi Kumar Alamanda | c38e452 | 2014-04-14 11:46:35 -0700 | [diff] [blame] | 724 | enable_snd_device(adev, snd_device); |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 725 | } |
| 726 | } |
| 727 | |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 728 | /* Re-route all the usecases on the shared backend other than the |
| 729 | specified usecase to new snd devices */ |
| 730 | list_for_each(node, &adev->usecase_list) { |
| 731 | usecase = node_to_item(node, struct audio_usecase, list); |
| 732 | /* Update the in_snd_device only before enabling the audio route */ |
| 733 | if (switch_device[usecase->id] ) { |
| 734 | usecase->in_snd_device = snd_device; |
Ravi Kumar Alamanda | c38e452 | 2014-04-14 11:46:35 -0700 | [diff] [blame] | 735 | enable_audio_route(adev, usecase); |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 736 | } |
| 737 | } |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 738 | } |
| 739 | } |
| 740 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 741 | /* must be called with hw device mutex locked */ |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 742 | static int read_hdmi_channel_masks(struct stream_out *out) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 743 | { |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 744 | int ret = 0; |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 745 | int channels = platform_edid_get_max_channels(out->dev->platform); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 746 | |
| 747 | switch (channels) { |
| 748 | /* |
| 749 | * Do not handle stereo output in Multi-channel cases |
| 750 | * Stereo case is handled in normal playback path |
| 751 | */ |
| 752 | case 6: |
| 753 | ALOGV("%s: HDMI supports 5.1", __func__); |
| 754 | out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_5POINT1; |
| 755 | break; |
| 756 | case 8: |
| 757 | ALOGV("%s: HDMI supports 5.1 and 7.1 channels", __func__); |
| 758 | out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_5POINT1; |
| 759 | out->supported_channel_masks[1] = AUDIO_CHANNEL_OUT_7POINT1; |
| 760 | break; |
| 761 | default: |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 762 | ALOGE("HDMI does not support multi channel playback"); |
| 763 | ret = -ENOSYS; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 764 | break; |
| 765 | } |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 766 | return ret; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 767 | } |
| 768 | |
Ravi Kumar Alamanda | a237ecc | 2014-07-24 17:27:05 -0700 | [diff] [blame] | 769 | static audio_usecase_t get_voice_usecase_id_from_list(struct audio_device *adev) |
| 770 | { |
| 771 | struct audio_usecase *usecase; |
| 772 | struct listnode *node; |
| 773 | |
| 774 | list_for_each(node, &adev->usecase_list) { |
| 775 | usecase = node_to_item(node, struct audio_usecase, list); |
| 776 | if (usecase->type == VOICE_CALL) { |
| 777 | ALOGV("%s: usecase id %d", __func__, usecase->id); |
| 778 | return usecase->id; |
| 779 | } |
| 780 | } |
| 781 | return USECASE_INVALID; |
| 782 | } |
| 783 | |
Ravi Kumar Alamanda | 8e6e98f | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 784 | struct audio_usecase *get_usecase_from_list(struct audio_device *adev, |
| 785 | audio_usecase_t uc_id) |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 786 | { |
| 787 | struct audio_usecase *usecase; |
| 788 | struct listnode *node; |
| 789 | |
| 790 | list_for_each(node, &adev->usecase_list) { |
| 791 | usecase = node_to_item(node, struct audio_usecase, list); |
| 792 | if (usecase->id == uc_id) |
| 793 | return usecase; |
| 794 | } |
| 795 | return NULL; |
| 796 | } |
| 797 | |
Ravi Kumar Alamanda | 8e6e98f | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 798 | int select_devices(struct audio_device *adev, |
| 799 | audio_usecase_t uc_id) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 800 | { |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 801 | snd_device_t out_snd_device = SND_DEVICE_NONE; |
| 802 | snd_device_t in_snd_device = SND_DEVICE_NONE; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 803 | struct audio_usecase *usecase = NULL; |
| 804 | struct audio_usecase *vc_usecase = NULL; |
Ravi Kumar Alamanda | 8e6e98f | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 805 | struct audio_usecase *hfp_usecase = NULL; |
| 806 | audio_usecase_t hfp_ucid; |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 807 | struct listnode *node; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 808 | int status = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 809 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 810 | usecase = get_usecase_from_list(adev, uc_id); |
| 811 | if (usecase == NULL) { |
| 812 | ALOGE("%s: Could not find the usecase(%d)", __func__, uc_id); |
| 813 | return -EINVAL; |
| 814 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 815 | |
Ravi Kumar Alamanda | 8e6e98f | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 816 | if ((usecase->type == VOICE_CALL) || |
| 817 | (usecase->type == PCM_HFP_CALL)) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 818 | out_snd_device = platform_get_output_snd_device(adev->platform, |
| 819 | usecase->stream.out->devices); |
| 820 | in_snd_device = platform_get_input_snd_device(adev->platform, usecase->stream.out->devices); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 821 | usecase->devices = usecase->stream.out->devices; |
| 822 | } else { |
| 823 | /* |
| 824 | * If the voice call is active, use the sound devices of voice call usecase |
| 825 | * so that it would not result any device switch. All the usecases will |
| 826 | * be switched to new device when select_devices() is called for voice call |
| 827 | * usecase. This is to avoid switching devices for voice call when |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 828 | * check_and_route_playback_usecases() is called below. |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 829 | */ |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 830 | if (voice_is_in_call(adev)) { |
Ravi Kumar Alamanda | a237ecc | 2014-07-24 17:27:05 -0700 | [diff] [blame] | 831 | vc_usecase = get_usecase_from_list(adev, |
| 832 | get_voice_usecase_id_from_list(adev)); |
| 833 | if ((vc_usecase != NULL) && |
| 834 | ((vc_usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) || |
| 835 | (usecase->devices == AUDIO_DEVICE_IN_VOICE_CALL))) { |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 836 | in_snd_device = vc_usecase->in_snd_device; |
| 837 | out_snd_device = vc_usecase->out_snd_device; |
| 838 | } |
Ravi Kumar Alamanda | 8e6e98f | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 839 | } else if (audio_extn_hfp_is_active(adev)) { |
| 840 | hfp_ucid = audio_extn_hfp_get_usecase(); |
| 841 | hfp_usecase = get_usecase_from_list(adev, hfp_ucid); |
| 842 | if (hfp_usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) { |
| 843 | in_snd_device = hfp_usecase->in_snd_device; |
| 844 | out_snd_device = hfp_usecase->out_snd_device; |
| 845 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 846 | } |
| 847 | if (usecase->type == PCM_PLAYBACK) { |
| 848 | usecase->devices = usecase->stream.out->devices; |
| 849 | in_snd_device = SND_DEVICE_NONE; |
Ravi Kumar Alamanda | 59d296d | 2013-05-02 11:25:27 -0700 | [diff] [blame] | 850 | if (out_snd_device == SND_DEVICE_NONE) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 851 | out_snd_device = platform_get_output_snd_device(adev->platform, |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 852 | usecase->stream.out->devices); |
Ravi Kumar Alamanda | 59d296d | 2013-05-02 11:25:27 -0700 | [diff] [blame] | 853 | if (usecase->stream.out == adev->primary_output && |
| 854 | adev->active_input && |
Eric Laurent | 50a38ed | 2015-10-14 18:48:06 -0700 | [diff] [blame] | 855 | (adev->active_input->source == AUDIO_SOURCE_VOICE_COMMUNICATION || |
| 856 | adev->mode == AUDIO_MODE_IN_COMMUNICATION) && |
Ravi Kumar Alamanda | f282901 | 2014-11-12 16:16:10 -0800 | [diff] [blame] | 857 | out_snd_device != usecase->out_snd_device) { |
Ravi Kumar Alamanda | 59d296d | 2013-05-02 11:25:27 -0700 | [diff] [blame] | 858 | select_devices(adev, adev->active_input->usecase); |
| 859 | } |
| 860 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 861 | } else if (usecase->type == PCM_CAPTURE) { |
| 862 | usecase->devices = usecase->stream.in->device; |
| 863 | out_snd_device = SND_DEVICE_NONE; |
Ravi Kumar Alamanda | 59d296d | 2013-05-02 11:25:27 -0700 | [diff] [blame] | 864 | if (in_snd_device == SND_DEVICE_NONE) { |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 865 | audio_devices_t out_device = AUDIO_DEVICE_NONE; |
Eric Laurent | 50a38ed | 2015-10-14 18:48:06 -0700 | [diff] [blame] | 866 | if (adev->active_input && |
| 867 | (adev->active_input->source == AUDIO_SOURCE_VOICE_COMMUNICATION || |
| 868 | adev->mode == AUDIO_MODE_IN_COMMUNICATION)) { |
Ravi Kumar Alamanda | f282901 | 2014-11-12 16:16:10 -0800 | [diff] [blame] | 869 | platform_set_echo_reference(adev, false, AUDIO_DEVICE_NONE); |
Ravi Kumar Alamanda | 0464359 | 2015-09-24 19:17:26 -0700 | [diff] [blame] | 870 | if (usecase->id == USECASE_AUDIO_RECORD_AFE_PROXY) { |
| 871 | out_device = AUDIO_DEVICE_OUT_TELEPHONY_TX; |
| 872 | } else if (adev->primary_output) { |
| 873 | out_device = adev->primary_output->devices; |
| 874 | } |
Ravi Kumar Alamanda | 59d296d | 2013-05-02 11:25:27 -0700 | [diff] [blame] | 875 | } |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 876 | in_snd_device = platform_get_input_snd_device(adev->platform, out_device); |
Ravi Kumar Alamanda | 59d296d | 2013-05-02 11:25:27 -0700 | [diff] [blame] | 877 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 878 | } |
| 879 | } |
| 880 | |
| 881 | if (out_snd_device == usecase->out_snd_device && |
| 882 | in_snd_device == usecase->in_snd_device) { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 883 | return 0; |
| 884 | } |
| 885 | |
Eric Laurent | 2bafff1 | 2016-03-17 12:17:23 -0700 | [diff] [blame] | 886 | if (out_snd_device != SND_DEVICE_NONE && |
| 887 | out_snd_device != adev->last_logged_snd_device[uc_id][0]) { |
| 888 | ALOGD("%s: changing use case %s output device from(%d: %s, acdb %d) to (%d: %s, acdb %d)", |
| 889 | __func__, |
| 890 | use_case_table[uc_id], |
| 891 | adev->last_logged_snd_device[uc_id][0], |
| 892 | platform_get_snd_device_name(adev->last_logged_snd_device[uc_id][0]), |
| 893 | adev->last_logged_snd_device[uc_id][0] != SND_DEVICE_NONE ? |
| 894 | platform_get_snd_device_acdb_id(adev->last_logged_snd_device[uc_id][0]) : |
| 895 | -1, |
| 896 | out_snd_device, |
| 897 | platform_get_snd_device_name(out_snd_device), |
| 898 | platform_get_snd_device_acdb_id(out_snd_device)); |
| 899 | adev->last_logged_snd_device[uc_id][0] = out_snd_device; |
| 900 | } |
| 901 | if (in_snd_device != SND_DEVICE_NONE && |
| 902 | in_snd_device != adev->last_logged_snd_device[uc_id][1]) { |
| 903 | ALOGD("%s: changing use case %s input device from(%d: %s, acdb %d) to (%d: %s, acdb %d)", |
| 904 | __func__, |
| 905 | use_case_table[uc_id], |
| 906 | adev->last_logged_snd_device[uc_id][1], |
| 907 | platform_get_snd_device_name(adev->last_logged_snd_device[uc_id][1]), |
| 908 | adev->last_logged_snd_device[uc_id][1] != SND_DEVICE_NONE ? |
| 909 | platform_get_snd_device_acdb_id(adev->last_logged_snd_device[uc_id][1]) : |
| 910 | -1, |
| 911 | in_snd_device, |
| 912 | platform_get_snd_device_name(in_snd_device), |
| 913 | platform_get_snd_device_acdb_id(in_snd_device)); |
| 914 | adev->last_logged_snd_device[uc_id][1] = in_snd_device; |
| 915 | } |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 916 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 917 | /* |
| 918 | * Limitation: While in call, to do a device switch we need to disable |
| 919 | * and enable both RX and TX devices though one of them is same as current |
| 920 | * device. |
| 921 | */ |
Ravi Kumar Alamanda | 36886fc | 2014-09-29 13:41:51 -0700 | [diff] [blame] | 922 | if ((usecase->type == VOICE_CALL) && |
| 923 | (usecase->in_snd_device != SND_DEVICE_NONE) && |
| 924 | (usecase->out_snd_device != SND_DEVICE_NONE)) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 925 | status = platform_switch_voice_call_device_pre(adev->platform); |
vivek mehta | 765eb64 | 2015-08-07 19:46:06 -0700 | [diff] [blame] | 926 | /* Disable sidetone only if voice call already exists */ |
| 927 | if (voice_is_call_state_active(adev)) |
| 928 | voice_set_sidetone(adev, usecase->out_snd_device, false); |
Ravi Kumar Alamanda | 610e8cc | 2013-02-12 01:42:38 -0800 | [diff] [blame] | 929 | } |
| 930 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 931 | /* Disable current sound devices */ |
| 932 | if (usecase->out_snd_device != SND_DEVICE_NONE) { |
Ravi Kumar Alamanda | c38e452 | 2014-04-14 11:46:35 -0700 | [diff] [blame] | 933 | disable_audio_route(adev, usecase); |
| 934 | disable_snd_device(adev, usecase->out_snd_device); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 935 | } |
| 936 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 937 | if (usecase->in_snd_device != SND_DEVICE_NONE) { |
Ravi Kumar Alamanda | c38e452 | 2014-04-14 11:46:35 -0700 | [diff] [blame] | 938 | disable_audio_route(adev, usecase); |
| 939 | disable_snd_device(adev, usecase->in_snd_device); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 940 | } |
| 941 | |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 942 | /* Applicable only on the targets that has external modem. |
| 943 | * New device information should be sent to modem before enabling |
| 944 | * the devices to reduce in-call device switch time. |
| 945 | */ |
Ravi Kumar Alamanda | 36886fc | 2014-09-29 13:41:51 -0700 | [diff] [blame] | 946 | if ((usecase->type == VOICE_CALL) && |
| 947 | (usecase->in_snd_device != SND_DEVICE_NONE) && |
| 948 | (usecase->out_snd_device != SND_DEVICE_NONE)) { |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 949 | status = platform_switch_voice_call_enable_device_config(adev->platform, |
| 950 | out_snd_device, |
| 951 | in_snd_device); |
Ravi Kumar Alamanda | 36886fc | 2014-09-29 13:41:51 -0700 | [diff] [blame] | 952 | } |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 953 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 954 | /* Enable new sound devices */ |
| 955 | if (out_snd_device != SND_DEVICE_NONE) { |
| 956 | if (usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 957 | check_and_route_playback_usecases(adev, usecase, out_snd_device); |
Ravi Kumar Alamanda | c38e452 | 2014-04-14 11:46:35 -0700 | [diff] [blame] | 958 | enable_snd_device(adev, out_snd_device); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 959 | } |
| 960 | |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 961 | if (in_snd_device != SND_DEVICE_NONE) { |
| 962 | check_and_route_capture_usecases(adev, usecase, in_snd_device); |
Ravi Kumar Alamanda | c38e452 | 2014-04-14 11:46:35 -0700 | [diff] [blame] | 963 | enable_snd_device(adev, in_snd_device); |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 964 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 965 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 966 | if (usecase->type == VOICE_CALL) |
| 967 | status = platform_switch_voice_call_device_post(adev->platform, |
| 968 | out_snd_device, |
| 969 | in_snd_device); |
Ravi Kumar Alamanda | 610e8cc | 2013-02-12 01:42:38 -0800 | [diff] [blame] | 970 | |
sangwoo | 170731f | 2013-06-08 15:36:36 +0900 | [diff] [blame] | 971 | usecase->in_snd_device = in_snd_device; |
| 972 | usecase->out_snd_device = out_snd_device; |
| 973 | |
Ravi Kumar Alamanda | c38e452 | 2014-04-14 11:46:35 -0700 | [diff] [blame] | 974 | enable_audio_route(adev, usecase); |
sangwoo | 170731f | 2013-06-08 15:36:36 +0900 | [diff] [blame] | 975 | |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 976 | /* Applicable only on the targets that has external modem. |
| 977 | * Enable device command should be sent to modem only after |
| 978 | * enabling voice call mixer controls |
| 979 | */ |
vivek mehta | 765eb64 | 2015-08-07 19:46:06 -0700 | [diff] [blame] | 980 | if (usecase->type == VOICE_CALL) { |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 981 | status = platform_switch_voice_call_usecase_route_post(adev->platform, |
| 982 | out_snd_device, |
| 983 | in_snd_device); |
vivek mehta | 765eb64 | 2015-08-07 19:46:06 -0700 | [diff] [blame] | 984 | /* Enable sidetone only if voice call already exists */ |
| 985 | if (voice_is_call_state_active(adev)) |
| 986 | voice_set_sidetone(adev, out_snd_device, true); |
| 987 | } |
Ravi Kumar Alamanda | 83281a9 | 2014-05-19 18:14:57 -0700 | [diff] [blame] | 988 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 989 | return status; |
| 990 | } |
| 991 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 992 | static int stop_input_stream(struct stream_in *in) |
| 993 | { |
| 994 | int i, ret = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 995 | struct audio_usecase *uc_info; |
| 996 | struct audio_device *adev = in->dev; |
| 997 | |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 998 | adev->active_input = NULL; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 999 | |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 1000 | ALOGV("%s: enter: usecase(%d: %s)", __func__, |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1001 | in->usecase, use_case_table[in->usecase]); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1002 | uc_info = get_usecase_from_list(adev, in->usecase); |
| 1003 | if (uc_info == NULL) { |
| 1004 | ALOGE("%s: Could not find the usecase (%d) in the list", |
| 1005 | __func__, in->usecase); |
| 1006 | return -EINVAL; |
| 1007 | } |
| 1008 | |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 1009 | /* 1. Disable stream specific mixer controls */ |
Ravi Kumar Alamanda | c38e452 | 2014-04-14 11:46:35 -0700 | [diff] [blame] | 1010 | disable_audio_route(adev, uc_info); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1011 | |
| 1012 | /* 2. Disable the tx device */ |
Ravi Kumar Alamanda | c38e452 | 2014-04-14 11:46:35 -0700 | [diff] [blame] | 1013 | disable_snd_device(adev, uc_info->in_snd_device); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1014 | |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 1015 | list_remove(&uc_info->list); |
| 1016 | free(uc_info); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1017 | |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 1018 | ALOGV("%s: exit: status(%d)", __func__, ret); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1019 | return ret; |
| 1020 | } |
| 1021 | |
| 1022 | int start_input_stream(struct stream_in *in) |
| 1023 | { |
| 1024 | /* 1. Enable output device and stream routing controls */ |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 1025 | int ret = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1026 | struct audio_usecase *uc_info; |
| 1027 | struct audio_device *adev = in->dev; |
| 1028 | |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 1029 | ALOGV("%s: enter: usecase(%d)", __func__, in->usecase); |
Haynes Mathew George | c735fb0 | 2016-06-30 18:00:28 -0700 | [diff] [blame] | 1030 | |
| 1031 | if (in->card_status == CARD_STATUS_OFFLINE || |
| 1032 | adev->card_status == CARD_STATUS_OFFLINE) { |
| 1033 | ALOGW("in->card_status or adev->card_status offline, try again"); |
| 1034 | ret = -EAGAIN; |
| 1035 | goto error_config; |
| 1036 | } |
| 1037 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1038 | in->pcm_device_id = platform_get_pcm_device_id(in->usecase, PCM_CAPTURE); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1039 | if (in->pcm_device_id < 0) { |
| 1040 | ALOGE("%s: Could not find PCM device id for the usecase(%d)", |
| 1041 | __func__, in->usecase); |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 1042 | ret = -EINVAL; |
| 1043 | goto error_config; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1044 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1045 | |
| 1046 | adev->active_input = in; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1047 | uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase)); |
| 1048 | uc_info->id = in->usecase; |
| 1049 | uc_info->type = PCM_CAPTURE; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 1050 | uc_info->stream.in = in; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1051 | uc_info->devices = in->device; |
| 1052 | uc_info->in_snd_device = SND_DEVICE_NONE; |
| 1053 | uc_info->out_snd_device = SND_DEVICE_NONE; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1054 | |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 1055 | list_add_tail(&adev->usecase_list, &uc_info->list); |
Ravi Kumar Alamanda | 533bb72 | 2015-09-23 13:47:03 -0700 | [diff] [blame] | 1056 | |
| 1057 | audio_extn_perf_lock_acquire(); |
| 1058 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1059 | select_devices(adev, in->usecase); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1060 | |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 1061 | ALOGV("%s: Opening PCM device card_id(%d) device_id(%d), channels %d", |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1062 | __func__, adev->snd_card, in->pcm_device_id, in->config.channels); |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 1063 | |
Andy Hung | 6ebe596 | 2016-01-15 17:46:57 -0800 | [diff] [blame] | 1064 | unsigned int flags = PCM_IN | PCM_MONOTONIC; |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 1065 | unsigned int pcm_open_retry_count = 0; |
| 1066 | |
| 1067 | if (in->usecase == USECASE_AUDIO_RECORD_AFE_PROXY) { |
| 1068 | flags |= PCM_MMAP | PCM_NOIRQ; |
| 1069 | pcm_open_retry_count = PROXY_OPEN_RETRY_COUNT; |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 1070 | } else if (in->realtime) { |
| 1071 | flags |= PCM_MMAP | PCM_NOIRQ; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1072 | } |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 1073 | |
| 1074 | while (1) { |
| 1075 | in->pcm = pcm_open(adev->snd_card, in->pcm_device_id, |
| 1076 | flags, &in->config); |
| 1077 | if (in->pcm == NULL || !pcm_is_ready(in->pcm)) { |
| 1078 | ALOGE("%s: %s", __func__, pcm_get_error(in->pcm)); |
| 1079 | if (in->pcm != NULL) { |
| 1080 | pcm_close(in->pcm); |
| 1081 | in->pcm = NULL; |
| 1082 | } |
| 1083 | if (pcm_open_retry_count-- == 0) { |
| 1084 | ret = -EIO; |
| 1085 | goto error_open; |
| 1086 | } |
| 1087 | usleep(PROXY_OPEN_WAIT_TIME * 1000); |
| 1088 | continue; |
| 1089 | } |
| 1090 | break; |
| 1091 | } |
| 1092 | |
Ravi Kumar Alamanda | 50919a7 | 2015-10-02 09:37:33 -0700 | [diff] [blame] | 1093 | ALOGV("%s: pcm_prepare", __func__); |
| 1094 | ret = pcm_prepare(in->pcm); |
| 1095 | if (ret < 0) { |
| 1096 | ALOGE("%s: pcm_prepare returned %d", __func__, ret); |
| 1097 | pcm_close(in->pcm); |
| 1098 | in->pcm = NULL; |
| 1099 | goto error_open; |
| 1100 | } |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 1101 | register_in_stream(in); |
| 1102 | if (in->realtime) { |
| 1103 | ret = pcm_start(in->pcm); |
| 1104 | } |
Ravi Kumar Alamanda | 533bb72 | 2015-09-23 13:47:03 -0700 | [diff] [blame] | 1105 | audio_extn_perf_lock_release(); |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 1106 | ALOGV("%s: exit", __func__); |
Haynes Mathew George | 88e6fb2 | 2015-08-19 11:51:34 -0700 | [diff] [blame] | 1107 | |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 1108 | return ret; |
| 1109 | |
| 1110 | error_open: |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1111 | stop_input_stream(in); |
Ravi Kumar Alamanda | 533bb72 | 2015-09-23 13:47:03 -0700 | [diff] [blame] | 1112 | audio_extn_perf_lock_release(); |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 1113 | |
| 1114 | error_config: |
| 1115 | adev->active_input = NULL; |
Eric Laurent | 2bafff1 | 2016-03-17 12:17:23 -0700 | [diff] [blame] | 1116 | ALOGW("%s: exit: status(%d)", __func__, ret); |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 1117 | |
| 1118 | return ret; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1119 | } |
| 1120 | |
Eric Laurent | a147807 | 2015-09-21 17:21:52 -0700 | [diff] [blame] | 1121 | void lock_input_stream(struct stream_in *in) |
| 1122 | { |
| 1123 | pthread_mutex_lock(&in->pre_lock); |
| 1124 | pthread_mutex_lock(&in->lock); |
| 1125 | pthread_mutex_unlock(&in->pre_lock); |
| 1126 | } |
| 1127 | |
| 1128 | void lock_output_stream(struct stream_out *out) |
| 1129 | { |
| 1130 | pthread_mutex_lock(&out->pre_lock); |
| 1131 | pthread_mutex_lock(&out->lock); |
| 1132 | pthread_mutex_unlock(&out->pre_lock); |
| 1133 | } |
| 1134 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1135 | /* must be called with out->lock locked */ |
| 1136 | static int send_offload_cmd_l(struct stream_out* out, int command) |
| 1137 | { |
| 1138 | struct offload_cmd *cmd = (struct offload_cmd *)calloc(1, sizeof(struct offload_cmd)); |
| 1139 | |
| 1140 | ALOGVV("%s %d", __func__, command); |
| 1141 | |
| 1142 | cmd->cmd = command; |
| 1143 | list_add_tail(&out->offload_cmd_list, &cmd->node); |
| 1144 | pthread_cond_signal(&out->offload_cond); |
| 1145 | return 0; |
| 1146 | } |
| 1147 | |
| 1148 | /* must be called iwth out->lock locked */ |
| 1149 | static void stop_compressed_output_l(struct stream_out *out) |
| 1150 | { |
| 1151 | out->offload_state = OFFLOAD_STATE_IDLE; |
| 1152 | out->playback_started = 0; |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 1153 | out->send_new_metadata = 1; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1154 | if (out->compr != NULL) { |
| 1155 | compress_stop(out->compr); |
| 1156 | while (out->offload_thread_blocked) { |
| 1157 | pthread_cond_wait(&out->cond, &out->lock); |
| 1158 | } |
| 1159 | } |
| 1160 | } |
| 1161 | |
| 1162 | static void *offload_thread_loop(void *context) |
| 1163 | { |
| 1164 | struct stream_out *out = (struct stream_out *) context; |
| 1165 | struct listnode *item; |
| 1166 | |
| 1167 | out->offload_state = OFFLOAD_STATE_IDLE; |
| 1168 | out->playback_started = 0; |
| 1169 | |
| 1170 | setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_AUDIO); |
| 1171 | set_sched_policy(0, SP_FOREGROUND); |
| 1172 | prctl(PR_SET_NAME, (unsigned long)"Offload Callback", 0, 0, 0); |
| 1173 | |
| 1174 | ALOGV("%s", __func__); |
Eric Laurent | a147807 | 2015-09-21 17:21:52 -0700 | [diff] [blame] | 1175 | lock_output_stream(out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1176 | for (;;) { |
| 1177 | struct offload_cmd *cmd = NULL; |
| 1178 | stream_callback_event_t event; |
| 1179 | bool send_callback = false; |
| 1180 | |
| 1181 | ALOGVV("%s offload_cmd_list %d out->offload_state %d", |
| 1182 | __func__, list_empty(&out->offload_cmd_list), |
| 1183 | out->offload_state); |
| 1184 | if (list_empty(&out->offload_cmd_list)) { |
| 1185 | ALOGV("%s SLEEPING", __func__); |
| 1186 | pthread_cond_wait(&out->offload_cond, &out->lock); |
| 1187 | ALOGV("%s RUNNING", __func__); |
| 1188 | continue; |
| 1189 | } |
| 1190 | |
| 1191 | item = list_head(&out->offload_cmd_list); |
| 1192 | cmd = node_to_item(item, struct offload_cmd, node); |
| 1193 | list_remove(item); |
| 1194 | |
| 1195 | ALOGVV("%s STATE %d CMD %d out->compr %p", |
| 1196 | __func__, out->offload_state, cmd->cmd, out->compr); |
| 1197 | |
| 1198 | if (cmd->cmd == OFFLOAD_CMD_EXIT) { |
| 1199 | free(cmd); |
| 1200 | break; |
| 1201 | } |
| 1202 | |
| 1203 | if (out->compr == NULL) { |
| 1204 | ALOGE("%s: Compress handle is NULL", __func__); |
Andy Hung | 68f55fd | 2016-04-21 11:51:11 -0700 | [diff] [blame] | 1205 | free(cmd); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1206 | pthread_cond_signal(&out->cond); |
| 1207 | continue; |
| 1208 | } |
| 1209 | out->offload_thread_blocked = true; |
| 1210 | pthread_mutex_unlock(&out->lock); |
| 1211 | send_callback = false; |
| 1212 | switch(cmd->cmd) { |
| 1213 | case OFFLOAD_CMD_WAIT_FOR_BUFFER: |
| 1214 | compress_wait(out->compr, -1); |
| 1215 | send_callback = true; |
| 1216 | event = STREAM_CBK_EVENT_WRITE_READY; |
| 1217 | break; |
| 1218 | case OFFLOAD_CMD_PARTIAL_DRAIN: |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 1219 | compress_next_track(out->compr); |
| 1220 | compress_partial_drain(out->compr); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1221 | send_callback = true; |
| 1222 | event = STREAM_CBK_EVENT_DRAIN_READY; |
Ravi Kumar Alamanda | cc4f6bf | 2014-12-02 19:21:51 -0800 | [diff] [blame] | 1223 | /* Resend the metadata for next iteration */ |
| 1224 | out->send_new_metadata = 1; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1225 | break; |
| 1226 | case OFFLOAD_CMD_DRAIN: |
| 1227 | compress_drain(out->compr); |
| 1228 | send_callback = true; |
| 1229 | event = STREAM_CBK_EVENT_DRAIN_READY; |
| 1230 | break; |
Haynes Mathew George | 3ddd3bd | 2016-07-07 20:01:53 -0700 | [diff] [blame] | 1231 | case OFFLOAD_CMD_ERROR: |
| 1232 | send_callback = true; |
| 1233 | event = STREAM_CBK_EVENT_ERROR; |
| 1234 | break; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1235 | default: |
| 1236 | ALOGE("%s unknown command received: %d", __func__, cmd->cmd); |
| 1237 | break; |
| 1238 | } |
Eric Laurent | a147807 | 2015-09-21 17:21:52 -0700 | [diff] [blame] | 1239 | lock_output_stream(out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1240 | out->offload_thread_blocked = false; |
| 1241 | pthread_cond_signal(&out->cond); |
Eric Laurent | 6e89524 | 2013-09-05 16:10:57 -0700 | [diff] [blame] | 1242 | if (send_callback) { |
Ravi Kumar Alamanda | cc4f6bf | 2014-12-02 19:21:51 -0800 | [diff] [blame] | 1243 | ALOGVV("%s: sending offload_callback event %d", __func__, event); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1244 | out->offload_callback(event, NULL, out->offload_cookie); |
Eric Laurent | 6e89524 | 2013-09-05 16:10:57 -0700 | [diff] [blame] | 1245 | } |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1246 | free(cmd); |
| 1247 | } |
| 1248 | |
| 1249 | pthread_cond_signal(&out->cond); |
| 1250 | while (!list_empty(&out->offload_cmd_list)) { |
| 1251 | item = list_head(&out->offload_cmd_list); |
| 1252 | list_remove(item); |
| 1253 | free(node_to_item(item, struct offload_cmd, node)); |
| 1254 | } |
| 1255 | pthread_mutex_unlock(&out->lock); |
| 1256 | |
| 1257 | return NULL; |
| 1258 | } |
| 1259 | |
| 1260 | static int create_offload_callback_thread(struct stream_out *out) |
| 1261 | { |
| 1262 | pthread_cond_init(&out->offload_cond, (const pthread_condattr_t *) NULL); |
| 1263 | list_init(&out->offload_cmd_list); |
| 1264 | pthread_create(&out->offload_thread, (const pthread_attr_t *) NULL, |
| 1265 | offload_thread_loop, out); |
| 1266 | return 0; |
| 1267 | } |
| 1268 | |
| 1269 | static int destroy_offload_callback_thread(struct stream_out *out) |
| 1270 | { |
Eric Laurent | a147807 | 2015-09-21 17:21:52 -0700 | [diff] [blame] | 1271 | lock_output_stream(out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1272 | stop_compressed_output_l(out); |
| 1273 | send_offload_cmd_l(out, OFFLOAD_CMD_EXIT); |
| 1274 | |
| 1275 | pthread_mutex_unlock(&out->lock); |
| 1276 | pthread_join(out->offload_thread, (void **) NULL); |
| 1277 | pthread_cond_destroy(&out->offload_cond); |
| 1278 | |
| 1279 | return 0; |
| 1280 | } |
| 1281 | |
Eric Laurent | 07eeafd | 2013-10-06 12:52:49 -0700 | [diff] [blame] | 1282 | static bool allow_hdmi_channel_config(struct audio_device *adev) |
| 1283 | { |
| 1284 | struct listnode *node; |
| 1285 | struct audio_usecase *usecase; |
| 1286 | bool ret = true; |
| 1287 | |
| 1288 | list_for_each(node, &adev->usecase_list) { |
| 1289 | usecase = node_to_item(node, struct audio_usecase, list); |
| 1290 | if (usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
| 1291 | /* |
| 1292 | * If voice call is already existing, do not proceed further to avoid |
| 1293 | * disabling/enabling both RX and TX devices, CSD calls, etc. |
| 1294 | * Once the voice call done, the HDMI channels can be configured to |
| 1295 | * max channels of remaining use cases. |
| 1296 | */ |
| 1297 | if (usecase->id == USECASE_VOICE_CALL) { |
Joe Onorato | 188b622 | 2016-03-01 11:02:27 -0800 | [diff] [blame] | 1298 | ALOGV("%s: voice call is active, no change in HDMI channels", |
Eric Laurent | 07eeafd | 2013-10-06 12:52:49 -0700 | [diff] [blame] | 1299 | __func__); |
| 1300 | ret = false; |
| 1301 | break; |
| 1302 | } else if (usecase->id == USECASE_AUDIO_PLAYBACK_MULTI_CH) { |
Joe Onorato | 188b622 | 2016-03-01 11:02:27 -0800 | [diff] [blame] | 1303 | ALOGV("%s: multi channel playback is active, " |
Eric Laurent | 07eeafd | 2013-10-06 12:52:49 -0700 | [diff] [blame] | 1304 | "no change in HDMI channels", __func__); |
| 1305 | ret = false; |
| 1306 | break; |
| 1307 | } |
| 1308 | } |
| 1309 | } |
| 1310 | return ret; |
| 1311 | } |
| 1312 | |
| 1313 | static int check_and_set_hdmi_channels(struct audio_device *adev, |
| 1314 | unsigned int channels) |
| 1315 | { |
| 1316 | struct listnode *node; |
| 1317 | struct audio_usecase *usecase; |
| 1318 | |
| 1319 | /* Check if change in HDMI channel config is allowed */ |
| 1320 | if (!allow_hdmi_channel_config(adev)) |
| 1321 | return 0; |
| 1322 | |
| 1323 | if (channels == adev->cur_hdmi_channels) { |
Joe Onorato | 188b622 | 2016-03-01 11:02:27 -0800 | [diff] [blame] | 1324 | ALOGV("%s: Requested channels are same as current", __func__); |
Eric Laurent | 07eeafd | 2013-10-06 12:52:49 -0700 | [diff] [blame] | 1325 | return 0; |
| 1326 | } |
| 1327 | |
| 1328 | platform_set_hdmi_channels(adev->platform, channels); |
| 1329 | adev->cur_hdmi_channels = channels; |
| 1330 | |
| 1331 | /* |
| 1332 | * Deroute all the playback streams routed to HDMI so that |
| 1333 | * the back end is deactivated. Note that backend will not |
| 1334 | * be deactivated if any one stream is connected to it. |
| 1335 | */ |
| 1336 | list_for_each(node, &adev->usecase_list) { |
| 1337 | usecase = node_to_item(node, struct audio_usecase, list); |
| 1338 | if (usecase->type == PCM_PLAYBACK && |
| 1339 | usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
Ravi Kumar Alamanda | c38e452 | 2014-04-14 11:46:35 -0700 | [diff] [blame] | 1340 | disable_audio_route(adev, usecase); |
Eric Laurent | 07eeafd | 2013-10-06 12:52:49 -0700 | [diff] [blame] | 1341 | } |
| 1342 | } |
| 1343 | |
| 1344 | /* |
| 1345 | * Enable all the streams disabled above. Now the HDMI backend |
| 1346 | * will be activated with new channel configuration |
| 1347 | */ |
| 1348 | list_for_each(node, &adev->usecase_list) { |
| 1349 | usecase = node_to_item(node, struct audio_usecase, list); |
| 1350 | if (usecase->type == PCM_PLAYBACK && |
| 1351 | usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
Ravi Kumar Alamanda | c38e452 | 2014-04-14 11:46:35 -0700 | [diff] [blame] | 1352 | enable_audio_route(adev, usecase); |
Eric Laurent | 07eeafd | 2013-10-06 12:52:49 -0700 | [diff] [blame] | 1353 | } |
| 1354 | } |
| 1355 | |
| 1356 | return 0; |
| 1357 | } |
| 1358 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1359 | static int stop_output_stream(struct stream_out *out) |
| 1360 | { |
| 1361 | int i, ret = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1362 | struct audio_usecase *uc_info; |
| 1363 | struct audio_device *adev = out->dev; |
| 1364 | |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 1365 | ALOGV("%s: enter: usecase(%d: %s)", __func__, |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1366 | out->usecase, use_case_table[out->usecase]); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1367 | uc_info = get_usecase_from_list(adev, out->usecase); |
| 1368 | if (uc_info == NULL) { |
| 1369 | ALOGE("%s: Could not find the usecase (%d) in the list", |
| 1370 | __func__, out->usecase); |
| 1371 | return -EINVAL; |
| 1372 | } |
| 1373 | |
Haynes Mathew George | 41f8665 | 2014-06-17 14:22:15 -0700 | [diff] [blame] | 1374 | if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) { |
| 1375 | if (adev->visualizer_stop_output != NULL) |
| 1376 | adev->visualizer_stop_output(out->handle, out->pcm_device_id); |
| 1377 | if (adev->offload_effects_stop_output != NULL) |
| 1378 | adev->offload_effects_stop_output(out->handle, out->pcm_device_id); |
| 1379 | } |
Eric Laurent | c4aef75 | 2013-09-12 17:45:53 -0700 | [diff] [blame] | 1380 | |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 1381 | /* 1. Get and set stream specific mixer controls */ |
Ravi Kumar Alamanda | c38e452 | 2014-04-14 11:46:35 -0700 | [diff] [blame] | 1382 | disable_audio_route(adev, uc_info); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1383 | |
| 1384 | /* 2. Disable the rx device */ |
Ravi Kumar Alamanda | c38e452 | 2014-04-14 11:46:35 -0700 | [diff] [blame] | 1385 | disable_snd_device(adev, uc_info->out_snd_device); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1386 | |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 1387 | list_remove(&uc_info->list); |
| 1388 | free(uc_info); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1389 | |
Eric Laurent | 0499d4f | 2014-08-25 22:39:29 -0500 | [diff] [blame] | 1390 | audio_extn_extspk_update(adev->extspk); |
| 1391 | |
Eric Laurent | 07eeafd | 2013-10-06 12:52:49 -0700 | [diff] [blame] | 1392 | /* Must be called after removing the usecase from list */ |
| 1393 | if (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) |
| 1394 | check_and_set_hdmi_channels(adev, DEFAULT_HDMI_OUT_CHANNELS); |
| 1395 | |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 1396 | ALOGV("%s: exit: status(%d)", __func__, ret); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1397 | return ret; |
| 1398 | } |
| 1399 | |
| 1400 | int start_output_stream(struct stream_out *out) |
| 1401 | { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1402 | int ret = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1403 | struct audio_usecase *uc_info; |
| 1404 | struct audio_device *adev = out->dev; |
| 1405 | |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 1406 | ALOGV("%s: enter: usecase(%d: %s) devices(%#x)", |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1407 | __func__, out->usecase, use_case_table[out->usecase], out->devices); |
Haynes Mathew George | c735fb0 | 2016-06-30 18:00:28 -0700 | [diff] [blame] | 1408 | |
| 1409 | if (out->card_status == CARD_STATUS_OFFLINE || |
| 1410 | adev->card_status == CARD_STATUS_OFFLINE) { |
| 1411 | ALOGW("out->card_status or adev->card_status offline, try again"); |
| 1412 | ret = -EAGAIN; |
| 1413 | goto error_config; |
| 1414 | } |
| 1415 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1416 | out->pcm_device_id = platform_get_pcm_device_id(out->usecase, PCM_PLAYBACK); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1417 | if (out->pcm_device_id < 0) { |
| 1418 | ALOGE("%s: Invalid PCM device id(%d) for the usecase(%d)", |
| 1419 | __func__, out->pcm_device_id, out->usecase); |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1420 | ret = -EINVAL; |
| 1421 | goto error_config; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1422 | } |
| 1423 | |
| 1424 | uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase)); |
| 1425 | uc_info->id = out->usecase; |
| 1426 | uc_info->type = PCM_PLAYBACK; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 1427 | uc_info->stream.out = out; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1428 | uc_info->devices = out->devices; |
| 1429 | uc_info->in_snd_device = SND_DEVICE_NONE; |
| 1430 | uc_info->out_snd_device = SND_DEVICE_NONE; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1431 | |
Eric Laurent | 07eeafd | 2013-10-06 12:52:49 -0700 | [diff] [blame] | 1432 | /* This must be called before adding this usecase to the list */ |
| 1433 | if (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) |
| 1434 | check_and_set_hdmi_channels(adev, out->config.channels); |
| 1435 | |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 1436 | list_add_tail(&adev->usecase_list, &uc_info->list); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1437 | |
Ravi Kumar Alamanda | 533bb72 | 2015-09-23 13:47:03 -0700 | [diff] [blame] | 1438 | audio_extn_perf_lock_acquire(); |
| 1439 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1440 | select_devices(adev, out->usecase); |
| 1441 | |
Eric Laurent | 0499d4f | 2014-08-25 22:39:29 -0500 | [diff] [blame] | 1442 | audio_extn_extspk_update(adev->extspk); |
| 1443 | |
Andy Hung | 31aca91 | 2014-03-20 17:14:59 -0700 | [diff] [blame] | 1444 | ALOGV("%s: Opening PCM device card_id(%d) device_id(%d) format(%#x)", |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1445 | __func__, adev->snd_card, out->pcm_device_id, out->config.format); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1446 | if (out->usecase != USECASE_AUDIO_PLAYBACK_OFFLOAD) { |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 1447 | unsigned int flags = PCM_OUT; |
| 1448 | unsigned int pcm_open_retry_count = 0; |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 1449 | |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 1450 | if (out->usecase == USECASE_AUDIO_PLAYBACK_AFE_PROXY) { |
| 1451 | flags |= PCM_MMAP | PCM_NOIRQ; |
| 1452 | pcm_open_retry_count = PROXY_OPEN_RETRY_COUNT; |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 1453 | } else if (out->realtime) { |
| 1454 | flags |= PCM_MMAP | PCM_NOIRQ; |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 1455 | } else |
| 1456 | flags |= PCM_MONOTONIC; |
| 1457 | |
| 1458 | while (1) { |
| 1459 | out->pcm = pcm_open(adev->snd_card, out->pcm_device_id, |
| 1460 | flags, &out->config); |
| 1461 | if (out->pcm == NULL || !pcm_is_ready(out->pcm)) { |
| 1462 | ALOGE("%s: %s", __func__, pcm_get_error(out->pcm)); |
| 1463 | if (out->pcm != NULL) { |
| 1464 | pcm_close(out->pcm); |
| 1465 | out->pcm = NULL; |
| 1466 | } |
| 1467 | if (pcm_open_retry_count-- == 0) { |
| 1468 | ret = -EIO; |
| 1469 | goto error_open; |
| 1470 | } |
| 1471 | usleep(PROXY_OPEN_WAIT_TIME * 1000); |
| 1472 | continue; |
| 1473 | } |
| 1474 | break; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1475 | } |
Ravi Kumar Alamanda | 50919a7 | 2015-10-02 09:37:33 -0700 | [diff] [blame] | 1476 | ALOGV("%s: pcm_prepare", __func__); |
| 1477 | if (pcm_is_ready(out->pcm)) { |
| 1478 | ret = pcm_prepare(out->pcm); |
| 1479 | if (ret < 0) { |
| 1480 | ALOGE("%s: pcm_prepare returned %d", __func__, ret); |
| 1481 | pcm_close(out->pcm); |
| 1482 | out->pcm = NULL; |
| 1483 | goto error_open; |
| 1484 | } |
| 1485 | } |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1486 | } else { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1487 | out->pcm = NULL; |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 1488 | out->compr = compress_open(adev->snd_card, out->pcm_device_id, |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1489 | COMPRESS_IN, &out->compr_config); |
| 1490 | if (out->compr && !is_compress_ready(out->compr)) { |
| 1491 | ALOGE("%s: %s", __func__, compress_get_error(out->compr)); |
| 1492 | compress_close(out->compr); |
| 1493 | out->compr = NULL; |
| 1494 | ret = -EIO; |
| 1495 | goto error_open; |
| 1496 | } |
| 1497 | if (out->offload_callback) |
| 1498 | compress_nonblock(out->compr, out->non_blocking); |
Eric Laurent | c4aef75 | 2013-09-12 17:45:53 -0700 | [diff] [blame] | 1499 | |
| 1500 | if (adev->visualizer_start_output != NULL) |
Haynes Mathew George | 41f8665 | 2014-06-17 14:22:15 -0700 | [diff] [blame] | 1501 | adev->visualizer_start_output(out->handle, out->pcm_device_id); |
| 1502 | if (adev->offload_effects_start_output != NULL) |
| 1503 | adev->offload_effects_start_output(out->handle, out->pcm_device_id); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1504 | } |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 1505 | ret = 0; |
| 1506 | register_out_stream(out); |
| 1507 | if (out->realtime) { |
| 1508 | ret = pcm_start(out->pcm); |
| 1509 | } |
Ravi Kumar Alamanda | 533bb72 | 2015-09-23 13:47:03 -0700 | [diff] [blame] | 1510 | audio_extn_perf_lock_release(); |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 1511 | ALOGV("%s: exit", __func__); |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 1512 | return ret; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1513 | error_open: |
Ravi Kumar Alamanda | 533bb72 | 2015-09-23 13:47:03 -0700 | [diff] [blame] | 1514 | audio_extn_perf_lock_release(); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1515 | stop_output_stream(out); |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1516 | error_config: |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1517 | return ret; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1518 | } |
| 1519 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1520 | static int check_input_parameters(uint32_t sample_rate, |
| 1521 | audio_format_t format, |
| 1522 | int channel_count) |
| 1523 | { |
vivek mehta | 4ed66e6 | 2016-04-15 23:33:34 -0700 | [diff] [blame] | 1524 | if ((format != AUDIO_FORMAT_PCM_16_BIT) && (format != AUDIO_FORMAT_PCM_8_24_BIT)) { |
vivek mehta | dae4471 | 2015-07-27 14:13:18 -0700 | [diff] [blame] | 1525 | ALOGE("%s: unsupported AUDIO FORMAT (%d) ", __func__, format); |
| 1526 | return -EINVAL; |
| 1527 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1528 | |
vivek mehta | dae4471 | 2015-07-27 14:13:18 -0700 | [diff] [blame] | 1529 | if ((channel_count < MIN_CHANNEL_COUNT) || (channel_count > MAX_CHANNEL_COUNT)) { |
Jean-Michel Trivi | c075069 | 2015-10-12 12:12:32 -0700 | [diff] [blame] | 1530 | ALOGE("%s: unsupported channel count (%d) passed Min / Max (%d / %d)", __func__, |
vivek mehta | dae4471 | 2015-07-27 14:13:18 -0700 | [diff] [blame] | 1531 | channel_count, MIN_CHANNEL_COUNT, MAX_CHANNEL_COUNT); |
| 1532 | return -EINVAL; |
| 1533 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1534 | |
| 1535 | switch (sample_rate) { |
| 1536 | case 8000: |
| 1537 | case 11025: |
| 1538 | case 12000: |
| 1539 | case 16000: |
| 1540 | case 22050: |
| 1541 | case 24000: |
| 1542 | case 32000: |
| 1543 | case 44100: |
| 1544 | case 48000: |
| 1545 | break; |
| 1546 | default: |
vivek mehta | dae4471 | 2015-07-27 14:13:18 -0700 | [diff] [blame] | 1547 | ALOGE("%s: unsupported (%d) samplerate passed ", __func__, sample_rate); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1548 | return -EINVAL; |
| 1549 | } |
| 1550 | |
| 1551 | return 0; |
| 1552 | } |
| 1553 | |
| 1554 | static size_t get_input_buffer_size(uint32_t sample_rate, |
| 1555 | audio_format_t format, |
Glenn Kasten | 68e79ce | 2014-07-15 10:56:59 -0700 | [diff] [blame] | 1556 | int channel_count, |
| 1557 | bool is_low_latency) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1558 | { |
| 1559 | size_t size = 0; |
| 1560 | |
Ravi Kumar Alamanda | 33d3306 | 2013-06-11 14:40:01 -0700 | [diff] [blame] | 1561 | if (check_input_parameters(sample_rate, format, channel_count) != 0) |
| 1562 | return 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1563 | |
Ravi Kumar Alamanda | 33d3306 | 2013-06-11 14:40:01 -0700 | [diff] [blame] | 1564 | size = (sample_rate * AUDIO_CAPTURE_PERIOD_DURATION_MSEC) / 1000; |
Glenn Kasten | 68e79ce | 2014-07-15 10:56:59 -0700 | [diff] [blame] | 1565 | if (is_low_latency) |
Glenn Kasten | 4f99339 | 2014-05-14 07:30:48 -0700 | [diff] [blame] | 1566 | size = configured_low_latency_capture_period_size; |
vivek mehta | 4ed66e6 | 2016-04-15 23:33:34 -0700 | [diff] [blame] | 1567 | |
| 1568 | size *= channel_count * audio_bytes_per_sample(format); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1569 | |
Glenn Kasten | 4f99339 | 2014-05-14 07:30:48 -0700 | [diff] [blame] | 1570 | /* make sure the size is multiple of 32 bytes |
| 1571 | * At 48 kHz mono 16-bit PCM: |
| 1572 | * 5.000 ms = 240 frames = 15*16*1*2 = 480, a whole multiple of 32 (15) |
| 1573 | * 3.333 ms = 160 frames = 10*16*1*2 = 320, a whole multiple of 32 (10) |
| 1574 | */ |
| 1575 | size += 0x1f; |
| 1576 | size &= ~0x1f; |
Ravi Kumar Alamanda | 33d3306 | 2013-06-11 14:40:01 -0700 | [diff] [blame] | 1577 | |
| 1578 | return size; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | static uint32_t out_get_sample_rate(const struct audio_stream *stream) |
| 1582 | { |
| 1583 | struct stream_out *out = (struct stream_out *)stream; |
| 1584 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1585 | return out->sample_rate; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1586 | } |
| 1587 | |
Haynes Mathew George | cc9649b | 2014-06-10 15:08:39 -0700 | [diff] [blame] | 1588 | static int out_set_sample_rate(struct audio_stream *stream __unused, uint32_t rate __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1589 | { |
| 1590 | return -ENOSYS; |
| 1591 | } |
| 1592 | |
| 1593 | static size_t out_get_buffer_size(const struct audio_stream *stream) |
| 1594 | { |
| 1595 | struct stream_out *out = (struct stream_out *)stream; |
| 1596 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1597 | if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) { |
| 1598 | return out->compr_config.fragment_size; |
| 1599 | } |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 1600 | return out->config.period_size * out->af_period_multiplier * |
Eric Laurent | fdf296a | 2014-07-03 16:41:51 -0700 | [diff] [blame] | 1601 | audio_stream_out_frame_size((const struct audio_stream_out *)stream); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1602 | } |
| 1603 | |
| 1604 | static uint32_t out_get_channels(const struct audio_stream *stream) |
| 1605 | { |
| 1606 | struct stream_out *out = (struct stream_out *)stream; |
| 1607 | |
| 1608 | return out->channel_mask; |
| 1609 | } |
| 1610 | |
| 1611 | static audio_format_t out_get_format(const struct audio_stream *stream) |
| 1612 | { |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1613 | struct stream_out *out = (struct stream_out *)stream; |
| 1614 | |
| 1615 | return out->format; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1616 | } |
| 1617 | |
Haynes Mathew George | cc9649b | 2014-06-10 15:08:39 -0700 | [diff] [blame] | 1618 | static int out_set_format(struct audio_stream *stream __unused, audio_format_t format __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1619 | { |
| 1620 | return -ENOSYS; |
| 1621 | } |
| 1622 | |
| 1623 | static int out_standby(struct audio_stream *stream) |
| 1624 | { |
| 1625 | struct stream_out *out = (struct stream_out *)stream; |
| 1626 | struct audio_device *adev = out->dev; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1627 | |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 1628 | ALOGV("%s: enter: usecase(%d: %s)", __func__, |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1629 | out->usecase, use_case_table[out->usecase]); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1630 | |
Eric Laurent | a147807 | 2015-09-21 17:21:52 -0700 | [diff] [blame] | 1631 | lock_output_stream(out); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1632 | if (!out->standby) { |
Haynes Mathew George | 88e6fb2 | 2015-08-19 11:51:34 -0700 | [diff] [blame] | 1633 | if (adev->adm_deregister_stream) |
| 1634 | adev->adm_deregister_stream(adev->adm_data, out->handle); |
| 1635 | |
Ravi Kumar Alamanda | 8bba9e9 | 2013-11-11 21:09:07 -0800 | [diff] [blame] | 1636 | pthread_mutex_lock(&adev->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1637 | out->standby = true; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1638 | if (out->usecase != USECASE_AUDIO_PLAYBACK_OFFLOAD) { |
| 1639 | if (out->pcm) { |
| 1640 | pcm_close(out->pcm); |
| 1641 | out->pcm = NULL; |
| 1642 | } |
| 1643 | } else { |
| 1644 | stop_compressed_output_l(out); |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 1645 | out->gapless_mdata.encoder_delay = 0; |
| 1646 | out->gapless_mdata.encoder_padding = 0; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1647 | if (out->compr != NULL) { |
| 1648 | compress_close(out->compr); |
| 1649 | out->compr = NULL; |
| 1650 | } |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 1651 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1652 | stop_output_stream(out); |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 1653 | pthread_mutex_unlock(&adev->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1654 | } |
| 1655 | pthread_mutex_unlock(&out->lock); |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 1656 | ALOGV("%s: exit", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1657 | return 0; |
| 1658 | } |
| 1659 | |
Haynes Mathew George | 3ddd3bd | 2016-07-07 20:01:53 -0700 | [diff] [blame] | 1660 | static int out_on_error(struct audio_stream *stream) |
| 1661 | { |
| 1662 | struct stream_out *out = (struct stream_out *)stream; |
| 1663 | struct audio_device *adev = out->dev; |
| 1664 | bool do_standby = false; |
| 1665 | |
| 1666 | lock_output_stream(out); |
| 1667 | if (!out->standby) { |
| 1668 | if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) { |
| 1669 | stop_compressed_output_l(out); |
| 1670 | send_offload_cmd_l(out, OFFLOAD_CMD_ERROR); |
| 1671 | } else |
| 1672 | do_standby = true; |
| 1673 | } |
| 1674 | pthread_mutex_unlock(&out->lock); |
| 1675 | |
| 1676 | if (do_standby) |
| 1677 | return out_standby(&out->stream.common); |
| 1678 | |
| 1679 | return 0; |
| 1680 | } |
| 1681 | |
Haynes Mathew George | cc9649b | 2014-06-10 15:08:39 -0700 | [diff] [blame] | 1682 | static int out_dump(const struct audio_stream *stream __unused, int fd __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1683 | { |
| 1684 | return 0; |
| 1685 | } |
| 1686 | |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 1687 | static int parse_compress_metadata(struct stream_out *out, struct str_parms *parms) |
| 1688 | { |
| 1689 | int ret = 0; |
| 1690 | char value[32]; |
| 1691 | struct compr_gapless_mdata tmp_mdata; |
| 1692 | |
| 1693 | if (!out || !parms) { |
| 1694 | return -EINVAL; |
| 1695 | } |
| 1696 | |
| 1697 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_DELAY_SAMPLES, value, sizeof(value)); |
| 1698 | if (ret >= 0) { |
| 1699 | tmp_mdata.encoder_delay = atoi(value); //whats a good limit check? |
| 1700 | } else { |
| 1701 | return -EINVAL; |
| 1702 | } |
| 1703 | |
| 1704 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_PADDING_SAMPLES, value, sizeof(value)); |
| 1705 | if (ret >= 0) { |
| 1706 | tmp_mdata.encoder_padding = atoi(value); |
| 1707 | } else { |
| 1708 | return -EINVAL; |
| 1709 | } |
| 1710 | |
| 1711 | out->gapless_mdata = tmp_mdata; |
| 1712 | out->send_new_metadata = 1; |
| 1713 | ALOGV("%s new encoder delay %u and padding %u", __func__, |
| 1714 | out->gapless_mdata.encoder_delay, out->gapless_mdata.encoder_padding); |
| 1715 | |
| 1716 | return 0; |
| 1717 | } |
| 1718 | |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 1719 | static bool output_drives_call(struct audio_device *adev, struct stream_out *out) |
| 1720 | { |
| 1721 | return out == adev->primary_output || out == adev->voice_tx_output; |
| 1722 | } |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 1723 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1724 | static int out_set_parameters(struct audio_stream *stream, const char *kvpairs) |
| 1725 | { |
| 1726 | struct stream_out *out = (struct stream_out *)stream; |
| 1727 | struct audio_device *adev = out->dev; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 1728 | struct audio_usecase *usecase; |
| 1729 | struct listnode *node; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1730 | struct str_parms *parms; |
| 1731 | char value[32]; |
| 1732 | int ret, val = 0; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 1733 | bool select_new_device = false; |
Eric Laurent | 03f0943 | 2014-03-25 18:09:11 -0700 | [diff] [blame] | 1734 | int status = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1735 | |
Eric Laurent | 2e140aa | 2016-06-30 17:14:46 -0700 | [diff] [blame] | 1736 | ALOGD("%s: enter: usecase(%d: %s) kvpairs: %s", |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1737 | __func__, out->usecase, use_case_table[out->usecase], kvpairs); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1738 | parms = str_parms_create_str(kvpairs); |
| 1739 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, value, sizeof(value)); |
| 1740 | if (ret >= 0) { |
| 1741 | val = atoi(value); |
Eric Laurent | a147807 | 2015-09-21 17:21:52 -0700 | [diff] [blame] | 1742 | lock_output_stream(out); |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 1743 | pthread_mutex_lock(&adev->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1744 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1745 | /* |
| 1746 | * When HDMI cable is unplugged the music playback is paused and |
| 1747 | * the policy manager sends routing=0. But the audioflinger |
| 1748 | * continues to write data until standby time (3sec). |
| 1749 | * As the HDMI core is turned off, the write gets blocked. |
| 1750 | * Avoid this by routing audio to speaker until standby. |
| 1751 | */ |
| 1752 | if (out->devices == AUDIO_DEVICE_OUT_AUX_DIGITAL && |
| 1753 | val == AUDIO_DEVICE_NONE) { |
| 1754 | val = AUDIO_DEVICE_OUT_SPEAKER; |
| 1755 | } |
| 1756 | |
| 1757 | /* |
| 1758 | * select_devices() call below switches all the usecases on the same |
Ravi Kumar Alamanda | b7ea4f5 | 2015-06-08 16:44:05 -0700 | [diff] [blame] | 1759 | * backend to the new device. Refer to check_and_route_playback_usecases() in |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1760 | * the select_devices(). But how do we undo this? |
| 1761 | * |
| 1762 | * For example, music playback is active on headset (deep-buffer usecase) |
| 1763 | * and if we go to ringtones and select a ringtone, low-latency usecase |
| 1764 | * will be started on headset+speaker. As we can't enable headset+speaker |
| 1765 | * and headset devices at the same time, select_devices() switches the music |
| 1766 | * playback to headset+speaker while starting low-lateny usecase for ringtone. |
| 1767 | * So when the ringtone playback is completed, how do we undo the same? |
| 1768 | * |
| 1769 | * We are relying on the out_set_parameters() call on deep-buffer output, |
| 1770 | * once the ringtone playback is ended. |
| 1771 | * NOTE: We should not check if the current devices are same as new devices. |
| 1772 | * Because select_devices() must be called to switch back the music |
| 1773 | * playback to headset. |
| 1774 | */ |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 1775 | audio_devices_t new_dev = val; |
| 1776 | if (new_dev != AUDIO_DEVICE_NONE) { |
| 1777 | bool same_dev = out->devices == new_dev; |
| 1778 | out->devices = new_dev; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1779 | |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 1780 | if (!out->standby) { |
| 1781 | if (!same_dev) { |
| 1782 | ALOGV("update routing change"); |
| 1783 | out->routing_change = true; |
| 1784 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1785 | select_devices(adev, out->usecase); |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 1786 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1787 | |
Eric Laurent | a765719 | 2014-10-09 21:09:33 -0700 | [diff] [blame] | 1788 | if (output_drives_call(adev, out)) { |
| 1789 | if (!voice_is_in_call(adev)) { |
| 1790 | if (adev->mode == AUDIO_MODE_IN_CALL) { |
| 1791 | adev->current_call_output = out; |
| 1792 | ret = voice_start_call(adev); |
| 1793 | } |
| 1794 | } else { |
| 1795 | adev->current_call_output = out; |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 1796 | voice_update_devices_for_all_voice_usecases(adev); |
Eric Laurent | a765719 | 2014-10-09 21:09:33 -0700 | [diff] [blame] | 1797 | } |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 1798 | } |
| 1799 | } |
| 1800 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1801 | pthread_mutex_unlock(&adev->lock); |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 1802 | pthread_mutex_unlock(&out->lock); |
Eric Laurent | 0499d4f | 2014-08-25 22:39:29 -0500 | [diff] [blame] | 1803 | |
| 1804 | /*handles device and call state changes*/ |
| 1805 | audio_extn_extspk_update(adev->extspk); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1806 | } |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 1807 | |
| 1808 | if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) { |
| 1809 | parse_compress_metadata(out, parms); |
| 1810 | } |
| 1811 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1812 | str_parms_destroy(parms); |
Eric Laurent | 03f0943 | 2014-03-25 18:09:11 -0700 | [diff] [blame] | 1813 | ALOGV("%s: exit: code(%d)", __func__, status); |
| 1814 | return status; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | static char* out_get_parameters(const struct audio_stream *stream, const char *keys) |
| 1818 | { |
| 1819 | struct stream_out *out = (struct stream_out *)stream; |
| 1820 | struct str_parms *query = str_parms_create_str(keys); |
| 1821 | char *str; |
| 1822 | char value[256]; |
| 1823 | struct str_parms *reply = str_parms_create(); |
| 1824 | size_t i, j; |
| 1825 | int ret; |
| 1826 | bool first = true; |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 1827 | ALOGV("%s: enter: keys - %s", __func__, keys); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1828 | ret = str_parms_get_str(query, AUDIO_PARAMETER_STREAM_SUP_CHANNELS, value, sizeof(value)); |
| 1829 | if (ret >= 0) { |
| 1830 | value[0] = '\0'; |
| 1831 | i = 0; |
| 1832 | while (out->supported_channel_masks[i] != 0) { |
| 1833 | for (j = 0; j < ARRAY_SIZE(out_channels_name_to_enum_table); j++) { |
| 1834 | if (out_channels_name_to_enum_table[j].value == out->supported_channel_masks[i]) { |
| 1835 | if (!first) { |
| 1836 | strcat(value, "|"); |
| 1837 | } |
| 1838 | strcat(value, out_channels_name_to_enum_table[j].name); |
| 1839 | first = false; |
| 1840 | break; |
| 1841 | } |
| 1842 | } |
| 1843 | i++; |
| 1844 | } |
| 1845 | str_parms_add_str(reply, AUDIO_PARAMETER_STREAM_SUP_CHANNELS, value); |
| 1846 | str = str_parms_to_str(reply); |
| 1847 | } else { |
| 1848 | str = strdup(keys); |
| 1849 | } |
| 1850 | str_parms_destroy(query); |
| 1851 | str_parms_destroy(reply); |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 1852 | ALOGV("%s: exit: returns - %s", __func__, str); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1853 | return str; |
| 1854 | } |
| 1855 | |
| 1856 | static uint32_t out_get_latency(const struct audio_stream_out *stream) |
| 1857 | { |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 1858 | uint32_t hw_delay, period_ms; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1859 | struct stream_out *out = (struct stream_out *)stream; |
| 1860 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1861 | if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) |
| 1862 | return COMPRESS_OFFLOAD_PLAYBACK_LATENCY; |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 1863 | else if (out->realtime) { |
| 1864 | // since the buffer won't be filled up faster than realtime, |
| 1865 | // return a smaller number |
| 1866 | period_ms = (out->af_period_multiplier * out->config.period_size * |
| 1867 | 1000) / (out->config.rate); |
| 1868 | hw_delay = platform_render_latency(out->usecase)/1000; |
| 1869 | return period_ms + hw_delay; |
| 1870 | } |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1871 | |
| 1872 | return (out->config.period_count * out->config.period_size * 1000) / |
| 1873 | (out->config.rate); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1874 | } |
| 1875 | |
| 1876 | static int out_set_volume(struct audio_stream_out *stream, float left, |
| 1877 | float right) |
| 1878 | { |
Eric Laurent | a9024de | 2013-04-04 09:19:12 -0700 | [diff] [blame] | 1879 | struct stream_out *out = (struct stream_out *)stream; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1880 | int volume[2]; |
| 1881 | |
Eric Laurent | a9024de | 2013-04-04 09:19:12 -0700 | [diff] [blame] | 1882 | if (out->usecase == USECASE_AUDIO_PLAYBACK_MULTI_CH) { |
| 1883 | /* only take left channel into account: the API is for stereo anyway */ |
| 1884 | out->muted = (left == 0.0f); |
| 1885 | return 0; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1886 | } else if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) { |
| 1887 | const char *mixer_ctl_name = "Compress Playback Volume"; |
| 1888 | struct audio_device *adev = out->dev; |
| 1889 | struct mixer_ctl *ctl; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1890 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 1891 | if (!ctl) { |
Haynes Mathew George | 20bcfa8 | 2014-06-25 13:37:03 -0700 | [diff] [blame] | 1892 | /* try with the control based on device id */ |
| 1893 | int pcm_device_id = platform_get_pcm_device_id(out->usecase, |
| 1894 | PCM_PLAYBACK); |
| 1895 | char ctl_name[128] = {0}; |
| 1896 | snprintf(ctl_name, sizeof(ctl_name), |
| 1897 | "Compress Playback %d Volume", pcm_device_id); |
| 1898 | ctl = mixer_get_ctl_by_name(adev->mixer, ctl_name); |
| 1899 | if (!ctl) { |
| 1900 | ALOGE("%s: Could not get volume ctl mixer cmd", __func__); |
| 1901 | return -EINVAL; |
| 1902 | } |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1903 | } |
| 1904 | volume[0] = (int)(left * COMPRESS_PLAYBACK_VOLUME_MAX); |
| 1905 | volume[1] = (int)(right * COMPRESS_PLAYBACK_VOLUME_MAX); |
| 1906 | mixer_ctl_set_array(ctl, volume, sizeof(volume)/sizeof(volume[0])); |
| 1907 | return 0; |
Eric Laurent | a9024de | 2013-04-04 09:19:12 -0700 | [diff] [blame] | 1908 | } |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1909 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1910 | return -ENOSYS; |
| 1911 | } |
| 1912 | |
Haynes Mathew George | c735fb0 | 2016-06-30 18:00:28 -0700 | [diff] [blame] | 1913 | // note: this call is safe only if the stream_cb is |
| 1914 | // removed first in close_output_stream (as is done now). |
| 1915 | static void out_snd_mon_cb(void * stream, struct str_parms * parms) |
| 1916 | { |
| 1917 | if (!stream || !parms) |
| 1918 | return; |
| 1919 | |
| 1920 | struct stream_out *out = (struct stream_out *)stream; |
| 1921 | struct audio_device *adev = out->dev; |
| 1922 | |
| 1923 | card_status_t status; |
| 1924 | int card; |
| 1925 | if (parse_snd_card_status(parms, &card, &status) < 0) |
| 1926 | return; |
| 1927 | |
| 1928 | pthread_mutex_lock(&adev->lock); |
| 1929 | bool valid_cb = (card == adev->snd_card); |
| 1930 | pthread_mutex_unlock(&adev->lock); |
| 1931 | |
| 1932 | if (!valid_cb) |
| 1933 | return; |
| 1934 | |
Haynes Mathew George | c735fb0 | 2016-06-30 18:00:28 -0700 | [diff] [blame] | 1935 | lock_output_stream(out); |
| 1936 | if (out->card_status != status) |
| 1937 | out->card_status = status; |
| 1938 | pthread_mutex_unlock(&out->lock); |
| 1939 | |
Haynes Mathew George | 3ddd3bd | 2016-07-07 20:01:53 -0700 | [diff] [blame] | 1940 | ALOGW("out_snd_mon_cb for card %d usecase %s, status %s", card, |
| 1941 | use_case_table[out->usecase], |
| 1942 | status == CARD_STATUS_OFFLINE ? "offline" : "online"); |
| 1943 | |
| 1944 | if (status == CARD_STATUS_OFFLINE) |
| 1945 | out_on_error(stream); |
Haynes Mathew George | c735fb0 | 2016-06-30 18:00:28 -0700 | [diff] [blame] | 1946 | |
| 1947 | return; |
| 1948 | } |
| 1949 | |
Uday Kishore Pasupuleti | cec8ad8 | 2015-04-15 10:34:06 -0700 | [diff] [blame] | 1950 | #ifdef NO_AUDIO_OUT |
| 1951 | static ssize_t out_write_for_no_output(struct audio_stream_out *stream, |
| 1952 | const void *buffer, size_t bytes) |
| 1953 | { |
| 1954 | struct stream_out *out = (struct stream_out *)stream; |
| 1955 | |
| 1956 | /* No Output device supported other than BT for playback. |
| 1957 | * Sleep for the amount of buffer duration |
| 1958 | */ |
Eric Laurent | a147807 | 2015-09-21 17:21:52 -0700 | [diff] [blame] | 1959 | lock_output_stream(out); |
Uday Kishore Pasupuleti | b14d76b | 2015-11-13 20:06:37 -0800 | [diff] [blame] | 1960 | usleep(bytes * 1000000 / audio_stream_out_frame_size(&out->stream.common) / |
Uday Kishore Pasupuleti | cec8ad8 | 2015-04-15 10:34:06 -0700 | [diff] [blame] | 1961 | out_get_sample_rate(&out->stream.common)); |
| 1962 | pthread_mutex_unlock(&out->lock); |
| 1963 | return bytes; |
| 1964 | } |
| 1965 | #endif |
| 1966 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1967 | static ssize_t out_write(struct audio_stream_out *stream, const void *buffer, |
| 1968 | size_t bytes) |
| 1969 | { |
| 1970 | struct stream_out *out = (struct stream_out *)stream; |
| 1971 | struct audio_device *adev = out->dev; |
Eric Laurent | 6e89524 | 2013-09-05 16:10:57 -0700 | [diff] [blame] | 1972 | ssize_t ret = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1973 | |
Eric Laurent | a147807 | 2015-09-21 17:21:52 -0700 | [diff] [blame] | 1974 | lock_output_stream(out); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1975 | if (out->standby) { |
Ravi Kumar Alamanda | 59d296d | 2013-05-02 11:25:27 -0700 | [diff] [blame] | 1976 | out->standby = false; |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 1977 | pthread_mutex_lock(&adev->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1978 | ret = start_output_stream(out); |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 1979 | pthread_mutex_unlock(&adev->lock); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1980 | /* ToDo: If use case is compress offload should return 0 */ |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1981 | if (ret != 0) { |
Ravi Kumar Alamanda | 59d296d | 2013-05-02 11:25:27 -0700 | [diff] [blame] | 1982 | out->standby = true; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1983 | goto exit; |
| 1984 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1985 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1986 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1987 | if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) { |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 1988 | ALOGVV("%s: writing buffer (%d bytes) to compress device", __func__, bytes); |
| 1989 | if (out->send_new_metadata) { |
| 1990 | ALOGVV("send new gapless metadata"); |
| 1991 | compress_set_gapless_metadata(out->compr, &out->gapless_mdata); |
| 1992 | out->send_new_metadata = 0; |
| 1993 | } |
Eric Laurent | b49b3f6 | 2016-02-29 17:59:49 -0800 | [diff] [blame] | 1994 | unsigned int avail; |
| 1995 | struct timespec tstamp; |
| 1996 | ret = compress_get_hpointer(out->compr, &avail, &tstamp); |
| 1997 | /* Do not limit write size if the available frames count is unknown */ |
| 1998 | if (ret != 0) { |
| 1999 | avail = bytes; |
| 2000 | } |
| 2001 | if (avail == 0) { |
| 2002 | ret = 0; |
| 2003 | } else { |
| 2004 | if (avail > bytes) { |
| 2005 | avail = bytes; |
| 2006 | } |
| 2007 | ret = compress_write(out->compr, buffer, avail); |
| 2008 | ALOGVV("%s: writing buffer (%d bytes) to compress device returned %zd", |
| 2009 | __func__, avail, ret); |
| 2010 | } |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 2011 | |
Eric Laurent | 6e89524 | 2013-09-05 16:10:57 -0700 | [diff] [blame] | 2012 | if (ret >= 0 && ret < (ssize_t)bytes) { |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2013 | send_offload_cmd_l(out, OFFLOAD_CMD_WAIT_FOR_BUFFER); |
| 2014 | } |
Eric Laurent | b49b3f6 | 2016-02-29 17:59:49 -0800 | [diff] [blame] | 2015 | if (ret > 0 && !out->playback_started) { |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2016 | compress_start(out->compr); |
| 2017 | out->playback_started = 1; |
| 2018 | out->offload_state = OFFLOAD_STATE_PLAYING; |
| 2019 | } |
| 2020 | pthread_mutex_unlock(&out->lock); |
| 2021 | return ret; |
| 2022 | } else { |
| 2023 | if (out->pcm) { |
| 2024 | if (out->muted) |
| 2025 | memset((void *)buffer, 0, bytes); |
Haynes Mathew George | 88e6fb2 | 2015-08-19 11:51:34 -0700 | [diff] [blame] | 2026 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2027 | ALOGVV("%s: writing buffer (%d bytes) to pcm device", __func__, bytes); |
Haynes Mathew George | 88e6fb2 | 2015-08-19 11:51:34 -0700 | [diff] [blame] | 2028 | |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 2029 | long ns = pcm_bytes_to_frames(out->pcm, bytes)*1000000000LL/ |
| 2030 | out->config.rate; |
| 2031 | request_out_focus(out, ns); |
| 2032 | |
| 2033 | bool use_mmap = is_mmap_usecase(out->usecase) || out->realtime; |
| 2034 | if (use_mmap) |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 2035 | ret = pcm_mmap_write(out->pcm, (void *)buffer, bytes); |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 2036 | else |
| 2037 | ret = pcm_write(out->pcm, (void *)buffer, bytes); |
Haynes Mathew George | 88e6fb2 | 2015-08-19 11:51:34 -0700 | [diff] [blame] | 2038 | |
Glenn Kasten | 2ccd7ba | 2013-09-10 09:04:31 -0700 | [diff] [blame] | 2039 | if (ret == 0) |
| 2040 | out->written += bytes / (out->config.channels * sizeof(short)); |
Haynes Mathew George | 88e6fb2 | 2015-08-19 11:51:34 -0700 | [diff] [blame] | 2041 | |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 2042 | release_out_focus(out, ns); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2043 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2044 | } |
| 2045 | |
| 2046 | exit: |
| 2047 | pthread_mutex_unlock(&out->lock); |
| 2048 | |
| 2049 | if (ret != 0) { |
Haynes Mathew George | 3ddd3bd | 2016-07-07 20:01:53 -0700 | [diff] [blame] | 2050 | out_on_error(&out->stream.common); |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 2051 | if (out->pcm) |
vivek mehta | 1a9b7c0 | 2015-06-25 11:49:38 -0700 | [diff] [blame] | 2052 | ALOGE("%s: error %zu - %s", __func__, ret, pcm_get_error(out->pcm)); |
Haynes Mathew George | 3ddd3bd | 2016-07-07 20:01:53 -0700 | [diff] [blame] | 2053 | if (out->usecase != USECASE_AUDIO_PLAYBACK_OFFLOAD) |
| 2054 | usleep(bytes * 1000000 / audio_stream_out_frame_size(stream) / |
| 2055 | out_get_sample_rate(&out->stream.common)); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2056 | } |
| 2057 | return bytes; |
| 2058 | } |
| 2059 | |
| 2060 | static int out_get_render_position(const struct audio_stream_out *stream, |
| 2061 | uint32_t *dsp_frames) |
| 2062 | { |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2063 | struct stream_out *out = (struct stream_out *)stream; |
| 2064 | *dsp_frames = 0; |
| 2065 | if ((out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) && (dsp_frames != NULL)) { |
Eric Laurent | a147807 | 2015-09-21 17:21:52 -0700 | [diff] [blame] | 2066 | lock_output_stream(out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2067 | if (out->compr != NULL) { |
Andy Hung | 7171da2 | 2016-03-08 16:58:42 -0800 | [diff] [blame] | 2068 | unsigned long frames = 0; |
| 2069 | // TODO: check return value |
| 2070 | compress_get_tstamp(out->compr, &frames, &out->sample_rate); |
| 2071 | *dsp_frames = (uint32_t)frames; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2072 | ALOGVV("%s rendered frames %d sample_rate %d", |
| 2073 | __func__, *dsp_frames, out->sample_rate); |
| 2074 | } |
| 2075 | pthread_mutex_unlock(&out->lock); |
| 2076 | return 0; |
| 2077 | } else |
| 2078 | return -EINVAL; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2079 | } |
| 2080 | |
Haynes Mathew George | cc9649b | 2014-06-10 15:08:39 -0700 | [diff] [blame] | 2081 | static int out_add_audio_effect(const struct audio_stream *stream __unused, |
| 2082 | effect_handle_t effect __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2083 | { |
| 2084 | return 0; |
| 2085 | } |
| 2086 | |
Haynes Mathew George | cc9649b | 2014-06-10 15:08:39 -0700 | [diff] [blame] | 2087 | static int out_remove_audio_effect(const struct audio_stream *stream __unused, |
| 2088 | effect_handle_t effect __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2089 | { |
| 2090 | return 0; |
| 2091 | } |
| 2092 | |
Haynes Mathew George | cc9649b | 2014-06-10 15:08:39 -0700 | [diff] [blame] | 2093 | static int out_get_next_write_timestamp(const struct audio_stream_out *stream __unused, |
| 2094 | int64_t *timestamp __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2095 | { |
| 2096 | return -EINVAL; |
| 2097 | } |
| 2098 | |
Glenn Kasten | 2ccd7ba | 2013-09-10 09:04:31 -0700 | [diff] [blame] | 2099 | static int out_get_presentation_position(const struct audio_stream_out *stream, |
| 2100 | uint64_t *frames, struct timespec *timestamp) |
| 2101 | { |
| 2102 | struct stream_out *out = (struct stream_out *)stream; |
Andy Hung | 7171da2 | 2016-03-08 16:58:42 -0800 | [diff] [blame] | 2103 | int ret = -EINVAL; |
Eric Laurent | 949a089 | 2013-09-20 09:20:13 -0700 | [diff] [blame] | 2104 | unsigned long dsp_frames; |
Glenn Kasten | 2ccd7ba | 2013-09-10 09:04:31 -0700 | [diff] [blame] | 2105 | |
Eric Laurent | a147807 | 2015-09-21 17:21:52 -0700 | [diff] [blame] | 2106 | lock_output_stream(out); |
Glenn Kasten | 2ccd7ba | 2013-09-10 09:04:31 -0700 | [diff] [blame] | 2107 | |
Eric Laurent | 949a089 | 2013-09-20 09:20:13 -0700 | [diff] [blame] | 2108 | if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) { |
| 2109 | if (out->compr != NULL) { |
Andy Hung | 7171da2 | 2016-03-08 16:58:42 -0800 | [diff] [blame] | 2110 | // TODO: check return value |
Eric Laurent | 949a089 | 2013-09-20 09:20:13 -0700 | [diff] [blame] | 2111 | compress_get_tstamp(out->compr, &dsp_frames, |
| 2112 | &out->sample_rate); |
| 2113 | ALOGVV("%s rendered frames %ld sample_rate %d", |
| 2114 | __func__, dsp_frames, out->sample_rate); |
| 2115 | *frames = dsp_frames; |
| 2116 | ret = 0; |
| 2117 | /* this is the best we can do */ |
| 2118 | clock_gettime(CLOCK_MONOTONIC, timestamp); |
| 2119 | } |
| 2120 | } else { |
| 2121 | if (out->pcm) { |
vivek mehta | 1a9b7c0 | 2015-06-25 11:49:38 -0700 | [diff] [blame] | 2122 | unsigned int avail; |
Eric Laurent | 949a089 | 2013-09-20 09:20:13 -0700 | [diff] [blame] | 2123 | if (pcm_get_htimestamp(out->pcm, &avail, timestamp) == 0) { |
| 2124 | size_t kernel_buffer_size = out->config.period_size * out->config.period_count; |
Eric Laurent | 949a089 | 2013-09-20 09:20:13 -0700 | [diff] [blame] | 2125 | int64_t signed_frames = out->written - kernel_buffer_size + avail; |
Haynes Mathew George | 7ff216f | 2013-09-11 19:51:41 -0700 | [diff] [blame] | 2126 | // This adjustment accounts for buffering after app processor. |
| 2127 | // It is based on estimated DSP latency per use case, rather than exact. |
| 2128 | signed_frames -= |
| 2129 | (platform_render_latency(out->usecase) * out->sample_rate / 1000000LL); |
| 2130 | |
Eric Laurent | 949a089 | 2013-09-20 09:20:13 -0700 | [diff] [blame] | 2131 | // It would be unusual for this value to be negative, but check just in case ... |
| 2132 | if (signed_frames >= 0) { |
| 2133 | *frames = signed_frames; |
| 2134 | ret = 0; |
| 2135 | } |
Glenn Kasten | 2ccd7ba | 2013-09-10 09:04:31 -0700 | [diff] [blame] | 2136 | } |
| 2137 | } |
| 2138 | } |
| 2139 | |
| 2140 | pthread_mutex_unlock(&out->lock); |
| 2141 | |
| 2142 | return ret; |
| 2143 | } |
| 2144 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2145 | static int out_set_callback(struct audio_stream_out *stream, |
| 2146 | stream_callback_t callback, void *cookie) |
| 2147 | { |
| 2148 | struct stream_out *out = (struct stream_out *)stream; |
| 2149 | |
| 2150 | ALOGV("%s", __func__); |
Eric Laurent | a147807 | 2015-09-21 17:21:52 -0700 | [diff] [blame] | 2151 | lock_output_stream(out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2152 | out->offload_callback = callback; |
| 2153 | out->offload_cookie = cookie; |
| 2154 | pthread_mutex_unlock(&out->lock); |
| 2155 | return 0; |
| 2156 | } |
| 2157 | |
| 2158 | static int out_pause(struct audio_stream_out* stream) |
| 2159 | { |
| 2160 | struct stream_out *out = (struct stream_out *)stream; |
| 2161 | int status = -ENOSYS; |
| 2162 | ALOGV("%s", __func__); |
| 2163 | if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) { |
Eric Laurent | a147807 | 2015-09-21 17:21:52 -0700 | [diff] [blame] | 2164 | lock_output_stream(out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2165 | if (out->compr != NULL && out->offload_state == OFFLOAD_STATE_PLAYING) { |
| 2166 | status = compress_pause(out->compr); |
| 2167 | out->offload_state = OFFLOAD_STATE_PAUSED; |
| 2168 | } |
| 2169 | pthread_mutex_unlock(&out->lock); |
| 2170 | } |
| 2171 | return status; |
| 2172 | } |
| 2173 | |
| 2174 | static int out_resume(struct audio_stream_out* stream) |
| 2175 | { |
| 2176 | struct stream_out *out = (struct stream_out *)stream; |
| 2177 | int status = -ENOSYS; |
| 2178 | ALOGV("%s", __func__); |
| 2179 | if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) { |
| 2180 | status = 0; |
Eric Laurent | a147807 | 2015-09-21 17:21:52 -0700 | [diff] [blame] | 2181 | lock_output_stream(out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2182 | if (out->compr != NULL && out->offload_state == OFFLOAD_STATE_PAUSED) { |
| 2183 | status = compress_resume(out->compr); |
| 2184 | out->offload_state = OFFLOAD_STATE_PLAYING; |
| 2185 | } |
| 2186 | pthread_mutex_unlock(&out->lock); |
| 2187 | } |
| 2188 | return status; |
| 2189 | } |
| 2190 | |
| 2191 | static int out_drain(struct audio_stream_out* stream, audio_drain_type_t type ) |
| 2192 | { |
| 2193 | struct stream_out *out = (struct stream_out *)stream; |
| 2194 | int status = -ENOSYS; |
| 2195 | ALOGV("%s", __func__); |
| 2196 | if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) { |
Eric Laurent | a147807 | 2015-09-21 17:21:52 -0700 | [diff] [blame] | 2197 | lock_output_stream(out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2198 | if (type == AUDIO_DRAIN_EARLY_NOTIFY) |
| 2199 | status = send_offload_cmd_l(out, OFFLOAD_CMD_PARTIAL_DRAIN); |
| 2200 | else |
| 2201 | status = send_offload_cmd_l(out, OFFLOAD_CMD_DRAIN); |
| 2202 | pthread_mutex_unlock(&out->lock); |
| 2203 | } |
| 2204 | return status; |
| 2205 | } |
| 2206 | |
| 2207 | static int out_flush(struct audio_stream_out* stream) |
| 2208 | { |
| 2209 | struct stream_out *out = (struct stream_out *)stream; |
| 2210 | ALOGV("%s", __func__); |
| 2211 | if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) { |
Eric Laurent | a147807 | 2015-09-21 17:21:52 -0700 | [diff] [blame] | 2212 | lock_output_stream(out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2213 | stop_compressed_output_l(out); |
| 2214 | pthread_mutex_unlock(&out->lock); |
| 2215 | return 0; |
| 2216 | } |
| 2217 | return -ENOSYS; |
| 2218 | } |
| 2219 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2220 | /** audio_stream_in implementation **/ |
| 2221 | static uint32_t in_get_sample_rate(const struct audio_stream *stream) |
| 2222 | { |
| 2223 | struct stream_in *in = (struct stream_in *)stream; |
| 2224 | |
| 2225 | return in->config.rate; |
| 2226 | } |
| 2227 | |
Haynes Mathew George | cc9649b | 2014-06-10 15:08:39 -0700 | [diff] [blame] | 2228 | static int in_set_sample_rate(struct audio_stream *stream __unused, uint32_t rate __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2229 | { |
| 2230 | return -ENOSYS; |
| 2231 | } |
| 2232 | |
| 2233 | static size_t in_get_buffer_size(const struct audio_stream *stream) |
| 2234 | { |
| 2235 | struct stream_in *in = (struct stream_in *)stream; |
| 2236 | |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 2237 | return in->config.period_size * in->af_period_multiplier * |
| 2238 | audio_stream_in_frame_size((const struct audio_stream_in *)stream); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2239 | } |
| 2240 | |
| 2241 | static uint32_t in_get_channels(const struct audio_stream *stream) |
| 2242 | { |
| 2243 | struct stream_in *in = (struct stream_in *)stream; |
| 2244 | |
| 2245 | return in->channel_mask; |
| 2246 | } |
| 2247 | |
vivek mehta | 4ed66e6 | 2016-04-15 23:33:34 -0700 | [diff] [blame] | 2248 | static audio_format_t in_get_format(const struct audio_stream *stream) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2249 | { |
vivek mehta | 4ed66e6 | 2016-04-15 23:33:34 -0700 | [diff] [blame] | 2250 | struct stream_in *in = (struct stream_in *)stream; |
| 2251 | return in->format; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2252 | } |
| 2253 | |
Haynes Mathew George | cc9649b | 2014-06-10 15:08:39 -0700 | [diff] [blame] | 2254 | static int in_set_format(struct audio_stream *stream __unused, audio_format_t format __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2255 | { |
| 2256 | return -ENOSYS; |
| 2257 | } |
| 2258 | |
| 2259 | static int in_standby(struct audio_stream *stream) |
| 2260 | { |
| 2261 | struct stream_in *in = (struct stream_in *)stream; |
| 2262 | struct audio_device *adev = in->dev; |
| 2263 | int status = 0; |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 2264 | ALOGV("%s: enter", __func__); |
Eric Laurent | a147807 | 2015-09-21 17:21:52 -0700 | [diff] [blame] | 2265 | |
| 2266 | lock_input_stream(in); |
Ravi Kumar Alamanda | a417cc5 | 2015-05-01 16:41:56 -0700 | [diff] [blame] | 2267 | |
| 2268 | if (!in->standby && in->is_st_session) { |
Joe Onorato | 188b622 | 2016-03-01 11:02:27 -0800 | [diff] [blame] | 2269 | ALOGV("%s: sound trigger pcm stop lab", __func__); |
Ravi Kumar Alamanda | a417cc5 | 2015-05-01 16:41:56 -0700 | [diff] [blame] | 2270 | audio_extn_sound_trigger_stop_lab(in); |
| 2271 | in->standby = true; |
| 2272 | } |
| 2273 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2274 | if (!in->standby) { |
Haynes Mathew George | 88e6fb2 | 2015-08-19 11:51:34 -0700 | [diff] [blame] | 2275 | if (adev->adm_deregister_stream) |
| 2276 | adev->adm_deregister_stream(adev->adm_data, in->capture_handle); |
| 2277 | |
Ravi Kumar Alamanda | 8bba9e9 | 2013-11-11 21:09:07 -0800 | [diff] [blame] | 2278 | pthread_mutex_lock(&adev->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2279 | in->standby = true; |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 2280 | if (in->pcm) { |
| 2281 | pcm_close(in->pcm); |
| 2282 | in->pcm = NULL; |
| 2283 | } |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 2284 | adev->enable_voicerx = false; |
| 2285 | platform_set_echo_reference(adev, false, AUDIO_DEVICE_NONE ); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2286 | status = stop_input_stream(in); |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 2287 | pthread_mutex_unlock(&adev->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2288 | } |
| 2289 | pthread_mutex_unlock(&in->lock); |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 2290 | ALOGV("%s: exit: status(%d)", __func__, status); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2291 | return status; |
| 2292 | } |
| 2293 | |
Haynes Mathew George | cc9649b | 2014-06-10 15:08:39 -0700 | [diff] [blame] | 2294 | static int in_dump(const struct audio_stream *stream __unused, int fd __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2295 | { |
| 2296 | return 0; |
| 2297 | } |
| 2298 | |
| 2299 | static int in_set_parameters(struct audio_stream *stream, const char *kvpairs) |
| 2300 | { |
| 2301 | struct stream_in *in = (struct stream_in *)stream; |
| 2302 | struct audio_device *adev = in->dev; |
| 2303 | struct str_parms *parms; |
| 2304 | char *str; |
| 2305 | char value[32]; |
| 2306 | int ret, val = 0; |
Eric Laurent | 03f0943 | 2014-03-25 18:09:11 -0700 | [diff] [blame] | 2307 | int status = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2308 | |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 2309 | ALOGV("%s: enter: kvpairs=%s", __func__, kvpairs); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2310 | parms = str_parms_create_str(kvpairs); |
| 2311 | |
| 2312 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_INPUT_SOURCE, value, sizeof(value)); |
| 2313 | |
Eric Laurent | a147807 | 2015-09-21 17:21:52 -0700 | [diff] [blame] | 2314 | lock_input_stream(in); |
| 2315 | |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 2316 | pthread_mutex_lock(&adev->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2317 | if (ret >= 0) { |
| 2318 | val = atoi(value); |
| 2319 | /* no audio source uses val == 0 */ |
| 2320 | if ((in->source != val) && (val != 0)) { |
| 2321 | in->source = val; |
| 2322 | } |
| 2323 | } |
| 2324 | |
| 2325 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, value, sizeof(value)); |
Eric Laurent | 03f0943 | 2014-03-25 18:09:11 -0700 | [diff] [blame] | 2326 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2327 | if (ret >= 0) { |
| 2328 | val = atoi(value); |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 2329 | if (((int)in->device != val) && (val != 0)) { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2330 | in->device = val; |
| 2331 | /* If recording is in progress, change the tx device to new device */ |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 2332 | if (!in->standby) { |
| 2333 | ALOGV("update input routing change"); |
| 2334 | in->routing_change = true; |
| 2335 | select_devices(adev, in->usecase); |
| 2336 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2337 | } |
| 2338 | } |
| 2339 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2340 | pthread_mutex_unlock(&adev->lock); |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 2341 | pthread_mutex_unlock(&in->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2342 | |
| 2343 | str_parms_destroy(parms); |
Eric Laurent | 03f0943 | 2014-03-25 18:09:11 -0700 | [diff] [blame] | 2344 | ALOGV("%s: exit: status(%d)", __func__, status); |
| 2345 | return status; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2346 | } |
| 2347 | |
Haynes Mathew George | cc9649b | 2014-06-10 15:08:39 -0700 | [diff] [blame] | 2348 | static char* in_get_parameters(const struct audio_stream *stream __unused, |
| 2349 | const char *keys __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2350 | { |
| 2351 | return strdup(""); |
| 2352 | } |
| 2353 | |
Haynes Mathew George | cc9649b | 2014-06-10 15:08:39 -0700 | [diff] [blame] | 2354 | static int in_set_gain(struct audio_stream_in *stream __unused, float gain __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2355 | { |
| 2356 | return 0; |
| 2357 | } |
| 2358 | |
Haynes Mathew George | c735fb0 | 2016-06-30 18:00:28 -0700 | [diff] [blame] | 2359 | static void in_snd_mon_cb(void * stream, struct str_parms * parms) |
| 2360 | { |
| 2361 | if (!stream || !parms) |
| 2362 | return; |
| 2363 | |
| 2364 | struct stream_in *in = (struct stream_in *)stream; |
| 2365 | struct audio_device *adev = in->dev; |
| 2366 | |
| 2367 | card_status_t status; |
| 2368 | int card; |
| 2369 | if (parse_snd_card_status(parms, &card, &status) < 0) |
| 2370 | return; |
| 2371 | |
| 2372 | pthread_mutex_lock(&adev->lock); |
| 2373 | bool valid_cb = (card == adev->snd_card); |
| 2374 | pthread_mutex_unlock(&adev->lock); |
| 2375 | |
| 2376 | if (!valid_cb) |
| 2377 | return; |
| 2378 | |
| 2379 | lock_input_stream(in); |
| 2380 | if (in->card_status != status) |
| 2381 | in->card_status = status; |
| 2382 | pthread_mutex_unlock(&in->lock); |
| 2383 | |
| 2384 | ALOGW("in_snd_mon_cb for card %d usecase %s, status %s", card, |
| 2385 | use_case_table[in->usecase], |
| 2386 | status == CARD_STATUS_OFFLINE ? "offline" : "online"); |
| 2387 | |
| 2388 | // a better solution would be to report error back to AF and let |
| 2389 | // it put the stream to standby |
| 2390 | if (status == CARD_STATUS_OFFLINE) |
| 2391 | in_standby(&in->stream.common); |
| 2392 | |
| 2393 | return; |
| 2394 | } |
| 2395 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2396 | static ssize_t in_read(struct audio_stream_in *stream, void *buffer, |
| 2397 | size_t bytes) |
| 2398 | { |
| 2399 | struct stream_in *in = (struct stream_in *)stream; |
| 2400 | struct audio_device *adev = in->dev; |
| 2401 | int i, ret = -1; |
vivek mehta | 4ed66e6 | 2016-04-15 23:33:34 -0700 | [diff] [blame] | 2402 | int *int_buf_stream = NULL; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2403 | |
Eric Laurent | a147807 | 2015-09-21 17:21:52 -0700 | [diff] [blame] | 2404 | lock_input_stream(in); |
| 2405 | |
Ravi Kumar Alamanda | a417cc5 | 2015-05-01 16:41:56 -0700 | [diff] [blame] | 2406 | if (in->is_st_session) { |
| 2407 | ALOGVV(" %s: reading on st session bytes=%d", __func__, bytes); |
| 2408 | /* Read from sound trigger HAL */ |
| 2409 | audio_extn_sound_trigger_read(in, buffer, bytes); |
| 2410 | pthread_mutex_unlock(&in->lock); |
| 2411 | return bytes; |
| 2412 | } |
| 2413 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2414 | if (in->standby) { |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 2415 | pthread_mutex_lock(&adev->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2416 | ret = start_input_stream(in); |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 2417 | pthread_mutex_unlock(&adev->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2418 | if (ret != 0) { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2419 | goto exit; |
| 2420 | } |
| 2421 | in->standby = 0; |
| 2422 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2423 | |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 2424 | //what's the duration requested by the client? |
| 2425 | long ns = pcm_bytes_to_frames(in->pcm, bytes)*1000000000LL/ |
| 2426 | in->config.rate; |
| 2427 | request_in_focus(in, ns); |
Haynes Mathew George | 88e6fb2 | 2015-08-19 11:51:34 -0700 | [diff] [blame] | 2428 | |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 2429 | bool use_mmap = is_mmap_usecase(in->usecase) || in->realtime; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2430 | if (in->pcm) { |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 2431 | if (use_mmap) { |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 2432 | ret = pcm_mmap_read(in->pcm, buffer, bytes); |
vivek mehta | 4ed66e6 | 2016-04-15 23:33:34 -0700 | [diff] [blame] | 2433 | } else { |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 2434 | ret = pcm_read(in->pcm, buffer, bytes); |
Eric Laurent | f8b50aa | 2016-05-06 11:03:53 -0700 | [diff] [blame] | 2435 | } |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 2436 | if (ret < 0) { |
| 2437 | ALOGE("Failed to read w/err %s", strerror(errno)); |
| 2438 | ret = -errno; |
| 2439 | } |
Eric Laurent | f8b50aa | 2016-05-06 11:03:53 -0700 | [diff] [blame] | 2440 | if (!ret && bytes > 0 && (in->format == AUDIO_FORMAT_PCM_8_24_BIT)) { |
| 2441 | if (bytes % 4 == 0) { |
| 2442 | /* data from DSP comes in 24_8 format, convert it to 8_24 */ |
| 2443 | int_buf_stream = buffer; |
| 2444 | for (size_t itt=0; itt < bytes/4 ; itt++) { |
| 2445 | int_buf_stream[itt] >>= 8; |
vivek mehta | 4ed66e6 | 2016-04-15 23:33:34 -0700 | [diff] [blame] | 2446 | } |
Eric Laurent | f8b50aa | 2016-05-06 11:03:53 -0700 | [diff] [blame] | 2447 | } else { |
| 2448 | ALOGE("%s: !!! something wrong !!! ... data not 32 bit aligned ", __func__); |
| 2449 | ret = -EINVAL; |
| 2450 | goto exit; |
vivek mehta | 4ed66e6 | 2016-04-15 23:33:34 -0700 | [diff] [blame] | 2451 | } |
| 2452 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2453 | } |
| 2454 | |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 2455 | release_in_focus(in, ns); |
Haynes Mathew George | 88e6fb2 | 2015-08-19 11:51:34 -0700 | [diff] [blame] | 2456 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2457 | /* |
| 2458 | * Instead of writing zeroes here, we could trust the hardware |
| 2459 | * to always provide zeroes when muted. |
Eric Laurent | 7b2b5ab | 2014-09-14 12:29:59 -0700 | [diff] [blame] | 2460 | * No need to acquire adev->lock to read mic_muted here as we don't change its state. |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2461 | */ |
Eric Laurent | 7b2b5ab | 2014-09-14 12:29:59 -0700 | [diff] [blame] | 2462 | if (ret == 0 && adev->mic_muted && in->usecase != USECASE_AUDIO_RECORD_AFE_PROXY) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2463 | memset(buffer, 0, bytes); |
| 2464 | |
| 2465 | exit: |
| 2466 | pthread_mutex_unlock(&in->lock); |
| 2467 | |
| 2468 | if (ret != 0) { |
| 2469 | in_standby(&in->stream.common); |
| 2470 | ALOGV("%s: read failed - sleeping for buffer duration", __func__); |
Eric Laurent | fdf296a | 2014-07-03 16:41:51 -0700 | [diff] [blame] | 2471 | usleep(bytes * 1000000 / audio_stream_in_frame_size(stream) / |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2472 | in_get_sample_rate(&in->stream.common)); |
Andy Hung | c858987 | 2016-03-10 16:37:48 -0800 | [diff] [blame] | 2473 | memset(buffer, 0, bytes); // clear return data |
| 2474 | } |
| 2475 | if (bytes > 0) { |
Andy Hung | 6ebe596 | 2016-01-15 17:46:57 -0800 | [diff] [blame] | 2476 | in->frames_read += bytes / audio_stream_in_frame_size(stream); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2477 | } |
| 2478 | return bytes; |
| 2479 | } |
| 2480 | |
Haynes Mathew George | cc9649b | 2014-06-10 15:08:39 -0700 | [diff] [blame] | 2481 | static uint32_t in_get_input_frames_lost(struct audio_stream_in *stream __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2482 | { |
| 2483 | return 0; |
| 2484 | } |
| 2485 | |
Andy Hung | 6ebe596 | 2016-01-15 17:46:57 -0800 | [diff] [blame] | 2486 | static int in_get_capture_position(const struct audio_stream_in *stream, |
| 2487 | int64_t *frames, int64_t *time) |
| 2488 | { |
| 2489 | if (stream == NULL || frames == NULL || time == NULL) { |
| 2490 | return -EINVAL; |
| 2491 | } |
| 2492 | struct stream_in *in = (struct stream_in *)stream; |
| 2493 | int ret = -ENOSYS; |
| 2494 | |
| 2495 | lock_input_stream(in); |
| 2496 | if (in->pcm) { |
| 2497 | struct timespec timestamp; |
| 2498 | unsigned int avail; |
| 2499 | if (pcm_get_htimestamp(in->pcm, &avail, ×tamp) == 0) { |
| 2500 | *frames = in->frames_read + avail; |
| 2501 | *time = timestamp.tv_sec * 1000000000LL + timestamp.tv_nsec; |
| 2502 | ret = 0; |
| 2503 | } |
| 2504 | } |
| 2505 | pthread_mutex_unlock(&in->lock); |
| 2506 | return ret; |
| 2507 | } |
| 2508 | |
Ravi Kumar Alamanda | f70ffb4 | 2013-04-16 15:55:53 -0700 | [diff] [blame] | 2509 | static int add_remove_audio_effect(const struct audio_stream *stream, |
| 2510 | effect_handle_t effect, |
| 2511 | bool enable) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2512 | { |
Ravi Kumar Alamanda | f70ffb4 | 2013-04-16 15:55:53 -0700 | [diff] [blame] | 2513 | struct stream_in *in = (struct stream_in *)stream; |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 2514 | struct audio_device *adev = in->dev; |
Ravi Kumar Alamanda | f70ffb4 | 2013-04-16 15:55:53 -0700 | [diff] [blame] | 2515 | int status = 0; |
| 2516 | effect_descriptor_t desc; |
| 2517 | |
| 2518 | status = (*effect)->get_descriptor(effect, &desc); |
| 2519 | if (status != 0) |
| 2520 | return status; |
| 2521 | |
Eric Laurent | a147807 | 2015-09-21 17:21:52 -0700 | [diff] [blame] | 2522 | lock_input_stream(in); |
Ravi Kumar Alamanda | f70ffb4 | 2013-04-16 15:55:53 -0700 | [diff] [blame] | 2523 | pthread_mutex_lock(&in->dev->lock); |
Eric Laurent | 50a38ed | 2015-10-14 18:48:06 -0700 | [diff] [blame] | 2524 | if ((in->source == AUDIO_SOURCE_VOICE_COMMUNICATION || |
vivek mehta | 733c1df | 2016-04-04 15:09:24 -0700 | [diff] [blame] | 2525 | in->source == AUDIO_SOURCE_VOICE_RECOGNITION || |
Eric Laurent | 50a38ed | 2015-10-14 18:48:06 -0700 | [diff] [blame] | 2526 | adev->mode == AUDIO_MODE_IN_COMMUNICATION) && |
Ravi Kumar Alamanda | f70ffb4 | 2013-04-16 15:55:53 -0700 | [diff] [blame] | 2527 | in->enable_aec != enable && |
| 2528 | (memcmp(&desc.type, FX_IID_AEC, sizeof(effect_uuid_t)) == 0)) { |
| 2529 | in->enable_aec = enable; |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 2530 | if (!enable) |
| 2531 | platform_set_echo_reference(in->dev, enable, AUDIO_DEVICE_NONE); |
vivek mehta | 733c1df | 2016-04-04 15:09:24 -0700 | [diff] [blame] | 2532 | if (in->source == AUDIO_SOURCE_VOICE_COMMUNICATION || |
| 2533 | adev->mode == AUDIO_MODE_IN_COMMUNICATION) { |
| 2534 | adev->enable_voicerx = enable; |
| 2535 | struct audio_usecase *usecase; |
| 2536 | struct listnode *node; |
| 2537 | list_for_each(node, &adev->usecase_list) { |
| 2538 | usecase = node_to_item(node, struct audio_usecase, list); |
| 2539 | if (usecase->type == PCM_PLAYBACK) { |
| 2540 | select_devices(adev, usecase->id); |
| 2541 | break; |
| 2542 | } |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 2543 | } |
| 2544 | } |
Ravi Kumar Alamanda | f70ffb4 | 2013-04-16 15:55:53 -0700 | [diff] [blame] | 2545 | if (!in->standby) |
| 2546 | select_devices(in->dev, in->usecase); |
| 2547 | } |
Ravi Kumar Alamanda | 3ad4e1b | 2014-06-03 00:08:15 -0700 | [diff] [blame] | 2548 | if (in->enable_ns != enable && |
| 2549 | (memcmp(&desc.type, FX_IID_NS, sizeof(effect_uuid_t)) == 0)) { |
| 2550 | in->enable_ns = enable; |
| 2551 | if (!in->standby) |
| 2552 | select_devices(in->dev, in->usecase); |
| 2553 | } |
Ravi Kumar Alamanda | f70ffb4 | 2013-04-16 15:55:53 -0700 | [diff] [blame] | 2554 | pthread_mutex_unlock(&in->dev->lock); |
| 2555 | pthread_mutex_unlock(&in->lock); |
| 2556 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2557 | return 0; |
| 2558 | } |
| 2559 | |
Ravi Kumar Alamanda | f70ffb4 | 2013-04-16 15:55:53 -0700 | [diff] [blame] | 2560 | static int in_add_audio_effect(const struct audio_stream *stream, |
| 2561 | effect_handle_t effect) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2562 | { |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 2563 | ALOGV("%s: effect %p", __func__, effect); |
Ravi Kumar Alamanda | f70ffb4 | 2013-04-16 15:55:53 -0700 | [diff] [blame] | 2564 | return add_remove_audio_effect(stream, effect, true); |
| 2565 | } |
| 2566 | |
| 2567 | static int in_remove_audio_effect(const struct audio_stream *stream, |
| 2568 | effect_handle_t effect) |
| 2569 | { |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 2570 | ALOGV("%s: effect %p", __func__, effect); |
Ravi Kumar Alamanda | f70ffb4 | 2013-04-16 15:55:53 -0700 | [diff] [blame] | 2571 | return add_remove_audio_effect(stream, effect, false); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2572 | } |
| 2573 | |
| 2574 | static int adev_open_output_stream(struct audio_hw_device *dev, |
| 2575 | audio_io_handle_t handle, |
| 2576 | audio_devices_t devices, |
| 2577 | audio_output_flags_t flags, |
| 2578 | struct audio_config *config, |
Eric Laurent | 91975a6 | 2014-07-27 17:15:50 -0700 | [diff] [blame] | 2579 | struct audio_stream_out **stream_out, |
| 2580 | const char *address __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2581 | { |
| 2582 | struct audio_device *adev = (struct audio_device *)dev; |
| 2583 | struct stream_out *out; |
| 2584 | int i, ret; |
| 2585 | |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 2586 | ALOGV("%s: enter: sample_rate(%d) channel_mask(%#x) devices(%#x) flags(%#x)", |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2587 | __func__, config->sample_rate, config->channel_mask, devices, flags); |
| 2588 | *stream_out = NULL; |
| 2589 | out = (struct stream_out *)calloc(1, sizeof(struct stream_out)); |
| 2590 | |
| 2591 | if (devices == AUDIO_DEVICE_NONE) |
| 2592 | devices = AUDIO_DEVICE_OUT_SPEAKER; |
| 2593 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2594 | out->flags = flags; |
| 2595 | out->devices = devices; |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2596 | out->dev = adev; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2597 | out->format = config->format; |
| 2598 | out->sample_rate = config->sample_rate; |
| 2599 | out->channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 2600 | out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_STEREO; |
Eric Laurent | c4aef75 | 2013-09-12 17:45:53 -0700 | [diff] [blame] | 2601 | out->handle = handle; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2602 | |
| 2603 | /* Init use case and pcm_config */ |
| 2604 | if (out->flags & AUDIO_OUTPUT_FLAG_DIRECT && |
Eric Laurent | 7f24504 | 2013-09-30 19:22:50 -0700 | [diff] [blame] | 2605 | !(out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) && |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2606 | out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 2607 | pthread_mutex_lock(&adev->lock); |
| 2608 | ret = read_hdmi_channel_masks(out); |
| 2609 | pthread_mutex_unlock(&adev->lock); |
Eric Laurent | 07eeafd | 2013-10-06 12:52:49 -0700 | [diff] [blame] | 2610 | if (ret != 0) |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 2611 | goto error_open; |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 2612 | |
| 2613 | if (config->sample_rate == 0) |
| 2614 | config->sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; |
| 2615 | if (config->channel_mask == 0) |
| 2616 | config->channel_mask = AUDIO_CHANNEL_OUT_5POINT1; |
Eric Laurent | ad1cec2 | 2015-12-16 10:12:27 -0800 | [diff] [blame] | 2617 | if (config->format == AUDIO_FORMAT_DEFAULT) |
| 2618 | config->format = AUDIO_FORMAT_PCM_16_BIT; |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 2619 | |
| 2620 | out->channel_mask = config->channel_mask; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2621 | out->sample_rate = config->sample_rate; |
Eric Laurent | ad1cec2 | 2015-12-16 10:12:27 -0800 | [diff] [blame] | 2622 | out->format = config->format; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2623 | out->usecase = USECASE_AUDIO_PLAYBACK_MULTI_CH; |
| 2624 | out->config = pcm_config_hdmi_multi; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2625 | out->config.rate = config->sample_rate; |
Eric Laurent | 0de8d1f | 2014-07-01 20:34:45 -0700 | [diff] [blame] | 2626 | out->config.channels = audio_channel_count_from_out_mask(out->channel_mask); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2627 | out->config.period_size = HDMI_MULTI_PERIOD_BYTES / (out->config.channels * 2); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2628 | } else if (out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) { |
Haynes Mathew George | 3580769 | 2016-07-07 20:04:54 -0700 | [diff] [blame] | 2629 | pthread_mutex_lock(&adev->lock); |
| 2630 | bool offline = (adev->card_status == CARD_STATUS_OFFLINE); |
| 2631 | pthread_mutex_unlock(&adev->lock); |
| 2632 | |
| 2633 | // reject offload during card offline to allow |
| 2634 | // fallback to s/w paths |
| 2635 | if (offline) { |
| 2636 | ret = -ENODEV; |
| 2637 | goto error_open; |
| 2638 | } |
| 2639 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2640 | if (config->offload_info.version != AUDIO_INFO_INITIALIZER.version || |
| 2641 | config->offload_info.size != AUDIO_INFO_INITIALIZER.size) { |
| 2642 | ALOGE("%s: Unsupported Offload information", __func__); |
| 2643 | ret = -EINVAL; |
| 2644 | goto error_open; |
| 2645 | } |
| 2646 | if (!is_supported_format(config->offload_info.format)) { |
| 2647 | ALOGE("%s: Unsupported audio format", __func__); |
| 2648 | ret = -EINVAL; |
| 2649 | goto error_open; |
| 2650 | } |
| 2651 | |
| 2652 | out->compr_config.codec = (struct snd_codec *) |
| 2653 | calloc(1, sizeof(struct snd_codec)); |
| 2654 | |
| 2655 | out->usecase = USECASE_AUDIO_PLAYBACK_OFFLOAD; |
| 2656 | if (config->offload_info.channel_mask) |
| 2657 | out->channel_mask = config->offload_info.channel_mask; |
| 2658 | else if (config->channel_mask) |
| 2659 | out->channel_mask = config->channel_mask; |
| 2660 | out->format = config->offload_info.format; |
| 2661 | out->sample_rate = config->offload_info.sample_rate; |
| 2662 | |
| 2663 | out->stream.set_callback = out_set_callback; |
| 2664 | out->stream.pause = out_pause; |
| 2665 | out->stream.resume = out_resume; |
| 2666 | out->stream.drain = out_drain; |
| 2667 | out->stream.flush = out_flush; |
| 2668 | |
| 2669 | out->compr_config.codec->id = |
| 2670 | get_snd_codec_id(config->offload_info.format); |
| 2671 | out->compr_config.fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE; |
| 2672 | out->compr_config.fragments = COMPRESS_OFFLOAD_NUM_FRAGMENTS; |
Eric Laurent | 1ccf397 | 2014-10-23 14:42:59 -0700 | [diff] [blame] | 2673 | out->compr_config.codec->sample_rate = config->offload_info.sample_rate; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2674 | out->compr_config.codec->bit_rate = |
| 2675 | config->offload_info.bit_rate; |
| 2676 | out->compr_config.codec->ch_in = |
Eric Laurent | 0de8d1f | 2014-07-01 20:34:45 -0700 | [diff] [blame] | 2677 | audio_channel_count_from_out_mask(config->channel_mask); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2678 | out->compr_config.codec->ch_out = out->compr_config.codec->ch_in; |
| 2679 | |
| 2680 | if (flags & AUDIO_OUTPUT_FLAG_NON_BLOCKING) |
| 2681 | out->non_blocking = 1; |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 2682 | |
| 2683 | out->send_new_metadata = 1; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2684 | create_offload_callback_thread(out); |
| 2685 | ALOGV("%s: offloaded output offload_info version %04x bit rate %d", |
| 2686 | __func__, config->offload_info.version, |
| 2687 | config->offload_info.bit_rate); |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 2688 | } else if (out->devices == AUDIO_DEVICE_OUT_TELEPHONY_TX) { |
| 2689 | if (config->sample_rate == 0) |
| 2690 | config->sample_rate = AFE_PROXY_SAMPLING_RATE; |
| 2691 | if (config->sample_rate != 48000 && config->sample_rate != 16000 && |
| 2692 | config->sample_rate != 8000) { |
| 2693 | config->sample_rate = AFE_PROXY_SAMPLING_RATE; |
| 2694 | ret = -EINVAL; |
| 2695 | goto error_open; |
| 2696 | } |
| 2697 | out->sample_rate = config->sample_rate; |
| 2698 | out->config.rate = config->sample_rate; |
| 2699 | if (config->format == AUDIO_FORMAT_DEFAULT) |
| 2700 | config->format = AUDIO_FORMAT_PCM_16_BIT; |
| 2701 | if (config->format != AUDIO_FORMAT_PCM_16_BIT) { |
| 2702 | config->format = AUDIO_FORMAT_PCM_16_BIT; |
| 2703 | ret = -EINVAL; |
| 2704 | goto error_open; |
| 2705 | } |
| 2706 | out->format = config->format; |
| 2707 | out->usecase = USECASE_AUDIO_PLAYBACK_AFE_PROXY; |
| 2708 | out->config = pcm_config_afe_proxy_playback; |
| 2709 | adev->voice_tx_output = out; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2710 | } else { |
Andy Hung | 6fcba9c | 2014-03-18 11:53:32 -0700 | [diff] [blame] | 2711 | if (out->flags & AUDIO_OUTPUT_FLAG_DEEP_BUFFER) { |
| 2712 | out->usecase = USECASE_AUDIO_PLAYBACK_DEEP_BUFFER; |
| 2713 | out->config = pcm_config_deep_buffer; |
Ravi Kumar Alamanda | f78a4d9 | 2015-04-24 15:18:23 -0700 | [diff] [blame] | 2714 | } else if (out->flags & AUDIO_OUTPUT_FLAG_TTS) { |
| 2715 | out->usecase = USECASE_AUDIO_PLAYBACK_TTS; |
| 2716 | out->config = pcm_config_deep_buffer; |
Ravi Kumar Alamanda | 2bc7b02 | 2015-06-25 20:08:01 -0700 | [diff] [blame] | 2717 | } else if (out->flags & AUDIO_OUTPUT_FLAG_RAW) { |
| 2718 | out->usecase = USECASE_AUDIO_PLAYBACK_ULL; |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 2719 | out->realtime = may_use_noirq_mode(adev, USECASE_AUDIO_PLAYBACK_ULL, out->flags); |
| 2720 | out->usecase = USECASE_AUDIO_PLAYBACK_ULL; |
| 2721 | out->config = out->realtime ? pcm_config_rt : pcm_config_low_latency; |
Andy Hung | 6fcba9c | 2014-03-18 11:53:32 -0700 | [diff] [blame] | 2722 | } else { |
| 2723 | out->usecase = USECASE_AUDIO_PLAYBACK_LOW_LATENCY; |
| 2724 | out->config = pcm_config_low_latency; |
| 2725 | } |
| 2726 | if (config->format != audio_format_from_pcm_format(out->config.format)) { |
| 2727 | if (k_enable_extended_precision |
| 2728 | && pcm_params_format_test(adev->use_case_table[out->usecase], |
| 2729 | pcm_format_from_audio_format(config->format))) { |
| 2730 | out->config.format = pcm_format_from_audio_format(config->format); |
| 2731 | /* out->format already set to config->format */ |
| 2732 | } else { |
| 2733 | /* deny the externally proposed config format |
| 2734 | * and use the one specified in audio_hw layer configuration. |
| 2735 | * Note: out->format is returned by out->stream.common.get_format() |
| 2736 | * and is used to set config->format in the code several lines below. |
| 2737 | */ |
| 2738 | out->format = audio_format_from_pcm_format(out->config.format); |
| 2739 | } |
| 2740 | } |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2741 | out->sample_rate = out->config.rate; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2742 | } |
Andy Hung | 6fcba9c | 2014-03-18 11:53:32 -0700 | [diff] [blame] | 2743 | ALOGV("%s: Usecase(%s) config->format %#x out->config.format %#x\n", |
| 2744 | __func__, use_case_table[out->usecase], config->format, out->config.format); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2745 | |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 2746 | if (flags & AUDIO_OUTPUT_FLAG_PRIMARY) { |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 2747 | if (adev->primary_output == NULL) |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 2748 | adev->primary_output = out; |
| 2749 | else { |
| 2750 | ALOGE("%s: Primary output is already opened", __func__); |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 2751 | ret = -EEXIST; |
| 2752 | goto error_open; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 2753 | } |
| 2754 | } |
| 2755 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2756 | /* Check if this usecase is already existing */ |
| 2757 | pthread_mutex_lock(&adev->lock); |
| 2758 | if (get_usecase_from_list(adev, out->usecase) != NULL) { |
| 2759 | ALOGE("%s: Usecase (%d) is already present", __func__, out->usecase); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2760 | pthread_mutex_unlock(&adev->lock); |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 2761 | ret = -EEXIST; |
| 2762 | goto error_open; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2763 | } |
| 2764 | pthread_mutex_unlock(&adev->lock); |
| 2765 | |
| 2766 | out->stream.common.get_sample_rate = out_get_sample_rate; |
| 2767 | out->stream.common.set_sample_rate = out_set_sample_rate; |
| 2768 | out->stream.common.get_buffer_size = out_get_buffer_size; |
| 2769 | out->stream.common.get_channels = out_get_channels; |
| 2770 | out->stream.common.get_format = out_get_format; |
| 2771 | out->stream.common.set_format = out_set_format; |
| 2772 | out->stream.common.standby = out_standby; |
| 2773 | out->stream.common.dump = out_dump; |
| 2774 | out->stream.common.set_parameters = out_set_parameters; |
| 2775 | out->stream.common.get_parameters = out_get_parameters; |
| 2776 | out->stream.common.add_audio_effect = out_add_audio_effect; |
| 2777 | out->stream.common.remove_audio_effect = out_remove_audio_effect; |
| 2778 | out->stream.get_latency = out_get_latency; |
| 2779 | out->stream.set_volume = out_set_volume; |
Uday Kishore Pasupuleti | cec8ad8 | 2015-04-15 10:34:06 -0700 | [diff] [blame] | 2780 | #ifdef NO_AUDIO_OUT |
| 2781 | out->stream.write = out_write_for_no_output; |
| 2782 | #else |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2783 | out->stream.write = out_write; |
Uday Kishore Pasupuleti | cec8ad8 | 2015-04-15 10:34:06 -0700 | [diff] [blame] | 2784 | #endif |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2785 | out->stream.get_render_position = out_get_render_position; |
| 2786 | out->stream.get_next_write_timestamp = out_get_next_write_timestamp; |
Glenn Kasten | 2ccd7ba | 2013-09-10 09:04:31 -0700 | [diff] [blame] | 2787 | out->stream.get_presentation_position = out_get_presentation_position; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2788 | |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 2789 | out->af_period_multiplier = out->realtime ? af_period_multiplier : 1; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2790 | out->standby = 1; |
Eric Laurent | a9024de | 2013-04-04 09:19:12 -0700 | [diff] [blame] | 2791 | /* out->muted = false; by calloc() */ |
Glenn Kasten | 2ccd7ba | 2013-09-10 09:04:31 -0700 | [diff] [blame] | 2792 | /* out->written = 0; by calloc() */ |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2793 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2794 | pthread_mutex_init(&out->lock, (const pthread_mutexattr_t *) NULL); |
Eric Laurent | a147807 | 2015-09-21 17:21:52 -0700 | [diff] [blame] | 2795 | pthread_mutex_init(&out->pre_lock, (const pthread_mutexattr_t *) NULL); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2796 | pthread_cond_init(&out->cond, (const pthread_condattr_t *) NULL); |
| 2797 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2798 | config->format = out->stream.common.get_format(&out->stream.common); |
| 2799 | config->channel_mask = out->stream.common.get_channels(&out->stream.common); |
| 2800 | config->sample_rate = out->stream.common.get_sample_rate(&out->stream.common); |
| 2801 | |
Haynes Mathew George | c735fb0 | 2016-06-30 18:00:28 -0700 | [diff] [blame] | 2802 | |
| 2803 | /* |
| 2804 | By locking output stream before registering, we allow the callback |
| 2805 | to update stream's state only after stream's initial state is set to |
| 2806 | adev state. |
| 2807 | */ |
| 2808 | lock_output_stream(out); |
| 2809 | audio_extn_snd_mon_register_listener(out, out_snd_mon_cb); |
| 2810 | pthread_mutex_lock(&adev->lock); |
| 2811 | out->card_status = adev->card_status; |
| 2812 | pthread_mutex_unlock(&adev->lock); |
| 2813 | pthread_mutex_unlock(&out->lock); |
| 2814 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2815 | *stream_out = &out->stream; |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 2816 | ALOGV("%s: exit", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2817 | return 0; |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 2818 | |
| 2819 | error_open: |
| 2820 | free(out); |
| 2821 | *stream_out = NULL; |
Eric Laurent | 2bafff1 | 2016-03-17 12:17:23 -0700 | [diff] [blame] | 2822 | ALOGW("%s: exit: ret %d", __func__, ret); |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 2823 | return ret; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2824 | } |
| 2825 | |
Haynes Mathew George | cc9649b | 2014-06-10 15:08:39 -0700 | [diff] [blame] | 2826 | static void adev_close_output_stream(struct audio_hw_device *dev __unused, |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2827 | struct audio_stream_out *stream) |
| 2828 | { |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2829 | struct stream_out *out = (struct stream_out *)stream; |
| 2830 | struct audio_device *adev = out->dev; |
| 2831 | |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 2832 | ALOGV("%s: enter", __func__); |
Haynes Mathew George | c735fb0 | 2016-06-30 18:00:28 -0700 | [diff] [blame] | 2833 | |
| 2834 | // must deregister from sndmonitor first to prevent races |
| 2835 | // between the callback and close_stream |
| 2836 | audio_extn_snd_mon_unregister_listener(out); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2837 | out_standby(&stream->common); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2838 | if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) { |
| 2839 | destroy_offload_callback_thread(out); |
| 2840 | |
| 2841 | if (out->compr_config.codec != NULL) |
| 2842 | free(out->compr_config.codec); |
| 2843 | } |
Ravi Kumar Alamanda | a4fc902 | 2014-10-08 18:57:46 -0700 | [diff] [blame] | 2844 | |
| 2845 | if (adev->voice_tx_output == out) |
| 2846 | adev->voice_tx_output = NULL; |
| 2847 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2848 | pthread_cond_destroy(&out->cond); |
| 2849 | pthread_mutex_destroy(&out->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2850 | free(stream); |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 2851 | ALOGV("%s: exit", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2852 | } |
| 2853 | |
| 2854 | static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs) |
| 2855 | { |
| 2856 | struct audio_device *adev = (struct audio_device *)dev; |
| 2857 | struct str_parms *parms; |
| 2858 | char *str; |
| 2859 | char value[32]; |
Jean-Michel Trivi | c56336b | 2013-05-24 16:55:17 -0700 | [diff] [blame] | 2860 | int val; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2861 | int ret; |
Eric Laurent | 03f0943 | 2014-03-25 18:09:11 -0700 | [diff] [blame] | 2862 | int status = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2863 | |
Joe Onorato | 188b622 | 2016-03-01 11:02:27 -0800 | [diff] [blame] | 2864 | ALOGV("%s: enter: %s", __func__, kvpairs); |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 2865 | |
| 2866 | pthread_mutex_lock(&adev->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2867 | |
| 2868 | parms = str_parms_create_str(kvpairs); |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 2869 | status = voice_set_parameters(adev, parms); |
| 2870 | if (status != 0) { |
| 2871 | goto done; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2872 | } |
| 2873 | |
| 2874 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_BT_NREC, value, sizeof(value)); |
| 2875 | if (ret >= 0) { |
Ravi Kumar Alamanda | e258e68 | 2015-06-25 13:32:42 -0700 | [diff] [blame] | 2876 | /* When set to false, HAL should disable EC and NS */ |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2877 | if (strcmp(value, AUDIO_PARAMETER_VALUE_ON) == 0) |
| 2878 | adev->bluetooth_nrec = true; |
| 2879 | else |
| 2880 | adev->bluetooth_nrec = false; |
| 2881 | } |
| 2882 | |
| 2883 | ret = str_parms_get_str(parms, "screen_state", value, sizeof(value)); |
| 2884 | if (ret >= 0) { |
| 2885 | if (strcmp(value, AUDIO_PARAMETER_VALUE_ON) == 0) |
| 2886 | adev->screen_off = false; |
| 2887 | else |
| 2888 | adev->screen_off = true; |
| 2889 | } |
| 2890 | |
Jean-Michel Trivi | c56336b | 2013-05-24 16:55:17 -0700 | [diff] [blame] | 2891 | ret = str_parms_get_int(parms, "rotation", &val); |
| 2892 | if (ret >= 0) { |
| 2893 | bool reverse_speakers = false; |
| 2894 | switch(val) { |
| 2895 | // FIXME: note that the code below assumes that the speakers are in the correct placement |
| 2896 | // relative to the user when the device is rotated 90deg from its default rotation. This |
| 2897 | // assumption is device-specific, not platform-specific like this code. |
| 2898 | case 270: |
| 2899 | reverse_speakers = true; |
| 2900 | break; |
| 2901 | case 0: |
| 2902 | case 90: |
| 2903 | case 180: |
| 2904 | break; |
| 2905 | default: |
| 2906 | ALOGE("%s: unexpected rotation of %d", __func__, val); |
Eric Laurent | 03f0943 | 2014-03-25 18:09:11 -0700 | [diff] [blame] | 2907 | status = -EINVAL; |
Jean-Michel Trivi | c56336b | 2013-05-24 16:55:17 -0700 | [diff] [blame] | 2908 | } |
Eric Laurent | 03f0943 | 2014-03-25 18:09:11 -0700 | [diff] [blame] | 2909 | if (status == 0) { |
Ravi Kumar Alamanda | 1f60cf8 | 2015-04-23 19:45:17 -0700 | [diff] [blame] | 2910 | platform_swap_lr_channels(adev, reverse_speakers); |
Jean-Michel Trivi | c56336b | 2013-05-24 16:55:17 -0700 | [diff] [blame] | 2911 | } |
Jean-Michel Trivi | c56336b | 2013-05-24 16:55:17 -0700 | [diff] [blame] | 2912 | } |
| 2913 | |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 2914 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_BT_SCO_WB, value, sizeof(value)); |
| 2915 | if (ret >= 0) { |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 2916 | adev->bt_wb_speech_enabled = !strcmp(value, AUDIO_PARAMETER_VALUE_ON); |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 2917 | } |
| 2918 | |
Ravi Kumar Alamanda | 8e6e98f | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 2919 | audio_extn_hfp_set_parameters(adev, parms); |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 2920 | done: |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2921 | str_parms_destroy(parms); |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 2922 | pthread_mutex_unlock(&adev->lock); |
Eric Laurent | 03f0943 | 2014-03-25 18:09:11 -0700 | [diff] [blame] | 2923 | ALOGV("%s: exit with code(%d)", __func__, status); |
| 2924 | return status; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2925 | } |
| 2926 | |
| 2927 | static char* adev_get_parameters(const struct audio_hw_device *dev, |
| 2928 | const char *keys) |
| 2929 | { |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 2930 | struct audio_device *adev = (struct audio_device *)dev; |
| 2931 | struct str_parms *reply = str_parms_create(); |
| 2932 | struct str_parms *query = str_parms_create_str(keys); |
| 2933 | char *str; |
| 2934 | |
| 2935 | pthread_mutex_lock(&adev->lock); |
| 2936 | |
| 2937 | voice_get_parameters(adev, query, reply); |
| 2938 | str = str_parms_to_str(reply); |
| 2939 | str_parms_destroy(query); |
| 2940 | str_parms_destroy(reply); |
| 2941 | |
| 2942 | pthread_mutex_unlock(&adev->lock); |
| 2943 | ALOGV("%s: exit: returns - %s", __func__, str); |
| 2944 | return str; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2945 | } |
| 2946 | |
Haynes Mathew George | cc9649b | 2014-06-10 15:08:39 -0700 | [diff] [blame] | 2947 | static int adev_init_check(const struct audio_hw_device *dev __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2948 | { |
| 2949 | return 0; |
| 2950 | } |
| 2951 | |
Haynes Mathew George | 5191a85 | 2013-09-11 14:19:36 -0700 | [diff] [blame] | 2952 | static int adev_set_voice_volume(struct audio_hw_device *dev, float volume) |
| 2953 | { |
| 2954 | int ret; |
| 2955 | struct audio_device *adev = (struct audio_device *)dev; |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 2956 | |
Eric Laurent | 4cc4ce1 | 2014-09-10 13:21:01 -0500 | [diff] [blame] | 2957 | audio_extn_extspk_set_voice_vol(adev->extspk, volume); |
| 2958 | |
Haynes Mathew George | 5191a85 | 2013-09-11 14:19:36 -0700 | [diff] [blame] | 2959 | pthread_mutex_lock(&adev->lock); |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 2960 | ret = voice_set_volume(adev, volume); |
Haynes Mathew George | 5191a85 | 2013-09-11 14:19:36 -0700 | [diff] [blame] | 2961 | pthread_mutex_unlock(&adev->lock); |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 2962 | |
Haynes Mathew George | 5191a85 | 2013-09-11 14:19:36 -0700 | [diff] [blame] | 2963 | return ret; |
| 2964 | } |
| 2965 | |
Haynes Mathew George | cc9649b | 2014-06-10 15:08:39 -0700 | [diff] [blame] | 2966 | static int adev_set_master_volume(struct audio_hw_device *dev __unused, float volume __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2967 | { |
| 2968 | return -ENOSYS; |
| 2969 | } |
| 2970 | |
Haynes Mathew George | cc9649b | 2014-06-10 15:08:39 -0700 | [diff] [blame] | 2971 | static int adev_get_master_volume(struct audio_hw_device *dev __unused, |
| 2972 | float *volume __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2973 | { |
| 2974 | return -ENOSYS; |
| 2975 | } |
| 2976 | |
Haynes Mathew George | cc9649b | 2014-06-10 15:08:39 -0700 | [diff] [blame] | 2977 | static int adev_set_master_mute(struct audio_hw_device *dev __unused, bool muted __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2978 | { |
| 2979 | return -ENOSYS; |
| 2980 | } |
| 2981 | |
Haynes Mathew George | cc9649b | 2014-06-10 15:08:39 -0700 | [diff] [blame] | 2982 | static int adev_get_master_mute(struct audio_hw_device *dev __unused, bool *muted __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2983 | { |
| 2984 | return -ENOSYS; |
| 2985 | } |
| 2986 | |
| 2987 | static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode) |
| 2988 | { |
| 2989 | struct audio_device *adev = (struct audio_device *)dev; |
| 2990 | |
| 2991 | pthread_mutex_lock(&adev->lock); |
| 2992 | if (adev->mode != mode) { |
Eric Laurent | 2bafff1 | 2016-03-17 12:17:23 -0700 | [diff] [blame] | 2993 | ALOGD("%s: mode %d", __func__, (int)mode); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2994 | adev->mode = mode; |
Ravi Kumar Alamanda | 36886fc | 2014-09-29 13:41:51 -0700 | [diff] [blame] | 2995 | if ((mode == AUDIO_MODE_NORMAL || mode == AUDIO_MODE_IN_COMMUNICATION) && |
| 2996 | voice_is_in_call(adev)) { |
| 2997 | voice_stop_call(adev); |
| 2998 | adev->current_call_output = NULL; |
| 2999 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3000 | } |
| 3001 | pthread_mutex_unlock(&adev->lock); |
Eric Laurent | 0499d4f | 2014-08-25 22:39:29 -0500 | [diff] [blame] | 3002 | |
| 3003 | audio_extn_extspk_set_mode(adev->extspk, mode); |
| 3004 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3005 | return 0; |
| 3006 | } |
| 3007 | |
| 3008 | static int adev_set_mic_mute(struct audio_hw_device *dev, bool state) |
| 3009 | { |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 3010 | int ret; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3011 | struct audio_device *adev = (struct audio_device *)dev; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3012 | |
Eric Laurent | 2bafff1 | 2016-03-17 12:17:23 -0700 | [diff] [blame] | 3013 | ALOGD("%s: state %d", __func__, (int)state); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 3014 | pthread_mutex_lock(&adev->lock); |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 3015 | ret = voice_set_mic_mute(adev, state); |
Eric Laurent | 7b2b5ab | 2014-09-14 12:29:59 -0700 | [diff] [blame] | 3016 | adev->mic_muted = state; |
Eric Laurent | a609e8e | 2014-06-18 02:15:17 +0000 | [diff] [blame] | 3017 | pthread_mutex_unlock(&adev->lock); |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 3018 | |
| 3019 | return ret; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3020 | } |
| 3021 | |
| 3022 | static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state) |
| 3023 | { |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 3024 | *state = voice_get_mic_mute((struct audio_device *)dev); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3025 | return 0; |
| 3026 | } |
| 3027 | |
Haynes Mathew George | cc9649b | 2014-06-10 15:08:39 -0700 | [diff] [blame] | 3028 | static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev __unused, |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3029 | const struct audio_config *config) |
| 3030 | { |
Eric Laurent | 0de8d1f | 2014-07-01 20:34:45 -0700 | [diff] [blame] | 3031 | int channel_count = audio_channel_count_from_in_mask(config->channel_mask); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3032 | |
Glenn Kasten | 68e79ce | 2014-07-15 10:56:59 -0700 | [diff] [blame] | 3033 | return get_input_buffer_size(config->sample_rate, config->format, channel_count, |
| 3034 | false /* is_low_latency: since we don't know, be conservative */); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3035 | } |
| 3036 | |
| 3037 | static int adev_open_input_stream(struct audio_hw_device *dev, |
Ravi Kumar Alamanda | a417cc5 | 2015-05-01 16:41:56 -0700 | [diff] [blame] | 3038 | audio_io_handle_t handle, |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3039 | audio_devices_t devices, |
| 3040 | struct audio_config *config, |
Glenn Kasten | 68e79ce | 2014-07-15 10:56:59 -0700 | [diff] [blame] | 3041 | struct audio_stream_in **stream_in, |
Eric Laurent | 91975a6 | 2014-07-27 17:15:50 -0700 | [diff] [blame] | 3042 | audio_input_flags_t flags, |
| 3043 | const char *address __unused, |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 3044 | audio_source_t source ) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3045 | { |
| 3046 | struct audio_device *adev = (struct audio_device *)dev; |
| 3047 | struct stream_in *in; |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 3048 | int ret = 0, buffer_size, frame_size; |
Eric Laurent | 0de8d1f | 2014-07-01 20:34:45 -0700 | [diff] [blame] | 3049 | int channel_count = audio_channel_count_from_in_mask(config->channel_mask); |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 3050 | bool is_low_latency = false; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3051 | |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 3052 | ALOGV("%s: enter", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3053 | *stream_in = NULL; |
| 3054 | if (check_input_parameters(config->sample_rate, config->format, channel_count) != 0) |
| 3055 | return -EINVAL; |
| 3056 | |
| 3057 | in = (struct stream_in *)calloc(1, sizeof(struct stream_in)); |
| 3058 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 3059 | pthread_mutex_init(&in->lock, (const pthread_mutexattr_t *) NULL); |
Eric Laurent | a147807 | 2015-09-21 17:21:52 -0700 | [diff] [blame] | 3060 | pthread_mutex_init(&in->pre_lock, (const pthread_mutexattr_t *) NULL); |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 3061 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3062 | in->stream.common.get_sample_rate = in_get_sample_rate; |
| 3063 | in->stream.common.set_sample_rate = in_set_sample_rate; |
| 3064 | in->stream.common.get_buffer_size = in_get_buffer_size; |
| 3065 | in->stream.common.get_channels = in_get_channels; |
| 3066 | in->stream.common.get_format = in_get_format; |
| 3067 | in->stream.common.set_format = in_set_format; |
| 3068 | in->stream.common.standby = in_standby; |
| 3069 | in->stream.common.dump = in_dump; |
| 3070 | in->stream.common.set_parameters = in_set_parameters; |
| 3071 | in->stream.common.get_parameters = in_get_parameters; |
| 3072 | in->stream.common.add_audio_effect = in_add_audio_effect; |
| 3073 | in->stream.common.remove_audio_effect = in_remove_audio_effect; |
| 3074 | in->stream.set_gain = in_set_gain; |
| 3075 | in->stream.read = in_read; |
| 3076 | in->stream.get_input_frames_lost = in_get_input_frames_lost; |
Andy Hung | 6ebe596 | 2016-01-15 17:46:57 -0800 | [diff] [blame] | 3077 | in->stream.get_capture_position = in_get_capture_position; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3078 | |
| 3079 | in->device = devices; |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 3080 | in->source = source; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3081 | in->dev = adev; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3082 | in->standby = 1; |
| 3083 | in->channel_mask = config->channel_mask; |
Ravi Kumar Alamanda | a417cc5 | 2015-05-01 16:41:56 -0700 | [diff] [blame] | 3084 | in->capture_handle = handle; |
Haynes Mathew George | 88e6fb2 | 2015-08-19 11:51:34 -0700 | [diff] [blame] | 3085 | in->flags = flags; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3086 | |
vivek mehta | 57ff9b5 | 2016-04-28 14:13:08 -0700 | [diff] [blame] | 3087 | // restrict 24 bit capture for unprocessed source only |
| 3088 | // for other sources if 24 bit requested reject 24 and set 16 bit capture only |
| 3089 | if (config->format == AUDIO_FORMAT_DEFAULT) { |
vivek mehta | 4ed66e6 | 2016-04-15 23:33:34 -0700 | [diff] [blame] | 3090 | config->format = AUDIO_FORMAT_PCM_16_BIT; |
vivek mehta | 57ff9b5 | 2016-04-28 14:13:08 -0700 | [diff] [blame] | 3091 | } else if (config->format == AUDIO_FORMAT_PCM_FLOAT || |
| 3092 | config->format == AUDIO_FORMAT_PCM_24_BIT_PACKED || |
| 3093 | config->format == AUDIO_FORMAT_PCM_8_24_BIT) { |
| 3094 | bool ret_error = false; |
| 3095 | /* 24 bit is restricted to UNPROCESSED source only,also format supported |
| 3096 | from HAL is 8_24 |
| 3097 | *> In case of UNPROCESSED source, for 24 bit, if format requested is other than |
| 3098 | 8_24 return error indicating supported format is 8_24 |
| 3099 | *> In case of any other source requesting 24 bit or float return error |
| 3100 | indicating format supported is 16 bit only. |
vivek mehta | 4ed66e6 | 2016-04-15 23:33:34 -0700 | [diff] [blame] | 3101 | |
vivek mehta | 57ff9b5 | 2016-04-28 14:13:08 -0700 | [diff] [blame] | 3102 | on error flinger will retry with supported format passed |
| 3103 | */ |
| 3104 | if (source != AUDIO_SOURCE_UNPROCESSED) { |
| 3105 | config->format = AUDIO_FORMAT_PCM_16_BIT; |
| 3106 | ret_error = true; |
| 3107 | } else if (config->format != AUDIO_FORMAT_PCM_8_24_BIT) { |
| 3108 | config->format = AUDIO_FORMAT_PCM_8_24_BIT; |
| 3109 | ret_error = true; |
| 3110 | } |
| 3111 | |
| 3112 | if (ret_error) { |
| 3113 | ret = -EINVAL; |
| 3114 | goto err_open; |
| 3115 | } |
vivek mehta | 4ed66e6 | 2016-04-15 23:33:34 -0700 | [diff] [blame] | 3116 | } |
| 3117 | |
vivek mehta | 57ff9b5 | 2016-04-28 14:13:08 -0700 | [diff] [blame] | 3118 | in->format = config->format; |
| 3119 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3120 | /* Update config params with the requested sample rate and channels */ |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 3121 | if (in->device == AUDIO_DEVICE_IN_TELEPHONY_RX) { |
| 3122 | if (config->sample_rate == 0) |
| 3123 | config->sample_rate = AFE_PROXY_SAMPLING_RATE; |
| 3124 | if (config->sample_rate != 48000 && config->sample_rate != 16000 && |
| 3125 | config->sample_rate != 8000) { |
| 3126 | config->sample_rate = AFE_PROXY_SAMPLING_RATE; |
| 3127 | ret = -EINVAL; |
| 3128 | goto err_open; |
| 3129 | } |
vivek mehta | 4ed66e6 | 2016-04-15 23:33:34 -0700 | [diff] [blame] | 3130 | |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 3131 | if (config->format != AUDIO_FORMAT_PCM_16_BIT) { |
| 3132 | config->format = AUDIO_FORMAT_PCM_16_BIT; |
| 3133 | ret = -EINVAL; |
| 3134 | goto err_open; |
| 3135 | } |
| 3136 | |
| 3137 | in->usecase = USECASE_AUDIO_RECORD_AFE_PROXY; |
| 3138 | in->config = pcm_config_afe_proxy_record; |
| 3139 | } else { |
| 3140 | in->usecase = USECASE_AUDIO_RECORD; |
| 3141 | if (config->sample_rate == LOW_LATENCY_CAPTURE_SAMPLE_RATE && |
| 3142 | (flags & AUDIO_INPUT_FLAG_FAST) != 0) { |
| 3143 | is_low_latency = true; |
Glenn Kasten | 4f99339 | 2014-05-14 07:30:48 -0700 | [diff] [blame] | 3144 | #if LOW_LATENCY_CAPTURE_USE_CASE |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 3145 | in->usecase = USECASE_AUDIO_RECORD_LOW_LATENCY; |
Glenn Kasten | 4f99339 | 2014-05-14 07:30:48 -0700 | [diff] [blame] | 3146 | #endif |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 3147 | in->realtime = may_use_noirq_mode(adev, in->usecase, in->flags); |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 3148 | } |
Ravi Kumar Alamanda | 99c752d | 2014-08-20 17:55:26 -0700 | [diff] [blame] | 3149 | |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 3150 | in->config = in->realtime ? pcm_config_audio_capture_rt : |
| 3151 | pcm_config_audio_capture; |
| 3152 | |
vivek mehta | 4ed66e6 | 2016-04-15 23:33:34 -0700 | [diff] [blame] | 3153 | if (config->format == AUDIO_FORMAT_PCM_8_24_BIT) |
| 3154 | in->config.format = PCM_FORMAT_S24_LE; |
| 3155 | |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 3156 | if (!in->realtime) { |
| 3157 | frame_size = audio_stream_in_frame_size(&in->stream); |
| 3158 | buffer_size = get_input_buffer_size(config->sample_rate, |
| 3159 | config->format, |
| 3160 | channel_count, |
Eric Laurent | f8b50aa | 2016-05-06 11:03:53 -0700 | [diff] [blame] | 3161 | is_low_latency); |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 3162 | in->config.period_size = buffer_size / frame_size; |
| 3163 | } // period size is left untouched for rt mode playback |
Glenn Kasten | 68e79ce | 2014-07-15 10:56:59 -0700 | [diff] [blame] | 3164 | } |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 3165 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3166 | in->config.channels = channel_count; |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 3167 | if (in->realtime) { |
| 3168 | in->af_period_multiplier = af_period_multiplier; |
| 3169 | } else { |
| 3170 | in->config.rate = config->sample_rate; |
| 3171 | in->af_period_multiplier = 1; |
| 3172 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3173 | |
Ravi Kumar Alamanda | a417cc5 | 2015-05-01 16:41:56 -0700 | [diff] [blame] | 3174 | /* This stream could be for sound trigger lab, |
| 3175 | get sound trigger pcm if present */ |
| 3176 | audio_extn_sound_trigger_check_and_get_session(in); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3177 | |
Haynes Mathew George | c735fb0 | 2016-06-30 18:00:28 -0700 | [diff] [blame] | 3178 | lock_input_stream(in); |
| 3179 | audio_extn_snd_mon_register_listener(in, in_snd_mon_cb); |
| 3180 | pthread_mutex_lock(&adev->lock); |
| 3181 | in->card_status = adev->card_status; |
| 3182 | pthread_mutex_unlock(&adev->lock); |
| 3183 | pthread_mutex_unlock(&in->lock); |
| 3184 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3185 | *stream_in = &in->stream; |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 3186 | ALOGV("%s: exit", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3187 | return 0; |
| 3188 | |
| 3189 | err_open: |
| 3190 | free(in); |
| 3191 | *stream_in = NULL; |
| 3192 | return ret; |
| 3193 | } |
| 3194 | |
Haynes Mathew George | cc9649b | 2014-06-10 15:08:39 -0700 | [diff] [blame] | 3195 | static void adev_close_input_stream(struct audio_hw_device *dev __unused, |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3196 | struct audio_stream_in *stream) |
| 3197 | { |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 3198 | ALOGV("%s", __func__); |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 3199 | |
Haynes Mathew George | c735fb0 | 2016-06-30 18:00:28 -0700 | [diff] [blame] | 3200 | // must deregister from sndmonitor first to prevent races |
| 3201 | // between the callback and close_stream |
| 3202 | audio_extn_snd_mon_unregister_listener(stream); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3203 | in_standby(&stream->common); |
| 3204 | free(stream); |
| 3205 | |
| 3206 | return; |
| 3207 | } |
| 3208 | |
Haynes Mathew George | cc9649b | 2014-06-10 15:08:39 -0700 | [diff] [blame] | 3209 | static int adev_dump(const audio_hw_device_t *device __unused, int fd __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3210 | { |
| 3211 | return 0; |
| 3212 | } |
| 3213 | |
Andy Hung | 31aca91 | 2014-03-20 17:14:59 -0700 | [diff] [blame] | 3214 | /* verifies input and output devices and their capabilities. |
| 3215 | * |
| 3216 | * This verification is required when enabling extended bit-depth or |
| 3217 | * sampling rates, as not all qcom products support it. |
| 3218 | * |
| 3219 | * Suitable for calling only on initialization such as adev_open(). |
| 3220 | * It fills the audio_device use_case_table[] array. |
| 3221 | * |
| 3222 | * Has a side-effect that it needs to configure audio routing / devices |
| 3223 | * in order to power up the devices and read the device parameters. |
| 3224 | * It does not acquire any hw device lock. Should restore the devices |
| 3225 | * back to "normal state" upon completion. |
| 3226 | */ |
| 3227 | static int adev_verify_devices(struct audio_device *adev) |
| 3228 | { |
| 3229 | /* enumeration is a bit difficult because one really wants to pull |
| 3230 | * the use_case, device id, etc from the hidden pcm_device_table[]. |
| 3231 | * In this case there are the following use cases and device ids. |
| 3232 | * |
| 3233 | * [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {0, 0}, |
| 3234 | * [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {15, 15}, |
| 3235 | * [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {1, 1}, |
| 3236 | * [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {9, 9}, |
| 3237 | * [USECASE_AUDIO_RECORD] = {0, 0}, |
| 3238 | * [USECASE_AUDIO_RECORD_LOW_LATENCY] = {15, 15}, |
| 3239 | * [USECASE_VOICE_CALL] = {2, 2}, |
| 3240 | * |
| 3241 | * USECASE_AUDIO_PLAYBACK_OFFLOAD, USECASE_AUDIO_PLAYBACK_MULTI_CH omitted. |
| 3242 | * USECASE_VOICE_CALL omitted, but possible for either input or output. |
| 3243 | */ |
| 3244 | |
| 3245 | /* should be the usecases enabled in adev_open_input_stream() */ |
| 3246 | static const int test_in_usecases[] = { |
| 3247 | USECASE_AUDIO_RECORD, |
| 3248 | USECASE_AUDIO_RECORD_LOW_LATENCY, /* does not appear to be used */ |
| 3249 | }; |
| 3250 | /* should be the usecases enabled in adev_open_output_stream()*/ |
| 3251 | static const int test_out_usecases[] = { |
| 3252 | USECASE_AUDIO_PLAYBACK_DEEP_BUFFER, |
| 3253 | USECASE_AUDIO_PLAYBACK_LOW_LATENCY, |
| 3254 | }; |
| 3255 | static const usecase_type_t usecase_type_by_dir[] = { |
| 3256 | PCM_PLAYBACK, |
| 3257 | PCM_CAPTURE, |
| 3258 | }; |
| 3259 | static const unsigned flags_by_dir[] = { |
| 3260 | PCM_OUT, |
| 3261 | PCM_IN, |
| 3262 | }; |
| 3263 | |
| 3264 | size_t i; |
| 3265 | unsigned dir; |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 3266 | const unsigned card_id = adev->snd_card; |
Andy Hung | 31aca91 | 2014-03-20 17:14:59 -0700 | [diff] [blame] | 3267 | char info[512]; /* for possible debug info */ |
| 3268 | |
| 3269 | for (dir = 0; dir < 2; ++dir) { |
| 3270 | const usecase_type_t usecase_type = usecase_type_by_dir[dir]; |
| 3271 | const unsigned flags_dir = flags_by_dir[dir]; |
| 3272 | const size_t testsize = |
| 3273 | dir ? ARRAY_SIZE(test_in_usecases) : ARRAY_SIZE(test_out_usecases); |
| 3274 | const int *testcases = |
| 3275 | dir ? test_in_usecases : test_out_usecases; |
| 3276 | const audio_devices_t audio_device = |
| 3277 | dir ? AUDIO_DEVICE_IN_BUILTIN_MIC : AUDIO_DEVICE_OUT_SPEAKER; |
| 3278 | |
| 3279 | for (i = 0; i < testsize; ++i) { |
| 3280 | const audio_usecase_t audio_usecase = testcases[i]; |
| 3281 | int device_id; |
| 3282 | snd_device_t snd_device; |
| 3283 | struct pcm_params **pparams; |
| 3284 | struct stream_out out; |
| 3285 | struct stream_in in; |
| 3286 | struct audio_usecase uc_info; |
| 3287 | int retval; |
| 3288 | |
| 3289 | pparams = &adev->use_case_table[audio_usecase]; |
| 3290 | pcm_params_free(*pparams); /* can accept null input */ |
| 3291 | *pparams = NULL; |
| 3292 | |
| 3293 | /* find the device ID for the use case (signed, for error) */ |
| 3294 | device_id = platform_get_pcm_device_id(audio_usecase, usecase_type); |
| 3295 | if (device_id < 0) |
| 3296 | continue; |
| 3297 | |
| 3298 | /* prepare structures for device probing */ |
| 3299 | memset(&uc_info, 0, sizeof(uc_info)); |
| 3300 | uc_info.id = audio_usecase; |
| 3301 | uc_info.type = usecase_type; |
| 3302 | if (dir) { |
| 3303 | adev->active_input = ∈ |
| 3304 | memset(&in, 0, sizeof(in)); |
| 3305 | in.device = audio_device; |
| 3306 | in.source = AUDIO_SOURCE_VOICE_COMMUNICATION; |
| 3307 | uc_info.stream.in = ∈ |
| 3308 | } else { |
| 3309 | adev->active_input = NULL; |
| 3310 | } |
| 3311 | memset(&out, 0, sizeof(out)); |
| 3312 | out.devices = audio_device; /* only field needed in select_devices */ |
| 3313 | uc_info.stream.out = &out; |
| 3314 | uc_info.devices = audio_device; |
| 3315 | uc_info.in_snd_device = SND_DEVICE_NONE; |
| 3316 | uc_info.out_snd_device = SND_DEVICE_NONE; |
| 3317 | list_add_tail(&adev->usecase_list, &uc_info.list); |
| 3318 | |
| 3319 | /* select device - similar to start_(in/out)put_stream() */ |
| 3320 | retval = select_devices(adev, audio_usecase); |
| 3321 | if (retval >= 0) { |
| 3322 | *pparams = pcm_params_get(card_id, device_id, flags_dir); |
| 3323 | #if LOG_NDEBUG == 0 |
| 3324 | if (*pparams) { |
| 3325 | ALOGV("%s: (%s) card %d device %d", __func__, |
| 3326 | dir ? "input" : "output", card_id, device_id); |
| 3327 | pcm_params_to_string(*pparams, info, ARRAY_SIZE(info)); |
Andy Hung | 31aca91 | 2014-03-20 17:14:59 -0700 | [diff] [blame] | 3328 | } else { |
| 3329 | ALOGV("%s: cannot locate card %d device %d", __func__, card_id, device_id); |
| 3330 | } |
| 3331 | #endif |
| 3332 | } |
| 3333 | |
| 3334 | /* deselect device - similar to stop_(in/out)put_stream() */ |
| 3335 | /* 1. Get and set stream specific mixer controls */ |
Glenn Kasten | e713730 | 2014-04-28 15:12:18 -0700 | [diff] [blame] | 3336 | retval = disable_audio_route(adev, &uc_info); |
Andy Hung | 31aca91 | 2014-03-20 17:14:59 -0700 | [diff] [blame] | 3337 | /* 2. Disable the rx device */ |
| 3338 | retval = disable_snd_device(adev, |
Glenn Kasten | e713730 | 2014-04-28 15:12:18 -0700 | [diff] [blame] | 3339 | dir ? uc_info.in_snd_device : uc_info.out_snd_device); |
Andy Hung | 31aca91 | 2014-03-20 17:14:59 -0700 | [diff] [blame] | 3340 | list_remove(&uc_info.list); |
| 3341 | } |
| 3342 | } |
| 3343 | adev->active_input = NULL; /* restore adev state */ |
| 3344 | return 0; |
| 3345 | } |
| 3346 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3347 | static int adev_close(hw_device_t *device) |
| 3348 | { |
Andy Hung | 31aca91 | 2014-03-20 17:14:59 -0700 | [diff] [blame] | 3349 | size_t i; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3350 | struct audio_device *adev = (struct audio_device *)device; |
vivek mehta | 1a9b7c0 | 2015-06-25 11:49:38 -0700 | [diff] [blame] | 3351 | |
| 3352 | if (!adev) |
| 3353 | return 0; |
| 3354 | |
Haynes Mathew George | c735fb0 | 2016-06-30 18:00:28 -0700 | [diff] [blame] | 3355 | audio_extn_snd_mon_unregister_listener(adev); |
vivek mehta | 1a9b7c0 | 2015-06-25 11:49:38 -0700 | [diff] [blame] | 3356 | pthread_mutex_lock(&adev_init_lock); |
| 3357 | |
| 3358 | if ((--audio_device_ref_count) == 0) { |
| 3359 | audio_route_free(adev->audio_route); |
| 3360 | free(adev->snd_dev_ref_cnt); |
| 3361 | platform_deinit(adev->platform); |
| 3362 | audio_extn_extspk_deinit(adev->extspk); |
| 3363 | audio_extn_sound_trigger_deinit(adev); |
| 3364 | for (i = 0; i < ARRAY_SIZE(adev->use_case_table); ++i) { |
| 3365 | pcm_params_free(adev->use_case_table[i]); |
| 3366 | } |
Haynes Mathew George | 88e6fb2 | 2015-08-19 11:51:34 -0700 | [diff] [blame] | 3367 | if (adev->adm_deinit) |
| 3368 | adev->adm_deinit(adev->adm_data); |
vivek mehta | 1a9b7c0 | 2015-06-25 11:49:38 -0700 | [diff] [blame] | 3369 | free(device); |
Andy Hung | 31aca91 | 2014-03-20 17:14:59 -0700 | [diff] [blame] | 3370 | } |
vivek mehta | 1a9b7c0 | 2015-06-25 11:49:38 -0700 | [diff] [blame] | 3371 | |
| 3372 | pthread_mutex_unlock(&adev_init_lock); |
Haynes Mathew George | 88e6fb2 | 2015-08-19 11:51:34 -0700 | [diff] [blame] | 3373 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3374 | return 0; |
| 3375 | } |
| 3376 | |
Glenn Kasten | 4f99339 | 2014-05-14 07:30:48 -0700 | [diff] [blame] | 3377 | /* This returns 1 if the input parameter looks at all plausible as a low latency period size, |
| 3378 | * or 0 otherwise. A return value of 1 doesn't mean the value is guaranteed to work, |
| 3379 | * just that it _might_ work. |
| 3380 | */ |
| 3381 | static int period_size_is_plausible_for_low_latency(int period_size) |
| 3382 | { |
| 3383 | switch (period_size) { |
Glenn Kasten | 5b5d04e | 2015-04-09 09:43:29 -0700 | [diff] [blame] | 3384 | case 48: |
| 3385 | case 96: |
| 3386 | case 144: |
Glenn Kasten | 4f99339 | 2014-05-14 07:30:48 -0700 | [diff] [blame] | 3387 | case 160: |
Glenn Kasten | 5b5d04e | 2015-04-09 09:43:29 -0700 | [diff] [blame] | 3388 | case 192: |
Glenn Kasten | 4f99339 | 2014-05-14 07:30:48 -0700 | [diff] [blame] | 3389 | case 240: |
| 3390 | case 320: |
| 3391 | case 480: |
| 3392 | return 1; |
| 3393 | default: |
| 3394 | return 0; |
| 3395 | } |
| 3396 | } |
| 3397 | |
Haynes Mathew George | c735fb0 | 2016-06-30 18:00:28 -0700 | [diff] [blame] | 3398 | static void adev_snd_mon_cb(void * stream __unused, struct str_parms * parms) |
| 3399 | { |
| 3400 | int card; |
| 3401 | card_status_t status; |
| 3402 | |
| 3403 | if (!parms) |
| 3404 | return; |
| 3405 | |
| 3406 | if (parse_snd_card_status(parms, &card, &status) < 0) |
| 3407 | return; |
| 3408 | |
| 3409 | pthread_mutex_lock(&adev->lock); |
| 3410 | bool valid_cb = (card == adev->snd_card); |
| 3411 | if (valid_cb) { |
| 3412 | if (adev->card_status != status) { |
| 3413 | adev->card_status = status; |
| 3414 | platform_snd_card_update(adev->platform, status); |
| 3415 | } |
| 3416 | } |
| 3417 | pthread_mutex_unlock(&adev->lock); |
| 3418 | return; |
| 3419 | } |
| 3420 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3421 | static int adev_open(const hw_module_t *module, const char *name, |
| 3422 | hw_device_t **device) |
| 3423 | { |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 3424 | int i, ret; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3425 | |
Eric Laurent | 2bafff1 | 2016-03-17 12:17:23 -0700 | [diff] [blame] | 3426 | ALOGD("%s: enter", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3427 | if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) return -EINVAL; |
vivek mehta | 1a9b7c0 | 2015-06-25 11:49:38 -0700 | [diff] [blame] | 3428 | pthread_mutex_lock(&adev_init_lock); |
| 3429 | if (audio_device_ref_count != 0) { |
| 3430 | *device = &adev->device.common; |
| 3431 | audio_device_ref_count++; |
| 3432 | ALOGV("%s: returning existing instance of adev", __func__); |
| 3433 | ALOGV("%s: exit", __func__); |
| 3434 | pthread_mutex_unlock(&adev_init_lock); |
| 3435 | return 0; |
| 3436 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3437 | adev = calloc(1, sizeof(struct audio_device)); |
| 3438 | |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 3439 | pthread_mutex_init(&adev->lock, (const pthread_mutexattr_t *) NULL); |
| 3440 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3441 | adev->device.common.tag = HARDWARE_DEVICE_TAG; |
| 3442 | adev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0; |
| 3443 | adev->device.common.module = (struct hw_module_t *)module; |
| 3444 | adev->device.common.close = adev_close; |
| 3445 | |
| 3446 | adev->device.init_check = adev_init_check; |
| 3447 | adev->device.set_voice_volume = adev_set_voice_volume; |
| 3448 | adev->device.set_master_volume = adev_set_master_volume; |
| 3449 | adev->device.get_master_volume = adev_get_master_volume; |
| 3450 | adev->device.set_master_mute = adev_set_master_mute; |
| 3451 | adev->device.get_master_mute = adev_get_master_mute; |
| 3452 | adev->device.set_mode = adev_set_mode; |
| 3453 | adev->device.set_mic_mute = adev_set_mic_mute; |
| 3454 | adev->device.get_mic_mute = adev_get_mic_mute; |
| 3455 | adev->device.set_parameters = adev_set_parameters; |
| 3456 | adev->device.get_parameters = adev_get_parameters; |
| 3457 | adev->device.get_input_buffer_size = adev_get_input_buffer_size; |
| 3458 | adev->device.open_output_stream = adev_open_output_stream; |
| 3459 | adev->device.close_output_stream = adev_close_output_stream; |
| 3460 | adev->device.open_input_stream = adev_open_input_stream; |
| 3461 | adev->device.close_input_stream = adev_close_input_stream; |
| 3462 | adev->device.dump = adev_dump; |
| 3463 | |
| 3464 | /* Set the default route before the PCM stream is opened */ |
| 3465 | pthread_mutex_lock(&adev->lock); |
| 3466 | adev->mode = AUDIO_MODE_NORMAL; |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 3467 | adev->active_input = NULL; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 3468 | adev->primary_output = NULL; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3469 | adev->bluetooth_nrec = true; |
Ravi Kumar Alamanda | f996704 | 2013-02-14 19:35:14 -0800 | [diff] [blame] | 3470 | adev->acdb_settings = TTY_MODE_OFF; |
Eric Laurent | 07eeafd | 2013-10-06 12:52:49 -0700 | [diff] [blame] | 3471 | /* adev->cur_hdmi_channels = 0; by calloc() */ |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 3472 | adev->snd_dev_ref_cnt = calloc(SND_DEVICE_MAX, sizeof(int)); |
Vineeta Srivastava | 4b89e37 | 2014-06-19 14:21:42 -0700 | [diff] [blame] | 3473 | voice_init(adev); |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 3474 | list_init(&adev->usecase_list); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3475 | pthread_mutex_unlock(&adev->lock); |
| 3476 | |
| 3477 | /* Loads platform specific libraries dynamically */ |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 3478 | adev->platform = platform_init(adev); |
| 3479 | if (!adev->platform) { |
| 3480 | free(adev->snd_dev_ref_cnt); |
| 3481 | free(adev); |
| 3482 | ALOGE("%s: Failed to init platform data, aborting.", __func__); |
| 3483 | *device = NULL; |
vivek mehta | 1a9b7c0 | 2015-06-25 11:49:38 -0700 | [diff] [blame] | 3484 | pthread_mutex_unlock(&adev_init_lock); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 3485 | return -EINVAL; |
| 3486 | } |
Eric Laurent | 0499d4f | 2014-08-25 22:39:29 -0500 | [diff] [blame] | 3487 | adev->extspk = audio_extn_extspk_init(adev); |
Ravi Kumar Alamanda | a417cc5 | 2015-05-01 16:41:56 -0700 | [diff] [blame] | 3488 | audio_extn_sound_trigger_init(adev); |
Eric Laurent | 0499d4f | 2014-08-25 22:39:29 -0500 | [diff] [blame] | 3489 | |
Glenn Kasten | 6d53bfd | 2016-04-04 16:58:03 -0700 | [diff] [blame] | 3490 | adev->visualizer_lib = dlopen(VISUALIZER_LIBRARY_PATH, RTLD_NOW); |
| 3491 | if (adev->visualizer_lib == NULL) { |
| 3492 | ALOGW("%s: DLOPEN failed for %s", __func__, VISUALIZER_LIBRARY_PATH); |
| 3493 | } else { |
| 3494 | ALOGV("%s: DLOPEN successful for %s", __func__, VISUALIZER_LIBRARY_PATH); |
| 3495 | adev->visualizer_start_output = |
| 3496 | (int (*)(audio_io_handle_t, int))dlsym(adev->visualizer_lib, |
| 3497 | "visualizer_hal_start_output"); |
| 3498 | adev->visualizer_stop_output = |
| 3499 | (int (*)(audio_io_handle_t, int))dlsym(adev->visualizer_lib, |
| 3500 | "visualizer_hal_stop_output"); |
Eric Laurent | c4aef75 | 2013-09-12 17:45:53 -0700 | [diff] [blame] | 3501 | } |
| 3502 | |
Glenn Kasten | 6d53bfd | 2016-04-04 16:58:03 -0700 | [diff] [blame] | 3503 | adev->offload_effects_lib = dlopen(OFFLOAD_EFFECTS_BUNDLE_LIBRARY_PATH, RTLD_NOW); |
| 3504 | if (adev->offload_effects_lib == NULL) { |
| 3505 | ALOGW("%s: DLOPEN failed for %s", __func__, |
| 3506 | OFFLOAD_EFFECTS_BUNDLE_LIBRARY_PATH); |
| 3507 | } else { |
| 3508 | ALOGV("%s: DLOPEN successful for %s", __func__, |
| 3509 | OFFLOAD_EFFECTS_BUNDLE_LIBRARY_PATH); |
| 3510 | adev->offload_effects_start_output = |
| 3511 | (int (*)(audio_io_handle_t, int))dlsym(adev->offload_effects_lib, |
| 3512 | "offload_effects_bundle_hal_start_output"); |
| 3513 | adev->offload_effects_stop_output = |
| 3514 | (int (*)(audio_io_handle_t, int))dlsym(adev->offload_effects_lib, |
| 3515 | "offload_effects_bundle_hal_stop_output"); |
Haynes Mathew George | 41f8665 | 2014-06-17 14:22:15 -0700 | [diff] [blame] | 3516 | } |
| 3517 | |
Glenn Kasten | 6d53bfd | 2016-04-04 16:58:03 -0700 | [diff] [blame] | 3518 | adev->adm_lib = dlopen(ADM_LIBRARY_PATH, RTLD_NOW); |
| 3519 | if (adev->adm_lib == NULL) { |
| 3520 | ALOGW("%s: DLOPEN failed for %s", __func__, ADM_LIBRARY_PATH); |
| 3521 | } else { |
| 3522 | ALOGV("%s: DLOPEN successful for %s", __func__, ADM_LIBRARY_PATH); |
| 3523 | adev->adm_init = (adm_init_t) |
| 3524 | dlsym(adev->adm_lib, "adm_init"); |
| 3525 | adev->adm_deinit = (adm_deinit_t) |
| 3526 | dlsym(adev->adm_lib, "adm_deinit"); |
| 3527 | adev->adm_register_input_stream = (adm_register_input_stream_t) |
| 3528 | dlsym(adev->adm_lib, "adm_register_input_stream"); |
| 3529 | adev->adm_register_output_stream = (adm_register_output_stream_t) |
| 3530 | dlsym(adev->adm_lib, "adm_register_output_stream"); |
| 3531 | adev->adm_deregister_stream = (adm_deregister_stream_t) |
| 3532 | dlsym(adev->adm_lib, "adm_deregister_stream"); |
| 3533 | adev->adm_request_focus = (adm_request_focus_t) |
| 3534 | dlsym(adev->adm_lib, "adm_request_focus"); |
| 3535 | adev->adm_abandon_focus = (adm_abandon_focus_t) |
| 3536 | dlsym(adev->adm_lib, "adm_abandon_focus"); |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 3537 | adev->adm_set_config = (adm_set_config_t) |
| 3538 | dlsym(adev->adm_lib, "adm_set_config"); |
| 3539 | adev->adm_request_focus_v2 = (adm_request_focus_v2_t) |
| 3540 | dlsym(adev->adm_lib, "adm_request_focus_v2"); |
| 3541 | adev->adm_is_noirq_avail = (adm_is_noirq_avail_t) |
| 3542 | dlsym(adev->adm_lib, "adm_is_noirq_avail"); |
| 3543 | adev->adm_on_routing_change = (adm_on_routing_change_t) |
| 3544 | dlsym(adev->adm_lib, "adm_on_routing_change"); |
Haynes Mathew George | 88e6fb2 | 2015-08-19 11:51:34 -0700 | [diff] [blame] | 3545 | } |
| 3546 | |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 3547 | adev->bt_wb_speech_enabled = false; |
Eric Laurent | cefbbac | 2014-09-04 13:54:10 -0500 | [diff] [blame] | 3548 | adev->enable_voicerx = false; |
Ravi Kumar Alamanda | 9f30654 | 2014-04-02 15:11:49 -0700 | [diff] [blame] | 3549 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3550 | *device = &adev->device.common; |
vivek mehta | 1a9b7c0 | 2015-06-25 11:49:38 -0700 | [diff] [blame] | 3551 | |
Andy Hung | 31aca91 | 2014-03-20 17:14:59 -0700 | [diff] [blame] | 3552 | if (k_enable_extended_precision) |
| 3553 | adev_verify_devices(adev); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3554 | |
Glenn Kasten | 4f99339 | 2014-05-14 07:30:48 -0700 | [diff] [blame] | 3555 | char value[PROPERTY_VALUE_MAX]; |
| 3556 | int trial; |
| 3557 | if (property_get("audio_hal.period_size", value, NULL) > 0) { |
| 3558 | trial = atoi(value); |
| 3559 | if (period_size_is_plausible_for_low_latency(trial)) { |
| 3560 | pcm_config_low_latency.period_size = trial; |
| 3561 | pcm_config_low_latency.start_threshold = trial / 4; |
| 3562 | pcm_config_low_latency.avail_min = trial / 4; |
| 3563 | configured_low_latency_capture_period_size = trial; |
| 3564 | } |
| 3565 | } |
| 3566 | if (property_get("audio_hal.in_period_size", value, NULL) > 0) { |
| 3567 | trial = atoi(value); |
| 3568 | if (period_size_is_plausible_for_low_latency(trial)) { |
| 3569 | configured_low_latency_capture_period_size = trial; |
| 3570 | } |
| 3571 | } |
| 3572 | |
vivek mehta | 1a9b7c0 | 2015-06-25 11:49:38 -0700 | [diff] [blame] | 3573 | audio_device_ref_count++; |
Haynes Mathew George | 03c4010 | 2016-01-29 17:57:48 -0800 | [diff] [blame] | 3574 | |
| 3575 | if (property_get("audio_hal.period_multiplier", value, NULL) > 0) { |
| 3576 | af_period_multiplier = atoi(value); |
| 3577 | if (af_period_multiplier < 0) { |
| 3578 | af_period_multiplier = 2; |
| 3579 | } else if (af_period_multiplier > 4) { |
| 3580 | af_period_multiplier = 4; |
| 3581 | } |
| 3582 | ALOGV("new period_multiplier = %d", af_period_multiplier); |
| 3583 | } |
| 3584 | |
vivek mehta | 1a9b7c0 | 2015-06-25 11:49:38 -0700 | [diff] [blame] | 3585 | pthread_mutex_unlock(&adev_init_lock); |
| 3586 | |
Haynes Mathew George | 88e6fb2 | 2015-08-19 11:51:34 -0700 | [diff] [blame] | 3587 | if (adev->adm_init) |
| 3588 | adev->adm_data = adev->adm_init(); |
| 3589 | |
Ravi Kumar Alamanda | 533bb72 | 2015-09-23 13:47:03 -0700 | [diff] [blame] | 3590 | audio_extn_perf_lock_init(); |
Haynes Mathew George | c735fb0 | 2016-06-30 18:00:28 -0700 | [diff] [blame] | 3591 | audio_extn_snd_mon_init(); |
| 3592 | pthread_mutex_lock(&adev->lock); |
| 3593 | audio_extn_snd_mon_register_listener(NULL, adev_snd_mon_cb); |
| 3594 | adev->card_status = CARD_STATUS_ONLINE; |
| 3595 | pthread_mutex_unlock(&adev->lock); |
Ravi Kumar Alamanda | 533bb72 | 2015-09-23 13:47:03 -0700 | [diff] [blame] | 3596 | |
Eric Laurent | 2bafff1 | 2016-03-17 12:17:23 -0700 | [diff] [blame] | 3597 | ALOGD("%s: exit", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3598 | return 0; |
| 3599 | } |
| 3600 | |
| 3601 | static struct hw_module_methods_t hal_module_methods = { |
| 3602 | .open = adev_open, |
| 3603 | }; |
| 3604 | |
| 3605 | struct audio_module HAL_MODULE_INFO_SYM = { |
| 3606 | .common = { |
| 3607 | .tag = HARDWARE_MODULE_TAG, |
| 3608 | .module_api_version = AUDIO_MODULE_API_VERSION_0_1, |
| 3609 | .hal_api_version = HARDWARE_HAL_API_VERSION, |
| 3610 | .id = AUDIO_HARDWARE_MODULE_ID, |
| 3611 | .name = "QCOM Audio HAL", |
| 3612 | .author = "Code Aurora Forum", |
| 3613 | .methods = &hal_module_methods, |
| 3614 | }, |
| 3615 | }; |