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