Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 1 | /* |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2 | ** |
| 3 | ** Copyright 2007, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #define LOG_TAG "IAudioFlinger" |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 19 | //#define LOG_NDEBUG 0 |
Jiabin Huang | ebe6410 | 2021-09-07 20:01:07 +0000 | [diff] [blame] | 20 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | #include <utils/Log.h> |
| 22 | |
| 23 | #include <stdint.h> |
| 24 | #include <sys/types.h> |
| 25 | |
Eric Laurent | b1cc36b | 2017-12-11 12:14:16 -0800 | [diff] [blame] | 26 | #include <binder/IPCThreadState.h> |
Mathias Agopian | 7562408 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 27 | #include <binder/Parcel.h> |
Steven Moreland | 25a9e55 | 2017-04-17 14:30:39 -0700 | [diff] [blame] | 28 | #include "IAudioFlinger.h" |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | |
| 30 | namespace android { |
| 31 | |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 32 | using aidl_utils::statusTFromBinderStatus; |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 33 | using binder::Status; |
Mikhail Naganov | 57bd06f | 2021-08-10 16:41:54 -0700 | [diff] [blame] | 34 | using media::audio::common::AudioChannelLayout; |
| 35 | using media::audio::common::AudioFormatDescription; |
jiabin | e99d088 | 2021-09-17 05:21:25 +0000 | [diff] [blame] | 36 | using media::audio::common::AudioMMapPolicyInfo; |
| 37 | using media::audio::common::AudioMMapPolicyType; |
Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 38 | using media::audio::common::AudioMode; |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 39 | using media::audio::common::AudioStreamType; |
Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 40 | using media::audio::common::AudioUuid; |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 41 | |
Eric Laurent | f75c2fe | 2015-04-02 13:49:15 -0700 | [diff] [blame] | 42 | #define MAX_ITEMS_PER_LIST 1024 |
| 43 | |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 44 | #define VALUE_OR_RETURN_BINDER(x) \ |
| 45 | ({ \ |
| 46 | auto _tmp = (x); \ |
| 47 | if (!_tmp.ok()) return Status::fromStatusT(_tmp.error()); \ |
| 48 | std::move(_tmp.value()); \ |
| 49 | }) |
| 50 | |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 51 | #define RETURN_BINDER_IF_ERROR(x) \ |
| 52 | { \ |
| 53 | auto _tmp = (x); \ |
| 54 | if (_tmp != OK) return Status::fromStatusT(_tmp); \ |
| 55 | } |
| 56 | |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 57 | ConversionResult<media::CreateTrackRequest> IAudioFlinger::CreateTrackInput::toAidl() const { |
| 58 | media::CreateTrackRequest aidl; |
| 59 | aidl.attr = VALUE_OR_RETURN(legacy2aidl_audio_attributes_t_AudioAttributesInternal(attr)); |
Mikhail Naganov | de3fa18 | 2021-07-30 15:06:42 -0700 | [diff] [blame] | 60 | // Do not be mislead by 'Input'--this is an input to 'createTrack', which creates output tracks. |
| 61 | aidl.config = VALUE_OR_RETURN(legacy2aidl_audio_config_t_AudioConfig( |
| 62 | config, false /*isInput*/)); |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 63 | aidl.clientInfo = VALUE_OR_RETURN(legacy2aidl_AudioClient_AudioClient(clientInfo)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 64 | aidl.sharedBuffer = VALUE_OR_RETURN(legacy2aidl_NullableIMemory_SharedFileRegion(sharedBuffer)); |
| 65 | aidl.notificationsPerBuffer = VALUE_OR_RETURN(convertIntegral<int32_t>(notificationsPerBuffer)); |
| 66 | aidl.speed = speed; |
| 67 | aidl.audioTrackCallback = audioTrackCallback; |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 68 | aidl.flags = VALUE_OR_RETURN(legacy2aidl_audio_output_flags_t_int32_t_mask(flags)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 69 | aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(frameCount)); |
| 70 | aidl.notificationFrameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(notificationFrameCount)); |
| 71 | aidl.selectedDeviceId = VALUE_OR_RETURN( |
| 72 | legacy2aidl_audio_port_handle_t_int32_t(selectedDeviceId)); |
| 73 | aidl.sessionId = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(sessionId)); |
| 74 | return aidl; |
| 75 | } |
| 76 | |
| 77 | ConversionResult<IAudioFlinger::CreateTrackInput> |
| 78 | IAudioFlinger::CreateTrackInput::fromAidl(const media::CreateTrackRequest& aidl) { |
| 79 | IAudioFlinger::CreateTrackInput legacy; |
| 80 | legacy.attr = VALUE_OR_RETURN(aidl2legacy_AudioAttributesInternal_audio_attributes_t(aidl.attr)); |
Mikhail Naganov | de3fa18 | 2021-07-30 15:06:42 -0700 | [diff] [blame] | 81 | // Do not be mislead by 'Input'--this is an input to 'createTrack', which creates output tracks. |
| 82 | legacy.config = VALUE_OR_RETURN( |
| 83 | aidl2legacy_AudioConfig_audio_config_t(aidl.config, false /*isInput*/)); |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 84 | legacy.clientInfo = VALUE_OR_RETURN(aidl2legacy_AudioClient_AudioClient(aidl.clientInfo)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 85 | legacy.sharedBuffer = VALUE_OR_RETURN(aidl2legacy_NullableSharedFileRegion_IMemory(aidl.sharedBuffer)); |
| 86 | legacy.notificationsPerBuffer = VALUE_OR_RETURN( |
| 87 | convertIntegral<uint32_t>(aidl.notificationsPerBuffer)); |
| 88 | legacy.speed = aidl.speed; |
| 89 | legacy.audioTrackCallback = aidl.audioTrackCallback; |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 90 | legacy.flags = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_output_flags_t_mask(aidl.flags)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 91 | legacy.frameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCount)); |
| 92 | legacy.notificationFrameCount = VALUE_OR_RETURN( |
| 93 | convertIntegral<size_t>(aidl.notificationFrameCount)); |
| 94 | legacy.selectedDeviceId = VALUE_OR_RETURN( |
| 95 | aidl2legacy_int32_t_audio_port_handle_t(aidl.selectedDeviceId)); |
| 96 | legacy.sessionId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_session_t(aidl.sessionId)); |
| 97 | return legacy; |
| 98 | } |
| 99 | |
| 100 | ConversionResult<media::CreateTrackResponse> |
| 101 | IAudioFlinger::CreateTrackOutput::toAidl() const { |
| 102 | media::CreateTrackResponse aidl; |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 103 | aidl.flags = VALUE_OR_RETURN(legacy2aidl_audio_output_flags_t_int32_t_mask(flags)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 104 | aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(frameCount)); |
| 105 | aidl.notificationFrameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(notificationFrameCount)); |
| 106 | aidl.selectedDeviceId = VALUE_OR_RETURN( |
| 107 | legacy2aidl_audio_port_handle_t_int32_t(selectedDeviceId)); |
| 108 | aidl.sessionId = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(sessionId)); |
| 109 | aidl.sampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(sampleRate)); |
Andy Hung | a2159aa | 2021-07-20 13:01:52 -0700 | [diff] [blame] | 110 | aidl.streamType = VALUE_OR_RETURN( |
| 111 | legacy2aidl_audio_stream_type_t_AudioStreamType(streamType)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 112 | aidl.afFrameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(afFrameCount)); |
| 113 | aidl.afSampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(afSampleRate)); |
| 114 | aidl.afLatencyMs = VALUE_OR_RETURN(convertIntegral<int32_t>(afLatencyMs)); |
| 115 | aidl.outputId = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(outputId)); |
| 116 | aidl.portId = VALUE_OR_RETURN(legacy2aidl_audio_port_handle_t_int32_t(portId)); |
Ytai Ben-Tsvi | 16d8761 | 2020-11-03 16:32:36 -0800 | [diff] [blame] | 117 | aidl.audioTrack = audioTrack; |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 118 | return aidl; |
| 119 | } |
| 120 | |
| 121 | ConversionResult<IAudioFlinger::CreateTrackOutput> |
| 122 | IAudioFlinger::CreateTrackOutput::fromAidl( |
| 123 | const media::CreateTrackResponse& aidl) { |
| 124 | IAudioFlinger::CreateTrackOutput legacy; |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 125 | legacy.flags = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_output_flags_t_mask(aidl.flags)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 126 | legacy.frameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCount)); |
| 127 | legacy.notificationFrameCount = VALUE_OR_RETURN( |
| 128 | convertIntegral<size_t>(aidl.notificationFrameCount)); |
| 129 | legacy.selectedDeviceId = VALUE_OR_RETURN( |
| 130 | aidl2legacy_int32_t_audio_port_handle_t(aidl.selectedDeviceId)); |
| 131 | legacy.sessionId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_session_t(aidl.sessionId)); |
| 132 | legacy.sampleRate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.sampleRate)); |
Andy Hung | a2159aa | 2021-07-20 13:01:52 -0700 | [diff] [blame] | 133 | legacy.streamType = VALUE_OR_RETURN( |
| 134 | aidl2legacy_AudioStreamType_audio_stream_type_t(aidl.streamType)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 135 | legacy.afFrameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.afFrameCount)); |
| 136 | legacy.afSampleRate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.afSampleRate)); |
| 137 | legacy.afLatencyMs = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.afLatencyMs)); |
| 138 | legacy.outputId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_io_handle_t(aidl.outputId)); |
| 139 | legacy.portId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_port_handle_t(aidl.portId)); |
Ytai Ben-Tsvi | 16d8761 | 2020-11-03 16:32:36 -0800 | [diff] [blame] | 140 | legacy.audioTrack = aidl.audioTrack; |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 141 | return legacy; |
| 142 | } |
| 143 | |
| 144 | ConversionResult<media::CreateRecordRequest> |
| 145 | IAudioFlinger::CreateRecordInput::toAidl() const { |
| 146 | media::CreateRecordRequest aidl; |
| 147 | aidl.attr = VALUE_OR_RETURN(legacy2aidl_audio_attributes_t_AudioAttributesInternal(attr)); |
Mikhail Naganov | de3fa18 | 2021-07-30 15:06:42 -0700 | [diff] [blame] | 148 | aidl.config = VALUE_OR_RETURN( |
| 149 | legacy2aidl_audio_config_base_t_AudioConfigBase(config, true /*isInput*/)); |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 150 | aidl.clientInfo = VALUE_OR_RETURN(legacy2aidl_AudioClient_AudioClient(clientInfo)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 151 | aidl.riid = VALUE_OR_RETURN(legacy2aidl_audio_unique_id_t_int32_t(riid)); |
Eric Laurent | ec376dc | 2021-04-08 20:41:22 +0200 | [diff] [blame] | 152 | aidl.maxSharedAudioHistoryMs = VALUE_OR_RETURN( |
| 153 | convertIntegral<int32_t>(maxSharedAudioHistoryMs)); |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 154 | aidl.flags = VALUE_OR_RETURN(legacy2aidl_audio_input_flags_t_int32_t_mask(flags)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 155 | aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(frameCount)); |
| 156 | aidl.notificationFrameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(notificationFrameCount)); |
| 157 | aidl.selectedDeviceId = VALUE_OR_RETURN( |
| 158 | legacy2aidl_audio_port_handle_t_int32_t(selectedDeviceId)); |
| 159 | aidl.sessionId = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(sessionId)); |
| 160 | return aidl; |
| 161 | } |
| 162 | |
| 163 | ConversionResult<IAudioFlinger::CreateRecordInput> |
| 164 | IAudioFlinger::CreateRecordInput::fromAidl( |
| 165 | const media::CreateRecordRequest& aidl) { |
| 166 | IAudioFlinger::CreateRecordInput legacy; |
Eric Laurent | ec376dc | 2021-04-08 20:41:22 +0200 | [diff] [blame] | 167 | legacy.attr = VALUE_OR_RETURN( |
| 168 | aidl2legacy_AudioAttributesInternal_audio_attributes_t(aidl.attr)); |
Mikhail Naganov | de3fa18 | 2021-07-30 15:06:42 -0700 | [diff] [blame] | 169 | legacy.config = VALUE_OR_RETURN( |
| 170 | aidl2legacy_AudioConfigBase_audio_config_base_t(aidl.config, true /*isInput*/)); |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 171 | legacy.clientInfo = VALUE_OR_RETURN(aidl2legacy_AudioClient_AudioClient(aidl.clientInfo)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 172 | legacy.riid = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_unique_id_t(aidl.riid)); |
Eric Laurent | ec376dc | 2021-04-08 20:41:22 +0200 | [diff] [blame] | 173 | legacy.maxSharedAudioHistoryMs = VALUE_OR_RETURN( |
| 174 | convertIntegral<int32_t>(aidl.maxSharedAudioHistoryMs)); |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 175 | legacy.flags = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_input_flags_t_mask(aidl.flags)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 176 | legacy.frameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCount)); |
| 177 | legacy.notificationFrameCount = VALUE_OR_RETURN( |
| 178 | convertIntegral<size_t>(aidl.notificationFrameCount)); |
| 179 | legacy.selectedDeviceId = VALUE_OR_RETURN( |
| 180 | aidl2legacy_int32_t_audio_port_handle_t(aidl.selectedDeviceId)); |
| 181 | legacy.sessionId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_session_t(aidl.sessionId)); |
| 182 | return legacy; |
| 183 | } |
| 184 | |
| 185 | ConversionResult<media::CreateRecordResponse> |
| 186 | IAudioFlinger::CreateRecordOutput::toAidl() const { |
| 187 | media::CreateRecordResponse aidl; |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 188 | aidl.flags = VALUE_OR_RETURN(legacy2aidl_audio_input_flags_t_int32_t_mask(flags)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 189 | aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(frameCount)); |
| 190 | aidl.notificationFrameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(notificationFrameCount)); |
| 191 | aidl.selectedDeviceId = VALUE_OR_RETURN( |
| 192 | legacy2aidl_audio_port_handle_t_int32_t(selectedDeviceId)); |
| 193 | aidl.sessionId = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(sessionId)); |
| 194 | aidl.sampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(sampleRate)); |
| 195 | aidl.inputId = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(inputId)); |
| 196 | aidl.cblk = VALUE_OR_RETURN(legacy2aidl_NullableIMemory_SharedFileRegion(cblk)); |
| 197 | aidl.buffers = VALUE_OR_RETURN(legacy2aidl_NullableIMemory_SharedFileRegion(buffers)); |
| 198 | aidl.portId = VALUE_OR_RETURN(legacy2aidl_audio_port_handle_t_int32_t(portId)); |
Ytai Ben-Tsvi | 16d8761 | 2020-11-03 16:32:36 -0800 | [diff] [blame] | 199 | aidl.audioRecord = audioRecord; |
jiabin | b00edc3 | 2021-08-16 16:27:54 +0000 | [diff] [blame] | 200 | aidl.serverConfig = VALUE_OR_RETURN( |
| 201 | legacy2aidl_audio_config_base_t_AudioConfigBase(serverConfig, true /*isInput*/)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 202 | return aidl; |
| 203 | } |
| 204 | |
| 205 | ConversionResult<IAudioFlinger::CreateRecordOutput> |
| 206 | IAudioFlinger::CreateRecordOutput::fromAidl( |
| 207 | const media::CreateRecordResponse& aidl) { |
| 208 | IAudioFlinger::CreateRecordOutput legacy; |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 209 | legacy.flags = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_input_flags_t_mask(aidl.flags)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 210 | legacy.frameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCount)); |
| 211 | legacy.notificationFrameCount = VALUE_OR_RETURN( |
| 212 | convertIntegral<size_t>(aidl.notificationFrameCount)); |
| 213 | legacy.selectedDeviceId = VALUE_OR_RETURN( |
| 214 | aidl2legacy_int32_t_audio_port_handle_t(aidl.selectedDeviceId)); |
| 215 | legacy.sessionId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_session_t(aidl.sessionId)); |
| 216 | legacy.sampleRate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.sampleRate)); |
| 217 | legacy.inputId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_io_handle_t(aidl.inputId)); |
| 218 | legacy.cblk = VALUE_OR_RETURN(aidl2legacy_NullableSharedFileRegion_IMemory(aidl.cblk)); |
| 219 | legacy.buffers = VALUE_OR_RETURN(aidl2legacy_NullableSharedFileRegion_IMemory(aidl.buffers)); |
| 220 | legacy.portId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_port_handle_t(aidl.portId)); |
Ytai Ben-Tsvi | 16d8761 | 2020-11-03 16:32:36 -0800 | [diff] [blame] | 221 | legacy.audioRecord = aidl.audioRecord; |
jiabin | b00edc3 | 2021-08-16 16:27:54 +0000 | [diff] [blame] | 222 | legacy.serverConfig = VALUE_OR_RETURN( |
| 223 | aidl2legacy_AudioConfigBase_audio_config_base_t(aidl.serverConfig, true /*isInput*/)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 224 | return legacy; |
| 225 | } |
Eric Laurent | 42896a0 | 2019-09-27 15:40:33 -0700 | [diff] [blame] | 226 | |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 227 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 228 | // AudioFlingerClientAdapter |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 229 | |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 230 | AudioFlingerClientAdapter::AudioFlingerClientAdapter( |
| 231 | const sp<media::IAudioFlingerService> delegate) : mDelegate(delegate) {} |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 232 | |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 233 | status_t AudioFlingerClientAdapter::createTrack(const media::CreateTrackRequest& input, |
| 234 | media::CreateTrackResponse& output) { |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 235 | return statusTFromBinderStatus(mDelegate->createTrack(input, &output)); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 236 | } |
| 237 | |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 238 | status_t AudioFlingerClientAdapter::createRecord(const media::CreateRecordRequest& input, |
| 239 | media::CreateRecordResponse& output) { |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 240 | return statusTFromBinderStatus(mDelegate->createRecord(input, &output)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | uint32_t AudioFlingerClientAdapter::sampleRate(audio_io_handle_t ioHandle) const { |
| 244 | auto result = [&]() -> ConversionResult<uint32_t> { |
| 245 | int32_t ioHandleAidl = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(ioHandle)); |
| 246 | int32_t aidlRet; |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 247 | RETURN_IF_ERROR(statusTFromBinderStatus(mDelegate->sampleRate(ioHandleAidl, &aidlRet))); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 248 | return convertIntegral<uint32_t>(aidlRet); |
| 249 | }(); |
| 250 | // Failure is ignored. |
| 251 | return result.value_or(0); |
| 252 | } |
| 253 | |
| 254 | audio_format_t AudioFlingerClientAdapter::format(audio_io_handle_t output) const { |
| 255 | auto result = [&]() -> ConversionResult<audio_format_t> { |
| 256 | int32_t outputAidl = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(output)); |
Mikhail Naganov | 57bd06f | 2021-08-10 16:41:54 -0700 | [diff] [blame] | 257 | AudioFormatDescription aidlRet; |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 258 | RETURN_IF_ERROR(statusTFromBinderStatus(mDelegate->format(outputAidl, &aidlRet))); |
Mikhail Naganov | b60bd1b | 2021-07-15 17:31:43 -0700 | [diff] [blame] | 259 | return aidl2legacy_AudioFormatDescription_audio_format_t(aidlRet); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 260 | }(); |
| 261 | return result.value_or(AUDIO_FORMAT_INVALID); |
| 262 | } |
| 263 | |
| 264 | size_t AudioFlingerClientAdapter::frameCount(audio_io_handle_t ioHandle) const { |
| 265 | auto result = [&]() -> ConversionResult<size_t> { |
| 266 | int32_t ioHandleAidl = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(ioHandle)); |
| 267 | int64_t aidlRet; |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 268 | RETURN_IF_ERROR(statusTFromBinderStatus(mDelegate->frameCount(ioHandleAidl, &aidlRet))); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 269 | return convertIntegral<size_t>(aidlRet); |
| 270 | }(); |
| 271 | // Failure is ignored. |
| 272 | return result.value_or(0); |
| 273 | } |
| 274 | |
| 275 | uint32_t AudioFlingerClientAdapter::latency(audio_io_handle_t output) const { |
| 276 | auto result = [&]() -> ConversionResult<uint32_t> { |
| 277 | int32_t outputAidl = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(output)); |
| 278 | int32_t aidlRet; |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 279 | RETURN_IF_ERROR(statusTFromBinderStatus(mDelegate->latency(outputAidl, &aidlRet))); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 280 | return convertIntegral<uint32_t>(aidlRet); |
| 281 | }(); |
| 282 | // Failure is ignored. |
| 283 | return result.value_or(0); |
| 284 | } |
| 285 | |
| 286 | status_t AudioFlingerClientAdapter::setMasterVolume(float value) { |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 287 | return statusTFromBinderStatus(mDelegate->setMasterVolume(value)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | status_t AudioFlingerClientAdapter::setMasterMute(bool muted) { |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 291 | return statusTFromBinderStatus(mDelegate->setMasterMute(muted)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | float AudioFlingerClientAdapter::masterVolume() const { |
| 295 | auto result = [&]() -> ConversionResult<float> { |
| 296 | float aidlRet; |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 297 | RETURN_IF_ERROR(statusTFromBinderStatus(mDelegate->masterVolume(&aidlRet))); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 298 | return aidlRet; |
| 299 | }(); |
| 300 | // Failure is ignored. |
| 301 | return result.value_or(0.f); |
| 302 | } |
| 303 | |
| 304 | bool AudioFlingerClientAdapter::masterMute() const { |
| 305 | auto result = [&]() -> ConversionResult<bool> { |
| 306 | bool aidlRet; |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 307 | RETURN_IF_ERROR(statusTFromBinderStatus(mDelegate->masterMute(&aidlRet))); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 308 | return aidlRet; |
| 309 | }(); |
| 310 | // Failure is ignored. |
| 311 | return result.value_or(false); |
| 312 | } |
| 313 | |
| 314 | status_t AudioFlingerClientAdapter::setMasterBalance(float balance) { |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 315 | return statusTFromBinderStatus(mDelegate->setMasterBalance(balance)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | status_t AudioFlingerClientAdapter::getMasterBalance(float* balance) const{ |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 319 | return statusTFromBinderStatus(mDelegate->getMasterBalance(balance)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | status_t AudioFlingerClientAdapter::setStreamVolume(audio_stream_type_t stream, float value, |
| 323 | audio_io_handle_t output) { |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 324 | AudioStreamType streamAidl = VALUE_OR_RETURN_STATUS( |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 325 | legacy2aidl_audio_stream_type_t_AudioStreamType(stream)); |
| 326 | int32_t outputAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(output)); |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 327 | return statusTFromBinderStatus(mDelegate->setStreamVolume(streamAidl, value, outputAidl)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | status_t AudioFlingerClientAdapter::setStreamMute(audio_stream_type_t stream, bool muted) { |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 331 | AudioStreamType streamAidl = VALUE_OR_RETURN_STATUS( |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 332 | legacy2aidl_audio_stream_type_t_AudioStreamType(stream)); |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 333 | return statusTFromBinderStatus(mDelegate->setStreamMute(streamAidl, muted)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | float AudioFlingerClientAdapter::streamVolume(audio_stream_type_t stream, |
| 337 | audio_io_handle_t output) const { |
| 338 | auto result = [&]() -> ConversionResult<float> { |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 339 | AudioStreamType streamAidl = VALUE_OR_RETURN_STATUS( |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 340 | legacy2aidl_audio_stream_type_t_AudioStreamType(stream)); |
| 341 | int32_t outputAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(output)); |
| 342 | float aidlRet; |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 343 | RETURN_IF_ERROR(statusTFromBinderStatus( |
| 344 | mDelegate->streamVolume(streamAidl, outputAidl, &aidlRet))); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 345 | return aidlRet; |
| 346 | }(); |
| 347 | // Failure is ignored. |
| 348 | return result.value_or(0.f); |
| 349 | } |
| 350 | |
| 351 | bool AudioFlingerClientAdapter::streamMute(audio_stream_type_t stream) const { |
| 352 | auto result = [&]() -> ConversionResult<bool> { |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 353 | AudioStreamType streamAidl = VALUE_OR_RETURN_STATUS( |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 354 | legacy2aidl_audio_stream_type_t_AudioStreamType(stream)); |
| 355 | bool aidlRet; |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 356 | RETURN_IF_ERROR(statusTFromBinderStatus( |
| 357 | mDelegate->streamMute(streamAidl, &aidlRet))); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 358 | return aidlRet; |
| 359 | }(); |
| 360 | // Failure is ignored. |
| 361 | return result.value_or(false); |
| 362 | } |
| 363 | |
| 364 | status_t AudioFlingerClientAdapter::setMode(audio_mode_t mode) { |
Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 365 | AudioMode modeAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_mode_t_AudioMode(mode)); |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 366 | return statusTFromBinderStatus(mDelegate->setMode(modeAidl)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | status_t AudioFlingerClientAdapter::setMicMute(bool state) { |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 370 | return statusTFromBinderStatus(mDelegate->setMicMute(state)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | bool AudioFlingerClientAdapter::getMicMute() const { |
| 374 | auto result = [&]() -> ConversionResult<bool> { |
| 375 | bool aidlRet; |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 376 | RETURN_IF_ERROR(statusTFromBinderStatus( |
| 377 | mDelegate->getMicMute(&aidlRet))); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 378 | return aidlRet; |
| 379 | }(); |
| 380 | // Failure is ignored. |
| 381 | return result.value_or(false); |
| 382 | } |
| 383 | |
| 384 | void AudioFlingerClientAdapter::setRecordSilenced(audio_port_handle_t portId, bool silenced) { |
| 385 | auto result = [&]() -> status_t { |
| 386 | int32_t portIdAidl = VALUE_OR_RETURN_STATUS( |
| 387 | legacy2aidl_audio_port_handle_t_int32_t(portId)); |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 388 | return statusTFromBinderStatus(mDelegate->setRecordSilenced(portIdAidl, silenced)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 389 | }(); |
| 390 | // Failure is ignored. |
| 391 | (void) result; |
| 392 | } |
| 393 | |
| 394 | status_t AudioFlingerClientAdapter::setParameters(audio_io_handle_t ioHandle, |
| 395 | const String8& keyValuePairs) { |
| 396 | int32_t ioHandleAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(ioHandle)); |
| 397 | std::string keyValuePairsAidl = VALUE_OR_RETURN_STATUS( |
| 398 | legacy2aidl_String8_string(keyValuePairs)); |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 399 | return statusTFromBinderStatus(mDelegate->setParameters(ioHandleAidl, keyValuePairsAidl)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | String8 AudioFlingerClientAdapter::getParameters(audio_io_handle_t ioHandle, const String8& keys) |
| 403 | const { |
| 404 | auto result = [&]() -> ConversionResult<String8> { |
| 405 | int32_t ioHandleAidl = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(ioHandle)); |
| 406 | std::string keysAidl = VALUE_OR_RETURN(legacy2aidl_String8_string(keys)); |
| 407 | std::string aidlRet; |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 408 | RETURN_IF_ERROR(statusTFromBinderStatus( |
| 409 | mDelegate->getParameters(ioHandleAidl, keysAidl, &aidlRet))); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 410 | return aidl2legacy_string_view_String8(aidlRet); |
| 411 | }(); |
| 412 | // Failure is ignored. |
| 413 | return result.value_or(String8()); |
| 414 | } |
| 415 | |
| 416 | void AudioFlingerClientAdapter::registerClient(const sp<media::IAudioFlingerClient>& client) { |
| 417 | mDelegate->registerClient(client); |
| 418 | // Failure is ignored. |
| 419 | } |
| 420 | |
| 421 | size_t AudioFlingerClientAdapter::getInputBufferSize(uint32_t sampleRate, audio_format_t format, |
| 422 | audio_channel_mask_t channelMask) const { |
| 423 | auto result = [&]() -> ConversionResult<size_t> { |
| 424 | int32_t sampleRateAidl = VALUE_OR_RETURN(convertIntegral<int32_t>(sampleRate)); |
Mikhail Naganov | 57bd06f | 2021-08-10 16:41:54 -0700 | [diff] [blame] | 425 | AudioFormatDescription formatAidl = VALUE_OR_RETURN( |
Mikhail Naganov | b60bd1b | 2021-07-15 17:31:43 -0700 | [diff] [blame] | 426 | legacy2aidl_audio_format_t_AudioFormatDescription(format)); |
Mikhail Naganov | 57bd06f | 2021-08-10 16:41:54 -0700 | [diff] [blame] | 427 | AudioChannelLayout channelMaskAidl = VALUE_OR_RETURN( |
Mikhail Naganov | de3fa18 | 2021-07-30 15:06:42 -0700 | [diff] [blame] | 428 | legacy2aidl_audio_channel_mask_t_AudioChannelLayout(channelMask, true /*isInput*/)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 429 | int64_t aidlRet; |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 430 | RETURN_IF_ERROR(statusTFromBinderStatus( |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 431 | mDelegate->getInputBufferSize(sampleRateAidl, formatAidl, channelMaskAidl, |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 432 | &aidlRet))); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 433 | return convertIntegral<size_t>(aidlRet); |
| 434 | }(); |
| 435 | // Failure is ignored. |
| 436 | return result.value_or(0); |
| 437 | } |
| 438 | |
| 439 | status_t AudioFlingerClientAdapter::openOutput(const media::OpenOutputRequest& request, |
| 440 | media::OpenOutputResponse* response) { |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 441 | return statusTFromBinderStatus(mDelegate->openOutput(request, response)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | audio_io_handle_t AudioFlingerClientAdapter::openDuplicateOutput(audio_io_handle_t output1, |
| 445 | audio_io_handle_t output2) { |
| 446 | auto result = [&]() -> ConversionResult<audio_io_handle_t> { |
| 447 | int32_t output1Aidl = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(output1)); |
| 448 | int32_t output2Aidl = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(output2)); |
| 449 | int32_t aidlRet; |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 450 | RETURN_IF_ERROR(statusTFromBinderStatus( |
| 451 | mDelegate->openDuplicateOutput(output1Aidl, output2Aidl, &aidlRet))); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 452 | return aidl2legacy_int32_t_audio_io_handle_t(aidlRet); |
| 453 | }(); |
| 454 | // Failure is ignored. |
| 455 | return result.value_or(0); |
| 456 | } |
| 457 | |
| 458 | status_t AudioFlingerClientAdapter::closeOutput(audio_io_handle_t output) { |
| 459 | int32_t outputAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(output)); |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 460 | return statusTFromBinderStatus(mDelegate->closeOutput(outputAidl)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | status_t AudioFlingerClientAdapter::suspendOutput(audio_io_handle_t output) { |
| 464 | int32_t outputAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(output)); |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 465 | return statusTFromBinderStatus(mDelegate->suspendOutput(outputAidl)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | status_t AudioFlingerClientAdapter::restoreOutput(audio_io_handle_t output) { |
| 469 | int32_t outputAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(output)); |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 470 | return statusTFromBinderStatus(mDelegate->restoreOutput(outputAidl)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | status_t AudioFlingerClientAdapter::openInput(const media::OpenInputRequest& request, |
| 474 | media::OpenInputResponse* response) { |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 475 | return statusTFromBinderStatus(mDelegate->openInput(request, response)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | status_t AudioFlingerClientAdapter::closeInput(audio_io_handle_t input) { |
| 479 | int32_t inputAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(input)); |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 480 | return statusTFromBinderStatus(mDelegate->closeInput(inputAidl)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | status_t AudioFlingerClientAdapter::invalidateStream(audio_stream_type_t stream) { |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 484 | AudioStreamType streamAidl = VALUE_OR_RETURN_STATUS( |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 485 | legacy2aidl_audio_stream_type_t_AudioStreamType(stream)); |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 486 | return statusTFromBinderStatus(mDelegate->invalidateStream(streamAidl)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | status_t AudioFlingerClientAdapter::setVoiceVolume(float volume) { |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 490 | return statusTFromBinderStatus(mDelegate->setVoiceVolume(volume)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | status_t AudioFlingerClientAdapter::getRenderPosition(uint32_t* halFrames, uint32_t* dspFrames, |
| 494 | audio_io_handle_t output) const { |
| 495 | int32_t outputAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(output)); |
| 496 | media::RenderPosition aidlRet; |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 497 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 498 | mDelegate->getRenderPosition(outputAidl, &aidlRet))); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 499 | if (halFrames != nullptr) { |
| 500 | *halFrames = VALUE_OR_RETURN_STATUS(convertIntegral<uint32_t>(aidlRet.halFrames)); |
| 501 | } |
| 502 | if (dspFrames != nullptr) { |
| 503 | *dspFrames = VALUE_OR_RETURN_STATUS(convertIntegral<uint32_t>(aidlRet.dspFrames)); |
| 504 | } |
| 505 | return OK; |
| 506 | } |
| 507 | |
| 508 | uint32_t AudioFlingerClientAdapter::getInputFramesLost(audio_io_handle_t ioHandle) const { |
| 509 | auto result = [&]() -> ConversionResult<uint32_t> { |
| 510 | int32_t ioHandleAidl = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(ioHandle)); |
| 511 | int32_t aidlRet; |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 512 | RETURN_IF_ERROR(statusTFromBinderStatus( |
| 513 | mDelegate->getInputFramesLost(ioHandleAidl, &aidlRet))); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 514 | return convertIntegral<uint32_t>(aidlRet); |
| 515 | }(); |
| 516 | // Failure is ignored. |
| 517 | return result.value_or(0); |
| 518 | } |
| 519 | |
| 520 | audio_unique_id_t AudioFlingerClientAdapter::newAudioUniqueId(audio_unique_id_use_t use) { |
| 521 | auto result = [&]() -> ConversionResult<audio_unique_id_t> { |
| 522 | media::AudioUniqueIdUse useAidl = VALUE_OR_RETURN( |
| 523 | legacy2aidl_audio_unique_id_use_t_AudioUniqueIdUse(use)); |
| 524 | int32_t aidlRet; |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 525 | RETURN_IF_ERROR(statusTFromBinderStatus( |
| 526 | mDelegate->newAudioUniqueId(useAidl, &aidlRet))); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 527 | return aidl2legacy_int32_t_audio_unique_id_t(aidlRet); |
| 528 | }(); |
| 529 | return result.value_or(AUDIO_UNIQUE_ID_ALLOCATE); |
| 530 | } |
| 531 | |
| 532 | void AudioFlingerClientAdapter::acquireAudioSessionId(audio_session_t audioSession, pid_t pid, |
| 533 | uid_t uid) { |
| 534 | [&]() -> status_t { |
| 535 | int32_t audioSessionAidl = VALUE_OR_RETURN_STATUS( |
| 536 | legacy2aidl_audio_session_t_int32_t(audioSession)); |
| 537 | int32_t pidAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_pid_t_int32_t(pid)); |
| 538 | int32_t uidAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_pid_t_int32_t(uid)); |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 539 | return statusTFromBinderStatus( |
| 540 | mDelegate->acquireAudioSessionId(audioSessionAidl, pidAidl, uidAidl)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 541 | }(); |
| 542 | // Failure is ignored. |
| 543 | } |
| 544 | |
| 545 | void AudioFlingerClientAdapter::releaseAudioSessionId(audio_session_t audioSession, pid_t pid) { |
| 546 | [&]() -> status_t { |
| 547 | int32_t audioSessionAidl = VALUE_OR_RETURN_STATUS( |
| 548 | legacy2aidl_audio_session_t_int32_t(audioSession)); |
| 549 | int32_t pidAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_pid_t_int32_t(pid)); |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 550 | return statusTFromBinderStatus( |
| 551 | mDelegate->releaseAudioSessionId(audioSessionAidl, pidAidl)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 552 | }(); |
| 553 | // Failure is ignored. |
| 554 | } |
| 555 | |
| 556 | status_t AudioFlingerClientAdapter::queryNumberEffects(uint32_t* numEffects) const { |
| 557 | int32_t aidlRet; |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 558 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 559 | mDelegate->queryNumberEffects(&aidlRet))); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 560 | if (numEffects != nullptr) { |
| 561 | *numEffects = VALUE_OR_RETURN_STATUS(convertIntegral<uint32_t>(aidlRet)); |
| 562 | } |
| 563 | return OK; |
| 564 | } |
| 565 | |
| 566 | status_t |
| 567 | AudioFlingerClientAdapter::queryEffect(uint32_t index, effect_descriptor_t* pDescriptor) const { |
| 568 | int32_t indexAidl = VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(index)); |
| 569 | media::EffectDescriptor aidlRet; |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 570 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 571 | mDelegate->queryEffect(indexAidl, &aidlRet))); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 572 | if (pDescriptor != nullptr) { |
| 573 | *pDescriptor = VALUE_OR_RETURN_STATUS( |
| 574 | aidl2legacy_EffectDescriptor_effect_descriptor_t(aidlRet)); |
| 575 | } |
| 576 | return OK; |
| 577 | } |
| 578 | |
| 579 | status_t AudioFlingerClientAdapter::getEffectDescriptor(const effect_uuid_t* pEffectUUID, |
| 580 | const effect_uuid_t* pTypeUUID, |
| 581 | uint32_t preferredTypeFlag, |
| 582 | effect_descriptor_t* pDescriptor) const { |
Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 583 | AudioUuid effectUuidAidl = VALUE_OR_RETURN_STATUS( |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 584 | legacy2aidl_audio_uuid_t_AudioUuid(*pEffectUUID)); |
Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 585 | AudioUuid typeUuidAidl = VALUE_OR_RETURN_STATUS( |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 586 | legacy2aidl_audio_uuid_t_AudioUuid(*pTypeUUID)); |
| 587 | int32_t preferredTypeFlagAidl = VALUE_OR_RETURN_STATUS( |
| 588 | convertReinterpret<int32_t>(preferredTypeFlag)); |
| 589 | media::EffectDescriptor aidlRet; |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 590 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 591 | mDelegate->getEffectDescriptor(effectUuidAidl, typeUuidAidl, preferredTypeFlagAidl, |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 592 | &aidlRet))); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 593 | if (pDescriptor != nullptr) { |
| 594 | *pDescriptor = VALUE_OR_RETURN_STATUS( |
| 595 | aidl2legacy_EffectDescriptor_effect_descriptor_t(aidlRet)); |
| 596 | } |
| 597 | return OK; |
| 598 | } |
| 599 | |
| 600 | status_t AudioFlingerClientAdapter::createEffect(const media::CreateEffectRequest& request, |
| 601 | media::CreateEffectResponse* response) { |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 602 | return statusTFromBinderStatus(mDelegate->createEffect(request, response)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | status_t |
| 606 | AudioFlingerClientAdapter::moveEffects(audio_session_t session, audio_io_handle_t srcOutput, |
| 607 | audio_io_handle_t dstOutput) { |
| 608 | int32_t sessionAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_session_t_int32_t(session)); |
| 609 | int32_t srcOutputAidl = VALUE_OR_RETURN_STATUS( |
| 610 | legacy2aidl_audio_io_handle_t_int32_t(srcOutput)); |
| 611 | int32_t dstOutputAidl = VALUE_OR_RETURN_STATUS( |
| 612 | legacy2aidl_audio_io_handle_t_int32_t(dstOutput)); |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 613 | return statusTFromBinderStatus( |
| 614 | mDelegate->moveEffects(sessionAidl, srcOutputAidl, dstOutputAidl)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | void AudioFlingerClientAdapter::setEffectSuspended(int effectId, |
| 618 | audio_session_t sessionId, |
| 619 | bool suspended) { |
| 620 | [&]() -> status_t { |
| 621 | int32_t effectIdAidl = VALUE_OR_RETURN_STATUS(convertReinterpret<int32_t>(effectId)); |
| 622 | int32_t sessionIdAidl = VALUE_OR_RETURN_STATUS( |
| 623 | legacy2aidl_audio_session_t_int32_t(sessionId)); |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 624 | return statusTFromBinderStatus( |
| 625 | mDelegate->setEffectSuspended(effectIdAidl, sessionIdAidl, suspended)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 626 | }(); |
| 627 | // Failure is ignored. |
| 628 | } |
| 629 | |
| 630 | audio_module_handle_t AudioFlingerClientAdapter::loadHwModule(const char* name) { |
| 631 | auto result = [&]() -> ConversionResult<audio_module_handle_t> { |
| 632 | std::string nameAidl(name); |
| 633 | int32_t aidlRet; |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 634 | RETURN_IF_ERROR(statusTFromBinderStatus( |
| 635 | mDelegate->loadHwModule(nameAidl, &aidlRet))); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 636 | return aidl2legacy_int32_t_audio_module_handle_t(aidlRet); |
| 637 | }(); |
| 638 | // Failure is ignored. |
| 639 | return result.value_or(0); |
| 640 | } |
| 641 | |
| 642 | uint32_t AudioFlingerClientAdapter::getPrimaryOutputSamplingRate() { |
| 643 | auto result = [&]() -> ConversionResult<uint32_t> { |
| 644 | int32_t aidlRet; |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 645 | RETURN_IF_ERROR(statusTFromBinderStatus( |
| 646 | mDelegate->getPrimaryOutputSamplingRate(&aidlRet))); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 647 | return convertIntegral<uint32_t>(aidlRet); |
| 648 | }(); |
| 649 | // Failure is ignored. |
| 650 | return result.value_or(0); |
| 651 | } |
| 652 | |
| 653 | size_t AudioFlingerClientAdapter::getPrimaryOutputFrameCount() { |
| 654 | auto result = [&]() -> ConversionResult<size_t> { |
| 655 | int64_t aidlRet; |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 656 | RETURN_IF_ERROR(statusTFromBinderStatus( |
| 657 | mDelegate->getPrimaryOutputFrameCount(&aidlRet))); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 658 | return convertIntegral<size_t>(aidlRet); |
| 659 | }(); |
| 660 | // Failure is ignored. |
| 661 | return result.value_or(0); |
| 662 | } |
| 663 | |
| 664 | status_t AudioFlingerClientAdapter::setLowRamDevice(bool isLowRamDevice, int64_t totalMemory) { |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 665 | return statusTFromBinderStatus(mDelegate->setLowRamDevice(isLowRamDevice, totalMemory)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | status_t AudioFlingerClientAdapter::getAudioPort(struct audio_port_v7* port) { |
| 669 | media::AudioPort portAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_port_v7_AudioPort(*port)); |
| 670 | media::AudioPort aidlRet; |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 671 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 672 | mDelegate->getAudioPort(portAidl, &aidlRet))); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 673 | *port = VALUE_OR_RETURN_STATUS(aidl2legacy_AudioPort_audio_port_v7(aidlRet)); |
| 674 | return OK; |
| 675 | } |
| 676 | |
| 677 | status_t AudioFlingerClientAdapter::createAudioPatch(const struct audio_patch* patch, |
| 678 | audio_patch_handle_t* handle) { |
| 679 | media::AudioPatch patchAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_patch_AudioPatch(*patch)); |
Kuowei Li | 247a367 | 2021-07-21 21:46:07 +0800 | [diff] [blame] | 680 | int32_t aidlRet = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_patch_handle_t_int32_t( |
| 681 | AUDIO_PATCH_HANDLE_NONE)); |
| 682 | if (handle != nullptr) { |
| 683 | aidlRet = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_patch_handle_t_int32_t(*handle)); |
| 684 | } |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 685 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 686 | mDelegate->createAudioPatch(patchAidl, &aidlRet))); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 687 | if (handle != nullptr) { |
| 688 | *handle = VALUE_OR_RETURN_STATUS(aidl2legacy_int32_t_audio_patch_handle_t(aidlRet)); |
| 689 | } |
| 690 | return OK; |
| 691 | } |
| 692 | |
| 693 | status_t AudioFlingerClientAdapter::releaseAudioPatch(audio_patch_handle_t handle) { |
| 694 | int32_t handleAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_patch_handle_t_int32_t(handle)); |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 695 | return statusTFromBinderStatus(mDelegate->releaseAudioPatch(handleAidl)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | status_t AudioFlingerClientAdapter::listAudioPatches(unsigned int* num_patches, |
| 699 | struct audio_patch* patches) { |
| 700 | std::vector<media::AudioPatch> aidlRet; |
| 701 | int32_t maxPatches = VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(*num_patches)); |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 702 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 703 | mDelegate->listAudioPatches(maxPatches, &aidlRet))); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 704 | *num_patches = VALUE_OR_RETURN_STATUS(convertIntegral<unsigned int>(aidlRet.size())); |
| 705 | return convertRange(aidlRet.begin(), aidlRet.end(), patches, |
| 706 | aidl2legacy_AudioPatch_audio_patch); |
| 707 | } |
| 708 | |
| 709 | status_t AudioFlingerClientAdapter::setAudioPortConfig(const struct audio_port_config* config) { |
| 710 | media::AudioPortConfig configAidl = VALUE_OR_RETURN_STATUS( |
| 711 | legacy2aidl_audio_port_config_AudioPortConfig(*config)); |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 712 | return statusTFromBinderStatus(mDelegate->setAudioPortConfig(configAidl)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | audio_hw_sync_t AudioFlingerClientAdapter::getAudioHwSyncForSession(audio_session_t sessionId) { |
| 716 | auto result = [&]() -> ConversionResult<audio_hw_sync_t> { |
| 717 | int32_t sessionIdAidl = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(sessionId)); |
| 718 | int32_t aidlRet; |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 719 | RETURN_IF_ERROR(statusTFromBinderStatus( |
| 720 | mDelegate->getAudioHwSyncForSession(sessionIdAidl, &aidlRet))); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 721 | return aidl2legacy_int32_t_audio_hw_sync_t(aidlRet); |
| 722 | }(); |
| 723 | return result.value_or(AUDIO_HW_SYNC_INVALID); |
| 724 | } |
| 725 | |
| 726 | status_t AudioFlingerClientAdapter::systemReady() { |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 727 | return statusTFromBinderStatus(mDelegate->systemReady()); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 728 | } |
| 729 | |
Eric Laurent | d66d7a1 | 2021-07-13 13:35:32 +0200 | [diff] [blame] | 730 | status_t AudioFlingerClientAdapter::audioPolicyReady() { |
| 731 | return statusTFromBinderStatus(mDelegate->audioPolicyReady()); |
| 732 | } |
| 733 | |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 734 | size_t AudioFlingerClientAdapter::frameCountHAL(audio_io_handle_t ioHandle) const { |
| 735 | auto result = [&]() -> ConversionResult<size_t> { |
| 736 | int32_t ioHandleAidl = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(ioHandle)); |
| 737 | int64_t aidlRet; |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 738 | RETURN_IF_ERROR(statusTFromBinderStatus( |
| 739 | mDelegate->frameCountHAL(ioHandleAidl, &aidlRet))); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 740 | return convertIntegral<size_t>(aidlRet); |
| 741 | }(); |
| 742 | // Failure is ignored. |
| 743 | return result.value_or(0); |
| 744 | } |
| 745 | |
| 746 | status_t |
| 747 | AudioFlingerClientAdapter::getMicrophones(std::vector<media::MicrophoneInfo>* microphones) { |
| 748 | std::vector<media::MicrophoneInfoData> aidlRet; |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 749 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 750 | mDelegate->getMicrophones(&aidlRet))); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 751 | if (microphones != nullptr) { |
| 752 | *microphones = VALUE_OR_RETURN_STATUS( |
| 753 | convertContainer<std::vector<media::MicrophoneInfo>>(aidlRet, |
| 754 | media::aidl2legacy_MicrophoneInfo)); |
| 755 | } |
| 756 | return OK; |
| 757 | } |
| 758 | |
| 759 | status_t AudioFlingerClientAdapter::setAudioHalPids(const std::vector<pid_t>& pids) { |
| 760 | std::vector<int32_t> pidsAidl = VALUE_OR_RETURN_STATUS( |
| 761 | convertContainer<std::vector<int32_t>>(pids, legacy2aidl_pid_t_int32_t)); |
Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 762 | return statusTFromBinderStatus(mDelegate->setAudioHalPids(pidsAidl)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 763 | } |
| 764 | |
jiabin | 1319f5a | 2021-03-30 22:21:24 +0000 | [diff] [blame] | 765 | status_t AudioFlingerClientAdapter::setVibratorInfos( |
| 766 | const std::vector<media::AudioVibratorInfo>& vibratorInfos) { |
| 767 | return statusTFromBinderStatus(mDelegate->setVibratorInfos(vibratorInfos)); |
| 768 | } |
| 769 | |
jiabin | 10a03f1 | 2021-05-07 23:46:28 +0000 | [diff] [blame] | 770 | status_t AudioFlingerClientAdapter::updateSecondaryOutputs( |
| 771 | const TrackSecondaryOutputsMap& trackSecondaryOutputs) { |
| 772 | std::vector<media::TrackSecondaryOutputInfo> trackSecondaryOutputInfos = |
| 773 | VALUE_OR_RETURN_STATUS( |
| 774 | convertContainer<std::vector<media::TrackSecondaryOutputInfo>>( |
| 775 | trackSecondaryOutputs, |
| 776 | legacy2aidl_TrackSecondaryOutputInfoPair_TrackSecondaryOutputInfo)); |
| 777 | return statusTFromBinderStatus(mDelegate->updateSecondaryOutputs(trackSecondaryOutputInfos)); |
| 778 | } |
| 779 | |
Jiabin Huang | ebe6410 | 2021-09-07 20:01:07 +0000 | [diff] [blame] | 780 | status_t AudioFlingerClientAdapter::getMmapPolicyInfos( |
jiabin | e99d088 | 2021-09-17 05:21:25 +0000 | [diff] [blame] | 781 | AudioMMapPolicyType policyType, std::vector<AudioMMapPolicyInfo> *policyInfos) { |
Jiabin Huang | ebe6410 | 2021-09-07 20:01:07 +0000 | [diff] [blame] | 782 | return statusTFromBinderStatus(mDelegate->getMmapPolicyInfos(policyType, policyInfos)); |
| 783 | } |
| 784 | |
jiabin | e504e7b | 2021-09-18 00:27:08 +0000 | [diff] [blame] | 785 | int32_t AudioFlingerClientAdapter::getAAudioMixerBurstCount() { |
| 786 | auto result = [&]() -> ConversionResult<int32_t> { |
| 787 | int32_t aidlRet; |
| 788 | RETURN_IF_ERROR(statusTFromBinderStatus(mDelegate->getAAudioMixerBurstCount(&aidlRet))); |
| 789 | return convertIntegral<int32_t>(aidlRet); |
| 790 | }(); |
| 791 | // Failure is ignored. |
| 792 | return result.value_or(0); |
| 793 | } |
| 794 | |
| 795 | int32_t AudioFlingerClientAdapter::getAAudioHardwareBurstMinUsec() { |
| 796 | auto result = [&]() -> ConversionResult<int32_t> { |
| 797 | int32_t aidlRet; |
| 798 | RETURN_IF_ERROR(statusTFromBinderStatus( |
| 799 | mDelegate->getAAudioHardwareBurstMinUsec(&aidlRet))); |
| 800 | return convertIntegral<int32_t>(aidlRet); |
| 801 | }(); |
| 802 | // Failure is ignored. |
| 803 | return result.value_or(0); |
| 804 | } |
| 805 | |
Mikhail Naganov | 516d398 | 2022-02-01 23:53:59 +0000 | [diff] [blame] | 806 | status_t AudioFlingerClientAdapter::setDeviceConnectedState( |
| 807 | const struct audio_port_v7 *port, bool connected) { |
| 808 | media::AudioPort aidlPort = VALUE_OR_RETURN_STATUS( |
| 809 | legacy2aidl_audio_port_v7_AudioPort(*port)); |
| 810 | return statusTFromBinderStatus(mDelegate->setDeviceConnectedState(aidlPort, connected)); |
| 811 | } |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 812 | |
Eric Laurent | 076e7c7 | 2022-05-03 18:12:28 +0200 | [diff] [blame] | 813 | status_t AudioFlingerClientAdapter::setRequestedLatencyMode( |
| 814 | audio_io_handle_t output, audio_latency_mode_t mode) { |
| 815 | int32_t outputAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(output)); |
| 816 | media::LatencyMode modeAidl = VALUE_OR_RETURN_STATUS( |
| 817 | legacy2aidl_audio_latency_mode_t_LatencyMode(mode)); |
| 818 | return statusTFromBinderStatus(mDelegate->setRequestedLatencyMode(outputAidl, modeAidl)); |
| 819 | } |
| 820 | |
| 821 | status_t AudioFlingerClientAdapter::getSupportedLatencyModes( |
| 822 | audio_io_handle_t output, std::vector<audio_latency_mode_t>* modes) { |
| 823 | if (modes == nullptr) { |
| 824 | return BAD_VALUE; |
| 825 | } |
| 826 | |
| 827 | int32_t outputAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(output)); |
| 828 | std::vector<media::LatencyMode> modesAidl; |
| 829 | |
| 830 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 831 | mDelegate->getSupportedLatencyModes(outputAidl, &modesAidl))); |
| 832 | |
| 833 | *modes = VALUE_OR_RETURN_STATUS( |
| 834 | convertContainer<std::vector<audio_latency_mode_t>>(modesAidl, |
| 835 | aidl2legacy_LatencyMode_audio_latency_mode_t)); |
| 836 | |
| 837 | return NO_ERROR; |
| 838 | } |
| 839 | |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 840 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 841 | // AudioFlingerServerAdapter |
| 842 | AudioFlingerServerAdapter::AudioFlingerServerAdapter( |
| 843 | const sp<AudioFlingerServerAdapter::Delegate>& delegate) : mDelegate(delegate) {} |
| 844 | |
Ytai Ben-Tsvi | 24b33fc | 2021-05-10 13:08:11 -0700 | [diff] [blame] | 845 | status_t AudioFlingerServerAdapter::onTransact(uint32_t code, |
| 846 | const Parcel& data, |
| 847 | Parcel* reply, |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 848 | uint32_t flags) { |
Ytai Ben-Tsvi | 24b33fc | 2021-05-10 13:08:11 -0700 | [diff] [blame] | 849 | return mDelegate->onTransactWrapper(static_cast<Delegate::TransactionCode>(code), |
| 850 | data, |
| 851 | flags, |
| 852 | [&] { |
| 853 | return BnAudioFlingerService::onTransact( |
| 854 | code, |
| 855 | data, |
| 856 | reply, |
| 857 | flags); |
| 858 | }); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | status_t AudioFlingerServerAdapter::dump(int fd, const Vector<String16>& args) { |
| 862 | return mDelegate->dump(fd, args); |
| 863 | } |
| 864 | |
| 865 | Status AudioFlingerServerAdapter::createTrack(const media::CreateTrackRequest& request, |
| 866 | media::CreateTrackResponse* _aidl_return) { |
| 867 | return Status::fromStatusT(mDelegate->createTrack(request, *_aidl_return)); |
| 868 | } |
| 869 | |
| 870 | Status AudioFlingerServerAdapter::createRecord(const media::CreateRecordRequest& request, |
| 871 | media::CreateRecordResponse* _aidl_return) { |
| 872 | return Status::fromStatusT(mDelegate->createRecord(request, *_aidl_return)); |
| 873 | } |
| 874 | |
| 875 | Status AudioFlingerServerAdapter::sampleRate(int32_t ioHandle, int32_t* _aidl_return) { |
| 876 | audio_io_handle_t ioHandleLegacy = VALUE_OR_RETURN_BINDER( |
| 877 | aidl2legacy_int32_t_audio_io_handle_t(ioHandle)); |
| 878 | *_aidl_return = VALUE_OR_RETURN_BINDER( |
| 879 | convertIntegral<int32_t>(mDelegate->sampleRate(ioHandleLegacy))); |
| 880 | return Status::ok(); |
| 881 | } |
| 882 | |
| 883 | Status AudioFlingerServerAdapter::format(int32_t output, |
Mikhail Naganov | 57bd06f | 2021-08-10 16:41:54 -0700 | [diff] [blame] | 884 | AudioFormatDescription* _aidl_return) { |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 885 | audio_io_handle_t outputLegacy = VALUE_OR_RETURN_BINDER( |
| 886 | aidl2legacy_int32_t_audio_io_handle_t(output)); |
| 887 | *_aidl_return = VALUE_OR_RETURN_BINDER( |
Mikhail Naganov | b60bd1b | 2021-07-15 17:31:43 -0700 | [diff] [blame] | 888 | legacy2aidl_audio_format_t_AudioFormatDescription(mDelegate->format(outputLegacy))); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 889 | return Status::ok(); |
| 890 | } |
| 891 | |
| 892 | Status AudioFlingerServerAdapter::frameCount(int32_t ioHandle, int64_t* _aidl_return) { |
| 893 | audio_io_handle_t ioHandleLegacy = VALUE_OR_RETURN_BINDER( |
| 894 | aidl2legacy_int32_t_audio_io_handle_t(ioHandle)); |
| 895 | *_aidl_return = VALUE_OR_RETURN_BINDER( |
| 896 | convertIntegral<int64_t>(mDelegate->frameCount(ioHandleLegacy))); |
| 897 | return Status::ok(); |
| 898 | } |
| 899 | |
| 900 | Status AudioFlingerServerAdapter::latency(int32_t output, int32_t* _aidl_return) { |
| 901 | audio_io_handle_t outputLegacy = VALUE_OR_RETURN_BINDER( |
| 902 | aidl2legacy_int32_t_audio_io_handle_t(output)); |
| 903 | *_aidl_return = VALUE_OR_RETURN_BINDER( |
| 904 | convertIntegral<int32_t>(mDelegate->latency(outputLegacy))); |
| 905 | return Status::ok(); |
| 906 | } |
| 907 | |
| 908 | Status AudioFlingerServerAdapter::setMasterVolume(float value) { |
| 909 | return Status::fromStatusT(mDelegate->setMasterVolume(value)); |
| 910 | } |
| 911 | |
| 912 | Status AudioFlingerServerAdapter::setMasterMute(bool muted) { |
| 913 | return Status::fromStatusT(mDelegate->setMasterMute(muted)); |
| 914 | } |
| 915 | |
| 916 | Status AudioFlingerServerAdapter::masterVolume(float* _aidl_return) { |
| 917 | *_aidl_return = mDelegate->masterVolume(); |
| 918 | return Status::ok(); |
| 919 | } |
| 920 | |
| 921 | Status AudioFlingerServerAdapter::masterMute(bool* _aidl_return) { |
| 922 | *_aidl_return = mDelegate->masterMute(); |
| 923 | return Status::ok(); |
| 924 | } |
| 925 | |
| 926 | Status AudioFlingerServerAdapter::setMasterBalance(float balance) { |
| 927 | return Status::fromStatusT(mDelegate->setMasterBalance(balance)); |
| 928 | } |
| 929 | |
| 930 | Status AudioFlingerServerAdapter::getMasterBalance(float* _aidl_return) { |
| 931 | return Status::fromStatusT(mDelegate->getMasterBalance(_aidl_return)); |
| 932 | } |
| 933 | |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 934 | Status AudioFlingerServerAdapter::setStreamVolume(AudioStreamType stream, float value, |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 935 | int32_t output) { |
| 936 | audio_stream_type_t streamLegacy = VALUE_OR_RETURN_BINDER( |
| 937 | aidl2legacy_AudioStreamType_audio_stream_type_t(stream)); |
| 938 | audio_io_handle_t outputLegacy = VALUE_OR_RETURN_BINDER( |
| 939 | aidl2legacy_int32_t_audio_io_handle_t(output)); |
| 940 | return Status::fromStatusT(mDelegate->setStreamVolume(streamLegacy, value, outputLegacy)); |
| 941 | } |
| 942 | |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 943 | Status AudioFlingerServerAdapter::setStreamMute(AudioStreamType stream, bool muted) { |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 944 | audio_stream_type_t streamLegacy = VALUE_OR_RETURN_BINDER( |
| 945 | aidl2legacy_AudioStreamType_audio_stream_type_t(stream)); |
| 946 | return Status::fromStatusT(mDelegate->setStreamMute(streamLegacy, muted)); |
| 947 | } |
| 948 | |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 949 | Status AudioFlingerServerAdapter::streamVolume(AudioStreamType stream, int32_t output, |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 950 | float* _aidl_return) { |
| 951 | audio_stream_type_t streamLegacy = VALUE_OR_RETURN_BINDER( |
| 952 | aidl2legacy_AudioStreamType_audio_stream_type_t(stream)); |
| 953 | audio_io_handle_t outputLegacy = VALUE_OR_RETURN_BINDER( |
| 954 | aidl2legacy_int32_t_audio_io_handle_t(output)); |
| 955 | *_aidl_return = mDelegate->streamVolume(streamLegacy, outputLegacy); |
| 956 | return Status::ok(); |
| 957 | } |
| 958 | |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 959 | Status AudioFlingerServerAdapter::streamMute(AudioStreamType stream, bool* _aidl_return) { |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 960 | audio_stream_type_t streamLegacy = VALUE_OR_RETURN_BINDER( |
| 961 | aidl2legacy_AudioStreamType_audio_stream_type_t(stream)); |
| 962 | *_aidl_return = mDelegate->streamMute(streamLegacy); |
| 963 | return Status::ok(); |
| 964 | } |
| 965 | |
Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 966 | Status AudioFlingerServerAdapter::setMode(AudioMode mode) { |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 967 | audio_mode_t modeLegacy = VALUE_OR_RETURN_BINDER(aidl2legacy_AudioMode_audio_mode_t(mode)); |
| 968 | return Status::fromStatusT(mDelegate->setMode(modeLegacy)); |
| 969 | } |
| 970 | |
| 971 | Status AudioFlingerServerAdapter::setMicMute(bool state) { |
| 972 | return Status::fromStatusT(mDelegate->setMicMute(state)); |
| 973 | } |
| 974 | |
| 975 | Status AudioFlingerServerAdapter::getMicMute(bool* _aidl_return) { |
| 976 | *_aidl_return = mDelegate->getMicMute(); |
| 977 | return Status::ok(); |
| 978 | } |
| 979 | |
| 980 | Status AudioFlingerServerAdapter::setRecordSilenced(int32_t portId, bool silenced) { |
| 981 | audio_port_handle_t portIdLegacy = VALUE_OR_RETURN_BINDER( |
| 982 | aidl2legacy_int32_t_audio_port_handle_t(portId)); |
| 983 | mDelegate->setRecordSilenced(portIdLegacy, silenced); |
| 984 | return Status::ok(); |
| 985 | } |
| 986 | |
| 987 | Status |
| 988 | AudioFlingerServerAdapter::setParameters(int32_t ioHandle, const std::string& keyValuePairs) { |
| 989 | audio_io_handle_t ioHandleLegacy = VALUE_OR_RETURN_BINDER( |
| 990 | aidl2legacy_int32_t_audio_io_handle_t(ioHandle)); |
| 991 | String8 keyValuePairsLegacy = VALUE_OR_RETURN_BINDER( |
| 992 | aidl2legacy_string_view_String8(keyValuePairs)); |
| 993 | return Status::fromStatusT(mDelegate->setParameters(ioHandleLegacy, keyValuePairsLegacy)); |
| 994 | } |
| 995 | |
| 996 | Status AudioFlingerServerAdapter::getParameters(int32_t ioHandle, const std::string& keys, |
| 997 | std::string* _aidl_return) { |
| 998 | audio_io_handle_t ioHandleLegacy = VALUE_OR_RETURN_BINDER( |
| 999 | aidl2legacy_int32_t_audio_io_handle_t(ioHandle)); |
| 1000 | String8 keysLegacy = VALUE_OR_RETURN_BINDER(aidl2legacy_string_view_String8(keys)); |
| 1001 | *_aidl_return = VALUE_OR_RETURN_BINDER( |
| 1002 | legacy2aidl_String8_string(mDelegate->getParameters(ioHandleLegacy, keysLegacy))); |
| 1003 | return Status::ok(); |
| 1004 | } |
| 1005 | |
| 1006 | Status AudioFlingerServerAdapter::registerClient(const sp<media::IAudioFlingerClient>& client) { |
| 1007 | mDelegate->registerClient(client); |
| 1008 | return Status::ok(); |
| 1009 | } |
| 1010 | |
| 1011 | Status AudioFlingerServerAdapter::getInputBufferSize(int32_t sampleRate, |
Mikhail Naganov | 57bd06f | 2021-08-10 16:41:54 -0700 | [diff] [blame] | 1012 | const AudioFormatDescription& format, |
| 1013 | const AudioChannelLayout& channelMask, |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 1014 | int64_t* _aidl_return) { |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 1015 | uint32_t sampleRateLegacy = VALUE_OR_RETURN_BINDER(convertIntegral<uint32_t>(sampleRate)); |
| 1016 | audio_format_t formatLegacy = VALUE_OR_RETURN_BINDER( |
Mikhail Naganov | b60bd1b | 2021-07-15 17:31:43 -0700 | [diff] [blame] | 1017 | aidl2legacy_AudioFormatDescription_audio_format_t(format)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 1018 | audio_channel_mask_t channelMaskLegacy = VALUE_OR_RETURN_BINDER( |
Mikhail Naganov | de3fa18 | 2021-07-30 15:06:42 -0700 | [diff] [blame] | 1019 | aidl2legacy_AudioChannelLayout_audio_channel_mask_t(channelMask, true /*isInput*/)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 1020 | size_t size = mDelegate->getInputBufferSize(sampleRateLegacy, formatLegacy, channelMaskLegacy); |
| 1021 | *_aidl_return = VALUE_OR_RETURN_BINDER(convertIntegral<int64_t>(size)); |
| 1022 | return Status::ok(); |
| 1023 | } |
| 1024 | |
| 1025 | Status AudioFlingerServerAdapter::openOutput(const media::OpenOutputRequest& request, |
| 1026 | media::OpenOutputResponse* _aidl_return) { |
| 1027 | return Status::fromStatusT(mDelegate->openOutput(request, _aidl_return)); |
| 1028 | } |
| 1029 | |
| 1030 | Status AudioFlingerServerAdapter::openDuplicateOutput(int32_t output1, int32_t output2, |
| 1031 | int32_t* _aidl_return) { |
| 1032 | audio_io_handle_t output1Legacy = VALUE_OR_RETURN_BINDER( |
| 1033 | aidl2legacy_int32_t_audio_io_handle_t(output1)); |
| 1034 | audio_io_handle_t output2Legacy = VALUE_OR_RETURN_BINDER( |
| 1035 | aidl2legacy_int32_t_audio_io_handle_t(output2)); |
| 1036 | audio_io_handle_t result = mDelegate->openDuplicateOutput(output1Legacy, output2Legacy); |
| 1037 | *_aidl_return = VALUE_OR_RETURN_BINDER(legacy2aidl_audio_io_handle_t_int32_t(result)); |
| 1038 | return Status::ok(); |
| 1039 | } |
| 1040 | |
| 1041 | Status AudioFlingerServerAdapter::closeOutput(int32_t output) { |
| 1042 | audio_io_handle_t outputLegacy = VALUE_OR_RETURN_BINDER( |
| 1043 | aidl2legacy_int32_t_audio_io_handle_t(output)); |
| 1044 | return Status::fromStatusT(mDelegate->closeOutput(outputLegacy)); |
| 1045 | } |
| 1046 | |
| 1047 | Status AudioFlingerServerAdapter::suspendOutput(int32_t output) { |
| 1048 | audio_io_handle_t outputLegacy = VALUE_OR_RETURN_BINDER( |
| 1049 | aidl2legacy_int32_t_audio_io_handle_t(output)); |
| 1050 | return Status::fromStatusT(mDelegate->suspendOutput(outputLegacy)); |
| 1051 | } |
| 1052 | |
| 1053 | Status AudioFlingerServerAdapter::restoreOutput(int32_t output) { |
| 1054 | audio_io_handle_t outputLegacy = VALUE_OR_RETURN_BINDER( |
| 1055 | aidl2legacy_int32_t_audio_io_handle_t(output)); |
| 1056 | return Status::fromStatusT(mDelegate->restoreOutput(outputLegacy)); |
| 1057 | } |
| 1058 | |
| 1059 | Status AudioFlingerServerAdapter::openInput(const media::OpenInputRequest& request, |
| 1060 | media::OpenInputResponse* _aidl_return) { |
| 1061 | return Status::fromStatusT(mDelegate->openInput(request, _aidl_return)); |
| 1062 | } |
| 1063 | |
| 1064 | Status AudioFlingerServerAdapter::closeInput(int32_t input) { |
| 1065 | audio_io_handle_t inputLegacy = VALUE_OR_RETURN_BINDER( |
| 1066 | aidl2legacy_int32_t_audio_io_handle_t(input)); |
| 1067 | return Status::fromStatusT(mDelegate->closeInput(inputLegacy)); |
| 1068 | } |
| 1069 | |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 1070 | Status AudioFlingerServerAdapter::invalidateStream(AudioStreamType stream) { |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 1071 | audio_stream_type_t streamLegacy = VALUE_OR_RETURN_BINDER( |
| 1072 | aidl2legacy_AudioStreamType_audio_stream_type_t(stream)); |
| 1073 | return Status::fromStatusT(mDelegate->invalidateStream(streamLegacy)); |
| 1074 | } |
| 1075 | |
| 1076 | Status AudioFlingerServerAdapter::setVoiceVolume(float volume) { |
| 1077 | return Status::fromStatusT(mDelegate->setVoiceVolume(volume)); |
| 1078 | } |
| 1079 | |
| 1080 | Status |
| 1081 | AudioFlingerServerAdapter::getRenderPosition(int32_t output, media::RenderPosition* _aidl_return) { |
| 1082 | audio_io_handle_t outputLegacy = VALUE_OR_RETURN_BINDER( |
| 1083 | aidl2legacy_int32_t_audio_io_handle_t(output)); |
| 1084 | uint32_t halFramesLegacy; |
| 1085 | uint32_t dspFramesLegacy; |
| 1086 | RETURN_BINDER_IF_ERROR( |
| 1087 | mDelegate->getRenderPosition(&halFramesLegacy, &dspFramesLegacy, outputLegacy)); |
| 1088 | _aidl_return->halFrames = VALUE_OR_RETURN_BINDER(convertIntegral<int32_t>(halFramesLegacy)); |
| 1089 | _aidl_return->dspFrames = VALUE_OR_RETURN_BINDER(convertIntegral<int32_t>(dspFramesLegacy)); |
| 1090 | return Status::ok(); |
| 1091 | } |
| 1092 | |
| 1093 | Status AudioFlingerServerAdapter::getInputFramesLost(int32_t ioHandle, int32_t* _aidl_return) { |
| 1094 | audio_io_handle_t ioHandleLegacy = VALUE_OR_RETURN_BINDER( |
| 1095 | aidl2legacy_int32_t_audio_io_handle_t(ioHandle)); |
| 1096 | uint32_t result = mDelegate->getInputFramesLost(ioHandleLegacy); |
| 1097 | *_aidl_return = VALUE_OR_RETURN_BINDER(convertIntegral<int32_t>(result)); |
| 1098 | return Status::ok(); |
| 1099 | } |
| 1100 | |
| 1101 | Status |
| 1102 | AudioFlingerServerAdapter::newAudioUniqueId(media::AudioUniqueIdUse use, int32_t* _aidl_return) { |
| 1103 | audio_unique_id_use_t useLegacy = VALUE_OR_RETURN_BINDER( |
| 1104 | aidl2legacy_AudioUniqueIdUse_audio_unique_id_use_t(use)); |
| 1105 | audio_unique_id_t result = mDelegate->newAudioUniqueId(useLegacy); |
| 1106 | *_aidl_return = VALUE_OR_RETURN_BINDER(legacy2aidl_audio_unique_id_t_int32_t(result)); |
| 1107 | return Status::ok(); |
| 1108 | } |
| 1109 | |
| 1110 | Status |
| 1111 | AudioFlingerServerAdapter::acquireAudioSessionId(int32_t audioSession, int32_t pid, int32_t uid) { |
| 1112 | audio_session_t audioSessionLegacy = VALUE_OR_RETURN_BINDER( |
| 1113 | aidl2legacy_int32_t_audio_session_t(audioSession)); |
| 1114 | pid_t pidLegacy = VALUE_OR_RETURN_BINDER(aidl2legacy_int32_t_pid_t(pid)); |
| 1115 | uid_t uidLegacy = VALUE_OR_RETURN_BINDER(aidl2legacy_int32_t_uid_t(uid)); |
| 1116 | mDelegate->acquireAudioSessionId(audioSessionLegacy, pidLegacy, uidLegacy); |
| 1117 | return Status::ok(); |
| 1118 | } |
| 1119 | |
| 1120 | Status AudioFlingerServerAdapter::releaseAudioSessionId(int32_t audioSession, int32_t pid) { |
| 1121 | audio_session_t audioSessionLegacy = VALUE_OR_RETURN_BINDER( |
| 1122 | aidl2legacy_int32_t_audio_session_t(audioSession)); |
| 1123 | pid_t pidLegacy = VALUE_OR_RETURN_BINDER(aidl2legacy_int32_t_pid_t(pid)); |
| 1124 | mDelegate->releaseAudioSessionId(audioSessionLegacy, pidLegacy); |
| 1125 | return Status::ok(); |
| 1126 | } |
| 1127 | |
| 1128 | Status AudioFlingerServerAdapter::queryNumberEffects(int32_t* _aidl_return) { |
| 1129 | uint32_t result; |
| 1130 | RETURN_BINDER_IF_ERROR(mDelegate->queryNumberEffects(&result)); |
| 1131 | *_aidl_return = VALUE_OR_RETURN_BINDER(convertIntegral<uint32_t>(result)); |
| 1132 | return Status::ok(); |
| 1133 | } |
| 1134 | |
| 1135 | Status |
| 1136 | AudioFlingerServerAdapter::queryEffect(int32_t index, media::EffectDescriptor* _aidl_return) { |
| 1137 | uint32_t indexLegacy = VALUE_OR_RETURN_BINDER(convertIntegral<uint32_t>(index)); |
| 1138 | effect_descriptor_t result; |
| 1139 | RETURN_BINDER_IF_ERROR(mDelegate->queryEffect(indexLegacy, &result)); |
| 1140 | *_aidl_return = VALUE_OR_RETURN_BINDER( |
| 1141 | legacy2aidl_effect_descriptor_t_EffectDescriptor(result)); |
| 1142 | return Status::ok(); |
| 1143 | } |
| 1144 | |
Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 1145 | Status AudioFlingerServerAdapter::getEffectDescriptor(const AudioUuid& effectUUID, |
| 1146 | const AudioUuid& typeUUID, |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 1147 | int32_t preferredTypeFlag, |
| 1148 | media::EffectDescriptor* _aidl_return) { |
| 1149 | effect_uuid_t effectUuidLegacy = VALUE_OR_RETURN_BINDER( |
| 1150 | aidl2legacy_AudioUuid_audio_uuid_t(effectUUID)); |
| 1151 | effect_uuid_t typeUuidLegacy = VALUE_OR_RETURN_BINDER( |
| 1152 | aidl2legacy_AudioUuid_audio_uuid_t(typeUUID)); |
| 1153 | uint32_t preferredTypeFlagLegacy = VALUE_OR_RETURN_BINDER( |
| 1154 | convertReinterpret<uint32_t>(preferredTypeFlag)); |
| 1155 | effect_descriptor_t result; |
| 1156 | RETURN_BINDER_IF_ERROR(mDelegate->getEffectDescriptor(&effectUuidLegacy, &typeUuidLegacy, |
| 1157 | preferredTypeFlagLegacy, &result)); |
| 1158 | *_aidl_return = VALUE_OR_RETURN_BINDER( |
| 1159 | legacy2aidl_effect_descriptor_t_EffectDescriptor(result)); |
| 1160 | return Status::ok(); |
| 1161 | } |
| 1162 | |
| 1163 | Status AudioFlingerServerAdapter::createEffect(const media::CreateEffectRequest& request, |
| 1164 | media::CreateEffectResponse* _aidl_return) { |
| 1165 | return Status::fromStatusT(mDelegate->createEffect(request, _aidl_return)); |
| 1166 | } |
| 1167 | |
| 1168 | Status |
| 1169 | AudioFlingerServerAdapter::moveEffects(int32_t session, int32_t srcOutput, int32_t dstOutput) { |
| 1170 | audio_session_t sessionLegacy = VALUE_OR_RETURN_BINDER( |
| 1171 | aidl2legacy_int32_t_audio_session_t(session)); |
| 1172 | audio_io_handle_t srcOutputLegacy = VALUE_OR_RETURN_BINDER( |
| 1173 | aidl2legacy_int32_t_audio_io_handle_t(srcOutput)); |
| 1174 | audio_io_handle_t dstOutputLegacy = VALUE_OR_RETURN_BINDER( |
| 1175 | aidl2legacy_int32_t_audio_io_handle_t(dstOutput)); |
| 1176 | return Status::fromStatusT( |
| 1177 | mDelegate->moveEffects(sessionLegacy, srcOutputLegacy, dstOutputLegacy)); |
| 1178 | } |
| 1179 | |
| 1180 | Status AudioFlingerServerAdapter::setEffectSuspended(int32_t effectId, int32_t sessionId, |
| 1181 | bool suspended) { |
| 1182 | int effectIdLegacy = VALUE_OR_RETURN_BINDER(convertReinterpret<int>(effectId)); |
| 1183 | audio_session_t sessionIdLegacy = VALUE_OR_RETURN_BINDER( |
| 1184 | aidl2legacy_int32_t_audio_session_t(sessionId)); |
| 1185 | mDelegate->setEffectSuspended(effectIdLegacy, sessionIdLegacy, suspended); |
| 1186 | return Status::ok(); |
| 1187 | } |
| 1188 | |
| 1189 | Status AudioFlingerServerAdapter::loadHwModule(const std::string& name, int32_t* _aidl_return) { |
| 1190 | audio_module_handle_t result = mDelegate->loadHwModule(name.c_str()); |
| 1191 | *_aidl_return = VALUE_OR_RETURN_BINDER(legacy2aidl_audio_module_handle_t_int32_t(result)); |
| 1192 | return Status::ok(); |
| 1193 | } |
| 1194 | |
| 1195 | Status AudioFlingerServerAdapter::getPrimaryOutputSamplingRate(int32_t* _aidl_return) { |
| 1196 | *_aidl_return = VALUE_OR_RETURN_BINDER( |
| 1197 | convertIntegral<int32_t>(mDelegate->getPrimaryOutputSamplingRate())); |
| 1198 | return Status::ok(); |
| 1199 | } |
| 1200 | |
| 1201 | Status AudioFlingerServerAdapter::getPrimaryOutputFrameCount(int64_t* _aidl_return) { |
| 1202 | *_aidl_return = VALUE_OR_RETURN_BINDER( |
| 1203 | convertIntegral<int64_t>(mDelegate->getPrimaryOutputFrameCount())); |
| 1204 | return Status::ok(); |
| 1205 | |
| 1206 | } |
| 1207 | |
| 1208 | Status AudioFlingerServerAdapter::setLowRamDevice(bool isLowRamDevice, int64_t totalMemory) { |
| 1209 | return Status::fromStatusT(mDelegate->setLowRamDevice(isLowRamDevice, totalMemory)); |
| 1210 | } |
| 1211 | |
| 1212 | Status AudioFlingerServerAdapter::getAudioPort(const media::AudioPort& port, |
| 1213 | media::AudioPort* _aidl_return) { |
| 1214 | audio_port_v7 portLegacy = VALUE_OR_RETURN_BINDER(aidl2legacy_AudioPort_audio_port_v7(port)); |
| 1215 | RETURN_BINDER_IF_ERROR(mDelegate->getAudioPort(&portLegacy)); |
| 1216 | *_aidl_return = VALUE_OR_RETURN_BINDER(legacy2aidl_audio_port_v7_AudioPort(portLegacy)); |
| 1217 | return Status::ok(); |
| 1218 | } |
| 1219 | |
| 1220 | Status AudioFlingerServerAdapter::createAudioPatch(const media::AudioPatch& patch, |
| 1221 | int32_t* _aidl_return) { |
| 1222 | audio_patch patchLegacy = VALUE_OR_RETURN_BINDER(aidl2legacy_AudioPatch_audio_patch(patch)); |
Kuowei Li | 247a367 | 2021-07-21 21:46:07 +0800 | [diff] [blame] | 1223 | audio_patch_handle_t handleLegacy = VALUE_OR_RETURN_BINDER( |
| 1224 | aidl2legacy_int32_t_audio_patch_handle_t(*_aidl_return)); |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 1225 | RETURN_BINDER_IF_ERROR(mDelegate->createAudioPatch(&patchLegacy, &handleLegacy)); |
| 1226 | *_aidl_return = VALUE_OR_RETURN_BINDER(legacy2aidl_audio_patch_handle_t_int32_t(handleLegacy)); |
| 1227 | return Status::ok(); |
| 1228 | } |
| 1229 | |
| 1230 | Status AudioFlingerServerAdapter::releaseAudioPatch(int32_t handle) { |
| 1231 | audio_patch_handle_t handleLegacy = VALUE_OR_RETURN_BINDER( |
| 1232 | aidl2legacy_int32_t_audio_patch_handle_t(handle)); |
| 1233 | return Status::fromStatusT(mDelegate->releaseAudioPatch(handleLegacy)); |
| 1234 | } |
| 1235 | |
| 1236 | Status AudioFlingerServerAdapter::listAudioPatches(int32_t maxCount, |
| 1237 | std::vector<media::AudioPatch>* _aidl_return) { |
| 1238 | unsigned int count = VALUE_OR_RETURN_BINDER(convertIntegral<unsigned int>(maxCount)); |
| 1239 | count = std::min(count, static_cast<unsigned int>(MAX_ITEMS_PER_LIST)); |
| 1240 | std::unique_ptr<audio_patch[]> patchesLegacy(new audio_patch[count]); |
| 1241 | RETURN_BINDER_IF_ERROR(mDelegate->listAudioPatches(&count, patchesLegacy.get())); |
| 1242 | RETURN_BINDER_IF_ERROR(convertRange(&patchesLegacy[0], |
| 1243 | &patchesLegacy[count], |
| 1244 | std::back_inserter(*_aidl_return), |
| 1245 | legacy2aidl_audio_patch_AudioPatch)); |
| 1246 | return Status::ok(); |
| 1247 | } |
| 1248 | |
| 1249 | Status AudioFlingerServerAdapter::setAudioPortConfig(const media::AudioPortConfig& config) { |
| 1250 | audio_port_config configLegacy = VALUE_OR_RETURN_BINDER( |
| 1251 | aidl2legacy_AudioPortConfig_audio_port_config(config)); |
| 1252 | return Status::fromStatusT(mDelegate->setAudioPortConfig(&configLegacy)); |
| 1253 | } |
| 1254 | |
| 1255 | Status AudioFlingerServerAdapter::getAudioHwSyncForSession(int32_t sessionId, |
| 1256 | int32_t* _aidl_return) { |
| 1257 | audio_session_t sessionIdLegacy = VALUE_OR_RETURN_BINDER( |
| 1258 | aidl2legacy_int32_t_audio_session_t(sessionId)); |
| 1259 | audio_hw_sync_t result = mDelegate->getAudioHwSyncForSession(sessionIdLegacy); |
| 1260 | *_aidl_return = VALUE_OR_RETURN_BINDER(legacy2aidl_audio_hw_sync_t_int32_t(result)); |
| 1261 | return Status::ok(); |
| 1262 | } |
| 1263 | |
| 1264 | Status AudioFlingerServerAdapter::systemReady() { |
| 1265 | return Status::fromStatusT(mDelegate->systemReady()); |
| 1266 | } |
| 1267 | |
Eric Laurent | d66d7a1 | 2021-07-13 13:35:32 +0200 | [diff] [blame] | 1268 | Status AudioFlingerServerAdapter::audioPolicyReady() { |
| 1269 | mDelegate->audioPolicyReady(); |
| 1270 | return Status::ok(); |
| 1271 | } |
| 1272 | |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 1273 | Status AudioFlingerServerAdapter::frameCountHAL(int32_t ioHandle, int64_t* _aidl_return) { |
| 1274 | audio_io_handle_t ioHandleLegacy = VALUE_OR_RETURN_BINDER( |
| 1275 | aidl2legacy_int32_t_audio_io_handle_t(ioHandle)); |
| 1276 | size_t result = mDelegate->frameCountHAL(ioHandleLegacy); |
| 1277 | *_aidl_return = VALUE_OR_RETURN_BINDER(convertIntegral<int64_t>(result)); |
| 1278 | return Status::ok(); |
| 1279 | } |
| 1280 | |
| 1281 | Status AudioFlingerServerAdapter::getMicrophones( |
| 1282 | std::vector<media::MicrophoneInfoData>* _aidl_return) { |
| 1283 | std::vector<media::MicrophoneInfo> resultLegacy; |
| 1284 | RETURN_BINDER_IF_ERROR(mDelegate->getMicrophones(&resultLegacy)); |
| 1285 | *_aidl_return = VALUE_OR_RETURN_BINDER(convertContainer<std::vector<media::MicrophoneInfoData>>( |
| 1286 | resultLegacy, media::legacy2aidl_MicrophoneInfo)); |
| 1287 | return Status::ok(); |
| 1288 | } |
| 1289 | |
| 1290 | Status AudioFlingerServerAdapter::setAudioHalPids(const std::vector<int32_t>& pids) { |
| 1291 | std::vector<pid_t> pidsLegacy = VALUE_OR_RETURN_BINDER( |
| 1292 | convertContainer<std::vector<pid_t>>(pids, aidl2legacy_int32_t_pid_t)); |
| 1293 | RETURN_BINDER_IF_ERROR(mDelegate->setAudioHalPids(pidsLegacy)); |
| 1294 | return Status::ok(); |
| 1295 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1296 | |
jiabin | 1319f5a | 2021-03-30 22:21:24 +0000 | [diff] [blame] | 1297 | Status AudioFlingerServerAdapter::setVibratorInfos( |
| 1298 | const std::vector<media::AudioVibratorInfo>& vibratorInfos) { |
| 1299 | return Status::fromStatusT(mDelegate->setVibratorInfos(vibratorInfos)); |
| 1300 | } |
| 1301 | |
jiabin | 10a03f1 | 2021-05-07 23:46:28 +0000 | [diff] [blame] | 1302 | Status AudioFlingerServerAdapter::updateSecondaryOutputs( |
| 1303 | const std::vector<media::TrackSecondaryOutputInfo>& trackSecondaryOutputInfos) { |
| 1304 | TrackSecondaryOutputsMap trackSecondaryOutputs = |
| 1305 | VALUE_OR_RETURN_BINDER(convertContainer<TrackSecondaryOutputsMap>( |
| 1306 | trackSecondaryOutputInfos, |
| 1307 | aidl2legacy_TrackSecondaryOutputInfo_TrackSecondaryOutputInfoPair)); |
| 1308 | return Status::fromStatusT(mDelegate->updateSecondaryOutputs(trackSecondaryOutputs)); |
| 1309 | } |
| 1310 | |
Jiabin Huang | ebe6410 | 2021-09-07 20:01:07 +0000 | [diff] [blame] | 1311 | Status AudioFlingerServerAdapter::getMmapPolicyInfos( |
jiabin | e99d088 | 2021-09-17 05:21:25 +0000 | [diff] [blame] | 1312 | AudioMMapPolicyType policyType, std::vector<AudioMMapPolicyInfo> *_aidl_return) { |
Jiabin Huang | ebe6410 | 2021-09-07 20:01:07 +0000 | [diff] [blame] | 1313 | return Status::fromStatusT(mDelegate->getMmapPolicyInfos(policyType, _aidl_return)); |
| 1314 | } |
| 1315 | |
jiabin | e504e7b | 2021-09-18 00:27:08 +0000 | [diff] [blame] | 1316 | Status AudioFlingerServerAdapter::getAAudioMixerBurstCount(int32_t* _aidl_return) { |
| 1317 | *_aidl_return = VALUE_OR_RETURN_BINDER( |
| 1318 | convertIntegral<int32_t>(mDelegate->getAAudioMixerBurstCount())); |
| 1319 | return Status::ok(); |
| 1320 | } |
| 1321 | |
| 1322 | Status AudioFlingerServerAdapter::getAAudioHardwareBurstMinUsec(int32_t* _aidl_return) { |
| 1323 | *_aidl_return = VALUE_OR_RETURN_BINDER( |
| 1324 | convertIntegral<int32_t>(mDelegate->getAAudioHardwareBurstMinUsec())); |
| 1325 | return Status::ok(); |
| 1326 | } |
| 1327 | |
Mikhail Naganov | 516d398 | 2022-02-01 23:53:59 +0000 | [diff] [blame] | 1328 | Status AudioFlingerServerAdapter::setDeviceConnectedState( |
| 1329 | const media::AudioPort& port, bool connected) { |
| 1330 | audio_port_v7 portLegacy = VALUE_OR_RETURN_BINDER(aidl2legacy_AudioPort_audio_port_v7(port)); |
| 1331 | return Status::fromStatusT(mDelegate->setDeviceConnectedState(&portLegacy, connected)); |
| 1332 | } |
| 1333 | |
Eric Laurent | 076e7c7 | 2022-05-03 18:12:28 +0200 | [diff] [blame] | 1334 | Status AudioFlingerServerAdapter::setRequestedLatencyMode( |
| 1335 | int32_t output, media::LatencyMode modeAidl) { |
| 1336 | audio_io_handle_t outputLegacy = VALUE_OR_RETURN_BINDER( |
| 1337 | aidl2legacy_int32_t_audio_io_handle_t(output)); |
| 1338 | audio_latency_mode_t modeLegacy = VALUE_OR_RETURN_BINDER( |
| 1339 | aidl2legacy_LatencyMode_audio_latency_mode_t(modeAidl)); |
| 1340 | return Status::fromStatusT(mDelegate->setRequestedLatencyMode( |
| 1341 | outputLegacy, modeLegacy)); |
| 1342 | } |
| 1343 | |
| 1344 | Status AudioFlingerServerAdapter::getSupportedLatencyModes( |
| 1345 | int output, std::vector<media::LatencyMode>* _aidl_return) { |
| 1346 | audio_io_handle_t outputLegacy = VALUE_OR_RETURN_BINDER( |
| 1347 | aidl2legacy_int32_t_audio_io_handle_t(output)); |
| 1348 | std::vector<audio_latency_mode_t> modesLegacy; |
| 1349 | |
| 1350 | RETURN_BINDER_IF_ERROR(mDelegate->getSupportedLatencyModes(outputLegacy, &modesLegacy)); |
| 1351 | |
| 1352 | *_aidl_return = VALUE_OR_RETURN_BINDER( |
| 1353 | convertContainer<std::vector<media::LatencyMode>>( |
| 1354 | modesLegacy, legacy2aidl_audio_latency_mode_t_LatencyMode)); |
| 1355 | return Status::ok(); |
| 1356 | } |
| 1357 | |
Glenn Kasten | 40bc906 | 2015-03-20 09:09:33 -0700 | [diff] [blame] | 1358 | } // namespace android |