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