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