Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 1 | /* |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2 | ** |
| 3 | ** Copyright 2007, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #define LOG_TAG "IAudioFlinger" |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 19 | //#define LOG_NDEBUG 0 |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | #include <utils/Log.h> |
| 21 | |
| 22 | #include <stdint.h> |
| 23 | #include <sys/types.h> |
| 24 | |
Eric Laurent | b1cc36b | 2017-12-11 12:14:16 -0800 | [diff] [blame] | 25 | #include <binder/IPCThreadState.h> |
Mathias Agopian | 7562408 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 26 | #include <binder/Parcel.h> |
Eric Laurent | 4dacbc3 | 2020-10-07 13:48:21 -0700 | [diff] [blame] | 27 | #include <media/AudioSanitizer.h> |
Eric Laurent | 14dc3cb | 2020-09-16 18:42:23 -0700 | [diff] [blame] | 28 | #include <media/IAudioPolicyService.h> |
Andy Hung | 4ef19fa | 2018-05-15 19:35:29 -0700 | [diff] [blame] | 29 | #include <mediautils/ServiceUtilities.h> |
Marco Nelissen | cf90b49 | 2019-09-26 11:20:54 -0700 | [diff] [blame] | 30 | #include <mediautils/TimeCheck.h> |
Steven Moreland | 25a9e55 | 2017-04-17 14:30:39 -0700 | [diff] [blame] | 31 | #include "IAudioFlinger.h" |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | |
| 33 | namespace android { |
| 34 | |
| 35 | enum { |
| 36 | CREATE_TRACK = IBinder::FIRST_CALL_TRANSACTION, |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 37 | CREATE_RECORD, |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | SAMPLE_RATE, |
Glenn Kasten | 5876f2f | 2012-11-30 10:52:16 -0800 | [diff] [blame] | 39 | RESERVED, // obsolete, was CHANNEL_COUNT |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | FORMAT, |
| 41 | FRAME_COUNT, |
| 42 | LATENCY, |
| 43 | SET_MASTER_VOLUME, |
| 44 | SET_MASTER_MUTE, |
| 45 | MASTER_VOLUME, |
| 46 | MASTER_MUTE, |
| 47 | SET_STREAM_VOLUME, |
| 48 | SET_STREAM_MUTE, |
| 49 | STREAM_VOLUME, |
| 50 | STREAM_MUTE, |
| 51 | SET_MODE, |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | SET_MIC_MUTE, |
| 53 | GET_MIC_MUTE, |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 54 | SET_RECORD_SILENCED, |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 55 | SET_PARAMETERS, |
| 56 | GET_PARAMETERS, |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | REGISTER_CLIENT, |
| 58 | GET_INPUTBUFFERSIZE, |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 59 | OPEN_OUTPUT, |
| 60 | OPEN_DUPLICATE_OUTPUT, |
| 61 | CLOSE_OUTPUT, |
| 62 | SUSPEND_OUTPUT, |
| 63 | RESTORE_OUTPUT, |
| 64 | OPEN_INPUT, |
| 65 | CLOSE_INPUT, |
Glenn Kasten | d2304db | 2014-02-03 07:40:31 -0800 | [diff] [blame] | 66 | INVALIDATE_STREAM, |
Eric Laurent | 342e9cf | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 67 | SET_VOICE_VOLUME, |
Eric Laurent | 05bca2f | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 68 | GET_RENDER_POSITION, |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 69 | GET_INPUT_FRAMES_LOST, |
Glenn Kasten | 9eae036 | 2016-04-19 09:09:14 -0700 | [diff] [blame] | 70 | NEW_AUDIO_UNIQUE_ID, |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 71 | ACQUIRE_AUDIO_SESSION_ID, |
| 72 | RELEASE_AUDIO_SESSION_ID, |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 73 | QUERY_NUM_EFFECTS, |
Eric Laurent | ffe9c25 | 2010-06-23 17:38:20 -0700 | [diff] [blame] | 74 | QUERY_EFFECT, |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 75 | GET_EFFECT_DESCRIPTOR, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 76 | CREATE_EFFECT, |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 77 | MOVE_EFFECTS, |
Glenn Kasten | cc0f1cf | 2012-09-24 11:27:18 -0700 | [diff] [blame] | 78 | LOAD_HW_MODULE, |
| 79 | GET_PRIMARY_OUTPUT_SAMPLING_RATE, |
| 80 | GET_PRIMARY_OUTPUT_FRAME_COUNT, |
Glenn Kasten | 4182c4e | 2013-07-15 14:45:07 -0700 | [diff] [blame] | 81 | SET_LOW_RAM_DEVICE, |
Eric Laurent | 4b12340 | 2014-04-11 09:22:20 -0700 | [diff] [blame] | 82 | LIST_AUDIO_PORTS, |
| 83 | GET_AUDIO_PORT, |
| 84 | CREATE_AUDIO_PATCH, |
| 85 | RELEASE_AUDIO_PATCH, |
| 86 | LIST_AUDIO_PATCHES, |
Eric Laurent | 93c3d41 | 2014-08-01 14:48:35 -0700 | [diff] [blame] | 87 | SET_AUDIO_PORT_CONFIG, |
Glenn Kasten | 9eae036 | 2016-04-19 09:09:14 -0700 | [diff] [blame] | 88 | GET_AUDIO_HW_SYNC_FOR_SESSION, |
Glenn Kasten | 4a8308b | 2016-04-18 14:10:01 -0700 | [diff] [blame] | 89 | SYSTEM_READY, |
| 90 | FRAME_COUNT_HAL, |
jiabin | 9ff780e | 2018-03-19 18:19:52 -0700 | [diff] [blame] | 91 | GET_MICROPHONES, |
Richard Folke Tullberg | 3fae037 | 2017-01-13 09:04:25 +0100 | [diff] [blame] | 92 | SET_MASTER_BALANCE, |
| 93 | GET_MASTER_BALANCE, |
Eric Laurent | b20cf7d | 2019-04-05 19:37:34 -0700 | [diff] [blame] | 94 | SET_EFFECT_SUSPENDED, |
Eric Laurent | 42896a0 | 2019-09-27 15:40:33 -0700 | [diff] [blame] | 95 | SET_AUDIO_HAL_PIDS |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | }; |
| 97 | |
Eric Laurent | f75c2fe | 2015-04-02 13:49:15 -0700 | [diff] [blame] | 98 | #define MAX_ITEMS_PER_LIST 1024 |
| 99 | |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame^] | 100 | ConversionResult<media::CreateTrackRequest> IAudioFlinger::CreateTrackInput::toAidl() const { |
| 101 | media::CreateTrackRequest aidl; |
| 102 | aidl.attr = VALUE_OR_RETURN(legacy2aidl_audio_attributes_t_AudioAttributesInternal(attr)); |
| 103 | aidl.config = VALUE_OR_RETURN(legacy2aidl_audio_config_t_AudioConfig(config)); |
| 104 | aidl.clientInfo = VALUE_OR_RETURN(legacy2aidl_AudioClient(clientInfo)); |
| 105 | aidl.sharedBuffer = VALUE_OR_RETURN(legacy2aidl_NullableIMemory_SharedFileRegion(sharedBuffer)); |
| 106 | aidl.notificationsPerBuffer = VALUE_OR_RETURN(convertIntegral<int32_t>(notificationsPerBuffer)); |
| 107 | aidl.speed = speed; |
| 108 | aidl.audioTrackCallback = audioTrackCallback; |
| 109 | aidl.opPackageName = opPackageName; |
| 110 | aidl.flags = VALUE_OR_RETURN(legacy2aidl_audio_output_flags_mask(flags)); |
| 111 | aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(frameCount)); |
| 112 | aidl.notificationFrameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(notificationFrameCount)); |
| 113 | aidl.selectedDeviceId = VALUE_OR_RETURN( |
| 114 | legacy2aidl_audio_port_handle_t_int32_t(selectedDeviceId)); |
| 115 | aidl.sessionId = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(sessionId)); |
| 116 | return aidl; |
| 117 | } |
| 118 | |
| 119 | ConversionResult<IAudioFlinger::CreateTrackInput> |
| 120 | IAudioFlinger::CreateTrackInput::fromAidl(const media::CreateTrackRequest& aidl) { |
| 121 | IAudioFlinger::CreateTrackInput legacy; |
| 122 | legacy.attr = VALUE_OR_RETURN(aidl2legacy_AudioAttributesInternal_audio_attributes_t(aidl.attr)); |
| 123 | legacy.config = VALUE_OR_RETURN(aidl2legacy_AudioConfig_audio_config_t(aidl.config)); |
| 124 | legacy.clientInfo = VALUE_OR_RETURN(aidl2legacy_AudioClient(aidl.clientInfo)); |
| 125 | legacy.sharedBuffer = VALUE_OR_RETURN(aidl2legacy_NullableSharedFileRegion_IMemory(aidl.sharedBuffer)); |
| 126 | legacy.notificationsPerBuffer = VALUE_OR_RETURN( |
| 127 | convertIntegral<uint32_t>(aidl.notificationsPerBuffer)); |
| 128 | legacy.speed = aidl.speed; |
| 129 | legacy.audioTrackCallback = aidl.audioTrackCallback; |
| 130 | legacy.opPackageName = aidl.opPackageName; |
| 131 | legacy.flags = VALUE_OR_RETURN(aidl2legacy_audio_output_flags_mask(aidl.flags)); |
| 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 | return legacy; |
| 139 | } |
| 140 | |
| 141 | ConversionResult<media::CreateTrackResponse> |
| 142 | IAudioFlinger::CreateTrackOutput::toAidl() const { |
| 143 | media::CreateTrackResponse aidl; |
| 144 | aidl.flags = VALUE_OR_RETURN(legacy2aidl_audio_output_flags_mask(flags)); |
| 145 | aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(frameCount)); |
| 146 | aidl.notificationFrameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(notificationFrameCount)); |
| 147 | aidl.selectedDeviceId = VALUE_OR_RETURN( |
| 148 | legacy2aidl_audio_port_handle_t_int32_t(selectedDeviceId)); |
| 149 | aidl.sessionId = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(sessionId)); |
| 150 | aidl.sampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(sampleRate)); |
| 151 | aidl.afFrameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(afFrameCount)); |
| 152 | aidl.afSampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(afSampleRate)); |
| 153 | aidl.afLatencyMs = VALUE_OR_RETURN(convertIntegral<int32_t>(afLatencyMs)); |
| 154 | aidl.outputId = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(outputId)); |
| 155 | aidl.portId = VALUE_OR_RETURN(legacy2aidl_audio_port_handle_t_int32_t(portId)); |
| 156 | return aidl; |
| 157 | } |
| 158 | |
| 159 | ConversionResult<IAudioFlinger::CreateTrackOutput> |
| 160 | IAudioFlinger::CreateTrackOutput::fromAidl( |
| 161 | const media::CreateTrackResponse& aidl) { |
| 162 | IAudioFlinger::CreateTrackOutput legacy; |
| 163 | legacy.flags = VALUE_OR_RETURN(aidl2legacy_audio_output_flags_mask(aidl.flags)); |
| 164 | legacy.frameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCount)); |
| 165 | legacy.notificationFrameCount = VALUE_OR_RETURN( |
| 166 | convertIntegral<size_t>(aidl.notificationFrameCount)); |
| 167 | legacy.selectedDeviceId = VALUE_OR_RETURN( |
| 168 | aidl2legacy_int32_t_audio_port_handle_t(aidl.selectedDeviceId)); |
| 169 | legacy.sessionId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_session_t(aidl.sessionId)); |
| 170 | legacy.sampleRate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.sampleRate)); |
| 171 | legacy.afFrameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.afFrameCount)); |
| 172 | legacy.afSampleRate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.afSampleRate)); |
| 173 | legacy.afLatencyMs = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.afLatencyMs)); |
| 174 | legacy.outputId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_io_handle_t(aidl.outputId)); |
| 175 | legacy.portId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_port_handle_t(aidl.portId)); |
| 176 | return legacy; |
| 177 | } |
| 178 | |
| 179 | ConversionResult<media::CreateRecordRequest> |
| 180 | IAudioFlinger::CreateRecordInput::toAidl() const { |
| 181 | media::CreateRecordRequest aidl; |
| 182 | aidl.attr = VALUE_OR_RETURN(legacy2aidl_audio_attributes_t_AudioAttributesInternal(attr)); |
| 183 | aidl.config = VALUE_OR_RETURN(legacy2aidl_audio_config_base_t_AudioConfigBase(config)); |
| 184 | aidl.clientInfo = VALUE_OR_RETURN(legacy2aidl_AudioClient(clientInfo)); |
| 185 | aidl.opPackageName = VALUE_OR_RETURN(legacy2aidl_String16_string(opPackageName)); |
| 186 | aidl.riid = VALUE_OR_RETURN(legacy2aidl_audio_unique_id_t_int32_t(riid)); |
| 187 | aidl.flags = VALUE_OR_RETURN(legacy2aidl_audio_input_flags_mask(flags)); |
| 188 | aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(frameCount)); |
| 189 | aidl.notificationFrameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(notificationFrameCount)); |
| 190 | aidl.selectedDeviceId = VALUE_OR_RETURN( |
| 191 | legacy2aidl_audio_port_handle_t_int32_t(selectedDeviceId)); |
| 192 | aidl.sessionId = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(sessionId)); |
| 193 | return aidl; |
| 194 | } |
| 195 | |
| 196 | ConversionResult<IAudioFlinger::CreateRecordInput> |
| 197 | IAudioFlinger::CreateRecordInput::fromAidl( |
| 198 | const media::CreateRecordRequest& aidl) { |
| 199 | IAudioFlinger::CreateRecordInput legacy; |
| 200 | legacy.attr = VALUE_OR_RETURN(aidl2legacy_AudioAttributesInternal_audio_attributes_t(aidl.attr)); |
| 201 | legacy.config = VALUE_OR_RETURN(aidl2legacy_AudioConfigBase_audio_config_base_t(aidl.config)); |
| 202 | legacy.clientInfo = VALUE_OR_RETURN(aidl2legacy_AudioClient(aidl.clientInfo)); |
| 203 | legacy.opPackageName = VALUE_OR_RETURN(aidl2legacy_string_view_String16(aidl.opPackageName)); |
| 204 | legacy.riid = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_unique_id_t(aidl.riid)); |
| 205 | legacy.flags = VALUE_OR_RETURN(aidl2legacy_audio_input_flags_mask(aidl.flags)); |
| 206 | legacy.frameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCount)); |
| 207 | legacy.notificationFrameCount = VALUE_OR_RETURN( |
| 208 | convertIntegral<size_t>(aidl.notificationFrameCount)); |
| 209 | legacy.selectedDeviceId = VALUE_OR_RETURN( |
| 210 | aidl2legacy_int32_t_audio_port_handle_t(aidl.selectedDeviceId)); |
| 211 | legacy.sessionId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_session_t(aidl.sessionId)); |
| 212 | return legacy; |
| 213 | } |
| 214 | |
| 215 | ConversionResult<media::CreateRecordResponse> |
| 216 | IAudioFlinger::CreateRecordOutput::toAidl() const { |
| 217 | media::CreateRecordResponse aidl; |
| 218 | aidl.flags = VALUE_OR_RETURN(legacy2aidl_audio_input_flags_mask(flags)); |
| 219 | aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(frameCount)); |
| 220 | aidl.notificationFrameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(notificationFrameCount)); |
| 221 | aidl.selectedDeviceId = VALUE_OR_RETURN( |
| 222 | legacy2aidl_audio_port_handle_t_int32_t(selectedDeviceId)); |
| 223 | aidl.sessionId = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(sessionId)); |
| 224 | aidl.sampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(sampleRate)); |
| 225 | aidl.inputId = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(inputId)); |
| 226 | aidl.cblk = VALUE_OR_RETURN(legacy2aidl_NullableIMemory_SharedFileRegion(cblk)); |
| 227 | aidl.buffers = VALUE_OR_RETURN(legacy2aidl_NullableIMemory_SharedFileRegion(buffers)); |
| 228 | aidl.portId = VALUE_OR_RETURN(legacy2aidl_audio_port_handle_t_int32_t(portId)); |
| 229 | return aidl; |
| 230 | } |
| 231 | |
| 232 | ConversionResult<IAudioFlinger::CreateRecordOutput> |
| 233 | IAudioFlinger::CreateRecordOutput::fromAidl( |
| 234 | const media::CreateRecordResponse& aidl) { |
| 235 | IAudioFlinger::CreateRecordOutput legacy; |
| 236 | legacy.flags = VALUE_OR_RETURN(aidl2legacy_audio_input_flags_mask(aidl.flags)); |
| 237 | legacy.frameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCount)); |
| 238 | legacy.notificationFrameCount = VALUE_OR_RETURN( |
| 239 | convertIntegral<size_t>(aidl.notificationFrameCount)); |
| 240 | legacy.selectedDeviceId = VALUE_OR_RETURN( |
| 241 | aidl2legacy_int32_t_audio_port_handle_t(aidl.selectedDeviceId)); |
| 242 | legacy.sessionId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_session_t(aidl.sessionId)); |
| 243 | legacy.sampleRate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.sampleRate)); |
| 244 | legacy.inputId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_io_handle_t(aidl.inputId)); |
| 245 | legacy.cblk = VALUE_OR_RETURN(aidl2legacy_NullableSharedFileRegion_IMemory(aidl.cblk)); |
| 246 | legacy.buffers = VALUE_OR_RETURN(aidl2legacy_NullableSharedFileRegion_IMemory(aidl.buffers)); |
| 247 | legacy.portId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_port_handle_t(aidl.portId)); |
| 248 | return legacy; |
| 249 | } |
Eric Laurent | 42896a0 | 2019-09-27 15:40:33 -0700 | [diff] [blame] | 250 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | class BpAudioFlinger : public BpInterface<IAudioFlinger> |
| 252 | { |
| 253 | public: |
Chih-Hung Hsieh | 090ef60 | 2016-04-27 10:39:54 -0700 | [diff] [blame] | 254 | explicit BpAudioFlinger(const sp<IBinder>& impl) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 | : BpInterface<IAudioFlinger>(impl) |
| 256 | { |
| 257 | } |
| 258 | |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame^] | 259 | virtual sp<IAudioTrack> createTrack(const media::CreateTrackRequest& input, |
| 260 | media::CreateTrackResponse& output, |
| 261 | status_t* status) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 262 | { |
| 263 | Parcel data, reply; |
Eric Laurent | 5841db7 | 2009-09-09 05:16:08 -0700 | [diff] [blame] | 264 | sp<IAudioTrack> track; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 265 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 266 | |
| 267 | if (status == nullptr) { |
| 268 | return track; |
Eric Laurent | 3d00aa6 | 2013-09-24 09:53:27 -0700 | [diff] [blame] | 269 | } |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 270 | |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame^] | 271 | data.writeParcelable(input); |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 272 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 273 | status_t lStatus = remote()->transact(CREATE_TRACK, data, &reply); |
| 274 | if (lStatus != NO_ERROR) { |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 275 | ALOGE("createTrack transaction error %d", lStatus); |
| 276 | *status = DEAD_OBJECT; |
| 277 | return track; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 278 | } |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 279 | *status = reply.readInt32(); |
| 280 | if (*status != NO_ERROR) { |
| 281 | ALOGE("createTrack returned error %d", *status); |
| 282 | return track; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 283 | } |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 284 | track = interface_cast<IAudioTrack>(reply.readStrongBinder()); |
| 285 | if (track == 0) { |
| 286 | ALOGE("createTrack returned an NULL IAudioTrack with status OK"); |
| 287 | *status = DEAD_OBJECT; |
| 288 | return track; |
| 289 | } |
| 290 | output.readFromParcel(&reply); |
Eric Laurent | 5841db7 | 2009-09-09 05:16:08 -0700 | [diff] [blame] | 291 | return track; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 292 | } |
| 293 | |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame^] | 294 | virtual sp<media::IAudioRecord> createRecord(const media::CreateRecordRequest& input, |
| 295 | media::CreateRecordResponse& output, |
| 296 | status_t* status) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 297 | { |
| 298 | Parcel data, reply; |
Ivan Lozano | ff6900d | 2017-08-01 15:47:38 -0700 | [diff] [blame] | 299 | sp<media::IAudioRecord> record; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 300 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 301 | |
| 302 | if (status == nullptr) { |
| 303 | return record; |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 304 | } |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 305 | |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame^] | 306 | data.writeParcelable(input); |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 307 | |
| 308 | status_t lStatus = remote()->transact(CREATE_RECORD, data, &reply); |
Eric Laurent | 5841db7 | 2009-09-09 05:16:08 -0700 | [diff] [blame] | 309 | if (lStatus != NO_ERROR) { |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 310 | ALOGE("createRecord transaction error %d", lStatus); |
| 311 | *status = DEAD_OBJECT; |
| 312 | return record; |
Eric Laurent | 5841db7 | 2009-09-09 05:16:08 -0700 | [diff] [blame] | 313 | } |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 314 | *status = reply.readInt32(); |
| 315 | if (*status != NO_ERROR) { |
| 316 | ALOGE("createRecord returned error %d", *status); |
| 317 | return record; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 318 | } |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 319 | |
| 320 | record = interface_cast<media::IAudioRecord>(reply.readStrongBinder()); |
| 321 | if (record == 0) { |
| 322 | ALOGE("createRecord returned a NULL IAudioRecord with status OK"); |
| 323 | *status = DEAD_OBJECT; |
| 324 | return record; |
| 325 | } |
| 326 | output.readFromParcel(&reply); |
Eric Laurent | 5841db7 | 2009-09-09 05:16:08 -0700 | [diff] [blame] | 327 | return record; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 328 | } |
| 329 | |
Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 330 | virtual uint32_t sampleRate(audio_io_handle_t ioHandle) const |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 331 | { |
| 332 | Parcel data, reply; |
| 333 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 334 | data.writeInt32((int32_t) ioHandle); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 335 | remote()->transact(SAMPLE_RATE, data, &reply); |
| 336 | return reply.readInt32(); |
| 337 | } |
| 338 | |
Glenn Kasten | 4a8308b | 2016-04-18 14:10:01 -0700 | [diff] [blame] | 339 | // RESERVED for channelCount() |
| 340 | |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 341 | virtual audio_format_t format(audio_io_handle_t output) const |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 342 | { |
| 343 | Parcel data, reply; |
| 344 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 345 | data.writeInt32((int32_t) output); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 346 | remote()->transact(FORMAT, data, &reply); |
Glenn Kasten | 58f3021 | 2012-01-12 12:27:51 -0800 | [diff] [blame] | 347 | return (audio_format_t) reply.readInt32(); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 348 | } |
| 349 | |
Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 350 | virtual size_t frameCount(audio_io_handle_t ioHandle) const |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 351 | { |
| 352 | Parcel data, reply; |
| 353 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 354 | data.writeInt32((int32_t) ioHandle); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 355 | remote()->transact(FRAME_COUNT, data, &reply); |
Glenn Kasten | e03dd22 | 2014-01-28 11:04:39 -0800 | [diff] [blame] | 356 | return reply.readInt64(); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 357 | } |
| 358 | |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 359 | virtual uint32_t latency(audio_io_handle_t output) const |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 360 | { |
| 361 | Parcel data, reply; |
| 362 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 363 | data.writeInt32((int32_t) output); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 364 | remote()->transact(LATENCY, data, &reply); |
| 365 | return reply.readInt32(); |
| 366 | } |
| 367 | |
| 368 | virtual status_t setMasterVolume(float value) |
| 369 | { |
| 370 | Parcel data, reply; |
| 371 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 372 | data.writeFloat(value); |
| 373 | remote()->transact(SET_MASTER_VOLUME, data, &reply); |
| 374 | return reply.readInt32(); |
| 375 | } |
| 376 | |
| 377 | virtual status_t setMasterMute(bool muted) |
| 378 | { |
| 379 | Parcel data, reply; |
| 380 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 381 | data.writeInt32(muted); |
| 382 | remote()->transact(SET_MASTER_MUTE, data, &reply); |
| 383 | return reply.readInt32(); |
| 384 | } |
| 385 | |
| 386 | virtual float masterVolume() const |
| 387 | { |
| 388 | Parcel data, reply; |
| 389 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 390 | remote()->transact(MASTER_VOLUME, data, &reply); |
| 391 | return reply.readFloat(); |
| 392 | } |
| 393 | |
| 394 | virtual bool masterMute() const |
| 395 | { |
| 396 | Parcel data, reply; |
| 397 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 398 | remote()->transact(MASTER_MUTE, data, &reply); |
| 399 | return reply.readInt32(); |
| 400 | } |
| 401 | |
Richard Folke Tullberg | 3fae037 | 2017-01-13 09:04:25 +0100 | [diff] [blame] | 402 | status_t setMasterBalance(float balance) override |
| 403 | { |
| 404 | Parcel data, reply; |
| 405 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 406 | data.writeFloat(balance); |
| 407 | status_t status = remote()->transact(SET_MASTER_BALANCE, data, &reply); |
| 408 | if (status != NO_ERROR) { |
| 409 | return status; |
| 410 | } |
| 411 | return reply.readInt32(); |
| 412 | } |
| 413 | |
| 414 | status_t getMasterBalance(float *balance) const override |
| 415 | { |
| 416 | Parcel data, reply; |
| 417 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 418 | status_t status = remote()->transact(GET_MASTER_BALANCE, data, &reply); |
| 419 | if (status != NO_ERROR) { |
| 420 | return status; |
| 421 | } |
| 422 | status = (status_t)reply.readInt32(); |
| 423 | if (status != NO_ERROR) { |
| 424 | return status; |
| 425 | } |
| 426 | *balance = reply.readFloat(); |
| 427 | return NO_ERROR; |
| 428 | } |
| 429 | |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 430 | virtual status_t setStreamVolume(audio_stream_type_t stream, float value, |
| 431 | audio_io_handle_t output) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 432 | { |
| 433 | Parcel data, reply; |
| 434 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 435 | data.writeInt32((int32_t) stream); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 436 | data.writeFloat(value); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 437 | data.writeInt32((int32_t) output); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 438 | remote()->transact(SET_STREAM_VOLUME, data, &reply); |
| 439 | return reply.readInt32(); |
| 440 | } |
| 441 | |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 442 | virtual status_t setStreamMute(audio_stream_type_t stream, bool muted) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 443 | { |
| 444 | Parcel data, reply; |
| 445 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 446 | data.writeInt32((int32_t) stream); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 447 | data.writeInt32(muted); |
| 448 | remote()->transact(SET_STREAM_MUTE, data, &reply); |
| 449 | return reply.readInt32(); |
| 450 | } |
| 451 | |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 452 | virtual float streamVolume(audio_stream_type_t stream, audio_io_handle_t output) const |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 453 | { |
| 454 | Parcel data, reply; |
| 455 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 456 | data.writeInt32((int32_t) stream); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 457 | data.writeInt32((int32_t) output); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 458 | remote()->transact(STREAM_VOLUME, data, &reply); |
| 459 | return reply.readFloat(); |
| 460 | } |
| 461 | |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 462 | virtual bool streamMute(audio_stream_type_t stream) const |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 463 | { |
| 464 | Parcel data, reply; |
| 465 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 466 | data.writeInt32((int32_t) stream); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 467 | remote()->transact(STREAM_MUTE, data, &reply); |
| 468 | return reply.readInt32(); |
| 469 | } |
| 470 | |
Glenn Kasten | f78aee7 | 2012-01-04 11:00:47 -0800 | [diff] [blame] | 471 | virtual status_t setMode(audio_mode_t mode) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 472 | { |
| 473 | Parcel data, reply; |
| 474 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 475 | data.writeInt32(mode); |
| 476 | remote()->transact(SET_MODE, data, &reply); |
| 477 | return reply.readInt32(); |
| 478 | } |
| 479 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 480 | virtual status_t setMicMute(bool state) |
| 481 | { |
| 482 | Parcel data, reply; |
| 483 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 484 | data.writeInt32(state); |
| 485 | remote()->transact(SET_MIC_MUTE, data, &reply); |
| 486 | return reply.readInt32(); |
| 487 | } |
| 488 | |
| 489 | virtual bool getMicMute() const |
| 490 | { |
| 491 | Parcel data, reply; |
| 492 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 493 | remote()->transact(GET_MIC_MUTE, data, &reply); |
| 494 | return reply.readInt32(); |
| 495 | } |
| 496 | |
Eric Laurent | 5ada82e | 2019-08-29 17:53:54 -0700 | [diff] [blame] | 497 | virtual void setRecordSilenced(audio_port_handle_t portId, bool silenced) |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 498 | { |
| 499 | Parcel data, reply; |
| 500 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Eric Laurent | 5ada82e | 2019-08-29 17:53:54 -0700 | [diff] [blame] | 501 | data.writeInt32(portId); |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 502 | data.writeInt32(silenced ? 1 : 0); |
| 503 | remote()->transact(SET_RECORD_SILENCED, data, &reply); |
| 504 | } |
| 505 | |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 506 | virtual status_t setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 507 | { |
| 508 | Parcel data, reply; |
| 509 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 510 | data.writeInt32((int32_t) ioHandle); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 511 | data.writeString8(keyValuePairs); |
| 512 | remote()->transact(SET_PARAMETERS, data, &reply); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 513 | return reply.readInt32(); |
| 514 | } |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 515 | |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 516 | virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys) const |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 517 | { |
| 518 | Parcel data, reply; |
| 519 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 520 | data.writeInt32((int32_t) ioHandle); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 521 | data.writeString8(keys); |
| 522 | remote()->transact(GET_PARAMETERS, data, &reply); |
| 523 | return reply.readString8(); |
| 524 | } |
| 525 | |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 526 | virtual void registerClient(const sp<media::IAudioFlingerClient>& client) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 527 | { |
| 528 | Parcel data, reply; |
| 529 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 530 | data.writeStrongBinder(IInterface::asBinder(client)); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 531 | remote()->transact(REGISTER_CLIENT, data, &reply); |
| 532 | } |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 533 | |
Glenn Kasten | dd8104c | 2012-07-02 12:42:44 -0700 | [diff] [blame] | 534 | virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format, |
| 535 | audio_channel_mask_t channelMask) const |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 536 | { |
| 537 | Parcel data, reply; |
| 538 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 539 | data.writeInt32(sampleRate); |
| 540 | data.writeInt32(format); |
Glenn Kasten | dd8104c | 2012-07-02 12:42:44 -0700 | [diff] [blame] | 541 | data.writeInt32(channelMask); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 542 | remote()->transact(GET_INPUTBUFFERSIZE, data, &reply); |
Glenn Kasten | e03dd22 | 2014-01-28 11:04:39 -0800 | [diff] [blame] | 543 | return reply.readInt64(); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 544 | } |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 545 | |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 546 | virtual status_t openOutput(audio_module_handle_t module, |
| 547 | audio_io_handle_t *output, |
| 548 | audio_config_t *config, |
jiabin | 4381040 | 2019-10-24 14:58:31 -0700 | [diff] [blame] | 549 | const sp<DeviceDescriptorBase>& device, |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 550 | uint32_t *latencyMs, |
| 551 | audio_output_flags_t flags) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 552 | { |
jiabin | 4381040 | 2019-10-24 14:58:31 -0700 | [diff] [blame] | 553 | if (output == nullptr || config == nullptr || device == nullptr || latencyMs == nullptr) { |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 554 | return BAD_VALUE; |
| 555 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 556 | Parcel data, reply; |
| 557 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 558 | data.writeInt32(module); |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 559 | data.write(config, sizeof(audio_config_t)); |
jiabin | 4381040 | 2019-10-24 14:58:31 -0700 | [diff] [blame] | 560 | data.writeParcelable(*device); |
Glenn Kasten | 18868c5 | 2012-03-07 09:15:37 -0800 | [diff] [blame] | 561 | data.writeInt32((int32_t) flags); |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 562 | status_t status = remote()->transact(OPEN_OUTPUT, data, &reply); |
| 563 | if (status != NO_ERROR) { |
| 564 | *output = AUDIO_IO_HANDLE_NONE; |
| 565 | return status; |
Richard Fitzgerald | b1a270d | 2013-05-14 12:12:21 +0100 | [diff] [blame] | 566 | } |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 567 | status = (status_t)reply.readInt32(); |
| 568 | if (status != NO_ERROR) { |
| 569 | *output = AUDIO_IO_HANDLE_NONE; |
| 570 | return status; |
Glenn Kasten | 507b286 | 2013-07-31 16:12:13 -0700 | [diff] [blame] | 571 | } |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 572 | *output = (audio_io_handle_t)reply.readInt32(); |
| 573 | ALOGV("openOutput() returned output, %d", *output); |
| 574 | reply.read(config, sizeof(audio_config_t)); |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 575 | *latencyMs = reply.readInt32(); |
| 576 | return NO_ERROR; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 577 | } |
| 578 | |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 579 | virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1, |
| 580 | audio_io_handle_t output2) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 581 | { |
| 582 | Parcel data, reply; |
| 583 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 584 | data.writeInt32((int32_t) output1); |
| 585 | data.writeInt32((int32_t) output2); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 586 | remote()->transact(OPEN_DUPLICATE_OUTPUT, data, &reply); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 587 | return (audio_io_handle_t) reply.readInt32(); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 588 | } |
| 589 | |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 590 | virtual status_t closeOutput(audio_io_handle_t output) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 591 | { |
| 592 | Parcel data, reply; |
| 593 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 594 | data.writeInt32((int32_t) output); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 595 | remote()->transact(CLOSE_OUTPUT, data, &reply); |
| 596 | return reply.readInt32(); |
| 597 | } |
| 598 | |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 599 | virtual status_t suspendOutput(audio_io_handle_t output) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 600 | { |
| 601 | Parcel data, reply; |
| 602 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 603 | data.writeInt32((int32_t) output); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 604 | remote()->transact(SUSPEND_OUTPUT, data, &reply); |
| 605 | return reply.readInt32(); |
| 606 | } |
| 607 | |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 608 | virtual status_t restoreOutput(audio_io_handle_t output) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 609 | { |
| 610 | Parcel data, reply; |
| 611 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 612 | data.writeInt32((int32_t) output); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 613 | remote()->transact(RESTORE_OUTPUT, data, &reply); |
| 614 | return reply.readInt32(); |
| 615 | } |
| 616 | |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 617 | virtual status_t openInput(audio_module_handle_t module, |
| 618 | audio_io_handle_t *input, |
| 619 | audio_config_t *config, |
| 620 | audio_devices_t *device, |
| 621 | const String8& address, |
| 622 | audio_source_t source, |
| 623 | audio_input_flags_t flags) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 624 | { |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 625 | if (input == NULL || config == NULL || device == NULL) { |
| 626 | return BAD_VALUE; |
| 627 | } |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 628 | Parcel data, reply; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 629 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 630 | data.writeInt32(module); |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 631 | data.writeInt32(*input); |
| 632 | data.write(config, sizeof(audio_config_t)); |
| 633 | data.writeInt32(*device); |
| 634 | data.writeString8(address); |
| 635 | data.writeInt32(source); |
Glenn Kasten | ec40d28 | 2014-07-15 15:31:26 -0700 | [diff] [blame] | 636 | data.writeInt32(flags); |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 637 | status_t status = remote()->transact(OPEN_INPUT, data, &reply); |
| 638 | if (status != NO_ERROR) { |
| 639 | *input = AUDIO_IO_HANDLE_NONE; |
| 640 | return status; |
Glenn Kasten | 507b286 | 2013-07-31 16:12:13 -0700 | [diff] [blame] | 641 | } |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 642 | status = (status_t)reply.readInt32(); |
| 643 | if (status != NO_ERROR) { |
| 644 | *input = AUDIO_IO_HANDLE_NONE; |
| 645 | return status; |
Glenn Kasten | 507b286 | 2013-07-31 16:12:13 -0700 | [diff] [blame] | 646 | } |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 647 | *input = (audio_io_handle_t)reply.readInt32(); |
| 648 | reply.read(config, sizeof(audio_config_t)); |
| 649 | *device = (audio_devices_t)reply.readInt32(); |
| 650 | return NO_ERROR; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 651 | } |
| 652 | |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 653 | virtual status_t closeInput(int input) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 654 | { |
| 655 | Parcel data, reply; |
| 656 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 657 | data.writeInt32(input); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 658 | remote()->transact(CLOSE_INPUT, data, &reply); |
| 659 | return reply.readInt32(); |
| 660 | } |
| 661 | |
Glenn Kasten | d2304db | 2014-02-03 07:40:31 -0800 | [diff] [blame] | 662 | virtual status_t invalidateStream(audio_stream_type_t stream) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 663 | { |
| 664 | Parcel data, reply; |
| 665 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 666 | data.writeInt32((int32_t) stream); |
Glenn Kasten | d2304db | 2014-02-03 07:40:31 -0800 | [diff] [blame] | 667 | remote()->transact(INVALIDATE_STREAM, data, &reply); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 668 | return reply.readInt32(); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 669 | } |
Eric Laurent | f0ee6f4 | 2009-10-21 08:14:22 -0700 | [diff] [blame] | 670 | |
| 671 | virtual status_t setVoiceVolume(float volume) |
| 672 | { |
| 673 | Parcel data, reply; |
| 674 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 675 | data.writeFloat(volume); |
| 676 | remote()->transact(SET_VOICE_VOLUME, data, &reply); |
| 677 | return reply.readInt32(); |
| 678 | } |
Eric Laurent | 342e9cf | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 679 | |
Kévin PETIT | 377b2ec | 2014-02-03 12:35:36 +0000 | [diff] [blame] | 680 | virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames, |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 681 | audio_io_handle_t output) const |
Eric Laurent | 342e9cf | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 682 | { |
| 683 | Parcel data, reply; |
| 684 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 685 | data.writeInt32((int32_t) output); |
Eric Laurent | 342e9cf | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 686 | remote()->transact(GET_RENDER_POSITION, data, &reply); |
| 687 | status_t status = reply.readInt32(); |
| 688 | if (status == NO_ERROR) { |
| 689 | uint32_t tmp = reply.readInt32(); |
Glenn Kasten | 507b286 | 2013-07-31 16:12:13 -0700 | [diff] [blame] | 690 | if (halFrames != NULL) { |
Eric Laurent | 342e9cf | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 691 | *halFrames = tmp; |
| 692 | } |
| 693 | tmp = reply.readInt32(); |
Glenn Kasten | 507b286 | 2013-07-31 16:12:13 -0700 | [diff] [blame] | 694 | if (dspFrames != NULL) { |
Eric Laurent | 342e9cf | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 695 | *dspFrames = tmp; |
| 696 | } |
| 697 | } |
| 698 | return status; |
| 699 | } |
Eric Laurent | 05bca2f | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 700 | |
Glenn Kasten | 5f972c0 | 2014-01-13 09:59:31 -0800 | [diff] [blame] | 701 | virtual uint32_t getInputFramesLost(audio_io_handle_t ioHandle) const |
Eric Laurent | 05bca2f | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 702 | { |
| 703 | Parcel data, reply; |
| 704 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 705 | data.writeInt32((int32_t) ioHandle); |
Glenn Kasten | 5f972c0 | 2014-01-13 09:59:31 -0800 | [diff] [blame] | 706 | status_t status = remote()->transact(GET_INPUT_FRAMES_LOST, data, &reply); |
| 707 | if (status != NO_ERROR) { |
| 708 | return 0; |
| 709 | } |
| 710 | return (uint32_t) reply.readInt32(); |
Eric Laurent | 05bca2f | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 711 | } |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 712 | |
Glenn Kasten | eeecb98 | 2016-02-26 10:44:04 -0800 | [diff] [blame] | 713 | virtual audio_unique_id_t newAudioUniqueId(audio_unique_id_use_t use) |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 714 | { |
| 715 | Parcel data, reply; |
| 716 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Glenn Kasten | eeecb98 | 2016-02-26 10:44:04 -0800 | [diff] [blame] | 717 | data.writeInt32((int32_t) use); |
Glenn Kasten | 9eae036 | 2016-04-19 09:09:14 -0700 | [diff] [blame] | 718 | status_t status = remote()->transact(NEW_AUDIO_UNIQUE_ID, data, &reply); |
| 719 | audio_unique_id_t id = AUDIO_UNIQUE_ID_ALLOCATE; |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 720 | if (status == NO_ERROR) { |
| 721 | id = reply.readInt32(); |
| 722 | } |
| 723 | return id; |
| 724 | } |
| 725 | |
Andy Hung | 8b0bfd9 | 2019-12-23 13:11:11 -0800 | [diff] [blame] | 726 | void acquireAudioSessionId(audio_session_t audioSession, pid_t pid, uid_t uid) override |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 727 | { |
| 728 | Parcel data, reply; |
| 729 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 730 | data.writeInt32(audioSession); |
Andy Hung | 8b0bfd9 | 2019-12-23 13:11:11 -0800 | [diff] [blame] | 731 | data.writeInt32((int32_t)pid); |
| 732 | data.writeInt32((int32_t)uid); |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 733 | remote()->transact(ACQUIRE_AUDIO_SESSION_ID, data, &reply); |
| 734 | } |
| 735 | |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 736 | virtual void releaseAudioSessionId(audio_session_t audioSession, int pid) |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 737 | { |
| 738 | Parcel data, reply; |
| 739 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 740 | data.writeInt32(audioSession); |
Marco Nelissen | d457c97 | 2014-02-11 08:47:07 -0800 | [diff] [blame] | 741 | data.writeInt32(pid); |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 742 | remote()->transact(RELEASE_AUDIO_SESSION_ID, data, &reply); |
| 743 | } |
| 744 | |
Glenn Kasten | f587ba5 | 2012-01-26 16:25:10 -0800 | [diff] [blame] | 745 | virtual status_t queryNumberEffects(uint32_t *numEffects) const |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 746 | { |
| 747 | Parcel data, reply; |
| 748 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 749 | status_t status = remote()->transact(QUERY_NUM_EFFECTS, data, &reply); |
| 750 | if (status != NO_ERROR) { |
| 751 | return status; |
| 752 | } |
| 753 | status = reply.readInt32(); |
| 754 | if (status != NO_ERROR) { |
| 755 | return status; |
| 756 | } |
Glenn Kasten | 9d1f02d | 2012-02-08 17:47:58 -0800 | [diff] [blame] | 757 | if (numEffects != NULL) { |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 758 | *numEffects = (uint32_t)reply.readInt32(); |
| 759 | } |
| 760 | return NO_ERROR; |
| 761 | } |
| 762 | |
Glenn Kasten | f587ba5 | 2012-01-26 16:25:10 -0800 | [diff] [blame] | 763 | virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) const |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 764 | { |
| 765 | if (pDescriptor == NULL) { |
| 766 | return BAD_VALUE; |
| 767 | } |
| 768 | Parcel data, reply; |
| 769 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Eric Laurent | ffe9c25 | 2010-06-23 17:38:20 -0700 | [diff] [blame] | 770 | data.writeInt32(index); |
| 771 | status_t status = remote()->transact(QUERY_EFFECT, data, &reply); |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 772 | if (status != NO_ERROR) { |
| 773 | return status; |
| 774 | } |
| 775 | status = reply.readInt32(); |
| 776 | if (status != NO_ERROR) { |
| 777 | return status; |
| 778 | } |
| 779 | reply.read(pDescriptor, sizeof(effect_descriptor_t)); |
| 780 | return NO_ERROR; |
| 781 | } |
| 782 | |
Glenn Kasten | 5e92a78 | 2012-01-30 07:40:52 -0800 | [diff] [blame] | 783 | virtual status_t getEffectDescriptor(const effect_uuid_t *pUuid, |
Ari Hausman-Cohen | 2046ec7 | 2018-04-24 14:00:55 -0700 | [diff] [blame] | 784 | const effect_uuid_t *pType, |
| 785 | uint32_t preferredTypeFlag, |
| 786 | effect_descriptor_t *pDescriptor) const |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 787 | { |
Ari Hausman-Cohen | 2046ec7 | 2018-04-24 14:00:55 -0700 | [diff] [blame] | 788 | if (pUuid == NULL || pType == NULL || pDescriptor == NULL) { |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 789 | return BAD_VALUE; |
| 790 | } |
| 791 | Parcel data, reply; |
| 792 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 793 | data.write(pUuid, sizeof(effect_uuid_t)); |
Ari Hausman-Cohen | 2046ec7 | 2018-04-24 14:00:55 -0700 | [diff] [blame] | 794 | data.write(pType, sizeof(effect_uuid_t)); |
| 795 | data.writeUint32(preferredTypeFlag); |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 796 | status_t status = remote()->transact(GET_EFFECT_DESCRIPTOR, data, &reply); |
| 797 | if (status != NO_ERROR) { |
| 798 | return status; |
| 799 | } |
| 800 | status = reply.readInt32(); |
| 801 | if (status != NO_ERROR) { |
| 802 | return status; |
| 803 | } |
| 804 | reply.read(pDescriptor, sizeof(effect_descriptor_t)); |
| 805 | return NO_ERROR; |
| 806 | } |
| 807 | |
Ytai Ben-Tsvi | 9cd8981 | 2020-07-01 17:12:06 -0700 | [diff] [blame] | 808 | virtual sp<media::IEffect> createEffect( |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 809 | effect_descriptor_t *pDesc, |
Ytai Ben-Tsvi | 9cd8981 | 2020-07-01 17:12:06 -0700 | [diff] [blame] | 810 | const sp<media::IEffectClient>& client, |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 811 | int32_t priority, |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 812 | audio_io_handle_t output, |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 813 | audio_session_t sessionId, |
Eric Laurent | 9487603 | 2019-11-13 12:45:28 -0800 | [diff] [blame] | 814 | const AudioDeviceTypeAddr& device, |
Svet Ganov | be71aa2 | 2015-04-28 12:06:02 -0700 | [diff] [blame] | 815 | const String16& opPackageName, |
Eric Laurent | b643627 | 2016-12-07 19:24:50 -0800 | [diff] [blame] | 816 | pid_t pid, |
Eric Laurent | 2fe0acd | 2020-03-13 14:30:46 -0700 | [diff] [blame] | 817 | bool probe, |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 818 | status_t *status, |
| 819 | int *id, |
| 820 | int *enabled) |
| 821 | { |
| 822 | Parcel data, reply; |
Ytai Ben-Tsvi | 9cd8981 | 2020-07-01 17:12:06 -0700 | [diff] [blame] | 823 | sp<media::IEffect> effect; |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 824 | if (pDesc == NULL) { |
Glenn Kasten | 507b286 | 2013-07-31 16:12:13 -0700 | [diff] [blame] | 825 | if (status != NULL) { |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 826 | *status = BAD_VALUE; |
| 827 | } |
Eric Laurent | 9487603 | 2019-11-13 12:45:28 -0800 | [diff] [blame] | 828 | return nullptr; |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 829 | } |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 830 | |
| 831 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 832 | data.write(pDesc, sizeof(effect_descriptor_t)); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 833 | data.writeStrongBinder(IInterface::asBinder(client)); |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 834 | data.writeInt32(priority); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 835 | data.writeInt32((int32_t) output); |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 836 | data.writeInt32(sessionId); |
Eric Laurent | 9487603 | 2019-11-13 12:45:28 -0800 | [diff] [blame] | 837 | if (data.writeParcelable(device) != NO_ERROR) { |
| 838 | if (status != NULL) { |
| 839 | *status = NO_INIT; |
| 840 | } |
| 841 | return nullptr; |
| 842 | } |
Svet Ganov | be71aa2 | 2015-04-28 12:06:02 -0700 | [diff] [blame] | 843 | data.writeString16(opPackageName); |
Eric Laurent | b643627 | 2016-12-07 19:24:50 -0800 | [diff] [blame] | 844 | data.writeInt32((int32_t) pid); |
Eric Laurent | 2fe0acd | 2020-03-13 14:30:46 -0700 | [diff] [blame] | 845 | data.writeInt32(probe ? 1 : 0); |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 846 | |
| 847 | status_t lStatus = remote()->transact(CREATE_EFFECT, data, &reply); |
| 848 | if (lStatus != NO_ERROR) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 849 | ALOGE("createEffect error: %s", strerror(-lStatus)); |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 850 | } else { |
| 851 | lStatus = reply.readInt32(); |
| 852 | int tmp = reply.readInt32(); |
Glenn Kasten | 507b286 | 2013-07-31 16:12:13 -0700 | [diff] [blame] | 853 | if (id != NULL) { |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 854 | *id = tmp; |
| 855 | } |
| 856 | tmp = reply.readInt32(); |
Glenn Kasten | a0d6833 | 2012-01-27 16:47:15 -0800 | [diff] [blame] | 857 | if (enabled != NULL) { |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 858 | *enabled = tmp; |
| 859 | } |
Ytai Ben-Tsvi | 9cd8981 | 2020-07-01 17:12:06 -0700 | [diff] [blame] | 860 | effect = interface_cast<media::IEffect>(reply.readStrongBinder()); |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 861 | reply.read(pDesc, sizeof(effect_descriptor_t)); |
| 862 | } |
Glenn Kasten | 507b286 | 2013-07-31 16:12:13 -0700 | [diff] [blame] | 863 | if (status != NULL) { |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 864 | *status = lStatus; |
| 865 | } |
| 866 | |
| 867 | return effect; |
| 868 | } |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 869 | |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 870 | virtual status_t moveEffects(audio_session_t session, audio_io_handle_t srcOutput, |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 871 | audio_io_handle_t dstOutput) |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 872 | { |
| 873 | Parcel data, reply; |
| 874 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 875 | data.writeInt32(session); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 876 | data.writeInt32((int32_t) srcOutput); |
| 877 | data.writeInt32((int32_t) dstOutput); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 878 | remote()->transact(MOVE_EFFECTS, data, &reply); |
| 879 | return reply.readInt32(); |
| 880 | } |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 881 | |
Eric Laurent | b20cf7d | 2019-04-05 19:37:34 -0700 | [diff] [blame] | 882 | virtual void setEffectSuspended(int effectId, |
| 883 | audio_session_t sessionId, |
| 884 | bool suspended) |
| 885 | { |
| 886 | Parcel data, reply; |
| 887 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 888 | data.writeInt32(effectId); |
| 889 | data.writeInt32(sessionId); |
| 890 | data.writeInt32(suspended ? 1 : 0); |
| 891 | remote()->transact(SET_EFFECT_SUSPENDED, data, &reply); |
| 892 | } |
| 893 | |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 894 | virtual audio_module_handle_t loadHwModule(const char *name) |
| 895 | { |
| 896 | Parcel data, reply; |
| 897 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 898 | data.writeCString(name); |
| 899 | remote()->transact(LOAD_HW_MODULE, data, &reply); |
| 900 | return (audio_module_handle_t) reply.readInt32(); |
| 901 | } |
Glenn Kasten | cc0f1cf | 2012-09-24 11:27:18 -0700 | [diff] [blame] | 902 | |
Glenn Kasten | 3b16c76 | 2012-11-14 08:44:39 -0800 | [diff] [blame] | 903 | virtual uint32_t getPrimaryOutputSamplingRate() |
Glenn Kasten | cc0f1cf | 2012-09-24 11:27:18 -0700 | [diff] [blame] | 904 | { |
| 905 | Parcel data, reply; |
| 906 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 907 | remote()->transact(GET_PRIMARY_OUTPUT_SAMPLING_RATE, data, &reply); |
| 908 | return reply.readInt32(); |
| 909 | } |
| 910 | |
Glenn Kasten | e33054e | 2012-11-14 12:54:39 -0800 | [diff] [blame] | 911 | virtual size_t getPrimaryOutputFrameCount() |
Glenn Kasten | cc0f1cf | 2012-09-24 11:27:18 -0700 | [diff] [blame] | 912 | { |
| 913 | Parcel data, reply; |
| 914 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 915 | remote()->transact(GET_PRIMARY_OUTPUT_FRAME_COUNT, data, &reply); |
Glenn Kasten | e03dd22 | 2014-01-28 11:04:39 -0800 | [diff] [blame] | 916 | return reply.readInt64(); |
Glenn Kasten | cc0f1cf | 2012-09-24 11:27:18 -0700 | [diff] [blame] | 917 | } |
| 918 | |
Andy Hung | 6f248bb | 2018-01-23 14:04:37 -0800 | [diff] [blame] | 919 | virtual status_t setLowRamDevice(bool isLowRamDevice, int64_t totalMemory) override |
Glenn Kasten | 4182c4e | 2013-07-15 14:45:07 -0700 | [diff] [blame] | 920 | { |
| 921 | Parcel data, reply; |
Andy Hung | 6f248bb | 2018-01-23 14:04:37 -0800 | [diff] [blame] | 922 | |
| 923 | static_assert(NO_ERROR == 0, "NO_ERROR must be 0"); |
| 924 | return data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()) |
| 925 | ?: data.writeInt32((int) isLowRamDevice) |
| 926 | ?: data.writeInt64(totalMemory) |
| 927 | ?: remote()->transact(SET_LOW_RAM_DEVICE, data, &reply) |
| 928 | ?: reply.readInt32(); |
Glenn Kasten | 4182c4e | 2013-07-15 14:45:07 -0700 | [diff] [blame] | 929 | } |
Andy Hung | 6f248bb | 2018-01-23 14:04:37 -0800 | [diff] [blame] | 930 | |
Eric Laurent | 4b12340 | 2014-04-11 09:22:20 -0700 | [diff] [blame] | 931 | virtual status_t listAudioPorts(unsigned int *num_ports, |
| 932 | struct audio_port *ports) |
| 933 | { |
| 934 | if (num_ports == NULL || *num_ports == 0 || ports == NULL) { |
| 935 | return BAD_VALUE; |
| 936 | } |
| 937 | Parcel data, reply; |
| 938 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 939 | data.writeInt32(*num_ports); |
| 940 | status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply); |
| 941 | if (status != NO_ERROR || |
| 942 | (status = (status_t)reply.readInt32()) != NO_ERROR) { |
| 943 | return status; |
| 944 | } |
| 945 | *num_ports = (unsigned int)reply.readInt32(); |
| 946 | reply.read(ports, *num_ports * sizeof(struct audio_port)); |
| 947 | return status; |
| 948 | } |
Jiabin Huang | 3a0cf47 | 2020-11-03 17:29:35 +0000 | [diff] [blame] | 949 | virtual status_t getAudioPort(struct audio_port *port) |
Eric Laurent | 4b12340 | 2014-04-11 09:22:20 -0700 | [diff] [blame] | 950 | { |
Jiabin Huang | 3a0cf47 | 2020-11-03 17:29:35 +0000 | [diff] [blame] | 951 | if (port == NULL) { |
Eric Laurent | 4b12340 | 2014-04-11 09:22:20 -0700 | [diff] [blame] | 952 | return BAD_VALUE; |
| 953 | } |
| 954 | Parcel data, reply; |
| 955 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
Jiabin Huang | 3a0cf47 | 2020-11-03 17:29:35 +0000 | [diff] [blame] | 956 | data.write(port, sizeof(struct audio_port)); |
Eric Laurent | 4b12340 | 2014-04-11 09:22:20 -0700 | [diff] [blame] | 957 | status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply); |
| 958 | if (status != NO_ERROR || |
| 959 | (status = (status_t)reply.readInt32()) != NO_ERROR) { |
| 960 | return status; |
| 961 | } |
| 962 | reply.read(port, sizeof(struct audio_port)); |
| 963 | return status; |
| 964 | } |
| 965 | virtual status_t createAudioPatch(const struct audio_patch *patch, |
| 966 | audio_patch_handle_t *handle) |
| 967 | { |
| 968 | if (patch == NULL || handle == NULL) { |
| 969 | return BAD_VALUE; |
| 970 | } |
| 971 | Parcel data, reply; |
| 972 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 973 | data.write(patch, sizeof(struct audio_patch)); |
| 974 | data.write(handle, sizeof(audio_patch_handle_t)); |
| 975 | status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply); |
| 976 | if (status != NO_ERROR || |
| 977 | (status = (status_t)reply.readInt32()) != NO_ERROR) { |
| 978 | return status; |
| 979 | } |
| 980 | reply.read(handle, sizeof(audio_patch_handle_t)); |
| 981 | return status; |
| 982 | } |
| 983 | virtual status_t releaseAudioPatch(audio_patch_handle_t handle) |
| 984 | { |
| 985 | Parcel data, reply; |
| 986 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 987 | data.write(&handle, sizeof(audio_patch_handle_t)); |
| 988 | status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply); |
| 989 | if (status != NO_ERROR) { |
| 990 | status = (status_t)reply.readInt32(); |
| 991 | } |
| 992 | return status; |
| 993 | } |
| 994 | virtual status_t listAudioPatches(unsigned int *num_patches, |
| 995 | struct audio_patch *patches) |
| 996 | { |
| 997 | if (num_patches == NULL || *num_patches == 0 || patches == NULL) { |
| 998 | return BAD_VALUE; |
| 999 | } |
| 1000 | Parcel data, reply; |
| 1001 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 1002 | data.writeInt32(*num_patches); |
| 1003 | status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply); |
| 1004 | if (status != NO_ERROR || |
| 1005 | (status = (status_t)reply.readInt32()) != NO_ERROR) { |
| 1006 | return status; |
| 1007 | } |
| 1008 | *num_patches = (unsigned int)reply.readInt32(); |
| 1009 | reply.read(patches, *num_patches * sizeof(struct audio_patch)); |
| 1010 | return status; |
| 1011 | } |
| 1012 | virtual status_t setAudioPortConfig(const struct audio_port_config *config) |
| 1013 | { |
| 1014 | if (config == NULL) { |
| 1015 | return BAD_VALUE; |
| 1016 | } |
| 1017 | Parcel data, reply; |
| 1018 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 1019 | data.write(config, sizeof(struct audio_port_config)); |
| 1020 | status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply); |
| 1021 | if (status != NO_ERROR) { |
| 1022 | status = (status_t)reply.readInt32(); |
| 1023 | } |
| 1024 | return status; |
| 1025 | } |
Eric Laurent | 93c3d41 | 2014-08-01 14:48:35 -0700 | [diff] [blame] | 1026 | virtual audio_hw_sync_t getAudioHwSyncForSession(audio_session_t sessionId) |
| 1027 | { |
| 1028 | Parcel data, reply; |
| 1029 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 1030 | data.writeInt32(sessionId); |
Glenn Kasten | 9eae036 | 2016-04-19 09:09:14 -0700 | [diff] [blame] | 1031 | status_t status = remote()->transact(GET_AUDIO_HW_SYNC_FOR_SESSION, data, &reply); |
Eric Laurent | 93c3d41 | 2014-08-01 14:48:35 -0700 | [diff] [blame] | 1032 | if (status != NO_ERROR) { |
| 1033 | return AUDIO_HW_SYNC_INVALID; |
| 1034 | } |
| 1035 | return (audio_hw_sync_t)reply.readInt32(); |
| 1036 | } |
Eric Laurent | 72e3f39 | 2015-05-20 14:43:50 -0700 | [diff] [blame] | 1037 | virtual status_t systemReady() |
| 1038 | { |
| 1039 | Parcel data, reply; |
| 1040 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 1041 | return remote()->transact(SYSTEM_READY, data, &reply, IBinder::FLAG_ONEWAY); |
| 1042 | } |
Glenn Kasten | 4a8308b | 2016-04-18 14:10:01 -0700 | [diff] [blame] | 1043 | virtual size_t frameCountHAL(audio_io_handle_t ioHandle) const |
| 1044 | { |
| 1045 | Parcel data, reply; |
| 1046 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 1047 | data.writeInt32((int32_t) ioHandle); |
| 1048 | status_t status = remote()->transact(FRAME_COUNT_HAL, data, &reply); |
| 1049 | if (status != NO_ERROR) { |
| 1050 | return 0; |
| 1051 | } |
| 1052 | return reply.readInt64(); |
| 1053 | } |
jiabin | 46a76fa | 2018-01-05 10:18:21 -0800 | [diff] [blame] | 1054 | virtual status_t getMicrophones(std::vector<media::MicrophoneInfo> *microphones) |
| 1055 | { |
| 1056 | Parcel data, reply; |
| 1057 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
jiabin | 9ff780e | 2018-03-19 18:19:52 -0700 | [diff] [blame] | 1058 | status_t status = remote()->transact(GET_MICROPHONES, data, &reply); |
jiabin | 46a76fa | 2018-01-05 10:18:21 -0800 | [diff] [blame] | 1059 | if (status != NO_ERROR || |
| 1060 | (status = (status_t)reply.readInt32()) != NO_ERROR) { |
| 1061 | return status; |
| 1062 | } |
| 1063 | status = reply.readParcelableVector(microphones); |
| 1064 | return status; |
| 1065 | } |
Eric Laurent | 42896a0 | 2019-09-27 15:40:33 -0700 | [diff] [blame] | 1066 | virtual status_t setAudioHalPids(const std::vector<pid_t>& pids) |
| 1067 | { |
| 1068 | Parcel data, reply; |
| 1069 | data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); |
| 1070 | data.writeInt32(pids.size()); |
| 1071 | for (auto pid : pids) { |
| 1072 | data.writeInt32(pid); |
| 1073 | } |
| 1074 | status_t status = remote()->transact(SET_AUDIO_HAL_PIDS, data, &reply); |
| 1075 | if (status != NO_ERROR) { |
| 1076 | return status; |
| 1077 | } |
| 1078 | return static_cast <status_t> (reply.readInt32()); |
| 1079 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1080 | }; |
| 1081 | |
| 1082 | IMPLEMENT_META_INTERFACE(AudioFlinger, "android.media.IAudioFlinger"); |
| 1083 | |
| 1084 | // ---------------------------------------------------------------------- |
| 1085 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1086 | status_t BnAudioFlinger::onTransact( |
| 1087 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 1088 | { |
Eric Laurent | b1cc36b | 2017-12-11 12:14:16 -0800 | [diff] [blame] | 1089 | // make sure transactions reserved to AudioPolicyManager do not come from other processes |
| 1090 | switch (code) { |
| 1091 | case SET_STREAM_VOLUME: |
| 1092 | case SET_STREAM_MUTE: |
Eric Laurent | b1cc36b | 2017-12-11 12:14:16 -0800 | [diff] [blame] | 1093 | case OPEN_OUTPUT: |
| 1094 | case OPEN_DUPLICATE_OUTPUT: |
| 1095 | case CLOSE_OUTPUT: |
| 1096 | case SUSPEND_OUTPUT: |
| 1097 | case RESTORE_OUTPUT: |
| 1098 | case OPEN_INPUT: |
| 1099 | case CLOSE_INPUT: |
| 1100 | case INVALIDATE_STREAM: |
| 1101 | case SET_VOICE_VOLUME: |
| 1102 | case MOVE_EFFECTS: |
Eric Laurent | b20cf7d | 2019-04-05 19:37:34 -0700 | [diff] [blame] | 1103 | case SET_EFFECT_SUSPENDED: |
Eric Laurent | b1cc36b | 2017-12-11 12:14:16 -0800 | [diff] [blame] | 1104 | case LOAD_HW_MODULE: |
| 1105 | case LIST_AUDIO_PORTS: |
| 1106 | case GET_AUDIO_PORT: |
| 1107 | case CREATE_AUDIO_PATCH: |
| 1108 | case RELEASE_AUDIO_PATCH: |
| 1109 | case LIST_AUDIO_PATCHES: |
| 1110 | case SET_AUDIO_PORT_CONFIG: |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1111 | case SET_RECORD_SILENCED: |
Eric Laurent | b1cc36b | 2017-12-11 12:14:16 -0800 | [diff] [blame] | 1112 | ALOGW("%s: transaction %d received from PID %d", |
| 1113 | __func__, code, IPCThreadState::self()->getCallingPid()); |
Eric Laurent | ef92bff | 2018-04-26 10:44:50 -0700 | [diff] [blame] | 1114 | // return status only for non void methods |
| 1115 | switch (code) { |
| 1116 | case SET_RECORD_SILENCED: |
Eric Laurent | b20cf7d | 2019-04-05 19:37:34 -0700 | [diff] [blame] | 1117 | case SET_EFFECT_SUSPENDED: |
Eric Laurent | ef92bff | 2018-04-26 10:44:50 -0700 | [diff] [blame] | 1118 | break; |
| 1119 | default: |
| 1120 | reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION)); |
| 1121 | break; |
| 1122 | } |
| 1123 | return OK; |
Eric Laurent | b1cc36b | 2017-12-11 12:14:16 -0800 | [diff] [blame] | 1124 | default: |
| 1125 | break; |
| 1126 | } |
| 1127 | |
Eric Laurent | 4980df2 | 2018-01-26 18:04:09 -0800 | [diff] [blame] | 1128 | // make sure the following transactions come from system components |
| 1129 | switch (code) { |
| 1130 | case SET_MASTER_VOLUME: |
| 1131 | case SET_MASTER_MUTE: |
| 1132 | case SET_MODE: |
| 1133 | case SET_MIC_MUTE: |
| 1134 | case SET_LOW_RAM_DEVICE: |
Eric Laurent | 42896a0 | 2019-09-27 15:40:33 -0700 | [diff] [blame] | 1135 | case SYSTEM_READY: |
| 1136 | case SET_AUDIO_HAL_PIDS: { |
Andy Hung | 4ef19fa | 2018-05-15 19:35:29 -0700 | [diff] [blame] | 1137 | if (!isServiceUid(IPCThreadState::self()->getCallingUid())) { |
Eric Laurent | 4980df2 | 2018-01-26 18:04:09 -0800 | [diff] [blame] | 1138 | ALOGW("%s: transaction %d received from PID %d unauthorized UID %d", |
| 1139 | __func__, code, IPCThreadState::self()->getCallingPid(), |
| 1140 | IPCThreadState::self()->getCallingUid()); |
Eric Laurent | ef92bff | 2018-04-26 10:44:50 -0700 | [diff] [blame] | 1141 | // return status only for non void methods |
| 1142 | switch (code) { |
| 1143 | case SYSTEM_READY: |
| 1144 | break; |
| 1145 | default: |
| 1146 | reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION)); |
| 1147 | break; |
| 1148 | } |
| 1149 | return OK; |
Eric Laurent | 4980df2 | 2018-01-26 18:04:09 -0800 | [diff] [blame] | 1150 | } |
Eric Laurent | 96c7eed | 2018-03-26 17:57:01 -0700 | [diff] [blame] | 1151 | } break; |
Eric Laurent | 4980df2 | 2018-01-26 18:04:09 -0800 | [diff] [blame] | 1152 | default: |
| 1153 | break; |
| 1154 | } |
| 1155 | |
Glenn Kasten | 67f9570 | 2020-06-22 16:42:52 -0700 | [diff] [blame] | 1156 | // List of relevant events that trigger log merging. |
Nicolas Roulet | dcdfaec | 2017-02-14 10:18:39 -0800 | [diff] [blame] | 1157 | // Log merging should activate during audio activity of any kind. This are considered the |
| 1158 | // most relevant events. |
| 1159 | // TODO should select more wisely the items from the list |
| 1160 | switch (code) { |
| 1161 | case CREATE_TRACK: |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 1162 | case CREATE_RECORD: |
Nicolas Roulet | dcdfaec | 2017-02-14 10:18:39 -0800 | [diff] [blame] | 1163 | case SET_MASTER_VOLUME: |
| 1164 | case SET_MASTER_MUTE: |
Nicolas Roulet | dcdfaec | 2017-02-14 10:18:39 -0800 | [diff] [blame] | 1165 | case SET_MIC_MUTE: |
| 1166 | case SET_PARAMETERS: |
Nicolas Roulet | dcdfaec | 2017-02-14 10:18:39 -0800 | [diff] [blame] | 1167 | case CREATE_EFFECT: |
| 1168 | case SYSTEM_READY: { |
| 1169 | requestLogMerge(); |
| 1170 | break; |
| 1171 | } |
| 1172 | default: |
| 1173 | break; |
| 1174 | } |
Eric Laurent | b1cc36b | 2017-12-11 12:14:16 -0800 | [diff] [blame] | 1175 | |
Eric Laurent | 39b09b5 | 2018-06-29 12:24:40 -0700 | [diff] [blame] | 1176 | std::string tag("IAudioFlinger command " + std::to_string(code)); |
| 1177 | TimeCheck check(tag.c_str()); |
Eric Laurent | 3528c93 | 2018-02-23 17:17:22 -0800 | [diff] [blame] | 1178 | |
Eric Laurent | 14dc3cb | 2020-09-16 18:42:23 -0700 | [diff] [blame] | 1179 | // Make sure we connect to Audio Policy Service before calling into AudioFlinger: |
| 1180 | // - AudioFlinger can call into Audio Policy Service with its global mutex held |
| 1181 | // - If this is the first time Audio Policy Service is queried from inside audioserver process |
| 1182 | // this will trigger Audio Policy Manager initialization. |
| 1183 | // - Audio Policy Manager initialization calls into AudioFlinger which will try to lock |
| 1184 | // its global mutex and a deadlock will occur. |
| 1185 | if (IPCThreadState::self()->getCallingPid() != getpid()) { |
| 1186 | AudioSystem::get_audio_policy_service(); |
| 1187 | } |
| 1188 | |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 1189 | switch (code) { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1190 | case CREATE_TRACK: { |
| 1191 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 1192 | |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame^] | 1193 | media::CreateTrackRequest input; |
| 1194 | if (data.readParcelable(&input) != NO_ERROR) { |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 1195 | reply->writeInt32(DEAD_OBJECT); |
| 1196 | return NO_ERROR; |
Eric Laurent | 3d00aa6 | 2013-09-24 09:53:27 -0700 | [diff] [blame] | 1197 | } |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 1198 | |
| 1199 | status_t status; |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame^] | 1200 | media::CreateTrackResponse output; |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 1201 | |
| 1202 | sp<IAudioTrack> track= createTrack(input, |
| 1203 | output, |
| 1204 | &status); |
| 1205 | |
| 1206 | LOG_ALWAYS_FATAL_IF((track != 0) != (status == NO_ERROR)); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1207 | reply->writeInt32(status); |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 1208 | if (status != NO_ERROR) { |
| 1209 | return NO_ERROR; |
| 1210 | } |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 1211 | reply->writeStrongBinder(IInterface::asBinder(track)); |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 1212 | output.writeToParcel(reply); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1213 | return NO_ERROR; |
| 1214 | } break; |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 1215 | case CREATE_RECORD: { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1216 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 1217 | |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame^] | 1218 | media::CreateRecordRequest input; |
| 1219 | if (data.readParcelable(&input) != NO_ERROR) { |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 1220 | reply->writeInt32(DEAD_OBJECT); |
| 1221 | return NO_ERROR; |
| 1222 | } |
| 1223 | |
| 1224 | status_t status; |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame^] | 1225 | media::CreateRecordResponse output; |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 1226 | |
| 1227 | sp<media::IAudioRecord> record = createRecord(input, |
| 1228 | output, |
| 1229 | &status); |
| 1230 | |
Glenn Kasten | e93cf2c | 2013-09-24 11:52:37 -0700 | [diff] [blame] | 1231 | LOG_ALWAYS_FATAL_IF((record != 0) != (status == NO_ERROR)); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1232 | reply->writeInt32(status); |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 1233 | if (status != NO_ERROR) { |
| 1234 | return NO_ERROR; |
| 1235 | } |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 1236 | reply->writeStrongBinder(IInterface::asBinder(record)); |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 1237 | output.writeToParcel(reply); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1238 | return NO_ERROR; |
| 1239 | } break; |
| 1240 | case SAMPLE_RATE: { |
| 1241 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 1242 | reply->writeInt32( sampleRate((audio_io_handle_t) data.readInt32()) ); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1243 | return NO_ERROR; |
| 1244 | } break; |
Glenn Kasten | 4a8308b | 2016-04-18 14:10:01 -0700 | [diff] [blame] | 1245 | |
| 1246 | // RESERVED for channelCount() |
| 1247 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1248 | case FORMAT: { |
| 1249 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 1250 | reply->writeInt32( format((audio_io_handle_t) data.readInt32()) ); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1251 | return NO_ERROR; |
| 1252 | } break; |
| 1253 | case FRAME_COUNT: { |
| 1254 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Glenn Kasten | e03dd22 | 2014-01-28 11:04:39 -0800 | [diff] [blame] | 1255 | reply->writeInt64( frameCount((audio_io_handle_t) data.readInt32()) ); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1256 | return NO_ERROR; |
| 1257 | } break; |
| 1258 | case LATENCY: { |
| 1259 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 1260 | reply->writeInt32( latency((audio_io_handle_t) data.readInt32()) ); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1261 | return NO_ERROR; |
| 1262 | } break; |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 1263 | case SET_MASTER_VOLUME: { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1264 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 1265 | reply->writeInt32( setMasterVolume(data.readFloat()) ); |
| 1266 | return NO_ERROR; |
| 1267 | } break; |
| 1268 | case SET_MASTER_MUTE: { |
| 1269 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 1270 | reply->writeInt32( setMasterMute(data.readInt32()) ); |
| 1271 | return NO_ERROR; |
| 1272 | } break; |
| 1273 | case MASTER_VOLUME: { |
| 1274 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 1275 | reply->writeFloat( masterVolume() ); |
| 1276 | return NO_ERROR; |
| 1277 | } break; |
| 1278 | case MASTER_MUTE: { |
| 1279 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 1280 | reply->writeInt32( masterMute() ); |
| 1281 | return NO_ERROR; |
| 1282 | } break; |
Richard Folke Tullberg | 3fae037 | 2017-01-13 09:04:25 +0100 | [diff] [blame] | 1283 | case SET_MASTER_BALANCE: { |
| 1284 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 1285 | reply->writeInt32( setMasterBalance(data.readFloat()) ); |
| 1286 | return NO_ERROR; |
| 1287 | } break; |
| 1288 | case GET_MASTER_BALANCE: { |
| 1289 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 1290 | float f; |
| 1291 | const status_t status = getMasterBalance(&f); |
| 1292 | reply->writeInt32((int32_t)status); |
| 1293 | if (status == NO_ERROR) { |
| 1294 | (void)reply->writeFloat(f); |
| 1295 | } |
| 1296 | return NO_ERROR; |
| 1297 | } break; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1298 | case SET_STREAM_VOLUME: { |
| 1299 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 1300 | int stream = data.readInt32(); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1301 | float volume = data.readFloat(); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 1302 | audio_io_handle_t output = (audio_io_handle_t) data.readInt32(); |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 1303 | reply->writeInt32( setStreamVolume((audio_stream_type_t) stream, volume, output) ); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1304 | return NO_ERROR; |
| 1305 | } break; |
| 1306 | case SET_STREAM_MUTE: { |
| 1307 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 1308 | int stream = data.readInt32(); |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 1309 | reply->writeInt32( setStreamMute((audio_stream_type_t) stream, data.readInt32()) ); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1310 | return NO_ERROR; |
| 1311 | } break; |
| 1312 | case STREAM_VOLUME: { |
| 1313 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 1314 | int stream = data.readInt32(); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 1315 | int output = data.readInt32(); |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 1316 | reply->writeFloat( streamVolume((audio_stream_type_t) stream, output) ); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1317 | return NO_ERROR; |
| 1318 | } break; |
| 1319 | case STREAM_MUTE: { |
| 1320 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 1321 | int stream = data.readInt32(); |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 1322 | reply->writeInt32( streamMute((audio_stream_type_t) stream) ); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1323 | return NO_ERROR; |
| 1324 | } break; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1325 | case SET_MODE: { |
| 1326 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Glenn Kasten | f78aee7 | 2012-01-04 11:00:47 -0800 | [diff] [blame] | 1327 | audio_mode_t mode = (audio_mode_t) data.readInt32(); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1328 | reply->writeInt32( setMode(mode) ); |
| 1329 | return NO_ERROR; |
| 1330 | } break; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1331 | case SET_MIC_MUTE: { |
| 1332 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 1333 | int state = data.readInt32(); |
| 1334 | reply->writeInt32( setMicMute(state) ); |
| 1335 | return NO_ERROR; |
| 1336 | } break; |
| 1337 | case GET_MIC_MUTE: { |
| 1338 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 1339 | reply->writeInt32( getMicMute() ); |
| 1340 | return NO_ERROR; |
| 1341 | } break; |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1342 | case SET_RECORD_SILENCED: { |
| 1343 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Eric Laurent | 5ada82e | 2019-08-29 17:53:54 -0700 | [diff] [blame] | 1344 | audio_port_handle_t portId = data.readInt32(); |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1345 | bool silenced = data.readInt32() == 1; |
Eric Laurent | 5ada82e | 2019-08-29 17:53:54 -0700 | [diff] [blame] | 1346 | setRecordSilenced(portId, silenced); |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1347 | return NO_ERROR; |
| 1348 | } break; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1349 | case SET_PARAMETERS: { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1350 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 1351 | audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32(); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1352 | String8 keyValuePairs(data.readString8()); |
| 1353 | reply->writeInt32(setParameters(ioHandle, keyValuePairs)); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1354 | return NO_ERROR; |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 1355 | } break; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1356 | case GET_PARAMETERS: { |
| 1357 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 1358 | audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32(); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1359 | String8 keys(data.readString8()); |
| 1360 | reply->writeString8(getParameters(ioHandle, keys)); |
| 1361 | return NO_ERROR; |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 1362 | } break; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1363 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1364 | case REGISTER_CLIENT: { |
| 1365 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1366 | sp<media::IAudioFlingerClient> client = interface_cast<media::IAudioFlingerClient>( |
Glenn Kasten | 85ab62c | 2012-11-01 11:11:38 -0700 | [diff] [blame] | 1367 | data.readStrongBinder()); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1368 | registerClient(client); |
| 1369 | return NO_ERROR; |
| 1370 | } break; |
| 1371 | case GET_INPUTBUFFERSIZE: { |
| 1372 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 1373 | uint32_t sampleRate = data.readInt32(); |
Glenn Kasten | 58f3021 | 2012-01-12 12:27:51 -0800 | [diff] [blame] | 1374 | audio_format_t format = (audio_format_t) data.readInt32(); |
Mikhail Naganov | 5577303 | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 1375 | audio_channel_mask_t channelMask = (audio_channel_mask_t) data.readInt32(); |
Glenn Kasten | e03dd22 | 2014-01-28 11:04:39 -0800 | [diff] [blame] | 1376 | reply->writeInt64( getInputBufferSize(sampleRate, format, channelMask) ); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1377 | return NO_ERROR; |
| 1378 | } break; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1379 | case OPEN_OUTPUT: { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1380 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 1381 | audio_module_handle_t module = (audio_module_handle_t)data.readInt32(); |
Wei Jia | e995e47 | 2015-09-09 09:48:34 -0700 | [diff] [blame] | 1382 | audio_config_t config = {}; |
| 1383 | if (data.read(&config, sizeof(audio_config_t)) != NO_ERROR) { |
| 1384 | ALOGE("b/23905951"); |
| 1385 | } |
jiabin | 4381040 | 2019-10-24 14:58:31 -0700 | [diff] [blame] | 1386 | sp<DeviceDescriptorBase> device = new DeviceDescriptorBase(AUDIO_DEVICE_NONE); |
| 1387 | status_t status = NO_ERROR; |
| 1388 | if ((status = data.readParcelable(device.get())) != NO_ERROR) { |
| 1389 | reply->writeInt32((int32_t)status); |
| 1390 | return NO_ERROR; |
| 1391 | } |
Eric Laurent | 0ca3cf9 | 2012-04-18 09:24:29 -0700 | [diff] [blame] | 1392 | audio_output_flags_t flags = (audio_output_flags_t) data.readInt32(); |
Wei Jia | 983dca3 | 2015-09-10 09:47:29 -0700 | [diff] [blame] | 1393 | uint32_t latencyMs = 0; |
Wei Jia | 4cac44b | 2015-09-16 15:01:16 -0700 | [diff] [blame] | 1394 | audio_io_handle_t output = AUDIO_IO_HANDLE_NONE; |
jiabin | 4381040 | 2019-10-24 14:58:31 -0700 | [diff] [blame] | 1395 | status = openOutput(module, &output, &config, device, &latencyMs, flags); |
Glenn Kasten | 7074296 | 2014-02-18 08:00:47 -0800 | [diff] [blame] | 1396 | ALOGV("OPEN_OUTPUT output, %d", output); |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 1397 | reply->writeInt32((int32_t)status); |
| 1398 | if (status == NO_ERROR) { |
| 1399 | reply->writeInt32((int32_t)output); |
| 1400 | reply->write(&config, sizeof(audio_config_t)); |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 1401 | reply->writeInt32(latencyMs); |
| 1402 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1403 | return NO_ERROR; |
| 1404 | } break; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1405 | case OPEN_DUPLICATE_OUTPUT: { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1406 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 1407 | audio_io_handle_t output1 = (audio_io_handle_t) data.readInt32(); |
| 1408 | audio_io_handle_t output2 = (audio_io_handle_t) data.readInt32(); |
| 1409 | reply->writeInt32((int32_t) openDuplicateOutput(output1, output2)); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1410 | return NO_ERROR; |
| 1411 | } break; |
| 1412 | case CLOSE_OUTPUT: { |
| 1413 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 1414 | reply->writeInt32(closeOutput((audio_io_handle_t) data.readInt32())); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1415 | return NO_ERROR; |
| 1416 | } break; |
| 1417 | case SUSPEND_OUTPUT: { |
| 1418 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 1419 | reply->writeInt32(suspendOutput((audio_io_handle_t) data.readInt32())); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1420 | return NO_ERROR; |
| 1421 | } break; |
| 1422 | case RESTORE_OUTPUT: { |
| 1423 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 1424 | reply->writeInt32(restoreOutput((audio_io_handle_t) data.readInt32())); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1425 | return NO_ERROR; |
| 1426 | } break; |
| 1427 | case OPEN_INPUT: { |
| 1428 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 1429 | audio_module_handle_t module = (audio_module_handle_t)data.readInt32(); |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 1430 | audio_io_handle_t input = (audio_io_handle_t)data.readInt32(); |
Wei Jia | e995e47 | 2015-09-09 09:48:34 -0700 | [diff] [blame] | 1431 | audio_config_t config = {}; |
| 1432 | if (data.read(&config, sizeof(audio_config_t)) != NO_ERROR) { |
| 1433 | ALOGE("b/23905951"); |
| 1434 | } |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 1435 | audio_devices_t device = (audio_devices_t)data.readInt32(); |
| 1436 | String8 address(data.readString8()); |
| 1437 | audio_source_t source = (audio_source_t)data.readInt32(); |
Glenn Kasten | ec40d28 | 2014-07-15 15:31:26 -0700 | [diff] [blame] | 1438 | audio_input_flags_t flags = (audio_input_flags_t) data.readInt32(); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1439 | |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 1440 | status_t status = openInput(module, &input, &config, |
| 1441 | &device, address, source, flags); |
| 1442 | reply->writeInt32((int32_t) status); |
| 1443 | if (status == NO_ERROR) { |
| 1444 | reply->writeInt32((int32_t) input); |
| 1445 | reply->write(&config, sizeof(audio_config_t)); |
| 1446 | reply->writeInt32(device); |
| 1447 | } |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1448 | return NO_ERROR; |
| 1449 | } break; |
| 1450 | case CLOSE_INPUT: { |
| 1451 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 1452 | reply->writeInt32(closeInput((audio_io_handle_t) data.readInt32())); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1453 | return NO_ERROR; |
| 1454 | } break; |
Glenn Kasten | d2304db | 2014-02-03 07:40:31 -0800 | [diff] [blame] | 1455 | case INVALIDATE_STREAM: { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1456 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Glenn Kasten | d2304db | 2014-02-03 07:40:31 -0800 | [diff] [blame] | 1457 | audio_stream_type_t stream = (audio_stream_type_t) data.readInt32(); |
| 1458 | reply->writeInt32(invalidateStream(stream)); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1459 | return NO_ERROR; |
| 1460 | } break; |
Eric Laurent | f0ee6f4 | 2009-10-21 08:14:22 -0700 | [diff] [blame] | 1461 | case SET_VOICE_VOLUME: { |
| 1462 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 1463 | float volume = data.readFloat(); |
| 1464 | reply->writeInt32( setVoiceVolume(volume) ); |
| 1465 | return NO_ERROR; |
| 1466 | } break; |
Eric Laurent | 342e9cf | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 1467 | case GET_RENDER_POSITION: { |
| 1468 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 1469 | audio_io_handle_t output = (audio_io_handle_t) data.readInt32(); |
Wei Jia | 983dca3 | 2015-09-10 09:47:29 -0700 | [diff] [blame] | 1470 | uint32_t halFrames = 0; |
| 1471 | uint32_t dspFrames = 0; |
Eric Laurent | 342e9cf | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 1472 | status_t status = getRenderPosition(&halFrames, &dspFrames, output); |
| 1473 | reply->writeInt32(status); |
| 1474 | if (status == NO_ERROR) { |
| 1475 | reply->writeInt32(halFrames); |
| 1476 | reply->writeInt32(dspFrames); |
| 1477 | } |
| 1478 | return NO_ERROR; |
| 1479 | } |
Eric Laurent | 05bca2f | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 1480 | case GET_INPUT_FRAMES_LOST: { |
| 1481 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 1482 | audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32(); |
Glenn Kasten | 5f972c0 | 2014-01-13 09:59:31 -0800 | [diff] [blame] | 1483 | reply->writeInt32((int32_t) getInputFramesLost(ioHandle)); |
Eric Laurent | 05bca2f | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 1484 | return NO_ERROR; |
| 1485 | } break; |
Glenn Kasten | 9eae036 | 2016-04-19 09:09:14 -0700 | [diff] [blame] | 1486 | case NEW_AUDIO_UNIQUE_ID: { |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1487 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Glenn Kasten | eeecb98 | 2016-02-26 10:44:04 -0800 | [diff] [blame] | 1488 | reply->writeInt32(newAudioUniqueId((audio_unique_id_use_t) data.readInt32())); |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1489 | return NO_ERROR; |
| 1490 | } break; |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 1491 | case ACQUIRE_AUDIO_SESSION_ID: { |
| 1492 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 1493 | audio_session_t audioSession = (audio_session_t) data.readInt32(); |
Andy Hung | 8b0bfd9 | 2019-12-23 13:11:11 -0800 | [diff] [blame] | 1494 | const pid_t pid = (pid_t)data.readInt32(); |
| 1495 | const uid_t uid = (uid_t)data.readInt32(); |
| 1496 | acquireAudioSessionId(audioSession, pid, uid); |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 1497 | return NO_ERROR; |
| 1498 | } break; |
| 1499 | case RELEASE_AUDIO_SESSION_ID: { |
| 1500 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 1501 | audio_session_t audioSession = (audio_session_t) data.readInt32(); |
Marco Nelissen | d457c97 | 2014-02-11 08:47:07 -0800 | [diff] [blame] | 1502 | int pid = data.readInt32(); |
| 1503 | releaseAudioSessionId(audioSession, pid); |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 1504 | return NO_ERROR; |
| 1505 | } break; |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1506 | case QUERY_NUM_EFFECTS: { |
| 1507 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Wei Jia | 983dca3 | 2015-09-10 09:47:29 -0700 | [diff] [blame] | 1508 | uint32_t numEffects = 0; |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1509 | status_t status = queryNumberEffects(&numEffects); |
| 1510 | reply->writeInt32(status); |
| 1511 | if (status == NO_ERROR) { |
| 1512 | reply->writeInt32((int32_t)numEffects); |
| 1513 | } |
| 1514 | return NO_ERROR; |
| 1515 | } |
Eric Laurent | ffe9c25 | 2010-06-23 17:38:20 -0700 | [diff] [blame] | 1516 | case QUERY_EFFECT: { |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1517 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Wei Jia | 983dca3 | 2015-09-10 09:47:29 -0700 | [diff] [blame] | 1518 | effect_descriptor_t desc = {}; |
Eric Laurent | ffe9c25 | 2010-06-23 17:38:20 -0700 | [diff] [blame] | 1519 | status_t status = queryEffect(data.readInt32(), &desc); |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1520 | reply->writeInt32(status); |
| 1521 | if (status == NO_ERROR) { |
| 1522 | reply->write(&desc, sizeof(effect_descriptor_t)); |
| 1523 | } |
| 1524 | return NO_ERROR; |
| 1525 | } |
| 1526 | case GET_EFFECT_DESCRIPTOR: { |
| 1527 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Andy Hung | f85d129 | 2019-08-21 14:45:41 -0700 | [diff] [blame] | 1528 | effect_uuid_t uuid = {}; |
| 1529 | if (data.read(&uuid, sizeof(effect_uuid_t)) != NO_ERROR) { |
| 1530 | android_errorWriteLog(0x534e4554, "139417189"); |
| 1531 | } |
| 1532 | effect_uuid_t type = {}; |
| 1533 | if (data.read(&type, sizeof(effect_uuid_t)) != NO_ERROR) { |
| 1534 | android_errorWriteLog(0x534e4554, "139417189"); |
| 1535 | } |
Ari Hausman-Cohen | 2046ec7 | 2018-04-24 14:00:55 -0700 | [diff] [blame] | 1536 | uint32_t preferredTypeFlag = data.readUint32(); |
Wei Jia | 983dca3 | 2015-09-10 09:47:29 -0700 | [diff] [blame] | 1537 | effect_descriptor_t desc = {}; |
Ari Hausman-Cohen | 2046ec7 | 2018-04-24 14:00:55 -0700 | [diff] [blame] | 1538 | status_t status = getEffectDescriptor(&uuid, &type, preferredTypeFlag, &desc); |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1539 | reply->writeInt32(status); |
| 1540 | if (status == NO_ERROR) { |
| 1541 | reply->write(&desc, sizeof(effect_descriptor_t)); |
| 1542 | } |
| 1543 | return NO_ERROR; |
| 1544 | } |
| 1545 | case CREATE_EFFECT: { |
| 1546 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Wei Jia | e995e47 | 2015-09-09 09:48:34 -0700 | [diff] [blame] | 1547 | effect_descriptor_t desc = {}; |
| 1548 | if (data.read(&desc, sizeof(effect_descriptor_t)) != NO_ERROR) { |
| 1549 | ALOGE("b/23905951"); |
| 1550 | } |
Ytai Ben-Tsvi | 9cd8981 | 2020-07-01 17:12:06 -0700 | [diff] [blame] | 1551 | sp<media::IEffectClient> client = |
| 1552 | interface_cast<media::IEffectClient>(data.readStrongBinder()); |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1553 | int32_t priority = data.readInt32(); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 1554 | audio_io_handle_t output = (audio_io_handle_t) data.readInt32(); |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 1555 | audio_session_t sessionId = (audio_session_t) data.readInt32(); |
Eric Laurent | 9487603 | 2019-11-13 12:45:28 -0800 | [diff] [blame] | 1556 | AudioDeviceTypeAddr device; |
| 1557 | status_t status = NO_ERROR; |
| 1558 | if ((status = data.readParcelable(&device)) != NO_ERROR) { |
| 1559 | return status; |
| 1560 | } |
Svet Ganov | be71aa2 | 2015-04-28 12:06:02 -0700 | [diff] [blame] | 1561 | const String16 opPackageName = data.readString16(); |
Eric Laurent | b643627 | 2016-12-07 19:24:50 -0800 | [diff] [blame] | 1562 | pid_t pid = (pid_t)data.readInt32(); |
Eric Laurent | 2fe0acd | 2020-03-13 14:30:46 -0700 | [diff] [blame] | 1563 | bool probe = data.readInt32() == 1; |
Eric Laurent | b643627 | 2016-12-07 19:24:50 -0800 | [diff] [blame] | 1564 | |
Wei Jia | 983dca3 | 2015-09-10 09:47:29 -0700 | [diff] [blame] | 1565 | int id = 0; |
| 1566 | int enabled = 0; |
Eric Laurent | 05bca2f | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 1567 | |
Ytai Ben-Tsvi | 9cd8981 | 2020-07-01 17:12:06 -0700 | [diff] [blame] | 1568 | sp<media::IEffect> effect = createEffect(&desc, client, priority, output, sessionId, |
| 1569 | device, opPackageName, pid, probe, &status, &id, &enabled); |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1570 | reply->writeInt32(status); |
| 1571 | reply->writeInt32(id); |
| 1572 | reply->writeInt32(enabled); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 1573 | reply->writeStrongBinder(IInterface::asBinder(effect)); |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1574 | reply->write(&desc, sizeof(effect_descriptor_t)); |
| 1575 | return NO_ERROR; |
| 1576 | } break; |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1577 | case MOVE_EFFECTS: { |
| 1578 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 1579 | audio_session_t session = (audio_session_t) data.readInt32(); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 1580 | audio_io_handle_t srcOutput = (audio_io_handle_t) data.readInt32(); |
| 1581 | audio_io_handle_t dstOutput = (audio_io_handle_t) data.readInt32(); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1582 | reply->writeInt32(moveEffects(session, srcOutput, dstOutput)); |
| 1583 | return NO_ERROR; |
| 1584 | } break; |
Eric Laurent | b20cf7d | 2019-04-05 19:37:34 -0700 | [diff] [blame] | 1585 | case SET_EFFECT_SUSPENDED: { |
| 1586 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 1587 | int effectId = data.readInt32(); |
| 1588 | audio_session_t sessionId = (audio_session_t) data.readInt32(); |
| 1589 | bool suspended = data.readInt32() == 1; |
| 1590 | setEffectSuspended(effectId, sessionId, suspended); |
| 1591 | return NO_ERROR; |
| 1592 | } break; |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 1593 | case LOAD_HW_MODULE: { |
| 1594 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 1595 | reply->writeInt32(loadHwModule(data.readCString())); |
| 1596 | return NO_ERROR; |
| 1597 | } break; |
Glenn Kasten | cc0f1cf | 2012-09-24 11:27:18 -0700 | [diff] [blame] | 1598 | case GET_PRIMARY_OUTPUT_SAMPLING_RATE: { |
| 1599 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 1600 | reply->writeInt32(getPrimaryOutputSamplingRate()); |
| 1601 | return NO_ERROR; |
| 1602 | } break; |
| 1603 | case GET_PRIMARY_OUTPUT_FRAME_COUNT: { |
| 1604 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Glenn Kasten | e03dd22 | 2014-01-28 11:04:39 -0800 | [diff] [blame] | 1605 | reply->writeInt64(getPrimaryOutputFrameCount()); |
Glenn Kasten | cc0f1cf | 2012-09-24 11:27:18 -0700 | [diff] [blame] | 1606 | return NO_ERROR; |
| 1607 | } break; |
Glenn Kasten | 4182c4e | 2013-07-15 14:45:07 -0700 | [diff] [blame] | 1608 | case SET_LOW_RAM_DEVICE: { |
| 1609 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Andy Hung | 6f248bb | 2018-01-23 14:04:37 -0800 | [diff] [blame] | 1610 | int32_t isLowRamDevice; |
| 1611 | int64_t totalMemory; |
| 1612 | const status_t status = |
| 1613 | data.readInt32(&isLowRamDevice) ?: |
| 1614 | data.readInt64(&totalMemory) ?: |
| 1615 | setLowRamDevice(isLowRamDevice != 0, totalMemory); |
| 1616 | (void)reply->writeInt32(status); |
Glenn Kasten | 4182c4e | 2013-07-15 14:45:07 -0700 | [diff] [blame] | 1617 | return NO_ERROR; |
| 1618 | } break; |
Eric Laurent | 4b12340 | 2014-04-11 09:22:20 -0700 | [diff] [blame] | 1619 | case LIST_AUDIO_PORTS: { |
| 1620 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Eric Laurent | f75c2fe | 2015-04-02 13:49:15 -0700 | [diff] [blame] | 1621 | unsigned int numPortsReq = data.readInt32(); |
| 1622 | if (numPortsReq > MAX_ITEMS_PER_LIST) { |
| 1623 | numPortsReq = MAX_ITEMS_PER_LIST; |
| 1624 | } |
| 1625 | unsigned int numPorts = numPortsReq; |
Eric Laurent | 4b12340 | 2014-04-11 09:22:20 -0700 | [diff] [blame] | 1626 | struct audio_port *ports = |
Eric Laurent | f75c2fe | 2015-04-02 13:49:15 -0700 | [diff] [blame] | 1627 | (struct audio_port *)calloc(numPortsReq, |
Eric Laurent | 4b12340 | 2014-04-11 09:22:20 -0700 | [diff] [blame] | 1628 | sizeof(struct audio_port)); |
Eric Laurent | f75c2fe | 2015-04-02 13:49:15 -0700 | [diff] [blame] | 1629 | if (ports == NULL) { |
| 1630 | reply->writeInt32(NO_MEMORY); |
| 1631 | reply->writeInt32(0); |
| 1632 | return NO_ERROR; |
| 1633 | } |
| 1634 | status_t status = listAudioPorts(&numPorts, ports); |
Eric Laurent | 4b12340 | 2014-04-11 09:22:20 -0700 | [diff] [blame] | 1635 | reply->writeInt32(status); |
Eric Laurent | f75c2fe | 2015-04-02 13:49:15 -0700 | [diff] [blame] | 1636 | reply->writeInt32(numPorts); |
Eric Laurent | 4b12340 | 2014-04-11 09:22:20 -0700 | [diff] [blame] | 1637 | if (status == NO_ERROR) { |
Eric Laurent | f75c2fe | 2015-04-02 13:49:15 -0700 | [diff] [blame] | 1638 | if (numPortsReq > numPorts) { |
| 1639 | numPortsReq = numPorts; |
| 1640 | } |
| 1641 | reply->write(ports, numPortsReq * sizeof(struct audio_port)); |
Eric Laurent | 4b12340 | 2014-04-11 09:22:20 -0700 | [diff] [blame] | 1642 | } |
| 1643 | free(ports); |
| 1644 | return NO_ERROR; |
| 1645 | } break; |
| 1646 | case GET_AUDIO_PORT: { |
| 1647 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Jiabin Huang | 3a0cf47 | 2020-11-03 17:29:35 +0000 | [diff] [blame] | 1648 | struct audio_port port = {}; |
Eric Laurent | 4dacbc3 | 2020-10-07 13:48:21 -0700 | [diff] [blame] | 1649 | status_t status = data.read(&port, sizeof(struct audio_port)); |
| 1650 | if (status != NO_ERROR) { |
Wei Jia | e995e47 | 2015-09-09 09:48:34 -0700 | [diff] [blame] | 1651 | ALOGE("b/23905951"); |
Eric Laurent | 4dacbc3 | 2020-10-07 13:48:21 -0700 | [diff] [blame] | 1652 | return status; |
Wei Jia | e995e47 | 2015-09-09 09:48:34 -0700 | [diff] [blame] | 1653 | } |
Eric Laurent | 4dacbc3 | 2020-10-07 13:48:21 -0700 | [diff] [blame] | 1654 | status = AudioSanitizer::sanitizeAudioPort(&port); |
| 1655 | if (status == NO_ERROR) { |
| 1656 | status = getAudioPort(&port); |
| 1657 | } |
Eric Laurent | 4b12340 | 2014-04-11 09:22:20 -0700 | [diff] [blame] | 1658 | reply->writeInt32(status); |
| 1659 | if (status == NO_ERROR) { |
Jiabin Huang | 3a0cf47 | 2020-11-03 17:29:35 +0000 | [diff] [blame] | 1660 | reply->write(&port, sizeof(struct audio_port)); |
Eric Laurent | 4b12340 | 2014-04-11 09:22:20 -0700 | [diff] [blame] | 1661 | } |
| 1662 | return NO_ERROR; |
| 1663 | } break; |
| 1664 | case CREATE_AUDIO_PATCH: { |
| 1665 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 1666 | struct audio_patch patch; |
Eric Laurent | 4dacbc3 | 2020-10-07 13:48:21 -0700 | [diff] [blame] | 1667 | status_t status = data.read(&patch, sizeof(struct audio_patch)); |
| 1668 | if (status != NO_ERROR) { |
| 1669 | return status; |
Wei Jia | e995e47 | 2015-09-09 09:48:34 -0700 | [diff] [blame] | 1670 | } |
Eric Laurent | 4dacbc3 | 2020-10-07 13:48:21 -0700 | [diff] [blame] | 1671 | audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE; |
| 1672 | status = data.read(&handle, sizeof(audio_patch_handle_t)); |
| 1673 | if (status != NO_ERROR) { |
| 1674 | ALOGE("b/23905951"); |
| 1675 | return status; |
| 1676 | } |
| 1677 | status = AudioSanitizer::sanitizeAudioPatch(&patch); |
| 1678 | if (status == NO_ERROR) { |
| 1679 | status = createAudioPatch(&patch, &handle); |
| 1680 | } |
Eric Laurent | 4b12340 | 2014-04-11 09:22:20 -0700 | [diff] [blame] | 1681 | reply->writeInt32(status); |
| 1682 | if (status == NO_ERROR) { |
| 1683 | reply->write(&handle, sizeof(audio_patch_handle_t)); |
| 1684 | } |
| 1685 | return NO_ERROR; |
| 1686 | } break; |
| 1687 | case RELEASE_AUDIO_PATCH: { |
| 1688 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 1689 | audio_patch_handle_t handle; |
| 1690 | data.read(&handle, sizeof(audio_patch_handle_t)); |
| 1691 | status_t status = releaseAudioPatch(handle); |
| 1692 | reply->writeInt32(status); |
| 1693 | return NO_ERROR; |
| 1694 | } break; |
| 1695 | case LIST_AUDIO_PATCHES: { |
| 1696 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Eric Laurent | f75c2fe | 2015-04-02 13:49:15 -0700 | [diff] [blame] | 1697 | unsigned int numPatchesReq = data.readInt32(); |
| 1698 | if (numPatchesReq > MAX_ITEMS_PER_LIST) { |
| 1699 | numPatchesReq = MAX_ITEMS_PER_LIST; |
| 1700 | } |
| 1701 | unsigned int numPatches = numPatchesReq; |
Eric Laurent | 4b12340 | 2014-04-11 09:22:20 -0700 | [diff] [blame] | 1702 | struct audio_patch *patches = |
Eric Laurent | f75c2fe | 2015-04-02 13:49:15 -0700 | [diff] [blame] | 1703 | (struct audio_patch *)calloc(numPatchesReq, |
Eric Laurent | 4b12340 | 2014-04-11 09:22:20 -0700 | [diff] [blame] | 1704 | sizeof(struct audio_patch)); |
Eric Laurent | f75c2fe | 2015-04-02 13:49:15 -0700 | [diff] [blame] | 1705 | if (patches == NULL) { |
| 1706 | reply->writeInt32(NO_MEMORY); |
| 1707 | reply->writeInt32(0); |
| 1708 | return NO_ERROR; |
| 1709 | } |
| 1710 | status_t status = listAudioPatches(&numPatches, patches); |
Eric Laurent | 4b12340 | 2014-04-11 09:22:20 -0700 | [diff] [blame] | 1711 | reply->writeInt32(status); |
Eric Laurent | f75c2fe | 2015-04-02 13:49:15 -0700 | [diff] [blame] | 1712 | reply->writeInt32(numPatches); |
Eric Laurent | 4b12340 | 2014-04-11 09:22:20 -0700 | [diff] [blame] | 1713 | if (status == NO_ERROR) { |
Eric Laurent | f75c2fe | 2015-04-02 13:49:15 -0700 | [diff] [blame] | 1714 | if (numPatchesReq > numPatches) { |
| 1715 | numPatchesReq = numPatches; |
| 1716 | } |
| 1717 | reply->write(patches, numPatchesReq * sizeof(struct audio_patch)); |
Eric Laurent | 4b12340 | 2014-04-11 09:22:20 -0700 | [diff] [blame] | 1718 | } |
| 1719 | free(patches); |
| 1720 | return NO_ERROR; |
| 1721 | } break; |
| 1722 | case SET_AUDIO_PORT_CONFIG: { |
| 1723 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 1724 | struct audio_port_config config; |
Eric Laurent | 4dacbc3 | 2020-10-07 13:48:21 -0700 | [diff] [blame] | 1725 | status_t status = data.read(&config, sizeof(struct audio_port_config)); |
| 1726 | if (status != NO_ERROR) { |
| 1727 | return status; |
| 1728 | } |
| 1729 | status = AudioSanitizer::sanitizeAudioPortConfig(&config); |
| 1730 | if (status == NO_ERROR) { |
| 1731 | status = setAudioPortConfig(&config); |
| 1732 | } |
Eric Laurent | 4b12340 | 2014-04-11 09:22:20 -0700 | [diff] [blame] | 1733 | reply->writeInt32(status); |
| 1734 | return NO_ERROR; |
| 1735 | } break; |
Glenn Kasten | 9eae036 | 2016-04-19 09:09:14 -0700 | [diff] [blame] | 1736 | case GET_AUDIO_HW_SYNC_FOR_SESSION: { |
Eric Laurent | 93c3d41 | 2014-08-01 14:48:35 -0700 | [diff] [blame] | 1737 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 1738 | reply->writeInt32(getAudioHwSyncForSession((audio_session_t) data.readInt32())); |
Eric Laurent | 93c3d41 | 2014-08-01 14:48:35 -0700 | [diff] [blame] | 1739 | return NO_ERROR; |
| 1740 | } break; |
Eric Laurent | 72e3f39 | 2015-05-20 14:43:50 -0700 | [diff] [blame] | 1741 | case SYSTEM_READY: { |
| 1742 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 1743 | systemReady(); |
| 1744 | return NO_ERROR; |
| 1745 | } break; |
Glenn Kasten | 4a8308b | 2016-04-18 14:10:01 -0700 | [diff] [blame] | 1746 | case FRAME_COUNT_HAL: { |
| 1747 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 1748 | reply->writeInt64( frameCountHAL((audio_io_handle_t) data.readInt32()) ); |
| 1749 | return NO_ERROR; |
| 1750 | } break; |
jiabin | 9ff780e | 2018-03-19 18:19:52 -0700 | [diff] [blame] | 1751 | case GET_MICROPHONES: { |
jiabin | 46a76fa | 2018-01-05 10:18:21 -0800 | [diff] [blame] | 1752 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 1753 | std::vector<media::MicrophoneInfo> microphones; |
| 1754 | status_t status = getMicrophones(µphones); |
| 1755 | reply->writeInt32(status); |
| 1756 | if (status == NO_ERROR) { |
| 1757 | reply->writeParcelableVector(microphones); |
| 1758 | } |
| 1759 | return NO_ERROR; |
| 1760 | } |
Eric Laurent | 42896a0 | 2019-09-27 15:40:33 -0700 | [diff] [blame] | 1761 | case SET_AUDIO_HAL_PIDS: { |
| 1762 | CHECK_INTERFACE(IAudioFlinger, data, reply); |
| 1763 | std::vector<pid_t> pids; |
| 1764 | int32_t size; |
| 1765 | status_t status = data.readInt32(&size); |
| 1766 | if (status != NO_ERROR) { |
| 1767 | return status; |
| 1768 | } |
| 1769 | if (size < 0) { |
| 1770 | return BAD_VALUE; |
| 1771 | } |
| 1772 | if (size > MAX_ITEMS_PER_LIST) { |
| 1773 | size = MAX_ITEMS_PER_LIST; |
| 1774 | } |
| 1775 | for (int32_t i = 0; i < size; i++) { |
| 1776 | int32_t pid; |
| 1777 | status = data.readInt32(&pid); |
| 1778 | if (status != NO_ERROR) { |
| 1779 | return status; |
| 1780 | } |
| 1781 | pids.push_back(pid); |
| 1782 | } |
| 1783 | reply->writeInt32(setAudioHalPids(pids)); |
| 1784 | return NO_ERROR; |
| 1785 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1786 | default: |
| 1787 | return BBinder::onTransact(code, data, reply, flags); |
| 1788 | } |
| 1789 | } |
| 1790 | |
| 1791 | // ---------------------------------------------------------------------------- |
| 1792 | |
Glenn Kasten | 40bc906 | 2015-03-20 09:09:33 -0700 | [diff] [blame] | 1793 | } // namespace android |