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