Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -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 "r_submix" |
Jean-Michel Trivi | 35a2c16 | 2012-09-17 10:13:26 -0700 | [diff] [blame] | 18 | //#define LOG_NDEBUG 0 |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 19 | |
| 20 | #include <errno.h> |
| 21 | #include <pthread.h> |
| 22 | #include <stdint.h> |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 23 | #include <stdlib.h> |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 24 | #include <sys/param.h> |
| 25 | #include <sys/time.h> |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 26 | |
| 27 | #include <cutils/log.h> |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 28 | #include <cutils/properties.h> |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 29 | #include <cutils/str_parms.h> |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 30 | |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 31 | #include <hardware/audio.h> |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 32 | #include <hardware/hardware.h> |
| 33 | #include <system/audio.h> |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 34 | |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 35 | #include <media/AudioParameter.h> |
| 36 | #include <media/AudioBufferProvider.h> |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 37 | #include <media/nbaio/MonoPipe.h> |
| 38 | #include <media/nbaio/MonoPipeReader.h> |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 39 | |
Jean-Michel Trivi | d441303 | 2012-09-30 11:08:06 -0700 | [diff] [blame] | 40 | #include <utils/String8.h> |
Jean-Michel Trivi | d441303 | 2012-09-30 11:08:06 -0700 | [diff] [blame] | 41 | |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 42 | extern "C" { |
| 43 | |
| 44 | namespace android { |
| 45 | |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 46 | // Set to 1 to enable extremely verbose logging in this module. |
| 47 | #define SUBMIX_VERBOSE_LOGGING 0 |
| 48 | #if SUBMIX_VERBOSE_LOGGING |
| 49 | #define SUBMIX_ALOGV(...) ALOGV(__VA_ARGS__) |
| 50 | #define SUBMIX_ALOGE(...) ALOGE(__VA_ARGS__) |
| 51 | #else |
| 52 | #define SUBMIX_ALOGV(...) |
| 53 | #define SUBMIX_ALOGE(...) |
| 54 | #endif // SUBMIX_VERBOSE_LOGGING |
| 55 | |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 56 | #define MAX_PIPE_DEPTH_IN_FRAMES (1024*8) |
| 57 | // The duration of MAX_READ_ATTEMPTS * READ_ATTEMPT_SLEEP_MS must be stricly inferior to |
| 58 | // the duration of a record buffer at the current record sample rate (of the device, not of |
| 59 | // the recording itself). Here we have: |
| 60 | // 3 * 5ms = 15ms < 1024 frames * 1000 / 48000 = 21.333ms |
Jean-Michel Trivi | 6acd966 | 2012-09-11 19:19:08 -0700 | [diff] [blame] | 61 | #define MAX_READ_ATTEMPTS 3 |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 62 | #define READ_ATTEMPT_SLEEP_MS 5 // 5ms between two read attempts when pipe is empty |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 63 | #define DEFAULT_RATE_HZ 48000 // default sample rate |
| 64 | |
| 65 | struct submix_config { |
| 66 | audio_format_t format; |
| 67 | audio_channel_mask_t channel_mask; |
| 68 | unsigned int rate; // sample rate for the device |
| 69 | unsigned int period_size; // size of the audio pipe is period_size * period_count in frames |
| 70 | unsigned int period_count; |
| 71 | }; |
| 72 | |
| 73 | struct submix_audio_device { |
| 74 | struct audio_hw_device device; |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 75 | bool output_standby; |
| 76 | bool input_standby; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 77 | submix_config config; |
| 78 | // Pipe variables: they handle the ring buffer that "pipes" audio: |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 79 | // - from the submix virtual audio output == what needs to be played |
| 80 | // remotely, seen as an output for AudioFlinger |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 81 | // - to the virtual audio source == what is captured by the component |
| 82 | // which "records" the submix / virtual audio source, and handles it as needed. |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 83 | // A usecase example is one where the component capturing the audio is then sending it over |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 84 | // Wifi for presentation on a remote Wifi Display device (e.g. a dongle attached to a TV, or a |
| 85 | // TV with Wifi Display capabilities), or to a wireless audio player. |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 86 | sp<MonoPipe> rsxSink; |
| 87 | sp<MonoPipeReader> rsxSource; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 88 | |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 89 | // device lock, also used to protect access to the audio pipe |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 90 | pthread_mutex_t lock; |
| 91 | }; |
| 92 | |
| 93 | struct submix_stream_out { |
| 94 | struct audio_stream_out stream; |
| 95 | struct submix_audio_device *dev; |
| 96 | }; |
| 97 | |
| 98 | struct submix_stream_in { |
| 99 | struct audio_stream_in stream; |
| 100 | struct submix_audio_device *dev; |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 101 | bool output_standby; // output standby state as seen from record thread |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 102 | |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 103 | // wall clock when recording starts |
| 104 | struct timespec record_start_time; |
| 105 | // how many frames have been requested to be read |
| 106 | int64_t read_counter_frames; |
| 107 | }; |
Jean-Michel Trivi | 6acd966 | 2012-09-11 19:19:08 -0700 | [diff] [blame] | 108 | |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 109 | // Get a pointer to submix_stream_out given an audio_stream_out that is embedded within the |
| 110 | // structure. |
| 111 | static struct submix_stream_out * audio_stream_out_get_submix_stream_out( |
| 112 | struct audio_stream_out * const stream) |
| 113 | { |
| 114 | ALOG_ASSERT(stream); |
| 115 | return reinterpret_cast<struct submix_stream_out *>(reinterpret_cast<uint8_t *>(stream) - |
| 116 | offsetof(struct submix_stream_out, stream)); |
| 117 | } |
| 118 | |
| 119 | // Get a pointer to submix_stream_out given an audio_stream that is embedded within the structure. |
| 120 | static struct submix_stream_out * audio_stream_get_submix_stream_out( |
| 121 | struct audio_stream * const stream) |
| 122 | { |
| 123 | ALOG_ASSERT(stream); |
| 124 | return audio_stream_out_get_submix_stream_out( |
| 125 | reinterpret_cast<struct audio_stream_out *>(stream)); |
| 126 | } |
| 127 | |
| 128 | // Get a pointer to submix_stream_in given an audio_stream_in that is embedded within the |
| 129 | // structure. |
| 130 | static struct submix_stream_in * audio_stream_in_get_submix_stream_in( |
| 131 | struct audio_stream_in * const stream) |
| 132 | { |
| 133 | ALOG_ASSERT(stream); |
| 134 | return reinterpret_cast<struct submix_stream_in *>(reinterpret_cast<uint8_t *>(stream) - |
| 135 | offsetof(struct submix_stream_in, stream)); |
| 136 | } |
| 137 | |
| 138 | // Get a pointer to submix_stream_in given an audio_stream that is embedded within the structure. |
| 139 | static struct submix_stream_in * audio_stream_get_submix_stream_in( |
| 140 | struct audio_stream * const stream) |
| 141 | { |
| 142 | ALOG_ASSERT(stream); |
| 143 | return audio_stream_in_get_submix_stream_in( |
| 144 | reinterpret_cast<struct audio_stream_in *>(stream)); |
| 145 | } |
| 146 | |
| 147 | // Get a pointer to submix_audio_device given a pointer to an audio_device that is embedded within |
| 148 | // the structure. |
| 149 | static struct submix_audio_device * audio_hw_device_get_submix_audio_device( |
| 150 | struct audio_hw_device *device) |
| 151 | { |
| 152 | ALOG_ASSERT(device); |
| 153 | return reinterpret_cast<struct submix_audio_device *>(reinterpret_cast<uint8_t *>(device) - |
| 154 | offsetof(struct submix_audio_device, device)); |
| 155 | } |
| 156 | |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 157 | /* audio HAL functions */ |
| 158 | |
| 159 | static uint32_t out_get_sample_rate(const struct audio_stream *stream) |
| 160 | { |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 161 | const struct submix_stream_out * const out = audio_stream_get_submix_stream_out( |
| 162 | const_cast<struct audio_stream *>(stream)); |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 163 | uint32_t out_rate = out->dev->config.rate; |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 164 | SUBMIX_ALOGV("out_get_sample_rate() returns %u", out_rate); |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 165 | return out_rate; |
| 166 | } |
| 167 | |
| 168 | static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate) |
| 169 | { |
| 170 | if ((rate != 44100) && (rate != 48000)) { |
| 171 | ALOGE("out_set_sample_rate(rate=%u) rate unsupported", rate); |
| 172 | return -ENOSYS; |
| 173 | } |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 174 | struct submix_stream_out * const out = audio_stream_get_submix_stream_out(stream); |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 175 | SUBMIX_ALOGV("out_set_sample_rate(rate=%u)", rate); |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 176 | out->dev->config.rate = rate; |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | static size_t out_get_buffer_size(const struct audio_stream *stream) |
| 181 | { |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 182 | const struct submix_stream_out * const out = audio_stream_get_submix_stream_out( |
| 183 | const_cast<struct audio_stream *>(stream)); |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 184 | const struct submix_config& config_out = out->dev->config; |
| 185 | size_t buffer_size = config_out.period_size * popcount(config_out.channel_mask) |
| 186 | * sizeof(int16_t); // only PCM 16bit |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 187 | SUBMIX_ALOGV("out_get_buffer_size() returns %u, period size=%u", |
| 188 | buffer_size, config_out.period_size); |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 189 | return buffer_size; |
| 190 | } |
| 191 | |
| 192 | static audio_channel_mask_t out_get_channels(const struct audio_stream *stream) |
| 193 | { |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 194 | const struct submix_stream_out * const out = audio_stream_get_submix_stream_out( |
| 195 | const_cast<struct audio_stream *>(stream)); |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 196 | uint32_t channels = out->dev->config.channel_mask; |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 197 | SUBMIX_ALOGV("out_get_channels() returns %08x", channels); |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 198 | return channels; |
| 199 | } |
| 200 | |
| 201 | static audio_format_t out_get_format(const struct audio_stream *stream) |
| 202 | { |
| 203 | return AUDIO_FORMAT_PCM_16_BIT; |
| 204 | } |
| 205 | |
| 206 | static int out_set_format(struct audio_stream *stream, audio_format_t format) |
| 207 | { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 208 | (void)stream; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 209 | if (format != AUDIO_FORMAT_PCM_16_BIT) { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 210 | ALOGE("out_set_format(format=%x) format unsupported", format); |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 211 | return -ENOSYS; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 212 | } |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 213 | SUBMIX_ALOGV("out_set_format(format=%x)", format); |
| 214 | return 0; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | static int out_standby(struct audio_stream *stream) |
| 218 | { |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 219 | struct submix_audio_device * const rsxadev = audio_stream_get_submix_stream_out(stream)->dev; |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 220 | ALOGI("out_standby()"); |
| 221 | |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 222 | pthread_mutex_lock(&rsxadev->lock); |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 223 | |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 224 | rsxadev->output_standby = true; |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 225 | |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 226 | pthread_mutex_unlock(&rsxadev->lock); |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 227 | |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 228 | return 0; |
| 229 | } |
| 230 | |
| 231 | static int out_dump(const struct audio_stream *stream, int fd) |
| 232 | { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 233 | (void)stream; |
| 234 | (void)fd; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 235 | return 0; |
| 236 | } |
| 237 | |
| 238 | static int out_set_parameters(struct audio_stream *stream, const char *kvpairs) |
| 239 | { |
Jean-Michel Trivi | d441303 | 2012-09-30 11:08:06 -0700 | [diff] [blame] | 240 | int exiting = -1; |
| 241 | AudioParameter parms = AudioParameter(String8(kvpairs)); |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 242 | SUBMIX_ALOGV("out_set_parameters() kvpairs='%s'", kvpairs); |
Jean-Michel Trivi | d441303 | 2012-09-30 11:08:06 -0700 | [diff] [blame] | 243 | // FIXME this is using hard-coded strings but in the future, this functionality will be |
| 244 | // converted to use audio HAL extensions required to support tunneling |
| 245 | if ((parms.getInt(String8("exiting"), exiting) == NO_ERROR) && (exiting > 0)) { |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 246 | struct submix_audio_device * const rsxadev = |
| 247 | audio_stream_get_submix_stream_out(stream)->dev; |
| 248 | pthread_mutex_lock(&rsxadev->lock); |
Jean-Michel Trivi | eafbfa4 | 2012-12-18 11:30:33 -0800 | [diff] [blame] | 249 | { // using the sink |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 250 | sp<MonoPipe> sink = rsxadev->rsxSink.get(); |
| 251 | if (sink == NULL) { |
| 252 | pthread_mutex_unlock(&rsxadev->lock); |
Jean-Michel Trivi | eafbfa4 | 2012-12-18 11:30:33 -0800 | [diff] [blame] | 253 | return 0; |
| 254 | } |
Jean-Michel Trivi | d441303 | 2012-09-30 11:08:06 -0700 | [diff] [blame] | 255 | |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 256 | ALOGI("out_set_parameters(): shutdown"); |
Jean-Michel Trivi | eafbfa4 | 2012-12-18 11:30:33 -0800 | [diff] [blame] | 257 | sink->shutdown(true); |
| 258 | } // done using the sink |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 259 | pthread_mutex_unlock(&rsxadev->lock); |
Jean-Michel Trivi | d441303 | 2012-09-30 11:08:06 -0700 | [diff] [blame] | 260 | } |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | static char * out_get_parameters(const struct audio_stream *stream, const char *keys) |
| 265 | { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 266 | (void)stream; |
| 267 | (void)keys; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 268 | return strdup(""); |
| 269 | } |
| 270 | |
| 271 | static uint32_t out_get_latency(const struct audio_stream_out *stream) |
| 272 | { |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 273 | const struct submix_stream_out * const out = audio_stream_out_get_submix_stream_out( |
| 274 | const_cast<struct audio_stream_out *>(stream)); |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 275 | const struct submix_config * config_out = &(out->dev->config); |
| 276 | uint32_t latency = (MAX_PIPE_DEPTH_IN_FRAMES * 1000) / config_out->rate; |
| 277 | ALOGV("out_get_latency() returns %u", latency); |
| 278 | return latency; |
| 279 | } |
| 280 | |
| 281 | static int out_set_volume(struct audio_stream_out *stream, float left, |
| 282 | float right) |
| 283 | { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 284 | (void)stream; |
| 285 | (void)left; |
| 286 | (void)right; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 287 | return -ENOSYS; |
| 288 | } |
| 289 | |
| 290 | static ssize_t out_write(struct audio_stream_out *stream, const void* buffer, |
| 291 | size_t bytes) |
| 292 | { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 293 | SUBMIX_ALOGV("out_write(bytes=%zd)", bytes); |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 294 | ssize_t written_frames = 0; |
Jean-Michel Trivi | 90b0fbd | 2012-10-30 19:03:22 -0700 | [diff] [blame] | 295 | const size_t frame_size = audio_stream_frame_size(&stream->common); |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 296 | struct submix_audio_device * const rsxadev = |
| 297 | audio_stream_out_get_submix_stream_out(stream)->dev; |
Jean-Michel Trivi | 90b0fbd | 2012-10-30 19:03:22 -0700 | [diff] [blame] | 298 | const size_t frames = bytes / frame_size; |
| 299 | |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 300 | pthread_mutex_lock(&rsxadev->lock); |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 301 | |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 302 | rsxadev->output_standby = false; |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 303 | |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 304 | sp<MonoPipe> sink = rsxadev->rsxSink.get(); |
| 305 | if (sink != NULL) { |
Jean-Michel Trivi | 90b0fbd | 2012-10-30 19:03:22 -0700 | [diff] [blame] | 306 | if (sink->isShutdown()) { |
Jean-Michel Trivi | eafbfa4 | 2012-12-18 11:30:33 -0800 | [diff] [blame] | 307 | sink.clear(); |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 308 | pthread_mutex_unlock(&rsxadev->lock); |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 309 | SUBMIX_ALOGV("out_write(): pipe shutdown, ignoring the write."); |
Jean-Michel Trivi | 90b0fbd | 2012-10-30 19:03:22 -0700 | [diff] [blame] | 310 | // the pipe has already been shutdown, this buffer will be lost but we must |
| 311 | // simulate timing so we don't drain the output faster than realtime |
| 312 | usleep(frames * 1000000 / out_get_sample_rate(&stream->common)); |
| 313 | return bytes; |
| 314 | } |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 315 | } else { |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 316 | pthread_mutex_unlock(&rsxadev->lock); |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 317 | ALOGE("out_write without a pipe!"); |
| 318 | ALOG_ASSERT("out_write without a pipe!"); |
| 319 | return 0; |
| 320 | } |
| 321 | |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 322 | pthread_mutex_unlock(&rsxadev->lock); |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 323 | |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 324 | written_frames = sink->write(buffer, frames); |
Jean-Michel Trivi | eafbfa4 | 2012-12-18 11:30:33 -0800 | [diff] [blame] | 325 | |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 326 | if (written_frames < 0) { |
| 327 | if (written_frames == (ssize_t)NEGOTIATE) { |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 328 | ALOGE("out_write() write to pipe returned NEGOTIATE"); |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 329 | |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 330 | pthread_mutex_lock(&rsxadev->lock); |
Jean-Michel Trivi | eafbfa4 | 2012-12-18 11:30:33 -0800 | [diff] [blame] | 331 | sink.clear(); |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 332 | pthread_mutex_unlock(&rsxadev->lock); |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 333 | |
| 334 | written_frames = 0; |
Jean-Michel Trivi | 6acd966 | 2012-09-11 19:19:08 -0700 | [diff] [blame] | 335 | return 0; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 336 | } else { |
| 337 | // write() returned UNDERRUN or WOULD_BLOCK, retry |
Colin Cross | 5685a08 | 2014-04-18 15:45:42 -0700 | [diff] [blame] | 338 | ALOGE("out_write() write to pipe returned unexpected %zd", written_frames); |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 339 | written_frames = sink->write(buffer, frames); |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 340 | } |
| 341 | } |
| 342 | |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 343 | pthread_mutex_lock(&rsxadev->lock); |
Jean-Michel Trivi | eafbfa4 | 2012-12-18 11:30:33 -0800 | [diff] [blame] | 344 | sink.clear(); |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 345 | pthread_mutex_unlock(&rsxadev->lock); |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 346 | |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 347 | if (written_frames < 0) { |
Colin Cross | 5685a08 | 2014-04-18 15:45:42 -0700 | [diff] [blame] | 348 | ALOGE("out_write() failed writing to pipe with %zd", written_frames); |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 349 | return 0; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 350 | } |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 351 | const ssize_t written_bytes = written_frames * frame_size; |
| 352 | SUBMIX_ALOGV("out_write() wrote %zd bytes %zd frames)", written_bytes, written_frames); |
| 353 | return written_bytes; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | static int out_get_render_position(const struct audio_stream_out *stream, |
| 357 | uint32_t *dsp_frames) |
| 358 | { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 359 | (void)stream; |
| 360 | (void)dsp_frames; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 361 | return -EINVAL; |
| 362 | } |
| 363 | |
| 364 | static int out_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect) |
| 365 | { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 366 | (void)stream; |
| 367 | (void)effect; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 368 | return 0; |
| 369 | } |
| 370 | |
| 371 | static int out_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect) |
| 372 | { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 373 | (void)stream; |
| 374 | (void)effect; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 375 | return 0; |
| 376 | } |
| 377 | |
| 378 | static int out_get_next_write_timestamp(const struct audio_stream_out *stream, |
| 379 | int64_t *timestamp) |
| 380 | { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 381 | (void)stream; |
| 382 | (void)timestamp; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 383 | return -EINVAL; |
| 384 | } |
| 385 | |
| 386 | /** audio_stream_in implementation **/ |
| 387 | static uint32_t in_get_sample_rate(const struct audio_stream *stream) |
| 388 | { |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 389 | const struct submix_stream_in * const in = audio_stream_get_submix_stream_in( |
| 390 | const_cast<struct audio_stream*>(stream)); |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 391 | SUBMIX_ALOGV("in_get_sample_rate() returns %u", in->dev->config.sample_rate); |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 392 | return in->dev->config.rate; |
| 393 | } |
| 394 | |
| 395 | static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate) |
| 396 | { |
| 397 | return -ENOSYS; |
| 398 | } |
| 399 | |
| 400 | static size_t in_get_buffer_size(const struct audio_stream *stream) |
| 401 | { |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 402 | const struct submix_stream_in * const in = audio_stream_get_submix_stream_in( |
| 403 | const_cast<struct audio_stream*>(stream)); |
Colin Cross | 5685a08 | 2014-04-18 15:45:42 -0700 | [diff] [blame] | 404 | ALOGV("in_get_buffer_size() returns %zu", |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 405 | in->dev->config.period_size * audio_stream_frame_size(stream)); |
| 406 | return in->dev->config.period_size * audio_stream_frame_size(stream); |
| 407 | } |
| 408 | |
| 409 | static audio_channel_mask_t in_get_channels(const struct audio_stream *stream) |
| 410 | { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 411 | (void)stream; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 412 | return AUDIO_CHANNEL_IN_STEREO; |
| 413 | } |
| 414 | |
| 415 | static audio_format_t in_get_format(const struct audio_stream *stream) |
| 416 | { |
| 417 | return AUDIO_FORMAT_PCM_16_BIT; |
| 418 | } |
| 419 | |
| 420 | static int in_set_format(struct audio_stream *stream, audio_format_t format) |
| 421 | { |
| 422 | if (format != AUDIO_FORMAT_PCM_16_BIT) { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 423 | ALOGE("in_set_format(format=%x) format unsupported", format); |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 424 | return -ENOSYS; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 425 | } |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 426 | SUBMIX_ALOGV("in_set_format(format=%x)", format); |
| 427 | return 0; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | static int in_standby(struct audio_stream *stream) |
| 431 | { |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 432 | struct submix_audio_device * const rsxadev = audio_stream_get_submix_stream_in(stream)->dev; |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 433 | ALOGI("in_standby()"); |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 434 | |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 435 | pthread_mutex_lock(&rsxadev->lock); |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 436 | |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 437 | rsxadev->input_standby = true; |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 438 | |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 439 | pthread_mutex_unlock(&rsxadev->lock); |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 440 | |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 441 | return 0; |
| 442 | } |
| 443 | |
| 444 | static int in_dump(const struct audio_stream *stream, int fd) |
| 445 | { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 446 | (void)stream; |
| 447 | (void)fd; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 448 | return 0; |
| 449 | } |
| 450 | |
| 451 | static int in_set_parameters(struct audio_stream *stream, const char *kvpairs) |
| 452 | { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 453 | (void)stream; |
| 454 | (void)kvpairs; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 455 | return 0; |
| 456 | } |
| 457 | |
| 458 | static char * in_get_parameters(const struct audio_stream *stream, |
| 459 | const char *keys) |
| 460 | { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 461 | (void)stream; |
| 462 | (void)keys; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 463 | return strdup(""); |
| 464 | } |
| 465 | |
| 466 | static int in_set_gain(struct audio_stream_in *stream, float gain) |
| 467 | { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 468 | (void)stream; |
| 469 | (void)gain; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 470 | return 0; |
| 471 | } |
| 472 | |
| 473 | static ssize_t in_read(struct audio_stream_in *stream, void* buffer, |
| 474 | size_t bytes) |
| 475 | { |
| 476 | ssize_t frames_read = -1977; |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 477 | struct submix_stream_in * const in = audio_stream_in_get_submix_stream_in(stream); |
| 478 | struct submix_audio_device * const rsxadev = in->dev; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 479 | const size_t frame_size = audio_stream_frame_size(&stream->common); |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 480 | const size_t frames_to_read = bytes / frame_size; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 481 | |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 482 | SUBMIX_ALOGV("in_read bytes=%zu", bytes); |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 483 | pthread_mutex_lock(&rsxadev->lock); |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 484 | |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 485 | const bool output_standby_transition = (in->output_standby != in->dev->output_standby); |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 486 | in->output_standby = rsxadev->output_standby; |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 487 | |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 488 | if (rsxadev->input_standby || output_standby_transition) { |
| 489 | rsxadev->input_standby = false; |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 490 | // keep track of when we exit input standby (== first read == start "real recording") |
| 491 | // or when we start recording silence, and reset projected time |
| 492 | int rc = clock_gettime(CLOCK_MONOTONIC, &in->record_start_time); |
| 493 | if (rc == 0) { |
| 494 | in->read_counter_frames = 0; |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | in->read_counter_frames += frames_to_read; |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 499 | size_t remaining_frames = frames_to_read; |
Jean-Michel Trivi | eafbfa4 | 2012-12-18 11:30:33 -0800 | [diff] [blame] | 500 | |
| 501 | { |
| 502 | // about to read from audio source |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 503 | sp<MonoPipeReader> source = rsxadev->rsxSource; |
| 504 | if (source == NULL) { |
Jean-Michel Trivi | eafbfa4 | 2012-12-18 11:30:33 -0800 | [diff] [blame] | 505 | ALOGE("no audio pipe yet we're trying to read!"); |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 506 | pthread_mutex_unlock(&rsxadev->lock); |
Jean-Michel Trivi | eafbfa4 | 2012-12-18 11:30:33 -0800 | [diff] [blame] | 507 | usleep((bytes / frame_size) * 1000000 / in_get_sample_rate(&stream->common)); |
| 508 | memset(buffer, 0, bytes); |
| 509 | return bytes; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 510 | } |
Jean-Michel Trivi | eafbfa4 | 2012-12-18 11:30:33 -0800 | [diff] [blame] | 511 | |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 512 | pthread_mutex_unlock(&rsxadev->lock); |
Jean-Michel Trivi | eafbfa4 | 2012-12-18 11:30:33 -0800 | [diff] [blame] | 513 | |
| 514 | // read the data from the pipe (it's non blocking) |
| 515 | int attempts = 0; |
| 516 | char* buff = (char*)buffer; |
| 517 | while ((remaining_frames > 0) && (attempts < MAX_READ_ATTEMPTS)) { |
| 518 | attempts++; |
| 519 | frames_read = source->read(buff, remaining_frames, AudioBufferProvider::kInvalidPTS); |
| 520 | if (frames_read > 0) { |
| 521 | remaining_frames -= frames_read; |
| 522 | buff += frames_read * frame_size; |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 523 | SUBMIX_ALOGV(" in_read (att=%d) got %zd frames, remaining=%zu", |
| 524 | attempts, frames_read, remaining_frames); |
Jean-Michel Trivi | eafbfa4 | 2012-12-18 11:30:33 -0800 | [diff] [blame] | 525 | } else { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 526 | SUBMIX_ALOGE(" in_read read returned %zd", frames_read); |
Jean-Michel Trivi | eafbfa4 | 2012-12-18 11:30:33 -0800 | [diff] [blame] | 527 | usleep(READ_ATTEMPT_SLEEP_MS * 1000); |
| 528 | } |
| 529 | } |
| 530 | // done using the source |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 531 | pthread_mutex_lock(&rsxadev->lock); |
Jean-Michel Trivi | eafbfa4 | 2012-12-18 11:30:33 -0800 | [diff] [blame] | 532 | source.clear(); |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 533 | pthread_mutex_unlock(&rsxadev->lock); |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 534 | } |
| 535 | |
Jean-Michel Trivi | 6acd966 | 2012-09-11 19:19:08 -0700 | [diff] [blame] | 536 | if (remaining_frames > 0) { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 537 | SUBMIX_ALOGV(" remaining_frames = %zu", remaining_frames); |
Jean-Michel Trivi | 6acd966 | 2012-09-11 19:19:08 -0700 | [diff] [blame] | 538 | memset(((char*)buffer)+ bytes - (remaining_frames * frame_size), 0, |
| 539 | remaining_frames * frame_size); |
Jean-Michel Trivi | 6acd966 | 2012-09-11 19:19:08 -0700 | [diff] [blame] | 540 | } |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 541 | |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 542 | // compute how much we need to sleep after reading the data by comparing the wall clock with |
| 543 | // the projected time at which we should return. |
| 544 | struct timespec time_after_read;// wall clock after reading from the pipe |
| 545 | struct timespec record_duration;// observed record duration |
| 546 | int rc = clock_gettime(CLOCK_MONOTONIC, &time_after_read); |
| 547 | const uint32_t sample_rate = in_get_sample_rate(&stream->common); |
| 548 | if (rc == 0) { |
| 549 | // for how long have we been recording? |
| 550 | record_duration.tv_sec = time_after_read.tv_sec - in->record_start_time.tv_sec; |
| 551 | record_duration.tv_nsec = time_after_read.tv_nsec - in->record_start_time.tv_nsec; |
| 552 | if (record_duration.tv_nsec < 0) { |
| 553 | record_duration.tv_sec--; |
| 554 | record_duration.tv_nsec += 1000000000; |
| 555 | } |
| 556 | |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 557 | // read_counter_frames contains the number of frames that have been read since the |
| 558 | // beginning of recording (including this call): it's converted to usec and compared to |
| 559 | // how long we've been recording for, which gives us how long we must wait to sync the |
| 560 | // projected recording time, and the observed recording time. |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 561 | long projected_vs_observed_offset_us = |
| 562 | ((int64_t)(in->read_counter_frames |
| 563 | - (record_duration.tv_sec*sample_rate))) |
| 564 | * 1000000 / sample_rate |
| 565 | - (record_duration.tv_nsec / 1000); |
| 566 | |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 567 | SUBMIX_ALOGV(" record duration %5lds %3ldms, will wait: %7ldus", |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 568 | record_duration.tv_sec, record_duration.tv_nsec/1000000, |
| 569 | projected_vs_observed_offset_us); |
| 570 | if (projected_vs_observed_offset_us > 0) { |
| 571 | usleep(projected_vs_observed_offset_us); |
| 572 | } |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 573 | } |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 574 | |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 575 | SUBMIX_ALOGV("in_read returns %zu", bytes); |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 576 | return bytes; |
| 577 | |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | static uint32_t in_get_input_frames_lost(struct audio_stream_in *stream) |
| 581 | { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 582 | (void)stream; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 583 | return 0; |
| 584 | } |
| 585 | |
| 586 | static int in_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect) |
| 587 | { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 588 | (void)stream; |
| 589 | (void)effect; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 590 | return 0; |
| 591 | } |
| 592 | |
| 593 | static int in_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect) |
| 594 | { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 595 | (void)stream; |
| 596 | (void)effect; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 597 | return 0; |
| 598 | } |
| 599 | |
| 600 | static int adev_open_output_stream(struct audio_hw_device *dev, |
| 601 | audio_io_handle_t handle, |
| 602 | audio_devices_t devices, |
| 603 | audio_output_flags_t flags, |
| 604 | struct audio_config *config, |
| 605 | struct audio_stream_out **stream_out) |
| 606 | { |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 607 | struct submix_audio_device * const rsxadev = audio_hw_device_get_submix_audio_device(dev); |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 608 | ALOGV("adev_open_output_stream()"); |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 609 | struct submix_stream_out *out; |
| 610 | int ret; |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 611 | (void)handle; |
| 612 | (void)devices; |
| 613 | (void)flags; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 614 | |
| 615 | out = (struct submix_stream_out *)calloc(1, sizeof(struct submix_stream_out)); |
| 616 | if (!out) { |
| 617 | ret = -ENOMEM; |
| 618 | goto err_open; |
| 619 | } |
| 620 | |
| 621 | pthread_mutex_lock(&rsxadev->lock); |
| 622 | |
| 623 | out->stream.common.get_sample_rate = out_get_sample_rate; |
| 624 | out->stream.common.set_sample_rate = out_set_sample_rate; |
| 625 | out->stream.common.get_buffer_size = out_get_buffer_size; |
| 626 | out->stream.common.get_channels = out_get_channels; |
| 627 | out->stream.common.get_format = out_get_format; |
| 628 | out->stream.common.set_format = out_set_format; |
| 629 | out->stream.common.standby = out_standby; |
| 630 | out->stream.common.dump = out_dump; |
| 631 | out->stream.common.set_parameters = out_set_parameters; |
| 632 | out->stream.common.get_parameters = out_get_parameters; |
| 633 | out->stream.common.add_audio_effect = out_add_audio_effect; |
| 634 | out->stream.common.remove_audio_effect = out_remove_audio_effect; |
| 635 | out->stream.get_latency = out_get_latency; |
| 636 | out->stream.set_volume = out_set_volume; |
| 637 | out->stream.write = out_write; |
| 638 | out->stream.get_render_position = out_get_render_position; |
| 639 | out->stream.get_next_write_timestamp = out_get_next_write_timestamp; |
| 640 | |
| 641 | config->channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 642 | rsxadev->config.channel_mask = config->channel_mask; |
| 643 | |
Eric Laurent | 9595f7c | 2013-08-22 09:55:13 -0700 | [diff] [blame] | 644 | if ((config->sample_rate != 48000) && (config->sample_rate != 44100)) { |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 645 | config->sample_rate = DEFAULT_RATE_HZ; |
| 646 | } |
| 647 | rsxadev->config.rate = config->sample_rate; |
| 648 | |
| 649 | config->format = AUDIO_FORMAT_PCM_16_BIT; |
| 650 | rsxadev->config.format = config->format; |
| 651 | |
| 652 | rsxadev->config.period_size = 1024; |
| 653 | rsxadev->config.period_count = 4; |
| 654 | out->dev = rsxadev; |
| 655 | |
| 656 | *stream_out = &out->stream; |
| 657 | |
| 658 | // initialize pipe |
| 659 | { |
| 660 | ALOGV(" initializing pipe"); |
Glenn Kasten | 0538a3e | 2014-03-07 08:26:16 -0800 | [diff] [blame] | 661 | const NBAIO_Format format = Format_from_SR_C(config->sample_rate, |
| 662 | popcount(config->channel_mask), config->format); |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 663 | const NBAIO_Format offers[1] = {format}; |
| 664 | size_t numCounterOffers = 0; |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 665 | // creating a MonoPipe with optional blocking set to true. |
| 666 | MonoPipe* sink = new MonoPipe(MAX_PIPE_DEPTH_IN_FRAMES, format, true/*writeCanBlock*/); |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 667 | ssize_t index = sink->negotiate(offers, 1, NULL, numCounterOffers); |
| 668 | ALOG_ASSERT(index == 0); |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 669 | MonoPipeReader* source = new MonoPipeReader(sink); |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 670 | numCounterOffers = 0; |
| 671 | index = source->negotiate(offers, 1, NULL, numCounterOffers); |
| 672 | ALOG_ASSERT(index == 0); |
| 673 | rsxadev->rsxSink = sink; |
| 674 | rsxadev->rsxSource = source; |
| 675 | } |
| 676 | |
| 677 | pthread_mutex_unlock(&rsxadev->lock); |
| 678 | |
| 679 | return 0; |
| 680 | |
| 681 | err_open: |
| 682 | *stream_out = NULL; |
| 683 | return ret; |
| 684 | } |
| 685 | |
| 686 | static void adev_close_output_stream(struct audio_hw_device *dev, |
| 687 | struct audio_stream_out *stream) |
| 688 | { |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 689 | struct submix_audio_device *rsxadev = audio_hw_device_get_submix_audio_device(dev); |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 690 | ALOGV("adev_close_output_stream()"); |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 691 | |
| 692 | pthread_mutex_lock(&rsxadev->lock); |
| 693 | |
| 694 | rsxadev->rsxSink.clear(); |
| 695 | rsxadev->rsxSource.clear(); |
| 696 | free(stream); |
| 697 | |
| 698 | pthread_mutex_unlock(&rsxadev->lock); |
| 699 | } |
| 700 | |
| 701 | static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs) |
| 702 | { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 703 | (void)dev; |
| 704 | (void)kvpairs; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 705 | return -ENOSYS; |
| 706 | } |
| 707 | |
| 708 | static char * adev_get_parameters(const struct audio_hw_device *dev, |
| 709 | const char *keys) |
| 710 | { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 711 | (void)dev; |
| 712 | (void)keys; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 713 | return strdup("");; |
| 714 | } |
| 715 | |
| 716 | static int adev_init_check(const struct audio_hw_device *dev) |
| 717 | { |
| 718 | ALOGI("adev_init_check()"); |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 719 | (void)dev; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 720 | return 0; |
| 721 | } |
| 722 | |
| 723 | static int adev_set_voice_volume(struct audio_hw_device *dev, float volume) |
| 724 | { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 725 | (void)dev; |
| 726 | (void)volume; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 727 | return -ENOSYS; |
| 728 | } |
| 729 | |
| 730 | static int adev_set_master_volume(struct audio_hw_device *dev, float volume) |
| 731 | { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 732 | (void)dev; |
| 733 | (void)volume; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 734 | return -ENOSYS; |
| 735 | } |
| 736 | |
| 737 | static int adev_get_master_volume(struct audio_hw_device *dev, float *volume) |
| 738 | { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 739 | (void)dev; |
| 740 | (void)volume; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 741 | return -ENOSYS; |
| 742 | } |
| 743 | |
| 744 | static int adev_set_master_mute(struct audio_hw_device *dev, bool muted) |
| 745 | { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 746 | (void)dev; |
| 747 | (void)muted; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 748 | return -ENOSYS; |
| 749 | } |
| 750 | |
| 751 | static int adev_get_master_mute(struct audio_hw_device *dev, bool *muted) |
| 752 | { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 753 | (void)dev; |
| 754 | (void)muted; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 755 | return -ENOSYS; |
| 756 | } |
| 757 | |
| 758 | static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode) |
| 759 | { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 760 | (void)dev; |
| 761 | (void)mode; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 762 | return 0; |
| 763 | } |
| 764 | |
| 765 | static int adev_set_mic_mute(struct audio_hw_device *dev, bool state) |
| 766 | { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 767 | (void)dev; |
| 768 | (void)state; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 769 | return -ENOSYS; |
| 770 | } |
| 771 | |
| 772 | static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state) |
| 773 | { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 774 | (void)dev; |
| 775 | (void)state; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 776 | return -ENOSYS; |
| 777 | } |
| 778 | |
| 779 | static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev, |
| 780 | const struct audio_config *config) |
| 781 | { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 782 | (void)dev; |
| 783 | (void)config; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 784 | //### TODO correlate this with pipe parameters |
| 785 | return 4096; |
| 786 | } |
| 787 | |
| 788 | static int adev_open_input_stream(struct audio_hw_device *dev, |
| 789 | audio_io_handle_t handle, |
| 790 | audio_devices_t devices, |
| 791 | struct audio_config *config, |
| 792 | struct audio_stream_in **stream_in) |
| 793 | { |
| 794 | ALOGI("adev_open_input_stream()"); |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 795 | struct submix_audio_device *rsxadev = audio_hw_device_get_submix_audio_device(dev); |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 796 | struct submix_stream_in *in; |
| 797 | int ret; |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 798 | (void)handle; |
| 799 | (void)devices; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 800 | |
| 801 | in = (struct submix_stream_in *)calloc(1, sizeof(struct submix_stream_in)); |
| 802 | if (!in) { |
| 803 | ret = -ENOMEM; |
| 804 | goto err_open; |
| 805 | } |
| 806 | |
| 807 | pthread_mutex_lock(&rsxadev->lock); |
| 808 | |
| 809 | in->stream.common.get_sample_rate = in_get_sample_rate; |
| 810 | in->stream.common.set_sample_rate = in_set_sample_rate; |
| 811 | in->stream.common.get_buffer_size = in_get_buffer_size; |
| 812 | in->stream.common.get_channels = in_get_channels; |
| 813 | in->stream.common.get_format = in_get_format; |
| 814 | in->stream.common.set_format = in_set_format; |
| 815 | in->stream.common.standby = in_standby; |
| 816 | in->stream.common.dump = in_dump; |
| 817 | in->stream.common.set_parameters = in_set_parameters; |
| 818 | in->stream.common.get_parameters = in_get_parameters; |
| 819 | in->stream.common.add_audio_effect = in_add_audio_effect; |
| 820 | in->stream.common.remove_audio_effect = in_remove_audio_effect; |
| 821 | in->stream.set_gain = in_set_gain; |
| 822 | in->stream.read = in_read; |
| 823 | in->stream.get_input_frames_lost = in_get_input_frames_lost; |
| 824 | |
| 825 | config->channel_mask = AUDIO_CHANNEL_IN_STEREO; |
| 826 | rsxadev->config.channel_mask = config->channel_mask; |
| 827 | |
Eric Laurent | 9595f7c | 2013-08-22 09:55:13 -0700 | [diff] [blame] | 828 | if ((config->sample_rate != 48000) && (config->sample_rate != 44100)) { |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 829 | config->sample_rate = DEFAULT_RATE_HZ; |
| 830 | } |
| 831 | rsxadev->config.rate = config->sample_rate; |
| 832 | |
| 833 | config->format = AUDIO_FORMAT_PCM_16_BIT; |
| 834 | rsxadev->config.format = config->format; |
| 835 | |
| 836 | rsxadev->config.period_size = 1024; |
| 837 | rsxadev->config.period_count = 4; |
| 838 | |
| 839 | *stream_in = &in->stream; |
| 840 | |
| 841 | in->dev = rsxadev; |
| 842 | |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 843 | in->read_counter_frames = 0; |
| 844 | in->output_standby = rsxadev->output_standby; |
| 845 | |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 846 | pthread_mutex_unlock(&rsxadev->lock); |
| 847 | |
| 848 | return 0; |
| 849 | |
| 850 | err_open: |
| 851 | *stream_in = NULL; |
| 852 | return ret; |
| 853 | } |
| 854 | |
| 855 | static void adev_close_input_stream(struct audio_hw_device *dev, |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 856 | struct audio_stream_in *stream) |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 857 | { |
Stewart Miles | f645c5e | 2014-05-01 09:03:27 -0700 | [diff] [blame^] | 858 | struct submix_audio_device *rsxadev = audio_hw_device_get_submix_audio_device(dev); |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 859 | ALOGV("adev_close_input_stream()"); |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 860 | |
| 861 | pthread_mutex_lock(&rsxadev->lock); |
| 862 | |
Jean-Michel Trivi | 90b0fbd | 2012-10-30 19:03:22 -0700 | [diff] [blame] | 863 | MonoPipe* sink = rsxadev->rsxSink.get(); |
| 864 | if (sink != NULL) { |
| 865 | ALOGI("shutdown"); |
| 866 | sink->shutdown(true); |
| 867 | } |
| 868 | |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 869 | free(stream); |
| 870 | |
| 871 | pthread_mutex_unlock(&rsxadev->lock); |
| 872 | } |
| 873 | |
| 874 | static int adev_dump(const audio_hw_device_t *device, int fd) |
| 875 | { |
Stewart Miles | c049a0a | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 876 | (void)device; |
| 877 | (void)fd; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 878 | return 0; |
| 879 | } |
| 880 | |
| 881 | static int adev_close(hw_device_t *device) |
| 882 | { |
| 883 | ALOGI("adev_close()"); |
| 884 | free(device); |
| 885 | return 0; |
| 886 | } |
| 887 | |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 888 | static int adev_open(const hw_module_t* module, const char* name, |
| 889 | hw_device_t** device) |
| 890 | { |
| 891 | ALOGI("adev_open(name=%s)", name); |
| 892 | struct submix_audio_device *rsxadev; |
| 893 | |
| 894 | if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) |
| 895 | return -EINVAL; |
| 896 | |
| 897 | rsxadev = (submix_audio_device*) calloc(1, sizeof(struct submix_audio_device)); |
| 898 | if (!rsxadev) |
| 899 | return -ENOMEM; |
| 900 | |
| 901 | rsxadev->device.common.tag = HARDWARE_DEVICE_TAG; |
Eric Laurent | 5d85c53 | 2012-09-10 10:36:09 -0700 | [diff] [blame] | 902 | rsxadev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0; |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 903 | rsxadev->device.common.module = (struct hw_module_t *) module; |
| 904 | rsxadev->device.common.close = adev_close; |
| 905 | |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 906 | rsxadev->device.init_check = adev_init_check; |
| 907 | rsxadev->device.set_voice_volume = adev_set_voice_volume; |
| 908 | rsxadev->device.set_master_volume = adev_set_master_volume; |
| 909 | rsxadev->device.get_master_volume = adev_get_master_volume; |
| 910 | rsxadev->device.set_master_mute = adev_set_master_mute; |
| 911 | rsxadev->device.get_master_mute = adev_get_master_mute; |
| 912 | rsxadev->device.set_mode = adev_set_mode; |
| 913 | rsxadev->device.set_mic_mute = adev_set_mic_mute; |
| 914 | rsxadev->device.get_mic_mute = adev_get_mic_mute; |
| 915 | rsxadev->device.set_parameters = adev_set_parameters; |
| 916 | rsxadev->device.get_parameters = adev_get_parameters; |
| 917 | rsxadev->device.get_input_buffer_size = adev_get_input_buffer_size; |
| 918 | rsxadev->device.open_output_stream = adev_open_output_stream; |
| 919 | rsxadev->device.close_output_stream = adev_close_output_stream; |
| 920 | rsxadev->device.open_input_stream = adev_open_input_stream; |
| 921 | rsxadev->device.close_input_stream = adev_close_input_stream; |
| 922 | rsxadev->device.dump = adev_dump; |
| 923 | |
Jean-Michel Trivi | eec8770 | 2012-09-17 09:59:42 -0700 | [diff] [blame] | 924 | rsxadev->input_standby = true; |
| 925 | rsxadev->output_standby = true; |
| 926 | |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 927 | *device = &rsxadev->device.common; |
| 928 | |
| 929 | return 0; |
| 930 | } |
| 931 | |
| 932 | static struct hw_module_methods_t hal_module_methods = { |
| 933 | /* open */ adev_open, |
| 934 | }; |
| 935 | |
| 936 | struct audio_module HAL_MODULE_INFO_SYM = { |
| 937 | /* common */ { |
| 938 | /* tag */ HARDWARE_MODULE_TAG, |
| 939 | /* module_api_version */ AUDIO_MODULE_API_VERSION_0_1, |
| 940 | /* hal_api_version */ HARDWARE_HAL_API_VERSION, |
| 941 | /* id */ AUDIO_HARDWARE_MODULE_ID, |
| 942 | /* name */ "Wifi Display audio HAL", |
| 943 | /* author */ "The Android Open Source Project", |
| 944 | /* methods */ &hal_module_methods, |
| 945 | /* dso */ NULL, |
| 946 | /* reserved */ { 0 }, |
| 947 | }, |
| 948 | }; |
| 949 | |
| 950 | } //namespace android |
| 951 | |
| 952 | } //extern "C" |