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