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 | |
| 17 | #define LOG_TAG "usb_audio_hw" |
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 | |
| 31 | #include <hardware/hardware.h> |
| 32 | #include <system/audio.h> |
| 33 | #include <hardware/audio.h> |
| 34 | |
| 35 | #include <tinyalsa/asoundlib.h> |
| 36 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 37 | /* This is the default configuration to hand to The Framework on the initial |
| 38 | * adev_open_output_stream(). Actual device attributes will be used on the subsequent |
| 39 | * adev_open_output_stream() after the card and device number have been set in out_set_parameters() |
| 40 | */ |
| 41 | #define OUT_PERIOD_SIZE 1024 |
| 42 | #define OUT_PERIOD_COUNT 4 |
| 43 | #define OUT_SAMPLING_RATE 44100 |
| 44 | |
| 45 | struct pcm_config default_alsa_out_config = { |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 46 | .channels = 2, |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 47 | .rate = OUT_SAMPLING_RATE, |
| 48 | .period_size = OUT_PERIOD_SIZE, |
| 49 | .period_count = OUT_PERIOD_COUNT, |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 50 | .format = PCM_FORMAT_S16_LE, |
| 51 | }; |
| 52 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 53 | /* |
| 54 | * Input defaults. See comment above. |
| 55 | */ |
| 56 | #define IN_PERIOD_SIZE 1024 |
| 57 | #define IN_PERIOD_COUNT 4 |
| 58 | #define IN_SAMPLING_RATE 44100 |
| 59 | |
| 60 | struct pcm_config default_alsa_in_config = { |
| 61 | .channels = 2, |
| 62 | .rate = IN_SAMPLING_RATE, |
| 63 | .period_size = IN_PERIOD_SIZE, |
| 64 | .period_count = IN_PERIOD_COUNT, |
| 65 | .format = PCM_FORMAT_S16_LE, |
| 66 | .start_threshold = 1, |
| 67 | .stop_threshold = (IN_PERIOD_SIZE * IN_PERIOD_COUNT), |
| 68 | }; |
| 69 | |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 70 | struct audio_device { |
| 71 | struct audio_hw_device hw_device; |
| 72 | |
| 73 | pthread_mutex_t lock; /* see note below on mutex acquisition order */ |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 74 | |
| 75 | /* output */ |
| 76 | int out_card; |
| 77 | int out_device; |
| 78 | |
| 79 | /* input */ |
| 80 | int in_card; |
| 81 | int in_device; |
| 82 | |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 83 | bool standby; |
| 84 | }; |
| 85 | |
| 86 | struct stream_out { |
| 87 | struct audio_stream_out stream; |
| 88 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 89 | pthread_mutex_t lock; /* see note below on mutex acquisition order */ |
| 90 | struct pcm *pcm; /* state of the stream */ |
| 91 | bool standby; |
| 92 | |
| 93 | struct audio_device *dev; /* hardware information */ |
| 94 | |
| 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 | |
| 101 | /* |
| 102 | * Output Configuration Cache |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 103 | * FIXME(pmclean) This is not reentrant. Should probably be moved into the stream structure |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 104 | * but that will involve changes in The Framework. |
| 105 | */ |
| 106 | static struct pcm_config cached_output_hardware_config; |
| 107 | static bool output_hardware_config_is_cached = false; |
| 108 | |
| 109 | struct stream_in { |
| 110 | struct audio_stream_in stream; |
| 111 | |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 112 | pthread_mutex_t lock; /* see note below on mutex acquisition order */ |
| 113 | struct pcm *pcm; |
| 114 | bool standby; |
| 115 | |
| 116 | struct audio_device *dev; |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 117 | |
| 118 | struct audio_config hal_pcm_config; |
| 119 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 120 | // struct resampler_itfe *resampler; |
| 121 | // struct resampler_buffer_provider buf_provider; |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 122 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 123 | int read_status; |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 124 | |
| 125 | // We may need to read more data from the device in order to data reduce to 16bit, 4chan */ |
| 126 | void * conversion_buffer; /* any conversions are put into here |
| 127 | * they could come from here too if |
| 128 | * there was a previous conversion */ |
| 129 | size_t conversion_buffer_size; /* in bytes */ |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 130 | }; |
| 131 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 132 | /* |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 133 | * Input Configuration Cache |
| 134 | * FIXME(pmclean) This is not reentrant. Should probably be moved into the stream structure |
| 135 | * but that will involve changes in The Framework. |
| 136 | */ |
| 137 | static struct pcm_config cached_input_hardware_config; |
| 138 | static bool input_hardware_config_is_cached = false; |
| 139 | |
| 140 | /* |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 141 | * Utility |
| 142 | */ |
| 143 | /* |
| 144 | * Translates from ALSA format ID to ANDROID_AUDIO_CORE format ID |
| 145 | * (see master/system/core/include/core/audio.h) |
| 146 | * TODO(pmclean) Replace with audio_format_from_pcm_format() (in hardware/audio_alsaops.h). |
| 147 | * post-integration. |
| 148 | */ |
| 149 | static audio_format_t alsa_to_fw_format_id(int alsa_fmt_id) |
| 150 | { |
| 151 | switch (alsa_fmt_id) { |
| 152 | case PCM_FORMAT_S8: |
| 153 | return AUDIO_FORMAT_PCM_8_BIT; |
| 154 | |
| 155 | case PCM_FORMAT_S24_3LE: |
| 156 | //TODO(pmclean) make sure this is the 'right' sort of 24-bit |
| 157 | return AUDIO_FORMAT_PCM_8_24_BIT; |
| 158 | |
| 159 | case PCM_FORMAT_S32_LE: |
| 160 | case PCM_FORMAT_S24_LE: |
| 161 | return AUDIO_FORMAT_PCM_32_BIT; |
| 162 | } |
| 163 | |
| 164 | return AUDIO_FORMAT_PCM_16_BIT; |
| 165 | } |
| 166 | |
| 167 | /* |
| 168 | * Data Conversions |
| 169 | */ |
| 170 | /* |
| 171 | * Convert a buffer of PCM16LE samples to packed (3-byte) PCM24LE samples. |
| 172 | * in_buff points to the buffer of PCM16 samples |
| 173 | * num_in_samples size of input buffer in SAMPLES |
| 174 | * out_buff points to the buffer to receive converted PCM24 LE samples. |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 175 | * returns |
| 176 | * the number of BYTES of output data. |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 177 | * We are doing this since we *always* present to The Framework as A PCM16LE device, but need to |
| 178 | * support PCM24_3LE (24-bit, packed). |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 179 | * NOTE: |
| 180 | * We're just filling the low-order byte of the PCM24LE samples with 0. |
| 181 | * This conversion is safe to do in-place (in_buff == out_buff). |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 182 | * TODO(pmclean, hung) Move this to a utilities module. |
| 183 | */ |
Mark Salyzyn | 88e458a | 2014-04-28 12:30:44 -0700 | [diff] [blame] | 184 | static size_t convert_16_to_24_3(const short * in_buff, size_t num_in_samples, unsigned char * out_buff) { |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 185 | /* |
| 186 | * Move from back to front so that the conversion can be done in-place |
| 187 | * i.e. in_buff == out_buff |
| 188 | */ |
| 189 | int in_buff_size_in_bytes = num_in_samples * 2; |
| 190 | /* we need 3 bytes in the output for every 2 bytes in the input */ |
| 191 | int out_buff_size_in_bytes = ((3 * in_buff_size_in_bytes) / 2); |
| 192 | unsigned char* dst_ptr = out_buff + out_buff_size_in_bytes - 1; |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 193 | size_t src_smpl_index; |
Mark Salyzyn | 88e458a | 2014-04-28 12:30:44 -0700 | [diff] [blame] | 194 | const unsigned char* src_ptr = ((const unsigned char *)in_buff) + in_buff_size_in_bytes - 1; |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 195 | for (src_smpl_index = 0; src_smpl_index < num_in_samples; src_smpl_index++) { |
| 196 | *dst_ptr-- = *src_ptr--; /* hi-byte */ |
| 197 | *dst_ptr-- = *src_ptr--; /* low-byte */ |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 198 | /*TODO(pmclean) - we might want to consider dithering the lowest byte. */ |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 199 | *dst_ptr-- = 0; /* zero-byte */ |
| 200 | } |
| 201 | |
| 202 | /* return number of *bytes* generated */ |
| 203 | return out_buff_size_in_bytes; |
| 204 | } |
| 205 | |
| 206 | /* |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 207 | * Convert a buffer of packed (3-byte) PCM24LE samples to PCM16LE samples. |
| 208 | * in_buff points to the buffer of PCM24LE samples |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 209 | * num_in_samples size of input buffer in SAMPLES |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 210 | * out_buff points to the buffer to receive converted PCM16LE LE samples. |
| 211 | * returns |
| 212 | * the number of BYTES of output data. |
| 213 | * We are doing this since we *always* present to The Framework as A PCM16LE device, but need to |
| 214 | * support PCM24_3LE (24-bit, packed). |
| 215 | * NOTE: |
| 216 | * We're just filling the low-order byte of the PCM24LE samples with 0. |
| 217 | * This conversion is safe to do in-place (in_buff == out_buff). |
| 218 | * TODO(pmclean, hung) Move this to a utilities module. |
| 219 | */ |
Mark Salyzyn | 88e458a | 2014-04-28 12:30:44 -0700 | [diff] [blame] | 220 | static size_t convert_24_3_to_16(const unsigned char * in_buff, size_t num_in_samples, short * out_buff) { |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 221 | /* |
| 222 | * Move from front to back so that the conversion can be done in-place |
| 223 | * i.e. in_buff == out_buff |
| 224 | */ |
| 225 | /* we need 2 bytes in the output for every 3 bytes in the input */ |
| 226 | unsigned char* dst_ptr = (unsigned char*)out_buff; |
Mark Salyzyn | 88e458a | 2014-04-28 12:30:44 -0700 | [diff] [blame] | 227 | const unsigned char* src_ptr = in_buff; |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 228 | size_t src_smpl_index; |
| 229 | for (src_smpl_index = 0; src_smpl_index < num_in_samples; src_smpl_index++) { |
| 230 | src_ptr++; /* lowest-(skip)-byte */ |
| 231 | *dst_ptr++ = *src_ptr++; /* low-byte */ |
| 232 | *dst_ptr++ = *src_ptr++; /* high-byte */ |
| 233 | } |
| 234 | |
| 235 | /* return number of *bytes* generated: */ |
| 236 | return num_in_samples * 2; |
| 237 | } |
| 238 | |
| 239 | /* |
| 240 | * Convert a buffer of N-channel, interleaved PCM16 samples to M-channel PCM16 channels |
| 241 | * (where N < M). |
| 242 | * in_buff points to the buffer of PCM16 samples |
| 243 | * in_buff_channels Specifies the number of channels in the input buffer. |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 244 | * out_buff points to the buffer to receive converted PCM16 samples. |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 245 | * out_buff_channels Specifies the number of channels in the output buffer. |
| 246 | * num_in_samples size of input buffer in SAMPLES |
| 247 | * returns |
| 248 | * the number of BYTES of output data. |
| 249 | * NOTE |
| 250 | * channels > N are filled with silence. |
| 251 | * This conversion is safe to do in-place (in_buff == out_buff) |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 252 | * We are doing this since we *always* present to The Framework as STEREO device, but need to |
| 253 | * support 4-channel devices. |
| 254 | * TODO(pmclean, hung) Move this to a utilities module. |
| 255 | */ |
Mark Salyzyn | 88e458a | 2014-04-28 12:30:44 -0700 | [diff] [blame] | 256 | static size_t expand_channels_16(const short* in_buff, int in_buff_chans, |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 257 | short* out_buff, int out_buff_chans, |
| 258 | size_t num_in_samples) { |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 259 | /* |
| 260 | * Move from back to front so that the conversion can be done in-place |
| 261 | * i.e. in_buff == out_buff |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 262 | * NOTE: num_in_samples * out_buff_channels must be an even multiple of in_buff_chans |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 263 | */ |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 264 | int num_out_samples = (num_in_samples * out_buff_chans)/in_buff_chans; |
| 265 | |
| 266 | short* dst_ptr = out_buff + num_out_samples - 1; |
Mark Salyzyn | 88e458a | 2014-04-28 12:30:44 -0700 | [diff] [blame] | 267 | size_t src_index; |
| 268 | const short* src_ptr = in_buff + num_in_samples - 1; |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 269 | int num_zero_chans = out_buff_chans - in_buff_chans; |
| 270 | for (src_index = 0; src_index < num_in_samples; src_index += in_buff_chans) { |
| 271 | int dst_offset; |
| 272 | for(dst_offset = 0; dst_offset < num_zero_chans; dst_offset++) { |
| 273 | *dst_ptr-- = 0; |
| 274 | } |
| 275 | for(; dst_offset < out_buff_chans; dst_offset++) { |
| 276 | *dst_ptr-- = *src_ptr--; |
| 277 | } |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | /* return number of *bytes* generated */ |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 281 | return num_out_samples * sizeof(short); |
| 282 | } |
| 283 | |
| 284 | /* |
| 285 | * Convert a buffer of N-channel, interleaved PCM16 samples to M-channel PCM16 channels |
| 286 | * (where N > M). |
| 287 | * in_buff points to the buffer of PCM16 samples |
| 288 | * in_buff_channels Specifies the number of channels in the input buffer. |
| 289 | * out_buff points to the buffer to receive converted PCM16 samples. |
| 290 | * out_buff_channels Specifies the number of channels in the output buffer. |
| 291 | * num_in_samples size of input buffer in SAMPLES |
| 292 | * returns |
| 293 | * the number of BYTES of output data. |
| 294 | * NOTE |
| 295 | * channels > N are thrown away. |
| 296 | * This conversion is safe to do in-place (in_buff == out_buff) |
| 297 | * We are doing this since we *always* present to The Framework as STEREO device, but need to |
| 298 | * support 4-channel devices. |
| 299 | * TODO(pmclean, hung) Move this to a utilities module. |
| 300 | */ |
| 301 | static size_t contract_channels_16(short* in_buff, int in_buff_chans, |
| 302 | short* out_buff, int out_buff_chans, |
| 303 | size_t num_in_samples) { |
| 304 | /* |
| 305 | * Move from front to back so that the conversion can be done in-place |
| 306 | * i.e. in_buff == out_buff |
| 307 | * NOTE: num_in_samples * out_buff_channels must be an even multiple of in_buff_chans |
| 308 | */ |
| 309 | int num_out_samples = (num_in_samples * out_buff_chans)/in_buff_chans; |
| 310 | |
| 311 | int num_skip_samples = in_buff_chans - out_buff_chans; |
| 312 | |
| 313 | short* dst_ptr = out_buff; |
| 314 | short* src_ptr = in_buff; |
Mark Salyzyn | 88e458a | 2014-04-28 12:30:44 -0700 | [diff] [blame] | 315 | size_t src_index; |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 316 | for (src_index = 0; src_index < num_in_samples; src_index += in_buff_chans) { |
| 317 | int dst_offset; |
| 318 | for(dst_offset = 0; dst_offset < out_buff_chans; dst_offset++) { |
| 319 | *dst_ptr++ = *src_ptr++; |
| 320 | } |
| 321 | src_ptr += num_skip_samples; |
| 322 | } |
| 323 | |
| 324 | /* return number of *bytes* generated */ |
| 325 | return num_out_samples * sizeof(short); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | /* |
| 329 | * ALSA Utilities |
| 330 | */ |
| 331 | /* |
| 332 | * gets the ALSA bit-format flag from a bits-per-sample value. |
| 333 | * TODO(pmclean, hung) Move this to a utilities module. |
| 334 | */ |
Mark Salyzyn | 88e458a | 2014-04-28 12:30:44 -0700 | [diff] [blame] | 335 | static int bits_to_alsa_format(unsigned int bits_per_sample, int default_format) |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 336 | { |
| 337 | enum pcm_format format; |
| 338 | for (format = PCM_FORMAT_S16_LE; format < PCM_FORMAT_MAX; format++) { |
| 339 | if (pcm_format_to_bits(format) == bits_per_sample) { |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 340 | return format; |
| 341 | } |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 342 | } |
| 343 | return default_format; |
| 344 | } |
| 345 | |
Paul McLean | cf61191 | 2014-04-28 13:03:18 -0700 | [diff] [blame] | 346 | static void log_pcm_params(struct pcm_params * alsa_hw_params) { |
| 347 | ALOGV("usb:audio_hw - PCM_PARAM_SAMPLE_BITS min:%u, max:%u", |
| 348 | pcm_params_get_min(alsa_hw_params, PCM_PARAM_SAMPLE_BITS), |
| 349 | pcm_params_get_max(alsa_hw_params, PCM_PARAM_SAMPLE_BITS)); |
| 350 | ALOGV("usb:audio_hw - PCM_PARAM_FRAME_BITS min:%u, max:%u", |
| 351 | pcm_params_get_min(alsa_hw_params, PCM_PARAM_FRAME_BITS), |
| 352 | pcm_params_get_max(alsa_hw_params, PCM_PARAM_FRAME_BITS)); |
| 353 | ALOGV("usb:audio_hw - PCM_PARAM_CHANNELS min:%u, max:%u", |
| 354 | pcm_params_get_min(alsa_hw_params, PCM_PARAM_CHANNELS), |
| 355 | pcm_params_get_max(alsa_hw_params, PCM_PARAM_CHANNELS)); |
| 356 | ALOGV("usb:audio_hw - PCM_PARAM_RATE min:%u, max:%u", |
| 357 | pcm_params_get_min(alsa_hw_params, PCM_PARAM_RATE), |
| 358 | pcm_params_get_max(alsa_hw_params, PCM_PARAM_RATE)); |
| 359 | ALOGV("usb:audio_hw - PCM_PARAM_PERIOD_TIME min:%u, max:%u", |
| 360 | pcm_params_get_min(alsa_hw_params, PCM_PARAM_PERIOD_TIME), |
| 361 | pcm_params_get_max(alsa_hw_params, PCM_PARAM_PERIOD_TIME)); |
| 362 | ALOGV("usb:audio_hw - PCM_PARAM_PERIOD_SIZE min:%u, max:%u", |
| 363 | pcm_params_get_min(alsa_hw_params, PCM_PARAM_PERIOD_SIZE), |
| 364 | pcm_params_get_max(alsa_hw_params, PCM_PARAM_PERIOD_SIZE)); |
| 365 | ALOGV("usb:audio_hw - PCM_PARAM_PERIOD_BYTES min:%u, max:%u", |
| 366 | pcm_params_get_min(alsa_hw_params, PCM_PARAM_PERIOD_BYTES), |
| 367 | pcm_params_get_max(alsa_hw_params, PCM_PARAM_PERIOD_BYTES)); |
| 368 | ALOGV("usb:audio_hw - PCM_PARAM_PERIODS min:%u, max:%u", |
| 369 | pcm_params_get_min(alsa_hw_params, PCM_PARAM_PERIODS), |
| 370 | pcm_params_get_max(alsa_hw_params, PCM_PARAM_PERIODS)); |
| 371 | ALOGV("usb:audio_hw - PCM_PARAM_BUFFER_TIME min:%u, max:%u", |
| 372 | pcm_params_get_min(alsa_hw_params, PCM_PARAM_BUFFER_TIME), |
| 373 | pcm_params_get_max(alsa_hw_params, PCM_PARAM_BUFFER_TIME)); |
| 374 | ALOGV("usb:audio_hw - PCM_PARAM_BUFFER_SIZE min:%u, max:%u", |
| 375 | pcm_params_get_min(alsa_hw_params, PCM_PARAM_BUFFER_SIZE), |
| 376 | pcm_params_get_max(alsa_hw_params, PCM_PARAM_BUFFER_SIZE)); |
| 377 | ALOGV("usb:audio_hw - PCM_PARAM_BUFFER_BYTES min:%u, max:%u", |
| 378 | pcm_params_get_min(alsa_hw_params, PCM_PARAM_BUFFER_BYTES), |
| 379 | pcm_params_get_max(alsa_hw_params, PCM_PARAM_BUFFER_BYTES)); |
| 380 | ALOGV("usb:audio_hw - PCM_PARAM_TICK_TIME min:%u, max:%u", |
| 381 | pcm_params_get_min(alsa_hw_params, PCM_PARAM_TICK_TIME), |
| 382 | pcm_params_get_max(alsa_hw_params, PCM_PARAM_TICK_TIME)); |
| 383 | } |
| 384 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 385 | /* |
Paul McLean | 33a6b17 | 2014-06-19 12:35:28 -0700 | [diff] [blame] | 386 | * Returns the supplied value rounded up to the next even multiple of 16 |
| 387 | */ |
| 388 | static unsigned int round_to_16_mult(unsigned int size) { |
| 389 | return (size + 15) & 0xFFFFFFF0; |
| 390 | } |
| 391 | |
| 392 | /*TODO(pmclean) - Evaluate if this value should/can be retrieved from a device-specific property */ |
| 393 | #define MIN_BUFF_TIME 5 /* milliseconds */ |
| 394 | |
| 395 | /* |
| 396 | * Returns the system defined minimum period size based on the supplied sample rate |
| 397 | */ |
| 398 | static unsigned int calc_min_period_size(unsigned int sample_rate) { |
| 399 | unsigned int period_size = (sample_rate * MIN_BUFF_TIME) / 1000; |
| 400 | return round_to_16_mult(period_size); |
| 401 | } |
| 402 | |
| 403 | /* |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 404 | * Reads and decodes configuration info from the specified ALSA card/device |
| 405 | */ |
| 406 | static int read_alsa_device_config(int card, int device, int io_type, struct pcm_config * config) |
| 407 | { |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 408 | ALOGV("usb:audio_hw - read_alsa_device_config(c:%d d:%d t:0x%X)",card, device, io_type); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 409 | |
| 410 | if (card < 0 || device < 0) { |
| 411 | return -EINVAL; |
| 412 | } |
| 413 | |
| 414 | struct pcm_params * alsa_hw_params = pcm_params_get(card, device, io_type); |
| 415 | if (alsa_hw_params == NULL) { |
| 416 | return -EINVAL; |
| 417 | } |
| 418 | |
| 419 | /* |
| 420 | * This Logging will be useful when testing new USB devices. |
| 421 | */ |
Paul McLean | cf61191 | 2014-04-28 13:03:18 -0700 | [diff] [blame] | 422 | /* log_pcm_params(alsa_hw_params); */ |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 423 | |
| 424 | config->channels = pcm_params_get_min(alsa_hw_params, PCM_PARAM_CHANNELS); |
| 425 | config->rate = pcm_params_get_min(alsa_hw_params, PCM_PARAM_RATE); |
Paul McLean | 33a6b17 | 2014-06-19 12:35:28 -0700 | [diff] [blame] | 426 | config->period_size = pcm_params_get_min(alsa_hw_params, PCM_PARAM_BUFFER_SIZE); |
| 427 | /* round this up to a multiple of 16 */ |
| 428 | config->period_size = round_to_16_mult(config->period_size); |
| 429 | /* make sure it is above a minimum value to minimize jitter */ |
| 430 | unsigned int min_period_size = calc_min_period_size(config->rate); |
| 431 | if (config->period_size < min_period_size) { |
| 432 | config->period_size = min_period_size; |
| 433 | } |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 434 | config->period_count = pcm_params_get_min(alsa_hw_params, PCM_PARAM_PERIODS); |
| 435 | |
Mark Salyzyn | 88e458a | 2014-04-28 12:30:44 -0700 | [diff] [blame] | 436 | unsigned int bits_per_sample = pcm_params_get_min(alsa_hw_params, PCM_PARAM_SAMPLE_BITS); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 437 | config->format = bits_to_alsa_format(bits_per_sample, PCM_FORMAT_S16_LE); |
| 438 | |
| 439 | return 0; |
| 440 | } |
| 441 | |
| 442 | /* |
| 443 | * HAl Functions |
| 444 | */ |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 445 | /** |
| 446 | * NOTE: when multiple mutexes have to be acquired, always respect the |
| 447 | * following order: hw device > out stream |
| 448 | */ |
| 449 | |
| 450 | /* Helper functions */ |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 451 | static uint32_t out_get_sample_rate(const struct audio_stream *stream) |
| 452 | { |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 453 | return cached_output_hardware_config.rate; |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate) |
| 457 | { |
| 458 | return 0; |
| 459 | } |
| 460 | |
| 461 | static size_t out_get_buffer_size(const struct audio_stream *stream) |
| 462 | { |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 463 | return cached_output_hardware_config.period_size * audio_stream_frame_size(stream); |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | static uint32_t out_get_channels(const struct audio_stream *stream) |
| 467 | { |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 468 | // Always Stero for now. We will do *some* conversions in this HAL. |
| 469 | // TODO(pmclean) When AudioPolicyManager & AudioFlinger supports arbitrary channels |
| 470 | // rewrite this to return the ACTUAL channel format |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 471 | return AUDIO_CHANNEL_OUT_STEREO; |
| 472 | } |
| 473 | |
| 474 | static audio_format_t out_get_format(const struct audio_stream *stream) |
| 475 | { |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 476 | // Always return 16-bit PCM. We will do *some* conversions in this HAL. |
| 477 | // TODO(pmclean) When AudioPolicyManager & AudioFlinger supports arbitrary PCM formats |
| 478 | // rewrite this to return the ACTUAL data format |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 479 | return AUDIO_FORMAT_PCM_16_BIT; |
| 480 | } |
| 481 | |
| 482 | static int out_set_format(struct audio_stream *stream, audio_format_t format) |
| 483 | { |
| 484 | return 0; |
| 485 | } |
| 486 | |
| 487 | static int out_standby(struct audio_stream *stream) |
| 488 | { |
| 489 | struct stream_out *out = (struct stream_out *)stream; |
| 490 | |
| 491 | pthread_mutex_lock(&out->dev->lock); |
| 492 | pthread_mutex_lock(&out->lock); |
| 493 | |
| 494 | if (!out->standby) { |
| 495 | pcm_close(out->pcm); |
| 496 | out->pcm = NULL; |
| 497 | out->standby = true; |
| 498 | } |
| 499 | |
| 500 | pthread_mutex_unlock(&out->lock); |
| 501 | pthread_mutex_unlock(&out->dev->lock); |
| 502 | |
| 503 | return 0; |
| 504 | } |
| 505 | |
| 506 | static int out_dump(const struct audio_stream *stream, int fd) |
| 507 | { |
| 508 | return 0; |
| 509 | } |
| 510 | |
| 511 | static int out_set_parameters(struct audio_stream *stream, const char *kvpairs) |
| 512 | { |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 513 | ALOGV("usb:audio_hw::out out_set_parameters() keys:%s", kvpairs); |
| 514 | |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 515 | struct stream_out *out = (struct stream_out *)stream; |
| 516 | struct audio_device *adev = out->dev; |
| 517 | struct str_parms *parms; |
| 518 | char value[32]; |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 519 | int param_val; |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 520 | int routing = 0; |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 521 | int ret_value = 0; |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 522 | |
| 523 | parms = str_parms_create_str(kvpairs); |
| 524 | pthread_mutex_lock(&adev->lock); |
| 525 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 526 | bool recache_device_params = false; |
| 527 | param_val = str_parms_get_str(parms, "card", value, sizeof(value)); |
| 528 | if (param_val >= 0) { |
| 529 | adev->out_card = atoi(value); |
| 530 | recache_device_params = true; |
| 531 | } |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 532 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 533 | param_val = str_parms_get_str(parms, "device", value, sizeof(value)); |
| 534 | if (param_val >= 0) { |
| 535 | adev->out_device = atoi(value); |
| 536 | recache_device_params = true; |
| 537 | } |
| 538 | |
| 539 | if (recache_device_params && adev->out_card >= 0 && adev->out_device >= 0) { |
| 540 | ret_value = read_alsa_device_config(adev->out_card, adev->out_device, PCM_OUT, |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 541 | &cached_output_hardware_config); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 542 | output_hardware_config_is_cached = (ret_value == 0); |
| 543 | } |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 544 | |
| 545 | pthread_mutex_unlock(&adev->lock); |
| 546 | str_parms_destroy(parms); |
| 547 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 548 | return ret_value; |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 549 | } |
| 550 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 551 | //TODO(pmclean) it seems like both out_get_parameters() and in_get_parameters() |
| 552 | // could be written in terms of a get_device_parameters(io_type) |
| 553 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 554 | static char * out_get_parameters(const struct audio_stream *stream, const char *keys) |
| 555 | { |
| 556 | ALOGV("usb:audio_hw::out out_get_parameters() keys:%s", keys); |
| 557 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 558 | struct stream_out *out = (struct stream_out *) stream; |
| 559 | struct audio_device *adev = out->dev; |
| 560 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 561 | if (adev->out_card < 0 || adev->out_device < 0) |
| 562 | return strdup(""); |
| 563 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 564 | unsigned min, max; |
| 565 | |
| 566 | struct str_parms *query = str_parms_create_str(keys); |
| 567 | struct str_parms *result = str_parms_create(); |
| 568 | |
| 569 | int num_written = 0; |
| 570 | char buffer[256]; |
| 571 | int buffer_size = sizeof(buffer) / sizeof(buffer[0]); |
| 572 | char* result_str = NULL; |
| 573 | |
| 574 | struct pcm_params * alsa_hw_params = pcm_params_get(adev->out_card, adev->out_device, PCM_OUT); |
| 575 | |
| 576 | // These keys are from hardware/libhardware/include/audio.h |
| 577 | // supported sample rates |
| 578 | if (str_parms_has_key(query, AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES)) { |
| 579 | // pcm_hw_params doesn't have a list of supported samples rates, just a min and a max, so |
| 580 | // if they are different, return a list containing those two values, otherwise just the one. |
| 581 | min = pcm_params_get_min(alsa_hw_params, PCM_PARAM_RATE); |
| 582 | max = pcm_params_get_max(alsa_hw_params, PCM_PARAM_RATE); |
Mark Salyzyn | 88e458a | 2014-04-28 12:30:44 -0700 | [diff] [blame] | 583 | num_written = snprintf(buffer, buffer_size, "%u", min); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 584 | if (min != max) { |
Mark Salyzyn | 88e458a | 2014-04-28 12:30:44 -0700 | [diff] [blame] | 585 | snprintf(buffer + num_written, buffer_size - num_written, "|%u", max); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 586 | } |
| 587 | str_parms_add_str(result, AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES, |
| 588 | buffer); |
| 589 | } // AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES |
| 590 | |
| 591 | // supported channel counts |
| 592 | if (str_parms_has_key(query, AUDIO_PARAMETER_STREAM_SUP_CHANNELS)) { |
| 593 | // Similarly for output channels count |
| 594 | min = pcm_params_get_min(alsa_hw_params, PCM_PARAM_CHANNELS); |
| 595 | max = pcm_params_get_max(alsa_hw_params, PCM_PARAM_CHANNELS); |
Mark Salyzyn | 88e458a | 2014-04-28 12:30:44 -0700 | [diff] [blame] | 596 | num_written = snprintf(buffer, buffer_size, "%u", min); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 597 | if (min != max) { |
Mark Salyzyn | 88e458a | 2014-04-28 12:30:44 -0700 | [diff] [blame] | 598 | snprintf(buffer + num_written, buffer_size - num_written, "|%u", max); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 599 | } |
| 600 | str_parms_add_str(result, AUDIO_PARAMETER_STREAM_SUP_CHANNELS, buffer); |
| 601 | } // AUDIO_PARAMETER_STREAM_SUP_CHANNELS |
| 602 | |
| 603 | // supported sample formats |
| 604 | if (str_parms_has_key(query, AUDIO_PARAMETER_STREAM_SUP_FORMATS)) { |
| 605 | // Similarly for output channels count |
| 606 | //TODO(pmclean): this is wrong. |
| 607 | min = pcm_params_get_min(alsa_hw_params, PCM_PARAM_SAMPLE_BITS); |
| 608 | max = pcm_params_get_max(alsa_hw_params, PCM_PARAM_SAMPLE_BITS); |
Mark Salyzyn | 88e458a | 2014-04-28 12:30:44 -0700 | [diff] [blame] | 609 | num_written = snprintf(buffer, buffer_size, "%u", min); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 610 | if (min != max) { |
Mark Salyzyn | 88e458a | 2014-04-28 12:30:44 -0700 | [diff] [blame] | 611 | snprintf(buffer + num_written, buffer_size - num_written, "|%u", max); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 612 | } |
| 613 | str_parms_add_str(result, AUDIO_PARAMETER_STREAM_SUP_FORMATS, buffer); |
| 614 | } // AUDIO_PARAMETER_STREAM_SUP_FORMATS |
| 615 | |
| 616 | result_str = str_parms_to_str(result); |
| 617 | |
| 618 | // done with these... |
| 619 | str_parms_destroy(query); |
| 620 | str_parms_destroy(result); |
| 621 | |
| 622 | return result_str; |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | static uint32_t out_get_latency(const struct audio_stream_out *stream) |
| 626 | { |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 627 | struct stream_out *out = (struct stream_out *) stream; |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 628 | |
| 629 | //TODO(pmclean): Do we need a term here for the USB latency |
| 630 | // (as reported in the USB descriptors)? |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 631 | uint32_t latency = (cached_output_hardware_config.period_size |
| 632 | * cached_output_hardware_config.period_count * 1000) / out_get_sample_rate(&stream->common); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 633 | return latency; |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 634 | } |
| 635 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 636 | 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] | 637 | { |
| 638 | return -ENOSYS; |
| 639 | } |
| 640 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 641 | /* must be called with hw device and output stream mutexes locked */ |
| 642 | static int start_output_stream(struct stream_out *out) |
| 643 | { |
| 644 | struct audio_device *adev = out->dev; |
| 645 | int return_val = 0; |
| 646 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 647 | ALOGV("usb:audio_hw::out start_output_stream(card:%d device:%d)", |
| 648 | adev->out_card, adev->out_device); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 649 | |
| 650 | out->pcm = pcm_open(adev->out_card, adev->out_device, PCM_OUT, &cached_output_hardware_config); |
| 651 | if (out->pcm == NULL) { |
| 652 | return -ENOMEM; |
| 653 | } |
| 654 | |
| 655 | if (out->pcm && !pcm_is_ready(out->pcm)) { |
| 656 | ALOGE("audio_hw audio_hw pcm_open() failed: %s", pcm_get_error(out->pcm)); |
| 657 | pcm_close(out->pcm); |
| 658 | return -ENOMEM; |
| 659 | } |
| 660 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 661 | return 0; |
| 662 | } |
| 663 | |
| 664 | 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] | 665 | { |
| 666 | int ret; |
| 667 | struct stream_out *out = (struct stream_out *)stream; |
| 668 | |
| 669 | pthread_mutex_lock(&out->dev->lock); |
| 670 | pthread_mutex_lock(&out->lock); |
| 671 | if (out->standby) { |
| 672 | ret = start_output_stream(out); |
| 673 | if (ret != 0) { |
| 674 | goto err; |
| 675 | } |
| 676 | out->standby = false; |
| 677 | } |
| 678 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 679 | // Setup conversion buffer |
| 680 | // compute maximum potential buffer size. |
| 681 | // * 2 for stereo -> quad conversion |
| 682 | // * 3/2 for 16bit -> 24 bit conversion |
Mark Salyzyn | 88e458a | 2014-04-28 12:30:44 -0700 | [diff] [blame] | 683 | size_t required_conversion_buffer_size = (bytes * 3 * 2) / 2; |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 684 | if (required_conversion_buffer_size > out->conversion_buffer_size) { |
| 685 | //TODO(pmclean) - remove this when AudioPolicyManger/AudioFlinger support arbitrary formats |
| 686 | // (and do these conversions themselves) |
| 687 | out->conversion_buffer_size = required_conversion_buffer_size; |
| 688 | out->conversion_buffer = realloc(out->conversion_buffer, out->conversion_buffer_size); |
| 689 | } |
| 690 | |
Mark Salyzyn | 88e458a | 2014-04-28 12:30:44 -0700 | [diff] [blame] | 691 | const void * write_buff = buffer; |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 692 | int num_write_buff_bytes = bytes; |
| 693 | |
| 694 | /* |
| 695 | * Num Channels conversion |
| 696 | */ |
| 697 | int num_device_channels = cached_output_hardware_config.channels; |
| 698 | int num_req_channels = 2; /* always, for now */ |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 699 | if (num_device_channels != num_req_channels) { |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 700 | num_write_buff_bytes = |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 701 | expand_channels_16(write_buff, num_req_channels, |
| 702 | out->conversion_buffer, num_device_channels, |
| 703 | num_write_buff_bytes / sizeof(short)); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 704 | write_buff = out->conversion_buffer; |
| 705 | } |
| 706 | |
| 707 | /* |
| 708 | * 16 vs 24-bit logic here |
| 709 | */ |
| 710 | switch (cached_output_hardware_config.format) { |
| 711 | case PCM_FORMAT_S16_LE: |
| 712 | // the output format is the same as the input format, so just write it out |
| 713 | break; |
| 714 | |
| 715 | case PCM_FORMAT_S24_3LE: |
| 716 | // 16-bit LE2 - 24-bit LE3 |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 717 | num_write_buff_bytes = convert_16_to_24_3(write_buff, |
| 718 | num_write_buff_bytes / sizeof(short), |
| 719 | out->conversion_buffer); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 720 | write_buff = out->conversion_buffer; |
| 721 | break; |
| 722 | |
| 723 | default: |
| 724 | // hmmmmm..... |
| 725 | ALOGV("usb:Unknown Format!!!"); |
| 726 | break; |
| 727 | } |
| 728 | |
| 729 | if (write_buff != NULL && num_write_buff_bytes != 0) { |
| 730 | pcm_write(out->pcm, write_buff, num_write_buff_bytes); |
| 731 | } |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 732 | |
| 733 | pthread_mutex_unlock(&out->lock); |
| 734 | pthread_mutex_unlock(&out->dev->lock); |
| 735 | |
| 736 | return bytes; |
| 737 | |
| 738 | err: |
| 739 | pthread_mutex_unlock(&out->lock); |
Amit Shekhar | f9953b7 | 2014-01-30 12:47:34 -0800 | [diff] [blame] | 740 | pthread_mutex_unlock(&out->dev->lock); |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 741 | if (ret != 0) { |
| 742 | usleep(bytes * 1000000 / audio_stream_frame_size(&stream->common) / |
| 743 | out_get_sample_rate(&stream->common)); |
| 744 | } |
| 745 | |
| 746 | return bytes; |
| 747 | } |
| 748 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 749 | 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] | 750 | { |
| 751 | return -EINVAL; |
| 752 | } |
| 753 | |
| 754 | static int out_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect) |
| 755 | { |
| 756 | return 0; |
| 757 | } |
| 758 | |
| 759 | static int out_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect) |
| 760 | { |
| 761 | return 0; |
| 762 | } |
| 763 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 764 | 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] | 765 | { |
| 766 | return -EINVAL; |
| 767 | } |
| 768 | |
| 769 | static int adev_open_output_stream(struct audio_hw_device *dev, |
Mike Lockwood | 46a9809 | 2012-04-24 16:41:18 -0700 | [diff] [blame] | 770 | audio_io_handle_t handle, |
| 771 | audio_devices_t devices, |
| 772 | audio_output_flags_t flags, |
| 773 | struct audio_config *config, |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 774 | struct audio_stream_out **stream_out) |
| 775 | { |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 776 | ALOGV("usb:audio_hw::out adev_open_output_stream() handle:0x%X, device:0x%X, flags:0x%X", |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 777 | handle, devices, flags); |
| 778 | |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 779 | struct audio_device *adev = (struct audio_device *)dev; |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 780 | |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 781 | struct stream_out *out; |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 782 | |
| 783 | out = (struct stream_out *)calloc(1, sizeof(struct stream_out)); |
| 784 | if (!out) |
| 785 | return -ENOMEM; |
| 786 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 787 | // setup function pointers |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 788 | out->stream.common.get_sample_rate = out_get_sample_rate; |
| 789 | out->stream.common.set_sample_rate = out_set_sample_rate; |
| 790 | out->stream.common.get_buffer_size = out_get_buffer_size; |
| 791 | out->stream.common.get_channels = out_get_channels; |
| 792 | out->stream.common.get_format = out_get_format; |
| 793 | out->stream.common.set_format = out_set_format; |
| 794 | out->stream.common.standby = out_standby; |
| 795 | out->stream.common.dump = out_dump; |
| 796 | out->stream.common.set_parameters = out_set_parameters; |
| 797 | out->stream.common.get_parameters = out_get_parameters; |
| 798 | out->stream.common.add_audio_effect = out_add_audio_effect; |
| 799 | out->stream.common.remove_audio_effect = out_remove_audio_effect; |
| 800 | out->stream.get_latency = out_get_latency; |
| 801 | out->stream.set_volume = out_set_volume; |
| 802 | out->stream.write = out_write; |
| 803 | out->stream.get_render_position = out_get_render_position; |
| 804 | out->stream.get_next_write_timestamp = out_get_next_write_timestamp; |
| 805 | |
| 806 | out->dev = adev; |
| 807 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 808 | if (output_hardware_config_is_cached) { |
| 809 | config->sample_rate = cached_output_hardware_config.rate; |
| 810 | |
| 811 | config->format = alsa_to_fw_format_id(cached_output_hardware_config.format); |
| 812 | if (config->format != AUDIO_FORMAT_PCM_16_BIT) { |
| 813 | // Always report PCM16 for now. AudioPolicyManagerBase/AudioFlinger dont' understand |
| 814 | // formats with more other format, so we won't get chosen (say with a 24bit DAC). |
| 815 | //TODO(pmclean) remove this when the above restriction is removed. |
| 816 | config->format = AUDIO_FORMAT_PCM_16_BIT; |
| 817 | } |
| 818 | |
| 819 | config->channel_mask = |
| 820 | audio_channel_out_mask_from_count(cached_output_hardware_config.channels); |
| 821 | if (config->channel_mask != AUDIO_CHANNEL_OUT_STEREO) { |
| 822 | // Always report STEREO for now. AudioPolicyManagerBase/AudioFlinger dont' understand |
| 823 | // formats with more channels, so we won't get chosen (say with a 4-channel DAC). |
| 824 | //TODO(pmclean) remove this when the above restriction is removed. |
| 825 | config->channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 826 | } |
| 827 | } else { |
| 828 | cached_output_hardware_config = default_alsa_out_config; |
| 829 | |
| 830 | config->format = out_get_format(&out->stream.common); |
| 831 | config->channel_mask = out_get_channels(&out->stream.common); |
| 832 | config->sample_rate = out_get_sample_rate(&out->stream.common); |
| 833 | } |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 834 | |
| 835 | out->conversion_buffer = NULL; |
| 836 | out->conversion_buffer_size = 0; |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 837 | |
| 838 | out->standby = true; |
| 839 | |
| 840 | *stream_out = &out->stream; |
| 841 | return 0; |
| 842 | |
| 843 | err_open: |
| 844 | free(out); |
| 845 | *stream_out = NULL; |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 846 | return -ENOSYS; |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | static void adev_close_output_stream(struct audio_hw_device *dev, |
| 850 | struct audio_stream_out *stream) |
| 851 | { |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 852 | ALOGV("usb:audio_hw::out adev_close_output_stream()"); |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 853 | struct stream_out *out = (struct stream_out *)stream; |
| 854 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 855 | //TODO(pmclean) why are we doing this when stream get's freed at the end |
| 856 | // because it closes the pcm device |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 857 | out_standby(&stream->common); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 858 | |
| 859 | free(out->conversion_buffer); |
| 860 | out->conversion_buffer = NULL; |
| 861 | out->conversion_buffer_size = 0; |
| 862 | |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 863 | free(stream); |
| 864 | } |
| 865 | |
| 866 | static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs) |
| 867 | { |
| 868 | return 0; |
| 869 | } |
| 870 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 871 | 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] | 872 | { |
| 873 | return strdup(""); |
| 874 | } |
| 875 | |
| 876 | static int adev_init_check(const struct audio_hw_device *dev) |
| 877 | { |
| 878 | return 0; |
| 879 | } |
| 880 | |
| 881 | static int adev_set_voice_volume(struct audio_hw_device *dev, float volume) |
| 882 | { |
| 883 | return -ENOSYS; |
| 884 | } |
| 885 | |
| 886 | static int adev_set_master_volume(struct audio_hw_device *dev, float volume) |
| 887 | { |
| 888 | return -ENOSYS; |
| 889 | } |
| 890 | |
| 891 | static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode) |
| 892 | { |
| 893 | return 0; |
| 894 | } |
| 895 | |
| 896 | static int adev_set_mic_mute(struct audio_hw_device *dev, bool state) |
| 897 | { |
| 898 | return -ENOSYS; |
| 899 | } |
| 900 | |
| 901 | static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state) |
| 902 | { |
| 903 | return -ENOSYS; |
| 904 | } |
| 905 | |
| 906 | static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev, |
Mike Lockwood | 46a9809 | 2012-04-24 16:41:18 -0700 | [diff] [blame] | 907 | const struct audio_config *config) |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 908 | { |
| 909 | return 0; |
| 910 | } |
| 911 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 912 | /* Helper functions */ |
| 913 | static uint32_t in_get_sample_rate(const struct audio_stream *stream) |
| 914 | { |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 915 | return cached_input_hardware_config.rate; |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate) |
| 919 | { |
| 920 | return -ENOSYS; |
| 921 | } |
| 922 | |
| 923 | static size_t in_get_buffer_size(const struct audio_stream *stream) |
| 924 | { |
Mark Salyzyn | 88e458a | 2014-04-28 12:30:44 -0700 | [diff] [blame] | 925 | ALOGV("usb: in_get_buffer_size() = %zu", |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 926 | cached_input_hardware_config.period_size * audio_stream_frame_size(stream)); |
| 927 | return cached_input_hardware_config.period_size * audio_stream_frame_size(stream); |
| 928 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | static uint32_t in_get_channels(const struct audio_stream *stream) |
| 932 | { |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 933 | // just report stereo for now |
| 934 | return AUDIO_CHANNEL_IN_STEREO; |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | static audio_format_t in_get_format(const struct audio_stream *stream) |
| 938 | { |
| 939 | // just report 16-bit, pcm for now. |
| 940 | return AUDIO_FORMAT_PCM_16_BIT; |
| 941 | } |
| 942 | |
| 943 | static int in_set_format(struct audio_stream *stream, audio_format_t format) |
| 944 | { |
| 945 | return -ENOSYS; |
| 946 | } |
| 947 | |
| 948 | static int in_standby(struct audio_stream *stream) |
| 949 | { |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 950 | struct stream_in *in = (struct stream_in *) stream; |
| 951 | |
| 952 | pthread_mutex_lock(&in->dev->lock); |
| 953 | pthread_mutex_lock(&in->lock); |
| 954 | |
| 955 | if (!in->standby) { |
| 956 | pcm_close(in->pcm); |
| 957 | in->pcm = NULL; |
| 958 | in->standby = true; |
| 959 | } |
| 960 | |
| 961 | pthread_mutex_unlock(&in->lock); |
| 962 | pthread_mutex_unlock(&in->dev->lock); |
| 963 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 964 | return 0; |
| 965 | } |
| 966 | |
| 967 | static int in_dump(const struct audio_stream *stream, int fd) |
| 968 | { |
| 969 | return 0; |
| 970 | } |
| 971 | |
| 972 | static int in_set_parameters(struct audio_stream *stream, const char *kvpairs) |
| 973 | { |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 974 | ALOGV("usb: audio_hw::in in_set_parameters() keys:%s", kvpairs); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 975 | |
| 976 | struct stream_in *in = (struct stream_in *)stream; |
| 977 | struct audio_device *adev = in->dev; |
| 978 | struct str_parms *parms; |
| 979 | char value[32]; |
| 980 | int param_val; |
| 981 | int routing = 0; |
| 982 | int ret_value = 0; |
| 983 | |
| 984 | parms = str_parms_create_str(kvpairs); |
| 985 | pthread_mutex_lock(&adev->lock); |
| 986 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 987 | bool recache_device_params = false; |
| 988 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 989 | // Card/Device |
| 990 | param_val = str_parms_get_str(parms, "card", value, sizeof(value)); |
| 991 | if (param_val >= 0) { |
| 992 | adev->in_card = atoi(value); |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 993 | recache_device_params = true; |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | param_val = str_parms_get_str(parms, "device", value, sizeof(value)); |
| 997 | if (param_val >= 0) { |
| 998 | adev->in_device = atoi(value); |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 999 | recache_device_params = true; |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 1000 | } |
| 1001 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1002 | if (recache_device_params && adev->in_card >= 0 && adev->in_device >= 0) { |
| 1003 | ret_value = read_alsa_device_config(adev->in_card, adev->in_device, |
| 1004 | PCM_IN, &(cached_input_hardware_config)); |
| 1005 | input_hardware_config_is_cached = (ret_value == 0); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | pthread_mutex_unlock(&adev->lock); |
| 1009 | str_parms_destroy(parms); |
| 1010 | |
| 1011 | return ret_value; |
| 1012 | } |
| 1013 | |
| 1014 | //TODO(pmclean) it seems like both out_get_parameters() and in_get_parameters() |
| 1015 | // could be written in terms of a get_device_parameters(io_type) |
| 1016 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1017 | static char * in_get_parameters(const struct audio_stream *stream, const char *keys) { |
| 1018 | ALOGV("usb:audio_hw::in in_get_parameters() keys:%s", keys); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 1019 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1020 | struct stream_in *in = (struct stream_in *)stream; |
| 1021 | struct audio_device *adev = in->dev; |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 1022 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1023 | if (adev->in_card < 0 || adev->in_device < 0) |
| 1024 | return strdup(""); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 1025 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1026 | struct pcm_params * alsa_hw_params = pcm_params_get(adev->in_card, adev->in_device, PCM_IN); |
| 1027 | if (alsa_hw_params == NULL) |
| 1028 | return strdup(""); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 1029 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1030 | struct str_parms *query = str_parms_create_str(keys); |
| 1031 | struct str_parms *result = str_parms_create(); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 1032 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1033 | int num_written = 0; |
| 1034 | char buffer[256]; |
| 1035 | int buffer_size = sizeof(buffer) / sizeof(buffer[0]); |
| 1036 | char* result_str = NULL; |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 1037 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1038 | unsigned min, max; |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 1039 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1040 | // These keys are from hardware/libhardware/include/audio.h |
| 1041 | // supported sample rates |
| 1042 | if (str_parms_has_key(query, AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES)) { |
| 1043 | // pcm_hw_params doesn't have a list of supported samples rates, just a min and a max, so |
| 1044 | // if they are different, return a list containing those two values, otherwise just the one. |
| 1045 | min = pcm_params_get_min(alsa_hw_params, PCM_PARAM_RATE); |
| 1046 | max = pcm_params_get_max(alsa_hw_params, PCM_PARAM_RATE); |
Mark Salyzyn | 88e458a | 2014-04-28 12:30:44 -0700 | [diff] [blame] | 1047 | num_written = snprintf(buffer, buffer_size, "%u", min); |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1048 | if (min != max) { |
Mark Salyzyn | 88e458a | 2014-04-28 12:30:44 -0700 | [diff] [blame] | 1049 | snprintf(buffer + num_written, buffer_size - num_written, "|%u", max); |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1050 | } |
| 1051 | str_parms_add_str(result, AUDIO_PARAMETER_STREAM_SAMPLING_RATE, buffer); |
| 1052 | } // AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 1053 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1054 | // supported channel counts |
| 1055 | if (str_parms_has_key(query, AUDIO_PARAMETER_STREAM_SUP_CHANNELS)) { |
| 1056 | // Similarly for output channels count |
| 1057 | min = pcm_params_get_min(alsa_hw_params, PCM_PARAM_CHANNELS); |
| 1058 | max = pcm_params_get_max(alsa_hw_params, PCM_PARAM_CHANNELS); |
Mark Salyzyn | 88e458a | 2014-04-28 12:30:44 -0700 | [diff] [blame] | 1059 | num_written = snprintf(buffer, buffer_size, "%u", min); |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1060 | if (min != max) { |
Mark Salyzyn | 88e458a | 2014-04-28 12:30:44 -0700 | [diff] [blame] | 1061 | snprintf(buffer + num_written, buffer_size - num_written, "|%u", max); |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1062 | } |
| 1063 | str_parms_add_str(result, AUDIO_PARAMETER_STREAM_CHANNELS, buffer); |
| 1064 | } // AUDIO_PARAMETER_STREAM_SUP_CHANNELS |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 1065 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1066 | // supported sample formats |
| 1067 | if (str_parms_has_key(query, AUDIO_PARAMETER_STREAM_SUP_FORMATS)) { |
| 1068 | //TODO(pmclean): this is wrong. |
| 1069 | min = pcm_params_get_min(alsa_hw_params, PCM_PARAM_SAMPLE_BITS); |
| 1070 | max = pcm_params_get_max(alsa_hw_params, PCM_PARAM_SAMPLE_BITS); |
Mark Salyzyn | 88e458a | 2014-04-28 12:30:44 -0700 | [diff] [blame] | 1071 | num_written = snprintf(buffer, buffer_size, "%u", min); |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1072 | if (min != max) { |
Mark Salyzyn | 88e458a | 2014-04-28 12:30:44 -0700 | [diff] [blame] | 1073 | snprintf(buffer + num_written, buffer_size - num_written, "|%u", max); |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1074 | } |
| 1075 | str_parms_add_str(result, AUDIO_PARAMETER_STREAM_SUP_FORMATS, buffer); |
| 1076 | } // AUDIO_PARAMETER_STREAM_SUP_FORMATS |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 1077 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1078 | result_str = str_parms_to_str(result); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 1079 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1080 | // done with these... |
| 1081 | str_parms_destroy(query); |
| 1082 | str_parms_destroy(result); |
| 1083 | |
| 1084 | return result_str; |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | static int in_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect) |
| 1088 | { |
| 1089 | return 0; |
| 1090 | } |
| 1091 | |
| 1092 | static int in_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect) |
| 1093 | { |
| 1094 | return 0; |
| 1095 | } |
| 1096 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1097 | static int in_set_gain(struct audio_stream_in *stream, float gain) |
| 1098 | { |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 1099 | return 0; |
| 1100 | } |
| 1101 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1102 | /* must be called with hw device and output stream mutexes locked */ |
| 1103 | static int start_input_stream(struct stream_in *in) { |
| 1104 | struct audio_device *adev = in->dev; |
| 1105 | int return_val = 0; |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 1106 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1107 | ALOGV("usb:audio_hw::start_input_stream(card:%d device:%d)", |
| 1108 | adev->in_card, adev->in_device); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 1109 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1110 | in->pcm = pcm_open(adev->in_card, adev->in_device, PCM_IN, &cached_input_hardware_config); |
| 1111 | if (in->pcm == NULL) { |
| 1112 | ALOGE("usb:audio_hw pcm_open() in->pcm == NULL"); |
| 1113 | return -ENOMEM; |
| 1114 | } |
| 1115 | |
| 1116 | if (in->pcm && !pcm_is_ready(in->pcm)) { |
| 1117 | ALOGE("usb:audio_hw audio_hw pcm_open() failed: %s", pcm_get_error(in->pcm)); |
| 1118 | pcm_close(in->pcm); |
| 1119 | return -ENOMEM; |
| 1120 | } |
| 1121 | |
| 1122 | return 0; |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 1123 | } |
| 1124 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1125 | //TODO(pmclean) mutex stuff here (see out_write) |
| 1126 | static ssize_t in_read(struct audio_stream_in *stream, void* buffer, size_t bytes) |
| 1127 | { |
Mark Salyzyn | 88e458a | 2014-04-28 12:30:44 -0700 | [diff] [blame] | 1128 | size_t num_read_buff_bytes = 0; |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1129 | void * read_buff = buffer; |
| 1130 | void * out_buff = buffer; |
| 1131 | |
| 1132 | struct stream_in * in = (struct stream_in *) stream; |
| 1133 | |
Paul McLean | cf61191 | 2014-04-28 13:03:18 -0700 | [diff] [blame] | 1134 | ALOGV("usb: in_read(%d)", bytes); |
| 1135 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1136 | pthread_mutex_lock(&in->dev->lock); |
| 1137 | pthread_mutex_lock(&in->lock); |
| 1138 | |
| 1139 | if (in->standby) { |
| 1140 | if (start_input_stream(in) != 0) { |
| 1141 | goto err; |
| 1142 | } |
| 1143 | in->standby = false; |
| 1144 | } |
| 1145 | |
| 1146 | // OK, we need to figure out how much data to read to be able to output the requested |
| 1147 | // number of bytes in the HAL format (16-bit, stereo). |
| 1148 | num_read_buff_bytes = bytes; |
| 1149 | int num_device_channels = cached_input_hardware_config.channels; |
| 1150 | int num_req_channels = 2; /* always, for now */ |
| 1151 | |
| 1152 | if (num_device_channels != num_req_channels) { |
Paul McLean | cf61191 | 2014-04-28 13:03:18 -0700 | [diff] [blame] | 1153 | num_read_buff_bytes = (num_device_channels * num_read_buff_bytes) / num_req_channels; |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1154 | } |
| 1155 | |
Eric Laurent | 7661a48 | 2014-06-11 12:00:16 -0700 | [diff] [blame] | 1156 | if (cached_input_hardware_config.format == PCM_FORMAT_S24_3LE) { |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1157 | num_read_buff_bytes = (3 * num_read_buff_bytes) / 2; |
| 1158 | } |
| 1159 | |
| 1160 | // Setup/Realloc the conversion buffer (if necessary). |
| 1161 | if (num_read_buff_bytes != bytes) { |
| 1162 | if (num_read_buff_bytes > in->conversion_buffer_size) { |
| 1163 | //TODO(pmclean) - remove this when AudioPolicyManger/AudioFlinger support arbitrary formats |
| 1164 | // (and do these conversions themselves) |
| 1165 | in->conversion_buffer_size = num_read_buff_bytes; |
| 1166 | in->conversion_buffer = realloc(in->conversion_buffer, in->conversion_buffer_size); |
| 1167 | } |
| 1168 | read_buff = in->conversion_buffer; |
| 1169 | } |
| 1170 | |
| 1171 | if (pcm_read(in->pcm, read_buff, num_read_buff_bytes) == 0) { |
| 1172 | /* |
| 1173 | * Do any conversions necessary to send the data in the format specified to/by the HAL |
| 1174 | * (but different from the ALSA format), such as 24bit ->16bit, or 4chan -> 2chan. |
| 1175 | */ |
Eric Laurent | 7661a48 | 2014-06-11 12:00:16 -0700 | [diff] [blame] | 1176 | if (cached_input_hardware_config.format == PCM_FORMAT_S24_3LE) { |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1177 | if (num_device_channels != num_req_channels) { |
| 1178 | out_buff = read_buff; |
| 1179 | } |
| 1180 | |
| 1181 | /* Bit Format Conversion */ |
| 1182 | num_read_buff_bytes = |
| 1183 | convert_24_3_to_16(read_buff, num_read_buff_bytes / 3, out_buff); |
| 1184 | } |
| 1185 | |
| 1186 | if (num_device_channels != num_req_channels) { |
| 1187 | out_buff = buffer; |
| 1188 | /* Num Channels conversion */ |
Paul McLean | cf61191 | 2014-04-28 13:03:18 -0700 | [diff] [blame] | 1189 | if (num_device_channels < num_req_channels) { |
| 1190 | num_read_buff_bytes = |
Paul McLean | cf61191 | 2014-04-28 13:03:18 -0700 | [diff] [blame] | 1191 | expand_channels_16(read_buff, num_device_channels, |
| 1192 | out_buff, num_req_channels, |
| 1193 | num_read_buff_bytes / sizeof(short)); |
Eric Laurent | fbc02dc | 2014-06-27 18:39:21 -0700 | [diff] [blame^] | 1194 | } else { |
| 1195 | num_read_buff_bytes = |
| 1196 | contract_channels_16(read_buff, num_device_channels, |
| 1197 | out_buff, num_req_channels, |
| 1198 | num_read_buff_bytes / sizeof(short)); |
Paul McLean | cf61191 | 2014-04-28 13:03:18 -0700 | [diff] [blame] | 1199 | } |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1200 | } |
| 1201 | } |
| 1202 | |
| 1203 | err: |
| 1204 | pthread_mutex_unlock(&in->lock); |
| 1205 | pthread_mutex_unlock(&in->dev->lock); |
| 1206 | |
| 1207 | return num_read_buff_bytes; |
| 1208 | } |
| 1209 | |
| 1210 | static uint32_t in_get_input_frames_lost(struct audio_stream_in *stream) |
| 1211 | { |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 1212 | return 0; |
| 1213 | } |
| 1214 | |
Mike Lockwood | 46a9809 | 2012-04-24 16:41:18 -0700 | [diff] [blame] | 1215 | static int adev_open_input_stream(struct audio_hw_device *dev, |
| 1216 | audio_io_handle_t handle, |
| 1217 | audio_devices_t devices, |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1218 | struct audio_config *config, |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1219 | struct audio_stream_in **stream_in) |
| 1220 | { |
Mark Salyzyn | 88e458a | 2014-04-28 12:30:44 -0700 | [diff] [blame] | 1221 | ALOGV("usb: in adev_open_input_stream() rate:%" PRIu32 ", chanMask:0x%" PRIX32 ", fmt:%" PRIu8, |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1222 | config->sample_rate, config->channel_mask, config->format); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 1223 | |
| 1224 | struct stream_in *in = (struct stream_in *)calloc(1, sizeof(struct stream_in)); |
Eric Laurent | 7661a48 | 2014-06-11 12:00:16 -0700 | [diff] [blame] | 1225 | int ret = 0; |
| 1226 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 1227 | if (in == NULL) |
| 1228 | return -ENOMEM; |
| 1229 | |
| 1230 | // setup function pointers |
| 1231 | in->stream.common.get_sample_rate = in_get_sample_rate; |
| 1232 | in->stream.common.set_sample_rate = in_set_sample_rate; |
| 1233 | in->stream.common.get_buffer_size = in_get_buffer_size; |
| 1234 | in->stream.common.get_channels = in_get_channels; |
| 1235 | in->stream.common.get_format = in_get_format; |
| 1236 | in->stream.common.set_format = in_set_format; |
| 1237 | in->stream.common.standby = in_standby; |
| 1238 | in->stream.common.dump = in_dump; |
| 1239 | in->stream.common.set_parameters = in_set_parameters; |
| 1240 | in->stream.common.get_parameters = in_get_parameters; |
| 1241 | in->stream.common.add_audio_effect = in_add_audio_effect; |
| 1242 | in->stream.common.remove_audio_effect = in_remove_audio_effect; |
| 1243 | |
| 1244 | in->stream.set_gain = in_set_gain; |
| 1245 | in->stream.read = in_read; |
| 1246 | in->stream.get_input_frames_lost = in_get_input_frames_lost; |
| 1247 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1248 | in->dev = (struct audio_device *)dev; |
| 1249 | |
Eric Laurent | 7661a48 | 2014-06-11 12:00:16 -0700 | [diff] [blame] | 1250 | if (config->channel_mask != AUDIO_CHANNEL_IN_STEREO) |
| 1251 | ret = -EINVAL; |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1252 | |
Eric Laurent | 7661a48 | 2014-06-11 12:00:16 -0700 | [diff] [blame] | 1253 | if (input_hardware_config_is_cached) { |
| 1254 | config->sample_rate = cached_input_hardware_config.rate; |
| 1255 | |
| 1256 | config->format = alsa_to_fw_format_id(cached_input_hardware_config.format); |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1257 | if (config->format != AUDIO_FORMAT_PCM_16_BIT) { |
| 1258 | // Always report PCM16 for now. AudioPolicyManagerBase/AudioFlinger dont' understand |
| 1259 | // formats with more other format, so we won't get chosen (say with a 24bit DAC). |
| 1260 | //TODO(pmclean) remove this when the above restriction is removed. |
| 1261 | config->format = AUDIO_FORMAT_PCM_16_BIT; |
| 1262 | } |
| 1263 | |
Eric Laurent | 7661a48 | 2014-06-11 12:00:16 -0700 | [diff] [blame] | 1264 | config->channel_mask = audio_channel_in_mask_from_count( |
| 1265 | cached_input_hardware_config.channels); |
| 1266 | if (config->channel_mask != AUDIO_CHANNEL_IN_STEREO) { |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1267 | // Always report STEREO for now. AudioPolicyManagerBase/AudioFlinger dont' understand |
| 1268 | // formats with more channels, so we won't get chosen (say with a 4-channel DAC). |
| 1269 | //TODO(pmclean) remove this when the above restriction is removed. |
Eric Laurent | 7661a48 | 2014-06-11 12:00:16 -0700 | [diff] [blame] | 1270 | config->channel_mask = AUDIO_CHANNEL_IN_STEREO; |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1271 | } |
| 1272 | } else { |
| 1273 | cached_input_hardware_config = default_alsa_in_config; |
| 1274 | |
Eric Laurent | 7661a48 | 2014-06-11 12:00:16 -0700 | [diff] [blame] | 1275 | config->format = in_get_format(&in->stream.common); |
| 1276 | config->channel_mask = in_get_channels(&in->stream.common); |
| 1277 | config->sample_rate = in_get_sample_rate(&in->stream.common); |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1278 | } |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 1279 | |
| 1280 | in->standby = true; |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 1281 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1282 | in->conversion_buffer = NULL; |
| 1283 | in->conversion_buffer_size = 0; |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 1284 | |
| 1285 | *stream_in = &in->stream; |
| 1286 | |
Eric Laurent | 7661a48 | 2014-06-11 12:00:16 -0700 | [diff] [blame] | 1287 | return ret; |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1288 | } |
| 1289 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1290 | static void adev_close_input_stream(struct audio_hw_device *dev, struct audio_stream_in *stream) |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1291 | { |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1292 | struct stream_in *in = (struct stream_in *)stream; |
| 1293 | |
| 1294 | //TODO(pmclean) why are we doing this when stream get's freed at the end |
| 1295 | // because it closes the pcm device |
| 1296 | in_standby(&stream->common); |
| 1297 | |
| 1298 | free(in->conversion_buffer); |
| 1299 | |
| 1300 | free(stream); |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1301 | } |
| 1302 | |
| 1303 | static int adev_dump(const audio_hw_device_t *device, int fd) |
| 1304 | { |
| 1305 | return 0; |
| 1306 | } |
| 1307 | |
| 1308 | static int adev_close(hw_device_t *device) |
| 1309 | { |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 1310 | struct audio_device *adev = (struct audio_device *)device; |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1311 | free(device); |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 1312 | |
| 1313 | output_hardware_config_is_cached = false; |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1314 | input_hardware_config_is_cached = false; |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 1315 | |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1316 | return 0; |
| 1317 | } |
| 1318 | |
Paul McLean | 30f4185 | 2014-04-16 15:44:20 -0700 | [diff] [blame] | 1319 | 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] | 1320 | { |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1321 | if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) |
| 1322 | return -EINVAL; |
| 1323 | |
Paul McLean | eedc92e | 2013-12-19 15:46:15 -0800 | [diff] [blame] | 1324 | struct audio_device *adev = calloc(1, sizeof(struct audio_device)); |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1325 | if (!adev) |
| 1326 | return -ENOMEM; |
| 1327 | |
| 1328 | adev->hw_device.common.tag = HARDWARE_DEVICE_TAG; |
Eric Laurent | 85e08e2 | 2012-08-28 14:30:35 -0700 | [diff] [blame] | 1329 | adev->hw_device.common.version = AUDIO_DEVICE_API_VERSION_2_0; |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1330 | adev->hw_device.common.module = (struct hw_module_t *) module; |
| 1331 | adev->hw_device.common.close = adev_close; |
| 1332 | |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1333 | adev->hw_device.init_check = adev_init_check; |
| 1334 | adev->hw_device.set_voice_volume = adev_set_voice_volume; |
| 1335 | adev->hw_device.set_master_volume = adev_set_master_volume; |
| 1336 | adev->hw_device.set_mode = adev_set_mode; |
| 1337 | adev->hw_device.set_mic_mute = adev_set_mic_mute; |
| 1338 | adev->hw_device.get_mic_mute = adev_get_mic_mute; |
| 1339 | adev->hw_device.set_parameters = adev_set_parameters; |
| 1340 | adev->hw_device.get_parameters = adev_get_parameters; |
| 1341 | adev->hw_device.get_input_buffer_size = adev_get_input_buffer_size; |
| 1342 | adev->hw_device.open_output_stream = adev_open_output_stream; |
| 1343 | adev->hw_device.close_output_stream = adev_close_output_stream; |
| 1344 | adev->hw_device.open_input_stream = adev_open_input_stream; |
| 1345 | adev->hw_device.close_input_stream = adev_close_input_stream; |
| 1346 | adev->hw_device.dump = adev_dump; |
| 1347 | |
| 1348 | *device = &adev->hw_device.common; |
| 1349 | |
| 1350 | return 0; |
| 1351 | } |
| 1352 | |
| 1353 | static struct hw_module_methods_t hal_module_methods = { |
| 1354 | .open = adev_open, |
| 1355 | }; |
| 1356 | |
| 1357 | struct audio_module HAL_MODULE_INFO_SYM = { |
| 1358 | .common = { |
| 1359 | .tag = HARDWARE_MODULE_TAG, |
Mike Lockwood | 46a9809 | 2012-04-24 16:41:18 -0700 | [diff] [blame] | 1360 | .module_api_version = AUDIO_MODULE_API_VERSION_0_1, |
| 1361 | .hal_api_version = HARDWARE_HAL_API_VERSION, |
Simon Wilson | 19957a3 | 2012-04-06 16:17:12 -0700 | [diff] [blame] | 1362 | .id = AUDIO_HARDWARE_MODULE_ID, |
| 1363 | .name = "USB audio HW HAL", |
| 1364 | .author = "The Android Open Source Project", |
| 1365 | .methods = &hal_module_methods, |
| 1366 | }, |
| 1367 | }; |