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