1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef MULTIMEDIA_AUDIO_FFI_H 17 #define MULTIMEDIA_AUDIO_FFI_H 18 #include <cstdint> 19 #include "cj_common_ffi.h" 20 #include "native/ffi_remote_data.h" 21 22 namespace OHOS { 23 namespace AudioStandard { 24 extern "C" { 25 struct CAudioCapturerInfo { 26 int32_t capturerFlags; 27 int32_t source; 28 }; 29 30 struct CAudioStreamInfo { 31 int32_t channels; 32 int32_t encodingType; 33 int32_t sampleFormat; 34 int32_t samplingRate; 35 int64_t channelLayout; 36 }; 37 38 struct CAudioCapturerOptions { 39 CAudioCapturerInfo audioCapturerInfo; 40 CAudioStreamInfo audioStreamInfo; 41 }; 42 43 struct COptionArr { 44 CArrI32 arr; 45 bool hasValue; 46 }; 47 48 struct CDeviceDescriptor { 49 char *address; 50 CArrI32 channelCounts; 51 CArrI32 channelMasks; 52 int32_t deviceRole; 53 int32_t deviceType; 54 char *displayName; 55 COptionArr encodingTypes; 56 int32_t id; 57 char *name; 58 CArrI32 sampleRates; 59 }; 60 61 struct CArrDeviceDescriptor { 62 CDeviceDescriptor *head; 63 int64_t size; 64 }; 65 66 struct CAudioCapturerChangeInfo { 67 CAudioCapturerInfo audioCapturerInfo; 68 CArrDeviceDescriptor deviceDescriptors; 69 int32_t streamId; 70 bool muted; 71 }; 72 73 struct CDeviceChangeAction { 74 CArrDeviceDescriptor deviceDescriptors; 75 int32_t changeType; 76 }; 77 78 struct CArrAudioCapturerChangeInfo { 79 CAudioCapturerChangeInfo *head; 80 int64_t size; 81 }; 82 83 struct CInterruptEvent { 84 int32_t eventType; 85 int32_t forceType; 86 int32_t hintType; 87 }; 88 89 enum AudioCapturerCallbackType : int32_t { 90 AUDIO_CAPTURER_CHANGE = 0, 91 AUDIO_INTERRUPT, 92 INPUT_DEVICE_CHANGE, 93 MARK_REACH, 94 PERIOD_REACH, 95 READ_DATA, 96 STATE_CHANGE 97 }; 98 99 enum AudioStreamManagerCallbackType : int32_t { CAPTURER_CHANGE = 0, RENDERER_CHANGE }; 100 101 enum AudioRoutingManagerCallbackType : int32_t { 102 DEVICE_CHANGE = 0, 103 AVAILABLE_DEVICE_CHANGE, 104 INPUT_DEVICE_CHANGE_FOR_CAPTURER_INFO, 105 OUTPUT_DEVICE_CHANGE_FOR_RENDERER_INFO 106 }; 107 108 struct CVolumeEvent { 109 int32_t volume; 110 int32_t volumeType; 111 bool updateUi; 112 }; 113 114 enum AudioVolumeManagerCallbackType : int32_t { 115 VOLUME_CHANGE = 0 116 }; 117 118 enum AudioVolumeGroupManagerCallbackType : int32_t { 119 RING_MODE_CHANGE = 0, 120 MICSTATE_CHANGE 121 }; 122 123 struct CMicStateChangeEvent { 124 bool mute; 125 }; 126 127 struct CAudioStreamDeviceChangeInfo { 128 int32_t changeReason; 129 CArrDeviceDescriptor deviceDescriptors; 130 }; 131 132 struct CAudioRendererInfo { 133 int32_t usage; 134 int32_t rendererFlags; 135 }; 136 137 struct CAudioRendererOptions { 138 CAudioRendererInfo audioRendererInfo; 139 CAudioStreamInfo audioStreamInfo; 140 int32_t privacyType; 141 }; 142 143 struct CAudioRendererChangeInfo { 144 CAudioRendererInfo rendererInfo; 145 CArrDeviceDescriptor deviceDescriptors; 146 int32_t streamId; 147 }; 148 149 struct CArrAudioRendererChangeInfo { 150 CAudioRendererChangeInfo *head; 151 int64_t size; 152 }; 153 154 enum AudioRendererCallbackType : int32_t { 155 AR_AUDIO_INTERRUPT = 0, 156 AR_MARK_REACH, 157 AR_PERIOD_REACH, 158 AR_STATE_CHANGE, 159 AR_OUTPUT_DEVICE_CHANGE, 160 AR_OUTPUT_DEVICE_CHANGE_WITH_INFO, 161 AR_WRITE_DATA 162 }; 163 164 // Audio Capturer 165 // MMA is the addreviation of MultimediaAudio 166 FFI_EXPORT int64_t FfiMMACreateAudioCapturer(CAudioCapturerOptions options, int32_t *errorCode); 167 FFI_EXPORT int32_t FfiMMAAudioCapturerGetState(int64_t id, int32_t *errorCode); 168 FFI_EXPORT uint32_t FfiMMAAudioCapturerGetStreamId(int64_t id, int32_t *errorCode); 169 FFI_EXPORT int64_t FfiMMAAudioCapturerGetAudioTime(int64_t id, int32_t *errorCode); 170 FFI_EXPORT uint32_t FfiMMAAudioCapturerGetBufferSize(int64_t id, int32_t *errorCode); 171 FFI_EXPORT uint32_t FfiMMAAudioCapturerGetOverflowCount(int64_t id, int32_t *errorCode); 172 FFI_EXPORT void FfiMMAAudioCapturerStart(int64_t id, int32_t *errorCode); 173 FFI_EXPORT void FfiMMAAudioCapturerStop(int64_t id, int32_t *errorCode); 174 FFI_EXPORT void FfiMMAAudioCapturerRelease(int64_t id, int32_t *errorCode); 175 FFI_EXPORT CAudioCapturerChangeInfo FfiMMAAudioCapturerGetAudioCapturerChangeInfo(int64_t id, int32_t *errorCode); 176 FFI_EXPORT CArrDeviceDescriptor FfiMMAAudioCapturerGetInputDevices(int64_t id, int32_t *errorCode); 177 FFI_EXPORT CAudioCapturerInfo FfiMMAAudioCapturerGetCapturerInfo(int64_t id, int32_t *errorCode); 178 FFI_EXPORT CAudioStreamInfo FfiMMAAudioCapturerGetStreamInfo(int64_t id, int32_t *errorCode); 179 FFI_EXPORT void FfiMMAAudioCapturerOn(int64_t id, int32_t callbackType, void (*callback)(), int32_t *errorCode); 180 FFI_EXPORT void FfiMMAAudioCapturerOnWithFrame(int64_t id, int32_t callbackType, void (*callback)(), int64_t frame, 181 int32_t *errorCode); 182 183 // Audio Manager 184 FFI_EXPORT int64_t FfiMMACreateAudioManager(int32_t *errorCode); 185 FFI_EXPORT int64_t FfiMMAAudioManagerGetRoutingManager(int64_t id, int32_t *errorCode); 186 FFI_EXPORT int64_t FfiMMAAudioManagerGetStreamManager(int64_t id, int32_t *errorCode); 187 FFI_EXPORT int32_t FfiMMAAudioManagerGetAudioScene(int64_t id, int32_t *errorCode); 188 FFI_EXPORT int64_t FfiMMAAudioManagerGetVolumeManager(int64_t id, int32_t *errorCode); 189 190 // Audio Stream Manager 191 // ASM is the addreviation of Audio Stream Manager 192 FFI_EXPORT bool FfiMMAASMIsActive(int64_t id, int32_t volumeType, int32_t *errorCode); 193 FFI_EXPORT CArrAudioCapturerChangeInfo FfiMMAASMGetCurrentAudioCapturerInfoArray(int64_t id, int32_t *errorCode); 194 FFI_EXPORT CArrAudioRendererChangeInfo FfiMMAASMGetCurrentAudioRendererInfoArray(int64_t id, int32_t *errorCode); 195 FFI_EXPORT CArrI32 FfiMMAASMGetAudioEffectInfoArray(int64_t id, int32_t usage, int32_t *errorCode); 196 FFI_EXPORT void FfiMMAASMOn(int64_t id, int32_t callbackType, void (*callback)(), int32_t *errorCode); 197 198 // Audio Routing Manager 199 // ARM is the addreviation of Audio Routing Manager 200 FFI_EXPORT void FfiMMAARMSetCommunicationDevice(int64_t id, int32_t deviceType, bool active, int32_t *errorCode); 201 FFI_EXPORT bool FfiMMAARMIsCommunicationDeviceActive(int64_t id, int32_t deviceType, int32_t *errorCode); 202 FFI_EXPORT CArrDeviceDescriptor FfiMMAARMGetDevices(int64_t id, int32_t deviceFlag, int32_t *errorCode); 203 FFI_EXPORT CArrDeviceDescriptor FfiMMAARMGetPreferredInputDeviceForCapturerInfo(int64_t id, 204 CAudioCapturerInfo capturerInfo, int32_t *errorCode); 205 FFI_EXPORT CArrDeviceDescriptor FfiMMAARMGetPreferredOutputDeviceForRendererInfo(int64_t id, 206 CAudioRendererInfo rendererInfo, int32_t *errorCode); 207 FFI_EXPORT void FfiMMAARMOn(int64_t id, int32_t callbackType, uint32_t deviceUsage, void (*callback)(), 208 int32_t *errorCode); 209 FFI_EXPORT void FfiMMAARMOnWithFlags(int64_t id, int32_t callbackType, void (*callback)(), int32_t flags, 210 int32_t *errorCode); 211 FFI_EXPORT void FfiMMAARMOnWithCapturerInfo(int64_t id, int32_t callbackType, void (*callback)(), 212 CAudioCapturerInfo capturerInfo, int32_t *errorCode); 213 FFI_EXPORT void FfiMMAARMOnWithRendererInfo(int64_t id, int32_t callbackType, void (*callback)(), 214 CAudioRendererInfo rendererInfo, int32_t *errorCode); 215 216 // Audio Volumne Manager 217 // AVM is the addreviation of Audio Volume Manager 218 FFI_EXPORT int64_t FfiMMAAVMGetVolumeGroupManager(int64_t id, int32_t groupId, int32_t *errorCode); 219 FFI_EXPORT void FfiMMAAVMOn(int64_t id, int32_t callbackType, void (*callback)(), int32_t *errorCode); 220 221 // Audio Volumne Group Manager 222 // AVGM is the addreviation of Audio Volume Group Manager 223 FFI_EXPORT int32_t FfiMMAAVGMGetMaxVolume(int64_t id, int32_t volumeType, int32_t *errorCode); 224 FFI_EXPORT int32_t FfiMMAAVGMGetMinVolume(int64_t id, int32_t volumeType, int32_t *errorCode); 225 FFI_EXPORT int32_t FfiMMAAVGMGetRingerMode(int64_t id, int32_t *errorCode); 226 FFI_EXPORT float FfiMMAAVGMGetSystemVolumeInDb(int64_t id, int32_t volumeType, int32_t volumeLevel, int32_t device, 227 int32_t *errorCode); 228 FFI_EXPORT int32_t FfiMMAAVGMGetVolume(int64_t id, int32_t volumeType, int32_t *errorCode); 229 FFI_EXPORT bool FfiMMAAVGMIsMicrophoneMute(int64_t id, int32_t *errorCode); 230 FFI_EXPORT bool FfiMMAAVGMIsMute(int64_t id, int32_t volumeType, int32_t *errorCode); 231 FFI_EXPORT bool FfiMMAAVGMIsVolumeUnadjustable(int64_t id, int32_t *errorCode); 232 FFI_EXPORT float FfiMMAAVGMGetMaxAmplitudeForOutputDevice(int64_t id, CDeviceDescriptor desc, int32_t *errorCode); 233 FFI_EXPORT float FfiMMAAVGMGetMaxAmplitudeForInputDevice(int64_t id, CDeviceDescriptor desc, int32_t *errorCode); 234 FFI_EXPORT void FfiMMAAVGMOn(int64_t id, int32_t callbackType, void (*callback)(), int32_t *errorCode); 235 236 /* Audio Renderer */ 237 FFI_EXPORT int64_t FfiMMACreateAudioRenderer(CAudioRendererOptions options, int32_t *errorCode); 238 FFI_EXPORT int32_t FfiMMAARGetState(int64_t id, int32_t *errorCode); 239 FFI_EXPORT int64_t FfiMMAARGetAudioTime(int64_t id, int32_t *errorCode); 240 FFI_EXPORT uint32_t FfiMMAARGetBufferSize(int64_t id, int32_t *errorCode); 241 FFI_EXPORT void FfiMMAARFlush(int64_t id, int32_t *errorCode); 242 FFI_EXPORT void FfiMMAARPause(int64_t id, int32_t *errorCode); 243 FFI_EXPORT void FfiMMAARDrain(int64_t id, int32_t *errorCode); 244 FFI_EXPORT CArrDeviceDescriptor FfiMMAARGetCurrentOutputDevices(int64_t id, int32_t *errorCode); 245 FFI_EXPORT double FfiMMAARGetSpeed(int64_t id, int32_t *errorCode); 246 FFI_EXPORT bool FfiMMAARGetSilentModeAndMixWithOthers(int64_t id, int32_t *errorCode); 247 FFI_EXPORT double FfiMMAARGetVolume(int64_t id, int32_t *errorCode); 248 FFI_EXPORT uint32_t FfiMMAARGetUnderflowCount(int64_t id, int32_t *errorCode); 249 FFI_EXPORT void FfiMMAARSetVolumeWithRamp(int64_t id, double volume, int32_t duration, int32_t *errorCode); 250 FFI_EXPORT void FfiMMAARSetSpeed(int64_t id, double speed, int32_t *errorCode); 251 FFI_EXPORT void FfiMMAARSetVolume(int64_t id, double volume, int32_t *errorCode); 252 FFI_EXPORT void FfiMMAARSetSilentModeAndMixWithOthers(int64_t id, bool on, int32_t *errorCode); 253 FFI_EXPORT void FfiMMAARSetInterruptMode(int64_t id, int32_t mode, int32_t *errorCode); 254 FFI_EXPORT void FfiMMAARSetChannelBlendMode(int64_t id, int32_t mode, int32_t *errorCode); 255 FFI_EXPORT void FfiMMAAROnWithFrame(int64_t id, int32_t callbackType, void (*callback)(), int64_t frame, 256 int32_t *errorCode); 257 FFI_EXPORT void FfiMMAAROn(int64_t id, int32_t callbackType, void (*callback)(), int32_t *errorCode); 258 FFI_EXPORT int32_t FfiMMAARGetAudioEffectMode(int64_t id, int32_t *errorCode); 259 FFI_EXPORT void FfiMMAARSetAudioEffectMode(int64_t id, int32_t mode, int32_t *errorCode); 260 FFI_EXPORT double FfiMMAARGetMinStreamVolume(int64_t id, int32_t *errorCode); 261 FFI_EXPORT double FfiMMAARGetMaxStreamVolume(int64_t id, int32_t *errorCode); 262 FFI_EXPORT void FfiMMAARRelease(int64_t id, int32_t *errorCode); 263 FFI_EXPORT uint32_t FfiMMAARGetStreamId(int64_t id, int32_t *errorCode); 264 FFI_EXPORT void FfiMMAARStop(int64_t id, int32_t *errorCode); 265 FFI_EXPORT void FfiMMAARStart(int64_t id, int32_t *errorCode); 266 FFI_EXPORT CAudioStreamInfo FfiMMAARGetStreamInfo(int64_t id, int32_t *errorCode); 267 FFI_EXPORT CAudioRendererInfo FfiMMAARGetRendererInfo(int64_t id, int32_t *errorCode); 268 FFI_EXPORT int32_t FfiMMAGetVolume(int64_t id, int32_t volumeType, int32_t *errorCode); 269 FFI_EXPORT bool FfiMMAIsMicrophoneMute(int64_t id, int32_t *errorCode); 270 FFI_EXPORT bool FfiMMAIsMute(int64_t id, int32_t volumeType, int32_t *errorCode); 271 FFI_EXPORT bool FfiMMAIsVolumeUnadjustable(int64_t id, int32_t *errorCode); 272 } 273 } // namespace AudioStandard 274 } // namespace OHOS 275 #endif // MULTIMEDIA_AUDIO_FFI_H 276