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