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