Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2009, 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 "IAudioPolicyService" |
| 19 | #include <utils/Log.h> |
| 20 | |
| 21 | #include <stdint.h> |
| 22 | #include <sys/types.h> |
| 23 | |
| 24 | #include <binder/Parcel.h> |
| 25 | |
| 26 | #include <media/IAudioPolicyService.h> |
| 27 | |
Dima Zavin | 6476024 | 2011-05-11 14:15:23 -0700 | [diff] [blame] | 28 | #include <system/audio.h> |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 29 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 30 | namespace android { |
| 31 | |
| 32 | enum { |
| 33 | SET_DEVICE_CONNECTION_STATE = IBinder::FIRST_CALL_TRANSACTION, |
| 34 | GET_DEVICE_CONNECTION_STATE, |
| 35 | SET_PHONE_STATE, |
Glenn Kasten | 0b07b80 | 2012-01-18 14:56:06 -0800 | [diff] [blame] | 36 | SET_RINGER_MODE, // reserved, no longer used |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 37 | SET_FORCE_USE, |
| 38 | GET_FORCE_USE, |
| 39 | GET_OUTPUT, |
| 40 | START_OUTPUT, |
| 41 | STOP_OUTPUT, |
| 42 | RELEASE_OUTPUT, |
| 43 | GET_INPUT, |
| 44 | START_INPUT, |
| 45 | STOP_INPUT, |
| 46 | RELEASE_INPUT, |
| 47 | INIT_STREAM_VOLUME, |
| 48 | SET_STREAM_VOLUME, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 49 | GET_STREAM_VOLUME, |
| 50 | GET_STRATEGY_FOR_STREAM, |
| 51 | GET_OUTPUT_FOR_EFFECT, |
| 52 | REGISTER_EFFECT, |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 53 | UNREGISTER_EFFECT, |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 54 | IS_STREAM_ACTIVE, |
Jean-Michel Trivi | d708603 | 2012-10-10 12:11:16 -0700 | [diff] [blame] | 55 | IS_SOURCE_ACTIVE, |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 56 | GET_DEVICES_FOR_STREAM, |
Eric Laurent | db7c079 | 2011-08-10 10:37:50 -0700 | [diff] [blame] | 57 | QUERY_DEFAULT_PRE_PROCESSING, |
Jean-Michel Trivi | 272ab54 | 2013-02-04 16:26:02 -0800 | [diff] [blame] | 58 | SET_EFFECT_ENABLED, |
Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 59 | IS_STREAM_ACTIVE_REMOTELY, |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 60 | IS_OFFLOAD_SUPPORTED, |
| 61 | LIST_AUDIO_PORTS, |
| 62 | GET_AUDIO_PORT, |
| 63 | CREATE_AUDIO_PATCH, |
| 64 | RELEASE_AUDIO_PATCH, |
| 65 | LIST_AUDIO_PATCHES, |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 66 | SET_AUDIO_PORT_CONFIG, |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame^] | 67 | REGISTER_CLIENT, |
| 68 | GET_OUTPUT_FOR_ATTR |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | class BpAudioPolicyService : public BpInterface<IAudioPolicyService> |
| 72 | { |
| 73 | public: |
| 74 | BpAudioPolicyService(const sp<IBinder>& impl) |
| 75 | : BpInterface<IAudioPolicyService>(impl) |
| 76 | { |
| 77 | } |
| 78 | |
| 79 | virtual status_t setDeviceConnectionState( |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 80 | audio_devices_t device, |
| 81 | audio_policy_dev_state_t state, |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 82 | const char *device_address) |
| 83 | { |
| 84 | Parcel data, reply; |
| 85 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 86 | data.writeInt32(static_cast <uint32_t>(device)); |
| 87 | data.writeInt32(static_cast <uint32_t>(state)); |
| 88 | data.writeCString(device_address); |
| 89 | remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply); |
| 90 | return static_cast <status_t> (reply.readInt32()); |
| 91 | } |
| 92 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 93 | virtual audio_policy_dev_state_t getDeviceConnectionState( |
| 94 | audio_devices_t device, |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 95 | const char *device_address) |
| 96 | { |
| 97 | Parcel data, reply; |
| 98 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 99 | data.writeInt32(static_cast <uint32_t>(device)); |
| 100 | data.writeCString(device_address); |
| 101 | remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 102 | return static_cast <audio_policy_dev_state_t>(reply.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Glenn Kasten | f78aee7 | 2012-01-04 11:00:47 -0800 | [diff] [blame] | 105 | virtual status_t setPhoneState(audio_mode_t state) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 106 | { |
| 107 | Parcel data, reply; |
| 108 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 109 | data.writeInt32(state); |
| 110 | remote()->transact(SET_PHONE_STATE, data, &reply); |
| 111 | return static_cast <status_t> (reply.readInt32()); |
| 112 | } |
| 113 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 114 | virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 115 | { |
| 116 | Parcel data, reply; |
| 117 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 118 | data.writeInt32(static_cast <uint32_t>(usage)); |
| 119 | data.writeInt32(static_cast <uint32_t>(config)); |
| 120 | remote()->transact(SET_FORCE_USE, data, &reply); |
| 121 | return static_cast <status_t> (reply.readInt32()); |
| 122 | } |
| 123 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 124 | virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 125 | { |
| 126 | Parcel data, reply; |
| 127 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 128 | data.writeInt32(static_cast <uint32_t>(usage)); |
| 129 | remote()->transact(GET_FORCE_USE, data, &reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 130 | return static_cast <audio_policy_forced_cfg_t> (reply.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | virtual audio_io_handle_t getOutput( |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 134 | audio_stream_type_t stream, |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 135 | uint32_t samplingRate, |
Glenn Kasten | 58f3021 | 2012-01-12 12:27:51 -0800 | [diff] [blame] | 136 | audio_format_t format, |
Glenn Kasten | 254af18 | 2012-07-03 14:59:05 -0700 | [diff] [blame] | 137 | audio_channel_mask_t channelMask, |
Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 138 | audio_output_flags_t flags, |
| 139 | const audio_offload_info_t *offloadInfo) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 140 | { |
| 141 | Parcel data, reply; |
| 142 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 143 | data.writeInt32(static_cast <uint32_t>(stream)); |
| 144 | data.writeInt32(samplingRate); |
| 145 | data.writeInt32(static_cast <uint32_t>(format)); |
Glenn Kasten | 254af18 | 2012-07-03 14:59:05 -0700 | [diff] [blame] | 146 | data.writeInt32(channelMask); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 147 | data.writeInt32(static_cast <uint32_t>(flags)); |
Glenn Kasten | 2301acc | 2014-01-17 10:21:00 -0800 | [diff] [blame] | 148 | // hasOffloadInfo |
Richard Fitzgerald | b1a270d | 2013-05-14 12:12:21 +0100 | [diff] [blame] | 149 | if (offloadInfo == NULL) { |
| 150 | data.writeInt32(0); |
| 151 | } else { |
| 152 | data.writeInt32(1); |
| 153 | data.write(offloadInfo, sizeof(audio_offload_info_t)); |
| 154 | } |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 155 | remote()->transact(GET_OUTPUT, data, &reply); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 156 | return static_cast <audio_io_handle_t> (reply.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame^] | 159 | virtual audio_io_handle_t getOutputForAttr( |
| 160 | const audio_attributes_t *attr, |
| 161 | uint32_t samplingRate, |
| 162 | audio_format_t format, |
| 163 | audio_channel_mask_t channelMask, |
| 164 | audio_output_flags_t flags, |
| 165 | const audio_offload_info_t *offloadInfo) |
| 166 | { |
| 167 | Parcel data, reply; |
| 168 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 169 | if (attr == NULL) { |
| 170 | ALOGE("Writing NULL audio attributes - shouldn't happen"); |
| 171 | return (audio_io_handle_t) 0; |
| 172 | } |
| 173 | data.write(attr, sizeof(audio_attributes_t)); |
| 174 | data.writeInt32(samplingRate); |
| 175 | data.writeInt32(static_cast <uint32_t>(format)); |
| 176 | data.writeInt32(channelMask); |
| 177 | data.writeInt32(static_cast <uint32_t>(flags)); |
| 178 | // hasOffloadInfo |
| 179 | if (offloadInfo == NULL) { |
| 180 | data.writeInt32(0); |
| 181 | } else { |
| 182 | data.writeInt32(1); |
| 183 | data.write(offloadInfo, sizeof(audio_offload_info_t)); |
| 184 | } |
| 185 | remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply); |
| 186 | return static_cast <audio_io_handle_t> (reply.readInt32()); |
| 187 | } |
| 188 | |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 189 | virtual status_t startOutput(audio_io_handle_t output, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 190 | audio_stream_type_t stream, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 191 | int session) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 192 | { |
| 193 | Parcel data, reply; |
| 194 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 195 | data.writeInt32(output); |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 196 | data.writeInt32((int32_t) stream); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 197 | data.writeInt32(session); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 198 | remote()->transact(START_OUTPUT, data, &reply); |
| 199 | return static_cast <status_t> (reply.readInt32()); |
| 200 | } |
| 201 | |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 202 | virtual status_t stopOutput(audio_io_handle_t output, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 203 | audio_stream_type_t stream, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 204 | int session) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 205 | { |
| 206 | Parcel data, reply; |
| 207 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 208 | data.writeInt32(output); |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 209 | data.writeInt32((int32_t) stream); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 210 | data.writeInt32(session); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 211 | remote()->transact(STOP_OUTPUT, data, &reply); |
| 212 | return static_cast <status_t> (reply.readInt32()); |
| 213 | } |
| 214 | |
| 215 | virtual void releaseOutput(audio_io_handle_t output) |
| 216 | { |
| 217 | Parcel data, reply; |
| 218 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 219 | data.writeInt32(output); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 220 | remote()->transact(RELEASE_OUTPUT, data, &reply); |
| 221 | } |
| 222 | |
| 223 | virtual audio_io_handle_t getInput( |
Glenn Kasten | eba51fb | 2012-01-23 13:58:49 -0800 | [diff] [blame] | 224 | audio_source_t inputSource, |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 225 | uint32_t samplingRate, |
Glenn Kasten | 58f3021 | 2012-01-12 12:27:51 -0800 | [diff] [blame] | 226 | audio_format_t format, |
Glenn Kasten | 254af18 | 2012-07-03 14:59:05 -0700 | [diff] [blame] | 227 | audio_channel_mask_t channelMask, |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 228 | int audioSession) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 229 | { |
| 230 | Parcel data, reply; |
| 231 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Glenn Kasten | eba51fb | 2012-01-23 13:58:49 -0800 | [diff] [blame] | 232 | data.writeInt32((int32_t) inputSource); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 233 | data.writeInt32(samplingRate); |
| 234 | data.writeInt32(static_cast <uint32_t>(format)); |
Glenn Kasten | 254af18 | 2012-07-03 14:59:05 -0700 | [diff] [blame] | 235 | data.writeInt32(channelMask); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 236 | data.writeInt32(audioSession); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 237 | remote()->transact(GET_INPUT, data, &reply); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 238 | return static_cast <audio_io_handle_t> (reply.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | virtual status_t startInput(audio_io_handle_t input) |
| 242 | { |
| 243 | Parcel data, reply; |
| 244 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 245 | data.writeInt32(input); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 246 | remote()->transact(START_INPUT, data, &reply); |
| 247 | return static_cast <status_t> (reply.readInt32()); |
| 248 | } |
| 249 | |
| 250 | virtual status_t stopInput(audio_io_handle_t input) |
| 251 | { |
| 252 | Parcel data, reply; |
| 253 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 254 | data.writeInt32(input); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 255 | remote()->transact(STOP_INPUT, data, &reply); |
| 256 | return static_cast <status_t> (reply.readInt32()); |
| 257 | } |
| 258 | |
| 259 | virtual void releaseInput(audio_io_handle_t input) |
| 260 | { |
| 261 | Parcel data, reply; |
| 262 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 263 | data.writeInt32(input); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 264 | remote()->transact(RELEASE_INPUT, data, &reply); |
| 265 | } |
| 266 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 267 | virtual status_t initStreamVolume(audio_stream_type_t stream, |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 268 | int indexMin, |
| 269 | int indexMax) |
| 270 | { |
| 271 | Parcel data, reply; |
| 272 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 273 | data.writeInt32(static_cast <uint32_t>(stream)); |
| 274 | data.writeInt32(indexMin); |
| 275 | data.writeInt32(indexMax); |
| 276 | remote()->transact(INIT_STREAM_VOLUME, data, &reply); |
| 277 | return static_cast <status_t> (reply.readInt32()); |
| 278 | } |
| 279 | |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 280 | virtual status_t setStreamVolumeIndex(audio_stream_type_t stream, |
| 281 | int index, |
| 282 | audio_devices_t device) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 283 | { |
| 284 | Parcel data, reply; |
| 285 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 286 | data.writeInt32(static_cast <uint32_t>(stream)); |
| 287 | data.writeInt32(index); |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 288 | data.writeInt32(static_cast <uint32_t>(device)); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 289 | remote()->transact(SET_STREAM_VOLUME, data, &reply); |
| 290 | return static_cast <status_t> (reply.readInt32()); |
| 291 | } |
| 292 | |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 293 | virtual status_t getStreamVolumeIndex(audio_stream_type_t stream, |
| 294 | int *index, |
| 295 | audio_devices_t device) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 296 | { |
| 297 | Parcel data, reply; |
| 298 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 299 | data.writeInt32(static_cast <uint32_t>(stream)); |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 300 | data.writeInt32(static_cast <uint32_t>(device)); |
| 301 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 302 | remote()->transact(GET_STREAM_VOLUME, data, &reply); |
| 303 | int lIndex = reply.readInt32(); |
| 304 | if (index) *index = lIndex; |
| 305 | return static_cast <status_t> (reply.readInt32()); |
| 306 | } |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 307 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 308 | virtual uint32_t getStrategyForStream(audio_stream_type_t stream) |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 309 | { |
| 310 | Parcel data, reply; |
| 311 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 312 | data.writeInt32(static_cast <uint32_t>(stream)); |
| 313 | remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply); |
| 314 | return reply.readInt32(); |
| 315 | } |
| 316 | |
Eric Laurent | 6374252 | 2012-03-08 13:42:42 -0800 | [diff] [blame] | 317 | virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream) |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 318 | { |
| 319 | Parcel data, reply; |
| 320 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 321 | data.writeInt32(static_cast <uint32_t>(stream)); |
| 322 | remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply); |
Eric Laurent | 6374252 | 2012-03-08 13:42:42 -0800 | [diff] [blame] | 323 | return (audio_devices_t) reply.readInt32(); |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 324 | } |
| 325 | |
Glenn Kasten | 58e5aa3 | 2012-06-20 14:08:14 -0700 | [diff] [blame] | 326 | virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc) |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 327 | { |
| 328 | Parcel data, reply; |
| 329 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 330 | data.write(desc, sizeof(effect_descriptor_t)); |
| 331 | remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply); |
| 332 | return static_cast <audio_io_handle_t> (reply.readInt32()); |
| 333 | } |
| 334 | |
Glenn Kasten | 58e5aa3 | 2012-06-20 14:08:14 -0700 | [diff] [blame] | 335 | virtual status_t registerEffect(const effect_descriptor_t *desc, |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 336 | audio_io_handle_t io, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 337 | uint32_t strategy, |
| 338 | int session, |
| 339 | int id) |
| 340 | { |
| 341 | Parcel data, reply; |
| 342 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 343 | data.write(desc, sizeof(effect_descriptor_t)); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 344 | data.writeInt32(io); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 345 | data.writeInt32(strategy); |
| 346 | data.writeInt32(session); |
| 347 | data.writeInt32(id); |
| 348 | remote()->transact(REGISTER_EFFECT, data, &reply); |
| 349 | return static_cast <status_t> (reply.readInt32()); |
| 350 | } |
| 351 | |
| 352 | virtual status_t unregisterEffect(int id) |
| 353 | { |
| 354 | Parcel data, reply; |
| 355 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 356 | data.writeInt32(id); |
| 357 | remote()->transact(UNREGISTER_EFFECT, data, &reply); |
| 358 | return static_cast <status_t> (reply.readInt32()); |
| 359 | } |
| 360 | |
Eric Laurent | db7c079 | 2011-08-10 10:37:50 -0700 | [diff] [blame] | 361 | virtual status_t setEffectEnabled(int id, bool enabled) |
| 362 | { |
| 363 | Parcel data, reply; |
| 364 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 365 | data.writeInt32(id); |
| 366 | data.writeInt32(enabled); |
| 367 | remote()->transact(SET_EFFECT_ENABLED, data, &reply); |
| 368 | return static_cast <status_t> (reply.readInt32()); |
| 369 | } |
| 370 | |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 371 | virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 372 | { |
| 373 | Parcel data, reply; |
| 374 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 375 | data.writeInt32((int32_t) stream); |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 376 | data.writeInt32(inPastMs); |
| 377 | remote()->transact(IS_STREAM_ACTIVE, data, &reply); |
| 378 | return reply.readInt32(); |
| 379 | } |
Eric Laurent | 57dae99 | 2011-07-24 13:36:09 -0700 | [diff] [blame] | 380 | |
Jean-Michel Trivi | 272ab54 | 2013-02-04 16:26:02 -0800 | [diff] [blame] | 381 | virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const |
| 382 | { |
| 383 | Parcel data, reply; |
| 384 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 385 | data.writeInt32((int32_t) stream); |
| 386 | data.writeInt32(inPastMs); |
| 387 | remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply); |
| 388 | return reply.readInt32(); |
| 389 | } |
| 390 | |
Jean-Michel Trivi | d708603 | 2012-10-10 12:11:16 -0700 | [diff] [blame] | 391 | virtual bool isSourceActive(audio_source_t source) const |
| 392 | { |
| 393 | Parcel data, reply; |
| 394 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 395 | data.writeInt32((int32_t) source); |
| 396 | remote()->transact(IS_SOURCE_ACTIVE, data, &reply); |
| 397 | return reply.readInt32(); |
| 398 | } |
| 399 | |
Eric Laurent | 57dae99 | 2011-07-24 13:36:09 -0700 | [diff] [blame] | 400 | virtual status_t queryDefaultPreProcessing(int audioSession, |
| 401 | effect_descriptor_t *descriptors, |
| 402 | uint32_t *count) |
| 403 | { |
| 404 | if (descriptors == NULL || count == NULL) { |
| 405 | return BAD_VALUE; |
| 406 | } |
| 407 | Parcel data, reply; |
| 408 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 409 | data.writeInt32(audioSession); |
| 410 | data.writeInt32(*count); |
| 411 | status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply); |
| 412 | if (status != NO_ERROR) { |
| 413 | return status; |
| 414 | } |
| 415 | status = static_cast <status_t> (reply.readInt32()); |
| 416 | uint32_t retCount = reply.readInt32(); |
| 417 | if (retCount != 0) { |
| 418 | uint32_t numDesc = (retCount < *count) ? retCount : *count; |
| 419 | reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc); |
| 420 | } |
| 421 | *count = retCount; |
| 422 | return status; |
| 423 | } |
Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 424 | |
| 425 | virtual bool isOffloadSupported(const audio_offload_info_t& info) |
| 426 | { |
Richard Fitzgerald | b1a270d | 2013-05-14 12:12:21 +0100 | [diff] [blame] | 427 | Parcel data, reply; |
| 428 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 429 | data.write(&info, sizeof(audio_offload_info_t)); |
| 430 | remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 431 | return reply.readInt32(); |
| 432 | } |
| 433 | |
| 434 | virtual status_t listAudioPorts(audio_port_role_t role, |
| 435 | audio_port_type_t type, |
| 436 | unsigned int *num_ports, |
| 437 | struct audio_port *ports, |
| 438 | unsigned int *generation) |
| 439 | { |
| 440 | if (num_ports == NULL || (*num_ports != 0 && ports == NULL) || |
| 441 | generation == NULL) { |
| 442 | return BAD_VALUE; |
| 443 | } |
| 444 | Parcel data, reply; |
| 445 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 446 | unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports; |
| 447 | data.writeInt32(role); |
| 448 | data.writeInt32(type); |
| 449 | data.writeInt32(numPortsReq); |
| 450 | status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply); |
| 451 | if (status == NO_ERROR) { |
| 452 | status = (status_t)reply.readInt32(); |
| 453 | *num_ports = (unsigned int)reply.readInt32(); |
| 454 | } |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 455 | if (status == NO_ERROR) { |
| 456 | if (numPortsReq > *num_ports) { |
| 457 | numPortsReq = *num_ports; |
| 458 | } |
| 459 | if (numPortsReq > 0) { |
| 460 | reply.read(ports, numPortsReq * sizeof(struct audio_port)); |
| 461 | } |
| 462 | *generation = reply.readInt32(); |
| 463 | } |
| 464 | return status; |
| 465 | } |
| 466 | |
| 467 | virtual status_t getAudioPort(struct audio_port *port) |
| 468 | { |
| 469 | if (port == NULL) { |
| 470 | return BAD_VALUE; |
| 471 | } |
| 472 | Parcel data, reply; |
| 473 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 474 | data.write(port, sizeof(struct audio_port)); |
| 475 | status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply); |
| 476 | if (status != NO_ERROR || |
| 477 | (status = (status_t)reply.readInt32()) != NO_ERROR) { |
| 478 | return status; |
| 479 | } |
| 480 | reply.read(port, sizeof(struct audio_port)); |
| 481 | return status; |
| 482 | } |
| 483 | |
| 484 | virtual status_t createAudioPatch(const struct audio_patch *patch, |
| 485 | audio_patch_handle_t *handle) |
| 486 | { |
| 487 | if (patch == NULL || handle == NULL) { |
| 488 | return BAD_VALUE; |
| 489 | } |
| 490 | Parcel data, reply; |
| 491 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 492 | data.write(patch, sizeof(struct audio_patch)); |
| 493 | data.write(handle, sizeof(audio_patch_handle_t)); |
| 494 | status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply); |
| 495 | if (status != NO_ERROR || |
| 496 | (status = (status_t)reply.readInt32()) != NO_ERROR) { |
| 497 | return status; |
| 498 | } |
| 499 | reply.read(handle, sizeof(audio_patch_handle_t)); |
| 500 | return status; |
| 501 | } |
| 502 | |
| 503 | virtual status_t releaseAudioPatch(audio_patch_handle_t handle) |
| 504 | { |
| 505 | Parcel data, reply; |
| 506 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 507 | data.write(&handle, sizeof(audio_patch_handle_t)); |
| 508 | status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply); |
| 509 | if (status != NO_ERROR) { |
| 510 | status = (status_t)reply.readInt32(); |
| 511 | } |
| 512 | return status; |
| 513 | } |
| 514 | |
| 515 | virtual status_t listAudioPatches(unsigned int *num_patches, |
| 516 | struct audio_patch *patches, |
| 517 | unsigned int *generation) |
| 518 | { |
| 519 | if (num_patches == NULL || (*num_patches != 0 && patches == NULL) || |
| 520 | generation == NULL) { |
| 521 | return BAD_VALUE; |
| 522 | } |
| 523 | Parcel data, reply; |
| 524 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 525 | unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches; |
| 526 | data.writeInt32(numPatchesReq); |
| 527 | status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply); |
| 528 | if (status == NO_ERROR) { |
| 529 | status = (status_t)reply.readInt32(); |
| 530 | *num_patches = (unsigned int)reply.readInt32(); |
| 531 | } |
| 532 | if (status == NO_ERROR) { |
| 533 | if (numPatchesReq > *num_patches) { |
| 534 | numPatchesReq = *num_patches; |
| 535 | } |
| 536 | if (numPatchesReq > 0) { |
| 537 | reply.read(patches, numPatchesReq * sizeof(struct audio_patch)); |
| 538 | } |
| 539 | *generation = reply.readInt32(); |
| 540 | } |
| 541 | return status; |
| 542 | } |
| 543 | |
| 544 | virtual status_t setAudioPortConfig(const struct audio_port_config *config) |
| 545 | { |
| 546 | if (config == NULL) { |
| 547 | return BAD_VALUE; |
| 548 | } |
| 549 | Parcel data, reply; |
| 550 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 551 | data.write(config, sizeof(struct audio_port_config)); |
| 552 | status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply); |
| 553 | if (status != NO_ERROR) { |
| 554 | status = (status_t)reply.readInt32(); |
| 555 | } |
| 556 | return status; |
| 557 | } |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 558 | virtual void registerClient(const sp<IAudioPolicyServiceClient>& client) |
| 559 | { |
| 560 | Parcel data, reply; |
| 561 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 562 | data.writeStrongBinder(client->asBinder()); |
| 563 | remote()->transact(REGISTER_CLIENT, data, &reply); |
| 564 | } |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 565 | }; |
| 566 | |
| 567 | IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService"); |
| 568 | |
| 569 | // ---------------------------------------------------------------------- |
| 570 | |
| 571 | |
| 572 | status_t BnAudioPolicyService::onTransact( |
| 573 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 574 | { |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 575 | switch (code) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 576 | case SET_DEVICE_CONNECTION_STATE: { |
| 577 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 578 | audio_devices_t device = |
| 579 | static_cast <audio_devices_t>(data.readInt32()); |
| 580 | audio_policy_dev_state_t state = |
| 581 | static_cast <audio_policy_dev_state_t>(data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 582 | const char *device_address = data.readCString(); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 583 | reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device, |
| 584 | state, |
| 585 | device_address))); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 586 | return NO_ERROR; |
| 587 | } break; |
| 588 | |
| 589 | case GET_DEVICE_CONNECTION_STATE: { |
| 590 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 591 | audio_devices_t device = |
| 592 | static_cast<audio_devices_t> (data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 593 | const char *device_address = data.readCString(); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 594 | reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device, |
| 595 | device_address))); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 596 | return NO_ERROR; |
| 597 | } break; |
| 598 | |
| 599 | case SET_PHONE_STATE: { |
| 600 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Glenn Kasten | 85ab62c | 2012-11-01 11:11:38 -0700 | [diff] [blame] | 601 | reply->writeInt32(static_cast <uint32_t>(setPhoneState( |
| 602 | (audio_mode_t) data.readInt32()))); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 603 | return NO_ERROR; |
| 604 | } break; |
| 605 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 606 | case SET_FORCE_USE: { |
| 607 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Glenn Kasten | 85ab62c | 2012-11-01 11:11:38 -0700 | [diff] [blame] | 608 | audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>( |
| 609 | data.readInt32()); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 610 | audio_policy_forced_cfg_t config = |
| 611 | static_cast <audio_policy_forced_cfg_t>(data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 612 | reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config))); |
| 613 | return NO_ERROR; |
| 614 | } break; |
| 615 | |
| 616 | case GET_FORCE_USE: { |
| 617 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Glenn Kasten | 85ab62c | 2012-11-01 11:11:38 -0700 | [diff] [blame] | 618 | audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>( |
| 619 | data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 620 | reply->writeInt32(static_cast <uint32_t>(getForceUse(usage))); |
| 621 | return NO_ERROR; |
| 622 | } break; |
| 623 | |
| 624 | case GET_OUTPUT: { |
| 625 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 626 | audio_stream_type_t stream = |
| 627 | static_cast <audio_stream_type_t>(data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 628 | uint32_t samplingRate = data.readInt32(); |
Glenn Kasten | 58f3021 | 2012-01-12 12:27:51 -0800 | [diff] [blame] | 629 | audio_format_t format = (audio_format_t) data.readInt32(); |
Glenn Kasten | 254af18 | 2012-07-03 14:59:05 -0700 | [diff] [blame] | 630 | audio_channel_mask_t channelMask = data.readInt32(); |
Eric Laurent | 0ca3cf9 | 2012-04-18 09:24:29 -0700 | [diff] [blame] | 631 | audio_output_flags_t flags = |
| 632 | static_cast <audio_output_flags_t>(data.readInt32()); |
Richard Fitzgerald | b1a270d | 2013-05-14 12:12:21 +0100 | [diff] [blame] | 633 | bool hasOffloadInfo = data.readInt32() != 0; |
| 634 | audio_offload_info_t offloadInfo; |
| 635 | if (hasOffloadInfo) { |
| 636 | data.read(&offloadInfo, sizeof(audio_offload_info_t)); |
| 637 | } |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 638 | audio_io_handle_t output = getOutput(stream, |
| 639 | samplingRate, |
| 640 | format, |
Glenn Kasten | 254af18 | 2012-07-03 14:59:05 -0700 | [diff] [blame] | 641 | channelMask, |
Richard Fitzgerald | b1a270d | 2013-05-14 12:12:21 +0100 | [diff] [blame] | 642 | flags, |
| 643 | hasOffloadInfo ? &offloadInfo : NULL); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 644 | reply->writeInt32(static_cast <int>(output)); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 645 | return NO_ERROR; |
| 646 | } break; |
| 647 | |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame^] | 648 | case GET_OUTPUT_FOR_ATTR: { |
| 649 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 650 | audio_attributes_t *attr = (audio_attributes_t *) calloc(1, sizeof(audio_attributes_t)); |
| 651 | data.read(attr, sizeof(audio_attributes_t)); |
| 652 | uint32_t samplingRate = data.readInt32(); |
| 653 | audio_format_t format = (audio_format_t) data.readInt32(); |
| 654 | audio_channel_mask_t channelMask = data.readInt32(); |
| 655 | audio_output_flags_t flags = |
| 656 | static_cast <audio_output_flags_t>(data.readInt32()); |
| 657 | bool hasOffloadInfo = data.readInt32() != 0; |
| 658 | audio_offload_info_t offloadInfo; |
| 659 | if (hasOffloadInfo) { |
| 660 | data.read(&offloadInfo, sizeof(audio_offload_info_t)); |
| 661 | } |
| 662 | audio_io_handle_t output = getOutputForAttr(attr, |
| 663 | samplingRate, |
| 664 | format, |
| 665 | channelMask, |
| 666 | flags, |
| 667 | hasOffloadInfo ? &offloadInfo : NULL); |
| 668 | reply->writeInt32(static_cast <int>(output)); |
| 669 | return NO_ERROR; |
| 670 | } break; |
| 671 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 672 | case START_OUTPUT: { |
| 673 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 674 | audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32()); |
Eric Laurent | ebcb254 | 2014-03-05 18:30:08 -0800 | [diff] [blame] | 675 | audio_stream_type_t stream = |
| 676 | static_cast <audio_stream_type_t>(data.readInt32()); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 677 | int session = data.readInt32(); |
| 678 | reply->writeInt32(static_cast <uint32_t>(startOutput(output, |
Eric Laurent | ebcb254 | 2014-03-05 18:30:08 -0800 | [diff] [blame] | 679 | stream, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 680 | session))); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 681 | return NO_ERROR; |
| 682 | } break; |
| 683 | |
| 684 | case STOP_OUTPUT: { |
| 685 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 686 | audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32()); |
Eric Laurent | ebcb254 | 2014-03-05 18:30:08 -0800 | [diff] [blame] | 687 | audio_stream_type_t stream = |
| 688 | static_cast <audio_stream_type_t>(data.readInt32()); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 689 | int session = data.readInt32(); |
| 690 | reply->writeInt32(static_cast <uint32_t>(stopOutput(output, |
Eric Laurent | ebcb254 | 2014-03-05 18:30:08 -0800 | [diff] [blame] | 691 | stream, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 692 | session))); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 693 | return NO_ERROR; |
| 694 | } break; |
| 695 | |
| 696 | case RELEASE_OUTPUT: { |
| 697 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 698 | audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 699 | releaseOutput(output); |
| 700 | return NO_ERROR; |
| 701 | } break; |
| 702 | |
| 703 | case GET_INPUT: { |
| 704 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Glenn Kasten | eba51fb | 2012-01-23 13:58:49 -0800 | [diff] [blame] | 705 | audio_source_t inputSource = (audio_source_t) data.readInt32(); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 706 | uint32_t samplingRate = data.readInt32(); |
Glenn Kasten | 58f3021 | 2012-01-12 12:27:51 -0800 | [diff] [blame] | 707 | audio_format_t format = (audio_format_t) data.readInt32(); |
Glenn Kasten | 254af18 | 2012-07-03 14:59:05 -0700 | [diff] [blame] | 708 | audio_channel_mask_t channelMask = data.readInt32(); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 709 | int audioSession = data.readInt32(); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 710 | audio_io_handle_t input = getInput(inputSource, |
| 711 | samplingRate, |
| 712 | format, |
Glenn Kasten | 254af18 | 2012-07-03 14:59:05 -0700 | [diff] [blame] | 713 | channelMask, |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 714 | audioSession); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 715 | reply->writeInt32(static_cast <int>(input)); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 716 | return NO_ERROR; |
| 717 | } break; |
| 718 | |
| 719 | case START_INPUT: { |
| 720 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 721 | audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 722 | reply->writeInt32(static_cast <uint32_t>(startInput(input))); |
| 723 | return NO_ERROR; |
| 724 | } break; |
| 725 | |
| 726 | case STOP_INPUT: { |
| 727 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 728 | audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 729 | reply->writeInt32(static_cast <uint32_t>(stopInput(input))); |
| 730 | return NO_ERROR; |
| 731 | } break; |
| 732 | |
| 733 | case RELEASE_INPUT: { |
| 734 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 735 | audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 736 | releaseInput(input); |
| 737 | return NO_ERROR; |
| 738 | } break; |
| 739 | |
| 740 | case INIT_STREAM_VOLUME: { |
| 741 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 742 | audio_stream_type_t stream = |
| 743 | static_cast <audio_stream_type_t>(data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 744 | int indexMin = data.readInt32(); |
| 745 | int indexMax = data.readInt32(); |
| 746 | reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax))); |
| 747 | return NO_ERROR; |
| 748 | } break; |
| 749 | |
| 750 | case SET_STREAM_VOLUME: { |
| 751 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 752 | audio_stream_type_t stream = |
| 753 | static_cast <audio_stream_type_t>(data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 754 | int index = data.readInt32(); |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 755 | audio_devices_t device = static_cast <audio_devices_t>(data.readInt32()); |
| 756 | reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream, |
| 757 | index, |
| 758 | device))); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 759 | return NO_ERROR; |
| 760 | } break; |
| 761 | |
| 762 | case GET_STREAM_VOLUME: { |
| 763 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 764 | audio_stream_type_t stream = |
| 765 | static_cast <audio_stream_type_t>(data.readInt32()); |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 766 | audio_devices_t device = static_cast <audio_devices_t>(data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 767 | int index; |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 768 | status_t status = getStreamVolumeIndex(stream, &index, device); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 769 | reply->writeInt32(index); |
| 770 | reply->writeInt32(static_cast <uint32_t>(status)); |
| 771 | return NO_ERROR; |
| 772 | } break; |
| 773 | |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 774 | case GET_STRATEGY_FOR_STREAM: { |
| 775 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 776 | audio_stream_type_t stream = |
| 777 | static_cast <audio_stream_type_t>(data.readInt32()); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 778 | reply->writeInt32(getStrategyForStream(stream)); |
| 779 | return NO_ERROR; |
| 780 | } break; |
| 781 | |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 782 | case GET_DEVICES_FOR_STREAM: { |
| 783 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 784 | audio_stream_type_t stream = |
| 785 | static_cast <audio_stream_type_t>(data.readInt32()); |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 786 | reply->writeInt32(static_cast <int>(getDevicesForStream(stream))); |
| 787 | return NO_ERROR; |
| 788 | } break; |
| 789 | |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 790 | case GET_OUTPUT_FOR_EFFECT: { |
| 791 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 792 | effect_descriptor_t desc; |
| 793 | data.read(&desc, sizeof(effect_descriptor_t)); |
| 794 | audio_io_handle_t output = getOutputForEffect(&desc); |
| 795 | reply->writeInt32(static_cast <int>(output)); |
| 796 | return NO_ERROR; |
| 797 | } break; |
| 798 | |
| 799 | case REGISTER_EFFECT: { |
| 800 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 801 | effect_descriptor_t desc; |
| 802 | data.read(&desc, sizeof(effect_descriptor_t)); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 803 | audio_io_handle_t io = data.readInt32(); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 804 | uint32_t strategy = data.readInt32(); |
| 805 | int session = data.readInt32(); |
| 806 | int id = data.readInt32(); |
| 807 | reply->writeInt32(static_cast <int32_t>(registerEffect(&desc, |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 808 | io, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 809 | strategy, |
| 810 | session, |
| 811 | id))); |
| 812 | return NO_ERROR; |
| 813 | } break; |
| 814 | |
| 815 | case UNREGISTER_EFFECT: { |
| 816 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 817 | int id = data.readInt32(); |
| 818 | reply->writeInt32(static_cast <int32_t>(unregisterEffect(id))); |
| 819 | return NO_ERROR; |
| 820 | } break; |
| 821 | |
Eric Laurent | db7c079 | 2011-08-10 10:37:50 -0700 | [diff] [blame] | 822 | case SET_EFFECT_ENABLED: { |
| 823 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 824 | int id = data.readInt32(); |
| 825 | bool enabled = static_cast <bool>(data.readInt32()); |
| 826 | reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled))); |
| 827 | return NO_ERROR; |
| 828 | } break; |
| 829 | |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 830 | case IS_STREAM_ACTIVE: { |
| 831 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 832 | audio_stream_type_t stream = (audio_stream_type_t) data.readInt32(); |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 833 | uint32_t inPastMs = (uint32_t)data.readInt32(); |
Eric Laurent | ebcb254 | 2014-03-05 18:30:08 -0800 | [diff] [blame] | 834 | reply->writeInt32( isStreamActive(stream, inPastMs) ); |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 835 | return NO_ERROR; |
| 836 | } break; |
| 837 | |
Jean-Michel Trivi | 272ab54 | 2013-02-04 16:26:02 -0800 | [diff] [blame] | 838 | case IS_STREAM_ACTIVE_REMOTELY: { |
| 839 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 840 | audio_stream_type_t stream = (audio_stream_type_t) data.readInt32(); |
| 841 | uint32_t inPastMs = (uint32_t)data.readInt32(); |
Eric Laurent | ebcb254 | 2014-03-05 18:30:08 -0800 | [diff] [blame] | 842 | reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) ); |
Jean-Michel Trivi | 272ab54 | 2013-02-04 16:26:02 -0800 | [diff] [blame] | 843 | return NO_ERROR; |
| 844 | } break; |
| 845 | |
Jean-Michel Trivi | d708603 | 2012-10-10 12:11:16 -0700 | [diff] [blame] | 846 | case IS_SOURCE_ACTIVE: { |
| 847 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 848 | audio_source_t source = (audio_source_t) data.readInt32(); |
| 849 | reply->writeInt32( isSourceActive(source)); |
| 850 | return NO_ERROR; |
| 851 | } |
| 852 | |
Eric Laurent | 57dae99 | 2011-07-24 13:36:09 -0700 | [diff] [blame] | 853 | case QUERY_DEFAULT_PRE_PROCESSING: { |
| 854 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 855 | int audioSession = data.readInt32(); |
| 856 | uint32_t count = data.readInt32(); |
| 857 | uint32_t retCount = count; |
| 858 | effect_descriptor_t *descriptors = |
| 859 | (effect_descriptor_t *)new char[count * sizeof(effect_descriptor_t)]; |
| 860 | status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount); |
| 861 | reply->writeInt32(status); |
| 862 | if (status != NO_ERROR && status != NO_MEMORY) { |
| 863 | retCount = 0; |
| 864 | } |
| 865 | reply->writeInt32(retCount); |
| 866 | if (retCount) { |
| 867 | if (retCount < count) { |
| 868 | count = retCount; |
| 869 | } |
| 870 | reply->write(descriptors, sizeof(effect_descriptor_t) * count); |
| 871 | } |
| 872 | delete[] descriptors; |
| 873 | return status; |
| 874 | } |
| 875 | |
Richard Fitzgerald | b1a270d | 2013-05-14 12:12:21 +0100 | [diff] [blame] | 876 | case IS_OFFLOAD_SUPPORTED: { |
| 877 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 878 | audio_offload_info_t info; |
| 879 | data.read(&info, sizeof(audio_offload_info_t)); |
| 880 | bool isSupported = isOffloadSupported(info); |
| 881 | reply->writeInt32(isSupported); |
| 882 | return NO_ERROR; |
| 883 | } |
| 884 | |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 885 | case LIST_AUDIO_PORTS: { |
| 886 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 887 | audio_port_role_t role = (audio_port_role_t)data.readInt32(); |
| 888 | audio_port_type_t type = (audio_port_type_t)data.readInt32(); |
| 889 | unsigned int numPortsReq = data.readInt32(); |
| 890 | unsigned int numPorts = numPortsReq; |
| 891 | unsigned int generation; |
| 892 | struct audio_port *ports = |
| 893 | (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port)); |
| 894 | status_t status = listAudioPorts(role, type, &numPorts, ports, &generation); |
| 895 | reply->writeInt32(status); |
| 896 | reply->writeInt32(numPorts); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 897 | |
| 898 | if (status == NO_ERROR) { |
| 899 | if (numPortsReq > numPorts) { |
| 900 | numPortsReq = numPorts; |
| 901 | } |
| 902 | reply->write(ports, numPortsReq * sizeof(struct audio_port)); |
| 903 | reply->writeInt32(generation); |
| 904 | } |
| 905 | free(ports); |
| 906 | return NO_ERROR; |
| 907 | } |
| 908 | |
| 909 | case GET_AUDIO_PORT: { |
| 910 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 911 | struct audio_port port; |
| 912 | data.read(&port, sizeof(struct audio_port)); |
| 913 | status_t status = getAudioPort(&port); |
| 914 | reply->writeInt32(status); |
| 915 | if (status == NO_ERROR) { |
| 916 | reply->write(&port, sizeof(struct audio_port)); |
| 917 | } |
| 918 | return NO_ERROR; |
| 919 | } |
| 920 | |
| 921 | case CREATE_AUDIO_PATCH: { |
| 922 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 923 | struct audio_patch patch; |
| 924 | data.read(&patch, sizeof(struct audio_patch)); |
| 925 | audio_patch_handle_t handle; |
| 926 | data.read(&handle, sizeof(audio_patch_handle_t)); |
| 927 | status_t status = createAudioPatch(&patch, &handle); |
| 928 | reply->writeInt32(status); |
| 929 | if (status == NO_ERROR) { |
| 930 | reply->write(&handle, sizeof(audio_patch_handle_t)); |
| 931 | } |
| 932 | return NO_ERROR; |
| 933 | } |
| 934 | |
| 935 | case RELEASE_AUDIO_PATCH: { |
| 936 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 937 | audio_patch_handle_t handle; |
| 938 | data.read(&handle, sizeof(audio_patch_handle_t)); |
| 939 | status_t status = releaseAudioPatch(handle); |
| 940 | reply->writeInt32(status); |
| 941 | return NO_ERROR; |
| 942 | } |
| 943 | |
| 944 | case LIST_AUDIO_PATCHES: { |
| 945 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 946 | unsigned int numPatchesReq = data.readInt32(); |
| 947 | unsigned int numPatches = numPatchesReq; |
| 948 | unsigned int generation; |
| 949 | struct audio_patch *patches = |
| 950 | (struct audio_patch *)calloc(numPatchesReq, |
| 951 | sizeof(struct audio_patch)); |
| 952 | status_t status = listAudioPatches(&numPatches, patches, &generation); |
| 953 | reply->writeInt32(status); |
| 954 | reply->writeInt32(numPatches); |
| 955 | if (status == NO_ERROR) { |
| 956 | if (numPatchesReq > numPatches) { |
| 957 | numPatchesReq = numPatches; |
| 958 | } |
| 959 | reply->write(patches, numPatchesReq * sizeof(struct audio_patch)); |
| 960 | reply->writeInt32(generation); |
| 961 | } |
| 962 | free(patches); |
| 963 | return NO_ERROR; |
| 964 | } |
| 965 | |
| 966 | case SET_AUDIO_PORT_CONFIG: { |
| 967 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 968 | struct audio_port_config config; |
| 969 | data.read(&config, sizeof(struct audio_port_config)); |
| 970 | status_t status = setAudioPortConfig(&config); |
| 971 | reply->writeInt32(status); |
| 972 | return NO_ERROR; |
| 973 | } |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 974 | case REGISTER_CLIENT: { |
| 975 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 976 | sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>( |
| 977 | data.readStrongBinder()); |
| 978 | registerClient(client); |
| 979 | return NO_ERROR; |
| 980 | } break; |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 981 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 982 | default: |
| 983 | return BBinder::onTransact(code, data, reply, flags); |
| 984 | } |
| 985 | } |
| 986 | |
| 987 | // ---------------------------------------------------------------------------- |
| 988 | |
| 989 | }; // namespace android |