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