1 /*
2 * Copyright (c) 2021 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_stub.h"
21
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 struct IDeviceIoService *testService = deviceObject->service;
32 OsalMemFree(testService);
33 ClearCapabilityGroup();
34 }
35
HdfCodecDriverBind(struct HdfDeviceObject * deviceObject)36 static int HdfCodecDriverBind(struct HdfDeviceObject *deviceObject)
37 {
38 HDF_LOGI("HdfCodecDriverBind enter!");
39
40 struct IDeviceIoService *ioService = (struct IDeviceIoService *)OsalMemAlloc(sizeof(struct IDeviceIoService));
41 if (ioService == NULL) {
42 HDF_LOGE("HdfCodecDriverBind OsalMemAlloc IDeviceIoService failed!");
43 return HDF_FAILURE;
44 }
45
46 ioService->Dispatch = CodecServiceDispatch;
47 ioService->Open = NULL;
48 ioService->Release = NULL;
49 int ret = HdfDeviceObjectSetInterfaceDesc(deviceObject, "ohos.hdi.codec_service");
50 if (ret != HDF_SUCCESS) {
51 HDF_LOGE("failed to set interface desc");
52 return ret;
53 }
54 deviceObject->service = ioService;
55 return HDF_SUCCESS;
56 }
57
HdfCodecDriverInit(struct HdfDeviceObject * deviceObject)58 static int HdfCodecDriverInit(struct HdfDeviceObject *deviceObject)
59 {
60 HDF_LOGI("HdfSampleDriverCInit enter, new hdi impl");
61 if (LoadCodecCapabilityFromHcs(deviceObject->property) != HDF_SUCCESS) {
62 HDF_LOGE("LoadCodecCapabilityFromHcs failed");
63 ClearCapabilityGroup();
64 }
65 return HDF_SUCCESS;
66 }
67
68 struct HdfDriverEntry g_codecHostDriverEntry = {
69 .moduleVersion = 1,
70 .moduleName = "libcodec_server.z.so",
71 .Bind = HdfCodecDriverBind,
72 .Init = HdfCodecDriverInit,
73 .Release = HdfCodecDriverRelease,
74 };
75
76 HDF_INIT(g_codecHostDriverEntry);