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