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 | |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 51 | inline void readRecordClientInfoFromParcel(const Parcel& data, record_client_info_t *clientInfo) { |
| 52 | clientInfo->uid = (uid_t) data.readUint32(); |
| 53 | clientInfo->session = (audio_session_t) data.readInt32(); |
| 54 | clientInfo->source = (audio_source_t) data.readInt32(); |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame^] | 55 | data.read(&clientInfo->port_id, sizeof(audio_port_handle_t)); |
| 56 | clientInfo->silenced = data.readBool(); |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 57 | } |
| 58 | |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame^] | 59 | inline void writeRecordClientInfoToParcel(Parcel& data, const record_client_info_t *clientInfo) { |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 60 | data.writeUint32((uint32_t) clientInfo->uid); |
| 61 | data.writeInt32((int32_t) clientInfo->session); |
| 62 | data.writeInt32((int32_t) clientInfo->source); |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame^] | 63 | data.write(&clientInfo->port_id, sizeof(audio_port_handle_t)); |
| 64 | data.writeBool(clientInfo->silenced); |
| 65 | } |
| 66 | |
| 67 | inline void readEffectVectorFromParcel(const Parcel& data, |
| 68 | std::vector<effect_descriptor_t> *effects) { |
| 69 | int32_t numEffects = data.readInt32(); |
| 70 | for (int32_t i = 0; i < numEffects; i++) { |
| 71 | effect_descriptor_t effect; |
| 72 | if (data.read(&effect, sizeof(effect_descriptor_t)) != NO_ERROR) { |
| 73 | break; |
| 74 | } |
| 75 | (*effects).push_back(effect); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | inline void writeEffectVectorToParcel(Parcel& data, std::vector<effect_descriptor_t> effects) { |
| 80 | data.writeUint32((uint32_t) effects.size()); |
| 81 | for (const auto& effect : effects) { |
| 82 | if (data.write(&effect, sizeof(effect_descriptor_t)) != NO_ERROR) { |
| 83 | break; |
| 84 | } |
| 85 | } |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 86 | } |
| 87 | |
Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 88 | // ---------------------------------------------------------------------- |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 89 | class BpAudioPolicyServiceClient : public BpInterface<IAudioPolicyServiceClient> |
| 90 | { |
| 91 | public: |
Chih-Hung Hsieh | 090ef60 | 2016-04-27 10:39:54 -0700 | [diff] [blame] | 92 | explicit BpAudioPolicyServiceClient(const sp<IBinder>& impl) |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 93 | : BpInterface<IAudioPolicyServiceClient>(impl) |
| 94 | { |
| 95 | } |
| 96 | |
| 97 | void onAudioPortListUpdate() |
| 98 | { |
| 99 | Parcel data, reply; |
| 100 | data.writeInterfaceToken(IAudioPolicyServiceClient::getInterfaceDescriptor()); |
| 101 | remote()->transact(PORT_LIST_UPDATE, data, &reply, IBinder::FLAG_ONEWAY); |
| 102 | } |
| 103 | |
| 104 | void onAudioPatchListUpdate() |
| 105 | { |
| 106 | Parcel data, reply; |
| 107 | data.writeInterfaceToken(IAudioPolicyServiceClient::getInterfaceDescriptor()); |
| 108 | remote()->transact(PATCH_LIST_UPDATE, data, &reply, IBinder::FLAG_ONEWAY); |
| 109 | } |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 110 | |
| 111 | void onDynamicPolicyMixStateUpdate(String8 regId, int32_t state) |
| 112 | { |
| 113 | Parcel data, reply; |
| 114 | data.writeInterfaceToken(IAudioPolicyServiceClient::getInterfaceDescriptor()); |
| 115 | data.writeString8(regId); |
| 116 | data.writeInt32(state); |
| 117 | remote()->transact(MIX_STATE_UPDATE, data, &reply, IBinder::FLAG_ONEWAY); |
| 118 | } |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 119 | |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame^] | 120 | void onRecordingConfigurationUpdate(int event, |
| 121 | const record_client_info_t *clientInfo, |
| 122 | const audio_config_base_t *clientConfig, |
| 123 | std::vector<effect_descriptor_t> clientEffects, |
| 124 | const audio_config_base_t *deviceConfig, |
| 125 | std::vector<effect_descriptor_t> effects, |
| 126 | audio_patch_handle_t patchHandle, |
| 127 | audio_source_t source) { |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 128 | Parcel data, reply; |
| 129 | data.writeInterfaceToken(IAudioPolicyServiceClient::getInterfaceDescriptor()); |
| 130 | data.writeInt32(event); |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame^] | 131 | writeRecordClientInfoToParcel(data, clientInfo); |
Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 132 | writeAudioConfigBaseToParcel(data, clientConfig); |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame^] | 133 | writeEffectVectorToParcel(data, clientEffects); |
Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 134 | writeAudioConfigBaseToParcel(data, deviceConfig); |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame^] | 135 | writeEffectVectorToParcel(data, effects); |
Jean-Michel Trivi | 8c7cf3b | 2016-02-25 17:08:24 -0800 | [diff] [blame] | 136 | data.writeInt32(patchHandle); |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame^] | 137 | data.writeInt32((int32_t) source); |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 138 | remote()->transact(RECORDING_CONFIGURATION_UPDATE, data, &reply, IBinder::FLAG_ONEWAY); |
| 139 | } |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 140 | }; |
| 141 | |
| 142 | IMPLEMENT_META_INTERFACE(AudioPolicyServiceClient, "android.media.IAudioPolicyServiceClient"); |
| 143 | |
| 144 | // ---------------------------------------------------------------------- |
| 145 | |
| 146 | status_t BnAudioPolicyServiceClient::onTransact( |
| 147 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 148 | { |
| 149 | switch (code) { |
| 150 | case PORT_LIST_UPDATE: { |
| 151 | CHECK_INTERFACE(IAudioPolicyServiceClient, data, reply); |
| 152 | onAudioPortListUpdate(); |
| 153 | return NO_ERROR; |
| 154 | } break; |
| 155 | case PATCH_LIST_UPDATE: { |
| 156 | CHECK_INTERFACE(IAudioPolicyServiceClient, data, reply); |
| 157 | onAudioPatchListUpdate(); |
| 158 | return NO_ERROR; |
| 159 | } break; |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 160 | case MIX_STATE_UPDATE: { |
| 161 | CHECK_INTERFACE(IAudioPolicyServiceClient, data, reply); |
| 162 | String8 regId = data.readString8(); |
| 163 | int32_t state = data.readInt32(); |
| 164 | onDynamicPolicyMixStateUpdate(regId, state); |
| 165 | return NO_ERROR; |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 166 | } break; |
| 167 | case RECORDING_CONFIGURATION_UPDATE: { |
| 168 | CHECK_INTERFACE(IAudioPolicyServiceClient, data, reply); |
| 169 | int event = (int) data.readInt32(); |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 170 | record_client_info_t clientInfo; |
Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 171 | audio_config_base_t clientConfig; |
| 172 | audio_config_base_t deviceConfig; |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 173 | readRecordClientInfoFromParcel(data, &clientInfo); |
Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 174 | readAudioConfigBaseFromParcel(data, &clientConfig); |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame^] | 175 | std::vector<effect_descriptor_t> clientEffects; |
| 176 | readEffectVectorFromParcel(data, &clientEffects); |
Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 177 | readAudioConfigBaseFromParcel(data, &deviceConfig); |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame^] | 178 | std::vector<effect_descriptor_t> effects; |
| 179 | readEffectVectorFromParcel(data, &effects); |
Jean-Michel Trivi | 8c7cf3b | 2016-02-25 17:08:24 -0800 | [diff] [blame] | 180 | audio_patch_handle_t patchHandle = (audio_patch_handle_t) data.readInt32(); |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame^] | 181 | audio_source_t source = (audio_source_t) data.readInt32(); |
| 182 | onRecordingConfigurationUpdate(event, &clientInfo, &clientConfig, clientEffects, |
| 183 | &deviceConfig, effects, patchHandle, source); |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 184 | return NO_ERROR; |
| 185 | } break; |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 186 | default: |
| 187 | return BBinder::onTransact(code, data, reply, flags); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | // ---------------------------------------------------------------------------- |
| 192 | |
Glenn Kasten | 40bc906 | 2015-03-20 09:09:33 -0700 | [diff] [blame] | 193 | } // namespace android |