Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Paul McLean | 9ab869a | 2015-01-13 09:37:06 -0800 | [diff] [blame] | 17 | #define LOG_TAG "modules.usbaudio.audio_hal" |
Paul McLean | cf61191 | 2014-04-28 13:03:18 -0700 | [diff] [blame] | 18 | /*#define LOG_NDEBUG 0*/ |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 19 | |
| 20 | #include <errno.h> |
Mark Salyzyn | 88e458a | 2014-04-28 12:30:44 -0700 | [diff] [blame] | 21 | #include <inttypes.h> |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 22 | #include <pthread.h> |
| 23 | #include <stdint.h> |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 24 | #include <stdlib.h> |
Mark Salyzyn | 88e458a | 2014-04-28 12:30:44 -0700 | [diff] [blame] | 25 | #include <sys/time.h> |
Tri Vo | 00a8673 | 2017-06-27 11:33:36 -0700 | [diff] [blame] | 26 | #include <unistd.h> |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 27 | |
Mark Salyzyn | 88e458a | 2014-04-28 12:30:44 -0700 | [diff] [blame] | 28 | #include <log/log.h> |
Paul McLean | 6a75e4e | 2016-05-25 14:09:02 -0600 | [diff] [blame] | 29 | #include <cutils/list.h> |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 30 | #include <cutils/str_parms.h> |
| 31 | #include <cutils/properties.h> |
| 32 | |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 33 | #include <hardware/audio.h> |
Paul McLean | e32cbc1 | 2014-06-25 10:42:07 -0700 | [diff] [blame] | 34 | #include <hardware/audio_alsaops.h> |
| 35 | #include <hardware/hardware.h> |
| 36 | |
| 37 | #include <system/audio.h> |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 38 | |
| 39 | #include <tinyalsa/asoundlib.h> |
| 40 | |
Paul McLean | c220115 | 2014-07-16 13:46:07 -0700 | [diff] [blame] | 41 | #include <audio_utils/channels.h> |
| 42 | |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 43 | #include "alsa_device_profile.h" |
| 44 | #include "alsa_device_proxy.h" |
Paul McLean | 9ab869a | 2015-01-13 09:37:06 -0800 | [diff] [blame] | 45 | #include "alsa_logging.h" |
Paul McLean | f62d75e | 2014-07-11 15:14:19 -0700 | [diff] [blame] | 46 | |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 47 | #define DEFAULT_INPUT_BUFFER_SIZE_MS 20 |
Paul McLean | f62d75e | 2014-07-11 15:14:19 -0700 | [diff] [blame] | 48 | |
Paul McLean | 1d585cc | 2016-05-24 11:28:10 -0600 | [diff] [blame] | 49 | /* Lock play & record samples rates at or above this threshold */ |
| 50 | #define RATELOCK_THRESHOLD 96000 |
| 51 | |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 52 | struct audio_device { |
| 53 | struct audio_hw_device hw_device; |
| 54 | |
| 55 | pthread_mutex_t lock; /* see note below on mutex acquisition order */ |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 56 | |
| 57 | /* output */ |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 58 | alsa_device_profile out_profile; |
Paul McLean | 6a75e4e | 2016-05-25 14:09:02 -0600 | [diff] [blame] | 59 | struct listnode output_stream_list; |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 60 | |
| 61 | /* input */ |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 62 | alsa_device_profile in_profile; |
Paul McLean | 6a75e4e | 2016-05-25 14:09:02 -0600 | [diff] [blame] | 63 | struct listnode input_stream_list; |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 64 | |
Paul McLean | 1d585cc | 2016-05-24 11:28:10 -0600 | [diff] [blame] | 65 | /* lock input & output sample rates */ |
| 66 | /*FIXME - How do we address multiple output streams? */ |
| 67 | uint32_t device_sample_rate; |
| 68 | |
Eric Laurent | 253def9 | 2014-09-14 12:18:18 -0700 | [diff] [blame] | 69 | bool mic_muted; |
| 70 | |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 71 | bool standby; |
| 72 | }; |
| 73 | |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 74 | struct stream_lock { |
| 75 | pthread_mutex_t lock; /* see note below on mutex acquisition order */ |
| 76 | pthread_mutex_t pre_lock; /* acquire before lock to avoid DOS by playback thread */ |
| 77 | }; |
| 78 | |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 79 | struct stream_out { |
| 80 | struct audio_stream_out stream; |
| 81 | |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 82 | struct stream_lock lock; |
| 83 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 84 | bool standby; |
| 85 | |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 86 | struct audio_device *adev; /* hardware information - only using this for the lock */ |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 87 | |
Paul McLean | 65ec72b | 2015-02-18 09:13:24 -0800 | [diff] [blame] | 88 | alsa_device_profile * profile; /* Points to the alsa_device_profile in the audio_device */ |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 89 | alsa_device_proxy proxy; /* state of the stream */ |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 90 | |
Andy Hung | 03576be | 2014-07-21 21:16:45 -0700 | [diff] [blame] | 91 | unsigned hal_channel_count; /* channel count exposed to AudioFlinger. |
| 92 | * This may differ from the device channel count when |
| 93 | * the device is not compatible with AudioFlinger |
| 94 | * capabilities, e.g. exposes too many channels or |
| 95 | * too few channels. */ |
Paul McLean | 64345f8 | 2016-06-06 13:26:05 -0600 | [diff] [blame] | 96 | audio_channel_mask_t hal_channel_mask; /* USB devices deal in channel counts, not masks |
| 97 | * so the proxy doesn't have a channel_mask, but |
| 98 | * audio HALs need to talk about channel masks |
| 99 | * so expose the one calculated by |
| 100 | * adev_open_output_stream */ |
Andy Hung | 182ddc7 | 2015-05-05 23:37:30 -0700 | [diff] [blame] | 101 | |
Paul McLean | 6a75e4e | 2016-05-25 14:09:02 -0600 | [diff] [blame] | 102 | struct listnode list_node; |
| 103 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 104 | void * conversion_buffer; /* any conversions are put into here |
| 105 | * they could come from here too if |
| 106 | * there was a previous conversion */ |
| 107 | size_t conversion_buffer_size; /* in bytes */ |
| 108 | }; |
| 109 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 110 | struct stream_in { |
| 111 | struct audio_stream_in stream; |
| 112 | |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 113 | struct stream_lock lock; |
| 114 | |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 115 | bool standby; |
| 116 | |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 117 | struct audio_device *adev; /* hardware information - only using this for the lock */ |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 118 | |
Paul McLean | 65ec72b | 2015-02-18 09:13:24 -0800 | [diff] [blame] | 119 | alsa_device_profile * profile; /* Points to the alsa_device_profile in the audio_device */ |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 120 | alsa_device_proxy proxy; /* state of the stream */ |
Paul McLean | f62d75e | 2014-07-11 15:14:19 -0700 | [diff] [blame] | 121 | |
Paul McLean | 2cfd81b | 2014-09-15 12:32:23 -0700 | [diff] [blame] | 122 | unsigned hal_channel_count; /* channel count exposed to AudioFlinger. |
| 123 | * This may differ from the device channel count when |
| 124 | * the device is not compatible with AudioFlinger |
| 125 | * capabilities, e.g. exposes too many channels or |
| 126 | * too few channels. */ |
Paul McLean | 64345f8 | 2016-06-06 13:26:05 -0600 | [diff] [blame] | 127 | audio_channel_mask_t hal_channel_mask; /* USB devices deal in channel counts, not masks |
| 128 | * so the proxy doesn't have a channel_mask, but |
| 129 | * audio HALs need to talk about channel masks |
| 130 | * so expose the one calculated by |
| 131 | * adev_open_input_stream */ |
Andy Hung | 780f1f8 | 2015-04-22 22:14:39 -0700 | [diff] [blame] | 132 | |
Paul McLean | 6a75e4e | 2016-05-25 14:09:02 -0600 | [diff] [blame] | 133 | struct listnode list_node; |
| 134 | |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 135 | /* We may need to read more data from the device in order to data reduce to 16bit, 4chan */ |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 136 | void * conversion_buffer; /* any conversions are put into here |
| 137 | * they could come from here too if |
| 138 | * there was a previous conversion */ |
| 139 | size_t conversion_buffer_size; /* in bytes */ |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 140 | }; |
| 141 | |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 142 | /* |
| 143 | * Locking Helpers |
| 144 | */ |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 145 | /* |
Eric Laurent | 7031809 | 2015-06-19 17:49:17 -0700 | [diff] [blame] | 146 | * NOTE: when multiple mutexes have to be acquired, always take the |
| 147 | * stream_in or stream_out mutex first, followed by the audio_device mutex. |
| 148 | * stream pre_lock is always acquired before stream lock to prevent starvation of control thread by |
| 149 | * higher priority playback or capture thread. |
| 150 | */ |
| 151 | |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 152 | static void stream_lock_init(struct stream_lock *lock) { |
| 153 | pthread_mutex_init(&lock->lock, (const pthread_mutexattr_t *) NULL); |
| 154 | pthread_mutex_init(&lock->pre_lock, (const pthread_mutexattr_t *) NULL); |
| 155 | } |
| 156 | |
| 157 | static void stream_lock(struct stream_lock *lock) { |
| 158 | pthread_mutex_lock(&lock->pre_lock); |
| 159 | pthread_mutex_lock(&lock->lock); |
| 160 | pthread_mutex_unlock(&lock->pre_lock); |
| 161 | } |
| 162 | |
| 163 | static void stream_unlock(struct stream_lock *lock) { |
| 164 | pthread_mutex_unlock(&lock->lock); |
| 165 | } |
| 166 | |
| 167 | static void device_lock(struct audio_device *adev) { |
| 168 | pthread_mutex_lock(&adev->lock); |
| 169 | } |
| 170 | |
| 171 | static int device_try_lock(struct audio_device *adev) { |
| 172 | return pthread_mutex_trylock(&adev->lock); |
| 173 | } |
| 174 | |
| 175 | static void device_unlock(struct audio_device *adev) { |
| 176 | pthread_mutex_unlock(&adev->lock); |
| 177 | } |
| 178 | |
| 179 | /* |
| 180 | * streams list management |
| 181 | */ |
| 182 | static void adev_add_stream_to_list( |
| 183 | struct audio_device* adev, struct listnode* list, struct listnode* stream_node) { |
| 184 | device_lock(adev); |
| 185 | |
| 186 | list_add_tail(list, stream_node); |
| 187 | |
| 188 | device_unlock(adev); |
| 189 | } |
| 190 | |
| 191 | static void adev_remove_stream_from_list( |
| 192 | struct audio_device* adev, struct listnode* stream_node) { |
| 193 | device_lock(adev); |
| 194 | |
| 195 | list_remove(stream_node); |
| 196 | |
| 197 | device_unlock(adev); |
| 198 | } |
| 199 | |
Eric Laurent | 7031809 | 2015-06-19 17:49:17 -0700 | [diff] [blame] | 200 | /* |
Paul McLean | 0f1753e | 2014-12-02 12:36:45 -0700 | [diff] [blame] | 201 | * Extract the card and device numbers from the supplied key/value pairs. |
| 202 | * kvpairs A null-terminated string containing the key/value pairs or card and device. |
| 203 | * i.e. "card=1;device=42" |
| 204 | * card A pointer to a variable to receive the parsed-out card number. |
| 205 | * device A pointer to a variable to receive the parsed-out device number. |
| 206 | * NOTE: The variables pointed to by card and device return -1 (undefined) if the |
| 207 | * associated key/value pair is not found in the provided string. |
Paul McLean | 65ec72b | 2015-02-18 09:13:24 -0800 | [diff] [blame] | 208 | * Return true if the kvpairs string contain a card/device spec, false otherwise. |
Paul McLean | 0f1753e | 2014-12-02 12:36:45 -0700 | [diff] [blame] | 209 | */ |
Paul McLean | 65ec72b | 2015-02-18 09:13:24 -0800 | [diff] [blame] | 210 | static bool parse_card_device_params(const char *kvpairs, int *card, int *device) |
Paul McLean | 0f1753e | 2014-12-02 12:36:45 -0700 | [diff] [blame] | 211 | { |
| 212 | struct str_parms * parms = str_parms_create_str(kvpairs); |
| 213 | char value[32]; |
| 214 | int param_val; |
| 215 | |
| 216 | // initialize to "undefined" state. |
| 217 | *card = -1; |
| 218 | *device = -1; |
| 219 | |
| 220 | param_val = str_parms_get_str(parms, "card", value, sizeof(value)); |
| 221 | if (param_val >= 0) { |
| 222 | *card = atoi(value); |
| 223 | } |
| 224 | |
| 225 | param_val = str_parms_get_str(parms, "device", value, sizeof(value)); |
| 226 | if (param_val >= 0) { |
| 227 | *device = atoi(value); |
| 228 | } |
| 229 | |
| 230 | str_parms_destroy(parms); |
Paul McLean | 65ec72b | 2015-02-18 09:13:24 -0800 | [diff] [blame] | 231 | |
| 232 | return *card >= 0 && *device >= 0; |
Paul McLean | 0f1753e | 2014-12-02 12:36:45 -0700 | [diff] [blame] | 233 | } |
| 234 | |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 235 | static char * device_get_parameters(alsa_device_profile * profile, const char * keys) |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 236 | { |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 237 | if (profile->card < 0 || profile->device < 0) { |
| 238 | return strdup(""); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 239 | } |
Paul McLean | e32cbc1 | 2014-06-25 10:42:07 -0700 | [diff] [blame] | 240 | |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 241 | struct str_parms *query = str_parms_create_str(keys); |
| 242 | struct str_parms *result = str_parms_create(); |
Paul McLean | e32cbc1 | 2014-06-25 10:42:07 -0700 | [diff] [blame] | 243 | |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 244 | /* These keys are from hardware/libhardware/include/audio.h */ |
| 245 | /* supported sample rates */ |
| 246 | if (str_parms_has_key(query, AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES)) { |
| 247 | char* rates_list = profile_get_sample_rate_strs(profile); |
| 248 | str_parms_add_str(result, AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES, |
| 249 | rates_list); |
| 250 | free(rates_list); |
Paul McLean | e32cbc1 | 2014-06-25 10:42:07 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 253 | /* supported channel counts */ |
| 254 | if (str_parms_has_key(query, AUDIO_PARAMETER_STREAM_SUP_CHANNELS)) { |
| 255 | char* channels_list = profile_get_channel_count_strs(profile); |
| 256 | str_parms_add_str(result, AUDIO_PARAMETER_STREAM_SUP_CHANNELS, |
| 257 | channels_list); |
| 258 | free(channels_list); |
Paul McLean | e32cbc1 | 2014-06-25 10:42:07 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 261 | /* supported sample formats */ |
| 262 | if (str_parms_has_key(query, AUDIO_PARAMETER_STREAM_SUP_FORMATS)) { |
| 263 | char * format_params = profile_get_format_strs(profile); |
| 264 | str_parms_add_str(result, AUDIO_PARAMETER_STREAM_SUP_FORMATS, |
| 265 | format_params); |
| 266 | free(format_params); |
Paul McLean | f62d75e | 2014-07-11 15:14:19 -0700 | [diff] [blame] | 267 | } |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 268 | str_parms_destroy(query); |
Paul McLean | f62d75e | 2014-07-11 15:14:19 -0700 | [diff] [blame] | 269 | |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 270 | char* result_str = str_parms_to_str(result); |
| 271 | str_parms_destroy(result); |
Paul McLean | f62d75e | 2014-07-11 15:14:19 -0700 | [diff] [blame] | 272 | |
Paul McLean | 65ec72b | 2015-02-18 09:13:24 -0800 | [diff] [blame] | 273 | ALOGV("device_get_parameters = %s", result_str); |
Paul McLean | f62d75e | 2014-07-11 15:14:19 -0700 | [diff] [blame] | 274 | |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 275 | return result_str; |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | /* |
| 279 | * HAl Functions |
| 280 | */ |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 281 | /** |
| 282 | * NOTE: when multiple mutexes have to be acquired, always respect the |
| 283 | * following order: hw device > out stream |
| 284 | */ |
| 285 | |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 286 | /* |
| 287 | * OUT functions |
| 288 | */ |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 289 | static uint32_t out_get_sample_rate(const struct audio_stream *stream) |
| 290 | { |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 291 | uint32_t rate = proxy_get_sample_rate(&((struct stream_out*)stream)->proxy); |
| 292 | ALOGV("out_get_sample_rate() = %d", rate); |
| 293 | return rate; |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate) |
| 297 | { |
| 298 | return 0; |
| 299 | } |
| 300 | |
| 301 | static size_t out_get_buffer_size(const struct audio_stream *stream) |
| 302 | { |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 303 | const struct stream_out* out = (const struct stream_out*)stream; |
| 304 | size_t buffer_size = |
| 305 | proxy_get_period_size(&out->proxy) * audio_stream_out_frame_size(&(out->stream)); |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 306 | return buffer_size; |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | static uint32_t out_get_channels(const struct audio_stream *stream) |
| 310 | { |
Andy Hung | 03576be | 2014-07-21 21:16:45 -0700 | [diff] [blame] | 311 | const struct stream_out *out = (const struct stream_out*)stream; |
Andy Hung | 182ddc7 | 2015-05-05 23:37:30 -0700 | [diff] [blame] | 312 | return out->hal_channel_mask; |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | static audio_format_t out_get_format(const struct audio_stream *stream) |
| 316 | { |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 317 | /* Note: The HAL doesn't do any FORMAT conversion at this time. It |
| 318 | * Relies on the framework to provide data in the specified format. |
| 319 | * This could change in the future. |
| 320 | */ |
| 321 | alsa_device_proxy * proxy = &((struct stream_out*)stream)->proxy; |
| 322 | audio_format_t format = audio_format_from_pcm_format(proxy_get_format(proxy)); |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 323 | return format; |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | static int out_set_format(struct audio_stream *stream, audio_format_t format) |
| 327 | { |
| 328 | return 0; |
| 329 | } |
| 330 | |
| 331 | static int out_standby(struct audio_stream *stream) |
| 332 | { |
| 333 | struct stream_out *out = (struct stream_out *)stream; |
| 334 | |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 335 | stream_lock(&out->lock); |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 336 | if (!out->standby) { |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 337 | device_lock(out->adev); |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 338 | proxy_close(&out->proxy); |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 339 | device_unlock(out->adev); |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 340 | out->standby = true; |
| 341 | } |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 342 | stream_unlock(&out->lock); |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 343 | return 0; |
| 344 | } |
| 345 | |
Paul McLean | 6a75e4e | 2016-05-25 14:09:02 -0600 | [diff] [blame] | 346 | static int out_dump(const struct audio_stream *stream, int fd) { |
| 347 | const struct stream_out* out_stream = (const struct stream_out*) stream; |
| 348 | |
| 349 | if (out_stream != NULL) { |
| 350 | dprintf(fd, "Output Profile:\n"); |
| 351 | profile_dump(out_stream->profile, fd); |
| 352 | |
| 353 | dprintf(fd, "Output Proxy:\n"); |
| 354 | proxy_dump(&out_stream->proxy, fd); |
| 355 | } |
| 356 | |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 357 | return 0; |
| 358 | } |
| 359 | |
| 360 | static int out_set_parameters(struct audio_stream *stream, const char *kvpairs) |
| 361 | { |
Paul McLean | 65ec72b | 2015-02-18 09:13:24 -0800 | [diff] [blame] | 362 | ALOGV("out_set_parameters() keys:%s", kvpairs); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 363 | |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 364 | struct stream_out *out = (struct stream_out *)stream; |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 365 | |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 366 | int routing = 0; |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 367 | int ret_value = 0; |
Eric Laurent | 05333d4 | 2014-08-04 20:29:17 -0700 | [diff] [blame] | 368 | int card = -1; |
| 369 | int device = -1; |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 370 | |
Paul McLean | 65ec72b | 2015-02-18 09:13:24 -0800 | [diff] [blame] | 371 | if (!parse_card_device_params(kvpairs, &card, &device)) { |
| 372 | // nothing to do |
| 373 | return ret_value; |
| 374 | } |
| 375 | |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 376 | stream_lock(&out->lock); |
Paul McLean | 65ec72b | 2015-02-18 09:13:24 -0800 | [diff] [blame] | 377 | /* Lock the device because that is where the profile lives */ |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 378 | device_lock(out->adev); |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 379 | |
Paul McLean | 65ec72b | 2015-02-18 09:13:24 -0800 | [diff] [blame] | 380 | if (!profile_is_cached_for(out->profile, card, device)) { |
Eric Laurent | 05333d4 | 2014-08-04 20:29:17 -0700 | [diff] [blame] | 381 | /* cannot read pcm device info if playback is active */ |
| 382 | if (!out->standby) |
| 383 | ret_value = -ENOSYS; |
| 384 | else { |
| 385 | int saved_card = out->profile->card; |
| 386 | int saved_device = out->profile->device; |
| 387 | out->profile->card = card; |
| 388 | out->profile->device = device; |
| 389 | ret_value = profile_read_device_info(out->profile) ? 0 : -EINVAL; |
| 390 | if (ret_value != 0) { |
| 391 | out->profile->card = saved_card; |
| 392 | out->profile->device = saved_device; |
| 393 | } |
| 394 | } |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 395 | } |
Paul McLean | 2c6196f | 2014-08-20 16:50:25 -0700 | [diff] [blame] | 396 | |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 397 | device_unlock(out->adev); |
| 398 | stream_unlock(&out->lock); |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 399 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 400 | return ret_value; |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Paul McLean | f62d75e | 2014-07-11 15:14:19 -0700 | [diff] [blame] | 403 | static char * out_get_parameters(const struct audio_stream *stream, const char *keys) |
| 404 | { |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 405 | struct stream_out *out = (struct stream_out *)stream; |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 406 | stream_lock(&out->lock); |
| 407 | device_lock(out->adev); |
Paul McLean | f62d75e | 2014-07-11 15:14:19 -0700 | [diff] [blame] | 408 | |
| 409 | char * params_str = device_get_parameters(out->profile, keys); |
| 410 | |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 411 | device_unlock(out->adev); |
| 412 | stream_unlock(&out->lock); |
Paul McLean | f62d75e | 2014-07-11 15:14:19 -0700 | [diff] [blame] | 413 | return params_str; |
| 414 | } |
| 415 | |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 416 | static uint32_t out_get_latency(const struct audio_stream_out *stream) |
| 417 | { |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 418 | alsa_device_proxy * proxy = &((struct stream_out*)stream)->proxy; |
| 419 | return proxy_get_latency(proxy); |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 420 | } |
| 421 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 422 | static int out_set_volume(struct audio_stream_out *stream, float left, float right) |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 423 | { |
| 424 | return -ENOSYS; |
| 425 | } |
| 426 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 427 | /* must be called with hw device and output stream mutexes locked */ |
| 428 | static int start_output_stream(struct stream_out *out) |
| 429 | { |
Paul McLean | 65ec72b | 2015-02-18 09:13:24 -0800 | [diff] [blame] | 430 | ALOGV("start_output_stream(card:%d device:%d)", out->profile->card, out->profile->device); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 431 | |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 432 | return proxy_open(&out->proxy); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | static ssize_t out_write(struct audio_stream_out *stream, const void* buffer, size_t bytes) |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 436 | { |
| 437 | int ret; |
| 438 | struct stream_out *out = (struct stream_out *)stream; |
| 439 | |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 440 | stream_lock(&out->lock); |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 441 | if (out->standby) { |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 442 | device_lock(out->adev); |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 443 | ret = start_output_stream(out); |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 444 | device_unlock(out->adev); |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 445 | if (ret != 0) { |
| 446 | goto err; |
| 447 | } |
| 448 | out->standby = false; |
| 449 | } |
Eric Laurent | 05333d4 | 2014-08-04 20:29:17 -0700 | [diff] [blame] | 450 | |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 451 | alsa_device_proxy* proxy = &out->proxy; |
Mark Salyzyn | 88e458a | 2014-04-28 12:30:44 -0700 | [diff] [blame] | 452 | const void * write_buff = buffer; |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 453 | int num_write_buff_bytes = bytes; |
Andy Hung | 03576be | 2014-07-21 21:16:45 -0700 | [diff] [blame] | 454 | const int num_device_channels = proxy_get_channel_count(proxy); /* what we told alsa */ |
| 455 | const int num_req_channels = out->hal_channel_count; /* what we told AudioFlinger */ |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 456 | if (num_device_channels != num_req_channels) { |
Andy Hung | 03576be | 2014-07-21 21:16:45 -0700 | [diff] [blame] | 457 | /* allocate buffer */ |
| 458 | const size_t required_conversion_buffer_size = |
| 459 | bytes * num_device_channels / num_req_channels; |
| 460 | if (required_conversion_buffer_size > out->conversion_buffer_size) { |
| 461 | out->conversion_buffer_size = required_conversion_buffer_size; |
| 462 | out->conversion_buffer = realloc(out->conversion_buffer, |
| 463 | out->conversion_buffer_size); |
| 464 | } |
| 465 | /* convert data */ |
| 466 | const audio_format_t audio_format = out_get_format(&(out->stream.common)); |
| 467 | const unsigned sample_size_in_bytes = audio_bytes_per_sample(audio_format); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 468 | num_write_buff_bytes = |
Andy Hung | 03576be | 2014-07-21 21:16:45 -0700 | [diff] [blame] | 469 | adjust_channels(write_buff, num_req_channels, |
| 470 | out->conversion_buffer, num_device_channels, |
| 471 | sample_size_in_bytes, num_write_buff_bytes); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 472 | write_buff = out->conversion_buffer; |
| 473 | } |
| 474 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 475 | if (write_buff != NULL && num_write_buff_bytes != 0) { |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 476 | proxy_write(&out->proxy, write_buff, num_write_buff_bytes); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 477 | } |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 478 | |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 479 | stream_unlock(&out->lock); |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 480 | |
| 481 | return bytes; |
| 482 | |
| 483 | err: |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 484 | stream_unlock(&out->lock); |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 485 | if (ret != 0) { |
Eric Laurent | c5ae6a0 | 2014-07-02 13:45:32 -0700 | [diff] [blame] | 486 | usleep(bytes * 1000000 / audio_stream_out_frame_size(stream) / |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 487 | out_get_sample_rate(&stream->common)); |
| 488 | } |
| 489 | |
| 490 | return bytes; |
| 491 | } |
| 492 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 493 | static int out_get_render_position(const struct audio_stream_out *stream, uint32_t *dsp_frames) |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 494 | { |
| 495 | return -EINVAL; |
| 496 | } |
| 497 | |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 498 | static int out_get_presentation_position(const struct audio_stream_out *stream, |
| 499 | uint64_t *frames, struct timespec *timestamp) |
| 500 | { |
Andy Hung | c9515ce | 2015-08-04 15:05:19 -0700 | [diff] [blame] | 501 | struct stream_out *out = (struct stream_out *)stream; // discard const qualifier |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 502 | stream_lock(&out->lock); |
Andy Hung | c9515ce | 2015-08-04 15:05:19 -0700 | [diff] [blame] | 503 | |
| 504 | const alsa_device_proxy *proxy = &out->proxy; |
| 505 | const int ret = proxy_get_presentation_position(proxy, frames, timestamp); |
| 506 | |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 507 | stream_unlock(&out->lock); |
Andy Hung | c9515ce | 2015-08-04 15:05:19 -0700 | [diff] [blame] | 508 | return ret; |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 509 | } |
| 510 | |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 511 | static int out_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect) |
| 512 | { |
| 513 | return 0; |
| 514 | } |
| 515 | |
| 516 | static int out_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect) |
| 517 | { |
| 518 | return 0; |
| 519 | } |
| 520 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 521 | static int out_get_next_write_timestamp(const struct audio_stream_out *stream, int64_t *timestamp) |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 522 | { |
| 523 | return -EINVAL; |
| 524 | } |
| 525 | |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 526 | static int adev_open_output_stream(struct audio_hw_device *hw_dev, |
Mike Lockwood | 46a9809 | 2012-04-24 16:41:18 -0700 | [diff] [blame] | 527 | audio_io_handle_t handle, |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 528 | audio_devices_t devicesSpec __unused, |
Mike Lockwood | 46a9809 | 2012-04-24 16:41:18 -0700 | [diff] [blame] | 529 | audio_output_flags_t flags, |
| 530 | struct audio_config *config, |
Eric Laurent | f5e2469 | 2014-07-27 16:14:57 -0700 | [diff] [blame] | 531 | struct audio_stream_out **stream_out, |
Paul McLean | 0f1753e | 2014-12-02 12:36:45 -0700 | [diff] [blame] | 532 | const char *address /*__unused*/) |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 533 | { |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 534 | ALOGV("adev_open_output_stream() handle:0x%X, devicesSpec:0x%X, flags:0x%X, addr:%s", |
| 535 | handle, devicesSpec, flags, address); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 536 | |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 537 | struct stream_out *out; |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 538 | |
| 539 | out = (struct stream_out *)calloc(1, sizeof(struct stream_out)); |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 540 | if (out == NULL) { |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 541 | return -ENOMEM; |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 542 | } |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 543 | |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 544 | /* setup function pointers */ |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 545 | out->stream.common.get_sample_rate = out_get_sample_rate; |
| 546 | out->stream.common.set_sample_rate = out_set_sample_rate; |
| 547 | out->stream.common.get_buffer_size = out_get_buffer_size; |
| 548 | out->stream.common.get_channels = out_get_channels; |
| 549 | out->stream.common.get_format = out_get_format; |
| 550 | out->stream.common.set_format = out_set_format; |
| 551 | out->stream.common.standby = out_standby; |
| 552 | out->stream.common.dump = out_dump; |
| 553 | out->stream.common.set_parameters = out_set_parameters; |
| 554 | out->stream.common.get_parameters = out_get_parameters; |
| 555 | out->stream.common.add_audio_effect = out_add_audio_effect; |
| 556 | out->stream.common.remove_audio_effect = out_remove_audio_effect; |
| 557 | out->stream.get_latency = out_get_latency; |
| 558 | out->stream.set_volume = out_set_volume; |
| 559 | out->stream.write = out_write; |
| 560 | out->stream.get_render_position = out_get_render_position; |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 561 | out->stream.get_presentation_position = out_get_presentation_position; |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 562 | out->stream.get_next_write_timestamp = out_get_next_write_timestamp; |
| 563 | |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 564 | stream_lock_init(&out->lock); |
Eric Laurent | 7031809 | 2015-06-19 17:49:17 -0700 | [diff] [blame] | 565 | |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 566 | out->adev = (struct audio_device *)hw_dev; |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 567 | device_lock(out->adev); |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 568 | out->profile = &out->adev->out_profile; |
Paul McLean | f62d75e | 2014-07-11 15:14:19 -0700 | [diff] [blame] | 569 | |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 570 | // build this to hand to the alsa_device_proxy |
| 571 | struct pcm_config proxy_config; |
Paul McLean | 2c6196f | 2014-08-20 16:50:25 -0700 | [diff] [blame] | 572 | memset(&proxy_config, 0, sizeof(proxy_config)); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 573 | |
Paul McLean | 0f1753e | 2014-12-02 12:36:45 -0700 | [diff] [blame] | 574 | /* Pull out the card/device pair */ |
| 575 | parse_card_device_params(address, &(out->profile->card), &(out->profile->device)); |
| 576 | |
| 577 | profile_read_device_info(out->profile); |
| 578 | |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 579 | int ret = 0; |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 580 | |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 581 | /* Rate */ |
| 582 | if (config->sample_rate == 0) { |
| 583 | proxy_config.rate = config->sample_rate = profile_get_default_sample_rate(out->profile); |
| 584 | } else if (profile_is_sample_rate_valid(out->profile, config->sample_rate)) { |
| 585 | proxy_config.rate = config->sample_rate; |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 586 | } else { |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 587 | proxy_config.rate = config->sample_rate = profile_get_default_sample_rate(out->profile); |
| 588 | ret = -EINVAL; |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 589 | } |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 590 | |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 591 | out->adev->device_sample_rate = config->sample_rate; |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 592 | device_unlock(out->adev); |
Paul McLean | 1d585cc | 2016-05-24 11:28:10 -0600 | [diff] [blame] | 593 | |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 594 | /* Format */ |
| 595 | if (config->format == AUDIO_FORMAT_DEFAULT) { |
| 596 | proxy_config.format = profile_get_default_format(out->profile); |
| 597 | config->format = audio_format_from_pcm_format(proxy_config.format); |
| 598 | } else { |
| 599 | enum pcm_format fmt = pcm_format_from_audio_format(config->format); |
| 600 | if (profile_is_format_valid(out->profile, fmt)) { |
| 601 | proxy_config.format = fmt; |
| 602 | } else { |
| 603 | proxy_config.format = profile_get_default_format(out->profile); |
| 604 | config->format = audio_format_from_pcm_format(proxy_config.format); |
| 605 | ret = -EINVAL; |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | /* Channels */ |
Paul McLean | 64345f8 | 2016-06-06 13:26:05 -0600 | [diff] [blame] | 610 | bool calc_mask = false; |
| 611 | if (config->channel_mask == AUDIO_CHANNEL_NONE) { |
| 612 | /* query case */ |
| 613 | out->hal_channel_count = profile_get_default_channel_count(out->profile); |
| 614 | calc_mask = true; |
Andy Hung | 182ddc7 | 2015-05-05 23:37:30 -0700 | [diff] [blame] | 615 | } else { |
Paul McLean | 64345f8 | 2016-06-06 13:26:05 -0600 | [diff] [blame] | 616 | /* explicit case */ |
| 617 | out->hal_channel_count = audio_channel_count_from_out_mask(config->channel_mask); |
Andy Hung | 182ddc7 | 2015-05-05 23:37:30 -0700 | [diff] [blame] | 618 | } |
Paul McLean | 698dbd7 | 2015-11-03 12:24:30 -0800 | [diff] [blame] | 619 | |
Paul McLean | 64345f8 | 2016-06-06 13:26:05 -0600 | [diff] [blame] | 620 | /* The Framework is currently limited to no more than this number of channels */ |
| 621 | if (out->hal_channel_count > FCC_8) { |
| 622 | out->hal_channel_count = FCC_8; |
| 623 | calc_mask = true; |
| 624 | } |
| 625 | |
| 626 | if (calc_mask) { |
| 627 | /* need to calculate the mask from channel count either because this is the query case |
| 628 | * or the specified mask isn't valid for this device, or is more then the FW can handle */ |
| 629 | config->channel_mask = out->hal_channel_count <= FCC_2 |
| 630 | /* position mask for mono and stereo*/ |
| 631 | ? audio_channel_out_mask_from_count(out->hal_channel_count) |
| 632 | /* otherwise indexed */ |
| 633 | : audio_channel_mask_for_index_assignment_from_count(out->hal_channel_count); |
| 634 | } |
| 635 | |
Andy Hung | 182ddc7 | 2015-05-05 23:37:30 -0700 | [diff] [blame] | 636 | out->hal_channel_mask = config->channel_mask; |
| 637 | |
Paul McLean | 64345f8 | 2016-06-06 13:26:05 -0600 | [diff] [blame] | 638 | // Validate the "logical" channel count against support in the "actual" profile. |
| 639 | // if they differ, choose the "actual" number of channels *closest* to the "logical". |
| 640 | // and store THAT in proxy_config.channels |
| 641 | proxy_config.channels = profile_get_closest_channel_count(out->profile, out->hal_channel_count); |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 642 | proxy_prepare(&out->proxy, out->profile, &proxy_config); |
| 643 | |
| 644 | /* TODO The retry mechanism isn't implemented in AudioPolicyManager/AudioFlinger. */ |
| 645 | ret = 0; |
| 646 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 647 | out->conversion_buffer = NULL; |
| 648 | out->conversion_buffer_size = 0; |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 649 | |
| 650 | out->standby = true; |
| 651 | |
Paul McLean | 6a75e4e | 2016-05-25 14:09:02 -0600 | [diff] [blame] | 652 | /* Save the stream for adev_dump() */ |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 653 | adev_add_stream_to_list(out->adev, &out->adev->output_stream_list, &out->list_node); |
Paul McLean | 6a75e4e | 2016-05-25 14:09:02 -0600 | [diff] [blame] | 654 | |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 655 | *stream_out = &out->stream; |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 656 | |
| 657 | return ret; |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 658 | |
| 659 | err_open: |
| 660 | free(out); |
| 661 | *stream_out = NULL; |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 662 | return -ENOSYS; |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 663 | } |
| 664 | |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 665 | static void adev_close_output_stream(struct audio_hw_device *hw_dev, |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 666 | struct audio_stream_out *stream) |
| 667 | { |
| 668 | struct stream_out *out = (struct stream_out *)stream; |
Paul McLean | 65ec72b | 2015-02-18 09:13:24 -0800 | [diff] [blame] | 669 | ALOGV("adev_close_output_stream(c:%d d:%d)", out->profile->card, out->profile->device); |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 670 | |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 671 | adev_remove_stream_from_list(out->adev, &out->list_node); |
Paul McLean | 6a75e4e | 2016-05-25 14:09:02 -0600 | [diff] [blame] | 672 | |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 673 | /* Close the pcm device */ |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 674 | out_standby(&stream->common); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 675 | |
| 676 | free(out->conversion_buffer); |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 677 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 678 | out->conversion_buffer = NULL; |
| 679 | out->conversion_buffer_size = 0; |
| 680 | |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 681 | device_lock(out->adev); |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 682 | out->adev->device_sample_rate = 0; |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 683 | device_unlock(out->adev); |
Paul McLean | 1d585cc | 2016-05-24 11:28:10 -0600 | [diff] [blame] | 684 | |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 685 | free(stream); |
| 686 | } |
| 687 | |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 688 | static size_t adev_get_input_buffer_size(const struct audio_hw_device *hw_dev, |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 689 | const struct audio_config *config) |
| 690 | { |
| 691 | /* TODO This needs to be calculated based on format/channels/rate */ |
| 692 | return 320; |
| 693 | } |
| 694 | |
| 695 | /* |
| 696 | * IN functions |
| 697 | */ |
| 698 | static uint32_t in_get_sample_rate(const struct audio_stream *stream) |
| 699 | { |
| 700 | uint32_t rate = proxy_get_sample_rate(&((const struct stream_in *)stream)->proxy); |
| 701 | ALOGV("in_get_sample_rate() = %d", rate); |
| 702 | return rate; |
| 703 | } |
| 704 | |
| 705 | static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate) |
| 706 | { |
| 707 | ALOGV("in_set_sample_rate(%d) - NOPE", rate); |
| 708 | return -ENOSYS; |
| 709 | } |
| 710 | |
| 711 | static size_t in_get_buffer_size(const struct audio_stream *stream) |
| 712 | { |
| 713 | const struct stream_in * in = ((const struct stream_in*)stream); |
Paul McLean | 2cfd81b | 2014-09-15 12:32:23 -0700 | [diff] [blame] | 714 | return proxy_get_period_size(&in->proxy) * audio_stream_in_frame_size(&(in->stream)); |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | static uint32_t in_get_channels(const struct audio_stream *stream) |
| 718 | { |
Paul McLean | 2cfd81b | 2014-09-15 12:32:23 -0700 | [diff] [blame] | 719 | const struct stream_in *in = (const struct stream_in*)stream; |
Andy Hung | 780f1f8 | 2015-04-22 22:14:39 -0700 | [diff] [blame] | 720 | return in->hal_channel_mask; |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | static audio_format_t in_get_format(const struct audio_stream *stream) |
| 724 | { |
Andy Hung | 780f1f8 | 2015-04-22 22:14:39 -0700 | [diff] [blame] | 725 | alsa_device_proxy *proxy = &((struct stream_in*)stream)->proxy; |
| 726 | audio_format_t format = audio_format_from_pcm_format(proxy_get_format(proxy)); |
| 727 | return format; |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | static int in_set_format(struct audio_stream *stream, audio_format_t format) |
| 731 | { |
| 732 | ALOGV("in_set_format(%d) - NOPE", format); |
| 733 | |
| 734 | return -ENOSYS; |
| 735 | } |
| 736 | |
| 737 | static int in_standby(struct audio_stream *stream) |
| 738 | { |
| 739 | struct stream_in *in = (struct stream_in *)stream; |
| 740 | |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 741 | stream_lock(&in->lock); |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 742 | if (!in->standby) { |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 743 | device_lock(in->adev); |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 744 | proxy_close(&in->proxy); |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 745 | device_unlock(in->adev); |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 746 | in->standby = true; |
| 747 | } |
| 748 | |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 749 | stream_unlock(&in->lock); |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 750 | |
| 751 | return 0; |
| 752 | } |
| 753 | |
| 754 | static int in_dump(const struct audio_stream *stream, int fd) |
| 755 | { |
Paul McLean | 6a75e4e | 2016-05-25 14:09:02 -0600 | [diff] [blame] | 756 | const struct stream_in* in_stream = (const struct stream_in*)stream; |
| 757 | if (in_stream != NULL) { |
| 758 | dprintf(fd, "Input Profile:\n"); |
| 759 | profile_dump(in_stream->profile, fd); |
| 760 | |
| 761 | dprintf(fd, "Input Proxy:\n"); |
| 762 | proxy_dump(&in_stream->proxy, fd); |
| 763 | } |
| 764 | |
| 765 | return 0; |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | static int in_set_parameters(struct audio_stream *stream, const char *kvpairs) |
| 769 | { |
Paul McLean | 65ec72b | 2015-02-18 09:13:24 -0800 | [diff] [blame] | 770 | ALOGV("in_set_parameters() keys:%s", kvpairs); |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 771 | |
| 772 | struct stream_in *in = (struct stream_in *)stream; |
| 773 | |
| 774 | char value[32]; |
| 775 | int param_val; |
| 776 | int routing = 0; |
| 777 | int ret_value = 0; |
Eric Laurent | 05333d4 | 2014-08-04 20:29:17 -0700 | [diff] [blame] | 778 | int card = -1; |
| 779 | int device = -1; |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 780 | |
Paul McLean | 65ec72b | 2015-02-18 09:13:24 -0800 | [diff] [blame] | 781 | if (!parse_card_device_params(kvpairs, &card, &device)) { |
| 782 | // nothing to do |
| 783 | return ret_value; |
| 784 | } |
| 785 | |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 786 | stream_lock(&in->lock); |
| 787 | device_lock(in->adev); |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 788 | |
Paul McLean | 2c6196f | 2014-08-20 16:50:25 -0700 | [diff] [blame] | 789 | if (card >= 0 && device >= 0 && !profile_is_cached_for(in->profile, card, device)) { |
Eric Laurent | 05333d4 | 2014-08-04 20:29:17 -0700 | [diff] [blame] | 790 | /* cannot read pcm device info if playback is active */ |
| 791 | if (!in->standby) |
| 792 | ret_value = -ENOSYS; |
| 793 | else { |
| 794 | int saved_card = in->profile->card; |
| 795 | int saved_device = in->profile->device; |
| 796 | in->profile->card = card; |
| 797 | in->profile->device = device; |
| 798 | ret_value = profile_read_device_info(in->profile) ? 0 : -EINVAL; |
| 799 | if (ret_value != 0) { |
| 800 | in->profile->card = saved_card; |
| 801 | in->profile->device = saved_device; |
| 802 | } |
| 803 | } |
Paul McLean | 2c6196f | 2014-08-20 16:50:25 -0700 | [diff] [blame] | 804 | } |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 805 | |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 806 | device_unlock(in->adev); |
| 807 | stream_unlock(&in->lock); |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 808 | |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 809 | return ret_value; |
| 810 | } |
| 811 | |
| 812 | static char * in_get_parameters(const struct audio_stream *stream, const char *keys) |
| 813 | { |
| 814 | struct stream_in *in = (struct stream_in *)stream; |
| 815 | |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 816 | stream_lock(&in->lock); |
| 817 | device_lock(in->adev); |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 818 | |
| 819 | char * params_str = device_get_parameters(in->profile, keys); |
| 820 | |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 821 | device_unlock(in->adev); |
| 822 | stream_unlock(&in->lock); |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 823 | |
| 824 | return params_str; |
| 825 | } |
| 826 | |
| 827 | static int in_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect) |
| 828 | { |
| 829 | return 0; |
| 830 | } |
| 831 | |
| 832 | static int in_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect) |
| 833 | { |
| 834 | return 0; |
| 835 | } |
| 836 | |
| 837 | static int in_set_gain(struct audio_stream_in *stream, float gain) |
| 838 | { |
| 839 | return 0; |
| 840 | } |
| 841 | |
| 842 | /* must be called with hw device and output stream mutexes locked */ |
| 843 | static int start_input_stream(struct stream_in *in) |
| 844 | { |
Paul McLean | 1d585cc | 2016-05-24 11:28:10 -0600 | [diff] [blame] | 845 | ALOGV("start_input_stream(card:%d device:%d)", in->profile->card, in->profile->device); |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 846 | |
| 847 | return proxy_open(&in->proxy); |
| 848 | } |
| 849 | |
| 850 | /* TODO mutex stuff here (see out_write) */ |
| 851 | static ssize_t in_read(struct audio_stream_in *stream, void* buffer, size_t bytes) |
| 852 | { |
| 853 | size_t num_read_buff_bytes = 0; |
| 854 | void * read_buff = buffer; |
| 855 | void * out_buff = buffer; |
Pavan Chikkala | 83b47a6 | 2015-01-09 12:21:13 -0800 | [diff] [blame] | 856 | int ret = 0; |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 857 | |
| 858 | struct stream_in * in = (struct stream_in *)stream; |
| 859 | |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 860 | stream_lock(&in->lock); |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 861 | if (in->standby) { |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 862 | device_lock(in->adev); |
Eric Laurent | 7031809 | 2015-06-19 17:49:17 -0700 | [diff] [blame] | 863 | ret = start_input_stream(in); |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 864 | device_unlock(in->adev); |
Eric Laurent | 7031809 | 2015-06-19 17:49:17 -0700 | [diff] [blame] | 865 | if (ret != 0) { |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 866 | goto err; |
| 867 | } |
| 868 | in->standby = false; |
| 869 | } |
| 870 | |
| 871 | alsa_device_profile * profile = in->profile; |
| 872 | |
| 873 | /* |
| 874 | * OK, we need to figure out how much data to read to be able to output the requested |
| 875 | * number of bytes in the HAL format (16-bit, stereo). |
| 876 | */ |
| 877 | num_read_buff_bytes = bytes; |
Andy Hung | 780f1f8 | 2015-04-22 22:14:39 -0700 | [diff] [blame] | 878 | int num_device_channels = proxy_get_channel_count(&in->proxy); /* what we told Alsa */ |
| 879 | int num_req_channels = in->hal_channel_count; /* what we told AudioFlinger */ |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 880 | |
| 881 | if (num_device_channels != num_req_channels) { |
| 882 | num_read_buff_bytes = (num_device_channels * num_read_buff_bytes) / num_req_channels; |
| 883 | } |
| 884 | |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 885 | /* Setup/Realloc the conversion buffer (if necessary). */ |
| 886 | if (num_read_buff_bytes != bytes) { |
| 887 | if (num_read_buff_bytes > in->conversion_buffer_size) { |
| 888 | /*TODO Remove this when AudioPolicyManger/AudioFlinger support arbitrary formats |
| 889 | (and do these conversions themselves) */ |
| 890 | in->conversion_buffer_size = num_read_buff_bytes; |
| 891 | in->conversion_buffer = realloc(in->conversion_buffer, in->conversion_buffer_size); |
| 892 | } |
| 893 | read_buff = in->conversion_buffer; |
| 894 | } |
| 895 | |
Pavan Chikkala | 83b47a6 | 2015-01-09 12:21:13 -0800 | [diff] [blame] | 896 | ret = proxy_read(&in->proxy, read_buff, num_read_buff_bytes); |
| 897 | if (ret == 0) { |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 898 | if (num_device_channels != num_req_channels) { |
| 899 | // ALOGV("chans dev:%d req:%d", num_device_channels, num_req_channels); |
| 900 | |
| 901 | out_buff = buffer; |
| 902 | /* Num Channels conversion */ |
| 903 | if (num_device_channels != num_req_channels) { |
| 904 | audio_format_t audio_format = in_get_format(&(in->stream.common)); |
| 905 | unsigned sample_size_in_bytes = audio_bytes_per_sample(audio_format); |
| 906 | |
| 907 | num_read_buff_bytes = |
| 908 | adjust_channels(read_buff, num_device_channels, |
| 909 | out_buff, num_req_channels, |
| 910 | sample_size_in_bytes, num_read_buff_bytes); |
| 911 | } |
| 912 | } |
Eric Laurent | 253def9 | 2014-09-14 12:18:18 -0700 | [diff] [blame] | 913 | |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 914 | /* no need to acquire in->adev->lock to read mic_muted here as we don't change its state */ |
| 915 | if (num_read_buff_bytes > 0 && in->adev->mic_muted) |
Eric Laurent | 253def9 | 2014-09-14 12:18:18 -0700 | [diff] [blame] | 916 | memset(buffer, 0, num_read_buff_bytes); |
Viswanath L | 8c7e111 | 2014-10-31 13:07:39 +0530 | [diff] [blame] | 917 | } else { |
Eric Laurent | e649942 | 2015-01-09 17:03:27 -0800 | [diff] [blame] | 918 | num_read_buff_bytes = 0; // reset the value after USB headset is unplugged |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | err: |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 922 | stream_unlock(&in->lock); |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 923 | return num_read_buff_bytes; |
| 924 | } |
| 925 | |
| 926 | static uint32_t in_get_input_frames_lost(struct audio_stream_in *stream) |
| 927 | { |
| 928 | return 0; |
| 929 | } |
| 930 | |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 931 | static int adev_open_input_stream(struct audio_hw_device *hw_dev, |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 932 | audio_io_handle_t handle, |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 933 | audio_devices_t devicesSpec __unused, |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 934 | struct audio_config *config, |
| 935 | struct audio_stream_in **stream_in, |
Eric Laurent | f5e2469 | 2014-07-27 16:14:57 -0700 | [diff] [blame] | 936 | audio_input_flags_t flags __unused, |
Eric Laurent | 981f774 | 2017-05-03 12:44:26 -0700 | [diff] [blame] | 937 | const char *address, |
Eric Laurent | f5e2469 | 2014-07-27 16:14:57 -0700 | [diff] [blame] | 938 | audio_source_t source __unused) |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 939 | { |
Paul McLean | 1d585cc | 2016-05-24 11:28:10 -0600 | [diff] [blame] | 940 | ALOGV("adev_open_input_stream() rate:%" PRIu32 ", chanMask:0x%" PRIX32 ", fmt:%" PRIu8, |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 941 | config->sample_rate, config->channel_mask, config->format); |
| 942 | |
| 943 | struct stream_in *in = (struct stream_in *)calloc(1, sizeof(struct stream_in)); |
| 944 | int ret = 0; |
| 945 | |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 946 | if (in == NULL) { |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 947 | return -ENOMEM; |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 948 | } |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 949 | |
| 950 | /* setup function pointers */ |
| 951 | in->stream.common.get_sample_rate = in_get_sample_rate; |
| 952 | in->stream.common.set_sample_rate = in_set_sample_rate; |
| 953 | in->stream.common.get_buffer_size = in_get_buffer_size; |
| 954 | in->stream.common.get_channels = in_get_channels; |
| 955 | in->stream.common.get_format = in_get_format; |
| 956 | in->stream.common.set_format = in_set_format; |
| 957 | in->stream.common.standby = in_standby; |
| 958 | in->stream.common.dump = in_dump; |
| 959 | in->stream.common.set_parameters = in_set_parameters; |
| 960 | in->stream.common.get_parameters = in_get_parameters; |
| 961 | in->stream.common.add_audio_effect = in_add_audio_effect; |
| 962 | in->stream.common.remove_audio_effect = in_remove_audio_effect; |
| 963 | |
| 964 | in->stream.set_gain = in_set_gain; |
| 965 | in->stream.read = in_read; |
| 966 | in->stream.get_input_frames_lost = in_get_input_frames_lost; |
| 967 | |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 968 | stream_lock_init(&in->lock); |
Eric Laurent | 7031809 | 2015-06-19 17:49:17 -0700 | [diff] [blame] | 969 | |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 970 | in->adev = (struct audio_device *)hw_dev; |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 971 | device_lock(in->adev); |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 972 | |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 973 | in->profile = &in->adev->in_profile; |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 974 | |
| 975 | struct pcm_config proxy_config; |
Paul McLean | 2c6196f | 2014-08-20 16:50:25 -0700 | [diff] [blame] | 976 | memset(&proxy_config, 0, sizeof(proxy_config)); |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 977 | |
Paul McLean | 0f1753e | 2014-12-02 12:36:45 -0700 | [diff] [blame] | 978 | /* Pull out the card/device pair */ |
| 979 | parse_card_device_params(address, &(in->profile->card), &(in->profile->device)); |
| 980 | |
| 981 | profile_read_device_info(in->profile); |
Paul McLean | 0f1753e | 2014-12-02 12:36:45 -0700 | [diff] [blame] | 982 | |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 983 | /* Rate */ |
| 984 | if (config->sample_rate == 0) { |
Paul McLean | 9a1c305 | 2016-05-25 13:30:54 -0600 | [diff] [blame] | 985 | config->sample_rate = profile_get_default_sample_rate(in->profile); |
| 986 | } |
| 987 | |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 988 | if (in->adev->device_sample_rate != 0 && /* we are playing, so lock the rate */ |
| 989 | in->adev->device_sample_rate >= RATELOCK_THRESHOLD) {/* but only for high sample rates */ |
| 990 | ret = config->sample_rate != in->adev->device_sample_rate ? -EINVAL : 0; |
| 991 | proxy_config.rate = config->sample_rate = in->adev->device_sample_rate; |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 992 | } else if (profile_is_sample_rate_valid(in->profile, config->sample_rate)) { |
Eric Laurent | 981f774 | 2017-05-03 12:44:26 -0700 | [diff] [blame] | 993 | proxy_config.rate = config->sample_rate; |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 994 | } else { |
| 995 | proxy_config.rate = config->sample_rate = profile_get_default_sample_rate(in->profile); |
| 996 | ret = -EINVAL; |
| 997 | } |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 998 | device_unlock(in->adev); |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 999 | |
| 1000 | /* Format */ |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 1001 | if (config->format == AUDIO_FORMAT_DEFAULT) { |
Andy Hung | 780f1f8 | 2015-04-22 22:14:39 -0700 | [diff] [blame] | 1002 | proxy_config.format = profile_get_default_format(in->profile); |
| 1003 | config->format = audio_format_from_pcm_format(proxy_config.format); |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 1004 | } else { |
Andy Hung | 780f1f8 | 2015-04-22 22:14:39 -0700 | [diff] [blame] | 1005 | enum pcm_format fmt = pcm_format_from_audio_format(config->format); |
| 1006 | if (profile_is_format_valid(in->profile, fmt)) { |
| 1007 | proxy_config.format = fmt; |
| 1008 | } else { |
| 1009 | proxy_config.format = profile_get_default_format(in->profile); |
| 1010 | config->format = audio_format_from_pcm_format(proxy_config.format); |
| 1011 | ret = -EINVAL; |
| 1012 | } |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 1013 | } |
| 1014 | |
Paul McLean | 2cfd81b | 2014-09-15 12:32:23 -0700 | [diff] [blame] | 1015 | /* Channels */ |
Paul McLean | 64345f8 | 2016-06-06 13:26:05 -0600 | [diff] [blame] | 1016 | bool calc_mask = false; |
| 1017 | if (config->channel_mask == AUDIO_CHANNEL_NONE) { |
| 1018 | /* query case */ |
| 1019 | in->hal_channel_count = profile_get_default_channel_count(in->profile); |
| 1020 | calc_mask = true; |
Andy Hung | 780f1f8 | 2015-04-22 22:14:39 -0700 | [diff] [blame] | 1021 | } else { |
Paul McLean | 64345f8 | 2016-06-06 13:26:05 -0600 | [diff] [blame] | 1022 | /* explicit case */ |
Andy Hung | 780f1f8 | 2015-04-22 22:14:39 -0700 | [diff] [blame] | 1023 | in->hal_channel_count = audio_channel_count_from_in_mask(config->channel_mask); |
| 1024 | } |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 1025 | |
Paul McLean | 64345f8 | 2016-06-06 13:26:05 -0600 | [diff] [blame] | 1026 | /* The Framework is currently limited to no more than this number of channels */ |
| 1027 | if (in->hal_channel_count > FCC_8) { |
| 1028 | in->hal_channel_count = FCC_8; |
| 1029 | calc_mask = true; |
| 1030 | } |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 1031 | |
Paul McLean | 64345f8 | 2016-06-06 13:26:05 -0600 | [diff] [blame] | 1032 | if (calc_mask) { |
| 1033 | /* need to calculate the mask from channel count either because this is the query case |
| 1034 | * or the specified mask isn't valid for this device, or is more then the FW can handle */ |
| 1035 | in->hal_channel_mask = in->hal_channel_count <= FCC_2 |
| 1036 | /* position mask for mono & stereo */ |
| 1037 | ? audio_channel_in_mask_from_count(in->hal_channel_count) |
| 1038 | /* otherwise indexed */ |
| 1039 | : audio_channel_mask_for_index_assignment_from_count(in->hal_channel_count); |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 1040 | |
Paul McLean | 64345f8 | 2016-06-06 13:26:05 -0600 | [diff] [blame] | 1041 | // if we change the mask... |
| 1042 | if (in->hal_channel_mask != config->channel_mask && |
| 1043 | config->channel_mask != AUDIO_CHANNEL_NONE) { |
| 1044 | config->channel_mask = in->hal_channel_mask; |
| 1045 | ret = -EINVAL; |
| 1046 | } |
| 1047 | } else { |
| 1048 | in->hal_channel_mask = config->channel_mask; |
| 1049 | } |
Paul McLean | 6a75e4e | 2016-05-25 14:09:02 -0600 | [diff] [blame] | 1050 | |
Paul McLean | 64345f8 | 2016-06-06 13:26:05 -0600 | [diff] [blame] | 1051 | if (ret == 0) { |
| 1052 | // Validate the "logical" channel count against support in the "actual" profile. |
| 1053 | // if they differ, choose the "actual" number of channels *closest* to the "logical". |
| 1054 | // and store THAT in proxy_config.channels |
| 1055 | proxy_config.channels = |
| 1056 | profile_get_closest_channel_count(in->profile, in->hal_channel_count); |
Eric Laurent | 981f774 | 2017-05-03 12:44:26 -0700 | [diff] [blame] | 1057 | ret = proxy_prepare(&in->proxy, in->profile, &proxy_config); |
| 1058 | if (ret == 0) { |
| 1059 | in->standby = true; |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 1060 | |
Eric Laurent | 981f774 | 2017-05-03 12:44:26 -0700 | [diff] [blame] | 1061 | in->conversion_buffer = NULL; |
| 1062 | in->conversion_buffer_size = 0; |
Paul McLean | 64345f8 | 2016-06-06 13:26:05 -0600 | [diff] [blame] | 1063 | |
Eric Laurent | 981f774 | 2017-05-03 12:44:26 -0700 | [diff] [blame] | 1064 | *stream_in = &in->stream; |
Paul McLean | 64345f8 | 2016-06-06 13:26:05 -0600 | [diff] [blame] | 1065 | |
Eric Laurent | 981f774 | 2017-05-03 12:44:26 -0700 | [diff] [blame] | 1066 | /* Save this for adev_dump() */ |
| 1067 | adev_add_stream_to_list(in->adev, &in->adev->input_stream_list, &in->list_node); |
| 1068 | } else { |
| 1069 | ALOGW("proxy_prepare error %d", ret); |
| 1070 | unsigned channel_count = proxy_get_channel_count(&in->proxy); |
| 1071 | config->channel_mask = channel_count <= FCC_2 |
| 1072 | ? audio_channel_in_mask_from_count(channel_count) |
| 1073 | : audio_channel_mask_for_index_assignment_from_count(channel_count); |
| 1074 | config->format = audio_format_from_pcm_format(proxy_get_format(&in->proxy)); |
| 1075 | config->sample_rate = proxy_get_sample_rate(&in->proxy); |
| 1076 | } |
| 1077 | } |
Paul McLean | 64345f8 | 2016-06-06 13:26:05 -0600 | [diff] [blame] | 1078 | |
Eric Laurent | 981f774 | 2017-05-03 12:44:26 -0700 | [diff] [blame] | 1079 | if (ret != 0) { |
Paul McLean | 64345f8 | 2016-06-06 13:26:05 -0600 | [diff] [blame] | 1080 | // Deallocate this stream on error, because AudioFlinger won't call |
| 1081 | // adev_close_input_stream() in this case. |
| 1082 | *stream_in = NULL; |
| 1083 | free(in); |
| 1084 | } |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 1085 | |
| 1086 | return ret; |
| 1087 | } |
| 1088 | |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 1089 | static void adev_close_input_stream(struct audio_hw_device *hw_dev, |
| 1090 | struct audio_stream_in *stream) |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 1091 | { |
| 1092 | struct stream_in *in = (struct stream_in *)stream; |
Paul McLean | 6a75e4e | 2016-05-25 14:09:02 -0600 | [diff] [blame] | 1093 | ALOGV("adev_close_input_stream(c:%d d:%d)", in->profile->card, in->profile->device); |
| 1094 | |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 1095 | adev_remove_stream_from_list(in->adev, &in->list_node); |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 1096 | |
| 1097 | /* Close the pcm device */ |
| 1098 | in_standby(&stream->common); |
| 1099 | |
| 1100 | free(in->conversion_buffer); |
| 1101 | |
| 1102 | free(stream); |
| 1103 | } |
| 1104 | |
| 1105 | /* |
| 1106 | * ADEV Functions |
| 1107 | */ |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 1108 | static int adev_set_parameters(struct audio_hw_device *hw_dev, const char *kvpairs) |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1109 | { |
| 1110 | return 0; |
| 1111 | } |
| 1112 | |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 1113 | static char * adev_get_parameters(const struct audio_hw_device *hw_dev, const char *keys) |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1114 | { |
| 1115 | return strdup(""); |
| 1116 | } |
| 1117 | |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 1118 | static int adev_init_check(const struct audio_hw_device *hw_dev) |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1119 | { |
| 1120 | return 0; |
| 1121 | } |
| 1122 | |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 1123 | static int adev_set_voice_volume(struct audio_hw_device *hw_dev, float volume) |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1124 | { |
| 1125 | return -ENOSYS; |
| 1126 | } |
| 1127 | |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 1128 | static int adev_set_master_volume(struct audio_hw_device *hw_dev, float volume) |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1129 | { |
| 1130 | return -ENOSYS; |
| 1131 | } |
| 1132 | |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 1133 | static int adev_set_mode(struct audio_hw_device *hw_dev, audio_mode_t mode) |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1134 | { |
| 1135 | return 0; |
| 1136 | } |
| 1137 | |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 1138 | static int adev_set_mic_mute(struct audio_hw_device *hw_dev, bool state) |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1139 | { |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 1140 | struct audio_device * adev = (struct audio_device *)hw_dev; |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 1141 | device_lock(adev); |
Eric Laurent | 253def9 | 2014-09-14 12:18:18 -0700 | [diff] [blame] | 1142 | adev->mic_muted = state; |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 1143 | device_unlock(adev); |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1144 | return -ENOSYS; |
| 1145 | } |
| 1146 | |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 1147 | static int adev_get_mic_mute(const struct audio_hw_device *hw_dev, bool *state) |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1148 | { |
| 1149 | return -ENOSYS; |
| 1150 | } |
| 1151 | |
Paul McLean | 76dba68 | 2016-06-01 12:29:11 -0600 | [diff] [blame] | 1152 | static int adev_dump(const struct audio_hw_device *device, int fd) |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1153 | { |
Paul McLean | 6a75e4e | 2016-05-25 14:09:02 -0600 | [diff] [blame] | 1154 | dprintf(fd, "\nUSB audio module:\n"); |
| 1155 | |
| 1156 | struct audio_device* adev = (struct audio_device*)device; |
| 1157 | const int kNumRetries = 3; |
| 1158 | const int kSleepTimeMS = 500; |
| 1159 | |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 1160 | // use device_try_lock() in case we dumpsys during a deadlock |
Paul McLean | 6a75e4e | 2016-05-25 14:09:02 -0600 | [diff] [blame] | 1161 | int retry = kNumRetries; |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 1162 | while (retry > 0 && device_try_lock(adev) != 0) { |
Paul McLean | 6a75e4e | 2016-05-25 14:09:02 -0600 | [diff] [blame] | 1163 | sleep(kSleepTimeMS); |
| 1164 | retry--; |
| 1165 | } |
| 1166 | |
| 1167 | if (retry > 0) { |
| 1168 | if (list_empty(&adev->output_stream_list)) { |
| 1169 | dprintf(fd, " No output streams.\n"); |
| 1170 | } else { |
| 1171 | struct listnode* node; |
| 1172 | list_for_each(node, &adev->output_stream_list) { |
| 1173 | struct audio_stream* stream = |
| 1174 | (struct audio_stream *)node_to_item(node, struct stream_out, list_node); |
| 1175 | out_dump(stream, fd); |
| 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | if (list_empty(&adev->input_stream_list)) { |
| 1180 | dprintf(fd, "\n No input streams.\n"); |
| 1181 | } else { |
| 1182 | struct listnode* node; |
| 1183 | list_for_each(node, &adev->input_stream_list) { |
| 1184 | struct audio_stream* stream = |
| 1185 | (struct audio_stream *)node_to_item(node, struct stream_in, list_node); |
| 1186 | in_dump(stream, fd); |
| 1187 | } |
| 1188 | } |
| 1189 | |
Paul McLean | 994ac07 | 2016-06-02 15:33:24 -0600 | [diff] [blame] | 1190 | device_unlock(adev); |
Paul McLean | 6a75e4e | 2016-05-25 14:09:02 -0600 | [diff] [blame] | 1191 | } else { |
| 1192 | // Couldn't lock |
| 1193 | dprintf(fd, " Could not obtain device lock.\n"); |
| 1194 | } |
| 1195 | |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1196 | return 0; |
| 1197 | } |
| 1198 | |
| 1199 | static int adev_close(hw_device_t *device) |
| 1200 | { |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 1201 | struct audio_device *adev = (struct audio_device *)device; |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1202 | free(device); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 1203 | |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1204 | return 0; |
| 1205 | } |
| 1206 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1207 | static int adev_open(const hw_module_t* module, const char* name, hw_device_t** device) |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1208 | { |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1209 | if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) |
| 1210 | return -EINVAL; |
| 1211 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 1212 | struct audio_device *adev = calloc(1, sizeof(struct audio_device)); |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1213 | if (!adev) |
| 1214 | return -ENOMEM; |
| 1215 | |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 1216 | profile_init(&adev->out_profile, PCM_OUT); |
| 1217 | profile_init(&adev->in_profile, PCM_IN); |
| 1218 | |
Paul McLean | 6a75e4e | 2016-05-25 14:09:02 -0600 | [diff] [blame] | 1219 | list_init(&adev->output_stream_list); |
| 1220 | list_init(&adev->input_stream_list); |
| 1221 | |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1222 | adev->hw_device.common.tag = HARDWARE_DEVICE_TAG; |
Eric Laurent | 85e08e2 | 2012-08-28 14:30:35 -0700 | [diff] [blame] | 1223 | adev->hw_device.common.version = AUDIO_DEVICE_API_VERSION_2_0; |
Paul McLean | c88e6ae | 2014-07-16 09:48:34 -0700 | [diff] [blame] | 1224 | adev->hw_device.common.module = (struct hw_module_t *)module; |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1225 | adev->hw_device.common.close = adev_close; |
| 1226 | |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1227 | adev->hw_device.init_check = adev_init_check; |
| 1228 | adev->hw_device.set_voice_volume = adev_set_voice_volume; |
| 1229 | adev->hw_device.set_master_volume = adev_set_master_volume; |
| 1230 | adev->hw_device.set_mode = adev_set_mode; |
| 1231 | adev->hw_device.set_mic_mute = adev_set_mic_mute; |
| 1232 | adev->hw_device.get_mic_mute = adev_get_mic_mute; |
| 1233 | adev->hw_device.set_parameters = adev_set_parameters; |
| 1234 | adev->hw_device.get_parameters = adev_get_parameters; |
| 1235 | adev->hw_device.get_input_buffer_size = adev_get_input_buffer_size; |
| 1236 | adev->hw_device.open_output_stream = adev_open_output_stream; |
| 1237 | adev->hw_device.close_output_stream = adev_close_output_stream; |
| 1238 | adev->hw_device.open_input_stream = adev_open_input_stream; |
| 1239 | adev->hw_device.close_input_stream = adev_close_input_stream; |
| 1240 | adev->hw_device.dump = adev_dump; |
| 1241 | |
| 1242 | *device = &adev->hw_device.common; |
| 1243 | |
| 1244 | return 0; |
| 1245 | } |
| 1246 | |
| 1247 | static struct hw_module_methods_t hal_module_methods = { |
| 1248 | .open = adev_open, |
| 1249 | }; |
| 1250 | |
| 1251 | struct audio_module HAL_MODULE_INFO_SYM = { |
| 1252 | .common = { |
| 1253 | .tag = HARDWARE_MODULE_TAG, |
Mike Lockwood | 46a9809 | 2012-04-24 16:41:18 -0700 | [diff] [blame] | 1254 | .module_api_version = AUDIO_MODULE_API_VERSION_0_1, |
| 1255 | .hal_api_version = HARDWARE_HAL_API_VERSION, |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1256 | .id = AUDIO_HARDWARE_MODULE_ID, |
| 1257 | .name = "USB audio HW HAL", |
| 1258 | .author = "The Android Open Source Project", |
| 1259 | .methods = &hal_module_methods, |
| 1260 | }, |
| 1261 | }; |