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