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