1 /*
2 * Copyright (c) 2022-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 #include "hdf_device_desc.h"
17 #include "hdf_device_object.h"
18 #include "audio_adapter_info_common.h"
19 #include "audio_uhdf_log.h"
20 #include "hdf_audio_server_common.h"
21 #include "hdf_audio_server_manager.h"
22
23 #define HDF_LOG_TAG HDF_AUDIO_HAL_HOST
24
AudioHdiA2dpServerRelease(struct HdfDeviceObject * deviceObject)25 static void AudioHdiA2dpServerRelease(struct HdfDeviceObject *deviceObject)
26 {
27 AUDIO_FUNC_LOGI("enter!");
28 /* g_renderAndCaptureManage release */
29 AdaptersServerManageInfomationRecycle();
30
31 if (deviceObject == NULL) {
32 AUDIO_FUNC_LOGE("deviceObject is null!");
33 return;
34 }
35 deviceObject->service = NULL;
36 AUDIO_FUNC_LOGD("end!");
37 return;
38 }
39
AudioHdiA2dpServerBind(struct HdfDeviceObject * deviceObject)40 static int AudioHdiA2dpServerBind(struct HdfDeviceObject *deviceObject)
41 {
42 AUDIO_FUNC_LOGI("enter!");
43 if (deviceObject == NULL) {
44 AUDIO_FUNC_LOGE("deviceObject is null!");
45 return AUDIO_HAL_ERR_INVALID_PARAM;
46 }
47 static struct IDeviceIoService hdiA2dpService = {
48 .Dispatch = HdiServiceDispatch,
49 .Open = NULL,
50 .Release = NULL,
51 };
52 AudioHdiSetLoadServerFlag(AUDIO_SERVER_A2DP);
53 if (HdiServiceGetFuncs() < 0) {
54 return AUDIO_HAL_ERR_INTERNAL;
55 }
56 int ret = HdfDeviceObjectSetInterfaceDesc(deviceObject, "ohos.hdi.audio_service");
57 if (ret != HDF_SUCCESS) {
58 AUDIO_FUNC_LOGE("failed to set interface desc");
59 return ret;
60 }
61 deviceObject->service = &hdiA2dpService;
62
63 AUDIO_FUNC_LOGD("end!");
64 return AUDIO_HAL_SUCCESS;
65 }
66
AudioHdiA2dpServerInit(struct HdfDeviceObject * deviceObject)67 static int AudioHdiA2dpServerInit(struct HdfDeviceObject *deviceObject)
68 {
69 AUDIO_FUNC_LOGI("enter!");
70 if (deviceObject == NULL) {
71 AUDIO_FUNC_LOGE("deviceObject is null!");
72 return AUDIO_HAL_ERR_INVALID_PARAM;
73 }
74 if (!HdfDeviceSetClass(deviceObject, DEVICE_CLASS_AUDIO)) {
75 AUDIO_FUNC_LOGE("Set A2dp DEVICE_CLASS_AUDIO fail!");
76 }
77
78 AUDIO_FUNC_LOGD("end!");
79 return AUDIO_HAL_SUCCESS;
80 }
81
82 struct HdfDriverEntry g_hdiAudioA2DPServerEntry = {
83 .moduleVersion = 1,
84 .moduleName = "hdi_audio_a2dp_server",
85 .Bind = AudioHdiA2dpServerBind,
86 .Init = AudioHdiA2dpServerInit,
87 .Release = AudioHdiA2dpServerRelease,
88 };
89
90 HDF_INIT(g_hdiAudioA2DPServerEntry);
91