Marco Nelissen | c74b93f | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 1 | /* |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2 | ** |
| 3 | ** Copyright 2007, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #define LOG_TAG "IAudioFlinger" |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 19 | //#define LOG_NDEBUG 0 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | #include <utils/Log.h> |
| 21 | |
| 22 | #include <stdint.h> |
| 23 | #include <sys/types.h> |
| 24 | |
Mathias Agopian | 0795272 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 25 | #include <binder/Parcel.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | |
| 27 | #include <media/IAudioFlinger.h> |
| 28 | |
| 29 | namespace android { |
| 30 | |
| 31 | enum { |
| 32 | CREATE_TRACK = IBinder::FIRST_CALL_TRANSACTION, |
| 33 | OPEN_RECORD, |
| 34 | SAMPLE_RATE, |
| 35 | CHANNEL_COUNT, |
| 36 | FORMAT, |
| 37 | FRAME_COUNT, |
| 38 | LATENCY, |
| 39 | SET_MASTER_VOLUME, |
| 40 | SET_MASTER_MUTE, |
| 41 | MASTER_VOLUME, |
| 42 | MASTER_MUTE, |
| 43 | SET_STREAM_VOLUME, |
| 44 | SET_STREAM_MUTE, |
| 45 | STREAM_VOLUME, |
| 46 | STREAM_MUTE, |
| 47 | SET_MODE, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | SET_MIC_MUTE, |
| 49 | GET_MIC_MUTE, |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 50 | SET_PARAMETERS, |
| 51 | GET_PARAMETERS, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | REGISTER_CLIENT, |
| 53 | GET_INPUTBUFFERSIZE, |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 54 | OPEN_OUTPUT, |
| 55 | OPEN_DUPLICATE_OUTPUT, |
| 56 | CLOSE_OUTPUT, |
| 57 | SUSPEND_OUTPUT, |
| 58 | RESTORE_OUTPUT, |
| 59 | OPEN_INPUT, |
| 60 | CLOSE_INPUT, |
Eric Laurent | 415f3e2 | 2009-10-21 08:14:22 -0700 | [diff] [blame] | 61 | SET_STREAM_OUTPUT, |
Eric Laurent | 0986e79 | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 62 | SET_VOICE_VOLUME, |
Eric Laurent | 47d0a92 | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 63 | GET_RENDER_POSITION, |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 64 | GET_INPUT_FRAMES_LOST, |
| 65 | NEW_AUDIO_SESSION_ID, |
Marco Nelissen | c74b93f | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 66 | ACQUIRE_AUDIO_SESSION_ID, |
| 67 | RELEASE_AUDIO_SESSION_ID, |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 68 | QUERY_NUM_EFFECTS, |
Eric Laurent | 53334cd | 2010-06-23 17:38:20 -0700 | [diff] [blame] | 69 | QUERY_EFFECT, |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 70 | GET_EFFECT_DESCRIPTOR, |
Eric Laurent | 8ed6ed0 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 71 | CREATE_EFFECT, |
| 72 | MOVE_EFFECTS |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | class BpAudioFlinger : public BpInterface<IAudioFlinger> |
| 76 | { |
| 77 | public: |
| 78 | BpAudioFlinger(const sp<IBinder>& impl) |
| 79 | : BpInterface<IAudioFlinger>(impl) |
| 80 | { |
| 81 | } |
| 82 | |
| 83 | virtual sp<IAudioTrack> createTrack( |
| 84 | pid_t pid, |
| 85 | int streamType, |
| 86 | uint32_t sampleRate, |
Jean-Michel Trivi | 5439223 | 2011-05-24 15:53:33 -0700 | [diff] [blame] | 87 | uint32_t format, |
| 88 | uint32_t channelMask, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | int frameCount, |
| 90 | uint32_t flags, |
| 91 | const sp<IMemory>& sharedBuffer, |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 92 | int output, |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 93 | int *sessionId, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | status_t *status) |
| 95 | { |
| 96 | Parcel data, reply; |
Eric Laurent | 8a77a99 | 2009-09-09 05:16:08 -0700 | [diff] [blame] | 97 | sp<IAudioTrack> track; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 99 | data.writeInt32(pid); |
| 100 | data.writeInt32(streamType); |
| 101 | data.writeInt32(sampleRate); |
| 102 | data.writeInt32(format); |
Jean-Michel Trivi | 5439223 | 2011-05-24 15:53:33 -0700 | [diff] [blame] | 103 | data.writeInt32(channelMask); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | data.writeInt32(frameCount); |
| 105 | data.writeInt32(flags); |
| 106 | data.writeStrongBinder(sharedBuffer->asBinder()); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 107 | data.writeInt32(output); |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 108 | int lSessionId = 0; |
| 109 | if (sessionId != NULL) { |
| 110 | lSessionId = *sessionId; |
| 111 | } |
| 112 | data.writeInt32(lSessionId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | status_t lStatus = remote()->transact(CREATE_TRACK, data, &reply); |
| 114 | if (lStatus != NO_ERROR) { |
| 115 | LOGE("createTrack error: %s", strerror(-lStatus)); |
Eric Laurent | 8a77a99 | 2009-09-09 05:16:08 -0700 | [diff] [blame] | 116 | } else { |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 117 | lSessionId = reply.readInt32(); |
| 118 | if (sessionId != NULL) { |
| 119 | *sessionId = lSessionId; |
| 120 | } |
Eric Laurent | 8a77a99 | 2009-09-09 05:16:08 -0700 | [diff] [blame] | 121 | lStatus = reply.readInt32(); |
| 122 | track = interface_cast<IAudioTrack>(reply.readStrongBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | if (status) { |
| 125 | *status = lStatus; |
| 126 | } |
Eric Laurent | 8a77a99 | 2009-09-09 05:16:08 -0700 | [diff] [blame] | 127 | return track; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | virtual sp<IAudioRecord> openRecord( |
| 131 | pid_t pid, |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 132 | int input, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | uint32_t sampleRate, |
Jean-Michel Trivi | 5439223 | 2011-05-24 15:53:33 -0700 | [diff] [blame] | 134 | uint32_t format, |
| 135 | uint32_t channelMask, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | int frameCount, |
| 137 | uint32_t flags, |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 138 | int *sessionId, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | status_t *status) |
| 140 | { |
| 141 | Parcel data, reply; |
Eric Laurent | 8a77a99 | 2009-09-09 05:16:08 -0700 | [diff] [blame] | 142 | sp<IAudioRecord> record; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 144 | data.writeInt32(pid); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 145 | data.writeInt32(input); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | data.writeInt32(sampleRate); |
| 147 | data.writeInt32(format); |
Jean-Michel Trivi | 5439223 | 2011-05-24 15:53:33 -0700 | [diff] [blame] | 148 | data.writeInt32(channelMask); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 149 | data.writeInt32(frameCount); |
| 150 | data.writeInt32(flags); |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 151 | int lSessionId = 0; |
| 152 | if (sessionId != NULL) { |
| 153 | lSessionId = *sessionId; |
| 154 | } |
| 155 | data.writeInt32(lSessionId); |
Eric Laurent | 8a77a99 | 2009-09-09 05:16:08 -0700 | [diff] [blame] | 156 | status_t lStatus = remote()->transact(OPEN_RECORD, data, &reply); |
| 157 | if (lStatus != NO_ERROR) { |
| 158 | LOGE("openRecord error: %s", strerror(-lStatus)); |
| 159 | } else { |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 160 | lSessionId = reply.readInt32(); |
| 161 | if (sessionId != NULL) { |
| 162 | *sessionId = lSessionId; |
| 163 | } |
Eric Laurent | 8a77a99 | 2009-09-09 05:16:08 -0700 | [diff] [blame] | 164 | lStatus = reply.readInt32(); |
| 165 | record = interface_cast<IAudioRecord>(reply.readStrongBinder()); |
| 166 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | if (status) { |
| 168 | *status = lStatus; |
| 169 | } |
Eric Laurent | 8a77a99 | 2009-09-09 05:16:08 -0700 | [diff] [blame] | 170 | return record; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 171 | } |
| 172 | |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 173 | virtual uint32_t sampleRate(int output) const |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | { |
| 175 | Parcel data, reply; |
| 176 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 177 | data.writeInt32(output); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | remote()->transact(SAMPLE_RATE, data, &reply); |
| 179 | return reply.readInt32(); |
| 180 | } |
| 181 | |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 182 | virtual int channelCount(int output) const |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | { |
| 184 | Parcel data, reply; |
| 185 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 186 | data.writeInt32(output); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | remote()->transact(CHANNEL_COUNT, data, &reply); |
| 188 | return reply.readInt32(); |
| 189 | } |
| 190 | |
Jean-Michel Trivi | 5439223 | 2011-05-24 15:53:33 -0700 | [diff] [blame] | 191 | virtual uint32_t format(int output) const |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 192 | { |
| 193 | Parcel data, reply; |
| 194 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 195 | data.writeInt32(output); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | remote()->transact(FORMAT, data, &reply); |
| 197 | return reply.readInt32(); |
| 198 | } |
| 199 | |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 200 | virtual size_t frameCount(int output) const |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 201 | { |
| 202 | Parcel data, reply; |
| 203 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 204 | data.writeInt32(output); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 205 | remote()->transact(FRAME_COUNT, data, &reply); |
| 206 | return reply.readInt32(); |
| 207 | } |
| 208 | |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 209 | virtual uint32_t latency(int output) const |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 210 | { |
| 211 | Parcel data, reply; |
| 212 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 213 | data.writeInt32(output); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 214 | remote()->transact(LATENCY, data, &reply); |
| 215 | return reply.readInt32(); |
| 216 | } |
| 217 | |
| 218 | virtual status_t setMasterVolume(float value) |
| 219 | { |
| 220 | Parcel data, reply; |
| 221 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 222 | data.writeFloat(value); |
| 223 | remote()->transact(SET_MASTER_VOLUME, data, &reply); |
| 224 | return reply.readInt32(); |
| 225 | } |
| 226 | |
| 227 | virtual status_t setMasterMute(bool muted) |
| 228 | { |
| 229 | Parcel data, reply; |
| 230 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 231 | data.writeInt32(muted); |
| 232 | remote()->transact(SET_MASTER_MUTE, data, &reply); |
| 233 | return reply.readInt32(); |
| 234 | } |
| 235 | |
| 236 | virtual float masterVolume() const |
| 237 | { |
| 238 | Parcel data, reply; |
| 239 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 240 | remote()->transact(MASTER_VOLUME, data, &reply); |
| 241 | return reply.readFloat(); |
| 242 | } |
| 243 | |
| 244 | virtual bool masterMute() const |
| 245 | { |
| 246 | Parcel data, reply; |
| 247 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 248 | remote()->transact(MASTER_MUTE, data, &reply); |
| 249 | return reply.readInt32(); |
| 250 | } |
| 251 | |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 252 | virtual status_t setStreamVolume(int stream, float value, int output) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | { |
| 254 | Parcel data, reply; |
| 255 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 256 | data.writeInt32(stream); |
| 257 | data.writeFloat(value); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 258 | data.writeInt32(output); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | remote()->transact(SET_STREAM_VOLUME, data, &reply); |
| 260 | return reply.readInt32(); |
| 261 | } |
| 262 | |
| 263 | virtual status_t setStreamMute(int stream, bool muted) |
| 264 | { |
| 265 | Parcel data, reply; |
| 266 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 267 | data.writeInt32(stream); |
| 268 | data.writeInt32(muted); |
| 269 | remote()->transact(SET_STREAM_MUTE, data, &reply); |
| 270 | return reply.readInt32(); |
| 271 | } |
| 272 | |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 273 | virtual float streamVolume(int stream, int output) const |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 274 | { |
| 275 | Parcel data, reply; |
| 276 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 277 | data.writeInt32(stream); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 278 | data.writeInt32(output); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 279 | remote()->transact(STREAM_VOLUME, data, &reply); |
| 280 | return reply.readFloat(); |
| 281 | } |
| 282 | |
| 283 | virtual bool streamMute(int stream) const |
| 284 | { |
| 285 | Parcel data, reply; |
| 286 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 287 | data.writeInt32(stream); |
| 288 | remote()->transact(STREAM_MUTE, data, &reply); |
| 289 | return reply.readInt32(); |
| 290 | } |
| 291 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 292 | virtual status_t setMode(int mode) |
| 293 | { |
| 294 | Parcel data, reply; |
| 295 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 296 | data.writeInt32(mode); |
| 297 | remote()->transact(SET_MODE, data, &reply); |
| 298 | return reply.readInt32(); |
| 299 | } |
| 300 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 301 | virtual status_t setMicMute(bool state) |
| 302 | { |
| 303 | Parcel data, reply; |
| 304 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 305 | data.writeInt32(state); |
| 306 | remote()->transact(SET_MIC_MUTE, data, &reply); |
| 307 | return reply.readInt32(); |
| 308 | } |
| 309 | |
| 310 | virtual bool getMicMute() const |
| 311 | { |
| 312 | Parcel data, reply; |
| 313 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 314 | remote()->transact(GET_MIC_MUTE, data, &reply); |
| 315 | return reply.readInt32(); |
| 316 | } |
| 317 | |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 318 | virtual status_t setParameters(int ioHandle, const String8& keyValuePairs) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 319 | { |
| 320 | Parcel data, reply; |
| 321 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 322 | data.writeInt32(ioHandle); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 323 | data.writeString8(keyValuePairs); |
| 324 | remote()->transact(SET_PARAMETERS, data, &reply); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 325 | return reply.readInt32(); |
| 326 | } |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 327 | |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 328 | virtual String8 getParameters(int ioHandle, const String8& keys) |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 329 | { |
| 330 | Parcel data, reply; |
| 331 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 332 | data.writeInt32(ioHandle); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 333 | data.writeString8(keys); |
| 334 | remote()->transact(GET_PARAMETERS, data, &reply); |
| 335 | return reply.readString8(); |
| 336 | } |
| 337 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 338 | virtual void registerClient(const sp<IAudioFlingerClient>& client) |
| 339 | { |
| 340 | Parcel data, reply; |
| 341 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 342 | data.writeStrongBinder(client->asBinder()); |
| 343 | remote()->transact(REGISTER_CLIENT, data, &reply); |
| 344 | } |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 345 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 346 | virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount) |
| 347 | { |
| 348 | Parcel data, reply; |
| 349 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 350 | data.writeInt32(sampleRate); |
| 351 | data.writeInt32(format); |
| 352 | data.writeInt32(channelCount); |
| 353 | remote()->transact(GET_INPUTBUFFERSIZE, data, &reply); |
| 354 | return reply.readInt32(); |
| 355 | } |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 356 | |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 357 | virtual int openOutput(uint32_t *pDevices, |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 358 | uint32_t *pSamplingRate, |
| 359 | uint32_t *pFormat, |
| 360 | uint32_t *pChannels, |
| 361 | uint32_t *pLatencyMs, |
| 362 | uint32_t flags) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 363 | { |
| 364 | Parcel data, reply; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 365 | uint32_t devices = pDevices ? *pDevices : 0; |
| 366 | uint32_t samplingRate = pSamplingRate ? *pSamplingRate : 0; |
| 367 | uint32_t format = pFormat ? *pFormat : 0; |
| 368 | uint32_t channels = pChannels ? *pChannels : 0; |
| 369 | uint32_t latency = pLatencyMs ? *pLatencyMs : 0; |
| 370 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 371 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 372 | data.writeInt32(devices); |
| 373 | data.writeInt32(samplingRate); |
| 374 | data.writeInt32(format); |
| 375 | data.writeInt32(channels); |
| 376 | data.writeInt32(latency); |
| 377 | data.writeInt32(flags); |
| 378 | remote()->transact(OPEN_OUTPUT, data, &reply); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 379 | int output = reply.readInt32(); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 380 | LOGV("openOutput() returned output, %p", output); |
| 381 | devices = reply.readInt32(); |
| 382 | if (pDevices) *pDevices = devices; |
| 383 | samplingRate = reply.readInt32(); |
| 384 | if (pSamplingRate) *pSamplingRate = samplingRate; |
| 385 | format = reply.readInt32(); |
| 386 | if (pFormat) *pFormat = format; |
| 387 | channels = reply.readInt32(); |
| 388 | if (pChannels) *pChannels = channels; |
| 389 | latency = reply.readInt32(); |
| 390 | if (pLatencyMs) *pLatencyMs = latency; |
| 391 | return output; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 392 | } |
| 393 | |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 394 | virtual int openDuplicateOutput(int output1, int output2) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 395 | { |
| 396 | Parcel data, reply; |
| 397 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 398 | data.writeInt32(output1); |
| 399 | data.writeInt32(output2); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 400 | remote()->transact(OPEN_DUPLICATE_OUTPUT, data, &reply); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 401 | return reply.readInt32(); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 404 | virtual status_t closeOutput(int output) |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 405 | { |
| 406 | Parcel data, reply; |
| 407 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 408 | data.writeInt32(output); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 409 | remote()->transact(CLOSE_OUTPUT, data, &reply); |
| 410 | return reply.readInt32(); |
| 411 | } |
| 412 | |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 413 | virtual status_t suspendOutput(int output) |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 414 | { |
| 415 | Parcel data, reply; |
| 416 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 417 | data.writeInt32(output); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 418 | remote()->transact(SUSPEND_OUTPUT, data, &reply); |
| 419 | return reply.readInt32(); |
| 420 | } |
| 421 | |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 422 | virtual status_t restoreOutput(int output) |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 423 | { |
| 424 | Parcel data, reply; |
| 425 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 426 | data.writeInt32(output); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 427 | remote()->transact(RESTORE_OUTPUT, data, &reply); |
| 428 | return reply.readInt32(); |
| 429 | } |
| 430 | |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 431 | virtual int openInput(uint32_t *pDevices, |
| 432 | uint32_t *pSamplingRate, |
| 433 | uint32_t *pFormat, |
| 434 | uint32_t *pChannels, |
| 435 | uint32_t acoustics) |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 436 | { |
| 437 | Parcel data, reply; |
| 438 | uint32_t devices = pDevices ? *pDevices : 0; |
| 439 | uint32_t samplingRate = pSamplingRate ? *pSamplingRate : 0; |
| 440 | uint32_t format = pFormat ? *pFormat : 0; |
| 441 | uint32_t channels = pChannels ? *pChannels : 0; |
| 442 | |
| 443 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 444 | data.writeInt32(devices); |
| 445 | data.writeInt32(samplingRate); |
| 446 | data.writeInt32(format); |
| 447 | data.writeInt32(channels); |
| 448 | data.writeInt32(acoustics); |
| 449 | remote()->transact(OPEN_INPUT, data, &reply); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 450 | int input = reply.readInt32(); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 451 | devices = reply.readInt32(); |
| 452 | if (pDevices) *pDevices = devices; |
| 453 | samplingRate = reply.readInt32(); |
| 454 | if (pSamplingRate) *pSamplingRate = samplingRate; |
| 455 | format = reply.readInt32(); |
| 456 | if (pFormat) *pFormat = format; |
| 457 | channels = reply.readInt32(); |
| 458 | if (pChannels) *pChannels = channels; |
| 459 | return input; |
| 460 | } |
| 461 | |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 462 | virtual status_t closeInput(int input) |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 463 | { |
| 464 | Parcel data, reply; |
| 465 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 466 | data.writeInt32(input); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 467 | remote()->transact(CLOSE_INPUT, data, &reply); |
| 468 | return reply.readInt32(); |
| 469 | } |
| 470 | |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 471 | virtual status_t setStreamOutput(uint32_t stream, int output) |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 472 | { |
| 473 | Parcel data, reply; |
| 474 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 475 | data.writeInt32(stream); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 476 | data.writeInt32(output); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 477 | remote()->transact(SET_STREAM_OUTPUT, data, &reply); |
| 478 | return reply.readInt32(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 479 | } |
Eric Laurent | 415f3e2 | 2009-10-21 08:14:22 -0700 | [diff] [blame] | 480 | |
| 481 | virtual status_t setVoiceVolume(float volume) |
| 482 | { |
| 483 | Parcel data, reply; |
| 484 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 485 | data.writeFloat(volume); |
| 486 | remote()->transact(SET_VOICE_VOLUME, data, &reply); |
| 487 | return reply.readInt32(); |
| 488 | } |
Eric Laurent | 0986e79 | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 489 | |
| 490 | virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames, int output) |
| 491 | { |
| 492 | Parcel data, reply; |
| 493 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 494 | data.writeInt32(output); |
| 495 | remote()->transact(GET_RENDER_POSITION, data, &reply); |
| 496 | status_t status = reply.readInt32(); |
| 497 | if (status == NO_ERROR) { |
| 498 | uint32_t tmp = reply.readInt32(); |
| 499 | if (halFrames) { |
| 500 | *halFrames = tmp; |
| 501 | } |
| 502 | tmp = reply.readInt32(); |
| 503 | if (dspFrames) { |
| 504 | *dspFrames = tmp; |
| 505 | } |
| 506 | } |
| 507 | return status; |
| 508 | } |
Eric Laurent | 47d0a92 | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 509 | |
| 510 | virtual unsigned int getInputFramesLost(int ioHandle) |
| 511 | { |
| 512 | Parcel data, reply; |
| 513 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 514 | data.writeInt32(ioHandle); |
| 515 | remote()->transact(GET_INPUT_FRAMES_LOST, data, &reply); |
| 516 | return reply.readInt32(); |
| 517 | } |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 518 | |
| 519 | virtual int newAudioSessionId() |
| 520 | { |
| 521 | Parcel data, reply; |
| 522 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 523 | status_t status = remote()->transact(NEW_AUDIO_SESSION_ID, data, &reply); |
| 524 | int id = 0; |
| 525 | if (status == NO_ERROR) { |
| 526 | id = reply.readInt32(); |
| 527 | } |
| 528 | return id; |
| 529 | } |
| 530 | |
Marco Nelissen | c74b93f | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 531 | virtual void acquireAudioSessionId(int audioSession) |
| 532 | { |
| 533 | Parcel data, reply; |
| 534 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 535 | data.writeInt32(audioSession); |
| 536 | remote()->transact(ACQUIRE_AUDIO_SESSION_ID, data, &reply); |
| 537 | } |
| 538 | |
| 539 | virtual void releaseAudioSessionId(int audioSession) |
| 540 | { |
| 541 | Parcel data, reply; |
| 542 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 543 | data.writeInt32(audioSession); |
| 544 | remote()->transact(RELEASE_AUDIO_SESSION_ID, data, &reply); |
| 545 | } |
| 546 | |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 547 | virtual status_t queryNumberEffects(uint32_t *numEffects) |
| 548 | { |
| 549 | Parcel data, reply; |
| 550 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 551 | status_t status = remote()->transact(QUERY_NUM_EFFECTS, data, &reply); |
| 552 | if (status != NO_ERROR) { |
| 553 | return status; |
| 554 | } |
| 555 | status = reply.readInt32(); |
| 556 | if (status != NO_ERROR) { |
| 557 | return status; |
| 558 | } |
| 559 | if (numEffects) { |
| 560 | *numEffects = (uint32_t)reply.readInt32(); |
| 561 | } |
| 562 | return NO_ERROR; |
| 563 | } |
| 564 | |
Eric Laurent | 53334cd | 2010-06-23 17:38:20 -0700 | [diff] [blame] | 565 | virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 566 | { |
| 567 | if (pDescriptor == NULL) { |
| 568 | return BAD_VALUE; |
| 569 | } |
| 570 | Parcel data, reply; |
| 571 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Eric Laurent | 53334cd | 2010-06-23 17:38:20 -0700 | [diff] [blame] | 572 | data.writeInt32(index); |
| 573 | status_t status = remote()->transact(QUERY_EFFECT, data, &reply); |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 574 | if (status != NO_ERROR) { |
| 575 | return status; |
| 576 | } |
| 577 | status = reply.readInt32(); |
| 578 | if (status != NO_ERROR) { |
| 579 | return status; |
| 580 | } |
| 581 | reply.read(pDescriptor, sizeof(effect_descriptor_t)); |
| 582 | return NO_ERROR; |
| 583 | } |
| 584 | |
| 585 | virtual status_t getEffectDescriptor(effect_uuid_t *pUuid, effect_descriptor_t *pDescriptor) |
| 586 | { |
| 587 | if (pUuid == NULL || pDescriptor == NULL) { |
| 588 | return BAD_VALUE; |
| 589 | } |
| 590 | Parcel data, reply; |
| 591 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 592 | data.write(pUuid, sizeof(effect_uuid_t)); |
| 593 | status_t status = remote()->transact(GET_EFFECT_DESCRIPTOR, data, &reply); |
| 594 | if (status != NO_ERROR) { |
| 595 | return status; |
| 596 | } |
| 597 | status = reply.readInt32(); |
| 598 | if (status != NO_ERROR) { |
| 599 | return status; |
| 600 | } |
| 601 | reply.read(pDescriptor, sizeof(effect_descriptor_t)); |
| 602 | return NO_ERROR; |
| 603 | } |
| 604 | |
| 605 | virtual sp<IEffect> createEffect(pid_t pid, |
| 606 | effect_descriptor_t *pDesc, |
| 607 | const sp<IEffectClient>& client, |
| 608 | int32_t priority, |
| 609 | int output, |
| 610 | int sessionId, |
| 611 | status_t *status, |
| 612 | int *id, |
| 613 | int *enabled) |
| 614 | { |
| 615 | Parcel data, reply; |
| 616 | sp<IEffect> effect; |
| 617 | |
| 618 | if (pDesc == NULL) { |
| 619 | return effect; |
| 620 | if (status) { |
| 621 | *status = BAD_VALUE; |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 626 | data.writeInt32(pid); |
| 627 | data.write(pDesc, sizeof(effect_descriptor_t)); |
| 628 | data.writeStrongBinder(client->asBinder()); |
| 629 | data.writeInt32(priority); |
| 630 | data.writeInt32(output); |
| 631 | data.writeInt32(sessionId); |
| 632 | |
| 633 | status_t lStatus = remote()->transact(CREATE_EFFECT, data, &reply); |
| 634 | if (lStatus != NO_ERROR) { |
| 635 | LOGE("createEffect error: %s", strerror(-lStatus)); |
| 636 | } else { |
| 637 | lStatus = reply.readInt32(); |
| 638 | int tmp = reply.readInt32(); |
| 639 | if (id) { |
| 640 | *id = tmp; |
| 641 | } |
| 642 | tmp = reply.readInt32(); |
| 643 | if (enabled) { |
| 644 | *enabled = tmp; |
| 645 | } |
| 646 | effect = interface_cast<IEffect>(reply.readStrongBinder()); |
| 647 | reply.read(pDesc, sizeof(effect_descriptor_t)); |
| 648 | } |
| 649 | if (status) { |
| 650 | *status = lStatus; |
| 651 | } |
| 652 | |
| 653 | return effect; |
| 654 | } |
Eric Laurent | 8ed6ed0 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 655 | |
| 656 | virtual status_t moveEffects(int session, int srcOutput, int dstOutput) |
| 657 | { |
| 658 | Parcel data, reply; |
| 659 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 660 | data.writeInt32(session); |
| 661 | data.writeInt32(srcOutput); |
| 662 | data.writeInt32(dstOutput); |
| 663 | remote()->transact(MOVE_EFFECTS, data, &reply); |
| 664 | return reply.readInt32(); |
| 665 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 666 | }; |
| 667 | |
| 668 | IMPLEMENT_META_INTERFACE(AudioFlinger, "android.media.IAudioFlinger"); |
| 669 | |
| 670 | // ---------------------------------------------------------------------- |
| 671 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 672 | status_t BnAudioFlinger::onTransact( |
| 673 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 674 | { |
| 675 | switch(code) { |
| 676 | case CREATE_TRACK: { |
| 677 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 678 | pid_t pid = data.readInt32(); |
| 679 | int streamType = data.readInt32(); |
| 680 | uint32_t sampleRate = data.readInt32(); |
| 681 | int format = data.readInt32(); |
| 682 | int channelCount = data.readInt32(); |
| 683 | size_t bufferCount = data.readInt32(); |
| 684 | uint32_t flags = data.readInt32(); |
| 685 | sp<IMemory> buffer = interface_cast<IMemory>(data.readStrongBinder()); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 686 | int output = data.readInt32(); |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 687 | int sessionId = data.readInt32(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 688 | status_t status; |
| 689 | sp<IAudioTrack> track = createTrack(pid, |
| 690 | streamType, sampleRate, format, |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 691 | channelCount, bufferCount, flags, buffer, output, &sessionId, &status); |
| 692 | reply->writeInt32(sessionId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 693 | reply->writeInt32(status); |
| 694 | reply->writeStrongBinder(track->asBinder()); |
| 695 | return NO_ERROR; |
| 696 | } break; |
| 697 | case OPEN_RECORD: { |
| 698 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 699 | pid_t pid = data.readInt32(); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 700 | int input = data.readInt32(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 701 | uint32_t sampleRate = data.readInt32(); |
| 702 | int format = data.readInt32(); |
| 703 | int channelCount = data.readInt32(); |
| 704 | size_t bufferCount = data.readInt32(); |
| 705 | uint32_t flags = data.readInt32(); |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 706 | int sessionId = data.readInt32(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 707 | status_t status; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 708 | sp<IAudioRecord> record = openRecord(pid, input, |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 709 | sampleRate, format, channelCount, bufferCount, flags, &sessionId, &status); |
| 710 | reply->writeInt32(sessionId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 711 | reply->writeInt32(status); |
| 712 | reply->writeStrongBinder(record->asBinder()); |
| 713 | return NO_ERROR; |
| 714 | } break; |
| 715 | case SAMPLE_RATE: { |
| 716 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 717 | reply->writeInt32( sampleRate(data.readInt32()) ); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 718 | return NO_ERROR; |
| 719 | } break; |
| 720 | case CHANNEL_COUNT: { |
| 721 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 722 | reply->writeInt32( channelCount(data.readInt32()) ); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 723 | return NO_ERROR; |
| 724 | } break; |
| 725 | case FORMAT: { |
| 726 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 727 | reply->writeInt32( format(data.readInt32()) ); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 728 | return NO_ERROR; |
| 729 | } break; |
| 730 | case FRAME_COUNT: { |
| 731 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 732 | reply->writeInt32( frameCount(data.readInt32()) ); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 733 | return NO_ERROR; |
| 734 | } break; |
| 735 | case LATENCY: { |
| 736 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 737 | reply->writeInt32( latency(data.readInt32()) ); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 738 | return NO_ERROR; |
| 739 | } break; |
| 740 | case SET_MASTER_VOLUME: { |
| 741 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 742 | reply->writeInt32( setMasterVolume(data.readFloat()) ); |
| 743 | return NO_ERROR; |
| 744 | } break; |
| 745 | case SET_MASTER_MUTE: { |
| 746 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 747 | reply->writeInt32( setMasterMute(data.readInt32()) ); |
| 748 | return NO_ERROR; |
| 749 | } break; |
| 750 | case MASTER_VOLUME: { |
| 751 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 752 | reply->writeFloat( masterVolume() ); |
| 753 | return NO_ERROR; |
| 754 | } break; |
| 755 | case MASTER_MUTE: { |
| 756 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 757 | reply->writeInt32( masterMute() ); |
| 758 | return NO_ERROR; |
| 759 | } break; |
| 760 | case SET_STREAM_VOLUME: { |
| 761 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 762 | int stream = data.readInt32(); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 763 | float volume = data.readFloat(); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 764 | int output = data.readInt32(); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 765 | reply->writeInt32( setStreamVolume(stream, volume, output) ); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 766 | return NO_ERROR; |
| 767 | } break; |
| 768 | case SET_STREAM_MUTE: { |
| 769 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 770 | int stream = data.readInt32(); |
| 771 | reply->writeInt32( setStreamMute(stream, data.readInt32()) ); |
| 772 | return NO_ERROR; |
| 773 | } break; |
| 774 | case STREAM_VOLUME: { |
| 775 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 776 | int stream = data.readInt32(); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 777 | int output = data.readInt32(); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 778 | reply->writeFloat( streamVolume(stream, output) ); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 779 | return NO_ERROR; |
| 780 | } break; |
| 781 | case STREAM_MUTE: { |
| 782 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 783 | int stream = data.readInt32(); |
| 784 | reply->writeInt32( streamMute(stream) ); |
| 785 | return NO_ERROR; |
| 786 | } break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 787 | case SET_MODE: { |
| 788 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 789 | int mode = data.readInt32(); |
| 790 | reply->writeInt32( setMode(mode) ); |
| 791 | return NO_ERROR; |
| 792 | } break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 793 | case SET_MIC_MUTE: { |
| 794 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 795 | int state = data.readInt32(); |
| 796 | reply->writeInt32( setMicMute(state) ); |
| 797 | return NO_ERROR; |
| 798 | } break; |
| 799 | case GET_MIC_MUTE: { |
| 800 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 801 | reply->writeInt32( getMicMute() ); |
| 802 | return NO_ERROR; |
| 803 | } break; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 804 | case SET_PARAMETERS: { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 805 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 806 | int ioHandle = data.readInt32(); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 807 | String8 keyValuePairs(data.readString8()); |
| 808 | reply->writeInt32(setParameters(ioHandle, keyValuePairs)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 809 | return NO_ERROR; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 810 | } break; |
| 811 | case GET_PARAMETERS: { |
| 812 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 813 | int ioHandle = data.readInt32(); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 814 | String8 keys(data.readString8()); |
| 815 | reply->writeString8(getParameters(ioHandle, keys)); |
| 816 | return NO_ERROR; |
| 817 | } break; |
| 818 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 819 | case REGISTER_CLIENT: { |
| 820 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 821 | sp<IAudioFlingerClient> client = interface_cast<IAudioFlingerClient>(data.readStrongBinder()); |
| 822 | registerClient(client); |
| 823 | return NO_ERROR; |
| 824 | } break; |
| 825 | case GET_INPUTBUFFERSIZE: { |
| 826 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 827 | uint32_t sampleRate = data.readInt32(); |
| 828 | int format = data.readInt32(); |
| 829 | int channelCount = data.readInt32(); |
| 830 | reply->writeInt32( getInputBufferSize(sampleRate, format, channelCount) ); |
| 831 | return NO_ERROR; |
| 832 | } break; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 833 | case OPEN_OUTPUT: { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 834 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 835 | uint32_t devices = data.readInt32(); |
| 836 | uint32_t samplingRate = data.readInt32(); |
| 837 | uint32_t format = data.readInt32(); |
| 838 | uint32_t channels = data.readInt32(); |
| 839 | uint32_t latency = data.readInt32(); |
| 840 | uint32_t flags = data.readInt32(); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 841 | int output = openOutput(&devices, |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 842 | &samplingRate, |
| 843 | &format, |
| 844 | &channels, |
| 845 | &latency, |
| 846 | flags); |
| 847 | LOGV("OPEN_OUTPUT output, %p", output); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 848 | reply->writeInt32(output); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 849 | reply->writeInt32(devices); |
| 850 | reply->writeInt32(samplingRate); |
| 851 | reply->writeInt32(format); |
| 852 | reply->writeInt32(channels); |
| 853 | reply->writeInt32(latency); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 854 | return NO_ERROR; |
| 855 | } break; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 856 | case OPEN_DUPLICATE_OUTPUT: { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 857 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 858 | int output1 = data.readInt32(); |
| 859 | int output2 = data.readInt32(); |
| 860 | reply->writeInt32(openDuplicateOutput(output1, output2)); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 861 | return NO_ERROR; |
| 862 | } break; |
| 863 | case CLOSE_OUTPUT: { |
| 864 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 865 | reply->writeInt32(closeOutput(data.readInt32())); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 866 | return NO_ERROR; |
| 867 | } break; |
| 868 | case SUSPEND_OUTPUT: { |
| 869 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 870 | reply->writeInt32(suspendOutput(data.readInt32())); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 871 | return NO_ERROR; |
| 872 | } break; |
| 873 | case RESTORE_OUTPUT: { |
| 874 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 875 | reply->writeInt32(restoreOutput(data.readInt32())); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 876 | return NO_ERROR; |
| 877 | } break; |
| 878 | case OPEN_INPUT: { |
| 879 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 880 | uint32_t devices = data.readInt32(); |
| 881 | uint32_t samplingRate = data.readInt32(); |
| 882 | uint32_t format = data.readInt32(); |
| 883 | uint32_t channels = data.readInt32(); |
| 884 | uint32_t acoutics = data.readInt32(); |
| 885 | |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 886 | int input = openInput(&devices, |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 887 | &samplingRate, |
| 888 | &format, |
| 889 | &channels, |
| 890 | acoutics); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 891 | reply->writeInt32(input); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 892 | reply->writeInt32(devices); |
| 893 | reply->writeInt32(samplingRate); |
| 894 | reply->writeInt32(format); |
| 895 | reply->writeInt32(channels); |
| 896 | return NO_ERROR; |
| 897 | } break; |
| 898 | case CLOSE_INPUT: { |
| 899 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 900 | reply->writeInt32(closeInput(data.readInt32())); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 901 | return NO_ERROR; |
| 902 | } break; |
| 903 | case SET_STREAM_OUTPUT: { |
| 904 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 905 | uint32_t stream = data.readInt32(); |
Eric Laurent | ddb78e7 | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 906 | int output = data.readInt32(); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 907 | reply->writeInt32(setStreamOutput(stream, output)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 908 | return NO_ERROR; |
| 909 | } break; |
Eric Laurent | 415f3e2 | 2009-10-21 08:14:22 -0700 | [diff] [blame] | 910 | case SET_VOICE_VOLUME: { |
| 911 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 912 | float volume = data.readFloat(); |
| 913 | reply->writeInt32( setVoiceVolume(volume) ); |
| 914 | return NO_ERROR; |
| 915 | } break; |
Eric Laurent | 0986e79 | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 916 | case GET_RENDER_POSITION: { |
| 917 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 918 | int output = data.readInt32(); |
| 919 | uint32_t halFrames; |
| 920 | uint32_t dspFrames; |
| 921 | status_t status = getRenderPosition(&halFrames, &dspFrames, output); |
| 922 | reply->writeInt32(status); |
| 923 | if (status == NO_ERROR) { |
| 924 | reply->writeInt32(halFrames); |
| 925 | reply->writeInt32(dspFrames); |
| 926 | } |
| 927 | return NO_ERROR; |
| 928 | } |
Eric Laurent | 47d0a92 | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 929 | case GET_INPUT_FRAMES_LOST: { |
| 930 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 931 | int ioHandle = data.readInt32(); |
| 932 | reply->writeInt32(getInputFramesLost(ioHandle)); |
| 933 | return NO_ERROR; |
| 934 | } break; |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 935 | case NEW_AUDIO_SESSION_ID: { |
| 936 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 937 | reply->writeInt32(newAudioSessionId()); |
| 938 | return NO_ERROR; |
| 939 | } break; |
Marco Nelissen | c74b93f | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 940 | case ACQUIRE_AUDIO_SESSION_ID: { |
| 941 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 942 | int audioSession = data.readInt32(); |
| 943 | acquireAudioSessionId(audioSession); |
| 944 | return NO_ERROR; |
| 945 | } break; |
| 946 | case RELEASE_AUDIO_SESSION_ID: { |
| 947 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 948 | int audioSession = data.readInt32(); |
| 949 | releaseAudioSessionId(audioSession); |
| 950 | return NO_ERROR; |
| 951 | } break; |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 952 | case QUERY_NUM_EFFECTS: { |
| 953 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 954 | uint32_t numEffects; |
| 955 | status_t status = queryNumberEffects(&numEffects); |
| 956 | reply->writeInt32(status); |
| 957 | if (status == NO_ERROR) { |
| 958 | reply->writeInt32((int32_t)numEffects); |
| 959 | } |
| 960 | return NO_ERROR; |
| 961 | } |
Eric Laurent | 53334cd | 2010-06-23 17:38:20 -0700 | [diff] [blame] | 962 | case QUERY_EFFECT: { |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 963 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 964 | effect_descriptor_t desc; |
Eric Laurent | 53334cd | 2010-06-23 17:38:20 -0700 | [diff] [blame] | 965 | status_t status = queryEffect(data.readInt32(), &desc); |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 966 | reply->writeInt32(status); |
| 967 | if (status == NO_ERROR) { |
| 968 | reply->write(&desc, sizeof(effect_descriptor_t)); |
| 969 | } |
| 970 | return NO_ERROR; |
| 971 | } |
| 972 | case GET_EFFECT_DESCRIPTOR: { |
| 973 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 974 | effect_uuid_t uuid; |
| 975 | data.read(&uuid, sizeof(effect_uuid_t)); |
| 976 | effect_descriptor_t desc; |
| 977 | status_t status = getEffectDescriptor(&uuid, &desc); |
| 978 | reply->writeInt32(status); |
| 979 | if (status == NO_ERROR) { |
| 980 | reply->write(&desc, sizeof(effect_descriptor_t)); |
| 981 | } |
| 982 | return NO_ERROR; |
| 983 | } |
| 984 | case CREATE_EFFECT: { |
| 985 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 986 | pid_t pid = data.readInt32(); |
| 987 | effect_descriptor_t desc; |
| 988 | data.read(&desc, sizeof(effect_descriptor_t)); |
| 989 | sp<IEffectClient> client = interface_cast<IEffectClient>(data.readStrongBinder()); |
| 990 | int32_t priority = data.readInt32(); |
| 991 | int output = data.readInt32(); |
| 992 | int sessionId = data.readInt32(); |
| 993 | status_t status; |
| 994 | int id; |
| 995 | int enabled; |
Eric Laurent | 47d0a92 | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 996 | |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 997 | sp<IEffect> effect = createEffect(pid, &desc, client, priority, output, sessionId, &status, &id, &enabled); |
| 998 | reply->writeInt32(status); |
| 999 | reply->writeInt32(id); |
| 1000 | reply->writeInt32(enabled); |
| 1001 | reply->writeStrongBinder(effect->asBinder()); |
| 1002 | reply->write(&desc, sizeof(effect_descriptor_t)); |
| 1003 | return NO_ERROR; |
| 1004 | } break; |
Eric Laurent | 8ed6ed0 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1005 | case MOVE_EFFECTS: { |
| 1006 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 1007 | int session = data.readInt32(); |
| 1008 | int srcOutput = data.readInt32(); |
| 1009 | int dstOutput = data.readInt32(); |
| 1010 | reply->writeInt32(moveEffects(session, srcOutput, dstOutput)); |
| 1011 | return NO_ERROR; |
| 1012 | } break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1013 | default: |
| 1014 | return BBinder::onTransact(code, data, reply, flags); |
| 1015 | } |
| 1016 | } |
| 1017 | |
| 1018 | // ---------------------------------------------------------------------------- |
| 1019 | |
| 1020 | }; // namespace android |