• 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_events.h"
20 #include "audio_uhdf_log.h"
21 #include "hdf_audio_events.h"
22 #include "hdf_audio_server_common.h"
23 
24 #define HDF_LOG_TAG HDF_AUDIO_HAL_HOST
25 
AudioHdiPrimaryServerRelease(struct HdfDeviceObject * deviceObject)26 static void AudioHdiPrimaryServerRelease(struct HdfDeviceObject *deviceObject)
27 {
28     AUDIO_FUNC_LOGI("enter!");
29     /* g_renderAndCaptureManage release */
30     AdaptersServerManageInfomationRecycle();
31     ReleaseAudioManagerObjectComm(GetAudioManagerFuncs());
32 
33     if (deviceObject == NULL) {
34         AUDIO_FUNC_LOGE("Parameter is null!");
35         return;
36     }
37     deviceObject->service = NULL;
38     AUDIO_FUNC_LOGD("end!");
39     return;
40 }
41 
AudioHdiPrimaryServerBind(struct HdfDeviceObject * deviceObject)42 static int AudioHdiPrimaryServerBind(struct HdfDeviceObject *deviceObject)
43 {
44     AUDIO_FUNC_LOGI("enter!");
45     if (deviceObject == NULL) {
46         AUDIO_FUNC_LOGE("deviceObject is null!");
47         return AUDIO_HAL_ERR_INVALID_PARAM;
48     }
49     static struct IDeviceIoService hdiPrimaryService = {
50         .Dispatch = HdiServiceDispatch,
51         .Open = NULL,
52         .Release = NULL,
53     };
54     AudioHdiSetLoadServerFlag(AUDIO_SERVER_PRIMARY);
55     if (HdiServiceGetFuncs() < 0) {
56         return AUDIO_HAL_ERR_INTERNAL;
57     }
58     int ret = HdfDeviceObjectSetInterfaceDesc(deviceObject, "ohos.hdi.audio_service");
59     if (ret != HDF_SUCCESS) {
60         AUDIO_FUNC_LOGE("failed to set interface desc");
61         return ret;
62     }
63     deviceObject->service = &hdiPrimaryService;
64 
65     AUDIO_FUNC_LOGD("end!");
66     return AUDIO_HAL_SUCCESS;
67 }
68 
AudioHdiPrimaryServerInit(struct HdfDeviceObject * deviceObject)69 static int AudioHdiPrimaryServerInit(struct HdfDeviceObject *deviceObject)
70 {
71     AUDIO_FUNC_LOGI("enter!");
72     if (deviceObject == NULL) {
73         AUDIO_FUNC_LOGE("deviceObject is null!");
74         return AUDIO_HAL_ERR_INVALID_PARAM;
75     }
76     if (!HdfDeviceSetClass(deviceObject, DEVICE_CLASS_AUDIO)) {
77         AUDIO_FUNC_LOGE("Set Primary DEVICE_CLASS_AUDIO fail!");
78     }
79     struct AudioEvent audioSrvEvent = {
80         .eventType = HDF_AUDIO_SERVICE_VALID,
81         .deviceType = HDF_AUDIO_PRIMARY_DEVICE,
82     };
83     AudioServiceStateChange(deviceObject, &audioSrvEvent);
84 
85     AUDIO_FUNC_LOGD("end!");
86     return AUDIO_HAL_SUCCESS;
87 }
88 
89 struct HdfDriverEntry g_hdiPrimaryServerEntry = {
90     .moduleVersion = 1,
91     .moduleName = "hdi_audio_primary_server",
92     .Bind = AudioHdiPrimaryServerBind,
93     .Init = AudioHdiPrimaryServerInit,
94     .Release = AudioHdiPrimaryServerRelease,
95 };
96 
97 HDF_INIT(g_hdiPrimaryServerEntry);
98