• 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 #include "hdf_audio_server_manager.h"
22 
23 #define HDF_LOG_TAG HDF_AUDIO_HAL_HOST
24 
AudioHdiUsbServerRelease(struct HdfDeviceObject * deviceObject)25 static void AudioHdiUsbServerRelease(struct HdfDeviceObject *deviceObject)
26 {
27     AUDIO_FUNC_LOGI("enter!");
28     /* g_renderAndCaptureManage release */
29     AdaptersServerManageInfomationRecycle();
30     AudioHdiServerRelease();
31 
32     if (deviceObject == NULL) {
33         AUDIO_FUNC_LOGE("deviceObject is null!");
34         return;
35     }
36     deviceObject->service = NULL;
37     AUDIO_FUNC_LOGD("end!");
38     return;
39 }
40 
AudioHdiUsbServerBind(struct HdfDeviceObject * deviceObject)41 static int AudioHdiUsbServerBind(struct HdfDeviceObject *deviceObject)
42 {
43     AUDIO_FUNC_LOGI("enter!");
44     if (deviceObject == NULL) {
45         AUDIO_FUNC_LOGE("deviceObject is null!");
46         return AUDIO_HAL_ERR_INVALID_PARAM;
47     }
48     static struct IDeviceIoService hdiUsbService = {
49         .Dispatch = HdiServiceDispatch,
50         .Open = NULL,
51         .Release = NULL,
52     };
53     AudioHdiSetLoadServerFlag(AUDIO_SERVER_USB);
54     if (HdiServiceGetFuncs() < 0) {
55         return AUDIO_HAL_ERR_INTERNAL;
56     }
57     int ret = HdfDeviceObjectSetInterfaceDesc(deviceObject, "ohos.hdi.audio_service");
58     if (ret != HDF_SUCCESS) {
59         AUDIO_FUNC_LOGE("failed to set interface desc");
60         return ret;
61     }
62     deviceObject->service = &hdiUsbService;
63     AUDIO_FUNC_LOGD("end!");
64     return AUDIO_HAL_SUCCESS;
65 }
66 
AudioHdiUsbServerInit(struct HdfDeviceObject * deviceObject)67 static int AudioHdiUsbServerInit(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 
75     if (!HdfDeviceSetClass(deviceObject, DEVICE_CLASS_AUDIO)) {
76         AUDIO_FUNC_LOGE("Set USB DEVICE_CLASS_AUDIO fail!");
77     }
78     struct AudioEvent audioSrvEvent = {
79         .eventType = HDF_AUDIO_SERVICE_INVALID,
80         .deviceType = HDF_AUDIO_USB_DEVICE,
81     };
82     AudioServiceStateChange(deviceObject, &audioSrvEvent);
83 
84     AUDIO_FUNC_LOGD("end!");
85     return AUDIO_HAL_SUCCESS;
86 }
87 
88 struct HdfDriverEntry g_hdiAudioUSBServerEntry = {
89     .moduleVersion = 1,
90     .moduleName = "hdi_audio_usb_server",
91     .Bind = AudioHdiUsbServerBind,
92     .Init = AudioHdiUsbServerInit,
93     .Release = AudioHdiUsbServerRelease,
94 };
95 
96 HDF_INIT(g_hdiAudioUSBServerEntry);
97