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, |
| 55 | GET_DEVICES_FOR_STREAM, |
Eric Laurent | db7c079 | 2011-08-10 10:37:50 -0700 | [diff] [blame] | 56 | QUERY_DEFAULT_PRE_PROCESSING, |
| 57 | SET_EFFECT_ENABLED |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | class BpAudioPolicyService : public BpInterface<IAudioPolicyService> |
| 61 | { |
| 62 | public: |
| 63 | BpAudioPolicyService(const sp<IBinder>& impl) |
| 64 | : BpInterface<IAudioPolicyService>(impl) |
| 65 | { |
| 66 | } |
| 67 | |
| 68 | virtual status_t setDeviceConnectionState( |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 69 | audio_devices_t device, |
| 70 | audio_policy_dev_state_t state, |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 71 | const char *device_address) |
| 72 | { |
| 73 | Parcel data, reply; |
| 74 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 75 | data.writeInt32(static_cast <uint32_t>(device)); |
| 76 | data.writeInt32(static_cast <uint32_t>(state)); |
| 77 | data.writeCString(device_address); |
| 78 | remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply); |
| 79 | return static_cast <status_t> (reply.readInt32()); |
| 80 | } |
| 81 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 82 | virtual audio_policy_dev_state_t getDeviceConnectionState( |
| 83 | audio_devices_t device, |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 84 | const char *device_address) |
| 85 | { |
| 86 | Parcel data, reply; |
| 87 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 88 | data.writeInt32(static_cast <uint32_t>(device)); |
| 89 | data.writeCString(device_address); |
| 90 | remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 91 | return static_cast <audio_policy_dev_state_t>(reply.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Glenn Kasten | f78aee7 | 2012-01-04 11:00:47 -0800 | [diff] [blame] | 94 | virtual status_t setPhoneState(audio_mode_t state) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 95 | { |
| 96 | Parcel data, reply; |
| 97 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 98 | data.writeInt32(state); |
| 99 | remote()->transact(SET_PHONE_STATE, data, &reply); |
| 100 | return static_cast <status_t> (reply.readInt32()); |
| 101 | } |
| 102 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 103 | 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] | 104 | { |
| 105 | Parcel data, reply; |
| 106 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 107 | data.writeInt32(static_cast <uint32_t>(usage)); |
| 108 | data.writeInt32(static_cast <uint32_t>(config)); |
| 109 | remote()->transact(SET_FORCE_USE, data, &reply); |
| 110 | return static_cast <status_t> (reply.readInt32()); |
| 111 | } |
| 112 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 113 | 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] | 114 | { |
| 115 | Parcel data, reply; |
| 116 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 117 | data.writeInt32(static_cast <uint32_t>(usage)); |
| 118 | remote()->transact(GET_FORCE_USE, data, &reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 119 | return static_cast <audio_policy_forced_cfg_t> (reply.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | virtual audio_io_handle_t getOutput( |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 123 | audio_stream_type_t stream, |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 124 | uint32_t samplingRate, |
| 125 | uint32_t format, |
| 126 | uint32_t channels, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 127 | audio_policy_output_flags_t flags) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 128 | { |
| 129 | Parcel data, reply; |
| 130 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 131 | data.writeInt32(static_cast <uint32_t>(stream)); |
| 132 | data.writeInt32(samplingRate); |
| 133 | data.writeInt32(static_cast <uint32_t>(format)); |
| 134 | data.writeInt32(channels); |
| 135 | data.writeInt32(static_cast <uint32_t>(flags)); |
| 136 | remote()->transact(GET_OUTPUT, data, &reply); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 137 | return static_cast <audio_io_handle_t> (reply.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 140 | virtual status_t startOutput(audio_io_handle_t output, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 141 | audio_stream_type_t stream, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 142 | int session) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 143 | { |
| 144 | Parcel data, reply; |
| 145 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 146 | data.writeInt32(output); |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 147 | data.writeInt32((int32_t) stream); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 148 | data.writeInt32(session); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 149 | remote()->transact(START_OUTPUT, data, &reply); |
| 150 | return static_cast <status_t> (reply.readInt32()); |
| 151 | } |
| 152 | |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 153 | virtual status_t stopOutput(audio_io_handle_t output, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 154 | audio_stream_type_t stream, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 155 | int session) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 156 | { |
| 157 | Parcel data, reply; |
| 158 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 159 | data.writeInt32(output); |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 160 | data.writeInt32((int32_t) stream); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 161 | data.writeInt32(session); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 162 | remote()->transact(STOP_OUTPUT, data, &reply); |
| 163 | return static_cast <status_t> (reply.readInt32()); |
| 164 | } |
| 165 | |
| 166 | virtual void releaseOutput(audio_io_handle_t output) |
| 167 | { |
| 168 | Parcel data, reply; |
| 169 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 170 | data.writeInt32(output); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 171 | remote()->transact(RELEASE_OUTPUT, data, &reply); |
| 172 | } |
| 173 | |
| 174 | virtual audio_io_handle_t getInput( |
| 175 | int inputSource, |
| 176 | uint32_t samplingRate, |
| 177 | uint32_t format, |
| 178 | uint32_t channels, |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 179 | audio_in_acoustics_t acoustics, |
| 180 | int audioSession) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 181 | { |
| 182 | Parcel data, reply; |
| 183 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 184 | data.writeInt32(inputSource); |
| 185 | data.writeInt32(samplingRate); |
| 186 | data.writeInt32(static_cast <uint32_t>(format)); |
| 187 | data.writeInt32(channels); |
| 188 | data.writeInt32(static_cast <uint32_t>(acoustics)); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 189 | data.writeInt32(audioSession); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 190 | remote()->transact(GET_INPUT, data, &reply); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 191 | return static_cast <audio_io_handle_t> (reply.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | virtual status_t startInput(audio_io_handle_t input) |
| 195 | { |
| 196 | Parcel data, reply; |
| 197 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 198 | data.writeInt32(input); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 199 | remote()->transact(START_INPUT, data, &reply); |
| 200 | return static_cast <status_t> (reply.readInt32()); |
| 201 | } |
| 202 | |
| 203 | virtual status_t stopInput(audio_io_handle_t input) |
| 204 | { |
| 205 | Parcel data, reply; |
| 206 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 207 | data.writeInt32(input); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 208 | remote()->transact(STOP_INPUT, data, &reply); |
| 209 | return static_cast <status_t> (reply.readInt32()); |
| 210 | } |
| 211 | |
| 212 | virtual void releaseInput(audio_io_handle_t input) |
| 213 | { |
| 214 | Parcel data, reply; |
| 215 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 216 | data.writeInt32(input); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 217 | remote()->transact(RELEASE_INPUT, data, &reply); |
| 218 | } |
| 219 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 220 | virtual status_t initStreamVolume(audio_stream_type_t stream, |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 221 | int indexMin, |
| 222 | int indexMax) |
| 223 | { |
| 224 | Parcel data, reply; |
| 225 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 226 | data.writeInt32(static_cast <uint32_t>(stream)); |
| 227 | data.writeInt32(indexMin); |
| 228 | data.writeInt32(indexMax); |
| 229 | remote()->transact(INIT_STREAM_VOLUME, data, &reply); |
| 230 | return static_cast <status_t> (reply.readInt32()); |
| 231 | } |
| 232 | |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 233 | virtual status_t setStreamVolumeIndex(audio_stream_type_t stream, |
| 234 | int index, |
| 235 | audio_devices_t device) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 236 | { |
| 237 | Parcel data, reply; |
| 238 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 239 | data.writeInt32(static_cast <uint32_t>(stream)); |
| 240 | data.writeInt32(index); |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 241 | data.writeInt32(static_cast <uint32_t>(device)); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 242 | remote()->transact(SET_STREAM_VOLUME, data, &reply); |
| 243 | return static_cast <status_t> (reply.readInt32()); |
| 244 | } |
| 245 | |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 246 | virtual status_t getStreamVolumeIndex(audio_stream_type_t stream, |
| 247 | int *index, |
| 248 | audio_devices_t device) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 249 | { |
| 250 | Parcel data, reply; |
| 251 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 252 | data.writeInt32(static_cast <uint32_t>(stream)); |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 253 | data.writeInt32(static_cast <uint32_t>(device)); |
| 254 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 255 | remote()->transact(GET_STREAM_VOLUME, data, &reply); |
| 256 | int lIndex = reply.readInt32(); |
| 257 | if (index) *index = lIndex; |
| 258 | return static_cast <status_t> (reply.readInt32()); |
| 259 | } |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 260 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 261 | virtual uint32_t getStrategyForStream(audio_stream_type_t stream) |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 262 | { |
| 263 | Parcel data, reply; |
| 264 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 265 | data.writeInt32(static_cast <uint32_t>(stream)); |
| 266 | remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply); |
| 267 | return reply.readInt32(); |
| 268 | } |
| 269 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 270 | virtual uint32_t getDevicesForStream(audio_stream_type_t stream) |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 271 | { |
| 272 | Parcel data, reply; |
| 273 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 274 | data.writeInt32(static_cast <uint32_t>(stream)); |
| 275 | remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply); |
| 276 | return (uint32_t) reply.readInt32(); |
| 277 | } |
| 278 | |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 279 | virtual audio_io_handle_t getOutputForEffect(effect_descriptor_t *desc) |
| 280 | { |
| 281 | Parcel data, reply; |
| 282 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 283 | data.write(desc, sizeof(effect_descriptor_t)); |
| 284 | remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply); |
| 285 | return static_cast <audio_io_handle_t> (reply.readInt32()); |
| 286 | } |
| 287 | |
| 288 | virtual status_t registerEffect(effect_descriptor_t *desc, |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 289 | audio_io_handle_t io, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 290 | uint32_t strategy, |
| 291 | int session, |
| 292 | int id) |
| 293 | { |
| 294 | Parcel data, reply; |
| 295 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 296 | data.write(desc, sizeof(effect_descriptor_t)); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 297 | data.writeInt32(io); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 298 | data.writeInt32(strategy); |
| 299 | data.writeInt32(session); |
| 300 | data.writeInt32(id); |
| 301 | remote()->transact(REGISTER_EFFECT, data, &reply); |
| 302 | return static_cast <status_t> (reply.readInt32()); |
| 303 | } |
| 304 | |
| 305 | virtual status_t unregisterEffect(int id) |
| 306 | { |
| 307 | Parcel data, reply; |
| 308 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 309 | data.writeInt32(id); |
| 310 | remote()->transact(UNREGISTER_EFFECT, data, &reply); |
| 311 | return static_cast <status_t> (reply.readInt32()); |
| 312 | } |
| 313 | |
Eric Laurent | db7c079 | 2011-08-10 10:37:50 -0700 | [diff] [blame] | 314 | virtual status_t setEffectEnabled(int id, bool enabled) |
| 315 | { |
| 316 | Parcel data, reply; |
| 317 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 318 | data.writeInt32(id); |
| 319 | data.writeInt32(enabled); |
| 320 | remote()->transact(SET_EFFECT_ENABLED, data, &reply); |
| 321 | return static_cast <status_t> (reply.readInt32()); |
| 322 | } |
| 323 | |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 324 | virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 325 | { |
| 326 | Parcel data, reply; |
| 327 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 328 | data.writeInt32((int32_t) stream); |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 329 | data.writeInt32(inPastMs); |
| 330 | remote()->transact(IS_STREAM_ACTIVE, data, &reply); |
| 331 | return reply.readInt32(); |
| 332 | } |
Eric Laurent | 57dae99 | 2011-07-24 13:36:09 -0700 | [diff] [blame] | 333 | |
| 334 | virtual status_t queryDefaultPreProcessing(int audioSession, |
| 335 | effect_descriptor_t *descriptors, |
| 336 | uint32_t *count) |
| 337 | { |
| 338 | if (descriptors == NULL || count == NULL) { |
| 339 | return BAD_VALUE; |
| 340 | } |
| 341 | Parcel data, reply; |
| 342 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 343 | data.writeInt32(audioSession); |
| 344 | data.writeInt32(*count); |
| 345 | status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply); |
| 346 | if (status != NO_ERROR) { |
| 347 | return status; |
| 348 | } |
| 349 | status = static_cast <status_t> (reply.readInt32()); |
| 350 | uint32_t retCount = reply.readInt32(); |
| 351 | if (retCount != 0) { |
| 352 | uint32_t numDesc = (retCount < *count) ? retCount : *count; |
| 353 | reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc); |
| 354 | } |
| 355 | *count = retCount; |
| 356 | return status; |
| 357 | } |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 358 | }; |
| 359 | |
| 360 | IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService"); |
| 361 | |
| 362 | // ---------------------------------------------------------------------- |
| 363 | |
| 364 | |
| 365 | status_t BnAudioPolicyService::onTransact( |
| 366 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 367 | { |
| 368 | switch(code) { |
| 369 | case SET_DEVICE_CONNECTION_STATE: { |
| 370 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 371 | audio_devices_t device = |
| 372 | static_cast <audio_devices_t>(data.readInt32()); |
| 373 | audio_policy_dev_state_t state = |
| 374 | static_cast <audio_policy_dev_state_t>(data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 375 | const char *device_address = data.readCString(); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 376 | reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device, |
| 377 | state, |
| 378 | device_address))); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 379 | return NO_ERROR; |
| 380 | } break; |
| 381 | |
| 382 | case GET_DEVICE_CONNECTION_STATE: { |
| 383 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 384 | audio_devices_t device = |
| 385 | static_cast<audio_devices_t> (data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 386 | const char *device_address = data.readCString(); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 387 | reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device, |
| 388 | device_address))); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 389 | return NO_ERROR; |
| 390 | } break; |
| 391 | |
| 392 | case SET_PHONE_STATE: { |
| 393 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Glenn Kasten | f78aee7 | 2012-01-04 11:00:47 -0800 | [diff] [blame] | 394 | reply->writeInt32(static_cast <uint32_t>(setPhoneState((audio_mode_t) data.readInt32()))); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 395 | return NO_ERROR; |
| 396 | } break; |
| 397 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 398 | case SET_FORCE_USE: { |
| 399 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 400 | audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(data.readInt32()); |
| 401 | audio_policy_forced_cfg_t config = |
| 402 | static_cast <audio_policy_forced_cfg_t>(data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 403 | reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config))); |
| 404 | return NO_ERROR; |
| 405 | } break; |
| 406 | |
| 407 | case GET_FORCE_USE: { |
| 408 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 409 | audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 410 | reply->writeInt32(static_cast <uint32_t>(getForceUse(usage))); |
| 411 | return NO_ERROR; |
| 412 | } break; |
| 413 | |
| 414 | case GET_OUTPUT: { |
| 415 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 416 | audio_stream_type_t stream = |
| 417 | static_cast <audio_stream_type_t>(data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 418 | uint32_t samplingRate = data.readInt32(); |
| 419 | uint32_t format = data.readInt32(); |
| 420 | uint32_t channels = data.readInt32(); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 421 | audio_policy_output_flags_t flags = |
| 422 | static_cast <audio_policy_output_flags_t>(data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 423 | |
| 424 | audio_io_handle_t output = getOutput(stream, |
| 425 | samplingRate, |
| 426 | format, |
| 427 | channels, |
| 428 | flags); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 429 | reply->writeInt32(static_cast <int>(output)); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 430 | return NO_ERROR; |
| 431 | } break; |
| 432 | |
| 433 | case START_OUTPUT: { |
| 434 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 435 | 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] | 436 | uint32_t stream = data.readInt32(); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 437 | int session = data.readInt32(); |
| 438 | reply->writeInt32(static_cast <uint32_t>(startOutput(output, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 439 | (audio_stream_type_t)stream, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 440 | session))); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 441 | return NO_ERROR; |
| 442 | } break; |
| 443 | |
| 444 | case STOP_OUTPUT: { |
| 445 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 446 | 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] | 447 | uint32_t stream = data.readInt32(); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 448 | int session = data.readInt32(); |
| 449 | reply->writeInt32(static_cast <uint32_t>(stopOutput(output, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 450 | (audio_stream_type_t)stream, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 451 | session))); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 452 | return NO_ERROR; |
| 453 | } break; |
| 454 | |
| 455 | case RELEASE_OUTPUT: { |
| 456 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 457 | 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] | 458 | releaseOutput(output); |
| 459 | return NO_ERROR; |
| 460 | } break; |
| 461 | |
| 462 | case GET_INPUT: { |
| 463 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 464 | int inputSource = data.readInt32(); |
| 465 | uint32_t samplingRate = data.readInt32(); |
| 466 | uint32_t format = data.readInt32(); |
| 467 | uint32_t channels = data.readInt32(); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 468 | audio_in_acoustics_t acoustics = |
| 469 | static_cast <audio_in_acoustics_t>(data.readInt32()); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 470 | int audioSession = data.readInt32(); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 471 | audio_io_handle_t input = getInput(inputSource, |
| 472 | samplingRate, |
| 473 | format, |
| 474 | channels, |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 475 | acoustics, |
| 476 | audioSession); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 477 | reply->writeInt32(static_cast <int>(input)); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 478 | return NO_ERROR; |
| 479 | } break; |
| 480 | |
| 481 | case START_INPUT: { |
| 482 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 483 | 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] | 484 | reply->writeInt32(static_cast <uint32_t>(startInput(input))); |
| 485 | return NO_ERROR; |
| 486 | } break; |
| 487 | |
| 488 | case STOP_INPUT: { |
| 489 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 490 | 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] | 491 | reply->writeInt32(static_cast <uint32_t>(stopInput(input))); |
| 492 | return NO_ERROR; |
| 493 | } break; |
| 494 | |
| 495 | case RELEASE_INPUT: { |
| 496 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 497 | 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] | 498 | releaseInput(input); |
| 499 | return NO_ERROR; |
| 500 | } break; |
| 501 | |
| 502 | case INIT_STREAM_VOLUME: { |
| 503 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 504 | audio_stream_type_t stream = |
| 505 | static_cast <audio_stream_type_t>(data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 506 | int indexMin = data.readInt32(); |
| 507 | int indexMax = data.readInt32(); |
| 508 | reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax))); |
| 509 | return NO_ERROR; |
| 510 | } break; |
| 511 | |
| 512 | case SET_STREAM_VOLUME: { |
| 513 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 514 | audio_stream_type_t stream = |
| 515 | static_cast <audio_stream_type_t>(data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 516 | int index = data.readInt32(); |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 517 | audio_devices_t device = static_cast <audio_devices_t>(data.readInt32()); |
| 518 | reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream, |
| 519 | index, |
| 520 | device))); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 521 | return NO_ERROR; |
| 522 | } break; |
| 523 | |
| 524 | case GET_STREAM_VOLUME: { |
| 525 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 526 | audio_stream_type_t stream = |
| 527 | static_cast <audio_stream_type_t>(data.readInt32()); |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 528 | audio_devices_t device = static_cast <audio_devices_t>(data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 529 | int index; |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 530 | status_t status = getStreamVolumeIndex(stream, &index, device); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 531 | reply->writeInt32(index); |
| 532 | reply->writeInt32(static_cast <uint32_t>(status)); |
| 533 | return NO_ERROR; |
| 534 | } break; |
| 535 | |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 536 | case GET_STRATEGY_FOR_STREAM: { |
| 537 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 538 | audio_stream_type_t stream = |
| 539 | static_cast <audio_stream_type_t>(data.readInt32()); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 540 | reply->writeInt32(getStrategyForStream(stream)); |
| 541 | return NO_ERROR; |
| 542 | } break; |
| 543 | |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 544 | case GET_DEVICES_FOR_STREAM: { |
| 545 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 546 | audio_stream_type_t stream = |
| 547 | static_cast <audio_stream_type_t>(data.readInt32()); |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 548 | reply->writeInt32(static_cast <int>(getDevicesForStream(stream))); |
| 549 | return NO_ERROR; |
| 550 | } break; |
| 551 | |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 552 | case GET_OUTPUT_FOR_EFFECT: { |
| 553 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 554 | effect_descriptor_t desc; |
| 555 | data.read(&desc, sizeof(effect_descriptor_t)); |
| 556 | audio_io_handle_t output = getOutputForEffect(&desc); |
| 557 | reply->writeInt32(static_cast <int>(output)); |
| 558 | return NO_ERROR; |
| 559 | } break; |
| 560 | |
| 561 | case REGISTER_EFFECT: { |
| 562 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 563 | effect_descriptor_t desc; |
| 564 | data.read(&desc, sizeof(effect_descriptor_t)); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 565 | audio_io_handle_t io = data.readInt32(); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 566 | uint32_t strategy = data.readInt32(); |
| 567 | int session = data.readInt32(); |
| 568 | int id = data.readInt32(); |
| 569 | reply->writeInt32(static_cast <int32_t>(registerEffect(&desc, |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 570 | io, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 571 | strategy, |
| 572 | session, |
| 573 | id))); |
| 574 | return NO_ERROR; |
| 575 | } break; |
| 576 | |
| 577 | case UNREGISTER_EFFECT: { |
| 578 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 579 | int id = data.readInt32(); |
| 580 | reply->writeInt32(static_cast <int32_t>(unregisterEffect(id))); |
| 581 | return NO_ERROR; |
| 582 | } break; |
| 583 | |
Eric Laurent | db7c079 | 2011-08-10 10:37:50 -0700 | [diff] [blame] | 584 | case SET_EFFECT_ENABLED: { |
| 585 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 586 | int id = data.readInt32(); |
| 587 | bool enabled = static_cast <bool>(data.readInt32()); |
| 588 | reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled))); |
| 589 | return NO_ERROR; |
| 590 | } break; |
| 591 | |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 592 | case IS_STREAM_ACTIVE: { |
| 593 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 594 | audio_stream_type_t stream = (audio_stream_type_t) data.readInt32(); |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 595 | uint32_t inPastMs = (uint32_t)data.readInt32(); |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 596 | reply->writeInt32( isStreamActive((audio_stream_type_t) stream, inPastMs) ); |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 597 | return NO_ERROR; |
| 598 | } break; |
| 599 | |
Eric Laurent | 57dae99 | 2011-07-24 13:36:09 -0700 | [diff] [blame] | 600 | case QUERY_DEFAULT_PRE_PROCESSING: { |
| 601 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 602 | int audioSession = data.readInt32(); |
| 603 | uint32_t count = data.readInt32(); |
| 604 | uint32_t retCount = count; |
| 605 | effect_descriptor_t *descriptors = |
| 606 | (effect_descriptor_t *)new char[count * sizeof(effect_descriptor_t)]; |
| 607 | status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount); |
| 608 | reply->writeInt32(status); |
| 609 | if (status != NO_ERROR && status != NO_MEMORY) { |
| 610 | retCount = 0; |
| 611 | } |
| 612 | reply->writeInt32(retCount); |
| 613 | if (retCount) { |
| 614 | if (retCount < count) { |
| 615 | count = retCount; |
| 616 | } |
| 617 | reply->write(descriptors, sizeof(effect_descriptor_t) * count); |
| 618 | } |
| 619 | delete[] descriptors; |
| 620 | return status; |
| 621 | } |
| 622 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 623 | default: |
| 624 | return BBinder::onTransact(code, data, reply, flags); |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | // ---------------------------------------------------------------------------- |
| 629 | |
| 630 | }; // namespace android |