The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006-2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "AudioSystem" |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | |
| 20 | #include <utils/Log.h> |
Ytai Ben-Tsvi | 5120eda | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 21 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 22 | #include <android/media/IAudioPolicyService.h> |
Ytai Ben-Tsvi | 5120eda | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 23 | #include <android/media/BnCaptureStateListener.h> |
Mathias Agopian | 7562408 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 24 | #include <binder/IServiceManager.h> |
Eric Laurent | fb00fc7 | 2017-05-25 18:17:12 -0700 | [diff] [blame] | 25 | #include <binder/ProcessState.h> |
François Gaffie | 2443760 | 2018-04-23 15:08:59 +0200 | [diff] [blame] | 26 | #include <binder/IPCThreadState.h> |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 27 | #include <media/AidlConversion.h> |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 28 | #include <media/AudioResamplerPublic.h> |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | #include <media/AudioSystem.h> |
Glenn Kasten | 1ab85ec | 2013-05-31 09:18:43 -0700 | [diff] [blame] | 30 | #include <media/IAudioFlinger.h> |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 31 | #include <media/PolicyAidlConversion.h> |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 32 | #include <media/TypeConverter.h> |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | #include <math.h> |
| 34 | |
Dima Zavin | 6476024 | 2011-05-11 14:15:23 -0700 | [diff] [blame] | 35 | #include <system/audio.h> |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 36 | #include <android/media/GetInputForAttrResponse.h> |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 37 | |
Ytai Ben-Tsvi | 1ff7569 | 2020-11-06 12:16:12 -0800 | [diff] [blame] | 38 | #define VALUE_OR_RETURN_BINDER_STATUS(x) \ |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 39 | ({ auto _tmp = (x); \ |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 40 | if (!_tmp.ok()) return aidl_utils::binderStatusFromStatusT(_tmp.error()); \ |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 41 | std::move(_tmp.value()); }) |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 42 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 43 | #define RETURN_STATUS_IF_ERROR(x) \ |
| 44 | { \ |
| 45 | auto _tmp = (x); \ |
| 46 | if (_tmp != OK) return _tmp; \ |
| 47 | } |
| 48 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 49 | // ---------------------------------------------------------------------------- |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 50 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | namespace android { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 52 | using aidl_utils::statusTFromBinderStatus; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 53 | using binder::Status; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 54 | using media::IAudioPolicyService; |
Svet Ganov | 3376113 | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 55 | using android::content::AttributionSourceState; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 56 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | // client singleton for AudioFlinger binder interface |
| 58 | Mutex AudioSystem::gLock; |
Ytai Ben-Tsvi | 000c3e4 | 2020-01-09 15:26:40 -0800 | [diff] [blame] | 59 | Mutex AudioSystem::gLockErrorCallbacks; |
Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 60 | Mutex AudioSystem::gLockAPS; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | sp<IAudioFlinger> AudioSystem::gAudioFlinger; |
| 62 | sp<AudioSystem::AudioFlingerClient> AudioSystem::gAudioFlingerClient; |
Ytai Ben-Tsvi | 000c3e4 | 2020-01-09 15:26:40 -0800 | [diff] [blame] | 63 | std::set<audio_error_callback> AudioSystem::gAudioErrorCallbacks; |
Jean-Michel Trivi | f613d42 | 2015-04-23 18:41:29 -0700 | [diff] [blame] | 64 | dynamic_policy_callback AudioSystem::gDynPolicyCallback = NULL; |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 65 | record_config_callback AudioSystem::gRecordConfigCallback = NULL; |
Jean-Michel Trivi | 9a6b9ad | 2020-10-22 16:46:43 -0700 | [diff] [blame] | 66 | routing_callback AudioSystem::gRoutingCallback = NULL; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | |
Ytai Ben-Tsvi | 5120eda | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 68 | // Required to be held while calling into gSoundTriggerCaptureStateListener. |
Ytai Ben-Tsvi | d9f8283 | 2020-08-27 09:31:10 -0700 | [diff] [blame] | 69 | class CaptureStateListenerImpl; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 70 | |
Ytai Ben-Tsvi | 5120eda | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 71 | Mutex gSoundTriggerCaptureStateListenerLock; |
Ytai Ben-Tsvi | d9f8283 | 2020-08-27 09:31:10 -0700 | [diff] [blame] | 72 | sp<CaptureStateListenerImpl> gSoundTriggerCaptureStateListener = nullptr; |
Ytai Ben-Tsvi | 5120eda | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 73 | |
Ahaan Ugale | 058f94b | 2021-05-21 02:23:50 -0700 | [diff] [blame^] | 74 | // Binder for the AudioFlinger service that's passed to this client process from the system server. |
| 75 | // This allows specific isolated processes to access the audio system. Currently used only for the |
| 76 | // HotwordDetectionService. |
| 77 | sp<IBinder> gAudioFlingerBinder = nullptr; |
| 78 | |
| 79 | void AudioSystem::setAudioFlingerBinder(const sp<IBinder>& audioFlinger) { |
| 80 | if (audioFlinger->getInterfaceDescriptor() != media::IAudioFlingerService::descriptor) { |
| 81 | ALOGE("setAudioFlingerBinder: received a binder of type %s", |
| 82 | String8(audioFlinger->getInterfaceDescriptor()).string()); |
| 83 | return; |
| 84 | } |
| 85 | Mutex::Autolock _l(gLock); |
| 86 | if (gAudioFlinger != nullptr) { |
| 87 | ALOGW("setAudioFlingerBinder: ignoring; AudioFlinger connection already established."); |
| 88 | return; |
| 89 | } |
| 90 | gAudioFlingerBinder = audioFlinger; |
| 91 | } |
| 92 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | // establish binder interface to AudioFlinger service |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 94 | const sp<IAudioFlinger> AudioSystem::get_audio_flinger() { |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 95 | sp<IAudioFlinger> af; |
| 96 | sp<AudioFlingerClient> afc; |
Mikhail Naganov | 69330d4 | 2020-04-08 19:29:50 +0000 | [diff] [blame] | 97 | bool reportNoError = false; |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 98 | { |
| 99 | Mutex::Autolock _l(gLock); |
| 100 | if (gAudioFlinger == 0) { |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 101 | sp<IBinder> binder; |
Ahaan Ugale | 058f94b | 2021-05-21 02:23:50 -0700 | [diff] [blame^] | 102 | if (gAudioFlingerBinder != nullptr) { |
| 103 | binder = gAudioFlingerBinder; |
| 104 | } else { |
| 105 | sp<IServiceManager> sm = defaultServiceManager(); |
| 106 | do { |
| 107 | binder = sm->getService(String16(IAudioFlinger::DEFAULT_SERVICE_NAME)); |
| 108 | if (binder != 0) |
| 109 | break; |
| 110 | ALOGW("AudioFlinger not published, waiting..."); |
| 111 | usleep(500000); // 0.5 s |
| 112 | } while (true); |
| 113 | } |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 114 | if (gAudioFlingerClient == NULL) { |
| 115 | gAudioFlingerClient = new AudioFlingerClient(); |
| 116 | } else { |
Mikhail Naganov | 69330d4 | 2020-04-08 19:29:50 +0000 | [diff] [blame] | 117 | reportNoError = true; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | } |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 119 | binder->linkToDeath(gAudioFlingerClient); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 120 | gAudioFlinger = new AudioFlingerClientAdapter( |
| 121 | interface_cast<media::IAudioFlingerService>(binder)); |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 122 | LOG_ALWAYS_FATAL_IF(gAudioFlinger == 0); |
| 123 | afc = gAudioFlingerClient; |
Eric Laurent | fb00fc7 | 2017-05-25 18:17:12 -0700 | [diff] [blame] | 124 | // Make sure callbacks can be received by gAudioFlingerClient |
| 125 | ProcessState::self()->startThreadPool(); |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 126 | } |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 127 | af = gAudioFlinger; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | } |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 129 | if (afc != 0) { |
François Gaffie | 2443760 | 2018-04-23 15:08:59 +0200 | [diff] [blame] | 130 | int64_t token = IPCThreadState::self()->clearCallingIdentity(); |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 131 | af->registerClient(afc); |
François Gaffie | 2443760 | 2018-04-23 15:08:59 +0200 | [diff] [blame] | 132 | IPCThreadState::self()->restoreCallingIdentity(token); |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 133 | } |
Mikhail Naganov | 69330d4 | 2020-04-08 19:29:50 +0000 | [diff] [blame] | 134 | if (reportNoError) reportError(NO_ERROR); |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 135 | return af; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | } |
| 137 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 138 | const sp<AudioSystem::AudioFlingerClient> AudioSystem::getAudioFlingerClient() { |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 139 | // calling get_audio_flinger() will initialize gAudioFlingerClient if needed |
| 140 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 141 | if (af == 0) return 0; |
| 142 | Mutex::Autolock _l(gLock); |
| 143 | return gAudioFlingerClient; |
| 144 | } |
| 145 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 146 | sp<AudioIoDescriptor> AudioSystem::getIoDescriptor(audio_io_handle_t ioHandle) { |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 147 | sp<AudioIoDescriptor> desc; |
| 148 | const sp<AudioFlingerClient> afc = getAudioFlingerClient(); |
| 149 | if (afc != 0) { |
| 150 | desc = afc->getIoDescriptor(ioHandle); |
| 151 | } |
| 152 | return desc; |
| 153 | } |
| 154 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 155 | /* static */ status_t AudioSystem::checkAudioFlinger() { |
Eric Laurent | 4629161 | 2013-07-18 14:38:44 -0700 | [diff] [blame] | 156 | if (defaultServiceManager()->checkService(String16("media.audio_flinger")) != 0) { |
| 157 | return NO_ERROR; |
| 158 | } |
| 159 | return DEAD_OBJECT; |
| 160 | } |
| 161 | |
Glenn Kasten | 4a8308b | 2016-04-18 14:10:01 -0700 | [diff] [blame] | 162 | // FIXME Declare in binder opcode order, similarly to IAudioFlinger.h and IAudioFlinger.cpp |
| 163 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 164 | status_t AudioSystem::muteMicrophone(bool state) { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 166 | if (af == 0) return PERMISSION_DENIED; |
| 167 | return af->setMicMute(state); |
| 168 | } |
| 169 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 170 | status_t AudioSystem::isMicrophoneMuted(bool* state) { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 171 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 172 | if (af == 0) return PERMISSION_DENIED; |
| 173 | *state = af->getMicMute(); |
| 174 | return NO_ERROR; |
| 175 | } |
| 176 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 177 | status_t AudioSystem::setMasterVolume(float value) { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 179 | if (af == 0) return PERMISSION_DENIED; |
| 180 | af->setMasterVolume(value); |
| 181 | return NO_ERROR; |
| 182 | } |
| 183 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 184 | status_t AudioSystem::setMasterMute(bool mute) { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 185 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 186 | if (af == 0) return PERMISSION_DENIED; |
| 187 | af->setMasterMute(mute); |
| 188 | return NO_ERROR; |
| 189 | } |
| 190 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 191 | status_t AudioSystem::getMasterVolume(float* volume) { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 192 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 193 | if (af == 0) return PERMISSION_DENIED; |
| 194 | *volume = af->masterVolume(); |
| 195 | return NO_ERROR; |
| 196 | } |
| 197 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 198 | status_t AudioSystem::getMasterMute(bool* mute) { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 199 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 200 | if (af == 0) return PERMISSION_DENIED; |
| 201 | *mute = af->masterMute(); |
| 202 | return NO_ERROR; |
| 203 | } |
| 204 | |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 205 | status_t AudioSystem::setStreamVolume(audio_stream_type_t stream, float value, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 206 | audio_io_handle_t output) { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 207 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 208 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 209 | if (af == 0) return PERMISSION_DENIED; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 210 | af->setStreamVolume(stream, value, output); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 211 | return NO_ERROR; |
| 212 | } |
| 213 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 214 | status_t AudioSystem::setStreamMute(audio_stream_type_t stream, bool mute) { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 215 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 216 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 217 | if (af == 0) return PERMISSION_DENIED; |
| 218 | af->setStreamMute(stream, mute); |
| 219 | return NO_ERROR; |
| 220 | } |
| 221 | |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 222 | status_t AudioSystem::getStreamVolume(audio_stream_type_t stream, float* volume, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 223 | audio_io_handle_t output) { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 224 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 225 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 226 | if (af == 0) return PERMISSION_DENIED; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 227 | *volume = af->streamVolume(stream, output); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 228 | return NO_ERROR; |
| 229 | } |
| 230 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 231 | status_t AudioSystem::getStreamMute(audio_stream_type_t stream, bool* mute) { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 232 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 233 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 234 | if (af == 0) return PERMISSION_DENIED; |
| 235 | *mute = af->streamMute(stream); |
| 236 | return NO_ERROR; |
| 237 | } |
| 238 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 239 | status_t AudioSystem::setMode(audio_mode_t mode) { |
Glenn Kasten | 930f4ca | 2012-01-06 16:47:31 -0800 | [diff] [blame] | 240 | if (uint32_t(mode) >= AUDIO_MODE_CNT) return BAD_VALUE; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 241 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 242 | if (af == 0) return PERMISSION_DENIED; |
| 243 | return af->setMode(mode); |
| 244 | } |
| 245 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 246 | status_t AudioSystem::setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs) { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 248 | if (af == 0) return PERMISSION_DENIED; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 249 | return af->setParameters(ioHandle, keyValuePairs); |
| 250 | } |
| 251 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 252 | String8 AudioSystem::getParameters(audio_io_handle_t ioHandle, const String8& keys) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 253 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 254 | String8 result = String8(""); |
| 255 | if (af == 0) return result; |
| 256 | |
| 257 | result = af->getParameters(ioHandle, keys); |
| 258 | return result; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | } |
| 260 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 261 | status_t AudioSystem::setParameters(const String8& keyValuePairs) { |
Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 262 | return setParameters(AUDIO_IO_HANDLE_NONE, keyValuePairs); |
Glenn Kasten | c23885e | 2013-12-19 16:35:18 -0800 | [diff] [blame] | 263 | } |
| 264 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 265 | String8 AudioSystem::getParameters(const String8& keys) { |
Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 266 | return getParameters(AUDIO_IO_HANDLE_NONE, keys); |
Glenn Kasten | c23885e | 2013-12-19 16:35:18 -0800 | [diff] [blame] | 267 | } |
| 268 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 269 | // convert volume steps to natural log scale |
| 270 | |
| 271 | // change this value to change volume scaling |
| 272 | static const float dBPerStep = 0.5f; |
| 273 | // shouldn't need to touch these |
| 274 | static const float dBConvert = -dBPerStep * 2.302585093f / 20.0f; |
| 275 | static const float dBConvertInverse = 1.0f / dBConvert; |
| 276 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 277 | float AudioSystem::linearToLog(int volume) { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 278 | // float v = volume ? exp(float(100 - volume) * dBConvert) : 0; |
Steve Block | b8a8052 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 279 | // ALOGD("linearToLog(%d)=%f", volume, v); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 280 | // return v; |
| 281 | return volume ? exp(float(100 - volume) * dBConvert) : 0; |
| 282 | } |
| 283 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 284 | int AudioSystem::logToLinear(float volume) { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 285 | // int v = volume ? 100 - int(dBConvertInverse * log(volume) + 0.5) : 0; |
Steve Block | b8a8052 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 286 | // ALOGD("logTolinear(%d)=%f", v, volume); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 287 | // return v; |
| 288 | return volume ? 100 - int(dBConvertInverse * log(volume) + 0.5) : 0; |
| 289 | } |
| 290 | |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 291 | /* static */ size_t AudioSystem::calculateMinFrameCount( |
| 292 | uint32_t afLatencyMs, uint32_t afFrameCount, uint32_t afSampleRate, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 293 | uint32_t sampleRate, float speed /*, uint32_t notificationsPerBufferReq*/) { |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 294 | // Ensure that buffer depth covers at least audio hardware latency |
| 295 | uint32_t minBufCount = afLatencyMs / ((1000 * afFrameCount) / afSampleRate); |
| 296 | if (minBufCount < 2) { |
| 297 | minBufCount = 2; |
| 298 | } |
| 299 | #if 0 |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 300 | // The notificationsPerBufferReq parameter is not yet used for non-fast tracks, |
| 301 | // but keeping the code here to make it easier to add later. |
| 302 | if (minBufCount < notificationsPerBufferReq) { |
| 303 | minBufCount = notificationsPerBufferReq; |
| 304 | } |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 305 | #endif |
| 306 | ALOGV("calculateMinFrameCount afLatency %u afFrameCount %u afSampleRate %u " |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 307 | "sampleRate %u speed %f minBufCount: %u" /*" notificationsPerBufferReq %u"*/, |
| 308 | afLatencyMs, afFrameCount, afSampleRate, sampleRate, speed, minBufCount |
| 309 | /*, notificationsPerBufferReq*/); |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 310 | return minBufCount * sourceFramesNeededWithTimestretch( |
| 311 | sampleRate, afFrameCount, afSampleRate, speed); |
| 312 | } |
| 313 | |
| 314 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 315 | status_t |
| 316 | AudioSystem::getOutputSamplingRate(uint32_t* samplingRate, audio_stream_type_t streamType) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 317 | audio_io_handle_t output; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 318 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 319 | if (streamType == AUDIO_STREAM_DEFAULT) { |
| 320 | streamType = AUDIO_STREAM_MUSIC; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 323 | output = getOutput(streamType); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 324 | if (output == 0) { |
| 325 | return PERMISSION_DENIED; |
| 326 | } |
| 327 | |
Jean-Michel Trivi | b7f24b1 | 2014-06-11 10:05:30 -0700 | [diff] [blame] | 328 | return getSamplingRate(output, samplingRate); |
Eric Laurent | 1a9ed11 | 2012-03-20 18:36:01 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 331 | status_t AudioSystem::getSamplingRate(audio_io_handle_t ioHandle, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 332 | uint32_t* samplingRate) { |
Eric Laurent | f6778fd | 2014-11-18 17:26:58 -0800 | [diff] [blame] | 333 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 334 | if (af == 0) return PERMISSION_DENIED; |
Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 335 | sp<AudioIoDescriptor> desc = getIoDescriptor(ioHandle); |
| 336 | if (desc == 0) { |
| 337 | *samplingRate = af->sampleRate(ioHandle); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 338 | } else { |
Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 339 | *samplingRate = desc->mSamplingRate; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 340 | } |
Glenn Kasten | f94006c | 2014-01-08 08:56:06 -0800 | [diff] [blame] | 341 | if (*samplingRate == 0) { |
Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 342 | ALOGE("AudioSystem::getSamplingRate failed for ioHandle %d", ioHandle); |
Glenn Kasten | f94006c | 2014-01-08 08:56:06 -0800 | [diff] [blame] | 343 | return BAD_VALUE; |
| 344 | } |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 345 | |
Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 346 | ALOGV("getSamplingRate() ioHandle %d, sampling rate %u", ioHandle, *samplingRate); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 347 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 348 | return NO_ERROR; |
| 349 | } |
| 350 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 351 | status_t AudioSystem::getOutputFrameCount(size_t* frameCount, audio_stream_type_t streamType) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 352 | audio_io_handle_t output; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 353 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 354 | if (streamType == AUDIO_STREAM_DEFAULT) { |
| 355 | streamType = AUDIO_STREAM_MUSIC; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 356 | } |
Eric Laurent | 48f7f5e | 2009-04-02 09:32:43 -0700 | [diff] [blame] | 357 | |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 358 | output = getOutput(streamType); |
Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 359 | if (output == AUDIO_IO_HANDLE_NONE) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 360 | return PERMISSION_DENIED; |
| 361 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 362 | |
Jean-Michel Trivi | b7f24b1 | 2014-06-11 10:05:30 -0700 | [diff] [blame] | 363 | return getFrameCount(output, frameCount); |
Eric Laurent | 1a9ed11 | 2012-03-20 18:36:01 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 366 | status_t AudioSystem::getFrameCount(audio_io_handle_t ioHandle, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 367 | size_t* frameCount) { |
Eric Laurent | f6778fd | 2014-11-18 17:26:58 -0800 | [diff] [blame] | 368 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 369 | if (af == 0) return PERMISSION_DENIED; |
Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 370 | sp<AudioIoDescriptor> desc = getIoDescriptor(ioHandle); |
| 371 | if (desc == 0) { |
| 372 | *frameCount = af->frameCount(ioHandle); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 373 | } else { |
Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 374 | *frameCount = desc->mFrameCount; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 375 | } |
Glenn Kasten | f94006c | 2014-01-08 08:56:06 -0800 | [diff] [blame] | 376 | if (*frameCount == 0) { |
Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 377 | ALOGE("AudioSystem::getFrameCount failed for ioHandle %d", ioHandle); |
Glenn Kasten | f94006c | 2014-01-08 08:56:06 -0800 | [diff] [blame] | 378 | return BAD_VALUE; |
| 379 | } |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 380 | |
Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 381 | ALOGV("getFrameCount() ioHandle %d, frameCount %zu", ioHandle, *frameCount); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 382 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 383 | return NO_ERROR; |
| 384 | } |
| 385 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 386 | status_t AudioSystem::getOutputLatency(uint32_t* latency, audio_stream_type_t streamType) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 387 | audio_io_handle_t output; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 389 | if (streamType == AUDIO_STREAM_DEFAULT) { |
| 390 | streamType = AUDIO_STREAM_MUSIC; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 391 | } |
Eric Laurent | 48f7f5e | 2009-04-02 09:32:43 -0700 | [diff] [blame] | 392 | |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 393 | output = getOutput(streamType); |
Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 394 | if (output == AUDIO_IO_HANDLE_NONE) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 395 | return PERMISSION_DENIED; |
| 396 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 397 | |
Glenn Kasten | 241618f | 2014-03-25 17:48:57 -0700 | [diff] [blame] | 398 | return getLatency(output, latency); |
Eric Laurent | 1a9ed11 | 2012-03-20 18:36:01 -0700 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | status_t AudioSystem::getLatency(audio_io_handle_t output, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 402 | uint32_t* latency) { |
Eric Laurent | f6778fd | 2014-11-18 17:26:58 -0800 | [diff] [blame] | 403 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 404 | if (af == 0) return PERMISSION_DENIED; |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 405 | sp<AudioIoDescriptor> outputDesc = getIoDescriptor(output); |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 406 | if (outputDesc == 0) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 407 | *latency = af->latency(output); |
| 408 | } else { |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 409 | *latency = outputDesc->mLatency; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 410 | } |
| 411 | |
Glenn Kasten | 241618f | 2014-03-25 17:48:57 -0700 | [diff] [blame] | 412 | ALOGV("getLatency() output %d, latency %d", output, *latency); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 413 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 414 | return NO_ERROR; |
| 415 | } |
| 416 | |
Glenn Kasten | dd8104c | 2012-07-02 12:42:44 -0700 | [diff] [blame] | 417 | status_t AudioSystem::getInputBufferSize(uint32_t sampleRate, audio_format_t format, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 418 | audio_channel_mask_t channelMask, size_t* buffSize) { |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 419 | const sp<AudioFlingerClient> afc = getAudioFlingerClient(); |
| 420 | if (afc == 0) { |
| 421 | return NO_INIT; |
| 422 | } |
| 423 | return afc->getInputBufferSize(sampleRate, format, channelMask, buffSize); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 424 | } |
| 425 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 426 | status_t AudioSystem::setVoiceVolume(float value) { |
Eric Laurent | f0ee6f4 | 2009-10-21 08:14:22 -0700 | [diff] [blame] | 427 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 428 | if (af == 0) return PERMISSION_DENIED; |
| 429 | return af->setVoiceVolume(value); |
| 430 | } |
| 431 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 432 | status_t AudioSystem::getRenderPosition(audio_io_handle_t output, uint32_t* halFrames, |
| 433 | uint32_t* dspFrames) { |
Eric Laurent | 342e9cf | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 434 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 435 | if (af == 0) return PERMISSION_DENIED; |
| 436 | |
Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 437 | return af->getRenderPosition(halFrames, dspFrames, output); |
Eric Laurent | 342e9cf | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 438 | } |
| 439 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 440 | uint32_t AudioSystem::getInputFramesLost(audio_io_handle_t ioHandle) { |
Eric Laurent | 05bca2f | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 441 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
Glenn Kasten | 5f972c0 | 2014-01-13 09:59:31 -0800 | [diff] [blame] | 442 | uint32_t result = 0; |
Eric Laurent | 05bca2f | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 443 | if (af == 0) return result; |
Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 444 | if (ioHandle == AUDIO_IO_HANDLE_NONE) return result; |
Eric Laurent | 05bca2f | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 445 | |
| 446 | result = af->getInputFramesLost(ioHandle); |
| 447 | return result; |
| 448 | } |
| 449 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 450 | audio_unique_id_t AudioSystem::newAudioUniqueId(audio_unique_id_use_t use) { |
Mikhail Naganov | 2996f67 | 2019-04-18 12:29:59 -0700 | [diff] [blame] | 451 | // Must not use AF as IDs will re-roll on audioserver restart, b/130369529. |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 452 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
Eric Laurent | de3f839 | 2014-07-27 18:38:22 -0700 | [diff] [blame] | 453 | if (af == 0) return AUDIO_UNIQUE_ID_ALLOCATE; |
Glenn Kasten | eeecb98 | 2016-02-26 10:44:04 -0800 | [diff] [blame] | 454 | return af->newAudioUniqueId(use); |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 455 | } |
| 456 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 457 | void AudioSystem::acquireAudioSessionId(audio_session_t audioSession, pid_t pid, uid_t uid) { |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 458 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 459 | if (af != 0) { |
Andy Hung | 8b0bfd9 | 2019-12-23 13:11:11 -0800 | [diff] [blame] | 460 | af->acquireAudioSessionId(audioSession, pid, uid); |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 461 | } |
| 462 | } |
| 463 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 464 | void AudioSystem::releaseAudioSessionId(audio_session_t audioSession, pid_t pid) { |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 465 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 466 | if (af != 0) { |
Marco Nelissen | d457c97 | 2014-02-11 08:47:07 -0800 | [diff] [blame] | 467 | af->releaseAudioSessionId(audioSession, pid); |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 468 | } |
| 469 | } |
| 470 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 471 | audio_hw_sync_t AudioSystem::getAudioHwSyncForSession(audio_session_t sessionId) { |
Eric Laurent | 93c3d41 | 2014-08-01 14:48:35 -0700 | [diff] [blame] | 472 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 473 | if (af == 0) return AUDIO_HW_SYNC_INVALID; |
| 474 | return af->getAudioHwSyncForSession(sessionId); |
| 475 | } |
| 476 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 477 | status_t AudioSystem::systemReady() { |
Eric Laurent | 72e3f39 | 2015-05-20 14:43:50 -0700 | [diff] [blame] | 478 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 479 | if (af == 0) return NO_INIT; |
| 480 | return af->systemReady(); |
| 481 | } |
| 482 | |
Glenn Kasten | 4a8308b | 2016-04-18 14:10:01 -0700 | [diff] [blame] | 483 | status_t AudioSystem::getFrameCountHAL(audio_io_handle_t ioHandle, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 484 | size_t* frameCount) { |
Glenn Kasten | 4a8308b | 2016-04-18 14:10:01 -0700 | [diff] [blame] | 485 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 486 | if (af == 0) return PERMISSION_DENIED; |
| 487 | sp<AudioIoDescriptor> desc = getIoDescriptor(ioHandle); |
| 488 | if (desc == 0) { |
| 489 | *frameCount = af->frameCountHAL(ioHandle); |
| 490 | } else { |
| 491 | *frameCount = desc->mFrameCountHAL; |
| 492 | } |
| 493 | if (*frameCount == 0) { |
| 494 | ALOGE("AudioSystem::getFrameCountHAL failed for ioHandle %d", ioHandle); |
| 495 | return BAD_VALUE; |
| 496 | } |
| 497 | |
| 498 | ALOGV("getFrameCountHAL() ioHandle %d, frameCount %zu", ioHandle, *frameCount); |
| 499 | |
| 500 | return NO_ERROR; |
| 501 | } |
| 502 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 503 | // --------------------------------------------------------------------------- |
| 504 | |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 505 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 506 | void AudioSystem::AudioFlingerClient::clearIoCache() { |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 507 | Mutex::Autolock _l(mLock); |
| 508 | mIoDescriptors.clear(); |
| 509 | mInBuffSize = 0; |
| 510 | mInSamplingRate = 0; |
| 511 | mInFormat = AUDIO_FORMAT_DEFAULT; |
| 512 | mInChannelMask = AUDIO_CHANNEL_NONE; |
| 513 | } |
| 514 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 515 | void AudioSystem::AudioFlingerClient::binderDied(const wp<IBinder>& who __unused) { |
Eric Laurent | f6778fd | 2014-11-18 17:26:58 -0800 | [diff] [blame] | 516 | { |
| 517 | Mutex::Autolock _l(AudioSystem::gLock); |
| 518 | AudioSystem::gAudioFlinger.clear(); |
Eric Laurent | f6778fd | 2014-11-18 17:26:58 -0800 | [diff] [blame] | 519 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 520 | |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 521 | // clear output handles and stream to output map caches |
| 522 | clearIoCache(); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 523 | |
Ytai Ben-Tsvi | 000c3e4 | 2020-01-09 15:26:40 -0800 | [diff] [blame] | 524 | reportError(DEAD_OBJECT); |
| 525 | |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 526 | ALOGW("AudioFlinger server died!"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 527 | } |
| 528 | |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 529 | Status AudioSystem::AudioFlingerClient::ioConfigChanged( |
| 530 | media::AudioIoConfigEvent _event, |
| 531 | const media::AudioIoDescriptor& _ioDesc) { |
Ytai Ben-Tsvi | 1ff7569 | 2020-11-06 12:16:12 -0800 | [diff] [blame] | 532 | audio_io_config_event event = VALUE_OR_RETURN_BINDER_STATUS( |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 533 | aidl2legacy_AudioIoConfigEvent_audio_io_config_event(_event)); |
| 534 | sp<AudioIoDescriptor> ioDesc( |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 535 | VALUE_OR_RETURN_BINDER_STATUS( |
| 536 | aidl2legacy_AudioIoDescriptor_AudioIoDescriptor(_ioDesc))); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 537 | |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 538 | ALOGV("ioConfigChanged() event %d", event); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 539 | |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 540 | if (ioDesc->mIoHandle == AUDIO_IO_HANDLE_NONE) return Status::ok(); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 541 | |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 542 | audio_port_handle_t deviceId = AUDIO_PORT_HANDLE_NONE; |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 543 | std::vector<sp<AudioDeviceCallback>> callbacksToCall; |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 544 | { |
| 545 | Mutex::Autolock _l(mLock); |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 546 | auto callbacks = std::map<audio_port_handle_t, wp<AudioDeviceCallback>>(); |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 547 | |
| 548 | switch (event) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 549 | case AUDIO_OUTPUT_OPENED: |
| 550 | case AUDIO_OUTPUT_REGISTERED: |
| 551 | case AUDIO_INPUT_OPENED: |
| 552 | case AUDIO_INPUT_REGISTERED: { |
| 553 | sp<AudioIoDescriptor> oldDesc = getIoDescriptor_l(ioDesc->mIoHandle); |
| 554 | if (oldDesc == 0) { |
| 555 | mIoDescriptors.add(ioDesc->mIoHandle, ioDesc); |
| 556 | } else { |
| 557 | deviceId = oldDesc->getDeviceId(); |
| 558 | mIoDescriptors.replaceValueFor(ioDesc->mIoHandle, ioDesc); |
| 559 | } |
| 560 | |
| 561 | if (ioDesc->getDeviceId() != AUDIO_PORT_HANDLE_NONE) { |
| 562 | deviceId = ioDesc->getDeviceId(); |
| 563 | if (event == AUDIO_OUTPUT_OPENED || event == AUDIO_INPUT_OPENED) { |
| 564 | auto it = mAudioDeviceCallbacks.find(ioDesc->mIoHandle); |
| 565 | if (it != mAudioDeviceCallbacks.end()) { |
| 566 | callbacks = it->second; |
| 567 | } |
| 568 | } |
| 569 | } |
| 570 | ALOGV("ioConfigChanged() new %s %s %d samplingRate %u, format %#x channel mask %#x " |
| 571 | "frameCount %zu deviceId %d", |
| 572 | event == AUDIO_OUTPUT_OPENED || event == AUDIO_OUTPUT_REGISTERED ? |
| 573 | "output" : "input", |
| 574 | event == AUDIO_OUTPUT_OPENED || event == AUDIO_INPUT_OPENED ? |
| 575 | "opened" : "registered", |
| 576 | ioDesc->mIoHandle, ioDesc->mSamplingRate, ioDesc->mFormat, |
| 577 | ioDesc->mChannelMask, |
| 578 | ioDesc->mFrameCount, ioDesc->getDeviceId()); |
| 579 | } |
| 580 | break; |
| 581 | case AUDIO_OUTPUT_CLOSED: |
| 582 | case AUDIO_INPUT_CLOSED: { |
| 583 | if (getIoDescriptor_l(ioDesc->mIoHandle) == 0) { |
| 584 | ALOGW("ioConfigChanged() closing unknown %s %d", |
| 585 | event == AUDIO_OUTPUT_CLOSED ? "output" : "input", ioDesc->mIoHandle); |
| 586 | break; |
| 587 | } |
| 588 | ALOGV("ioConfigChanged() %s %d closed", |
| 589 | event == AUDIO_OUTPUT_CLOSED ? "output" : "input", ioDesc->mIoHandle); |
| 590 | |
| 591 | mIoDescriptors.removeItem(ioDesc->mIoHandle); |
| 592 | mAudioDeviceCallbacks.erase(ioDesc->mIoHandle); |
| 593 | } |
| 594 | break; |
| 595 | |
| 596 | case AUDIO_OUTPUT_CONFIG_CHANGED: |
| 597 | case AUDIO_INPUT_CONFIG_CHANGED: { |
| 598 | sp<AudioIoDescriptor> oldDesc = getIoDescriptor_l(ioDesc->mIoHandle); |
| 599 | if (oldDesc == 0) { |
| 600 | ALOGW("ioConfigChanged() modifying unknown %s! %d", |
| 601 | event == AUDIO_OUTPUT_CONFIG_CHANGED ? "output" : "input", |
| 602 | ioDesc->mIoHandle); |
| 603 | break; |
| 604 | } |
| 605 | |
Eric Laurent | 7c1ec5f | 2015-07-09 14:52:47 -0700 | [diff] [blame] | 606 | deviceId = oldDesc->getDeviceId(); |
| 607 | mIoDescriptors.replaceValueFor(ioDesc->mIoHandle, ioDesc); |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 608 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 609 | if (deviceId != ioDesc->getDeviceId()) { |
| 610 | deviceId = ioDesc->getDeviceId(); |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 611 | auto it = mAudioDeviceCallbacks.find(ioDesc->mIoHandle); |
| 612 | if (it != mAudioDeviceCallbacks.end()) { |
| 613 | callbacks = it->second; |
Francois Gaffie | 24a9fb0 | 2019-01-18 17:51:34 +0100 | [diff] [blame] | 614 | } |
| 615 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 616 | ALOGV("ioConfigChanged() new config for %s %d samplingRate %u, format %#x " |
| 617 | "channel mask %#x frameCount %zu frameCountHAL %zu deviceId %d", |
| 618 | event == AUDIO_OUTPUT_CONFIG_CHANGED ? "output" : "input", |
| 619 | ioDesc->mIoHandle, ioDesc->mSamplingRate, ioDesc->mFormat, |
| 620 | ioDesc->mChannelMask, ioDesc->mFrameCount, ioDesc->mFrameCountHAL, |
| 621 | ioDesc->getDeviceId()); |
| 622 | |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 623 | } |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 624 | break; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 625 | case AUDIO_CLIENT_STARTED: { |
| 626 | sp<AudioIoDescriptor> oldDesc = getIoDescriptor_l(ioDesc->mIoHandle); |
| 627 | if (oldDesc == 0) { |
| 628 | ALOGW("ioConfigChanged() start client on unknown io! %d", ioDesc->mIoHandle); |
| 629 | break; |
| 630 | } |
| 631 | ALOGV("ioConfigChanged() AUDIO_CLIENT_STARTED io %d port %d num callbacks %zu", |
| 632 | ioDesc->mIoHandle, ioDesc->mPortId, mAudioDeviceCallbacks.size()); |
| 633 | oldDesc->mPatch = ioDesc->mPatch; |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 634 | auto it = mAudioDeviceCallbacks.find(ioDesc->mIoHandle); |
| 635 | if (it != mAudioDeviceCallbacks.end()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 636 | auto cbks = it->second; |
| 637 | auto it2 = cbks.find(ioDesc->mPortId); |
| 638 | if (it2 != cbks.end()) { |
| 639 | callbacks.emplace(ioDesc->mPortId, it2->second); |
| 640 | deviceId = oldDesc->getDeviceId(); |
| 641 | } |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 642 | } |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 643 | } |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 644 | break; |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | for (auto wpCbk : callbacks) { |
| 648 | sp<AudioDeviceCallback> spCbk = wpCbk.second.promote(); |
| 649 | if (spCbk != nullptr) { |
| 650 | callbacksToCall.push_back(spCbk); |
| 651 | } |
Eric Laurent | ad2e7b9 | 2017-09-14 20:06:42 -0700 | [diff] [blame] | 652 | } |
Eric Laurent | 4463ff5 | 2019-02-07 13:56:09 -0800 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | // Callbacks must be called without mLock held. May lead to dead lock if calling for |
| 656 | // example getRoutedDevice that updates the device and tries to acquire mLock. |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 657 | for (auto cb : callbacksToCall) { |
| 658 | // If callbacksToCall is not empty, it implies ioDesc->mIoHandle and deviceId are valid |
| 659 | cb->onAudioDeviceUpdate(ioDesc->mIoHandle, deviceId); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 660 | } |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 661 | |
| 662 | return Status::ok(); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 663 | } |
| 664 | |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 665 | status_t AudioSystem::AudioFlingerClient::getInputBufferSize( |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 666 | uint32_t sampleRate, audio_format_t format, |
| 667 | audio_channel_mask_t channelMask, size_t* buffSize) { |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 668 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 669 | if (af == 0) { |
| 670 | return PERMISSION_DENIED; |
| 671 | } |
| 672 | Mutex::Autolock _l(mLock); |
| 673 | // Do we have a stale mInBuffSize or are we requesting the input buffer size for new values |
| 674 | if ((mInBuffSize == 0) || (sampleRate != mInSamplingRate) || (format != mInFormat) |
| 675 | || (channelMask != mInChannelMask)) { |
| 676 | size_t inBuffSize = af->getInputBufferSize(sampleRate, format, channelMask); |
| 677 | if (inBuffSize == 0) { |
Glenn Kasten | 49f36ba | 2017-12-06 13:02:02 -0800 | [diff] [blame] | 678 | ALOGE("AudioSystem::getInputBufferSize failed sampleRate %d format %#x channelMask %#x", |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 679 | sampleRate, format, channelMask); |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 680 | return BAD_VALUE; |
| 681 | } |
| 682 | // A benign race is possible here: we could overwrite a fresher cache entry |
| 683 | // save the request params |
| 684 | mInSamplingRate = sampleRate; |
| 685 | mInFormat = format; |
| 686 | mInChannelMask = channelMask; |
| 687 | |
| 688 | mInBuffSize = inBuffSize; |
| 689 | } |
| 690 | |
| 691 | *buffSize = mInBuffSize; |
| 692 | |
| 693 | return NO_ERROR; |
| 694 | } |
| 695 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 696 | sp<AudioIoDescriptor> |
| 697 | AudioSystem::AudioFlingerClient::getIoDescriptor_l(audio_io_handle_t ioHandle) { |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 698 | sp<AudioIoDescriptor> desc; |
| 699 | ssize_t index = mIoDescriptors.indexOfKey(ioHandle); |
| 700 | if (index >= 0) { |
| 701 | desc = mIoDescriptors.valueAt(index); |
| 702 | } |
| 703 | return desc; |
| 704 | } |
| 705 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 706 | sp<AudioIoDescriptor> AudioSystem::AudioFlingerClient::getIoDescriptor(audio_io_handle_t ioHandle) { |
Praveen Chavan | 49fdeaf | 2015-09-29 02:25:47 -0700 | [diff] [blame] | 707 | Mutex::Autolock _l(mLock); |
| 708 | return getIoDescriptor_l(ioHandle); |
| 709 | } |
| 710 | |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 711 | status_t AudioSystem::AudioFlingerClient::addAudioDeviceCallback( |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 712 | const wp<AudioDeviceCallback>& callback, audio_io_handle_t audioIo, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 713 | audio_port_handle_t portId) { |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 714 | ALOGV("%s audioIo %d portId %d", __func__, audioIo, portId); |
Eric Laurent | 4463ff5 | 2019-02-07 13:56:09 -0800 | [diff] [blame] | 715 | Mutex::Autolock _l(mLock); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 716 | auto& callbacks = mAudioDeviceCallbacks.emplace( |
| 717 | audioIo, |
| 718 | std::map<audio_port_handle_t, wp<AudioDeviceCallback>>()).first->second; |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 719 | auto result = callbacks.try_emplace(portId, callback); |
| 720 | if (!result.second) { |
| 721 | return INVALID_OPERATION; |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 722 | } |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 723 | return NO_ERROR; |
| 724 | } |
| 725 | |
| 726 | status_t AudioSystem::AudioFlingerClient::removeAudioDeviceCallback( |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 727 | const wp<AudioDeviceCallback>& callback __unused, audio_io_handle_t audioIo, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 728 | audio_port_handle_t portId) { |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 729 | ALOGV("%s audioIo %d portId %d", __func__, audioIo, portId); |
Eric Laurent | 4463ff5 | 2019-02-07 13:56:09 -0800 | [diff] [blame] | 730 | Mutex::Autolock _l(mLock); |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 731 | auto it = mAudioDeviceCallbacks.find(audioIo); |
| 732 | if (it == mAudioDeviceCallbacks.end()) { |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 733 | return INVALID_OPERATION; |
| 734 | } |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 735 | if (it->second.erase(portId) == 0) { |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 736 | return INVALID_OPERATION; |
| 737 | } |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 738 | if (it->second.size() == 0) { |
| 739 | mAudioDeviceCallbacks.erase(audioIo); |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 740 | } |
| 741 | return NO_ERROR; |
| 742 | } |
| 743 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 744 | /* static */ uintptr_t AudioSystem::addErrorCallback(audio_error_callback cb) { |
Ytai Ben-Tsvi | 000c3e4 | 2020-01-09 15:26:40 -0800 | [diff] [blame] | 745 | Mutex::Autolock _l(gLockErrorCallbacks); |
| 746 | gAudioErrorCallbacks.insert(cb); |
| 747 | return reinterpret_cast<uintptr_t>(cb); |
| 748 | } |
| 749 | |
| 750 | /* static */ void AudioSystem::removeErrorCallback(uintptr_t cb) { |
| 751 | Mutex::Autolock _l(gLockErrorCallbacks); |
| 752 | gAudioErrorCallbacks.erase(reinterpret_cast<audio_error_callback>(cb)); |
| 753 | } |
| 754 | |
| 755 | /* static */ void AudioSystem::reportError(status_t err) { |
| 756 | Mutex::Autolock _l(gLockErrorCallbacks); |
| 757 | for (auto callback : gAudioErrorCallbacks) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 758 | callback(err); |
Ytai Ben-Tsvi | 000c3e4 | 2020-01-09 15:26:40 -0800 | [diff] [blame] | 759 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 760 | } |
| 761 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 762 | /*static*/ void AudioSystem::setDynPolicyCallback(dynamic_policy_callback cb) { |
Jean-Michel Trivi | f613d42 | 2015-04-23 18:41:29 -0700 | [diff] [blame] | 763 | Mutex::Autolock _l(gLock); |
| 764 | gDynPolicyCallback = cb; |
| 765 | } |
| 766 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 767 | /*static*/ void AudioSystem::setRecordConfigCallback(record_config_callback cb) { |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 768 | Mutex::Autolock _l(gLock); |
| 769 | gRecordConfigCallback = cb; |
| 770 | } |
| 771 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 772 | /*static*/ void AudioSystem::setRoutingCallback(routing_callback cb) { |
Jean-Michel Trivi | 9a6b9ad | 2020-10-22 16:46:43 -0700 | [diff] [blame] | 773 | Mutex::Autolock _l(gLock); |
| 774 | gRoutingCallback = cb; |
| 775 | } |
| 776 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 777 | // client singleton for AudioPolicyService binder interface |
Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 778 | // protected by gLockAPS |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 779 | sp<IAudioPolicyService> AudioSystem::gAudioPolicyService; |
| 780 | sp<AudioSystem::AudioPolicyServiceClient> AudioSystem::gAudioPolicyServiceClient; |
| 781 | |
| 782 | |
Glenn Kasten | 18a6d90 | 2012-09-24 11:27:56 -0700 | [diff] [blame] | 783 | // establish binder interface to AudioPolicy service |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 784 | const sp<IAudioPolicyService> AudioSystem::get_audio_policy_service() { |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 785 | sp<IAudioPolicyService> ap; |
| 786 | sp<AudioPolicyServiceClient> apc; |
| 787 | { |
| 788 | Mutex::Autolock _l(gLockAPS); |
| 789 | if (gAudioPolicyService == 0) { |
| 790 | sp<IServiceManager> sm = defaultServiceManager(); |
| 791 | sp<IBinder> binder; |
| 792 | do { |
| 793 | binder = sm->getService(String16("media.audio_policy")); |
| 794 | if (binder != 0) |
| 795 | break; |
| 796 | ALOGW("AudioPolicyService not published, waiting..."); |
| 797 | usleep(500000); // 0.5 s |
| 798 | } while (true); |
| 799 | if (gAudioPolicyServiceClient == NULL) { |
| 800 | gAudioPolicyServiceClient = new AudioPolicyServiceClient(); |
| 801 | } |
| 802 | binder->linkToDeath(gAudioPolicyServiceClient); |
| 803 | gAudioPolicyService = interface_cast<IAudioPolicyService>(binder); |
| 804 | LOG_ALWAYS_FATAL_IF(gAudioPolicyService == 0); |
| 805 | apc = gAudioPolicyServiceClient; |
Eric Laurent | fb00fc7 | 2017-05-25 18:17:12 -0700 | [diff] [blame] | 806 | // Make sure callbacks can be received by gAudioPolicyServiceClient |
| 807 | ProcessState::self()->startThreadPool(); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 808 | } |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 809 | ap = gAudioPolicyService; |
| 810 | } |
| 811 | if (apc != 0) { |
François Gaffie | 2443760 | 2018-04-23 15:08:59 +0200 | [diff] [blame] | 812 | int64_t token = IPCThreadState::self()->clearCallingIdentity(); |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 813 | ap->registerClient(apc); |
François Gaffie | 2443760 | 2018-04-23 15:08:59 +0200 | [diff] [blame] | 814 | ap->setAudioPortCallbacksEnabled(apc->isAudioPortCbEnabled()); |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 815 | ap->setAudioVolumeGroupCallbacksEnabled(apc->isAudioVolumeGroupCbEnabled()); |
François Gaffie | 2443760 | 2018-04-23 15:08:59 +0200 | [diff] [blame] | 816 | IPCThreadState::self()->restoreCallingIdentity(token); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 817 | } |
Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 818 | |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 819 | return ap; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 820 | } |
| 821 | |
Glenn Kasten | fb1fdc9 | 2013-07-10 17:03:19 -0700 | [diff] [blame] | 822 | // --------------------------------------------------------------------------- |
| 823 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 824 | void AudioSystem::onNewAudioModulesAvailable() { |
Mikhail Naganov | 88b30d2 | 2020-03-09 19:43:13 +0000 | [diff] [blame] | 825 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 826 | if (aps == 0) return; |
| 827 | aps->onNewAudioModulesAvailable(); |
| 828 | } |
| 829 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 830 | status_t AudioSystem::setDeviceConnectionState(audio_devices_t device, |
| 831 | audio_policy_dev_state_t state, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 832 | const char* device_address, |
| 833 | const char* device_name, |
| 834 | audio_format_t encodedFormat) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 835 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 836 | const char* address = ""; |
| 837 | const char* name = ""; |
Eric Laurent | 71b63e3 | 2011-09-02 14:20:56 -0700 | [diff] [blame] | 838 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 839 | if (aps == 0) return PERMISSION_DENIED; |
| 840 | |
Eric Laurent | 71b63e3 | 2011-09-02 14:20:56 -0700 | [diff] [blame] | 841 | if (device_address != NULL) { |
| 842 | address = device_address; |
| 843 | } |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 844 | if (device_name != NULL) { |
| 845 | name = device_name; |
| 846 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 847 | |
| 848 | media::AudioDevice deviceAidl; |
| 849 | deviceAidl.type = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_devices_t_int32_t(device)); |
| 850 | deviceAidl.address = address; |
| 851 | |
| 852 | return statusTFromBinderStatus( |
| 853 | aps->setDeviceConnectionState( |
| 854 | deviceAidl, |
| 855 | VALUE_OR_RETURN_STATUS( |
| 856 | legacy2aidl_audio_policy_dev_state_t_AudioPolicyDeviceState(state)), |
| 857 | name, |
| 858 | VALUE_OR_RETURN_STATUS(legacy2aidl_audio_format_t_AudioFormat(encodedFormat)))); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 859 | } |
| 860 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 861 | audio_policy_dev_state_t AudioSystem::getDeviceConnectionState(audio_devices_t device, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 862 | const char* device_address) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 863 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 864 | if (aps == 0) return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 865 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 866 | auto result = [&]() -> ConversionResult<audio_policy_dev_state_t> { |
| 867 | media::AudioDevice deviceAidl; |
| 868 | deviceAidl.type = VALUE_OR_RETURN(legacy2aidl_audio_devices_t_int32_t(device)); |
| 869 | deviceAidl.address = device_address; |
| 870 | |
| 871 | media::AudioPolicyDeviceState result; |
| 872 | RETURN_IF_ERROR(statusTFromBinderStatus( |
| 873 | aps->getDeviceConnectionState(deviceAidl, &result))); |
| 874 | |
| 875 | return aidl2legacy_AudioPolicyDeviceState_audio_policy_dev_state_t(result); |
| 876 | }(); |
| 877 | return result.value_or(AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 878 | } |
| 879 | |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 880 | status_t AudioSystem::handleDeviceConfigChange(audio_devices_t device, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 881 | const char* device_address, |
| 882 | const char* device_name, |
| 883 | audio_format_t encodedFormat) { |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 884 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 885 | const char* address = ""; |
| 886 | const char* name = ""; |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 887 | |
| 888 | if (aps == 0) return PERMISSION_DENIED; |
| 889 | |
| 890 | if (device_address != NULL) { |
| 891 | address = device_address; |
| 892 | } |
| 893 | if (device_name != NULL) { |
| 894 | name = device_name; |
| 895 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 896 | |
| 897 | media::AudioDevice deviceAidl; |
| 898 | deviceAidl.type = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_devices_t_int32_t(device)); |
| 899 | deviceAidl.address = address; |
| 900 | |
| 901 | return statusTFromBinderStatus( |
| 902 | aps->handleDeviceConfigChange(deviceAidl, name, VALUE_OR_RETURN_STATUS( |
| 903 | legacy2aidl_audio_format_t_AudioFormat(encodedFormat)))); |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 904 | } |
| 905 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 906 | status_t AudioSystem::setPhoneState(audio_mode_t state, uid_t uid) { |
Glenn Kasten | 347966c | 2012-01-18 14:58:32 -0800 | [diff] [blame] | 907 | if (uint32_t(state) >= AUDIO_MODE_CNT) return BAD_VALUE; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 908 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 909 | if (aps == 0) return PERMISSION_DENIED; |
| 910 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 911 | return statusTFromBinderStatus(aps->setPhoneState( |
| 912 | VALUE_OR_RETURN_STATUS(legacy2aidl_audio_mode_t_AudioMode(state)), |
| 913 | VALUE_OR_RETURN_STATUS(legacy2aidl_uid_t_int32_t(uid)))); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 914 | } |
| 915 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 916 | status_t |
| 917 | AudioSystem::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] | 918 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 919 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 920 | |
| 921 | return statusTFromBinderStatus( |
| 922 | aps->setForceUse( |
| 923 | VALUE_OR_RETURN_STATUS( |
| 924 | legacy2aidl_audio_policy_force_use_t_AudioPolicyForceUse(usage)), |
| 925 | VALUE_OR_RETURN_STATUS( |
| 926 | legacy2aidl_audio_policy_forced_cfg_t_AudioPolicyForcedConfig( |
| 927 | config)))); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 928 | } |
| 929 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 930 | audio_policy_forced_cfg_t AudioSystem::getForceUse(audio_policy_force_use_t usage) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 931 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 932 | if (aps == 0) return AUDIO_POLICY_FORCE_NONE; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 933 | |
| 934 | auto result = [&]() -> ConversionResult<audio_policy_forced_cfg_t> { |
| 935 | media::AudioPolicyForceUse usageAidl = VALUE_OR_RETURN( |
| 936 | legacy2aidl_audio_policy_force_use_t_AudioPolicyForceUse(usage)); |
| 937 | media::AudioPolicyForcedConfig configAidl; |
| 938 | RETURN_IF_ERROR(statusTFromBinderStatus( |
| 939 | aps->getForceUse(usageAidl, &configAidl))); |
| 940 | return aidl2legacy_AudioPolicyForcedConfig_audio_policy_forced_cfg_t(configAidl); |
| 941 | }(); |
| 942 | |
| 943 | return result.value_or(AUDIO_POLICY_FORCE_NONE); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 947 | audio_io_handle_t AudioSystem::getOutput(audio_stream_type_t stream) { |
Eric Laurent | 1a9ed11 | 2012-03-20 18:36:01 -0700 | [diff] [blame] | 948 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 949 | if (aps == 0) return AUDIO_IO_HANDLE_NONE; |
| 950 | |
| 951 | auto result = [&]() -> ConversionResult<audio_io_handle_t> { |
| 952 | media::AudioStreamType streamAidl = VALUE_OR_RETURN( |
| 953 | legacy2aidl_audio_stream_type_t_AudioStreamType(stream)); |
| 954 | int32_t outputAidl; |
| 955 | RETURN_IF_ERROR( |
| 956 | statusTFromBinderStatus(aps->getOutput(streamAidl, &outputAidl))); |
| 957 | return aidl2legacy_int32_t_audio_io_handle_t(outputAidl); |
| 958 | }(); |
| 959 | |
| 960 | return result.value_or(AUDIO_IO_HANDLE_NONE); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 961 | } |
| 962 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 963 | status_t AudioSystem::getOutputForAttr(audio_attributes_t* attr, |
| 964 | audio_io_handle_t* output, |
| 965 | audio_session_t session, |
| 966 | audio_stream_type_t* stream, |
Svet Ganov | 3376113 | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 967 | const AttributionSourceState& attributionSource, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 968 | const audio_config_t* config, |
| 969 | audio_output_flags_t flags, |
| 970 | audio_port_handle_t* selectedDeviceId, |
| 971 | audio_port_handle_t* portId, |
| 972 | std::vector<audio_io_handle_t>* secondaryOutputs) { |
| 973 | if (attr == nullptr) { |
| 974 | ALOGE("%s NULL audio attributes", __func__); |
| 975 | return BAD_VALUE; |
| 976 | } |
| 977 | if (output == nullptr) { |
| 978 | ALOGE("%s NULL output - shouldn't happen", __func__); |
| 979 | return BAD_VALUE; |
| 980 | } |
| 981 | if (selectedDeviceId == nullptr) { |
| 982 | ALOGE("%s NULL selectedDeviceId - shouldn't happen", __func__); |
| 983 | return BAD_VALUE; |
| 984 | } |
| 985 | if (portId == nullptr) { |
| 986 | ALOGE("%s NULL portId - shouldn't happen", __func__); |
| 987 | return BAD_VALUE; |
| 988 | } |
| 989 | if (secondaryOutputs == nullptr) { |
| 990 | ALOGE("%s NULL secondaryOutputs - shouldn't happen", __func__); |
| 991 | return BAD_VALUE; |
| 992 | } |
| 993 | |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 994 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 995 | if (aps == 0) return NO_INIT; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 996 | |
| 997 | media::AudioAttributesInternal attrAidl = VALUE_OR_RETURN_STATUS( |
| 998 | legacy2aidl_audio_attributes_t_AudioAttributesInternal(*attr)); |
| 999 | int32_t sessionAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_session_t_int32_t(session)); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1000 | media::AudioConfig configAidl = VALUE_OR_RETURN_STATUS( |
| 1001 | legacy2aidl_audio_config_t_AudioConfig(*config)); |
| 1002 | int32_t flagsAidl = VALUE_OR_RETURN_STATUS( |
| 1003 | legacy2aidl_audio_output_flags_t_int32_t_mask(flags)); |
Eric Laurent | f99edd3 | 2021-02-01 15:57:33 +0100 | [diff] [blame] | 1004 | int32_t selectedDeviceIdAidl = VALUE_OR_RETURN_STATUS( |
| 1005 | legacy2aidl_audio_port_handle_t_int32_t(*selectedDeviceId)); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1006 | |
| 1007 | media::GetOutputForAttrResponse responseAidl; |
| 1008 | |
| 1009 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
Svet Ganov | 3376113 | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 1010 | aps->getOutputForAttr(attrAidl, sessionAidl, attributionSource, configAidl, flagsAidl, |
Eric Laurent | f99edd3 | 2021-02-01 15:57:33 +0100 | [diff] [blame] | 1011 | selectedDeviceIdAidl, &responseAidl))); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1012 | |
| 1013 | *output = VALUE_OR_RETURN_STATUS( |
| 1014 | aidl2legacy_int32_t_audio_io_handle_t(responseAidl.output)); |
| 1015 | |
| 1016 | if (stream != nullptr) { |
| 1017 | *stream = VALUE_OR_RETURN_STATUS( |
| 1018 | aidl2legacy_AudioStreamType_audio_stream_type_t(responseAidl.stream)); |
| 1019 | } |
| 1020 | *selectedDeviceId = VALUE_OR_RETURN_STATUS( |
| 1021 | aidl2legacy_int32_t_audio_port_handle_t(responseAidl.selectedDeviceId)); |
| 1022 | *portId = VALUE_OR_RETURN_STATUS(aidl2legacy_int32_t_audio_port_handle_t(responseAidl.portId)); |
| 1023 | *secondaryOutputs = VALUE_OR_RETURN_STATUS(convertContainer<std::vector<audio_io_handle_t>>( |
| 1024 | responseAidl.secondaryOutputs, aidl2legacy_int32_t_audio_io_handle_t)); |
| 1025 | |
| 1026 | return OK; |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 1027 | } |
| 1028 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1029 | status_t AudioSystem::startOutput(audio_port_handle_t portId) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1030 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1031 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1032 | |
| 1033 | int32_t portIdAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_port_handle_t_int32_t(portId)); |
| 1034 | return statusTFromBinderStatus(aps->startOutput(portIdAidl)); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1035 | } |
| 1036 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1037 | status_t AudioSystem::stopOutput(audio_port_handle_t portId) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1038 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1039 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1040 | |
| 1041 | int32_t portIdAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_port_handle_t_int32_t(portId)); |
| 1042 | return statusTFromBinderStatus(aps->stopOutput(portIdAidl)); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1043 | } |
| 1044 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1045 | void AudioSystem::releaseOutput(audio_port_handle_t portId) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1046 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1047 | if (aps == 0) return; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1048 | |
| 1049 | auto status = [&]() -> status_t { |
| 1050 | int32_t portIdAidl = VALUE_OR_RETURN_STATUS( |
| 1051 | legacy2aidl_audio_port_handle_t_int32_t(portId)); |
| 1052 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(aps->releaseOutput(portIdAidl))); |
| 1053 | return OK; |
| 1054 | }(); |
| 1055 | |
| 1056 | // Ignore status. |
| 1057 | (void) status; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1058 | } |
| 1059 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1060 | status_t AudioSystem::getInputForAttr(const audio_attributes_t* attr, |
| 1061 | audio_io_handle_t* input, |
| 1062 | audio_unique_id_t riid, |
| 1063 | audio_session_t session, |
Svet Ganov | 3376113 | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 1064 | const AttributionSourceState &attributionSource, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1065 | const audio_config_base_t* config, |
| 1066 | audio_input_flags_t flags, |
| 1067 | audio_port_handle_t* selectedDeviceId, |
| 1068 | audio_port_handle_t* portId) { |
| 1069 | if (attr == NULL) { |
| 1070 | ALOGE("getInputForAttr NULL attr - shouldn't happen"); |
| 1071 | return BAD_VALUE; |
| 1072 | } |
| 1073 | if (input == NULL) { |
| 1074 | ALOGE("getInputForAttr NULL input - shouldn't happen"); |
| 1075 | return BAD_VALUE; |
| 1076 | } |
| 1077 | if (selectedDeviceId == NULL) { |
| 1078 | ALOGE("getInputForAttr NULL selectedDeviceId - shouldn't happen"); |
| 1079 | return BAD_VALUE; |
| 1080 | } |
| 1081 | if (portId == NULL) { |
| 1082 | ALOGE("getInputForAttr NULL portId - shouldn't happen"); |
| 1083 | return BAD_VALUE; |
| 1084 | } |
| 1085 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1086 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 1087 | if (aps == 0) return NO_INIT; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1088 | |
| 1089 | media::AudioAttributesInternal attrAidl = VALUE_OR_RETURN_STATUS( |
| 1090 | legacy2aidl_audio_attributes_t_AudioAttributesInternal(*attr)); |
| 1091 | int32_t inputAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(*input)); |
| 1092 | int32_t riidAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_unique_id_t_int32_t(riid)); |
| 1093 | int32_t sessionAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_session_t_int32_t(session)); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1094 | media::AudioConfigBase configAidl = VALUE_OR_RETURN_STATUS( |
| 1095 | legacy2aidl_audio_config_base_t_AudioConfigBase(*config)); |
| 1096 | int32_t flagsAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_input_flags_t_int32_t_mask(flags)); |
Eric Laurent | f99edd3 | 2021-02-01 15:57:33 +0100 | [diff] [blame] | 1097 | int32_t selectedDeviceIdAidl = VALUE_OR_RETURN_STATUS( |
| 1098 | legacy2aidl_audio_port_handle_t_int32_t(*selectedDeviceId)); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1099 | |
| 1100 | media::GetInputForAttrResponse response; |
| 1101 | |
| 1102 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
Svet Ganov | 3376113 | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 1103 | aps->getInputForAttr(attrAidl, inputAidl, riidAidl, sessionAidl, attributionSource, |
Philip P. Moltmann | bda4575 | 2020-07-17 16:41:18 -0700 | [diff] [blame] | 1104 | configAidl, flagsAidl, selectedDeviceIdAidl, &response))); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1105 | |
| 1106 | *input = VALUE_OR_RETURN_STATUS(aidl2legacy_int32_t_audio_io_handle_t(response.input)); |
| 1107 | *selectedDeviceId = VALUE_OR_RETURN_STATUS( |
| 1108 | aidl2legacy_int32_t_audio_port_handle_t(response.selectedDeviceId)); |
| 1109 | *portId = VALUE_OR_RETURN_STATUS(aidl2legacy_int32_t_audio_port_handle_t(response.portId)); |
| 1110 | |
| 1111 | return OK; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1112 | } |
| 1113 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1114 | status_t AudioSystem::startInput(audio_port_handle_t portId) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1115 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1116 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1117 | |
| 1118 | int32_t portIdAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_port_handle_t_int32_t(portId)); |
| 1119 | return statusTFromBinderStatus(aps->startInput(portIdAidl)); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1120 | } |
| 1121 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1122 | status_t AudioSystem::stopInput(audio_port_handle_t portId) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1123 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1124 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1125 | |
| 1126 | int32_t portIdAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_port_handle_t_int32_t(portId)); |
| 1127 | return statusTFromBinderStatus(aps->stopInput(portIdAidl)); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1128 | } |
| 1129 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1130 | void AudioSystem::releaseInput(audio_port_handle_t portId) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1131 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1132 | if (aps == 0) return; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1133 | |
| 1134 | auto status = [&]() -> status_t { |
| 1135 | int32_t portIdAidl = VALUE_OR_RETURN_STATUS( |
| 1136 | legacy2aidl_audio_port_handle_t_int32_t(portId)); |
| 1137 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(aps->releaseInput(portIdAidl))); |
| 1138 | return OK; |
| 1139 | }(); |
| 1140 | |
| 1141 | // Ignore status. |
| 1142 | (void) status; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1143 | } |
| 1144 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1145 | status_t AudioSystem::initStreamVolume(audio_stream_type_t stream, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1146 | int indexMin, |
| 1147 | int indexMax) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1148 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1149 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1150 | |
| 1151 | media::AudioStreamType streamAidl = VALUE_OR_RETURN_STATUS( |
| 1152 | legacy2aidl_audio_stream_type_t_AudioStreamType(stream)); |
| 1153 | int32_t indexMinAidl = VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(indexMin)); |
| 1154 | int32_t indexMaxAidl = VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(indexMax)); |
| 1155 | return statusTFromBinderStatus( |
| 1156 | aps->initStreamVolume(streamAidl, indexMinAidl, indexMaxAidl)); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1157 | } |
| 1158 | |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 1159 | status_t AudioSystem::setStreamVolumeIndex(audio_stream_type_t stream, |
| 1160 | int index, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1161 | audio_devices_t device) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1162 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1163 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1164 | |
| 1165 | media::AudioStreamType streamAidl = VALUE_OR_RETURN_STATUS( |
| 1166 | legacy2aidl_audio_stream_type_t_AudioStreamType(stream)); |
| 1167 | int32_t indexAidl = VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(index)); |
| 1168 | int32_t deviceAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_devices_t_int32_t(device)); |
| 1169 | return statusTFromBinderStatus( |
| 1170 | aps->setStreamVolumeIndex(streamAidl, deviceAidl, indexAidl)); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1171 | } |
| 1172 | |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 1173 | status_t AudioSystem::getStreamVolumeIndex(audio_stream_type_t stream, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1174 | int* index, |
| 1175 | audio_devices_t device) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1176 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1177 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1178 | |
| 1179 | media::AudioStreamType streamAidl = VALUE_OR_RETURN_STATUS( |
| 1180 | legacy2aidl_audio_stream_type_t_AudioStreamType(stream)); |
| 1181 | int32_t deviceAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_devices_t_int32_t(device)); |
| 1182 | int32_t indexAidl; |
| 1183 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 1184 | aps->getStreamVolumeIndex(streamAidl, deviceAidl, &indexAidl))); |
| 1185 | if (index != nullptr) { |
| 1186 | *index = VALUE_OR_RETURN_STATUS(convertIntegral<int>(indexAidl)); |
| 1187 | } |
| 1188 | return OK; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1189 | } |
| 1190 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1191 | status_t AudioSystem::setVolumeIndexForAttributes(const audio_attributes_t& attr, |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1192 | int index, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1193 | audio_devices_t device) { |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1194 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1195 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1196 | |
| 1197 | media::AudioAttributesInternal attrAidl = VALUE_OR_RETURN_STATUS( |
| 1198 | legacy2aidl_audio_attributes_t_AudioAttributesInternal(attr)); |
| 1199 | int32_t indexAidl = VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(index)); |
| 1200 | int32_t deviceAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_devices_t_int32_t(device)); |
| 1201 | return statusTFromBinderStatus( |
| 1202 | aps->setVolumeIndexForAttributes(attrAidl, deviceAidl, indexAidl)); |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1203 | } |
| 1204 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1205 | status_t AudioSystem::getVolumeIndexForAttributes(const audio_attributes_t& attr, |
| 1206 | int& index, |
| 1207 | audio_devices_t device) { |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1208 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1209 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1210 | |
| 1211 | media::AudioAttributesInternal attrAidl = VALUE_OR_RETURN_STATUS( |
| 1212 | legacy2aidl_audio_attributes_t_AudioAttributesInternal(attr)); |
| 1213 | int32_t deviceAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_devices_t_int32_t(device)); |
| 1214 | int32_t indexAidl; |
| 1215 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 1216 | aps->getVolumeIndexForAttributes(attrAidl, deviceAidl, &indexAidl))); |
| 1217 | index = VALUE_OR_RETURN_STATUS(convertIntegral<int>(indexAidl)); |
| 1218 | return OK; |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1219 | } |
| 1220 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1221 | status_t AudioSystem::getMaxVolumeIndexForAttributes(const audio_attributes_t& attr, int& index) { |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1222 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1223 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1224 | |
| 1225 | media::AudioAttributesInternal attrAidl = VALUE_OR_RETURN_STATUS( |
| 1226 | legacy2aidl_audio_attributes_t_AudioAttributesInternal(attr)); |
| 1227 | int32_t indexAidl; |
| 1228 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 1229 | aps->getMaxVolumeIndexForAttributes(attrAidl, &indexAidl))); |
| 1230 | index = VALUE_OR_RETURN_STATUS(convertIntegral<int>(indexAidl)); |
| 1231 | return OK; |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1232 | } |
| 1233 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1234 | status_t AudioSystem::getMinVolumeIndexForAttributes(const audio_attributes_t& attr, int& index) { |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1235 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1236 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1237 | |
| 1238 | media::AudioAttributesInternal attrAidl = VALUE_OR_RETURN_STATUS( |
| 1239 | legacy2aidl_audio_attributes_t_AudioAttributesInternal(attr)); |
| 1240 | int32_t indexAidl; |
| 1241 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 1242 | aps->getMinVolumeIndexForAttributes(attrAidl, &indexAidl))); |
| 1243 | index = VALUE_OR_RETURN_STATUS(convertIntegral<int>(indexAidl)); |
| 1244 | return OK; |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1245 | } |
| 1246 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1247 | product_strategy_t AudioSystem::getStrategyForStream(audio_stream_type_t stream) { |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1248 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1249 | if (aps == 0) return PRODUCT_STRATEGY_NONE; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1250 | |
| 1251 | auto result = [&]() -> ConversionResult<product_strategy_t> { |
| 1252 | media::AudioStreamType streamAidl = VALUE_OR_RETURN( |
| 1253 | legacy2aidl_audio_stream_type_t_AudioStreamType(stream)); |
| 1254 | int32_t resultAidl; |
| 1255 | RETURN_IF_ERROR(statusTFromBinderStatus( |
| 1256 | aps->getStrategyForStream(streamAidl, &resultAidl))); |
| 1257 | return aidl2legacy_int32_t_product_strategy_t(resultAidl); |
| 1258 | }(); |
| 1259 | return result.value_or(PRODUCT_STRATEGY_NONE); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1260 | } |
| 1261 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1262 | audio_devices_t AudioSystem::getDevicesForStream(audio_stream_type_t stream) { |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 1263 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
Glenn Kasten | 45faf7e | 2014-01-17 10:23:01 -0800 | [diff] [blame] | 1264 | if (aps == 0) return AUDIO_DEVICE_NONE; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1265 | |
| 1266 | auto result = [&]() -> ConversionResult<audio_devices_t> { |
| 1267 | media::AudioStreamType streamAidl = VALUE_OR_RETURN( |
| 1268 | legacy2aidl_audio_stream_type_t_AudioStreamType(stream)); |
| 1269 | int32_t resultAidl; |
| 1270 | RETURN_IF_ERROR(statusTFromBinderStatus( |
| 1271 | aps->getDevicesForStream(streamAidl, &resultAidl))); |
| 1272 | return aidl2legacy_int32_t_audio_devices_t(resultAidl); |
| 1273 | }(); |
| 1274 | return result.value_or(AUDIO_DEVICE_NONE); |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 1275 | } |
| 1276 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1277 | status_t AudioSystem::getDevicesForAttributes(const AudioAttributes& aa, |
| 1278 | AudioDeviceTypeAddrVector* devices) { |
Jean-Michel Trivi | f41599b | 2020-01-07 14:22:08 -0800 | [diff] [blame] | 1279 | if (devices == nullptr) { |
| 1280 | return BAD_VALUE; |
| 1281 | } |
| 1282 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1283 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1284 | |
| 1285 | media::AudioAttributesEx aaAidl = VALUE_OR_RETURN_STATUS( |
| 1286 | legacy2aidl_AudioAttributes_AudioAttributesEx(aa)); |
| 1287 | std::vector<media::AudioDevice> retAidl; |
| 1288 | RETURN_STATUS_IF_ERROR( |
| 1289 | statusTFromBinderStatus(aps->getDevicesForAttributes(aaAidl, &retAidl))); |
| 1290 | *devices = VALUE_OR_RETURN_STATUS( |
| 1291 | convertContainer<AudioDeviceTypeAddrVector>( |
| 1292 | retAidl, |
| 1293 | aidl2legacy_AudioDeviceTypeAddress)); |
| 1294 | return OK; |
Jean-Michel Trivi | f41599b | 2020-01-07 14:22:08 -0800 | [diff] [blame] | 1295 | } |
| 1296 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1297 | audio_io_handle_t AudioSystem::getOutputForEffect(const effect_descriptor_t* desc) { |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1298 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
Glenn Kasten | efa6ea9 | 2014-01-08 09:10:43 -0800 | [diff] [blame] | 1299 | // FIXME change return type to status_t, and return PERMISSION_DENIED here |
Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 1300 | if (aps == 0) return AUDIO_IO_HANDLE_NONE; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1301 | |
| 1302 | auto result = [&]() -> ConversionResult<audio_io_handle_t> { |
| 1303 | media::EffectDescriptor descAidl = VALUE_OR_RETURN( |
| 1304 | legacy2aidl_effect_descriptor_t_EffectDescriptor(*desc)); |
| 1305 | int32_t retAidl; |
| 1306 | RETURN_IF_ERROR( |
| 1307 | statusTFromBinderStatus(aps->getOutputForEffect(descAidl, &retAidl))); |
| 1308 | return aidl2legacy_int32_t_audio_io_handle_t(retAidl); |
| 1309 | }(); |
| 1310 | |
| 1311 | return result.value_or(AUDIO_IO_HANDLE_NONE); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1312 | } |
| 1313 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1314 | status_t AudioSystem::registerEffect(const effect_descriptor_t* desc, |
| 1315 | audio_io_handle_t io, |
| 1316 | product_strategy_t strategy, |
| 1317 | audio_session_t session, |
| 1318 | int id) { |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1319 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1320 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1321 | |
| 1322 | media::EffectDescriptor descAidl = VALUE_OR_RETURN_STATUS( |
| 1323 | legacy2aidl_effect_descriptor_t_EffectDescriptor(*desc)); |
| 1324 | int32_t ioAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(io)); |
| 1325 | int32_t strategyAidl = VALUE_OR_RETURN_STATUS(aidl2legacy_int32_t_product_strategy_t(strategy)); |
| 1326 | int32_t sessionAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_session_t_int32_t(session)); |
| 1327 | int32_t idAidl = VALUE_OR_RETURN_STATUS(convertReinterpret<int32_t>(id)); |
| 1328 | return statusTFromBinderStatus( |
| 1329 | aps->registerEffect(descAidl, ioAidl, strategyAidl, sessionAidl, idAidl)); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1330 | } |
| 1331 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1332 | status_t AudioSystem::unregisterEffect(int id) { |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1333 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1334 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1335 | |
| 1336 | int32_t idAidl = VALUE_OR_RETURN_STATUS(convertReinterpret<int32_t>(id)); |
| 1337 | return statusTFromBinderStatus( |
| 1338 | aps->unregisterEffect(idAidl)); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1339 | } |
| 1340 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1341 | status_t AudioSystem::setEffectEnabled(int id, bool enabled) { |
Eric Laurent | db7c079 | 2011-08-10 10:37:50 -0700 | [diff] [blame] | 1342 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1343 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1344 | |
| 1345 | int32_t idAidl = VALUE_OR_RETURN_STATUS(convertReinterpret<int32_t>(id)); |
| 1346 | return statusTFromBinderStatus( |
| 1347 | aps->setEffectEnabled(idAidl, enabled)); |
Eric Laurent | db7c079 | 2011-08-10 10:37:50 -0700 | [diff] [blame] | 1348 | } |
| 1349 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1350 | status_t AudioSystem::moveEffectsToIo(const std::vector<int>& ids, audio_io_handle_t io) { |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 1351 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1352 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1353 | |
| 1354 | std::vector<int32_t> idsAidl = VALUE_OR_RETURN_STATUS( |
| 1355 | convertContainer<std::vector<int32_t>>(ids, convertReinterpret<int32_t, int>)); |
| 1356 | int32_t ioAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(io)); |
| 1357 | return statusTFromBinderStatus(aps->moveEffectsToIo(idsAidl, ioAidl)); |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 1358 | } |
| 1359 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1360 | status_t AudioSystem::isStreamActive(audio_stream_type_t stream, bool* state, uint32_t inPastMs) { |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 1361 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1362 | if (aps == 0) return PERMISSION_DENIED; |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1363 | if (state == NULL) return BAD_VALUE; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1364 | |
| 1365 | media::AudioStreamType streamAidl = VALUE_OR_RETURN_STATUS( |
| 1366 | legacy2aidl_audio_stream_type_t_AudioStreamType(stream)); |
| 1367 | int32_t inPastMsAidl = VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(inPastMs)); |
| 1368 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 1369 | aps->isStreamActive(streamAidl, inPastMsAidl, state))); |
| 1370 | return OK; |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 1371 | } |
| 1372 | |
Jean-Michel Trivi | 272ab54 | 2013-02-04 16:26:02 -0800 | [diff] [blame] | 1373 | status_t AudioSystem::isStreamActiveRemotely(audio_stream_type_t stream, bool* state, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1374 | uint32_t inPastMs) { |
Jean-Michel Trivi | 272ab54 | 2013-02-04 16:26:02 -0800 | [diff] [blame] | 1375 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1376 | if (aps == 0) return PERMISSION_DENIED; |
| 1377 | if (state == NULL) return BAD_VALUE; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1378 | |
| 1379 | media::AudioStreamType streamAidl = VALUE_OR_RETURN_STATUS( |
| 1380 | legacy2aidl_audio_stream_type_t_AudioStreamType(stream)); |
| 1381 | int32_t inPastMsAidl = VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(inPastMs)); |
| 1382 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 1383 | aps->isStreamActiveRemotely(streamAidl, inPastMsAidl, state))); |
| 1384 | return OK; |
Jean-Michel Trivi | 272ab54 | 2013-02-04 16:26:02 -0800 | [diff] [blame] | 1385 | } |
| 1386 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1387 | status_t AudioSystem::isSourceActive(audio_source_t stream, bool* state) { |
Jean-Michel Trivi | d708603 | 2012-10-10 12:11:16 -0700 | [diff] [blame] | 1388 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1389 | if (aps == 0) return PERMISSION_DENIED; |
| 1390 | if (state == NULL) return BAD_VALUE; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1391 | |
| 1392 | media::AudioSourceType streamAidl = VALUE_OR_RETURN_STATUS( |
| 1393 | legacy2aidl_audio_source_t_AudioSourceType(stream)); |
| 1394 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 1395 | aps->isSourceActive(streamAidl, state))); |
| 1396 | return OK; |
Jean-Michel Trivi | d708603 | 2012-10-10 12:11:16 -0700 | [diff] [blame] | 1397 | } |
| 1398 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1399 | uint32_t AudioSystem::getPrimaryOutputSamplingRate() { |
Glenn Kasten | cc0f1cf | 2012-09-24 11:27:18 -0700 | [diff] [blame] | 1400 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 1401 | if (af == 0) return 0; |
| 1402 | return af->getPrimaryOutputSamplingRate(); |
| 1403 | } |
| 1404 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1405 | size_t AudioSystem::getPrimaryOutputFrameCount() { |
Glenn Kasten | cc0f1cf | 2012-09-24 11:27:18 -0700 | [diff] [blame] | 1406 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 1407 | if (af == 0) return 0; |
| 1408 | return af->getPrimaryOutputFrameCount(); |
| 1409 | } |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 1410 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1411 | status_t AudioSystem::setLowRamDevice(bool isLowRamDevice, int64_t totalMemory) { |
Glenn Kasten | 4182c4e | 2013-07-15 14:45:07 -0700 | [diff] [blame] | 1412 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 1413 | if (af == 0) return PERMISSION_DENIED; |
Andy Hung | 6f248bb | 2018-01-23 14:04:37 -0800 | [diff] [blame] | 1414 | return af->setLowRamDevice(isLowRamDevice, totalMemory); |
Glenn Kasten | 4182c4e | 2013-07-15 14:45:07 -0700 | [diff] [blame] | 1415 | } |
| 1416 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1417 | void AudioSystem::clearAudioConfigCache() { |
Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 1418 | // called by restoreTrack_l(), which needs new IAudioFlinger and IAudioPolicyService instances |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1419 | ALOGV("clearAudioConfigCache()"); |
Eric Laurent | f6778fd | 2014-11-18 17:26:58 -0800 | [diff] [blame] | 1420 | { |
| 1421 | Mutex::Autolock _l(gLock); |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1422 | if (gAudioFlingerClient != 0) { |
| 1423 | gAudioFlingerClient->clearIoCache(); |
| 1424 | } |
Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 1425 | gAudioFlinger.clear(); |
| 1426 | } |
| 1427 | { |
| 1428 | Mutex::Autolock _l(gLockAPS); |
| 1429 | gAudioPolicyService.clear(); |
| 1430 | } |
Eric Laurent | 9f6530f | 2011-08-30 10:18:54 -0700 | [diff] [blame] | 1431 | } |
| 1432 | |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 1433 | status_t AudioSystem::setSupportedSystemUsages(const std::vector<audio_usage_t>& systemUsages) { |
| 1434 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1435 | if (aps == nullptr) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1436 | |
| 1437 | std::vector<media::AudioUsage> systemUsagesAidl = VALUE_OR_RETURN_STATUS( |
| 1438 | convertContainer<std::vector<media::AudioUsage>>(systemUsages, |
| 1439 | legacy2aidl_audio_usage_t_AudioUsage)); |
| 1440 | return statusTFromBinderStatus(aps->setSupportedSystemUsages(systemUsagesAidl)); |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 1441 | } |
| 1442 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1443 | status_t AudioSystem::setAllowedCapturePolicy(uid_t uid, audio_flags_mask_t capturePolicy) { |
Kevin Rocard | b99cc75 | 2019-03-21 20:52:24 -0700 | [diff] [blame] | 1444 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1445 | if (aps == nullptr) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1446 | |
| 1447 | int32_t uidAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_uid_t_int32_t(uid)); |
| 1448 | int32_t capturePolicyAidl = VALUE_OR_RETURN_STATUS( |
| 1449 | legacy2aidl_audio_flags_mask_t_int32_t_mask(capturePolicy)); |
| 1450 | return statusTFromBinderStatus(aps->setAllowedCapturePolicy(uidAidl, capturePolicyAidl)); |
Kevin Rocard | b99cc75 | 2019-03-21 20:52:24 -0700 | [diff] [blame] | 1451 | } |
| 1452 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1453 | audio_offload_mode_t AudioSystem::getOffloadSupport(const audio_offload_info_t& info) { |
Eric Laurent | 90fe31c | 2020-11-26 20:06:35 +0100 | [diff] [blame] | 1454 | ALOGV("%s", __func__); |
Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 1455 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
Eric Laurent | 90fe31c | 2020-11-26 20:06:35 +0100 | [diff] [blame] | 1456 | if (aps == 0) return AUDIO_OFFLOAD_NOT_SUPPORTED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1457 | |
| 1458 | auto result = [&]() -> ConversionResult<audio_offload_mode_t> { |
| 1459 | media::AudioOffloadInfo infoAidl = VALUE_OR_RETURN( |
| 1460 | legacy2aidl_audio_offload_info_t_AudioOffloadInfo(info)); |
| 1461 | media::AudioOffloadMode retAidl; |
| 1462 | RETURN_IF_ERROR( |
| 1463 | statusTFromBinderStatus(aps->getOffloadSupport(infoAidl, &retAidl))); |
| 1464 | return aidl2legacy_AudioOffloadMode_audio_offload_mode_t(retAidl); |
| 1465 | }(); |
| 1466 | |
| 1467 | return result.value_or(static_cast<audio_offload_mode_t>(0)); |
Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 1468 | } |
| 1469 | |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1470 | status_t AudioSystem::listAudioPorts(audio_port_role_t role, |
| 1471 | audio_port_type_t type, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1472 | unsigned int* num_ports, |
| 1473 | struct audio_port_v7* ports, |
| 1474 | unsigned int* generation) { |
| 1475 | if (num_ports == nullptr || (*num_ports != 0 && ports == nullptr) || |
| 1476 | generation == nullptr) { |
| 1477 | return BAD_VALUE; |
| 1478 | } |
| 1479 | |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1480 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1481 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1482 | |
| 1483 | media::AudioPortRole roleAidl = VALUE_OR_RETURN_STATUS( |
| 1484 | legacy2aidl_audio_port_role_t_AudioPortRole(role)); |
| 1485 | media::AudioPortType typeAidl = VALUE_OR_RETURN_STATUS( |
| 1486 | legacy2aidl_audio_port_type_t_AudioPortType(type)); |
| 1487 | media::Int numPortsAidl; |
| 1488 | numPortsAidl.value = VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(*num_ports)); |
| 1489 | std::vector<media::AudioPort> portsAidl; |
| 1490 | int32_t generationAidl; |
| 1491 | |
| 1492 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 1493 | aps->listAudioPorts(roleAidl, typeAidl, &numPortsAidl, &portsAidl, &generationAidl))); |
| 1494 | *num_ports = VALUE_OR_RETURN_STATUS(convertIntegral<unsigned int>(numPortsAidl.value)); |
| 1495 | *generation = VALUE_OR_RETURN_STATUS(convertIntegral<unsigned int>(generationAidl)); |
| 1496 | RETURN_STATUS_IF_ERROR(convertRange(portsAidl.begin(), portsAidl.end(), ports, |
| 1497 | aidl2legacy_AudioPort_audio_port_v7)); |
| 1498 | return OK; |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1499 | } |
| 1500 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1501 | status_t AudioSystem::getAudioPort(struct audio_port_v7* port) { |
| 1502 | if (port == nullptr) { |
| 1503 | return BAD_VALUE; |
| 1504 | } |
| 1505 | |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1506 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1507 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1508 | |
| 1509 | media::AudioPort portAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_port_v7_AudioPort(*port)); |
| 1510 | RETURN_STATUS_IF_ERROR( |
| 1511 | statusTFromBinderStatus(aps->getAudioPort(portAidl, &portAidl))); |
| 1512 | *port = VALUE_OR_RETURN_STATUS(aidl2legacy_AudioPort_audio_port_v7(portAidl)); |
| 1513 | return OK; |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1514 | } |
| 1515 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1516 | status_t AudioSystem::createAudioPatch(const struct audio_patch* patch, |
| 1517 | audio_patch_handle_t* handle) { |
| 1518 | if (patch == nullptr || handle == nullptr) { |
| 1519 | return BAD_VALUE; |
| 1520 | } |
| 1521 | |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1522 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1523 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1524 | |
| 1525 | media::AudioPatch patchAidl = VALUE_OR_RETURN_STATUS( |
| 1526 | legacy2aidl_audio_patch_AudioPatch(*patch)); |
| 1527 | int32_t handleAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_patch_handle_t_int32_t(*handle)); |
| 1528 | RETURN_STATUS_IF_ERROR( |
| 1529 | statusTFromBinderStatus(aps->createAudioPatch(patchAidl, handleAidl, &handleAidl))); |
| 1530 | *handle = VALUE_OR_RETURN_STATUS(aidl2legacy_int32_t_audio_patch_handle_t(handleAidl)); |
| 1531 | return OK; |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1532 | } |
| 1533 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1534 | status_t AudioSystem::releaseAudioPatch(audio_patch_handle_t handle) { |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1535 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1536 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1537 | |
| 1538 | int32_t handleAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_patch_handle_t_int32_t(handle)); |
| 1539 | return statusTFromBinderStatus(aps->releaseAudioPatch(handleAidl)); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1540 | } |
| 1541 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1542 | status_t AudioSystem::listAudioPatches(unsigned int* num_patches, |
| 1543 | struct audio_patch* patches, |
| 1544 | unsigned int* generation) { |
| 1545 | if (num_patches == nullptr || (*num_patches != 0 && patches == nullptr) || |
| 1546 | generation == nullptr) { |
| 1547 | return BAD_VALUE; |
| 1548 | } |
| 1549 | |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1550 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1551 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1552 | |
| 1553 | |
| 1554 | media::Int numPatchesAidl; |
| 1555 | numPatchesAidl.value = VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(*num_patches)); |
| 1556 | std::vector<media::AudioPatch> patchesAidl; |
| 1557 | int32_t generationAidl; |
| 1558 | |
| 1559 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 1560 | aps->listAudioPatches(&numPatchesAidl, &patchesAidl, &generationAidl))); |
| 1561 | *num_patches = VALUE_OR_RETURN_STATUS(convertIntegral<unsigned int>(numPatchesAidl.value)); |
| 1562 | *generation = VALUE_OR_RETURN_STATUS(convertIntegral<unsigned int>(generationAidl)); |
| 1563 | RETURN_STATUS_IF_ERROR(convertRange(patchesAidl.begin(), patchesAidl.end(), patches, |
| 1564 | aidl2legacy_AudioPatch_audio_patch)); |
| 1565 | return OK; |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1566 | } |
| 1567 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1568 | status_t AudioSystem::setAudioPortConfig(const struct audio_port_config* config) { |
| 1569 | if (config == nullptr) { |
| 1570 | return BAD_VALUE; |
| 1571 | } |
| 1572 | |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1573 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1574 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1575 | |
| 1576 | media::AudioPortConfig configAidl = VALUE_OR_RETURN_STATUS( |
| 1577 | legacy2aidl_audio_port_config_AudioPortConfig(*config)); |
| 1578 | return statusTFromBinderStatus(aps->setAudioPortConfig(configAidl)); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1579 | } |
| 1580 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1581 | status_t AudioSystem::addAudioPortCallback(const sp<AudioPortCallback>& callback) { |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1582 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1583 | if (aps == 0) return PERMISSION_DENIED; |
| 1584 | |
| 1585 | Mutex::Autolock _l(gLockAPS); |
| 1586 | if (gAudioPolicyServiceClient == 0) { |
| 1587 | return NO_INIT; |
| 1588 | } |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 1589 | int ret = gAudioPolicyServiceClient->addAudioPortCallback(callback); |
| 1590 | if (ret == 1) { |
| 1591 | aps->setAudioPortCallbacksEnabled(true); |
| 1592 | } |
| 1593 | return (ret < 0) ? INVALID_OPERATION : NO_ERROR; |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 1594 | } |
| 1595 | |
Jean-Michel Trivi | f613d42 | 2015-04-23 18:41:29 -0700 | [diff] [blame] | 1596 | /*static*/ |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1597 | status_t AudioSystem::removeAudioPortCallback(const sp<AudioPortCallback>& callback) { |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1598 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1599 | if (aps == 0) return PERMISSION_DENIED; |
| 1600 | |
| 1601 | Mutex::Autolock _l(gLockAPS); |
| 1602 | if (gAudioPolicyServiceClient == 0) { |
| 1603 | return NO_INIT; |
| 1604 | } |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 1605 | int ret = gAudioPolicyServiceClient->removeAudioPortCallback(callback); |
| 1606 | if (ret == 0) { |
| 1607 | aps->setAudioPortCallbacksEnabled(false); |
| 1608 | } |
| 1609 | return (ret < 0) ? INVALID_OPERATION : NO_ERROR; |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1610 | } |
| 1611 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1612 | status_t AudioSystem::addAudioVolumeGroupCallback(const sp<AudioVolumeGroupCallback>& callback) { |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1613 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1614 | if (aps == 0) return PERMISSION_DENIED; |
| 1615 | |
| 1616 | Mutex::Autolock _l(gLockAPS); |
| 1617 | if (gAudioPolicyServiceClient == 0) { |
| 1618 | return NO_INIT; |
| 1619 | } |
| 1620 | int ret = gAudioPolicyServiceClient->addAudioVolumeGroupCallback(callback); |
| 1621 | if (ret == 1) { |
| 1622 | aps->setAudioVolumeGroupCallbacksEnabled(true); |
| 1623 | } |
| 1624 | return (ret < 0) ? INVALID_OPERATION : NO_ERROR; |
| 1625 | } |
| 1626 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1627 | status_t AudioSystem::removeAudioVolumeGroupCallback(const sp<AudioVolumeGroupCallback>& callback) { |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1628 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1629 | if (aps == 0) return PERMISSION_DENIED; |
| 1630 | |
| 1631 | Mutex::Autolock _l(gLockAPS); |
| 1632 | if (gAudioPolicyServiceClient == 0) { |
| 1633 | return NO_INIT; |
| 1634 | } |
| 1635 | int ret = gAudioPolicyServiceClient->removeAudioVolumeGroupCallback(callback); |
| 1636 | if (ret == 0) { |
| 1637 | aps->setAudioVolumeGroupCallbacksEnabled(false); |
| 1638 | } |
| 1639 | return (ret < 0) ? INVALID_OPERATION : NO_ERROR; |
| 1640 | } |
| 1641 | |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1642 | status_t AudioSystem::addAudioDeviceCallback( |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 1643 | const wp<AudioDeviceCallback>& callback, audio_io_handle_t audioIo, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1644 | audio_port_handle_t portId) { |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1645 | const sp<AudioFlingerClient> afc = getAudioFlingerClient(); |
| 1646 | if (afc == 0) { |
| 1647 | return NO_INIT; |
| 1648 | } |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 1649 | status_t status = afc->addAudioDeviceCallback(callback, audioIo, portId); |
Eric Laurent | 7c1ec5f | 2015-07-09 14:52:47 -0700 | [diff] [blame] | 1650 | if (status == NO_ERROR) { |
| 1651 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 1652 | if (af != 0) { |
| 1653 | af->registerClient(afc); |
| 1654 | } |
| 1655 | } |
| 1656 | return status; |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | status_t AudioSystem::removeAudioDeviceCallback( |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 1660 | const wp<AudioDeviceCallback>& callback, audio_io_handle_t audioIo, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1661 | audio_port_handle_t portId) { |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1662 | const sp<AudioFlingerClient> afc = getAudioFlingerClient(); |
| 1663 | if (afc == 0) { |
| 1664 | return NO_INIT; |
| 1665 | } |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 1666 | return afc->removeAudioDeviceCallback(callback, audioIo, portId); |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1667 | } |
| 1668 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1669 | audio_port_handle_t AudioSystem::getDeviceIdForIo(audio_io_handle_t audioIo) { |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1670 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 1671 | if (af == 0) return PERMISSION_DENIED; |
| 1672 | const sp<AudioIoDescriptor> desc = getIoDescriptor(audioIo); |
| 1673 | if (desc == 0) { |
| 1674 | return AUDIO_PORT_HANDLE_NONE; |
| 1675 | } |
| 1676 | return desc->getDeviceId(); |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1677 | } |
| 1678 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1679 | status_t AudioSystem::acquireSoundTriggerSession(audio_session_t* session, |
| 1680 | audio_io_handle_t* ioHandle, |
| 1681 | audio_devices_t* device) { |
| 1682 | if (session == nullptr || ioHandle == nullptr || device == nullptr) { |
| 1683 | return BAD_VALUE; |
| 1684 | } |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1685 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1686 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1687 | |
| 1688 | media::SoundTriggerSession retAidl; |
| 1689 | RETURN_STATUS_IF_ERROR( |
| 1690 | statusTFromBinderStatus(aps->acquireSoundTriggerSession(&retAidl))); |
| 1691 | *session = VALUE_OR_RETURN_STATUS(aidl2legacy_int32_t_audio_session_t(retAidl.session)); |
| 1692 | *ioHandle = VALUE_OR_RETURN_STATUS(aidl2legacy_int32_t_audio_io_handle_t(retAidl.ioHandle)); |
| 1693 | *device = VALUE_OR_RETURN_STATUS(aidl2legacy_int32_t_audio_devices_t(retAidl.device)); |
| 1694 | return OK; |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1695 | } |
| 1696 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1697 | status_t AudioSystem::releaseSoundTriggerSession(audio_session_t session) { |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1698 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1699 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1700 | |
| 1701 | int32_t sessionAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_session_t_int32_t(session)); |
| 1702 | return statusTFromBinderStatus(aps->releaseSoundTriggerSession(sessionAidl)); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1703 | } |
Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 1704 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1705 | audio_mode_t AudioSystem::getPhoneState() { |
Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 1706 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1707 | if (aps == 0) return AUDIO_MODE_INVALID; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1708 | |
| 1709 | auto result = [&]() -> ConversionResult<audio_mode_t> { |
| 1710 | media::AudioMode retAidl; |
| 1711 | RETURN_IF_ERROR(statusTFromBinderStatus(aps->getPhoneState(&retAidl))); |
| 1712 | return aidl2legacy_AudioMode_audio_mode_t(retAidl); |
| 1713 | }(); |
| 1714 | |
| 1715 | return result.value_or(AUDIO_MODE_INVALID); |
Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 1716 | } |
| 1717 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1718 | status_t AudioSystem::registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration) { |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1719 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1720 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1721 | |
| 1722 | size_t mixesSize = std::min(mixes.size(), size_t{MAX_MIXES_PER_POLICY}); |
| 1723 | std::vector<media::AudioMix> mixesAidl; |
| 1724 | RETURN_STATUS_IF_ERROR( |
| 1725 | convertRange(mixes.begin(), mixes.begin() + mixesSize, std::back_inserter(mixesAidl), |
| 1726 | legacy2aidl_AudioMix)); |
| 1727 | return statusTFromBinderStatus(aps->registerPolicyMixes(mixesAidl, registration)); |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1728 | } |
Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 1729 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1730 | status_t AudioSystem::setUidDeviceAffinities(uid_t uid, const AudioDeviceTypeAddrVector& devices) { |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1731 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1732 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1733 | |
| 1734 | int32_t uidAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_uid_t_int32_t(uid)); |
| 1735 | std::vector<media::AudioDevice> devicesAidl = VALUE_OR_RETURN_STATUS( |
| 1736 | convertContainer<std::vector<media::AudioDevice>>(devices, |
| 1737 | legacy2aidl_AudioDeviceTypeAddress)); |
| 1738 | return statusTFromBinderStatus(aps->setUidDeviceAffinities(uidAidl, devicesAidl)); |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1739 | } |
| 1740 | |
| 1741 | status_t AudioSystem::removeUidDeviceAffinities(uid_t uid) { |
| 1742 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1743 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1744 | |
| 1745 | int32_t uidAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_uid_t_int32_t(uid)); |
| 1746 | return statusTFromBinderStatus(aps->removeUidDeviceAffinities(uidAidl)); |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1747 | } |
| 1748 | |
Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1749 | status_t AudioSystem::setUserIdDeviceAffinities(int userId, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1750 | const AudioDeviceTypeAddrVector& devices) { |
Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1751 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1752 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1753 | |
| 1754 | int32_t userIdAidl = VALUE_OR_RETURN_STATUS(convertReinterpret<int32_t>(userId)); |
| 1755 | std::vector<media::AudioDevice> devicesAidl = VALUE_OR_RETURN_STATUS( |
| 1756 | convertContainer<std::vector<media::AudioDevice>>(devices, |
| 1757 | legacy2aidl_AudioDeviceTypeAddress)); |
| 1758 | return statusTFromBinderStatus( |
| 1759 | aps->setUserIdDeviceAffinities(userIdAidl, devicesAidl)); |
Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1760 | } |
| 1761 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1762 | status_t AudioSystem::removeUserIdDeviceAffinities(int userId) { |
Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1763 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1764 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1765 | int32_t userIdAidl = VALUE_OR_RETURN_STATUS(convertReinterpret<int32_t>(userId)); |
| 1766 | return statusTFromBinderStatus(aps->removeUserIdDeviceAffinities(userIdAidl)); |
Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1767 | } |
| 1768 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1769 | status_t AudioSystem::startAudioSource(const struct audio_port_config* source, |
| 1770 | const audio_attributes_t* attributes, |
| 1771 | audio_port_handle_t* portId) { |
| 1772 | if (source == nullptr || attributes == nullptr || portId == nullptr) { |
| 1773 | return BAD_VALUE; |
| 1774 | } |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1775 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1776 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1777 | |
| 1778 | media::AudioPortConfig sourceAidl = VALUE_OR_RETURN_STATUS( |
| 1779 | legacy2aidl_audio_port_config_AudioPortConfig(*source)); |
| 1780 | media::AudioAttributesInternal attributesAidl = VALUE_OR_RETURN_STATUS( |
| 1781 | legacy2aidl_audio_attributes_t_AudioAttributesInternal(*attributes)); |
| 1782 | int32_t portIdAidl; |
| 1783 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 1784 | aps->startAudioSource(sourceAidl, attributesAidl, &portIdAidl))); |
| 1785 | *portId = VALUE_OR_RETURN_STATUS(aidl2legacy_int32_t_audio_port_handle_t(portIdAidl)); |
| 1786 | return OK; |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1787 | } |
| 1788 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1789 | status_t AudioSystem::stopAudioSource(audio_port_handle_t portId) { |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1790 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1791 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1792 | |
| 1793 | int32_t portIdAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_port_handle_t_int32_t(portId)); |
| 1794 | return statusTFromBinderStatus(aps->stopAudioSource(portIdAidl)); |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1795 | } |
| 1796 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1797 | status_t AudioSystem::setMasterMono(bool mono) { |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1798 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1799 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1800 | return statusTFromBinderStatus(aps->setMasterMono(mono)); |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1801 | } |
| 1802 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1803 | status_t AudioSystem::getMasterMono(bool* mono) { |
| 1804 | if (mono == nullptr) { |
| 1805 | return BAD_VALUE; |
| 1806 | } |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1807 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1808 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1809 | return statusTFromBinderStatus(aps->getMasterMono(mono)); |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1810 | } |
| 1811 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1812 | status_t AudioSystem::setMasterBalance(float balance) { |
Richard Folke Tullberg | 3fae037 | 2017-01-13 09:04:25 +0100 | [diff] [blame] | 1813 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 1814 | if (af == 0) return PERMISSION_DENIED; |
| 1815 | return af->setMasterBalance(balance); |
| 1816 | } |
| 1817 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1818 | status_t AudioSystem::getMasterBalance(float* balance) { |
Richard Folke Tullberg | 3fae037 | 2017-01-13 09:04:25 +0100 | [diff] [blame] | 1819 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 1820 | if (af == 0) return PERMISSION_DENIED; |
| 1821 | return af->getMasterBalance(balance); |
| 1822 | } |
| 1823 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1824 | float |
| 1825 | AudioSystem::getStreamVolumeDB(audio_stream_type_t stream, int index, audio_devices_t device) { |
Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 1826 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1827 | if (aps == 0) return NAN; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1828 | |
| 1829 | auto result = [&]() -> ConversionResult<float> { |
| 1830 | media::AudioStreamType streamAidl = VALUE_OR_RETURN( |
| 1831 | legacy2aidl_audio_stream_type_t_AudioStreamType(stream)); |
| 1832 | int32_t indexAidl = VALUE_OR_RETURN(convertIntegral<int32_t>(index)); |
| 1833 | int32_t deviceAidl = VALUE_OR_RETURN(legacy2aidl_audio_devices_t_int32_t(device)); |
| 1834 | float retAidl; |
| 1835 | RETURN_IF_ERROR(statusTFromBinderStatus( |
| 1836 | aps->getStreamVolumeDB(streamAidl, indexAidl, deviceAidl, &retAidl))); |
| 1837 | return retAidl; |
| 1838 | }(); |
| 1839 | return result.value_or(NAN); |
Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 1840 | } |
| 1841 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1842 | status_t AudioSystem::getMicrophones(std::vector<media::MicrophoneInfo>* microphones) { |
jiabin | 46a76fa | 2018-01-05 10:18:21 -0800 | [diff] [blame] | 1843 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 1844 | if (af == 0) return PERMISSION_DENIED; |
| 1845 | return af->getMicrophones(microphones); |
| 1846 | } |
| 1847 | |
Eric Laurent | 42896a0 | 2019-09-27 15:40:33 -0700 | [diff] [blame] | 1848 | status_t AudioSystem::setAudioHalPids(const std::vector<pid_t>& pids) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1849 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 1850 | if (af == nullptr) return PERMISSION_DENIED; |
| 1851 | return af->setAudioHalPids(pids); |
Eric Laurent | 42896a0 | 2019-09-27 15:40:33 -0700 | [diff] [blame] | 1852 | } |
| 1853 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1854 | status_t AudioSystem::getSurroundFormats(unsigned int* numSurroundFormats, |
| 1855 | audio_format_t* surroundFormats, |
Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 1856 | bool* surroundFormatsEnabled) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1857 | if (numSurroundFormats == nullptr || (*numSurroundFormats != 0 && |
| 1858 | (surroundFormats == nullptr || |
| 1859 | surroundFormatsEnabled == nullptr))) { |
| 1860 | return BAD_VALUE; |
| 1861 | } |
| 1862 | |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 1863 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1864 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1865 | media::Int numSurroundFormatsAidl; |
| 1866 | numSurroundFormatsAidl.value = |
| 1867 | VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(*numSurroundFormats)); |
| 1868 | std::vector<media::audio::common::AudioFormat> surroundFormatsAidl; |
Kriti Dang | 877b27e | 2021-02-02 12:10:40 +0100 | [diff] [blame] | 1869 | std::vector<bool> surroundFormatsEnabledAidl; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1870 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 1871 | aps->getSurroundFormats(&numSurroundFormatsAidl, &surroundFormatsAidl, |
| 1872 | &surroundFormatsEnabledAidl))); |
Kriti Dang | 877b27e | 2021-02-02 12:10:40 +0100 | [diff] [blame] | 1873 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1874 | *numSurroundFormats = VALUE_OR_RETURN_STATUS( |
| 1875 | convertIntegral<unsigned int>(numSurroundFormatsAidl.value)); |
| 1876 | RETURN_STATUS_IF_ERROR( |
| 1877 | convertRange(surroundFormatsAidl.begin(), surroundFormatsAidl.end(), surroundFormats, |
| 1878 | aidl2legacy_AudioFormat_audio_format_t)); |
Kriti Dang | 877b27e | 2021-02-02 12:10:40 +0100 | [diff] [blame] | 1879 | std::copy(surroundFormatsEnabledAidl.begin(), surroundFormatsEnabledAidl.end(), |
| 1880 | surroundFormatsEnabled); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1881 | return OK; |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 1882 | } |
| 1883 | |
Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 1884 | status_t AudioSystem::getReportedSurroundFormats(unsigned int* numSurroundFormats, |
| 1885 | audio_format_t* surroundFormats) { |
| 1886 | if (numSurroundFormats == nullptr || (*numSurroundFormats != 0 && surroundFormats == nullptr)) { |
| 1887 | return BAD_VALUE; |
| 1888 | } |
| 1889 | |
| 1890 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1891 | if (aps == 0) return PERMISSION_DENIED; |
| 1892 | media::Int numSurroundFormatsAidl; |
| 1893 | numSurroundFormatsAidl.value = |
| 1894 | VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(*numSurroundFormats)); |
| 1895 | std::vector<media::audio::common::AudioFormat> surroundFormatsAidl; |
| 1896 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 1897 | aps->getReportedSurroundFormats(&numSurroundFormatsAidl, &surroundFormatsAidl))); |
| 1898 | |
| 1899 | *numSurroundFormats = VALUE_OR_RETURN_STATUS( |
| 1900 | convertIntegral<unsigned int>(numSurroundFormatsAidl.value)); |
| 1901 | RETURN_STATUS_IF_ERROR( |
| 1902 | convertRange(surroundFormatsAidl.begin(), surroundFormatsAidl.end(), surroundFormats, |
| 1903 | aidl2legacy_AudioFormat_audio_format_t)); |
| 1904 | return OK; |
| 1905 | } |
| 1906 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1907 | status_t AudioSystem::setSurroundFormatEnabled(audio_format_t audioFormat, bool enabled) { |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 1908 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1909 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1910 | |
| 1911 | media::audio::common::AudioFormat audioFormatAidl = VALUE_OR_RETURN_STATUS( |
| 1912 | legacy2aidl_audio_format_t_AudioFormat(audioFormat)); |
| 1913 | return statusTFromBinderStatus( |
| 1914 | aps->setSurroundFormatEnabled(audioFormatAidl, enabled)); |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 1915 | } |
| 1916 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1917 | status_t AudioSystem::setAssistantUid(uid_t uid) { |
| 1918 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1919 | if (aps == 0) return PERMISSION_DENIED; |
| 1920 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1921 | int32_t uidAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_uid_t_int32_t(uid)); |
| 1922 | return statusTFromBinderStatus(aps->setAssistantUid(uidAidl)); |
Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1923 | } |
| 1924 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1925 | status_t AudioSystem::setA11yServicesUids(const std::vector<uid_t>& uids) { |
| 1926 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1927 | if (aps == 0) return PERMISSION_DENIED; |
| 1928 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1929 | std::vector<int32_t> uidsAidl = VALUE_OR_RETURN_STATUS( |
| 1930 | convertContainer<std::vector<int32_t>>(uids, legacy2aidl_uid_t_int32_t)); |
| 1931 | return statusTFromBinderStatus(aps->setA11yServicesUids(uidsAidl)); |
Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1932 | } |
| 1933 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1934 | status_t AudioSystem::setCurrentImeUid(uid_t uid) { |
| 1935 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
Kohsuke Yatoh | a623a13 | 2020-03-24 20:10:26 -0700 | [diff] [blame] | 1936 | if (aps == 0) return PERMISSION_DENIED; |
| 1937 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1938 | int32_t uidAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_uid_t_int32_t(uid)); |
| 1939 | return statusTFromBinderStatus(aps->setCurrentImeUid(uidAidl)); |
Kohsuke Yatoh | a623a13 | 2020-03-24 20:10:26 -0700 | [diff] [blame] | 1940 | } |
| 1941 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1942 | bool AudioSystem::isHapticPlaybackSupported() { |
jiabin | 6012f91 | 2018-11-02 17:06:30 -0700 | [diff] [blame] | 1943 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1944 | if (aps == 0) return false; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1945 | |
| 1946 | auto result = [&]() -> ConversionResult<bool> { |
| 1947 | bool retVal; |
| 1948 | RETURN_IF_ERROR( |
| 1949 | statusTFromBinderStatus(aps->isHapticPlaybackSupported(&retVal))); |
| 1950 | return retVal; |
| 1951 | }(); |
| 1952 | return result.value_or(false); |
jiabin | 6012f91 | 2018-11-02 17:06:30 -0700 | [diff] [blame] | 1953 | } |
| 1954 | |
Arun Mirpuri | 11029ad | 2018-12-19 20:45:19 -0800 | [diff] [blame] | 1955 | status_t AudioSystem::getHwOffloadEncodingFormatsSupportedForA2DP( |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1956 | std::vector<audio_format_t>* formats) { |
| 1957 | if (formats == nullptr) { |
| 1958 | return BAD_VALUE; |
| 1959 | } |
| 1960 | |
| 1961 | const sp<IAudioPolicyService> |
| 1962 | & aps = AudioSystem::get_audio_policy_service(); |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1963 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1964 | |
| 1965 | std::vector<media::audio::common::AudioFormat> formatsAidl; |
| 1966 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 1967 | aps->getHwOffloadEncodingFormatsSupportedForA2DP(&formatsAidl))); |
| 1968 | *formats = VALUE_OR_RETURN_STATUS( |
| 1969 | convertContainer<std::vector<audio_format_t>>(formatsAidl, |
| 1970 | aidl2legacy_AudioFormat_audio_format_t)); |
| 1971 | return OK; |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1972 | } |
| 1973 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1974 | status_t AudioSystem::listAudioProductStrategies(AudioProductStrategyVector& strategies) { |
Arun Mirpuri | 11029ad | 2018-12-19 20:45:19 -0800 | [diff] [blame] | 1975 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1976 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1977 | |
| 1978 | std::vector<media::AudioProductStrategy> strategiesAidl; |
| 1979 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 1980 | aps->listAudioProductStrategies(&strategiesAidl))); |
| 1981 | strategies = VALUE_OR_RETURN_STATUS( |
| 1982 | convertContainer<AudioProductStrategyVector>(strategiesAidl, |
| 1983 | aidl2legacy_AudioProductStrategy)); |
| 1984 | return OK; |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1985 | } |
| 1986 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1987 | audio_attributes_t AudioSystem::streamTypeToAttributes(audio_stream_type_t stream) { |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1988 | AudioProductStrategyVector strategies; |
| 1989 | listAudioProductStrategies(strategies); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1990 | for (const auto& strategy : strategies) { |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1991 | auto attrVect = strategy.getAudioAttributes(); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1992 | auto iter = std::find_if(begin(attrVect), end(attrVect), [&stream](const auto& attributes) { |
| 1993 | return attributes.getStreamType() == stream; |
| 1994 | }); |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1995 | if (iter != end(attrVect)) { |
| 1996 | return iter->getAttributes(); |
| 1997 | } |
| 1998 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1999 | ALOGE("invalid stream type %s when converting to attributes", toString(stream).c_str()); |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 2000 | return AUDIO_ATTRIBUTES_INITIALIZER; |
| 2001 | } |
| 2002 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2003 | audio_stream_type_t AudioSystem::attributesToStreamType(const audio_attributes_t& attr) { |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 2004 | product_strategy_t psId; |
| 2005 | status_t ret = AudioSystem::getProductStrategyFromAudioAttributes(AudioAttributes(attr), psId); |
| 2006 | if (ret != NO_ERROR) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2007 | ALOGE("no strategy found for attributes %s", toString(attr).c_str()); |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 2008 | return AUDIO_STREAM_MUSIC; |
| 2009 | } |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 2010 | AudioProductStrategyVector strategies; |
| 2011 | listAudioProductStrategies(strategies); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2012 | for (const auto& strategy : strategies) { |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 2013 | if (strategy.getId() == psId) { |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 2014 | auto attrVect = strategy.getAudioAttributes(); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2015 | auto iter = std::find_if(begin(attrVect), end(attrVect), [&attr](const auto& refAttr) { |
| 2016 | return AudioProductStrategy::attributesMatches( |
| 2017 | refAttr.getAttributes(), attr); |
| 2018 | }); |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 2019 | if (iter != end(attrVect)) { |
| 2020 | return iter->getStreamType(); |
| 2021 | } |
| 2022 | } |
| 2023 | } |
Jean-Michel Trivi | ed67865 | 2019-12-19 13:39:30 -0800 | [diff] [blame] | 2024 | switch (attr.usage) { |
| 2025 | case AUDIO_USAGE_VIRTUAL_SOURCE: |
| 2026 | // virtual source is not expected to have an associated product strategy |
| 2027 | break; |
| 2028 | default: |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2029 | ALOGE("invalid attributes %s when converting to stream", toString(attr).c_str()); |
Jean-Michel Trivi | ed67865 | 2019-12-19 13:39:30 -0800 | [diff] [blame] | 2030 | break; |
| 2031 | } |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 2032 | return AUDIO_STREAM_MUSIC; |
| 2033 | } |
| 2034 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2035 | status_t AudioSystem::getProductStrategyFromAudioAttributes(const AudioAttributes& aa, |
Francois Gaffie | 11b6592 | 2020-09-24 16:59:08 +0200 | [diff] [blame] | 2036 | product_strategy_t& productStrategy, |
| 2037 | bool fallbackOnDefault) { |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 2038 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 2039 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2040 | |
| 2041 | media::AudioAttributesEx aaAidl = VALUE_OR_RETURN_STATUS( |
| 2042 | legacy2aidl_AudioAttributes_AudioAttributesEx(aa)); |
| 2043 | int32_t productStrategyAidl; |
| 2044 | |
| 2045 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
Francois Gaffie | 11b6592 | 2020-09-24 16:59:08 +0200 | [diff] [blame] | 2046 | aps->getProductStrategyFromAudioAttributes(aaAidl, fallbackOnDefault, |
| 2047 | &productStrategyAidl))); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2048 | productStrategy = VALUE_OR_RETURN_STATUS( |
| 2049 | aidl2legacy_int32_t_product_strategy_t(productStrategyAidl)); |
| 2050 | return OK; |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 2051 | } |
| 2052 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2053 | status_t AudioSystem::listAudioVolumeGroups(AudioVolumeGroupVector& groups) { |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 2054 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2055 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2056 | |
| 2057 | std::vector<media::AudioVolumeGroup> groupsAidl; |
| 2058 | RETURN_STATUS_IF_ERROR( |
| 2059 | statusTFromBinderStatus(aps->listAudioVolumeGroups(&groupsAidl))); |
| 2060 | groups = VALUE_OR_RETURN_STATUS( |
| 2061 | convertContainer<AudioVolumeGroupVector>(groupsAidl, aidl2legacy_AudioVolumeGroup)); |
| 2062 | return OK; |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 2063 | } |
| 2064 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2065 | status_t AudioSystem::getVolumeGroupFromAudioAttributes(const AudioAttributes& aa, |
Francois Gaffie | 11b6592 | 2020-09-24 16:59:08 +0200 | [diff] [blame] | 2066 | volume_group_t& volumeGroup, |
| 2067 | bool fallbackOnDefault) { |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 2068 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2069 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2070 | |
| 2071 | media::AudioAttributesEx aaAidl = VALUE_OR_RETURN_STATUS( |
| 2072 | legacy2aidl_AudioAttributes_AudioAttributesEx(aa)); |
| 2073 | int32_t volumeGroupAidl; |
| 2074 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
Francois Gaffie | 11b6592 | 2020-09-24 16:59:08 +0200 | [diff] [blame] | 2075 | aps->getVolumeGroupFromAudioAttributes(aaAidl, fallbackOnDefault, &volumeGroupAidl))); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2076 | volumeGroup = VALUE_OR_RETURN_STATUS(aidl2legacy_int32_t_volume_group_t(volumeGroupAidl)); |
| 2077 | return OK; |
Arun Mirpuri | 11029ad | 2018-12-19 20:45:19 -0800 | [diff] [blame] | 2078 | } |
Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 2079 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2080 | status_t AudioSystem::setRttEnabled(bool enabled) { |
Eric Laurent | 6ede98f | 2019-06-11 14:50:30 -0700 | [diff] [blame] | 2081 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2082 | if (aps == 0) return PERMISSION_DENIED; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2083 | return statusTFromBinderStatus(aps->setRttEnabled(enabled)); |
Eric Laurent | 6ede98f | 2019-06-11 14:50:30 -0700 | [diff] [blame] | 2084 | } |
| 2085 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2086 | bool AudioSystem::isCallScreenModeSupported() { |
Eric Laurent | 8340e67 | 2019-11-06 11:01:08 -0800 | [diff] [blame] | 2087 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2088 | if (aps == 0) return false; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2089 | |
| 2090 | auto result = [&]() -> ConversionResult<bool> { |
| 2091 | bool retAidl; |
| 2092 | RETURN_IF_ERROR( |
| 2093 | statusTFromBinderStatus(aps->isCallScreenModeSupported(&retAidl))); |
| 2094 | return retAidl; |
| 2095 | }(); |
| 2096 | return result.value_or(false); |
Eric Laurent | 8340e67 | 2019-11-06 11:01:08 -0800 | [diff] [blame] | 2097 | } |
| 2098 | |
jiabin | 0a48893 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 2099 | status_t AudioSystem::setDevicesRoleForStrategy(product_strategy_t strategy, |
| 2100 | device_role_t role, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2101 | const AudioDeviceTypeAddrVector& devices) { |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 2102 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2103 | if (aps == 0) { |
| 2104 | return PERMISSION_DENIED; |
| 2105 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2106 | |
| 2107 | int32_t strategyAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_product_strategy_t_int32_t(strategy)); |
| 2108 | media::DeviceRole roleAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_device_role_t_DeviceRole(role)); |
| 2109 | std::vector<media::AudioDevice> devicesAidl = VALUE_OR_RETURN_STATUS( |
| 2110 | convertContainer<std::vector<media::AudioDevice>>(devices, |
| 2111 | legacy2aidl_AudioDeviceTypeAddress)); |
| 2112 | return statusTFromBinderStatus( |
| 2113 | aps->setDevicesRoleForStrategy(strategyAidl, roleAidl, devicesAidl)); |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 2114 | } |
| 2115 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2116 | status_t |
| 2117 | AudioSystem::removeDevicesRoleForStrategy(product_strategy_t strategy, device_role_t role) { |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 2118 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2119 | if (aps == 0) { |
| 2120 | return PERMISSION_DENIED; |
| 2121 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2122 | int32_t strategyAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_product_strategy_t_int32_t(strategy)); |
| 2123 | media::DeviceRole roleAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_device_role_t_DeviceRole(role)); |
| 2124 | return statusTFromBinderStatus( |
| 2125 | aps->removeDevicesRoleForStrategy(strategyAidl, roleAidl)); |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 2126 | } |
| 2127 | |
jiabin | 0a48893 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 2128 | status_t AudioSystem::getDevicesForRoleAndStrategy(product_strategy_t strategy, |
| 2129 | device_role_t role, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2130 | AudioDeviceTypeAddrVector& devices) { |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 2131 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2132 | if (aps == 0) { |
| 2133 | return PERMISSION_DENIED; |
| 2134 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2135 | int32_t strategyAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_product_strategy_t_int32_t(strategy)); |
| 2136 | media::DeviceRole roleAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_device_role_t_DeviceRole(role)); |
| 2137 | std::vector<media::AudioDevice> devicesAidl; |
| 2138 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 2139 | aps->getDevicesForRoleAndStrategy(strategyAidl, roleAidl, &devicesAidl))); |
| 2140 | devices = VALUE_OR_RETURN_STATUS( |
| 2141 | convertContainer<AudioDeviceTypeAddrVector>(devicesAidl, |
| 2142 | aidl2legacy_AudioDeviceTypeAddress)); |
| 2143 | return OK; |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 2144 | } |
| 2145 | |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2146 | status_t AudioSystem::setDevicesRoleForCapturePreset(audio_source_t audioSource, |
| 2147 | device_role_t role, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2148 | const AudioDeviceTypeAddrVector& devices) { |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2149 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2150 | if (aps == 0) { |
| 2151 | return PERMISSION_DENIED; |
| 2152 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2153 | |
| 2154 | media::AudioSourceType audioSourceAidl = VALUE_OR_RETURN_STATUS( |
| 2155 | legacy2aidl_audio_source_t_AudioSourceType(audioSource)); |
| 2156 | media::DeviceRole roleAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_device_role_t_DeviceRole(role)); |
| 2157 | std::vector<media::AudioDevice> devicesAidl = VALUE_OR_RETURN_STATUS( |
| 2158 | convertContainer<std::vector<media::AudioDevice>>(devices, |
| 2159 | legacy2aidl_AudioDeviceTypeAddress)); |
| 2160 | return statusTFromBinderStatus( |
| 2161 | aps->setDevicesRoleForCapturePreset(audioSourceAidl, roleAidl, devicesAidl)); |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | status_t AudioSystem::addDevicesRoleForCapturePreset(audio_source_t audioSource, |
| 2165 | device_role_t role, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2166 | const AudioDeviceTypeAddrVector& devices) { |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2167 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2168 | if (aps == 0) { |
| 2169 | return PERMISSION_DENIED; |
| 2170 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2171 | media::AudioSourceType audioSourceAidl = VALUE_OR_RETURN_STATUS( |
| 2172 | legacy2aidl_audio_source_t_AudioSourceType(audioSource)); |
| 2173 | media::DeviceRole roleAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_device_role_t_DeviceRole(role)); |
| 2174 | std::vector<media::AudioDevice> devicesAidl = VALUE_OR_RETURN_STATUS( |
| 2175 | convertContainer<std::vector<media::AudioDevice>>(devices, |
| 2176 | legacy2aidl_AudioDeviceTypeAddress)); |
| 2177 | return statusTFromBinderStatus( |
| 2178 | aps->addDevicesRoleForCapturePreset(audioSourceAidl, roleAidl, devicesAidl)); |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2179 | } |
| 2180 | |
| 2181 | status_t AudioSystem::removeDevicesRoleForCapturePreset( |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2182 | audio_source_t audioSource, device_role_t role, const AudioDeviceTypeAddrVector& devices) { |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2183 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2184 | if (aps == 0) { |
| 2185 | return PERMISSION_DENIED; |
| 2186 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2187 | media::AudioSourceType audioSourceAidl = VALUE_OR_RETURN_STATUS( |
| 2188 | legacy2aidl_audio_source_t_AudioSourceType(audioSource)); |
| 2189 | media::DeviceRole roleAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_device_role_t_DeviceRole(role)); |
| 2190 | std::vector<media::AudioDevice> devicesAidl = VALUE_OR_RETURN_STATUS( |
| 2191 | convertContainer<std::vector<media::AudioDevice>>(devices, |
| 2192 | legacy2aidl_AudioDeviceTypeAddress)); |
| 2193 | return statusTFromBinderStatus( |
| 2194 | aps->removeDevicesRoleForCapturePreset(audioSourceAidl, roleAidl, devicesAidl)); |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2195 | } |
| 2196 | |
| 2197 | status_t AudioSystem::clearDevicesRoleForCapturePreset(audio_source_t audioSource, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2198 | device_role_t role) { |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2199 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2200 | if (aps == 0) { |
| 2201 | return PERMISSION_DENIED; |
| 2202 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2203 | media::AudioSourceType audioSourceAidl = VALUE_OR_RETURN_STATUS( |
| 2204 | legacy2aidl_audio_source_t_AudioSourceType(audioSource)); |
| 2205 | media::DeviceRole roleAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_device_role_t_DeviceRole(role)); |
| 2206 | return statusTFromBinderStatus( |
| 2207 | aps->clearDevicesRoleForCapturePreset(audioSourceAidl, roleAidl)); |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2208 | } |
| 2209 | |
| 2210 | status_t AudioSystem::getDevicesForRoleAndCapturePreset(audio_source_t audioSource, |
| 2211 | device_role_t role, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2212 | AudioDeviceTypeAddrVector& devices) { |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2213 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2214 | if (aps == 0) { |
| 2215 | return PERMISSION_DENIED; |
| 2216 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2217 | media::AudioSourceType audioSourceAidl = VALUE_OR_RETURN_STATUS( |
| 2218 | legacy2aidl_audio_source_t_AudioSourceType(audioSource)); |
| 2219 | media::DeviceRole roleAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_device_role_t_DeviceRole(role)); |
| 2220 | std::vector<media::AudioDevice> devicesAidl; |
| 2221 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 2222 | aps->getDevicesForRoleAndCapturePreset(audioSourceAidl, roleAidl, &devicesAidl))); |
| 2223 | devices = VALUE_OR_RETURN_STATUS( |
| 2224 | convertContainer<AudioDeviceTypeAddrVector>(devicesAidl, |
| 2225 | aidl2legacy_AudioDeviceTypeAddress)); |
| 2226 | return OK; |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2227 | } |
| 2228 | |
Ytai Ben-Tsvi | 5120eda | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 2229 | class CaptureStateListenerImpl : public media::BnCaptureStateListener, |
| 2230 | public IBinder::DeathRecipient { |
| 2231 | public: |
Ytai Ben-Tsvi | d9f8283 | 2020-08-27 09:31:10 -0700 | [diff] [blame] | 2232 | CaptureStateListenerImpl( |
| 2233 | const sp<IAudioPolicyService>& aps, |
| 2234 | const sp<AudioSystem::CaptureStateListener>& listener) |
Ytai Ben-Tsvi | a46b6d3 | 2020-08-31 13:29:11 -0700 | [diff] [blame] | 2235 | : mAps(aps), mListener(listener) {} |
| 2236 | |
| 2237 | void init() { |
Ytai Ben-Tsvi | d9f8283 | 2020-08-27 09:31:10 -0700 | [diff] [blame] | 2238 | bool active; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2239 | status_t status = statusTFromBinderStatus( |
| 2240 | mAps->registerSoundTriggerCaptureStateListener(this, &active)); |
Ytai Ben-Tsvi | d9f8283 | 2020-08-27 09:31:10 -0700 | [diff] [blame] | 2241 | if (status != NO_ERROR) { |
| 2242 | mListener->onServiceDied(); |
| 2243 | return; |
| 2244 | } |
| 2245 | mListener->onStateChanged(active); |
Ytai Ben-Tsvi | a46b6d3 | 2020-08-31 13:29:11 -0700 | [diff] [blame] | 2246 | IInterface::asBinder(mAps)->linkToDeath(this); |
Ytai Ben-Tsvi | d9f8283 | 2020-08-27 09:31:10 -0700 | [diff] [blame] | 2247 | } |
| 2248 | |
Ytai Ben-Tsvi | 5120eda | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 2249 | binder::Status setCaptureState(bool active) override { |
| 2250 | Mutex::Autolock _l(gSoundTriggerCaptureStateListenerLock); |
Ytai Ben-Tsvi | d9f8283 | 2020-08-27 09:31:10 -0700 | [diff] [blame] | 2251 | mListener->onStateChanged(active); |
Ytai Ben-Tsvi | 5120eda | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 2252 | return binder::Status::ok(); |
| 2253 | } |
| 2254 | |
| 2255 | void binderDied(const wp<IBinder>&) override { |
| 2256 | Mutex::Autolock _l(gSoundTriggerCaptureStateListenerLock); |
Ytai Ben-Tsvi | d9f8283 | 2020-08-27 09:31:10 -0700 | [diff] [blame] | 2257 | mListener->onServiceDied(); |
Ytai Ben-Tsvi | 5120eda | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 2258 | gSoundTriggerCaptureStateListener = nullptr; |
| 2259 | } |
Ytai Ben-Tsvi | d9f8283 | 2020-08-27 09:31:10 -0700 | [diff] [blame] | 2260 | |
| 2261 | private: |
| 2262 | // Need this in order to keep the death receipent alive. |
| 2263 | sp<IAudioPolicyService> mAps; |
| 2264 | sp<AudioSystem::CaptureStateListener> mListener; |
Ytai Ben-Tsvi | 5120eda | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 2265 | }; |
| 2266 | |
| 2267 | status_t AudioSystem::registerSoundTriggerCaptureStateListener( |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2268 | const sp<CaptureStateListener>& listener) { |
Ytai Ben-Tsvi | d9f8283 | 2020-08-27 09:31:10 -0700 | [diff] [blame] | 2269 | LOG_ALWAYS_FATAL_IF(listener == nullptr); |
| 2270 | |
Ytai Ben-Tsvi | 5120eda | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 2271 | const sp<IAudioPolicyService>& aps = |
| 2272 | AudioSystem::get_audio_policy_service(); |
| 2273 | if (aps == 0) { |
| 2274 | return PERMISSION_DENIED; |
| 2275 | } |
| 2276 | |
Ytai Ben-Tsvi | 5120eda | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 2277 | Mutex::Autolock _l(gSoundTriggerCaptureStateListenerLock); |
Ytai Ben-Tsvi | d9f8283 | 2020-08-27 09:31:10 -0700 | [diff] [blame] | 2278 | gSoundTriggerCaptureStateListener = new CaptureStateListenerImpl(aps, listener); |
Ytai Ben-Tsvi | a46b6d3 | 2020-08-31 13:29:11 -0700 | [diff] [blame] | 2279 | gSoundTriggerCaptureStateListener->init(); |
Ytai Ben-Tsvi | 5120eda | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 2280 | |
Ytai Ben-Tsvi | 5120eda | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 2281 | return NO_ERROR; |
| 2282 | } |
| 2283 | |
jiabin | 1319f5a | 2021-03-30 22:21:24 +0000 | [diff] [blame] | 2284 | status_t AudioSystem::setVibratorInfos( |
| 2285 | const std::vector<media::AudioVibratorInfo>& vibratorInfos) { |
| 2286 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 2287 | if (af == nullptr) { |
| 2288 | return PERMISSION_DENIED; |
| 2289 | } |
| 2290 | return af->setVibratorInfos(vibratorInfos); |
| 2291 | } |
| 2292 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 2293 | // --------------------------------------------------------------------------- |
| 2294 | |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 2295 | int AudioSystem::AudioPolicyServiceClient::addAudioPortCallback( |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2296 | const sp<AudioPortCallback>& callback) { |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 2297 | Mutex::Autolock _l(mLock); |
| 2298 | for (size_t i = 0; i < mAudioPortCallbacks.size(); i++) { |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 2299 | if (mAudioPortCallbacks[i] == callback) { |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 2300 | return -1; |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 2301 | } |
| 2302 | } |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 2303 | mAudioPortCallbacks.add(callback); |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 2304 | return mAudioPortCallbacks.size(); |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 2305 | } |
| 2306 | |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 2307 | int AudioSystem::AudioPolicyServiceClient::removeAudioPortCallback( |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2308 | const sp<AudioPortCallback>& callback) { |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 2309 | Mutex::Autolock _l(mLock); |
| 2310 | size_t i; |
| 2311 | for (i = 0; i < mAudioPortCallbacks.size(); i++) { |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 2312 | if (mAudioPortCallbacks[i] == callback) { |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 2313 | break; |
| 2314 | } |
| 2315 | } |
| 2316 | if (i == mAudioPortCallbacks.size()) { |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 2317 | return -1; |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 2318 | } |
| 2319 | mAudioPortCallbacks.removeAt(i); |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 2320 | return mAudioPortCallbacks.size(); |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 2321 | } |
| 2322 | |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 2323 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2324 | Status AudioSystem::AudioPolicyServiceClient::onAudioPortListUpdate() { |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 2325 | Mutex::Autolock _l(mLock); |
| 2326 | for (size_t i = 0; i < mAudioPortCallbacks.size(); i++) { |
| 2327 | mAudioPortCallbacks[i]->onAudioPortListUpdate(); |
| 2328 | } |
Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2329 | return Status::ok(); |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 2330 | } |
| 2331 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2332 | Status AudioSystem::AudioPolicyServiceClient::onAudioPatchListUpdate() { |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 2333 | Mutex::Autolock _l(mLock); |
| 2334 | for (size_t i = 0; i < mAudioPortCallbacks.size(); i++) { |
| 2335 | mAudioPortCallbacks[i]->onAudioPatchListUpdate(); |
| 2336 | } |
Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2337 | return Status::ok(); |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 2338 | } |
| 2339 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 2340 | // ---------------------------------------------------------------------------- |
| 2341 | int AudioSystem::AudioPolicyServiceClient::addAudioVolumeGroupCallback( |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2342 | const sp<AudioVolumeGroupCallback>& callback) { |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 2343 | Mutex::Autolock _l(mLock); |
| 2344 | for (size_t i = 0; i < mAudioVolumeGroupCallback.size(); i++) { |
| 2345 | if (mAudioVolumeGroupCallback[i] == callback) { |
| 2346 | return -1; |
| 2347 | } |
| 2348 | } |
| 2349 | mAudioVolumeGroupCallback.add(callback); |
| 2350 | return mAudioVolumeGroupCallback.size(); |
| 2351 | } |
| 2352 | |
| 2353 | int AudioSystem::AudioPolicyServiceClient::removeAudioVolumeGroupCallback( |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2354 | const sp<AudioVolumeGroupCallback>& callback) { |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 2355 | Mutex::Autolock _l(mLock); |
| 2356 | size_t i; |
| 2357 | for (i = 0; i < mAudioVolumeGroupCallback.size(); i++) { |
| 2358 | if (mAudioVolumeGroupCallback[i] == callback) { |
| 2359 | break; |
| 2360 | } |
| 2361 | } |
| 2362 | if (i == mAudioVolumeGroupCallback.size()) { |
| 2363 | return -1; |
| 2364 | } |
| 2365 | mAudioVolumeGroupCallback.removeAt(i); |
| 2366 | return mAudioVolumeGroupCallback.size(); |
| 2367 | } |
| 2368 | |
Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2369 | Status AudioSystem::AudioPolicyServiceClient::onAudioVolumeGroupChanged(int32_t group, |
| 2370 | int32_t flags) { |
| 2371 | volume_group_t groupLegacy = VALUE_OR_RETURN_BINDER_STATUS( |
| 2372 | aidl2legacy_int32_t_volume_group_t(group)); |
| 2373 | int flagsLegacy = VALUE_OR_RETURN_BINDER_STATUS(convertReinterpret<int>(flags)); |
| 2374 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 2375 | Mutex::Autolock _l(mLock); |
| 2376 | for (size_t i = 0; i < mAudioVolumeGroupCallback.size(); i++) { |
Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2377 | mAudioVolumeGroupCallback[i]->onAudioVolumeGroupChanged(groupLegacy, flagsLegacy); |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 2378 | } |
Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2379 | return Status::ok(); |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 2380 | } |
| 2381 | // ---------------------------------------------------------------------------- |
| 2382 | |
Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2383 | Status AudioSystem::AudioPolicyServiceClient::onDynamicPolicyMixStateUpdate( |
| 2384 | const ::std::string& regId, int32_t state) { |
| 2385 | ALOGV("AudioPolicyServiceClient::onDynamicPolicyMixStateUpdate(%s, %d)", regId.c_str(), state); |
| 2386 | |
| 2387 | String8 regIdLegacy = VALUE_OR_RETURN_BINDER_STATUS(aidl2legacy_string_view_String8(regId)); |
| 2388 | int stateLegacy = VALUE_OR_RETURN_BINDER_STATUS(convertReinterpret<int>(state)); |
Jean-Michel Trivi | f613d42 | 2015-04-23 18:41:29 -0700 | [diff] [blame] | 2389 | dynamic_policy_callback cb = NULL; |
| 2390 | { |
| 2391 | Mutex::Autolock _l(AudioSystem::gLock); |
| 2392 | cb = gDynPolicyCallback; |
| 2393 | } |
| 2394 | |
| 2395 | if (cb != NULL) { |
Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2396 | cb(DYNAMIC_POLICY_EVENT_MIX_STATE_UPDATE, regIdLegacy, stateLegacy); |
Jean-Michel Trivi | f613d42 | 2015-04-23 18:41:29 -0700 | [diff] [blame] | 2397 | } |
Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2398 | return Status::ok(); |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 2399 | } |
| 2400 | |
Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2401 | Status AudioSystem::AudioPolicyServiceClient::onRecordingConfigurationUpdate( |
| 2402 | int32_t event, |
| 2403 | const media::RecordClientInfo& clientInfo, |
| 2404 | const media::AudioConfigBase& clientConfig, |
| 2405 | const std::vector<media::EffectDescriptor>& clientEffects, |
| 2406 | const media::AudioConfigBase& deviceConfig, |
| 2407 | const std::vector<media::EffectDescriptor>& effects, |
| 2408 | int32_t patchHandle, |
| 2409 | media::AudioSourceType source) { |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 2410 | record_config_callback cb = NULL; |
| 2411 | { |
| 2412 | Mutex::Autolock _l(AudioSystem::gLock); |
| 2413 | cb = gRecordConfigCallback; |
| 2414 | } |
| 2415 | |
| 2416 | if (cb != NULL) { |
Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2417 | int eventLegacy = VALUE_OR_RETURN_BINDER_STATUS(convertReinterpret<int>(event)); |
| 2418 | record_client_info_t clientInfoLegacy = VALUE_OR_RETURN_BINDER_STATUS( |
| 2419 | aidl2legacy_RecordClientInfo_record_client_info_t(clientInfo)); |
| 2420 | audio_config_base_t clientConfigLegacy = VALUE_OR_RETURN_BINDER_STATUS( |
| 2421 | aidl2legacy_AudioConfigBase_audio_config_base_t(clientConfig)); |
| 2422 | std::vector<effect_descriptor_t> clientEffectsLegacy = VALUE_OR_RETURN_BINDER_STATUS( |
| 2423 | convertContainer<std::vector<effect_descriptor_t>>( |
| 2424 | clientEffects, |
| 2425 | aidl2legacy_EffectDescriptor_effect_descriptor_t)); |
| 2426 | audio_config_base_t deviceConfigLegacy = VALUE_OR_RETURN_BINDER_STATUS( |
| 2427 | aidl2legacy_AudioConfigBase_audio_config_base_t(deviceConfig)); |
| 2428 | std::vector<effect_descriptor_t> effectsLegacy = VALUE_OR_RETURN_BINDER_STATUS( |
| 2429 | convertContainer<std::vector<effect_descriptor_t>>( |
| 2430 | effects, |
| 2431 | aidl2legacy_EffectDescriptor_effect_descriptor_t)); |
| 2432 | audio_patch_handle_t patchHandleLegacy = VALUE_OR_RETURN_BINDER_STATUS( |
| 2433 | aidl2legacy_int32_t_audio_patch_handle_t(patchHandle)); |
| 2434 | audio_source_t sourceLegacy = VALUE_OR_RETURN_BINDER_STATUS( |
| 2435 | aidl2legacy_AudioSourceType_audio_source_t(source)); |
| 2436 | cb(eventLegacy, &clientInfoLegacy, &clientConfigLegacy, clientEffectsLegacy, |
| 2437 | &deviceConfigLegacy, effectsLegacy, patchHandleLegacy, sourceLegacy); |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 2438 | } |
Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2439 | return Status::ok(); |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 2440 | } |
| 2441 | |
Jean-Michel Trivi | 9a6b9ad | 2020-10-22 16:46:43 -0700 | [diff] [blame] | 2442 | Status AudioSystem::AudioPolicyServiceClient::onRoutingUpdated() { |
| 2443 | routing_callback cb = NULL; |
| 2444 | { |
| 2445 | Mutex::Autolock _l(AudioSystem::gLock); |
| 2446 | cb = gRoutingCallback; |
| 2447 | } |
| 2448 | |
| 2449 | if (cb != NULL) { |
| 2450 | cb(); |
| 2451 | } |
| 2452 | return Status::ok(); |
| 2453 | } |
| 2454 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2455 | void AudioSystem::AudioPolicyServiceClient::binderDied(const wp<IBinder>& who __unused) { |
Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 2456 | { |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 2457 | Mutex::Autolock _l(mLock); |
| 2458 | for (size_t i = 0; i < mAudioPortCallbacks.size(); i++) { |
| 2459 | mAudioPortCallbacks[i]->onServiceDied(); |
Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 2460 | } |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 2461 | for (size_t i = 0; i < mAudioVolumeGroupCallback.size(); i++) { |
| 2462 | mAudioVolumeGroupCallback[i]->onServiceDied(); |
| 2463 | } |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 2464 | } |
Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 2465 | { |
| 2466 | Mutex::Autolock _l(gLockAPS); |
| 2467 | AudioSystem::gAudioPolicyService.clear(); |
| 2468 | } |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 2469 | |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 2470 | ALOGW("AudioPolicyService server died!"); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 2471 | } |
| 2472 | |
Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2473 | ConversionResult<record_client_info_t> |
| 2474 | aidl2legacy_RecordClientInfo_record_client_info_t(const media::RecordClientInfo& aidl) { |
| 2475 | record_client_info_t legacy; |
| 2476 | legacy.riid = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_unique_id_t(aidl.riid)); |
| 2477 | legacy.uid = VALUE_OR_RETURN(aidl2legacy_int32_t_uid_t(aidl.uid)); |
| 2478 | legacy.session = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_session_t(aidl.session)); |
| 2479 | legacy.source = VALUE_OR_RETURN(aidl2legacy_AudioSourceType_audio_source_t(aidl.source)); |
| 2480 | legacy.port_id = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_port_handle_t(aidl.portId)); |
| 2481 | legacy.silenced = aidl.silenced; |
| 2482 | return legacy; |
| 2483 | } |
| 2484 | |
| 2485 | ConversionResult<media::RecordClientInfo> |
| 2486 | legacy2aidl_record_client_info_t_RecordClientInfo(const record_client_info_t& legacy) { |
| 2487 | media::RecordClientInfo aidl; |
| 2488 | aidl.riid = VALUE_OR_RETURN(legacy2aidl_audio_unique_id_t_int32_t(legacy.riid)); |
| 2489 | aidl.uid = VALUE_OR_RETURN(legacy2aidl_uid_t_int32_t(legacy.uid)); |
| 2490 | aidl.session = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(legacy.session)); |
| 2491 | aidl.source = VALUE_OR_RETURN(legacy2aidl_audio_source_t_AudioSourceType(legacy.source)); |
| 2492 | aidl.portId = VALUE_OR_RETURN(legacy2aidl_audio_port_handle_t_int32_t(legacy.port_id)); |
| 2493 | aidl.silenced = legacy.silenced; |
| 2494 | return aidl; |
| 2495 | } |
| 2496 | |
Glenn Kasten | 40bc906 | 2015-03-20 09:09:33 -0700 | [diff] [blame] | 2497 | } // namespace android |