• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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_object.h>
17 #include <hdf_log.h>
18 #include <osal_mem.h>
19 #include "codec_config_parser.h"
20 #include "codec_service.h"
21 #include "codec_stub.h"
22 
CodecServiceDispatch(struct HdfDeviceIoClient * client,int cmdId,struct HdfSBuf * data,struct HdfSBuf * reply)23 static int32_t CodecServiceDispatch(struct HdfDeviceIoClient *client, int cmdId,
24     struct HdfSBuf *data, struct HdfSBuf *reply)
25 {
26     return CodecServiceOnRemoteRequest(client, cmdId, data, reply);
27 }
28 
HdfCodecDriverRelease(struct HdfDeviceObject * deviceObject)29 static void HdfCodecDriverRelease(struct HdfDeviceObject *deviceObject)
30 {
31     if (deviceObject == NULL) {
32         HDF_LOGE("invalid parameter");
33         return;
34     }
35     struct IDeviceIoService *testService = deviceObject->service;
36     OsalMemFree(testService);
37     ClearCapabilityGroup();
38     DeinitOemIfaceLock();
39 }
40 
HdfCodecDriverBind(struct HdfDeviceObject * deviceObject)41 static int HdfCodecDriverBind(struct HdfDeviceObject *deviceObject)
42 {
43     HDF_LOGI("HdfCodecDriverBind enter!");
44     if (deviceObject == NULL) {
45         HDF_LOGE("invalid parameter");
46         return HDF_ERR_INVALID_PARAM;
47     }
48     struct IDeviceIoService *ioService = (struct IDeviceIoService *)OsalMemAlloc(sizeof(struct IDeviceIoService));
49     if (ioService == NULL) {
50         HDF_LOGE("HdfCodecDriverBind OsalMemAlloc IDeviceIoService failed!");
51         return HDF_FAILURE;
52     }
53 
54     ioService->Dispatch = CodecServiceDispatch;
55     ioService->Open = NULL;
56     ioService->Release = NULL;
57     int ret = HdfDeviceObjectSetInterfaceDesc(deviceObject, "ohos.hdi.codec_service");
58     if (ret != HDF_SUCCESS) {
59         HDF_LOGE("failed to set interface desc");
60         return ret;
61     }
62     deviceObject->service = ioService;
63     return HDF_SUCCESS;
64 }
65 
HdfCodecDriverInit(struct HdfDeviceObject * deviceObject)66 static int HdfCodecDriverInit(struct HdfDeviceObject *deviceObject)
67 {
68     HDF_LOGI("HdfSampleDriverCInit enter, new hdi impl");
69     if (deviceObject == NULL) {
70         HDF_LOGE("invalid parameter");
71         return HDF_ERR_INVALID_PARAM;
72     }
73     if (LoadCodecCapabilityFromHcs(deviceObject->property) != HDF_SUCCESS) {
74         HDF_LOGE("LoadCodecCapabilityFromHcs failed");
75         ClearCapabilityGroup();
76     }
77     InitOemIfaceLock();
78     return HDF_SUCCESS;
79 }
80 
81 struct HdfDriverEntry g_codecHostDriverEntry = {
82     .moduleVersion = 1,
83     .moduleName = "libcodec_server.z.so",
84     .Bind = HdfCodecDriverBind,
85     .Init = HdfCodecDriverInit,
86     .Release = HdfCodecDriverRelease,
87 };
88 
89 HDF_INIT(g_codecHostDriverEntry);