Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1 | /* |
Arun Kumar Dasari | 3b17418 | 2016-12-27 13:01:14 +0530 | [diff] [blame] | 2 | * Copyright (c) 2013-2017, 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. |
Jitendra Naruka | 1b6513f | 2014-11-22 19:34:13 -0800 | [diff] [blame] | 18 | * |
| 19 | * This file was modified by DTS, Inc. The portions of the |
| 20 | * code modified by DTS, Inc are copyrighted and |
| 21 | * licensed separately, as follows: |
| 22 | * |
| 23 | * (C) 2014 DTS, Inc. |
| 24 | * |
| 25 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 26 | * you may not use this file except in compliance with the License. |
| 27 | * You may obtain a copy of the License at |
| 28 | * |
| 29 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 30 | * |
| 31 | * Unless required by applicable law or agreed to in writing, software |
| 32 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 33 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 34 | * See the License for the specific language governing permissions and |
| 35 | * limitations under the License. |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 36 | */ |
| 37 | |
| 38 | #define LOG_TAG "audio_hw_primary" |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 39 | #define ATRACE_TAG (ATRACE_TAG_AUDIO|ATRACE_TAG_HAL) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 40 | /*#define LOG_NDEBUG 0*/ |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 41 | /*#define VERY_VERY_VERBOSE_LOGGING*/ |
| 42 | #ifdef VERY_VERY_VERBOSE_LOGGING |
| 43 | #define ALOGVV ALOGV |
| 44 | #else |
| 45 | #define ALOGVV(a...) do { } while(0) |
| 46 | #endif |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 47 | |
| 48 | #include <errno.h> |
| 49 | #include <pthread.h> |
| 50 | #include <stdint.h> |
| 51 | #include <sys/time.h> |
| 52 | #include <stdlib.h> |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 53 | #include <math.h> |
Eric Laurent | c4aef75 | 2013-09-12 17:45:53 -0700 | [diff] [blame] | 54 | #include <dlfcn.h> |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 55 | #include <sys/resource.h> |
| 56 | #include <sys/prctl.h> |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 57 | |
| 58 | #include <cutils/log.h> |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 59 | #include <cutils/trace.h> |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 60 | #include <cutils/str_parms.h> |
| 61 | #include <cutils/properties.h> |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 62 | #include <cutils/atomic.h> |
| 63 | #include <cutils/sched_policy.h> |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 64 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 65 | #include <hardware/audio_effect.h> |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 66 | #include <system/thread_defs.h> |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 67 | #include <audio_effects/effect_aec.h> |
| 68 | #include <audio_effects/effect_ns.h> |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 69 | #include <audio_utils/format.h> |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 70 | #include "audio_hw.h" |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 71 | #include "platform_api.h" |
| 72 | #include <platform.h> |
Apoorv Raghuvanshi | 9eaf94e | 2013-10-04 16:13:44 -0700 | [diff] [blame] | 73 | #include "audio_extn.h" |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 74 | #include "voice_extn.h" |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 75 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 76 | #include "sound/compress_params.h" |
ApurupaPattapu | c6a3a9e | 2014-01-10 14:46:02 -0800 | [diff] [blame] | 77 | #include "sound/asound.h" |
ApurupaPattapu | 2e084df | 2013-12-18 15:47:59 -0800 | [diff] [blame] | 78 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 79 | #define COMPRESS_OFFLOAD_NUM_FRAGMENTS 4 |
Ashish Jain | 5106d36 | 2016-05-11 19:23:33 +0530 | [diff] [blame] | 80 | /*DIRECT PCM has same buffer sizes as DEEP Buffer*/ |
| 81 | #define DIRECT_PCM_NUM_FRAGMENTS 2 |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 82 | /* ToDo: Check and update a proper value in msec */ |
Alexy Joseph | 01e54e6 | 2015-03-03 19:01:03 -0800 | [diff] [blame] | 83 | #define COMPRESS_OFFLOAD_PLAYBACK_LATENCY 50 |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 84 | #define COMPRESS_PLAYBACK_VOLUME_MAX 0x2000 |
Preetam Singh Ranawat | cb6212e | 2016-07-19 18:33:53 +0530 | [diff] [blame] | 85 | #define DSD_VOLUME_MIN_DB (-110) |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 86 | |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 87 | #define PROXY_OPEN_RETRY_COUNT 100 |
| 88 | #define PROXY_OPEN_WAIT_TIME 20 |
ApurupaPattapu | c6a3a9e | 2014-01-10 14:46:02 -0800 | [diff] [blame] | 89 | |
Mingming Yin | 08c7e31 | 2015-03-16 18:10:58 -0700 | [diff] [blame] | 90 | #ifdef USE_LL_AS_PRIMARY_OUTPUT |
| 91 | #define USECASE_AUDIO_PLAYBACK_PRIMARY USECASE_AUDIO_PLAYBACK_LOW_LATENCY |
| 92 | #define PCM_CONFIG_AUDIO_PLAYBACK_PRIMARY pcm_config_low_latency |
| 93 | #else |
Haynes Mathew George | bf14371 | 2013-12-03 13:02:53 -0800 | [diff] [blame] | 94 | #define USECASE_AUDIO_PLAYBACK_PRIMARY USECASE_AUDIO_PLAYBACK_DEEP_BUFFER |
Mingming Yin | 08c7e31 | 2015-03-16 18:10:58 -0700 | [diff] [blame] | 95 | #define PCM_CONFIG_AUDIO_PLAYBACK_PRIMARY pcm_config_deep_buffer |
| 96 | #endif |
Haynes Mathew George | bf14371 | 2013-12-03 13:02:53 -0800 | [diff] [blame] | 97 | |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 98 | #define ULL_PERIOD_SIZE (DEFAULT_OUTPUT_SAMPLING_RATE/1000) |
| 99 | |
Ravi Kumar Alamanda | dc9bb15 | 2014-09-08 15:59:58 -0700 | [diff] [blame] | 100 | static unsigned int configured_low_latency_capture_period_size = |
| 101 | LOW_LATENCY_CAPTURE_PERIOD_SIZE; |
| 102 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 103 | struct pcm_config pcm_config_deep_buffer = { |
| 104 | .channels = 2, |
| 105 | .rate = DEFAULT_OUTPUT_SAMPLING_RATE, |
| 106 | .period_size = DEEP_BUFFER_OUTPUT_PERIOD_SIZE, |
| 107 | .period_count = DEEP_BUFFER_OUTPUT_PERIOD_COUNT, |
| 108 | .format = PCM_FORMAT_S16_LE, |
| 109 | .start_threshold = DEEP_BUFFER_OUTPUT_PERIOD_SIZE / 4, |
| 110 | .stop_threshold = INT_MAX, |
| 111 | .avail_min = DEEP_BUFFER_OUTPUT_PERIOD_SIZE / 4, |
| 112 | }; |
| 113 | |
| 114 | struct pcm_config pcm_config_low_latency = { |
| 115 | .channels = 2, |
| 116 | .rate = DEFAULT_OUTPUT_SAMPLING_RATE, |
| 117 | .period_size = LOW_LATENCY_OUTPUT_PERIOD_SIZE, |
| 118 | .period_count = LOW_LATENCY_OUTPUT_PERIOD_COUNT, |
| 119 | .format = PCM_FORMAT_S16_LE, |
| 120 | .start_threshold = LOW_LATENCY_OUTPUT_PERIOD_SIZE / 4, |
| 121 | .stop_threshold = INT_MAX, |
| 122 | .avail_min = LOW_LATENCY_OUTPUT_PERIOD_SIZE / 4, |
| 123 | }; |
| 124 | |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 125 | static int af_period_multiplier = 4; |
| 126 | struct pcm_config pcm_config_rt = { |
| 127 | .channels = 2, |
| 128 | .rate = DEFAULT_OUTPUT_SAMPLING_RATE, |
| 129 | .period_size = ULL_PERIOD_SIZE, //1 ms |
| 130 | .period_count = 512, //=> buffer size is 512ms |
| 131 | .format = PCM_FORMAT_S16_LE, |
| 132 | .start_threshold = ULL_PERIOD_SIZE*8, //8ms |
| 133 | .stop_threshold = INT_MAX, |
| 134 | .silence_threshold = 0, |
| 135 | .silence_size = 0, |
| 136 | .avail_min = ULL_PERIOD_SIZE, //1 ms |
| 137 | }; |
| 138 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 139 | struct pcm_config pcm_config_hdmi_multi = { |
| 140 | .channels = HDMI_MULTI_DEFAULT_CHANNEL_COUNT, /* changed when the stream is opened */ |
| 141 | .rate = DEFAULT_OUTPUT_SAMPLING_RATE, /* changed when the stream is opened */ |
| 142 | .period_size = HDMI_MULTI_PERIOD_SIZE, |
| 143 | .period_count = HDMI_MULTI_PERIOD_COUNT, |
| 144 | .format = PCM_FORMAT_S16_LE, |
| 145 | .start_threshold = 0, |
| 146 | .stop_threshold = INT_MAX, |
| 147 | .avail_min = 0, |
| 148 | }; |
| 149 | |
| 150 | struct pcm_config pcm_config_audio_capture = { |
| 151 | .channels = 2, |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 152 | .period_count = AUDIO_CAPTURE_PERIOD_COUNT, |
| 153 | .format = PCM_FORMAT_S16_LE, |
| 154 | }; |
| 155 | |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 156 | struct pcm_config pcm_config_audio_capture_rt = { |
| 157 | .channels = 2, |
| 158 | .rate = DEFAULT_OUTPUT_SAMPLING_RATE, |
| 159 | .period_size = ULL_PERIOD_SIZE, |
| 160 | .period_count = 512, |
| 161 | .format = PCM_FORMAT_S16_LE, |
| 162 | .start_threshold = 0, |
| 163 | .stop_threshold = INT_MAX, |
| 164 | .silence_threshold = 0, |
| 165 | .silence_size = 0, |
| 166 | .avail_min = ULL_PERIOD_SIZE, //1 ms |
| 167 | }; |
| 168 | |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 169 | #define AFE_PROXY_CHANNEL_COUNT 2 |
| 170 | #define AFE_PROXY_SAMPLING_RATE 48000 |
| 171 | |
| 172 | #define AFE_PROXY_PLAYBACK_PERIOD_SIZE 768 |
| 173 | #define AFE_PROXY_PLAYBACK_PERIOD_COUNT 4 |
| 174 | |
| 175 | struct pcm_config pcm_config_afe_proxy_playback = { |
| 176 | .channels = AFE_PROXY_CHANNEL_COUNT, |
| 177 | .rate = AFE_PROXY_SAMPLING_RATE, |
| 178 | .period_size = AFE_PROXY_PLAYBACK_PERIOD_SIZE, |
| 179 | .period_count = AFE_PROXY_PLAYBACK_PERIOD_COUNT, |
| 180 | .format = PCM_FORMAT_S16_LE, |
| 181 | .start_threshold = AFE_PROXY_PLAYBACK_PERIOD_SIZE, |
| 182 | .stop_threshold = INT_MAX, |
| 183 | .avail_min = AFE_PROXY_PLAYBACK_PERIOD_SIZE, |
| 184 | }; |
| 185 | |
| 186 | #define AFE_PROXY_RECORD_PERIOD_SIZE 768 |
| 187 | #define AFE_PROXY_RECORD_PERIOD_COUNT 4 |
| 188 | |
| 189 | struct pcm_config pcm_config_afe_proxy_record = { |
| 190 | .channels = AFE_PROXY_CHANNEL_COUNT, |
| 191 | .rate = AFE_PROXY_SAMPLING_RATE, |
| 192 | .period_size = AFE_PROXY_RECORD_PERIOD_SIZE, |
| 193 | .period_count = AFE_PROXY_RECORD_PERIOD_COUNT, |
| 194 | .format = PCM_FORMAT_S16_LE, |
| 195 | .start_threshold = AFE_PROXY_RECORD_PERIOD_SIZE, |
| 196 | .stop_threshold = INT_MAX, |
| 197 | .avail_min = AFE_PROXY_RECORD_PERIOD_SIZE, |
| 198 | }; |
| 199 | |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 200 | #define AUDIO_MAX_PCM_FORMATS 7 |
| 201 | |
| 202 | const uint32_t format_to_bitwidth_table[AUDIO_MAX_PCM_FORMATS] = { |
| 203 | [AUDIO_FORMAT_DEFAULT] = 0, |
| 204 | [AUDIO_FORMAT_PCM_16_BIT] = sizeof(uint16_t), |
| 205 | [AUDIO_FORMAT_PCM_8_BIT] = sizeof(uint8_t), |
| 206 | [AUDIO_FORMAT_PCM_32_BIT] = sizeof(uint32_t), |
| 207 | [AUDIO_FORMAT_PCM_8_24_BIT] = sizeof(uint32_t), |
| 208 | [AUDIO_FORMAT_PCM_FLOAT] = sizeof(float), |
| 209 | [AUDIO_FORMAT_PCM_24_BIT_PACKED] = sizeof(uint8_t) * 3, |
| 210 | }; |
| 211 | |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 212 | const char * const use_case_table[AUDIO_USECASE_MAX] = { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 213 | [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = "deep-buffer-playback", |
| 214 | [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = "low-latency-playback", |
Ravi Kumar Alamanda | 474de5a | 2015-06-25 20:08:01 -0700 | [diff] [blame] | 215 | [USECASE_AUDIO_PLAYBACK_ULL] = "audio-ull-playback", |
| 216 | [USECASE_AUDIO_PLAYBACK_MULTI_CH] = "multi-channel-playback", |
Shruthi Krishna | ace1085 | 2013-10-25 14:32:12 -0700 | [diff] [blame] | 217 | [USECASE_AUDIO_PLAYBACK_OFFLOAD] = "compress-offload-playback", |
vivek mehta | 446c396 | 2015-09-14 10:57:35 -0700 | [diff] [blame] | 218 | //Enabled for Direct_PCM |
Subhash Chandra Bose Naripeddy | 16ff4f8 | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 219 | [USECASE_AUDIO_PLAYBACK_OFFLOAD2] = "compress-offload-playback2", |
| 220 | [USECASE_AUDIO_PLAYBACK_OFFLOAD3] = "compress-offload-playback3", |
| 221 | [USECASE_AUDIO_PLAYBACK_OFFLOAD4] = "compress-offload-playback4", |
| 222 | [USECASE_AUDIO_PLAYBACK_OFFLOAD5] = "compress-offload-playback5", |
| 223 | [USECASE_AUDIO_PLAYBACK_OFFLOAD6] = "compress-offload-playback6", |
| 224 | [USECASE_AUDIO_PLAYBACK_OFFLOAD7] = "compress-offload-playback7", |
| 225 | [USECASE_AUDIO_PLAYBACK_OFFLOAD8] = "compress-offload-playback8", |
| 226 | [USECASE_AUDIO_PLAYBACK_OFFLOAD9] = "compress-offload-playback9", |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 227 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 228 | [USECASE_AUDIO_RECORD] = "audio-record", |
Mingming Yin | e62d784 | 2013-10-25 16:26:03 -0700 | [diff] [blame] | 229 | [USECASE_AUDIO_RECORD_COMPRESS] = "audio-record-compress", |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 230 | [USECASE_AUDIO_RECORD_COMPRESS2] = "audio-record-compress2", |
| 231 | [USECASE_AUDIO_RECORD_COMPRESS3] = "audio-record-compress3", |
| 232 | [USECASE_AUDIO_RECORD_COMPRESS4] = "audio-record-compress4", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 233 | [USECASE_AUDIO_RECORD_LOW_LATENCY] = "low-latency-record", |
Preetam Singh Ranawat | de84f1a | 2013-11-01 14:58:16 -0700 | [diff] [blame] | 234 | [USECASE_AUDIO_RECORD_FM_VIRTUAL] = "fm-virtual-record", |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 235 | [USECASE_AUDIO_PLAYBACK_FM] = "play-fm", |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 236 | [USECASE_AUDIO_HFP_SCO] = "hfp-sco", |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 237 | [USECASE_AUDIO_HFP_SCO_WB] = "hfp-sco-wb", |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 238 | [USECASE_VOICE_CALL] = "voice-call", |
Mingming Yin | 3ee55c6 | 2014-08-04 14:23:35 -0700 | [diff] [blame] | 239 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 240 | [USECASE_VOICE2_CALL] = "voice2-call", |
| 241 | [USECASE_VOLTE_CALL] = "volte-call", |
| 242 | [USECASE_QCHAT_CALL] = "qchat-call", |
Vicky Sehrawat | 7e4fc15 | 2014-02-12 17:58:59 -0800 | [diff] [blame] | 243 | [USECASE_VOWLAN_CALL] = "vowlan-call", |
Vidyakumar Athota | 0e10935 | 2015-02-12 17:38:22 -0800 | [diff] [blame] | 244 | [USECASE_VOICEMMODE1_CALL] = "voicemmode1-call", |
| 245 | [USECASE_VOICEMMODE2_CALL] = "voicemmode2-call", |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 246 | [USECASE_COMPRESS_VOIP_CALL] = "compress-voip-call", |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 247 | [USECASE_INCALL_REC_UPLINK] = "incall-rec-uplink", |
| 248 | [USECASE_INCALL_REC_DOWNLINK] = "incall-rec-downlink", |
| 249 | [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = "incall-rec-uplink-and-downlink", |
Helen Zeng | e56b485 | 2013-12-03 16:54:40 -0800 | [diff] [blame] | 250 | [USECASE_INCALL_REC_UPLINK_COMPRESS] = "incall-rec-uplink-compress", |
| 251 | [USECASE_INCALL_REC_DOWNLINK_COMPRESS] = "incall-rec-downlink-compress", |
| 252 | [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS] = "incall-rec-uplink-and-downlink-compress", |
| 253 | |
Shiv Maliyappanahalli | f3b9a42 | 2013-10-22 16:38:08 -0700 | [diff] [blame] | 254 | [USECASE_INCALL_MUSIC_UPLINK] = "incall_music_uplink", |
| 255 | [USECASE_INCALL_MUSIC_UPLINK2] = "incall_music_uplink2", |
Gopikrishnaiah Anandan | f538cef | 2013-10-28 14:06:03 -0700 | [diff] [blame] | 256 | [USECASE_AUDIO_SPKR_CALIB_RX] = "spkr-rx-calib", |
| 257 | [USECASE_AUDIO_SPKR_CALIB_TX] = "spkr-vi-record", |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 258 | |
| 259 | [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = "afe-proxy-playback", |
| 260 | [USECASE_AUDIO_RECORD_AFE_PROXY] = "afe-proxy-record", |
Shiv Maliyappanahalli | c065640 | 2016-09-03 14:13:26 -0700 | [diff] [blame] | 261 | [USECASE_AUDIO_PLAYBACK_EXT_DISP_SILENCE] = "silence-playback", |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 262 | }; |
| 263 | |
Subhash Chandra Bose Naripeddy | 16ff4f8 | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 264 | static const audio_usecase_t offload_usecases[] = { |
| 265 | USECASE_AUDIO_PLAYBACK_OFFLOAD, |
Subhash Chandra Bose Naripeddy | 16ff4f8 | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 266 | USECASE_AUDIO_PLAYBACK_OFFLOAD2, |
| 267 | USECASE_AUDIO_PLAYBACK_OFFLOAD3, |
| 268 | USECASE_AUDIO_PLAYBACK_OFFLOAD4, |
| 269 | USECASE_AUDIO_PLAYBACK_OFFLOAD5, |
| 270 | USECASE_AUDIO_PLAYBACK_OFFLOAD6, |
| 271 | USECASE_AUDIO_PLAYBACK_OFFLOAD7, |
| 272 | USECASE_AUDIO_PLAYBACK_OFFLOAD8, |
| 273 | USECASE_AUDIO_PLAYBACK_OFFLOAD9, |
Subhash Chandra Bose Naripeddy | 16ff4f8 | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 274 | }; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 275 | |
| 276 | #define STRING_TO_ENUM(string) { #string, string } |
| 277 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 278 | struct string_to_enum { |
| 279 | const char *name; |
| 280 | uint32_t value; |
| 281 | }; |
| 282 | |
| 283 | static const struct string_to_enum out_channels_name_to_enum_table[] = { |
| 284 | STRING_TO_ENUM(AUDIO_CHANNEL_OUT_STEREO), |
Mingming Yin | 3a941d4 | 2016-02-17 18:08:05 -0800 | [diff] [blame] | 285 | STRING_TO_ENUM(AUDIO_CHANNEL_OUT_2POINT1), |
| 286 | STRING_TO_ENUM(AUDIO_CHANNEL_OUT_QUAD), |
| 287 | STRING_TO_ENUM(AUDIO_CHANNEL_OUT_SURROUND), |
Pradnya Chaphekar | 4403bd7 | 2014-09-09 09:50:01 -0700 | [diff] [blame] | 288 | STRING_TO_ENUM(AUDIO_CHANNEL_OUT_PENTA), |
Mingming Yin | 3a941d4 | 2016-02-17 18:08:05 -0800 | [diff] [blame] | 289 | STRING_TO_ENUM(AUDIO_CHANNEL_OUT_5POINT1), |
| 290 | STRING_TO_ENUM(AUDIO_CHANNEL_OUT_6POINT1), |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 291 | STRING_TO_ENUM(AUDIO_CHANNEL_OUT_7POINT1), |
| 292 | }; |
| 293 | |
Pradnya Chaphekar | 8a9dcd8 | 2014-09-09 09:49:10 -0700 | [diff] [blame] | 294 | static const struct string_to_enum out_formats_name_to_enum_table[] = { |
| 295 | STRING_TO_ENUM(AUDIO_FORMAT_AC3), |
| 296 | STRING_TO_ENUM(AUDIO_FORMAT_E_AC3), |
| 297 | STRING_TO_ENUM(AUDIO_FORMAT_E_AC3_JOC), |
Mingming Yin | 3a941d4 | 2016-02-17 18:08:05 -0800 | [diff] [blame] | 298 | STRING_TO_ENUM(AUDIO_FORMAT_DTS), |
| 299 | STRING_TO_ENUM(AUDIO_FORMAT_DTS_HD), |
| 300 | }; |
| 301 | |
| 302 | //list of all supported sample rates by HDMI specification. |
| 303 | static const int out_hdmi_sample_rates[] = { |
| 304 | 32000, 44100, 48000, 88200, 96000, 176400, 192000, |
| 305 | }; |
| 306 | |
| 307 | static const struct string_to_enum out_hdmi_sample_rates_name_to_enum_table[] = { |
| 308 | STRING_TO_ENUM(32000), |
| 309 | STRING_TO_ENUM(44100), |
| 310 | STRING_TO_ENUM(48000), |
| 311 | STRING_TO_ENUM(88200), |
| 312 | STRING_TO_ENUM(96000), |
| 313 | STRING_TO_ENUM(176400), |
| 314 | STRING_TO_ENUM(192000), |
Pradnya Chaphekar | 8a9dcd8 | 2014-09-09 09:49:10 -0700 | [diff] [blame] | 315 | }; |
| 316 | |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 317 | static struct audio_device *adev = NULL; |
| 318 | static pthread_mutex_t adev_init_lock; |
Kiran Kandi | 910e186 | 2013-10-29 13:29:42 -0700 | [diff] [blame] | 319 | static unsigned int audio_device_ref_count; |
vivek mehta | b72d08d | 2016-04-29 03:16:47 -0700 | [diff] [blame] | 320 | //cache last MBDRC cal step level |
| 321 | static int last_known_cal_step = -1 ; |
Kiran Kandi | 910e186 | 2013-10-29 13:29:42 -0700 | [diff] [blame] | 322 | |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 323 | static bool may_use_noirq_mode(struct audio_device *adev, audio_usecase_t uc_id, |
| 324 | int flags __unused) |
| 325 | { |
| 326 | int dir = 0; |
| 327 | switch (uc_id) { |
| 328 | case USECASE_AUDIO_RECORD_LOW_LATENCY: |
| 329 | dir = 1; |
| 330 | case USECASE_AUDIO_PLAYBACK_ULL: |
| 331 | break; |
| 332 | default: |
| 333 | return false; |
| 334 | } |
| 335 | |
| 336 | int dev_id = platform_get_pcm_device_id(uc_id, dir == 0 ? |
| 337 | PCM_PLAYBACK : PCM_CAPTURE); |
| 338 | if (adev->adm_is_noirq_avail) |
| 339 | return adev->adm_is_noirq_avail(adev->adm_data, |
| 340 | adev->snd_card, dev_id, dir); |
| 341 | return false; |
| 342 | } |
| 343 | |
| 344 | static void register_out_stream(struct stream_out *out) |
| 345 | { |
| 346 | struct audio_device *adev = out->dev; |
| 347 | if (is_offload_usecase(out->usecase) || |
| 348 | !adev->adm_register_output_stream) |
| 349 | return; |
| 350 | |
| 351 | // register stream first for backward compatibility |
| 352 | adev->adm_register_output_stream(adev->adm_data, |
| 353 | out->handle, |
| 354 | out->flags); |
| 355 | |
| 356 | if (!adev->adm_set_config) |
| 357 | return; |
| 358 | |
| 359 | if (out->realtime) |
| 360 | adev->adm_set_config(adev->adm_data, |
| 361 | out->handle, |
| 362 | out->pcm, &out->config); |
| 363 | } |
| 364 | |
| 365 | static void register_in_stream(struct stream_in *in) |
| 366 | { |
| 367 | struct audio_device *adev = in->dev; |
| 368 | if (!adev->adm_register_input_stream) |
| 369 | return; |
| 370 | |
| 371 | adev->adm_register_input_stream(adev->adm_data, |
| 372 | in->capture_handle, |
| 373 | in->flags); |
| 374 | |
| 375 | if (!adev->adm_set_config) |
| 376 | return; |
| 377 | |
| 378 | if (in->realtime) |
| 379 | adev->adm_set_config(adev->adm_data, |
| 380 | in->capture_handle, |
| 381 | in->pcm, |
| 382 | &in->config); |
| 383 | } |
| 384 | |
| 385 | static void request_out_focus(struct stream_out *out, long ns) |
| 386 | { |
| 387 | struct audio_device *adev = out->dev; |
| 388 | |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 389 | if (adev->adm_request_focus_v2) |
| 390 | adev->adm_request_focus_v2(adev->adm_data, out->handle, ns); |
| 391 | else if (adev->adm_request_focus) |
| 392 | adev->adm_request_focus(adev->adm_data, out->handle); |
| 393 | } |
| 394 | |
| 395 | static void request_in_focus(struct stream_in *in, long ns) |
| 396 | { |
| 397 | struct audio_device *adev = in->dev; |
| 398 | |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 399 | if (adev->adm_request_focus_v2) |
| 400 | adev->adm_request_focus_v2(adev->adm_data, in->capture_handle, ns); |
| 401 | else if (adev->adm_request_focus) |
| 402 | adev->adm_request_focus(adev->adm_data, in->capture_handle); |
| 403 | } |
| 404 | |
| 405 | static void release_out_focus(struct stream_out *out) |
| 406 | { |
| 407 | struct audio_device *adev = out->dev; |
| 408 | |
| 409 | if (adev->adm_abandon_focus) |
| 410 | adev->adm_abandon_focus(adev->adm_data, out->handle); |
| 411 | } |
| 412 | |
| 413 | static void release_in_focus(struct stream_in *in) |
| 414 | { |
| 415 | struct audio_device *adev = in->dev; |
| 416 | if (adev->adm_abandon_focus) |
| 417 | adev->adm_abandon_focus(adev->adm_data, in->capture_handle); |
| 418 | } |
| 419 | |
vivek mehta | a76401a | 2015-04-24 14:12:15 -0700 | [diff] [blame] | 420 | __attribute__ ((visibility ("default"))) |
| 421 | bool audio_hw_send_gain_dep_calibration(int level) { |
| 422 | bool ret_val = false; |
vivek mehta | b72d08d | 2016-04-29 03:16:47 -0700 | [diff] [blame] | 423 | ALOGV("%s: called ...", __func__); |
vivek mehta | a76401a | 2015-04-24 14:12:15 -0700 | [diff] [blame] | 424 | |
| 425 | pthread_mutex_lock(&adev_init_lock); |
| 426 | |
| 427 | if (adev != NULL && adev->platform != NULL) { |
| 428 | pthread_mutex_lock(&adev->lock); |
| 429 | ret_val = platform_send_gain_dep_cal(adev->platform, level); |
vivek mehta | b72d08d | 2016-04-29 03:16:47 -0700 | [diff] [blame] | 430 | |
| 431 | // if cal set fails, cache level info |
| 432 | // if cal set succeds, reset known last cal set |
| 433 | if (!ret_val) |
| 434 | last_known_cal_step = level; |
| 435 | else if (last_known_cal_step != -1) |
| 436 | last_known_cal_step = -1; |
| 437 | |
vivek mehta | a76401a | 2015-04-24 14:12:15 -0700 | [diff] [blame] | 438 | pthread_mutex_unlock(&adev->lock); |
| 439 | } else { |
| 440 | ALOGE("%s: %s is NULL", __func__, adev == NULL ? "adev" : "adev->platform"); |
| 441 | } |
| 442 | |
| 443 | pthread_mutex_unlock(&adev_init_lock); |
| 444 | |
| 445 | return ret_val; |
| 446 | } |
| 447 | |
Ashish Jain | 5106d36 | 2016-05-11 19:23:33 +0530 | [diff] [blame] | 448 | static int check_and_set_gapless_mode(struct audio_device *adev, bool enable_gapless) |
| 449 | { |
Krishnankutty Kolathappilly | 6d8788b | 2014-01-09 12:45:31 -0800 | [diff] [blame] | 450 | bool gapless_enabled = false; |
| 451 | const char *mixer_ctl_name = "Compress Gapless Playback"; |
| 452 | struct mixer_ctl *ctl; |
| 453 | |
| 454 | ALOGV("%s:", __func__); |
Ashish Jain | 5106d36 | 2016-05-11 19:23:33 +0530 | [diff] [blame] | 455 | gapless_enabled = property_get_bool("audio.offload.gapless.enabled", false); |
| 456 | |
| 457 | /*Disable gapless if its AV playback*/ |
| 458 | gapless_enabled = gapless_enabled && enable_gapless; |
Krishnankutty Kolathappilly | 6d8788b | 2014-01-09 12:45:31 -0800 | [diff] [blame] | 459 | |
| 460 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 461 | if (!ctl) { |
| 462 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 463 | __func__, mixer_ctl_name); |
| 464 | return -EINVAL; |
| 465 | } |
| 466 | |
| 467 | if (mixer_ctl_set_value(ctl, 0, gapless_enabled) < 0) { |
| 468 | ALOGE("%s: Could not set gapless mode %d", |
| 469 | __func__, gapless_enabled); |
| 470 | return -EINVAL; |
| 471 | } |
| 472 | return 0; |
| 473 | } |
Haynes Mathew George | 5191a85 | 2013-09-11 14:19:36 -0700 | [diff] [blame] | 474 | |
Aniket Kumar Lata | f56b640 | 2016-10-27 12:03:18 -0700 | [diff] [blame] | 475 | __attribute__ ((visibility ("default"))) |
| 476 | int audio_hw_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl, |
| 477 | int table_size) { |
| 478 | int ret_val = 0; |
| 479 | ALOGV("%s: enter ... ", __func__); |
| 480 | |
| 481 | pthread_mutex_lock(&adev_init_lock); |
| 482 | if (adev == NULL) { |
| 483 | ALOGW("%s: adev is NULL .... ", __func__); |
| 484 | goto done; |
| 485 | } |
| 486 | |
| 487 | pthread_mutex_lock(&adev->lock); |
| 488 | ret_val = platform_get_gain_level_mapping(mapping_tbl, table_size); |
| 489 | pthread_mutex_unlock(&adev->lock); |
| 490 | done: |
| 491 | pthread_mutex_unlock(&adev_init_lock); |
| 492 | ALOGV("%s: exit ... ", __func__); |
| 493 | return ret_val; |
| 494 | } |
| 495 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 496 | static bool is_supported_format(audio_format_t format) |
| 497 | { |
Eric Laurent | 86e1713 | 2013-09-12 17:49:30 -0700 | [diff] [blame] | 498 | if (format == AUDIO_FORMAT_MP3 || |
Satish Babu Patakokila | 0c31392 | 2016-12-08 12:07:08 +0530 | [diff] [blame] | 499 | format == AUDIO_FORMAT_MP2 || |
Ashish Jain | f9b7816 | 2014-08-25 20:36:25 +0530 | [diff] [blame] | 500 | format == AUDIO_FORMAT_AAC_LC || |
| 501 | format == AUDIO_FORMAT_AAC_HE_V1 || |
| 502 | format == AUDIO_FORMAT_AAC_HE_V2 || |
Manish Dewangan | a6fc544 | 2015-08-24 20:30:31 +0530 | [diff] [blame] | 503 | format == AUDIO_FORMAT_AAC_ADTS_LC || |
| 504 | format == AUDIO_FORMAT_AAC_ADTS_HE_V1 || |
| 505 | format == AUDIO_FORMAT_AAC_ADTS_HE_V2 || |
Arun Kumar Dasari | 3b17418 | 2016-12-27 13:01:14 +0530 | [diff] [blame] | 506 | format == AUDIO_FORMAT_AAC_LATM_LC || |
| 507 | format == AUDIO_FORMAT_AAC_LATM_HE_V1 || |
| 508 | format == AUDIO_FORMAT_AAC_LATM_HE_V2 || |
Ashish Jain | 5106d36 | 2016-05-11 19:23:33 +0530 | [diff] [blame] | 509 | format == AUDIO_FORMAT_PCM_24_BIT_PACKED || |
| 510 | format == AUDIO_FORMAT_PCM_8_24_BIT || |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 511 | format == AUDIO_FORMAT_PCM_FLOAT || |
| 512 | format == AUDIO_FORMAT_PCM_32_BIT || |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 513 | format == AUDIO_FORMAT_PCM_16_BIT || |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 514 | format == AUDIO_FORMAT_AC3 || |
| 515 | format == AUDIO_FORMAT_E_AC3 || |
| 516 | format == AUDIO_FORMAT_DTS || |
| 517 | format == AUDIO_FORMAT_DTS_HD || |
Weiyin Jiang | 18ac4e9 | 2015-03-15 15:03:40 +0800 | [diff] [blame] | 518 | format == AUDIO_FORMAT_FLAC || |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 519 | format == AUDIO_FORMAT_ALAC || |
| 520 | format == AUDIO_FORMAT_APE || |
Preetam Singh Ranawat | cb6212e | 2016-07-19 18:33:53 +0530 | [diff] [blame] | 521 | format == AUDIO_FORMAT_DSD || |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 522 | format == AUDIO_FORMAT_VORBIS || |
Weiyin Jiang | 18ac4e9 | 2015-03-15 15:03:40 +0800 | [diff] [blame] | 523 | format == AUDIO_FORMAT_WMA || |
| 524 | format == AUDIO_FORMAT_WMA_PRO) |
ApurupaPattapu | c6a3a9e | 2014-01-10 14:46:02 -0800 | [diff] [blame] | 525 | return true; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 526 | |
| 527 | return false; |
| 528 | } |
| 529 | |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 530 | static inline bool is_mmap_usecase(audio_usecase_t uc_id) |
| 531 | { |
| 532 | return (uc_id == USECASE_AUDIO_RECORD_AFE_PROXY) || |
| 533 | (uc_id == USECASE_AUDIO_PLAYBACK_AFE_PROXY); |
| 534 | } |
| 535 | |
Venkata Narendra Kumar Gutta | ed0f94f | 2014-07-09 16:29:28 +0530 | [diff] [blame] | 536 | int get_snd_card_state(struct audio_device *adev) |
Naresh Tanniru | 8065983 | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 537 | { |
| 538 | int snd_scard_state; |
| 539 | |
| 540 | if (!adev) |
| 541 | return SND_CARD_STATE_OFFLINE; |
| 542 | |
| 543 | pthread_mutex_lock(&adev->snd_card_status.lock); |
| 544 | snd_scard_state = adev->snd_card_status.state; |
| 545 | pthread_mutex_unlock(&adev->snd_card_status.lock); |
| 546 | |
| 547 | return snd_scard_state; |
| 548 | } |
| 549 | |
| 550 | static int set_snd_card_state(struct audio_device *adev, int snd_scard_state) |
| 551 | { |
| 552 | if (!adev) |
| 553 | return -ENOSYS; |
| 554 | |
| 555 | pthread_mutex_lock(&adev->snd_card_status.lock); |
Ben Romberger | feca4b8 | 2015-07-07 20:40:44 -0700 | [diff] [blame] | 556 | if (adev->snd_card_status.state != snd_scard_state) { |
| 557 | adev->snd_card_status.state = snd_scard_state; |
| 558 | platform_snd_card_update(adev->platform, snd_scard_state); |
| 559 | } |
Naresh Tanniru | 8065983 | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 560 | pthread_mutex_unlock(&adev->snd_card_status.lock); |
| 561 | |
| 562 | return 0; |
| 563 | } |
| 564 | |
Avinash Vaish | 71a8b97 | 2014-07-24 15:36:33 +0530 | [diff] [blame] | 565 | static int enable_audio_route_for_voice_usecases(struct audio_device *adev, |
| 566 | struct audio_usecase *uc_info) |
| 567 | { |
| 568 | struct listnode *node; |
| 569 | struct audio_usecase *usecase; |
| 570 | |
| 571 | if (uc_info == NULL) |
| 572 | return -EINVAL; |
| 573 | |
| 574 | /* Re-route all voice usecases on the shared backend other than the |
| 575 | specified usecase to new snd devices */ |
| 576 | list_for_each(node, &adev->usecase_list) { |
| 577 | usecase = node_to_item(node, struct audio_usecase, list); |
Narsinga Rao Chella | e7f33c1 | 2015-01-28 15:23:34 -0800 | [diff] [blame] | 578 | if ((usecase->type == VOICE_CALL) && (usecase != uc_info)) |
Avinash Vaish | 71a8b97 | 2014-07-24 15:36:33 +0530 | [diff] [blame] | 579 | enable_audio_route(adev, usecase); |
| 580 | } |
| 581 | return 0; |
| 582 | } |
| 583 | |
Preetam Singh Ranawat | 6a83666 | 2016-09-08 17:04:35 +0530 | [diff] [blame] | 584 | static void enable_asrc_mode(struct audio_device *adev) |
Preetam Singh Ranawat | b0c0dd7 | 2016-08-18 00:32:06 +0530 | [diff] [blame] | 585 | { |
Preetam Singh Ranawat | 6a83666 | 2016-09-08 17:04:35 +0530 | [diff] [blame] | 586 | ALOGV("%s", __func__); |
| 587 | audio_route_apply_and_update_path(adev->audio_route, |
| 588 | "asrc-mode"); |
| 589 | adev->asrc_mode_enabled = true; |
| 590 | } |
| 591 | |
| 592 | static void disable_asrc_mode(struct audio_device *adev) |
| 593 | { |
| 594 | ALOGV("%s", __func__); |
| 595 | audio_route_reset_and_update_path(adev->audio_route, |
| 596 | "asrc-mode"); |
| 597 | adev->asrc_mode_enabled = false; |
| 598 | } |
| 599 | |
| 600 | /* |
| 601 | * - Enable ASRC mode for incoming mix path use case(Headphone backend)if Headphone |
| 602 | * 44.1 or Native DSD backends are enabled for any of current use case. |
| 603 | * e.g. 48-> + (Naitve DSD or Headphone 44.1) |
| 604 | * - Disable current mix path use case(Headphone backend) and re-enable it with |
| 605 | * ASRC mode for incoming Headphone 44.1 or Native DSD use case. |
| 606 | * e.g. Naitve DSD or Headphone 44.1 -> + 48 |
| 607 | */ |
| 608 | static void check_and_set_asrc_mode(struct audio_device *adev, snd_device_t snd_device) |
| 609 | { |
| 610 | ALOGV("%s snd device %d", __func__, snd_device); |
| 611 | int new_backend_idx = platform_get_backend_index(snd_device); |
| 612 | |
| 613 | if (((new_backend_idx == HEADPHONE_BACKEND) || |
| 614 | (new_backend_idx == HEADPHONE_44_1_BACKEND) || |
| 615 | (new_backend_idx == DSD_NATIVE_BACKEND)) && |
| 616 | !adev->asrc_mode_enabled) { |
Preetam Singh Ranawat | b0c0dd7 | 2016-08-18 00:32:06 +0530 | [diff] [blame] | 617 | struct listnode *node = NULL; |
| 618 | struct audio_usecase *uc = NULL; |
| 619 | struct stream_out *curr_out = NULL; |
Preetam Singh Ranawat | 6a83666 | 2016-09-08 17:04:35 +0530 | [diff] [blame] | 620 | int usecase_backend_idx = DEFAULT_CODEC_BACKEND; |
Preetam Singh Ranawat | b0c0dd7 | 2016-08-18 00:32:06 +0530 | [diff] [blame] | 621 | |
| 622 | list_for_each(node, &adev->usecase_list) { |
| 623 | uc = node_to_item(node, struct audio_usecase, list); |
| 624 | curr_out = (struct stream_out*) uc->stream.out; |
Preetam Singh Ranawat | b0c0dd7 | 2016-08-18 00:32:06 +0530 | [diff] [blame] | 625 | if (curr_out && PCM_PLAYBACK == uc->type) { |
Preetam Singh Ranawat | 6a83666 | 2016-09-08 17:04:35 +0530 | [diff] [blame] | 626 | usecase_backend_idx = platform_get_backend_index(uc->out_snd_device); |
| 627 | |
| 628 | if((new_backend_idx == HEADPHONE_BACKEND) && |
| 629 | ((usecase_backend_idx == HEADPHONE_44_1_BACKEND) || |
| 630 | (usecase_backend_idx == DSD_NATIVE_BACKEND))) { |
Preetam Singh Ranawat | b0c0dd7 | 2016-08-18 00:32:06 +0530 | [diff] [blame] | 631 | ALOGD("%s:DSD or native stream detected enabling asrcmode in hardware", |
| 632 | __func__); |
Preetam Singh Ranawat | 6a83666 | 2016-09-08 17:04:35 +0530 | [diff] [blame] | 633 | enable_asrc_mode(adev); |
| 634 | break; |
| 635 | } else if(((new_backend_idx == HEADPHONE_44_1_BACKEND) || |
| 636 | (new_backend_idx == DSD_NATIVE_BACKEND)) && |
| 637 | (usecase_backend_idx == HEADPHONE_BACKEND)) { |
| 638 | ALOGD("%s:48K stream detected, disabling and enabling it with asrcmode in hardware", |
| 639 | __func__); |
| 640 | disable_audio_route(adev, uc); |
| 641 | disable_snd_device(adev, uc->out_snd_device); |
| 642 | // Apply true-high-quality-mode if DSD or > 44.1KHz or >=24-bit |
| 643 | if (new_backend_idx == DSD_NATIVE_BACKEND) |
| 644 | audio_route_apply_and_update_path(adev->audio_route, |
| 645 | "hph-true-highquality-mode"); |
| 646 | else if ((new_backend_idx == HEADPHONE_44_1_BACKEND) && |
| 647 | (curr_out->bit_width >= 24)) |
| 648 | audio_route_apply_and_update_path(adev->audio_route, |
| 649 | "hph-highquality-mode"); |
| 650 | enable_asrc_mode(adev); |
| 651 | enable_snd_device(adev, uc->out_snd_device); |
| 652 | enable_audio_route(adev, uc); |
Preetam Singh Ranawat | b0c0dd7 | 2016-08-18 00:32:06 +0530 | [diff] [blame] | 653 | break; |
| 654 | } |
| 655 | } |
| 656 | } |
| 657 | } |
| 658 | } |
| 659 | |
Ravi Kumar Alamanda | dc9bb15 | 2014-09-08 15:59:58 -0700 | [diff] [blame] | 660 | int pcm_ioctl(struct pcm *pcm, int request, ...) |
| 661 | { |
| 662 | va_list ap; |
| 663 | void * arg; |
| 664 | int pcm_fd = *(int*)pcm; |
| 665 | |
| 666 | va_start(ap, request); |
| 667 | arg = va_arg(ap, void *); |
| 668 | va_end(ap); |
| 669 | |
| 670 | return ioctl(pcm_fd, request, arg); |
| 671 | } |
| 672 | |
Gopikrishnaiah Anandan | f538cef | 2013-10-28 14:06:03 -0700 | [diff] [blame] | 673 | int enable_audio_route(struct audio_device *adev, |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 674 | struct audio_usecase *usecase) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 675 | { |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 676 | snd_device_t snd_device; |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 677 | char mixer_path[MIXER_PATH_MAX_LENGTH]; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 678 | |
| 679 | if (usecase == NULL) |
| 680 | return -EINVAL; |
| 681 | |
| 682 | ALOGV("%s: enter: usecase(%d)", __func__, usecase->id); |
| 683 | |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 684 | if (usecase->type == PCM_CAPTURE) |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 685 | snd_device = usecase->in_snd_device; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 686 | else |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 687 | snd_device = usecase->out_snd_device; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 688 | |
Subhash Chandra Bose Naripeddy | 7690c56 | 2013-12-14 00:34:53 -0800 | [diff] [blame] | 689 | #ifdef DS1_DOLBY_DAP_ENABLED |
| 690 | audio_extn_dolby_set_dmid(adev); |
| 691 | audio_extn_dolby_set_endpoint(adev); |
| 692 | #endif |
Pradnya Chaphekar | 8a9dcd8 | 2014-09-09 09:49:10 -0700 | [diff] [blame] | 693 | audio_extn_dolby_ds2_set_endpoint(adev); |
Ravi Kumar Alamanda | 8fa6b19 | 2014-09-09 16:06:42 -0700 | [diff] [blame] | 694 | audio_extn_sound_trigger_update_stream_status(usecase, ST_EVENT_STREAM_BUSY); |
Dhananjay Kumar | 45b7174 | 2014-05-29 21:47:27 +0530 | [diff] [blame] | 695 | audio_extn_listen_update_stream_status(usecase, LISTEN_EVENT_STREAM_BUSY); |
Ben Romberger | 1fafdde | 2015-09-09 19:43:15 -0700 | [diff] [blame] | 696 | audio_extn_utils_send_app_type_cfg(adev, usecase); |
Dhananjay Kumar | 14170dd | 2015-08-28 13:24:16 +0530 | [diff] [blame] | 697 | audio_extn_utils_send_audio_calibration(adev, usecase); |
Apoorv Raghuvanshi | 8880cac | 2015-02-06 15:33:49 -0800 | [diff] [blame] | 698 | strlcpy(mixer_path, use_case_table[usecase->id], MIXER_PATH_MAX_LENGTH); |
Banajit Goswami | 20cdd21 | 2015-09-11 01:11:30 -0700 | [diff] [blame] | 699 | platform_add_backend_name(mixer_path, snd_device, usecase); |
Ravi Kumar Alamanda | c7d9bef | 2015-09-30 22:27:26 -0700 | [diff] [blame] | 700 | ALOGD("%s: apply mixer and update path: %s", __func__, mixer_path); |
Haynes Mathew George | ef1e3d3 | 2014-04-24 11:53:44 -0700 | [diff] [blame] | 701 | audio_route_apply_and_update_path(adev->audio_route, mixer_path); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 702 | ALOGV("%s: exit", __func__); |
| 703 | return 0; |
| 704 | } |
| 705 | |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 706 | int disable_audio_route(struct audio_device *adev, |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 707 | struct audio_usecase *usecase) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 708 | { |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 709 | snd_device_t snd_device; |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 710 | char mixer_path[MIXER_PATH_MAX_LENGTH]; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 711 | |
Preetam Singh Ranawat | a5f32b4 | 2014-09-23 12:12:47 +0530 | [diff] [blame] | 712 | if (usecase == NULL || usecase->id == USECASE_INVALID) |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 713 | return -EINVAL; |
| 714 | |
| 715 | ALOGV("%s: enter: usecase(%d)", __func__, usecase->id); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 716 | if (usecase->type == PCM_CAPTURE) |
| 717 | snd_device = usecase->in_snd_device; |
| 718 | else |
| 719 | snd_device = usecase->out_snd_device; |
Apoorv Raghuvanshi | 8880cac | 2015-02-06 15:33:49 -0800 | [diff] [blame] | 720 | strlcpy(mixer_path, use_case_table[usecase->id], MIXER_PATH_MAX_LENGTH); |
Banajit Goswami | 20cdd21 | 2015-09-11 01:11:30 -0700 | [diff] [blame] | 721 | platform_add_backend_name(mixer_path, snd_device, usecase); |
Ravi Kumar Alamanda | c7d9bef | 2015-09-30 22:27:26 -0700 | [diff] [blame] | 722 | ALOGD("%s: reset and update mixer path: %s", __func__, mixer_path); |
Haynes Mathew George | ef1e3d3 | 2014-04-24 11:53:44 -0700 | [diff] [blame] | 723 | audio_route_reset_and_update_path(adev->audio_route, mixer_path); |
Ravi Kumar Alamanda | 8fa6b19 | 2014-09-09 16:06:42 -0700 | [diff] [blame] | 724 | audio_extn_sound_trigger_update_stream_status(usecase, ST_EVENT_STREAM_FREE); |
Dhananjay Kumar | 45b7174 | 2014-05-29 21:47:27 +0530 | [diff] [blame] | 725 | audio_extn_listen_update_stream_status(usecase, LISTEN_EVENT_STREAM_FREE); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 726 | ALOGV("%s: exit", __func__); |
| 727 | return 0; |
| 728 | } |
| 729 | |
Gopikrishnaiah Anandan | f538cef | 2013-10-28 14:06:03 -0700 | [diff] [blame] | 730 | int enable_snd_device(struct audio_device *adev, |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 731 | snd_device_t snd_device) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 732 | { |
Sidipotu Ashok | 9f0b16e | 2016-04-28 13:48:28 +0530 | [diff] [blame] | 733 | int i, num_devices = 0; |
| 734 | snd_device_t new_snd_devices[SND_DEVICE_OUT_END]; |
Ravi Kumar Alamanda | 48c921d | 2013-10-29 06:07:44 -0700 | [diff] [blame] | 735 | char device_name[DEVICE_NAME_MAX_SIZE] = {0}; |
| 736 | |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 737 | if (snd_device < SND_DEVICE_MIN || |
| 738 | snd_device >= SND_DEVICE_MAX) { |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 739 | ALOGE("%s: Invalid sound device %d", __func__, snd_device); |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 740 | return -EINVAL; |
| 741 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 742 | |
| 743 | adev->snd_dev_ref_cnt[snd_device]++; |
Ravi Kumar Alamanda | 48c921d | 2013-10-29 06:07:44 -0700 | [diff] [blame] | 744 | |
| 745 | if(platform_get_snd_device_name_extn(adev->platform, snd_device, device_name) < 0 ) { |
| 746 | ALOGE("%s: Invalid sound device returned", __func__); |
| 747 | return -EINVAL; |
| 748 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 749 | if (adev->snd_dev_ref_cnt[snd_device] > 1) { |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 750 | ALOGV("%s: snd_device(%d: %s) is already active", |
Ravi Kumar Alamanda | 48c921d | 2013-10-29 06:07:44 -0700 | [diff] [blame] | 751 | __func__, snd_device, device_name); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 752 | return 0; |
| 753 | } |
| 754 | |
Sidipotu Ashok | e6f78cb | 2015-11-05 14:42:20 +0530 | [diff] [blame] | 755 | |
Gopikrishnaiah Anandan | e85d046 | 2014-06-30 21:41:20 -0700 | [diff] [blame] | 756 | if (audio_extn_spkr_prot_is_enabled()) |
| 757 | audio_extn_spkr_prot_calib_cancel(adev); |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 758 | |
Xiaojun Sang | 040cc9f | 2015-08-03 19:38:28 +0800 | [diff] [blame] | 759 | if (platform_can_enable_spkr_prot_on_device(snd_device) && |
| 760 | audio_extn_spkr_prot_is_enabled()) { |
| 761 | if (platform_get_spkr_prot_acdb_id(snd_device) < 0) { |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 762 | adev->snd_dev_ref_cnt[snd_device]--; |
| 763 | return -EINVAL; |
| 764 | } |
Ravit Dennis | aaee49c | 2015-02-04 21:26:22 +0200 | [diff] [blame] | 765 | audio_extn_dev_arbi_acquire(snd_device); |
Kuirong Wang | a9f7cee | 2016-03-07 11:21:52 -0800 | [diff] [blame] | 766 | if (audio_extn_spkr_prot_start_processing(snd_device)) { |
Vidyakumar Athota | 1c6419a | 2014-01-10 14:47:34 -0800 | [diff] [blame] | 767 | ALOGE("%s: spkr_start_processing failed", __func__); |
Ravit Dennis | aaee49c | 2015-02-04 21:26:22 +0200 | [diff] [blame] | 768 | audio_extn_dev_arbi_release(snd_device); |
Vidyakumar Athota | 1c6419a | 2014-01-10 14:47:34 -0800 | [diff] [blame] | 769 | return -EINVAL; |
| 770 | } |
Haynes Mathew George | bfe8ff4 | 2016-09-22 17:38:16 -0700 | [diff] [blame] | 771 | } else if (platform_split_snd_device(adev->platform, |
| 772 | snd_device, |
| 773 | &num_devices, |
| 774 | new_snd_devices) == 0) { |
Sidipotu Ashok | 9f0b16e | 2016-04-28 13:48:28 +0530 | [diff] [blame] | 775 | for (i = 0; i < num_devices; i++) { |
| 776 | enable_snd_device(adev, new_snd_devices[i]); |
| 777 | } |
Vidyakumar Athota | 1c6419a | 2014-01-10 14:47:34 -0800 | [diff] [blame] | 778 | } else { |
Ravi Kumar Alamanda | c7d9bef | 2015-09-30 22:27:26 -0700 | [diff] [blame] | 779 | ALOGD("%s: snd_device(%d: %s)", __func__, snd_device, device_name); |
Naresh Tanniru | cd2353e | 2016-08-19 00:37:25 +0530 | [diff] [blame] | 780 | |
Preetam Singh Ranawat | f1d417c | 2017-01-10 17:00:32 +0530 | [diff] [blame] | 781 | if (platform_check_codec_asrc_support(adev->platform)) |
| 782 | check_and_set_asrc_mode(adev, snd_device); |
| 783 | |
Naresh Tanniru | cd2353e | 2016-08-19 00:37:25 +0530 | [diff] [blame] | 784 | if ((SND_DEVICE_OUT_BT_A2DP == snd_device) && |
| 785 | (audio_extn_a2dp_start_playback() < 0)) { |
| 786 | ALOGE(" fail to configure A2dp control path "); |
| 787 | return -EINVAL; |
| 788 | } |
| 789 | |
Bharath Ramachandramurthy | 0de1678 | 2014-03-28 21:34:33 -0700 | [diff] [blame] | 790 | /* due to the possibility of calibration overwrite between listen |
| 791 | and audio, notify listen hal before audio calibration is sent */ |
Ravi Kumar Alamanda | 8fa6b19 | 2014-09-09 16:06:42 -0700 | [diff] [blame] | 792 | audio_extn_sound_trigger_update_device_status(snd_device, |
| 793 | ST_EVENT_SND_DEVICE_BUSY); |
Dhananjay Kumar | 45b7174 | 2014-05-29 21:47:27 +0530 | [diff] [blame] | 794 | audio_extn_listen_update_device_status(snd_device, |
| 795 | LISTEN_EVENT_SND_DEVICE_BUSY); |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 796 | if (platform_get_snd_device_acdb_id(snd_device) < 0) { |
Gopikrishnaiah Anandan | f538cef | 2013-10-28 14:06:03 -0700 | [diff] [blame] | 797 | adev->snd_dev_ref_cnt[snd_device]--; |
Ravi Kumar Alamanda | 8fa6b19 | 2014-09-09 16:06:42 -0700 | [diff] [blame] | 798 | audio_extn_sound_trigger_update_device_status(snd_device, |
| 799 | ST_EVENT_SND_DEVICE_FREE); |
Dhananjay Kumar | 45b7174 | 2014-05-29 21:47:27 +0530 | [diff] [blame] | 800 | audio_extn_listen_update_device_status(snd_device, |
| 801 | LISTEN_EVENT_SND_DEVICE_FREE); |
Gopikrishnaiah Anandan | f538cef | 2013-10-28 14:06:03 -0700 | [diff] [blame] | 802 | return -EINVAL; |
| 803 | } |
Lior Barenboim | 0b61bc7 | 2014-05-13 13:01:37 +0300 | [diff] [blame] | 804 | audio_extn_dev_arbi_acquire(snd_device); |
Haynes Mathew George | ef1e3d3 | 2014-04-24 11:53:44 -0700 | [diff] [blame] | 805 | audio_route_apply_and_update_path(adev->audio_route, device_name); |
Sidipotu Ashok | e6f78cb | 2015-11-05 14:42:20 +0530 | [diff] [blame] | 806 | |
| 807 | if (SND_DEVICE_OUT_HEADPHONES == snd_device && |
| 808 | !adev->native_playback_enabled && |
| 809 | audio_is_true_native_stream_active(adev)) { |
| 810 | ALOGD("%s: %d: napb: enabling native mode in hardware", |
| 811 | __func__, __LINE__); |
| 812 | audio_route_apply_and_update_path(adev->audio_route, |
| 813 | "true-native-mode"); |
| 814 | adev->native_playback_enabled = true; |
Preetam Singh Ranawat | 6a83666 | 2016-09-08 17:04:35 +0530 | [diff] [blame] | 815 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 816 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 817 | return 0; |
| 818 | } |
| 819 | |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 820 | int disable_snd_device(struct audio_device *adev, |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 821 | snd_device_t snd_device) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 822 | { |
Sidipotu Ashok | 9f0b16e | 2016-04-28 13:48:28 +0530 | [diff] [blame] | 823 | int i, num_devices = 0; |
| 824 | snd_device_t new_snd_devices[SND_DEVICE_OUT_END]; |
Ravi Kumar Alamanda | 48c921d | 2013-10-29 06:07:44 -0700 | [diff] [blame] | 825 | char device_name[DEVICE_NAME_MAX_SIZE] = {0}; |
| 826 | |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 827 | if (snd_device < SND_DEVICE_MIN || |
| 828 | snd_device >= SND_DEVICE_MAX) { |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 829 | ALOGE("%s: Invalid sound device %d", __func__, snd_device); |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 830 | return -EINVAL; |
| 831 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 832 | if (adev->snd_dev_ref_cnt[snd_device] <= 0) { |
| 833 | ALOGE("%s: device ref cnt is already 0", __func__); |
| 834 | return -EINVAL; |
| 835 | } |
Ravi Kumar Alamanda | 48c921d | 2013-10-29 06:07:44 -0700 | [diff] [blame] | 836 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 837 | adev->snd_dev_ref_cnt[snd_device]--; |
Apoorv Raghuvanshi | 5792d4b | 2013-10-07 18:40:05 -0700 | [diff] [blame] | 838 | |
Ravi Kumar Alamanda | 48c921d | 2013-10-29 06:07:44 -0700 | [diff] [blame] | 839 | if(platform_get_snd_device_name_extn(adev->platform, snd_device, device_name) < 0) { |
| 840 | ALOGE("%s: Invalid sound device returned", __func__); |
| 841 | return -EINVAL; |
| 842 | } |
| 843 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 844 | if (adev->snd_dev_ref_cnt[snd_device] == 0) { |
Ravi Kumar Alamanda | c7d9bef | 2015-09-30 22:27:26 -0700 | [diff] [blame] | 845 | ALOGD("%s: snd_device(%d: %s)", __func__, snd_device, device_name); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 846 | |
Xiaojun Sang | 040cc9f | 2015-08-03 19:38:28 +0800 | [diff] [blame] | 847 | if (platform_can_enable_spkr_prot_on_device(snd_device) && |
| 848 | audio_extn_spkr_prot_is_enabled()) { |
Anish Kumar | 46c7b87 | 2014-09-09 01:49:44 -0700 | [diff] [blame] | 849 | audio_extn_spkr_prot_stop_processing(snd_device); |
Haynes Mathew George | bfe8ff4 | 2016-09-22 17:38:16 -0700 | [diff] [blame] | 850 | } else if (platform_split_snd_device(adev->platform, |
| 851 | snd_device, |
| 852 | &num_devices, |
| 853 | new_snd_devices) == 0) { |
Sidipotu Ashok | 9f0b16e | 2016-04-28 13:48:28 +0530 | [diff] [blame] | 854 | for (i = 0; i < num_devices; i++) { |
| 855 | disable_snd_device(adev, new_snd_devices[i]); |
| 856 | } |
Lior Barenboim | 0b61bc7 | 2014-05-13 13:01:37 +0300 | [diff] [blame] | 857 | } else { |
Haynes Mathew George | ef1e3d3 | 2014-04-24 11:53:44 -0700 | [diff] [blame] | 858 | audio_route_reset_and_update_path(adev->audio_route, device_name); |
Lior Barenboim | 0b61bc7 | 2014-05-13 13:01:37 +0300 | [diff] [blame] | 859 | } |
Ravi Kumar Alamanda | 8fa6b19 | 2014-09-09 16:06:42 -0700 | [diff] [blame] | 860 | |
Naresh Tanniru | cd2353e | 2016-08-19 00:37:25 +0530 | [diff] [blame] | 861 | if (SND_DEVICE_OUT_BT_A2DP == snd_device) |
| 862 | audio_extn_a2dp_stop_playback(); |
| 863 | |
Shiv Maliyappanahalli | c065640 | 2016-09-03 14:13:26 -0700 | [diff] [blame] | 864 | if (snd_device == SND_DEVICE_OUT_HDMI || snd_device == SND_DEVICE_OUT_DISPLAY_PORT) |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 865 | adev->is_channel_status_set = false; |
Sidipotu Ashok | e6f78cb | 2015-11-05 14:42:20 +0530 | [diff] [blame] | 866 | else if (SND_DEVICE_OUT_HEADPHONES == snd_device && |
| 867 | adev->native_playback_enabled) { |
| 868 | ALOGD("%s: %d: napb: disabling native mode in hardware", |
| 869 | __func__, __LINE__); |
| 870 | audio_route_reset_and_update_path(adev->audio_route, |
| 871 | "true-native-mode"); |
| 872 | adev->native_playback_enabled = false; |
Preetam Singh Ranawat | b0c0dd7 | 2016-08-18 00:32:06 +0530 | [diff] [blame] | 873 | } else if (SND_DEVICE_OUT_HEADPHONES == snd_device && |
| 874 | adev->asrc_mode_enabled) { |
| 875 | ALOGD("%s: %d: disabling asrc mode in hardware", __func__, __LINE__); |
Preetam Singh Ranawat | 6a83666 | 2016-09-08 17:04:35 +0530 | [diff] [blame] | 876 | disable_asrc_mode(adev); |
| 877 | audio_route_apply_and_update_path(adev->audio_route, "hph-lowpower-mode"); |
Sidipotu Ashok | e6f78cb | 2015-11-05 14:42:20 +0530 | [diff] [blame] | 878 | } |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 879 | |
Ravit Dennis | aaee49c | 2015-02-04 21:26:22 +0200 | [diff] [blame] | 880 | audio_extn_dev_arbi_release(snd_device); |
Ravi Kumar Alamanda | 8fa6b19 | 2014-09-09 16:06:42 -0700 | [diff] [blame] | 881 | audio_extn_sound_trigger_update_device_status(snd_device, |
| 882 | ST_EVENT_SND_DEVICE_FREE); |
Dhananjay Kumar | 45b7174 | 2014-05-29 21:47:27 +0530 | [diff] [blame] | 883 | audio_extn_listen_update_device_status(snd_device, |
Kiran Kandi | de144c8 | 2013-11-20 15:58:32 -0800 | [diff] [blame] | 884 | LISTEN_EVENT_SND_DEVICE_FREE); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 885 | } |
Ravi Kumar Alamanda | 48c921d | 2013-10-29 06:07:44 -0700 | [diff] [blame] | 886 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 887 | return 0; |
| 888 | } |
| 889 | |
Haynes Mathew George | bfe8ff4 | 2016-09-22 17:38:16 -0700 | [diff] [blame] | 890 | /* |
| 891 | legend: |
| 892 | uc - existing usecase |
| 893 | new_uc - new usecase |
| 894 | d1, d11, d2 - SND_DEVICE enums |
| 895 | a1, a2 - corresponding ANDROID device enums |
| 896 | B1, B2 - backend strings |
| 897 | |
| 898 | case 1 |
| 899 | uc->dev d1 (a1) B1 |
| 900 | new_uc->dev d1 (a1), d2 (a2) B1, B2 |
| 901 | |
| 902 | resolution: disable and enable uc->dev on d1 |
| 903 | |
| 904 | case 2 |
| 905 | uc->dev d1 (a1) B1 |
| 906 | new_uc->dev d11 (a1) B1 |
| 907 | |
| 908 | resolution: need to switch uc since d1 and d11 are related |
| 909 | (e.g. speaker and voice-speaker) |
| 910 | use ANDROID_DEVICE_OUT enums to match devices since SND_DEVICE enums may vary |
| 911 | |
| 912 | case 3 |
| 913 | uc->dev d1 (a1) B1 |
| 914 | new_uc->dev d2 (a2) B2 |
| 915 | |
| 916 | resolution: no need to switch uc |
| 917 | |
| 918 | case 4 |
| 919 | uc->dev d1 (a1) B1 |
| 920 | new_uc->dev d2 (a2) B1 |
| 921 | |
| 922 | resolution: disable enable uc-dev on d2 since backends match |
| 923 | we cannot enable two streams on two different devices if they |
| 924 | share the same backend. e.g. if offload is on speaker device using |
| 925 | QUAD_MI2S backend and a low-latency stream is started on voice-handset |
| 926 | using the same backend, offload must also be switched to voice-handset. |
| 927 | |
| 928 | case 5 |
| 929 | uc->dev d1 (a1) B1 |
| 930 | new_uc->dev d1 (a1), d2 (a2) B1 |
| 931 | |
| 932 | resolution: disable enable uc-dev on d2 since backends match |
| 933 | we cannot enable two streams on two different devices if they |
| 934 | share the same backend. |
| 935 | |
| 936 | case 6 |
| 937 | uc->dev d1 (a1) B1 |
| 938 | new_uc->dev d2 (a1) B2 |
| 939 | |
| 940 | resolution: no need to switch |
| 941 | |
| 942 | case 7 |
| 943 | uc->dev d1 (a1), d2 (a2) B1, B2 |
| 944 | new_uc->dev d1 (a1) B1 |
| 945 | |
| 946 | resolution: no need to switch |
| 947 | |
| 948 | */ |
| 949 | static snd_device_t derive_playback_snd_device(void * platform, |
| 950 | struct audio_usecase *uc, |
| 951 | struct audio_usecase *new_uc, |
| 952 | snd_device_t new_snd_device) |
| 953 | { |
| 954 | audio_devices_t a1 = uc->stream.out->devices; |
| 955 | audio_devices_t a2 = new_uc->stream.out->devices; |
| 956 | |
| 957 | snd_device_t d1 = uc->out_snd_device; |
| 958 | snd_device_t d2 = new_snd_device; |
| 959 | |
| 960 | // Treat as a special case when a1 and a2 are not disjoint |
| 961 | if ((a1 != a2) && (a1 & a2)) { |
| 962 | snd_device_t d3[2]; |
| 963 | int num_devices = 0; |
| 964 | int ret = platform_split_snd_device(platform, |
| 965 | popcount(a1) > 1 ? d1 : d2, |
| 966 | &num_devices, |
| 967 | d3); |
| 968 | if (ret < 0) { |
| 969 | if (ret != -ENOSYS) { |
| 970 | ALOGW("%s failed to split snd_device %d", |
| 971 | __func__, |
| 972 | popcount(a1) > 1 ? d1 : d2); |
| 973 | } |
| 974 | goto end; |
| 975 | } |
| 976 | |
| 977 | // NB: case 7 is hypothetical and isn't a practical usecase yet. |
| 978 | // But if it does happen, we need to give priority to d2 if |
| 979 | // the combo devices active on the existing usecase share a backend. |
| 980 | // This is because we cannot have a usecase active on a combo device |
| 981 | // and a new usecase requests one device in this combo pair. |
| 982 | if (platform_check_backends_match(d3[0], d3[1])) { |
| 983 | return d2; // case 5 |
| 984 | } else { |
| 985 | return d1; // case 1 |
| 986 | } |
| 987 | } else { |
| 988 | if (platform_check_backends_match(d1, d2)) { |
| 989 | return d2; // case 2, 4 |
| 990 | } else { |
| 991 | return d1; // case 6, 3 |
| 992 | } |
| 993 | } |
| 994 | |
| 995 | end: |
| 996 | return d2; // return whatever was calculated before. |
| 997 | } |
| 998 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 999 | static void check_usecases_codec_backend(struct audio_device *adev, |
Sidipotu Ashok | 9f0b16e | 2016-04-28 13:48:28 +0530 | [diff] [blame] | 1000 | struct audio_usecase *uc_info, |
| 1001 | snd_device_t snd_device) |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1002 | { |
| 1003 | struct listnode *node; |
| 1004 | struct audio_usecase *usecase; |
| 1005 | bool switch_device[AUDIO_USECASE_MAX]; |
| 1006 | int i, num_uc_to_switch = 0; |
kunleiz | 5cd52b8 | 2016-11-07 17:22:52 +0800 | [diff] [blame] | 1007 | int status = 0; |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1008 | bool force_restart_session = false; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1009 | /* |
| 1010 | * This function is to make sure that all the usecases that are active on |
| 1011 | * the hardware codec backend are always routed to any one device that is |
| 1012 | * handled by the hardware codec. |
| 1013 | * For example, if low-latency and deep-buffer usecases are currently active |
| 1014 | * on speaker and out_set_parameters(headset) is received on low-latency |
| 1015 | * output, then we have to make sure deep-buffer is also switched to headset, |
| 1016 | * because of the limitation that both the devices cannot be enabled |
| 1017 | * at the same time as they share the same backend. |
| 1018 | */ |
Mingming Yin | 3ee55c6 | 2014-08-04 14:23:35 -0700 | [diff] [blame] | 1019 | /* |
| 1020 | * This call is to check if we need to force routing for a particular stream |
| 1021 | * If there is a backend configuration change for the device when a |
| 1022 | * new stream starts, then ADM needs to be closed and re-opened with the new |
| 1023 | * configuraion. This call check if we need to re-route all the streams |
Apoorv Raghuvanshi | 2149216 | 2015-02-19 18:19:36 -0800 | [diff] [blame] | 1024 | * associated with the backend. Touch tone + 24 bit + native playback. |
Mingming Yin | 3ee55c6 | 2014-08-04 14:23:35 -0700 | [diff] [blame] | 1025 | */ |
Apoorv Raghuvanshi | 2149216 | 2015-02-19 18:19:36 -0800 | [diff] [blame] | 1026 | bool force_routing = platform_check_and_set_codec_backend_cfg(adev, uc_info, |
| 1027 | snd_device); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1028 | /* For a2dp device reconfigure all active sessions |
| 1029 | * with new AFE encoder format based on a2dp state |
| 1030 | */ |
| 1031 | if ((SND_DEVICE_OUT_BT_A2DP == snd_device || |
| 1032 | SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device) && |
| 1033 | audio_extn_a2dp_is_force_device_switch()) { |
| 1034 | force_routing = true; |
| 1035 | force_restart_session = true; |
| 1036 | } |
Sidipotu Ashok | e6f78cb | 2015-11-05 14:42:20 +0530 | [diff] [blame] | 1037 | ALOGD("%s:becf: force routing %d", __func__, force_routing); |
| 1038 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1039 | /* Disable all the usecases on the shared backend other than the |
Apoorv Raghuvanshi | f59bb22 | 2015-02-18 12:23:23 -0800 | [diff] [blame] | 1040 | * specified usecase. |
Apoorv Raghuvanshi | f59bb22 | 2015-02-18 12:23:23 -0800 | [diff] [blame] | 1041 | */ |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1042 | for (i = 0; i < AUDIO_USECASE_MAX; i++) |
| 1043 | switch_device[i] = false; |
| 1044 | |
| 1045 | list_for_each(node, &adev->usecase_list) { |
| 1046 | usecase = node_to_item(node, struct audio_usecase, list); |
Apoorv Raghuvanshi | 2149216 | 2015-02-19 18:19:36 -0800 | [diff] [blame] | 1047 | |
Sidipotu Ashok | 9f0b16e | 2016-04-28 13:48:28 +0530 | [diff] [blame] | 1048 | ALOGD("%s:becf: (%d) check_usecases curr device: %s, usecase device:%s " |
| 1049 | "backends match %d",__func__, i, |
Sidipotu Ashok | e6f78cb | 2015-11-05 14:42:20 +0530 | [diff] [blame] | 1050 | platform_get_snd_device_name(snd_device), |
Sidipotu Ashok | 9f0b16e | 2016-04-28 13:48:28 +0530 | [diff] [blame] | 1051 | platform_get_snd_device_name(usecase->out_snd_device), |
| 1052 | platform_check_backends_match(snd_device, usecase->out_snd_device)); |
Shiv Maliyappanahalli | 80ac628 | 2013-12-20 18:56:15 -0800 | [diff] [blame] | 1053 | if (usecase->type != PCM_CAPTURE && |
Sidipotu Ashok | 9f0b16e | 2016-04-28 13:48:28 +0530 | [diff] [blame] | 1054 | usecase != uc_info && |
Haynes Mathew George | bfe8ff4 | 2016-09-22 17:38:16 -0700 | [diff] [blame] | 1055 | (derive_playback_snd_device(adev->platform, |
| 1056 | usecase, uc_info, |
| 1057 | snd_device) != usecase->out_snd_device || force_routing) && |
Ashish Jain | d84fd6a | 2016-07-27 12:33:25 +0530 | [diff] [blame] | 1058 | ((usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) || |
| 1059 | (usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) || |
Ashish Jain | b26edfb | 2016-08-25 00:10:11 +0530 | [diff] [blame] | 1060 | (usecase->devices & AUDIO_DEVICE_OUT_USB_DEVICE) || |
Ashish Jain | c597d10 | 2016-12-12 10:31:34 +0530 | [diff] [blame] | 1061 | (usecase->devices & AUDIO_DEVICE_OUT_ALL_A2DP) || |
| 1062 | (usecase->devices & AUDIO_DEVICE_OUT_ALL_SCO)) && |
| 1063 | ((force_restart_session) || |
| 1064 | (platform_check_backends_match(snd_device, usecase->out_snd_device)))) { |
Preetam Singh Ranawat | 6a83666 | 2016-09-08 17:04:35 +0530 | [diff] [blame] | 1065 | |
Sidipotu Ashok | 9f0b16e | 2016-04-28 13:48:28 +0530 | [diff] [blame] | 1066 | ALOGD("%s:becf: check_usecases (%s) is active on (%s) - disabling ..", |
| 1067 | __func__, use_case_table[usecase->id], |
| 1068 | platform_get_snd_device_name(usecase->out_snd_device)); |
| 1069 | disable_audio_route(adev, usecase); |
| 1070 | switch_device[usecase->id] = true; |
| 1071 | num_uc_to_switch++; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1072 | } |
| 1073 | } |
| 1074 | |
Sidipotu Ashok | e6f78cb | 2015-11-05 14:42:20 +0530 | [diff] [blame] | 1075 | ALOGD("%s:becf: check_usecases num.of Usecases to switch %d", __func__, |
| 1076 | num_uc_to_switch); |
| 1077 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1078 | if (num_uc_to_switch) { |
Haynes Mathew George | ef1e3d3 | 2014-04-24 11:53:44 -0700 | [diff] [blame] | 1079 | /* All streams have been de-routed. Disable the device */ |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1080 | |
Venkata Narendra Kumar Gutta | 7610e63 | 2014-04-14 23:16:38 +0530 | [diff] [blame] | 1081 | /* Make sure the previous devices to be disabled first and then enable the |
| 1082 | selected devices */ |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1083 | list_for_each(node, &adev->usecase_list) { |
| 1084 | usecase = node_to_item(node, struct audio_usecase, list); |
| 1085 | if (switch_device[usecase->id]) { |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 1086 | disable_snd_device(adev, usecase->out_snd_device); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1087 | } |
| 1088 | } |
| 1089 | |
Krishnankutty Kolathappilly | dc4f757 | 2013-11-01 20:07:13 -0700 | [diff] [blame] | 1090 | list_for_each(node, &adev->usecase_list) { |
| 1091 | usecase = node_to_item(node, struct audio_usecase, list); |
| 1092 | if (switch_device[usecase->id]) { |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 1093 | enable_snd_device(adev, snd_device); |
Krishnankutty Kolathappilly | dc4f757 | 2013-11-01 20:07:13 -0700 | [diff] [blame] | 1094 | } |
| 1095 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1096 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1097 | /* Re-route all the usecases on the shared backend other than the |
| 1098 | specified usecase to new snd devices */ |
| 1099 | list_for_each(node, &adev->usecase_list) { |
| 1100 | usecase = node_to_item(node, struct audio_usecase, list); |
Karthik Reddy Katta | 3abfee2 | 2016-02-23 10:55:27 +0530 | [diff] [blame] | 1101 | /* Update the out_snd_device only before enabling the audio route */ |
| 1102 | if (switch_device[usecase->id]) { |
| 1103 | usecase->out_snd_device = snd_device; |
| 1104 | if (usecase->type != VOICE_CALL) { |
Sidipotu Ashok | e6f78cb | 2015-11-05 14:42:20 +0530 | [diff] [blame] | 1105 | ALOGD("%s:becf: enabling usecase (%s) on (%s)", __func__, |
Karthik Reddy Katta | 3abfee2 | 2016-02-23 10:55:27 +0530 | [diff] [blame] | 1106 | use_case_table[usecase->id], |
| 1107 | platform_get_snd_device_name(usecase->out_snd_device)); |
kunleiz | 5cd52b8 | 2016-11-07 17:22:52 +0800 | [diff] [blame] | 1108 | /* Update voc calibration before enabling VoIP route */ |
| 1109 | if (usecase->type == VOIP_CALL) |
| 1110 | status = platform_switch_voice_call_device_post(adev->platform, |
| 1111 | usecase->out_snd_device, |
| 1112 | usecase->in_snd_device); |
Avinash Vaish | 71a8b97 | 2014-07-24 15:36:33 +0530 | [diff] [blame] | 1113 | enable_audio_route(adev, usecase); |
Karthik Reddy Katta | 3abfee2 | 2016-02-23 10:55:27 +0530 | [diff] [blame] | 1114 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1115 | } |
| 1116 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1117 | } |
| 1118 | } |
| 1119 | |
Manish Dewangan | ba9fcfa | 2016-03-24 16:20:06 +0530 | [diff] [blame] | 1120 | static void check_usecases_capture_codec_backend(struct audio_device *adev, |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 1121 | struct audio_usecase *uc_info, |
| 1122 | snd_device_t snd_device) |
| 1123 | { |
| 1124 | struct listnode *node; |
| 1125 | struct audio_usecase *usecase; |
| 1126 | bool switch_device[AUDIO_USECASE_MAX]; |
| 1127 | int i, num_uc_to_switch = 0; |
Dhanalakshmi Siddani | b678a80 | 2016-12-03 11:51:41 +0530 | [diff] [blame] | 1128 | int backend_check_cond = AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND; |
kunleiz | 5cd52b8 | 2016-11-07 17:22:52 +0800 | [diff] [blame] | 1129 | int status = 0; |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 1130 | |
Manish Dewangan | ba9fcfa | 2016-03-24 16:20:06 +0530 | [diff] [blame] | 1131 | bool force_routing = platform_check_and_set_capture_codec_backend_cfg(adev, uc_info, |
| 1132 | snd_device); |
| 1133 | ALOGD("%s:becf: force routing %d", __func__, force_routing); |
Dhanalakshmi Siddani | b678a80 | 2016-12-03 11:51:41 +0530 | [diff] [blame] | 1134 | |
| 1135 | /* |
| 1136 | * Make sure out devices is checked against out codec backend device and |
| 1137 | * also in devices against in codec backend. Checking out device against in |
| 1138 | * codec backend or vice versa causes issues. |
| 1139 | */ |
| 1140 | if (uc_info->type == PCM_CAPTURE) |
| 1141 | backend_check_cond = AUDIO_DEVICE_IN_ALL_CODEC_BACKEND; |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 1142 | /* |
| 1143 | * This function is to make sure that all the active capture usecases |
| 1144 | * are always routed to the same input sound device. |
| 1145 | * For example, if audio-record and voice-call usecases are currently |
| 1146 | * active on speaker(rx) and speaker-mic (tx) and out_set_parameters(earpiece) |
| 1147 | * is received for voice call then we have to make sure that audio-record |
| 1148 | * usecase is also switched to earpiece i.e. voice-dmic-ef, |
| 1149 | * because of the limitation that two devices cannot be enabled |
| 1150 | * at the same time if they share the same backend. |
| 1151 | */ |
| 1152 | for (i = 0; i < AUDIO_USECASE_MAX; i++) |
| 1153 | switch_device[i] = false; |
| 1154 | |
| 1155 | list_for_each(node, &adev->usecase_list) { |
| 1156 | usecase = node_to_item(node, struct audio_usecase, list); |
Dhanalakshmi Siddani | b678a80 | 2016-12-03 11:51:41 +0530 | [diff] [blame] | 1157 | /* |
| 1158 | * TODO: Enhance below condition to handle BT sco/USB multi recording |
| 1159 | */ |
Shiv Maliyappanahalli | 80ac628 | 2013-12-20 18:56:15 -0800 | [diff] [blame] | 1160 | if (usecase->type != PCM_PLAYBACK && |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 1161 | usecase != uc_info && |
Manish Dewangan | ba9fcfa | 2016-03-24 16:20:06 +0530 | [diff] [blame] | 1162 | (usecase->in_snd_device != snd_device || force_routing) && |
Dhanalakshmi Siddani | b678a80 | 2016-12-03 11:51:41 +0530 | [diff] [blame] | 1163 | ((uc_info->devices & backend_check_cond) && |
Karthik Reddy Katta | 0d47176 | 2015-08-20 13:36:07 +0530 | [diff] [blame] | 1164 | (((usecase->devices & ~AUDIO_DEVICE_BIT_IN) & AUDIO_DEVICE_IN_ALL_CODEC_BACKEND) || |
kunleiz | 303ff1a | 2016-03-15 17:40:20 +0800 | [diff] [blame] | 1165 | (usecase->type == VOICE_CALL) || (usecase->type == VOIP_CALL))) && |
Anish Kumar | a020a7c | 2014-10-17 11:13:22 -0700 | [diff] [blame] | 1166 | (usecase->id != USECASE_AUDIO_SPKR_CALIB_TX)) { |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 1167 | ALOGV("%s: Usecase (%s) is active on (%s) - disabling ..", |
| 1168 | __func__, use_case_table[usecase->id], |
Devin Kim | 1e5f353 | 2013-08-09 07:48:29 -0700 | [diff] [blame] | 1169 | platform_get_snd_device_name(usecase->in_snd_device)); |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 1170 | disable_audio_route(adev, usecase); |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 1171 | switch_device[usecase->id] = true; |
| 1172 | num_uc_to_switch++; |
| 1173 | } |
| 1174 | } |
| 1175 | |
| 1176 | if (num_uc_to_switch) { |
Haynes Mathew George | ef1e3d3 | 2014-04-24 11:53:44 -0700 | [diff] [blame] | 1177 | /* All streams have been de-routed. Disable the device */ |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 1178 | |
Venkata Narendra Kumar Gutta | 7610e63 | 2014-04-14 23:16:38 +0530 | [diff] [blame] | 1179 | /* Make sure the previous devices to be disabled first and then enable the |
| 1180 | selected devices */ |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 1181 | list_for_each(node, &adev->usecase_list) { |
| 1182 | usecase = node_to_item(node, struct audio_usecase, list); |
| 1183 | if (switch_device[usecase->id]) { |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 1184 | disable_snd_device(adev, usecase->in_snd_device); |
Shiv Maliyappanahalli | 80ac628 | 2013-12-20 18:56:15 -0800 | [diff] [blame] | 1185 | } |
| 1186 | } |
| 1187 | |
| 1188 | list_for_each(node, &adev->usecase_list) { |
| 1189 | usecase = node_to_item(node, struct audio_usecase, list); |
| 1190 | if (switch_device[usecase->id]) { |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 1191 | enable_snd_device(adev, snd_device); |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 1192 | } |
| 1193 | } |
| 1194 | |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 1195 | /* Re-route all the usecases on the shared backend other than the |
| 1196 | specified usecase to new snd devices */ |
| 1197 | list_for_each(node, &adev->usecase_list) { |
| 1198 | usecase = node_to_item(node, struct audio_usecase, list); |
| 1199 | /* Update the in_snd_device only before enabling the audio route */ |
| 1200 | if (switch_device[usecase->id] ) { |
| 1201 | usecase->in_snd_device = snd_device; |
kunleiz | 5cd52b8 | 2016-11-07 17:22:52 +0800 | [diff] [blame] | 1202 | if (usecase->type != VOICE_CALL) { |
| 1203 | /* Update voc calibration before enabling VoIP route */ |
| 1204 | if (usecase->type == VOIP_CALL) |
| 1205 | status = platform_switch_voice_call_device_post(adev->platform, |
| 1206 | usecase->out_snd_device, |
| 1207 | usecase->in_snd_device); |
Avinash Vaish | 71a8b97 | 2014-07-24 15:36:33 +0530 | [diff] [blame] | 1208 | enable_audio_route(adev, usecase); |
kunleiz | 5cd52b8 | 2016-11-07 17:22:52 +0800 | [diff] [blame] | 1209 | } |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 1210 | } |
| 1211 | } |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 1212 | } |
| 1213 | } |
| 1214 | |
Mingming Yin | 3a941d4 | 2016-02-17 18:08:05 -0800 | [diff] [blame] | 1215 | static void reset_hdmi_sink_caps(struct stream_out *out) { |
| 1216 | int i = 0; |
| 1217 | |
| 1218 | for (i = 0; i<= MAX_SUPPORTED_CHANNEL_MASKS; i++) { |
| 1219 | out->supported_channel_masks[i] = 0; |
| 1220 | } |
| 1221 | for (i = 0; i<= MAX_SUPPORTED_FORMATS; i++) { |
| 1222 | out->supported_formats[i] = 0; |
| 1223 | } |
| 1224 | for (i = 0; i<= MAX_SUPPORTED_SAMPLE_RATES; i++) { |
| 1225 | out->supported_sample_rates[i] = 0; |
| 1226 | } |
| 1227 | } |
| 1228 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1229 | /* must be called with hw device mutex locked */ |
Mingming Yin | 3a941d4 | 2016-02-17 18:08:05 -0800 | [diff] [blame] | 1230 | static int read_hdmi_sink_caps(struct stream_out *out) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1231 | { |
Mingming Yin | 3a941d4 | 2016-02-17 18:08:05 -0800 | [diff] [blame] | 1232 | int ret = 0, i = 0, j = 0; |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 1233 | int channels = platform_edid_get_max_channels(out->dev->platform); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1234 | |
Mingming Yin | 3a941d4 | 2016-02-17 18:08:05 -0800 | [diff] [blame] | 1235 | reset_hdmi_sink_caps(out); |
| 1236 | |
Shiv Maliyappanahalli | c065640 | 2016-09-03 14:13:26 -0700 | [diff] [blame] | 1237 | /* Cache ext disp type */ |
Garmond Leung | 37850ab | 2016-10-06 11:42:18 -0700 | [diff] [blame] | 1238 | if (platform_get_ext_disp_type(adev->platform) <= 0) { |
Shiv Maliyappanahalli | c065640 | 2016-09-03 14:13:26 -0700 | [diff] [blame] | 1239 | ALOGE("%s: Failed to query disp type, ret:%d", __func__, ret); |
Garmond Leung | 37850ab | 2016-10-06 11:42:18 -0700 | [diff] [blame] | 1240 | return -EINVAL; |
Shiv Maliyappanahalli | c065640 | 2016-09-03 14:13:26 -0700 | [diff] [blame] | 1241 | } |
| 1242 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1243 | switch (channels) { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1244 | case 8: |
Mingming Yin | 3a941d4 | 2016-02-17 18:08:05 -0800 | [diff] [blame] | 1245 | ALOGV("%s: HDMI supports 7.1 channels", __func__); |
Pradnya Chaphekar | 4403bd7 | 2014-09-09 09:50:01 -0700 | [diff] [blame] | 1246 | out->supported_channel_masks[i++] = AUDIO_CHANNEL_OUT_7POINT1; |
Mingming Yin | 3a941d4 | 2016-02-17 18:08:05 -0800 | [diff] [blame] | 1247 | out->supported_channel_masks[i++] = AUDIO_CHANNEL_OUT_6POINT1; |
| 1248 | case 6: |
| 1249 | ALOGV("%s: HDMI supports 5.1 channels", __func__); |
| 1250 | out->supported_channel_masks[i++] = AUDIO_CHANNEL_OUT_5POINT1; |
| 1251 | out->supported_channel_masks[i++] = AUDIO_CHANNEL_OUT_PENTA; |
| 1252 | out->supported_channel_masks[i++] = AUDIO_CHANNEL_OUT_QUAD; |
| 1253 | out->supported_channel_masks[i++] = AUDIO_CHANNEL_OUT_SURROUND; |
| 1254 | out->supported_channel_masks[i++] = AUDIO_CHANNEL_OUT_2POINT1; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1255 | break; |
| 1256 | default: |
Mingming Yin | 3a941d4 | 2016-02-17 18:08:05 -0800 | [diff] [blame] | 1257 | ALOGE("invalid/nonstandard channal count[%d]",channels); |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 1258 | ret = -ENOSYS; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1259 | break; |
| 1260 | } |
Mingming Yin | 3a941d4 | 2016-02-17 18:08:05 -0800 | [diff] [blame] | 1261 | |
| 1262 | // check channel format caps |
| 1263 | i = 0; |
| 1264 | if (platform_is_edid_supported_format(out->dev->platform, AUDIO_FORMAT_AC3)) { |
| 1265 | ALOGV(":%s HDMI supports AC3/EAC3 formats", __func__); |
| 1266 | out->supported_formats[i++] = AUDIO_FORMAT_AC3; |
| 1267 | //Adding EAC3/EAC3_JOC formats if AC3 is supported by the sink. |
| 1268 | //EAC3/EAC3_JOC will be converted to AC3 for decoding if needed |
| 1269 | out->supported_formats[i++] = AUDIO_FORMAT_E_AC3; |
| 1270 | out->supported_formats[i++] = AUDIO_FORMAT_E_AC3_JOC; |
| 1271 | } |
| 1272 | |
| 1273 | if (platform_is_edid_supported_format(out->dev->platform, AUDIO_FORMAT_DTS)) { |
| 1274 | ALOGV(":%s HDMI supports DTS format", __func__); |
| 1275 | out->supported_formats[i++] = AUDIO_FORMAT_DTS; |
| 1276 | } |
| 1277 | |
| 1278 | if (platform_is_edid_supported_format(out->dev->platform, AUDIO_FORMAT_DTS_HD)) { |
| 1279 | ALOGV(":%s HDMI supports DTS HD format", __func__); |
| 1280 | out->supported_formats[i++] = AUDIO_FORMAT_DTS_HD; |
| 1281 | } |
| 1282 | |
| 1283 | |
| 1284 | // check sample rate caps |
| 1285 | i = 0; |
| 1286 | for (j = 0; j < MAX_SUPPORTED_SAMPLE_RATES; j++) { |
| 1287 | if (platform_is_edid_supported_sample_rate(out->dev->platform, out_hdmi_sample_rates[j])) { |
| 1288 | ALOGV(":%s HDMI supports sample rate:%d", __func__, out_hdmi_sample_rates[j]); |
| 1289 | out->supported_sample_rates[i++] = out_hdmi_sample_rates[j]; |
| 1290 | } |
| 1291 | } |
| 1292 | |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 1293 | return ret; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1294 | } |
| 1295 | |
Alexy Joseph | b137994 | 2016-01-29 15:49:38 -0800 | [diff] [blame] | 1296 | audio_usecase_t get_usecase_id_from_usecase_type(const struct audio_device *adev, |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 1297 | usecase_type_t type) |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 1298 | { |
| 1299 | struct audio_usecase *usecase; |
| 1300 | struct listnode *node; |
| 1301 | |
| 1302 | list_for_each(node, &adev->usecase_list) { |
| 1303 | usecase = node_to_item(node, struct audio_usecase, list); |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 1304 | if (usecase->type == type) { |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 1305 | ALOGV("%s: usecase id %d", __func__, usecase->id); |
| 1306 | return usecase->id; |
| 1307 | } |
| 1308 | } |
| 1309 | return USECASE_INVALID; |
| 1310 | } |
| 1311 | |
Alexy Joseph | b137994 | 2016-01-29 15:49:38 -0800 | [diff] [blame] | 1312 | struct audio_usecase *get_usecase_from_list(const struct audio_device *adev, |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 1313 | audio_usecase_t uc_id) |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1314 | { |
| 1315 | struct audio_usecase *usecase; |
| 1316 | struct listnode *node; |
| 1317 | |
| 1318 | list_for_each(node, &adev->usecase_list) { |
| 1319 | usecase = node_to_item(node, struct audio_usecase, list); |
| 1320 | if (usecase->id == uc_id) |
| 1321 | return usecase; |
| 1322 | } |
| 1323 | return NULL; |
| 1324 | } |
| 1325 | |
Dhananjay Kumar | d483324 | 2016-10-06 22:09:12 +0530 | [diff] [blame] | 1326 | struct stream_in *get_next_active_input(const struct audio_device *adev) |
| 1327 | { |
| 1328 | struct audio_usecase *usecase; |
| 1329 | struct listnode *node; |
| 1330 | |
| 1331 | list_for_each_reverse(node, &adev->usecase_list) { |
| 1332 | usecase = node_to_item(node, struct audio_usecase, list); |
| 1333 | if (usecase->type == PCM_CAPTURE) |
| 1334 | return usecase->stream.in; |
| 1335 | } |
| 1336 | return NULL; |
| 1337 | } |
| 1338 | |
Sidipotu Ashok | e6f78cb | 2015-11-05 14:42:20 +0530 | [diff] [blame] | 1339 | /* |
| 1340 | * is a true native playback active |
| 1341 | */ |
| 1342 | bool audio_is_true_native_stream_active(struct audio_device *adev) |
| 1343 | { |
| 1344 | bool active = false; |
| 1345 | int i = 0; |
| 1346 | struct listnode *node; |
| 1347 | |
| 1348 | if (NATIVE_AUDIO_MODE_TRUE_44_1 != platform_get_native_support()) { |
| 1349 | ALOGV("%s:napb: not in true mode or non hdphones device", |
| 1350 | __func__); |
| 1351 | active = false; |
| 1352 | goto exit; |
| 1353 | } |
| 1354 | |
| 1355 | list_for_each(node, &adev->usecase_list) { |
| 1356 | struct audio_usecase *uc; |
| 1357 | uc = node_to_item(node, struct audio_usecase, list); |
| 1358 | struct stream_out *curr_out = |
| 1359 | (struct stream_out*) uc->stream.out; |
| 1360 | |
| 1361 | if (curr_out && PCM_PLAYBACK == uc->type) { |
| 1362 | ALOGD("%s:napb: (%d) (%s)id (%d) sr %d bw " |
| 1363 | "(%d) device %s", __func__, i++, use_case_table[uc->id], |
| 1364 | uc->id, curr_out->sample_rate, |
| 1365 | curr_out->bit_width, |
| 1366 | platform_get_snd_device_name(uc->out_snd_device)); |
| 1367 | |
| 1368 | if (is_offload_usecase(uc->id) && |
| 1369 | (curr_out->sample_rate == OUTPUT_SAMPLING_RATE_44100)) { |
| 1370 | active = true; |
| 1371 | ALOGD("%s:napb:native stream detected", __func__); |
| 1372 | } |
| 1373 | } |
| 1374 | } |
| 1375 | exit: |
| 1376 | return active; |
| 1377 | } |
| 1378 | |
Preetam Singh Ranawat | cb6212e | 2016-07-19 18:33:53 +0530 | [diff] [blame] | 1379 | /* |
| 1380 | * if native DSD playback active |
| 1381 | */ |
| 1382 | bool audio_is_dsd_native_stream_active(struct audio_device *adev) |
| 1383 | { |
| 1384 | bool active = false; |
| 1385 | struct listnode *node = NULL; |
| 1386 | struct audio_usecase *uc = NULL; |
| 1387 | struct stream_out *curr_out = NULL; |
| 1388 | |
| 1389 | list_for_each(node, &adev->usecase_list) { |
| 1390 | uc = node_to_item(node, struct audio_usecase, list); |
| 1391 | curr_out = (struct stream_out*) uc->stream.out; |
| 1392 | |
| 1393 | if (curr_out && PCM_PLAYBACK == uc->type && |
| 1394 | (DSD_NATIVE_BACKEND == platform_get_backend_index(uc->out_snd_device))) { |
| 1395 | active = true; |
| 1396 | ALOGV("%s:DSD playback is active", __func__); |
Preetam Singh Ranawat | f5fbdd6 | 2016-09-29 18:38:31 +0530 | [diff] [blame] | 1397 | break; |
Preetam Singh Ranawat | cb6212e | 2016-07-19 18:33:53 +0530 | [diff] [blame] | 1398 | } |
| 1399 | } |
| 1400 | return active; |
| 1401 | } |
Sidipotu Ashok | e6f78cb | 2015-11-05 14:42:20 +0530 | [diff] [blame] | 1402 | |
| 1403 | static bool force_device_switch(struct audio_usecase *usecase) |
| 1404 | { |
| 1405 | bool ret = false; |
| 1406 | bool is_it_true_mode = false; |
| 1407 | |
| 1408 | if (is_offload_usecase(usecase->id) && |
| 1409 | (usecase->stream.out) && |
Xiaojun Sang | 869f201 | 2016-02-23 16:33:07 +0800 | [diff] [blame] | 1410 | (usecase->stream.out->sample_rate == OUTPUT_SAMPLING_RATE_44100) && |
| 1411 | (usecase->stream.out->devices == AUDIO_DEVICE_OUT_WIRED_HEADSET || |
| 1412 | usecase->stream.out->devices == AUDIO_DEVICE_OUT_WIRED_HEADPHONE)) { |
Sidipotu Ashok | e6f78cb | 2015-11-05 14:42:20 +0530 | [diff] [blame] | 1413 | is_it_true_mode = (NATIVE_AUDIO_MODE_TRUE_44_1 == platform_get_native_support()? true : false); |
| 1414 | if ((is_it_true_mode && !adev->native_playback_enabled) || |
| 1415 | (!is_it_true_mode && adev->native_playback_enabled)){ |
| 1416 | ret = true; |
| 1417 | ALOGD("napb: time to toggle native mode"); |
| 1418 | } |
| 1419 | } |
| 1420 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1421 | // Force all a2dp output devices to reconfigure for proper AFE encode format |
Ashish Jain | c597d10 | 2016-12-12 10:31:34 +0530 | [diff] [blame] | 1422 | //Also handle a case where in earlier a2dp start failed as A2DP stream was |
| 1423 | //in suspended state, hence try to trigger a retry when we again get a routing request. |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1424 | if((usecase->stream.out) && |
Naresh Tanniru | f7e9e63 | 2016-11-04 14:54:20 -0700 | [diff] [blame] | 1425 | (usecase->stream.out->devices & AUDIO_DEVICE_OUT_ALL_A2DP) && |
Ashish Jain | c597d10 | 2016-12-12 10:31:34 +0530 | [diff] [blame] | 1426 | audio_extn_a2dp_is_force_device_switch()) { |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 1427 | ALOGD("Force a2dp device switch to update new encoder config"); |
| 1428 | ret = true; |
| 1429 | } |
| 1430 | |
Sidipotu Ashok | e6f78cb | 2015-11-05 14:42:20 +0530 | [diff] [blame] | 1431 | return ret; |
| 1432 | } |
| 1433 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 1434 | 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] | 1435 | { |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1436 | snd_device_t out_snd_device = SND_DEVICE_NONE; |
| 1437 | snd_device_t in_snd_device = SND_DEVICE_NONE; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1438 | struct audio_usecase *usecase = NULL; |
| 1439 | struct audio_usecase *vc_usecase = NULL; |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 1440 | struct audio_usecase *voip_usecase = NULL; |
Vimal Puthanveed | 37b4a1c | 2014-01-07 16:47:47 -0800 | [diff] [blame] | 1441 | struct audio_usecase *hfp_usecase = NULL; |
Vimal Puthanveed | 41fcff2 | 2014-01-23 15:56:53 -0800 | [diff] [blame] | 1442 | audio_usecase_t hfp_ucid; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1443 | int status = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1444 | |
Sidipotu Ashok | e6f78cb | 2015-11-05 14:42:20 +0530 | [diff] [blame] | 1445 | ALOGD("%s for use case (%s)", __func__, use_case_table[uc_id]); |
| 1446 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1447 | usecase = get_usecase_from_list(adev, uc_id); |
| 1448 | if (usecase == NULL) { |
| 1449 | ALOGE("%s: Could not find the usecase(%d)", __func__, uc_id); |
| 1450 | return -EINVAL; |
| 1451 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1452 | |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 1453 | if ((usecase->type == VOICE_CALL) || |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 1454 | (usecase->type == VOIP_CALL) || |
| 1455 | (usecase->type == PCM_HFP_CALL)) { |
Aditya Bavanari | bdda2f2 | 2016-10-19 15:02:05 +0530 | [diff] [blame] | 1456 | if(usecase->stream.out == NULL) { |
| 1457 | ALOGE("%s: stream.out is NULL", __func__); |
| 1458 | return -EINVAL; |
| 1459 | } |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1460 | out_snd_device = platform_get_output_snd_device(adev->platform, |
Apoorv Raghuvanshi | f59bb22 | 2015-02-18 12:23:23 -0800 | [diff] [blame] | 1461 | usecase->stream.out); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1462 | 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] | 1463 | usecase->devices = usecase->stream.out->devices; |
| 1464 | } else { |
| 1465 | /* |
| 1466 | * If the voice call is active, use the sound devices of voice call usecase |
| 1467 | * so that it would not result any device switch. All the usecases will |
| 1468 | * be switched to new device when select_devices() is called for voice call |
| 1469 | * usecase. This is to avoid switching devices for voice call when |
| 1470 | * check_usecases_codec_backend() is called below. |
Alexy Joseph | 79dfa3c | 2016-04-20 18:44:56 -0700 | [diff] [blame] | 1471 | * choose voice call device only if the use case device is |
| 1472 | * also using the codec backend |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1473 | */ |
Shiv Maliyappanahalli | bb4cf0b | 2016-01-21 11:30:06 -0800 | [diff] [blame] | 1474 | if (voice_is_in_call(adev) && adev->mode != AUDIO_MODE_NORMAL) { |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 1475 | vc_usecase = get_usecase_from_list(adev, |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 1476 | get_usecase_id_from_usecase_type(adev, VOICE_CALL)); |
Alexy Joseph | dbcddf2 | 2016-05-16 17:54:09 -0700 | [diff] [blame] | 1477 | if ((vc_usecase) && (((vc_usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) && |
| 1478 | (usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND)) || |
Preetam Singh Ranawat | 097cb1f | 2016-07-19 13:49:04 +0530 | [diff] [blame] | 1479 | ((vc_usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) && |
| 1480 | (usecase->devices & AUDIO_DEVICE_IN_ALL_CODEC_BACKEND)) || |
Alexy Joseph | dbcddf2 | 2016-05-16 17:54:09 -0700 | [diff] [blame] | 1481 | (usecase->devices == AUDIO_DEVICE_IN_VOICE_CALL))) { |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1482 | in_snd_device = vc_usecase->in_snd_device; |
| 1483 | out_snd_device = vc_usecase->out_snd_device; |
| 1484 | } |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 1485 | } else if (voice_extn_compress_voip_is_active(adev)) { |
| 1486 | voip_usecase = get_usecase_from_list(adev, USECASE_COMPRESS_VOIP_CALL); |
Mingming Yin | 2d8aa2e | 2014-08-14 00:00:51 -0700 | [diff] [blame] | 1487 | if ((voip_usecase) && ((voip_usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) && |
Zhou Song | 0154bf1 | 2016-08-04 10:48:16 +0800 | [diff] [blame] | 1488 | ((usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) || |
| 1489 | ((usecase->devices & ~AUDIO_DEVICE_BIT_IN) & AUDIO_DEVICE_IN_ALL_CODEC_BACKEND)) && |
Mingming Yin | 2d8aa2e | 2014-08-14 00:00:51 -0700 | [diff] [blame] | 1490 | (voip_usecase->stream.out != adev->primary_output))) { |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 1491 | in_snd_device = voip_usecase->in_snd_device; |
| 1492 | out_snd_device = voip_usecase->out_snd_device; |
| 1493 | } |
Vimal Puthanveed | 37b4a1c | 2014-01-07 16:47:47 -0800 | [diff] [blame] | 1494 | } else if (audio_extn_hfp_is_active(adev)) { |
Vimal Puthanveed | 41fcff2 | 2014-01-23 15:56:53 -0800 | [diff] [blame] | 1495 | hfp_ucid = audio_extn_hfp_get_usecase(); |
| 1496 | hfp_usecase = get_usecase_from_list(adev, hfp_ucid); |
Mingming Yin | 2d8aa2e | 2014-08-14 00:00:51 -0700 | [diff] [blame] | 1497 | if ((hfp_usecase) && (hfp_usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND)) { |
Vimal Puthanveed | 37b4a1c | 2014-01-07 16:47:47 -0800 | [diff] [blame] | 1498 | in_snd_device = hfp_usecase->in_snd_device; |
| 1499 | out_snd_device = hfp_usecase->out_snd_device; |
| 1500 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1501 | } |
| 1502 | if (usecase->type == PCM_PLAYBACK) { |
Aditya Bavanari | bdda2f2 | 2016-10-19 15:02:05 +0530 | [diff] [blame] | 1503 | if (usecase->stream.out == NULL) { |
| 1504 | ALOGE("%s: stream.out is NULL", __func__); |
| 1505 | return -EINVAL; |
| 1506 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1507 | usecase->devices = usecase->stream.out->devices; |
| 1508 | in_snd_device = SND_DEVICE_NONE; |
Ravi Kumar Alamanda | 59d296d | 2013-05-02 11:25:27 -0700 | [diff] [blame] | 1509 | if (out_snd_device == SND_DEVICE_NONE) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1510 | out_snd_device = platform_get_output_snd_device(adev->platform, |
Apoorv Raghuvanshi | f59bb22 | 2015-02-18 12:23:23 -0800 | [diff] [blame] | 1511 | usecase->stream.out); |
Ravi Kumar Alamanda | 59d296d | 2013-05-02 11:25:27 -0700 | [diff] [blame] | 1512 | if (usecase->stream.out == adev->primary_output && |
| 1513 | adev->active_input && |
Ravi Kumar Alamanda | d1c85bb | 2014-11-17 18:36:24 -0800 | [diff] [blame] | 1514 | out_snd_device != usecase->out_snd_device) { |
Ravi Kumar Alamanda | 59d296d | 2013-05-02 11:25:27 -0700 | [diff] [blame] | 1515 | select_devices(adev, adev->active_input->usecase); |
| 1516 | } |
| 1517 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1518 | } else if (usecase->type == PCM_CAPTURE) { |
Aditya Bavanari | bdda2f2 | 2016-10-19 15:02:05 +0530 | [diff] [blame] | 1519 | if (usecase->stream.in == NULL) { |
| 1520 | ALOGE("%s: stream.in is NULL", __func__); |
| 1521 | return -EINVAL; |
| 1522 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1523 | usecase->devices = usecase->stream.in->device; |
| 1524 | out_snd_device = SND_DEVICE_NONE; |
Ravi Kumar Alamanda | 59d296d | 2013-05-02 11:25:27 -0700 | [diff] [blame] | 1525 | if (in_snd_device == SND_DEVICE_NONE) { |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 1526 | audio_devices_t out_device = AUDIO_DEVICE_NONE; |
Leena Winterrowd | 3c8fbae | 2016-01-12 15:05:53 -0800 | [diff] [blame] | 1527 | if (adev->active_input && |
| 1528 | (adev->active_input->source == AUDIO_SOURCE_VOICE_COMMUNICATION || |
Karthik Reddy Katta | f621ec7 | 2014-11-21 16:37:38 +0530 | [diff] [blame] | 1529 | (adev->mode == AUDIO_MODE_IN_COMMUNICATION && |
| 1530 | adev->active_input->source == AUDIO_SOURCE_MIC)) && |
| 1531 | adev->primary_output && !adev->primary_output->standby) { |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 1532 | out_device = adev->primary_output->devices; |
Apoorv Raghuvanshi | 924b302 | 2015-07-06 15:07:14 -0700 | [diff] [blame] | 1533 | platform_set_echo_reference(adev, false, AUDIO_DEVICE_NONE); |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 1534 | } else if (usecase->id == USECASE_AUDIO_RECORD_AFE_PROXY) { |
| 1535 | out_device = AUDIO_DEVICE_OUT_TELEPHONY_TX; |
Ravi Kumar Alamanda | 59d296d | 2013-05-02 11:25:27 -0700 | [diff] [blame] | 1536 | } |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 1537 | 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] | 1538 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1539 | } |
| 1540 | } |
| 1541 | |
| 1542 | if (out_snd_device == usecase->out_snd_device && |
| 1543 | in_snd_device == usecase->in_snd_device) { |
Sidipotu Ashok | e6f78cb | 2015-11-05 14:42:20 +0530 | [diff] [blame] | 1544 | |
| 1545 | if (!force_device_switch(usecase)) |
| 1546 | return 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1547 | } |
| 1548 | |
sangwoo | bc67724 | 2013-08-08 16:53:43 +0900 | [diff] [blame] | 1549 | 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] | 1550 | out_snd_device, platform_get_snd_device_name(out_snd_device), |
| 1551 | in_snd_device, platform_get_snd_device_name(in_snd_device)); |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1552 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1553 | /* |
| 1554 | * Limitation: While in call, to do a device switch we need to disable |
| 1555 | * and enable both RX and TX devices though one of them is same as current |
| 1556 | * device. |
| 1557 | */ |
Vidyakumar Athota | 21b3bb9 | 2014-04-25 11:08:08 -0700 | [diff] [blame] | 1558 | if ((usecase->type == VOICE_CALL) && |
| 1559 | (usecase->in_snd_device != SND_DEVICE_NONE) && |
| 1560 | (usecase->out_snd_device != SND_DEVICE_NONE)) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1561 | status = platform_switch_voice_call_device_pre(adev->platform); |
Narsinga Rao Chella | 116142b | 2015-08-14 18:00:08 -0700 | [diff] [blame] | 1562 | } |
| 1563 | |
| 1564 | if (((usecase->type == VOICE_CALL) || |
| 1565 | (usecase->type == VOIP_CALL)) && |
| 1566 | (usecase->out_snd_device != SND_DEVICE_NONE)) { |
| 1567 | /* Disable sidetone only if voice/voip call already exists */ |
| 1568 | if (voice_is_call_state_active(adev) || |
| 1569 | voice_extn_compress_voip_is_started(adev)) |
Bhalchandra Gajare | 45fee28 | 2015-06-09 22:23:45 -0700 | [diff] [blame] | 1570 | voice_set_sidetone(adev, usecase->out_snd_device, false); |
Vidyakumar Athota | ea269c6 | 2016-10-31 09:05:59 -0700 | [diff] [blame] | 1571 | |
| 1572 | /* Disable aanc only if voice call exists */ |
| 1573 | if (voice_is_call_state_active(adev)) |
| 1574 | voice_check_and_update_aanc_path(adev, usecase->out_snd_device, false); |
Ravi Kumar Alamanda | 610e8cc | 2013-02-12 01:42:38 -0800 | [diff] [blame] | 1575 | } |
| 1576 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1577 | /* Disable current sound devices */ |
| 1578 | if (usecase->out_snd_device != SND_DEVICE_NONE) { |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 1579 | disable_audio_route(adev, usecase); |
| 1580 | disable_snd_device(adev, usecase->out_snd_device); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1581 | } |
| 1582 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1583 | if (usecase->in_snd_device != SND_DEVICE_NONE) { |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 1584 | disable_audio_route(adev, usecase); |
| 1585 | disable_snd_device(adev, usecase->in_snd_device); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1586 | } |
| 1587 | |
Vidyakumar Athota | 545dbd3 | 2013-11-13 17:30:53 -0800 | [diff] [blame] | 1588 | /* Applicable only on the targets that has external modem. |
| 1589 | * New device information should be sent to modem before enabling |
| 1590 | * the devices to reduce in-call device switch time. |
| 1591 | */ |
Vidyakumar Athota | 21b3bb9 | 2014-04-25 11:08:08 -0700 | [diff] [blame] | 1592 | if ((usecase->type == VOICE_CALL) && |
| 1593 | (usecase->in_snd_device != SND_DEVICE_NONE) && |
| 1594 | (usecase->out_snd_device != SND_DEVICE_NONE)) { |
Vidyakumar Athota | 545dbd3 | 2013-11-13 17:30:53 -0800 | [diff] [blame] | 1595 | status = platform_switch_voice_call_enable_device_config(adev->platform, |
| 1596 | out_snd_device, |
| 1597 | in_snd_device); |
Vidyakumar Athota | 21b3bb9 | 2014-04-25 11:08:08 -0700 | [diff] [blame] | 1598 | } |
Vidyakumar Athota | 545dbd3 | 2013-11-13 17:30:53 -0800 | [diff] [blame] | 1599 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1600 | /* Enable new sound devices */ |
| 1601 | if (out_snd_device != SND_DEVICE_NONE) { |
Kuirong Wang | a9f7cee | 2016-03-07 11:21:52 -0800 | [diff] [blame] | 1602 | check_usecases_codec_backend(adev, usecase, out_snd_device); |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 1603 | enable_snd_device(adev, out_snd_device); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1604 | } |
| 1605 | |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 1606 | if (in_snd_device != SND_DEVICE_NONE) { |
Manish Dewangan | ba9fcfa | 2016-03-24 16:20:06 +0530 | [diff] [blame] | 1607 | check_usecases_capture_codec_backend(adev, usecase, in_snd_device); |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 1608 | enable_snd_device(adev, in_snd_device); |
Ravi Kumar Alamanda | c4ba743 | 2013-06-05 14:11:39 -0700 | [diff] [blame] | 1609 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1610 | |
Avinash Vaish | 71a8b97 | 2014-07-24 15:36:33 +0530 | [diff] [blame] | 1611 | if (usecase->type == VOICE_CALL || usecase->type == VOIP_CALL) { |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1612 | status = platform_switch_voice_call_device_post(adev->platform, |
| 1613 | out_snd_device, |
| 1614 | in_snd_device); |
Avinash Vaish | 71a8b97 | 2014-07-24 15:36:33 +0530 | [diff] [blame] | 1615 | enable_audio_route_for_voice_usecases(adev, usecase); |
| 1616 | } |
Ravi Kumar Alamanda | 610e8cc | 2013-02-12 01:42:38 -0800 | [diff] [blame] | 1617 | |
sangwoo | 170731f | 2013-06-08 15:36:36 +0900 | [diff] [blame] | 1618 | usecase->in_snd_device = in_snd_device; |
| 1619 | usecase->out_snd_device = out_snd_device; |
| 1620 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 1621 | audio_extn_utils_update_stream_app_type_cfg_for_usecase(adev, |
| 1622 | usecase); |
Preetam Singh Ranawat | a4a37d8 | 2014-09-25 16:56:38 +0530 | [diff] [blame] | 1623 | if (usecase->type == PCM_PLAYBACK) { |
Weiyin Jiang | 6f4c806 | 2016-11-23 15:30:29 +0800 | [diff] [blame] | 1624 | if ((24 == usecase->stream.out->bit_width) && |
| 1625 | (usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER)) { |
| 1626 | usecase->stream.out->app_type_cfg.sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; |
| 1627 | } else if ((out_snd_device == SND_DEVICE_OUT_HDMI || |
| 1628 | out_snd_device == SND_DEVICE_OUT_USB_HEADSET || |
| 1629 | out_snd_device == SND_DEVICE_OUT_DISPLAY_PORT) && |
| 1630 | (usecase->stream.out->sample_rate >= OUTPUT_SAMPLING_RATE_44100)) { |
| 1631 | /* |
| 1632 | * To best utlize DSP, check if the stream sample rate is supported/multiple of |
| 1633 | * configured device sample rate, if not update the COPP rate to be equal to the |
| 1634 | * device sample rate, else open COPP at stream sample rate |
| 1635 | */ |
| 1636 | platform_check_and_update_copp_sample_rate(adev->platform, out_snd_device, |
| 1637 | usecase->stream.out->sample_rate, |
| 1638 | &usecase->stream.out->app_type_cfg.sample_rate); |
| 1639 | } else if ((out_snd_device != SND_DEVICE_OUT_HEADPHONES_44_1 && |
| 1640 | usecase->stream.out->sample_rate == OUTPUT_SAMPLING_RATE_44100) || |
| 1641 | (usecase->stream.out->sample_rate < OUTPUT_SAMPLING_RATE_44100)) { |
| 1642 | usecase->stream.out->app_type_cfg.sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; |
| 1643 | } |
| 1644 | |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 1645 | /* Notify device change info to effect clients registered */ |
Weiyin Jiang | 6f4c806 | 2016-11-23 15:30:29 +0800 | [diff] [blame] | 1646 | pthread_mutex_unlock(&adev->lock); |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 1647 | audio_extn_gef_notify_device_config( |
| 1648 | usecase->stream.out->devices, |
| 1649 | usecase->stream.out->channel_mask, |
Weiyin Jiang | 6f4c806 | 2016-11-23 15:30:29 +0800 | [diff] [blame] | 1650 | usecase->stream.out->app_type_cfg.sample_rate, |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 1651 | platform_get_snd_device_acdb_id(usecase->out_snd_device)); |
Weiyin Jiang | 6f4c806 | 2016-11-23 15:30:29 +0800 | [diff] [blame] | 1652 | pthread_mutex_lock(&adev->lock); |
Preetam Singh Ranawat | a4a37d8 | 2014-09-25 16:56:38 +0530 | [diff] [blame] | 1653 | } |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 1654 | enable_audio_route(adev, usecase); |
sangwoo | 170731f | 2013-06-08 15:36:36 +0900 | [diff] [blame] | 1655 | |
Vidyakumar Athota | 493f289 | 2016-08-14 11:56:55 -0700 | [diff] [blame] | 1656 | if (usecase->type == VOICE_CALL || usecase->type == VOIP_CALL) { |
Vidyakumar Athota | ea269c6 | 2016-10-31 09:05:59 -0700 | [diff] [blame] | 1657 | /* Enable aanc only if voice call exists */ |
| 1658 | if (voice_is_call_state_active(adev)) |
| 1659 | voice_check_and_update_aanc_path(adev, out_snd_device, true); |
| 1660 | |
Vidyakumar Athota | 493f289 | 2016-08-14 11:56:55 -0700 | [diff] [blame] | 1661 | /* Enable sidetone only if other voice/voip call already exists */ |
| 1662 | if (voice_is_call_state_active(adev) || |
| 1663 | voice_extn_compress_voip_is_started(adev)) |
| 1664 | voice_set_sidetone(adev, out_snd_device, true); |
| 1665 | } |
| 1666 | |
Vidyakumar Athota | 1fd2179 | 2013-11-15 14:50:57 -0800 | [diff] [blame] | 1667 | /* Applicable only on the targets that has external modem. |
| 1668 | * Enable device command should be sent to modem only after |
| 1669 | * enabling voice call mixer controls |
| 1670 | */ |
Vidyakumar Athota | 339342f | 2014-07-01 15:30:57 -0700 | [diff] [blame] | 1671 | if (usecase->type == VOICE_CALL) |
Vidyakumar Athota | 1fd2179 | 2013-11-15 14:50:57 -0800 | [diff] [blame] | 1672 | status = platform_switch_voice_call_usecase_route_post(adev->platform, |
| 1673 | out_snd_device, |
| 1674 | in_snd_device); |
Sidipotu Ashok | f43018c | 2014-05-02 16:21:50 +0530 | [diff] [blame] | 1675 | ALOGD("%s: done",__func__); |
| 1676 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1677 | return status; |
| 1678 | } |
| 1679 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1680 | static int stop_input_stream(struct stream_in *in) |
| 1681 | { |
Satya Krishna Pindiproli | f1cd92b | 2016-04-14 19:05:23 +0530 | [diff] [blame] | 1682 | int ret = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1683 | struct audio_usecase *uc_info; |
| 1684 | struct audio_device *adev = in->dev; |
| 1685 | |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 1686 | ALOGV("%s: enter: usecase(%d: %s)", __func__, |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1687 | in->usecase, use_case_table[in->usecase]); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1688 | uc_info = get_usecase_from_list(adev, in->usecase); |
| 1689 | if (uc_info == NULL) { |
| 1690 | ALOGE("%s: Could not find the usecase (%d) in the list", |
| 1691 | __func__, in->usecase); |
| 1692 | return -EINVAL; |
| 1693 | } |
| 1694 | |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 1695 | /* Close in-call recording streams */ |
| 1696 | voice_check_and_stop_incall_rec_usecase(adev, in); |
| 1697 | |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 1698 | /* 1. Disable stream specific mixer controls */ |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 1699 | disable_audio_route(adev, uc_info); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1700 | |
| 1701 | /* 2. Disable the tx device */ |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 1702 | disable_snd_device(adev, uc_info->in_snd_device); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1703 | |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 1704 | list_remove(&uc_info->list); |
| 1705 | free(uc_info); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1706 | |
Aalique Grahame | 2e9b2e4 | 2016-12-07 12:43:48 -0800 | [diff] [blame] | 1707 | adev->active_input = get_next_active_input(adev); |
| 1708 | |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 1709 | ALOGV("%s: exit: status(%d)", __func__, ret); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1710 | return ret; |
| 1711 | } |
| 1712 | |
| 1713 | int start_input_stream(struct stream_in *in) |
| 1714 | { |
| 1715 | /* 1. Enable output device and stream routing controls */ |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 1716 | int ret = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1717 | struct audio_usecase *uc_info; |
| 1718 | struct audio_device *adev = in->dev; |
Naresh Tanniru | 8065983 | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 1719 | int snd_card_status = get_snd_card_state(adev); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1720 | |
Mingming Yin | 2664a5b | 2015-09-03 10:53:11 -0700 | [diff] [blame] | 1721 | int usecase = platform_update_usecase_from_source(in->source,in->usecase); |
| 1722 | if (get_usecase_from_list(adev, usecase) == NULL) |
| 1723 | in->usecase = usecase; |
Sidipotu Ashok | f43018c | 2014-05-02 16:21:50 +0530 | [diff] [blame] | 1724 | ALOGD("%s: enter: stream(%p)usecase(%d: %s)", |
| 1725 | __func__, &in->stream, in->usecase, use_case_table[in->usecase]); |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 1726 | |
Naresh Tanniru | 8065983 | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 1727 | |
| 1728 | if (SND_CARD_STATE_OFFLINE == snd_card_status) { |
Naresh Tanniru | 4c63039 | 2014-05-12 01:05:52 +0530 | [diff] [blame] | 1729 | ALOGE("%s: sound card is not active/SSR returning error", __func__); |
Dhanalakshmi Siddani | 4d57e99 | 2014-07-17 16:37:51 +0530 | [diff] [blame] | 1730 | ret = -EIO; |
Naresh Tanniru | 4c63039 | 2014-05-12 01:05:52 +0530 | [diff] [blame] | 1731 | goto error_config; |
| 1732 | } |
Naresh Tanniru | 4c63039 | 2014-05-12 01:05:52 +0530 | [diff] [blame] | 1733 | |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 1734 | /* Check if source matches incall recording usecase criteria */ |
| 1735 | ret = voice_check_and_set_incall_rec_usecase(adev, in); |
| 1736 | if (ret) |
| 1737 | goto error_config; |
| 1738 | else |
Mingming Yin | 2664a5b | 2015-09-03 10:53:11 -0700 | [diff] [blame] | 1739 | ALOGV("%s: usecase(%d)", __func__, in->usecase); |
| 1740 | |
| 1741 | if (get_usecase_from_list(adev, in->usecase) != NULL) { |
| 1742 | ALOGE("%s: use case assigned already in use, stream(%p)usecase(%d: %s)", |
| 1743 | __func__, &in->stream, in->usecase, use_case_table[in->usecase]); |
Zhou Song | 4e0704d | 2016-04-20 13:00:14 +0800 | [diff] [blame] | 1744 | return -EINVAL; |
Mingming Yin | 2664a5b | 2015-09-03 10:53:11 -0700 | [diff] [blame] | 1745 | } |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 1746 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 1747 | 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] | 1748 | if (in->pcm_device_id < 0) { |
| 1749 | ALOGE("%s: Could not find PCM device id for the usecase(%d)", |
| 1750 | __func__, in->usecase); |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 1751 | ret = -EINVAL; |
| 1752 | goto error_config; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1753 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1754 | |
| 1755 | adev->active_input = in; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1756 | uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase)); |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 1757 | |
| 1758 | if (!uc_info) { |
| 1759 | ret = -ENOMEM; |
| 1760 | goto error_config; |
| 1761 | } |
| 1762 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1763 | uc_info->id = in->usecase; |
| 1764 | uc_info->type = PCM_CAPTURE; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 1765 | uc_info->stream.in = in; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1766 | uc_info->devices = in->device; |
| 1767 | uc_info->in_snd_device = SND_DEVICE_NONE; |
| 1768 | uc_info->out_snd_device = SND_DEVICE_NONE; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1769 | |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 1770 | list_add_tail(&adev->usecase_list, &uc_info->list); |
Sudheer Papothi | fa9d228 | 2015-09-17 01:53:25 +0530 | [diff] [blame] | 1771 | audio_extn_perf_lock_acquire(&adev->perf_lock_handle, 0, |
| 1772 | adev->perf_lock_opts, |
| 1773 | adev->perf_lock_opts_size); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1774 | select_devices(adev, in->usecase); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1775 | |
Manish Dewangan | ba9fcfa | 2016-03-24 16:20:06 +0530 | [diff] [blame] | 1776 | ALOGV("%s: Opening PCM device card_id(%d) device_id(%d), channels %d format %d", |
| 1777 | __func__, adev->snd_card, in->pcm_device_id, in->config.channels, in->config.format); |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 1778 | |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 1779 | if (audio_extn_cin_attached_usecase(in->usecase)) { |
| 1780 | ret = audio_extn_cin_start_input_stream(in); |
| 1781 | if (ret) |
| 1782 | goto error_open; |
| 1783 | else |
| 1784 | goto done_open; |
| 1785 | } |
| 1786 | |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 1787 | unsigned int flags = PCM_IN; |
| 1788 | unsigned int pcm_open_retry_count = 0; |
| 1789 | |
| 1790 | if (in->usecase == USECASE_AUDIO_RECORD_AFE_PROXY) { |
| 1791 | flags |= PCM_MMAP | PCM_NOIRQ; |
| 1792 | pcm_open_retry_count = PROXY_OPEN_RETRY_COUNT; |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 1793 | } else if (in->realtime) { |
| 1794 | flags |= PCM_MMAP | PCM_NOIRQ; |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | while (1) { |
| 1798 | in->pcm = pcm_open(adev->snd_card, in->pcm_device_id, |
| 1799 | flags, &in->config); |
| 1800 | if (in->pcm == NULL || !pcm_is_ready(in->pcm)) { |
| 1801 | ALOGE("%s: %s", __func__, pcm_get_error(in->pcm)); |
| 1802 | if (in->pcm != NULL) { |
| 1803 | pcm_close(in->pcm); |
| 1804 | in->pcm = NULL; |
| 1805 | } |
| 1806 | if (pcm_open_retry_count-- == 0) { |
| 1807 | ret = -EIO; |
| 1808 | goto error_open; |
| 1809 | } |
| 1810 | usleep(PROXY_OPEN_WAIT_TIME * 1000); |
| 1811 | continue; |
| 1812 | } |
| 1813 | break; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1814 | } |
Ravi Kumar Alamanda | c7d9bef | 2015-09-30 22:27:26 -0700 | [diff] [blame] | 1815 | |
| 1816 | ALOGV("%s: pcm_prepare", __func__); |
| 1817 | ret = pcm_prepare(in->pcm); |
| 1818 | if (ret < 0) { |
| 1819 | ALOGE("%s: pcm_prepare returned %d", __func__, ret); |
| 1820 | pcm_close(in->pcm); |
| 1821 | in->pcm = NULL; |
| 1822 | goto error_open; |
| 1823 | } |
| 1824 | |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 1825 | register_in_stream(in); |
| 1826 | if (in->realtime) { |
| 1827 | ret = pcm_start(in->pcm); |
| 1828 | if (ret < 0) |
| 1829 | goto error_open; |
| 1830 | } |
| 1831 | |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 1832 | done_open: |
Sudheer Papothi | fa9d228 | 2015-09-17 01:53:25 +0530 | [diff] [blame] | 1833 | audio_extn_perf_lock_release(&adev->perf_lock_handle); |
Ravi Kumar Alamanda | c7d9bef | 2015-09-30 22:27:26 -0700 | [diff] [blame] | 1834 | ALOGD("%s: exit", __func__); |
Ravi Kumar Alamanda | 8a0f977 | 2015-06-15 10:35:19 -0700 | [diff] [blame] | 1835 | |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 1836 | return ret; |
| 1837 | |
| 1838 | error_open: |
Sudheer Papothi | fa9d228 | 2015-09-17 01:53:25 +0530 | [diff] [blame] | 1839 | audio_extn_perf_lock_release(&adev->perf_lock_handle); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1840 | stop_input_stream(in); |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 1841 | error_config: |
Dhananjay Kumar | d483324 | 2016-10-06 22:09:12 +0530 | [diff] [blame] | 1842 | adev->active_input = get_next_active_input(adev); |
Laxminath Kasam | 2cb4b75 | 2015-09-24 03:59:15 +0530 | [diff] [blame] | 1843 | /* |
| 1844 | * sleep 50ms to allow sufficient time for kernel |
| 1845 | * drivers to recover incases like SSR. |
| 1846 | */ |
| 1847 | usleep(50000); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 1848 | ALOGD("%s: exit: status(%d)", __func__, ret); |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 1849 | |
| 1850 | return ret; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1851 | } |
| 1852 | |
Shiv Maliyappanahalli | 736d4ce | 2015-09-28 15:23:06 -0700 | [diff] [blame] | 1853 | void lock_input_stream(struct stream_in *in) |
| 1854 | { |
| 1855 | pthread_mutex_lock(&in->pre_lock); |
| 1856 | pthread_mutex_lock(&in->lock); |
| 1857 | pthread_mutex_unlock(&in->pre_lock); |
| 1858 | } |
| 1859 | |
| 1860 | void lock_output_stream(struct stream_out *out) |
| 1861 | { |
| 1862 | pthread_mutex_lock(&out->pre_lock); |
| 1863 | pthread_mutex_lock(&out->lock); |
| 1864 | pthread_mutex_unlock(&out->pre_lock); |
| 1865 | } |
| 1866 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1867 | /* must be called with out->lock locked */ |
| 1868 | static int send_offload_cmd_l(struct stream_out* out, int command) |
| 1869 | { |
| 1870 | struct offload_cmd *cmd = (struct offload_cmd *)calloc(1, sizeof(struct offload_cmd)); |
| 1871 | |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 1872 | if (!cmd) { |
| 1873 | ALOGE("failed to allocate mem for command 0x%x", command); |
| 1874 | return -ENOMEM; |
| 1875 | } |
| 1876 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1877 | ALOGVV("%s %d", __func__, command); |
| 1878 | |
| 1879 | cmd->cmd = command; |
| 1880 | list_add_tail(&out->offload_cmd_list, &cmd->node); |
| 1881 | pthread_cond_signal(&out->offload_cond); |
| 1882 | return 0; |
| 1883 | } |
| 1884 | |
| 1885 | /* must be called iwth out->lock locked */ |
| 1886 | static void stop_compressed_output_l(struct stream_out *out) |
| 1887 | { |
| 1888 | out->offload_state = OFFLOAD_STATE_IDLE; |
| 1889 | out->playback_started = 0; |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 1890 | out->send_new_metadata = 1; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1891 | if (out->compr != NULL) { |
| 1892 | compress_stop(out->compr); |
| 1893 | while (out->offload_thread_blocked) { |
| 1894 | pthread_cond_wait(&out->cond, &out->lock); |
| 1895 | } |
| 1896 | } |
| 1897 | } |
| 1898 | |
Subhash Chandra Bose Naripeddy | 16ff4f8 | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 1899 | bool is_offload_usecase(audio_usecase_t uc_id) |
| 1900 | { |
| 1901 | unsigned int i; |
| 1902 | for (i = 0; i < sizeof(offload_usecases)/sizeof(offload_usecases[0]); i++) { |
| 1903 | if (uc_id == offload_usecases[i]) |
| 1904 | return true; |
| 1905 | } |
| 1906 | return false; |
| 1907 | } |
| 1908 | |
vivek mehta | 446c396 | 2015-09-14 10:57:35 -0700 | [diff] [blame] | 1909 | static audio_usecase_t get_offload_usecase(struct audio_device *adev, bool is_direct_pcm) |
Subhash Chandra Bose Naripeddy | 16ff4f8 | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 1910 | { |
vivek mehta | 446c396 | 2015-09-14 10:57:35 -0700 | [diff] [blame] | 1911 | audio_usecase_t ret_uc = USECASE_INVALID; |
| 1912 | unsigned int offload_uc_index; |
Alexy Joseph | b137994 | 2016-01-29 15:49:38 -0800 | [diff] [blame] | 1913 | unsigned int num_usecase = sizeof(offload_usecases)/sizeof(offload_usecases[0]); |
vivek mehta | 446c396 | 2015-09-14 10:57:35 -0700 | [diff] [blame] | 1914 | if (!adev->multi_offload_enable) { |
| 1915 | if (is_direct_pcm) |
| 1916 | ret_uc = USECASE_AUDIO_PLAYBACK_OFFLOAD2; |
| 1917 | else |
| 1918 | ret_uc = USECASE_AUDIO_PLAYBACK_OFFLOAD; |
Subhash Chandra Bose Naripeddy | 16ff4f8 | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 1919 | |
vivek mehta | 446c396 | 2015-09-14 10:57:35 -0700 | [diff] [blame] | 1920 | pthread_mutex_lock(&adev->lock); |
| 1921 | if (get_usecase_from_list(adev, ret_uc) != NULL) |
| 1922 | ret_uc = USECASE_INVALID; |
| 1923 | pthread_mutex_unlock(&adev->lock); |
| 1924 | |
| 1925 | return ret_uc; |
| 1926 | } |
Subhash Chandra Bose Naripeddy | 16ff4f8 | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 1927 | |
| 1928 | ALOGV("%s: num_usecase: %d", __func__, num_usecase); |
vivek mehta | 446c396 | 2015-09-14 10:57:35 -0700 | [diff] [blame] | 1929 | for (offload_uc_index = 0; offload_uc_index < num_usecase; offload_uc_index++) { |
| 1930 | if (!(adev->offload_usecases_state & (0x1 << offload_uc_index))) { |
| 1931 | adev->offload_usecases_state |= 0x1 << offload_uc_index; |
| 1932 | ret_uc = offload_usecases[offload_uc_index]; |
Subhash Chandra Bose Naripeddy | 16ff4f8 | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 1933 | break; |
| 1934 | } |
| 1935 | } |
vivek mehta | 446c396 | 2015-09-14 10:57:35 -0700 | [diff] [blame] | 1936 | |
| 1937 | ALOGV("%s: offload usecase is %d", __func__, ret_uc); |
| 1938 | return ret_uc; |
Subhash Chandra Bose Naripeddy | 16ff4f8 | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | static void free_offload_usecase(struct audio_device *adev, |
| 1942 | audio_usecase_t uc_id) |
| 1943 | { |
vivek mehta | 446c396 | 2015-09-14 10:57:35 -0700 | [diff] [blame] | 1944 | unsigned int offload_uc_index; |
Alexy Joseph | b137994 | 2016-01-29 15:49:38 -0800 | [diff] [blame] | 1945 | unsigned int num_usecase = sizeof(offload_usecases)/sizeof(offload_usecases[0]); |
vivek mehta | 446c396 | 2015-09-14 10:57:35 -0700 | [diff] [blame] | 1946 | |
| 1947 | if (!adev->multi_offload_enable) |
| 1948 | return; |
| 1949 | |
| 1950 | for (offload_uc_index = 0; offload_uc_index < num_usecase; offload_uc_index++) { |
| 1951 | if (offload_usecases[offload_uc_index] == uc_id) { |
| 1952 | adev->offload_usecases_state &= ~(0x1 << offload_uc_index); |
Subhash Chandra Bose Naripeddy | 16ff4f8 | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 1953 | break; |
| 1954 | } |
| 1955 | } |
| 1956 | ALOGV("%s: free offload usecase %d", __func__, uc_id); |
| 1957 | } |
| 1958 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1959 | static void *offload_thread_loop(void *context) |
| 1960 | { |
| 1961 | struct stream_out *out = (struct stream_out *) context; |
| 1962 | struct listnode *item; |
Krishnankutty Kolathappilly | d4f1d13 | 2014-01-06 18:33:58 -0800 | [diff] [blame] | 1963 | int ret = 0; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1964 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1965 | setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_AUDIO); |
| 1966 | set_sched_policy(0, SP_FOREGROUND); |
| 1967 | prctl(PR_SET_NAME, (unsigned long)"Offload Callback", 0, 0, 0); |
| 1968 | |
| 1969 | ALOGV("%s", __func__); |
Shiv Maliyappanahalli | 736d4ce | 2015-09-28 15:23:06 -0700 | [diff] [blame] | 1970 | lock_output_stream(out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 1971 | for (;;) { |
| 1972 | struct offload_cmd *cmd = NULL; |
| 1973 | stream_callback_event_t event; |
| 1974 | bool send_callback = false; |
| 1975 | |
| 1976 | ALOGVV("%s offload_cmd_list %d out->offload_state %d", |
| 1977 | __func__, list_empty(&out->offload_cmd_list), |
| 1978 | out->offload_state); |
| 1979 | if (list_empty(&out->offload_cmd_list)) { |
| 1980 | ALOGV("%s SLEEPING", __func__); |
| 1981 | pthread_cond_wait(&out->offload_cond, &out->lock); |
| 1982 | ALOGV("%s RUNNING", __func__); |
| 1983 | continue; |
| 1984 | } |
| 1985 | |
| 1986 | item = list_head(&out->offload_cmd_list); |
| 1987 | cmd = node_to_item(item, struct offload_cmd, node); |
| 1988 | list_remove(item); |
| 1989 | |
| 1990 | ALOGVV("%s STATE %d CMD %d out->compr %p", |
| 1991 | __func__, out->offload_state, cmd->cmd, out->compr); |
| 1992 | |
| 1993 | if (cmd->cmd == OFFLOAD_CMD_EXIT) { |
| 1994 | free(cmd); |
| 1995 | break; |
| 1996 | } |
| 1997 | |
| 1998 | if (out->compr == NULL) { |
| 1999 | ALOGE("%s: Compress handle is NULL", __func__); |
Haynes Mathew George | a9abb20 | 2016-06-02 14:13:20 -0700 | [diff] [blame] | 2000 | free(cmd); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2001 | pthread_cond_signal(&out->cond); |
| 2002 | continue; |
| 2003 | } |
| 2004 | out->offload_thread_blocked = true; |
| 2005 | pthread_mutex_unlock(&out->lock); |
| 2006 | send_callback = false; |
| 2007 | switch(cmd->cmd) { |
| 2008 | case OFFLOAD_CMD_WAIT_FOR_BUFFER: |
Apoorv Raghuvanshi | 44bd917 | 2014-05-28 14:50:07 -0700 | [diff] [blame] | 2009 | ALOGD("copl(%p):calling compress_wait", out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2010 | compress_wait(out->compr, -1); |
Apoorv Raghuvanshi | 44bd917 | 2014-05-28 14:50:07 -0700 | [diff] [blame] | 2011 | ALOGD("copl(%p):out of compress_wait", out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2012 | send_callback = true; |
| 2013 | event = STREAM_CBK_EVENT_WRITE_READY; |
| 2014 | break; |
| 2015 | case OFFLOAD_CMD_PARTIAL_DRAIN: |
Krishnankutty Kolathappilly | d4f1d13 | 2014-01-06 18:33:58 -0800 | [diff] [blame] | 2016 | ret = compress_next_track(out->compr); |
Sidipotu Ashok | 5582056 | 2014-02-10 16:16:38 +0530 | [diff] [blame] | 2017 | if(ret == 0) { |
Apoorv Raghuvanshi | 44bd917 | 2014-05-28 14:50:07 -0700 | [diff] [blame] | 2018 | ALOGD("copl(%p):calling compress_partial_drain", out); |
Preetam Singh Ranawat | 2d0e463 | 2015-02-02 12:40:59 +0530 | [diff] [blame] | 2019 | ret = compress_partial_drain(out->compr); |
Apoorv Raghuvanshi | 44bd917 | 2014-05-28 14:50:07 -0700 | [diff] [blame] | 2020 | ALOGD("copl(%p):out of compress_partial_drain", out); |
Preetam Singh Ranawat | 2d0e463 | 2015-02-02 12:40:59 +0530 | [diff] [blame] | 2021 | if (ret < 0) |
| 2022 | ret = -errno; |
Sidipotu Ashok | 5582056 | 2014-02-10 16:16:38 +0530 | [diff] [blame] | 2023 | } |
Preetam Singh Ranawat | 2d0e463 | 2015-02-02 12:40:59 +0530 | [diff] [blame] | 2024 | else if (ret == -ETIMEDOUT) |
Krishnankutty Kolathappilly | d4f1d13 | 2014-01-06 18:33:58 -0800 | [diff] [blame] | 2025 | compress_drain(out->compr); |
| 2026 | else |
| 2027 | ALOGE("%s: Next track returned error %d",__func__, ret); |
Preetam Singh Ranawat | 2d0e463 | 2015-02-02 12:40:59 +0530 | [diff] [blame] | 2028 | if (ret != -ENETRESET) { |
| 2029 | send_callback = true; |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 2030 | pthread_mutex_lock(&out->lock); |
| 2031 | out->send_new_metadata = 1; |
| 2032 | out->send_next_track_params = true; |
| 2033 | pthread_mutex_unlock(&out->lock); |
Preetam Singh Ranawat | 2d0e463 | 2015-02-02 12:40:59 +0530 | [diff] [blame] | 2034 | event = STREAM_CBK_EVENT_DRAIN_READY; |
| 2035 | ALOGV("copl(%p):send drain callback, ret %d", out, ret); |
| 2036 | } else |
| 2037 | ALOGE("%s: Block drain ready event during SSR", __func__); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2038 | break; |
| 2039 | case OFFLOAD_CMD_DRAIN: |
Apoorv Raghuvanshi | 44bd917 | 2014-05-28 14:50:07 -0700 | [diff] [blame] | 2040 | ALOGD("copl(%p):calling compress_drain", out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2041 | compress_drain(out->compr); |
Apoorv Raghuvanshi | 44bd917 | 2014-05-28 14:50:07 -0700 | [diff] [blame] | 2042 | ALOGD("copl(%p):calling compress_drain", out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2043 | send_callback = true; |
| 2044 | event = STREAM_CBK_EVENT_DRAIN_READY; |
| 2045 | break; |
| 2046 | default: |
| 2047 | ALOGE("%s unknown command received: %d", __func__, cmd->cmd); |
| 2048 | break; |
| 2049 | } |
Shiv Maliyappanahalli | 736d4ce | 2015-09-28 15:23:06 -0700 | [diff] [blame] | 2050 | lock_output_stream(out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2051 | out->offload_thread_blocked = false; |
| 2052 | pthread_cond_signal(&out->cond); |
vivek mehta | f1f4743 | 2015-09-25 14:07:43 -0700 | [diff] [blame] | 2053 | if (send_callback && out->offload_callback) { |
Ravi Kumar Alamanda | 38e6fe3 | 2014-12-02 19:21:51 -0800 | [diff] [blame] | 2054 | ALOGVV("%s: sending offload_callback event %d", __func__, event); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2055 | out->offload_callback(event, NULL, out->offload_cookie); |
Eric Laurent | 6e89524 | 2013-09-05 16:10:57 -0700 | [diff] [blame] | 2056 | } |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2057 | free(cmd); |
| 2058 | } |
| 2059 | |
| 2060 | pthread_cond_signal(&out->cond); |
| 2061 | while (!list_empty(&out->offload_cmd_list)) { |
| 2062 | item = list_head(&out->offload_cmd_list); |
| 2063 | list_remove(item); |
| 2064 | free(node_to_item(item, struct offload_cmd, node)); |
| 2065 | } |
| 2066 | pthread_mutex_unlock(&out->lock); |
| 2067 | |
| 2068 | return NULL; |
| 2069 | } |
| 2070 | |
| 2071 | static int create_offload_callback_thread(struct stream_out *out) |
| 2072 | { |
| 2073 | pthread_cond_init(&out->offload_cond, (const pthread_condattr_t *) NULL); |
| 2074 | list_init(&out->offload_cmd_list); |
| 2075 | pthread_create(&out->offload_thread, (const pthread_attr_t *) NULL, |
| 2076 | offload_thread_loop, out); |
| 2077 | return 0; |
| 2078 | } |
| 2079 | |
| 2080 | static int destroy_offload_callback_thread(struct stream_out *out) |
| 2081 | { |
Shiv Maliyappanahalli | 736d4ce | 2015-09-28 15:23:06 -0700 | [diff] [blame] | 2082 | lock_output_stream(out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2083 | stop_compressed_output_l(out); |
| 2084 | send_offload_cmd_l(out, OFFLOAD_CMD_EXIT); |
| 2085 | |
| 2086 | pthread_mutex_unlock(&out->lock); |
| 2087 | pthread_join(out->offload_thread, (void **) NULL); |
| 2088 | pthread_cond_destroy(&out->offload_cond); |
| 2089 | |
| 2090 | return 0; |
| 2091 | } |
| 2092 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2093 | static int stop_output_stream(struct stream_out *out) |
| 2094 | { |
Satya Krishna Pindiproli | f1cd92b | 2016-04-14 19:05:23 +0530 | [diff] [blame] | 2095 | int ret = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2096 | struct audio_usecase *uc_info; |
| 2097 | struct audio_device *adev = out->dev; |
| 2098 | |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 2099 | ALOGV("%s: enter: usecase(%d: %s)", __func__, |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 2100 | out->usecase, use_case_table[out->usecase]); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2101 | uc_info = get_usecase_from_list(adev, out->usecase); |
| 2102 | if (uc_info == NULL) { |
| 2103 | ALOGE("%s: Could not find the usecase (%d) in the list", |
| 2104 | __func__, out->usecase); |
| 2105 | return -EINVAL; |
| 2106 | } |
| 2107 | |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 2108 | if (is_offload_usecase(out->usecase) && |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 2109 | !(audio_extn_passthru_is_passthrough_stream(out))) { |
Subhash Chandra Bose Naripeddy | 1d08916 | 2013-11-13 13:31:50 -0800 | [diff] [blame] | 2110 | if (adev->visualizer_stop_output != NULL) |
| 2111 | adev->visualizer_stop_output(out->handle, out->pcm_device_id); |
Jitendra Naruka | 1b6513f | 2014-11-22 19:34:13 -0800 | [diff] [blame] | 2112 | |
| 2113 | audio_extn_dts_remove_state_notifier_node(out->usecase); |
| 2114 | |
Subhash Chandra Bose Naripeddy | 1d08916 | 2013-11-13 13:31:50 -0800 | [diff] [blame] | 2115 | if (adev->offload_effects_stop_output != NULL) |
| 2116 | adev->offload_effects_stop_output(out->handle, out->pcm_device_id); |
| 2117 | } |
Eric Laurent | c4aef75 | 2013-09-12 17:45:53 -0700 | [diff] [blame] | 2118 | |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 2119 | /* 1. Get and set stream specific mixer controls */ |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 2120 | disable_audio_route(adev, uc_info); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 2121 | |
| 2122 | /* 2. Disable the rx device */ |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 2123 | disable_snd_device(adev, uc_info->out_snd_device); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2124 | |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 2125 | list_remove(&uc_info->list); |
| 2126 | free(uc_info); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2127 | |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 2128 | if (is_offload_usecase(out->usecase) && |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 2129 | (audio_extn_passthru_is_passthrough_stream(out))) { |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 2130 | ALOGV("Disable passthrough , reset mixer to pcm"); |
| 2131 | /* NO_PASSTHROUGH */ |
| 2132 | out->compr_config.codec->compr_passthr = 0; |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 2133 | audio_extn_passthru_on_stop(out); |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 2134 | audio_extn_dolby_set_dap_bypass(adev, DAP_STATE_ON); |
| 2135 | } |
Eric Laurent | 07eeafd | 2013-10-06 12:52:49 -0700 | [diff] [blame] | 2136 | |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 2137 | /* Must be called after removing the usecase from list */ |
| 2138 | if (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) |
Ashish Jain | d84fd6a | 2016-07-27 12:33:25 +0530 | [diff] [blame] | 2139 | audio_extn_keep_alive_start(); |
| 2140 | |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 2141 | ALOGV("%s: exit: status(%d)", __func__, ret); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2142 | return ret; |
| 2143 | } |
| 2144 | |
| 2145 | int start_output_stream(struct stream_out *out) |
| 2146 | { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2147 | int ret = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2148 | struct audio_usecase *uc_info; |
| 2149 | struct audio_device *adev = out->dev; |
Naresh Tanniru | 8065983 | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 2150 | int snd_card_status = get_snd_card_state(adev); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2151 | |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 2152 | if ((out->usecase < 0) || (out->usecase >= AUDIO_USECASE_MAX)) { |
| 2153 | ret = -EINVAL; |
| 2154 | goto error_config; |
| 2155 | } |
| 2156 | |
Sidipotu Ashok | f43018c | 2014-05-02 16:21:50 +0530 | [diff] [blame] | 2157 | ALOGD("%s: enter: stream(%p)usecase(%d: %s) devices(%#x)", |
| 2158 | __func__, &out->stream, out->usecase, use_case_table[out->usecase], |
| 2159 | out->devices); |
Naresh Tanniru | 4c63039 | 2014-05-12 01:05:52 +0530 | [diff] [blame] | 2160 | |
Naresh Tanniru | 8065983 | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 2161 | if (SND_CARD_STATE_OFFLINE == snd_card_status) { |
Naresh Tanniru | 4c63039 | 2014-05-12 01:05:52 +0530 | [diff] [blame] | 2162 | ALOGE("%s: sound card is not active/SSR returning error", __func__); |
Dhanalakshmi Siddani | 4d57e99 | 2014-07-17 16:37:51 +0530 | [diff] [blame] | 2163 | ret = -EIO; |
Naresh Tanniru | 4c63039 | 2014-05-12 01:05:52 +0530 | [diff] [blame] | 2164 | goto error_config; |
| 2165 | } |
Naresh Tanniru | 4c63039 | 2014-05-12 01:05:52 +0530 | [diff] [blame] | 2166 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 2167 | 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] | 2168 | if (out->pcm_device_id < 0) { |
| 2169 | ALOGE("%s: Invalid PCM device id(%d) for the usecase(%d)", |
| 2170 | __func__, out->pcm_device_id, out->usecase); |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 2171 | ret = -EINVAL; |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 2172 | goto error_open; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2173 | } |
| 2174 | |
| 2175 | uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase)); |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 2176 | |
| 2177 | if (!uc_info) { |
| 2178 | ret = -ENOMEM; |
| 2179 | goto error_config; |
| 2180 | } |
| 2181 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2182 | uc_info->id = out->usecase; |
| 2183 | uc_info->type = PCM_PLAYBACK; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 2184 | uc_info->stream.out = out; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 2185 | uc_info->devices = out->devices; |
| 2186 | uc_info->in_snd_device = SND_DEVICE_NONE; |
| 2187 | uc_info->out_snd_device = SND_DEVICE_NONE; |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 2188 | list_add_tail(&adev->usecase_list, &uc_info->list); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2189 | |
Sudheer Papothi | fa9d228 | 2015-09-17 01:53:25 +0530 | [diff] [blame] | 2190 | audio_extn_perf_lock_acquire(&adev->perf_lock_handle, 0, |
| 2191 | adev->perf_lock_opts, |
| 2192 | adev->perf_lock_opts_size); |
Ashish Jain | d84fd6a | 2016-07-27 12:33:25 +0530 | [diff] [blame] | 2193 | |
| 2194 | if (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
| 2195 | audio_extn_keep_alive_stop(); |
| 2196 | if (audio_extn_passthru_is_enabled() && |
| 2197 | audio_extn_passthru_is_passthrough_stream(out)) { |
| 2198 | audio_extn_passthru_on_start(out); |
| 2199 | audio_extn_passthru_update_stream_configuration(adev, out); |
| 2200 | } |
| 2201 | } |
| 2202 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 2203 | select_devices(adev, out->usecase); |
| 2204 | |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 2205 | ALOGV("%s: Opening PCM device card_id(%d) device_id(%d) format(%#x)", |
| 2206 | __func__, adev->snd_card, out->pcm_device_id, out->config.format); |
Subhash Chandra Bose Naripeddy | 16ff4f8 | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 2207 | if (!is_offload_usecase(out->usecase)) { |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 2208 | unsigned int flags = PCM_OUT; |
| 2209 | unsigned int pcm_open_retry_count = 0; |
| 2210 | if (out->usecase == USECASE_AUDIO_PLAYBACK_AFE_PROXY) { |
| 2211 | flags |= PCM_MMAP | PCM_NOIRQ; |
| 2212 | pcm_open_retry_count = PROXY_OPEN_RETRY_COUNT; |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 2213 | } else if (out->realtime) { |
| 2214 | flags |= PCM_MMAP | PCM_NOIRQ; |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 2215 | } else |
| 2216 | flags |= PCM_MONOTONIC; |
| 2217 | |
| 2218 | while (1) { |
| 2219 | out->pcm = pcm_open(adev->snd_card, out->pcm_device_id, |
| 2220 | flags, &out->config); |
| 2221 | if (out->pcm == NULL || !pcm_is_ready(out->pcm)) { |
| 2222 | ALOGE("%s: %s", __func__, pcm_get_error(out->pcm)); |
| 2223 | if (out->pcm != NULL) { |
| 2224 | pcm_close(out->pcm); |
| 2225 | out->pcm = NULL; |
| 2226 | } |
| 2227 | if (pcm_open_retry_count-- == 0) { |
| 2228 | ret = -EIO; |
| 2229 | goto error_open; |
| 2230 | } |
| 2231 | usleep(PROXY_OPEN_WAIT_TIME * 1000); |
| 2232 | continue; |
| 2233 | } |
| 2234 | break; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2235 | } |
Ravi Kumar Alamanda | 8a0f977 | 2015-06-15 10:35:19 -0700 | [diff] [blame] | 2236 | |
Pradnya Chaphekar | 4403bd7 | 2014-09-09 09:50:01 -0700 | [diff] [blame] | 2237 | platform_set_stream_channel_map(adev->platform, out->channel_mask, |
| 2238 | out->pcm_device_id); |
Ravi Kumar Alamanda | 8a0f977 | 2015-06-15 10:35:19 -0700 | [diff] [blame] | 2239 | |
Ravi Kumar Alamanda | c7d9bef | 2015-09-30 22:27:26 -0700 | [diff] [blame] | 2240 | ALOGV("%s: pcm_prepare", __func__); |
| 2241 | if (pcm_is_ready(out->pcm)) { |
| 2242 | ret = pcm_prepare(out->pcm); |
| 2243 | if (ret < 0) { |
| 2244 | ALOGE("%s: pcm_prepare returned %d", __func__, ret); |
| 2245 | pcm_close(out->pcm); |
| 2246 | out->pcm = NULL; |
| 2247 | goto error_open; |
| 2248 | } |
| 2249 | } |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2250 | } else { |
Pradnya Chaphekar | 4403bd7 | 2014-09-09 09:50:01 -0700 | [diff] [blame] | 2251 | platform_set_stream_channel_map(adev->platform, out->channel_mask, |
| 2252 | out->pcm_device_id); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2253 | out->pcm = NULL; |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 2254 | out->compr = compress_open(adev->snd_card, |
| 2255 | out->pcm_device_id, |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2256 | COMPRESS_IN, &out->compr_config); |
| 2257 | if (out->compr && !is_compress_ready(out->compr)) { |
| 2258 | ALOGE("%s: %s", __func__, compress_get_error(out->compr)); |
| 2259 | compress_close(out->compr); |
| 2260 | out->compr = NULL; |
| 2261 | ret = -EIO; |
| 2262 | goto error_open; |
| 2263 | } |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 2264 | /* compress_open sends params of the track, so reset the flag here */ |
| 2265 | out->is_compr_metadata_avail = false; |
| 2266 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2267 | if (out->offload_callback) |
| 2268 | compress_nonblock(out->compr, out->non_blocking); |
Eric Laurent | c4aef75 | 2013-09-12 17:45:53 -0700 | [diff] [blame] | 2269 | |
Fred Oh | 3f43e74 | 2015-03-04 18:42:34 -0800 | [diff] [blame] | 2270 | /* Since small bufs uses blocking writes, a write will be blocked |
| 2271 | for the default max poll time (20s) in the event of an SSR. |
| 2272 | Reduce the poll time to observe and deal with SSR faster. |
| 2273 | */ |
Ashish Jain | 5106d36 | 2016-05-11 19:23:33 +0530 | [diff] [blame] | 2274 | if (!out->non_blocking) { |
Fred Oh | 3f43e74 | 2015-03-04 18:42:34 -0800 | [diff] [blame] | 2275 | compress_set_max_poll_wait(out->compr, 1000); |
| 2276 | } |
| 2277 | |
Jitendra Naruka | 1b6513f | 2014-11-22 19:34:13 -0800 | [diff] [blame] | 2278 | audio_extn_dts_create_state_notifier_node(out->usecase); |
| 2279 | audio_extn_dts_notify_playback_state(out->usecase, 0, out->sample_rate, |
| 2280 | popcount(out->channel_mask), |
| 2281 | out->playback_started); |
| 2282 | |
Subhash Chandra Bose Naripeddy | 7690c56 | 2013-12-14 00:34:53 -0800 | [diff] [blame] | 2283 | #ifdef DS1_DOLBY_DDP_ENABLED |
| 2284 | if (audio_extn_is_dolby_format(out->format)) |
| 2285 | audio_extn_dolby_send_ddp_endp_params(adev); |
| 2286 | #endif |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 2287 | if (!(audio_extn_passthru_is_passthrough_stream(out))) { |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 2288 | if (adev->visualizer_start_output != NULL) |
| 2289 | adev->visualizer_start_output(out->handle, out->pcm_device_id); |
| 2290 | if (adev->offload_effects_start_output != NULL) |
Ashish Jain | 5106d36 | 2016-05-11 19:23:33 +0530 | [diff] [blame] | 2291 | adev->offload_effects_start_output(out->handle, out->pcm_device_id, adev->mixer); |
Jitendra Naruka | 1b6513f | 2014-11-22 19:34:13 -0800 | [diff] [blame] | 2292 | audio_extn_check_and_set_dts_hpx_state(adev); |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 2293 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2294 | } |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 2295 | |
| 2296 | if (ret == 0) { |
| 2297 | register_out_stream(out); |
| 2298 | if (out->realtime) { |
| 2299 | ret = pcm_start(out->pcm); |
| 2300 | if (ret < 0) |
| 2301 | goto error_open; |
| 2302 | } |
| 2303 | } |
| 2304 | |
Sudheer Papothi | fa9d228 | 2015-09-17 01:53:25 +0530 | [diff] [blame] | 2305 | audio_extn_perf_lock_release(&adev->perf_lock_handle); |
Ravi Kumar Alamanda | c7d9bef | 2015-09-30 22:27:26 -0700 | [diff] [blame] | 2306 | ALOGD("%s: exit", __func__); |
Ravi Kumar Alamanda | 8a0f977 | 2015-06-15 10:35:19 -0700 | [diff] [blame] | 2307 | |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 2308 | return ret; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2309 | error_open: |
Sudheer Papothi | fa9d228 | 2015-09-17 01:53:25 +0530 | [diff] [blame] | 2310 | audio_extn_perf_lock_release(&adev->perf_lock_handle); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2311 | stop_output_stream(out); |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 2312 | error_config: |
Laxminath Kasam | 2cb4b75 | 2015-09-24 03:59:15 +0530 | [diff] [blame] | 2313 | /* |
| 2314 | * sleep 50ms to allow sufficient time for kernel |
| 2315 | * drivers to recover incases like SSR. |
| 2316 | */ |
| 2317 | usleep(50000); |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 2318 | return ret; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2319 | } |
| 2320 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2321 | static int check_input_parameters(uint32_t sample_rate, |
| 2322 | audio_format_t format, |
| 2323 | int channel_count) |
| 2324 | { |
Ravi Kumar Alamanda | fae4211 | 2013-11-07 23:31:54 -0800 | [diff] [blame] | 2325 | int ret = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2326 | |
Manish Dewangan | ba9fcfa | 2016-03-24 16:20:06 +0530 | [diff] [blame] | 2327 | if (((format != AUDIO_FORMAT_PCM_16_BIT) && (format != AUDIO_FORMAT_PCM_8_24_BIT) && |
| 2328 | (format != AUDIO_FORMAT_PCM_24_BIT_PACKED) && (format != AUDIO_FORMAT_PCM_32_BIT) && |
| 2329 | (format != AUDIO_FORMAT_PCM_FLOAT)) && |
Mingming Yin | e62d784 | 2013-10-25 16:26:03 -0700 | [diff] [blame] | 2330 | !voice_extn_compress_voip_is_format_supported(format) && |
Manish Dewangan | ba9fcfa | 2016-03-24 16:20:06 +0530 | [diff] [blame] | 2331 | !audio_extn_compr_cap_format_supported(format)) ret = -EINVAL; |
Ravi Kumar Alamanda | fae4211 | 2013-11-07 23:31:54 -0800 | [diff] [blame] | 2332 | |
| 2333 | switch (channel_count) { |
| 2334 | case 1: |
| 2335 | case 2: |
Chaithanya Krishna Bacharaju | 9955b16 | 2016-05-25 16:25:53 +0530 | [diff] [blame] | 2336 | case 3: |
| 2337 | case 4: |
Ravi Kumar Alamanda | fae4211 | 2013-11-07 23:31:54 -0800 | [diff] [blame] | 2338 | case 6: |
| 2339 | break; |
| 2340 | default: |
| 2341 | ret = -EINVAL; |
| 2342 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2343 | |
| 2344 | switch (sample_rate) { |
| 2345 | case 8000: |
| 2346 | case 11025: |
| 2347 | case 12000: |
| 2348 | case 16000: |
| 2349 | case 22050: |
| 2350 | case 24000: |
| 2351 | case 32000: |
| 2352 | case 44100: |
| 2353 | case 48000: |
Manish Dewangan | ba9fcfa | 2016-03-24 16:20:06 +0530 | [diff] [blame] | 2354 | case 96000: |
| 2355 | case 192000: |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2356 | break; |
| 2357 | default: |
Ravi Kumar Alamanda | fae4211 | 2013-11-07 23:31:54 -0800 | [diff] [blame] | 2358 | ret = -EINVAL; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2359 | } |
| 2360 | |
Ravi Kumar Alamanda | fae4211 | 2013-11-07 23:31:54 -0800 | [diff] [blame] | 2361 | return ret; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2362 | } |
| 2363 | |
| 2364 | static size_t get_input_buffer_size(uint32_t sample_rate, |
| 2365 | audio_format_t format, |
Ravi Kumar Alamanda | dc9bb15 | 2014-09-08 15:59:58 -0700 | [diff] [blame] | 2366 | int channel_count, |
| 2367 | bool is_low_latency) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2368 | { |
| 2369 | size_t size = 0; |
| 2370 | |
Ravi Kumar Alamanda | 33d3306 | 2013-06-11 14:40:01 -0700 | [diff] [blame] | 2371 | if (check_input_parameters(sample_rate, format, channel_count) != 0) |
| 2372 | return 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2373 | |
Ravi Kumar Alamanda | 33d3306 | 2013-06-11 14:40:01 -0700 | [diff] [blame] | 2374 | size = (sample_rate * AUDIO_CAPTURE_PERIOD_DURATION_MSEC) / 1000; |
Ravi Kumar Alamanda | dc9bb15 | 2014-09-08 15:59:58 -0700 | [diff] [blame] | 2375 | if (is_low_latency) |
| 2376 | size = configured_low_latency_capture_period_size; |
Manish Dewangan | ba9fcfa | 2016-03-24 16:20:06 +0530 | [diff] [blame] | 2377 | |
| 2378 | size *= audio_bytes_per_sample(format) * channel_count; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2379 | |
Ravi Kumar Alamanda | dc9bb15 | 2014-09-08 15:59:58 -0700 | [diff] [blame] | 2380 | /* make sure the size is multiple of 32 bytes |
| 2381 | * At 48 kHz mono 16-bit PCM: |
| 2382 | * 5.000 ms = 240 frames = 15*16*1*2 = 480, a whole multiple of 32 (15) |
| 2383 | * 3.333 ms = 160 frames = 10*16*1*2 = 320, a whole multiple of 32 (10) |
| 2384 | */ |
| 2385 | size += 0x1f; |
| 2386 | size &= ~0x1f; |
Ravi Kumar Alamanda | 33d3306 | 2013-06-11 14:40:01 -0700 | [diff] [blame] | 2387 | |
| 2388 | return size; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2389 | } |
| 2390 | |
Ashish Jain | 058165c | 2016-09-28 23:18:48 +0530 | [diff] [blame] | 2391 | static size_t get_output_period_size(uint32_t sample_rate, |
| 2392 | audio_format_t format, |
| 2393 | int channel_count, |
| 2394 | int duration /*in millisecs*/) |
| 2395 | { |
| 2396 | size_t size = 0; |
| 2397 | uint32_t bytes_per_sample = audio_bytes_per_sample(format); |
| 2398 | |
| 2399 | if ((duration == 0) || (sample_rate == 0) || |
| 2400 | (bytes_per_sample == 0) || (channel_count == 0)) { |
| 2401 | ALOGW("Invalid config duration %d sr %d bps %d ch %d", duration, sample_rate, |
| 2402 | bytes_per_sample, channel_count); |
| 2403 | return -EINVAL; |
| 2404 | } |
| 2405 | |
| 2406 | size = (sample_rate * |
| 2407 | duration * |
| 2408 | bytes_per_sample * |
| 2409 | channel_count) / 1000; |
| 2410 | /* |
| 2411 | * To have same PCM samples for all channels, the buffer size requires to |
| 2412 | * be multiple of (number of channels * bytes per sample) |
| 2413 | * For writes to succeed, the buffer must be written at address which is multiple of 32 |
| 2414 | */ |
| 2415 | size = ALIGN(size, (bytes_per_sample * channel_count * 32)); |
| 2416 | |
| 2417 | return (size/(channel_count * bytes_per_sample)); |
| 2418 | } |
| 2419 | |
Ashish Jain | 5106d36 | 2016-05-11 19:23:33 +0530 | [diff] [blame] | 2420 | static uint64_t get_actual_pcm_frames_rendered(struct stream_out *out) |
| 2421 | { |
| 2422 | uint64_t actual_frames_rendered = 0; |
| 2423 | size_t kernel_buffer_size = out->compr_config.fragment_size * out->compr_config.fragments; |
| 2424 | |
| 2425 | /* This adjustment accounts for buffering after app processor. |
| 2426 | * It is based on estimated DSP latency per use case, rather than exact. |
| 2427 | */ |
| 2428 | int64_t platform_latency = platform_render_latency(out->usecase) * |
| 2429 | out->sample_rate / 1000000LL; |
| 2430 | |
| 2431 | /* not querying actual state of buffering in kernel as it would involve an ioctl call |
| 2432 | * which then needs protection, this causes delay in TS query for pcm_offload usecase |
| 2433 | * hence only estimate. |
| 2434 | */ |
| 2435 | int64_t signed_frames = out->written - kernel_buffer_size; |
| 2436 | |
| 2437 | signed_frames = signed_frames / (audio_bytes_per_sample(out->format) * popcount(out->channel_mask)) - platform_latency; |
| 2438 | |
| 2439 | if (signed_frames > 0) |
| 2440 | actual_frames_rendered = signed_frames; |
| 2441 | |
| 2442 | ALOGVV("%s signed frames %lld out_written %lld kernel_buffer_size %d" |
| 2443 | "bytes/sample %zu channel count %d", __func__,(long long int)signed_frames, |
| 2444 | (long long int)out->written, (int)kernel_buffer_size, |
| 2445 | audio_bytes_per_sample(out->compr_config.codec->format), |
| 2446 | popcount(out->channel_mask)); |
| 2447 | |
| 2448 | return actual_frames_rendered; |
| 2449 | } |
| 2450 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2451 | static uint32_t out_get_sample_rate(const struct audio_stream *stream) |
| 2452 | { |
| 2453 | struct stream_out *out = (struct stream_out *)stream; |
| 2454 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2455 | return out->sample_rate; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2456 | } |
| 2457 | |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 2458 | static int out_set_sample_rate(struct audio_stream *stream __unused, |
| 2459 | uint32_t rate __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2460 | { |
| 2461 | return -ENOSYS; |
| 2462 | } |
| 2463 | |
| 2464 | static size_t out_get_buffer_size(const struct audio_stream *stream) |
| 2465 | { |
| 2466 | struct stream_out *out = (struct stream_out *)stream; |
| 2467 | |
Subhash Chandra Bose Naripeddy | 16ff4f8 | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 2468 | if (is_offload_usecase(out->usecase)) |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2469 | return out->compr_config.fragment_size; |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 2470 | else if(out->usecase == USECASE_COMPRESS_VOIP_CALL) |
| 2471 | return voice_extn_compress_voip_out_get_buffer_size(out); |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 2472 | else if (out->flags & AUDIO_OUTPUT_FLAG_DIRECT_PCM) |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 2473 | return out->hal_fragment_size; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2474 | |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 2475 | return out->config.period_size * out->af_period_multiplier * |
Ravi Kumar Alamanda | c3bc081 | 2014-09-08 15:34:32 -0700 | [diff] [blame] | 2476 | audio_stream_out_frame_size((const struct audio_stream_out *)stream); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2477 | } |
| 2478 | |
| 2479 | static uint32_t out_get_channels(const struct audio_stream *stream) |
| 2480 | { |
| 2481 | struct stream_out *out = (struct stream_out *)stream; |
| 2482 | |
| 2483 | return out->channel_mask; |
| 2484 | } |
| 2485 | |
| 2486 | static audio_format_t out_get_format(const struct audio_stream *stream) |
| 2487 | { |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2488 | struct stream_out *out = (struct stream_out *)stream; |
| 2489 | |
| 2490 | return out->format; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2491 | } |
| 2492 | |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 2493 | static int out_set_format(struct audio_stream *stream __unused, |
| 2494 | audio_format_t format __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2495 | { |
| 2496 | return -ENOSYS; |
| 2497 | } |
| 2498 | |
| 2499 | static int out_standby(struct audio_stream *stream) |
| 2500 | { |
| 2501 | struct stream_out *out = (struct stream_out *)stream; |
| 2502 | struct audio_device *adev = out->dev; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2503 | |
Sidipotu Ashok | f43018c | 2014-05-02 16:21:50 +0530 | [diff] [blame] | 2504 | ALOGD("%s: enter: stream (%p) usecase(%d: %s)", __func__, |
| 2505 | stream, out->usecase, use_case_table[out->usecase]); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2506 | |
Shiv Maliyappanahalli | 736d4ce | 2015-09-28 15:23:06 -0700 | [diff] [blame] | 2507 | lock_output_stream(out); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2508 | if (!out->standby) { |
Ravi Kumar Alamanda | 8a0f977 | 2015-06-15 10:35:19 -0700 | [diff] [blame] | 2509 | if (adev->adm_deregister_stream) |
| 2510 | adev->adm_deregister_stream(adev->adm_data, out->handle); |
| 2511 | |
Haynes Mathew George | 7fce0a5 | 2016-06-23 18:22:27 -0700 | [diff] [blame] | 2512 | if (is_offload_usecase(out->usecase)) |
| 2513 | stop_compressed_output_l(out); |
| 2514 | |
Ravi Kumar Alamanda | 8bba9e9 | 2013-11-11 21:09:07 -0800 | [diff] [blame] | 2515 | pthread_mutex_lock(&adev->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2516 | out->standby = true; |
Zhou Song | a889504 | 2016-07-05 17:54:22 +0800 | [diff] [blame] | 2517 | if (out->usecase == USECASE_COMPRESS_VOIP_CALL) { |
| 2518 | voice_extn_compress_voip_close_output_stream(stream); |
| 2519 | pthread_mutex_unlock(&adev->lock); |
| 2520 | pthread_mutex_unlock(&out->lock); |
| 2521 | ALOGD("VOIP output entered standby"); |
| 2522 | return 0; |
| 2523 | } else if (!is_offload_usecase(out->usecase)) { |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2524 | if (out->pcm) { |
| 2525 | pcm_close(out->pcm); |
| 2526 | out->pcm = NULL; |
| 2527 | } |
| 2528 | } else { |
Apoorv Raghuvanshi | 44bd917 | 2014-05-28 14:50:07 -0700 | [diff] [blame] | 2529 | ALOGD("copl(%p):standby", out); |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 2530 | out->send_next_track_params = false; |
| 2531 | out->is_compr_metadata_avail = false; |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 2532 | out->gapless_mdata.encoder_delay = 0; |
| 2533 | out->gapless_mdata.encoder_padding = 0; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2534 | if (out->compr != NULL) { |
| 2535 | compress_close(out->compr); |
| 2536 | out->compr = NULL; |
| 2537 | } |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 2538 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2539 | stop_output_stream(out); |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 2540 | pthread_mutex_unlock(&adev->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2541 | } |
| 2542 | pthread_mutex_unlock(&out->lock); |
Ashish Jain | bbce432 | 2016-02-16 13:25:27 +0530 | [diff] [blame] | 2543 | ALOGD("%s: exit", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2544 | return 0; |
| 2545 | } |
| 2546 | |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 2547 | static int out_dump(const struct audio_stream *stream __unused, |
| 2548 | int fd __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2549 | { |
| 2550 | return 0; |
| 2551 | } |
| 2552 | |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 2553 | static int parse_compress_metadata(struct stream_out *out, struct str_parms *parms) |
| 2554 | { |
| 2555 | int ret = 0; |
| 2556 | char value[32]; |
ApurupaPattapu | 2e084df | 2013-12-18 15:47:59 -0800 | [diff] [blame] | 2557 | |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 2558 | if (!out || !parms) { |
Krishnankutty Kolathappilly | eb78be7 | 2013-12-15 12:03:07 -0800 | [diff] [blame] | 2559 | ALOGE("%s: return invalid ",__func__); |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 2560 | return -EINVAL; |
| 2561 | } |
| 2562 | |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 2563 | ret = audio_extn_parse_compress_metadata(out, parms); |
Weiyin Jiang | 18ac4e9 | 2015-03-15 15:03:40 +0800 | [diff] [blame] | 2564 | |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 2565 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_DELAY_SAMPLES, value, sizeof(value)); |
| 2566 | if (ret >= 0) { |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 2567 | out->gapless_mdata.encoder_delay = atoi(value); //whats a good limit check? |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 2568 | } |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 2569 | ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_PADDING_SAMPLES, value, sizeof(value)); |
| 2570 | if (ret >= 0) { |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 2571 | out->gapless_mdata.encoder_padding = atoi(value); |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 2572 | } |
| 2573 | |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 2574 | ALOGV("%s new encoder delay %u and padding %u", __func__, |
| 2575 | out->gapless_mdata.encoder_delay, out->gapless_mdata.encoder_padding); |
| 2576 | |
| 2577 | return 0; |
| 2578 | } |
| 2579 | |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 2580 | static bool output_drives_call(struct audio_device *adev, struct stream_out *out) |
| 2581 | { |
| 2582 | return out == adev->primary_output || out == adev->voice_tx_output; |
| 2583 | } |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 2584 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2585 | static int out_set_parameters(struct audio_stream *stream, const char *kvpairs) |
| 2586 | { |
| 2587 | struct stream_out *out = (struct stream_out *)stream; |
| 2588 | struct audio_device *adev = out->dev; |
| 2589 | struct str_parms *parms; |
| 2590 | char value[32]; |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 2591 | int ret = 0, val = 0, err; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2592 | |
sangwoo | bc67724 | 2013-08-08 16:53:43 +0900 | [diff] [blame] | 2593 | ALOGD("%s: enter: usecase(%d: %s) kvpairs: %s", |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 2594 | __func__, out->usecase, use_case_table[out->usecase], kvpairs); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2595 | parms = str_parms_create_str(kvpairs); |
Preetam Singh Ranawat | a5f32b4 | 2014-09-23 12:12:47 +0530 | [diff] [blame] | 2596 | if (!parms) |
| 2597 | goto error; |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 2598 | err = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, value, sizeof(value)); |
| 2599 | if (err >= 0) { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2600 | val = atoi(value); |
Shiv Maliyappanahalli | 736d4ce | 2015-09-28 15:23:06 -0700 | [diff] [blame] | 2601 | lock_output_stream(out); |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 2602 | pthread_mutex_lock(&adev->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2603 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 2604 | /* |
Weiyin Jiang | 4256eeb | 2016-05-19 13:28:30 +0800 | [diff] [blame] | 2605 | * When HDMI cable is unplugged the music playback is paused and |
| 2606 | * the policy manager sends routing=0. But the audioflinger continues |
| 2607 | * to write data until standby time (3sec). As the HDMI core is |
| 2608 | * turned off, the write gets blocked. |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 2609 | * Avoid this by routing audio to speaker until standby. |
| 2610 | */ |
Weiyin Jiang | 4256eeb | 2016-05-19 13:28:30 +0800 | [diff] [blame] | 2611 | if ((out->devices == AUDIO_DEVICE_OUT_AUX_DIGITAL) && |
| 2612 | (val == AUDIO_DEVICE_NONE) && |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 2613 | !audio_extn_passthru_is_passthrough_stream(out) && |
Weiyin Jiang | 4256eeb | 2016-05-19 13:28:30 +0800 | [diff] [blame] | 2614 | (platform_get_edid_info(adev->platform) != 0) /* HDMI disconnected */) { |
| 2615 | val = AUDIO_DEVICE_OUT_SPEAKER; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 2616 | } |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2617 | /* |
| 2618 | * When A2DP is disconnected the |
| 2619 | * music playback is paused and the policy manager sends routing=0 |
| 2620 | * But the audioflingercontinues to write data until standby time |
| 2621 | * (3sec). As BT is turned off, the write gets blocked. |
| 2622 | * Avoid this by routing audio to speaker until standby. |
| 2623 | */ |
Naresh Tanniru | f7e9e63 | 2016-11-04 14:54:20 -0700 | [diff] [blame] | 2624 | if ((out->devices & AUDIO_DEVICE_OUT_ALL_A2DP) && |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 2625 | (val == AUDIO_DEVICE_NONE)) { |
| 2626 | val = AUDIO_DEVICE_OUT_SPEAKER; |
| 2627 | } |
Naresh Tanniru | 03f9dd5 | 2016-10-19 18:46:22 +0530 | [diff] [blame] | 2628 | /* To avoid a2dp to sco overlapping force route BT usecases |
| 2629 | * to speaker based on Phone state |
| 2630 | */ |
Ashish Jain | c597d10 | 2016-12-12 10:31:34 +0530 | [diff] [blame] | 2631 | if ((((val & AUDIO_DEVICE_OUT_SPEAKER) && |
| 2632 | (val & AUDIO_DEVICE_OUT_ALL_A2DP)) || |
| 2633 | ((adev->snd_dev_ref_cnt[SND_DEVICE_OUT_BT_A2DP] == 0) && |
| 2634 | (val & AUDIO_DEVICE_OUT_ALL_A2DP))) && |
Naresh Tanniru | 03f9dd5 | 2016-10-19 18:46:22 +0530 | [diff] [blame] | 2635 | ((adev->mode == AUDIO_MODE_RINGTONE) || |
| 2636 | (adev->mode == AUDIO_MODE_IN_CALL))) { |
| 2637 | ALOGD("Forcing a2dp routing to speaker for ring/call mode"); |
| 2638 | val = AUDIO_DEVICE_OUT_SPEAKER; |
| 2639 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 2640 | /* |
| 2641 | * select_devices() call below switches all the usecases on the same |
| 2642 | * backend to the new device. Refer to check_usecases_codec_backend() in |
| 2643 | * the select_devices(). But how do we undo this? |
| 2644 | * |
| 2645 | * For example, music playback is active on headset (deep-buffer usecase) |
| 2646 | * and if we go to ringtones and select a ringtone, low-latency usecase |
| 2647 | * will be started on headset+speaker. As we can't enable headset+speaker |
| 2648 | * and headset devices at the same time, select_devices() switches the music |
| 2649 | * playback to headset+speaker while starting low-lateny usecase for ringtone. |
| 2650 | * So when the ringtone playback is completed, how do we undo the same? |
| 2651 | * |
| 2652 | * We are relying on the out_set_parameters() call on deep-buffer output, |
| 2653 | * once the ringtone playback is ended. |
| 2654 | * NOTE: We should not check if the current devices are same as new devices. |
| 2655 | * Because select_devices() must be called to switch back the music |
| 2656 | * playback to headset. |
| 2657 | */ |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 2658 | if (val != 0) { |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 2659 | audio_devices_t new_dev = val; |
| 2660 | bool same_dev = out->devices == new_dev; |
| 2661 | out->devices = new_dev; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 2662 | |
Ravi Kumar Alamanda | be14939 | 2014-10-20 17:07:43 -0700 | [diff] [blame] | 2663 | if (output_drives_call(adev, out)) { |
| 2664 | if(!voice_is_in_call(adev)) { |
| 2665 | if (adev->mode == AUDIO_MODE_IN_CALL) { |
| 2666 | adev->current_call_output = out; |
| 2667 | ret = voice_start_call(adev); |
| 2668 | } |
| 2669 | } else { |
| 2670 | adev->current_call_output = out; |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 2671 | voice_update_devices_for_all_voice_usecases(adev); |
Ravi Kumar Alamanda | be14939 | 2014-10-20 17:07:43 -0700 | [diff] [blame] | 2672 | } |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 2673 | } |
Shiv Maliyappanahalli | 6b32c4c | 2015-11-04 18:10:20 -0800 | [diff] [blame] | 2674 | |
| 2675 | if (!out->standby) { |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 2676 | if (!same_dev) { |
| 2677 | ALOGV("update routing change"); |
Sudheer Papothi | 8026698 | 2016-08-16 02:36:18 +0530 | [diff] [blame] | 2678 | audio_extn_perf_lock_acquire(&adev->perf_lock_handle, 0, |
| 2679 | adev->perf_lock_opts, |
| 2680 | adev->perf_lock_opts_size); |
Haynes Mathew George | 822b549 | 2016-07-01 16:57:24 -0700 | [diff] [blame] | 2681 | if (adev->adm_on_routing_change) |
| 2682 | adev->adm_on_routing_change(adev->adm_data, |
| 2683 | out->handle); |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 2684 | } |
Shiv Maliyappanahalli | 6b32c4c | 2015-11-04 18:10:20 -0800 | [diff] [blame] | 2685 | select_devices(adev, out->usecase); |
Sudheer Papothi | 8026698 | 2016-08-16 02:36:18 +0530 | [diff] [blame] | 2686 | if (!same_dev) |
| 2687 | audio_extn_perf_lock_release(&adev->perf_lock_handle); |
Shiv Maliyappanahalli | 6b32c4c | 2015-11-04 18:10:20 -0800 | [diff] [blame] | 2688 | } |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 2689 | } |
| 2690 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2691 | pthread_mutex_unlock(&adev->lock); |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 2692 | pthread_mutex_unlock(&out->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2693 | } |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 2694 | |
| 2695 | if (out == adev->primary_output) { |
| 2696 | pthread_mutex_lock(&adev->lock); |
| 2697 | audio_extn_set_parameters(adev, parms); |
| 2698 | pthread_mutex_unlock(&adev->lock); |
| 2699 | } |
Subhash Chandra Bose Naripeddy | 16ff4f8 | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 2700 | if (is_offload_usecase(out->usecase)) { |
Shiv Maliyappanahalli | 736d4ce | 2015-09-28 15:23:06 -0700 | [diff] [blame] | 2701 | lock_output_stream(out); |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 2702 | parse_compress_metadata(out, parms); |
Jitendra Naruka | 1b6513f | 2014-11-22 19:34:13 -0800 | [diff] [blame] | 2703 | |
| 2704 | audio_extn_dts_create_state_notifier_node(out->usecase); |
| 2705 | audio_extn_dts_notify_playback_state(out->usecase, 0, out->sample_rate, |
| 2706 | popcount(out->channel_mask), |
| 2707 | out->playback_started); |
| 2708 | |
Krishnankutty Kolathappilly | eb78be7 | 2013-12-15 12:03:07 -0800 | [diff] [blame] | 2709 | pthread_mutex_unlock(&out->lock); |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 2710 | } |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 2711 | |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 2712 | err = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_PROFILE, value, sizeof(value)); |
| 2713 | if (err >= 0) { |
| 2714 | strlcpy(out->profile, value, sizeof(out->profile)); |
| 2715 | ALOGV("updating stream profile with value '%s'", out->profile); |
| 2716 | lock_output_stream(out); |
| 2717 | audio_extn_utils_update_stream_output_app_type_cfg(adev->platform, |
| 2718 | &adev->streams_output_cfg_list, |
| 2719 | out->devices, out->flags, out->format, |
| 2720 | out->sample_rate, out->bit_width, |
| 2721 | out->channel_mask, out->profile, |
| 2722 | &out->app_type_cfg); |
| 2723 | pthread_mutex_unlock(&out->lock); |
| 2724 | } |
| 2725 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2726 | str_parms_destroy(parms); |
Preetam Singh Ranawat | a5f32b4 | 2014-09-23 12:12:47 +0530 | [diff] [blame] | 2727 | error: |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 2728 | ALOGV("%s: exit: code(%d)", __func__, ret); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2729 | return ret; |
| 2730 | } |
| 2731 | |
| 2732 | static char* out_get_parameters(const struct audio_stream *stream, const char *keys) |
| 2733 | { |
| 2734 | struct stream_out *out = (struct stream_out *)stream; |
| 2735 | struct str_parms *query = str_parms_create_str(keys); |
Alexy Joseph | aee4fdd | 2016-01-29 13:02:07 -0800 | [diff] [blame] | 2736 | char *str = (char*) NULL; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2737 | char value[256]; |
| 2738 | struct str_parms *reply = str_parms_create(); |
| 2739 | size_t i, j; |
| 2740 | int ret; |
| 2741 | bool first = true; |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 2742 | |
| 2743 | if (!query || !reply) { |
Alexy Joseph | aee4fdd | 2016-01-29 13:02:07 -0800 | [diff] [blame] | 2744 | if (reply) { |
| 2745 | str_parms_destroy(reply); |
| 2746 | } |
| 2747 | if (query) { |
| 2748 | str_parms_destroy(query); |
| 2749 | } |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 2750 | ALOGE("out_get_parameters: failed to allocate mem for query or reply"); |
| 2751 | return NULL; |
| 2752 | } |
| 2753 | |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 2754 | ALOGV("%s: enter: keys - %s", __func__, keys); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2755 | ret = str_parms_get_str(query, AUDIO_PARAMETER_STREAM_SUP_CHANNELS, value, sizeof(value)); |
| 2756 | if (ret >= 0) { |
| 2757 | value[0] = '\0'; |
| 2758 | i = 0; |
| 2759 | while (out->supported_channel_masks[i] != 0) { |
| 2760 | for (j = 0; j < ARRAY_SIZE(out_channels_name_to_enum_table); j++) { |
| 2761 | if (out_channels_name_to_enum_table[j].value == out->supported_channel_masks[i]) { |
| 2762 | if (!first) { |
Apoorv Raghuvanshi | 8880cac | 2015-02-06 15:33:49 -0800 | [diff] [blame] | 2763 | strlcat(value, "|", sizeof(value)); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2764 | } |
Apoorv Raghuvanshi | 8880cac | 2015-02-06 15:33:49 -0800 | [diff] [blame] | 2765 | strlcat(value, out_channels_name_to_enum_table[j].name, sizeof(value)); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2766 | first = false; |
| 2767 | break; |
| 2768 | } |
| 2769 | } |
| 2770 | i++; |
| 2771 | } |
| 2772 | str_parms_add_str(reply, AUDIO_PARAMETER_STREAM_SUP_CHANNELS, value); |
| 2773 | str = str_parms_to_str(reply); |
| 2774 | } else { |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 2775 | voice_extn_out_get_parameters(out, query, reply); |
| 2776 | str = str_parms_to_str(reply); |
Mingming Yin | 7b762e7 | 2015-03-04 13:47:32 -0800 | [diff] [blame] | 2777 | if (str && !strncmp(str, "", sizeof(""))) { |
Narsinga Rao Chella | 29b8fc7 | 2014-01-29 12:52:19 -0800 | [diff] [blame] | 2778 | free(str); |
| 2779 | str = strdup(keys); |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 2780 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2781 | } |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 2782 | |
Alexy Joseph | 62142aa | 2015-11-16 15:10:34 -0800 | [diff] [blame] | 2783 | |
| 2784 | ret = str_parms_get_str(query, "is_direct_pcm_track", value, sizeof(value)); |
| 2785 | if (ret >= 0) { |
| 2786 | value[0] = '\0'; |
| 2787 | if (out->flags & AUDIO_OUTPUT_FLAG_DIRECT_PCM) { |
| 2788 | ALOGV("in direct_pcm"); |
Sharad Sangle | 3dd5a4a | 2015-12-10 18:39:17 +0530 | [diff] [blame] | 2789 | strlcat(value, "true", sizeof(value )); |
Alexy Joseph | 62142aa | 2015-11-16 15:10:34 -0800 | [diff] [blame] | 2790 | } else { |
| 2791 | ALOGV("not in direct_pcm"); |
Sharad Sangle | 3dd5a4a | 2015-12-10 18:39:17 +0530 | [diff] [blame] | 2792 | strlcat(value, "false", sizeof(value)); |
Alexy Joseph | 62142aa | 2015-11-16 15:10:34 -0800 | [diff] [blame] | 2793 | } |
| 2794 | str_parms_add_str(reply, "is_direct_pcm_track", value); |
Alexy Joseph | aee4fdd | 2016-01-29 13:02:07 -0800 | [diff] [blame] | 2795 | if (str) |
| 2796 | free(str); |
Alexy Joseph | 62142aa | 2015-11-16 15:10:34 -0800 | [diff] [blame] | 2797 | str = str_parms_to_str(reply); |
| 2798 | } |
| 2799 | |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 2800 | ret = str_parms_get_str(query, AUDIO_PARAMETER_STREAM_SUP_FORMATS, value, sizeof(value)); |
| 2801 | if (ret >= 0) { |
| 2802 | value[0] = '\0'; |
| 2803 | i = 0; |
| 2804 | first = true; |
| 2805 | while (out->supported_formats[i] != 0) { |
| 2806 | for (j = 0; j < ARRAY_SIZE(out_formats_name_to_enum_table); j++) { |
| 2807 | if (out_formats_name_to_enum_table[j].value == out->supported_formats[i]) { |
| 2808 | if (!first) { |
Apoorv Raghuvanshi | 8880cac | 2015-02-06 15:33:49 -0800 | [diff] [blame] | 2809 | strlcat(value, "|", sizeof(value)); |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 2810 | } |
| 2811 | strlcat(value, out_formats_name_to_enum_table[j].name, sizeof(value)); |
| 2812 | first = false; |
| 2813 | break; |
| 2814 | } |
| 2815 | } |
| 2816 | i++; |
| 2817 | } |
| 2818 | str_parms_add_str(reply, AUDIO_PARAMETER_STREAM_SUP_FORMATS, value); |
Alexy Joseph | aee4fdd | 2016-01-29 13:02:07 -0800 | [diff] [blame] | 2819 | if (str) |
| 2820 | free(str); |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 2821 | str = str_parms_to_str(reply); |
| 2822 | } |
Mingming Yin | 3a941d4 | 2016-02-17 18:08:05 -0800 | [diff] [blame] | 2823 | |
| 2824 | ret = str_parms_get_str(query, AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES, value, sizeof(value)); |
| 2825 | if (ret >= 0) { |
| 2826 | value[0] = '\0'; |
| 2827 | i = 0; |
| 2828 | first = true; |
| 2829 | while (out->supported_sample_rates[i] != 0) { |
| 2830 | for (j = 0; j < ARRAY_SIZE(out_hdmi_sample_rates_name_to_enum_table); j++) { |
| 2831 | if (out_hdmi_sample_rates_name_to_enum_table[j].value == out->supported_sample_rates[i]) { |
| 2832 | if (!first) { |
| 2833 | strlcat(value, "|", sizeof(value)); |
| 2834 | } |
| 2835 | strlcat(value, out_hdmi_sample_rates_name_to_enum_table[j].name, sizeof(value)); |
| 2836 | first = false; |
| 2837 | break; |
| 2838 | } |
| 2839 | } |
| 2840 | i++; |
| 2841 | } |
| 2842 | str_parms_add_str(reply, AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES, value); |
| 2843 | if (str) |
| 2844 | free(str); |
| 2845 | str = str_parms_to_str(reply); |
| 2846 | } |
| 2847 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2848 | str_parms_destroy(query); |
| 2849 | str_parms_destroy(reply); |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 2850 | ALOGV("%s: exit: returns - %s", __func__, str); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2851 | return str; |
| 2852 | } |
| 2853 | |
| 2854 | static uint32_t out_get_latency(const struct audio_stream_out *stream) |
| 2855 | { |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 2856 | uint32_t period_ms; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2857 | struct stream_out *out = (struct stream_out *)stream; |
Alexy Joseph | aa54c87 | 2014-12-03 02:46:47 -0800 | [diff] [blame] | 2858 | uint32_t latency = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2859 | |
Alexy Joseph | aa54c87 | 2014-12-03 02:46:47 -0800 | [diff] [blame] | 2860 | if (is_offload_usecase(out->usecase)) { |
Alexy Joseph | 01e54e6 | 2015-03-03 19:01:03 -0800 | [diff] [blame] | 2861 | latency = COMPRESS_OFFLOAD_PLAYBACK_LATENCY; |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 2862 | } else if (out->realtime) { |
| 2863 | // since the buffer won't be filled up faster than realtime, |
| 2864 | // return a smaller number |
| 2865 | if (out->config.rate) |
| 2866 | period_ms = (out->af_period_multiplier * out->config.period_size * |
| 2867 | 1000) / (out->config.rate); |
| 2868 | else |
| 2869 | period_ms = 0; |
| 2870 | latency = period_ms + platform_render_latency(out->usecase)/1000; |
Alexy Joseph | aa54c87 | 2014-12-03 02:46:47 -0800 | [diff] [blame] | 2871 | } else { |
| 2872 | latency = (out->config.period_count * out->config.period_size * 1000) / |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2873 | (out->config.rate); |
Alexy Joseph | aa54c87 | 2014-12-03 02:46:47 -0800 | [diff] [blame] | 2874 | } |
| 2875 | |
Anish Kumar | 50ebcbf | 2014-12-09 04:01:39 +0530 | [diff] [blame] | 2876 | ALOGV("%s: Latency %d", __func__, latency); |
Alexy Joseph | aa54c87 | 2014-12-03 02:46:47 -0800 | [diff] [blame] | 2877 | return latency; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2878 | } |
| 2879 | |
Preetam Singh Ranawat | cb6212e | 2016-07-19 18:33:53 +0530 | [diff] [blame] | 2880 | static float AmpToDb(float amplification) |
| 2881 | { |
Preetam Singh Ranawat | f5fbdd6 | 2016-09-29 18:38:31 +0530 | [diff] [blame] | 2882 | float db = DSD_VOLUME_MIN_DB; |
| 2883 | if (amplification > 0) { |
| 2884 | db = 20 * log10(amplification); |
| 2885 | if(db < DSD_VOLUME_MIN_DB) |
| 2886 | return DSD_VOLUME_MIN_DB; |
Preetam Singh Ranawat | cb6212e | 2016-07-19 18:33:53 +0530 | [diff] [blame] | 2887 | } |
Preetam Singh Ranawat | f5fbdd6 | 2016-09-29 18:38:31 +0530 | [diff] [blame] | 2888 | return db; |
Preetam Singh Ranawat | cb6212e | 2016-07-19 18:33:53 +0530 | [diff] [blame] | 2889 | } |
| 2890 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2891 | static int out_set_volume(struct audio_stream_out *stream, float left, |
| 2892 | float right) |
| 2893 | { |
Eric Laurent | a9024de | 2013-04-04 09:19:12 -0700 | [diff] [blame] | 2894 | struct stream_out *out = (struct stream_out *)stream; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2895 | int volume[2]; |
| 2896 | |
Eric Laurent | a9024de | 2013-04-04 09:19:12 -0700 | [diff] [blame] | 2897 | if (out->usecase == USECASE_AUDIO_PLAYBACK_MULTI_CH) { |
| 2898 | /* only take left channel into account: the API is for stereo anyway */ |
| 2899 | out->muted = (left == 0.0f); |
| 2900 | return 0; |
Subhash Chandra Bose Naripeddy | 16ff4f8 | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 2901 | } else if (is_offload_usecase(out->usecase)) { |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 2902 | if (audio_extn_passthru_is_passthrough_stream(out)) { |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 2903 | /* |
| 2904 | * Set mute or umute on HDMI passthrough stream. |
| 2905 | * Only take left channel into account. |
| 2906 | * Mute is 0 and unmute 1 |
| 2907 | */ |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 2908 | audio_extn_passthru_set_volume(out, (left == 0.0f)); |
Preetam Singh Ranawat | cb6212e | 2016-07-19 18:33:53 +0530 | [diff] [blame] | 2909 | } else if (out->format == AUDIO_FORMAT_DSD){ |
| 2910 | char mixer_ctl_name[128] = "DSD Volume"; |
| 2911 | struct audio_device *adev = out->dev; |
| 2912 | struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 2913 | |
| 2914 | if (!ctl) { |
| 2915 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 2916 | __func__, mixer_ctl_name); |
| 2917 | return -EINVAL; |
| 2918 | } |
| 2919 | volume[0] = (int)(AmpToDb(left)); |
| 2920 | volume[1] = (int)(AmpToDb(right)); |
| 2921 | mixer_ctl_set_array(ctl, volume, sizeof(volume)/sizeof(volume[0])); |
| 2922 | return 0; |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 2923 | } else { |
| 2924 | char mixer_ctl_name[128]; |
| 2925 | struct audio_device *adev = out->dev; |
| 2926 | struct mixer_ctl *ctl; |
| 2927 | int pcm_device_id = platform_get_pcm_device_id(out->usecase, |
Subhash Chandra Bose Naripeddy | 1d08916 | 2013-11-13 13:31:50 -0800 | [diff] [blame] | 2928 | PCM_PLAYBACK); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2929 | |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 2930 | snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), |
| 2931 | "Compress Playback %d Volume", pcm_device_id); |
| 2932 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 2933 | if (!ctl) { |
| 2934 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 2935 | __func__, mixer_ctl_name); |
| 2936 | return -EINVAL; |
| 2937 | } |
| 2938 | volume[0] = (int)(left * COMPRESS_PLAYBACK_VOLUME_MAX); |
| 2939 | volume[1] = (int)(right * COMPRESS_PLAYBACK_VOLUME_MAX); |
| 2940 | mixer_ctl_set_array(ctl, volume, sizeof(volume)/sizeof(volume[0])); |
| 2941 | return 0; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2942 | } |
Eric Laurent | a9024de | 2013-04-04 09:19:12 -0700 | [diff] [blame] | 2943 | } |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2944 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2945 | return -ENOSYS; |
| 2946 | } |
| 2947 | |
| 2948 | static ssize_t out_write(struct audio_stream_out *stream, const void *buffer, |
| 2949 | size_t bytes) |
| 2950 | { |
| 2951 | struct stream_out *out = (struct stream_out *)stream; |
| 2952 | struct audio_device *adev = out->dev; |
Naresh Tanniru | 8065983 | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 2953 | int snd_scard_state = get_snd_card_state(adev); |
Eric Laurent | 6e89524 | 2013-09-05 16:10:57 -0700 | [diff] [blame] | 2954 | ssize_t ret = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2955 | |
Shiv Maliyappanahalli | 736d4ce | 2015-09-28 15:23:06 -0700 | [diff] [blame] | 2956 | lock_output_stream(out); |
Naresh Tanniru | 4c63039 | 2014-05-12 01:05:52 +0530 | [diff] [blame] | 2957 | |
Naresh Tanniru | 8065983 | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 2958 | if (SND_CARD_STATE_OFFLINE == snd_scard_state) { |
Zhou Song | 0b2e5dc | 2015-03-16 14:41:38 +0800 | [diff] [blame] | 2959 | |
Dhanalakshmi Siddani | 44db0cc | 2016-06-30 16:40:38 +0530 | [diff] [blame] | 2960 | if ((!(out->flags & AUDIO_OUTPUT_FLAG_DIRECT_PCM)) && is_offload_usecase(out->usecase)) { |
Ashish Jain | bbce432 | 2016-02-16 13:25:27 +0530 | [diff] [blame] | 2961 | /*during SSR for compress usecase we should return error to flinger*/ |
Naresh Tanniru | 8065983 | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 2962 | ALOGD(" copl %s: sound card is not active/SSR state", __func__); |
| 2963 | pthread_mutex_unlock(&out->lock); |
| 2964 | return -ENETRESET; |
Ashish Jain | bbce432 | 2016-02-16 13:25:27 +0530 | [diff] [blame] | 2965 | } else { |
| 2966 | /* increase written size during SSR to avoid mismatch |
| 2967 | * with the written frames count in AF |
| 2968 | */ |
Haynes Mathew George | a99f753 | 2016-08-24 16:01:21 -0700 | [diff] [blame] | 2969 | // bytes per frame |
| 2970 | size_t bpf = audio_bytes_per_sample(out->format) * |
| 2971 | audio_channel_count_from_out_mask(out->channel_mask); |
| 2972 | if (bpf != 0) |
| 2973 | out->written += bytes / bpf; |
Ashish Jain | bbce432 | 2016-02-16 13:25:27 +0530 | [diff] [blame] | 2974 | ALOGD(" %s: sound card is not active/SSR state", __func__); |
| 2975 | ret= -EIO; |
| 2976 | goto exit; |
Naresh Tanniru | 4c63039 | 2014-05-12 01:05:52 +0530 | [diff] [blame] | 2977 | } |
| 2978 | } |
| 2979 | |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 2980 | if (audio_extn_passthru_should_drop_data(out)) { |
Ashish Jain | d84fd6a | 2016-07-27 12:33:25 +0530 | [diff] [blame] | 2981 | ALOGV(" %s : Drop data as compress passthrough session is going on", __func__); |
| 2982 | if (audio_bytes_per_sample(out->format) != 0) |
| 2983 | out->written += bytes / (out->config.channels * audio_bytes_per_sample(out->format)); |
| 2984 | ret = -EIO; |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 2985 | goto exit; |
| 2986 | } |
| 2987 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2988 | if (out->standby) { |
Ravi Kumar Alamanda | 59d296d | 2013-05-02 11:25:27 -0700 | [diff] [blame] | 2989 | out->standby = false; |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 2990 | pthread_mutex_lock(&adev->lock); |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 2991 | if (out->usecase == USECASE_COMPRESS_VOIP_CALL) |
| 2992 | ret = voice_extn_compress_voip_start_output_stream(out); |
| 2993 | else |
| 2994 | ret = start_output_stream(out); |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 2995 | pthread_mutex_unlock(&adev->lock); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 2996 | /* ToDo: If use case is compress offload should return 0 */ |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2997 | if (ret != 0) { |
Ravi Kumar Alamanda | 59d296d | 2013-05-02 11:25:27 -0700 | [diff] [blame] | 2998 | out->standby = true; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2999 | goto exit; |
| 3000 | } |
vivek mehta | b72d08d | 2016-04-29 03:16:47 -0700 | [diff] [blame] | 3001 | |
| 3002 | if (last_known_cal_step != -1) { |
| 3003 | ALOGD("%s: retry previous failed cal level set", __func__); |
| 3004 | audio_hw_send_gain_dep_calibration(last_known_cal_step); |
| 3005 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3006 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3007 | |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 3008 | if (adev->is_channel_status_set == false && (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL)){ |
Alexy Joseph | b137994 | 2016-01-29 15:49:38 -0800 | [diff] [blame] | 3009 | audio_utils_set_hdmi_channel_status(out, (void *)buffer, bytes); |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 3010 | adev->is_channel_status_set = true; |
| 3011 | } |
| 3012 | |
Subhash Chandra Bose Naripeddy | 16ff4f8 | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 3013 | if (is_offload_usecase(out->usecase)) { |
Alexy Joseph | 01e54e6 | 2015-03-03 19:01:03 -0800 | [diff] [blame] | 3014 | ALOGVV("copl(%p): writing buffer (%zu bytes) to compress device", out, bytes); |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 3015 | if (out->send_new_metadata) { |
Apoorv Raghuvanshi | 44bd917 | 2014-05-28 14:50:07 -0700 | [diff] [blame] | 3016 | ALOGD("copl(%p):send new gapless metadata", out); |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 3017 | compress_set_gapless_metadata(out->compr, &out->gapless_mdata); |
| 3018 | out->send_new_metadata = 0; |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 3019 | if (out->send_next_track_params && out->is_compr_metadata_avail) { |
| 3020 | ALOGD("copl(%p):send next track params in gapless", out); |
| 3021 | compress_set_next_track_param(out->compr, &(out->compr_config.codec->options)); |
| 3022 | out->send_next_track_params = false; |
| 3023 | out->is_compr_metadata_avail = false; |
| 3024 | } |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 3025 | } |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 3026 | if ((out->flags & AUDIO_OUTPUT_FLAG_DIRECT_PCM) && |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 3027 | (out->convert_buffer) != NULL) { |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 3028 | |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 3029 | if ((bytes > out->hal_fragment_size)) { |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 3030 | ALOGW("Error written bytes %zu > %d (fragment_size)", |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 3031 | bytes, out->hal_fragment_size); |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 3032 | pthread_mutex_unlock(&out->lock); |
| 3033 | return -EINVAL; |
| 3034 | } else { |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 3035 | audio_format_t dst_format = out->hal_op_format; |
| 3036 | audio_format_t src_format = out->hal_ip_format; |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 3037 | |
| 3038 | uint32_t frames = bytes / format_to_bitwidth_table[src_format]; |
| 3039 | uint32_t bytes_to_write = frames * format_to_bitwidth_table[dst_format]; |
| 3040 | |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 3041 | memcpy_by_audio_format(out->convert_buffer, |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 3042 | dst_format, |
| 3043 | buffer, |
| 3044 | src_format, |
| 3045 | frames); |
| 3046 | |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 3047 | ret = compress_write(out->compr, out->convert_buffer, |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 3048 | bytes_to_write); |
| 3049 | |
| 3050 | /*Convert written bytes in audio flinger format*/ |
| 3051 | if (ret > 0) |
| 3052 | ret = ((ret * format_to_bitwidth_table[out->format]) / |
| 3053 | format_to_bitwidth_table[dst_format]); |
| 3054 | } |
| 3055 | } else |
| 3056 | ret = compress_write(out->compr, buffer, bytes); |
| 3057 | |
Dhanalakshmi Siddani | 37ca1d6 | 2014-08-20 12:28:34 +0530 | [diff] [blame] | 3058 | if (ret < 0) |
| 3059 | ret = -errno; |
Satya Krishna Pindiproli | f1cd92b | 2016-04-14 19:05:23 +0530 | [diff] [blame] | 3060 | ALOGVV("%s: writing buffer (%zu bytes) to compress device returned %zd", __func__, bytes, ret); |
Ashish Jain | b26edfb | 2016-08-25 00:10:11 +0530 | [diff] [blame] | 3061 | /*msg to cb thread only if non blocking write is enabled*/ |
| 3062 | if (ret >= 0 && ret < (ssize_t)bytes && out->non_blocking) { |
Sidipotu Ashok | 5582056 | 2014-02-10 16:16:38 +0530 | [diff] [blame] | 3063 | 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] | 3064 | send_offload_cmd_l(out, OFFLOAD_CMD_WAIT_FOR_BUFFER); |
Naresh Tanniru | 8065983 | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 3065 | } else if (-ENETRESET == ret) { |
| 3066 | ALOGE("copl %s: received sound card offline state on compress write", __func__); |
| 3067 | set_snd_card_state(adev,SND_CARD_STATE_OFFLINE); |
| 3068 | pthread_mutex_unlock(&out->lock); |
| 3069 | out_standby(&out->stream.common); |
| 3070 | return ret; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3071 | } |
Ashish Jain | 5106d36 | 2016-05-11 19:23:33 +0530 | [diff] [blame] | 3072 | if ( ret == (ssize_t)bytes && !out->non_blocking) |
| 3073 | out->written += bytes; |
| 3074 | |
Dhanalakshmi Siddani | a6b76c7 | 2016-09-09 18:10:31 +0530 | [diff] [blame] | 3075 | /* Call compr start only when non-zero bytes of data is there to be rendered */ |
| 3076 | if (!out->playback_started && ret > 0) { |
| 3077 | int status = compress_start(out->compr); |
| 3078 | if (status < 0) { |
| 3079 | ret = status; |
| 3080 | ALOGE("%s: compr start failed with err %d", __func__, errno); |
| 3081 | goto exit; |
| 3082 | } |
Alexy Joseph | 7de344d | 2015-03-30 10:40:03 -0700 | [diff] [blame] | 3083 | audio_extn_dts_eagle_fade(adev, true, out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3084 | out->playback_started = 1; |
| 3085 | out->offload_state = OFFLOAD_STATE_PLAYING; |
Jitendra Naruka | 1b6513f | 2014-11-22 19:34:13 -0800 | [diff] [blame] | 3086 | |
| 3087 | audio_extn_dts_notify_playback_state(out->usecase, 0, out->sample_rate, |
| 3088 | popcount(out->channel_mask), |
| 3089 | out->playback_started); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3090 | } |
| 3091 | pthread_mutex_unlock(&out->lock); |
| 3092 | return ret; |
| 3093 | } else { |
| 3094 | if (out->pcm) { |
| 3095 | if (out->muted) |
| 3096 | memset((void *)buffer, 0, bytes); |
Ravi Kumar Alamanda | 8a0f977 | 2015-06-15 10:35:19 -0700 | [diff] [blame] | 3097 | |
Satya Krishna Pindiproli | f1cd92b | 2016-04-14 19:05:23 +0530 | [diff] [blame] | 3098 | ALOGVV("%s: writing buffer (%zu bytes) to pcm device", __func__, bytes); |
Ravi Kumar Alamanda | 8a0f977 | 2015-06-15 10:35:19 -0700 | [diff] [blame] | 3099 | |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 3100 | long ns = 0; |
Ravi Kumar Alamanda | 8a0f977 | 2015-06-15 10:35:19 -0700 | [diff] [blame] | 3101 | |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 3102 | if (out->config.rate) |
| 3103 | ns = pcm_bytes_to_frames(out->pcm, bytes)*1000000000LL/ |
| 3104 | out->config.rate; |
| 3105 | |
| 3106 | bool use_mmap = is_mmap_usecase(out->usecase) || out->realtime; |
| 3107 | |
| 3108 | request_out_focus(out, ns); |
| 3109 | |
| 3110 | if (use_mmap) |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 3111 | ret = pcm_mmap_write(out->pcm, (void *)buffer, bytes); |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 3112 | else if (out->hal_op_format != out->hal_ip_format && |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 3113 | out->convert_buffer != NULL) { |
| 3114 | |
| 3115 | memcpy_by_audio_format(out->convert_buffer, |
| 3116 | out->hal_op_format, |
| 3117 | buffer, |
| 3118 | out->hal_ip_format, |
| 3119 | out->config.period_size * out->config.channels); |
| 3120 | |
| 3121 | ret = pcm_write(out->pcm, out->convert_buffer, |
| 3122 | (out->config.period_size * |
| 3123 | out->config.channels * |
| 3124 | format_to_bitwidth_table[out->hal_op_format])); |
| 3125 | } else { |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 3126 | ret = pcm_write(out->pcm, (void *)buffer, bytes); |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 3127 | } |
Ravi Kumar Alamanda | 8a0f977 | 2015-06-15 10:35:19 -0700 | [diff] [blame] | 3128 | |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 3129 | release_out_focus(out); |
| 3130 | |
Dhanalakshmi Siddani | 37ca1d6 | 2014-08-20 12:28:34 +0530 | [diff] [blame] | 3131 | if (ret < 0) |
| 3132 | ret = -errno; |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 3133 | else if (ret == 0 && (audio_bytes_per_sample(out->format) != 0)) |
| 3134 | out->written += bytes / (out->config.channels * audio_bytes_per_sample(out->format)); |
| 3135 | else |
| 3136 | ret = -EINVAL; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3137 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3138 | } |
| 3139 | |
| 3140 | exit: |
Dhanalakshmi Siddani | 8fc6d91 | 2014-05-26 18:03:42 +0530 | [diff] [blame] | 3141 | /* ToDo: There may be a corner case when SSR happens back to back during |
| 3142 | start/stop. Need to post different error to handle that. */ |
Naresh Tanniru | 4c63039 | 2014-05-12 01:05:52 +0530 | [diff] [blame] | 3143 | if (-ENETRESET == ret) { |
Naresh Tanniru | 8065983 | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 3144 | set_snd_card_state(adev,SND_CARD_STATE_OFFLINE); |
Naresh Tanniru | 4c63039 | 2014-05-12 01:05:52 +0530 | [diff] [blame] | 3145 | } |
| 3146 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3147 | pthread_mutex_unlock(&out->lock); |
| 3148 | |
| 3149 | if (ret != 0) { |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 3150 | if (out->pcm) |
Alexy Joseph | b137994 | 2016-01-29 15:49:38 -0800 | [diff] [blame] | 3151 | ALOGE("%s: error %d, %s", __func__, (int)ret, pcm_get_error(out->pcm)); |
Venkata Narendra Kumar Gutta | bc9c9ca | 2014-06-25 20:38:03 +0530 | [diff] [blame] | 3152 | if (out->usecase == USECASE_COMPRESS_VOIP_CALL) { |
Venkata Narendra Kumar Gutta | 9181214 | 2014-08-11 18:20:49 +0530 | [diff] [blame] | 3153 | pthread_mutex_lock(&adev->lock); |
Venkata Narendra Kumar Gutta | bc9c9ca | 2014-06-25 20:38:03 +0530 | [diff] [blame] | 3154 | voice_extn_compress_voip_close_output_stream(&out->stream.common); |
Venkata Narendra Kumar Gutta | 9181214 | 2014-08-11 18:20:49 +0530 | [diff] [blame] | 3155 | pthread_mutex_unlock(&adev->lock); |
Venkata Narendra Kumar Gutta | bc9c9ca | 2014-06-25 20:38:03 +0530 | [diff] [blame] | 3156 | out->standby = true; |
| 3157 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3158 | out_standby(&out->stream.common); |
Dhanalakshmi Siddani | a6b76c7 | 2016-09-09 18:10:31 +0530 | [diff] [blame] | 3159 | if (!(out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD)) |
| 3160 | usleep((uint64_t)bytes * 1000000 / audio_stream_out_frame_size(stream) / |
| 3161 | out_get_sample_rate(&out->stream.common)); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3162 | } |
| 3163 | return bytes; |
| 3164 | } |
| 3165 | |
| 3166 | static int out_get_render_position(const struct audio_stream_out *stream, |
| 3167 | uint32_t *dsp_frames) |
| 3168 | { |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3169 | struct stream_out *out = (struct stream_out *)stream; |
Preetam Singh Ranawat | 2d0e463 | 2015-02-02 12:40:59 +0530 | [diff] [blame] | 3170 | struct audio_device *adev = out->dev; |
Zhou Song | 32a556e | 2015-05-05 10:46:56 +0800 | [diff] [blame] | 3171 | |
| 3172 | if (dsp_frames == NULL) |
| 3173 | return -EINVAL; |
| 3174 | |
| 3175 | *dsp_frames = 0; |
| 3176 | if (is_offload_usecase(out->usecase)) { |
Mingming Yin | 9e348b5 | 2014-11-19 16:18:55 -0800 | [diff] [blame] | 3177 | ssize_t ret = 0; |
Ashish Jain | 5106d36 | 2016-05-11 19:23:33 +0530 | [diff] [blame] | 3178 | |
| 3179 | /* Below piece of code is not guarded against any lock beacuse audioFliner serializes |
| 3180 | * this operation and adev_close_output_stream(where out gets reset). |
| 3181 | */ |
| 3182 | if (!out->non_blocking && (out->flags & AUDIO_OUTPUT_FLAG_DIRECT_PCM)) { |
| 3183 | *dsp_frames = get_actual_pcm_frames_rendered(out); |
| 3184 | ALOGVV("dsp_frames %d sampleRate %d",(int)*dsp_frames,out->sample_rate); |
| 3185 | return 0; |
| 3186 | } |
| 3187 | |
Shiv Maliyappanahalli | 736d4ce | 2015-09-28 15:23:06 -0700 | [diff] [blame] | 3188 | lock_output_stream(out); |
Ashish Jain | 5106d36 | 2016-05-11 19:23:33 +0530 | [diff] [blame] | 3189 | if (out->compr != NULL && out->non_blocking) { |
Naresh Tanniru | 8065983 | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 3190 | ret = compress_get_tstamp(out->compr, (unsigned long *)dsp_frames, |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3191 | &out->sample_rate); |
Dhanalakshmi Siddani | 37ca1d6 | 2014-08-20 12:28:34 +0530 | [diff] [blame] | 3192 | if (ret < 0) |
| 3193 | ret = -errno; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3194 | ALOGVV("%s rendered frames %d sample_rate %d", |
Ashish Jain | 5106d36 | 2016-05-11 19:23:33 +0530 | [diff] [blame] | 3195 | __func__, *dsp_frames, out->sample_rate); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3196 | } |
| 3197 | pthread_mutex_unlock(&out->lock); |
Naresh Tanniru | 8065983 | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 3198 | if (-ENETRESET == ret) { |
| 3199 | ALOGE(" ERROR: sound card not active Unable to get time stamp from compress driver"); |
| 3200 | set_snd_card_state(adev,SND_CARD_STATE_OFFLINE); |
| 3201 | return -EINVAL; |
| 3202 | } else if(ret < 0) { |
| 3203 | ALOGE(" ERROR: Unable to get time stamp from compress driver"); |
| 3204 | return -EINVAL; |
Preetam Singh Ranawat | 2d0e463 | 2015-02-02 12:40:59 +0530 | [diff] [blame] | 3205 | } else if (get_snd_card_state(adev) == SND_CARD_STATE_OFFLINE){ |
| 3206 | /* |
| 3207 | * Handle corner case where compress session is closed during SSR |
| 3208 | * and timestamp is queried |
| 3209 | */ |
| 3210 | ALOGE(" ERROR: sound card not active, return error"); |
| 3211 | return -EINVAL; |
Naresh Tanniru | 8065983 | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 3212 | } else { |
| 3213 | return 0; |
| 3214 | } |
Zhou Song | 32a556e | 2015-05-05 10:46:56 +0800 | [diff] [blame] | 3215 | } else if (audio_is_linear_pcm(out->format)) { |
| 3216 | *dsp_frames = out->written; |
| 3217 | return 0; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3218 | } else |
| 3219 | return -EINVAL; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3220 | } |
| 3221 | |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 3222 | static int out_add_audio_effect(const struct audio_stream *stream __unused, |
| 3223 | effect_handle_t effect __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3224 | { |
| 3225 | return 0; |
| 3226 | } |
| 3227 | |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 3228 | static int out_remove_audio_effect(const struct audio_stream *stream __unused, |
| 3229 | effect_handle_t effect __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3230 | { |
| 3231 | return 0; |
| 3232 | } |
| 3233 | |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 3234 | static int out_get_next_write_timestamp(const struct audio_stream_out *stream __unused, |
| 3235 | int64_t *timestamp __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3236 | { |
| 3237 | return -EINVAL; |
| 3238 | } |
| 3239 | |
Glenn Kasten | 2ccd7ba | 2013-09-10 09:04:31 -0700 | [diff] [blame] | 3240 | static int out_get_presentation_position(const struct audio_stream_out *stream, |
| 3241 | uint64_t *frames, struct timespec *timestamp) |
| 3242 | { |
| 3243 | struct stream_out *out = (struct stream_out *)stream; |
| 3244 | int ret = -1; |
Eric Laurent | 949a089 | 2013-09-20 09:20:13 -0700 | [diff] [blame] | 3245 | unsigned long dsp_frames; |
Glenn Kasten | 2ccd7ba | 2013-09-10 09:04:31 -0700 | [diff] [blame] | 3246 | |
Ashish Jain | 5106d36 | 2016-05-11 19:23:33 +0530 | [diff] [blame] | 3247 | /* below piece of code is not guarded against any lock because audioFliner serializes |
| 3248 | * this operation and adev_close_output_stream( where out gets reset). |
| 3249 | */ |
| 3250 | if (is_offload_usecase(out->usecase) && !out->non_blocking && |
| 3251 | (out->flags & AUDIO_OUTPUT_FLAG_DIRECT_PCM)) { |
| 3252 | *frames = get_actual_pcm_frames_rendered(out); |
| 3253 | /* this is the best we can do */ |
| 3254 | clock_gettime(CLOCK_MONOTONIC, timestamp); |
| 3255 | ALOGVV("frames %lld playedat %lld",(long long int)*frames, |
| 3256 | timestamp->tv_sec * 1000000LL + timestamp->tv_nsec / 1000); |
| 3257 | return 0; |
| 3258 | } |
| 3259 | |
Shiv Maliyappanahalli | 736d4ce | 2015-09-28 15:23:06 -0700 | [diff] [blame] | 3260 | lock_output_stream(out); |
Glenn Kasten | 2ccd7ba | 2013-09-10 09:04:31 -0700 | [diff] [blame] | 3261 | |
Ashish Jain | 5106d36 | 2016-05-11 19:23:33 +0530 | [diff] [blame] | 3262 | if (is_offload_usecase(out->usecase) && out->compr != NULL && out->non_blocking) { |
| 3263 | ret = compress_get_tstamp(out->compr, &dsp_frames, |
| 3264 | &out->sample_rate); |
| 3265 | ALOGVV("%s rendered frames %ld sample_rate %d", |
| 3266 | __func__, dsp_frames, out->sample_rate); |
| 3267 | *frames = dsp_frames; |
| 3268 | if (ret < 0) |
| 3269 | ret = -errno; |
| 3270 | if (-ENETRESET == ret) { |
| 3271 | ALOGE(" ERROR: sound card not active Unable to get time stamp from compress driver"); |
| 3272 | set_snd_card_state(adev,SND_CARD_STATE_OFFLINE); |
| 3273 | ret = -EINVAL; |
| 3274 | } else |
| 3275 | ret = 0; |
| 3276 | /* this is the best we can do */ |
| 3277 | clock_gettime(CLOCK_MONOTONIC, timestamp); |
Eric Laurent | 949a089 | 2013-09-20 09:20:13 -0700 | [diff] [blame] | 3278 | } else { |
| 3279 | if (out->pcm) { |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 3280 | unsigned int avail; |
Eric Laurent | 949a089 | 2013-09-20 09:20:13 -0700 | [diff] [blame] | 3281 | if (pcm_get_htimestamp(out->pcm, &avail, timestamp) == 0) { |
| 3282 | 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] | 3283 | int64_t signed_frames = out->written - kernel_buffer_size + avail; |
Haynes Mathew George | 7ff216f | 2013-09-11 19:51:41 -0700 | [diff] [blame] | 3284 | // This adjustment accounts for buffering after app processor. |
| 3285 | // It is based on estimated DSP latency per use case, rather than exact. |
| 3286 | signed_frames -= |
| 3287 | (platform_render_latency(out->usecase) * out->sample_rate / 1000000LL); |
| 3288 | |
Eric Laurent | 949a089 | 2013-09-20 09:20:13 -0700 | [diff] [blame] | 3289 | // It would be unusual for this value to be negative, but check just in case ... |
| 3290 | if (signed_frames >= 0) { |
| 3291 | *frames = signed_frames; |
| 3292 | ret = 0; |
| 3293 | } |
Glenn Kasten | 2ccd7ba | 2013-09-10 09:04:31 -0700 | [diff] [blame] | 3294 | } |
Ashish Jain | bbce432 | 2016-02-16 13:25:27 +0530 | [diff] [blame] | 3295 | } else if (adev->snd_card_status.state == SND_CARD_STATE_OFFLINE) { |
| 3296 | *frames = out->written; |
| 3297 | clock_gettime(CLOCK_MONOTONIC, timestamp); |
| 3298 | ret = 0; |
Glenn Kasten | 2ccd7ba | 2013-09-10 09:04:31 -0700 | [diff] [blame] | 3299 | } |
| 3300 | } |
Glenn Kasten | 2ccd7ba | 2013-09-10 09:04:31 -0700 | [diff] [blame] | 3301 | pthread_mutex_unlock(&out->lock); |
Glenn Kasten | 2ccd7ba | 2013-09-10 09:04:31 -0700 | [diff] [blame] | 3302 | return ret; |
| 3303 | } |
| 3304 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3305 | static int out_set_callback(struct audio_stream_out *stream, |
| 3306 | stream_callback_t callback, void *cookie) |
| 3307 | { |
| 3308 | struct stream_out *out = (struct stream_out *)stream; |
| 3309 | |
| 3310 | ALOGV("%s", __func__); |
Shiv Maliyappanahalli | 736d4ce | 2015-09-28 15:23:06 -0700 | [diff] [blame] | 3311 | lock_output_stream(out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3312 | out->offload_callback = callback; |
| 3313 | out->offload_cookie = cookie; |
| 3314 | pthread_mutex_unlock(&out->lock); |
| 3315 | return 0; |
| 3316 | } |
| 3317 | |
| 3318 | static int out_pause(struct audio_stream_out* stream) |
| 3319 | { |
| 3320 | struct stream_out *out = (struct stream_out *)stream; |
| 3321 | int status = -ENOSYS; |
| 3322 | ALOGV("%s", __func__); |
Subhash Chandra Bose Naripeddy | 16ff4f8 | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 3323 | if (is_offload_usecase(out->usecase)) { |
Apoorv Raghuvanshi | 44bd917 | 2014-05-28 14:50:07 -0700 | [diff] [blame] | 3324 | ALOGD("copl(%p):pause compress driver", out); |
Shiv Maliyappanahalli | 736d4ce | 2015-09-28 15:23:06 -0700 | [diff] [blame] | 3325 | lock_output_stream(out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3326 | if (out->compr != NULL && out->offload_state == OFFLOAD_STATE_PLAYING) { |
Naresh Tanniru | 8065983 | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 3327 | struct audio_device *adev = out->dev; |
| 3328 | int snd_scard_state = get_snd_card_state(adev); |
| 3329 | |
| 3330 | if (SND_CARD_STATE_ONLINE == snd_scard_state) |
| 3331 | status = compress_pause(out->compr); |
| 3332 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3333 | out->offload_state = OFFLOAD_STATE_PAUSED; |
Jitendra Naruka | 1b6513f | 2014-11-22 19:34:13 -0800 | [diff] [blame] | 3334 | |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 3335 | if (audio_extn_passthru_is_active()) { |
| 3336 | ALOGV("offload use case, pause passthru"); |
| 3337 | audio_extn_passthru_on_pause(out); |
| 3338 | } |
| 3339 | |
Dhanalakshmi Siddani | 79415e7 | 2015-03-23 11:54:47 +0530 | [diff] [blame] | 3340 | audio_extn_dts_eagle_fade(adev, false, out); |
Jitendra Naruka | 1b6513f | 2014-11-22 19:34:13 -0800 | [diff] [blame] | 3341 | audio_extn_dts_notify_playback_state(out->usecase, 0, |
| 3342 | out->sample_rate, popcount(out->channel_mask), |
| 3343 | 0); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3344 | } |
| 3345 | pthread_mutex_unlock(&out->lock); |
| 3346 | } |
| 3347 | return status; |
| 3348 | } |
| 3349 | |
| 3350 | static int out_resume(struct audio_stream_out* stream) |
| 3351 | { |
| 3352 | struct stream_out *out = (struct stream_out *)stream; |
| 3353 | int status = -ENOSYS; |
| 3354 | ALOGV("%s", __func__); |
Subhash Chandra Bose Naripeddy | 16ff4f8 | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 3355 | if (is_offload_usecase(out->usecase)) { |
Apoorv Raghuvanshi | 44bd917 | 2014-05-28 14:50:07 -0700 | [diff] [blame] | 3356 | ALOGD("copl(%p):resume compress driver", out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3357 | status = 0; |
Shiv Maliyappanahalli | 736d4ce | 2015-09-28 15:23:06 -0700 | [diff] [blame] | 3358 | lock_output_stream(out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3359 | if (out->compr != NULL && out->offload_state == OFFLOAD_STATE_PAUSED) { |
Naresh Tanniru | 8065983 | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 3360 | struct audio_device *adev = out->dev; |
| 3361 | int snd_scard_state = get_snd_card_state(adev); |
| 3362 | |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 3363 | if (SND_CARD_STATE_ONLINE == snd_scard_state) { |
| 3364 | if (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
| 3365 | pthread_mutex_lock(&out->dev->lock); |
| 3366 | ALOGV("offload resume, check and set hdmi backend again"); |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 3367 | pthread_mutex_unlock(&out->dev->lock); |
| 3368 | } |
Naresh Tanniru | 8065983 | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 3369 | status = compress_resume(out->compr); |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 3370 | } |
| 3371 | if (!status) { |
| 3372 | out->offload_state = OFFLOAD_STATE_PLAYING; |
| 3373 | } |
Dhanalakshmi Siddani | 79415e7 | 2015-03-23 11:54:47 +0530 | [diff] [blame] | 3374 | audio_extn_dts_eagle_fade(adev, true, out); |
Jitendra Naruka | 1b6513f | 2014-11-22 19:34:13 -0800 | [diff] [blame] | 3375 | audio_extn_dts_notify_playback_state(out->usecase, 0, out->sample_rate, |
| 3376 | popcount(out->channel_mask), 1); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3377 | } |
| 3378 | pthread_mutex_unlock(&out->lock); |
| 3379 | } |
| 3380 | return status; |
| 3381 | } |
| 3382 | |
| 3383 | static int out_drain(struct audio_stream_out* stream, audio_drain_type_t type ) |
| 3384 | { |
| 3385 | struct stream_out *out = (struct stream_out *)stream; |
| 3386 | int status = -ENOSYS; |
| 3387 | ALOGV("%s", __func__); |
Subhash Chandra Bose Naripeddy | 16ff4f8 | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 3388 | if (is_offload_usecase(out->usecase)) { |
Shiv Maliyappanahalli | 736d4ce | 2015-09-28 15:23:06 -0700 | [diff] [blame] | 3389 | lock_output_stream(out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3390 | if (type == AUDIO_DRAIN_EARLY_NOTIFY) |
| 3391 | status = send_offload_cmd_l(out, OFFLOAD_CMD_PARTIAL_DRAIN); |
| 3392 | else |
| 3393 | status = send_offload_cmd_l(out, OFFLOAD_CMD_DRAIN); |
| 3394 | pthread_mutex_unlock(&out->lock); |
| 3395 | } |
| 3396 | return status; |
| 3397 | } |
| 3398 | |
| 3399 | static int out_flush(struct audio_stream_out* stream) |
| 3400 | { |
| 3401 | struct stream_out *out = (struct stream_out *)stream; |
| 3402 | ALOGV("%s", __func__); |
Subhash Chandra Bose Naripeddy | 16ff4f8 | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 3403 | if (is_offload_usecase(out->usecase)) { |
Apoorv Raghuvanshi | 44bd917 | 2014-05-28 14:50:07 -0700 | [diff] [blame] | 3404 | ALOGD("copl(%p):calling compress flush", out); |
Shiv Maliyappanahalli | 736d4ce | 2015-09-28 15:23:06 -0700 | [diff] [blame] | 3405 | lock_output_stream(out); |
Haynes Mathew George | afe54d8 | 2016-09-21 14:39:19 -0700 | [diff] [blame] | 3406 | if (out->offload_state == OFFLOAD_STATE_PAUSED) { |
| 3407 | stop_compressed_output_l(out); |
| 3408 | out->written = 0; |
| 3409 | } else { |
| 3410 | ALOGW("%s called in invalid state %d", __func__, out->offload_state); |
| 3411 | } |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3412 | pthread_mutex_unlock(&out->lock); |
Apoorv Raghuvanshi | 44bd917 | 2014-05-28 14:50:07 -0700 | [diff] [blame] | 3413 | ALOGD("copl(%p):out of compress flush", out); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3414 | return 0; |
| 3415 | } |
| 3416 | return -ENOSYS; |
| 3417 | } |
| 3418 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3419 | /** audio_stream_in implementation **/ |
| 3420 | static uint32_t in_get_sample_rate(const struct audio_stream *stream) |
| 3421 | { |
| 3422 | struct stream_in *in = (struct stream_in *)stream; |
| 3423 | |
| 3424 | return in->config.rate; |
| 3425 | } |
| 3426 | |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 3427 | static int in_set_sample_rate(struct audio_stream *stream __unused, |
| 3428 | uint32_t rate __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3429 | { |
| 3430 | return -ENOSYS; |
| 3431 | } |
| 3432 | |
| 3433 | static size_t in_get_buffer_size(const struct audio_stream *stream) |
| 3434 | { |
| 3435 | struct stream_in *in = (struct stream_in *)stream; |
| 3436 | |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 3437 | if(in->usecase == USECASE_COMPRESS_VOIP_CALL) |
| 3438 | return voice_extn_compress_voip_in_get_buffer_size(in); |
Mingming Yin | e62d784 | 2013-10-25 16:26:03 -0700 | [diff] [blame] | 3439 | else if(audio_extn_compr_cap_usecase_supported(in->usecase)) |
| 3440 | return audio_extn_compr_cap_get_buffer_size(in->config.format); |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 3441 | else if(audio_extn_cin_attached_usecase(in->usecase)) |
| 3442 | return audio_extn_cin_get_buffer_size(in); |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 3443 | |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 3444 | return in->config.period_size * in->af_period_multiplier * |
| 3445 | audio_stream_in_frame_size((const struct audio_stream_in *)stream); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3446 | } |
| 3447 | |
| 3448 | static uint32_t in_get_channels(const struct audio_stream *stream) |
| 3449 | { |
| 3450 | struct stream_in *in = (struct stream_in *)stream; |
| 3451 | |
| 3452 | return in->channel_mask; |
| 3453 | } |
| 3454 | |
| 3455 | static audio_format_t in_get_format(const struct audio_stream *stream) |
| 3456 | { |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 3457 | struct stream_in *in = (struct stream_in *)stream; |
| 3458 | |
| 3459 | return in->format; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3460 | } |
| 3461 | |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 3462 | static int in_set_format(struct audio_stream *stream __unused, |
| 3463 | audio_format_t format __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3464 | { |
| 3465 | return -ENOSYS; |
| 3466 | } |
| 3467 | |
| 3468 | static int in_standby(struct audio_stream *stream) |
| 3469 | { |
| 3470 | struct stream_in *in = (struct stream_in *)stream; |
| 3471 | struct audio_device *adev = in->dev; |
| 3472 | int status = 0; |
Sidipotu Ashok | f43018c | 2014-05-02 16:21:50 +0530 | [diff] [blame] | 3473 | ALOGD("%s: enter: stream (%p) usecase(%d: %s)", __func__, |
| 3474 | stream, in->usecase, use_case_table[in->usecase]); |
| 3475 | |
Shiv Maliyappanahalli | 736d4ce | 2015-09-28 15:23:06 -0700 | [diff] [blame] | 3476 | lock_input_stream(in); |
Ravi Kumar Alamanda | 8fa6b19 | 2014-09-09 16:06:42 -0700 | [diff] [blame] | 3477 | if (!in->standby && in->is_st_session) { |
| 3478 | ALOGD("%s: sound trigger pcm stop lab", __func__); |
| 3479 | audio_extn_sound_trigger_stop_lab(in); |
| 3480 | in->standby = 1; |
| 3481 | } |
| 3482 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3483 | if (!in->standby) { |
Ravi Kumar Alamanda | 8a0f977 | 2015-06-15 10:35:19 -0700 | [diff] [blame] | 3484 | if (adev->adm_deregister_stream) |
| 3485 | adev->adm_deregister_stream(adev->adm_data, in->capture_handle); |
| 3486 | |
Ravi Kumar Alamanda | 8bba9e9 | 2013-11-11 21:09:07 -0800 | [diff] [blame] | 3487 | pthread_mutex_lock(&adev->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3488 | in->standby = true; |
Zhou Song | a889504 | 2016-07-05 17:54:22 +0800 | [diff] [blame] | 3489 | if (in->usecase == USECASE_COMPRESS_VOIP_CALL) { |
| 3490 | voice_extn_compress_voip_close_input_stream(stream); |
| 3491 | ALOGD("VOIP input entered standby"); |
| 3492 | } else { |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 3493 | if (audio_extn_cin_attached_usecase(in->usecase)) |
| 3494 | audio_extn_cin_stop_input_stream(in); |
Zhou Song | a889504 | 2016-07-05 17:54:22 +0800 | [diff] [blame] | 3495 | if (in->pcm) { |
| 3496 | pcm_close(in->pcm); |
| 3497 | in->pcm = NULL; |
| 3498 | } |
| 3499 | status = stop_input_stream(in); |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 3500 | } |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 3501 | pthread_mutex_unlock(&adev->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3502 | } |
| 3503 | pthread_mutex_unlock(&in->lock); |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 3504 | ALOGV("%s: exit: status(%d)", __func__, status); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3505 | return status; |
| 3506 | } |
| 3507 | |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 3508 | static int in_dump(const struct audio_stream *stream __unused, |
| 3509 | int fd __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3510 | { |
| 3511 | return 0; |
| 3512 | } |
| 3513 | |
| 3514 | static int in_set_parameters(struct audio_stream *stream, const char *kvpairs) |
| 3515 | { |
| 3516 | struct stream_in *in = (struct stream_in *)stream; |
| 3517 | struct audio_device *adev = in->dev; |
| 3518 | struct str_parms *parms; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3519 | char value[32]; |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 3520 | int ret = 0, val = 0, err; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3521 | |
Sidipotu Ashok | f43018c | 2014-05-02 16:21:50 +0530 | [diff] [blame] | 3522 | ALOGD("%s: enter: kvpairs=%s", __func__, kvpairs); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3523 | parms = str_parms_create_str(kvpairs); |
| 3524 | |
Preetam Singh Ranawat | a5f32b4 | 2014-09-23 12:12:47 +0530 | [diff] [blame] | 3525 | if (!parms) |
| 3526 | goto error; |
Shiv Maliyappanahalli | 736d4ce | 2015-09-28 15:23:06 -0700 | [diff] [blame] | 3527 | lock_input_stream(in); |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 3528 | pthread_mutex_lock(&adev->lock); |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 3529 | |
| 3530 | err = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_INPUT_SOURCE, value, sizeof(value)); |
| 3531 | if (err >= 0) { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3532 | val = atoi(value); |
| 3533 | /* no audio source uses val == 0 */ |
| 3534 | if ((in->source != val) && (val != 0)) { |
| 3535 | in->source = val; |
Narsinga Rao Chella | 2a99dea | 2014-01-24 15:33:23 -0800 | [diff] [blame] | 3536 | if ((in->source == AUDIO_SOURCE_VOICE_COMMUNICATION) && |
| 3537 | (in->dev->mode == AUDIO_MODE_IN_COMMUNICATION) && |
| 3538 | (voice_extn_compress_voip_is_format_supported(in->format)) && |
Shiv Maliyappanahalli | e66aba2 | 2016-01-27 16:08:57 -0800 | [diff] [blame] | 3539 | (in->config.rate == 8000 || in->config.rate == 16000 || |
| 3540 | in->config.rate == 32000 || in->config.rate == 48000 ) && |
Ravi Kumar Alamanda | c3bc081 | 2014-09-08 15:34:32 -0700 | [diff] [blame] | 3541 | (audio_channel_count_from_in_mask(in->channel_mask) == 1)) { |
Narsinga Rao Chella | 7d5a3e8 | 2014-02-04 16:23:52 -0800 | [diff] [blame] | 3542 | err = voice_extn_compress_voip_open_input_stream(in); |
| 3543 | if (err != 0) { |
Narsinga Rao Chella | 2a99dea | 2014-01-24 15:33:23 -0800 | [diff] [blame] | 3544 | ALOGE("%s: Compress voip input cannot be opened, error:%d", |
Narsinga Rao Chella | 7d5a3e8 | 2014-02-04 16:23:52 -0800 | [diff] [blame] | 3545 | __func__, err); |
Narsinga Rao Chella | 2a99dea | 2014-01-24 15:33:23 -0800 | [diff] [blame] | 3546 | } |
| 3547 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3548 | } |
| 3549 | } |
| 3550 | |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 3551 | err = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, value, sizeof(value)); |
| 3552 | if (err >= 0) { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3553 | val = atoi(value); |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 3554 | if (((int)in->device != val) && (val != 0)) { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3555 | in->device = val; |
| 3556 | /* If recording is in progress, change the tx device to new device */ |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 3557 | if (!in->standby && !in->is_st_session) { |
| 3558 | ALOGV("update input routing change"); |
Haynes Mathew George | 822b549 | 2016-07-01 16:57:24 -0700 | [diff] [blame] | 3559 | if (adev->adm_on_routing_change) |
| 3560 | adev->adm_on_routing_change(adev->adm_data, |
| 3561 | in->capture_handle); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 3562 | ret = select_devices(adev, in->usecase); |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 3563 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3564 | } |
| 3565 | } |
| 3566 | |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 3567 | err = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_PROFILE, value, sizeof(value)); |
| 3568 | if (err >= 0) { |
| 3569 | strlcpy(in->profile, value, sizeof(in->profile)); |
| 3570 | ALOGV("updating stream profile with value '%s'", in->profile); |
| 3571 | audio_extn_utils_update_stream_input_app_type_cfg(adev->platform, |
| 3572 | &adev->streams_input_cfg_list, |
| 3573 | in->device, in->flags, in->format, |
| 3574 | in->sample_rate, in->bit_width, |
| 3575 | in->profile, &in->app_type_cfg); |
| 3576 | } |
| 3577 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3578 | pthread_mutex_unlock(&adev->lock); |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 3579 | pthread_mutex_unlock(&in->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3580 | |
| 3581 | str_parms_destroy(parms); |
Preetam Singh Ranawat | a5f32b4 | 2014-09-23 12:12:47 +0530 | [diff] [blame] | 3582 | error: |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 3583 | ALOGV("%s: exit: status(%d)", __func__, ret); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3584 | return ret; |
| 3585 | } |
| 3586 | |
| 3587 | static char* in_get_parameters(const struct audio_stream *stream, |
| 3588 | const char *keys) |
| 3589 | { |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 3590 | struct stream_in *in = (struct stream_in *)stream; |
| 3591 | struct str_parms *query = str_parms_create_str(keys); |
| 3592 | char *str; |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 3593 | struct str_parms *reply = str_parms_create(); |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 3594 | |
| 3595 | if (!query || !reply) { |
Alexy Joseph | aee4fdd | 2016-01-29 13:02:07 -0800 | [diff] [blame] | 3596 | if (reply) { |
| 3597 | str_parms_destroy(reply); |
| 3598 | } |
| 3599 | if (query) { |
| 3600 | str_parms_destroy(query); |
| 3601 | } |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 3602 | ALOGE("in_get_parameters: failed to create query or reply"); |
| 3603 | return NULL; |
| 3604 | } |
| 3605 | |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 3606 | ALOGV("%s: enter: keys - %s", __func__, keys); |
| 3607 | |
| 3608 | voice_extn_in_get_parameters(in, query, reply); |
| 3609 | |
| 3610 | str = str_parms_to_str(reply); |
| 3611 | str_parms_destroy(query); |
| 3612 | str_parms_destroy(reply); |
| 3613 | |
| 3614 | ALOGV("%s: exit: returns - %s", __func__, str); |
| 3615 | return str; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3616 | } |
| 3617 | |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 3618 | static int in_set_gain(struct audio_stream_in *stream __unused, |
| 3619 | float gain __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3620 | { |
| 3621 | return 0; |
| 3622 | } |
| 3623 | |
| 3624 | static ssize_t in_read(struct audio_stream_in *stream, void *buffer, |
| 3625 | size_t bytes) |
| 3626 | { |
| 3627 | struct stream_in *in = (struct stream_in *)stream; |
| 3628 | struct audio_device *adev = in->dev; |
Satya Krishna Pindiproli | f1cd92b | 2016-04-14 19:05:23 +0530 | [diff] [blame] | 3629 | int ret = -1; |
Naresh Tanniru | 8065983 | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 3630 | int snd_scard_state = get_snd_card_state(adev); |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 3631 | size_t bytes_read = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3632 | |
Shiv Maliyappanahalli | 736d4ce | 2015-09-28 15:23:06 -0700 | [diff] [blame] | 3633 | lock_input_stream(in); |
Naresh Tanniru | 4c63039 | 2014-05-12 01:05:52 +0530 | [diff] [blame] | 3634 | |
Bharath Ramachandramurthy | 76d2089 | 2015-04-27 15:47:55 -0700 | [diff] [blame] | 3635 | if (in->is_st_session) { |
| 3636 | ALOGVV(" %s: reading on st session bytes=%zu", __func__, bytes); |
| 3637 | /* Read from sound trigger HAL */ |
| 3638 | audio_extn_sound_trigger_read(in, buffer, bytes); |
| 3639 | pthread_mutex_unlock(&in->lock); |
| 3640 | return bytes; |
| 3641 | } |
| 3642 | |
Ashish Jain | bbce432 | 2016-02-16 13:25:27 +0530 | [diff] [blame] | 3643 | if (SND_CARD_STATE_OFFLINE == snd_scard_state) { |
Bharath Ramachandramurthy | 76d2089 | 2015-04-27 15:47:55 -0700 | [diff] [blame] | 3644 | ALOGD(" %s: sound card is not active/SSR state", __func__); |
| 3645 | ret= -EIO;; |
| 3646 | goto exit; |
Naresh Tanniru | 4c63039 | 2014-05-12 01:05:52 +0530 | [diff] [blame] | 3647 | } |
| 3648 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3649 | if (in->standby) { |
Bharath Ramachandramurthy | 76d2089 | 2015-04-27 15:47:55 -0700 | [diff] [blame] | 3650 | pthread_mutex_lock(&adev->lock); |
| 3651 | if (in->usecase == USECASE_COMPRESS_VOIP_CALL) |
| 3652 | ret = voice_extn_compress_voip_start_input_stream(in); |
| 3653 | else |
| 3654 | ret = start_input_stream(in); |
| 3655 | pthread_mutex_unlock(&adev->lock); |
| 3656 | if (ret != 0) { |
| 3657 | goto exit; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3658 | } |
| 3659 | in->standby = 0; |
| 3660 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3661 | |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 3662 | // what's the duration requested by the client? |
| 3663 | long ns = 0; |
| 3664 | |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 3665 | if (in->pcm && in->config.rate) |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 3666 | ns = pcm_bytes_to_frames(in->pcm, bytes)*1000000000LL/ |
| 3667 | in->config.rate; |
| 3668 | |
| 3669 | request_in_focus(in, ns); |
| 3670 | bool use_mmap = is_mmap_usecase(in->usecase) || in->realtime; |
Ravi Kumar Alamanda | 8a0f977 | 2015-06-15 10:35:19 -0700 | [diff] [blame] | 3671 | |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 3672 | if (audio_extn_cin_attached_usecase(in->usecase)) { |
| 3673 | ret = audio_extn_cin_read(in, buffer, bytes, &bytes_read); |
| 3674 | } else if (in->pcm) { |
Manish Dewangan | ba9fcfa | 2016-03-24 16:20:06 +0530 | [diff] [blame] | 3675 | if (audio_extn_ssr_get_stream() == in) { |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 3676 | ret = audio_extn_ssr_read(stream, buffer, bytes); |
Manish Dewangan | ba9fcfa | 2016-03-24 16:20:06 +0530 | [diff] [blame] | 3677 | } else if (audio_extn_compr_cap_usecase_supported(in->usecase)) { |
Mingming Yin | e62d784 | 2013-10-25 16:26:03 -0700 | [diff] [blame] | 3678 | ret = audio_extn_compr_cap_read(in, buffer, bytes); |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 3679 | } else if (use_mmap) { |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 3680 | ret = pcm_mmap_read(in->pcm, buffer, bytes); |
Manish Dewangan | ba9fcfa | 2016-03-24 16:20:06 +0530 | [diff] [blame] | 3681 | } else { |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 3682 | ret = pcm_read(in->pcm, buffer, bytes); |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 3683 | /* data from DSP comes in 24_8 format, convert it to 8_24 */ |
| 3684 | if (!ret && bytes > 0 && (in->format == AUDIO_FORMAT_PCM_8_24_BIT)) { |
| 3685 | if (audio_extn_utils_convert_format_24_8_to_8_24(buffer, bytes) |
| 3686 | != bytes) { |
Manish Dewangan | ba9fcfa | 2016-03-24 16:20:06 +0530 | [diff] [blame] | 3687 | ret = -EINVAL; |
| 3688 | goto exit; |
| 3689 | } |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 3690 | } else if (ret < 0) { |
Manish Dewangan | ba9fcfa | 2016-03-24 16:20:06 +0530 | [diff] [blame] | 3691 | ret = -errno; |
| 3692 | } |
| 3693 | } |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 3694 | /* bytes read is always set to bytes for non compress usecases */ |
| 3695 | bytes_read = bytes; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3696 | } |
| 3697 | |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 3698 | release_in_focus(in); |
Ravi Kumar Alamanda | 8a0f977 | 2015-06-15 10:35:19 -0700 | [diff] [blame] | 3699 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3700 | /* |
| 3701 | * Instead of writing zeroes here, we could trust the hardware |
| 3702 | * to always provide zeroes when muted. |
| 3703 | */ |
Pavan Chikkala | 6396484 | 2014-12-04 10:48:28 +0530 | [diff] [blame] | 3704 | if (ret == 0 && voice_get_mic_mute(adev) && !voice_is_in_call_rec_stream(in) && |
| 3705 | in->usecase != USECASE_AUDIO_RECORD_AFE_PROXY) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3706 | memset(buffer, 0, bytes); |
| 3707 | |
| 3708 | exit: |
Dhanalakshmi Siddani | 8fc6d91 | 2014-05-26 18:03:42 +0530 | [diff] [blame] | 3709 | /* ToDo: There may be a corner case when SSR happens back to back during |
Dhanalakshmi Siddani | 4d57e99 | 2014-07-17 16:37:51 +0530 | [diff] [blame] | 3710 | start/stop. Need to post different error to handle that. */ |
Bharath Ramachandramurthy | 76d2089 | 2015-04-27 15:47:55 -0700 | [diff] [blame] | 3711 | if (-ENETRESET == ret) |
| 3712 | set_snd_card_state(adev,SND_CARD_STATE_OFFLINE); |
| 3713 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3714 | pthread_mutex_unlock(&in->lock); |
| 3715 | |
| 3716 | if (ret != 0) { |
Venkata Narendra Kumar Gutta | bc9c9ca | 2014-06-25 20:38:03 +0530 | [diff] [blame] | 3717 | if (in->usecase == USECASE_COMPRESS_VOIP_CALL) { |
Venkata Narendra Kumar Gutta | 9181214 | 2014-08-11 18:20:49 +0530 | [diff] [blame] | 3718 | pthread_mutex_lock(&adev->lock); |
Venkata Narendra Kumar Gutta | bc9c9ca | 2014-06-25 20:38:03 +0530 | [diff] [blame] | 3719 | voice_extn_compress_voip_close_input_stream(&in->stream.common); |
Venkata Narendra Kumar Gutta | 9181214 | 2014-08-11 18:20:49 +0530 | [diff] [blame] | 3720 | pthread_mutex_unlock(&adev->lock); |
Venkata Narendra Kumar Gutta | bc9c9ca | 2014-06-25 20:38:03 +0530 | [diff] [blame] | 3721 | in->standby = true; |
| 3722 | } |
Dhanalakshmi Siddani | 4d57e99 | 2014-07-17 16:37:51 +0530 | [diff] [blame] | 3723 | memset(buffer, 0, bytes); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3724 | in_standby(&in->stream.common); |
Ravi Kumar Alamanda | 8fa6b19 | 2014-09-09 16:06:42 -0700 | [diff] [blame] | 3725 | ALOGV("%s: read failed status %d- sleeping for buffer duration", __func__, ret); |
Ashish Jain | bbce432 | 2016-02-16 13:25:27 +0530 | [diff] [blame] | 3726 | usleep((uint64_t)bytes * 1000000 / audio_stream_in_frame_size(stream) / |
Naresh Tanniru | 4c63039 | 2014-05-12 01:05:52 +0530 | [diff] [blame] | 3727 | in_get_sample_rate(&in->stream.common)); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3728 | } |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 3729 | return bytes_read; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3730 | } |
| 3731 | |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 3732 | 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] | 3733 | { |
| 3734 | return 0; |
| 3735 | } |
| 3736 | |
Ravi Kumar Alamanda | f70ffb4 | 2013-04-16 15:55:53 -0700 | [diff] [blame] | 3737 | static int add_remove_audio_effect(const struct audio_stream *stream, |
| 3738 | effect_handle_t effect, |
| 3739 | bool enable) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3740 | { |
Ravi Kumar Alamanda | f70ffb4 | 2013-04-16 15:55:53 -0700 | [diff] [blame] | 3741 | struct stream_in *in = (struct stream_in *)stream; |
| 3742 | int status = 0; |
| 3743 | effect_descriptor_t desc; |
| 3744 | |
| 3745 | status = (*effect)->get_descriptor(effect, &desc); |
| 3746 | if (status != 0) |
| 3747 | return status; |
| 3748 | |
Shiv Maliyappanahalli | 736d4ce | 2015-09-28 15:23:06 -0700 | [diff] [blame] | 3749 | lock_input_stream(in); |
Ravi Kumar Alamanda | f70ffb4 | 2013-04-16 15:55:53 -0700 | [diff] [blame] | 3750 | pthread_mutex_lock(&in->dev->lock); |
| 3751 | if ((in->source == AUDIO_SOURCE_VOICE_COMMUNICATION) && |
| 3752 | in->enable_aec != enable && |
| 3753 | (memcmp(&desc.type, FX_IID_AEC, sizeof(effect_uuid_t)) == 0)) { |
| 3754 | in->enable_aec = enable; |
| 3755 | if (!in->standby) |
| 3756 | select_devices(in->dev, in->usecase); |
| 3757 | } |
Ravi Kumar Alamanda | 198185e | 2013-11-07 15:42:19 -0800 | [diff] [blame] | 3758 | if (in->enable_ns != enable && |
| 3759 | (memcmp(&desc.type, FX_IID_NS, sizeof(effect_uuid_t)) == 0)) { |
| 3760 | in->enable_ns = enable; |
| 3761 | if (!in->standby) |
| 3762 | select_devices(in->dev, in->usecase); |
| 3763 | } |
Ravi Kumar Alamanda | f70ffb4 | 2013-04-16 15:55:53 -0700 | [diff] [blame] | 3764 | pthread_mutex_unlock(&in->dev->lock); |
| 3765 | pthread_mutex_unlock(&in->lock); |
| 3766 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3767 | return 0; |
| 3768 | } |
| 3769 | |
Ravi Kumar Alamanda | f70ffb4 | 2013-04-16 15:55:53 -0700 | [diff] [blame] | 3770 | static int in_add_audio_effect(const struct audio_stream *stream, |
| 3771 | effect_handle_t effect) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3772 | { |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 3773 | ALOGV("%s: effect %p", __func__, effect); |
Ravi Kumar Alamanda | f70ffb4 | 2013-04-16 15:55:53 -0700 | [diff] [blame] | 3774 | return add_remove_audio_effect(stream, effect, true); |
| 3775 | } |
| 3776 | |
| 3777 | static int in_remove_audio_effect(const struct audio_stream *stream, |
| 3778 | effect_handle_t effect) |
| 3779 | { |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 3780 | ALOGV("%s: effect %p", __func__, effect); |
Ravi Kumar Alamanda | f70ffb4 | 2013-04-16 15:55:53 -0700 | [diff] [blame] | 3781 | return add_remove_audio_effect(stream, effect, false); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3782 | } |
| 3783 | |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 3784 | int adev_open_output_stream(struct audio_hw_device *dev, |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3785 | audio_io_handle_t handle, |
| 3786 | audio_devices_t devices, |
| 3787 | audio_output_flags_t flags, |
| 3788 | struct audio_config *config, |
Ravi Kumar Alamanda | c3bc081 | 2014-09-08 15:34:32 -0700 | [diff] [blame] | 3789 | struct audio_stream_out **stream_out, |
| 3790 | const char *address __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3791 | { |
| 3792 | struct audio_device *adev = (struct audio_device *)dev; |
| 3793 | struct stream_out *out; |
Satya Krishna Pindiproli | f1cd92b | 2016-04-14 19:05:23 +0530 | [diff] [blame] | 3794 | int ret = 0; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 3795 | audio_format_t format; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3796 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3797 | *stream_out = NULL; |
Naresh Tanniru | 8065983 | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 3798 | |
| 3799 | if ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) && |
| 3800 | (SND_CARD_STATE_OFFLINE == get_snd_card_state(adev))) { |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 3801 | ALOGE("sound card is not active rejecting compress output open request"); |
Naresh Tanniru | 8065983 | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 3802 | return -EINVAL; |
| 3803 | } |
| 3804 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3805 | out = (struct stream_out *)calloc(1, sizeof(struct stream_out)); |
| 3806 | |
Mingming Yin | 3a941d4 | 2016-02-17 18:08:05 -0800 | [diff] [blame] | 3807 | ALOGD("%s: enter: format(%#x) sample_rate(%d) channel_mask(%#x) devices(%#x) flags(%#x)\ |
| 3808 | stream_handle(%p)", __func__, config->format, config->sample_rate, config->channel_mask, |
Sidipotu Ashok | f43018c | 2014-05-02 16:21:50 +0530 | [diff] [blame] | 3809 | devices, flags, &out->stream); |
| 3810 | |
| 3811 | |
Haynes Mathew George | b9012ab | 2013-12-10 13:44:56 -0800 | [diff] [blame] | 3812 | if (!out) { |
| 3813 | return -ENOMEM; |
| 3814 | } |
| 3815 | |
Haynes Mathew George | 204045b | 2015-02-25 20:32:03 -0800 | [diff] [blame] | 3816 | pthread_mutex_init(&out->lock, (const pthread_mutexattr_t *) NULL); |
Shiv Maliyappanahalli | 736d4ce | 2015-09-28 15:23:06 -0700 | [diff] [blame] | 3817 | pthread_mutex_init(&out->pre_lock, (const pthread_mutexattr_t *) NULL); |
Haynes Mathew George | 204045b | 2015-02-25 20:32:03 -0800 | [diff] [blame] | 3818 | pthread_cond_init(&out->cond, (const pthread_condattr_t *) NULL); |
| 3819 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3820 | if (devices == AUDIO_DEVICE_NONE) |
| 3821 | devices = AUDIO_DEVICE_OUT_SPEAKER; |
| 3822 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3823 | out->flags = flags; |
| 3824 | out->devices = devices; |
Haynes Mathew George | 47cd4cb | 2013-07-19 11:58:50 -0700 | [diff] [blame] | 3825 | out->dev = adev; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 3826 | format = out->format = config->format; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3827 | out->sample_rate = config->sample_rate; |
| 3828 | out->channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 3829 | out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_STEREO; |
Eric Laurent | c4aef75 | 2013-09-12 17:45:53 -0700 | [diff] [blame] | 3830 | out->handle = handle; |
Mingming Yin | 3ee55c6 | 2014-08-04 14:23:35 -0700 | [diff] [blame] | 3831 | out->bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH; |
Alexy Joseph | aa54c87 | 2014-12-03 02:46:47 -0800 | [diff] [blame] | 3832 | out->non_blocking = 0; |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 3833 | out->convert_buffer = NULL; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3834 | |
Mingming Yin | 3a941d4 | 2016-02-17 18:08:05 -0800 | [diff] [blame] | 3835 | if (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL && |
| 3836 | (flags & AUDIO_OUTPUT_FLAG_DIRECT)) { |
| 3837 | pthread_mutex_lock(&adev->lock); |
| 3838 | ALOGV("AUDIO_DEVICE_OUT_AUX_DIGITAL and DIRECT|OFFLOAD, check hdmi caps"); |
| 3839 | ret = read_hdmi_sink_caps(out); |
| 3840 | pthread_mutex_unlock(&adev->lock); |
| 3841 | if (ret != 0) { |
| 3842 | if (ret == -ENOSYS) { |
| 3843 | /* ignore and go with default */ |
| 3844 | ret = 0; |
| 3845 | } else { |
| 3846 | ALOGE("error reading hdmi sink caps"); |
| 3847 | goto error_open; |
| 3848 | } |
| 3849 | } |
| 3850 | } |
| 3851 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3852 | /* Init use case and pcm_config */ |
Mingming Yin | 57c4662 | 2015-07-21 15:22:22 -0700 | [diff] [blame] | 3853 | if ((out->flags & AUDIO_OUTPUT_FLAG_DIRECT) && |
Satya Krishna Pindiproli | 125900e | 2016-01-22 14:32:15 +0530 | [diff] [blame] | 3854 | !(out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD || |
| 3855 | (out->flags & AUDIO_OUTPUT_FLAG_DIRECT_PCM)) && |
Apoorv Raghuvanshi | 947cb90 | 2013-12-09 13:45:39 -0800 | [diff] [blame] | 3856 | (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL || |
| 3857 | out->devices & AUDIO_DEVICE_OUT_PROXY)) { |
| 3858 | |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 3859 | pthread_mutex_lock(&adev->lock); |
Mingming Yin | 3a941d4 | 2016-02-17 18:08:05 -0800 | [diff] [blame] | 3860 | if (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
| 3861 | /* |
| 3862 | * Do not handle stereo output in Multi-channel cases |
| 3863 | * Stereo case is handled in normal playback path |
| 3864 | */ |
| 3865 | if (out->supported_channel_masks[0] == AUDIO_CHANNEL_OUT_STEREO) |
| 3866 | ret = AUDIO_CHANNEL_OUT_STEREO; |
| 3867 | } |
Apoorv Raghuvanshi | 947cb90 | 2013-12-09 13:45:39 -0800 | [diff] [blame] | 3868 | |
| 3869 | if (out->devices & AUDIO_DEVICE_OUT_PROXY) |
| 3870 | ret = audio_extn_read_afe_proxy_channel_masks(out); |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 3871 | pthread_mutex_unlock(&adev->lock); |
Eric Laurent | 07eeafd | 2013-10-06 12:52:49 -0700 | [diff] [blame] | 3872 | if (ret != 0) |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 3873 | goto error_open; |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 3874 | |
| 3875 | if (config->sample_rate == 0) |
| 3876 | config->sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; |
| 3877 | if (config->channel_mask == 0) |
| 3878 | config->channel_mask = AUDIO_CHANNEL_OUT_5POINT1; |
Mingming Yin | 3a941d4 | 2016-02-17 18:08:05 -0800 | [diff] [blame] | 3879 | if (config->format == 0) |
| 3880 | config->format = AUDIO_FORMAT_PCM_16_BIT; |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 3881 | |
| 3882 | out->channel_mask = config->channel_mask; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3883 | out->sample_rate = config->sample_rate; |
Mingming Yin | 3a941d4 | 2016-02-17 18:08:05 -0800 | [diff] [blame] | 3884 | out->format = config->format; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3885 | out->usecase = USECASE_AUDIO_PLAYBACK_MULTI_CH; |
| 3886 | out->config = pcm_config_hdmi_multi; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 3887 | out->config.rate = config->sample_rate; |
Ravi Kumar Alamanda | c3bc081 | 2014-09-08 15:34:32 -0700 | [diff] [blame] | 3888 | 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] | 3889 | out->config.period_size = HDMI_MULTI_PERIOD_BYTES / (out->config.channels * 2); |
kunleiz | c5fefba | 2016-11-15 11:20:56 +0800 | [diff] [blame] | 3890 | } else if ((out->dev->mode == AUDIO_MODE_IN_COMMUNICATION || voice_extn_compress_voip_is_active(out->dev)) && |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 3891 | (out->flags == (AUDIO_OUTPUT_FLAG_DIRECT | AUDIO_OUTPUT_FLAG_VOIP_RX)) && |
Narsinga Rao Chella | 1eceff8 | 2013-12-02 19:25:28 -0800 | [diff] [blame] | 3892 | (voice_extn_compress_voip_is_config_supported(config))) { |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 3893 | ret = voice_extn_compress_voip_open_output_stream(out); |
| 3894 | if (ret != 0) { |
| 3895 | ALOGE("%s: Compress voip output cannot be opened, error:%d", |
| 3896 | __func__, ret); |
| 3897 | goto error_open; |
| 3898 | } |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 3899 | } else if ((out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) || |
| 3900 | (out->flags & AUDIO_OUTPUT_FLAG_DIRECT_PCM)) { |
| 3901 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3902 | if (config->offload_info.version != AUDIO_INFO_INITIALIZER.version || |
| 3903 | config->offload_info.size != AUDIO_INFO_INITIALIZER.size) { |
| 3904 | ALOGE("%s: Unsupported Offload information", __func__); |
| 3905 | ret = -EINVAL; |
| 3906 | goto error_open; |
| 3907 | } |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 3908 | |
Mingming Yin | 3a941d4 | 2016-02-17 18:08:05 -0800 | [diff] [blame] | 3909 | if (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 3910 | if(config->offload_info.format == 0) |
| 3911 | config->offload_info.format = out->supported_formats[0]; |
Mingming Yin | 3a941d4 | 2016-02-17 18:08:05 -0800 | [diff] [blame] | 3912 | if (config->offload_info.sample_rate == 0) |
| 3913 | config->offload_info.sample_rate = out->supported_sample_rates[0]; |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 3914 | } |
| 3915 | |
Mingming Yin | 9031010 | 2013-11-13 16:57:00 -0800 | [diff] [blame] | 3916 | if (!is_supported_format(config->offload_info.format) && |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 3917 | !audio_extn_passthru_is_supported_format(config->offload_info.format)) { |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 3918 | ALOGE("%s: Unsupported audio format %x " , __func__, config->offload_info.format); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3919 | ret = -EINVAL; |
| 3920 | goto error_open; |
| 3921 | } |
| 3922 | |
| 3923 | out->compr_config.codec = (struct snd_codec *) |
| 3924 | calloc(1, sizeof(struct snd_codec)); |
| 3925 | |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 3926 | if (!out->compr_config.codec) { |
| 3927 | ret = -ENOMEM; |
| 3928 | goto error_open; |
| 3929 | } |
| 3930 | |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 3931 | if (out->flags & AUDIO_OUTPUT_FLAG_DIRECT_PCM) { |
Ashish Jain | 5106d36 | 2016-05-11 19:23:33 +0530 | [diff] [blame] | 3932 | out->stream.pause = out_pause; |
| 3933 | out->stream.flush = out_flush; |
| 3934 | out->stream.resume = out_resume; |
vivek mehta | 446c396 | 2015-09-14 10:57:35 -0700 | [diff] [blame] | 3935 | out->usecase = get_offload_usecase(adev, true); |
| 3936 | ALOGV("DIRECT_PCM usecase ... usecase selected %d ", out->usecase); |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 3937 | } else { |
Mingming Yin | 21d6047 | 2015-09-30 13:56:25 -0700 | [diff] [blame] | 3938 | out->stream.set_callback = out_set_callback; |
| 3939 | out->stream.pause = out_pause; |
| 3940 | out->stream.resume = out_resume; |
| 3941 | out->stream.drain = out_drain; |
| 3942 | out->stream.flush = out_flush; |
vivek mehta | 446c396 | 2015-09-14 10:57:35 -0700 | [diff] [blame] | 3943 | out->usecase = get_offload_usecase(adev, false); |
| 3944 | ALOGV("Compress Offload usecase .. usecase selected %d", out->usecase); |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 3945 | } |
vivek mehta | 446c396 | 2015-09-14 10:57:35 -0700 | [diff] [blame] | 3946 | |
| 3947 | if (out->usecase == USECASE_INVALID) { |
Mingming Yin | 3a941d4 | 2016-02-17 18:08:05 -0800 | [diff] [blame] | 3948 | if (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL && |
| 3949 | config->format == 0 && config->sample_rate == 0 && |
| 3950 | config->channel_mask == 0) { |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 3951 | ALOGI("%s dummy open to query sink capability",__func__); |
Mingming Yin | 3a941d4 | 2016-02-17 18:08:05 -0800 | [diff] [blame] | 3952 | out->usecase = USECASE_AUDIO_PLAYBACK_OFFLOAD; |
| 3953 | } else { |
| 3954 | ALOGE("%s, Max allowed OFFLOAD usecase reached ... ", __func__); |
| 3955 | ret = -EEXIST; |
| 3956 | goto error_open; |
| 3957 | } |
vivek mehta | 446c396 | 2015-09-14 10:57:35 -0700 | [diff] [blame] | 3958 | } |
| 3959 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3960 | if (config->offload_info.channel_mask) |
| 3961 | out->channel_mask = config->offload_info.channel_mask; |
ApurupaPattapu | c6a3a9e | 2014-01-10 14:46:02 -0800 | [diff] [blame] | 3962 | else if (config->channel_mask) { |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3963 | out->channel_mask = config->channel_mask; |
ApurupaPattapu | c6a3a9e | 2014-01-10 14:46:02 -0800 | [diff] [blame] | 3964 | config->offload_info.channel_mask = config->channel_mask; |
Haynes Mathew George | a99f753 | 2016-08-24 16:01:21 -0700 | [diff] [blame] | 3965 | } else { |
| 3966 | ALOGE("out->channel_mask not set for OFFLOAD/DIRECT_PCM"); |
| 3967 | ret = -EINVAL; |
| 3968 | goto error_open; |
ApurupaPattapu | c6a3a9e | 2014-01-10 14:46:02 -0800 | [diff] [blame] | 3969 | } |
Haynes Mathew George | a99f753 | 2016-08-24 16:01:21 -0700 | [diff] [blame] | 3970 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 3971 | format = out->format = config->offload_info.format; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3972 | out->sample_rate = config->offload_info.sample_rate; |
| 3973 | |
Mingming Yin | 3ee55c6 | 2014-08-04 14:23:35 -0700 | [diff] [blame] | 3974 | out->bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3975 | |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 3976 | out->compr_config.codec->id = get_snd_codec_id(config->offload_info.format); |
| 3977 | if (audio_extn_is_dolby_format(config->offload_info.format)) { |
| 3978 | audio_extn_dolby_send_ddp_endp_params(adev); |
| 3979 | audio_extn_dolby_set_dmid(adev); |
| 3980 | } |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 3981 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3982 | out->compr_config.codec->sample_rate = |
Ravi Kumar Alamanda | b91bff3 | 2014-11-14 12:05:54 -0800 | [diff] [blame] | 3983 | config->offload_info.sample_rate; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3984 | out->compr_config.codec->bit_rate = |
| 3985 | config->offload_info.bit_rate; |
| 3986 | out->compr_config.codec->ch_in = |
Dhanalakshmi Siddani | a15c679 | 2016-08-10 15:33:53 +0530 | [diff] [blame] | 3987 | audio_channel_count_from_out_mask(out->channel_mask); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3988 | out->compr_config.codec->ch_out = out->compr_config.codec->ch_in; |
Satya Krishna Pindiproli | 5d82d01 | 2015-08-12 18:21:25 +0530 | [diff] [blame] | 3989 | out->bit_width = AUDIO_OUTPUT_BIT_WIDTH; |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 3990 | /*TODO: Do we need to change it for passthrough */ |
| 3991 | out->compr_config.codec->format = SND_AUDIOSTREAMFORMAT_RAW; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 3992 | |
Manish Dewangan | a6fc544 | 2015-08-24 20:30:31 +0530 | [diff] [blame] | 3993 | if ((config->offload_info.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_AAC) |
| 3994 | out->compr_config.codec->format = SND_AUDIOSTREAMFORMAT_RAW; |
Arun Kumar Dasari | 3b17418 | 2016-12-27 13:01:14 +0530 | [diff] [blame] | 3995 | else if ((config->offload_info.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_AAC_ADTS) |
Manish Dewangan | a6fc544 | 2015-08-24 20:30:31 +0530 | [diff] [blame] | 3996 | out->compr_config.codec->format = SND_AUDIOSTREAMFORMAT_MP4ADTS; |
Arun Kumar Dasari | 3b17418 | 2016-12-27 13:01:14 +0530 | [diff] [blame] | 3997 | else if ((config->offload_info.format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_AAC_LATM) |
| 3998 | out->compr_config.codec->format = SND_AUDIOSTREAMFORMAT_MP4LATM; |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 3999 | |
| 4000 | if ((config->offload_info.format & AUDIO_FORMAT_MAIN_MASK) == |
| 4001 | AUDIO_FORMAT_PCM) { |
| 4002 | |
| 4003 | /*Based on platform support, configure appropriate alsa format for corresponding |
| 4004 | *hal input format. |
| 4005 | */ |
| 4006 | out->compr_config.codec->format = hal_format_to_alsa( |
| 4007 | config->offload_info.format); |
| 4008 | |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 4009 | out->hal_op_format = alsa_format_to_hal( |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 4010 | out->compr_config.codec->format); |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 4011 | out->hal_ip_format = out->format; |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 4012 | |
| 4013 | /*for direct PCM playback populate bit_width based on selected alsa format as |
| 4014 | *hal input format and alsa format might differ based on platform support. |
| 4015 | */ |
| 4016 | out->bit_width = audio_bytes_per_sample( |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 4017 | out->hal_op_format) << 3; |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 4018 | |
| 4019 | out->compr_config.fragments = DIRECT_PCM_NUM_FRAGMENTS; |
| 4020 | |
| 4021 | /* Check if alsa session is configured with the same format as HAL input format, |
| 4022 | * if not then derive correct fragment size needed to accomodate the |
| 4023 | * conversion of HAL input format to alsa format. |
| 4024 | */ |
| 4025 | audio_extn_utils_update_direct_pcm_fragment_size(out); |
| 4026 | |
| 4027 | /*if hal input and output fragment size is different this indicates HAL input format is |
| 4028 | *not same as the alsa format |
| 4029 | */ |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 4030 | if (out->hal_fragment_size != out->compr_config.fragment_size) { |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 4031 | /*Allocate a buffer to convert input data to the alsa configured format. |
| 4032 | *size of convert buffer is equal to the size required to hold one fragment size |
| 4033 | *worth of pcm data, this is because flinger does not write more than fragment_size |
| 4034 | */ |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 4035 | out->convert_buffer = calloc(1,out->compr_config.fragment_size); |
| 4036 | if (out->convert_buffer == NULL){ |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 4037 | ALOGE("Allocation failed for convert buffer for size %d", out->compr_config.fragment_size); |
| 4038 | ret = -ENOMEM; |
| 4039 | goto error_open; |
| 4040 | } |
| 4041 | } |
| 4042 | } else if (audio_extn_passthru_is_passthrough_stream(out)) { |
| 4043 | out->compr_config.fragment_size = |
| 4044 | audio_extn_passthru_get_buffer_size(&config->offload_info); |
| 4045 | out->compr_config.fragments = COMPRESS_OFFLOAD_NUM_FRAGMENTS; |
| 4046 | } else { |
| 4047 | out->compr_config.fragment_size = |
| 4048 | platform_get_compress_offload_buffer_size(&config->offload_info); |
| 4049 | out->compr_config.fragments = COMPRESS_OFFLOAD_NUM_FRAGMENTS; |
| 4050 | } |
Mingming Yin | 3ee55c6 | 2014-08-04 14:23:35 -0700 | [diff] [blame] | 4051 | |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 4052 | if (config->offload_info.format == AUDIO_FORMAT_FLAC) |
Satya Krishna Pindiproli | 5d82d01 | 2015-08-12 18:21:25 +0530 | [diff] [blame] | 4053 | out->compr_config.codec->options.flac_dec.sample_size = AUDIO_OUTPUT_BIT_WIDTH; |
Mingming Yin | 3ee55c6 | 2014-08-04 14:23:35 -0700 | [diff] [blame] | 4054 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 4055 | if (flags & AUDIO_OUTPUT_FLAG_NON_BLOCKING) |
| 4056 | out->non_blocking = 1; |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 4057 | |
Alexy Joseph | aa54c87 | 2014-12-03 02:46:47 -0800 | [diff] [blame] | 4058 | |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 4059 | out->send_new_metadata = 1; |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 4060 | out->send_next_track_params = false; |
| 4061 | out->is_compr_metadata_avail = false; |
Haynes Mathew George | b9012ab | 2013-12-10 13:44:56 -0800 | [diff] [blame] | 4062 | out->offload_state = OFFLOAD_STATE_IDLE; |
| 4063 | out->playback_started = 0; |
| 4064 | |
Jitendra Naruka | 1b6513f | 2014-11-22 19:34:13 -0800 | [diff] [blame] | 4065 | audio_extn_dts_create_state_notifier_node(out->usecase); |
| 4066 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 4067 | ALOGV("%s: offloaded output offload_info version %04x bit rate %d", |
| 4068 | __func__, config->offload_info.version, |
| 4069 | config->offload_info.bit_rate); |
Ashish Jain | 5106d36 | 2016-05-11 19:23:33 +0530 | [diff] [blame] | 4070 | |
Preetam Singh Ranawat | f5fbdd6 | 2016-09-29 18:38:31 +0530 | [diff] [blame] | 4071 | /* Check if DSD audio format is supported in codec |
| 4072 | * and there is no active native DSD use case |
Preetam Singh Ranawat | cb6212e | 2016-07-19 18:33:53 +0530 | [diff] [blame] | 4073 | */ |
| 4074 | |
| 4075 | if ((config->format == AUDIO_FORMAT_DSD) && |
Preetam Singh Ranawat | f5fbdd6 | 2016-09-29 18:38:31 +0530 | [diff] [blame] | 4076 | (!platform_check_codec_dsd_support(adev->platform) || |
| 4077 | audio_is_dsd_native_stream_active(adev))) { |
Preetam Singh Ranawat | cb6212e | 2016-07-19 18:33:53 +0530 | [diff] [blame] | 4078 | ret = -EINVAL; |
| 4079 | goto error_open; |
| 4080 | } |
| 4081 | |
Ashish Jain | 5106d36 | 2016-05-11 19:23:33 +0530 | [diff] [blame] | 4082 | /* Disable gapless if any of the following is true |
| 4083 | * passthrough playback |
| 4084 | * AV playback |
| 4085 | * Direct PCM playback |
| 4086 | */ |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 4087 | if (audio_extn_passthru_is_passthrough_stream(out) || |
Preetam Singh Ranawat | f5fbdd6 | 2016-09-29 18:38:31 +0530 | [diff] [blame] | 4088 | (config->format == AUDIO_FORMAT_DSD) || |
| 4089 | config->offload_info.has_video || |
| 4090 | out->flags & AUDIO_OUTPUT_FLAG_DIRECT_PCM) { |
Ashish Jain | 5106d36 | 2016-05-11 19:23:33 +0530 | [diff] [blame] | 4091 | check_and_set_gapless_mode(adev, false); |
| 4092 | } else |
| 4093 | check_and_set_gapless_mode(adev, true); |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 4094 | |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 4095 | if (audio_extn_passthru_is_passthrough_stream(out)) { |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 4096 | out->flags |= AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH; |
| 4097 | } |
Preetam Singh Ranawat | cb6212e | 2016-07-19 18:33:53 +0530 | [diff] [blame] | 4098 | if (config->format == AUDIO_FORMAT_DSD) { |
| 4099 | out->flags |= AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH; |
| 4100 | out->compr_config.codec->compr_passthr = PASSTHROUGH_DSD; |
| 4101 | } |
Aalique Grahame | 0359a1f | 2016-09-08 16:54:22 -0700 | [diff] [blame] | 4102 | |
| 4103 | create_offload_callback_thread(out); |
| 4104 | |
Shiv Maliyappanahalli | f3b9a42 | 2013-10-22 16:38:08 -0700 | [diff] [blame] | 4105 | } else if (out->flags & AUDIO_OUTPUT_FLAG_INCALL_MUSIC) { |
Satya Krishna Pindiproli | f1cd92b | 2016-04-14 19:05:23 +0530 | [diff] [blame] | 4106 | ret = voice_extn_check_and_set_incall_music_usecase(adev, out); |
Shiv Maliyappanahalli | f3b9a42 | 2013-10-22 16:38:08 -0700 | [diff] [blame] | 4107 | if (ret != 0) { |
| 4108 | ALOGE("%s: Incall music delivery usecase cannot be set error:%d", |
| 4109 | __func__, ret); |
| 4110 | goto error_open; |
| 4111 | } |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 4112 | } else if (out->devices == AUDIO_DEVICE_OUT_TELEPHONY_TX) { |
| 4113 | if (config->sample_rate == 0) |
| 4114 | config->sample_rate = AFE_PROXY_SAMPLING_RATE; |
| 4115 | if (config->sample_rate != 48000 && config->sample_rate != 16000 && |
| 4116 | config->sample_rate != 8000) { |
| 4117 | config->sample_rate = AFE_PROXY_SAMPLING_RATE; |
| 4118 | ret = -EINVAL; |
| 4119 | goto error_open; |
| 4120 | } |
| 4121 | out->sample_rate = config->sample_rate; |
| 4122 | out->config.rate = config->sample_rate; |
| 4123 | if (config->format == AUDIO_FORMAT_DEFAULT) |
| 4124 | config->format = AUDIO_FORMAT_PCM_16_BIT; |
| 4125 | if (config->format != AUDIO_FORMAT_PCM_16_BIT) { |
| 4126 | config->format = AUDIO_FORMAT_PCM_16_BIT; |
| 4127 | ret = -EINVAL; |
| 4128 | goto error_open; |
| 4129 | } |
| 4130 | out->format = config->format; |
| 4131 | out->usecase = USECASE_AUDIO_PLAYBACK_AFE_PROXY; |
| 4132 | out->config = pcm_config_afe_proxy_playback; |
| 4133 | adev->voice_tx_output = out; |
Ravi Kumar Alamanda | 8f715d9 | 2013-11-01 20:37:38 -0700 | [diff] [blame] | 4134 | } else { |
Ashish Jain | 058165c | 2016-09-28 23:18:48 +0530 | [diff] [blame] | 4135 | unsigned int channels = 0; |
| 4136 | /*Update config params to default if not set by the caller*/ |
| 4137 | if (config->sample_rate == 0) |
| 4138 | config->sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; |
| 4139 | if (config->channel_mask == AUDIO_CHANNEL_NONE) |
| 4140 | config->channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 4141 | if (config->format == AUDIO_FORMAT_DEFAULT) |
| 4142 | config->format = AUDIO_FORMAT_PCM_16_BIT; |
| 4143 | |
| 4144 | channels = audio_channel_count_from_out_mask(out->channel_mask); |
| 4145 | |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 4146 | if (out->flags & AUDIO_OUTPUT_FLAG_RAW) { |
| 4147 | out->usecase = USECASE_AUDIO_PLAYBACK_ULL; |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 4148 | out->realtime = may_use_noirq_mode(adev, USECASE_AUDIO_PLAYBACK_ULL, |
| 4149 | out->flags); |
| 4150 | out->config = out->realtime ? pcm_config_rt : pcm_config_low_latency; |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 4151 | } else if (out->flags & AUDIO_OUTPUT_FLAG_FAST) { |
| 4152 | out->usecase = USECASE_AUDIO_PLAYBACK_LOW_LATENCY; |
| 4153 | out->config = pcm_config_low_latency; |
| 4154 | } else if (out->flags & AUDIO_OUTPUT_FLAG_DEEP_BUFFER) { |
| 4155 | out->usecase = USECASE_AUDIO_PLAYBACK_DEEP_BUFFER; |
| 4156 | out->config = pcm_config_deep_buffer; |
Ashish Jain | 058165c | 2016-09-28 23:18:48 +0530 | [diff] [blame] | 4157 | out->config.period_size = get_output_period_size(config->sample_rate, out->format, |
| 4158 | channels, DEEP_BUFFER_OUTPUT_PERIOD_DURATION); |
| 4159 | if (out->config.period_size <= 0) { |
| 4160 | ALOGE("Invalid configuration period size is not valid"); |
| 4161 | ret = -EINVAL; |
| 4162 | goto error_open; |
| 4163 | } |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 4164 | } else { |
| 4165 | /* primary path is the default path selected if no other outputs are available/suitable */ |
| 4166 | out->usecase = USECASE_AUDIO_PLAYBACK_PRIMARY; |
| 4167 | out->config = PCM_CONFIG_AUDIO_PLAYBACK_PRIMARY; |
| 4168 | } |
| 4169 | out->hal_ip_format = format = out->format; |
| 4170 | out->config.format = hal_format_to_pcm(out->hal_ip_format); |
| 4171 | out->hal_op_format = pcm_format_to_hal(out->config.format); |
| 4172 | out->bit_width = format_to_bitwidth_table[out->hal_op_format] << 3; |
| 4173 | out->config.rate = config->sample_rate; |
Ravi Kumar Alamanda | 8f715d9 | 2013-11-01 20:37:38 -0700 | [diff] [blame] | 4174 | out->sample_rate = out->config.rate; |
Ashish Jain | 058165c | 2016-09-28 23:18:48 +0530 | [diff] [blame] | 4175 | out->config.channels = channels; |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 4176 | if (out->hal_ip_format != out->hal_op_format) { |
| 4177 | uint32_t buffer_size = out->config.period_size * |
| 4178 | format_to_bitwidth_table[out->hal_op_format] * |
| 4179 | out->config.channels; |
| 4180 | out->convert_buffer = calloc(1, buffer_size); |
| 4181 | if (out->convert_buffer == NULL){ |
| 4182 | ALOGE("Allocation failed for convert buffer for size %d", |
| 4183 | out->compr_config.fragment_size); |
| 4184 | ret = -ENOMEM; |
| 4185 | goto error_open; |
| 4186 | } |
| 4187 | ALOGD("Convert buffer allocated of size %d", buffer_size); |
| 4188 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4189 | } |
| 4190 | |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 4191 | ALOGV("%s devices:%d, format:%x, out->sample_rate:%d,out->bit_width:%d out->format:%d out->flags:%x, flags:%x", |
| 4192 | __func__, devices, format, out->sample_rate, out->bit_width, out->format, out->flags, flags); |
| 4193 | |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 4194 | /* TODO remove this hardcoding and check why width is zero*/ |
| 4195 | if (out->bit_width == 0) |
| 4196 | out->bit_width = 16; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 4197 | audio_extn_utils_update_stream_output_app_type_cfg(adev->platform, |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 4198 | &adev->streams_output_cfg_list, |
Amit Shekhar | 1d89604 | 2014-10-03 13:16:09 -0700 | [diff] [blame] | 4199 | devices, flags, format, out->sample_rate, |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 4200 | out->bit_width, out->channel_mask, out->profile, |
Manish Dewangan | 837dc46 | 2015-05-27 10:17:41 +0530 | [diff] [blame] | 4201 | &out->app_type_cfg); |
Haynes Mathew George | bf14371 | 2013-12-03 13:02:53 -0800 | [diff] [blame] | 4202 | if ((out->usecase == USECASE_AUDIO_PLAYBACK_PRIMARY) || |
| 4203 | (flags & AUDIO_OUTPUT_FLAG_PRIMARY)) { |
| 4204 | /* Ensure the default output is not selected twice */ |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 4205 | if(adev->primary_output == NULL) |
| 4206 | adev->primary_output = out; |
| 4207 | else { |
| 4208 | ALOGE("%s: Primary output is already opened", __func__); |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 4209 | ret = -EEXIST; |
| 4210 | goto error_open; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 4211 | } |
| 4212 | } |
| 4213 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4214 | /* Check if this usecase is already existing */ |
| 4215 | pthread_mutex_lock(&adev->lock); |
Narsinga Rao Chella | 7ce0535 | 2014-04-17 20:00:41 -0700 | [diff] [blame] | 4216 | if ((get_usecase_from_list(adev, out->usecase) != NULL) && |
| 4217 | (out->usecase != USECASE_COMPRESS_VOIP_CALL)) { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4218 | ALOGE("%s: Usecase (%d) is already present", __func__, out->usecase); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4219 | pthread_mutex_unlock(&adev->lock); |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 4220 | ret = -EEXIST; |
| 4221 | goto error_open; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4222 | } |
| 4223 | pthread_mutex_unlock(&adev->lock); |
| 4224 | |
| 4225 | out->stream.common.get_sample_rate = out_get_sample_rate; |
| 4226 | out->stream.common.set_sample_rate = out_set_sample_rate; |
| 4227 | out->stream.common.get_buffer_size = out_get_buffer_size; |
| 4228 | out->stream.common.get_channels = out_get_channels; |
| 4229 | out->stream.common.get_format = out_get_format; |
| 4230 | out->stream.common.set_format = out_set_format; |
| 4231 | out->stream.common.standby = out_standby; |
| 4232 | out->stream.common.dump = out_dump; |
| 4233 | out->stream.common.set_parameters = out_set_parameters; |
| 4234 | out->stream.common.get_parameters = out_get_parameters; |
| 4235 | out->stream.common.add_audio_effect = out_add_audio_effect; |
| 4236 | out->stream.common.remove_audio_effect = out_remove_audio_effect; |
| 4237 | out->stream.get_latency = out_get_latency; |
| 4238 | out->stream.set_volume = out_set_volume; |
| 4239 | out->stream.write = out_write; |
| 4240 | out->stream.get_render_position = out_get_render_position; |
| 4241 | out->stream.get_next_write_timestamp = out_get_next_write_timestamp; |
Glenn Kasten | 2ccd7ba | 2013-09-10 09:04:31 -0700 | [diff] [blame] | 4242 | out->stream.get_presentation_position = out_get_presentation_position; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4243 | |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 4244 | out->af_period_multiplier = out->realtime ? af_period_multiplier : 1; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4245 | out->standby = 1; |
Eric Laurent | a9024de | 2013-04-04 09:19:12 -0700 | [diff] [blame] | 4246 | /* out->muted = false; by calloc() */ |
Glenn Kasten | 2ccd7ba | 2013-09-10 09:04:31 -0700 | [diff] [blame] | 4247 | /* out->written = 0; by calloc() */ |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4248 | |
| 4249 | config->format = out->stream.common.get_format(&out->stream.common); |
| 4250 | config->channel_mask = out->stream.common.get_channels(&out->stream.common); |
| 4251 | config->sample_rate = out->stream.common.get_sample_rate(&out->stream.common); |
| 4252 | |
| 4253 | *stream_out = &out->stream; |
Sidipotu Ashok | f43018c | 2014-05-02 16:21:50 +0530 | [diff] [blame] | 4254 | ALOGD("%s: Stream (%p) picks up usecase (%s)", __func__, &out->stream, |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 4255 | use_case_table[out->usecase]); |
Jitendra Naruka | 1b6513f | 2014-11-22 19:34:13 -0800 | [diff] [blame] | 4256 | |
| 4257 | if (out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) |
| 4258 | audio_extn_dts_notify_playback_state(out->usecase, 0, out->sample_rate, |
| 4259 | popcount(out->channel_mask), out->playback_started); |
| 4260 | |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 4261 | ALOGV("%s: exit", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4262 | return 0; |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 4263 | |
| 4264 | error_open: |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 4265 | if (out->convert_buffer) |
| 4266 | free(out->convert_buffer); |
Ravi Kumar Alamanda | b199506 | 2013-03-21 23:18:20 -0700 | [diff] [blame] | 4267 | free(out); |
| 4268 | *stream_out = NULL; |
| 4269 | ALOGD("%s: exit: ret %d", __func__, ret); |
| 4270 | return ret; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4271 | } |
| 4272 | |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 4273 | void adev_close_output_stream(struct audio_hw_device *dev __unused, |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4274 | struct audio_stream_out *stream) |
| 4275 | { |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 4276 | struct stream_out *out = (struct stream_out *)stream; |
| 4277 | struct audio_device *adev = out->dev; |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 4278 | int ret = 0; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 4279 | |
Sidipotu Ashok | f43018c | 2014-05-02 16:21:50 +0530 | [diff] [blame] | 4280 | ALOGD("%s: enter:stream_handle(%p)",__func__, out); |
| 4281 | |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 4282 | if (out->usecase == USECASE_COMPRESS_VOIP_CALL) { |
Venkata Narendra Kumar Gutta | 9181214 | 2014-08-11 18:20:49 +0530 | [diff] [blame] | 4283 | pthread_mutex_lock(&adev->lock); |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 4284 | ret = voice_extn_compress_voip_close_output_stream(&stream->common); |
Venkata Narendra Kumar Gutta | 9181214 | 2014-08-11 18:20:49 +0530 | [diff] [blame] | 4285 | pthread_mutex_unlock(&adev->lock); |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 4286 | if(ret != 0) |
| 4287 | ALOGE("%s: Compress voip output cannot be closed, error:%d", |
| 4288 | __func__, ret); |
Ravi Kumar Alamanda | c3bc081 | 2014-09-08 15:34:32 -0700 | [diff] [blame] | 4289 | } else |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 4290 | out_standby(&stream->common); |
| 4291 | |
Subhash Chandra Bose Naripeddy | 16ff4f8 | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 4292 | if (is_offload_usecase(out->usecase)) { |
Jitendra Naruka | 1b6513f | 2014-11-22 19:34:13 -0800 | [diff] [blame] | 4293 | audio_extn_dts_remove_state_notifier_node(out->usecase); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 4294 | destroy_offload_callback_thread(out); |
Subhash Chandra Bose Naripeddy | 16ff4f8 | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 4295 | free_offload_usecase(adev, out->usecase); |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 4296 | if (out->compr_config.codec != NULL) |
| 4297 | free(out->compr_config.codec); |
| 4298 | } |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 4299 | |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 4300 | if (out->convert_buffer != NULL) { |
| 4301 | free(out->convert_buffer); |
| 4302 | out->convert_buffer = NULL; |
| 4303 | } |
| 4304 | |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 4305 | if (adev->voice_tx_output == out) |
| 4306 | adev->voice_tx_output = NULL; |
| 4307 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 4308 | pthread_cond_destroy(&out->cond); |
| 4309 | pthread_mutex_destroy(&out->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4310 | free(stream); |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 4311 | ALOGV("%s: exit", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4312 | } |
| 4313 | |
Alexy Joseph | 2beb67f | 2014-10-06 12:15:01 -0700 | [diff] [blame] | 4314 | static void close_compress_sessions(struct audio_device *adev) |
| 4315 | { |
Mingming Yin | 7b762e7 | 2015-03-04 13:47:32 -0800 | [diff] [blame] | 4316 | struct stream_out *out; |
Naresh Tanniru | f0bbefb | 2015-06-03 01:50:57 +0530 | [diff] [blame] | 4317 | struct listnode *node, *tempnode; |
Mingming Yin | 7b762e7 | 2015-03-04 13:47:32 -0800 | [diff] [blame] | 4318 | struct audio_usecase *usecase; |
Alexy Joseph | 2beb67f | 2014-10-06 12:15:01 -0700 | [diff] [blame] | 4319 | pthread_mutex_lock(&adev->lock); |
Naresh Tanniru | f0bbefb | 2015-06-03 01:50:57 +0530 | [diff] [blame] | 4320 | |
| 4321 | list_for_each_safe(node, tempnode, &adev->usecase_list) { |
Alexy Joseph | 2beb67f | 2014-10-06 12:15:01 -0700 | [diff] [blame] | 4322 | usecase = node_to_item(node, struct audio_usecase, list); |
Naresh Tanniru | f0bbefb | 2015-06-03 01:50:57 +0530 | [diff] [blame] | 4323 | if (is_offload_usecase(usecase->id)) { |
| 4324 | if (usecase->stream.out) { |
Alexy Joseph | 2beb67f | 2014-10-06 12:15:01 -0700 | [diff] [blame] | 4325 | ALOGI(" %s closing compress session %d on OFFLINE state", __func__, usecase->id); |
| 4326 | out = usecase->stream.out; |
| 4327 | pthread_mutex_unlock(&adev->lock); |
| 4328 | out_standby(&out->stream.common); |
| 4329 | pthread_mutex_lock(&adev->lock); |
Aalique Grahame | 6379b8d | 2016-12-22 13:02:32 -0800 | [diff] [blame] | 4330 | tempnode = list_head(&adev->usecase_list); |
Alexy Joseph | 2beb67f | 2014-10-06 12:15:01 -0700 | [diff] [blame] | 4331 | } |
Naresh Tanniru | f0bbefb | 2015-06-03 01:50:57 +0530 | [diff] [blame] | 4332 | } |
Alexy Joseph | 2beb67f | 2014-10-06 12:15:01 -0700 | [diff] [blame] | 4333 | } |
| 4334 | pthread_mutex_unlock(&adev->lock); |
| 4335 | } |
| 4336 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4337 | static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs) |
| 4338 | { |
| 4339 | struct audio_device *adev = (struct audio_device *)dev; |
| 4340 | struct str_parms *parms; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4341 | char value[32]; |
Jean-Michel Trivi | c56336b | 2013-05-24 16:55:17 -0700 | [diff] [blame] | 4342 | int val; |
Ravi Kumar Alamanda | c3bc081 | 2014-09-08 15:34:32 -0700 | [diff] [blame] | 4343 | int ret; |
| 4344 | int status = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4345 | |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 4346 | ALOGD("%s: enter: %s", __func__, kvpairs); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4347 | parms = str_parms_create_str(kvpairs); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4348 | |
Preetam Singh Ranawat | a5f32b4 | 2014-09-23 12:12:47 +0530 | [diff] [blame] | 4349 | if (!parms) |
| 4350 | goto error; |
Ravi Kumar Alamanda | c3bc081 | 2014-09-08 15:34:32 -0700 | [diff] [blame] | 4351 | ret = str_parms_get_str(parms, "SND_CARD_STATUS", value, sizeof(value)); |
| 4352 | if (ret >= 0) { |
Naresh Tanniru | 4c63039 | 2014-05-12 01:05:52 +0530 | [diff] [blame] | 4353 | char *snd_card_status = value+2; |
Naresh Tanniru | 4c63039 | 2014-05-12 01:05:52 +0530 | [diff] [blame] | 4354 | if (strstr(snd_card_status, "OFFLINE")) { |
| 4355 | ALOGD("Received sound card OFFLINE status"); |
Naresh Tanniru | 8065983 | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 4356 | set_snd_card_state(adev,SND_CARD_STATE_OFFLINE); |
Naresh Tanniru | 726c71d | 2016-02-23 04:46:02 -0800 | [diff] [blame] | 4357 | //close compress sessions on OFFLINE status |
| 4358 | close_compress_sessions(adev); |
Naresh Tanniru | 4c63039 | 2014-05-12 01:05:52 +0530 | [diff] [blame] | 4359 | } else if (strstr(snd_card_status, "ONLINE")) { |
| 4360 | ALOGD("Received sound card ONLINE status"); |
Naresh Tanniru | 8065983 | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 4361 | set_snd_card_state(adev,SND_CARD_STATE_ONLINE); |
Mingming Yin | 15dae80 | 2015-04-16 18:36:10 -0700 | [diff] [blame] | 4362 | //send dts hpx license if enabled |
| 4363 | audio_extn_dts_eagle_send_lic(); |
Naresh Tanniru | 4c63039 | 2014-05-12 01:05:52 +0530 | [diff] [blame] | 4364 | } |
Naresh Tanniru | 4c63039 | 2014-05-12 01:05:52 +0530 | [diff] [blame] | 4365 | } |
| 4366 | |
| 4367 | pthread_mutex_lock(&adev->lock); |
Ravi Kumar Alamanda | c3bc081 | 2014-09-08 15:34:32 -0700 | [diff] [blame] | 4368 | status = voice_set_parameters(adev, parms); |
| 4369 | if (status != 0) |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 4370 | goto done; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4371 | |
Ravi Kumar Alamanda | c3bc081 | 2014-09-08 15:34:32 -0700 | [diff] [blame] | 4372 | status = platform_set_parameters(adev->platform, parms); |
| 4373 | if (status != 0) |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 4374 | goto done; |
| 4375 | |
Ravi Kumar Alamanda | c3bc081 | 2014-09-08 15:34:32 -0700 | [diff] [blame] | 4376 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_BT_NREC, value, sizeof(value)); |
| 4377 | if (ret >= 0) { |
Vicky Sehrawat | e240e5d | 2014-08-12 17:17:04 -0700 | [diff] [blame] | 4378 | /* When set to false, HAL should disable EC and NS */ |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4379 | if (strcmp(value, AUDIO_PARAMETER_VALUE_ON) == 0) |
| 4380 | adev->bluetooth_nrec = true; |
| 4381 | else |
| 4382 | adev->bluetooth_nrec = false; |
| 4383 | } |
| 4384 | |
Ravi Kumar Alamanda | c3bc081 | 2014-09-08 15:34:32 -0700 | [diff] [blame] | 4385 | ret = str_parms_get_str(parms, "screen_state", value, sizeof(value)); |
| 4386 | if (ret >= 0) { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4387 | if (strcmp(value, AUDIO_PARAMETER_VALUE_ON) == 0) |
| 4388 | adev->screen_off = false; |
| 4389 | else |
| 4390 | adev->screen_off = true; |
| 4391 | } |
| 4392 | |
Ravi Kumar Alamanda | c3bc081 | 2014-09-08 15:34:32 -0700 | [diff] [blame] | 4393 | ret = str_parms_get_int(parms, "rotation", &val); |
| 4394 | if (ret >= 0) { |
Jean-Michel Trivi | c56336b | 2013-05-24 16:55:17 -0700 | [diff] [blame] | 4395 | bool reverse_speakers = false; |
| 4396 | switch(val) { |
| 4397 | // FIXME: note that the code below assumes that the speakers are in the correct placement |
| 4398 | // relative to the user when the device is rotated 90deg from its default rotation. This |
| 4399 | // assumption is device-specific, not platform-specific like this code. |
| 4400 | case 270: |
| 4401 | reverse_speakers = true; |
| 4402 | break; |
| 4403 | case 0: |
| 4404 | case 90: |
| 4405 | case 180: |
| 4406 | break; |
| 4407 | default: |
| 4408 | ALOGE("%s: unexpected rotation of %d", __func__, val); |
Ravi Kumar Alamanda | c3bc081 | 2014-09-08 15:34:32 -0700 | [diff] [blame] | 4409 | status = -EINVAL; |
Jean-Michel Trivi | c56336b | 2013-05-24 16:55:17 -0700 | [diff] [blame] | 4410 | } |
Ravi Kumar Alamanda | c3bc081 | 2014-09-08 15:34:32 -0700 | [diff] [blame] | 4411 | if (status == 0) { |
| 4412 | if (adev->speaker_lr_swap != reverse_speakers) { |
| 4413 | adev->speaker_lr_swap = reverse_speakers; |
| 4414 | // only update the selected device if there is active pcm playback |
| 4415 | struct audio_usecase *usecase; |
| 4416 | struct listnode *node; |
| 4417 | list_for_each(node, &adev->usecase_list) { |
| 4418 | usecase = node_to_item(node, struct audio_usecase, list); |
| 4419 | if (usecase->type == PCM_PLAYBACK) { |
| 4420 | select_devices(adev, usecase->id); |
| 4421 | break; |
| 4422 | } |
Jean-Michel Trivi | c56336b | 2013-05-24 16:55:17 -0700 | [diff] [blame] | 4423 | } |
| 4424 | } |
| 4425 | } |
Jean-Michel Trivi | c56336b | 2013-05-24 16:55:17 -0700 | [diff] [blame] | 4426 | } |
| 4427 | |
Mingming Yin | 514a8bc | 2014-07-29 15:22:21 -0700 | [diff] [blame] | 4428 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_BT_SCO_WB, value, sizeof(value)); |
| 4429 | if (ret >= 0) { |
| 4430 | if (strcmp(value, AUDIO_PARAMETER_VALUE_ON) == 0) |
| 4431 | adev->bt_wb_speech_enabled = true; |
| 4432 | else |
| 4433 | adev->bt_wb_speech_enabled = false; |
| 4434 | } |
| 4435 | |
Pradnya Chaphekar | 4403bd7 | 2014-09-09 09:50:01 -0700 | [diff] [blame] | 4436 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_DEVICE_CONNECT, value, sizeof(value)); |
| 4437 | if (ret >= 0) { |
| 4438 | val = atoi(value); |
| 4439 | if (val & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
Shiv Maliyappanahalli | c065640 | 2016-09-03 14:13:26 -0700 | [diff] [blame] | 4440 | ALOGV("cache new ext disp type and edid"); |
| 4441 | ret = platform_get_ext_disp_type(adev->platform); |
| 4442 | if (ret < 0) { |
| 4443 | ALOGE("%s: Failed to query disp type, ret:%d", __func__, ret); |
Weiyin Jiang | f50ce4e | 2016-10-13 14:22:03 +0800 | [diff] [blame] | 4444 | status = ret; |
| 4445 | goto done; |
Shiv Maliyappanahalli | c065640 | 2016-09-03 14:13:26 -0700 | [diff] [blame] | 4446 | } |
Pradnya Chaphekar | 4403bd7 | 2014-09-09 09:50:01 -0700 | [diff] [blame] | 4447 | platform_cache_edid(adev->platform); |
Kuirong Wang | a9f7cee | 2016-03-07 11:21:52 -0800 | [diff] [blame] | 4448 | } else if ((val & AUDIO_DEVICE_OUT_USB_DEVICE) || |
yidongh | 86ca17d | 2016-08-30 18:28:01 +0800 | [diff] [blame] | 4449 | !(val ^ AUDIO_DEVICE_IN_USB_DEVICE)) { |
vivek mehta | 344576a | 2016-04-12 18:56:03 -0700 | [diff] [blame] | 4450 | /* |
| 4451 | * Do not allow AFE proxy port usage by WFD source when USB headset is connected. |
| 4452 | * Per AudioPolicyManager, USB device is higher priority than WFD. |
| 4453 | * For Voice call over USB headset, voice call audio is routed to AFE proxy ports. |
| 4454 | * If WFD use case occupies AFE proxy, it may result unintended behavior while |
| 4455 | * starting voice call on USB |
| 4456 | */ |
Kuirong Wang | a9f7cee | 2016-03-07 11:21:52 -0800 | [diff] [blame] | 4457 | ret = str_parms_get_str(parms, "card", value, sizeof(value)); |
| 4458 | if (ret >= 0) { |
Kuirong Wang | 27152a1 | 2016-11-11 10:20:30 -0800 | [diff] [blame] | 4459 | audio_extn_usb_add_device(AUDIO_DEVICE_OUT_USB_DEVICE, atoi(value)); |
| 4460 | audio_extn_usb_add_device(AUDIO_DEVICE_IN_USB_DEVICE, atoi(value)); |
Kuirong Wang | a9f7cee | 2016-03-07 11:21:52 -0800 | [diff] [blame] | 4461 | } |
vivek mehta | 344576a | 2016-04-12 18:56:03 -0700 | [diff] [blame] | 4462 | ALOGV("detected USB connect .. disable proxy"); |
| 4463 | adev->allow_afe_proxy_usage = false; |
Pradnya Chaphekar | 4403bd7 | 2014-09-09 09:50:01 -0700 | [diff] [blame] | 4464 | } |
| 4465 | } |
| 4466 | |
| 4467 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_DEVICE_DISCONNECT, value, sizeof(value)); |
| 4468 | if (ret >= 0) { |
| 4469 | val = atoi(value); |
Garmond Leung | e3b6d48 | 2016-10-25 16:48:01 -0700 | [diff] [blame] | 4470 | /* |
| 4471 | * The HDMI / Displayport disconnect handling has been moved to |
| 4472 | * audio extension to ensure that its parameters are not |
| 4473 | * invalidated prior to updating sysfs of the disconnect event |
| 4474 | * Invalidate will be handled by audio_extn_ext_disp_set_parameters() |
| 4475 | */ |
| 4476 | if ((val & AUDIO_DEVICE_OUT_USB_DEVICE) || |
yidongh | 86ca17d | 2016-08-30 18:28:01 +0800 | [diff] [blame] | 4477 | !(val ^ AUDIO_DEVICE_IN_USB_DEVICE)) { |
Kuirong Wang | a9f7cee | 2016-03-07 11:21:52 -0800 | [diff] [blame] | 4478 | ret = str_parms_get_str(parms, "card", value, sizeof(value)); |
| 4479 | if (ret >= 0) { |
Ashish Jain | 3e37a70 | 2016-11-25 12:27:15 +0530 | [diff] [blame] | 4480 | audio_extn_usb_remove_device(AUDIO_DEVICE_OUT_USB_DEVICE, atoi(value)); |
| 4481 | audio_extn_usb_remove_device(AUDIO_DEVICE_IN_USB_DEVICE, atoi(value)); |
Kuirong Wang | a9f7cee | 2016-03-07 11:21:52 -0800 | [diff] [blame] | 4482 | } |
vivek mehta | 344576a | 2016-04-12 18:56:03 -0700 | [diff] [blame] | 4483 | ALOGV("detected USB disconnect .. enable proxy"); |
| 4484 | adev->allow_afe_proxy_usage = true; |
Pradnya Chaphekar | 4403bd7 | 2014-09-09 09:50:01 -0700 | [diff] [blame] | 4485 | } |
| 4486 | } |
| 4487 | |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 4488 | ret = str_parms_get_str(parms,"reconfigA2dp", value, sizeof(value)); |
| 4489 | if (ret >= 0) { |
| 4490 | struct audio_usecase *usecase; |
| 4491 | struct listnode *node; |
| 4492 | list_for_each(node, &adev->usecase_list) { |
| 4493 | usecase = node_to_item(node, struct audio_usecase, list); |
| 4494 | if ((usecase->type == PCM_PLAYBACK) && |
Naresh Tanniru | f7e9e63 | 2016-11-04 14:54:20 -0700 | [diff] [blame] | 4495 | (usecase->devices & AUDIO_DEVICE_OUT_ALL_A2DP)){ |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 4496 | ALOGD("reconfigure a2dp... forcing device switch"); |
Naresh Tanniru | cd2353e | 2016-08-19 00:37:25 +0530 | [diff] [blame] | 4497 | lock_output_stream(usecase->stream.out); |
| 4498 | audio_extn_a2dp_set_handoff_mode(true); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 4499 | //force device switch to re configure encoder |
| 4500 | select_devices(adev, usecase->id); |
Naresh Tanniru | cd2353e | 2016-08-19 00:37:25 +0530 | [diff] [blame] | 4501 | audio_extn_a2dp_set_handoff_mode(false); |
| 4502 | pthread_mutex_unlock(&usecase->stream.out->lock); |
Naresh Tanniru | 9d027a6 | 2015-03-13 01:32:10 +0530 | [diff] [blame] | 4503 | break; |
| 4504 | } |
| 4505 | } |
| 4506 | } |
Naresh Tanniru | cd2353e | 2016-08-19 00:37:25 +0530 | [diff] [blame] | 4507 | audio_extn_set_parameters(adev, parms); |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 4508 | done: |
| 4509 | str_parms_destroy(parms); |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 4510 | pthread_mutex_unlock(&adev->lock); |
Preetam Singh Ranawat | a5f32b4 | 2014-09-23 12:12:47 +0530 | [diff] [blame] | 4511 | error: |
Ravi Kumar Alamanda | c3bc081 | 2014-09-08 15:34:32 -0700 | [diff] [blame] | 4512 | ALOGV("%s: exit with code(%d)", __func__, status); |
| 4513 | return status; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4514 | } |
| 4515 | |
| 4516 | static char* adev_get_parameters(const struct audio_hw_device *dev, |
| 4517 | const char *keys) |
| 4518 | { |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 4519 | struct audio_device *adev = (struct audio_device *)dev; |
| 4520 | struct str_parms *reply = str_parms_create(); |
| 4521 | struct str_parms *query = str_parms_create_str(keys); |
| 4522 | char *str; |
Naresh Tanniru | d7205b6 | 2014-06-20 02:54:48 +0530 | [diff] [blame] | 4523 | char value[256] = {0}; |
| 4524 | int ret = 0; |
| 4525 | |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 4526 | if (!query || !reply) { |
Alexy Joseph | aee4fdd | 2016-01-29 13:02:07 -0800 | [diff] [blame] | 4527 | if (reply) { |
| 4528 | str_parms_destroy(reply); |
| 4529 | } |
| 4530 | if (query) { |
| 4531 | str_parms_destroy(query); |
| 4532 | } |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 4533 | ALOGE("adev_get_parameters: failed to create query or reply"); |
| 4534 | return NULL; |
| 4535 | } |
| 4536 | |
Naresh Tanniru | d7205b6 | 2014-06-20 02:54:48 +0530 | [diff] [blame] | 4537 | ret = str_parms_get_str(query, "SND_CARD_STATUS", value, |
| 4538 | sizeof(value)); |
| 4539 | if (ret >=0) { |
| 4540 | int val = 1; |
| 4541 | pthread_mutex_lock(&adev->snd_card_status.lock); |
| 4542 | if (SND_CARD_STATE_OFFLINE == adev->snd_card_status.state) |
| 4543 | val = 0; |
| 4544 | pthread_mutex_unlock(&adev->snd_card_status.lock); |
| 4545 | str_parms_add_int(reply, "SND_CARD_STATUS", val); |
| 4546 | goto exit; |
| 4547 | } |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 4548 | |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 4549 | pthread_mutex_lock(&adev->lock); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 4550 | audio_extn_get_parameters(adev, query, reply); |
Shiv Maliyappanahalli | f930849 | 2013-12-12 12:18:09 -0800 | [diff] [blame] | 4551 | voice_get_parameters(adev, query, reply); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 4552 | platform_get_parameters(adev->platform, query, reply); |
Naresh Tanniru | 8065983 | 2014-06-04 18:17:56 +0530 | [diff] [blame] | 4553 | pthread_mutex_unlock(&adev->lock); |
| 4554 | |
Naresh Tanniru | d7205b6 | 2014-06-20 02:54:48 +0530 | [diff] [blame] | 4555 | exit: |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 4556 | str = str_parms_to_str(reply); |
| 4557 | str_parms_destroy(query); |
| 4558 | str_parms_destroy(reply); |
| 4559 | |
| 4560 | ALOGV("%s: exit: returns - %s", __func__, str); |
| 4561 | return str; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4562 | } |
| 4563 | |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 4564 | 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] | 4565 | { |
| 4566 | return 0; |
| 4567 | } |
| 4568 | |
| 4569 | static int adev_set_voice_volume(struct audio_hw_device *dev, float volume) |
| 4570 | { |
Haynes Mathew George | 5191a85 | 2013-09-11 14:19:36 -0700 | [diff] [blame] | 4571 | int ret; |
| 4572 | struct audio_device *adev = (struct audio_device *)dev; |
| 4573 | pthread_mutex_lock(&adev->lock); |
| 4574 | /* cache volume */ |
Shruthi Krishna | ace1085 | 2013-10-25 14:32:12 -0700 | [diff] [blame] | 4575 | ret = voice_set_volume(adev, volume); |
Haynes Mathew George | 5191a85 | 2013-09-11 14:19:36 -0700 | [diff] [blame] | 4576 | pthread_mutex_unlock(&adev->lock); |
| 4577 | return ret; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4578 | } |
| 4579 | |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 4580 | static int adev_set_master_volume(struct audio_hw_device *dev __unused, |
| 4581 | float volume __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4582 | { |
| 4583 | return -ENOSYS; |
| 4584 | } |
| 4585 | |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 4586 | static int adev_get_master_volume(struct audio_hw_device *dev __unused, |
| 4587 | float *volume __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4588 | { |
| 4589 | return -ENOSYS; |
| 4590 | } |
| 4591 | |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 4592 | static int adev_set_master_mute(struct audio_hw_device *dev __unused, |
| 4593 | bool muted __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4594 | { |
| 4595 | return -ENOSYS; |
| 4596 | } |
| 4597 | |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 4598 | static int adev_get_master_mute(struct audio_hw_device *dev __unused, |
| 4599 | bool *muted __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4600 | { |
| 4601 | return -ENOSYS; |
| 4602 | } |
| 4603 | |
| 4604 | static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode) |
| 4605 | { |
| 4606 | struct audio_device *adev = (struct audio_device *)dev; |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 4607 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4608 | pthread_mutex_lock(&adev->lock); |
| 4609 | if (adev->mode != mode) { |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 4610 | ALOGD("%s: mode %d\n", __func__, mode); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4611 | adev->mode = mode; |
Shiv Maliyappanahalli | bb4cf0b | 2016-01-21 11:30:06 -0800 | [diff] [blame] | 4612 | if ((mode == AUDIO_MODE_NORMAL) && voice_is_in_call(adev)) { |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 4613 | voice_stop_call(adev); |
Banajit Goswami | 20cdd21 | 2015-09-11 01:11:30 -0700 | [diff] [blame] | 4614 | platform_set_gsm_mode(adev->platform, false); |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 4615 | adev->current_call_output = NULL; |
| 4616 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4617 | } |
| 4618 | pthread_mutex_unlock(&adev->lock); |
| 4619 | return 0; |
| 4620 | } |
| 4621 | |
| 4622 | static int adev_set_mic_mute(struct audio_hw_device *dev, bool state) |
| 4623 | { |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 4624 | int ret; |
| 4625 | |
| 4626 | pthread_mutex_lock(&adev->lock); |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 4627 | ALOGD("%s state %d\n", __func__, state); |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 4628 | ret = voice_set_mic_mute((struct audio_device *)dev, state); |
| 4629 | pthread_mutex_unlock(&adev->lock); |
| 4630 | |
| 4631 | return ret; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4632 | } |
| 4633 | |
| 4634 | static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state) |
| 4635 | { |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 4636 | *state = voice_get_mic_mute((struct audio_device *)dev); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4637 | return 0; |
| 4638 | } |
| 4639 | |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 4640 | 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] | 4641 | const struct audio_config *config) |
| 4642 | { |
Ravi Kumar Alamanda | c3bc081 | 2014-09-08 15:34:32 -0700 | [diff] [blame] | 4643 | 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] | 4644 | |
Ravi Kumar Alamanda | dc9bb15 | 2014-09-08 15:59:58 -0700 | [diff] [blame] | 4645 | return get_input_buffer_size(config->sample_rate, config->format, channel_count, |
| 4646 | false /* is_low_latency: since we don't know, be conservative */); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4647 | } |
| 4648 | |
| 4649 | static int adev_open_input_stream(struct audio_hw_device *dev, |
Bharath Ramachandramurthy | 76d2089 | 2015-04-27 15:47:55 -0700 | [diff] [blame] | 4650 | audio_io_handle_t handle, |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4651 | audio_devices_t devices, |
| 4652 | struct audio_config *config, |
Ravi Kumar Alamanda | c3bc081 | 2014-09-08 15:34:32 -0700 | [diff] [blame] | 4653 | struct audio_stream_in **stream_in, |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 4654 | audio_input_flags_t flags, |
Ravi Kumar Alamanda | c3bc081 | 2014-09-08 15:34:32 -0700 | [diff] [blame] | 4655 | const char *address __unused, |
Vidyakumar Athota | 5c39821 | 2015-03-31 21:53:21 -0700 | [diff] [blame] | 4656 | audio_source_t source) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4657 | { |
| 4658 | struct audio_device *adev = (struct audio_device *)dev; |
| 4659 | struct stream_in *in; |
Ravi Kumar Alamanda | fae4211 | 2013-11-07 23:31:54 -0800 | [diff] [blame] | 4660 | int ret = 0, buffer_size, frame_size; |
Ravi Kumar Alamanda | c3bc081 | 2014-09-08 15:34:32 -0700 | [diff] [blame] | 4661 | int channel_count = audio_channel_count_from_in_mask(config->channel_mask); |
Ravi Kumar Alamanda | dc9bb15 | 2014-09-08 15:59:58 -0700 | [diff] [blame] | 4662 | bool is_low_latency = false; |
Divya Narayanan Poojary | 45f1919 | 2016-09-30 18:52:13 +0530 | [diff] [blame] | 4663 | bool channel_mask_updated = false; |
Sidipotu Ashok | f43018c | 2014-05-02 16:21:50 +0530 | [diff] [blame] | 4664 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4665 | *stream_in = NULL; |
Chaithanya Krishna Bacharaju | 9955b16 | 2016-05-25 16:25:53 +0530 | [diff] [blame] | 4666 | if (check_input_parameters(config->sample_rate, config->format, channel_count) != 0) { |
| 4667 | ALOGE("%s: invalid input parameters", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4668 | return -EINVAL; |
Chaithanya Krishna Bacharaju | 9955b16 | 2016-05-25 16:25:53 +0530 | [diff] [blame] | 4669 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4670 | |
| 4671 | in = (struct stream_in *)calloc(1, sizeof(struct stream_in)); |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 4672 | |
| 4673 | if (!in) { |
| 4674 | ALOGE("failed to allocate input stream"); |
| 4675 | return -ENOMEM; |
| 4676 | } |
| 4677 | |
Sidipotu Ashok | f43018c | 2014-05-02 16:21:50 +0530 | [diff] [blame] | 4678 | ALOGD("%s: enter: sample_rate(%d) channel_mask(%#x) devices(%#x)\ |
Manish Dewangan | ba9fcfa | 2016-03-24 16:20:06 +0530 | [diff] [blame] | 4679 | stream_handle(%p) io_handle(%d) source(%d) format %x",__func__, config->sample_rate, |
| 4680 | config->channel_mask, devices, &in->stream, handle, source, config->format); |
Ravi Kumar Alamanda | 4070310 | 2014-04-24 10:34:41 -0700 | [diff] [blame] | 4681 | pthread_mutex_init(&in->lock, (const pthread_mutexattr_t *) NULL); |
Shiv Maliyappanahalli | 736d4ce | 2015-09-28 15:23:06 -0700 | [diff] [blame] | 4682 | pthread_mutex_init(&in->pre_lock, (const pthread_mutexattr_t *) NULL); |
Ravi Kumar Alamanda | 4070310 | 2014-04-24 10:34:41 -0700 | [diff] [blame] | 4683 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4684 | in->stream.common.get_sample_rate = in_get_sample_rate; |
| 4685 | in->stream.common.set_sample_rate = in_set_sample_rate; |
| 4686 | in->stream.common.get_buffer_size = in_get_buffer_size; |
| 4687 | in->stream.common.get_channels = in_get_channels; |
| 4688 | in->stream.common.get_format = in_get_format; |
| 4689 | in->stream.common.set_format = in_set_format; |
| 4690 | in->stream.common.standby = in_standby; |
| 4691 | in->stream.common.dump = in_dump; |
| 4692 | in->stream.common.set_parameters = in_set_parameters; |
| 4693 | in->stream.common.get_parameters = in_get_parameters; |
| 4694 | in->stream.common.add_audio_effect = in_add_audio_effect; |
| 4695 | in->stream.common.remove_audio_effect = in_remove_audio_effect; |
| 4696 | in->stream.set_gain = in_set_gain; |
| 4697 | in->stream.read = in_read; |
| 4698 | in->stream.get_input_frames_lost = in_get_input_frames_lost; |
| 4699 | |
| 4700 | in->device = devices; |
Vidyakumar Athota | 5c39821 | 2015-03-31 21:53:21 -0700 | [diff] [blame] | 4701 | in->source = source; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4702 | in->dev = adev; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4703 | in->standby = 1; |
| 4704 | in->channel_mask = config->channel_mask; |
Ravi Kumar Alamanda | 8fa6b19 | 2014-09-09 16:06:42 -0700 | [diff] [blame] | 4705 | in->capture_handle = handle; |
Ravi Kumar Alamanda | 8a0f977 | 2015-06-15 10:35:19 -0700 | [diff] [blame] | 4706 | in->flags = flags; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4707 | |
Dhananjay Kumar | 973fc36 | 2017-01-09 18:48:15 +0530 | [diff] [blame^] | 4708 | in->usecase = USECASE_AUDIO_RECORD; |
| 4709 | if (config->sample_rate == LOW_LATENCY_CAPTURE_SAMPLE_RATE && |
| 4710 | (flags & AUDIO_INPUT_FLAG_FAST) != 0) { |
| 4711 | is_low_latency = true; |
| 4712 | #if LOW_LATENCY_CAPTURE_USE_CASE |
| 4713 | in->usecase = USECASE_AUDIO_RECORD_LOW_LATENCY; |
| 4714 | #endif |
| 4715 | in->realtime = may_use_noirq_mode(adev, in->usecase, in->flags); |
| 4716 | } |
| 4717 | |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 4718 | in->format = config->format; |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 4719 | if (in->realtime) { |
| 4720 | in->config = pcm_config_audio_capture_rt; |
| 4721 | in->sample_rate = in->config.rate; |
| 4722 | in->af_period_multiplier = af_period_multiplier; |
| 4723 | } else { |
| 4724 | in->config = pcm_config_audio_capture; |
| 4725 | in->config.rate = config->sample_rate; |
| 4726 | in->sample_rate = config->sample_rate; |
| 4727 | in->af_period_multiplier = 1; |
| 4728 | } |
Manish Dewangan | ba9fcfa | 2016-03-24 16:20:06 +0530 | [diff] [blame] | 4729 | in->bit_width = 16; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4730 | |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 4731 | /* restrict 24 bit capture for unprocessed source only |
| 4732 | * for other sources if 24 bit requested reject 24 and set 16 bit capture only |
| 4733 | */ |
| 4734 | if (config->format == AUDIO_FORMAT_DEFAULT) { |
| 4735 | config->format = AUDIO_FORMAT_PCM_16_BIT; |
| 4736 | } else if ((config->format == AUDIO_FORMAT_PCM_FLOAT) || |
| 4737 | (config->format == AUDIO_FORMAT_PCM_32_BIT) || |
| 4738 | (config->format == AUDIO_FORMAT_PCM_24_BIT_PACKED) || |
| 4739 | (config->format == AUDIO_FORMAT_PCM_8_24_BIT)) { |
| 4740 | bool ret_error = false; |
| 4741 | in->bit_width = 24; |
| 4742 | /* 24 bit is restricted to UNPROCESSED source only,also format supported |
| 4743 | from HAL is 24_packed and 8_24 |
| 4744 | *> In case of UNPROCESSED source, for 24 bit, if format requested is other than |
| 4745 | 24_packed return error indicating supported format is 24_packed |
| 4746 | *> In case of any other source requesting 24 bit or float return error |
| 4747 | indicating format supported is 16 bit only. |
| 4748 | |
| 4749 | on error flinger will retry with supported format passed |
| 4750 | */ |
| 4751 | if ((source != AUDIO_SOURCE_UNPROCESSED) && |
| 4752 | (source != AUDIO_SOURCE_CAMCORDER)) { |
| 4753 | config->format = AUDIO_FORMAT_PCM_16_BIT; |
| 4754 | if (config->sample_rate > 48000) |
| 4755 | config->sample_rate = 48000; |
| 4756 | ret_error = true; |
| 4757 | } else if (config->format == AUDIO_FORMAT_PCM_24_BIT_PACKED) { |
| 4758 | in->config.format = PCM_FORMAT_S24_3LE; |
| 4759 | } else if (config->format == AUDIO_FORMAT_PCM_8_24_BIT) { |
| 4760 | in->config.format = PCM_FORMAT_S24_LE; |
| 4761 | } else { |
| 4762 | config->format = AUDIO_FORMAT_PCM_24_BIT_PACKED; |
| 4763 | ret_error = true; |
| 4764 | } |
| 4765 | |
| 4766 | if (ret_error) { |
| 4767 | ret = -EINVAL; |
| 4768 | goto err_open; |
| 4769 | } |
| 4770 | } |
| 4771 | |
Dhanalakshmi Siddani | 74cf00b | 2016-12-02 13:55:57 +0530 | [diff] [blame] | 4772 | /* Update config params with the requested sample rate and channels */ |
Dhanalakshmi Siddani | 0b1488e | 2016-09-06 12:58:42 +0530 | [diff] [blame] | 4773 | if ((in->device == AUDIO_DEVICE_IN_TELEPHONY_RX) && |
| 4774 | (adev->mode != AUDIO_MODE_IN_CALL)) { |
| 4775 | ret = -EINVAL; |
| 4776 | goto err_open; |
| 4777 | } |
| 4778 | |
| 4779 | if ((in->device == AUDIO_DEVICE_IN_TELEPHONY_RX) || |
| 4780 | (in->device == AUDIO_DEVICE_IN_PROXY)) { |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 4781 | if (config->sample_rate == 0) |
| 4782 | config->sample_rate = AFE_PROXY_SAMPLING_RATE; |
| 4783 | if (config->sample_rate != 48000 && config->sample_rate != 16000 && |
| 4784 | config->sample_rate != 8000) { |
| 4785 | config->sample_rate = AFE_PROXY_SAMPLING_RATE; |
| 4786 | ret = -EINVAL; |
| 4787 | goto err_open; |
| 4788 | } |
| 4789 | if (config->format == AUDIO_FORMAT_DEFAULT) |
| 4790 | config->format = AUDIO_FORMAT_PCM_16_BIT; |
| 4791 | if (config->format != AUDIO_FORMAT_PCM_16_BIT) { |
| 4792 | config->format = AUDIO_FORMAT_PCM_16_BIT; |
| 4793 | ret = -EINVAL; |
| 4794 | goto err_open; |
| 4795 | } |
| 4796 | |
| 4797 | in->usecase = USECASE_AUDIO_RECORD_AFE_PROXY; |
| 4798 | in->config = pcm_config_afe_proxy_record; |
| 4799 | in->config.channels = channel_count; |
| 4800 | in->config.rate = config->sample_rate; |
Manish Dewangan | ba9fcfa | 2016-03-24 16:20:06 +0530 | [diff] [blame] | 4801 | in->sample_rate = config->sample_rate; |
Divya Narayanan Poojary | 45f1919 | 2016-09-30 18:52:13 +0530 | [diff] [blame] | 4802 | } else if (!audio_extn_check_and_set_multichannel_usecase(adev, |
| 4803 | in, config, &channel_mask_updated)) { |
| 4804 | if (channel_mask_updated == true) { |
| 4805 | ALOGD("%s: return error to retry with updated channel mask (%#x)", |
| 4806 | __func__, config->channel_mask); |
| 4807 | ret = -EINVAL; |
| 4808 | goto err_open; |
| 4809 | } |
Naresh Tanniru | c909398 | 2015-10-16 18:05:29 +0530 | [diff] [blame] | 4810 | ALOGD("%s: created surround sound session succesfully",__func__); |
Mingming Yin | e62d784 | 2013-10-25 16:26:03 -0700 | [diff] [blame] | 4811 | } else if (audio_extn_compr_cap_enabled() && |
Narsinga Rao Chella | 2a99dea | 2014-01-24 15:33:23 -0800 | [diff] [blame] | 4812 | audio_extn_compr_cap_format_supported(config->format) && |
| 4813 | (in->dev->mode != AUDIO_MODE_IN_COMMUNICATION)) { |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 4814 | audio_extn_compr_cap_init(in); |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 4815 | } else if (audio_extn_cin_applicable_stream(in)) { |
| 4816 | ret = audio_extn_cin_configure_input_stream(in); |
| 4817 | if (ret) |
| 4818 | goto err_open; |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 4819 | } else { |
| 4820 | in->config.channels = channel_count; |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 4821 | if (!in->realtime) { |
| 4822 | in->format = config->format; |
| 4823 | frame_size = audio_stream_in_frame_size(&in->stream); |
| 4824 | buffer_size = get_input_buffer_size(config->sample_rate, |
| 4825 | config->format, |
| 4826 | channel_count, |
| 4827 | is_low_latency); |
| 4828 | in->config.period_size = buffer_size / frame_size; |
| 4829 | } |
| 4830 | |
Vidyakumar Athota | 5c39821 | 2015-03-31 21:53:21 -0700 | [diff] [blame] | 4831 | if ((in->source == AUDIO_SOURCE_VOICE_COMMUNICATION) && |
kunleiz | c5fefba | 2016-11-15 11:20:56 +0800 | [diff] [blame] | 4832 | (in->dev->mode == AUDIO_MODE_IN_COMMUNICATION || voice_extn_compress_voip_is_active(in->dev)) && |
Vidyakumar Athota | 5c39821 | 2015-03-31 21:53:21 -0700 | [diff] [blame] | 4833 | (voice_extn_compress_voip_is_format_supported(in->format)) && |
Shiv Maliyappanahalli | e66aba2 | 2016-01-27 16:08:57 -0800 | [diff] [blame] | 4834 | (in->config.rate == 8000 || in->config.rate == 16000 || |
| 4835 | in->config.rate == 32000 || in->config.rate == 48000) && |
Vidyakumar Athota | 5c39821 | 2015-03-31 21:53:21 -0700 | [diff] [blame] | 4836 | (audio_channel_count_from_in_mask(in->channel_mask) == 1)) { |
| 4837 | voice_extn_compress_voip_open_input_stream(in); |
| 4838 | } |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 4839 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4840 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 4841 | audio_extn_utils_update_stream_input_app_type_cfg(adev->platform, |
| 4842 | &adev->streams_input_cfg_list, |
| 4843 | devices, flags, in->format, in->sample_rate, |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 4844 | in->bit_width, in->profile, &in->app_type_cfg); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 4845 | |
Ravi Kumar Alamanda | 8fa6b19 | 2014-09-09 16:06:42 -0700 | [diff] [blame] | 4846 | /* This stream could be for sound trigger lab, |
| 4847 | get sound trigger pcm if present */ |
| 4848 | audio_extn_sound_trigger_check_and_get_session(in); |
| 4849 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4850 | *stream_in = &in->stream; |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 4851 | ALOGV("%s: exit", __func__); |
Ravi Kumar Alamanda | fae4211 | 2013-11-07 23:31:54 -0800 | [diff] [blame] | 4852 | return ret; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4853 | |
| 4854 | err_open: |
| 4855 | free(in); |
| 4856 | *stream_in = NULL; |
| 4857 | return ret; |
| 4858 | } |
| 4859 | |
| 4860 | static void adev_close_input_stream(struct audio_hw_device *dev, |
| 4861 | struct audio_stream_in *stream) |
| 4862 | { |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 4863 | int ret; |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 4864 | struct stream_in *in = (struct stream_in *)stream; |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 4865 | struct audio_device *adev = (struct audio_device *)dev; |
Venkata Narendra Kumar Gutta | 9181214 | 2014-08-11 18:20:49 +0530 | [diff] [blame] | 4866 | |
Sidipotu Ashok | f43018c | 2014-05-02 16:21:50 +0530 | [diff] [blame] | 4867 | ALOGD("%s: enter:stream_handle(%p)",__func__, in); |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 4868 | |
Venkata Narendra Kumar Gutta | 1bbbf54 | 2014-09-04 19:11:25 +0530 | [diff] [blame] | 4869 | /* Disable echo reference while closing input stream */ |
Apoorv Raghuvanshi | 924b302 | 2015-07-06 15:07:14 -0700 | [diff] [blame] | 4870 | platform_set_echo_reference(adev, false, AUDIO_DEVICE_NONE); |
Venkata Narendra Kumar Gutta | 1bbbf54 | 2014-09-04 19:11:25 +0530 | [diff] [blame] | 4871 | |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 4872 | if (in->usecase == USECASE_COMPRESS_VOIP_CALL) { |
Venkata Narendra Kumar Gutta | 9181214 | 2014-08-11 18:20:49 +0530 | [diff] [blame] | 4873 | pthread_mutex_lock(&adev->lock); |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 4874 | ret = voice_extn_compress_voip_close_input_stream(&stream->common); |
Venkata Narendra Kumar Gutta | 9181214 | 2014-08-11 18:20:49 +0530 | [diff] [blame] | 4875 | pthread_mutex_unlock(&adev->lock); |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 4876 | if (ret != 0) |
| 4877 | ALOGE("%s: Compress voip input cannot be closed, error:%d", |
| 4878 | __func__, ret); |
| 4879 | } else |
| 4880 | in_standby(&stream->common); |
| 4881 | |
Shiv Maliyappanahalli | 5a10aea | 2015-07-02 10:36:23 -0700 | [diff] [blame] | 4882 | if (audio_extn_ssr_get_stream() == in) { |
Apoorv Raghuvanshi | 6178a3f | 2013-10-19 12:38:54 -0700 | [diff] [blame] | 4883 | audio_extn_ssr_deinit(); |
| 4884 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4885 | |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 4886 | if (audio_extn_compr_cap_enabled() && |
Mingming Yin | e62d784 | 2013-10-25 16:26:03 -0700 | [diff] [blame] | 4887 | audio_extn_compr_cap_format_supported(in->config.format)) |
| 4888 | audio_extn_compr_cap_deinit(); |
Dhanalakshmi Siddani | 74cf00b | 2016-12-02 13:55:57 +0530 | [diff] [blame] | 4889 | |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 4890 | if (audio_extn_cin_attached_usecase(in->usecase)) |
| 4891 | audio_extn_cin_close_input_stream(in); |
Ravi Kumar Alamanda | 8fa6b19 | 2014-09-09 16:06:42 -0700 | [diff] [blame] | 4892 | |
Mingming Yin | fd7607b | 2016-01-22 12:48:44 -0800 | [diff] [blame] | 4893 | if (in->is_st_session) { |
| 4894 | ALOGV("%s: sound trigger pcm stop lab", __func__); |
| 4895 | audio_extn_sound_trigger_stop_lab(in); |
| 4896 | } |
Ravi Kumar Alamanda | 8fa6b19 | 2014-09-09 16:06:42 -0700 | [diff] [blame] | 4897 | free(stream); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4898 | return; |
| 4899 | } |
| 4900 | |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 4901 | static int adev_dump(const audio_hw_device_t *device __unused, |
| 4902 | int fd __unused) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4903 | { |
| 4904 | return 0; |
| 4905 | } |
| 4906 | |
| 4907 | static int adev_close(hw_device_t *device) |
| 4908 | { |
| 4909 | struct audio_device *adev = (struct audio_device *)device; |
Kiran Kandi | 910e186 | 2013-10-29 13:29:42 -0700 | [diff] [blame] | 4910 | |
| 4911 | if (!adev) |
| 4912 | return 0; |
| 4913 | |
| 4914 | pthread_mutex_lock(&adev_init_lock); |
| 4915 | |
| 4916 | if ((--audio_device_ref_count) == 0) { |
Ravi Kumar Alamanda | 8fa6b19 | 2014-09-09 16:06:42 -0700 | [diff] [blame] | 4917 | audio_extn_sound_trigger_deinit(adev); |
Kiran Kandi | de144c8 | 2013-11-20 15:58:32 -0800 | [diff] [blame] | 4918 | audio_extn_listen_deinit(adev); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 4919 | audio_extn_utils_release_streams_cfg_lists( |
| 4920 | &adev->streams_output_cfg_list, |
| 4921 | &adev->streams_input_cfg_list); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 4922 | if (audio_extn_qaf_is_enabled()) |
| 4923 | audio_extn_qaf_deinit(); |
Kiran Kandi | 910e186 | 2013-10-29 13:29:42 -0700 | [diff] [blame] | 4924 | audio_route_free(adev->audio_route); |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 4925 | audio_extn_gef_deinit(); |
Kiran Kandi | 910e186 | 2013-10-29 13:29:42 -0700 | [diff] [blame] | 4926 | free(adev->snd_dev_ref_cnt); |
| 4927 | platform_deinit(adev->platform); |
Ravi Kumar Alamanda | 8a0f977 | 2015-06-15 10:35:19 -0700 | [diff] [blame] | 4928 | if (adev->adm_deinit) |
| 4929 | adev->adm_deinit(adev->adm_data); |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 4930 | qahwi_deinit(device); |
Kiran Kandi | 910e186 | 2013-10-29 13:29:42 -0700 | [diff] [blame] | 4931 | free(device); |
| 4932 | adev = NULL; |
| 4933 | } |
| 4934 | pthread_mutex_unlock(&adev_init_lock); |
Ravi Kumar Alamanda | 8a0f977 | 2015-06-15 10:35:19 -0700 | [diff] [blame] | 4935 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4936 | return 0; |
| 4937 | } |
| 4938 | |
Ravi Kumar Alamanda | dc9bb15 | 2014-09-08 15:59:58 -0700 | [diff] [blame] | 4939 | /* This returns 1 if the input parameter looks at all plausible as a low latency period size, |
| 4940 | * or 0 otherwise. A return value of 1 doesn't mean the value is guaranteed to work, |
| 4941 | * just that it _might_ work. |
| 4942 | */ |
| 4943 | static int period_size_is_plausible_for_low_latency(int period_size) |
| 4944 | { |
| 4945 | switch (period_size) { |
| 4946 | case 160: |
Ravi Kumar Alamanda | 474de5a | 2015-06-25 20:08:01 -0700 | [diff] [blame] | 4947 | case 192: |
Ravi Kumar Alamanda | dc9bb15 | 2014-09-08 15:59:58 -0700 | [diff] [blame] | 4948 | case 240: |
| 4949 | case 320: |
| 4950 | case 480: |
| 4951 | return 1; |
| 4952 | default: |
| 4953 | return 0; |
| 4954 | } |
| 4955 | } |
| 4956 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4957 | static int adev_open(const hw_module_t *module, const char *name, |
| 4958 | hw_device_t **device) |
| 4959 | { |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 4960 | int ret; |
| 4961 | |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 4962 | ALOGD("%s: enter", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4963 | if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) return -EINVAL; |
| 4964 | |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 4965 | pthread_mutex_lock(&adev_init_lock); |
Kiran Kandi | 910e186 | 2013-10-29 13:29:42 -0700 | [diff] [blame] | 4966 | if (audio_device_ref_count != 0){ |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 4967 | *device = &adev->device.common; |
Kiran Kandi | 910e186 | 2013-10-29 13:29:42 -0700 | [diff] [blame] | 4968 | audio_device_ref_count++; |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 4969 | ALOGD("%s: returning existing instance of adev", __func__); |
| 4970 | ALOGD("%s: exit", __func__); |
| 4971 | pthread_mutex_unlock(&adev_init_lock); |
| 4972 | return 0; |
| 4973 | } |
| 4974 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4975 | adev = calloc(1, sizeof(struct audio_device)); |
| 4976 | |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 4977 | if (!adev) { |
| 4978 | pthread_mutex_unlock(&adev_init_lock); |
| 4979 | return -ENOMEM; |
| 4980 | } |
| 4981 | |
Ravi Kumar Alamanda | 4070310 | 2014-04-24 10:34:41 -0700 | [diff] [blame] | 4982 | pthread_mutex_init(&adev->lock, (const pthread_mutexattr_t *) NULL); |
| 4983 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 4984 | adev->device.common.tag = HARDWARE_DEVICE_TAG; |
| 4985 | adev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0; |
| 4986 | adev->device.common.module = (struct hw_module_t *)module; |
| 4987 | adev->device.common.close = adev_close; |
| 4988 | |
| 4989 | adev->device.init_check = adev_init_check; |
| 4990 | adev->device.set_voice_volume = adev_set_voice_volume; |
| 4991 | adev->device.set_master_volume = adev_set_master_volume; |
| 4992 | adev->device.get_master_volume = adev_get_master_volume; |
| 4993 | adev->device.set_master_mute = adev_set_master_mute; |
| 4994 | adev->device.get_master_mute = adev_get_master_mute; |
| 4995 | adev->device.set_mode = adev_set_mode; |
| 4996 | adev->device.set_mic_mute = adev_set_mic_mute; |
| 4997 | adev->device.get_mic_mute = adev_get_mic_mute; |
| 4998 | adev->device.set_parameters = adev_set_parameters; |
| 4999 | adev->device.get_parameters = adev_get_parameters; |
| 5000 | adev->device.get_input_buffer_size = adev_get_input_buffer_size; |
| 5001 | adev->device.open_output_stream = adev_open_output_stream; |
| 5002 | adev->device.close_output_stream = adev_close_output_stream; |
| 5003 | adev->device.open_input_stream = adev_open_input_stream; |
| 5004 | adev->device.close_input_stream = adev_close_input_stream; |
| 5005 | adev->device.dump = adev_dump; |
| 5006 | |
| 5007 | /* Set the default route before the PCM stream is opened */ |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 5008 | adev->mode = AUDIO_MODE_NORMAL; |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 5009 | adev->active_input = NULL; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 5010 | adev->primary_output = NULL; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 5011 | adev->out_device = AUDIO_DEVICE_NONE; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 5012 | adev->bluetooth_nrec = true; |
Ravi Kumar Alamanda | f996704 | 2013-02-14 19:35:14 -0800 | [diff] [blame] | 5013 | adev->acdb_settings = TTY_MODE_OFF; |
vivek mehta | 344576a | 2016-04-12 18:56:03 -0700 | [diff] [blame] | 5014 | adev->allow_afe_proxy_usage = true; |
Eric Laurent | 07eeafd | 2013-10-06 12:52:49 -0700 | [diff] [blame] | 5015 | /* adev->cur_hdmi_channels = 0; by calloc() */ |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 5016 | adev->snd_dev_ref_cnt = calloc(SND_DEVICE_MAX, sizeof(int)); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 5017 | voice_init(adev); |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 5018 | list_init(&adev->usecase_list); |
Krishnankutty Kolathappilly | 0b2de1c | 2014-02-14 14:45:49 -0800 | [diff] [blame] | 5019 | adev->cur_wfd_channels = 2; |
Subhash Chandra Bose Naripeddy | 16ff4f8 | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 5020 | adev->offload_usecases_state = 0; |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 5021 | adev->is_channel_status_set = false; |
Sudheer Papothi | fa9d228 | 2015-09-17 01:53:25 +0530 | [diff] [blame] | 5022 | adev->perf_lock_opts[0] = 0x101; |
| 5023 | adev->perf_lock_opts[1] = 0x20E; |
| 5024 | adev->perf_lock_opts_size = 2; |
Naresh Tanniru | 4c63039 | 2014-05-12 01:05:52 +0530 | [diff] [blame] | 5025 | |
| 5026 | pthread_mutex_init(&adev->snd_card_status.lock, (const pthread_mutexattr_t *) NULL); |
| 5027 | adev->snd_card_status.state = SND_CARD_STATE_OFFLINE; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 5028 | /* Loads platform specific libraries dynamically */ |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 5029 | adev->platform = platform_init(adev); |
| 5030 | if (!adev->platform) { |
| 5031 | free(adev->snd_dev_ref_cnt); |
| 5032 | free(adev); |
| 5033 | ALOGE("%s: Failed to init platform data, aborting.", __func__); |
| 5034 | *device = NULL; |
Apoorv Raghuvanshi | 6e57d7e | 2013-12-16 16:02:45 -0800 | [diff] [blame] | 5035 | pthread_mutex_unlock(&adev_init_lock); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 5036 | pthread_mutex_destroy(&adev->lock); |
| 5037 | pthread_mutex_destroy(&adev->snd_card_status.lock); |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 5038 | return -EINVAL; |
| 5039 | } |
Eric Laurent | c4aef75 | 2013-09-12 17:45:53 -0700 | [diff] [blame] | 5040 | |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 5041 | if (audio_extn_qaf_is_enabled()) { |
| 5042 | ret = audio_extn_qaf_init(adev); |
| 5043 | if (ret < 0) { |
| 5044 | free(adev); |
| 5045 | ALOGE("%s: Failed to init platform data, aborting.", __func__); |
| 5046 | *device = NULL; |
| 5047 | pthread_mutex_unlock(&adev_init_lock); |
| 5048 | pthread_mutex_destroy(&adev->lock); |
| 5049 | return ret; |
| 5050 | } |
| 5051 | |
| 5052 | adev->device.open_output_stream = audio_extn_qaf_open_output_stream; |
| 5053 | adev->device.close_output_stream = audio_extn_qaf_close_output_stream; |
| 5054 | } |
| 5055 | |
Naresh Tanniru | 4c63039 | 2014-05-12 01:05:52 +0530 | [diff] [blame] | 5056 | adev->snd_card_status.state = SND_CARD_STATE_ONLINE; |
| 5057 | |
Eric Laurent | c4aef75 | 2013-09-12 17:45:53 -0700 | [diff] [blame] | 5058 | if (access(VISUALIZER_LIBRARY_PATH, R_OK) == 0) { |
| 5059 | adev->visualizer_lib = dlopen(VISUALIZER_LIBRARY_PATH, RTLD_NOW); |
| 5060 | if (adev->visualizer_lib == NULL) { |
| 5061 | ALOGE("%s: DLOPEN failed for %s", __func__, VISUALIZER_LIBRARY_PATH); |
| 5062 | } else { |
| 5063 | ALOGV("%s: DLOPEN successful for %s", __func__, VISUALIZER_LIBRARY_PATH); |
| 5064 | adev->visualizer_start_output = |
Subhash Chandra Bose Naripeddy | 1d08916 | 2013-11-13 13:31:50 -0800 | [diff] [blame] | 5065 | (int (*)(audio_io_handle_t, int))dlsym(adev->visualizer_lib, |
Eric Laurent | c4aef75 | 2013-09-12 17:45:53 -0700 | [diff] [blame] | 5066 | "visualizer_hal_start_output"); |
| 5067 | adev->visualizer_stop_output = |
Subhash Chandra Bose Naripeddy | 1d08916 | 2013-11-13 13:31:50 -0800 | [diff] [blame] | 5068 | (int (*)(audio_io_handle_t, int))dlsym(adev->visualizer_lib, |
Eric Laurent | c4aef75 | 2013-09-12 17:45:53 -0700 | [diff] [blame] | 5069 | "visualizer_hal_stop_output"); |
| 5070 | } |
| 5071 | } |
Dhanalakshmi Siddani | 0b1488e | 2016-09-06 12:58:42 +0530 | [diff] [blame] | 5072 | audio_extn_init(); |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 5073 | audio_extn_listen_init(adev, adev->snd_card); |
Ravi Kumar Alamanda | 8fa6b19 | 2014-09-09 16:06:42 -0700 | [diff] [blame] | 5074 | audio_extn_sound_trigger_init(adev); |
Weiyin Jiang | aa80acd | 2016-09-21 16:42:11 +0800 | [diff] [blame] | 5075 | audio_extn_gef_init(adev); |
Eric Laurent | c4aef75 | 2013-09-12 17:45:53 -0700 | [diff] [blame] | 5076 | |
Subhash Chandra Bose Naripeddy | 1d08916 | 2013-11-13 13:31:50 -0800 | [diff] [blame] | 5077 | if (access(OFFLOAD_EFFECTS_BUNDLE_LIBRARY_PATH, R_OK) == 0) { |
| 5078 | adev->offload_effects_lib = dlopen(OFFLOAD_EFFECTS_BUNDLE_LIBRARY_PATH, RTLD_NOW); |
| 5079 | if (adev->offload_effects_lib == NULL) { |
| 5080 | ALOGE("%s: DLOPEN failed for %s", __func__, |
| 5081 | OFFLOAD_EFFECTS_BUNDLE_LIBRARY_PATH); |
| 5082 | } else { |
| 5083 | ALOGV("%s: DLOPEN successful for %s", __func__, |
| 5084 | OFFLOAD_EFFECTS_BUNDLE_LIBRARY_PATH); |
| 5085 | adev->offload_effects_start_output = |
Ashish Jain | 5106d36 | 2016-05-11 19:23:33 +0530 | [diff] [blame] | 5086 | (int (*)(audio_io_handle_t, int, struct mixer *))dlsym(adev->offload_effects_lib, |
Subhash Chandra Bose Naripeddy | 1d08916 | 2013-11-13 13:31:50 -0800 | [diff] [blame] | 5087 | "offload_effects_bundle_hal_start_output"); |
| 5088 | adev->offload_effects_stop_output = |
| 5089 | (int (*)(audio_io_handle_t, int))dlsym(adev->offload_effects_lib, |
| 5090 | "offload_effects_bundle_hal_stop_output"); |
Jitendra Naruka | 1b6513f | 2014-11-22 19:34:13 -0800 | [diff] [blame] | 5091 | adev->offload_effects_set_hpx_state = |
| 5092 | (int (*)(bool))dlsym(adev->offload_effects_lib, |
| 5093 | "offload_effects_bundle_set_hpx_state"); |
Dhananjay Kumar | d68883d | 2015-09-04 13:39:26 +0530 | [diff] [blame] | 5094 | adev->offload_effects_get_parameters = |
| 5095 | (void (*)(struct str_parms *, struct str_parms *)) |
| 5096 | dlsym(adev->offload_effects_lib, |
| 5097 | "offload_effects_bundle_get_parameters"); |
| 5098 | adev->offload_effects_set_parameters = |
| 5099 | (void (*)(struct str_parms *))dlsym(adev->offload_effects_lib, |
| 5100 | "offload_effects_bundle_set_parameters"); |
Subhash Chandra Bose Naripeddy | 1d08916 | 2013-11-13 13:31:50 -0800 | [diff] [blame] | 5101 | } |
| 5102 | } |
| 5103 | |
Ravi Kumar Alamanda | 8a0f977 | 2015-06-15 10:35:19 -0700 | [diff] [blame] | 5104 | if (access(ADM_LIBRARY_PATH, R_OK) == 0) { |
| 5105 | adev->adm_lib = dlopen(ADM_LIBRARY_PATH, RTLD_NOW); |
| 5106 | if (adev->adm_lib == NULL) { |
| 5107 | ALOGE("%s: DLOPEN failed for %s", __func__, ADM_LIBRARY_PATH); |
| 5108 | } else { |
| 5109 | ALOGV("%s: DLOPEN successful for %s", __func__, ADM_LIBRARY_PATH); |
| 5110 | adev->adm_init = (adm_init_t) |
| 5111 | dlsym(adev->adm_lib, "adm_init"); |
| 5112 | adev->adm_deinit = (adm_deinit_t) |
| 5113 | dlsym(adev->adm_lib, "adm_deinit"); |
| 5114 | adev->adm_register_input_stream = (adm_register_input_stream_t) |
| 5115 | dlsym(adev->adm_lib, "adm_register_input_stream"); |
| 5116 | adev->adm_register_output_stream = (adm_register_output_stream_t) |
| 5117 | dlsym(adev->adm_lib, "adm_register_output_stream"); |
| 5118 | adev->adm_deregister_stream = (adm_deregister_stream_t) |
| 5119 | dlsym(adev->adm_lib, "adm_deregister_stream"); |
| 5120 | adev->adm_request_focus = (adm_request_focus_t) |
| 5121 | dlsym(adev->adm_lib, "adm_request_focus"); |
| 5122 | adev->adm_abandon_focus = (adm_abandon_focus_t) |
| 5123 | dlsym(adev->adm_lib, "adm_abandon_focus"); |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 5124 | adev->adm_set_config = (adm_set_config_t) |
| 5125 | dlsym(adev->adm_lib, "adm_set_config"); |
| 5126 | adev->adm_request_focus_v2 = (adm_request_focus_v2_t) |
| 5127 | dlsym(adev->adm_lib, "adm_request_focus_v2"); |
| 5128 | adev->adm_is_noirq_avail = (adm_is_noirq_avail_t) |
| 5129 | dlsym(adev->adm_lib, "adm_is_noirq_avail"); |
| 5130 | adev->adm_on_routing_change = (adm_on_routing_change_t) |
| 5131 | dlsym(adev->adm_lib, "adm_on_routing_change"); |
Ravi Kumar Alamanda | 8a0f977 | 2015-06-15 10:35:19 -0700 | [diff] [blame] | 5132 | } |
| 5133 | } |
| 5134 | |
Mingming Yin | 514a8bc | 2014-07-29 15:22:21 -0700 | [diff] [blame] | 5135 | adev->bt_wb_speech_enabled = false; |
| 5136 | |
Pradnya Chaphekar | 8a9dcd8 | 2014-09-09 09:49:10 -0700 | [diff] [blame] | 5137 | audio_extn_ds2_enable(adev); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 5138 | *device = &adev->device.common; |
| 5139 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 5140 | audio_extn_utils_update_streams_cfg_lists(adev->platform, adev->mixer, |
| 5141 | &adev->streams_output_cfg_list, |
| 5142 | &adev->streams_input_cfg_list); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 5143 | |
Kiran Kandi | 910e186 | 2013-10-29 13:29:42 -0700 | [diff] [blame] | 5144 | audio_device_ref_count++; |
Ravi Kumar Alamanda | dc9bb15 | 2014-09-08 15:59:58 -0700 | [diff] [blame] | 5145 | |
| 5146 | char value[PROPERTY_VALUE_MAX]; |
| 5147 | int trial; |
| 5148 | if (property_get("audio_hal.period_size", value, NULL) > 0) { |
| 5149 | trial = atoi(value); |
| 5150 | if (period_size_is_plausible_for_low_latency(trial)) { |
| 5151 | pcm_config_low_latency.period_size = trial; |
| 5152 | pcm_config_low_latency.start_threshold = trial / 4; |
| 5153 | pcm_config_low_latency.avail_min = trial / 4; |
| 5154 | configured_low_latency_capture_period_size = trial; |
| 5155 | } |
| 5156 | } |
| 5157 | if (property_get("audio_hal.in_period_size", value, NULL) > 0) { |
| 5158 | trial = atoi(value); |
| 5159 | if (period_size_is_plausible_for_low_latency(trial)) { |
| 5160 | configured_low_latency_capture_period_size = trial; |
| 5161 | } |
| 5162 | } |
| 5163 | |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 5164 | if (property_get("audio_hal.period_multiplier", value, NULL) > 0) { |
| 5165 | af_period_multiplier = atoi(value); |
| 5166 | if (af_period_multiplier < 0) |
| 5167 | af_period_multiplier = 2; |
| 5168 | else if (af_period_multiplier > 4) |
| 5169 | af_period_multiplier = 4; |
| 5170 | |
| 5171 | ALOGV("new period_multiplier = %d", af_period_multiplier); |
| 5172 | } |
| 5173 | |
vivek mehta | 446c396 | 2015-09-14 10:57:35 -0700 | [diff] [blame] | 5174 | adev->multi_offload_enable = property_get_bool("audio.offload.multiple.enabled", false); |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 5175 | pthread_mutex_unlock(&adev_init_lock); |
| 5176 | |
Ravi Kumar Alamanda | 8a0f977 | 2015-06-15 10:35:19 -0700 | [diff] [blame] | 5177 | if (adev->adm_init) |
| 5178 | adev->adm_data = adev->adm_init(); |
| 5179 | |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 5180 | qahwi_init(*device); |
Sudheer Papothi | fa9d228 | 2015-09-17 01:53:25 +0530 | [diff] [blame] | 5181 | audio_extn_perf_lock_init(); |
Eric Laurent | 994a693 | 2013-07-17 11:51:42 -0700 | [diff] [blame] | 5182 | ALOGV("%s: exit", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 5183 | return 0; |
| 5184 | } |
| 5185 | |
| 5186 | static struct hw_module_methods_t hal_module_methods = { |
| 5187 | .open = adev_open, |
| 5188 | }; |
| 5189 | |
| 5190 | struct audio_module HAL_MODULE_INFO_SYM = { |
| 5191 | .common = { |
| 5192 | .tag = HARDWARE_MODULE_TAG, |
| 5193 | .module_api_version = AUDIO_MODULE_API_VERSION_0_1, |
| 5194 | .hal_api_version = HARDWARE_HAL_API_VERSION, |
| 5195 | .id = AUDIO_HARDWARE_MODULE_ID, |
| 5196 | .name = "QCOM Audio HAL", |
Duy Truong | fae1962 | 2013-11-24 02:17:54 -0800 | [diff] [blame] | 5197 | .author = "The Linux Foundation", |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 5198 | .methods = &hal_module_methods, |
| 5199 | }, |
| 5200 | }; |