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 MICROPHONE_BLOCKED, 104 INPUT_DEVICE_CHANGE_FOR_CAPTURER_INFO, 105 OUTPUT_DEVICE_CHANGE_FOR_RENDERER_INFO 106 }; 107 108 // Audio Capturer 109 // MMA is the addreviation of MultimediaAudio 110 FFI_EXPORT int64_t FfiMMACreateAudioCapturer(CAudioCapturerOptions options, int32_t *errorCode); 111 FFI_EXPORT int32_t FfiMMAAudioCapturerGetState(int64_t id, int32_t *errorCode); 112 FFI_EXPORT uint32_t FfiMMAAudioCapturerGetStreamId(int64_t id, int32_t *errorCode); 113 FFI_EXPORT int64_t FfiMMAAudioCapturerGetAudioTime(int64_t id, int32_t *errorCode); 114 FFI_EXPORT uint32_t FfiMMAAudioCapturerGetBufferSize(int64_t id, int32_t *errorCode); 115 FFI_EXPORT uint32_t FfiMMAAudioCapturerGetOverflowCount(int64_t id, int32_t *errorCode); 116 FFI_EXPORT void FfiMMAAudioCapturerStart(int64_t id, int32_t *errorCode); 117 FFI_EXPORT void FfiMMAAudioCapturerStop(int64_t id, int32_t *errorCode); 118 FFI_EXPORT void FfiMMAAudioCapturerRelease(int64_t id, int32_t *errorCode); 119 FFI_EXPORT CAudioCapturerChangeInfo FfiMMAAudioCapturerGetAudioCapturerChangeInfo(int64_t id, int32_t *errorCode); 120 FFI_EXPORT CArrDeviceDescriptor FfiMMAAudioCapturerGetInputDevices(int64_t id, int32_t *errorCode); 121 FFI_EXPORT CAudioCapturerInfo FfiMMAAudioCapturerGetCapturerInfo(int64_t id, int32_t *errorCode); 122 FFI_EXPORT CAudioStreamInfo FfiMMAAudioCapturerGetStreamInfo(int64_t id, int32_t *errorCode); 123 FFI_EXPORT void FfiMMAAudioCapturerOn(int64_t id, int32_t callbackType, void (*callback)(), int32_t *errorCode); 124 FFI_EXPORT void FfiMMAAudioCapturerOnWithFrame(int64_t id, int32_t callbackType, void (*callback)(), int64_t frame, 125 int32_t *errorCode); 126 127 // Audio Manager 128 FFI_EXPORT int64_t FfiMMACreateAudioManager(int32_t *errorCode); 129 FFI_EXPORT int64_t FfiMMAAudioManagerGetRoutingManager(int64_t id, int32_t *errorCode); 130 FFI_EXPORT int64_t FfiMMAAudioManagerGetStreamManager(int64_t id, int32_t *errorCode); 131 FFI_EXPORT int32_t FfiMMAAudioManagerGetAudioScene(int64_t id, int32_t *errorCode); 132 FFI_EXPORT int64_t FfiMMAAudioManagerGetVolumeManager(int64_t id, int32_t *errorCode); 133 134 // Audio Stream Manager 135 // ASM is the addreviation of Audio Stream Manager 136 FFI_EXPORT bool FfiMMAASMIsActive(int64_t id, int32_t volumeType, int32_t *errorCode); 137 FFI_EXPORT CArrAudioCapturerChangeInfo FfiMMAASMGetCurrentAudioCapturerInfoArray(int64_t id, int32_t *errorCode); 138 FFI_EXPORT CArrI32 FfiMMAASMGetAudioEffectInfoArray(int64_t id, int32_t usage, int32_t *errorCode); 139 FFI_EXPORT void FfiMMAASMOn(int64_t id, int32_t callbackType, void (*callback)(), int32_t *errorCode); 140 141 // Audio Routing Manager 142 // ARM is the addreviation of Audio Routing Manager 143 FFI_EXPORT void FfiMMAARMSetCommunicationDevice(int64_t id, int32_t deviceType, bool active, int32_t *errorCode); 144 FFI_EXPORT bool FfiMMAARMIsCommunicationDeviceActive(int64_t id, int32_t deviceType, int32_t *errorCode); 145 FFI_EXPORT CArrDeviceDescriptor FfiMMAARMGetDevices(int64_t id, int32_t deviceFlag, int32_t *errorCode); 146 FFI_EXPORT CArrDeviceDescriptor FfiMMAARMGetPreferredInputDeviceForCapturerInfo(int64_t id, 147 CAudioCapturerInfo capturerInfo, int32_t *errorCode); 148 FFI_EXPORT void FfiMMAARMOn(int64_t id, int32_t callbackType, void (*callback)(), int32_t *errorCode); 149 FFI_EXPORT void FfiMMAARMOnWithFlags(int64_t id, int32_t callbackType, void (*callback)(), int32_t flags, 150 int32_t *errorCode); 151 FFI_EXPORT void FfiMMAARMWOnithCapturerInfo(int64_t id, int32_t callbackType, void (*callback)(), 152 CAudioCapturerInfo capturerInfo, int32_t *errorCode); 153 154 // Audio Volumne Manager 155 // AVM is the addreviation of Audio Volume Manager 156 FFI_EXPORT int64_t FfiMMAAVMGetVolumeGroupManager(int64_t id, int32_t groupId, int32_t *errorCode); 157 158 // Audio Volumne Group Manager 159 // AVGM is the addreviation of Audio Volume Group Manager 160 FFI_EXPORT int32_t FfiMMAAVGMGetMaxVolume(int64_t id, int32_t volumeType, int32_t *errorCode); 161 FFI_EXPORT int32_t FfiMMAAVGMGetMinVolume(int64_t id, int32_t volumeType, int32_t *errorCode); 162 FFI_EXPORT int32_t FfiMMAAVGMGetRingerMode(int64_t id, int32_t *errorCode); 163 FFI_EXPORT float FfiMMAAVGMGetSystemVolumeInDb(int64_t id, int32_t volumeType, int32_t volumeLevel, int32_t device, 164 int32_t *errorCode); 165 FFI_EXPORT int32_t FfiMMAAVGMGetVolume(int64_t id, int32_t volumeType, int32_t *errorCode); 166 FFI_EXPORT bool FfiMMAAVGMIsMicrophoneMute(int64_t id, int32_t *errorCode); 167 FFI_EXPORT bool FfiMMAAVGMIsMute(int64_t id, int32_t volumeType, int32_t *errorCode); 168 FFI_EXPORT bool FfiMMAAVGMIsVolumeUnadjustable(int64_t id, int32_t *errorCode); 169 } 170 } // namespace AudioStandard 171 } // namespace OHOS 172 #endif // MULTIMEDIA_AUDIO_FFI_H 173