• 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 
AudioHdiUsbServerRelease(struct HdfDeviceObject * deviceObject)24 static void AudioHdiUsbServerRelease(struct HdfDeviceObject *deviceObject)
25 {
26     AUDIO_FUNC_LOGI("enter!");
27     /* g_renderAndCaptureManage release */
28     AdaptersServerManageInfomationRecycle();
29     ReleaseAudioManagerObjectComm(GetAudioManagerFuncs());
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 
AudioHdiUsbServerBind(struct HdfDeviceObject * deviceObject)40 static int AudioHdiUsbServerBind(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 hdiUsbService = {
48         .Dispatch = HdiServiceDispatch,
49         .Open = NULL,
50         .Release = NULL,
51     };
52     AudioHdiSetLoadServerFlag(AUDIO_SERVER_USB);
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 = &hdiUsbService;
62     AUDIO_FUNC_LOGD("end!");
63     return AUDIO_HAL_SUCCESS;
64 }
65 
AudioHdiUsbServerInit(struct HdfDeviceObject * deviceObject)66 static int AudioHdiUsbServerInit(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 
74     if (!HdfDeviceSetClass(deviceObject, DEVICE_CLASS_AUDIO)) {
75         AUDIO_FUNC_LOGE("Set USB DEVICE_CLASS_AUDIO fail!");
76     }
77     struct AudioEvent audioSrvEvent = {
78         .eventType = HDF_AUDIO_SERVICE_INVALID,
79         .deviceType = HDF_AUDIO_USB_DEVICE,
80     };
81     AudioServiceStateChange(deviceObject, &audioSrvEvent);
82 
83     AUDIO_FUNC_LOGD("end!");
84     return AUDIO_HAL_SUCCESS;
85 }
86 
87 struct HdfDriverEntry g_hdiAudioUSBServerEntry = {
88     .moduleVersion = 1,
89     .moduleName = "hdi_audio_usb_server",
90     .Bind = AudioHdiUsbServerBind,
91     .Init = AudioHdiUsbServerInit,
92     .Release = AudioHdiUsbServerRelease,
93 };
94 
95 HDF_INIT(g_hdiAudioUSBServerEntry);
96