Nicolas Roulet | dcdfaec | 2017-02-14 10:18:39 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 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 | #ifndef ANDROID_IAUDIOFLINGER_H |
| 18 | #define ANDROID_IAUDIOFLINGER_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | #include <unistd.h> |
| 23 | |
| 24 | #include <utils/RefBase.h> |
| 25 | #include <utils/Errors.h> |
| 26 | #include <binder/IInterface.h> |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 27 | #include <binder/Parcel.h> |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 28 | #include <binder/Parcelable.h> |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 29 | #include <media/AudioClient.h> |
jiabin | 4381040 | 2019-10-24 14:58:31 -0700 | [diff] [blame] | 30 | #include <media/DeviceDescriptorBase.h> |
Nicolas Roulet | dcdfaec | 2017-02-14 10:18:39 -0800 | [diff] [blame] | 31 | #include <media/IAudioTrack.h> |
Nicolas Roulet | dcdfaec | 2017-02-14 10:18:39 -0800 | [diff] [blame] | 32 | #include <media/IAudioFlingerClient.h> |
| 33 | #include <system/audio.h> |
| 34 | #include <system/audio_effect.h> |
| 35 | #include <system/audio_policy.h> |
| 36 | #include <media/IEffect.h> |
| 37 | #include <media/IEffectClient.h> |
| 38 | #include <utils/String8.h> |
jiabin | 46a76fa | 2018-01-05 10:18:21 -0800 | [diff] [blame] | 39 | #include <media/MicrophoneInfo.h> |
| 40 | #include <vector> |
Nicolas Roulet | dcdfaec | 2017-02-14 10:18:39 -0800 | [diff] [blame] | 41 | |
Ivan Lozano | ff6900d | 2017-08-01 15:47:38 -0700 | [diff] [blame] | 42 | #include "android/media/IAudioRecord.h" |
jiabin | f6eb4c3 | 2020-02-25 14:06:25 -0800 | [diff] [blame] | 43 | #include "android/media/IAudioTrackCallback.h" |
Ivan Lozano | ff6900d | 2017-08-01 15:47:38 -0700 | [diff] [blame] | 44 | |
Nicolas Roulet | dcdfaec | 2017-02-14 10:18:39 -0800 | [diff] [blame] | 45 | namespace android { |
| 46 | |
| 47 | // ---------------------------------------------------------------------------- |
| 48 | |
| 49 | class IAudioFlinger : public IInterface |
| 50 | { |
| 51 | public: |
| 52 | DECLARE_META_INTERFACE(AudioFlinger); |
| 53 | |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 54 | /* CreateTrackInput contains all input arguments sent by AudioTrack to AudioFlinger |
| 55 | * when calling createTrack() including arguments that will be updated by AudioFlinger |
| 56 | * and returned in CreateTrackOutput object |
| 57 | */ |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 58 | class CreateTrackInput : public Parcelable { |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 59 | public: |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 60 | status_t readFromParcel(const Parcel *parcel) override { |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 61 | /* input arguments*/ |
| 62 | memset(&attr, 0, sizeof(audio_attributes_t)); |
| 63 | if (parcel->read(&attr, sizeof(audio_attributes_t)) != NO_ERROR) { |
| 64 | return DEAD_OBJECT; |
| 65 | } |
| 66 | attr.tags[AUDIO_ATTRIBUTES_TAGS_MAX_SIZE -1] = '\0'; |
| 67 | memset(&config, 0, sizeof(audio_config_t)); |
| 68 | if (parcel->read(&config, sizeof(audio_config_t)) != NO_ERROR) { |
| 69 | return DEAD_OBJECT; |
| 70 | } |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 71 | if (clientInfo.readFromParcel(parcel) != NO_ERROR) { |
| 72 | return DEAD_OBJECT; |
| 73 | } |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 74 | if (parcel->readInt32() != 0) { |
Ytai Ben-Tsvi | 7dd3972 | 2019-09-05 15:14:30 -0700 | [diff] [blame] | 75 | // TODO: Using unsecurePointer() has some associated security |
| 76 | // pitfalls (see declaration for details). |
| 77 | // Either document why it is safe in this case or address |
| 78 | // the issue (e.g. by copying). |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 79 | sharedBuffer = interface_cast<IMemory>(parcel->readStrongBinder()); |
Ytai Ben-Tsvi | 7dd3972 | 2019-09-05 15:14:30 -0700 | [diff] [blame] | 80 | if (sharedBuffer == 0 || sharedBuffer->unsecurePointer() == NULL) { |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 81 | return BAD_VALUE; |
| 82 | } |
| 83 | } |
| 84 | notificationsPerBuffer = parcel->readInt32(); |
| 85 | speed = parcel->readFloat(); |
jiabin | f6eb4c3 | 2020-02-25 14:06:25 -0800 | [diff] [blame] | 86 | audioTrackCallback = interface_cast<media::IAudioTrackCallback>( |
| 87 | parcel->readStrongBinder()); |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 88 | |
| 89 | /* input/output arguments*/ |
| 90 | (void)parcel->read(&flags, sizeof(audio_output_flags_t)); |
| 91 | frameCount = parcel->readInt64(); |
| 92 | notificationFrameCount = parcel->readInt64(); |
| 93 | (void)parcel->read(&selectedDeviceId, sizeof(audio_port_handle_t)); |
| 94 | (void)parcel->read(&sessionId, sizeof(audio_session_t)); |
| 95 | return NO_ERROR; |
| 96 | } |
| 97 | |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 98 | status_t writeToParcel(Parcel *parcel) const override { |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 99 | /* input arguments*/ |
| 100 | (void)parcel->write(&attr, sizeof(audio_attributes_t)); |
| 101 | (void)parcel->write(&config, sizeof(audio_config_t)); |
| 102 | (void)clientInfo.writeToParcel(parcel); |
| 103 | if (sharedBuffer != 0) { |
| 104 | (void)parcel->writeInt32(1); |
| 105 | (void)parcel->writeStrongBinder(IInterface::asBinder(sharedBuffer)); |
| 106 | } else { |
| 107 | (void)parcel->writeInt32(0); |
| 108 | } |
| 109 | (void)parcel->writeInt32(notificationsPerBuffer); |
| 110 | (void)parcel->writeFloat(speed); |
jiabin | f6eb4c3 | 2020-02-25 14:06:25 -0800 | [diff] [blame] | 111 | (void)parcel->writeStrongBinder(IInterface::asBinder(audioTrackCallback)); |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 112 | |
| 113 | /* input/output arguments*/ |
| 114 | (void)parcel->write(&flags, sizeof(audio_output_flags_t)); |
| 115 | (void)parcel->writeInt64(frameCount); |
| 116 | (void)parcel->writeInt64(notificationFrameCount); |
| 117 | (void)parcel->write(&selectedDeviceId, sizeof(audio_port_handle_t)); |
| 118 | (void)parcel->write(&sessionId, sizeof(audio_session_t)); |
| 119 | return NO_ERROR; |
| 120 | } |
| 121 | |
| 122 | /* input */ |
| 123 | audio_attributes_t attr; |
| 124 | audio_config_t config; |
| 125 | AudioClient clientInfo; |
| 126 | sp<IMemory> sharedBuffer; |
| 127 | uint32_t notificationsPerBuffer; |
| 128 | float speed; |
jiabin | f6eb4c3 | 2020-02-25 14:06:25 -0800 | [diff] [blame] | 129 | sp<media::IAudioTrackCallback> audioTrackCallback; |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 130 | |
| 131 | /* input/output */ |
| 132 | audio_output_flags_t flags; |
| 133 | size_t frameCount; |
| 134 | size_t notificationFrameCount; |
| 135 | audio_port_handle_t selectedDeviceId; |
| 136 | audio_session_t sessionId; |
| 137 | }; |
| 138 | |
| 139 | /* CreateTrackOutput contains all output arguments returned by AudioFlinger to AudioTrack |
| 140 | * when calling createTrack() including arguments that were passed as I/O for update by |
| 141 | * CreateTrackInput. |
| 142 | */ |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 143 | class CreateTrackOutput : public Parcelable { |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 144 | public: |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 145 | status_t readFromParcel(const Parcel *parcel) override { |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 146 | /* input/output arguments*/ |
| 147 | (void)parcel->read(&flags, sizeof(audio_output_flags_t)); |
| 148 | frameCount = parcel->readInt64(); |
| 149 | notificationFrameCount = parcel->readInt64(); |
| 150 | (void)parcel->read(&selectedDeviceId, sizeof(audio_port_handle_t)); |
| 151 | (void)parcel->read(&sessionId, sizeof(audio_session_t)); |
| 152 | |
| 153 | /* output arguments*/ |
| 154 | sampleRate = parcel->readUint32(); |
| 155 | afFrameCount = parcel->readInt64(); |
| 156 | afSampleRate = parcel->readInt64(); |
| 157 | afLatencyMs = parcel->readInt32(); |
| 158 | (void)parcel->read(&outputId, sizeof(audio_io_handle_t)); |
Eric Laurent | 973db02 | 2018-11-20 14:54:31 -0800 | [diff] [blame] | 159 | (void)parcel->read(&portId, sizeof(audio_port_handle_t)); |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 160 | return NO_ERROR; |
| 161 | } |
| 162 | |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 163 | status_t writeToParcel(Parcel *parcel) const override { |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 164 | /* input/output arguments*/ |
| 165 | (void)parcel->write(&flags, sizeof(audio_output_flags_t)); |
| 166 | (void)parcel->writeInt64(frameCount); |
| 167 | (void)parcel->writeInt64(notificationFrameCount); |
| 168 | (void)parcel->write(&selectedDeviceId, sizeof(audio_port_handle_t)); |
| 169 | (void)parcel->write(&sessionId, sizeof(audio_session_t)); |
| 170 | |
| 171 | /* output arguments*/ |
| 172 | (void)parcel->writeUint32(sampleRate); |
| 173 | (void)parcel->writeInt64(afFrameCount); |
| 174 | (void)parcel->writeInt64(afSampleRate); |
| 175 | (void)parcel->writeInt32(afLatencyMs); |
| 176 | (void)parcel->write(&outputId, sizeof(audio_io_handle_t)); |
Eric Laurent | 973db02 | 2018-11-20 14:54:31 -0800 | [diff] [blame] | 177 | (void)parcel->write(&portId, sizeof(audio_port_handle_t)); |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 178 | return NO_ERROR; |
| 179 | } |
| 180 | |
| 181 | /* input/output */ |
| 182 | audio_output_flags_t flags; |
| 183 | size_t frameCount; |
| 184 | size_t notificationFrameCount; |
| 185 | audio_port_handle_t selectedDeviceId; |
| 186 | audio_session_t sessionId; |
| 187 | |
| 188 | /* output */ |
| 189 | uint32_t sampleRate; |
| 190 | size_t afFrameCount; |
| 191 | uint32_t afSampleRate; |
| 192 | uint32_t afLatencyMs; |
| 193 | audio_io_handle_t outputId; |
Eric Laurent | 973db02 | 2018-11-20 14:54:31 -0800 | [diff] [blame] | 194 | audio_port_handle_t portId; |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 195 | }; |
Nicolas Roulet | dcdfaec | 2017-02-14 10:18:39 -0800 | [diff] [blame] | 196 | |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 197 | /* CreateRecordInput contains all input arguments sent by AudioRecord to AudioFlinger |
| 198 | * when calling createRecord() including arguments that will be updated by AudioFlinger |
| 199 | * and returned in CreateRecordOutput object |
| 200 | */ |
| 201 | class CreateRecordInput : public Parcelable { |
| 202 | public: |
| 203 | status_t readFromParcel(const Parcel *parcel) override { |
| 204 | /* input arguments*/ |
| 205 | memset(&attr, 0, sizeof(audio_attributes_t)); |
| 206 | if (parcel->read(&attr, sizeof(audio_attributes_t)) != NO_ERROR) { |
| 207 | return DEAD_OBJECT; |
| 208 | } |
| 209 | attr.tags[AUDIO_ATTRIBUTES_TAGS_MAX_SIZE -1] = '\0'; |
| 210 | memset(&config, 0, sizeof(audio_config_base_t)); |
| 211 | if (parcel->read(&config, sizeof(audio_config_base_t)) != NO_ERROR) { |
| 212 | return DEAD_OBJECT; |
| 213 | } |
| 214 | if (clientInfo.readFromParcel(parcel) != NO_ERROR) { |
| 215 | return DEAD_OBJECT; |
| 216 | } |
| 217 | opPackageName = parcel->readString16(); |
Mikhail Naganov | 2996f67 | 2019-04-18 12:29:59 -0700 | [diff] [blame] | 218 | if (parcel->read(&riid, sizeof(audio_unique_id_t)) != NO_ERROR) { |
| 219 | return DEAD_OBJECT; |
| 220 | } |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 221 | |
| 222 | /* input/output arguments*/ |
| 223 | (void)parcel->read(&flags, sizeof(audio_input_flags_t)); |
| 224 | frameCount = parcel->readInt64(); |
| 225 | notificationFrameCount = parcel->readInt64(); |
| 226 | (void)parcel->read(&selectedDeviceId, sizeof(audio_port_handle_t)); |
| 227 | (void)parcel->read(&sessionId, sizeof(audio_session_t)); |
| 228 | return NO_ERROR; |
| 229 | } |
| 230 | |
| 231 | status_t writeToParcel(Parcel *parcel) const override { |
| 232 | /* input arguments*/ |
| 233 | (void)parcel->write(&attr, sizeof(audio_attributes_t)); |
| 234 | (void)parcel->write(&config, sizeof(audio_config_base_t)); |
| 235 | (void)clientInfo.writeToParcel(parcel); |
| 236 | (void)parcel->writeString16(opPackageName); |
Mikhail Naganov | 2996f67 | 2019-04-18 12:29:59 -0700 | [diff] [blame] | 237 | (void)parcel->write(&riid, sizeof(audio_unique_id_t)); |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 238 | |
| 239 | /* input/output arguments*/ |
| 240 | (void)parcel->write(&flags, sizeof(audio_input_flags_t)); |
| 241 | (void)parcel->writeInt64(frameCount); |
| 242 | (void)parcel->writeInt64(notificationFrameCount); |
| 243 | (void)parcel->write(&selectedDeviceId, sizeof(audio_port_handle_t)); |
| 244 | (void)parcel->write(&sessionId, sizeof(audio_session_t)); |
| 245 | return NO_ERROR; |
| 246 | } |
| 247 | |
| 248 | /* input */ |
| 249 | audio_attributes_t attr; |
| 250 | audio_config_base_t config; |
| 251 | AudioClient clientInfo; |
| 252 | String16 opPackageName; |
Mikhail Naganov | 2996f67 | 2019-04-18 12:29:59 -0700 | [diff] [blame] | 253 | audio_unique_id_t riid; |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 254 | |
| 255 | /* input/output */ |
| 256 | audio_input_flags_t flags; |
| 257 | size_t frameCount; |
| 258 | size_t notificationFrameCount; |
| 259 | audio_port_handle_t selectedDeviceId; |
| 260 | audio_session_t sessionId; |
| 261 | }; |
| 262 | |
| 263 | /* CreateRecordOutput contains all output arguments returned by AudioFlinger to AudioRecord |
| 264 | * when calling createRecord() including arguments that were passed as I/O for update by |
| 265 | * CreateRecordInput. |
| 266 | */ |
| 267 | class CreateRecordOutput : public Parcelable { |
| 268 | public: |
| 269 | status_t readFromParcel(const Parcel *parcel) override { |
| 270 | /* input/output arguments*/ |
| 271 | (void)parcel->read(&flags, sizeof(audio_input_flags_t)); |
| 272 | frameCount = parcel->readInt64(); |
| 273 | notificationFrameCount = parcel->readInt64(); |
| 274 | (void)parcel->read(&selectedDeviceId, sizeof(audio_port_handle_t)); |
| 275 | (void)parcel->read(&sessionId, sizeof(audio_session_t)); |
| 276 | |
| 277 | /* output arguments*/ |
| 278 | sampleRate = parcel->readUint32(); |
| 279 | (void)parcel->read(&inputId, sizeof(audio_io_handle_t)); |
| 280 | if (parcel->readInt32() != 0) { |
| 281 | cblk = interface_cast<IMemory>(parcel->readStrongBinder()); |
Ytai Ben-Tsvi | 7dd3972 | 2019-09-05 15:14:30 -0700 | [diff] [blame] | 282 | // TODO: Using unsecurePointer() has some associated security |
| 283 | // pitfalls (see declaration for details). |
| 284 | // Either document why it is safe in this case or address |
| 285 | // the issue (e.g. by copying). |
| 286 | if (cblk == 0 || cblk->unsecurePointer() == NULL) { |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 287 | return BAD_VALUE; |
| 288 | } |
| 289 | } |
| 290 | if (parcel->readInt32() != 0) { |
| 291 | buffers = interface_cast<IMemory>(parcel->readStrongBinder()); |
Ytai Ben-Tsvi | 7dd3972 | 2019-09-05 15:14:30 -0700 | [diff] [blame] | 292 | // TODO: Using unsecurePointer() has some associated security |
| 293 | // pitfalls (see declaration for details). |
| 294 | // Either document why it is safe in this case or address |
| 295 | // the issue (e.g. by copying). |
| 296 | if (buffers == 0 || buffers->unsecurePointer() == NULL) { |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 297 | return BAD_VALUE; |
| 298 | } |
| 299 | } |
Eric Laurent | 973db02 | 2018-11-20 14:54:31 -0800 | [diff] [blame] | 300 | (void)parcel->read(&portId, sizeof(audio_port_handle_t)); |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 301 | return NO_ERROR; |
| 302 | } |
| 303 | |
| 304 | status_t writeToParcel(Parcel *parcel) const override { |
| 305 | /* input/output arguments*/ |
| 306 | (void)parcel->write(&flags, sizeof(audio_input_flags_t)); |
| 307 | (void)parcel->writeInt64(frameCount); |
| 308 | (void)parcel->writeInt64(notificationFrameCount); |
| 309 | (void)parcel->write(&selectedDeviceId, sizeof(audio_port_handle_t)); |
| 310 | (void)parcel->write(&sessionId, sizeof(audio_session_t)); |
| 311 | |
| 312 | /* output arguments*/ |
| 313 | (void)parcel->writeUint32(sampleRate); |
| 314 | (void)parcel->write(&inputId, sizeof(audio_io_handle_t)); |
| 315 | if (cblk != 0) { |
| 316 | (void)parcel->writeInt32(1); |
| 317 | (void)parcel->writeStrongBinder(IInterface::asBinder(cblk)); |
| 318 | } else { |
| 319 | (void)parcel->writeInt32(0); |
| 320 | } |
| 321 | if (buffers != 0) { |
| 322 | (void)parcel->writeInt32(1); |
| 323 | (void)parcel->writeStrongBinder(IInterface::asBinder(buffers)); |
| 324 | } else { |
| 325 | (void)parcel->writeInt32(0); |
| 326 | } |
Eric Laurent | 973db02 | 2018-11-20 14:54:31 -0800 | [diff] [blame] | 327 | (void)parcel->write(&portId, sizeof(audio_port_handle_t)); |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 328 | |
| 329 | return NO_ERROR; |
| 330 | } |
| 331 | |
| 332 | /* input/output */ |
| 333 | audio_input_flags_t flags; |
| 334 | size_t frameCount; |
| 335 | size_t notificationFrameCount; |
| 336 | audio_port_handle_t selectedDeviceId; |
| 337 | audio_session_t sessionId; |
| 338 | |
| 339 | /* output */ |
| 340 | uint32_t sampleRate; |
| 341 | audio_io_handle_t inputId; |
| 342 | sp<IMemory> cblk; |
| 343 | sp<IMemory> buffers; |
Eric Laurent | 973db02 | 2018-11-20 14:54:31 -0800 | [diff] [blame] | 344 | audio_port_handle_t portId; |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 345 | }; |
| 346 | |
Nicolas Roulet | dcdfaec | 2017-02-14 10:18:39 -0800 | [diff] [blame] | 347 | // invariant on exit for all APIs that return an sp<>: |
| 348 | // (return value != 0) == (*status == NO_ERROR) |
| 349 | |
| 350 | /* create an audio track and registers it with AudioFlinger. |
| 351 | * return null if the track cannot be created. |
| 352 | */ |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 353 | virtual sp<IAudioTrack> createTrack(const CreateTrackInput& input, |
| 354 | CreateTrackOutput& output, |
| 355 | status_t *status) = 0; |
Nicolas Roulet | dcdfaec | 2017-02-14 10:18:39 -0800 | [diff] [blame] | 356 | |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 357 | virtual sp<media::IAudioRecord> createRecord(const CreateRecordInput& input, |
| 358 | CreateRecordOutput& output, |
| 359 | status_t *status) = 0; |
Nicolas Roulet | dcdfaec | 2017-02-14 10:18:39 -0800 | [diff] [blame] | 360 | |
| 361 | // FIXME Surprisingly, format/latency don't work for input handles |
| 362 | |
| 363 | /* query the audio hardware state. This state never changes, |
| 364 | * and therefore can be cached. |
| 365 | */ |
| 366 | virtual uint32_t sampleRate(audio_io_handle_t ioHandle) const = 0; |
| 367 | |
| 368 | // reserved; formerly channelCount() |
| 369 | |
| 370 | virtual audio_format_t format(audio_io_handle_t output) const = 0; |
| 371 | virtual size_t frameCount(audio_io_handle_t ioHandle) const = 0; |
| 372 | |
| 373 | // return estimated latency in milliseconds |
| 374 | virtual uint32_t latency(audio_io_handle_t output) const = 0; |
| 375 | |
| 376 | /* set/get the audio hardware state. This will probably be used by |
| 377 | * the preference panel, mostly. |
| 378 | */ |
| 379 | virtual status_t setMasterVolume(float value) = 0; |
| 380 | virtual status_t setMasterMute(bool muted) = 0; |
| 381 | |
| 382 | virtual float masterVolume() const = 0; |
| 383 | virtual bool masterMute() const = 0; |
| 384 | |
Richard Folke Tullberg | 3fae037 | 2017-01-13 09:04:25 +0100 | [diff] [blame] | 385 | virtual status_t setMasterBalance(float balance) = 0; |
| 386 | virtual status_t getMasterBalance(float *balance) const = 0; |
| 387 | |
Nicolas Roulet | dcdfaec | 2017-02-14 10:18:39 -0800 | [diff] [blame] | 388 | /* set/get stream type state. This will probably be used by |
| 389 | * the preference panel, mostly. |
| 390 | */ |
| 391 | virtual status_t setStreamVolume(audio_stream_type_t stream, float value, |
| 392 | audio_io_handle_t output) = 0; |
| 393 | virtual status_t setStreamMute(audio_stream_type_t stream, bool muted) = 0; |
| 394 | |
| 395 | virtual float streamVolume(audio_stream_type_t stream, |
| 396 | audio_io_handle_t output) const = 0; |
| 397 | virtual bool streamMute(audio_stream_type_t stream) const = 0; |
| 398 | |
| 399 | // set audio mode |
| 400 | virtual status_t setMode(audio_mode_t mode) = 0; |
| 401 | |
| 402 | // mic mute/state |
| 403 | virtual status_t setMicMute(bool state) = 0; |
| 404 | virtual bool getMicMute() const = 0; |
Eric Laurent | 5ada82e | 2019-08-29 17:53:54 -0700 | [diff] [blame] | 405 | virtual void setRecordSilenced(audio_port_handle_t portId, bool silenced) = 0; |
Nicolas Roulet | dcdfaec | 2017-02-14 10:18:39 -0800 | [diff] [blame] | 406 | |
| 407 | virtual status_t setParameters(audio_io_handle_t ioHandle, |
| 408 | const String8& keyValuePairs) = 0; |
| 409 | virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys) |
| 410 | const = 0; |
| 411 | |
| 412 | // Register an object to receive audio input/output change and track notifications. |
| 413 | // For a given calling pid, AudioFlinger disregards any registrations after the first. |
| 414 | // Thus the IAudioFlingerClient must be a singleton per process. |
| 415 | virtual void registerClient(const sp<IAudioFlingerClient>& client) = 0; |
| 416 | |
Judy Hsiao | abab522 | 2019-11-09 18:14:58 +0800 | [diff] [blame] | 417 | // retrieve the audio recording buffer size in bytes |
Nicolas Roulet | dcdfaec | 2017-02-14 10:18:39 -0800 | [diff] [blame] | 418 | // FIXME This API assumes a route, and so should be deprecated. |
| 419 | virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format, |
| 420 | audio_channel_mask_t channelMask) const = 0; |
| 421 | |
| 422 | virtual status_t openOutput(audio_module_handle_t module, |
| 423 | audio_io_handle_t *output, |
| 424 | audio_config_t *config, |
jiabin | 4381040 | 2019-10-24 14:58:31 -0700 | [diff] [blame] | 425 | const sp<DeviceDescriptorBase>& device, |
Nicolas Roulet | dcdfaec | 2017-02-14 10:18:39 -0800 | [diff] [blame] | 426 | uint32_t *latencyMs, |
| 427 | audio_output_flags_t flags) = 0; |
| 428 | virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1, |
| 429 | audio_io_handle_t output2) = 0; |
| 430 | virtual status_t closeOutput(audio_io_handle_t output) = 0; |
| 431 | virtual status_t suspendOutput(audio_io_handle_t output) = 0; |
| 432 | virtual status_t restoreOutput(audio_io_handle_t output) = 0; |
| 433 | |
| 434 | virtual status_t openInput(audio_module_handle_t module, |
| 435 | audio_io_handle_t *input, |
| 436 | audio_config_t *config, |
| 437 | audio_devices_t *device, |
| 438 | const String8& address, |
| 439 | audio_source_t source, |
| 440 | audio_input_flags_t flags) = 0; |
| 441 | virtual status_t closeInput(audio_io_handle_t input) = 0; |
| 442 | |
| 443 | virtual status_t invalidateStream(audio_stream_type_t stream) = 0; |
| 444 | |
| 445 | virtual status_t setVoiceVolume(float volume) = 0; |
| 446 | |
| 447 | virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames, |
| 448 | audio_io_handle_t output) const = 0; |
| 449 | |
| 450 | virtual uint32_t getInputFramesLost(audio_io_handle_t ioHandle) const = 0; |
| 451 | |
| 452 | virtual audio_unique_id_t newAudioUniqueId(audio_unique_id_use_t use) = 0; |
| 453 | |
Andy Hung | 8b0bfd9 | 2019-12-23 13:11:11 -0800 | [diff] [blame] | 454 | virtual void acquireAudioSessionId(audio_session_t audioSession, pid_t pid, uid_t uid) = 0; |
Nicolas Roulet | dcdfaec | 2017-02-14 10:18:39 -0800 | [diff] [blame] | 455 | virtual void releaseAudioSessionId(audio_session_t audioSession, pid_t pid) = 0; |
| 456 | |
| 457 | virtual status_t queryNumberEffects(uint32_t *numEffects) const = 0; |
| 458 | |
| 459 | virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) const = 0; |
| 460 | |
| 461 | virtual status_t getEffectDescriptor(const effect_uuid_t *pEffectUUID, |
Ari Hausman-Cohen | 2046ec7 | 2018-04-24 14:00:55 -0700 | [diff] [blame] | 462 | const effect_uuid_t *pTypeUUID, |
| 463 | uint32_t preferredTypeFlag, |
| 464 | effect_descriptor_t *pDescriptor) const = 0; |
Nicolas Roulet | dcdfaec | 2017-02-14 10:18:39 -0800 | [diff] [blame] | 465 | |
| 466 | virtual sp<IEffect> createEffect( |
| 467 | effect_descriptor_t *pDesc, |
| 468 | const sp<IEffectClient>& client, |
| 469 | int32_t priority, |
| 470 | // AudioFlinger doesn't take over handle reference from client |
| 471 | audio_io_handle_t output, |
| 472 | audio_session_t sessionId, |
Eric Laurent | 9487603 | 2019-11-13 12:45:28 -0800 | [diff] [blame] | 473 | const AudioDeviceTypeAddr& device, |
Nicolas Roulet | dcdfaec | 2017-02-14 10:18:39 -0800 | [diff] [blame] | 474 | const String16& callingPackage, |
| 475 | pid_t pid, |
Eric Laurent | 2fe0acd | 2020-03-13 14:30:46 -0700 | [diff] [blame] | 476 | bool probe, |
Nicolas Roulet | dcdfaec | 2017-02-14 10:18:39 -0800 | [diff] [blame] | 477 | status_t *status, |
| 478 | int *id, |
| 479 | int *enabled) = 0; |
| 480 | |
| 481 | virtual status_t moveEffects(audio_session_t session, audio_io_handle_t srcOutput, |
| 482 | audio_io_handle_t dstOutput) = 0; |
| 483 | |
Eric Laurent | b20cf7d | 2019-04-05 19:37:34 -0700 | [diff] [blame] | 484 | virtual void setEffectSuspended(int effectId, |
| 485 | audio_session_t sessionId, |
| 486 | bool suspended) = 0; |
| 487 | |
Nicolas Roulet | dcdfaec | 2017-02-14 10:18:39 -0800 | [diff] [blame] | 488 | virtual audio_module_handle_t loadHwModule(const char *name) = 0; |
| 489 | |
| 490 | // helpers for android.media.AudioManager.getProperty(), see description there for meaning |
| 491 | // FIXME move these APIs to AudioPolicy to permit a more accurate implementation |
| 492 | // that looks on primary device for a stream with fast flag, primary flag, or first one. |
| 493 | virtual uint32_t getPrimaryOutputSamplingRate() = 0; |
| 494 | virtual size_t getPrimaryOutputFrameCount() = 0; |
| 495 | |
| 496 | // Intended for AudioService to inform AudioFlinger of device's low RAM attribute, |
| 497 | // and should be called at most once. For a definition of what "low RAM" means, see |
Andy Hung | 6f248bb | 2018-01-23 14:04:37 -0800 | [diff] [blame] | 498 | // android.app.ActivityManager.isLowRamDevice(). The totalMemory parameter |
| 499 | // is obtained from android.app.ActivityManager.MemoryInfo.totalMem. |
| 500 | virtual status_t setLowRamDevice(bool isLowRamDevice, int64_t totalMemory) = 0; |
Nicolas Roulet | dcdfaec | 2017-02-14 10:18:39 -0800 | [diff] [blame] | 501 | |
| 502 | /* List available audio ports and their attributes */ |
| 503 | virtual status_t listAudioPorts(unsigned int *num_ports, |
| 504 | struct audio_port *ports) = 0; |
| 505 | |
| 506 | /* Get attributes for a given audio port */ |
| 507 | virtual status_t getAudioPort(struct audio_port *port) = 0; |
| 508 | |
| 509 | /* Create an audio patch between several source and sink ports */ |
| 510 | virtual status_t createAudioPatch(const struct audio_patch *patch, |
| 511 | audio_patch_handle_t *handle) = 0; |
| 512 | |
| 513 | /* Release an audio patch */ |
| 514 | virtual status_t releaseAudioPatch(audio_patch_handle_t handle) = 0; |
| 515 | |
| 516 | /* List existing audio patches */ |
| 517 | virtual status_t listAudioPatches(unsigned int *num_patches, |
| 518 | struct audio_patch *patches) = 0; |
| 519 | /* Set audio port configuration */ |
| 520 | virtual status_t setAudioPortConfig(const struct audio_port_config *config) = 0; |
| 521 | |
| 522 | /* Get the HW synchronization source used for an audio session */ |
| 523 | virtual audio_hw_sync_t getAudioHwSyncForSession(audio_session_t sessionId) = 0; |
| 524 | |
| 525 | /* Indicate JAVA services are ready (scheduling, power management ...) */ |
| 526 | virtual status_t systemReady() = 0; |
| 527 | |
| 528 | // Returns the number of frames per audio HAL buffer. |
| 529 | virtual size_t frameCountHAL(audio_io_handle_t ioHandle) const = 0; |
jiabin | 46a76fa | 2018-01-05 10:18:21 -0800 | [diff] [blame] | 530 | |
| 531 | /* List available microphones and their characteristics */ |
| 532 | virtual status_t getMicrophones(std::vector<media::MicrophoneInfo> *microphones) = 0; |
Eric Laurent | 42896a0 | 2019-09-27 15:40:33 -0700 | [diff] [blame] | 533 | |
| 534 | virtual status_t setAudioHalPids(const std::vector<pid_t>& pids) = 0; |
Nicolas Roulet | dcdfaec | 2017-02-14 10:18:39 -0800 | [diff] [blame] | 535 | }; |
| 536 | |
| 537 | |
| 538 | // ---------------------------------------------------------------------------- |
| 539 | |
| 540 | class BnAudioFlinger : public BnInterface<IAudioFlinger> |
| 541 | { |
| 542 | public: |
| 543 | virtual status_t onTransact( uint32_t code, |
| 544 | const Parcel& data, |
| 545 | Parcel* reply, |
| 546 | uint32_t flags = 0); |
| 547 | |
| 548 | // Requests media.log to start merging log buffers |
| 549 | virtual void requestLogMerge() = 0; |
| 550 | }; |
| 551 | |
| 552 | // ---------------------------------------------------------------------------- |
| 553 | |
| 554 | }; // namespace android |
| 555 | |
| 556 | #endif // ANDROID_IAUDIOFLINGER_H |