Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1 | /* |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 2 | * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved. |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 3 | * Not a Contribution. |
| 4 | * |
Shiv Maliyappanahalli | 8911f28 | 2014-01-10 15:56:19 -0800 | [diff] [blame] | 5 | * Copyright (C) 2013 The Android Open Source Project |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | */ |
| 19 | |
| 20 | #define LOG_TAG "audio_hw_primary" |
Steve Kondik | 5a44701 | 2014-12-02 16:04:20 -0800 | [diff] [blame] | 21 | //#define LOG_NDEBUG 0 |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 22 | /*#define VERY_VERY_VERBOSE_LOGGING*/ |
| 23 | #ifdef VERY_VERY_VERBOSE_LOGGING |
| 24 | #define ALOGVV ALOGV |
| 25 | #else |
| 26 | #define ALOGVV(a...) do { } while(0) |
| 27 | #endif |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 28 | #include <errno.h> |
| 29 | #include <pthread.h> |
| 30 | #include <stdint.h> |
| 31 | #include <sys/time.h> |
| 32 | #include <stdlib.h> |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 33 | #include <math.h> |
Eric Laurent | c4aef75 | 2013-09-12 17:45:53 -0700 | [diff] [blame] | 34 | #include <dlfcn.h> |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 35 | #include <sys/resource.h> |
| 36 | #include <sys/prctl.h> |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 37 | |
| 38 | #include <cutils/log.h> |
| 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> |
Steve Kondik | 3abbbc8 | 2014-11-29 14:14:43 -0800 | [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" |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 50 | #include "platform_api.h" |
| 51 | #include <platform.h> |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 52 | #include "audio_extn.h" |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [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" |
ApurupaPattapu | 0c56687 | 2014-01-10 14:46:02 -0800 | [diff] [blame] | 56 | #include "sound/asound.h" |
| 57 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 58 | #define COMPRESS_OFFLOAD_NUM_FRAGMENTS 4 |
| 59 | /* ToDo: Check and update a proper value in msec */ |
Alexy Joseph | 62babb9 | 2015-03-03 19:01:03 -0800 | [diff] [blame] | 60 | #define COMPRESS_OFFLOAD_PLAYBACK_LATENCY 50 |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 61 | #define COMPRESS_PLAYBACK_VOLUME_MAX 0x2000 |
| 62 | |
Divya Narayanan Poojary | ab9b1ef | 2014-09-12 15:52:36 +0530 | [diff] [blame] | 63 | #define PROXY_OPEN_RETRY_COUNT 100 |
| 64 | #define PROXY_OPEN_WAIT_TIME 20 |
ApurupaPattapu | 0c56687 | 2014-01-10 14:46:02 -0800 | [diff] [blame] | 65 | |
Steve Kondik | b045f47 | 2014-11-12 23:24:07 -0800 | [diff] [blame] | 66 | #ifdef LOW_LATENCY_PRIMARY |
| 67 | #define USECASE_AUDIO_PLAYBACK_PRIMARY USECASE_AUDIO_PLAYBACK_LOW_LATENCY |
| 68 | #else |
Haynes Mathew George | bf14371 | 2013-12-03 13:02:53 -0800 | [diff] [blame] | 69 | #define USECASE_AUDIO_PLAYBACK_PRIMARY USECASE_AUDIO_PLAYBACK_DEEP_BUFFER |
Steve Kondik | b045f47 | 2014-11-12 23:24:07 -0800 | [diff] [blame] | 70 | #endif |
Haynes Mathew George | bf14371 | 2013-12-03 13:02:53 -0800 | [diff] [blame] | 71 | |
Ravi Kumar Alamanda | 1c3de5e | 2014-09-08 15:59:58 -0700 | [diff] [blame] | 72 | static unsigned int configured_low_latency_capture_period_size = |
| 73 | LOW_LATENCY_CAPTURE_PERIOD_SIZE; |
| 74 | |
Steve Kondik | 3abbbc8 | 2014-11-29 14:14:43 -0800 | [diff] [blame] | 75 | /* This constant enables extended precision handling. |
Steve Kondik | 3abbbc8 | 2014-11-29 14:14:43 -0800 | [diff] [blame] | 76 | */ |
| 77 | static const bool k_enable_extended_precision = true; |
| 78 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 79 | struct pcm_config pcm_config_deep_buffer = { |
| 80 | .channels = 2, |
| 81 | .rate = DEFAULT_OUTPUT_SAMPLING_RATE, |
| 82 | .period_size = DEEP_BUFFER_OUTPUT_PERIOD_SIZE, |
| 83 | .period_count = DEEP_BUFFER_OUTPUT_PERIOD_COUNT, |
| 84 | .format = PCM_FORMAT_S16_LE, |
| 85 | .start_threshold = DEEP_BUFFER_OUTPUT_PERIOD_SIZE / 4, |
| 86 | .stop_threshold = INT_MAX, |
| 87 | .avail_min = DEEP_BUFFER_OUTPUT_PERIOD_SIZE / 4, |
| 88 | }; |
| 89 | |
| 90 | struct pcm_config pcm_config_low_latency = { |
| 91 | .channels = 2, |
| 92 | .rate = DEFAULT_OUTPUT_SAMPLING_RATE, |
| 93 | .period_size = LOW_LATENCY_OUTPUT_PERIOD_SIZE, |
| 94 | .period_count = LOW_LATENCY_OUTPUT_PERIOD_COUNT, |
| 95 | .format = PCM_FORMAT_S16_LE, |
| 96 | .start_threshold = LOW_LATENCY_OUTPUT_PERIOD_SIZE / 4, |
| 97 | .stop_threshold = INT_MAX, |
| 98 | .avail_min = LOW_LATENCY_OUTPUT_PERIOD_SIZE / 4, |
| 99 | }; |
| 100 | |
| 101 | struct pcm_config pcm_config_hdmi_multi = { |
| 102 | .channels = HDMI_MULTI_DEFAULT_CHANNEL_COUNT, /* changed when the stream is opened */ |
| 103 | .rate = DEFAULT_OUTPUT_SAMPLING_RATE, /* changed when the stream is opened */ |
| 104 | .period_size = HDMI_MULTI_PERIOD_SIZE, |
| 105 | .period_count = HDMI_MULTI_PERIOD_COUNT, |
| 106 | .format = PCM_FORMAT_S16_LE, |
| 107 | .start_threshold = 0, |
| 108 | .stop_threshold = INT_MAX, |
| 109 | .avail_min = 0, |
| 110 | }; |
| 111 | |
| 112 | struct pcm_config pcm_config_audio_capture = { |
| 113 | .channels = 2, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 114 | .period_count = AUDIO_CAPTURE_PERIOD_COUNT, |
| 115 | .format = PCM_FORMAT_S16_LE, |
| 116 | }; |
| 117 | |
Divya Narayanan Poojary | ab9b1ef | 2014-09-12 15:52:36 +0530 | [diff] [blame] | 118 | #define AFE_PROXY_CHANNEL_COUNT 2 |
| 119 | #define AFE_PROXY_SAMPLING_RATE 48000 |
| 120 | |
| 121 | #define AFE_PROXY_PLAYBACK_PERIOD_SIZE 768 |
| 122 | #define AFE_PROXY_PLAYBACK_PERIOD_COUNT 4 |
| 123 | |
| 124 | struct pcm_config pcm_config_afe_proxy_playback = { |
| 125 | .channels = AFE_PROXY_CHANNEL_COUNT, |
| 126 | .rate = AFE_PROXY_SAMPLING_RATE, |
| 127 | .period_size = AFE_PROXY_PLAYBACK_PERIOD_SIZE, |
| 128 | .period_count = AFE_PROXY_PLAYBACK_PERIOD_COUNT, |
| 129 | .format = PCM_FORMAT_S16_LE, |
| 130 | .start_threshold = AFE_PROXY_PLAYBACK_PERIOD_SIZE, |
| 131 | .stop_threshold = INT_MAX, |
| 132 | .avail_min = AFE_PROXY_PLAYBACK_PERIOD_SIZE, |
| 133 | }; |
| 134 | |
| 135 | #define AFE_PROXY_RECORD_PERIOD_SIZE 768 |
| 136 | #define AFE_PROXY_RECORD_PERIOD_COUNT 4 |
| 137 | |
| 138 | struct pcm_config pcm_config_afe_proxy_record = { |
| 139 | .channels = AFE_PROXY_CHANNEL_COUNT, |
| 140 | .rate = AFE_PROXY_SAMPLING_RATE, |
| 141 | .period_size = AFE_PROXY_RECORD_PERIOD_SIZE, |
| 142 | .period_count = AFE_PROXY_RECORD_PERIOD_COUNT, |
| 143 | .format = PCM_FORMAT_S16_LE, |
| 144 | .start_threshold = AFE_PROXY_RECORD_PERIOD_SIZE, |
| 145 | .stop_threshold = INT_MAX, |
| 146 | .avail_min = AFE_PROXY_RECORD_PERIOD_SIZE, |
| 147 | }; |
| 148 | |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 149 | const char * const use_case_table[AUDIO_USECASE_MAX] = { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 150 | [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = "deep-buffer-playback", |
| 151 | [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = "low-latency-playback", |
| 152 | [USECASE_AUDIO_PLAYBACK_MULTI_CH] = "multi-channel-playback", |
Shruthi Krishna | ace1085 | 2013-10-25 14:32:12 -0700 | [diff] [blame] | 153 | [USECASE_AUDIO_PLAYBACK_OFFLOAD] = "compress-offload-playback", |
Subhash Chandra Bose Naripeddy | 148144e | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 154 | #ifdef MULTIPLE_OFFLOAD_ENABLED |
| 155 | [USECASE_AUDIO_PLAYBACK_OFFLOAD2] = "compress-offload-playback2", |
| 156 | [USECASE_AUDIO_PLAYBACK_OFFLOAD3] = "compress-offload-playback3", |
| 157 | [USECASE_AUDIO_PLAYBACK_OFFLOAD4] = "compress-offload-playback4", |
| 158 | [USECASE_AUDIO_PLAYBACK_OFFLOAD5] = "compress-offload-playback5", |
| 159 | [USECASE_AUDIO_PLAYBACK_OFFLOAD6] = "compress-offload-playback6", |
| 160 | [USECASE_AUDIO_PLAYBACK_OFFLOAD7] = "compress-offload-playback7", |
| 161 | [USECASE_AUDIO_PLAYBACK_OFFLOAD8] = "compress-offload-playback8", |
| 162 | [USECASE_AUDIO_PLAYBACK_OFFLOAD9] = "compress-offload-playback9", |
| 163 | #endif |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 164 | [USECASE_AUDIO_RECORD] = "audio-record", |
Mingming Yin | e62d784 | 2013-10-25 16:26:03 -0700 | [diff] [blame] | 165 | [USECASE_AUDIO_RECORD_COMPRESS] = "audio-record-compress", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 166 | [USECASE_AUDIO_RECORD_LOW_LATENCY] = "low-latency-record", |
Preetam Singh Ranawat | de84f1a | 2013-11-01 14:58:16 -0700 | [diff] [blame] | 167 | [USECASE_AUDIO_RECORD_FM_VIRTUAL] = "fm-virtual-record", |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 168 | [USECASE_AUDIO_PLAYBACK_FM] = "play-fm", |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 169 | [USECASE_AUDIO_HFP_SCO] = "hfp-sco", |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 170 | [USECASE_AUDIO_HFP_SCO_WB] = "hfp-sco-wb", |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 171 | [USECASE_VOICE_CALL] = "voice-call", |
Mingming Yin | ee73360 | 2014-04-03 17:47:22 -0700 | [diff] [blame] | 172 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 173 | [USECASE_VOICE2_CALL] = "voice2-call", |
| 174 | [USECASE_VOLTE_CALL] = "volte-call", |
| 175 | [USECASE_QCHAT_CALL] = "qchat-call", |
Vicky Sehrawat | 111aeb3 | 2014-02-12 17:58:59 -0800 | [diff] [blame] | 176 | [USECASE_VOWLAN_CALL] = "vowlan-call", |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 177 | [USECASE_COMPRESS_VOIP_CALL] = "compress-voip-call", |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 178 | [USECASE_INCALL_REC_UPLINK] = "incall-rec-uplink", |
| 179 | [USECASE_INCALL_REC_DOWNLINK] = "incall-rec-downlink", |
| 180 | [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = "incall-rec-uplink-and-downlink", |
Helen Zeng | e56b485 | 2013-12-03 16:54:40 -0800 | [diff] [blame] | 181 | [USECASE_INCALL_REC_UPLINK_COMPRESS] = "incall-rec-uplink-compress", |
| 182 | [USECASE_INCALL_REC_DOWNLINK_COMPRESS] = "incall-rec-downlink-compress", |
| 183 | [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS] = "incall-rec-uplink-and-downlink-compress", |
| 184 | |
Shiv Maliyappanahalli | f3b9a42 | 2013-10-22 16:38:08 -0700 | [diff] [blame] | 185 | [USECASE_INCALL_MUSIC_UPLINK] = "incall_music_uplink", |
| 186 | [USECASE_INCALL_MUSIC_UPLINK2] = "incall_music_uplink2", |
Gopikrishnaiah Anandan | f538cef | 2013-10-28 14:06:03 -0700 | [diff] [blame] | 187 | [USECASE_AUDIO_SPKR_CALIB_RX] = "spkr-rx-calib", |
| 188 | [USECASE_AUDIO_SPKR_CALIB_TX] = "spkr-vi-record", |
Divya Narayanan Poojary | ab9b1ef | 2014-09-12 15:52:36 +0530 | [diff] [blame] | 189 | |
| 190 | [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = "afe-proxy-playback", |
| 191 | [USECASE_AUDIO_RECORD_AFE_PROXY] = "afe-proxy-record", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 192 | }; |
| 193 | |
Subhash Chandra Bose Naripeddy | 148144e | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 194 | static const audio_usecase_t offload_usecases[] = { |
| 195 | USECASE_AUDIO_PLAYBACK_OFFLOAD, |
| 196 | #ifdef MULTIPLE_OFFLOAD_ENABLED |
| 197 | USECASE_AUDIO_PLAYBACK_OFFLOAD2, |
| 198 | USECASE_AUDIO_PLAYBACK_OFFLOAD3, |
Steve Kondik | ac72feb | 2014-07-20 23:15:34 -0700 | [diff] [blame] | 199 | #ifndef PLATFORM_MSM8974 |
Subhash Chandra Bose Naripeddy | 148144e | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 200 | USECASE_AUDIO_PLAYBACK_OFFLOAD4, |
| 201 | USECASE_AUDIO_PLAYBACK_OFFLOAD5, |
| 202 | USECASE_AUDIO_PLAYBACK_OFFLOAD6, |
| 203 | USECASE_AUDIO_PLAYBACK_OFFLOAD7, |
Steve Kondik | ac72feb | 2014-07-20 23:15:34 -0700 | [diff] [blame] | 204 | #endif |
Subhash Chandra Bose Naripeddy | 148144e | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 205 | USECASE_AUDIO_PLAYBACK_OFFLOAD8, |
Steve Kondik | ac72feb | 2014-07-20 23:15:34 -0700 | [diff] [blame] | 206 | #ifndef PLATFORM_MSM8974 |
Subhash Chandra Bose Naripeddy | 148144e | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 207 | USECASE_AUDIO_PLAYBACK_OFFLOAD9, |
| 208 | #endif |
Steve Kondik | ac72feb | 2014-07-20 23:15:34 -0700 | [diff] [blame] | 209 | #endif |
Subhash Chandra Bose Naripeddy | 148144e | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 210 | }; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 211 | |
| 212 | #define STRING_TO_ENUM(string) { #string, string } |
| 213 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 214 | struct string_to_enum { |
| 215 | const char *name; |
| 216 | uint32_t value; |
| 217 | }; |
| 218 | |
| 219 | static const struct string_to_enum out_channels_name_to_enum_table[] = { |
| 220 | STRING_TO_ENUM(AUDIO_CHANNEL_OUT_STEREO), |
| 221 | STRING_TO_ENUM(AUDIO_CHANNEL_OUT_5POINT1), |
| 222 | STRING_TO_ENUM(AUDIO_CHANNEL_OUT_7POINT1), |
| 223 | }; |
| 224 | |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 225 | static struct audio_device *adev = NULL; |
| 226 | static pthread_mutex_t adev_init_lock; |
Kiran Kandi | 910e186 | 2013-10-29 13:29:42 -0700 | [diff] [blame] | 227 | static unsigned int audio_device_ref_count; |
| 228 | |
Haynes Mathew George | 5191a85 | 2013-09-11 14:19:36 -0700 | [diff] [blame] | 229 | static int set_voice_volume_l(struct audio_device *adev, float volume); |
Krishnankutty Kolathappilly | 9d1632f | 2014-01-09 12:45:31 -0800 | [diff] [blame] | 230 | |
Ethan Chen | 79c356c | 2015-06-07 12:26:14 -0700 | [diff] [blame] | 231 | static amplifier_device_t * get_amplifier_device(void) |
| 232 | { |
| 233 | int rc; |
| 234 | amplifier_module_t *module; |
| 235 | |
| 236 | if (adev->amp) |
| 237 | return adev->amp; |
| 238 | |
| 239 | rc = hw_get_module(AMPLIFIER_HARDWARE_MODULE_ID, |
| 240 | (const hw_module_t **) &module); |
| 241 | if (rc) { |
| 242 | ALOGV("%s: Failed to obtain reference to amplifier module: %s\n", |
| 243 | __func__, strerror(-rc)); |
| 244 | return NULL; |
| 245 | } |
| 246 | |
| 247 | rc = amplifier_device_open((const hw_module_t *) module, &adev->amp); |
| 248 | if (rc) { |
| 249 | ALOGV("%s: Failed to open amplifier hardware device: %s\n", |
| 250 | __func__, strerror(-rc)); |
| 251 | return NULL; |
| 252 | } |
| 253 | |
| 254 | return adev->amp; |
| 255 | } |
| 256 | |
| 257 | static int amplifier_open(void) |
| 258 | { |
| 259 | amplifier_device_t *amp = get_amplifier_device(); |
| 260 | |
| 261 | if (!amp) { |
| 262 | return -ENODEV; |
| 263 | } |
| 264 | |
| 265 | return 0; |
| 266 | } |
| 267 | |
| 268 | static int amplifier_set_input_devices(uint32_t devices) |
| 269 | { |
| 270 | amplifier_device_t *amp = get_amplifier_device(); |
| 271 | if (amp && amp->set_input_devices) |
| 272 | return amp->set_input_devices(amp, devices); |
| 273 | |
| 274 | return 0; |
| 275 | } |
| 276 | |
| 277 | static int amplifier_set_output_devices(uint32_t devices) |
| 278 | { |
| 279 | amplifier_device_t *amp = get_amplifier_device(); |
| 280 | if (amp && amp->set_output_devices) |
| 281 | return amp->set_output_devices(amp, devices); |
| 282 | |
| 283 | return 0; |
| 284 | } |
| 285 | |
Ethan Chen | 6720ae6 | 2015-07-03 21:35:30 -0700 | [diff] [blame] | 286 | static int amplifier_enable_devices(uint32_t devices, bool enable) |
| 287 | { |
| 288 | amplifier_device_t *amp = get_amplifier_device(); |
| 289 | bool is_output = devices > SND_DEVICE_OUT_BEGIN && |
| 290 | devices < SND_DEVICE_OUT_END; |
| 291 | |
| 292 | if (amp && amp->enable_output_devices && is_output) |
| 293 | return amp->enable_output_devices(amp, devices, enable); |
| 294 | |
| 295 | if (amp && amp->enable_input_devices && !is_output) |
| 296 | return amp->enable_input_devices(amp, devices, enable); |
| 297 | |
| 298 | return 0; |
| 299 | } |
| 300 | |
Ethan Chen | 79c356c | 2015-06-07 12:26:14 -0700 | [diff] [blame] | 301 | static int amplifier_set_mode(audio_mode_t mode) |
| 302 | { |
| 303 | amplifier_device_t *amp = get_amplifier_device(); |
| 304 | if (amp && amp->set_mode) |
| 305 | return amp->set_mode(amp, mode); |
| 306 | |
| 307 | return 0; |
| 308 | } |
| 309 | |
| 310 | static int amplifier_output_stream_start(struct audio_stream_out *stream, |
| 311 | bool offload) |
| 312 | { |
| 313 | amplifier_device_t *amp = get_amplifier_device(); |
| 314 | if (amp && amp->output_stream_start) |
| 315 | return amp->output_stream_start(amp, stream, offload); |
| 316 | |
| 317 | return 0; |
| 318 | } |
| 319 | |
| 320 | static int amplifier_input_stream_start(struct audio_stream_in *stream) |
| 321 | { |
| 322 | amplifier_device_t *amp = get_amplifier_device(); |
| 323 | if (amp && amp->input_stream_start) |
| 324 | return amp->input_stream_start(amp, stream); |
| 325 | |
| 326 | return 0; |
| 327 | } |
| 328 | |
| 329 | static int amplifier_output_stream_standby(struct audio_stream_out *stream) |
| 330 | { |
| 331 | amplifier_device_t *amp = get_amplifier_device(); |
| 332 | if (amp && amp->output_stream_standby) |
| 333 | return amp->output_stream_standby(amp, stream); |
| 334 | |
| 335 | return 0; |
| 336 | } |
| 337 | |
| 338 | static int amplifier_input_stream_standby(struct audio_stream_in *stream) |
| 339 | { |
| 340 | amplifier_device_t *amp = get_amplifier_device(); |
| 341 | if (amp && amp->input_stream_standby) |
| 342 | return amp->input_stream_standby(amp, stream); |
| 343 | |
| 344 | return 0; |
| 345 | } |
| 346 | |
| 347 | static int amplifier_close(void) |
| 348 | { |
| 349 | amplifier_device_t *amp = get_amplifier_device(); |
| 350 | if (amp) |
| 351 | amplifier_device_close(amp); |
| 352 | |
| 353 | return 0; |
| 354 | } |
| 355 | |
Krishnankutty Kolathappilly | 9d1632f | 2014-01-09 12:45:31 -0800 | [diff] [blame] | 356 | static int check_and_set_gapless_mode(struct audio_device *adev) { |
| 357 | |
| 358 | |
| 359 | char value[PROPERTY_VALUE_MAX] = {0}; |
| 360 | bool gapless_enabled = false; |
| 361 | const char *mixer_ctl_name = "Compress Gapless Playback"; |
| 362 | struct mixer_ctl *ctl; |
| 363 | |
| 364 | ALOGV("%s:", __func__); |
| 365 | property_get("audio.offload.gapless.enabled", value, NULL); |
| 366 | gapless_enabled = atoi(value) || !strncmp("true", value, 4); |
| 367 | |
| 368 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 369 | if (!ctl) { |
| 370 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 371 | __func__, mixer_ctl_name); |
| 372 | return -EINVAL; |
| 373 | } |
| 374 | |
| 375 | if (mixer_ctl_set_value(ctl, 0, gapless_enabled) < 0) { |
| 376 | ALOGE("%s: Could not set gapless mode %d", |
| 377 | __func__, gapless_enabled); |
| 378 | return -EINVAL; |
| 379 | } |
| 380 | return 0; |
| 381 | } |
Haynes Mathew George | 5191a85 | 2013-09-11 14:19:36 -0700 | [diff] [blame] | 382 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 383 | static bool is_supported_format(audio_format_t format) |
| 384 | { |
Steve Kondik | 3fdf4fc | 2014-12-10 21:15:43 -0800 | [diff] [blame] | 385 | switch (format) { |
Steve Kondik | 3abbbc8 | 2014-11-29 14:14:43 -0800 | [diff] [blame] | 386 | case AUDIO_FORMAT_MP3: |
Steve Kondik | 3fdf4fc | 2014-12-10 21:15:43 -0800 | [diff] [blame] | 387 | case AUDIO_FORMAT_PCM_16_BIT_OFFLOAD: |
| 388 | case AUDIO_FORMAT_PCM_24_BIT_OFFLOAD: |
Steve Kondik | 6bedcdf | 2014-07-21 11:48:30 -0700 | [diff] [blame] | 389 | #ifdef FLAC_OFFLOAD_ENABLED |
Steve Kondik | 3abbbc8 | 2014-11-29 14:14:43 -0800 | [diff] [blame] | 390 | case AUDIO_FORMAT_FLAC: |
Steve Kondik | 6bedcdf | 2014-07-21 11:48:30 -0700 | [diff] [blame] | 391 | #endif |
Steve Kondik | 3abbbc8 | 2014-11-29 14:14:43 -0800 | [diff] [blame] | 392 | #ifdef WMA_OFFLOAD_ENABLED |
| 393 | case AUDIO_FORMAT_WMA: |
| 394 | case AUDIO_FORMAT_WMA_PRO: |
| 395 | #endif |
| 396 | #ifdef MP2_OFFLOAD_ENABLED |
| 397 | case AUDIO_FORMAT_MP2: |
| 398 | #endif |
| 399 | case AUDIO_FORMAT_AAC_LC: |
| 400 | case AUDIO_FORMAT_AAC_HE_V1: |
| 401 | case AUDIO_FORMAT_AAC_HE_V2: |
Ashish Jain | cff6e3e | 2014-08-25 20:36:25 +0530 | [diff] [blame] | 402 | return true; |
Steve Kondik | 3abbbc8 | 2014-11-29 14:14:43 -0800 | [diff] [blame] | 403 | |
Steve Kondik | 3fdf4fc | 2014-12-10 21:15:43 -0800 | [diff] [blame] | 404 | default: |
| 405 | return false; |
Ashish Jain | cff6e3e | 2014-08-25 20:36:25 +0530 | [diff] [blame] | 406 | } |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 407 | return false; |
| 408 | } |
| 409 | |
| 410 | static int get_snd_codec_id(audio_format_t format) |
| 411 | { |
| 412 | int id = 0; |
| 413 | |
Ashish Jain | cff6e3e | 2014-08-25 20:36:25 +0530 | [diff] [blame] | 414 | switch (format & AUDIO_FORMAT_MAIN_MASK) { |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 415 | case AUDIO_FORMAT_MP3: |
| 416 | id = SND_AUDIOCODEC_MP3; |
| 417 | break; |
| 418 | case AUDIO_FORMAT_AAC: |
| 419 | id = SND_AUDIOCODEC_AAC; |
| 420 | break; |
Ashish Jain | cff6e3e | 2014-08-25 20:36:25 +0530 | [diff] [blame] | 421 | case AUDIO_FORMAT_PCM_OFFLOAD: |
ApurupaPattapu | 0c56687 | 2014-01-10 14:46:02 -0800 | [diff] [blame] | 422 | id = SND_AUDIOCODEC_PCM; |
| 423 | break; |
Steve Kondik | 6bedcdf | 2014-07-21 11:48:30 -0700 | [diff] [blame] | 424 | #ifdef FLAC_OFFLOAD_ENABLED |
ApurupaPattapu | 9d6b436 | 2014-02-27 10:24:11 -0800 | [diff] [blame] | 425 | case AUDIO_FORMAT_FLAC: |
| 426 | id = SND_AUDIOCODEC_FLAC; |
| 427 | break; |
Steve Kondik | 6bedcdf | 2014-07-21 11:48:30 -0700 | [diff] [blame] | 428 | #endif |
Ethan Chen | c856d97 | 2014-07-25 14:57:15 -0700 | [diff] [blame] | 429 | #ifdef WMA_OFFLOAD_ENABLED |
Steve Kondik | ba3b35d | 2014-07-18 01:49:48 -0700 | [diff] [blame] | 430 | case AUDIO_FORMAT_WMA: |
| 431 | id = SND_AUDIOCODEC_WMA; |
| 432 | break; |
| 433 | case AUDIO_FORMAT_WMA_PRO: |
| 434 | id = SND_AUDIOCODEC_WMA_PRO; |
| 435 | break; |
Ethan Chen | c856d97 | 2014-07-25 14:57:15 -0700 | [diff] [blame] | 436 | #endif |
| 437 | #ifdef MP2_OFFLOAD_ENABLED |
Steve Kondik | ba3b35d | 2014-07-18 01:49:48 -0700 | [diff] [blame] | 438 | case AUDIO_FORMAT_MP2: |
| 439 | id = SND_AUDIOCODEC_MP2; |
| 440 | break; |
Ethan Chen | c856d97 | 2014-07-25 14:57:15 -0700 | [diff] [blame] | 441 | #endif |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 442 | default: |
Mingming Yin | 9031010 | 2013-11-13 16:57:00 -0800 | [diff] [blame] | 443 | ALOGE("%s: Unsupported audio format :%x", __func__, format); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | return id; |
| 447 | } |
Ravi Kumar Alamanda | f996704 | 2013-02-14 19:35:14 -0800 | [diff] [blame] | 448 | |
Avinash Vaish | 8005dc8 | 2014-07-24 15:36:33 +0530 | [diff] [blame] | 449 | static int enable_audio_route_for_voice_usecases(struct audio_device *adev, |
| 450 | struct audio_usecase *uc_info) |
| 451 | { |
| 452 | struct listnode *node; |
| 453 | struct audio_usecase *usecase; |
| 454 | |
| 455 | if (uc_info == NULL) |
| 456 | return -EINVAL; |
| 457 | |
| 458 | /* Re-route all voice usecases on the shared backend other than the |
| 459 | specified usecase to new snd devices */ |
| 460 | list_for_each(node, &adev->usecase_list) { |
| 461 | usecase = node_to_item(node, struct audio_usecase, list); |
| 462 | if ((usecase->type == VOICE_CALL || usecase->type == VOIP_CALL) && |
| 463 | (usecase != uc_info)) |
| 464 | enable_audio_route(adev, usecase); |
| 465 | } |
| 466 | return 0; |
| 467 | } |
| 468 | |
Venkata Narendra Kumar Gutta | c9e9e2c | 2014-07-09 16:29:28 +0530 | [diff] [blame] | 469 | int get_snd_card_state(struct audio_device *adev) |
Naresh Tanniru | cef332d | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 470 | { |
| 471 | int snd_scard_state; |
| 472 | |
| 473 | if (!adev) |
| 474 | return SND_CARD_STATE_OFFLINE; |
| 475 | |
| 476 | pthread_mutex_lock(&adev->snd_card_status.lock); |
| 477 | snd_scard_state = adev->snd_card_status.state; |
| 478 | pthread_mutex_unlock(&adev->snd_card_status.lock); |
| 479 | |
| 480 | return snd_scard_state; |
| 481 | } |
| 482 | |
| 483 | static int set_snd_card_state(struct audio_device *adev, int snd_scard_state) |
| 484 | { |
| 485 | if (!adev) |
| 486 | return -ENOSYS; |
| 487 | |
| 488 | pthread_mutex_lock(&adev->snd_card_status.lock); |
| 489 | adev->snd_card_status.state = snd_scard_state; |
| 490 | pthread_mutex_unlock(&adev->snd_card_status.lock); |
| 491 | |
| 492 | return 0; |
| 493 | } |
| 494 | |
Ravi Kumar Alamanda | 1c3de5e | 2014-09-08 15:59:58 -0700 | [diff] [blame] | 495 | int pcm_ioctl(struct pcm *pcm, int request, ...) |
| 496 | { |
| 497 | va_list ap; |
| 498 | void * arg; |
| 499 | int pcm_fd = *(int*)pcm; |
| 500 | |
| 501 | va_start(ap, request); |
| 502 | arg = va_arg(ap, void *); |
| 503 | va_end(ap); |
| 504 | |
| 505 | return ioctl(pcm_fd, request, arg); |
| 506 | } |
| 507 | |
Gopikrishnaiah Anandan | f538cef | 2013-10-28 14:06:03 -0700 | [diff] [blame] | 508 | int enable_audio_route(struct audio_device *adev, |
Haynes Mathew George | ea09892 | 2014-04-24 17:53:50 -0700 | [diff] [blame] | 509 | struct audio_usecase *usecase) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 510 | { |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 511 | snd_device_t snd_device; |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 512 | char mixer_path[MIXER_PATH_MAX_LENGTH]; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 513 | |
| 514 | if (usecase == NULL) |
| 515 | return -EINVAL; |
| 516 | |
| 517 | ALOGV("%s: enter: usecase(%d)", __func__, usecase->id); |
| 518 | |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 519 | if (usecase->type == PCM_CAPTURE) |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 520 | snd_device = usecase->in_snd_device; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 521 | else |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 522 | snd_device = usecase->out_snd_device; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 523 | |
Subhash Chandra Bose Naripeddy | e0a0712 | 2013-12-14 00:34:53 -0800 | [diff] [blame] | 524 | #ifdef DS1_DOLBY_DAP_ENABLED |
| 525 | audio_extn_dolby_set_dmid(adev); |
| 526 | audio_extn_dolby_set_endpoint(adev); |
| 527 | #endif |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 528 | strcpy(mixer_path, use_case_table[usecase->id]); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 529 | platform_add_backend_name(mixer_path, snd_device); |
Haynes Mathew George | f930675 | 2014-04-24 11:53:44 -0700 | [diff] [blame] | 530 | ALOGV("%s: apply mixer and update path: %s", __func__, mixer_path); |
| 531 | audio_route_apply_and_update_path(adev->audio_route, mixer_path); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 532 | ALOGV("%s: exit", __func__); |
| 533 | return 0; |
| 534 | } |
| 535 | |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 536 | int disable_audio_route(struct audio_device *adev, |
Haynes Mathew George | ea09892 | 2014-04-24 17:53:50 -0700 | [diff] [blame] | 537 | struct audio_usecase *usecase) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 538 | { |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 539 | snd_device_t snd_device; |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 540 | char mixer_path[MIXER_PATH_MAX_LENGTH]; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 541 | |
| 542 | if (usecase == NULL) |
| 543 | return -EINVAL; |
| 544 | |
| 545 | ALOGV("%s: enter: usecase(%d)", __func__, usecase->id); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 546 | if (usecase->type == PCM_CAPTURE) |
| 547 | snd_device = usecase->in_snd_device; |
| 548 | else |
| 549 | snd_device = usecase->out_snd_device; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 550 | strcpy(mixer_path, use_case_table[usecase->id]); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 551 | platform_add_backend_name(mixer_path, snd_device); |
Haynes Mathew George | f930675 | 2014-04-24 11:53:44 -0700 | [diff] [blame] | 552 | ALOGV("%s: reset and update mixer path: %s", __func__, mixer_path); |
| 553 | audio_route_reset_and_update_path(adev->audio_route, mixer_path); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 554 | ALOGV("%s: exit", __func__); |
| 555 | return 0; |
| 556 | } |
| 557 | |
Gopikrishnaiah Anandan | f538cef | 2013-10-28 14:06:03 -0700 | [diff] [blame] | 558 | int enable_snd_device(struct audio_device *adev, |
Haynes Mathew George | ea09892 | 2014-04-24 17:53:50 -0700 | [diff] [blame] | 559 | snd_device_t snd_device) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 560 | { |
Ravi Kumar Alamanda | 48c921d | 2013-10-29 06:07:44 -0700 | [diff] [blame] | 561 | char device_name[DEVICE_NAME_MAX_SIZE] = {0}; |
| 562 | |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 563 | if (snd_device < SND_DEVICE_MIN || |
| 564 | snd_device >= SND_DEVICE_MAX) { |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 565 | ALOGE("%s: Invalid sound device %d", __func__, snd_device); |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 566 | return -EINVAL; |
| 567 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 568 | |
| 569 | adev->snd_dev_ref_cnt[snd_device]++; |
Ravi Kumar Alamanda | 48c921d | 2013-10-29 06:07:44 -0700 | [diff] [blame] | 570 | |
| 571 | if(platform_get_snd_device_name_extn(adev->platform, snd_device, device_name) < 0 ) { |
| 572 | ALOGE("%s: Invalid sound device returned", __func__); |
| 573 | return -EINVAL; |
| 574 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 575 | if (adev->snd_dev_ref_cnt[snd_device] > 1) { |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 576 | ALOGV("%s: snd_device(%d: %s) is already active", |
Ravi Kumar Alamanda | 48c921d | 2013-10-29 06:07:44 -0700 | [diff] [blame] | 577 | __func__, snd_device, device_name); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 578 | return 0; |
| 579 | } |
| 580 | |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 581 | /* start usb playback thread */ |
| 582 | if(SND_DEVICE_OUT_USB_HEADSET == snd_device || |
| 583 | SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET == snd_device) |
| 584 | audio_extn_usb_start_playback(adev); |
| 585 | |
| 586 | /* start usb capture thread */ |
| 587 | if(SND_DEVICE_IN_USB_HEADSET_MIC == snd_device) |
| 588 | audio_extn_usb_start_capture(adev); |
| 589 | |
Tony Layher | 692f19a | 2015-01-03 13:16:45 -0500 | [diff] [blame] | 590 | if ((snd_device == SND_DEVICE_OUT_SPEAKER || |
| 591 | snd_device == SND_DEVICE_OUT_VOICE_SPEAKER) && |
Gopikrishnaiah Anandan | f538cef | 2013-10-28 14:06:03 -0700 | [diff] [blame] | 592 | audio_extn_spkr_prot_is_enabled()) { |
| 593 | if (audio_extn_spkr_prot_start_processing(snd_device)) { |
| 594 | ALOGE("%s: spkr_start_processing failed", __func__); |
| 595 | return -EINVAL; |
| 596 | } |
| 597 | } else { |
| 598 | ALOGV("%s: snd_device(%d: %s)", __func__, |
Steve Kondik | 6288f9e | 2014-12-27 13:36:30 -0800 | [diff] [blame] | 599 | snd_device, device_name); |
Gopikrishnaiah Anandan | f538cef | 2013-10-28 14:06:03 -0700 | [diff] [blame] | 600 | if (platform_send_audio_calibration(adev->platform, snd_device) < 0) { |
| 601 | adev->snd_dev_ref_cnt[snd_device]--; |
| 602 | return -EINVAL; |
| 603 | } |
Steve Kondik | 6288f9e | 2014-12-27 13:36:30 -0800 | [diff] [blame] | 604 | audio_extn_listen_update_status(snd_device, |
| 605 | LISTEN_EVENT_SND_DEVICE_BUSY); |
Kiran Kandi | de144c8 | 2013-11-20 15:58:32 -0800 | [diff] [blame] | 606 | |
Ethan Chen | 6720ae6 | 2015-07-03 21:35:30 -0700 | [diff] [blame] | 607 | amplifier_enable_devices(snd_device, true); |
Haynes Mathew George | f930675 | 2014-04-24 11:53:44 -0700 | [diff] [blame] | 608 | audio_route_apply_and_update_path(adev->audio_route, device_name); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 609 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 610 | return 0; |
| 611 | } |
| 612 | |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 613 | int disable_snd_device(struct audio_device *adev, |
Haynes Mathew George | ea09892 | 2014-04-24 17:53:50 -0700 | [diff] [blame] | 614 | snd_device_t snd_device) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 615 | { |
Ravi Kumar Alamanda | 48c921d | 2013-10-29 06:07:44 -0700 | [diff] [blame] | 616 | char device_name[DEVICE_NAME_MAX_SIZE] = {0}; |
| 617 | |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 618 | if (snd_device < SND_DEVICE_MIN || |
| 619 | snd_device >= SND_DEVICE_MAX) { |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 620 | ALOGE("%s: Invalid sound device %d", __func__, snd_device); |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 621 | return -EINVAL; |
| 622 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 623 | if (adev->snd_dev_ref_cnt[snd_device] <= 0) { |
| 624 | ALOGE("%s: device ref cnt is already 0", __func__); |
| 625 | return -EINVAL; |
| 626 | } |
Ravi Kumar Alamanda | 48c921d | 2013-10-29 06:07:44 -0700 | [diff] [blame] | 627 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 628 | adev->snd_dev_ref_cnt[snd_device]--; |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 629 | |
Ravi Kumar Alamanda | 48c921d | 2013-10-29 06:07:44 -0700 | [diff] [blame] | 630 | if(platform_get_snd_device_name_extn(adev->platform, snd_device, device_name) < 0) { |
| 631 | ALOGE("%s: Invalid sound device returned", __func__); |
| 632 | return -EINVAL; |
| 633 | } |
| 634 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 635 | if (adev->snd_dev_ref_cnt[snd_device] == 0) { |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 636 | ALOGV("%s: snd_device(%d: %s)", __func__, |
Ravi Kumar Alamanda | 48c921d | 2013-10-29 06:07:44 -0700 | [diff] [blame] | 637 | snd_device, device_name); |
Ravi Kumar Alamanda | fae4211 | 2013-11-07 23:31:54 -0800 | [diff] [blame] | 638 | /* exit usb play back thread */ |
| 639 | if(SND_DEVICE_OUT_USB_HEADSET == snd_device || |
| 640 | SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET == snd_device) |
| 641 | audio_extn_usb_stop_playback(); |
| 642 | |
| 643 | /* exit usb capture thread */ |
| 644 | if(SND_DEVICE_IN_USB_HEADSET_MIC == snd_device) |
Rajshekar Eashwarappa | 4dfa075 | 2014-10-02 20:18:20 +0530 | [diff] [blame] | 645 | audio_extn_usb_stop_capture(); |
Tony Layher | 692f19a | 2015-01-03 13:16:45 -0500 | [diff] [blame] | 646 | |
| 647 | if ((snd_device == SND_DEVICE_OUT_SPEAKER || |
| 648 | snd_device == SND_DEVICE_OUT_VOICE_SPEAKER) && |
Gopikrishnaiah Anandan | f538cef | 2013-10-28 14:06:03 -0700 | [diff] [blame] | 649 | audio_extn_spkr_prot_is_enabled()) { |
| 650 | audio_extn_spkr_prot_stop_processing(); |
Ethan Chen | 6720ae6 | 2015-07-03 21:35:30 -0700 | [diff] [blame] | 651 | } else { |
Haynes Mathew George | f930675 | 2014-04-24 11:53:44 -0700 | [diff] [blame] | 652 | audio_route_reset_and_update_path(adev->audio_route, device_name); |
Ethan Chen | 6720ae6 | 2015-07-03 21:35:30 -0700 | [diff] [blame] | 653 | amplifier_enable_devices(snd_device, false); |
| 654 | } |
Kiran Kandi | de144c8 | 2013-11-20 15:58:32 -0800 | [diff] [blame] | 655 | |
Steve Kondik | 6288f9e | 2014-12-27 13:36:30 -0800 | [diff] [blame] | 656 | audio_extn_listen_update_status(snd_device, |
Kiran Kandi | de144c8 | 2013-11-20 15:58:32 -0800 | [diff] [blame] | 657 | LISTEN_EVENT_SND_DEVICE_FREE); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 658 | } |
Ravi Kumar Alamanda | 48c921d | 2013-10-29 06:07:44 -0700 | [diff] [blame] | 659 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 660 | return 0; |
| 661 | } |
| 662 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 663 | static void check_usecases_codec_backend(struct audio_device *adev, |
| 664 | struct audio_usecase *uc_info, |
| 665 | snd_device_t snd_device) |
| 666 | { |
| 667 | struct listnode *node; |
| 668 | struct audio_usecase *usecase; |
| 669 | bool switch_device[AUDIO_USECASE_MAX]; |
| 670 | int i, num_uc_to_switch = 0; |
| 671 | |
| 672 | /* |
| 673 | * This function is to make sure that all the usecases that are active on |
| 674 | * the hardware codec backend are always routed to any one device that is |
| 675 | * handled by the hardware codec. |
| 676 | * For example, if low-latency and deep-buffer usecases are currently active |
| 677 | * on speaker and out_set_parameters(headset) is received on low-latency |
| 678 | * output, then we have to make sure deep-buffer is also switched to headset, |
| 679 | * because of the limitation that both the devices cannot be enabled |
| 680 | * at the same time as they share the same backend. |
| 681 | */ |
ApurupaPattapu | 9d6b436 | 2014-02-27 10:24:11 -0800 | [diff] [blame] | 682 | /* |
| 683 | * This call is to check if we need to force routing for a particular stream |
| 684 | * If there is a backend configuration change for the device when a |
| 685 | * new stream starts, then ADM needs to be closed and re-opened with the new |
| 686 | * configuraion. This call check if we need to re-route all the streams |
| 687 | * associated with the backend. Touch tone + 24 bit playback. |
| 688 | */ |
| 689 | bool force_routing = platform_check_and_set_codec_backend_cfg(adev, uc_info); |
| 690 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 691 | /* Disable all the usecases on the shared backend other than the |
| 692 | specified usecase */ |
| 693 | for (i = 0; i < AUDIO_USECASE_MAX; i++) |
| 694 | switch_device[i] = false; |
| 695 | |
| 696 | list_for_each(node, &adev->usecase_list) { |
| 697 | usecase = node_to_item(node, struct audio_usecase, list); |
Shiv Maliyappanahalli | 80ac628 | 2013-12-20 18:56:15 -0800 | [diff] [blame] | 698 | if (usecase->type != PCM_CAPTURE && |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 699 | usecase != uc_info && |
ApurupaPattapu | 9d6b436 | 2014-02-27 10:24:11 -0800 | [diff] [blame] | 700 | (usecase->out_snd_device != snd_device || force_routing) && |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 701 | usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) { |
| 702 | ALOGV("%s: Usecase (%s) is active on (%s) - disabling ..", |
| 703 | __func__, use_case_table[usecase->id], |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 704 | platform_get_snd_device_name(usecase->out_snd_device)); |
Haynes Mathew George | ea09892 | 2014-04-24 17:53:50 -0700 | [diff] [blame] | 705 | disable_audio_route(adev, usecase); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 706 | switch_device[usecase->id] = true; |
| 707 | num_uc_to_switch++; |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | if (num_uc_to_switch) { |
Haynes Mathew George | f930675 | 2014-04-24 11:53:44 -0700 | [diff] [blame] | 712 | /* All streams have been de-routed. Disable the device */ |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 713 | |
| 714 | list_for_each(node, &adev->usecase_list) { |
| 715 | usecase = node_to_item(node, struct audio_usecase, list); |
| 716 | if (switch_device[usecase->id]) { |
Haynes Mathew George | ea09892 | 2014-04-24 17:53:50 -0700 | [diff] [blame] | 717 | disable_snd_device(adev, usecase->out_snd_device); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 718 | } |
| 719 | } |
| 720 | |
Krishnankutty Kolathappilly | dc4f757 | 2013-11-01 20:07:13 -0700 | [diff] [blame] | 721 | list_for_each(node, &adev->usecase_list) { |
| 722 | usecase = node_to_item(node, struct audio_usecase, list); |
| 723 | if (switch_device[usecase->id]) { |
Haynes Mathew George | ea09892 | 2014-04-24 17:53:50 -0700 | [diff] [blame] | 724 | enable_snd_device(adev, snd_device); |
Krishnankutty Kolathappilly | dc4f757 | 2013-11-01 20:07:13 -0700 | [diff] [blame] | 725 | } |
| 726 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 727 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -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 out_snd_device only before enabling the audio route */ |
| 733 | if (switch_device[usecase->id] ) { |
| 734 | usecase->out_snd_device = snd_device; |
Avinash Vaish | 8005dc8 | 2014-07-24 15:36:33 +0530 | [diff] [blame] | 735 | if (usecase->type != VOICE_CALL && usecase->type != VOIP_CALL) |
| 736 | enable_audio_route(adev, usecase); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 737 | } |
| 738 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 739 | } |
| 740 | } |
| 741 | |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 742 | static void check_and_route_capture_usecases(struct audio_device *adev, |
| 743 | struct audio_usecase *uc_info, |
| 744 | snd_device_t snd_device) |
| 745 | { |
| 746 | struct listnode *node; |
| 747 | struct audio_usecase *usecase; |
| 748 | bool switch_device[AUDIO_USECASE_MAX]; |
| 749 | int i, num_uc_to_switch = 0; |
| 750 | |
| 751 | /* |
| 752 | * This function is to make sure that all the active capture usecases |
| 753 | * are always routed to the same input sound device. |
| 754 | * For example, if audio-record and voice-call usecases are currently |
| 755 | * active on speaker(rx) and speaker-mic (tx) and out_set_parameters(earpiece) |
| 756 | * is received for voice call then we have to make sure that audio-record |
| 757 | * usecase is also switched to earpiece i.e. voice-dmic-ef, |
| 758 | * because of the limitation that two devices cannot be enabled |
| 759 | * at the same time if they share the same backend. |
| 760 | */ |
| 761 | for (i = 0; i < AUDIO_USECASE_MAX; i++) |
| 762 | switch_device[i] = false; |
| 763 | |
| 764 | list_for_each(node, &adev->usecase_list) { |
| 765 | usecase = node_to_item(node, struct audio_usecase, list); |
Shiv Maliyappanahalli | 80ac628 | 2013-12-20 18:56:15 -0800 | [diff] [blame] | 766 | if (usecase->type != PCM_PLAYBACK && |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 767 | usecase != uc_info && |
Avinash Vaish | 4401479 | 2015-03-27 14:46:04 +0530 | [diff] [blame] | 768 | usecase->in_snd_device != snd_device && |
| 769 | (usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND)) { |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 770 | ALOGV("%s: Usecase (%s) is active on (%s) - disabling ..", |
| 771 | __func__, use_case_table[usecase->id], |
Devin Kim | 1e5f353 | 2013-08-09 07:48:29 -0700 | [diff] [blame] | 772 | platform_get_snd_device_name(usecase->in_snd_device)); |
Haynes Mathew George | ea09892 | 2014-04-24 17:53:50 -0700 | [diff] [blame] | 773 | disable_audio_route(adev, usecase); |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 774 | switch_device[usecase->id] = true; |
| 775 | num_uc_to_switch++; |
| 776 | } |
| 777 | } |
| 778 | |
| 779 | if (num_uc_to_switch) { |
Haynes Mathew George | f930675 | 2014-04-24 11:53:44 -0700 | [diff] [blame] | 780 | /* All streams have been de-routed. Disable the device */ |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 781 | |
| 782 | list_for_each(node, &adev->usecase_list) { |
| 783 | usecase = node_to_item(node, struct audio_usecase, list); |
| 784 | if (switch_device[usecase->id]) { |
Haynes Mathew George | ea09892 | 2014-04-24 17:53:50 -0700 | [diff] [blame] | 785 | disable_snd_device(adev, usecase->in_snd_device); |
Shiv Maliyappanahalli | 80ac628 | 2013-12-20 18:56:15 -0800 | [diff] [blame] | 786 | } |
| 787 | } |
| 788 | |
| 789 | list_for_each(node, &adev->usecase_list) { |
| 790 | usecase = node_to_item(node, struct audio_usecase, list); |
| 791 | if (switch_device[usecase->id]) { |
Haynes Mathew George | ea09892 | 2014-04-24 17:53:50 -0700 | [diff] [blame] | 792 | enable_snd_device(adev, snd_device); |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 793 | } |
| 794 | } |
| 795 | |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 796 | /* Re-route all the usecases on the shared backend other than the |
| 797 | specified usecase to new snd devices */ |
| 798 | list_for_each(node, &adev->usecase_list) { |
| 799 | usecase = node_to_item(node, struct audio_usecase, list); |
| 800 | /* Update the in_snd_device only before enabling the audio route */ |
| 801 | if (switch_device[usecase->id] ) { |
| 802 | usecase->in_snd_device = snd_device; |
Avinash Vaish | 8005dc8 | 2014-07-24 15:36:33 +0530 | [diff] [blame] | 803 | if (usecase->type != VOICE_CALL && usecase->type != VOIP_CALL) |
| 804 | enable_audio_route(adev, usecase); |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 805 | } |
| 806 | } |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 807 | } |
| 808 | } |
| 809 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 810 | /* must be called with hw device mutex locked */ |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 811 | static int read_hdmi_channel_masks(struct stream_out *out) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 812 | { |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 813 | int ret = 0; |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 814 | int channels = platform_edid_get_max_channels(out->dev->platform); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 815 | |
| 816 | switch (channels) { |
| 817 | /* |
| 818 | * Do not handle stereo output in Multi-channel cases |
| 819 | * Stereo case is handled in normal playback path |
| 820 | */ |
| 821 | case 6: |
| 822 | ALOGV("%s: HDMI supports 5.1", __func__); |
| 823 | out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_5POINT1; |
| 824 | break; |
| 825 | case 8: |
| 826 | ALOGV("%s: HDMI supports 5.1 and 7.1 channels", __func__); |
| 827 | out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_5POINT1; |
| 828 | out->supported_channel_masks[1] = AUDIO_CHANNEL_OUT_7POINT1; |
| 829 | break; |
| 830 | default: |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 831 | ALOGE("HDMI does not support multi channel playback"); |
| 832 | ret = -ENOSYS; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 833 | break; |
| 834 | } |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 835 | return ret; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 836 | } |
| 837 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 838 | static audio_usecase_t get_voice_usecase_id_from_list(struct audio_device *adev) |
| 839 | { |
| 840 | struct audio_usecase *usecase; |
| 841 | struct listnode *node; |
| 842 | |
| 843 | list_for_each(node, &adev->usecase_list) { |
| 844 | usecase = node_to_item(node, struct audio_usecase, list); |
| 845 | if (usecase->type == VOICE_CALL) { |
| 846 | ALOGV("%s: usecase id %d", __func__, usecase->id); |
| 847 | return usecase->id; |
| 848 | } |
| 849 | } |
| 850 | return USECASE_INVALID; |
| 851 | } |
| 852 | |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 853 | struct audio_usecase *get_usecase_from_list(struct audio_device *adev, |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 854 | audio_usecase_t uc_id) |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 855 | { |
| 856 | struct audio_usecase *usecase; |
| 857 | struct listnode *node; |
| 858 | |
| 859 | list_for_each(node, &adev->usecase_list) { |
| 860 | usecase = node_to_item(node, struct audio_usecase, list); |
| 861 | if (usecase->id == uc_id) |
| 862 | return usecase; |
| 863 | } |
| 864 | return NULL; |
| 865 | } |
| 866 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 867 | int select_devices(struct audio_device *adev, audio_usecase_t uc_id) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 868 | { |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 869 | snd_device_t out_snd_device = SND_DEVICE_NONE; |
| 870 | snd_device_t in_snd_device = SND_DEVICE_NONE; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 871 | struct audio_usecase *usecase = NULL; |
| 872 | struct audio_usecase *vc_usecase = NULL; |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 873 | struct audio_usecase *voip_usecase = NULL; |
Vimal Puthanveed | 37b4a1c | 2014-01-07 16:47:47 -0800 | [diff] [blame] | 874 | struct audio_usecase *hfp_usecase = NULL; |
Vimal Puthanveed | 739e715 | 2014-01-23 15:56:53 -0800 | [diff] [blame] | 875 | audio_usecase_t hfp_ucid; |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 876 | struct listnode *node; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 877 | int status = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 878 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 879 | usecase = get_usecase_from_list(adev, uc_id); |
| 880 | if (usecase == NULL) { |
| 881 | ALOGE("%s: Could not find the usecase(%d)", __func__, uc_id); |
| 882 | return -EINVAL; |
| 883 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 884 | |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 885 | if ((usecase->type == VOICE_CALL) || |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 886 | (usecase->type == VOIP_CALL) || |
| 887 | (usecase->type == PCM_HFP_CALL)) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 888 | out_snd_device = platform_get_output_snd_device(adev->platform, |
| 889 | usecase->stream.out->devices); |
| 890 | 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] | 891 | usecase->devices = usecase->stream.out->devices; |
| 892 | } else { |
| 893 | /* |
| 894 | * If the voice call is active, use the sound devices of voice call usecase |
| 895 | * so that it would not result any device switch. All the usecases will |
| 896 | * be switched to new device when select_devices() is called for voice call |
| 897 | * usecase. This is to avoid switching devices for voice call when |
| 898 | * check_usecases_codec_backend() is called below. |
| 899 | */ |
Vidyakumar Athota | f85f6a2 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 900 | if (adev->voice.in_call && adev->mode == AUDIO_MODE_IN_CALL) { |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 901 | vc_usecase = get_usecase_from_list(adev, |
| 902 | get_voice_usecase_id_from_list(adev)); |
Mingming Yin | 6c23f38 | 2014-08-14 00:00:51 -0700 | [diff] [blame] | 903 | if ((vc_usecase) && ((vc_usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) || |
| 904 | (usecase->devices == AUDIO_DEVICE_IN_VOICE_CALL))) { |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 905 | in_snd_device = vc_usecase->in_snd_device; |
| 906 | out_snd_device = vc_usecase->out_snd_device; |
| 907 | } |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 908 | } else if (voice_extn_compress_voip_is_active(adev)) { |
| 909 | voip_usecase = get_usecase_from_list(adev, USECASE_COMPRESS_VOIP_CALL); |
Mingming Yin | 6c23f38 | 2014-08-14 00:00:51 -0700 | [diff] [blame] | 910 | if ((voip_usecase) && ((voip_usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) && |
Avinash Vaish | 6a4c337 | 2014-06-25 12:20:37 +0530 | [diff] [blame] | 911 | (usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) && |
Mingming Yin | 6c23f38 | 2014-08-14 00:00:51 -0700 | [diff] [blame] | 912 | (voip_usecase->stream.out != adev->primary_output))) { |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 913 | in_snd_device = voip_usecase->in_snd_device; |
| 914 | out_snd_device = voip_usecase->out_snd_device; |
| 915 | } |
Vimal Puthanveed | 37b4a1c | 2014-01-07 16:47:47 -0800 | [diff] [blame] | 916 | } else if (audio_extn_hfp_is_active(adev)) { |
Vimal Puthanveed | 739e715 | 2014-01-23 15:56:53 -0800 | [diff] [blame] | 917 | hfp_ucid = audio_extn_hfp_get_usecase(); |
| 918 | hfp_usecase = get_usecase_from_list(adev, hfp_ucid); |
Mingming Yin | 6c23f38 | 2014-08-14 00:00:51 -0700 | [diff] [blame] | 919 | if ((hfp_usecase) && (hfp_usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND)) { |
Vimal Puthanveed | 37b4a1c | 2014-01-07 16:47:47 -0800 | [diff] [blame] | 920 | in_snd_device = hfp_usecase->in_snd_device; |
| 921 | out_snd_device = hfp_usecase->out_snd_device; |
| 922 | } |
Vimal Puthanveed | 8fa9eab | 2014-01-07 16:47:47 -0800 | [diff] [blame] | 923 | } else if (audio_extn_hfp_is_active(adev)) { |
| 924 | hfp_usecase = get_usecase_from_list(adev, USECASE_AUDIO_HFP_SCO); |
| 925 | if (hfp_usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) { |
| 926 | in_snd_device = hfp_usecase->in_snd_device; |
| 927 | out_snd_device = hfp_usecase->out_snd_device; |
| 928 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 929 | } |
| 930 | if (usecase->type == PCM_PLAYBACK) { |
| 931 | usecase->devices = usecase->stream.out->devices; |
| 932 | in_snd_device = SND_DEVICE_NONE; |
Ravi Kumar Alamanda | 59d296d | 2013-05-02 11:25:27 -0700 | [diff] [blame] | 933 | if (out_snd_device == SND_DEVICE_NONE) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 934 | out_snd_device = platform_get_output_snd_device(adev->platform, |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 935 | usecase->stream.out->devices); |
Ravi Kumar Alamanda | 59d296d | 2013-05-02 11:25:27 -0700 | [diff] [blame] | 936 | if (usecase->stream.out == adev->primary_output && |
Shreyas Nagasandra Chandrasekhar | 23b3af2 | 2014-09-03 19:10:01 +0530 | [diff] [blame] | 937 | adev->active_input ) { |
Ravi Kumar Alamanda | 59d296d | 2013-05-02 11:25:27 -0700 | [diff] [blame] | 938 | select_devices(adev, adev->active_input->usecase); |
| 939 | } |
| 940 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 941 | } else if (usecase->type == PCM_CAPTURE) { |
| 942 | usecase->devices = usecase->stream.in->device; |
| 943 | out_snd_device = SND_DEVICE_NONE; |
Ravi Kumar Alamanda | 59d296d | 2013-05-02 11:25:27 -0700 | [diff] [blame] | 944 | if (in_snd_device == SND_DEVICE_NONE) { |
Divya Narayanan Poojary | ab9b1ef | 2014-09-12 15:52:36 +0530 | [diff] [blame] | 945 | audio_devices_t out_device = AUDIO_DEVICE_NONE; |
Shreyas Nagasandra Chandrasekhar | 23b3af2 | 2014-09-03 19:10:01 +0530 | [diff] [blame] | 946 | if ((adev->active_input->source == AUDIO_SOURCE_VOICE_COMMUNICATION || (adev->mode == AUDIO_MODE_IN_COMMUNICATION && adev->active_input->source == AUDIO_SOURCE_MIC)) && |
Ravi Kumar Alamanda | 59d296d | 2013-05-02 11:25:27 -0700 | [diff] [blame] | 947 | adev->primary_output && !adev->primary_output->standby) { |
Divya Narayanan Poojary | ab9b1ef | 2014-09-12 15:52:36 +0530 | [diff] [blame] | 948 | out_device = adev->primary_output->devices; |
| 949 | } else if(usecase->id == USECASE_AUDIO_RECORD_AFE_PROXY) { |
| 950 | out_device = AUDIO_DEVICE_OUT_TELEPHONY_TX; |
Ravi Kumar Alamanda | 59d296d | 2013-05-02 11:25:27 -0700 | [diff] [blame] | 951 | } |
Divya Narayanan Poojary | ab9b1ef | 2014-09-12 15:52:36 +0530 | [diff] [blame] | 952 | 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] | 953 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 954 | } |
| 955 | } |
| 956 | |
| 957 | if (out_snd_device == usecase->out_snd_device && |
| 958 | in_snd_device == usecase->in_snd_device) { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 959 | return 0; |
| 960 | } |
| 961 | |
sangwoo | bc67724 | 2013-08-08 16:53:43 +0900 | [diff] [blame] | 962 | ALOGD("%s: out_snd_device(%d: %s) in_snd_device(%d: %s)", __func__, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 963 | out_snd_device, platform_get_snd_device_name(out_snd_device), |
| 964 | in_snd_device, platform_get_snd_device_name(in_snd_device)); |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 965 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 966 | /* |
| 967 | * Limitation: While in call, to do a device switch we need to disable |
| 968 | * and enable both RX and TX devices though one of them is same as current |
| 969 | * device. |
| 970 | */ |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 971 | if (usecase->type == VOICE_CALL || usecase->type == VOIP_CALL) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 972 | status = platform_switch_voice_call_device_pre(adev->platform); |
Ravi Kumar Alamanda | 610e8cc | 2013-02-12 01:42:38 -0800 | [diff] [blame] | 973 | } |
| 974 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 975 | /* Disable current sound devices */ |
| 976 | if (usecase->out_snd_device != SND_DEVICE_NONE) { |
Haynes Mathew George | ea09892 | 2014-04-24 17:53:50 -0700 | [diff] [blame] | 977 | disable_audio_route(adev, usecase); |
| 978 | disable_snd_device(adev, usecase->out_snd_device); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 979 | } |
| 980 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 981 | if (usecase->in_snd_device != SND_DEVICE_NONE) { |
Haynes Mathew George | ea09892 | 2014-04-24 17:53:50 -0700 | [diff] [blame] | 982 | disable_audio_route(adev, usecase); |
| 983 | disable_snd_device(adev, usecase->in_snd_device); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 984 | } |
| 985 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 986 | /* Enable new sound devices */ |
| 987 | if (out_snd_device != SND_DEVICE_NONE) { |
| 988 | if (usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) |
| 989 | check_usecases_codec_backend(adev, usecase, out_snd_device); |
Haynes Mathew George | ea09892 | 2014-04-24 17:53:50 -0700 | [diff] [blame] | 990 | enable_snd_device(adev, out_snd_device); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 991 | } |
| 992 | |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 993 | if (in_snd_device != SND_DEVICE_NONE) { |
| 994 | check_and_route_capture_usecases(adev, usecase, in_snd_device); |
Haynes Mathew George | ea09892 | 2014-04-24 17:53:50 -0700 | [diff] [blame] | 995 | enable_snd_device(adev, in_snd_device); |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 996 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 997 | |
Avinash Vaish | 8005dc8 | 2014-07-24 15:36:33 +0530 | [diff] [blame] | 998 | if (usecase->type == VOICE_CALL || usecase->type == VOIP_CALL) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 999 | status = platform_switch_voice_call_device_post(adev->platform, |
| 1000 | out_snd_device, |
| 1001 | in_snd_device); |
Avinash Vaish | 8005dc8 | 2014-07-24 15:36:33 +0530 | [diff] [blame] | 1002 | enable_audio_route_for_voice_usecases(adev, usecase); |
| 1003 | } |
Ravi Kumar Alamanda | 610e8cc | 2013-02-12 01:42:38 -0800 | [diff] [blame] | 1004 | |
sangwoo | 170731f | 2013-06-08 15:36:36 +0900 | [diff] [blame] | 1005 | usecase->in_snd_device = in_snd_device; |
| 1006 | usecase->out_snd_device = out_snd_device; |
| 1007 | |
Haynes Mathew George | ea09892 | 2014-04-24 17:53:50 -0700 | [diff] [blame] | 1008 | enable_audio_route(adev, usecase); |
sangwoo | 170731f | 2013-06-08 15:36:36 +0900 | [diff] [blame] | 1009 | |
Daniel Hillenbrand | 8373bc6 | 2013-05-23 10:10:00 +0530 | [diff] [blame] | 1010 | /* Rely on amplifier_set_devices to distinguish between in/out devices */ |
Ethan Chen | 79c356c | 2015-06-07 12:26:14 -0700 | [diff] [blame] | 1011 | amplifier_set_input_devices(in_snd_device); |
| 1012 | amplifier_set_output_devices(out_snd_device); |
Daniel Hillenbrand | 8373bc6 | 2013-05-23 10:10:00 +0530 | [diff] [blame] | 1013 | |
Vidyakumar Athota | 1fd2179 | 2013-11-15 14:50:57 -0800 | [diff] [blame] | 1014 | /* Applicable only on the targets that has external modem. |
| 1015 | * Enable device command should be sent to modem only after |
| 1016 | * enabling voice call mixer controls |
| 1017 | */ |
| 1018 | if (usecase->type == VOICE_CALL) |
| 1019 | status = platform_switch_voice_call_usecase_route_post(adev->platform, |
| 1020 | out_snd_device, |
| 1021 | in_snd_device); |
| 1022 | |
Sidipotu Ashok | e4514fa | 2014-05-02 16:21:50 +0530 | [diff] [blame] | 1023 | ALOGD("%s: done",__func__); |
| 1024 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1025 | return status; |
| 1026 | } |
| 1027 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1028 | static int stop_input_stream(struct stream_in *in) |
| 1029 | { |
| 1030 | int i, ret = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1031 | struct audio_usecase *uc_info; |
| 1032 | struct audio_device *adev = in->dev; |
| 1033 | |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 1034 | adev->active_input = NULL; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1035 | |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 1036 | ALOGV("%s: enter: usecase(%d: %s)", __func__, |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1037 | in->usecase, use_case_table[in->usecase]); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1038 | uc_info = get_usecase_from_list(adev, in->usecase); |
| 1039 | if (uc_info == NULL) { |
| 1040 | ALOGE("%s: Could not find the usecase (%d) in the list", |
| 1041 | __func__, in->usecase); |
| 1042 | return -EINVAL; |
| 1043 | } |
| 1044 | |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 1045 | /* Close in-call recording streams */ |
| 1046 | voice_check_and_stop_incall_rec_usecase(adev, in); |
| 1047 | |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 1048 | /* 1. Disable stream specific mixer controls */ |
Haynes Mathew George | ea09892 | 2014-04-24 17:53:50 -0700 | [diff] [blame] | 1049 | disable_audio_route(adev, uc_info); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1050 | |
| 1051 | /* 2. Disable the tx device */ |
Haynes Mathew George | ea09892 | 2014-04-24 17:53:50 -0700 | [diff] [blame] | 1052 | disable_snd_device(adev, uc_info->in_snd_device); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1053 | |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 1054 | list_remove(&uc_info->list); |
| 1055 | free(uc_info); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1056 | |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 1057 | ALOGV("%s: exit: status(%d)", __func__, ret); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1058 | return ret; |
| 1059 | } |
| 1060 | |
| 1061 | int start_input_stream(struct stream_in *in) |
| 1062 | { |
| 1063 | /* 1. Enable output device and stream routing controls */ |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 1064 | int ret = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1065 | struct audio_usecase *uc_info; |
| 1066 | struct audio_device *adev = in->dev; |
Naresh Tanniru | cef332d | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 1067 | int snd_card_status = get_snd_card_state(adev); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1068 | |
Ramjee Singh | 240ac65 | 2015-07-31 16:12:29 +0530 | [diff] [blame] | 1069 | int usecase = platform_update_usecase_from_source(in->source,in->usecase); |
| 1070 | if (get_usecase_from_list(adev, usecase) == NULL) |
| 1071 | in->usecase = usecase; |
| 1072 | |
Sidipotu Ashok | e4514fa | 2014-05-02 16:21:50 +0530 | [diff] [blame] | 1073 | ALOGD("%s: enter: stream(%p)usecase(%d: %s)", |
| 1074 | __func__, &in->stream, in->usecase, use_case_table[in->usecase]); |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 1075 | |
Naresh Tanniru | cef332d | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 1076 | if (SND_CARD_STATE_OFFLINE == snd_card_status) { |
| 1077 | ALOGE("%s: sound card is not active/SSR returning error ", __func__); |
Naresh Tanniru | 2d19ab4 | 2014-05-11 19:56:25 +0530 | [diff] [blame] | 1078 | ret = -ENETRESET; |
Naresh Tanniru | 2d19ab4 | 2014-05-11 19:56:25 +0530 | [diff] [blame] | 1079 | goto error_config; |
| 1080 | } |
Naresh Tanniru | 2d19ab4 | 2014-05-11 19:56:25 +0530 | [diff] [blame] | 1081 | |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 1082 | /* Check if source matches incall recording usecase criteria */ |
| 1083 | ret = voice_check_and_set_incall_rec_usecase(adev, in); |
| 1084 | if (ret) |
| 1085 | goto error_config; |
| 1086 | else |
| 1087 | ALOGV("%s: usecase(%d)", __func__, in->usecase); |
| 1088 | |
Ramjee Singh | 240ac65 | 2015-07-31 16:12:29 +0530 | [diff] [blame] | 1089 | if (get_usecase_from_list(adev, in->usecase) != NULL) { |
| 1090 | ALOGE("%s: use case assigned already in use, stream(%p)usecase(%d: %s)", |
| 1091 | __func__, &in->stream, in->usecase, use_case_table[in->usecase]); |
| 1092 | goto error_config; |
| 1093 | } |
| 1094 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1095 | 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] | 1096 | if (in->pcm_device_id < 0) { |
| 1097 | ALOGE("%s: Could not find PCM device id for the usecase(%d)", |
| 1098 | __func__, in->usecase); |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 1099 | ret = -EINVAL; |
| 1100 | goto error_config; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1101 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1102 | |
| 1103 | adev->active_input = in; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1104 | uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase)); |
Haynes Mathew George | 9f0254a | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 1105 | |
| 1106 | if (!uc_info) { |
| 1107 | ret = -ENOMEM; |
| 1108 | goto error_config; |
| 1109 | } |
| 1110 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1111 | uc_info->id = in->usecase; |
| 1112 | uc_info->type = PCM_CAPTURE; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 1113 | uc_info->stream.in = in; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1114 | uc_info->devices = in->device; |
| 1115 | uc_info->in_snd_device = SND_DEVICE_NONE; |
| 1116 | uc_info->out_snd_device = SND_DEVICE_NONE; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1117 | |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 1118 | list_add_tail(&adev->usecase_list, &uc_info->list); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1119 | select_devices(adev, in->usecase); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1120 | |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 1121 | ALOGV("%s: Opening PCM device card_id(%d) device_id(%d), channels %d", |
Divya Narayanan Poojary | ab9b1ef | 2014-09-12 15:52:36 +0530 | [diff] [blame] | 1122 | __func__, adev->snd_card, in->pcm_device_id, in->config.channels); |
| 1123 | |
| 1124 | unsigned int flags = PCM_IN; |
| 1125 | unsigned int pcm_open_retry_entry_count = 0; |
| 1126 | |
| 1127 | if (in->usecase == USECASE_AUDIO_RECORD_AFE_PROXY) { |
| 1128 | flags |= PCM_MMAP | PCM_NOIRQ; |
| 1129 | pcm_open_retry_entry_count = PROXY_OPEN_RETRY_COUNT; |
| 1130 | } |
| 1131 | |
| 1132 | while(1) { |
| 1133 | in->pcm = pcm_open(adev->snd_card, in->pcm_device_id, |
| 1134 | flags, &in->config); |
| 1135 | if (in->pcm == NULL || !pcm_is_ready(in->pcm)) { |
| 1136 | ALOGE("%s: %s", __func__, pcm_get_error(in->pcm)); |
| 1137 | if (in->pcm != NULL) { |
| 1138 | pcm_close(in->pcm); |
| 1139 | in->pcm = NULL; |
| 1140 | } |
| 1141 | if (pcm_open_retry_entry_count-- == 0) { |
| 1142 | ret = -EIO; |
| 1143 | goto error_open; |
| 1144 | } |
| 1145 | usleep(PROXY_OPEN_WAIT_TIME * 1000); |
| 1146 | continue; |
| 1147 | } |
| 1148 | break; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1149 | } |
Naresh Tanniru | 2d19ab4 | 2014-05-11 19:56:25 +0530 | [diff] [blame] | 1150 | |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 1151 | ALOGV("%s: exit", __func__); |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 1152 | return ret; |
| 1153 | |
| 1154 | error_open: |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1155 | stop_input_stream(in); |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 1156 | |
| 1157 | error_config: |
| 1158 | adev->active_input = NULL; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1159 | ALOGD("%s: exit: status(%d)", __func__, ret); |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 1160 | |
| 1161 | return ret; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1162 | } |
| 1163 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1164 | /* must be called with out->lock locked */ |
| 1165 | static int send_offload_cmd_l(struct stream_out* out, int command) |
| 1166 | { |
| 1167 | struct offload_cmd *cmd = (struct offload_cmd *)calloc(1, sizeof(struct offload_cmd)); |
| 1168 | |
Haynes Mathew George | 9f0254a | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 1169 | if (!cmd) { |
| 1170 | ALOGE("failed to allocate mem for command 0x%x", command); |
| 1171 | return -ENOMEM; |
| 1172 | } |
| 1173 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1174 | ALOGVV("%s %d", __func__, command); |
| 1175 | |
| 1176 | cmd->cmd = command; |
| 1177 | list_add_tail(&out->offload_cmd_list, &cmd->node); |
| 1178 | pthread_cond_signal(&out->offload_cond); |
| 1179 | return 0; |
| 1180 | } |
| 1181 | |
| 1182 | /* must be called iwth out->lock locked */ |
| 1183 | static void stop_compressed_output_l(struct stream_out *out) |
| 1184 | { |
| 1185 | out->offload_state = OFFLOAD_STATE_IDLE; |
| 1186 | out->playback_started = 0; |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 1187 | out->send_new_metadata = 1; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1188 | if (out->compr != NULL) { |
| 1189 | compress_stop(out->compr); |
| 1190 | while (out->offload_thread_blocked) { |
| 1191 | pthread_cond_wait(&out->cond, &out->lock); |
| 1192 | } |
| 1193 | } |
| 1194 | } |
| 1195 | |
Subhash Chandra Bose Naripeddy | 148144e | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 1196 | bool is_offload_usecase(audio_usecase_t uc_id) |
| 1197 | { |
| 1198 | unsigned int i; |
| 1199 | for (i = 0; i < sizeof(offload_usecases)/sizeof(offload_usecases[0]); i++) { |
| 1200 | if (uc_id == offload_usecases[i]) |
| 1201 | return true; |
| 1202 | } |
| 1203 | return false; |
| 1204 | } |
| 1205 | |
| 1206 | static audio_usecase_t get_offload_usecase(struct audio_device *adev) |
| 1207 | { |
| 1208 | audio_usecase_t ret = USECASE_AUDIO_PLAYBACK_OFFLOAD; |
| 1209 | unsigned int i, num_usecase = sizeof(offload_usecases)/sizeof(offload_usecases[0]); |
| 1210 | char value[PROPERTY_VALUE_MAX] = {0}; |
| 1211 | |
| 1212 | property_get("audio.offload.multiple.enabled", value, NULL); |
| 1213 | if (!(atoi(value) || !strncmp("true", value, 4))) |
| 1214 | num_usecase = 1; /* If prop is not set, limit the num of offload usecases to 1 */ |
| 1215 | |
| 1216 | ALOGV("%s: num_usecase: %d", __func__, num_usecase); |
| 1217 | for (i = 0; i < num_usecase; i++) { |
| 1218 | if (!(adev->offload_usecases_state & (0x1<<i))) { |
| 1219 | adev->offload_usecases_state |= 0x1 << i; |
| 1220 | ret = offload_usecases[i]; |
| 1221 | break; |
| 1222 | } |
| 1223 | } |
| 1224 | ALOGV("%s: offload usecase is %d", __func__, ret); |
| 1225 | return ret; |
| 1226 | } |
| 1227 | |
| 1228 | static void free_offload_usecase(struct audio_device *adev, |
| 1229 | audio_usecase_t uc_id) |
| 1230 | { |
| 1231 | unsigned int i; |
| 1232 | for (i = 0; i < sizeof(offload_usecases)/sizeof(offload_usecases[0]); i++) { |
| 1233 | if (offload_usecases[i] == uc_id) { |
| 1234 | adev->offload_usecases_state &= ~(0x1<<i); |
| 1235 | break; |
| 1236 | } |
| 1237 | } |
| 1238 | ALOGV("%s: free offload usecase %d", __func__, uc_id); |
| 1239 | } |
| 1240 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1241 | static void *offload_thread_loop(void *context) |
| 1242 | { |
| 1243 | struct stream_out *out = (struct stream_out *) context; |
| 1244 | struct listnode *item; |
Krishnankutty Kolathappilly | 0fe78f0 | 2014-01-06 18:33:58 -0800 | [diff] [blame] | 1245 | int ret = 0; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1246 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1247 | setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_AUDIO); |
| 1248 | set_sched_policy(0, SP_FOREGROUND); |
| 1249 | prctl(PR_SET_NAME, (unsigned long)"Offload Callback", 0, 0, 0); |
| 1250 | |
| 1251 | ALOGV("%s", __func__); |
| 1252 | pthread_mutex_lock(&out->lock); |
| 1253 | for (;;) { |
| 1254 | struct offload_cmd *cmd = NULL; |
| 1255 | stream_callback_event_t event; |
| 1256 | bool send_callback = false; |
| 1257 | |
| 1258 | ALOGVV("%s offload_cmd_list %d out->offload_state %d", |
| 1259 | __func__, list_empty(&out->offload_cmd_list), |
| 1260 | out->offload_state); |
| 1261 | if (list_empty(&out->offload_cmd_list)) { |
| 1262 | ALOGV("%s SLEEPING", __func__); |
| 1263 | pthread_cond_wait(&out->offload_cond, &out->lock); |
| 1264 | ALOGV("%s RUNNING", __func__); |
| 1265 | continue; |
| 1266 | } |
| 1267 | |
| 1268 | item = list_head(&out->offload_cmd_list); |
| 1269 | cmd = node_to_item(item, struct offload_cmd, node); |
| 1270 | list_remove(item); |
| 1271 | |
| 1272 | ALOGVV("%s STATE %d CMD %d out->compr %p", |
| 1273 | __func__, out->offload_state, cmd->cmd, out->compr); |
| 1274 | |
| 1275 | if (cmd->cmd == OFFLOAD_CMD_EXIT) { |
| 1276 | free(cmd); |
| 1277 | break; |
| 1278 | } |
| 1279 | |
| 1280 | if (out->compr == NULL) { |
| 1281 | ALOGE("%s: Compress handle is NULL", __func__); |
| 1282 | pthread_cond_signal(&out->cond); |
| 1283 | continue; |
| 1284 | } |
| 1285 | out->offload_thread_blocked = true; |
| 1286 | pthread_mutex_unlock(&out->lock); |
| 1287 | send_callback = false; |
| 1288 | switch(cmd->cmd) { |
| 1289 | case OFFLOAD_CMD_WAIT_FOR_BUFFER: |
Steve Kondik | 05c1796 | 2015-02-25 00:55:50 -0800 | [diff] [blame] | 1290 | ALOGV("copl(%x):calling compress_wait", (unsigned int)out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1291 | compress_wait(out->compr, -1); |
Steve Kondik | 05c1796 | 2015-02-25 00:55:50 -0800 | [diff] [blame] | 1292 | ALOGV("copl(%x):out of compress_wait", (unsigned int)out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1293 | send_callback = true; |
| 1294 | event = STREAM_CBK_EVENT_WRITE_READY; |
| 1295 | break; |
| 1296 | case OFFLOAD_CMD_PARTIAL_DRAIN: |
Krishnankutty Kolathappilly | 0fe78f0 | 2014-01-06 18:33:58 -0800 | [diff] [blame] | 1297 | ret = compress_next_track(out->compr); |
Sidipotu Ashok | 5bfacf7 | 2014-02-10 16:16:38 +0530 | [diff] [blame] | 1298 | if(ret == 0) { |
Steve Kondik | 05c1796 | 2015-02-25 00:55:50 -0800 | [diff] [blame] | 1299 | ALOGV("copl(%p):calling compress_partial_drain", out); |
Dhanalakshmi Siddani | 5754e2c | 2014-12-23 16:57:43 +0530 | [diff] [blame] | 1300 | ret = compress_partial_drain(out->compr); |
Steve Kondik | 05c1796 | 2015-02-25 00:55:50 -0800 | [diff] [blame] | 1301 | ALOGV("copl(%p):out of compress_partial_drain", out); |
Dhanalakshmi Siddani | 5754e2c | 2014-12-23 16:57:43 +0530 | [diff] [blame] | 1302 | if (ret < 0) |
| 1303 | ret = -errno; |
Sidipotu Ashok | 5bfacf7 | 2014-02-10 16:16:38 +0530 | [diff] [blame] | 1304 | } |
Dhanalakshmi Siddani | 5754e2c | 2014-12-23 16:57:43 +0530 | [diff] [blame] | 1305 | else if (ret == -ETIMEDOUT) |
Krishnankutty Kolathappilly | 0fe78f0 | 2014-01-06 18:33:58 -0800 | [diff] [blame] | 1306 | compress_drain(out->compr); |
| 1307 | else |
| 1308 | ALOGE("%s: Next track returned error %d",__func__, ret); |
Dhanalakshmi Siddani | 5754e2c | 2014-12-23 16:57:43 +0530 | [diff] [blame] | 1309 | |
| 1310 | if (ret != -ENETRESET) { |
| 1311 | send_callback = true; |
| 1312 | event = STREAM_CBK_EVENT_DRAIN_READY; |
| 1313 | |
| 1314 | /* Resend the metadata for next iteration */ |
| 1315 | out->send_new_metadata = 1; |
| 1316 | ALOGV("copl(%p):send drain callback, ret %d", out, ret); |
| 1317 | } else |
| 1318 | ALOGE("%s: Block drain ready event during SSR", __func__); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1319 | break; |
| 1320 | case OFFLOAD_CMD_DRAIN: |
Steve Kondik | 05c1796 | 2015-02-25 00:55:50 -0800 | [diff] [blame] | 1321 | ALOGV("copl(%x):calling compress_drain", (unsigned int)out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1322 | compress_drain(out->compr); |
Steve Kondik | 05c1796 | 2015-02-25 00:55:50 -0800 | [diff] [blame] | 1323 | ALOGV("copl(%x):out of compress_drain", (unsigned int)out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1324 | send_callback = true; |
| 1325 | event = STREAM_CBK_EVENT_DRAIN_READY; |
| 1326 | break; |
| 1327 | default: |
| 1328 | ALOGE("%s unknown command received: %d", __func__, cmd->cmd); |
| 1329 | break; |
| 1330 | } |
| 1331 | pthread_mutex_lock(&out->lock); |
| 1332 | out->offload_thread_blocked = false; |
| 1333 | pthread_cond_signal(&out->cond); |
Eric Laurent | 6e89524 | 2013-09-05 16:10:57 -0700 | [diff] [blame] | 1334 | if (send_callback) { |
Ravi Kumar Alamanda | 3d31617 | 2014-12-02 19:21:51 -0800 | [diff] [blame] | 1335 | ALOGVV("%s: sending offload_callback event %d", __func__, event); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1336 | out->offload_callback(event, NULL, out->offload_cookie); |
Eric Laurent | 6e89524 | 2013-09-05 16:10:57 -0700 | [diff] [blame] | 1337 | } |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1338 | free(cmd); |
| 1339 | } |
| 1340 | |
| 1341 | pthread_cond_signal(&out->cond); |
| 1342 | while (!list_empty(&out->offload_cmd_list)) { |
| 1343 | item = list_head(&out->offload_cmd_list); |
| 1344 | list_remove(item); |
| 1345 | free(node_to_item(item, struct offload_cmd, node)); |
| 1346 | } |
| 1347 | pthread_mutex_unlock(&out->lock); |
| 1348 | |
| 1349 | return NULL; |
| 1350 | } |
| 1351 | |
| 1352 | static int create_offload_callback_thread(struct stream_out *out) |
| 1353 | { |
| 1354 | pthread_cond_init(&out->offload_cond, (const pthread_condattr_t *) NULL); |
| 1355 | list_init(&out->offload_cmd_list); |
| 1356 | pthread_create(&out->offload_thread, (const pthread_attr_t *) NULL, |
| 1357 | offload_thread_loop, out); |
| 1358 | return 0; |
| 1359 | } |
| 1360 | |
| 1361 | static int destroy_offload_callback_thread(struct stream_out *out) |
| 1362 | { |
| 1363 | pthread_mutex_lock(&out->lock); |
| 1364 | stop_compressed_output_l(out); |
| 1365 | send_offload_cmd_l(out, OFFLOAD_CMD_EXIT); |
| 1366 | |
| 1367 | pthread_mutex_unlock(&out->lock); |
| 1368 | pthread_join(out->offload_thread, (void **) NULL); |
| 1369 | pthread_cond_destroy(&out->offload_cond); |
| 1370 | |
| 1371 | return 0; |
| 1372 | } |
| 1373 | |
Eric Laurent | 07eeafd | 2013-10-06 12:52:49 -0700 | [diff] [blame] | 1374 | static bool allow_hdmi_channel_config(struct audio_device *adev) |
| 1375 | { |
| 1376 | struct listnode *node; |
| 1377 | struct audio_usecase *usecase; |
| 1378 | bool ret = true; |
| 1379 | |
| 1380 | list_for_each(node, &adev->usecase_list) { |
| 1381 | usecase = node_to_item(node, struct audio_usecase, list); |
| 1382 | if (usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
| 1383 | /* |
| 1384 | * If voice call is already existing, do not proceed further to avoid |
| 1385 | * disabling/enabling both RX and TX devices, CSD calls, etc. |
| 1386 | * Once the voice call done, the HDMI channels can be configured to |
| 1387 | * max channels of remaining use cases. |
| 1388 | */ |
| 1389 | if (usecase->id == USECASE_VOICE_CALL) { |
| 1390 | ALOGD("%s: voice call is active, no change in HDMI channels", |
| 1391 | __func__); |
| 1392 | ret = false; |
| 1393 | break; |
| 1394 | } else if (usecase->id == USECASE_AUDIO_PLAYBACK_MULTI_CH) { |
| 1395 | ALOGD("%s: multi channel playback is active, " |
| 1396 | "no change in HDMI channels", __func__); |
| 1397 | ret = false; |
| 1398 | break; |
Subhash Chandra Bose Naripeddy | 148144e | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 1399 | } else if (is_offload_usecase(usecase->id) && |
Divya Narayanan Poojary | 69236ba | 2014-09-18 11:57:57 +0530 | [diff] [blame] | 1400 | audio_channel_count_from_out_mask(usecase->stream.out->channel_mask) > 2) { |
Mingming Yin | 3ed162b | 2014-02-24 17:56:01 -0800 | [diff] [blame] | 1401 | ALOGD("%s: multi-channel(%x) compress offload playback is active, " |
| 1402 | "no change in HDMI channels", __func__, usecase->stream.out->channel_mask); |
| 1403 | ret = false; |
| 1404 | break; |
Eric Laurent | 07eeafd | 2013-10-06 12:52:49 -0700 | [diff] [blame] | 1405 | } |
| 1406 | } |
| 1407 | } |
| 1408 | return ret; |
| 1409 | } |
| 1410 | |
| 1411 | static int check_and_set_hdmi_channels(struct audio_device *adev, |
| 1412 | unsigned int channels) |
| 1413 | { |
| 1414 | struct listnode *node; |
| 1415 | struct audio_usecase *usecase; |
| 1416 | |
| 1417 | /* Check if change in HDMI channel config is allowed */ |
| 1418 | if (!allow_hdmi_channel_config(adev)) |
| 1419 | return 0; |
| 1420 | |
| 1421 | if (channels == adev->cur_hdmi_channels) { |
Mingming Yin | 10fef6a | 2013-11-26 17:17:01 -0800 | [diff] [blame] | 1422 | ALOGD("%s: Requested channels are same as current channels(%d)", __func__, channels); |
Eric Laurent | 07eeafd | 2013-10-06 12:52:49 -0700 | [diff] [blame] | 1423 | return 0; |
| 1424 | } |
| 1425 | |
| 1426 | platform_set_hdmi_channels(adev->platform, channels); |
| 1427 | adev->cur_hdmi_channels = channels; |
| 1428 | |
| 1429 | /* |
| 1430 | * Deroute all the playback streams routed to HDMI so that |
| 1431 | * the back end is deactivated. Note that backend will not |
| 1432 | * be deactivated if any one stream is connected to it. |
| 1433 | */ |
| 1434 | list_for_each(node, &adev->usecase_list) { |
| 1435 | usecase = node_to_item(node, struct audio_usecase, list); |
| 1436 | if (usecase->type == PCM_PLAYBACK && |
| 1437 | usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
Haynes Mathew George | ea09892 | 2014-04-24 17:53:50 -0700 | [diff] [blame] | 1438 | disable_audio_route(adev, usecase); |
Eric Laurent | 07eeafd | 2013-10-06 12:52:49 -0700 | [diff] [blame] | 1439 | } |
| 1440 | } |
| 1441 | |
| 1442 | /* |
| 1443 | * Enable all the streams disabled above. Now the HDMI backend |
| 1444 | * will be activated with new channel configuration |
| 1445 | */ |
| 1446 | list_for_each(node, &adev->usecase_list) { |
| 1447 | usecase = node_to_item(node, struct audio_usecase, list); |
| 1448 | if (usecase->type == PCM_PLAYBACK && |
| 1449 | usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
Haynes Mathew George | ea09892 | 2014-04-24 17:53:50 -0700 | [diff] [blame] | 1450 | enable_audio_route(adev, usecase); |
Eric Laurent | 07eeafd | 2013-10-06 12:52:49 -0700 | [diff] [blame] | 1451 | } |
| 1452 | } |
| 1453 | |
| 1454 | return 0; |
| 1455 | } |
| 1456 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1457 | static int stop_output_stream(struct stream_out *out) |
| 1458 | { |
| 1459 | int i, ret = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1460 | struct audio_usecase *uc_info; |
| 1461 | struct audio_device *adev = out->dev; |
| 1462 | |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 1463 | ALOGV("%s: enter: usecase(%d: %s)", __func__, |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1464 | out->usecase, use_case_table[out->usecase]); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1465 | uc_info = get_usecase_from_list(adev, out->usecase); |
| 1466 | if (uc_info == NULL) { |
| 1467 | ALOGE("%s: Could not find the usecase (%d) in the list", |
| 1468 | __func__, out->usecase); |
| 1469 | return -EINVAL; |
| 1470 | } |
| 1471 | |
Subhash Chandra Bose Naripeddy | 148144e | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 1472 | if (is_offload_usecase(out->usecase)) { |
Subhash Chandra Bose Naripeddy | 1d08916 | 2013-11-13 13:31:50 -0800 | [diff] [blame] | 1473 | if (adev->visualizer_stop_output != NULL) |
| 1474 | adev->visualizer_stop_output(out->handle, out->pcm_device_id); |
| 1475 | if (adev->offload_effects_stop_output != NULL) |
| 1476 | adev->offload_effects_stop_output(out->handle, out->pcm_device_id); |
| 1477 | } |
Eric Laurent | c4aef75 | 2013-09-12 17:45:53 -0700 | [diff] [blame] | 1478 | |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 1479 | /* 1. Get and set stream specific mixer controls */ |
Haynes Mathew George | ea09892 | 2014-04-24 17:53:50 -0700 | [diff] [blame] | 1480 | disable_audio_route(adev, uc_info); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1481 | |
| 1482 | /* 2. Disable the rx device */ |
Haynes Mathew George | ea09892 | 2014-04-24 17:53:50 -0700 | [diff] [blame] | 1483 | disable_snd_device(adev, uc_info->out_snd_device); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1484 | |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 1485 | list_remove(&uc_info->list); |
| 1486 | free(uc_info); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1487 | |
Eric Laurent | da46bfb | 2014-08-25 22:39:29 -0500 | [diff] [blame] | 1488 | audio_extn_extspk_update(adev->extspk); |
| 1489 | |
Eric Laurent | 07eeafd | 2013-10-06 12:52:49 -0700 | [diff] [blame] | 1490 | /* Must be called after removing the usecase from list */ |
| 1491 | if (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) |
| 1492 | check_and_set_hdmi_channels(adev, DEFAULT_HDMI_OUT_CHANNELS); |
| 1493 | |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 1494 | ALOGV("%s: exit: status(%d)", __func__, ret); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1495 | return ret; |
| 1496 | } |
| 1497 | |
| 1498 | int start_output_stream(struct stream_out *out) |
| 1499 | { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1500 | int ret = 0; |
Mingming Yin | 6c34443 | 2014-05-01 15:37:31 -0700 | [diff] [blame] | 1501 | int sink_channels = 0; |
| 1502 | char prop_value[PROPERTY_VALUE_MAX] = {0}; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1503 | struct audio_usecase *uc_info; |
| 1504 | struct audio_device *adev = out->dev; |
Naresh Tanniru | cef332d | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 1505 | int snd_card_status = get_snd_card_state(adev); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1506 | |
Haynes Mathew George | 9f0254a | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 1507 | if ((out->usecase < 0) || (out->usecase >= AUDIO_USECASE_MAX)) { |
| 1508 | ret = -EINVAL; |
| 1509 | goto error_config; |
| 1510 | } |
| 1511 | |
Sidipotu Ashok | e4514fa | 2014-05-02 16:21:50 +0530 | [diff] [blame] | 1512 | ALOGD("%s: enter: stream(%p)usecase(%d: %s) devices(%#x)", |
| 1513 | __func__, &out->stream, out->usecase, use_case_table[out->usecase], |
| 1514 | out->devices); |
Naresh Tanniru | 2d19ab4 | 2014-05-11 19:56:25 +0530 | [diff] [blame] | 1515 | |
Naresh Tanniru | cef332d | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 1516 | if (SND_CARD_STATE_OFFLINE == snd_card_status) { |
Naresh Tanniru | 2d19ab4 | 2014-05-11 19:56:25 +0530 | [diff] [blame] | 1517 | ALOGE("%s: sound card is not active/SSR returning error", __func__); |
| 1518 | ret = -ENETRESET; |
Naresh Tanniru | 2d19ab4 | 2014-05-11 19:56:25 +0530 | [diff] [blame] | 1519 | goto error_config; |
| 1520 | } |
Naresh Tanniru | 2d19ab4 | 2014-05-11 19:56:25 +0530 | [diff] [blame] | 1521 | |
Sidipotu Ashok | 5bfacf7 | 2014-02-10 16:16:38 +0530 | [diff] [blame] | 1522 | ALOGD("%s: enter: usecase(%d: %s) devices(%#x)", |
| 1523 | __func__, out->usecase, use_case_table[out->usecase], out->devices); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1524 | 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] | 1525 | if (out->pcm_device_id < 0) { |
| 1526 | ALOGE("%s: Invalid PCM device id(%d) for the usecase(%d)", |
| 1527 | __func__, out->pcm_device_id, out->usecase); |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1528 | ret = -EINVAL; |
| 1529 | goto error_config; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1530 | } |
| 1531 | |
| 1532 | uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase)); |
Haynes Mathew George | 9f0254a | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 1533 | |
| 1534 | if (!uc_info) { |
| 1535 | ret = -ENOMEM; |
| 1536 | goto error_config; |
| 1537 | } |
| 1538 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1539 | uc_info->id = out->usecase; |
| 1540 | uc_info->type = PCM_PLAYBACK; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 1541 | uc_info->stream.out = out; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1542 | uc_info->devices = out->devices; |
| 1543 | uc_info->in_snd_device = SND_DEVICE_NONE; |
| 1544 | uc_info->out_snd_device = SND_DEVICE_NONE; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1545 | |
Eric Laurent | 07eeafd | 2013-10-06 12:52:49 -0700 | [diff] [blame] | 1546 | /* This must be called before adding this usecase to the list */ |
Mingming Yin | 10fef6a | 2013-11-26 17:17:01 -0800 | [diff] [blame] | 1547 | if (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
Mingming Yin | 6c34443 | 2014-05-01 15:37:31 -0700 | [diff] [blame] | 1548 | property_get("audio.use.hdmi.sink.cap", prop_value, NULL); |
| 1549 | if (!strncmp("true", prop_value, 4)) { |
| 1550 | sink_channels = platform_edid_get_max_channels(out->dev->platform); |
| 1551 | ALOGD("%s: set HDMI channel count[%d] based on sink capability", __func__, sink_channels); |
| 1552 | check_and_set_hdmi_channels(adev, sink_channels); |
| 1553 | } else { |
Subhash Chandra Bose Naripeddy | 148144e | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 1554 | if (is_offload_usecase(out->usecase)) |
Mingming Yin | 6c34443 | 2014-05-01 15:37:31 -0700 | [diff] [blame] | 1555 | check_and_set_hdmi_channels(adev, out->compr_config.codec->ch_in); |
| 1556 | else |
| 1557 | check_and_set_hdmi_channels(adev, out->config.channels); |
| 1558 | } |
Mingming Yin | 10fef6a | 2013-11-26 17:17:01 -0800 | [diff] [blame] | 1559 | } |
Eric Laurent | 07eeafd | 2013-10-06 12:52:49 -0700 | [diff] [blame] | 1560 | |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 1561 | list_add_tail(&adev->usecase_list, &uc_info->list); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1562 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1563 | select_devices(adev, out->usecase); |
| 1564 | |
Eric Laurent | da46bfb | 2014-08-25 22:39:29 -0500 | [diff] [blame] | 1565 | audio_extn_extspk_update(adev->extspk); |
| 1566 | |
Steve Kondik | 3abbbc8 | 2014-11-29 14:14:43 -0800 | [diff] [blame] | 1567 | ALOGV("%s: Opening PCM device card_id(%d) device_id(%d) format(%#x)", |
| 1568 | __func__, adev->snd_card, out->pcm_device_id, out->config.format); |
| 1569 | |
Subhash Chandra Bose Naripeddy | 148144e | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 1570 | if (!is_offload_usecase(out->usecase)) { |
Divya Narayanan Poojary | ab9b1ef | 2014-09-12 15:52:36 +0530 | [diff] [blame] | 1571 | unsigned int flags = PCM_OUT; |
| 1572 | unsigned int pcm_open_retry_count = 0; |
| 1573 | if (out->usecase == USECASE_AUDIO_PLAYBACK_AFE_PROXY) { |
| 1574 | flags |= PCM_MMAP | PCM_NOIRQ; |
| 1575 | pcm_open_retry_count = PROXY_OPEN_RETRY_COUNT; |
| 1576 | } else |
| 1577 | flags |= PCM_MONOTONIC; |
| 1578 | |
| 1579 | while (1) { |
| 1580 | out->pcm = pcm_open(adev->snd_card, out->pcm_device_id, |
| 1581 | flags, &out->config); |
| 1582 | if (out->pcm && !pcm_is_ready(out->pcm)) { |
| 1583 | ALOGE("%s: %s", __func__, pcm_get_error(out->pcm)); |
| 1584 | if (out->pcm != NULL) { |
| 1585 | pcm_close(out->pcm); |
| 1586 | out->pcm = NULL; |
| 1587 | } |
| 1588 | if (pcm_open_retry_count-- == 0) { |
| 1589 | ret = -EIO; |
| 1590 | goto error_open; |
| 1591 | } |
| 1592 | usleep(PROXY_OPEN_WAIT_TIME * 1000); |
| 1593 | continue; |
| 1594 | } |
| 1595 | break; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1596 | } |
| 1597 | } else { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1598 | out->pcm = NULL; |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 1599 | out->compr = compress_open(adev->snd_card, |
| 1600 | out->pcm_device_id, |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1601 | COMPRESS_IN, &out->compr_config); |
| 1602 | if (out->compr && !is_compress_ready(out->compr)) { |
| 1603 | ALOGE("%s: %s", __func__, compress_get_error(out->compr)); |
| 1604 | compress_close(out->compr); |
| 1605 | out->compr = NULL; |
| 1606 | ret = -EIO; |
| 1607 | goto error_open; |
| 1608 | } |
| 1609 | if (out->offload_callback) |
| 1610 | compress_nonblock(out->compr, out->non_blocking); |
Eric Laurent | c4aef75 | 2013-09-12 17:45:53 -0700 | [diff] [blame] | 1611 | |
Fred Oh | 1483d8a | 2015-03-04 18:42:34 -0800 | [diff] [blame] | 1612 | /* Since small bufs uses blocking writes, a write will be blocked |
| 1613 | for the default max poll time (20s) in the event of an SSR. |
| 1614 | Reduce the poll time to observe and deal with SSR faster. |
| 1615 | */ |
| 1616 | if (out->use_small_bufs) { |
| 1617 | compress_set_max_poll_wait(out->compr, 1000); |
| 1618 | } |
| 1619 | |
Subhash Chandra Bose Naripeddy | e0a0712 | 2013-12-14 00:34:53 -0800 | [diff] [blame] | 1620 | #ifdef DS1_DOLBY_DDP_ENABLED |
| 1621 | if (audio_extn_is_dolby_format(out->format)) |
| 1622 | audio_extn_dolby_send_ddp_endp_params(adev); |
| 1623 | #endif |
| 1624 | |
Eric Laurent | c4aef75 | 2013-09-12 17:45:53 -0700 | [diff] [blame] | 1625 | if (adev->visualizer_start_output != NULL) |
Subhash Chandra Bose Naripeddy | 1d08916 | 2013-11-13 13:31:50 -0800 | [diff] [blame] | 1626 | adev->visualizer_start_output(out->handle, out->pcm_device_id); |
| 1627 | if (adev->offload_effects_start_output != NULL) |
| 1628 | adev->offload_effects_start_output(out->handle, out->pcm_device_id); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1629 | } |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 1630 | ALOGV("%s: exit", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1631 | return 0; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1632 | error_open: |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1633 | stop_output_stream(out); |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1634 | error_config: |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1635 | return ret; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1636 | } |
| 1637 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1638 | static int check_input_parameters(uint32_t sample_rate, |
| 1639 | audio_format_t format, |
| 1640 | int channel_count) |
| 1641 | { |
Ravi Kumar Alamanda | fae4211 | 2013-11-07 23:31:54 -0800 | [diff] [blame] | 1642 | int ret = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1643 | |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 1644 | if ((format != AUDIO_FORMAT_PCM_16_BIT) && |
Mingming Yin | e62d784 | 2013-10-25 16:26:03 -0700 | [diff] [blame] | 1645 | !voice_extn_compress_voip_is_format_supported(format) && |
| 1646 | !audio_extn_compr_cap_format_supported(format)) ret = -EINVAL; |
Ravi Kumar Alamanda | fae4211 | 2013-11-07 23:31:54 -0800 | [diff] [blame] | 1647 | |
| 1648 | switch (channel_count) { |
| 1649 | case 1: |
| 1650 | case 2: |
| 1651 | case 6: |
| 1652 | break; |
| 1653 | default: |
| 1654 | ret = -EINVAL; |
| 1655 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1656 | |
| 1657 | switch (sample_rate) { |
| 1658 | case 8000: |
| 1659 | case 11025: |
| 1660 | case 12000: |
| 1661 | case 16000: |
| 1662 | case 22050: |
| 1663 | case 24000: |
| 1664 | case 32000: |
| 1665 | case 44100: |
| 1666 | case 48000: |
| 1667 | break; |
| 1668 | default: |
Ravi Kumar Alamanda | fae4211 | 2013-11-07 23:31:54 -0800 | [diff] [blame] | 1669 | ret = -EINVAL; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1670 | } |
| 1671 | |
Ravi Kumar Alamanda | fae4211 | 2013-11-07 23:31:54 -0800 | [diff] [blame] | 1672 | return ret; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1673 | } |
| 1674 | |
| 1675 | static size_t get_input_buffer_size(uint32_t sample_rate, |
| 1676 | audio_format_t format, |
Ravi Kumar Alamanda | 1c3de5e | 2014-09-08 15:59:58 -0700 | [diff] [blame] | 1677 | int channel_count, |
| 1678 | bool is_low_latency) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1679 | { |
| 1680 | size_t size = 0; |
| 1681 | |
Ravi Kumar Alamanda | 33d3306 | 2013-06-11 14:40:01 -0700 | [diff] [blame] | 1682 | if (check_input_parameters(sample_rate, format, channel_count) != 0) |
| 1683 | return 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1684 | |
Ravi Kumar Alamanda | 33d3306 | 2013-06-11 14:40:01 -0700 | [diff] [blame] | 1685 | size = (sample_rate * AUDIO_CAPTURE_PERIOD_DURATION_MSEC) / 1000; |
Ravi Kumar Alamanda | 1c3de5e | 2014-09-08 15:59:58 -0700 | [diff] [blame] | 1686 | if (is_low_latency) |
| 1687 | size = configured_low_latency_capture_period_size; |
Ravi Kumar Alamanda | 33d3306 | 2013-06-11 14:40:01 -0700 | [diff] [blame] | 1688 | /* ToDo: should use frame_size computed based on the format and |
| 1689 | channel_count here. */ |
| 1690 | size *= sizeof(short) * channel_count; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1691 | |
Ravi Kumar Alamanda | 1c3de5e | 2014-09-08 15:59:58 -0700 | [diff] [blame] | 1692 | /* make sure the size is multiple of 32 bytes |
| 1693 | * At 48 kHz mono 16-bit PCM: |
| 1694 | * 5.000 ms = 240 frames = 15*16*1*2 = 480, a whole multiple of 32 (15) |
| 1695 | * 3.333 ms = 160 frames = 10*16*1*2 = 320, a whole multiple of 32 (10) |
| 1696 | */ |
| 1697 | size += 0x1f; |
| 1698 | size &= ~0x1f; |
Ravi Kumar Alamanda | 33d3306 | 2013-06-11 14:40:01 -0700 | [diff] [blame] | 1699 | |
| 1700 | return size; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1701 | } |
| 1702 | |
| 1703 | static uint32_t out_get_sample_rate(const struct audio_stream *stream) |
| 1704 | { |
| 1705 | struct stream_out *out = (struct stream_out *)stream; |
| 1706 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1707 | return out->sample_rate; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1708 | } |
| 1709 | |
Divya Narayanan Poojary | bd9f33f | 2014-09-17 17:35:59 +0530 | [diff] [blame] | 1710 | static int out_set_sample_rate(struct audio_stream *stream __unused, |
| 1711 | uint32_t rate __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1712 | { |
| 1713 | return -ENOSYS; |
| 1714 | } |
| 1715 | |
| 1716 | static size_t out_get_buffer_size(const struct audio_stream *stream) |
| 1717 | { |
| 1718 | struct stream_out *out = (struct stream_out *)stream; |
| 1719 | |
Subhash Chandra Bose Naripeddy | 148144e | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 1720 | if (is_offload_usecase(out->usecase)) |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1721 | return out->compr_config.fragment_size; |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 1722 | else if(out->usecase == USECASE_COMPRESS_VOIP_CALL) |
| 1723 | return voice_extn_compress_voip_out_get_buffer_size(out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1724 | |
Divya Narayanan Poojary | 69236ba | 2014-09-18 11:57:57 +0530 | [diff] [blame] | 1725 | return out->config.period_size * |
| 1726 | audio_stream_out_frame_size((const struct audio_stream_out *)stream); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1727 | } |
| 1728 | |
| 1729 | static uint32_t out_get_channels(const struct audio_stream *stream) |
| 1730 | { |
| 1731 | struct stream_out *out = (struct stream_out *)stream; |
| 1732 | |
| 1733 | return out->channel_mask; |
| 1734 | } |
| 1735 | |
| 1736 | static audio_format_t out_get_format(const struct audio_stream *stream) |
| 1737 | { |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1738 | struct stream_out *out = (struct stream_out *)stream; |
| 1739 | |
| 1740 | return out->format; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1741 | } |
| 1742 | |
Divya Narayanan Poojary | bd9f33f | 2014-09-17 17:35:59 +0530 | [diff] [blame] | 1743 | static int out_set_format(struct audio_stream *stream __unused, |
| 1744 | audio_format_t format __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1745 | { |
| 1746 | return -ENOSYS; |
| 1747 | } |
| 1748 | |
| 1749 | static int out_standby(struct audio_stream *stream) |
| 1750 | { |
| 1751 | struct stream_out *out = (struct stream_out *)stream; |
| 1752 | struct audio_device *adev = out->dev; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1753 | |
Sidipotu Ashok | e4514fa | 2014-05-02 16:21:50 +0530 | [diff] [blame] | 1754 | ALOGD("%s: enter: stream (%p) usecase(%d: %s)", __func__, |
| 1755 | stream, out->usecase, use_case_table[out->usecase]); |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 1756 | if (out->usecase == USECASE_COMPRESS_VOIP_CALL) { |
| 1757 | /* Ignore standby in case of voip call because the voip output |
| 1758 | * stream is closed in adev_close_output_stream() |
| 1759 | */ |
Sidipotu Ashok | e4514fa | 2014-05-02 16:21:50 +0530 | [diff] [blame] | 1760 | ALOGD("%s: Ignore Standby in VOIP call", __func__); |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 1761 | return 0; |
| 1762 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1763 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1764 | pthread_mutex_lock(&out->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1765 | if (!out->standby) { |
Ravi Kumar Alamanda | 8bba9e9 | 2013-11-11 21:09:07 -0800 | [diff] [blame] | 1766 | pthread_mutex_lock(&adev->lock); |
Ethan Chen | 79c356c | 2015-06-07 12:26:14 -0700 | [diff] [blame] | 1767 | |
| 1768 | amplifier_output_stream_standby((struct audio_stream_out *) stream); |
| 1769 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1770 | out->standby = true; |
Subhash Chandra Bose Naripeddy | 148144e | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 1771 | if (!is_offload_usecase(out->usecase)) { |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1772 | if (out->pcm) { |
| 1773 | pcm_close(out->pcm); |
| 1774 | out->pcm = NULL; |
| 1775 | } |
| 1776 | } else { |
Sidipotu Ashok | 5bfacf7 | 2014-02-10 16:16:38 +0530 | [diff] [blame] | 1777 | ALOGD("copl(%x):standby", (unsigned int)out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1778 | stop_compressed_output_l(out); |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 1779 | out->gapless_mdata.encoder_delay = 0; |
| 1780 | out->gapless_mdata.encoder_padding = 0; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1781 | if (out->compr != NULL) { |
| 1782 | compress_close(out->compr); |
| 1783 | out->compr = NULL; |
| 1784 | } |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 1785 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1786 | stop_output_stream(out); |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 1787 | pthread_mutex_unlock(&adev->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1788 | } |
| 1789 | pthread_mutex_unlock(&out->lock); |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 1790 | ALOGV("%s: exit", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1791 | return 0; |
| 1792 | } |
| 1793 | |
Divya Narayanan Poojary | bd9f33f | 2014-09-17 17:35:59 +0530 | [diff] [blame] | 1794 | static int out_dump(const struct audio_stream *stream __unused, |
| 1795 | int fd __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1796 | { |
| 1797 | return 0; |
| 1798 | } |
| 1799 | |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 1800 | static int parse_compress_metadata(struct stream_out *out, struct str_parms *parms) |
| 1801 | { |
| 1802 | int ret = 0; |
| 1803 | char value[32]; |
Krishnankutty Kolathappilly | eb78be7 | 2013-12-15 12:03:07 -0800 | [diff] [blame] | 1804 | bool is_meta_data_params = false; |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 1805 | struct compr_gapless_mdata tmp_mdata; |
Krishnankutty Kolathappilly | eb78be7 | 2013-12-15 12:03:07 -0800 | [diff] [blame] | 1806 | tmp_mdata.encoder_delay = 0; |
| 1807 | tmp_mdata.encoder_padding = 0; |
ApurupaPattapu | daa708c | 2013-12-18 15:47:59 -0800 | [diff] [blame] | 1808 | |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 1809 | if (!out || !parms) { |
Krishnankutty Kolathappilly | eb78be7 | 2013-12-15 12:03:07 -0800 | [diff] [blame] | 1810 | ALOGE("%s: return invalid ",__func__); |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 1811 | return -EINVAL; |
| 1812 | } |
| 1813 | |
ApurupaPattapu | daa708c | 2013-12-18 15:47:59 -0800 | [diff] [blame] | 1814 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_FORMAT, value, sizeof(value)); |
| 1815 | if (ret >= 0) { |
| 1816 | if (atoi(value) == SND_AUDIOSTREAMFORMAT_MP4ADTS) { |
| 1817 | out->compr_config.codec->format = SND_AUDIOSTREAMFORMAT_MP4ADTS; |
| 1818 | ALOGV("ADTS format is set in offload mode"); |
| 1819 | } |
| 1820 | out->send_new_metadata = 1; |
| 1821 | } |
| 1822 | |
Steve Kondik | 6bedcdf | 2014-07-21 11:48:30 -0700 | [diff] [blame] | 1823 | #ifdef FLAC_OFFLOAD_ENABLED |
ApurupaPattapu | 9d6b436 | 2014-02-27 10:24:11 -0800 | [diff] [blame] | 1824 | if (out->format == AUDIO_FORMAT_FLAC) { |
| 1825 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_FLAC_MIN_BLK_SIZE, value, sizeof(value)); |
| 1826 | if (ret >= 0) { |
| 1827 | out->compr_config.codec->options.flac_dec.min_blk_size = atoi(value); |
| 1828 | out->send_new_metadata = 1; |
| 1829 | } |
| 1830 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_FLAC_MAX_BLK_SIZE, value, sizeof(value)); |
| 1831 | if (ret >= 0) { |
| 1832 | out->compr_config.codec->options.flac_dec.max_blk_size = atoi(value); |
| 1833 | out->send_new_metadata = 1; |
| 1834 | } |
| 1835 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_FLAC_MIN_FRAME_SIZE, value, sizeof(value)); |
| 1836 | if (ret >= 0) { |
| 1837 | out->compr_config.codec->options.flac_dec.min_frame_size = atoi(value); |
| 1838 | out->send_new_metadata = 1; |
| 1839 | } |
| 1840 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_FLAC_MAX_FRAME_SIZE, value, sizeof(value)); |
| 1841 | if (ret >= 0) { |
| 1842 | out->compr_config.codec->options.flac_dec.max_frame_size = atoi(value); |
| 1843 | out->send_new_metadata = 1; |
| 1844 | } |
| 1845 | } |
Steve Kondik | 6bedcdf | 2014-07-21 11:48:30 -0700 | [diff] [blame] | 1846 | #endif |
ApurupaPattapu | 9d6b436 | 2014-02-27 10:24:11 -0800 | [diff] [blame] | 1847 | |
Krishnankutty Kolathappilly | eb78be7 | 2013-12-15 12:03:07 -0800 | [diff] [blame] | 1848 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_SAMPLE_RATE, value, sizeof(value)); |
| 1849 | if(ret >= 0) |
| 1850 | is_meta_data_params = true; |
| 1851 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_NUM_CHANNEL, value, sizeof(value)); |
| 1852 | if(ret >= 0 ) |
| 1853 | is_meta_data_params = true; |
| 1854 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_AVG_BIT_RATE, value, sizeof(value)); |
| 1855 | if(ret >= 0 ) |
| 1856 | is_meta_data_params = true; |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 1857 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_DELAY_SAMPLES, value, sizeof(value)); |
| 1858 | if (ret >= 0) { |
Krishnankutty Kolathappilly | eb78be7 | 2013-12-15 12:03:07 -0800 | [diff] [blame] | 1859 | is_meta_data_params = true; |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 1860 | tmp_mdata.encoder_delay = atoi(value); //whats a good limit check? |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 1861 | } |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 1862 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_PADDING_SAMPLES, value, sizeof(value)); |
| 1863 | if (ret >= 0) { |
Krishnankutty Kolathappilly | eb78be7 | 2013-12-15 12:03:07 -0800 | [diff] [blame] | 1864 | is_meta_data_params = true; |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 1865 | tmp_mdata.encoder_padding = atoi(value); |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 1866 | } |
| 1867 | |
Krishnankutty Kolathappilly | eb78be7 | 2013-12-15 12:03:07 -0800 | [diff] [blame] | 1868 | if(!is_meta_data_params) { |
| 1869 | ALOGV("%s: Not gapless meta data params", __func__); |
| 1870 | return 0; |
| 1871 | } |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 1872 | out->gapless_mdata = tmp_mdata; |
| 1873 | out->send_new_metadata = 1; |
| 1874 | ALOGV("%s new encoder delay %u and padding %u", __func__, |
| 1875 | out->gapless_mdata.encoder_delay, out->gapless_mdata.encoder_padding); |
| 1876 | |
Steve Kondik | ba3b35d | 2014-07-18 01:49:48 -0700 | [diff] [blame] | 1877 | if(out->format == AUDIO_FORMAT_WMA || out->format == AUDIO_FORMAT_WMA_PRO) { |
| 1878 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_WMA_FORMAT_TAG, value, sizeof(value)); |
| 1879 | if (ret >= 0) { |
| 1880 | out->compr_config.codec->format = atoi(value); |
| 1881 | } |
| 1882 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_WMA_BLOCK_ALIGN, value, sizeof(value)); |
| 1883 | if (ret >= 0) { |
| 1884 | out->compr_config.codec->options.wma.super_block_align = atoi(value); |
| 1885 | } |
| 1886 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_WMA_BIT_PER_SAMPLE, value, sizeof(value)); |
| 1887 | if (ret >= 0) { |
| 1888 | out->compr_config.codec->options.wma.bits_per_sample = atoi(value); |
| 1889 | } |
| 1890 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_WMA_CHANNEL_MASK, value, sizeof(value)); |
| 1891 | if (ret >= 0) { |
| 1892 | out->compr_config.codec->options.wma.channelmask = atoi(value); |
| 1893 | } |
| 1894 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_WMA_ENCODE_OPTION, value, sizeof(value)); |
| 1895 | if (ret >= 0) { |
| 1896 | out->compr_config.codec->options.wma.encodeopt = atoi(value); |
| 1897 | } |
| 1898 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_WMA_ENCODE_OPTION1, value, sizeof(value)); |
| 1899 | if (ret >= 0) { |
| 1900 | out->compr_config.codec->options.wma.encodeopt1 = atoi(value); |
| 1901 | } |
| 1902 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_WMA_ENCODE_OPTION2, value, sizeof(value)); |
| 1903 | if (ret >= 0) { |
| 1904 | out->compr_config.codec->options.wma.encodeopt2 = atoi(value); |
| 1905 | } |
| 1906 | ALOGV("WMA params: fmt %x, balgn %x, sr %d, chmsk %x, encop %x, op1 %x, op2 %x", |
| 1907 | out->compr_config.codec->format, |
| 1908 | out->compr_config.codec->options.wma.super_block_align, |
| 1909 | out->compr_config.codec->options.wma.bits_per_sample, |
| 1910 | out->compr_config.codec->options.wma.channelmask, |
| 1911 | out->compr_config.codec->options.wma.encodeopt, |
| 1912 | out->compr_config.codec->options.wma.encodeopt1, |
| 1913 | out->compr_config.codec->options.wma.encodeopt2); |
| 1914 | } |
| 1915 | |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 1916 | return 0; |
| 1917 | } |
| 1918 | |
Divya Narayanan Poojary | ab9b1ef | 2014-09-12 15:52:36 +0530 | [diff] [blame] | 1919 | static bool output_drives_call(struct audio_device *adev, struct stream_out *out) |
| 1920 | { |
| 1921 | return out == adev->primary_output || out == adev->voice_tx_output; |
| 1922 | } |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 1923 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1924 | static int out_set_parameters(struct audio_stream *stream, const char *kvpairs) |
| 1925 | { |
| 1926 | struct stream_out *out = (struct stream_out *)stream; |
| 1927 | struct audio_device *adev = out->dev; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 1928 | struct audio_usecase *usecase; |
| 1929 | struct listnode *node; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1930 | struct str_parms *parms; |
| 1931 | char value[32]; |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 1932 | int ret = 0, val = 0, err; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 1933 | bool select_new_device = false; |
Steve Kondik | 3abbbc8 | 2014-11-29 14:14:43 -0800 | [diff] [blame] | 1934 | int status = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1935 | |
sangwoo | bc67724 | 2013-08-08 16:53:43 +0900 | [diff] [blame] | 1936 | ALOGD("%s: enter: usecase(%d: %s) kvpairs: %s", |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1937 | __func__, out->usecase, use_case_table[out->usecase], kvpairs); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1938 | parms = str_parms_create_str(kvpairs); |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 1939 | err = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, value, sizeof(value)); |
| 1940 | if (err >= 0) { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1941 | val = atoi(value); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1942 | pthread_mutex_lock(&out->lock); |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 1943 | pthread_mutex_lock(&adev->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1944 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1945 | /* |
Dhanalakshmi Siddani | 523ae41 | 2014-04-18 22:26:56 +0530 | [diff] [blame] | 1946 | * When HDMI cable is unplugged/usb hs is disconnected the |
| 1947 | * music playback is paused and the policy manager sends routing=0 |
| 1948 | * But the audioflingercontinues to write data until standby time |
| 1949 | * (3sec). As the HDMI core is turned off, the write gets blocked. |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1950 | * Avoid this by routing audio to speaker until standby. |
| 1951 | */ |
Dhanalakshmi Siddani | 523ae41 | 2014-04-18 22:26:56 +0530 | [diff] [blame] | 1952 | if ((out->devices == AUDIO_DEVICE_OUT_AUX_DIGITAL || |
Steve Kondik | eadb6c8 | 2014-09-03 18:40:06 -0700 | [diff] [blame] | 1953 | out->devices == AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET || |
| 1954 | out->devices == AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) && |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1955 | val == AUDIO_DEVICE_NONE) { |
| 1956 | val = AUDIO_DEVICE_OUT_SPEAKER; |
| 1957 | } |
| 1958 | |
| 1959 | /* |
| 1960 | * select_devices() call below switches all the usecases on the same |
| 1961 | * backend to the new device. Refer to check_usecases_codec_backend() in |
| 1962 | * the select_devices(). But how do we undo this? |
| 1963 | * |
| 1964 | * For example, music playback is active on headset (deep-buffer usecase) |
| 1965 | * and if we go to ringtones and select a ringtone, low-latency usecase |
| 1966 | * will be started on headset+speaker. As we can't enable headset+speaker |
| 1967 | * and headset devices at the same time, select_devices() switches the music |
| 1968 | * playback to headset+speaker while starting low-lateny usecase for ringtone. |
| 1969 | * So when the ringtone playback is completed, how do we undo the same? |
| 1970 | * |
| 1971 | * We are relying on the out_set_parameters() call on deep-buffer output, |
| 1972 | * once the ringtone playback is ended. |
| 1973 | * NOTE: We should not check if the current devices are same as new devices. |
| 1974 | * Because select_devices() must be called to switch back the music |
| 1975 | * playback to headset. |
| 1976 | */ |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 1977 | if (val != 0) { |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1978 | out->devices = val; |
| 1979 | |
| 1980 | if (!out->standby) |
| 1981 | select_devices(adev, out->usecase); |
| 1982 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 1983 | if ((adev->mode == AUDIO_MODE_IN_CALL) && |
Divya Narayanan Poojary | ab9b1ef | 2014-09-12 15:52:36 +0530 | [diff] [blame] | 1984 | output_drives_call(adev, out)) { |
| 1985 | adev->current_call_output = out; |
Vidyakumar Athota | f85f6a2 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 1986 | if (!adev->voice.in_call) |
Divya Narayanan Poojary | ab9b1ef | 2014-09-12 15:52:36 +0530 | [diff] [blame] | 1987 | ret = voice_start_call(adev); |
| 1988 | else |
| 1989 | voice_update_devices_for_all_voice_usecases(adev); |
Vidyakumar Athota | f85f6a2 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 1990 | } |
| 1991 | } |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 1992 | |
Vidyakumar Athota | f85f6a2 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 1993 | if ((adev->mode == AUDIO_MODE_NORMAL) && |
| 1994 | adev->voice.in_call && |
| 1995 | output_drives_call(adev, out)) { |
| 1996 | ret = voice_stop_call(adev); |
| 1997 | adev->current_call_output = NULL; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1998 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1999 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2000 | pthread_mutex_unlock(&adev->lock); |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 2001 | pthread_mutex_unlock(&out->lock); |
Eric Laurent | da46bfb | 2014-08-25 22:39:29 -0500 | [diff] [blame] | 2002 | |
| 2003 | /*handles device and call state changes*/ |
| 2004 | audio_extn_extspk_update(adev->extspk); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2005 | } |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 2006 | |
| 2007 | if (out == adev->primary_output) { |
| 2008 | pthread_mutex_lock(&adev->lock); |
| 2009 | audio_extn_set_parameters(adev, parms); |
| 2010 | pthread_mutex_unlock(&adev->lock); |
| 2011 | } |
Subhash Chandra Bose Naripeddy | 148144e | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 2012 | if (is_offload_usecase(out->usecase)) { |
Krishnankutty Kolathappilly | eb78be7 | 2013-12-15 12:03:07 -0800 | [diff] [blame] | 2013 | pthread_mutex_lock(&out->lock); |
Steve Kondik | ba3b35d | 2014-07-18 01:49:48 -0700 | [diff] [blame] | 2014 | ret = parse_compress_metadata(out, parms); |
Krishnankutty Kolathappilly | eb78be7 | 2013-12-15 12:03:07 -0800 | [diff] [blame] | 2015 | pthread_mutex_unlock(&out->lock); |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 2016 | } |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 2017 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2018 | str_parms_destroy(parms); |
Steve Kondik | 3abbbc8 | 2014-11-29 14:14:43 -0800 | [diff] [blame] | 2019 | ALOGV("%s: exit: code(%d)", __func__, status); |
| 2020 | return status; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2021 | } |
| 2022 | |
| 2023 | static char* out_get_parameters(const struct audio_stream *stream, const char *keys) |
| 2024 | { |
| 2025 | struct stream_out *out = (struct stream_out *)stream; |
| 2026 | struct str_parms *query = str_parms_create_str(keys); |
| 2027 | char *str; |
| 2028 | char value[256]; |
| 2029 | struct str_parms *reply = str_parms_create(); |
| 2030 | size_t i, j; |
| 2031 | int ret; |
| 2032 | bool first = true; |
Haynes Mathew George | 9f0254a | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 2033 | |
| 2034 | if (!query || !reply) { |
| 2035 | ALOGE("out_get_parameters: failed to allocate mem for query or reply"); |
| 2036 | return NULL; |
| 2037 | } |
| 2038 | |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 2039 | ALOGV("%s: enter: keys - %s", __func__, keys); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2040 | ret = str_parms_get_str(query, AUDIO_PARAMETER_STREAM_SUP_CHANNELS, value, sizeof(value)); |
| 2041 | if (ret >= 0) { |
| 2042 | value[0] = '\0'; |
| 2043 | i = 0; |
| 2044 | while (out->supported_channel_masks[i] != 0) { |
| 2045 | for (j = 0; j < ARRAY_SIZE(out_channels_name_to_enum_table); j++) { |
| 2046 | if (out_channels_name_to_enum_table[j].value == out->supported_channel_masks[i]) { |
| 2047 | if (!first) { |
| 2048 | strcat(value, "|"); |
| 2049 | } |
| 2050 | strcat(value, out_channels_name_to_enum_table[j].name); |
| 2051 | first = false; |
| 2052 | break; |
| 2053 | } |
| 2054 | } |
| 2055 | i++; |
| 2056 | } |
| 2057 | str_parms_add_str(reply, AUDIO_PARAMETER_STREAM_SUP_CHANNELS, value); |
| 2058 | str = str_parms_to_str(reply); |
| 2059 | } else { |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 2060 | voice_extn_out_get_parameters(out, query, reply); |
| 2061 | str = str_parms_to_str(reply); |
| 2062 | if (!strncmp(str, "", sizeof(""))) { |
Narsinga Rao Chella | 2e03235 | 2014-01-29 12:52:19 -0800 | [diff] [blame] | 2063 | free(str); |
| 2064 | str = strdup(keys); |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 2065 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2066 | } |
| 2067 | str_parms_destroy(query); |
| 2068 | str_parms_destroy(reply); |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 2069 | ALOGV("%s: exit: returns - %s", __func__, str); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2070 | return str; |
| 2071 | } |
| 2072 | |
| 2073 | static uint32_t out_get_latency(const struct audio_stream_out *stream) |
| 2074 | { |
| 2075 | struct stream_out *out = (struct stream_out *)stream; |
Alexy Joseph | 3a2fec3 | 2014-12-03 02:46:47 -0800 | [diff] [blame] | 2076 | uint32_t latency = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2077 | |
Alexy Joseph | 3a2fec3 | 2014-12-03 02:46:47 -0800 | [diff] [blame] | 2078 | if (is_offload_usecase(out->usecase)) { |
Alexy Joseph | 62babb9 | 2015-03-03 19:01:03 -0800 | [diff] [blame] | 2079 | latency = COMPRESS_OFFLOAD_PLAYBACK_LATENCY; |
Alexy Joseph | 3a2fec3 | 2014-12-03 02:46:47 -0800 | [diff] [blame] | 2080 | } else { |
| 2081 | latency = (out->config.period_count * out->config.period_size * 1000) / |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2082 | (out->config.rate); |
Alexy Joseph | 3a2fec3 | 2014-12-03 02:46:47 -0800 | [diff] [blame] | 2083 | } |
| 2084 | |
Anish Kumar | 1a0594f | 2014-12-09 04:01:39 +0530 | [diff] [blame] | 2085 | ALOGV("%s: Latency %d", __func__, latency); |
Alexy Joseph | 3a2fec3 | 2014-12-03 02:46:47 -0800 | [diff] [blame] | 2086 | return latency; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2087 | } |
| 2088 | |
| 2089 | static int out_set_volume(struct audio_stream_out *stream, float left, |
| 2090 | float right) |
| 2091 | { |
Eric Laurent | a9024de | 2013-04-04 09:19:12 -0700 | [diff] [blame] | 2092 | struct stream_out *out = (struct stream_out *)stream; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2093 | int volume[2]; |
| 2094 | |
Eric Laurent | a9024de | 2013-04-04 09:19:12 -0700 | [diff] [blame] | 2095 | if (out->usecase == USECASE_AUDIO_PLAYBACK_MULTI_CH) { |
| 2096 | /* only take left channel into account: the API is for stereo anyway */ |
| 2097 | out->muted = (left == 0.0f); |
| 2098 | return 0; |
Subhash Chandra Bose Naripeddy | 148144e | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 2099 | } else if (is_offload_usecase(out->usecase)) { |
Subhash Chandra Bose Naripeddy | 1d08916 | 2013-11-13 13:31:50 -0800 | [diff] [blame] | 2100 | char mixer_ctl_name[128]; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2101 | struct audio_device *adev = out->dev; |
| 2102 | struct mixer_ctl *ctl; |
Subhash Chandra Bose Naripeddy | 1d08916 | 2013-11-13 13:31:50 -0800 | [diff] [blame] | 2103 | int pcm_device_id = platform_get_pcm_device_id(out->usecase, |
| 2104 | PCM_PLAYBACK); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2105 | |
Subhash Chandra Bose Naripeddy | 1d08916 | 2013-11-13 13:31:50 -0800 | [diff] [blame] | 2106 | snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), |
| 2107 | "Compress Playback %d Volume", pcm_device_id); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2108 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 2109 | if (!ctl) { |
| 2110 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 2111 | __func__, mixer_ctl_name); |
| 2112 | return -EINVAL; |
| 2113 | } |
| 2114 | volume[0] = (int)(left * COMPRESS_PLAYBACK_VOLUME_MAX); |
| 2115 | volume[1] = (int)(right * COMPRESS_PLAYBACK_VOLUME_MAX); |
| 2116 | mixer_ctl_set_array(ctl, volume, sizeof(volume)/sizeof(volume[0])); |
| 2117 | return 0; |
Eric Laurent | a9024de | 2013-04-04 09:19:12 -0700 | [diff] [blame] | 2118 | } |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2119 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2120 | return -ENOSYS; |
| 2121 | } |
| 2122 | |
| 2123 | static ssize_t out_write(struct audio_stream_out *stream, const void *buffer, |
| 2124 | size_t bytes) |
| 2125 | { |
| 2126 | struct stream_out *out = (struct stream_out *)stream; |
| 2127 | struct audio_device *adev = out->dev; |
Naresh Tanniru | cef332d | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 2128 | int snd_scard_state = get_snd_card_state(adev); |
Eric Laurent | 6e89524 | 2013-09-05 16:10:57 -0700 | [diff] [blame] | 2129 | ssize_t ret = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2130 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2131 | pthread_mutex_lock(&out->lock); |
Naresh Tanniru | 2d19ab4 | 2014-05-11 19:56:25 +0530 | [diff] [blame] | 2132 | |
Naresh Tanniru | cef332d | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 2133 | if (SND_CARD_STATE_OFFLINE == snd_scard_state) { |
| 2134 | if (out->pcm) { |
Naresh Tanniru | 2d19ab4 | 2014-05-11 19:56:25 +0530 | [diff] [blame] | 2135 | ALOGD(" %s: sound card is not active/SSR state", __func__); |
| 2136 | ret= -ENETRESET; |
| 2137 | goto exit; |
Alexy Joseph | 5520435 | 2014-10-06 12:15:01 -0700 | [diff] [blame] | 2138 | } else if (is_offload_usecase(out->usecase)) { |
Naresh Tanniru | cef332d | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 2139 | //during SSR for compress usecase we should return error to flinger |
| 2140 | ALOGD(" copl %s: sound card is not active/SSR state", __func__); |
| 2141 | pthread_mutex_unlock(&out->lock); |
| 2142 | return -ENETRESET; |
Naresh Tanniru | 2d19ab4 | 2014-05-11 19:56:25 +0530 | [diff] [blame] | 2143 | } |
| 2144 | } |
| 2145 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2146 | if (out->standby) { |
Ravi Kumar Alamanda | 59d296d | 2013-05-02 11:25:27 -0700 | [diff] [blame] | 2147 | out->standby = false; |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 2148 | pthread_mutex_lock(&adev->lock); |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 2149 | if (out->usecase == USECASE_COMPRESS_VOIP_CALL) |
| 2150 | ret = voice_extn_compress_voip_start_output_stream(out); |
| 2151 | else |
| 2152 | ret = start_output_stream(out); |
Ethan Chen | 79c356c | 2015-06-07 12:26:14 -0700 | [diff] [blame] | 2153 | |
| 2154 | if (ret == 0) |
| 2155 | amplifier_output_stream_start(stream, |
| 2156 | is_offload_usecase(out->usecase)); |
| 2157 | |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 2158 | pthread_mutex_unlock(&adev->lock); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2159 | /* ToDo: If use case is compress offload should return 0 */ |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2160 | if (ret != 0) { |
Ravi Kumar Alamanda | 59d296d | 2013-05-02 11:25:27 -0700 | [diff] [blame] | 2161 | out->standby = true; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2162 | goto exit; |
| 2163 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2164 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2165 | |
Subhash Chandra Bose Naripeddy | 148144e | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 2166 | if (is_offload_usecase(out->usecase)) { |
Alexy Joseph | 62babb9 | 2015-03-03 19:01:03 -0800 | [diff] [blame] | 2167 | ALOGVV("copl(%p): writing buffer (%zu bytes) to compress device", out, bytes); |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 2168 | if (out->send_new_metadata) { |
Sidipotu Ashok | 5bfacf7 | 2014-02-10 16:16:38 +0530 | [diff] [blame] | 2169 | ALOGD("copl(%x):send new gapless metadata", (unsigned int)out); |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 2170 | compress_set_gapless_metadata(out->compr, &out->gapless_mdata); |
| 2171 | out->send_new_metadata = 0; |
| 2172 | } |
| 2173 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2174 | ret = compress_write(out->compr, buffer, bytes); |
Dhanalakshmi Siddani | 834b22f | 2014-08-20 12:28:34 +0530 | [diff] [blame] | 2175 | if (ret < 0) |
| 2176 | ret = -errno; |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 2177 | ALOGVV("%s: writing buffer (%d bytes) to compress device returned %d", __func__, bytes, ret); |
Eric Laurent | 6e89524 | 2013-09-05 16:10:57 -0700 | [diff] [blame] | 2178 | if (ret >= 0 && ret < (ssize_t)bytes) { |
Sidipotu Ashok | 5bfacf7 | 2014-02-10 16:16:38 +0530 | [diff] [blame] | 2179 | ALOGD("No space available in compress driver, post msg to cb thread"); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2180 | send_offload_cmd_l(out, OFFLOAD_CMD_WAIT_FOR_BUFFER); |
Naresh Tanniru | cef332d | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 2181 | } else if (-ENETRESET == ret) { |
| 2182 | ALOGE("copl %s: received sound card offline state on compress write", __func__); |
| 2183 | set_snd_card_state(adev,SND_CARD_STATE_OFFLINE); |
| 2184 | pthread_mutex_unlock(&out->lock); |
| 2185 | out_standby(&out->stream.common); |
| 2186 | return ret; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2187 | } |
Naresh Tanniru | cef332d | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 2188 | if (!out->playback_started && ret >= 0) { |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2189 | compress_start(out->compr); |
| 2190 | out->playback_started = 1; |
| 2191 | out->offload_state = OFFLOAD_STATE_PLAYING; |
| 2192 | } |
| 2193 | pthread_mutex_unlock(&out->lock); |
| 2194 | return ret; |
| 2195 | } else { |
| 2196 | if (out->pcm) { |
| 2197 | if (out->muted) |
| 2198 | memset((void *)buffer, 0, bytes); |
| 2199 | ALOGVV("%s: writing buffer (%d bytes) to pcm device", __func__, bytes); |
Divya Narayanan Poojary | ab9b1ef | 2014-09-12 15:52:36 +0530 | [diff] [blame] | 2200 | if (out->usecase == USECASE_AUDIO_PLAYBACK_AFE_PROXY) |
| 2201 | ret = pcm_mmap_write(out->pcm, (void *)buffer, bytes); |
| 2202 | else |
| 2203 | ret = pcm_write(out->pcm, (void *)buffer, bytes); |
Dhanalakshmi Siddani | 834b22f | 2014-08-20 12:28:34 +0530 | [diff] [blame] | 2204 | if (ret < 0) |
| 2205 | ret = -errno; |
| 2206 | else if (ret == 0) |
Glenn Kasten | 2ccd7ba | 2013-09-10 09:04:31 -0700 | [diff] [blame] | 2207 | out->written += bytes / (out->config.channels * sizeof(short)); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2208 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2209 | } |
| 2210 | |
| 2211 | exit: |
Dhanalakshmi Siddani | 4fe3e51 | 2014-05-26 18:03:42 +0530 | [diff] [blame] | 2212 | /* ToDo: There may be a corner case when SSR happens back to back during |
| 2213 | start/stop. Need to post different error to handle that. */ |
Naresh Tanniru | 2d19ab4 | 2014-05-11 19:56:25 +0530 | [diff] [blame] | 2214 | if (-ENETRESET == ret) { |
Naresh Tanniru | cef332d | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 2215 | set_snd_card_state(adev,SND_CARD_STATE_OFFLINE); |
Naresh Tanniru | 2d19ab4 | 2014-05-11 19:56:25 +0530 | [diff] [blame] | 2216 | } |
| 2217 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2218 | pthread_mutex_unlock(&out->lock); |
| 2219 | |
| 2220 | if (ret != 0) { |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 2221 | if (out->pcm) |
| 2222 | ALOGE("%s: error %d - %s", __func__, ret, pcm_get_error(out->pcm)); |
Venkata Narendra Kumar Gutta | 369dd68 | 2014-06-25 20:38:03 +0530 | [diff] [blame] | 2223 | if (out->usecase == USECASE_COMPRESS_VOIP_CALL) { |
Venkata Narendra Kumar Gutta | 593b7c1 | 2014-08-11 18:20:49 +0530 | [diff] [blame] | 2224 | pthread_mutex_lock(&adev->lock); |
Venkata Narendra Kumar Gutta | 369dd68 | 2014-06-25 20:38:03 +0530 | [diff] [blame] | 2225 | voice_extn_compress_voip_close_output_stream(&out->stream.common); |
Venkata Narendra Kumar Gutta | 593b7c1 | 2014-08-11 18:20:49 +0530 | [diff] [blame] | 2226 | pthread_mutex_unlock(&adev->lock); |
Venkata Narendra Kumar Gutta | 369dd68 | 2014-06-25 20:38:03 +0530 | [diff] [blame] | 2227 | out->standby = true; |
| 2228 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2229 | out_standby(&out->stream.common); |
Steve Kondik | 3abbbc8 | 2014-11-29 14:14:43 -0800 | [diff] [blame] | 2230 | usleep(bytes * 1000000 / audio_stream_out_frame_size(stream) / |
| 2231 | out_get_sample_rate(&out->stream.common)); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2232 | } |
| 2233 | return bytes; |
| 2234 | } |
| 2235 | |
| 2236 | static int out_get_render_position(const struct audio_stream_out *stream, |
| 2237 | uint32_t *dsp_frames) |
| 2238 | { |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2239 | struct stream_out *out = (struct stream_out *)stream; |
Subhash Chandra Bose Naripeddy | 148144e | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 2240 | if (is_offload_usecase(out->usecase) && (dsp_frames != NULL)) { |
| 2241 | ssize_t ret = 0; |
Haynes Mathew George | 9f0254a | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 2242 | *dsp_frames = 0; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2243 | pthread_mutex_lock(&out->lock); |
| 2244 | if (out->compr != NULL) { |
Naresh Tanniru | cef332d | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 2245 | ret = compress_get_tstamp(out->compr, (unsigned long *)dsp_frames, |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2246 | &out->sample_rate); |
Dhanalakshmi Siddani | 834b22f | 2014-08-20 12:28:34 +0530 | [diff] [blame] | 2247 | if (ret < 0) |
| 2248 | ret = -errno; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2249 | ALOGVV("%s rendered frames %d sample_rate %d", |
| 2250 | __func__, *dsp_frames, out->sample_rate); |
| 2251 | } |
| 2252 | pthread_mutex_unlock(&out->lock); |
Naresh Tanniru | cef332d | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 2253 | if (-ENETRESET == ret) { |
| 2254 | ALOGE(" ERROR: sound card not active Unable to get time stamp from compress driver"); |
| 2255 | set_snd_card_state(adev,SND_CARD_STATE_OFFLINE); |
| 2256 | return -EINVAL; |
| 2257 | } else if(ret < 0) { |
Steve Kondik | 8150624 | 2014-07-21 16:12:57 -0700 | [diff] [blame] | 2258 | if (out->compr == NULL) { |
| 2259 | return 0; |
| 2260 | } |
| 2261 | ALOGE(" ERROR: Unable to get time stamp from compress driver ret=%d", ret); |
Naresh Tanniru | cef332d | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 2262 | return -EINVAL; |
| 2263 | } else { |
| 2264 | return 0; |
| 2265 | } |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2266 | } else |
| 2267 | return -EINVAL; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2268 | } |
| 2269 | |
Divya Narayanan Poojary | bd9f33f | 2014-09-17 17:35:59 +0530 | [diff] [blame] | 2270 | static int out_add_audio_effect(const struct audio_stream *stream __unused, |
| 2271 | effect_handle_t effect __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2272 | { |
| 2273 | return 0; |
| 2274 | } |
| 2275 | |
Divya Narayanan Poojary | bd9f33f | 2014-09-17 17:35:59 +0530 | [diff] [blame] | 2276 | static int out_remove_audio_effect(const struct audio_stream *stream __unused, |
| 2277 | effect_handle_t effect __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2278 | { |
| 2279 | return 0; |
| 2280 | } |
| 2281 | |
Divya Narayanan Poojary | bd9f33f | 2014-09-17 17:35:59 +0530 | [diff] [blame] | 2282 | static int out_get_next_write_timestamp(const struct audio_stream_out *stream __unused, |
| 2283 | int64_t *timestamp __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2284 | { |
| 2285 | return -EINVAL; |
| 2286 | } |
| 2287 | |
Glenn Kasten | 2ccd7ba | 2013-09-10 09:04:31 -0700 | [diff] [blame] | 2288 | static int out_get_presentation_position(const struct audio_stream_out *stream, |
| 2289 | uint64_t *frames, struct timespec *timestamp) |
| 2290 | { |
| 2291 | struct stream_out *out = (struct stream_out *)stream; |
| 2292 | int ret = -1; |
Eric Laurent | 949a089 | 2013-09-20 09:20:13 -0700 | [diff] [blame] | 2293 | unsigned long dsp_frames; |
Glenn Kasten | 2ccd7ba | 2013-09-10 09:04:31 -0700 | [diff] [blame] | 2294 | |
| 2295 | pthread_mutex_lock(&out->lock); |
| 2296 | |
Subhash Chandra Bose Naripeddy | 148144e | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 2297 | if (is_offload_usecase(out->usecase)) { |
Eric Laurent | 949a089 | 2013-09-20 09:20:13 -0700 | [diff] [blame] | 2298 | if (out->compr != NULL) { |
| 2299 | compress_get_tstamp(out->compr, &dsp_frames, |
| 2300 | &out->sample_rate); |
| 2301 | ALOGVV("%s rendered frames %ld sample_rate %d", |
| 2302 | __func__, dsp_frames, out->sample_rate); |
| 2303 | *frames = dsp_frames; |
| 2304 | ret = 0; |
| 2305 | /* this is the best we can do */ |
| 2306 | clock_gettime(CLOCK_MONOTONIC, timestamp); |
| 2307 | } |
| 2308 | } else { |
| 2309 | if (out->pcm) { |
| 2310 | size_t avail; |
| 2311 | if (pcm_get_htimestamp(out->pcm, &avail, timestamp) == 0) { |
| 2312 | 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] | 2313 | int64_t signed_frames = out->written - kernel_buffer_size + avail; |
Haynes Mathew George | 7ff216f | 2013-09-11 19:51:41 -0700 | [diff] [blame] | 2314 | // This adjustment accounts for buffering after app processor. |
| 2315 | // It is based on estimated DSP latency per use case, rather than exact. |
| 2316 | signed_frames -= |
| 2317 | (platform_render_latency(out->usecase) * out->sample_rate / 1000000LL); |
| 2318 | |
Eric Laurent | 949a089 | 2013-09-20 09:20:13 -0700 | [diff] [blame] | 2319 | // It would be unusual for this value to be negative, but check just in case ... |
| 2320 | if (signed_frames >= 0) { |
| 2321 | *frames = signed_frames; |
| 2322 | ret = 0; |
| 2323 | } |
Glenn Kasten | 2ccd7ba | 2013-09-10 09:04:31 -0700 | [diff] [blame] | 2324 | } |
| 2325 | } |
| 2326 | } |
| 2327 | |
| 2328 | pthread_mutex_unlock(&out->lock); |
| 2329 | |
| 2330 | return ret; |
| 2331 | } |
| 2332 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2333 | static int out_set_callback(struct audio_stream_out *stream, |
| 2334 | stream_callback_t callback, void *cookie) |
| 2335 | { |
| 2336 | struct stream_out *out = (struct stream_out *)stream; |
| 2337 | |
| 2338 | ALOGV("%s", __func__); |
| 2339 | pthread_mutex_lock(&out->lock); |
| 2340 | out->offload_callback = callback; |
| 2341 | out->offload_cookie = cookie; |
| 2342 | pthread_mutex_unlock(&out->lock); |
| 2343 | return 0; |
| 2344 | } |
| 2345 | |
| 2346 | static int out_pause(struct audio_stream_out* stream) |
| 2347 | { |
| 2348 | struct stream_out *out = (struct stream_out *)stream; |
| 2349 | int status = -ENOSYS; |
| 2350 | ALOGV("%s", __func__); |
Subhash Chandra Bose Naripeddy | 148144e | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 2351 | if (is_offload_usecase(out->usecase)) { |
Sidipotu Ashok | 5bfacf7 | 2014-02-10 16:16:38 +0530 | [diff] [blame] | 2352 | ALOGD("copl(%x):pause compress driver", (unsigned int)out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2353 | pthread_mutex_lock(&out->lock); |
| 2354 | if (out->compr != NULL && out->offload_state == OFFLOAD_STATE_PLAYING) { |
Naresh Tanniru | cef332d | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 2355 | struct audio_device *adev = out->dev; |
| 2356 | int snd_scard_state = get_snd_card_state(adev); |
| 2357 | |
| 2358 | if (SND_CARD_STATE_ONLINE == snd_scard_state) |
| 2359 | status = compress_pause(out->compr); |
| 2360 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2361 | out->offload_state = OFFLOAD_STATE_PAUSED; |
| 2362 | } |
| 2363 | pthread_mutex_unlock(&out->lock); |
| 2364 | } |
| 2365 | return status; |
| 2366 | } |
| 2367 | |
| 2368 | static int out_resume(struct audio_stream_out* stream) |
| 2369 | { |
| 2370 | struct stream_out *out = (struct stream_out *)stream; |
| 2371 | int status = -ENOSYS; |
| 2372 | ALOGV("%s", __func__); |
Subhash Chandra Bose Naripeddy | 148144e | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 2373 | if (is_offload_usecase(out->usecase)) { |
Sidipotu Ashok | 5bfacf7 | 2014-02-10 16:16:38 +0530 | [diff] [blame] | 2374 | ALOGD("copl(%x):resume compress driver", (unsigned int)out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2375 | status = 0; |
| 2376 | pthread_mutex_lock(&out->lock); |
| 2377 | if (out->compr != NULL && out->offload_state == OFFLOAD_STATE_PAUSED) { |
Naresh Tanniru | cef332d | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 2378 | struct audio_device *adev = out->dev; |
| 2379 | int snd_scard_state = get_snd_card_state(adev); |
| 2380 | |
| 2381 | if (SND_CARD_STATE_ONLINE == snd_scard_state) |
| 2382 | status = compress_resume(out->compr); |
| 2383 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2384 | out->offload_state = OFFLOAD_STATE_PLAYING; |
| 2385 | } |
| 2386 | pthread_mutex_unlock(&out->lock); |
| 2387 | } |
| 2388 | return status; |
| 2389 | } |
| 2390 | |
| 2391 | static int out_drain(struct audio_stream_out* stream, audio_drain_type_t type ) |
| 2392 | { |
| 2393 | struct stream_out *out = (struct stream_out *)stream; |
| 2394 | int status = -ENOSYS; |
| 2395 | ALOGV("%s", __func__); |
Subhash Chandra Bose Naripeddy | 148144e | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 2396 | if (is_offload_usecase(out->usecase)) { |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2397 | pthread_mutex_lock(&out->lock); |
| 2398 | if (type == AUDIO_DRAIN_EARLY_NOTIFY) |
| 2399 | status = send_offload_cmd_l(out, OFFLOAD_CMD_PARTIAL_DRAIN); |
| 2400 | else |
| 2401 | status = send_offload_cmd_l(out, OFFLOAD_CMD_DRAIN); |
| 2402 | pthread_mutex_unlock(&out->lock); |
| 2403 | } |
| 2404 | return status; |
| 2405 | } |
| 2406 | |
| 2407 | static int out_flush(struct audio_stream_out* stream) |
| 2408 | { |
| 2409 | struct stream_out *out = (struct stream_out *)stream; |
| 2410 | ALOGV("%s", __func__); |
Subhash Chandra Bose Naripeddy | 148144e | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 2411 | if (is_offload_usecase(out->usecase)) { |
Sidipotu Ashok | 5bfacf7 | 2014-02-10 16:16:38 +0530 | [diff] [blame] | 2412 | ALOGD("copl(%x):calling compress flush", (unsigned int)out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2413 | pthread_mutex_lock(&out->lock); |
| 2414 | stop_compressed_output_l(out); |
| 2415 | pthread_mutex_unlock(&out->lock); |
Sidipotu Ashok | 5bfacf7 | 2014-02-10 16:16:38 +0530 | [diff] [blame] | 2416 | ALOGD("copl(%x):out of compress flush", (unsigned int)out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2417 | return 0; |
| 2418 | } |
| 2419 | return -ENOSYS; |
| 2420 | } |
| 2421 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2422 | /** audio_stream_in implementation **/ |
| 2423 | static uint32_t in_get_sample_rate(const struct audio_stream *stream) |
| 2424 | { |
| 2425 | struct stream_in *in = (struct stream_in *)stream; |
| 2426 | |
| 2427 | return in->config.rate; |
| 2428 | } |
| 2429 | |
Divya Narayanan Poojary | bd9f33f | 2014-09-17 17:35:59 +0530 | [diff] [blame] | 2430 | static int in_set_sample_rate(struct audio_stream *stream __unused, |
| 2431 | uint32_t rate __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2432 | { |
| 2433 | return -ENOSYS; |
| 2434 | } |
| 2435 | |
| 2436 | static size_t in_get_buffer_size(const struct audio_stream *stream) |
| 2437 | { |
| 2438 | struct stream_in *in = (struct stream_in *)stream; |
| 2439 | |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 2440 | if(in->usecase == USECASE_COMPRESS_VOIP_CALL) |
| 2441 | return voice_extn_compress_voip_in_get_buffer_size(in); |
Mingming Yin | e62d784 | 2013-10-25 16:26:03 -0700 | [diff] [blame] | 2442 | else if(audio_extn_compr_cap_usecase_supported(in->usecase)) |
| 2443 | return audio_extn_compr_cap_get_buffer_size(in->config.format); |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 2444 | |
Divya Narayanan Poojary | 69236ba | 2014-09-18 11:57:57 +0530 | [diff] [blame] | 2445 | return in->config.period_size * |
Steve Kondik | 3abbbc8 | 2014-11-29 14:14:43 -0800 | [diff] [blame] | 2446 | audio_stream_in_frame_size((const struct audio_stream_in *)stream); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2447 | } |
| 2448 | |
| 2449 | static uint32_t in_get_channels(const struct audio_stream *stream) |
| 2450 | { |
| 2451 | struct stream_in *in = (struct stream_in *)stream; |
| 2452 | |
| 2453 | return in->channel_mask; |
| 2454 | } |
| 2455 | |
| 2456 | static audio_format_t in_get_format(const struct audio_stream *stream) |
| 2457 | { |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 2458 | struct stream_in *in = (struct stream_in *)stream; |
| 2459 | |
| 2460 | return in->format; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2461 | } |
| 2462 | |
Divya Narayanan Poojary | bd9f33f | 2014-09-17 17:35:59 +0530 | [diff] [blame] | 2463 | static int in_set_format(struct audio_stream *stream __unused, |
| 2464 | audio_format_t format __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2465 | { |
| 2466 | return -ENOSYS; |
| 2467 | } |
| 2468 | |
| 2469 | static int in_standby(struct audio_stream *stream) |
| 2470 | { |
| 2471 | struct stream_in *in = (struct stream_in *)stream; |
| 2472 | struct audio_device *adev = in->dev; |
| 2473 | int status = 0; |
Sidipotu Ashok | e4514fa | 2014-05-02 16:21:50 +0530 | [diff] [blame] | 2474 | ALOGD("%s: enter: stream (%p) usecase(%d: %s)", __func__, |
| 2475 | stream, in->usecase, use_case_table[in->usecase]); |
| 2476 | |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 2477 | |
| 2478 | if (in->usecase == USECASE_COMPRESS_VOIP_CALL) { |
| 2479 | /* Ignore standby in case of voip call because the voip input |
| 2480 | * stream is closed in adev_close_input_stream() |
| 2481 | */ |
| 2482 | ALOGV("%s: Ignore Standby in VOIP call", __func__); |
| 2483 | return status; |
| 2484 | } |
| 2485 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2486 | pthread_mutex_lock(&in->lock); |
| 2487 | if (!in->standby) { |
Ravi Kumar Alamanda | 8bba9e9 | 2013-11-11 21:09:07 -0800 | [diff] [blame] | 2488 | pthread_mutex_lock(&adev->lock); |
Ethan Chen | 79c356c | 2015-06-07 12:26:14 -0700 | [diff] [blame] | 2489 | |
| 2490 | amplifier_input_stream_standby((struct audio_stream_in *) stream); |
| 2491 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2492 | in->standby = true; |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 2493 | if (in->pcm) { |
| 2494 | pcm_close(in->pcm); |
| 2495 | in->pcm = NULL; |
| 2496 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2497 | status = stop_input_stream(in); |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 2498 | pthread_mutex_unlock(&adev->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2499 | } |
| 2500 | pthread_mutex_unlock(&in->lock); |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 2501 | ALOGV("%s: exit: status(%d)", __func__, status); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2502 | return status; |
| 2503 | } |
| 2504 | |
Divya Narayanan Poojary | bd9f33f | 2014-09-17 17:35:59 +0530 | [diff] [blame] | 2505 | static int in_dump(const struct audio_stream *stream __unused, |
| 2506 | int fd __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2507 | { |
| 2508 | return 0; |
| 2509 | } |
| 2510 | |
| 2511 | static int in_set_parameters(struct audio_stream *stream, const char *kvpairs) |
| 2512 | { |
| 2513 | struct stream_in *in = (struct stream_in *)stream; |
| 2514 | struct audio_device *adev = in->dev; |
| 2515 | struct str_parms *parms; |
| 2516 | char *str; |
| 2517 | char value[32]; |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 2518 | int ret = 0, val = 0, err; |
Steve Kondik | 3abbbc8 | 2014-11-29 14:14:43 -0800 | [diff] [blame] | 2519 | int status = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2520 | |
Sidipotu Ashok | e4514fa | 2014-05-02 16:21:50 +0530 | [diff] [blame] | 2521 | ALOGD("%s: enter: kvpairs=%s", __func__, kvpairs); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2522 | parms = str_parms_create_str(kvpairs); |
| 2523 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2524 | pthread_mutex_lock(&in->lock); |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 2525 | pthread_mutex_lock(&adev->lock); |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 2526 | |
| 2527 | err = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_INPUT_SOURCE, value, sizeof(value)); |
| 2528 | if (err >= 0) { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2529 | val = atoi(value); |
| 2530 | /* no audio source uses val == 0 */ |
| 2531 | if ((in->source != val) && (val != 0)) { |
| 2532 | in->source = val; |
Narsinga Rao Chella | b0668ee | 2014-01-24 15:33:23 -0800 | [diff] [blame] | 2533 | if ((in->source == AUDIO_SOURCE_VOICE_COMMUNICATION) && |
| 2534 | (in->dev->mode == AUDIO_MODE_IN_COMMUNICATION) && |
| 2535 | (voice_extn_compress_voip_is_format_supported(in->format)) && |
| 2536 | (in->config.rate == 8000 || in->config.rate == 16000) && |
Steve Kondik | b6ab1fa | 2015-02-06 16:55:26 -0800 | [diff] [blame] | 2537 | (audio_channel_count_from_in_mask(in->channel_mask) == 1)) { |
Narsinga Rao Chella | 287b816 | 2014-02-04 16:23:52 -0800 | [diff] [blame] | 2538 | err = voice_extn_compress_voip_open_input_stream(in); |
| 2539 | if (err != 0) { |
Narsinga Rao Chella | b0668ee | 2014-01-24 15:33:23 -0800 | [diff] [blame] | 2540 | ALOGE("%s: Compress voip input cannot be opened, error:%d", |
Narsinga Rao Chella | 287b816 | 2014-02-04 16:23:52 -0800 | [diff] [blame] | 2541 | __func__, err); |
Narsinga Rao Chella | b0668ee | 2014-01-24 15:33:23 -0800 | [diff] [blame] | 2542 | } |
| 2543 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2544 | } |
| 2545 | } |
| 2546 | |
Steve Kondik | 3abbbc8 | 2014-11-29 14:14:43 -0800 | [diff] [blame] | 2547 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, value, sizeof(value)); |
| 2548 | |
| 2549 | if (ret >= 0) { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2550 | val = atoi(value); |
Divya Narayanan Poojary | ab9b1ef | 2014-09-12 15:52:36 +0530 | [diff] [blame] | 2551 | if (((int)in->device != val) && (val != 0)) { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2552 | in->device = val; |
| 2553 | /* If recording is in progress, change the tx device to new device */ |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 2554 | if (!in->standby) |
Steve Kondik | 3abbbc8 | 2014-11-29 14:14:43 -0800 | [diff] [blame] | 2555 | status = select_devices(adev, in->usecase); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2556 | } |
| 2557 | } |
| 2558 | |
Narsinga Rao Chella | b0668ee | 2014-01-24 15:33:23 -0800 | [diff] [blame] | 2559 | done: |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2560 | pthread_mutex_unlock(&adev->lock); |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 2561 | pthread_mutex_unlock(&in->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2562 | |
| 2563 | str_parms_destroy(parms); |
Steve Kondik | 3abbbc8 | 2014-11-29 14:14:43 -0800 | [diff] [blame] | 2564 | ALOGV("%s: exit: status(%d)", __func__, status); |
| 2565 | return status; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2566 | } |
| 2567 | |
| 2568 | static char* in_get_parameters(const struct audio_stream *stream, |
| 2569 | const char *keys) |
| 2570 | { |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 2571 | struct stream_in *in = (struct stream_in *)stream; |
| 2572 | struct str_parms *query = str_parms_create_str(keys); |
| 2573 | char *str; |
| 2574 | char value[256]; |
| 2575 | struct str_parms *reply = str_parms_create(); |
Haynes Mathew George | 9f0254a | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 2576 | |
| 2577 | if (!query || !reply) { |
| 2578 | ALOGE("in_get_parameters: failed to create query or reply"); |
| 2579 | return NULL; |
| 2580 | } |
| 2581 | |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 2582 | ALOGV("%s: enter: keys - %s", __func__, keys); |
| 2583 | |
| 2584 | voice_extn_in_get_parameters(in, query, reply); |
| 2585 | |
| 2586 | str = str_parms_to_str(reply); |
| 2587 | str_parms_destroy(query); |
| 2588 | str_parms_destroy(reply); |
| 2589 | |
| 2590 | ALOGV("%s: exit: returns - %s", __func__, str); |
| 2591 | return str; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2592 | } |
| 2593 | |
Divya Narayanan Poojary | bd9f33f | 2014-09-17 17:35:59 +0530 | [diff] [blame] | 2594 | static int in_set_gain(struct audio_stream_in *stream __unused, |
| 2595 | float gain __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2596 | { |
| 2597 | return 0; |
| 2598 | } |
| 2599 | |
| 2600 | static ssize_t in_read(struct audio_stream_in *stream, void *buffer, |
| 2601 | size_t bytes) |
| 2602 | { |
| 2603 | struct stream_in *in = (struct stream_in *)stream; |
| 2604 | struct audio_device *adev = in->dev; |
| 2605 | int i, ret = -1; |
Naresh Tanniru | cef332d | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 2606 | int snd_scard_state = get_snd_card_state(adev); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2607 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2608 | pthread_mutex_lock(&in->lock); |
Naresh Tanniru | 2d19ab4 | 2014-05-11 19:56:25 +0530 | [diff] [blame] | 2609 | |
| 2610 | if (in->pcm) { |
Naresh Tanniru | cef332d | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 2611 | if(SND_CARD_STATE_OFFLINE == snd_scard_state) { |
Naresh Tanniru | 2d19ab4 | 2014-05-11 19:56:25 +0530 | [diff] [blame] | 2612 | ALOGD(" %s: sound card is not active/SSR state", __func__); |
| 2613 | ret= -ENETRESET; |
| 2614 | goto exit; |
Naresh Tanniru | 2d19ab4 | 2014-05-11 19:56:25 +0530 | [diff] [blame] | 2615 | } |
| 2616 | } |
| 2617 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2618 | if (in->standby) { |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 2619 | pthread_mutex_lock(&adev->lock); |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 2620 | if (in->usecase == USECASE_COMPRESS_VOIP_CALL) |
| 2621 | ret = voice_extn_compress_voip_start_input_stream(in); |
| 2622 | else |
| 2623 | ret = start_input_stream(in); |
Ethan Chen | 79c356c | 2015-06-07 12:26:14 -0700 | [diff] [blame] | 2624 | |
| 2625 | if (ret == 0) |
| 2626 | amplifier_input_stream_start(stream); |
| 2627 | |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 2628 | pthread_mutex_unlock(&adev->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2629 | if (ret != 0) { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2630 | goto exit; |
| 2631 | } |
| 2632 | in->standby = 0; |
| 2633 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2634 | |
| 2635 | if (in->pcm) { |
Divya Narayanan Poojary | 69236ba | 2014-09-18 11:57:57 +0530 | [diff] [blame] | 2636 | if (audio_extn_ssr_get_enabled() && |
| 2637 | audio_channel_count_from_in_mask(in->channel_mask) == 6) |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 2638 | ret = audio_extn_ssr_read(stream, buffer, bytes); |
Mingming Yin | e62d784 | 2013-10-25 16:26:03 -0700 | [diff] [blame] | 2639 | else if (audio_extn_compr_cap_usecase_supported(in->usecase)) |
| 2640 | ret = audio_extn_compr_cap_read(in, buffer, bytes); |
Divya Narayanan Poojary | ab9b1ef | 2014-09-12 15:52:36 +0530 | [diff] [blame] | 2641 | else if (in->usecase == USECASE_AUDIO_RECORD_AFE_PROXY) |
| 2642 | ret = pcm_mmap_read(in->pcm, buffer, bytes); |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 2643 | else |
| 2644 | ret = pcm_read(in->pcm, buffer, bytes); |
Dhanalakshmi Siddani | 834b22f | 2014-08-20 12:28:34 +0530 | [diff] [blame] | 2645 | if (ret < 0) |
| 2646 | ret = -errno; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2647 | } |
| 2648 | |
| 2649 | /* |
| 2650 | * Instead of writing zeroes here, we could trust the hardware |
| 2651 | * to always provide zeroes when muted. |
| 2652 | */ |
Pavan Chikkala | 6c183fd | 2014-12-04 10:48:28 +0530 | [diff] [blame] | 2653 | if (ret == 0 && voice_get_mic_mute(adev) && !voice_is_in_call_rec_stream(in) && |
| 2654 | in->usecase != USECASE_AUDIO_RECORD_AFE_PROXY) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2655 | memset(buffer, 0, bytes); |
| 2656 | |
| 2657 | exit: |
Dhanalakshmi Siddani | 4fe3e51 | 2014-05-26 18:03:42 +0530 | [diff] [blame] | 2658 | /* ToDo: There may be a corner case when SSR happens back to back during |
| 2659 | start/stop. Need to post different error to handle that. */ |
Naresh Tanniru | 2d19ab4 | 2014-05-11 19:56:25 +0530 | [diff] [blame] | 2660 | if (-ENETRESET == ret) { |
Naresh Tanniru | cef332d | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 2661 | set_snd_card_state(adev,SND_CARD_STATE_OFFLINE); |
Naresh Tanniru | 2d19ab4 | 2014-05-11 19:56:25 +0530 | [diff] [blame] | 2662 | memset(buffer, 0, bytes); |
Naresh Tanniru | 2d19ab4 | 2014-05-11 19:56:25 +0530 | [diff] [blame] | 2663 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2664 | pthread_mutex_unlock(&in->lock); |
| 2665 | |
| 2666 | if (ret != 0) { |
Venkata Narendra Kumar Gutta | 369dd68 | 2014-06-25 20:38:03 +0530 | [diff] [blame] | 2667 | if (in->usecase == USECASE_COMPRESS_VOIP_CALL) { |
Venkata Narendra Kumar Gutta | 593b7c1 | 2014-08-11 18:20:49 +0530 | [diff] [blame] | 2668 | pthread_mutex_lock(&adev->lock); |
Venkata Narendra Kumar Gutta | 369dd68 | 2014-06-25 20:38:03 +0530 | [diff] [blame] | 2669 | voice_extn_compress_voip_close_input_stream(&in->stream.common); |
Venkata Narendra Kumar Gutta | 593b7c1 | 2014-08-11 18:20:49 +0530 | [diff] [blame] | 2670 | pthread_mutex_unlock(&adev->lock); |
Venkata Narendra Kumar Gutta | 369dd68 | 2014-06-25 20:38:03 +0530 | [diff] [blame] | 2671 | in->standby = true; |
| 2672 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2673 | in_standby(&in->stream.common); |
| 2674 | ALOGV("%s: read failed - sleeping for buffer duration", __func__); |
Steve Kondik | 3abbbc8 | 2014-11-29 14:14:43 -0800 | [diff] [blame] | 2675 | usleep(bytes * 1000000 / audio_stream_in_frame_size(stream) / |
| 2676 | in_get_sample_rate(&in->stream.common)); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2677 | } |
| 2678 | return bytes; |
| 2679 | } |
| 2680 | |
Divya Narayanan Poojary | bd9f33f | 2014-09-17 17:35:59 +0530 | [diff] [blame] | 2681 | 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] | 2682 | { |
| 2683 | return 0; |
| 2684 | } |
| 2685 | |
Ravi Kumar Alamanda | f70ffb4 | 2013-04-16 15:55:53 -0700 | [diff] [blame] | 2686 | static int add_remove_audio_effect(const struct audio_stream *stream, |
| 2687 | effect_handle_t effect, |
| 2688 | bool enable) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2689 | { |
Ravi Kumar Alamanda | f70ffb4 | 2013-04-16 15:55:53 -0700 | [diff] [blame] | 2690 | struct stream_in *in = (struct stream_in *)stream; |
| 2691 | int status = 0; |
| 2692 | effect_descriptor_t desc; |
| 2693 | |
| 2694 | status = (*effect)->get_descriptor(effect, &desc); |
| 2695 | if (status != 0) |
| 2696 | return status; |
| 2697 | |
| 2698 | pthread_mutex_lock(&in->lock); |
| 2699 | pthread_mutex_lock(&in->dev->lock); |
| 2700 | if ((in->source == AUDIO_SOURCE_VOICE_COMMUNICATION) && |
| 2701 | in->enable_aec != enable && |
| 2702 | (memcmp(&desc.type, FX_IID_AEC, sizeof(effect_uuid_t)) == 0)) { |
| 2703 | in->enable_aec = enable; |
| 2704 | if (!in->standby) |
| 2705 | select_devices(in->dev, in->usecase); |
| 2706 | } |
Ravi Kumar Alamanda | 198185e | 2013-11-07 15:42:19 -0800 | [diff] [blame] | 2707 | if (in->enable_ns != enable && |
| 2708 | (memcmp(&desc.type, FX_IID_NS, sizeof(effect_uuid_t)) == 0)) { |
| 2709 | in->enable_ns = enable; |
| 2710 | if (!in->standby) |
| 2711 | select_devices(in->dev, in->usecase); |
| 2712 | } |
Ravi Kumar Alamanda | f70ffb4 | 2013-04-16 15:55:53 -0700 | [diff] [blame] | 2713 | pthread_mutex_unlock(&in->dev->lock); |
| 2714 | pthread_mutex_unlock(&in->lock); |
| 2715 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2716 | return 0; |
| 2717 | } |
| 2718 | |
Ravi Kumar Alamanda | f70ffb4 | 2013-04-16 15:55:53 -0700 | [diff] [blame] | 2719 | static int in_add_audio_effect(const struct audio_stream *stream, |
| 2720 | effect_handle_t effect) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2721 | { |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 2722 | ALOGV("%s: effect %p", __func__, effect); |
Ravi Kumar Alamanda | f70ffb4 | 2013-04-16 15:55:53 -0700 | [diff] [blame] | 2723 | return add_remove_audio_effect(stream, effect, true); |
| 2724 | } |
| 2725 | |
| 2726 | static int in_remove_audio_effect(const struct audio_stream *stream, |
| 2727 | effect_handle_t effect) |
| 2728 | { |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 2729 | ALOGV("%s: effect %p", __func__, effect); |
Ravi Kumar Alamanda | f70ffb4 | 2013-04-16 15:55:53 -0700 | [diff] [blame] | 2730 | return add_remove_audio_effect(stream, effect, false); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2731 | } |
| 2732 | |
| 2733 | static int adev_open_output_stream(struct audio_hw_device *dev, |
| 2734 | audio_io_handle_t handle, |
| 2735 | audio_devices_t devices, |
| 2736 | audio_output_flags_t flags, |
| 2737 | struct audio_config *config, |
Divya Narayanan Poojary | bd9f33f | 2014-09-17 17:35:59 +0530 | [diff] [blame] | 2738 | struct audio_stream_out **stream_out, |
| 2739 | const char *address __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2740 | { |
| 2741 | struct audio_device *adev = (struct audio_device *)dev; |
| 2742 | struct stream_out *out; |
Shiv Maliyappanahalli | f930849 | 2013-12-12 12:18:09 -0800 | [diff] [blame] | 2743 | int i, ret = 0; |
Steve Kondik | 5a44701 | 2014-12-02 16:04:20 -0800 | [diff] [blame] | 2744 | int32_t sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2745 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2746 | *stream_out = NULL; |
Naresh Tanniru | cef332d | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 2747 | |
| 2748 | if ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) && |
| 2749 | (SND_CARD_STATE_OFFLINE == get_snd_card_state(adev))) { |
| 2750 | ALOGE(" sound card is not active rejecting compress output open request"); |
| 2751 | return -EINVAL; |
| 2752 | } |
| 2753 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2754 | out = (struct stream_out *)calloc(1, sizeof(struct stream_out)); |
| 2755 | |
Sidipotu Ashok | e4514fa | 2014-05-02 16:21:50 +0530 | [diff] [blame] | 2756 | ALOGD("%s: enter: sample_rate(%d) channel_mask(%#x) devices(%#x) flags(%#x)\ |
| 2757 | stream_handle(%p)",__func__, config->sample_rate, config->channel_mask, |
| 2758 | devices, flags, &out->stream); |
| 2759 | |
| 2760 | |
Haynes Mathew George | b9012ab | 2013-12-10 13:44:56 -0800 | [diff] [blame] | 2761 | if (!out) { |
| 2762 | return -ENOMEM; |
| 2763 | } |
| 2764 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2765 | if (devices == AUDIO_DEVICE_NONE) |
| 2766 | devices = AUDIO_DEVICE_OUT_SPEAKER; |
| 2767 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2768 | out->flags = flags; |
| 2769 | out->devices = devices; |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 2770 | out->dev = adev; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2771 | out->format = config->format; |
| 2772 | out->sample_rate = config->sample_rate; |
| 2773 | out->channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 2774 | out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_STEREO; |
Eric Laurent | c4aef75 | 2013-09-12 17:45:53 -0700 | [diff] [blame] | 2775 | out->handle = handle; |
ApurupaPattapu | 9d6b436 | 2014-02-27 10:24:11 -0800 | [diff] [blame] | 2776 | out->bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH; |
Alexy Joseph | 3a2fec3 | 2014-12-03 02:46:47 -0800 | [diff] [blame] | 2777 | out->non_blocking = 0; |
| 2778 | out->use_small_bufs = false; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2779 | |
| 2780 | /* Init use case and pcm_config */ |
Apoorv Raghuvanshi | 947cb90 | 2013-12-09 13:45:39 -0800 | [diff] [blame] | 2781 | if ((out->flags == AUDIO_OUTPUT_FLAG_DIRECT) && |
Mingming Yin | ee73360 | 2014-04-03 17:47:22 -0700 | [diff] [blame] | 2782 | ( |
| 2783 | #ifdef AFE_PROXY_ENABLED |
| 2784 | out->devices & AUDIO_DEVICE_OUT_PROXY || |
| 2785 | #endif |
| 2786 | out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL)) { |
Apoorv Raghuvanshi | 947cb90 | 2013-12-09 13:45:39 -0800 | [diff] [blame] | 2787 | |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 2788 | pthread_mutex_lock(&adev->lock); |
Apoorv Raghuvanshi | 947cb90 | 2013-12-09 13:45:39 -0800 | [diff] [blame] | 2789 | if (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) |
| 2790 | ret = read_hdmi_channel_masks(out); |
| 2791 | |
Mingming Yin | ee73360 | 2014-04-03 17:47:22 -0700 | [diff] [blame] | 2792 | #ifdef AFE_PROXY_ENABLED |
Apoorv Raghuvanshi | 947cb90 | 2013-12-09 13:45:39 -0800 | [diff] [blame] | 2793 | if (out->devices & AUDIO_DEVICE_OUT_PROXY) |
| 2794 | ret = audio_extn_read_afe_proxy_channel_masks(out); |
Mingming Yin | ee73360 | 2014-04-03 17:47:22 -0700 | [diff] [blame] | 2795 | #endif |
| 2796 | |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 2797 | pthread_mutex_unlock(&adev->lock); |
Eric Laurent | 07eeafd | 2013-10-06 12:52:49 -0700 | [diff] [blame] | 2798 | if (ret != 0) |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 2799 | goto error_open; |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 2800 | |
| 2801 | if (config->sample_rate == 0) |
| 2802 | config->sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; |
| 2803 | if (config->channel_mask == 0) |
| 2804 | config->channel_mask = AUDIO_CHANNEL_OUT_5POINT1; |
| 2805 | |
| 2806 | out->channel_mask = config->channel_mask; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2807 | out->sample_rate = config->sample_rate; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2808 | out->usecase = USECASE_AUDIO_PLAYBACK_MULTI_CH; |
| 2809 | out->config = pcm_config_hdmi_multi; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2810 | out->config.rate = config->sample_rate; |
Divya Narayanan Poojary | 69236ba | 2014-09-18 11:57:57 +0530 | [diff] [blame] | 2811 | 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] | 2812 | out->config.period_size = HDMI_MULTI_PERIOD_BYTES / (out->config.channels * 2); |
Mingming Yin | ee73360 | 2014-04-03 17:47:22 -0700 | [diff] [blame] | 2813 | #ifdef COMPRESS_VOIP_ENABLED |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 2814 | } else if ((out->dev->mode == AUDIO_MODE_IN_COMMUNICATION) && |
| 2815 | (out->flags == (AUDIO_OUTPUT_FLAG_DIRECT | AUDIO_OUTPUT_FLAG_VOIP_RX)) && |
Narsinga Rao Chella | 1eceff8 | 2013-12-02 19:25:28 -0800 | [diff] [blame] | 2816 | (voice_extn_compress_voip_is_config_supported(config))) { |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 2817 | ret = voice_extn_compress_voip_open_output_stream(out); |
| 2818 | if (ret != 0) { |
| 2819 | ALOGE("%s: Compress voip output cannot be opened, error:%d", |
| 2820 | __func__, ret); |
| 2821 | goto error_open; |
| 2822 | } |
Mingming Yin | ee73360 | 2014-04-03 17:47:22 -0700 | [diff] [blame] | 2823 | #endif |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2824 | } else if (out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) { |
Sidipotu Ashok | 5bfacf7 | 2014-02-10 16:16:38 +0530 | [diff] [blame] | 2825 | ALOGD("%s: copl(%x): sample_rate(%d) channel_mask(%#x) devices(%#x) flags(%#x)", |
| 2826 | __func__, (unsigned int)out, config->sample_rate, config->channel_mask, devices, flags); |
| 2827 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2828 | if (config->offload_info.version != AUDIO_INFO_INITIALIZER.version || |
| 2829 | config->offload_info.size != AUDIO_INFO_INITIALIZER.size) { |
| 2830 | ALOGE("%s: Unsupported Offload information", __func__); |
| 2831 | ret = -EINVAL; |
| 2832 | goto error_open; |
| 2833 | } |
Mingming Yin | 9031010 | 2013-11-13 16:57:00 -0800 | [diff] [blame] | 2834 | if (!is_supported_format(config->offload_info.format) && |
Subhash Chandra Bose Naripeddy | e0a0712 | 2013-12-14 00:34:53 -0800 | [diff] [blame] | 2835 | !audio_extn_is_dolby_format(config->offload_info.format)) { |
Steve Kondik | 3fdf4fc | 2014-12-10 21:15:43 -0800 | [diff] [blame] | 2836 | ALOGE("%s: Unsupported offload audio format %x", __func__, config->offload_info.format); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2837 | ret = -EINVAL; |
| 2838 | goto error_open; |
| 2839 | } |
| 2840 | |
| 2841 | out->compr_config.codec = (struct snd_codec *) |
| 2842 | calloc(1, sizeof(struct snd_codec)); |
| 2843 | |
Haynes Mathew George | 9f0254a | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 2844 | if (!out->compr_config.codec) { |
| 2845 | ret = -ENOMEM; |
| 2846 | goto error_open; |
| 2847 | } |
| 2848 | |
Subhash Chandra Bose Naripeddy | 148144e | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 2849 | out->usecase = get_offload_usecase(adev); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2850 | if (config->offload_info.channel_mask) |
| 2851 | out->channel_mask = config->offload_info.channel_mask; |
ApurupaPattapu | 0c56687 | 2014-01-10 14:46:02 -0800 | [diff] [blame] | 2852 | else if (config->channel_mask) { |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2853 | out->channel_mask = config->channel_mask; |
ApurupaPattapu | 0c56687 | 2014-01-10 14:46:02 -0800 | [diff] [blame] | 2854 | config->offload_info.channel_mask = config->channel_mask; |
| 2855 | } |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2856 | out->format = config->offload_info.format; |
| 2857 | out->sample_rate = config->offload_info.sample_rate; |
| 2858 | |
| 2859 | out->stream.set_callback = out_set_callback; |
| 2860 | out->stream.pause = out_pause; |
| 2861 | out->stream.resume = out_resume; |
| 2862 | out->stream.drain = out_drain; |
| 2863 | out->stream.flush = out_flush; |
ApurupaPattapu | 9d6b436 | 2014-02-27 10:24:11 -0800 | [diff] [blame] | 2864 | out->bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2865 | |
Subhash Chandra Bose Naripeddy | e0a0712 | 2013-12-14 00:34:53 -0800 | [diff] [blame] | 2866 | if (audio_extn_is_dolby_format(config->offload_info.format)) |
Mingming Yin | 9031010 | 2013-11-13 16:57:00 -0800 | [diff] [blame] | 2867 | out->compr_config.codec->id = |
Subhash Chandra Bose Naripeddy | e0a0712 | 2013-12-14 00:34:53 -0800 | [diff] [blame] | 2868 | audio_extn_dolby_get_snd_codec_id(adev, out, |
| 2869 | config->offload_info.format); |
Mingming Yin | 9031010 | 2013-11-13 16:57:00 -0800 | [diff] [blame] | 2870 | else |
| 2871 | out->compr_config.codec->id = |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2872 | get_snd_codec_id(config->offload_info.format); |
Steve Kondik | 3abbbc8 | 2014-11-29 14:14:43 -0800 | [diff] [blame] | 2873 | |
ApurupaPattapu | 0c56687 | 2014-01-10 14:46:02 -0800 | [diff] [blame] | 2874 | if (audio_is_offload_pcm(config->offload_info.format)) { |
| 2875 | out->compr_config.fragment_size = |
| 2876 | platform_get_pcm_offload_buffer_size(&config->offload_info); |
Steve Kondik | 3abbbc8 | 2014-11-29 14:14:43 -0800 | [diff] [blame] | 2877 | } else { |
ApurupaPattapu | 0c56687 | 2014-01-10 14:46:02 -0800 | [diff] [blame] | 2878 | out->compr_config.fragment_size = |
| 2879 | platform_get_compress_offload_buffer_size(&config->offload_info); |
| 2880 | } |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2881 | out->compr_config.fragments = COMPRESS_OFFLOAD_NUM_FRAGMENTS; |
Eric Laurent | 0043e15 | 2014-10-23 14:42:59 -0700 | [diff] [blame^] | 2882 | #ifdef NEW_SAMPLE_RATE_ENABLED |
| 2883 | out->compr_config.codec->sample_rate = config->offload_info.sample_rate; |
| 2884 | #else |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2885 | out->compr_config.codec->sample_rate = |
| 2886 | compress_get_alsa_rate(config->offload_info.sample_rate); |
Eric Laurent | 0043e15 | 2014-10-23 14:42:59 -0700 | [diff] [blame^] | 2887 | #endif |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2888 | out->compr_config.codec->bit_rate = |
| 2889 | config->offload_info.bit_rate; |
| 2890 | out->compr_config.codec->ch_in = |
Divya Narayanan Poojary | 69236ba | 2014-09-18 11:57:57 +0530 | [diff] [blame] | 2891 | audio_channel_count_from_out_mask(config->channel_mask); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2892 | out->compr_config.codec->ch_out = out->compr_config.codec->ch_in; |
ApurupaPattapu | 9d6b436 | 2014-02-27 10:24:11 -0800 | [diff] [blame] | 2893 | out->bit_width = config->offload_info.bit_width; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2894 | |
Steve Kondik | 3fdf4fc | 2014-12-10 21:15:43 -0800 | [diff] [blame] | 2895 | if ((config->offload_info.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_AAC) |
Steve Kondik | 3745401 | 2014-11-23 19:54:21 -0800 | [diff] [blame] | 2896 | out->compr_config.codec->format = SND_AUDIOSTREAMFORMAT_RAW; |
ApurupaPattapu | 0c56687 | 2014-01-10 14:46:02 -0800 | [diff] [blame] | 2897 | if (config->offload_info.format == AUDIO_FORMAT_PCM_16_BIT_OFFLOAD) |
| 2898 | out->compr_config.codec->format = SNDRV_PCM_FORMAT_S16_LE; |
ApurupaPattapu | 0c56687 | 2014-01-10 14:46:02 -0800 | [diff] [blame] | 2899 | |
Steve Kondik | 3abbbc8 | 2014-11-29 14:14:43 -0800 | [diff] [blame] | 2900 | if (config->offload_info.format == AUDIO_FORMAT_PCM_24_BIT_OFFLOAD) |
ApurupaPattapu | 9d6b436 | 2014-02-27 10:24:11 -0800 | [diff] [blame] | 2901 | out->compr_config.codec->format = SNDRV_PCM_FORMAT_S24_LE; |
ApurupaPattapu | 9d6b436 | 2014-02-27 10:24:11 -0800 | [diff] [blame] | 2902 | |
Steve Kondik | 3abbbc8 | 2014-11-29 14:14:43 -0800 | [diff] [blame] | 2903 | if (out->bit_width == 24) |
| 2904 | out->compr_config.codec->format = SNDRV_PCM_FORMAT_S24_LE; |
ApurupaPattapu | 9d6b436 | 2014-02-27 10:24:11 -0800 | [diff] [blame] | 2905 | |
Steve Kondik | 6bedcdf | 2014-07-21 11:48:30 -0700 | [diff] [blame] | 2906 | #ifdef FLAC_OFFLOAD_ENABLED |
Steve Kondik | 3745401 | 2014-11-23 19:54:21 -0800 | [diff] [blame] | 2907 | if (config->offload_info.format == AUDIO_FORMAT_FLAC) |
| 2908 | out->compr_config.codec->options.flac_dec.sample_size = config->offload_info.bit_width; |
Steve Kondik | 6bedcdf | 2014-07-21 11:48:30 -0700 | [diff] [blame] | 2909 | #endif |
ApurupaPattapu | 9d6b436 | 2014-02-27 10:24:11 -0800 | [diff] [blame] | 2910 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2911 | if (flags & AUDIO_OUTPUT_FLAG_NON_BLOCKING) |
| 2912 | out->non_blocking = 1; |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 2913 | |
Alexy Joseph | 3a2fec3 | 2014-12-03 02:46:47 -0800 | [diff] [blame] | 2914 | if (config->offload_info.use_small_bufs) { |
| 2915 | //this flag is set from framework only if its for PCM formats |
| 2916 | //no need to check for PCM format again |
| 2917 | out->non_blocking = 0; |
| 2918 | out->use_small_bufs = true; |
| 2919 | ALOGI("Keep write blocking for small buff: non_blockling %d", |
| 2920 | out->non_blocking); |
| 2921 | } |
| 2922 | |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 2923 | out->send_new_metadata = 1; |
Haynes Mathew George | b9012ab | 2013-12-10 13:44:56 -0800 | [diff] [blame] | 2924 | out->offload_state = OFFLOAD_STATE_IDLE; |
| 2925 | out->playback_started = 0; |
| 2926 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2927 | create_offload_callback_thread(out); |
| 2928 | ALOGV("%s: offloaded output offload_info version %04x bit rate %d", |
| 2929 | __func__, config->offload_info.version, |
| 2930 | config->offload_info.bit_rate); |
Krishnankutty Kolathappilly | b165a8a | 2014-01-07 11:25:51 -0800 | [diff] [blame] | 2931 | //Decide if we need to use gapless mode by default |
Krishnankutty Kolathappilly | 9d1632f | 2014-01-09 12:45:31 -0800 | [diff] [blame] | 2932 | check_and_set_gapless_mode(adev); |
Krishnankutty Kolathappilly | b165a8a | 2014-01-07 11:25:51 -0800 | [diff] [blame] | 2933 | |
Mingming Yin | ee73360 | 2014-04-03 17:47:22 -0700 | [diff] [blame] | 2934 | #ifdef INCALL_MUSIC_ENABLED |
Shiv Maliyappanahalli | f3b9a42 | 2013-10-22 16:38:08 -0700 | [diff] [blame] | 2935 | } else if (out->flags & AUDIO_OUTPUT_FLAG_INCALL_MUSIC) { |
| 2936 | ret = voice_check_and_set_incall_music_usecase(adev, out); |
| 2937 | if (ret != 0) { |
| 2938 | ALOGE("%s: Incall music delivery usecase cannot be set error:%d", |
| 2939 | __func__, ret); |
| 2940 | goto error_open; |
| 2941 | } |
Mingming Yin | ee73360 | 2014-04-03 17:47:22 -0700 | [diff] [blame] | 2942 | #endif |
Divya Narayanan Poojary | ab9b1ef | 2014-09-12 15:52:36 +0530 | [diff] [blame] | 2943 | } else if (out->devices == AUDIO_DEVICE_OUT_TELEPHONY_TX) { |
| 2944 | if (config->sample_rate == 0) |
| 2945 | config->sample_rate = AFE_PROXY_SAMPLING_RATE; |
| 2946 | if (config->sample_rate != 48000 && config->sample_rate != 16000 && |
| 2947 | config->sample_rate != 8000) { |
| 2948 | config->sample_rate = AFE_PROXY_SAMPLING_RATE; |
| 2949 | ret = -EINVAL; |
| 2950 | goto error_open; |
| 2951 | } |
| 2952 | out->sample_rate = config->sample_rate; |
| 2953 | out->config.rate = config->sample_rate; |
| 2954 | if (config->format == AUDIO_FORMAT_DEFAULT) |
| 2955 | config->format = AUDIO_FORMAT_PCM_16_BIT; |
| 2956 | if (config->format != AUDIO_FORMAT_PCM_16_BIT) { |
| 2957 | config->format = AUDIO_FORMAT_PCM_16_BIT; |
| 2958 | ret = -EINVAL; |
| 2959 | goto error_open; |
| 2960 | } |
| 2961 | out->format = config->format; |
| 2962 | out->usecase = USECASE_AUDIO_PLAYBACK_AFE_PROXY; |
| 2963 | out->config = pcm_config_afe_proxy_playback; |
| 2964 | adev->voice_tx_output = out; |
Ravi Kumar Alamanda | 8f715d9 | 2013-11-01 20:37:38 -0700 | [diff] [blame] | 2965 | } else { |
Steve Kondik | 3abbbc8 | 2014-11-29 14:14:43 -0800 | [diff] [blame] | 2966 | #ifndef LOW_LATENCY_PRIMARY |
| 2967 | if (out->flags & AUDIO_OUTPUT_FLAG_FAST) { |
| 2968 | out->usecase = USECASE_AUDIO_PLAYBACK_LOW_LATENCY; |
| 2969 | out->config = pcm_config_low_latency; |
Steve Kondik | b045f47 | 2014-11-12 23:24:07 -0800 | [diff] [blame] | 2970 | #endif |
Steve Kondik | 3abbbc8 | 2014-11-29 14:14:43 -0800 | [diff] [blame] | 2971 | #ifdef LOW_LATENCY_PRIMARY |
| 2972 | if (out->flags & AUDIO_OUTPUT_FLAG_DEEP_BUFFER) { |
| 2973 | out->usecase = USECASE_AUDIO_PLAYBACK_DEEP_BUFFER; |
| 2974 | out->config = pcm_config_deep_buffer; |
| 2975 | #endif |
| 2976 | } else { |
| 2977 | /* primary path is the default path selected if no other outputs are available/suitable */ |
| 2978 | out->usecase = USECASE_AUDIO_PLAYBACK_PRIMARY; |
| 2979 | #ifdef LOW_LATENCY_PRIMARY |
| 2980 | out->config = pcm_config_low_latency; |
| 2981 | #else |
| 2982 | out->config = pcm_config_deep_buffer; |
| 2983 | #endif |
| 2984 | } |
| 2985 | if (config->format != audio_format_from_pcm_format(out->config.format)) { |
| 2986 | if (k_enable_extended_precision |
| 2987 | && pcm_params_format_test(adev->use_case_table[out->usecase], |
| 2988 | pcm_format_from_audio_format(config->format))) { |
| 2989 | out->config.format = pcm_format_from_audio_format(config->format); |
| 2990 | /* out->format already set to config->format */ |
| 2991 | } else { |
| 2992 | /* deny the externally proposed config format |
| 2993 | * and use the one specified in audio_hw layer configuration. |
| 2994 | * Note: out->format is returned by out->stream.common.get_format() |
| 2995 | * and is used to set config->format in the code several lines below. |
| 2996 | */ |
Steve Kondik | 5a44701 | 2014-12-02 16:04:20 -0800 | [diff] [blame] | 2997 | ALOGW("Audio format %x is not available on this output", out->format); |
Steve Kondik | 3abbbc8 | 2014-11-29 14:14:43 -0800 | [diff] [blame] | 2998 | out->format = audio_format_from_pcm_format(out->config.format); |
| 2999 | } |
| 3000 | } |
| 3001 | |
Ravi Kumar Alamanda | 8f715d9 | 2013-11-01 20:37:38 -0700 | [diff] [blame] | 3002 | out->sample_rate = out->config.rate; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3003 | } |
| 3004 | |
Steve Kondik | 5a44701 | 2014-12-02 16:04:20 -0800 | [diff] [blame] | 3005 | ALOGV("%s flags %x, format %x, sample_rate %d, out->bit_width %d", |
| 3006 | __func__, flags, out->format, out->sample_rate, out->bit_width); |
| 3007 | |
Haynes Mathew George | bf14371 | 2013-12-03 13:02:53 -0800 | [diff] [blame] | 3008 | if ((out->usecase == USECASE_AUDIO_PLAYBACK_PRIMARY) || |
Steve Kondik | 3abbbc8 | 2014-11-29 14:14:43 -0800 | [diff] [blame] | 3009 | flags & AUDIO_OUTPUT_FLAG_PRIMARY) { |
Haynes Mathew George | bf14371 | 2013-12-03 13:02:53 -0800 | [diff] [blame] | 3010 | /* Ensure the default output is not selected twice */ |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 3011 | if(adev->primary_output == NULL) |
| 3012 | adev->primary_output = out; |
| 3013 | else { |
| 3014 | ALOGE("%s: Primary output is already opened", __func__); |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 3015 | ret = -EEXIST; |
| 3016 | goto error_open; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 3017 | } |
| 3018 | } |
| 3019 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3020 | /* Check if this usecase is already existing */ |
| 3021 | pthread_mutex_lock(&adev->lock); |
Narsinga Rao Chella | 0d06c8e | 2014-04-17 20:00:41 -0700 | [diff] [blame] | 3022 | if ((get_usecase_from_list(adev, out->usecase) != NULL) && |
| 3023 | (out->usecase != USECASE_COMPRESS_VOIP_CALL)) { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3024 | ALOGE("%s: Usecase (%d) is already present", __func__, out->usecase); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3025 | pthread_mutex_unlock(&adev->lock); |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 3026 | ret = -EEXIST; |
| 3027 | goto error_open; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3028 | } |
| 3029 | pthread_mutex_unlock(&adev->lock); |
| 3030 | |
| 3031 | out->stream.common.get_sample_rate = out_get_sample_rate; |
| 3032 | out->stream.common.set_sample_rate = out_set_sample_rate; |
| 3033 | out->stream.common.get_buffer_size = out_get_buffer_size; |
| 3034 | out->stream.common.get_channels = out_get_channels; |
| 3035 | out->stream.common.get_format = out_get_format; |
| 3036 | out->stream.common.set_format = out_set_format; |
| 3037 | out->stream.common.standby = out_standby; |
| 3038 | out->stream.common.dump = out_dump; |
| 3039 | out->stream.common.set_parameters = out_set_parameters; |
| 3040 | out->stream.common.get_parameters = out_get_parameters; |
| 3041 | out->stream.common.add_audio_effect = out_add_audio_effect; |
| 3042 | out->stream.common.remove_audio_effect = out_remove_audio_effect; |
| 3043 | out->stream.get_latency = out_get_latency; |
| 3044 | out->stream.set_volume = out_set_volume; |
| 3045 | out->stream.write = out_write; |
| 3046 | out->stream.get_render_position = out_get_render_position; |
| 3047 | out->stream.get_next_write_timestamp = out_get_next_write_timestamp; |
Glenn Kasten | 2ccd7ba | 2013-09-10 09:04:31 -0700 | [diff] [blame] | 3048 | out->stream.get_presentation_position = out_get_presentation_position; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3049 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3050 | out->standby = 1; |
Eric Laurent | a9024de | 2013-04-04 09:19:12 -0700 | [diff] [blame] | 3051 | /* out->muted = false; by calloc() */ |
Glenn Kasten | 2ccd7ba | 2013-09-10 09:04:31 -0700 | [diff] [blame] | 3052 | /* out->written = 0; by calloc() */ |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3053 | |
Divya Narayanan Poojary | 69236ba | 2014-09-18 11:57:57 +0530 | [diff] [blame] | 3054 | pthread_mutex_init(&out->lock, (const pthread_mutexattr_t *) NULL); |
| 3055 | pthread_cond_init(&out->cond, (const pthread_condattr_t *) NULL); |
| 3056 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3057 | config->format = out->stream.common.get_format(&out->stream.common); |
| 3058 | config->channel_mask = out->stream.common.get_channels(&out->stream.common); |
| 3059 | config->sample_rate = out->stream.common.get_sample_rate(&out->stream.common); |
| 3060 | |
| 3061 | *stream_out = &out->stream; |
Sidipotu Ashok | e4514fa | 2014-05-02 16:21:50 +0530 | [diff] [blame] | 3062 | ALOGD("%s: Stream (%p) picks up usecase (%s)", __func__, &out->stream, |
| 3063 | use_case_table[out->usecase]); |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 3064 | ALOGV("%s: exit", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3065 | return 0; |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 3066 | |
| 3067 | error_open: |
| 3068 | free(out); |
| 3069 | *stream_out = NULL; |
| 3070 | ALOGD("%s: exit: ret %d", __func__, ret); |
| 3071 | return ret; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3072 | } |
| 3073 | |
Divya Narayanan Poojary | bd9f33f | 2014-09-17 17:35:59 +0530 | [diff] [blame] | 3074 | 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] | 3075 | struct audio_stream_out *stream) |
| 3076 | { |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3077 | struct stream_out *out = (struct stream_out *)stream; |
| 3078 | struct audio_device *adev = out->dev; |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 3079 | int ret = 0; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3080 | |
Sidipotu Ashok | e4514fa | 2014-05-02 16:21:50 +0530 | [diff] [blame] | 3081 | ALOGD("%s: enter:stream_handle(%p)",__func__, out); |
| 3082 | |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 3083 | if (out->usecase == USECASE_COMPRESS_VOIP_CALL) { |
Venkata Narendra Kumar Gutta | 593b7c1 | 2014-08-11 18:20:49 +0530 | [diff] [blame] | 3084 | pthread_mutex_lock(&adev->lock); |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 3085 | ret = voice_extn_compress_voip_close_output_stream(&stream->common); |
Venkata Narendra Kumar Gutta | 593b7c1 | 2014-08-11 18:20:49 +0530 | [diff] [blame] | 3086 | pthread_mutex_unlock(&adev->lock); |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 3087 | if(ret != 0) |
| 3088 | ALOGE("%s: Compress voip output cannot be closed, error:%d", |
| 3089 | __func__, ret); |
| 3090 | } |
| 3091 | else |
| 3092 | out_standby(&stream->common); |
| 3093 | |
Subhash Chandra Bose Naripeddy | 148144e | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 3094 | if (is_offload_usecase(out->usecase)) { |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3095 | destroy_offload_callback_thread(out); |
Subhash Chandra Bose Naripeddy | 148144e | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 3096 | free_offload_usecase(adev, out->usecase); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3097 | if (out->compr_config.codec != NULL) |
| 3098 | free(out->compr_config.codec); |
| 3099 | } |
| 3100 | pthread_cond_destroy(&out->cond); |
| 3101 | pthread_mutex_destroy(&out->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3102 | free(stream); |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 3103 | ALOGV("%s: exit", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3104 | } |
| 3105 | |
Alexy Joseph | 5520435 | 2014-10-06 12:15:01 -0700 | [diff] [blame] | 3106 | static void close_compress_sessions(struct audio_device *adev) |
| 3107 | { |
| 3108 | struct stream_out *out = NULL; |
| 3109 | struct listnode *node = NULL; |
| 3110 | struct listnode *tmp = NULL; |
| 3111 | struct audio_usecase *usecase = NULL; |
| 3112 | pthread_mutex_lock(&adev->lock); |
| 3113 | list_for_each_safe(node, tmp, &adev->usecase_list) { |
| 3114 | usecase = node_to_item(node, struct audio_usecase, list); |
| 3115 | if (is_offload_usecase(usecase->id)) { |
| 3116 | if (usecase && usecase->stream.out) { |
| 3117 | ALOGI(" %s closing compress session %d on OFFLINE state", __func__, usecase->id); |
| 3118 | out = usecase->stream.out; |
| 3119 | pthread_mutex_unlock(&adev->lock); |
| 3120 | out_standby(&out->stream.common); |
| 3121 | pthread_mutex_lock(&adev->lock); |
| 3122 | } |
| 3123 | } |
| 3124 | } |
| 3125 | pthread_mutex_unlock(&adev->lock); |
| 3126 | } |
| 3127 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3128 | static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs) |
| 3129 | { |
| 3130 | struct audio_device *adev = (struct audio_device *)dev; |
| 3131 | struct str_parms *parms; |
| 3132 | char *str; |
| 3133 | char value[32]; |
Jean-Michel Trivi | c56336b | 2013-05-24 16:55:17 -0700 | [diff] [blame] | 3134 | int val; |
Divya Narayanan Poojary | 69236ba | 2014-09-18 11:57:57 +0530 | [diff] [blame] | 3135 | int ret; |
| 3136 | int status = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3137 | |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 3138 | ALOGD("%s: enter: %s", __func__, kvpairs); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3139 | parms = str_parms_create_str(kvpairs); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3140 | |
Naresh Tanniru | 2d19ab4 | 2014-05-11 19:56:25 +0530 | [diff] [blame] | 3141 | ret = str_parms_get_str(parms, "SND_CARD_STATUS", value, sizeof(value)); |
| 3142 | if (ret >= 0) { |
| 3143 | char *snd_card_status = value+2; |
Naresh Tanniru | 2d19ab4 | 2014-05-11 19:56:25 +0530 | [diff] [blame] | 3144 | if (strstr(snd_card_status, "OFFLINE")) { |
Naresh Tanniru | cef332d | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 3145 | struct listnode *node; |
| 3146 | struct audio_usecase *usecase; |
| 3147 | |
Naresh Tanniru | 2d19ab4 | 2014-05-11 19:56:25 +0530 | [diff] [blame] | 3148 | ALOGD("Received sound card OFFLINE status"); |
Naresh Tanniru | cef332d | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 3149 | set_snd_card_state(adev,SND_CARD_STATE_OFFLINE); |
| 3150 | |
Alexy Joseph | 5520435 | 2014-10-06 12:15:01 -0700 | [diff] [blame] | 3151 | //close compress sessions on OFFLINE status |
| 3152 | close_compress_sessions(adev); |
Naresh Tanniru | 2d19ab4 | 2014-05-11 19:56:25 +0530 | [diff] [blame] | 3153 | } else if (strstr(snd_card_status, "ONLINE")) { |
| 3154 | ALOGD("Received sound card ONLINE status"); |
Naresh Tanniru | cef332d | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 3155 | set_snd_card_state(adev,SND_CARD_STATE_ONLINE); |
Naresh Tanniru | 2d19ab4 | 2014-05-11 19:56:25 +0530 | [diff] [blame] | 3156 | } |
Naresh Tanniru | 2d19ab4 | 2014-05-11 19:56:25 +0530 | [diff] [blame] | 3157 | } |
| 3158 | |
| 3159 | pthread_mutex_lock(&adev->lock); |
Divya Narayanan Poojary | 69236ba | 2014-09-18 11:57:57 +0530 | [diff] [blame] | 3160 | status = voice_set_parameters(adev, parms); |
| 3161 | if (status != 0) |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 3162 | goto done; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3163 | |
Divya Narayanan Poojary | 69236ba | 2014-09-18 11:57:57 +0530 | [diff] [blame] | 3164 | status = platform_set_parameters(adev->platform, parms); |
| 3165 | if (status != 0) |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 3166 | goto done; |
| 3167 | |
Divya Narayanan Poojary | 69236ba | 2014-09-18 11:57:57 +0530 | [diff] [blame] | 3168 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_BT_NREC, value, sizeof(value)); |
| 3169 | if (ret >= 0) { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3170 | /* When set to false, HAL should disable EC and NS |
| 3171 | * But it is currently not supported. |
| 3172 | */ |
| 3173 | if (strcmp(value, AUDIO_PARAMETER_VALUE_ON) == 0) |
| 3174 | adev->bluetooth_nrec = true; |
| 3175 | else |
| 3176 | adev->bluetooth_nrec = false; |
| 3177 | } |
| 3178 | |
Divya Narayanan Poojary | 69236ba | 2014-09-18 11:57:57 +0530 | [diff] [blame] | 3179 | ret = str_parms_get_str(parms, "screen_state", value, sizeof(value)); |
| 3180 | if (ret >= 0) { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3181 | if (strcmp(value, AUDIO_PARAMETER_VALUE_ON) == 0) |
| 3182 | adev->screen_off = false; |
| 3183 | else |
| 3184 | adev->screen_off = true; |
| 3185 | } |
| 3186 | |
Divya Narayanan Poojary | 69236ba | 2014-09-18 11:57:57 +0530 | [diff] [blame] | 3187 | ret = str_parms_get_int(parms, "rotation", &val); |
| 3188 | if (ret >= 0) { |
Jean-Michel Trivi | c56336b | 2013-05-24 16:55:17 -0700 | [diff] [blame] | 3189 | bool reverse_speakers = false; |
| 3190 | switch(val) { |
| 3191 | // FIXME: note that the code below assumes that the speakers are in the correct placement |
| 3192 | // relative to the user when the device is rotated 90deg from its default rotation. This |
| 3193 | // assumption is device-specific, not platform-specific like this code. |
| 3194 | case 270: |
| 3195 | reverse_speakers = true; |
| 3196 | break; |
| 3197 | case 0: |
| 3198 | case 90: |
| 3199 | case 180: |
| 3200 | break; |
| 3201 | default: |
| 3202 | ALOGE("%s: unexpected rotation of %d", __func__, val); |
Divya Narayanan Poojary | 69236ba | 2014-09-18 11:57:57 +0530 | [diff] [blame] | 3203 | status = -EINVAL; |
Jean-Michel Trivi | c56336b | 2013-05-24 16:55:17 -0700 | [diff] [blame] | 3204 | } |
Divya Narayanan Poojary | 69236ba | 2014-09-18 11:57:57 +0530 | [diff] [blame] | 3205 | if (status == 0) { |
| 3206 | if (adev->speaker_lr_swap != reverse_speakers) { |
| 3207 | adev->speaker_lr_swap = reverse_speakers; |
| 3208 | // only update the selected device if there is active pcm playback |
| 3209 | struct audio_usecase *usecase; |
| 3210 | struct listnode *node; |
| 3211 | list_for_each(node, &adev->usecase_list) { |
| 3212 | usecase = node_to_item(node, struct audio_usecase, list); |
| 3213 | if (usecase->type == PCM_PLAYBACK) { |
Steve Kondik | 3abbbc8 | 2014-11-29 14:14:43 -0800 | [diff] [blame] | 3214 | status = select_devices(adev, usecase->id); |
Divya Narayanan Poojary | 69236ba | 2014-09-18 11:57:57 +0530 | [diff] [blame] | 3215 | break; |
| 3216 | } |
Jean-Michel Trivi | c56336b | 2013-05-24 16:55:17 -0700 | [diff] [blame] | 3217 | } |
| 3218 | } |
| 3219 | } |
Jean-Michel Trivi | c56336b | 2013-05-24 16:55:17 -0700 | [diff] [blame] | 3220 | } |
| 3221 | |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 3222 | audio_extn_set_parameters(adev, parms); |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 3223 | |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 3224 | done: |
| 3225 | str_parms_destroy(parms); |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 3226 | pthread_mutex_unlock(&adev->lock); |
Divya Narayanan Poojary | 69236ba | 2014-09-18 11:57:57 +0530 | [diff] [blame] | 3227 | ALOGV("%s: exit with code(%d)", __func__, status); |
| 3228 | return status; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3229 | } |
| 3230 | |
| 3231 | static char* adev_get_parameters(const struct audio_hw_device *dev, |
| 3232 | const char *keys) |
| 3233 | { |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 3234 | struct audio_device *adev = (struct audio_device *)dev; |
| 3235 | struct str_parms *reply = str_parms_create(); |
| 3236 | struct str_parms *query = str_parms_create_str(keys); |
| 3237 | char *str; |
Naresh Tanniru | c6ca635 | 2014-06-20 02:54:48 +0530 | [diff] [blame] | 3238 | char value[256] = {0}; |
| 3239 | int ret = 0; |
| 3240 | |
Haynes Mathew George | 9f0254a | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 3241 | if (!query || !reply) { |
| 3242 | ALOGE("adev_get_parameters: failed to create query or reply"); |
| 3243 | return NULL; |
| 3244 | } |
| 3245 | |
Naresh Tanniru | c6ca635 | 2014-06-20 02:54:48 +0530 | [diff] [blame] | 3246 | ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_SND_CARD_STATUS, value, |
| 3247 | sizeof(value)); |
| 3248 | if (ret >=0) { |
| 3249 | int val = 1; |
| 3250 | pthread_mutex_lock(&adev->snd_card_status.lock); |
| 3251 | if (SND_CARD_STATE_OFFLINE == adev->snd_card_status.state) |
| 3252 | val = 0; |
| 3253 | pthread_mutex_unlock(&adev->snd_card_status.lock); |
| 3254 | str_parms_add_int(reply, AUDIO_PARAMETER_KEY_SND_CARD_STATUS, val); |
| 3255 | goto exit; |
| 3256 | } |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 3257 | |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 3258 | pthread_mutex_lock(&adev->lock); |
Naresh Tanniru | c6ca635 | 2014-06-20 02:54:48 +0530 | [diff] [blame] | 3259 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 3260 | audio_extn_get_parameters(adev, query, reply); |
Shiv Maliyappanahalli | f930849 | 2013-12-12 12:18:09 -0800 | [diff] [blame] | 3261 | voice_get_parameters(adev, query, reply); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 3262 | platform_get_parameters(adev->platform, query, reply); |
Naresh Tanniru | cef332d | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 3263 | pthread_mutex_unlock(&adev->lock); |
| 3264 | |
Naresh Tanniru | c6ca635 | 2014-06-20 02:54:48 +0530 | [diff] [blame] | 3265 | exit: |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 3266 | str = str_parms_to_str(reply); |
| 3267 | str_parms_destroy(query); |
| 3268 | str_parms_destroy(reply); |
| 3269 | |
| 3270 | ALOGV("%s: exit: returns - %s", __func__, str); |
| 3271 | return str; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3272 | } |
| 3273 | |
Divya Narayanan Poojary | bd9f33f | 2014-09-17 17:35:59 +0530 | [diff] [blame] | 3274 | 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] | 3275 | { |
| 3276 | return 0; |
| 3277 | } |
| 3278 | |
| 3279 | static int adev_set_voice_volume(struct audio_hw_device *dev, float volume) |
| 3280 | { |
Haynes Mathew George | 5191a85 | 2013-09-11 14:19:36 -0700 | [diff] [blame] | 3281 | int ret; |
| 3282 | struct audio_device *adev = (struct audio_device *)dev; |
Eric Laurent | 321b96d | 2014-09-10 13:21:01 -0500 | [diff] [blame] | 3283 | |
| 3284 | audio_extn_extspk_set_voice_vol(adev->extspk, volume); |
| 3285 | |
Haynes Mathew George | 5191a85 | 2013-09-11 14:19:36 -0700 | [diff] [blame] | 3286 | pthread_mutex_lock(&adev->lock); |
| 3287 | /* cache volume */ |
Shruthi Krishna | ace1085 | 2013-10-25 14:32:12 -0700 | [diff] [blame] | 3288 | ret = voice_set_volume(adev, volume); |
Haynes Mathew George | 5191a85 | 2013-09-11 14:19:36 -0700 | [diff] [blame] | 3289 | pthread_mutex_unlock(&adev->lock); |
| 3290 | return ret; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3291 | } |
| 3292 | |
Divya Narayanan Poojary | bd9f33f | 2014-09-17 17:35:59 +0530 | [diff] [blame] | 3293 | static int adev_set_master_volume(struct audio_hw_device *dev __unused, |
| 3294 | float volume __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3295 | { |
| 3296 | return -ENOSYS; |
| 3297 | } |
| 3298 | |
Divya Narayanan Poojary | bd9f33f | 2014-09-17 17:35:59 +0530 | [diff] [blame] | 3299 | static int adev_get_master_volume(struct audio_hw_device *dev __unused, |
| 3300 | float *volume __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3301 | { |
| 3302 | return -ENOSYS; |
| 3303 | } |
| 3304 | |
Divya Narayanan Poojary | bd9f33f | 2014-09-17 17:35:59 +0530 | [diff] [blame] | 3305 | static int adev_set_master_mute(struct audio_hw_device *dev __unused, |
| 3306 | bool muted __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3307 | { |
| 3308 | return -ENOSYS; |
| 3309 | } |
| 3310 | |
Divya Narayanan Poojary | bd9f33f | 2014-09-17 17:35:59 +0530 | [diff] [blame] | 3311 | static int adev_get_master_mute(struct audio_hw_device *dev __unused, |
| 3312 | bool *muted __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3313 | { |
| 3314 | return -ENOSYS; |
| 3315 | } |
| 3316 | |
| 3317 | static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode) |
| 3318 | { |
| 3319 | struct audio_device *adev = (struct audio_device *)dev; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3320 | pthread_mutex_lock(&adev->lock); |
| 3321 | if (adev->mode != mode) { |
Shiv Maliyappanahalli | f3b9a42 | 2013-10-22 16:38:08 -0700 | [diff] [blame] | 3322 | ALOGD("%s mode %d\n", __func__, mode); |
Daniel Hillenbrand | 8373bc6 | 2013-05-23 10:10:00 +0530 | [diff] [blame] | 3323 | if (amplifier_set_mode(mode) != 0) |
| 3324 | ALOGE("Failed setting amplifier mode"); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3325 | adev->mode = mode; |
| 3326 | } |
| 3327 | pthread_mutex_unlock(&adev->lock); |
Eric Laurent | da46bfb | 2014-08-25 22:39:29 -0500 | [diff] [blame] | 3328 | |
| 3329 | audio_extn_extspk_set_mode(adev->extspk, mode); |
| 3330 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3331 | return 0; |
| 3332 | } |
| 3333 | |
| 3334 | static int adev_set_mic_mute(struct audio_hw_device *dev, bool state) |
| 3335 | { |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 3336 | int ret; |
| 3337 | |
| 3338 | pthread_mutex_lock(&adev->lock); |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 3339 | ALOGD("%s state %d\n", __func__, state); |
Shreyas Nagasandra Chandrasekhar | 9781c6c | 2014-12-01 05:49:35 -0800 | [diff] [blame] | 3340 | ret = voice_set_mic_mute((struct audio_device *)dev, state); |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 3341 | pthread_mutex_unlock(&adev->lock); |
| 3342 | |
| 3343 | return ret; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3344 | } |
| 3345 | |
| 3346 | static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state) |
| 3347 | { |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 3348 | *state = voice_get_mic_mute((struct audio_device *)dev); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3349 | return 0; |
| 3350 | } |
| 3351 | |
Divya Narayanan Poojary | bd9f33f | 2014-09-17 17:35:59 +0530 | [diff] [blame] | 3352 | 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] | 3353 | const struct audio_config *config) |
| 3354 | { |
Divya Narayanan Poojary | 69236ba | 2014-09-18 11:57:57 +0530 | [diff] [blame] | 3355 | 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] | 3356 | |
Ravi Kumar Alamanda | 1c3de5e | 2014-09-08 15:59:58 -0700 | [diff] [blame] | 3357 | return get_input_buffer_size(config->sample_rate, config->format, channel_count, |
| 3358 | false /* is_low_latency: since we don't know, be conservative */); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3359 | } |
| 3360 | |
| 3361 | static int adev_open_input_stream(struct audio_hw_device *dev, |
Divya Narayanan Poojary | bd9f33f | 2014-09-17 17:35:59 +0530 | [diff] [blame] | 3362 | audio_io_handle_t handle __unused, |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3363 | audio_devices_t devices, |
| 3364 | struct audio_config *config, |
Divya Narayanan Poojary | bd9f33f | 2014-09-17 17:35:59 +0530 | [diff] [blame] | 3365 | struct audio_stream_in **stream_in, |
| 3366 | audio_input_flags_t flags __unused, |
| 3367 | const char *address __unused, |
Vidyakumar Athota | 7e6ba2e | 2015-03-31 21:53:21 -0700 | [diff] [blame] | 3368 | audio_source_t source) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3369 | { |
| 3370 | struct audio_device *adev = (struct audio_device *)dev; |
| 3371 | struct stream_in *in; |
Ravi Kumar Alamanda | fae4211 | 2013-11-07 23:31:54 -0800 | [diff] [blame] | 3372 | int ret = 0, buffer_size, frame_size; |
Divya Narayanan Poojary | 69236ba | 2014-09-18 11:57:57 +0530 | [diff] [blame] | 3373 | int channel_count = audio_channel_count_from_in_mask(config->channel_mask); |
Ravi Kumar Alamanda | 1c3de5e | 2014-09-08 15:59:58 -0700 | [diff] [blame] | 3374 | bool is_low_latency = false; |
Sidipotu Ashok | e4514fa | 2014-05-02 16:21:50 +0530 | [diff] [blame] | 3375 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3376 | *stream_in = NULL; |
| 3377 | if (check_input_parameters(config->sample_rate, config->format, channel_count) != 0) |
| 3378 | return -EINVAL; |
| 3379 | |
| 3380 | in = (struct stream_in *)calloc(1, sizeof(struct stream_in)); |
Haynes Mathew George | 9f0254a | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 3381 | |
| 3382 | if (!in) { |
| 3383 | ALOGE("failed to allocate input stream"); |
| 3384 | return -ENOMEM; |
| 3385 | } |
| 3386 | |
Sidipotu Ashok | e4514fa | 2014-05-02 16:21:50 +0530 | [diff] [blame] | 3387 | ALOGD("%s: enter: sample_rate(%d) channel_mask(%#x) devices(%#x)\ |
Vidyakumar Athota | 7e6ba2e | 2015-03-31 21:53:21 -0700 | [diff] [blame] | 3388 | stream_handle(%p) io_handle(%d) source(%d)",__func__, config->sample_rate, config->channel_mask, |
| 3389 | devices, &in->stream, handle, source); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3390 | |
Ravi Kumar Alamanda | 33de814 | 2014-04-24 10:34:41 -0700 | [diff] [blame] | 3391 | pthread_mutex_init(&in->lock, (const pthread_mutexattr_t *) NULL); |
| 3392 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3393 | in->stream.common.get_sample_rate = in_get_sample_rate; |
| 3394 | in->stream.common.set_sample_rate = in_set_sample_rate; |
| 3395 | in->stream.common.get_buffer_size = in_get_buffer_size; |
| 3396 | in->stream.common.get_channels = in_get_channels; |
| 3397 | in->stream.common.get_format = in_get_format; |
| 3398 | in->stream.common.set_format = in_set_format; |
| 3399 | in->stream.common.standby = in_standby; |
| 3400 | in->stream.common.dump = in_dump; |
| 3401 | in->stream.common.set_parameters = in_set_parameters; |
| 3402 | in->stream.common.get_parameters = in_get_parameters; |
| 3403 | in->stream.common.add_audio_effect = in_add_audio_effect; |
| 3404 | in->stream.common.remove_audio_effect = in_remove_audio_effect; |
| 3405 | in->stream.set_gain = in_set_gain; |
| 3406 | in->stream.read = in_read; |
| 3407 | in->stream.get_input_frames_lost = in_get_input_frames_lost; |
| 3408 | |
| 3409 | in->device = devices; |
Vidyakumar Athota | 7e6ba2e | 2015-03-31 21:53:21 -0700 | [diff] [blame] | 3410 | in->source = source; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3411 | in->dev = adev; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3412 | in->standby = 1; |
| 3413 | in->channel_mask = config->channel_mask; |
| 3414 | |
| 3415 | /* Update config params with the requested sample rate and channels */ |
| 3416 | in->usecase = USECASE_AUDIO_RECORD; |
Ravi Kumar Alamanda | 1c3de5e | 2014-09-08 15:59:58 -0700 | [diff] [blame] | 3417 | if (config->sample_rate == LOW_LATENCY_CAPTURE_SAMPLE_RATE && |
| 3418 | (flags & AUDIO_INPUT_FLAG_FAST) != 0) { |
| 3419 | is_low_latency = true; |
| 3420 | #if LOW_LATENCY_CAPTURE_USE_CASE |
| 3421 | in->usecase = USECASE_AUDIO_RECORD_LOW_LATENCY; |
| 3422 | #endif |
| 3423 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3424 | in->config = pcm_config_audio_capture; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3425 | in->config.rate = config->sample_rate; |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 3426 | in->format = config->format; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3427 | |
Divya Narayanan Poojary | ab9b1ef | 2014-09-12 15:52:36 +0530 | [diff] [blame] | 3428 | if (in->device == AUDIO_DEVICE_IN_TELEPHONY_RX) { |
Pavan Chikkala | 3c0036d | 2014-12-17 16:45:10 +0530 | [diff] [blame] | 3429 | if (adev->mode != AUDIO_MODE_IN_CALL) { |
| 3430 | ret = -EINVAL; |
| 3431 | goto err_open; |
Pavan Chikkala | 3ec42ef | 2014-11-21 20:57:48 +0530 | [diff] [blame] | 3432 | } |
Divya Narayanan Poojary | ab9b1ef | 2014-09-12 15:52:36 +0530 | [diff] [blame] | 3433 | if (config->sample_rate == 0) |
| 3434 | config->sample_rate = AFE_PROXY_SAMPLING_RATE; |
| 3435 | if (config->sample_rate != 48000 && config->sample_rate != 16000 && |
| 3436 | config->sample_rate != 8000) { |
| 3437 | config->sample_rate = AFE_PROXY_SAMPLING_RATE; |
| 3438 | ret = -EINVAL; |
| 3439 | goto err_open; |
| 3440 | } |
| 3441 | if (config->format == AUDIO_FORMAT_DEFAULT) |
| 3442 | config->format = AUDIO_FORMAT_PCM_16_BIT; |
| 3443 | if (config->format != AUDIO_FORMAT_PCM_16_BIT) { |
| 3444 | config->format = AUDIO_FORMAT_PCM_16_BIT; |
| 3445 | ret = -EINVAL; |
| 3446 | goto err_open; |
| 3447 | } |
| 3448 | in->usecase = USECASE_AUDIO_RECORD_AFE_PROXY; |
| 3449 | in->config = pcm_config_afe_proxy_record; |
| 3450 | in->config.channels = channel_count; |
| 3451 | in->config.rate = config->sample_rate; |
| 3452 | } else if (channel_count == 6) { |
Ravi Kumar Alamanda | fae4211 | 2013-11-07 23:31:54 -0800 | [diff] [blame] | 3453 | if(audio_extn_ssr_get_enabled()) { |
Divya Narayanan Poojary | bd9f33f | 2014-09-17 17:35:59 +0530 | [diff] [blame] | 3454 | if(audio_extn_ssr_init(in)) { |
Ravi Kumar Alamanda | fae4211 | 2013-11-07 23:31:54 -0800 | [diff] [blame] | 3455 | ALOGE("%s: audio_extn_ssr_init failed", __func__); |
| 3456 | ret = -EINVAL; |
| 3457 | goto err_open; |
| 3458 | } |
| 3459 | } else { |
Mingming Yin | daf9c54 | 2014-09-16 17:41:33 -0700 | [diff] [blame] | 3460 | ALOGW("%s: surround sound recording is not supported", __func__); |
Ravi Kumar Alamanda | fae4211 | 2013-11-07 23:31:54 -0800 | [diff] [blame] | 3461 | } |
Mingming Yin | e62d784 | 2013-10-25 16:26:03 -0700 | [diff] [blame] | 3462 | } else if (audio_extn_compr_cap_enabled() && |
Narsinga Rao Chella | b0668ee | 2014-01-24 15:33:23 -0800 | [diff] [blame] | 3463 | audio_extn_compr_cap_format_supported(config->format) && |
| 3464 | (in->dev->mode != AUDIO_MODE_IN_COMMUNICATION)) { |
Divya Narayanan Poojary | bd9f33f | 2014-09-17 17:35:59 +0530 | [diff] [blame] | 3465 | audio_extn_compr_cap_init(in); |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 3466 | } else { |
| 3467 | in->config.channels = channel_count; |
Divya Narayanan Poojary | 69236ba | 2014-09-18 11:57:57 +0530 | [diff] [blame] | 3468 | frame_size = audio_stream_in_frame_size(&in->stream); |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 3469 | buffer_size = get_input_buffer_size(config->sample_rate, |
| 3470 | config->format, |
Ravi Kumar Alamanda | 1c3de5e | 2014-09-08 15:59:58 -0700 | [diff] [blame] | 3471 | channel_count, |
| 3472 | is_low_latency); |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 3473 | in->config.period_size = buffer_size / frame_size; |
Vidyakumar Athota | 7e6ba2e | 2015-03-31 21:53:21 -0700 | [diff] [blame] | 3474 | if ((in->source == AUDIO_SOURCE_VOICE_COMMUNICATION) && |
| 3475 | (in->dev->mode == AUDIO_MODE_IN_COMMUNICATION) && |
| 3476 | (voice_extn_compress_voip_is_format_supported(in->format)) && |
| 3477 | (in->config.rate == 8000 || in->config.rate == 16000) && |
| 3478 | (audio_channel_count_from_in_mask(in->channel_mask) == 1)) { |
| 3479 | voice_extn_compress_voip_open_input_stream(in); |
| 3480 | } |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 3481 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3482 | |
| 3483 | *stream_in = &in->stream; |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 3484 | ALOGV("%s: exit", __func__); |
Ravi Kumar Alamanda | fae4211 | 2013-11-07 23:31:54 -0800 | [diff] [blame] | 3485 | return ret; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3486 | |
| 3487 | err_open: |
| 3488 | free(in); |
| 3489 | *stream_in = NULL; |
| 3490 | return ret; |
| 3491 | } |
| 3492 | |
Divya Narayanan Poojary | bd9f33f | 2014-09-17 17:35:59 +0530 | [diff] [blame] | 3493 | 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] | 3494 | struct audio_stream_in *stream) |
| 3495 | { |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 3496 | int ret; |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 3497 | struct stream_in *in = (struct stream_in *)stream; |
Venkata Narendra Kumar Gutta | 593b7c1 | 2014-08-11 18:20:49 +0530 | [diff] [blame] | 3498 | struct audio_device *adev = in->dev; |
| 3499 | |
Sidipotu Ashok | e4514fa | 2014-05-02 16:21:50 +0530 | [diff] [blame] | 3500 | ALOGD("%s: enter:stream_handle(%p)",__func__, in); |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 3501 | |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 3502 | if (in->usecase == USECASE_COMPRESS_VOIP_CALL) { |
Venkata Narendra Kumar Gutta | 593b7c1 | 2014-08-11 18:20:49 +0530 | [diff] [blame] | 3503 | pthread_mutex_lock(&adev->lock); |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 3504 | ret = voice_extn_compress_voip_close_input_stream(&stream->common); |
Venkata Narendra Kumar Gutta | 593b7c1 | 2014-08-11 18:20:49 +0530 | [diff] [blame] | 3505 | pthread_mutex_unlock(&adev->lock); |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 3506 | if (ret != 0) |
| 3507 | ALOGE("%s: Compress voip input cannot be closed, error:%d", |
| 3508 | __func__, ret); |
| 3509 | } else |
| 3510 | in_standby(&stream->common); |
| 3511 | |
Divya Narayanan Poojary | 69236ba | 2014-09-18 11:57:57 +0530 | [diff] [blame] | 3512 | if (audio_extn_ssr_get_enabled() && |
| 3513 | (audio_channel_count_from_in_mask(in->channel_mask) == 6)) { |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 3514 | audio_extn_ssr_deinit(); |
| 3515 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3516 | free(stream); |
| 3517 | |
Mingming Yin | e62d784 | 2013-10-25 16:26:03 -0700 | [diff] [blame] | 3518 | if(audio_extn_compr_cap_enabled() && |
| 3519 | audio_extn_compr_cap_format_supported(in->config.format)) |
| 3520 | audio_extn_compr_cap_deinit(); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3521 | return; |
| 3522 | } |
| 3523 | |
Divya Narayanan Poojary | bd9f33f | 2014-09-17 17:35:59 +0530 | [diff] [blame] | 3524 | static int adev_dump(const audio_hw_device_t *device __unused, |
| 3525 | int fd __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3526 | { |
| 3527 | return 0; |
| 3528 | } |
| 3529 | |
Steve Kondik | 3abbbc8 | 2014-11-29 14:14:43 -0800 | [diff] [blame] | 3530 | /* verifies input and output devices and their capabilities. |
| 3531 | * |
| 3532 | * This verification is required when enabling extended bit-depth or |
| 3533 | * sampling rates, as not all qcom products support it. |
| 3534 | * |
| 3535 | * Suitable for calling only on initialization such as adev_open(). |
| 3536 | * It fills the audio_device use_case_table[] array. |
| 3537 | * |
| 3538 | * Has a side-effect that it needs to configure audio routing / devices |
| 3539 | * in order to power up the devices and read the device parameters. |
| 3540 | * It does not acquire any hw device lock. Should restore the devices |
| 3541 | * back to "normal state" upon completion. |
| 3542 | */ |
| 3543 | static int adev_verify_devices(struct audio_device *adev) |
| 3544 | { |
| 3545 | /* enumeration is a bit difficult because one really wants to pull |
| 3546 | * the use_case, device id, etc from the hidden pcm_device_table[]. |
| 3547 | * In this case there are the following use cases and device ids. |
| 3548 | * |
| 3549 | * [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {0, 0}, |
| 3550 | * [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {15, 15}, |
| 3551 | * [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {1, 1}, |
| 3552 | * [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {9, 9}, |
| 3553 | * [USECASE_AUDIO_RECORD] = {0, 0}, |
| 3554 | * [USECASE_AUDIO_RECORD_LOW_LATENCY] = {15, 15}, |
| 3555 | * [USECASE_VOICE_CALL] = {2, 2}, |
| 3556 | * |
| 3557 | * USECASE_AUDIO_PLAYBACK_OFFLOAD, USECASE_AUDIO_PLAYBACK_MULTI_CH omitted. |
| 3558 | * USECASE_VOICE_CALL omitted, but possible for either input or output. |
| 3559 | */ |
| 3560 | |
| 3561 | /* should be the usecases enabled in adev_open_input_stream() */ |
| 3562 | static const int test_in_usecases[] = { |
| 3563 | USECASE_AUDIO_RECORD, |
| 3564 | USECASE_AUDIO_RECORD_LOW_LATENCY, /* does not appear to be used */ |
| 3565 | }; |
| 3566 | /* should be the usecases enabled in adev_open_output_stream()*/ |
| 3567 | static const int test_out_usecases[] = { |
| 3568 | USECASE_AUDIO_PLAYBACK_DEEP_BUFFER, |
| 3569 | USECASE_AUDIO_PLAYBACK_LOW_LATENCY, |
| 3570 | }; |
| 3571 | static const usecase_type_t usecase_type_by_dir[] = { |
| 3572 | PCM_PLAYBACK, |
| 3573 | PCM_CAPTURE, |
| 3574 | }; |
| 3575 | static const unsigned flags_by_dir[] = { |
| 3576 | PCM_OUT, |
| 3577 | PCM_IN, |
| 3578 | }; |
| 3579 | |
| 3580 | size_t i; |
| 3581 | unsigned dir; |
| 3582 | const unsigned card_id = adev->snd_card; |
| 3583 | char info[512]; /* for possible debug info */ |
| 3584 | |
| 3585 | for (dir = 0; dir < 2; ++dir) { |
| 3586 | const usecase_type_t usecase_type = usecase_type_by_dir[dir]; |
| 3587 | const unsigned flags_dir = flags_by_dir[dir]; |
| 3588 | const size_t testsize = |
| 3589 | dir ? ARRAY_SIZE(test_in_usecases) : ARRAY_SIZE(test_out_usecases); |
| 3590 | const int *testcases = |
| 3591 | dir ? test_in_usecases : test_out_usecases; |
| 3592 | const audio_devices_t audio_device = |
| 3593 | dir ? AUDIO_DEVICE_IN_BUILTIN_MIC : AUDIO_DEVICE_OUT_SPEAKER; |
| 3594 | |
| 3595 | for (i = 0; i < testsize; ++i) { |
| 3596 | const audio_usecase_t audio_usecase = testcases[i]; |
| 3597 | int device_id; |
| 3598 | snd_device_t snd_device; |
| 3599 | struct pcm_params **pparams; |
| 3600 | struct stream_out out; |
| 3601 | struct stream_in in; |
| 3602 | struct audio_usecase uc_info; |
| 3603 | int retval; |
| 3604 | |
| 3605 | pparams = &adev->use_case_table[audio_usecase]; |
| 3606 | pcm_params_free(*pparams); /* can accept null input */ |
| 3607 | *pparams = NULL; |
| 3608 | |
| 3609 | /* find the device ID for the use case (signed, for error) */ |
| 3610 | device_id = platform_get_pcm_device_id(audio_usecase, usecase_type); |
| 3611 | if (device_id < 0) |
| 3612 | continue; |
| 3613 | |
| 3614 | /* prepare structures for device probing */ |
| 3615 | memset(&uc_info, 0, sizeof(uc_info)); |
| 3616 | uc_info.id = audio_usecase; |
| 3617 | uc_info.type = usecase_type; |
| 3618 | if (dir) { |
| 3619 | adev->active_input = ∈ |
| 3620 | memset(&in, 0, sizeof(in)); |
| 3621 | in.device = audio_device; |
| 3622 | in.source = AUDIO_SOURCE_VOICE_COMMUNICATION; |
| 3623 | uc_info.stream.in = ∈ |
| 3624 | } else { |
| 3625 | adev->active_input = NULL; |
| 3626 | } |
| 3627 | memset(&out, 0, sizeof(out)); |
| 3628 | out.devices = audio_device; /* only field needed in select_devices */ |
| 3629 | uc_info.stream.out = &out; |
| 3630 | uc_info.devices = audio_device; |
| 3631 | uc_info.in_snd_device = SND_DEVICE_NONE; |
| 3632 | uc_info.out_snd_device = SND_DEVICE_NONE; |
| 3633 | list_add_tail(&adev->usecase_list, &uc_info.list); |
| 3634 | |
| 3635 | /* select device - similar to start_(in/out)put_stream() */ |
| 3636 | retval = select_devices(adev, audio_usecase); |
| 3637 | if (retval >= 0) { |
| 3638 | *pparams = pcm_params_get(card_id, device_id, flags_dir); |
| 3639 | #if LOG_NDEBUG == 0 |
| 3640 | if (*pparams) { |
| 3641 | ALOGV("%s: (%s) card %d device %d", __func__, |
| 3642 | dir ? "input" : "output", card_id, device_id); |
| 3643 | pcm_params_to_string(*pparams, info, ARRAY_SIZE(info)); |
| 3644 | ALOGV(info); /* print parameters */ |
| 3645 | } else { |
| 3646 | ALOGV("%s: cannot locate card %d device %d", __func__, card_id, device_id); |
| 3647 | } |
| 3648 | #endif |
| 3649 | } |
| 3650 | |
| 3651 | /* deselect device - similar to stop_(in/out)put_stream() */ |
| 3652 | /* 1. Get and set stream specific mixer controls */ |
| 3653 | retval = disable_audio_route(adev, &uc_info); |
| 3654 | /* 2. Disable the rx device */ |
| 3655 | retval = disable_snd_device(adev, |
| 3656 | dir ? uc_info.in_snd_device : uc_info.out_snd_device); |
| 3657 | list_remove(&uc_info.list); |
| 3658 | } |
| 3659 | } |
| 3660 | adev->active_input = NULL; /* restore adev state */ |
| 3661 | return 0; |
| 3662 | } |
| 3663 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3664 | static int adev_close(hw_device_t *device) |
| 3665 | { |
Steve Kondik | 3abbbc8 | 2014-11-29 14:14:43 -0800 | [diff] [blame] | 3666 | size_t i; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3667 | struct audio_device *adev = (struct audio_device *)device; |
Kiran Kandi | 910e186 | 2013-10-29 13:29:42 -0700 | [diff] [blame] | 3668 | |
| 3669 | if (!adev) |
| 3670 | return 0; |
| 3671 | |
| 3672 | pthread_mutex_lock(&adev_init_lock); |
| 3673 | |
| 3674 | if ((--audio_device_ref_count) == 0) { |
Daniel Hillenbrand | 8373bc6 | 2013-05-23 10:10:00 +0530 | [diff] [blame] | 3675 | if (amplifier_close() != 0) |
| 3676 | ALOGE("Amplifier close failed"); |
Kiran Kandi | de144c8 | 2013-11-20 15:58:32 -0800 | [diff] [blame] | 3677 | audio_extn_listen_deinit(adev); |
Kiran Kandi | 910e186 | 2013-10-29 13:29:42 -0700 | [diff] [blame] | 3678 | audio_route_free(adev->audio_route); |
| 3679 | free(adev->snd_dev_ref_cnt); |
| 3680 | platform_deinit(adev->platform); |
Eric Laurent | da46bfb | 2014-08-25 22:39:29 -0500 | [diff] [blame] | 3681 | audio_extn_extspk_deinit(adev->extspk); |
Steve Kondik | 3abbbc8 | 2014-11-29 14:14:43 -0800 | [diff] [blame] | 3682 | for (i = 0; i < ARRAY_SIZE(adev->use_case_table); ++i) { |
| 3683 | pcm_params_free(adev->use_case_table[i]); |
| 3684 | } |
Kiran Kandi | 910e186 | 2013-10-29 13:29:42 -0700 | [diff] [blame] | 3685 | free(device); |
| 3686 | adev = NULL; |
| 3687 | } |
| 3688 | pthread_mutex_unlock(&adev_init_lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3689 | return 0; |
| 3690 | } |
| 3691 | |
Ravi Kumar Alamanda | 1c3de5e | 2014-09-08 15:59:58 -0700 | [diff] [blame] | 3692 | /* This returns 1 if the input parameter looks at all plausible as a low latency period size, |
| 3693 | * or 0 otherwise. A return value of 1 doesn't mean the value is guaranteed to work, |
| 3694 | * just that it _might_ work. |
| 3695 | */ |
| 3696 | static int period_size_is_plausible_for_low_latency(int period_size) |
| 3697 | { |
| 3698 | switch (period_size) { |
| 3699 | case 160: |
| 3700 | case 240: |
| 3701 | case 320: |
| 3702 | case 480: |
| 3703 | return 1; |
| 3704 | default: |
| 3705 | return 0; |
| 3706 | } |
| 3707 | } |
| 3708 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3709 | static int adev_open(const hw_module_t *module, const char *name, |
| 3710 | hw_device_t **device) |
| 3711 | { |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 3712 | int i, ret; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3713 | |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 3714 | ALOGD("%s: enter", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3715 | if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) return -EINVAL; |
| 3716 | |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 3717 | pthread_mutex_lock(&adev_init_lock); |
Kiran Kandi | 910e186 | 2013-10-29 13:29:42 -0700 | [diff] [blame] | 3718 | if (audio_device_ref_count != 0){ |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 3719 | *device = &adev->device.common; |
Kiran Kandi | 910e186 | 2013-10-29 13:29:42 -0700 | [diff] [blame] | 3720 | audio_device_ref_count++; |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 3721 | ALOGD("%s: returning existing instance of adev", __func__); |
| 3722 | ALOGD("%s: exit", __func__); |
| 3723 | pthread_mutex_unlock(&adev_init_lock); |
| 3724 | return 0; |
| 3725 | } |
| 3726 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3727 | adev = calloc(1, sizeof(struct audio_device)); |
| 3728 | |
Haynes Mathew George | 9f0254a | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 3729 | if (!adev) { |
| 3730 | pthread_mutex_unlock(&adev_init_lock); |
| 3731 | return -ENOMEM; |
| 3732 | } |
| 3733 | |
Ravi Kumar Alamanda | 33de814 | 2014-04-24 10:34:41 -0700 | [diff] [blame] | 3734 | pthread_mutex_init(&adev->lock, (const pthread_mutexattr_t *) NULL); |
| 3735 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3736 | adev->device.common.tag = HARDWARE_DEVICE_TAG; |
| 3737 | adev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0; |
| 3738 | adev->device.common.module = (struct hw_module_t *)module; |
| 3739 | adev->device.common.close = adev_close; |
| 3740 | |
| 3741 | adev->device.init_check = adev_init_check; |
| 3742 | adev->device.set_voice_volume = adev_set_voice_volume; |
| 3743 | adev->device.set_master_volume = adev_set_master_volume; |
| 3744 | adev->device.get_master_volume = adev_get_master_volume; |
| 3745 | adev->device.set_master_mute = adev_set_master_mute; |
| 3746 | adev->device.get_master_mute = adev_get_master_mute; |
| 3747 | adev->device.set_mode = adev_set_mode; |
| 3748 | adev->device.set_mic_mute = adev_set_mic_mute; |
| 3749 | adev->device.get_mic_mute = adev_get_mic_mute; |
| 3750 | adev->device.set_parameters = adev_set_parameters; |
| 3751 | adev->device.get_parameters = adev_get_parameters; |
| 3752 | adev->device.get_input_buffer_size = adev_get_input_buffer_size; |
| 3753 | adev->device.open_output_stream = adev_open_output_stream; |
| 3754 | adev->device.close_output_stream = adev_close_output_stream; |
| 3755 | adev->device.open_input_stream = adev_open_input_stream; |
| 3756 | adev->device.close_input_stream = adev_close_input_stream; |
| 3757 | adev->device.dump = adev_dump; |
| 3758 | |
| 3759 | /* Set the default route before the PCM stream is opened */ |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3760 | adev->mode = AUDIO_MODE_NORMAL; |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 3761 | adev->active_input = NULL; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 3762 | adev->primary_output = NULL; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3763 | adev->out_device = AUDIO_DEVICE_NONE; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3764 | adev->bluetooth_nrec = true; |
Ravi Kumar Alamanda | f996704 | 2013-02-14 19:35:14 -0800 | [diff] [blame] | 3765 | adev->acdb_settings = TTY_MODE_OFF; |
Eric Laurent | 07eeafd | 2013-10-06 12:52:49 -0700 | [diff] [blame] | 3766 | /* adev->cur_hdmi_channels = 0; by calloc() */ |
ApurupaPattapu | 9d6b436 | 2014-02-27 10:24:11 -0800 | [diff] [blame] | 3767 | adev->cur_codec_backend_samplerate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
| 3768 | adev->cur_codec_backend_bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 3769 | adev->snd_dev_ref_cnt = calloc(SND_DEVICE_MAX, sizeof(int)); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 3770 | voice_init(adev); |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 3771 | list_init(&adev->usecase_list); |
Krishnankutty Kolathappilly | 9b7e96b | 2014-02-14 14:45:49 -0800 | [diff] [blame] | 3772 | adev->cur_wfd_channels = 2; |
Subhash Chandra Bose Naripeddy | 148144e | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 3773 | adev->offload_usecases_state = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3774 | |
Naresh Tanniru | 2d19ab4 | 2014-05-11 19:56:25 +0530 | [diff] [blame] | 3775 | pthread_mutex_init(&adev->snd_card_status.lock, (const pthread_mutexattr_t *) NULL); |
| 3776 | adev->snd_card_status.state = SND_CARD_STATE_OFFLINE; |
| 3777 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3778 | /* Loads platform specific libraries dynamically */ |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 3779 | adev->platform = platform_init(adev); |
| 3780 | if (!adev->platform) { |
| 3781 | free(adev->snd_dev_ref_cnt); |
| 3782 | free(adev); |
| 3783 | ALOGE("%s: Failed to init platform data, aborting.", __func__); |
| 3784 | *device = NULL; |
Apoorv Raghuvanshi | 6e57d7e | 2013-12-16 16:02:45 -0800 | [diff] [blame] | 3785 | pthread_mutex_unlock(&adev_init_lock); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 3786 | return -EINVAL; |
| 3787 | } |
Eric Laurent | c4aef75 | 2013-09-12 17:45:53 -0700 | [diff] [blame] | 3788 | |
Naresh Tanniru | 2d19ab4 | 2014-05-11 19:56:25 +0530 | [diff] [blame] | 3789 | adev->snd_card_status.state = SND_CARD_STATE_ONLINE; |
Eric Laurent | da46bfb | 2014-08-25 22:39:29 -0500 | [diff] [blame] | 3790 | adev->extspk = audio_extn_extspk_init(adev); |
Naresh Tanniru | 2d19ab4 | 2014-05-11 19:56:25 +0530 | [diff] [blame] | 3791 | |
Eric Laurent | c4aef75 | 2013-09-12 17:45:53 -0700 | [diff] [blame] | 3792 | if (access(VISUALIZER_LIBRARY_PATH, R_OK) == 0) { |
| 3793 | adev->visualizer_lib = dlopen(VISUALIZER_LIBRARY_PATH, RTLD_NOW); |
| 3794 | if (adev->visualizer_lib == NULL) { |
| 3795 | ALOGE("%s: DLOPEN failed for %s", __func__, VISUALIZER_LIBRARY_PATH); |
| 3796 | } else { |
| 3797 | ALOGV("%s: DLOPEN successful for %s", __func__, VISUALIZER_LIBRARY_PATH); |
| 3798 | adev->visualizer_start_output = |
Subhash Chandra Bose Naripeddy | 1d08916 | 2013-11-13 13:31:50 -0800 | [diff] [blame] | 3799 | (int (*)(audio_io_handle_t, int))dlsym(adev->visualizer_lib, |
Eric Laurent | c4aef75 | 2013-09-12 17:45:53 -0700 | [diff] [blame] | 3800 | "visualizer_hal_start_output"); |
| 3801 | adev->visualizer_stop_output = |
Subhash Chandra Bose Naripeddy | 1d08916 | 2013-11-13 13:31:50 -0800 | [diff] [blame] | 3802 | (int (*)(audio_io_handle_t, int))dlsym(adev->visualizer_lib, |
Eric Laurent | c4aef75 | 2013-09-12 17:45:53 -0700 | [diff] [blame] | 3803 | "visualizer_hal_stop_output"); |
| 3804 | } |
| 3805 | } |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 3806 | audio_extn_listen_init(adev, adev->snd_card); |
Eric Laurent | c4aef75 | 2013-09-12 17:45:53 -0700 | [diff] [blame] | 3807 | |
Subhash Chandra Bose Naripeddy | 1d08916 | 2013-11-13 13:31:50 -0800 | [diff] [blame] | 3808 | if (access(OFFLOAD_EFFECTS_BUNDLE_LIBRARY_PATH, R_OK) == 0) { |
| 3809 | adev->offload_effects_lib = dlopen(OFFLOAD_EFFECTS_BUNDLE_LIBRARY_PATH, RTLD_NOW); |
| 3810 | if (adev->offload_effects_lib == NULL) { |
| 3811 | ALOGE("%s: DLOPEN failed for %s", __func__, |
| 3812 | OFFLOAD_EFFECTS_BUNDLE_LIBRARY_PATH); |
| 3813 | } else { |
| 3814 | ALOGV("%s: DLOPEN successful for %s", __func__, |
| 3815 | OFFLOAD_EFFECTS_BUNDLE_LIBRARY_PATH); |
| 3816 | adev->offload_effects_start_output = |
| 3817 | (int (*)(audio_io_handle_t, int))dlsym(adev->offload_effects_lib, |
| 3818 | "offload_effects_bundle_hal_start_output"); |
| 3819 | adev->offload_effects_stop_output = |
| 3820 | (int (*)(audio_io_handle_t, int))dlsym(adev->offload_effects_lib, |
| 3821 | "offload_effects_bundle_hal_stop_output"); |
| 3822 | } |
| 3823 | } |
| 3824 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3825 | *device = &adev->device.common; |
Steve Kondik | 3abbbc8 | 2014-11-29 14:14:43 -0800 | [diff] [blame] | 3826 | if (k_enable_extended_precision) |
| 3827 | adev_verify_devices(adev); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3828 | |
Daniel Hillenbrand | 8373bc6 | 2013-05-23 10:10:00 +0530 | [diff] [blame] | 3829 | if (amplifier_open() != 0) |
| 3830 | ALOGE("Amplifier initialization failed"); |
Daniel Hillenbrand | 8373bc6 | 2013-05-23 10:10:00 +0530 | [diff] [blame] | 3831 | |
Kiran Kandi | 910e186 | 2013-10-29 13:29:42 -0700 | [diff] [blame] | 3832 | audio_device_ref_count++; |
Ravi Kumar Alamanda | 1c3de5e | 2014-09-08 15:59:58 -0700 | [diff] [blame] | 3833 | |
| 3834 | char value[PROPERTY_VALUE_MAX]; |
| 3835 | int trial; |
| 3836 | if (property_get("audio_hal.period_size", value, NULL) > 0) { |
| 3837 | trial = atoi(value); |
| 3838 | if (period_size_is_plausible_for_low_latency(trial)) { |
| 3839 | pcm_config_low_latency.period_size = trial; |
| 3840 | pcm_config_low_latency.start_threshold = trial / 4; |
| 3841 | pcm_config_low_latency.avail_min = trial / 4; |
| 3842 | configured_low_latency_capture_period_size = trial; |
| 3843 | } |
| 3844 | } |
| 3845 | if (property_get("audio_hal.in_period_size", value, NULL) > 0) { |
| 3846 | trial = atoi(value); |
| 3847 | if (period_size_is_plausible_for_low_latency(trial)) { |
| 3848 | configured_low_latency_capture_period_size = trial; |
| 3849 | } |
| 3850 | } |
| 3851 | |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 3852 | pthread_mutex_unlock(&adev_init_lock); |
| 3853 | |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 3854 | ALOGV("%s: exit", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3855 | return 0; |
| 3856 | } |
| 3857 | |
| 3858 | static struct hw_module_methods_t hal_module_methods = { |
| 3859 | .open = adev_open, |
| 3860 | }; |
| 3861 | |
| 3862 | struct audio_module HAL_MODULE_INFO_SYM = { |
| 3863 | .common = { |
| 3864 | .tag = HARDWARE_MODULE_TAG, |
| 3865 | .module_api_version = AUDIO_MODULE_API_VERSION_0_1, |
| 3866 | .hal_api_version = HARDWARE_HAL_API_VERSION, |
| 3867 | .id = AUDIO_HARDWARE_MODULE_ID, |
| 3868 | .name = "QCOM Audio HAL", |
Duy Truong | fae1962 | 2013-11-24 02:17:54 -0800 | [diff] [blame] | 3869 | .author = "The Linux Foundation", |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3870 | .methods = &hal_module_methods, |
| 3871 | }, |
| 3872 | }; |