1094332d3Sopenharmony_ci/* 2094332d3Sopenharmony_ci * Copyright (c) 2021-2023 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 <errno.h> 20094332d3Sopenharmony_ci#include <inttypes.h> 21094332d3Sopenharmony_ci#include <math.h> 22094332d3Sopenharmony_ci#include <pthread.h> 23094332d3Sopenharmony_ci#include <sys/mman.h> 24094332d3Sopenharmony_ci#include <sys/types.h> 25094332d3Sopenharmony_ci#include <unistd.h> 26094332d3Sopenharmony_ci 27094332d3Sopenharmony_ci#include "audio_common.h" 28094332d3Sopenharmony_ci#include "audio_manager.h" 29094332d3Sopenharmony_ci#include "hdf_base.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 59094332d3Sopenharmony_ci#define HDF_AUDIO_CODEC_PRIMARY_DEV "hdf_audio_codec_primary_dev" 60094332d3Sopenharmony_ci#define HDF_AUDIO_CODEC_HDMI_DEV "hdf_audio_codec_hdmi_dev" 61094332d3Sopenharmony_ci#define HDF_AUDIO_CODEC_USB_DEV "hdf_audio_codec_usb_dev" 62094332d3Sopenharmony_ci#define HDF_AUDIO_CODEC_A2DP_DEV "hdf_audio_codec_a2dp_dev" 63094332d3Sopenharmony_ci#define PRIMARY "primary" 64094332d3Sopenharmony_ci#define USB "usb" 65094332d3Sopenharmony_ci#define A2DP "a2dp" 66094332d3Sopenharmony_ci#define HDMI "hdmi" 67094332d3Sopenharmony_ci 68094332d3Sopenharmony_ci/** 69094332d3Sopenharmony_ci * @brief Enumerates HAL return value types. 70094332d3Sopenharmony_ci */ 71094332d3Sopenharmony_citypedef enum { 72094332d3Sopenharmony_ci AUDIO_HAL_SUCCESS = 0, 73094332d3Sopenharmony_ci AUDIO_HAL_ERR_INTERNAL = -1, /* audio system internal errors */ 74094332d3Sopenharmony_ci AUDIO_HAL_ERR_NOT_SUPPORT = -2, /* operation is not supported */ 75094332d3Sopenharmony_ci AUDIO_HAL_ERR_INVALID_PARAM = -3, /* parameter is invalid */ 76094332d3Sopenharmony_ci AUDIO_HAL_ERR_INVALID_OBJECT = -4, /* Invalid object */ 77094332d3Sopenharmony_ci AUDIO_HAL_ERR_MALLOC_FAIL = -6, /* Memory allocation fails */ 78094332d3Sopenharmony_ci 79094332d3Sopenharmony_ci #define HDF_AUDIO_HAL_ERR_START (-7000) /* Defines the start of the device module error codes. */ 80094332d3Sopenharmony_ci #define HDF_AUDIO_HAL_ERR_NUM(v) (HDF_AUDIO_HAL_ERR_START + (v)) /* Defines the device module error codes. */ 81094332d3Sopenharmony_ci AUDIO_HAL_ERR_NOTREADY = HDF_AUDIO_HAL_ERR_NUM(-1), /* audio adapter is not ready */ 82094332d3Sopenharmony_ci AUDIO_HAL_ERR_AI_BUSY = HDF_AUDIO_HAL_ERR_NUM(-2), /* audio capture is busy now */ 83094332d3Sopenharmony_ci AUDIO_HAL_ERR_AO_BUSY = HDF_AUDIO_HAL_ERR_NUM(-3), /* audio render is busy now */ 84094332d3Sopenharmony_ci} AUDIO_HAL_ERR_CODE; 85094332d3Sopenharmony_ci 86094332d3Sopenharmony_ci#ifndef UNUSED 87094332d3Sopenharmony_ci #define UNUSED(x) ((void)(x)) 88094332d3Sopenharmony_ci#endif 89094332d3Sopenharmony_ci 90094332d3Sopenharmony_ci#ifndef UT_TEST 91094332d3Sopenharmony_ci #define STATIC_T static 92094332d3Sopenharmony_ci#else 93094332d3Sopenharmony_ci #define STATIC_T 94094332d3Sopenharmony_ci#endif 95094332d3Sopenharmony_ci 96094332d3Sopenharmony_ci#define USECASE_AUDIO_RENDER_DEEP_BUFFER "deep-buffer-render" 97094332d3Sopenharmony_ci#define USECASE_AUDIO_RENDER_LOW_LATENCY "low-latency-render" 98094332d3Sopenharmony_ci 99094332d3Sopenharmony_ci#define AUDIO_ATTR_PARAM_ROUTE "attr-route" 100094332d3Sopenharmony_ci#define ROUTE_SAMPLE "attr-route=x;" 101094332d3Sopenharmony_ci#define AUDIO_ATTR_PARAM_FORMAT "attr-format" 102094332d3Sopenharmony_ci#define FORMAT_SAMPLE "attr-format=xx;" 103094332d3Sopenharmony_ci#define AUDIO_ATTR_PARAM_CHANNELS "attr-channels" 104094332d3Sopenharmony_ci#define CHANNELS_SAMPLE "attr-channels=x;" 105094332d3Sopenharmony_ci#define AUDIO_ATTR_PARAM_FRAME_COUNT "attr-frame-count" 106094332d3Sopenharmony_ci#define FRAME_COUNT_SAMPLE "attr-frame-count=xxxxxxxxxxxxxxxxxxxx;" 107094332d3Sopenharmony_ci#define AUDIO_ATTR_PARAM_SAMPLING_RATE "attr-sampling-rate" 108094332d3Sopenharmony_ci#define SAMPLING_RATE_SAMPLE "attr-sampling-rate=xxxxx" 109094332d3Sopenharmony_ci#define AUDIO_ATTR_PARAM_CONNECT "usb-connect" 110094332d3Sopenharmony_ci#define AUDIO_ATTR_PARAM_DISCONNECT "usb-disconnect" 111094332d3Sopenharmony_ci#define TELHPONE_RATE 8000 112094332d3Sopenharmony_ci#define BROADCAST_AM_RATE 11025 113094332d3Sopenharmony_ci#define BROADCAST_FM_RATE 22050 114094332d3Sopenharmony_ci#define MINI_CAM_DV_RATE 32000 115094332d3Sopenharmony_ci#define MUSIC_RATE 44100 116094332d3Sopenharmony_ci#define HIGHT_MUSIC_RATE 48000 117094332d3Sopenharmony_ci#define AUDIO_SAMPLE_RATE_12000 12000 118094332d3Sopenharmony_ci#define AUDIO_SAMPLE_RATE_16000 16000 119094332d3Sopenharmony_ci#define AUDIO_SAMPLE_RATE_24000 24000 120094332d3Sopenharmony_ci#define AUDIO_SAMPLE_RATE_64000 64000 121094332d3Sopenharmony_ci#define AUDIO_SAMPLE_RATE_96000 96000 122094332d3Sopenharmony_ci#define SUPPORT_ADAPTER_NUM_MAX 8 123094332d3Sopenharmony_citypedef int32_t (*CallbackProcessFunc)(AudioHandle handle, enum AudioCallbackType callBackType); 124094332d3Sopenharmony_ci 125094332d3Sopenharmony_cienum AudioTurnStandbyMode { 126094332d3Sopenharmony_ci AUDIO_TURN_STANDBY_LATER = 0, 127094332d3Sopenharmony_ci AUDIO_TURN_STANDBY_NOW, 128094332d3Sopenharmony_ci AUDIO_TURN_STANDBY_BUTT, 129094332d3Sopenharmony_ci}; 130094332d3Sopenharmony_ci 131094332d3Sopenharmony_cistruct DevHandle { 132094332d3Sopenharmony_ci void *object; 133094332d3Sopenharmony_ci}; 134094332d3Sopenharmony_ci 135094332d3Sopenharmony_cistruct AudioPortAndCapability { 136094332d3Sopenharmony_ci struct AudioPort port; 137094332d3Sopenharmony_ci struct AudioPortCapability capability; 138094332d3Sopenharmony_ci enum AudioPortPassthroughMode mode; 139094332d3Sopenharmony_ci}; 140094332d3Sopenharmony_ci 141094332d3Sopenharmony_cistruct AudioHwAdapter { 142094332d3Sopenharmony_ci struct AudioAdapter common; 143094332d3Sopenharmony_ci struct AudioAdapterDescriptor adapterDescriptor; 144094332d3Sopenharmony_ci struct AudioPortAndCapability *portCapabilitys; 145094332d3Sopenharmony_ci struct HdfRemoteService *proxyRemoteHandle; // proxyRemoteHandle 146094332d3Sopenharmony_ci int32_t adapterMgrRenderFlag; 147094332d3Sopenharmony_ci int32_t adapterMgrCaptureFlag; 148094332d3Sopenharmony_ci}; 149094332d3Sopenharmony_ci 150094332d3Sopenharmony_cistruct AudioFrameRenderMode { 151094332d3Sopenharmony_ci uint64_t frames; 152094332d3Sopenharmony_ci struct AudioTimeStamp time; 153094332d3Sopenharmony_ci struct AudioSampleAttributes attrs; 154094332d3Sopenharmony_ci enum AudioChannelMode mode; 155094332d3Sopenharmony_ci uint32_t byteRate; 156094332d3Sopenharmony_ci uint32_t periodSize; 157094332d3Sopenharmony_ci uint32_t periodCount; 158094332d3Sopenharmony_ci uint32_t startThreshold; 159094332d3Sopenharmony_ci uint32_t stopThreshold; 160094332d3Sopenharmony_ci uint32_t silenceThreshold; 161094332d3Sopenharmony_ci uint32_t silenceSize; 162094332d3Sopenharmony_ci char *buffer; 163094332d3Sopenharmony_ci uint64_t bufferFrameSize; 164094332d3Sopenharmony_ci uint64_t bufferSize; 165094332d3Sopenharmony_ci RenderCallback callback; 166094332d3Sopenharmony_ci void* cookie; 167094332d3Sopenharmony_ci CallbackProcessFunc callbackProcess; 168094332d3Sopenharmony_ci AudioHandle renderhandle; 169094332d3Sopenharmony_ci struct AudioMmapBufferDescriptor mmapBufDesc; 170094332d3Sopenharmony_ci}; 171094332d3Sopenharmony_ci 172094332d3Sopenharmony_cistruct AudioGain { 173094332d3Sopenharmony_ci float gain; 174094332d3Sopenharmony_ci float gainMin; 175094332d3Sopenharmony_ci float gainMax; 176094332d3Sopenharmony_ci}; 177094332d3Sopenharmony_ci 178094332d3Sopenharmony_cistruct AudioVol { 179094332d3Sopenharmony_ci int volMin; 180094332d3Sopenharmony_ci int volMax; 181094332d3Sopenharmony_ci}; 182094332d3Sopenharmony_ci 183094332d3Sopenharmony_cistruct AudioCtlParam { 184094332d3Sopenharmony_ci bool mute; 185094332d3Sopenharmony_ci float volume; 186094332d3Sopenharmony_ci float speed; 187094332d3Sopenharmony_ci bool pause; 188094332d3Sopenharmony_ci bool stop; 189094332d3Sopenharmony_ci pthread_mutex_t mutex; 190094332d3Sopenharmony_ci bool mutexFlag; 191094332d3Sopenharmony_ci pthread_cond_t functionCond; 192094332d3Sopenharmony_ci struct AudioVol volThreshold; 193094332d3Sopenharmony_ci struct AudioGain audioGain; 194094332d3Sopenharmony_ci enum AudioTurnStandbyMode turnStandbyStatus; 195094332d3Sopenharmony_ci}; 196094332d3Sopenharmony_ci 197094332d3Sopenharmony_cienum PathRoute { 198094332d3Sopenharmony_ci DEEP_BUFF = 0, 199094332d3Sopenharmony_ci RECORD, 200094332d3Sopenharmony_ci RECORD_LOW_LATRNCY, 201094332d3Sopenharmony_ci LOW_LATRNCY, 202094332d3Sopenharmony_ci}; 203094332d3Sopenharmony_ci 204094332d3Sopenharmony_cistruct PathPlan { 205094332d3Sopenharmony_ci char pathPlanName[PATHPLAN_LEN]; 206094332d3Sopenharmony_ci int value; 207094332d3Sopenharmony_ci}; 208094332d3Sopenharmony_ci 209094332d3Sopenharmony_cistruct PathDeviceSwitch { 210094332d3Sopenharmony_ci char deviceSwitch[PATHPLAN_LEN]; 211094332d3Sopenharmony_ci int32_t value; 212094332d3Sopenharmony_ci}; 213094332d3Sopenharmony_ci 214094332d3Sopenharmony_cistruct PathDeviceInfo { 215094332d3Sopenharmony_ci char deviceType[NAME_LEN]; 216094332d3Sopenharmony_ci int32_t deviceNum; 217094332d3Sopenharmony_ci struct PathDeviceSwitch deviceSwitchs[PATHPLAN_COUNT]; 218094332d3Sopenharmony_ci}; 219094332d3Sopenharmony_ci 220094332d3Sopenharmony_cistruct PathSelect { 221094332d3Sopenharmony_ci char useCase[NAME_LEN]; 222094332d3Sopenharmony_ci struct PathDeviceInfo deviceInfo; 223094332d3Sopenharmony_ci int useCaseDeviceNum; 224094332d3Sopenharmony_ci struct PathPlan pathPlan[PATHPLAN_COUNT]; 225094332d3Sopenharmony_ci}; 226094332d3Sopenharmony_ci 227094332d3Sopenharmony_cistruct HwInfo { 228094332d3Sopenharmony_ci uint32_t card; 229094332d3Sopenharmony_ci uint32_t device; 230094332d3Sopenharmony_ci char cardServiceName[NAME_LEN]; 231094332d3Sopenharmony_ci int flags; 232094332d3Sopenharmony_ci bool callBackEnable; 233094332d3Sopenharmony_ci char adapterName[NAME_LEN]; 234094332d3Sopenharmony_ci struct AudioPort portDescript; 235094332d3Sopenharmony_ci struct AudioDeviceDescriptor deviceDescript; 236094332d3Sopenharmony_ci enum PathRoute pathroute; 237094332d3Sopenharmony_ci struct PathSelect pathSelect; 238094332d3Sopenharmony_ci}; 239094332d3Sopenharmony_ci 240094332d3Sopenharmony_cistruct AudioHwRenderMode { 241094332d3Sopenharmony_ci struct AudioCtlParam ctlParam; 242094332d3Sopenharmony_ci struct HwInfo hwInfo; 243094332d3Sopenharmony_ci}; 244094332d3Sopenharmony_ci 245094332d3Sopenharmony_cistruct AudioHwRenderParam { 246094332d3Sopenharmony_ci struct AudioHwRenderMode renderMode; 247094332d3Sopenharmony_ci struct AudioFrameRenderMode frameRenderMode; 248094332d3Sopenharmony_ci}; 249094332d3Sopenharmony_ci 250094332d3Sopenharmony_cistruct ErrorDump { 251094332d3Sopenharmony_ci int32_t errorCode; 252094332d3Sopenharmony_ci uint32_t count; 253094332d3Sopenharmony_ci uint64_t frames; 254094332d3Sopenharmony_ci char *reason; // Specific reasons for failure 255094332d3Sopenharmony_ci char *currentTime; 256094332d3Sopenharmony_ci}; 257094332d3Sopenharmony_ci 258094332d3Sopenharmony_cistruct ErrorLog { 259094332d3Sopenharmony_ci uint32_t totalErrors; 260094332d3Sopenharmony_ci uint32_t iter; 261094332d3Sopenharmony_ci struct ErrorDump errorDump[ERROR_LOG_MAX_NUM]; 262094332d3Sopenharmony_ci}; 263094332d3Sopenharmony_ci 264094332d3Sopenharmony_cistruct AudioHwRender { 265094332d3Sopenharmony_ci struct AudioRender common; 266094332d3Sopenharmony_ci struct AudioHwRenderParam renderParam; 267094332d3Sopenharmony_ci struct DevHandle *devDataHandle; // Bind Data handle 268094332d3Sopenharmony_ci struct DevHandle *devCtlHandle; // Bind Ctl handle 269094332d3Sopenharmony_ci struct HdfRemoteService *proxyRemoteHandle; // proxyRemoteHandle 270094332d3Sopenharmony_ci struct ErrorLog errorLog; 271094332d3Sopenharmony_ci}; 272094332d3Sopenharmony_ci 273094332d3Sopenharmony_cistruct AudioHwCaptureMode { 274094332d3Sopenharmony_ci struct AudioCtlParam ctlParam; 275094332d3Sopenharmony_ci struct HwInfo hwInfo; 276094332d3Sopenharmony_ci}; 277094332d3Sopenharmony_ci 278094332d3Sopenharmony_cistruct AudioFrameCaptureMode { 279094332d3Sopenharmony_ci uint64_t frames; 280094332d3Sopenharmony_ci struct AudioTimeStamp time; 281094332d3Sopenharmony_ci struct AudioSampleAttributes attrs; 282094332d3Sopenharmony_ci enum AudioChannelMode mode; 283094332d3Sopenharmony_ci uint32_t byteRate; 284094332d3Sopenharmony_ci uint32_t periodSize; 285094332d3Sopenharmony_ci uint32_t periodCount; 286094332d3Sopenharmony_ci uint32_t startThreshold; 287094332d3Sopenharmony_ci uint32_t stopThreshold; 288094332d3Sopenharmony_ci uint32_t silenceThreshold; 289094332d3Sopenharmony_ci uint32_t silenceSize; 290094332d3Sopenharmony_ci char *buffer; 291094332d3Sopenharmony_ci uint64_t bufferFrameSize; 292094332d3Sopenharmony_ci uint64_t bufferSize; 293094332d3Sopenharmony_ci struct AudioMmapBufferDescriptor mmapBufDesc; 294094332d3Sopenharmony_ci}; 295094332d3Sopenharmony_ci 296094332d3Sopenharmony_cistruct AudioHwCaptureParam { 297094332d3Sopenharmony_ci struct AudioHwCaptureMode captureMode; 298094332d3Sopenharmony_ci struct AudioFrameCaptureMode frameCaptureMode; 299094332d3Sopenharmony_ci}; 300094332d3Sopenharmony_ci 301094332d3Sopenharmony_cistruct AudioHwCapture { 302094332d3Sopenharmony_ci struct AudioCapture common; 303094332d3Sopenharmony_ci struct AudioHwCaptureParam captureParam; 304094332d3Sopenharmony_ci struct DevHandle *devDataHandle; // Bind Data handle 305094332d3Sopenharmony_ci struct DevHandle *devCtlHandle; // Bind Ctl handle 306094332d3Sopenharmony_ci struct HdfRemoteService *proxyRemoteHandle; // proxyRemoteHandle 307094332d3Sopenharmony_ci struct ErrorLog errorLog; 308094332d3Sopenharmony_ci}; 309094332d3Sopenharmony_ci 310094332d3Sopenharmony_cistruct ParamValMap { 311094332d3Sopenharmony_ci char key[EXTPARAM_LEN]; 312094332d3Sopenharmony_ci char value[EXTPARAM_LEN]; 313094332d3Sopenharmony_ci}; 314094332d3Sopenharmony_ci 315094332d3Sopenharmony_cistruct ExtraParams { 316094332d3Sopenharmony_ci int32_t route; 317094332d3Sopenharmony_ci int32_t format; 318094332d3Sopenharmony_ci uint32_t channels; 319094332d3Sopenharmony_ci uint64_t frames; 320094332d3Sopenharmony_ci uint32_t sampleRate; 321094332d3Sopenharmony_ci bool flag; 322094332d3Sopenharmony_ci}; 323094332d3Sopenharmony_ci 324094332d3Sopenharmony_cienum AudioAddrType { 325094332d3Sopenharmony_ci AUDIO_ADAPTER_ADDR = 0, /** Record the address of the adapter for FUZZ. */ 326094332d3Sopenharmony_ci AUDIO_RENDER_ADDR, /** Record the address of the render for FUZZ. */ 327094332d3Sopenharmony_ci AUDIO_CAPTURE_ADDR, /** Record the address of the capturef or FUZZ. */ 328094332d3Sopenharmony_ci AUDIO_INVALID_ADDR, /** Invalid value. */ 329094332d3Sopenharmony_ci}; 330094332d3Sopenharmony_ci 331094332d3Sopenharmony_cistruct AudioAddrDB { // Record the address of the adapter Mgr for FUZZ. 332094332d3Sopenharmony_ci void *addrValue; 333094332d3Sopenharmony_ci const char *adapterName; 334094332d3Sopenharmony_ci enum AudioAddrType addrType; 335094332d3Sopenharmony_ci}; 336094332d3Sopenharmony_ci 337094332d3Sopenharmony_cienum ErrorDumpCode { 338094332d3Sopenharmony_ci WRITE_FRAME_ERROR_CODE = -5, 339094332d3Sopenharmony_ci}; 340094332d3Sopenharmony_ci 341094332d3Sopenharmony_cienum AudioAdaptType { 342094332d3Sopenharmony_ci INVAILD_PATH_SELECT = -1, 343094332d3Sopenharmony_ci RENDER_PATH_SELECT, 344094332d3Sopenharmony_ci CAPTURE_PATH_SELECT, 345094332d3Sopenharmony_ci CHECKSCENE_PATH_SELECT, 346094332d3Sopenharmony_ci CHECKSCENE_PATH_SELECT_CAPTURE, 347094332d3Sopenharmony_ci}; 348094332d3Sopenharmony_ci 349094332d3Sopenharmony_cienum AudioServiceNameType { 350094332d3Sopenharmony_ci AUDIO_SERVICE_IN = 0, 351094332d3Sopenharmony_ci AUDIO_SERVICE_OUT, 352094332d3Sopenharmony_ci AUDIO_SERVICE_MAX, 353094332d3Sopenharmony_ci}; 354094332d3Sopenharmony_ci 355094332d3Sopenharmony_ci/* dispatch cmdId */ 356094332d3Sopenharmony_cienum AudioInterfaceLibParaCmdList { 357094332d3Sopenharmony_ci AUDIO_DRV_PCM_IOCTL_HW_PARAMS = 0, 358094332d3Sopenharmony_ci AUDIO_DRV_PCM_IOCTL_PREPARE, 359094332d3Sopenharmony_ci AUDIO_DRV_PCM_IOCTL_PREPARE_CAPTURE, 360094332d3Sopenharmony_ci AUDIO_DRV_PCM_IOCTL_WRITE, 361094332d3Sopenharmony_ci AUDIO_DRV_PCM_IOCTL_READ, 362094332d3Sopenharmony_ci AUDIO_DRV_PCM_IOCTRL_START, 363094332d3Sopenharmony_ci AUDIO_DRV_PCM_IOCTRL_STOP, 364094332d3Sopenharmony_ci AUDIO_DRV_PCM_IOCTRL_START_CAPTURE, 365094332d3Sopenharmony_ci AUDIO_DRV_PCM_IOCTRL_STOP_CAPTURE, 366094332d3Sopenharmony_ci AUDIO_DRV_PCM_IOCTRL_PAUSE, 367094332d3Sopenharmony_ci AUDIO_DRV_PCM_IOCTRL_PAUSE_CAPTURE, 368094332d3Sopenharmony_ci AUDIO_DRV_PCM_IOCTRL_RESUME, 369094332d3Sopenharmony_ci AUDIO_DRV_PCM_IOCTRL_RESUME_CAPTURE, 370094332d3Sopenharmony_ci AUDIO_DRV_PCM_IOCTL_MMAP_BUFFER, 371094332d3Sopenharmony_ci AUDIO_DRV_PCM_IOCTL_MMAP_BUFFER_CAPTURE, 372094332d3Sopenharmony_ci AUDIO_DRV_PCM_IOCTL_MMAP_POSITION, 373094332d3Sopenharmony_ci AUDIO_DRV_PCM_IOCTL_MMAP_POSITION_CAPTURE, 374094332d3Sopenharmony_ci AUDIO_DRV_PCM_IOCTRL_RENDER_OPEN, 375094332d3Sopenharmony_ci AUDIO_DRV_PCM_IOCTRL_RENDER_CLOSE, 376094332d3Sopenharmony_ci AUDIO_DRV_PCM_IOCTRL_CAPTURE_OPEN, 377094332d3Sopenharmony_ci AUDIO_DRV_PCM_IOCTRL_CAPTURE_CLOSE, 378094332d3Sopenharmony_ci AUDIO_DRV_PCM_IOCTL_BUTT, 379094332d3Sopenharmony_ci}; 380094332d3Sopenharmony_ci 381094332d3Sopenharmony_cienum AudioStreamType { 382094332d3Sopenharmony_ci AUDIO_CAPTURE_STREAM = 0, 383094332d3Sopenharmony_ci AUDIO_RENDER_STREAM, 384094332d3Sopenharmony_ci}; 385094332d3Sopenharmony_ci 386094332d3Sopenharmony_citypedef struct DevHandle *(*BindServiceRenderSo)(const char *); 387094332d3Sopenharmony_citypedef int32_t (*InterfaceLibModeRenderSo)(struct DevHandle *, struct AudioHwRenderParam *, int); 388094332d3Sopenharmony_citypedef void(*CloseServiceRenderSo)(struct DevHandle *); 389094332d3Sopenharmony_ci 390094332d3Sopenharmony_citypedef struct DevHandle *(*BindServiceCaptureSo)(const char *); 391094332d3Sopenharmony_citypedef int32_t (*InterfaceLibModeCaptureSo)(struct DevHandle *, struct AudioHwCaptureParam *, int); 392094332d3Sopenharmony_citypedef void(*CloseServiceCaptureSo)(struct DevHandle *); 393094332d3Sopenharmony_ci 394094332d3Sopenharmony_citypedef int32_t (*InterfaceLibGetCardInfoSo)(struct AudioAdapterDescriptor **, int *); 395094332d3Sopenharmony_ci 396094332d3Sopenharmony_citypedef int32_t (*PathSelGetConfToJsonObj)(void); 397094332d3Sopenharmony_citypedef int32_t (*PathSelAnalysisJson)(void *adapterParam, enum AudioAdaptType adaptType); 398094332d3Sopenharmony_ci 399094332d3Sopenharmony_ciBindServiceRenderSo *AudioSoGetBindServiceRender(void); 400094332d3Sopenharmony_ciInterfaceLibModeRenderSo *AudioSoGetInterfaceLibModeRender(void); 401094332d3Sopenharmony_ciCloseServiceRenderSo *AudioSoGetCloseServiceRender(void); 402094332d3Sopenharmony_ci 403094332d3Sopenharmony_ciBindServiceCaptureSo *AudioSoGetBindServiceCapture(void); 404094332d3Sopenharmony_ciInterfaceLibModeCaptureSo *AudioSoGetInterfaceLibModeCapture(void); 405094332d3Sopenharmony_ciCloseServiceCaptureSo *AudioSoGetCloseServiceCapture(void); 406094332d3Sopenharmony_ci 407094332d3Sopenharmony_ci#ifndef AUDIO_HAL_NOTSUPPORT_PATHSELECT 408094332d3Sopenharmony_ciPathSelGetConfToJsonObj *AudioSoGetPathSelGetConfToJsonObj(void); 409094332d3Sopenharmony_ciPathSelAnalysisJson *AudioSoGetPathSelAnalysisJson(void); 410094332d3Sopenharmony_ci#endif 411094332d3Sopenharmony_ci 412094332d3Sopenharmony_ciint32_t GetAudioRenderFunc(struct AudioHwRender *hwRender); 413094332d3Sopenharmony_ciint32_t CheckParaDesc(const struct AudioDeviceDescriptor *desc, const char *type); 414094332d3Sopenharmony_ciint32_t CheckParaAttr(const struct AudioSampleAttributes *attrs); 415094332d3Sopenharmony_ciint32_t AttrFormatToBit(const struct AudioSampleAttributes *attrs, int32_t *format); 416094332d3Sopenharmony_ciint32_t InitHwRenderParam(struct AudioHwRender *hwRender, const struct AudioDeviceDescriptor *desc, 417094332d3Sopenharmony_ci const struct AudioSampleAttributes *attrs); 418094332d3Sopenharmony_ciint32_t InitForGetPortCapability(struct AudioPort portIndex, struct AudioPortCapability *capabilityIndex); 419094332d3Sopenharmony_civoid AudioAdapterReleaseCapSubPorts(const struct AudioPortAndCapability *portCapabilitys, int32_t num); 420094332d3Sopenharmony_ciint32_t AudioAdapterInitAllPorts(struct AudioAdapter *adapter); 421094332d3Sopenharmony_civoid AudioReleaseRenderHandle(struct AudioHwRender *hwRender); 422094332d3Sopenharmony_ciint32_t AudioAdapterCreateRenderPre(struct AudioHwRender *hwRender, const struct AudioDeviceDescriptor *desc, 423094332d3Sopenharmony_ci const struct AudioSampleAttributes *attrs, const struct AudioHwAdapter *hwAdapter); 424094332d3Sopenharmony_ciint32_t AudioAdapterBindServiceRender(struct AudioHwRender *hwRender); 425094332d3Sopenharmony_ciint32_t AudioAdapterCreateRender(struct AudioAdapter *adapter, const struct AudioDeviceDescriptor *desc, 426094332d3Sopenharmony_ci const struct AudioSampleAttributes *attrs, struct AudioRender **render); 427094332d3Sopenharmony_ciint32_t AudioAdapterDestroyRender(struct AudioAdapter *adapter, struct AudioRender *render); 428094332d3Sopenharmony_ciint32_t GetAudioCaptureFunc(struct AudioHwCapture *hwCapture); 429094332d3Sopenharmony_ciint32_t InitHwCaptureParam(struct AudioHwCapture *hwCapture, const struct AudioDeviceDescriptor *desc, 430094332d3Sopenharmony_ci const struct AudioSampleAttributes *attrs); 431094332d3Sopenharmony_civoid AudioReleaseCaptureHandle(struct AudioHwCapture *hwCapture); 432094332d3Sopenharmony_ciint32_t AudioAdapterCreateCapturePre(struct AudioHwCapture *hwCapture, const struct AudioDeviceDescriptor *desc, 433094332d3Sopenharmony_ci const struct AudioSampleAttributes *attrs, struct AudioHwAdapter *hwAdapter); 434094332d3Sopenharmony_ciint32_t AudioAdapterInterfaceLibModeCapture(struct AudioHwCapture *hwCapture); 435094332d3Sopenharmony_ciint32_t AudioAdapterCreateCapture(struct AudioAdapter *adapter, const struct AudioDeviceDescriptor *desc, 436094332d3Sopenharmony_ci const struct AudioSampleAttributes *attrs, struct AudioCapture **capture); 437094332d3Sopenharmony_ciint32_t AudioAdapterDestroyCapture(struct AudioAdapter *adapter, struct AudioCapture *capture); 438094332d3Sopenharmony_ciint32_t AudioAdapterGetPortCapability(struct AudioAdapter *adapter, const struct AudioPort *port, 439094332d3Sopenharmony_ci struct AudioPortCapability *capability); 440094332d3Sopenharmony_ciint32_t AudioAdapterSetPassthroughMode(struct AudioAdapter *adapter, const struct AudioPort *port, 441094332d3Sopenharmony_ci enum AudioPortPassthroughMode mode); 442094332d3Sopenharmony_ciint32_t AudioAdapterGetPassthroughMode(struct AudioAdapter *adapter, const struct AudioPort *port, 443094332d3Sopenharmony_ci enum AudioPortPassthroughMode *mode); 444094332d3Sopenharmony_ciint32_t AudioAdapterUpdateAudioRoute(struct AudioAdapter *adapter, const struct AudioRoute *route, 445094332d3Sopenharmony_ci int32_t *routeHandle); 446094332d3Sopenharmony_ciint32_t AudioAdapterReleaseAudioRoute(struct AudioAdapter *adapter, int32_t routeHandle); 447094332d3Sopenharmony_ciint32_t AudioAdapterSetExtraParams(struct AudioAdapter *adapter, enum AudioExtParamKey key, 448094332d3Sopenharmony_ci const char *condition, const char *value); 449094332d3Sopenharmony_ciint32_t AudioAdapterGetExtraParams(struct AudioAdapter *adapter, enum AudioExtParamKey key, 450094332d3Sopenharmony_ci const char *condition, char *value, int32_t length); 451094332d3Sopenharmony_ciint32_t PcmBytesToFrames(const struct AudioFrameRenderMode *frameRenderMode, uint64_t bytes, uint32_t *frameCount); 452094332d3Sopenharmony_ciint32_t AudioAdapterSetMicMute(struct AudioAdapter *adapter, bool mute); 453094332d3Sopenharmony_ciint32_t AudioAdapterGetMicMute(struct AudioAdapter *adapter, bool *mute); 454094332d3Sopenharmony_ciint32_t AudioAdapterSetVoiceVolume(struct AudioAdapter *adapter, float volume); 455094332d3Sopenharmony_ciint32_t AudioRenderStart(AudioHandle handle); 456094332d3Sopenharmony_ciint32_t AudioRenderStop(AudioHandle handle); 457094332d3Sopenharmony_ciint32_t AudioRenderPause(AudioHandle handle); 458094332d3Sopenharmony_ciint32_t AudioRenderResume(AudioHandle handle); 459094332d3Sopenharmony_ciint32_t AudioRenderFlush(AudioHandle handle); 460094332d3Sopenharmony_ciint32_t AudioRenderGetFrameSize(AudioHandle handle, uint64_t *size); 461094332d3Sopenharmony_ciint32_t AudioRenderGetFrameCount(AudioHandle handle, uint64_t *count); 462094332d3Sopenharmony_ciint32_t AudioRenderSetSampleAttributes(AudioHandle handle, const struct AudioSampleAttributes *attrs); 463094332d3Sopenharmony_ciint32_t AudioRenderGetSampleAttributes(AudioHandle handle, struct AudioSampleAttributes *attrs); 464094332d3Sopenharmony_ciint32_t AudioRenderGetCurrentChannelId(AudioHandle handle, uint32_t *channelId); 465094332d3Sopenharmony_ciint32_t AudioRenderCheckSceneCapability(AudioHandle handle, const struct AudioSceneDescriptor *scene, 466094332d3Sopenharmony_ci bool *supported); 467094332d3Sopenharmony_ciint32_t AudioRenderSelectScene(AudioHandle handle, const struct AudioSceneDescriptor *scene); 468094332d3Sopenharmony_ciint32_t AudioRenderSetMute(AudioHandle handle, bool mute); 469094332d3Sopenharmony_ciint32_t AudioRenderGetMute(AudioHandle handle, bool *mute); 470094332d3Sopenharmony_ciint32_t AudioRenderSetVolume(AudioHandle handle, float volume); 471094332d3Sopenharmony_ciint32_t AudioRenderGetVolume(AudioHandle handle, float *volume); 472094332d3Sopenharmony_ciint32_t AudioRenderGetGainThreshold(AudioHandle handle, float *min, float *max); 473094332d3Sopenharmony_ciint32_t AudioRenderGetGain(AudioHandle handle, float *gain); 474094332d3Sopenharmony_ciint32_t AudioRenderSetGain(AudioHandle handle, float gain); 475094332d3Sopenharmony_ciint32_t AudioRenderGetLatency(struct AudioRender *render, uint32_t *ms); 476094332d3Sopenharmony_ciint32_t AudioRenderRenderFrame(struct AudioRender *render, const void *frame, 477094332d3Sopenharmony_ci uint64_t requestBytes, uint64_t *replyBytes); 478094332d3Sopenharmony_ciint32_t AudioRenderGetRenderPosition(struct AudioRender *render, uint64_t *frames, struct AudioTimeStamp *time); 479094332d3Sopenharmony_ciint32_t AudioRenderSetRenderSpeed(struct AudioRender *render, float speed); 480094332d3Sopenharmony_ciint32_t AudioRenderGetRenderSpeed(struct AudioRender *render, float *speed); 481094332d3Sopenharmony_ciint32_t AudioRenderSetChannelMode(struct AudioRender *render, enum AudioChannelMode mode); 482094332d3Sopenharmony_ciint32_t AudioRenderGetChannelMode(struct AudioRender *render, enum AudioChannelMode *mode); 483094332d3Sopenharmony_ciint32_t AudioRenderSetExtraParams(AudioHandle handle, const char *keyValueList); 484094332d3Sopenharmony_ciint32_t AudioRenderGetExtraParams(AudioHandle handle, char *keyValueList, int32_t listLenth); 485094332d3Sopenharmony_ciint32_t AudioRenderReqMmapBuffer(AudioHandle handle, int32_t reqSize, struct AudioMmapBufferDescriptor *desc); 486094332d3Sopenharmony_ciint32_t AudioRenderGetMmapPosition(AudioHandle handle, uint64_t *frames, struct AudioTimeStamp *time); 487094332d3Sopenharmony_ciint32_t AudioRenderAddEffect(AudioHandle handle, uint64_t effectid); 488094332d3Sopenharmony_ciint32_t AudioRenderRemoveEffect(AudioHandle handle, uint64_t effectid); 489094332d3Sopenharmony_ciint32_t AudioRenderTurnStandbyMode(AudioHandle handle); 490094332d3Sopenharmony_ciint32_t AudioRenderAudioDevDump(AudioHandle handle, int32_t range, int32_t fd); 491094332d3Sopenharmony_ciint32_t AudioRenderRegCallback(struct AudioRender *render, RenderCallback callback, void* cookie); 492094332d3Sopenharmony_ciint32_t AudioRenderDrainBuffer(struct AudioRender *render, enum AudioDrainNotifyType *type); 493094332d3Sopenharmony_ciint32_t AudioCaptureStart(AudioHandle handle); 494094332d3Sopenharmony_ciint32_t AudioCaptureStop(AudioHandle handle); 495094332d3Sopenharmony_ciint32_t AudioCapturePause(AudioHandle handle); 496094332d3Sopenharmony_ciint32_t AudioCaptureResume(AudioHandle handle); 497094332d3Sopenharmony_ciint32_t AudioCaptureFlush(AudioHandle handle); 498094332d3Sopenharmony_ciint32_t AudioCaptureGetFrameSize(AudioHandle handle, uint64_t *size); 499094332d3Sopenharmony_ciint32_t AudioCaptureGetFrameCount(AudioHandle handle, uint64_t *count); 500094332d3Sopenharmony_ciint32_t AudioCaptureSetSampleAttributes(AudioHandle handle, const struct AudioSampleAttributes *attrs); 501094332d3Sopenharmony_ciint32_t AudioCaptureGetSampleAttributes(AudioHandle handle, struct AudioSampleAttributes *attrs); 502094332d3Sopenharmony_ciint32_t AudioCaptureGetCurrentChannelId(AudioHandle handle, uint32_t *channelId); 503094332d3Sopenharmony_ciint32_t AudioCaptureCheckSceneCapability(AudioHandle handle, const struct AudioSceneDescriptor *scene, 504094332d3Sopenharmony_ci bool *supported); 505094332d3Sopenharmony_ciint32_t AudioCaptureSelectScene(AudioHandle handle, const struct AudioSceneDescriptor *scene); 506094332d3Sopenharmony_ciint32_t AudioCaptureSetMute(AudioHandle handle, bool mute); 507094332d3Sopenharmony_ciint32_t AudioCaptureGetMute(AudioHandle handle, bool *mute); 508094332d3Sopenharmony_ciint32_t AudioCaptureSetVolume(AudioHandle handle, float volume); 509094332d3Sopenharmony_ciint32_t AudioCaptureGetVolume(AudioHandle handle, float *volume); 510094332d3Sopenharmony_ciint32_t AudioCaptureGetGainThreshold(AudioHandle handle, float *min, float *max); 511094332d3Sopenharmony_ciint32_t AudioCaptureGetGain(AudioHandle handle, float *gain); 512094332d3Sopenharmony_ciint32_t AudioCaptureSetGain(AudioHandle handle, float gain); 513094332d3Sopenharmony_ciint32_t AudioCaptureCaptureFrame(struct AudioCapture *capture, void *frame, 514094332d3Sopenharmony_ci uint64_t requestBytes, uint64_t *replyBytes); 515094332d3Sopenharmony_ciint32_t AudioCaptureGetCapturePosition(struct AudioCapture *capture, uint64_t *frames, struct AudioTimeStamp *time); 516094332d3Sopenharmony_ciint32_t AudioCaptureSetExtraParams(AudioHandle handle, const char *keyValueList); 517094332d3Sopenharmony_ciint32_t AudioCaptureGetExtraParams(const AudioHandle handle, char *keyValueList, int32_t listLenth); 518094332d3Sopenharmony_ciint32_t AudioCaptureReqMmapBuffer(AudioHandle handle, int32_t reqSize, struct AudioMmapBufferDescriptor *desc); 519094332d3Sopenharmony_ciint32_t AudioCaptureGetMmapPosition(AudioHandle handle, uint64_t *frames, struct AudioTimeStamp *time); 520094332d3Sopenharmony_ciint32_t AudioCaptureAddEffect(AudioHandle handle, uint64_t effectid); 521094332d3Sopenharmony_ciint32_t AudioCaptureRemoveEffect(AudioHandle handle, uint64_t effectid); 522094332d3Sopenharmony_ciint32_t AudioCaptureTurnStandbyMode(AudioHandle handle); 523094332d3Sopenharmony_ciint32_t AudioCaptureAudioDevDump(AudioHandle handle, int32_t range, int32_t fd); 524094332d3Sopenharmony_ciint32_t CallbackProcessing(AudioHandle handle, enum AudioCallbackType callBackType); 525094332d3Sopenharmony_ci 526094332d3Sopenharmony_cistruct AudioAdapterDescriptor *AudioAdapterGetConfigDescs(void); 527094332d3Sopenharmony_ciint32_t AudioAdapterGetAdapterNum(void); 528094332d3Sopenharmony_ci 529094332d3Sopenharmony_ci#ifdef __cplusplus 530094332d3Sopenharmony_ci} 531094332d3Sopenharmony_ci#endif 532094332d3Sopenharmony_ci#endif 533