1 /* 2 * Copyright (c) 2025 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 INTF_DEF_H 17 #define INTF_DEF_H 18 19 #include <stdio.h> 20 #include <stdint.h> 21 #include <stdbool.h> 22 #include <string.h> 23 #include "audio_hdi_log.h" 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 #define MAX_MIX_CHANNELS 32 30 #define PA_MAX_OUTPUTS_PER_SOURCE 256 31 32 // device class 33 enum ClassType : uint32_t { 34 CLASS_TYPE_PRIMARY = 0, 35 CLASS_TYPE_A2DP, 36 CLASS_TYPE_FILE, 37 CLASS_TYPE_REMOTE, 38 CLASS_TYPE_USB, 39 CLASS_TYPE_OFFLOAD, 40 CLASS_TYPE_MULTICHANNEL, 41 CLASS_TYPE_DP, 42 CLASS_TYPE_NUM, 43 }; 44 45 // same with AudioSampleFormat in audio_info.h 46 enum AudioSampleFormatIntf { 47 SAMPLE_U8 = 0, 48 SAMPLE_S16 = 1, 49 SAMPLE_S24 = 2, 50 SAMPLE_S32 = 3, 51 SAMPLE_F32 = 4, 52 INVALID_WIDTH = -1, 53 }; 54 55 struct SinkAdapterAttr { 56 const char *adapterName; 57 uint32_t openMicSpeaker; 58 int32_t format; 59 uint32_t sampleRate; 60 uint32_t channel; 61 float volume; 62 const char *filePath; 63 const char *deviceNetworkId; 64 int32_t deviceType; 65 uint64_t channelLayout; 66 const char *aux; 67 }; 68 69 struct SinkAdapter { 70 uint32_t renderId; 71 const char *deviceClass; 72 73 int32_t (*SinkAdapterInit)(struct SinkAdapter *adapter, const struct SinkAdapterAttr *attr); 74 void (*SinkAdapterDeInit)(struct SinkAdapter *adapter); 75 int32_t (*SinkAdapterStart)(struct SinkAdapter *adapter); 76 int32_t (*SinkAdapterStop)(struct SinkAdapter *adapter); 77 int32_t (*SinkAdapterResume)(struct SinkAdapter *adapter); 78 int32_t (*SinkAdapterPause)(struct SinkAdapter *adapter); 79 int32_t (*SinkAdapterFlush)(struct SinkAdapter *adapter); 80 int32_t (*SinkAdapterReset)(struct SinkAdapter *adapter); 81 int32_t (*SinkAdapterRenderFrame)(struct SinkAdapter *adapter, char *data, uint64_t len, uint64_t *writeLen); 82 83 int32_t (*SinkAdapterSetVolume)(struct SinkAdapter *adapter, float left, float right); 84 int32_t (*SinkAdapterGetVolume)(struct SinkAdapter *adapter, float *left, float *right); 85 86 int32_t (*SinkAdapterGetLatency)(struct SinkAdapter *adapter, uint32_t *latency); 87 int32_t (*SinkAdapterGetPresentationPosition)(struct SinkAdapter *adapter, uint64_t *frames, int64_t *timeSec, 88 int64_t *timeNanoSec); 89 90 int32_t (*SinkAdapterGetAudioScene)(struct SinkAdapter *adapter); 91 92 int32_t (*SinkAdapterSetPaPower)(struct SinkAdapter *adapter, int32_t flag); 93 int32_t (*SinkAdapterSetPriPaPower)(struct SinkAdapter *adapter); 94 95 int32_t (*SinkAdapterUpdateAppsUid)(struct SinkAdapter *adapter, const int32_t appsUid[MAX_MIX_CHANNELS], 96 const size_t size); 97 98 // offload extend function 99 int32_t (*SinkAdapterRegistOffloadHdiCallback)(struct SinkAdapter *adapter, int8_t *rawCallback, int8_t *userdata); 100 int32_t (*SinkAdapterSetBufferSize)(struct SinkAdapter *adapter, uint32_t sizeMs); 101 int32_t (*SinkAdapterLockOffloadRunningLock)(struct SinkAdapter *adapter); 102 int32_t (*SinkAdapterUnLockOffloadRunningLock)(struct SinkAdapter *adapter); 103 104 // remote extend function 105 int32_t (*SinkAdapterSplitRenderFrame)(struct SinkAdapter *adapter, char *data, uint64_t len, uint64_t *writeLen, 106 const char *streamType); 107 108 // primary extend function 109 int32_t (*SinkSetDeviceConnectedFlag)(struct SinkAdapter *adapter, bool flag); 110 }; 111 112 struct SourceAdapterAttr { 113 const char *adapterName; 114 uint32_t openMicSpeaker; 115 int32_t format; 116 uint32_t sampleRate; 117 uint32_t channel; 118 float volume; 119 uint32_t bufferSize; 120 bool isBigEndian; 121 const char *filePath; 122 const char *deviceNetworkId; 123 int32_t deviceType; 124 int32_t sourceType; 125 uint64_t channelLayout; 126 bool hasEcConfig; 127 int32_t formatEc; 128 uint32_t sampleRateEc; 129 uint32_t channelEc; 130 }; 131 132 struct SourceAdapterFrameDesc { 133 char *frame; 134 uint64_t frameLen; 135 }; 136 137 struct SourceAdapter { 138 uint32_t captureId; 139 const char *deviceClass; 140 struct SourceAdapterAttr *attr; 141 uint32_t sessionId[PA_MAX_OUTPUTS_PER_SOURCE]; 142 143 int32_t (*SourceAdapterInit)(struct SourceAdapter *adapter, const struct SourceAdapterAttr *attr); 144 void (*SourceAdapterDeInit)(struct SourceAdapter *adapter); 145 146 int32_t (*SourceAdapterStart)(struct SourceAdapter *adapter); 147 int32_t (*SourceAdapterStop)(struct SourceAdapter *adapter); 148 int32_t (*SourceAdapterCaptureFrame)(struct SourceAdapter *adapter, char *frame, uint64_t requestBytes, 149 uint64_t *replyBytes); 150 int32_t (*SourceAdapterCaptureFrameWithEc)(struct SourceAdapter *adapter, struct SourceAdapterFrameDesc *fdesc, 151 uint64_t *replyBytes, struct SourceAdapterFrameDesc *fdescEc, uint64_t *replyBytesEc); 152 153 int32_t (*SourceAdapterSetVolume)(struct SourceAdapter *adapter, float left, float right); 154 int32_t (*SourceAdapterGetVolume)(struct SourceAdapter *adapter, float *left, float *right); 155 int32_t (*SourceAdapterSetMute)(struct SourceAdapter *adapter, bool isMute); 156 bool (*SourceAdapterGetMute)(struct SourceAdapter *adapter); 157 158 int32_t (*SourceAdapterUpdateAppsUid)(struct SourceAdapter *adapter, 159 const int32_t appsUid[PA_MAX_OUTPUTS_PER_SOURCE], const size_t size); 160 int32_t (*SourceAdapterUpdateSessionUid)(struct SourceAdapter *adapter, 161 const int32_t sessionId[PA_MAX_OUTPUTS_PER_SOURCE], const size_t size); 162 }; 163 164 typedef enum EcType { 165 EC_NONE = 0, 166 EC_SAME_ADAPTER, 167 EC_DIFFERENT_ADAPTER 168 } EcType; 169 170 typedef enum MicRefSwitch { 171 REF_OFF = 0, 172 REF_ON 173 } MicRefSwitch; 174 175 #ifdef __cplusplus 176 } 177 #endif 178 #endif // INTF_DEF_H 179