1 /* 2 * Copyright (c) 2021-2023 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 STR_MAX 512 26 #define CHECK_NULL_PTR_RETURN_VALUE(ptr, ret) do { \ 27 if ((ptr) == NULL) { \ 28 HDF_LOGE("%{public}s:line:%{public}d pointer is null, ret = %{public}d", __func__, __LINE__, ret); \ 29 return (ret); \ 30 } \ 31 } while (0) 32 33 enum AudioServerType { 34 AUDIO_SERVER_PRIMARY, 35 AUDIO_SERVER_USB, 36 AUDIO_SERVER_A2DP, 37 AUDIO_SERVER_BOTTOM 38 }; 39 40 typedef int32_t (*AudioAllfunc)(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply); 41 struct HdiServiceDispatchCmdHandleList { 42 enum AudioHdiServerCmdId cmd; 43 AudioAllfunc func; 44 }; 45 46 int32_t HdiServiceRenderCaptureReadData(struct HdfSBuf *data, 47 const char **adapterName, uint32_t *pid); 48 int32_t AudioAdapterListCheckAndGetRender(struct AudioRender **render, struct HdfSBuf *data); 49 int32_t AudioAdapterListCheckAndGetCapture(struct AudioCapture **capture, struct HdfSBuf *data); 50 int32_t ReadAudioSapmleAttrbutes(struct HdfSBuf *data, struct AudioSampleAttributes *attrs); 51 int32_t WriteAudioSampleAttributes(struct HdfSBuf *reply, const struct AudioSampleAttributes *attrs); 52 53 int32_t HdiServicePositionWrite(struct HdfSBuf *reply, 54 uint64_t frames, struct AudioTimeStamp time); 55 int32_t HdiServiceReqMmapBuffer(struct AudioMmapBufferDescriptor *desc, struct HdfSBuf *data); 56 57 int32_t HdiServiceGetFuncs(); 58 void AudioHdiServerRelease(void); 59 int32_t HdiServiceGetAllAdapter(const struct HdfDeviceIoClient *client, 60 struct HdfSBuf *data, struct HdfSBuf *reply); 61 int32_t HdiServiceLoadAdapter(const struct HdfDeviceIoClient *client, 62 struct HdfSBuf *data, struct HdfSBuf *reply); 63 int32_t HdiServiceInitAllPorts(const struct HdfDeviceIoClient *client, 64 struct HdfSBuf *data, struct HdfSBuf *reply); 65 int32_t HdiServiceUnloadAdapter(const struct HdfDeviceIoClient *client, 66 struct HdfSBuf *data, struct HdfSBuf *reply); 67 int32_t HdiServiceGetPortCapability(const struct HdfDeviceIoClient *client, 68 struct HdfSBuf *data, struct HdfSBuf *reply); 69 int32_t HdiServiceSetPassthroughMode(const struct HdfDeviceIoClient *client, 70 struct HdfSBuf *data, struct HdfSBuf *reply); 71 int32_t HdiServiceGetPassthroughMode(const struct HdfDeviceIoClient *client, 72 struct HdfSBuf *data, struct HdfSBuf *reply); 73 int32_t HdiServiceGetDevStatusByPNP(const struct HdfDeviceIoClient *client, 74 struct HdfSBuf *data, struct HdfSBuf *reply); 75 int32_t AudioServiceStateChange(struct HdfDeviceObject *device, 76 struct AudioEvent *audioSrvEvent); 77 78 enum AudioServerType AudioHdiGetLoadServerFlag(void); 79 void AudioHdiSetLoadServerFlag(enum AudioServerType serverType); 80 void AudioHdiClearLoadServerFlag(void); 81 82 int32_t HdiServiceDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, 83 struct HdfSBuf *reply); 84 #endif 85