1094332d3Sopenharmony_ci/*
2094332d3Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License.
5094332d3Sopenharmony_ci * You may obtain a copy of the License at
6094332d3Sopenharmony_ci *
7094332d3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8094332d3Sopenharmony_ci *
9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and
13094332d3Sopenharmony_ci * limitations under the License.
14094332d3Sopenharmony_ci */
15094332d3Sopenharmony_ci
16094332d3Sopenharmony_ci#ifndef AUDIO_INTERNAL_H
17094332d3Sopenharmony_ci#define AUDIO_INTERNAL_H
18094332d3Sopenharmony_ci
19094332d3Sopenharmony_ci#include <inttypes.h>
20094332d3Sopenharmony_ci#include <pthread.h>
21094332d3Sopenharmony_ci#include "hdf_base.h"
22094332d3Sopenharmony_ci#include "hdf_remote_service.h"
23094332d3Sopenharmony_ci#include "hdf_sbuf.h"
24094332d3Sopenharmony_ci#include "v4_0/iaudio_adapter.h"
25094332d3Sopenharmony_ci#include "v4_0/iaudio_callback.h"
26094332d3Sopenharmony_ci#include "v4_0/iaudio_capture.h"
27094332d3Sopenharmony_ci#include "v4_0/iaudio_manager.h"
28094332d3Sopenharmony_ci#include "v4_0/iaudio_render.h"
29094332d3Sopenharmony_ci#include "v4_0/audio_types.h"
30094332d3Sopenharmony_ci
31094332d3Sopenharmony_ci#ifdef __cplusplus
32094332d3Sopenharmony_ciextern "C" {
33094332d3Sopenharmony_ci#endif
34094332d3Sopenharmony_ci
35094332d3Sopenharmony_ci#define LOG_ENABLE            0
36094332d3Sopenharmony_ci#define LOGV_ENABLE           0
37094332d3Sopenharmony_ci#define NAME_LEN              64
38094332d3Sopenharmony_ci#define BIT_NUM_32            32
39094332d3Sopenharmony_ci#define BIT_NUM_24            24
40094332d3Sopenharmony_ci#define BIT_NUM_16            16
41094332d3Sopenharmony_ci#define BIT_NUM_8             8
42094332d3Sopenharmony_ci#define PERIOD_COUNT          2
43094332d3Sopenharmony_ci#define FRAME_DATA            (8192 * 2)
44094332d3Sopenharmony_ci#define PATHPLAN_LEN          64
45094332d3Sopenharmony_ci#define PATHPLAN_COUNT        32
46094332d3Sopenharmony_ci#define PATH_NAME_LEN         128
47094332d3Sopenharmony_ci#define VOLUME_CHANGE         100
48094332d3Sopenharmony_ci#define SEC_TO_NSEC           1000000000
49094332d3Sopenharmony_ci#define MAP_MAX               100
50094332d3Sopenharmony_ci#define FORMAT_ONE            "%-5d  %-10d  %-20" PRIu64 " %-15s  %s\n"
51094332d3Sopenharmony_ci#define FORMAT_TWO            "%-5d  %-10d  %s\n"
52094332d3Sopenharmony_ci#define ERROR_LOG_MAX_NUM     8
53094332d3Sopenharmony_ci#define ERROR_REASON_DESC_LEN 64
54094332d3Sopenharmony_ci#define RANGE_MAX             5
55094332d3Sopenharmony_ci#define RANGE_MIN             4
56094332d3Sopenharmony_ci#define EXTPARAM_LEN          32
57094332d3Sopenharmony_ci#define KEY_VALUE_LIST_LEN    128
58094332d3Sopenharmony_ci#define MAX_AUDIO_STREAM_NUM  10
59094332d3Sopenharmony_ci
60094332d3Sopenharmony_ci#define HDF_AUDIO_CODEC_PRIMARY_DEV "hdf_audio_codec_primary_dev"
61094332d3Sopenharmony_ci#define HDF_AUDIO_CODEC_HDMI_DEV    "hdf_audio_codec_hdmi_dev"
62094332d3Sopenharmony_ci#define HDF_AUDIO_CODEC_USB_DEV     "hdf_audio_codec_usb_dev"
63094332d3Sopenharmony_ci#define HDF_AUDIO_CODEC_A2DP_DEV    "hdf_audio_codec_a2dp_dev"
64094332d3Sopenharmony_ci#define PRIMARY                     "primary"
65094332d3Sopenharmony_ci#define USB                         "usb"
66094332d3Sopenharmony_ci#define A2DP                        "a2dp"
67094332d3Sopenharmony_ci#define HDMI                        "hdmi"
68094332d3Sopenharmony_ci
69094332d3Sopenharmony_citypedef void *AudioHandle;
70094332d3Sopenharmony_ci
71094332d3Sopenharmony_ci/**
72094332d3Sopenharmony_ci * @brief Enumerates HAL return value types.
73094332d3Sopenharmony_ci */
74094332d3Sopenharmony_citypedef enum {
75094332d3Sopenharmony_ci    AUDIO_SUCCESS = 0,
76094332d3Sopenharmony_ci    AUDIO_ERR_INTERNAL = -1,       /* audio system internal errors */
77094332d3Sopenharmony_ci    AUDIO_ERR_NOT_SUPPORT = -2,    /* operation is not supported */
78094332d3Sopenharmony_ci    AUDIO_ERR_INVALID_PARAM = -3,  /* parameter is invaild */
79094332d3Sopenharmony_ci    AUDIO_ERR_INVALID_OBJECT = -4, /* Invalid object */
80094332d3Sopenharmony_ci    AUDIO_ERR_MALLOC_FAIL = -6,    /* Memory allocation fails */
81094332d3Sopenharmony_ci    AUDIO_ERR_NOTREADY = -7001,    /* audio adapter is not ready */
82094332d3Sopenharmony_ci    AUDIO_ERR_AI_BUSY = -7002,     /* audio capture is busy now */
83094332d3Sopenharmony_ci    AUDIO_ERR_AO_BUSY = -7003,     /* audio render is busy now */
84094332d3Sopenharmony_ci} AUDIO_UHDF_ERR_CODE;
85094332d3Sopenharmony_ci
86094332d3Sopenharmony_citypedef enum {
87094332d3Sopenharmony_ci    TELHPONE_RATE = 8000,
88094332d3Sopenharmony_ci    BROADCAST_AM_RATE = 11025,
89094332d3Sopenharmony_ci    BROADCAST_FM_RATE = 22050,
90094332d3Sopenharmony_ci    MINI_CAM_DV_RATE = 32000,
91094332d3Sopenharmony_ci    MUSIC_RATE = 44100,
92094332d3Sopenharmony_ci    HIGHT_MUSIC_RATE = 48000,
93094332d3Sopenharmony_ci    AUDIO_SAMPLE_RATE_12000 = 12000,
94094332d3Sopenharmony_ci    AUDIO_SAMPLE_RATE_16000 = 16000,
95094332d3Sopenharmony_ci    AUDIO_SAMPLE_RATE_24000 = 24000,
96094332d3Sopenharmony_ci    AUDIO_SAMPLE_RATE_64000 = 64000,
97094332d3Sopenharmony_ci    AUDIO_SAMPLE_RATE_96000 = 96000
98094332d3Sopenharmony_ci} AUDIO_SAMPLE_RATE;
99094332d3Sopenharmony_ci
100094332d3Sopenharmony_ci#ifndef UT_TEST
101094332d3Sopenharmony_ci#define STATIC_T static
102094332d3Sopenharmony_ci#else
103094332d3Sopenharmony_ci#define STATIC_T
104094332d3Sopenharmony_ci#endif
105094332d3Sopenharmony_ci
106094332d3Sopenharmony_ci#define ADAPTER_NAME_LEN 32
107094332d3Sopenharmony_ci
108094332d3Sopenharmony_ci#define USECASE_AUDIO_RENDER_DEEP_BUFFER "deep-buffer-render"
109094332d3Sopenharmony_ci#define USECASE_AUDIO_RENDER_LOW_LATENCY "low-latency-render"
110094332d3Sopenharmony_ci
111094332d3Sopenharmony_ci#define AUDIO_ATTR_PARAM_ROUTE         "attr-route"
112094332d3Sopenharmony_ci#define ROUTE_SAMPLE                   "attr-route=x;"
113094332d3Sopenharmony_ci#define AUDIO_ATTR_PARAM_FORMAT        "attr-format"
114094332d3Sopenharmony_ci#define FORMAT_SAMPLE                  "attr-format=xx;"
115094332d3Sopenharmony_ci#define AUDIO_ATTR_PARAM_CHANNELS      "attr-channels"
116094332d3Sopenharmony_ci#define CHANNELS_SAMPLE                "attr-channels=x;"
117094332d3Sopenharmony_ci#define AUDIO_ATTR_PARAM_FRAME_COUNT   "attr-frame-count"
118094332d3Sopenharmony_ci#define FRAME_COUNT_SAMPLE             "attr-frame-count=xxxxxxxxxxxxxxxxxxxx;"
119094332d3Sopenharmony_ci#define AUDIO_ATTR_PARAM_SAMPLING_RATE "attr-sampling-rate"
120094332d3Sopenharmony_ci#define SAMPLING_RATE_SAMPLE           "attr-sampling-rate=xxxxx"
121094332d3Sopenharmony_ci#define AUDIO_ATTR_PARAM_CONNECT       "usb-connect"
122094332d3Sopenharmony_ci#define AUDIO_ATTR_PARAM_DISCONNECT    "usb-disconnect"
123094332d3Sopenharmony_ci#define SUPPORT_ADAPTER_NUM_MAX        8
124094332d3Sopenharmony_ci
125094332d3Sopenharmony_citypedef int32_t (*CallbackProcessFunc)(AudioHandle handle, enum AudioCallbackType callBackType);
126094332d3Sopenharmony_ci
127094332d3Sopenharmony_cienum AudioTurnStandbyMode {
128094332d3Sopenharmony_ci    AUDIO_TURN_STANDBY_LATER = 0,
129094332d3Sopenharmony_ci    AUDIO_TURN_STANDBY_NOW,
130094332d3Sopenharmony_ci    AUDIO_TURN_STANDBY_BUTT,
131094332d3Sopenharmony_ci};
132094332d3Sopenharmony_ci
133094332d3Sopenharmony_cistruct DevHandle {
134094332d3Sopenharmony_ci    void *object;
135094332d3Sopenharmony_ci};
136094332d3Sopenharmony_ci
137094332d3Sopenharmony_cistruct AudioPortAndCapability {
138094332d3Sopenharmony_ci    struct AudioPort port;
139094332d3Sopenharmony_ci    struct AudioPortCapability capability;
140094332d3Sopenharmony_ci    enum AudioPortPassthroughMode mode;
141094332d3Sopenharmony_ci};
142094332d3Sopenharmony_ci
143094332d3Sopenharmony_cistruct AudioFrameRenderMode {
144094332d3Sopenharmony_ci    uint64_t frames;
145094332d3Sopenharmony_ci    struct AudioTimeStamp time;
146094332d3Sopenharmony_ci    struct AudioSampleAttributes attrs;
147094332d3Sopenharmony_ci    enum AudioChannelMode mode;
148094332d3Sopenharmony_ci    uint32_t byteRate;
149094332d3Sopenharmony_ci    uint32_t periodSize;
150094332d3Sopenharmony_ci    uint32_t periodCount;
151094332d3Sopenharmony_ci    uint32_t startThreshold;
152094332d3Sopenharmony_ci    uint32_t stopThreshold;
153094332d3Sopenharmony_ci    uint32_t silenceThreshold;
154094332d3Sopenharmony_ci    uint32_t silenceSize;
155094332d3Sopenharmony_ci    char *buffer;
156094332d3Sopenharmony_ci    uint64_t bufferFrameSize;
157094332d3Sopenharmony_ci    uint64_t bufferSize;
158094332d3Sopenharmony_ci    pthread_mutex_t mutex;
159094332d3Sopenharmony_ci    struct IAudioCallback callback;
160094332d3Sopenharmony_ci    void *cookie;
161094332d3Sopenharmony_ci    CallbackProcessFunc callbackProcess;
162094332d3Sopenharmony_ci    AudioHandle renderhandle;
163094332d3Sopenharmony_ci    struct AudioMmapBufferDescriptor mmapBufDesc;
164094332d3Sopenharmony_ci};
165094332d3Sopenharmony_ci
166094332d3Sopenharmony_cistruct AudioGain {
167094332d3Sopenharmony_ci    float gain;
168094332d3Sopenharmony_ci    float gainMin;
169094332d3Sopenharmony_ci    float gainMax;
170094332d3Sopenharmony_ci};
171094332d3Sopenharmony_ci
172094332d3Sopenharmony_cistruct AudioVol {
173094332d3Sopenharmony_ci    int volMin;
174094332d3Sopenharmony_ci    int volMax;
175094332d3Sopenharmony_ci};
176094332d3Sopenharmony_ci
177094332d3Sopenharmony_cistruct AudioCtlParam {
178094332d3Sopenharmony_ci    bool mute;
179094332d3Sopenharmony_ci    bool pause;
180094332d3Sopenharmony_ci    bool stop;
181094332d3Sopenharmony_ci    bool mutexFlag;
182094332d3Sopenharmony_ci    float volume;
183094332d3Sopenharmony_ci    float speed;
184094332d3Sopenharmony_ci    pthread_mutex_t mutex;
185094332d3Sopenharmony_ci    pthread_cond_t functionCond;
186094332d3Sopenharmony_ci    struct AudioVol volThreshold;
187094332d3Sopenharmony_ci    struct AudioGain audioGain;
188094332d3Sopenharmony_ci    enum AudioTurnStandbyMode turnStandbyStatus;
189094332d3Sopenharmony_ci};
190094332d3Sopenharmony_ci
191094332d3Sopenharmony_cienum PathRoute {
192094332d3Sopenharmony_ci    DEEP_BUFF = 0,
193094332d3Sopenharmony_ci    RECORD,
194094332d3Sopenharmony_ci    RECORD_LOW_LATRNCY,
195094332d3Sopenharmony_ci    LOW_LATRNCY,
196094332d3Sopenharmony_ci};
197094332d3Sopenharmony_ci
198094332d3Sopenharmony_cistruct PathPlan {
199094332d3Sopenharmony_ci    char pathPlanName[PATHPLAN_LEN];
200094332d3Sopenharmony_ci    int value;
201094332d3Sopenharmony_ci};
202094332d3Sopenharmony_ci
203094332d3Sopenharmony_cistruct PathDeviceSwitch {
204094332d3Sopenharmony_ci    char deviceSwitch[PATHPLAN_LEN];
205094332d3Sopenharmony_ci    int32_t value;
206094332d3Sopenharmony_ci};
207094332d3Sopenharmony_ci
208094332d3Sopenharmony_cistruct PathDeviceInfo {
209094332d3Sopenharmony_ci    char deviceType[NAME_LEN];
210094332d3Sopenharmony_ci    int32_t deviceNum;
211094332d3Sopenharmony_ci    struct PathDeviceSwitch deviceSwitchs[PATHPLAN_COUNT];
212094332d3Sopenharmony_ci};
213094332d3Sopenharmony_ci
214094332d3Sopenharmony_cistruct PathSelect {
215094332d3Sopenharmony_ci    char useCase[NAME_LEN];
216094332d3Sopenharmony_ci    struct PathDeviceInfo deviceInfo;
217094332d3Sopenharmony_ci    int useCaseDeviceNum;
218094332d3Sopenharmony_ci    struct PathPlan pathPlan[PATHPLAN_COUNT];
219094332d3Sopenharmony_ci};
220094332d3Sopenharmony_ci
221094332d3Sopenharmony_cistruct HwInfo {
222094332d3Sopenharmony_ci    uint32_t card;
223094332d3Sopenharmony_ci    uint32_t device;
224094332d3Sopenharmony_ci    char cardServiceName[NAME_LEN];
225094332d3Sopenharmony_ci    int flags;
226094332d3Sopenharmony_ci    bool callBackEnable;
227094332d3Sopenharmony_ci    char adapterName[NAME_LEN];
228094332d3Sopenharmony_ci    struct AudioPort portDescript;
229094332d3Sopenharmony_ci    struct AudioDeviceDescriptor deviceDescript;
230094332d3Sopenharmony_ci    enum PathRoute pathroute;
231094332d3Sopenharmony_ci    struct PathSelect pathSelect;
232094332d3Sopenharmony_ci};
233094332d3Sopenharmony_ci
234094332d3Sopenharmony_cistruct AudioHwRenderMode {
235094332d3Sopenharmony_ci    struct AudioCtlParam ctlParam;
236094332d3Sopenharmony_ci    struct HwInfo hwInfo;
237094332d3Sopenharmony_ci};
238094332d3Sopenharmony_ci
239094332d3Sopenharmony_cistruct AudioHwRenderParam {
240094332d3Sopenharmony_ci    struct AudioHwRenderMode renderMode;
241094332d3Sopenharmony_ci    struct AudioFrameRenderMode frameRenderMode;
242094332d3Sopenharmony_ci};
243094332d3Sopenharmony_ci
244094332d3Sopenharmony_cistruct ErrorDump {
245094332d3Sopenharmony_ci    int32_t errorCode;
246094332d3Sopenharmony_ci    int32_t count;
247094332d3Sopenharmony_ci    uint64_t frames;
248094332d3Sopenharmony_ci    char *reason; // Specific reasons for failure
249094332d3Sopenharmony_ci    char *currentTime;
250094332d3Sopenharmony_ci};
251094332d3Sopenharmony_ci
252094332d3Sopenharmony_cistruct ErrorLog {
253094332d3Sopenharmony_ci    uint32_t totalErrors;
254094332d3Sopenharmony_ci    uint32_t iter;
255094332d3Sopenharmony_ci    struct ErrorDump errorDump[ERROR_LOG_MAX_NUM];
256094332d3Sopenharmony_ci};
257094332d3Sopenharmony_ci
258094332d3Sopenharmony_cistruct AudioHwRender {
259094332d3Sopenharmony_ci    struct IAudioRender common;
260094332d3Sopenharmony_ci    struct HdfRemoteService *remote;
261094332d3Sopenharmony_ci    struct HdfRemoteDispatcher dispatcher;
262094332d3Sopenharmony_ci    struct AudioHwRenderParam renderParam;
263094332d3Sopenharmony_ci    struct DevHandle *devDataHandle;            // Bind Data handle
264094332d3Sopenharmony_ci    struct DevHandle *devCtlHandle;             // Bind Ctl handle
265094332d3Sopenharmony_ci    struct HdfRemoteService *proxyRemoteHandle; // proxyPriRemoteHandle
266094332d3Sopenharmony_ci    struct ErrorLog errorLog;
267094332d3Sopenharmony_ci};
268094332d3Sopenharmony_ci
269094332d3Sopenharmony_cistruct AudioHwCaptureMode {
270094332d3Sopenharmony_ci    struct AudioCtlParam ctlParam;
271094332d3Sopenharmony_ci    struct HwInfo hwInfo;
272094332d3Sopenharmony_ci};
273094332d3Sopenharmony_ci
274094332d3Sopenharmony_cistruct AudioFrameCaptureMode {
275094332d3Sopenharmony_ci    uint64_t frames;
276094332d3Sopenharmony_ci    struct AudioTimeStamp time;
277094332d3Sopenharmony_ci    struct AudioSampleAttributes attrs;
278094332d3Sopenharmony_ci    enum AudioChannelMode mode;
279094332d3Sopenharmony_ci    uint32_t byteRate;
280094332d3Sopenharmony_ci    uint32_t periodSize;
281094332d3Sopenharmony_ci    uint32_t periodCount;
282094332d3Sopenharmony_ci    uint32_t startThreshold;
283094332d3Sopenharmony_ci    uint32_t stopThreshold;
284094332d3Sopenharmony_ci    uint32_t silenceThreshold;
285094332d3Sopenharmony_ci    uint32_t silenceSize;
286094332d3Sopenharmony_ci    char *buffer;
287094332d3Sopenharmony_ci    uint64_t bufferFrameSize;
288094332d3Sopenharmony_ci    uint64_t bufferSize;
289094332d3Sopenharmony_ci    struct AudioMmapBufferDescriptor mmapBufDesc;
290094332d3Sopenharmony_ci};
291094332d3Sopenharmony_ci
292094332d3Sopenharmony_cistruct AudioHwCaptureParam {
293094332d3Sopenharmony_ci    struct AudioHwCaptureMode captureMode;
294094332d3Sopenharmony_ci    struct AudioFrameCaptureMode frameCaptureMode;
295094332d3Sopenharmony_ci};
296094332d3Sopenharmony_ci
297094332d3Sopenharmony_cistruct AudioHwCapture {
298094332d3Sopenharmony_ci    struct IAudioCapture common;
299094332d3Sopenharmony_ci    struct HdfRemoteService *proxyRemoteHandle;
300094332d3Sopenharmony_ci    struct HdfRemoteDispatcher dispatcher;
301094332d3Sopenharmony_ci    struct AudioHwCaptureParam captureParam;
302094332d3Sopenharmony_ci    struct DevHandle *devDataHandle; // Bind Data handle
303094332d3Sopenharmony_ci    struct DevHandle *devCtlHandle;  // Bind Ctl handle
304094332d3Sopenharmony_ci    struct ErrorLog errorLog;
305094332d3Sopenharmony_ci};
306094332d3Sopenharmony_ci
307094332d3Sopenharmony_cistruct AudioRenderAndCaptureInfo {
308094332d3Sopenharmony_ci    struct AudioHwRender *renderServicePtr[MAX_AUDIO_STREAM_NUM];
309094332d3Sopenharmony_ci    uint32_t renderCnt;
310094332d3Sopenharmony_ci    struct AudioHwCapture *captureServicePtr[MAX_AUDIO_STREAM_NUM];
311094332d3Sopenharmony_ci    uint32_t captureCnt;
312094332d3Sopenharmony_ci};
313094332d3Sopenharmony_ci
314094332d3Sopenharmony_cistruct AudioHwAdapter {
315094332d3Sopenharmony_ci    struct IAudioAdapter common;
316094332d3Sopenharmony_ci    struct HdfRemoteService *proxyRemoteHandle;
317094332d3Sopenharmony_ci    struct HdfRemoteDispatcher dispatcher;
318094332d3Sopenharmony_ci    struct AudioAdapterDescriptor adapterDescriptor;
319094332d3Sopenharmony_ci    struct AudioPortAndCapability *portCapabilitys;
320094332d3Sopenharmony_ci    struct AudioRenderAndCaptureInfo infos;
321094332d3Sopenharmony_ci};
322094332d3Sopenharmony_ci
323094332d3Sopenharmony_cistruct AudioAdapterInfo {
324094332d3Sopenharmony_ci    char adapterName[ADAPTER_NAME_LEN];
325094332d3Sopenharmony_ci    struct AudioHwAdapter *adapterServicePtr;
326094332d3Sopenharmony_ci    uint32_t refCnt;
327094332d3Sopenharmony_ci};
328094332d3Sopenharmony_ci
329094332d3Sopenharmony_cistruct AudioHwManager {
330094332d3Sopenharmony_ci    struct IAudioManager interface;
331094332d3Sopenharmony_ci    int32_t (*OnRemoteRequest)(
332094332d3Sopenharmony_ci        struct IAudioManager *serviceImpl, int code, struct HdfSBuf *data, struct HdfSBuf *reply);
333094332d3Sopenharmony_ci    struct AudioAdapterInfo adapterInfos[SUPPORT_ADAPTER_NUM_MAX];
334094332d3Sopenharmony_ci};
335094332d3Sopenharmony_ci
336094332d3Sopenharmony_cistruct ParamValMap {
337094332d3Sopenharmony_ci    char key[EXTPARAM_LEN];
338094332d3Sopenharmony_ci    char value[EXTPARAM_LEN];
339094332d3Sopenharmony_ci};
340094332d3Sopenharmony_ci
341094332d3Sopenharmony_cistruct ExtraParams {
342094332d3Sopenharmony_ci    int32_t route;
343094332d3Sopenharmony_ci    int32_t format;
344094332d3Sopenharmony_ci    uint32_t channels;
345094332d3Sopenharmony_ci    uint64_t frames;
346094332d3Sopenharmony_ci    uint32_t sampleRate;
347094332d3Sopenharmony_ci    bool flag;
348094332d3Sopenharmony_ci};
349094332d3Sopenharmony_ci
350094332d3Sopenharmony_cienum AudioAddrType {
351094332d3Sopenharmony_ci    AUDIO_ADAPTER_ADDR = 0, /** Record the address of the adapter for FUZZ. */
352094332d3Sopenharmony_ci    AUDIO_RENDER_ADDR,      /** Record the address of the render for FUZZ. */
353094332d3Sopenharmony_ci    AUDIO_CAPTURE_ADDR,     /** Record the address of the capturef or FUZZ. */
354094332d3Sopenharmony_ci    AUDIO_INVALID_ADDR,     /** Invalid value. */
355094332d3Sopenharmony_ci};
356094332d3Sopenharmony_ci
357094332d3Sopenharmony_cistruct AudioAddrDB { // Record the address of the adapter Mgr for FUZZ.
358094332d3Sopenharmony_ci    void *addrValue;
359094332d3Sopenharmony_ci    const char *adapterName;
360094332d3Sopenharmony_ci    enum AudioAddrType addrType;
361094332d3Sopenharmony_ci};
362094332d3Sopenharmony_ci
363094332d3Sopenharmony_cienum ErrorDumpCode {
364094332d3Sopenharmony_ci    WRITE_FRAME_ERROR_CODE = -5,
365094332d3Sopenharmony_ci};
366094332d3Sopenharmony_ci
367094332d3Sopenharmony_cienum AudioAdaptType {
368094332d3Sopenharmony_ci    INVAILD_PATH_SELECT = -1,
369094332d3Sopenharmony_ci    RENDER_PATH_SELECT,
370094332d3Sopenharmony_ci    CAPTURE_PATH_SELECT,
371094332d3Sopenharmony_ci    CHECKSCENE_PATH_SELECT,
372094332d3Sopenharmony_ci    CHECKSCENE_PATH_SELECT_CAPTURE,
373094332d3Sopenharmony_ci};
374094332d3Sopenharmony_ci
375094332d3Sopenharmony_cienum AudioServiceNameType {
376094332d3Sopenharmony_ci    AUDIO_SERVICE_IN = 0,
377094332d3Sopenharmony_ci    AUDIO_SERVICE_OUT,
378094332d3Sopenharmony_ci    AUDIO_SERVICE_MAX,
379094332d3Sopenharmony_ci};
380094332d3Sopenharmony_ci
381094332d3Sopenharmony_ci/* dispatch cmdId */
382094332d3Sopenharmony_cienum AudioInterfaceLibParaCmdList {
383094332d3Sopenharmony_ci    AUDIO_DRV_PCM_IOCTL_HW_PARAMS = 0,
384094332d3Sopenharmony_ci    AUDIO_DRV_PCM_IOCTL_PREPARE,
385094332d3Sopenharmony_ci    AUDIO_DRV_PCM_IOCTL_PREPARE_CAPTURE,
386094332d3Sopenharmony_ci    AUDIO_DRV_PCM_IOCTL_WRITE,
387094332d3Sopenharmony_ci    AUDIO_DRV_PCM_IOCTL_READ,
388094332d3Sopenharmony_ci    AUDIO_DRV_PCM_IOCTRL_START,
389094332d3Sopenharmony_ci    AUDIO_DRV_PCM_IOCTRL_STOP,
390094332d3Sopenharmony_ci    AUDIO_DRV_PCM_IOCTRL_START_CAPTURE,
391094332d3Sopenharmony_ci    AUDIO_DRV_PCM_IOCTRL_STOP_CAPTURE,
392094332d3Sopenharmony_ci    AUDIO_DRV_PCM_IOCTRL_PAUSE,
393094332d3Sopenharmony_ci    AUDIO_DRV_PCM_IOCTRL_PAUSE_CAPTURE,
394094332d3Sopenharmony_ci    AUDIO_DRV_PCM_IOCTRL_RESUME,
395094332d3Sopenharmony_ci    AUDIO_DRV_PCM_IOCTRL_RESUME_CAPTURE,
396094332d3Sopenharmony_ci    AUDIO_DRV_PCM_IOCTL_MMAP_BUFFER,
397094332d3Sopenharmony_ci    AUDIO_DRV_PCM_IOCTL_MMAP_BUFFER_CAPTURE,
398094332d3Sopenharmony_ci    AUDIO_DRV_PCM_IOCTL_MMAP_POSITION,
399094332d3Sopenharmony_ci    AUDIO_DRV_PCM_IOCTL_MMAP_POSITION_CAPTURE,
400094332d3Sopenharmony_ci    AUDIO_DRV_PCM_IOCTRL_RENDER_OPEN,
401094332d3Sopenharmony_ci    AUDIO_DRV_PCM_IOCTRL_RENDER_CLOSE,
402094332d3Sopenharmony_ci    AUDIO_DRV_PCM_IOCTRL_CAPTURE_OPEN,
403094332d3Sopenharmony_ci    AUDIO_DRV_PCM_IOCTRL_CAPTURE_CLOSE,
404094332d3Sopenharmony_ci    AUDIO_DRV_PCM_IOCTL_BUTT,
405094332d3Sopenharmony_ci};
406094332d3Sopenharmony_ci
407094332d3Sopenharmony_cienum AudioStreamType {
408094332d3Sopenharmony_ci    AUDIO_CAPTURE_STREAM = 0,
409094332d3Sopenharmony_ci    AUDIO_RENDER_STREAM,
410094332d3Sopenharmony_ci};
411094332d3Sopenharmony_ci
412094332d3Sopenharmony_citypedef struct DevHandle *(*BindServiceRenderPassthrough)(const char *);
413094332d3Sopenharmony_citypedef int32_t (*InterfaceLibModeRenderPassthrough)(struct DevHandle *, struct AudioHwRenderParam *, int);
414094332d3Sopenharmony_citypedef void (*CloseServiceRenderPassthrough)(struct DevHandle *);
415094332d3Sopenharmony_ci
416094332d3Sopenharmony_citypedef struct DevHandle *(*BindServiceCapturePassthrough)(const char *);
417094332d3Sopenharmony_citypedef int32_t (*InterfaceLibModeCapturePassthrough)(struct DevHandle *, struct AudioHwCaptureParam *, int);
418094332d3Sopenharmony_citypedef void (*CloseServiceCapturePassthrough)(struct DevHandle *);
419094332d3Sopenharmony_ci
420094332d3Sopenharmony_citypedef struct int32_t *(*InterfaceLibModeGetAllCardInfo)(struct AudioAdapterDescriptor **, int *);
421094332d3Sopenharmony_ci
422094332d3Sopenharmony_citypedef int32_t (*PathSelGetConfToJsonObj)(void);
423094332d3Sopenharmony_citypedef int32_t (*PathSelAnalysisJson)(void *adapterParam, enum AudioAdaptType adaptType);
424094332d3Sopenharmony_ci
425094332d3Sopenharmony_ciBindServiceRenderPassthrough *AudioPassthroughGetBindServiceRender(void);
426094332d3Sopenharmony_ciInterfaceLibModeRenderPassthrough *AudioPassthroughGetInterfaceLibModeRender(void);
427094332d3Sopenharmony_ciCloseServiceRenderPassthrough *AudioPassthroughGetCloseServiceRender(void);
428094332d3Sopenharmony_ci
429094332d3Sopenharmony_ciBindServiceCapturePassthrough *AudioPassthroughGetBindServiceCapture(void);
430094332d3Sopenharmony_ciInterfaceLibModeCapturePassthrough *AudioPassthroughGetInterfaceLibModeCapture(void);
431094332d3Sopenharmony_ciCloseServiceCapturePassthrough *AudioPassthroughGetCloseServiceCapture(void);
432094332d3Sopenharmony_ci
433094332d3Sopenharmony_ci#ifndef AUDIO_HAL_NOTSUPPORT_PATHSELECT
434094332d3Sopenharmony_ciPathSelGetConfToJsonObj *AudioPassthroughGetPathSelGetConfToJsonObj(void);
435094332d3Sopenharmony_ciPathSelAnalysisJson *AudioPassthroughGetPathSelAnalysisJson(void);
436094332d3Sopenharmony_ci#endif
437094332d3Sopenharmony_ci
438094332d3Sopenharmony_ciint32_t CheckParaDesc(const struct AudioDeviceDescriptor *desc, const char *type);
439094332d3Sopenharmony_ciint32_t CheckParaAttr(const struct AudioSampleAttributes *attrs);
440094332d3Sopenharmony_ciint32_t AttrFormatToBit(const struct AudioSampleAttributes *attrs, int32_t *format);
441094332d3Sopenharmony_ciint32_t InitHwRenderParam(struct AudioHwRender *hwRender, const struct AudioDeviceDescriptor *desc,
442094332d3Sopenharmony_ci    const struct AudioSampleAttributes *attrs);
443094332d3Sopenharmony_ciint32_t InitForGetPortCapability(struct AudioPort portIndex, struct AudioPortCapability *capabilityIndex);
444094332d3Sopenharmony_civoid AudioAdapterReleaseCapSubPorts(const struct AudioPortAndCapability *portCapabilitys, int32_t num);
445094332d3Sopenharmony_ciint32_t AudioAdapterInitAllPorts(struct IAudioAdapter *adapter);
446094332d3Sopenharmony_civoid AudioReleaseRenderHandle(struct AudioHwRender *hwRender);
447094332d3Sopenharmony_ciint32_t AudioAdapterCreateRenderPre(struct AudioHwRender *hwRender, const struct AudioDeviceDescriptor *desc,
448094332d3Sopenharmony_ci    const struct AudioSampleAttributes *attrs, const struct AudioHwAdapter *hwAdapter);
449094332d3Sopenharmony_ciint32_t AudioAdapterBindServiceRender(struct AudioHwRender *hwRender);
450094332d3Sopenharmony_ciint32_t AudioAdapterCreateRender(struct IAudioAdapter *adapter, const struct AudioDeviceDescriptor *desc,
451094332d3Sopenharmony_ci    const struct AudioSampleAttributes *attrs, struct IAudioRender **render, uint32_t *renderId);
452094332d3Sopenharmony_ciint32_t AudioAdapterDestroyRender(struct IAudioAdapter *adapter, uint32_t renderId);
453094332d3Sopenharmony_ciint32_t GetAudioCaptureFunc(struct AudioHwCapture *hwCapture);
454094332d3Sopenharmony_ciint32_t InitHwCaptureParam(struct AudioHwCapture *hwCapture, const struct AudioDeviceDescriptor *desc,
455094332d3Sopenharmony_ci    const struct AudioSampleAttributes *attrs);
456094332d3Sopenharmony_civoid AudioReleaseCaptureHandle(struct AudioHwCapture *hwCapture);
457094332d3Sopenharmony_ciint32_t AudioAdapterCreateCapturePre(struct AudioHwCapture *hwCapture, const struct AudioDeviceDescriptor *desc,
458094332d3Sopenharmony_ci    const struct AudioSampleAttributes *attrs, struct AudioHwAdapter *hwAdapter);
459094332d3Sopenharmony_ciint32_t AudioAdapterInterfaceLibModeCapture(struct AudioHwCapture *hwCapture);
460094332d3Sopenharmony_ciint32_t AudioAdapterCreateCapture(struct IAudioAdapter *adapter, const struct AudioDeviceDescriptor *desc,
461094332d3Sopenharmony_ci    const struct AudioSampleAttributes *attrs, struct IAudioCapture **capture, uint32_t *captureId);
462094332d3Sopenharmony_ciint32_t AudioAdapterDestroyCapture(struct IAudioAdapter *adapter, uint32_t captureId);
463094332d3Sopenharmony_ciint32_t AudioAdapterGetPortCapability(
464094332d3Sopenharmony_ci    struct IAudioAdapter *adapter, const struct AudioPort *port, struct AudioPortCapability *capability);
465094332d3Sopenharmony_ciint32_t AudioAdapterSetPassthroughMode(
466094332d3Sopenharmony_ci    struct IAudioAdapter *adapter, const struct AudioPort *port, enum AudioPortPassthroughMode mode);
467094332d3Sopenharmony_ciint32_t AudioAdapterGetPassthroughMode(
468094332d3Sopenharmony_ci    struct IAudioAdapter *adapter, const struct AudioPort *port, enum AudioPortPassthroughMode *mode);
469094332d3Sopenharmony_ciint32_t AudioAdapterGetDeviceStatus(struct IAudioAdapter *adapter, struct AudioDeviceStatus *status);
470094332d3Sopenharmony_ciint32_t PcmBytesToFrames(const struct AudioFrameRenderMode *frameRenderMode, uint64_t bytes, uint32_t *frameCount);
471094332d3Sopenharmony_ciint32_t AudioRenderStart(struct IAudioRender *handle);
472094332d3Sopenharmony_ciint32_t AudioRenderStop(struct IAudioRender *handle);
473094332d3Sopenharmony_ciint32_t AudioRenderPause(struct IAudioRender *handle);
474094332d3Sopenharmony_ciint32_t AudioRenderResume(struct IAudioRender *handle);
475094332d3Sopenharmony_ciint32_t AudioRenderFlush(struct IAudioRender *handle);
476094332d3Sopenharmony_ciint32_t AudioRenderGetFrameSize(struct IAudioRender *handle, uint64_t *size);
477094332d3Sopenharmony_ciint32_t AudioRenderGetFrameCount(struct IAudioRender *handle, uint64_t *count);
478094332d3Sopenharmony_ciint32_t AudioRenderSetSampleAttributes(struct IAudioRender *handle, const struct AudioSampleAttributes *attrs);
479094332d3Sopenharmony_ciint32_t AudioRenderGetSampleAttributes(struct IAudioRender *handle, struct AudioSampleAttributes *attrs);
480094332d3Sopenharmony_ciint32_t AudioRenderGetCurrentChannelId(struct IAudioRender *handle, uint32_t *channelId);
481094332d3Sopenharmony_ciint32_t AudioRenderCheckSceneCapability(
482094332d3Sopenharmony_ci    struct IAudioRender *handle, const struct AudioSceneDescriptor *scene, bool *supported);
483094332d3Sopenharmony_ciint32_t AudioRenderSelectScene(struct IAudioRender *handle, const struct AudioSceneDescriptor *scene);
484094332d3Sopenharmony_ciint32_t AudioRenderSetMute(struct IAudioRender *handle, bool mute);
485094332d3Sopenharmony_ciint32_t AudioRenderGetMute(struct IAudioRender *handle, bool *mute);
486094332d3Sopenharmony_ciint32_t AudioRenderSetVolume(struct IAudioRender *handle, float volume);
487094332d3Sopenharmony_ciint32_t AudioRenderGetVolume(struct IAudioRender *handle, float *volume);
488094332d3Sopenharmony_ciint32_t AudioRenderGetGainThreshold(struct IAudioRender *handle, float *min, float *max);
489094332d3Sopenharmony_ciint32_t AudioRenderGetGain(struct IAudioRender *handle, float *gain);
490094332d3Sopenharmony_ciint32_t AudioRenderSetGain(struct IAudioRender *handle, float gain);
491094332d3Sopenharmony_ciint32_t AudioRenderGetLatency(struct IAudioRender *handle, uint32_t *ms);
492094332d3Sopenharmony_ciint32_t AudioRenderRenderFrame(struct IAudioRender *render, const int8_t *frame,
493094332d3Sopenharmony_ci    uint32_t frameLen, uint64_t *replyBytes);
494094332d3Sopenharmony_ciint32_t AudioRenderGetRenderPosition(struct IAudioRender *render, uint64_t *frames, struct AudioTimeStamp *time);
495094332d3Sopenharmony_ciint32_t AudioRenderSetRenderSpeed(struct IAudioRender *render, float speed);
496094332d3Sopenharmony_ciint32_t AudioRenderGetRenderSpeed(struct IAudioRender *render, float *speed);
497094332d3Sopenharmony_ciint32_t AudioRenderSetChannelMode(struct IAudioRender *render, enum AudioChannelMode mode);
498094332d3Sopenharmony_ciint32_t AudioRenderGetChannelMode(struct IAudioRender *render, enum AudioChannelMode *mode);
499094332d3Sopenharmony_ciint32_t AudioRenderSetExtraParams(struct IAudioRender *handle, const char *keyValueList);
500094332d3Sopenharmony_ciint32_t AudioRenderGetExtraParams(struct IAudioRender *handle, char *keyValueList, uint32_t listLenth);
501094332d3Sopenharmony_ciint32_t AudioRenderReqMmapBuffer(
502094332d3Sopenharmony_ci    struct IAudioRender *handle, int32_t reqSize, struct AudioMmapBufferDescriptor *desc);
503094332d3Sopenharmony_ciint32_t AudioRenderGetMmapPosition(struct IAudioRender *handle, uint64_t *frames, struct AudioTimeStamp *time);
504094332d3Sopenharmony_ciint32_t AudioRenderTurnStandbyMode(struct IAudioRender *handle);
505094332d3Sopenharmony_ciint32_t AudioRenderAudioDevDump(struct IAudioRender *handle, int32_t range, int32_t fd);
506094332d3Sopenharmony_ciint32_t AudioRenderRegCallback(struct IAudioRender *render, struct IAudioCallback *audioCallback, int8_t cookie);
507094332d3Sopenharmony_ciint32_t AudioRenderDrainBuffer(struct IAudioRender *render, enum AudioDrainNotifyType *type);
508094332d3Sopenharmony_ciint32_t AudioCaptureStart(struct IAudioCapture *handle);
509094332d3Sopenharmony_ciint32_t AudioCaptureStop(struct IAudioCapture *handle);
510094332d3Sopenharmony_ciint32_t AudioCapturePause(struct IAudioCapture *handle);
511094332d3Sopenharmony_ciint32_t AudioCaptureResume(struct IAudioCapture *handle);
512094332d3Sopenharmony_ciint32_t AudioCaptureFlush(struct IAudioCapture *handle);
513094332d3Sopenharmony_ciint32_t AudioCaptureGetFrameSize(struct IAudioCapture *handle, uint64_t *size);
514094332d3Sopenharmony_ciint32_t AudioCaptureGetFrameCount(struct IAudioCapture *handle, uint64_t *count);
515094332d3Sopenharmony_ciint32_t AudioCaptureSetSampleAttributes(struct IAudioCapture *handle, const struct AudioSampleAttributes *attrs);
516094332d3Sopenharmony_ciint32_t AudioCaptureGetSampleAttributes(struct IAudioCapture *handle, struct AudioSampleAttributes *attrs);
517094332d3Sopenharmony_ciint32_t AudioCaptureGetCurrentChannelId(struct IAudioCapture *handle, uint32_t *channelId);
518094332d3Sopenharmony_ciint32_t AudioCaptureCheckSceneCapability(
519094332d3Sopenharmony_ci    struct IAudioCapture *handle, const struct AudioSceneDescriptor *scene, bool *supported);
520094332d3Sopenharmony_ciint32_t AudioCaptureSelectScene(struct IAudioCapture *handle, const struct AudioSceneDescriptor *scene);
521094332d3Sopenharmony_ciint32_t AudioCaptureSetMute(struct IAudioCapture *handle, bool mute);
522094332d3Sopenharmony_ciint32_t AudioCaptureGetMute(struct IAudioCapture *handle, bool *mute);
523094332d3Sopenharmony_ciint32_t AudioCaptureSetVolume(struct IAudioCapture *handle, float volume);
524094332d3Sopenharmony_ciint32_t AudioCaptureGetVolume(struct IAudioCapture *handle, float *volume);
525094332d3Sopenharmony_ciint32_t AudioCaptureGetGainThreshold(struct IAudioCapture *handle, float *min, float *max);
526094332d3Sopenharmony_ciint32_t AudioCaptureGetGain(struct IAudioCapture *handle, float *gain);
527094332d3Sopenharmony_ciint32_t AudioCaptureSetGain(struct IAudioCapture *handle, float gain);
528094332d3Sopenharmony_ciint32_t AudioCaptureCaptureFrame(struct IAudioCapture *capture, int8_t *frame,
529094332d3Sopenharmony_ci    uint32_t *frameLen, uint64_t *replyBytes);
530094332d3Sopenharmony_ciint32_t AudioCaptureGetCapturePosition(struct IAudioCapture *capture, uint64_t *frames, struct AudioTimeStamp *time);
531094332d3Sopenharmony_ciint32_t AudioCaptureSetExtraParams(struct IAudioCapture *handle, const char *keyValueList);
532094332d3Sopenharmony_ciint32_t AudioCaptureGetExtraParams(struct IAudioCapture *handle, char *keyValueList, uint32_t keyValueListLen);
533094332d3Sopenharmony_ciint32_t AudioCaptureReqMmapBuffer(
534094332d3Sopenharmony_ci    struct IAudioCapture *handle, int32_t reqSize, struct AudioMmapBufferDescriptor *desc);
535094332d3Sopenharmony_ciint32_t AudioCaptureGetMmapPosition(struct IAudioCapture *handle, uint64_t *frames, struct AudioTimeStamp *time);
536094332d3Sopenharmony_ciint32_t AudioCaptureTurnStandbyMode(struct IAudioCapture *handle);
537094332d3Sopenharmony_ciint32_t AudioCaptureAudioDevDump(struct IAudioCapture *handle, int32_t range, int32_t fd);
538094332d3Sopenharmony_ciint32_t CallbackProcessing(AudioHandle handle, enum AudioCallbackType callBackType);
539094332d3Sopenharmony_ci
540094332d3Sopenharmony_ci#ifdef __cplusplus
541094332d3Sopenharmony_ci}
542094332d3Sopenharmony_ci#endif
543094332d3Sopenharmony_ci#endif
544