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