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