1 /*
2 * Copyright (c) 2022 Shenzhen Kaihong DID 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 "codec_component_capability_config.h"
17 #include <hdf_log.h>
18 #include "codec_config_parser.h"
19 #include "codec_types.h"
20
21 #define HDF_LOG_TAG codec_hdi_server
22
23 static CodecCapablites g_codecCapabilites = {0};
24 static const struct DeviceResourceNode *g_resourceNode = NULL;
25
AllCapabilityMarshalling(struct HdfSBuf * reply)26 static int32_t AllCapabilityMarshalling(struct HdfSBuf *reply)
27 {
28 int32_t groupIndex;
29 int32_t capIndex;
30 CodecCapablityGroup *group = NULL;
31 CodecCompCapability *cap = NULL;
32 CodecCapablityGroup *codeCapGroups[] = {
33 &(g_codecCapabilites.videoHwEncoderGroup), &(g_codecCapabilites.videoHwDecoderGroup),
34 &(g_codecCapabilites.audioHwEncoderGroup), &(g_codecCapabilites.audioHwDecoderGroup),
35 &(g_codecCapabilites.videoSwEncoderGroup), &(g_codecCapabilites.videoSwDecoderGroup),
36 &(g_codecCapabilites.audioSwEncoderGroup), &(g_codecCapabilites.audioSwDecoderGroup)
37 };
38
39 for (groupIndex = 0; groupIndex < CODEC_CAPABLITY_GROUP_NUM; groupIndex++) {
40 group = codeCapGroups[groupIndex];
41 for (capIndex = 0; capIndex < group->num; capIndex++) {
42 cap = &group->capablitis[capIndex];
43 if (!CodecCompCapabilityBlockMarshalling(reply, cap)) {
44 HDF_LOGE("%{public}s: write capbility to sbuf failed!", __func__);
45 return HDF_FAILURE;
46 }
47 }
48 }
49
50 return HDF_SUCCESS;
51 }
52
InitDataNode(const struct DeviceResourceNode * node)53 int32_t InitDataNode(const struct DeviceResourceNode *node)
54 {
55 if (node == NULL) {
56 HDF_LOGE("%{public}s: data node is null!", __func__);
57 return HDF_FAILURE;
58 }
59 g_resourceNode = node;
60 return HDF_SUCCESS;
61 }
62
ClearCapabilityData()63 int32_t ClearCapabilityData()
64 {
65 return ClearCapabilityGroup(&g_codecCapabilites);
66 }
67
LoadCapabilityData()68 int32_t LoadCapabilityData()
69 {
70 return LoadCodecCapabilityFromHcs(g_resourceNode, &g_codecCapabilites);
71 }
72
HandleGetNumCmd(struct HdfSBuf * reply)73 int32_t HandleGetNumCmd(struct HdfSBuf *reply)
74 {
75 if (!g_codecCapabilites.inited) {
76 HDF_LOGE("%{public}s: g_codecCapabilites not init!", __func__);
77 return HDF_FAILURE;
78 }
79
80 if (!HdfSbufWriteInt32(reply, g_codecCapabilites.total)) {
81 HDF_LOGE("%{public}s: write num failed!", __func__);
82 return HDF_FAILURE;
83 }
84
85 return HDF_SUCCESS;
86 }
87
HandleGetAllCapablityListCmd(struct HdfSBuf * reply)88 int32_t HandleGetAllCapablityListCmd(struct HdfSBuf *reply)
89 {
90 if (!g_codecCapabilites.inited) {
91 HDF_LOGE("%{public}s: g_codecCapabilites not init!", __func__);
92 return HDF_FAILURE;
93 }
94
95 if (AllCapabilityMarshalling(reply) != HDF_SUCCESS) {
96 HDF_LOGE("%{public}s: write all capbility to sbuf failed!", __func__);
97 return HDF_FAILURE;
98 }
99
100 return HDF_SUCCESS;
101 }
102