1 /* 2 * Copyright (c) 2021 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 HDF_AUDIO_SERVER_COMMON_H 17 #define HDF_AUDIO_SERVER_COMMON_H 18 19 #include "audio_events.h" 20 #include "audio_internal.h" 21 #include "hdf_audio_server.h" 22 #include "hdf_device_desc.h" 23 #include "hdf_log.h" 24 25 #define MAX_AUDIO_ADAPTER_NUM_SERVER 8 // Limit the number of sound cards supported to a maximum of 8 26 #define STR_MAX 512 27 28 enum AudioServerType { 29 AUDIO_SERVER_PRIMARY, 30 AUDIO_SERVER_USB, 31 AUDIO_SERVER_A2DP, 32 AUDIO_SERVER_BOTTOM 33 }; 34 35 typedef int32_t (*AudioAllfunc)(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply); 36 struct HdiServiceDispatchCmdHandleList { 37 enum AudioHdiServerCmdId cmd; 38 AudioAllfunc func; 39 }; 40 41 /* RenderManage Info */ 42 struct AudioInfoInAdapter { 43 const char *adapterName; 44 struct AudioAdapter *adapter; 45 int adapterUserNum; 46 int renderStatus; 47 int renderPriority; 48 struct AudioRender *render; 49 bool renderBusy; 50 bool renderDestory; 51 uint32_t renderPid; 52 int captureStatus; 53 int capturePriority; 54 struct AudioCapture *capture; 55 bool captureBusy; 56 bool captureDestory; 57 uint32_t capturePid; 58 }; 59 60 int32_t AudioAdapterListGetAdapterCapture(const char *adapterName, 61 struct AudioAdapter **adapter, struct AudioCapture **capture); 62 int32_t AudioDestroyCaptureInfoInAdapter(const char *adapterName); 63 int32_t AudioCreatCaptureCheck(const char *adapterName, const int32_t priority); 64 int32_t AudioAddCaptureInfoInAdapter(const char *adapterName, 65 struct AudioCapture *capture, 66 const struct AudioAdapter *adapter, 67 const int32_t priority, 68 uint32_t capturePid); 69 int32_t AudioAdapterListGetAdapter(const char *adapterName, struct AudioAdapter **adapter); 70 int32_t AudioCreatRenderCheck(const char *adapterName, const int32_t priority); 71 int32_t AudioAddRenderInfoInAdapter(const char *adapterName, 72 struct AudioRender *render, 73 const struct AudioAdapter *adapter, 74 const int32_t priority, 75 uint32_t renderPid); 76 int32_t AudioDestroyRenderInfoInAdapter(const char *adapterName); 77 int32_t AudioAdapterListGetAdapterRender(const char *adapterName, 78 struct AudioAdapter **adapter, struct AudioRender **render); 79 int32_t AudioAdapterListDestory(const char *adapterName, struct AudioAdapter **adapter); 80 int32_t AudioAdapterListAdd(const char *adapterName, struct AudioAdapter *adapter); 81 int32_t HdiServiceRenderCaptureReadData(struct HdfSBuf *data, 82 const char **adapterName, uint32_t *pid); 83 int32_t AudioAdapterListGetRender(const char *adapterName, 84 struct AudioRender **render, uint32_t pid); 85 void AudioSetRenderStatus(const char *adapterName, bool renderStatus); 86 int32_t AudioGetRenderStatus(const char *adapterName); 87 int32_t AudioAdapterListCheckAndGetRender(struct AudioRender **render, struct HdfSBuf *data); 88 int32_t AudioAdapterListGetCapture(const char *adapterName, 89 struct AudioCapture **capture, uint32_t pid); 90 int32_t AudioAdapterFrameGetCapture(const char *adapterName, 91 struct AudioCapture **capture, uint32_t pid, uint32_t *index); 92 void AudioSetCaptureBusy(uint32_t index, bool captureStatus); 93 int32_t AudioAdapterListCheckAndGetCapture(struct AudioCapture **capture, struct HdfSBuf *data); 94 int32_t ReadAudioSapmleAttrbutes(struct HdfSBuf *data, struct AudioSampleAttributes *attrs); 95 int32_t WriteAudioSampleAttributes(struct HdfSBuf *reply, const struct AudioSampleAttributes *attrs); 96 void AudioSetCaptureStatus(const char *adapterName, bool captureStatus); 97 int32_t AudioGetCaptureStatus(const char *adapterName); 98 void AdaptersServerManageInfomationRecycle(void); 99 int32_t HdiServicePositionWrite(struct HdfSBuf *reply, 100 uint64_t frames, struct AudioTimeStamp time); 101 int32_t HdiServiceReqMmapBuffer(struct AudioMmapBufferDescriptor *desc, struct HdfSBuf *data); 102 103 int32_t HdiServiceGetFuncs(); 104 void AudioHdiServerRelease(void); 105 int32_t HdiServiceGetAllAdapter(const struct HdfDeviceIoClient *client, 106 struct HdfSBuf *data, struct HdfSBuf *reply); 107 int32_t HdiServiceLoadAdapter(const struct HdfDeviceIoClient *client, 108 struct HdfSBuf *data, struct HdfSBuf *reply); 109 int32_t HdiServiceInitAllPorts(const struct HdfDeviceIoClient *client, 110 struct HdfSBuf *data, struct HdfSBuf *reply); 111 int32_t HdiServiceUnloadAdapter(const struct HdfDeviceIoClient *client, 112 struct HdfSBuf *data, struct HdfSBuf *reply); 113 int32_t HdiServiceGetPortCapability(const struct HdfDeviceIoClient *client, 114 struct HdfSBuf *data, struct HdfSBuf *reply); 115 int32_t HdiServiceSetPassthroughMode(const struct HdfDeviceIoClient *client, 116 struct HdfSBuf *data, struct HdfSBuf *reply); 117 int32_t HdiServiceGetPassthroughMode(const struct HdfDeviceIoClient *client, 118 struct HdfSBuf *data, struct HdfSBuf *reply); 119 int32_t HdiServiceGetDevStatusByPNP(const struct HdfDeviceIoClient *client, 120 struct HdfSBuf *data, struct HdfSBuf *reply); 121 int32_t AudioServiceStateChange(struct HdfDeviceObject *device, 122 struct AudioEvent *audioSrvEvent); 123 124 enum AudioServerType AudioHdiGetLoadServerFlag(void); 125 void AudioHdiSetLoadServerFlag(enum AudioServerType serverType); 126 void AudioHdiClearLoadServerFlag(void); 127 128 int32_t HdiServiceDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, 129 struct HdfSBuf *reply); 130 #endif 131 132