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