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