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