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