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