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