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