| Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2009 The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
|  | 17 | #define LOG_TAG "IAudioPolicyServiceClient" | 
|  | 18 | #include <utils/Log.h> | 
|  | 19 |  | 
|  | 20 | #include <stdint.h> | 
|  | 21 | #include <sys/types.h> | 
|  | 22 |  | 
|  | 23 | #include <binder/Parcel.h> | 
|  | 24 |  | 
|  | 25 | #include <media/IAudioPolicyServiceClient.h> | 
|  | 26 | #include <media/AudioSystem.h> | 
|  | 27 |  | 
|  | 28 | namespace android { | 
|  | 29 |  | 
|  | 30 | enum { | 
|  | 31 | PORT_LIST_UPDATE = IBinder::FIRST_CALL_TRANSACTION, | 
| Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 32 | PATCH_LIST_UPDATE, | 
| Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 33 | MIX_STATE_UPDATE, | 
|  | 34 | RECORDING_CONFIGURATION_UPDATE | 
| Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 35 | }; | 
|  | 36 |  | 
| Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 37 | // ---------------------------------------------------------------------- | 
|  | 38 | inline void readAudioConfigBaseFromParcel(const Parcel& data, audio_config_base_t *config) { | 
|  | 39 | config->sample_rate = data.readUint32(); | 
|  | 40 | config->channel_mask = (audio_channel_mask_t) data.readInt32(); | 
|  | 41 | config->format = (audio_format_t) data.readInt32(); | 
|  | 42 | } | 
|  | 43 |  | 
|  | 44 | inline void writeAudioConfigBaseToParcel(Parcel& data, const audio_config_base_t *config) | 
|  | 45 | { | 
|  | 46 | data.writeUint32(config->sample_rate); | 
|  | 47 | data.writeInt32((int32_t) config->channel_mask); | 
|  | 48 | data.writeInt32((int32_t) config->format); | 
|  | 49 | } | 
|  | 50 |  | 
|  | 51 | // ---------------------------------------------------------------------- | 
| Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 52 | class BpAudioPolicyServiceClient : public BpInterface<IAudioPolicyServiceClient> | 
|  | 53 | { | 
|  | 54 | public: | 
| Chih-Hung Hsieh | 090ef60 | 2016-04-27 10:39:54 -0700 | [diff] [blame] | 55 | explicit BpAudioPolicyServiceClient(const sp<IBinder>& impl) | 
| Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 56 | : BpInterface<IAudioPolicyServiceClient>(impl) | 
|  | 57 | { | 
|  | 58 | } | 
|  | 59 |  | 
|  | 60 | void onAudioPortListUpdate() | 
|  | 61 | { | 
|  | 62 | Parcel data, reply; | 
|  | 63 | data.writeInterfaceToken(IAudioPolicyServiceClient::getInterfaceDescriptor()); | 
|  | 64 | remote()->transact(PORT_LIST_UPDATE, data, &reply, IBinder::FLAG_ONEWAY); | 
|  | 65 | } | 
|  | 66 |  | 
|  | 67 | void onAudioPatchListUpdate() | 
|  | 68 | { | 
|  | 69 | Parcel data, reply; | 
|  | 70 | data.writeInterfaceToken(IAudioPolicyServiceClient::getInterfaceDescriptor()); | 
|  | 71 | remote()->transact(PATCH_LIST_UPDATE, data, &reply, IBinder::FLAG_ONEWAY); | 
|  | 72 | } | 
| Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 73 |  | 
|  | 74 | void onDynamicPolicyMixStateUpdate(String8 regId, int32_t state) | 
|  | 75 | { | 
|  | 76 | Parcel data, reply; | 
|  | 77 | data.writeInterfaceToken(IAudioPolicyServiceClient::getInterfaceDescriptor()); | 
|  | 78 | data.writeString8(regId); | 
|  | 79 | data.writeInt32(state); | 
|  | 80 | remote()->transact(MIX_STATE_UPDATE, data, &reply, IBinder::FLAG_ONEWAY); | 
|  | 81 | } | 
| Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 82 |  | 
|  | 83 | void onRecordingConfigurationUpdate(int event, audio_session_t session, | 
| Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 84 | audio_source_t source, const audio_config_base_t *clientConfig, | 
| Jean-Michel Trivi | 8c7cf3b | 2016-02-25 17:08:24 -0800 | [diff] [blame] | 85 | const audio_config_base_t *deviceConfig, audio_patch_handle_t patchHandle) { | 
| Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 86 | Parcel data, reply; | 
|  | 87 | data.writeInterfaceToken(IAudioPolicyServiceClient::getInterfaceDescriptor()); | 
|  | 88 | data.writeInt32(event); | 
|  | 89 | data.writeInt32(session); | 
|  | 90 | data.writeInt32(source); | 
| Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 91 | writeAudioConfigBaseToParcel(data, clientConfig); | 
|  | 92 | writeAudioConfigBaseToParcel(data, deviceConfig); | 
| Jean-Michel Trivi | 8c7cf3b | 2016-02-25 17:08:24 -0800 | [diff] [blame] | 93 | data.writeInt32(patchHandle); | 
| Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 94 | remote()->transact(RECORDING_CONFIGURATION_UPDATE, data, &reply, IBinder::FLAG_ONEWAY); | 
|  | 95 | } | 
| Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 96 | }; | 
|  | 97 |  | 
|  | 98 | IMPLEMENT_META_INTERFACE(AudioPolicyServiceClient, "android.media.IAudioPolicyServiceClient"); | 
|  | 99 |  | 
|  | 100 | // ---------------------------------------------------------------------- | 
|  | 101 |  | 
|  | 102 | status_t BnAudioPolicyServiceClient::onTransact( | 
|  | 103 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) | 
|  | 104 | { | 
|  | 105 | switch (code) { | 
|  | 106 | case PORT_LIST_UPDATE: { | 
|  | 107 | CHECK_INTERFACE(IAudioPolicyServiceClient, data, reply); | 
|  | 108 | onAudioPortListUpdate(); | 
|  | 109 | return NO_ERROR; | 
|  | 110 | } break; | 
|  | 111 | case PATCH_LIST_UPDATE: { | 
|  | 112 | CHECK_INTERFACE(IAudioPolicyServiceClient, data, reply); | 
|  | 113 | onAudioPatchListUpdate(); | 
|  | 114 | return NO_ERROR; | 
|  | 115 | } break; | 
| Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 116 | case MIX_STATE_UPDATE: { | 
|  | 117 | CHECK_INTERFACE(IAudioPolicyServiceClient, data, reply); | 
|  | 118 | String8 regId = data.readString8(); | 
|  | 119 | int32_t state = data.readInt32(); | 
|  | 120 | onDynamicPolicyMixStateUpdate(regId, state); | 
|  | 121 | return NO_ERROR; | 
| Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 122 | } break; | 
|  | 123 | case RECORDING_CONFIGURATION_UPDATE: { | 
|  | 124 | CHECK_INTERFACE(IAudioPolicyServiceClient, data, reply); | 
|  | 125 | int event = (int) data.readInt32(); | 
|  | 126 | audio_session_t session = (audio_session_t) data.readInt32(); | 
|  | 127 | audio_source_t source = (audio_source_t) data.readInt32(); | 
| Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 128 | audio_config_base_t clientConfig; | 
|  | 129 | audio_config_base_t deviceConfig; | 
|  | 130 | readAudioConfigBaseFromParcel(data, &clientConfig); | 
|  | 131 | readAudioConfigBaseFromParcel(data, &deviceConfig); | 
| Jean-Michel Trivi | 8c7cf3b | 2016-02-25 17:08:24 -0800 | [diff] [blame] | 132 | audio_patch_handle_t patchHandle = (audio_patch_handle_t) data.readInt32(); | 
|  | 133 | onRecordingConfigurationUpdate(event, session, source, &clientConfig, &deviceConfig, | 
|  | 134 | patchHandle); | 
| Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 135 | return NO_ERROR; | 
|  | 136 | } break; | 
| Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 137 | default: | 
|  | 138 | return BBinder::onTransact(code, data, reply, flags); | 
|  | 139 | } | 
|  | 140 | } | 
|  | 141 |  | 
|  | 142 | // ---------------------------------------------------------------------------- | 
|  | 143 |  | 
| Glenn Kasten | 40bc906 | 2015-03-20 09:09:33 -0700 | [diff] [blame] | 144 | } // namespace android |