diff --git a/OAT.xml b/OAT.xml
index d03da3632eb9b15682b76d6fdf2d2a2d2f8d267a..ae4423733e4725130142575269d4a4c474b57ee8 100644
--- a/OAT.xml
+++ b/OAT.xml
@@ -62,6 +62,7 @@ Note:If the text contains special characters, please escape them according to th
+
diff --git a/codec/BUILD.gn b/codec/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..701cf25b575a17759d29060b54a0d355400572d7
--- /dev/null
+++ b/codec/BUILD.gn
@@ -0,0 +1,19 @@
+# Copyright (c) 2021 Shenzhen Kaihong DID Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build/ohos.gni")
+import("//drivers/adapter/uhdf2/uhdf.gni")
+
+group("hdf_mediacodec") {
+ deps = [ "//drivers/peripheral/codec/hal/config:codec_capability_config" ]
+}
diff --git a/codec/hal/config/BUILD.gn b/codec/hal/config/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..c0b7a6b51f25d409c4d2a175ea193b420e2d5947
--- /dev/null
+++ b/codec/hal/config/BUILD.gn
@@ -0,0 +1,49 @@
+# Copyright (c) 2021 Shenzhen Kaihong DID Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build/ohos.gni")
+import("//drivers/adapter/uhdf2/uhdf.gni")
+
+ohos_shared_library("libcodec_capability_config") {
+ include_dirs = [
+ "//drivers/adapter/uhdf2/include/hdi",
+ "//drivers/peripheral/codec/interfaces/include",
+ "//drivers/peripheral/codec/hal/config/capability_config/include",
+ "//drivers/peripheral/codec/hal/config/common/include",
+ ]
+ sources = [
+ "capability_config/src/codec_capability_config.c",
+ "capability_config/src/config_parser.c",
+ "common/src/codec_utils.c",
+ ]
+
+ deps = [
+ "//drivers/adapter/uhdf2/hdi:libhdi",
+ "//drivers/adapter/uhdf2/host:libhdf_host",
+ "//drivers/adapter/uhdf2/ipc:libhdf_ipc_adapter",
+ "//drivers/adapter/uhdf2/utils:libhdf_utils",
+ ]
+
+ if (is_standard_system) {
+ external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
+ } else {
+ external_deps = [ "hilog:libhilog" ]
+ }
+
+ subsystem_name = "hdf"
+ part_name = "hdf"
+}
+
+group("codec_capability_config") {
+ deps = [ ":libcodec_capability_config" ]
+}
diff --git a/codec/hal/config/capability_config/include/codec_config_reader.h b/codec/hal/config/capability_config/include/codec_config_reader.h
new file mode 100644
index 0000000000000000000000000000000000000000..eb7b437be9ea5397c1a543a85ea8c4b9d9794373
--- /dev/null
+++ b/codec/hal/config/capability_config/include/codec_config_reader.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2021 Shenzhen Kaihong DID Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef DRIVERS_PERIPHERAL_CODEC_CONFIG_READER_H_
+#define DRIVERS_PERIPHERAL_CODEC_CONFIG_READER_H_
+
+#include
+#include "hdf_io_service_if.h"
+#include "hdf_remote_service.h"
+#include "codec_type.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+struct HdfRemoteService *GetConfigService(void);
+int32_t EnumrateCapability(struct HdfRemoteService *remote, int index, CodecCapbility *cap);
+int32_t GetCapability(struct HdfRemoteService *remote,
+ AvCodecMime mime, CodecType type, uint32_t flags, CodecCapbility *cap);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif // DRIVERS_PERIPHERAL_CODEC_CONFIG_READER_H_
diff --git a/codec/hal/config/capability_config/include/config_parser.h b/codec/hal/config/capability_config/include/config_parser.h
new file mode 100644
index 0000000000000000000000000000000000000000..8b623d80efe69276edd0e35f7cd5812412b00608
--- /dev/null
+++ b/codec/hal/config/capability_config/include/config_parser.h
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2021 Shenzhen Kaihong DID Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef DRIVERS_PERIPHERAL_CODEC_CONFIG_PARSER_H_
+#define DRIVERS_PERIPHERAL_CODEC_CONFIG_PARSER_H_
+
+#define NODE_VIDEO_HARDWARE_ENCODERS "VideoHwEncoders"
+#define NODE_VIDEO_HARDWARE_DECODERS "VideoHwDecoders"
+#define NODE_VIDEO_SOFTWARE_ENCODERS "VideoSwEncoders"
+#define NODE_VIDEO_SOFTWARE_DECODERS "VideoSwDecoders"
+#define NODE_AUDIO_HARDWARE_ENCODERS "AudioHwEncoders"
+#define NODE_AUDIO_HARDWARE_DECODERS "AudioHwDecoders"
+#define NODE_AUDIO_SOFTWARE_ENCODERS "AudioSwEncoders"
+#define NODE_AUDIO_SOFTWARE_DECODERS "AudioSwDecoders"
+
+#define CODEC_CONFIG_KEY_MIME "mime"
+#define CODEC_CONFIG_KEY_TYPE "type"
+#define CODEC_CONFIG_KEY_SUPPORT_PROFILES "supportProfiles"
+#define CODEC_CONFIG_KEY_IS_SOFTWARE_CODEC "isSoftwareCodec"
+#define CODEC_CONFIG_KEY_CAPS_MASK "capsMask"
+#define CODEC_CONFIG_KEY_ALLOCATE_MASK "allocateMask"
+#define CODEC_CONFIG_KEY_MIN_INPUT_BUFFER_NUM "minInputBufferNum"
+#define CODEC_CONFIG_KEY_MAX_INPUT_BUFFER_NUM "maxInputBufferNum"
+#define CODEC_CONFIG_KEY_MIN_OUTPUT_BUFFER_NUM "minOutputBufferNum"
+#define CODEC_CONFIG_KEY_MAX_OUTPUT_BUFFER_NUM "maxOutputBufferNum"
+#define CODEC_CONFIG_KEY_MIN_BITRATE "minBitRate"
+#define CODEC_CONFIG_KEY_MAX_BITRATE "maxBitRate"
+#define CODEC_CONFIG_KEY_BUFFER_SIZE "bufferSize"
+#define CODEC_CONFIG_KEY_MIN_WIDTH "minWidth"
+#define CODEC_CONFIG_KEY_MIN_HEIGHT "minHeight"
+#define CODEC_CONFIG_KEY_MAX_WIDTH "maxWidth"
+#define CODEC_CONFIG_KEY_MAX_HEIGHT "maxHeight"
+#define CODEC_CONFIG_KEY_WIDTH_ALGINMENT "widthAlginment"
+#define CODEC_CONFIG_KEY_HEIGHT_ALGINMENT "heightAlginment"
+#define CODEC_CONFIG_KEY_SUPPORT_PIXELF_MTS "supportPixelFmts"
+#define CODEC_CONFIG_KEY_SUPPORT_LEVELS "supportLevels"
+#define CODEC_CONFIG_KEY_SAMPLE_FORMATS "sampleFormats"
+#define CODEC_CONFIG_KEY_SAMPLE_RATE "sampleRate"
+#define CODEC_CONFIG_KEY_CHANNEL_COUNT "channelCount"
+
+#define CODEC_CAPABLITY_GROUP_NUM 8
+
+#include
+#include "codec_type.h"
+
+typedef enum {
+ CODEC_CONFIG_CMD_ENUMERATE_CAP,
+ CODEC_CONFIG_CMD_GET_CAP
+} CodecInterfaceCmd;
+
+typedef struct {
+ int num;
+ CodecCapbility *capablitis;
+} CodecCapablityGroup;
+
+typedef struct {
+ bool inited;
+ CodecCapablityGroup videoHwEncoderGroup;
+ CodecCapablityGroup videoHwDecoderGroup;
+ CodecCapablityGroup videoSwEncoderGroup;
+ CodecCapablityGroup videoSwDecoderGroup;
+ CodecCapablityGroup audioHwEncoderGroup;
+ CodecCapablityGroup audioHwDecoderGroup;
+ CodecCapablityGroup audioSwEncoderGroup;
+ CodecCapablityGroup audioSwDecoderGroup;
+} CodecCapablites;
+
+int32_t LoadCodecCapabilityFromHcs(const struct DeviceResourceNode *node, CodecCapablites *caps);
+int32_t ClearCapabilityGroup(CodecCapablites *caps);
+
+#endif // DRIVERS_PERIPHERAL_CODEC_CONFIG_PARSER_H_
diff --git a/codec/hal/config/capability_config/src/codec_capability_config.c b/codec/hal/config/capability_config/src/codec_capability_config.c
new file mode 100644
index 0000000000000000000000000000000000000000..cddea66f05917b576f628be032e2f9ab1a699999
--- /dev/null
+++ b/codec/hal/config/capability_config/src/codec_capability_config.c
@@ -0,0 +1,329 @@
+/*
+ * Copyright (c) 2021 Shenzhen Kaihong DID Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include
+#include
+#include "hdf_base.h"
+#include "hdf_log.h"
+#include "codec_type.h"
+#include "config_parser.h"
+#include "codec_utils.h"
+
+#define HDF_LOG_TAG "codec_config_service"
+
+static CodecCapablites codecCapabilites = {0};
+static const struct DeviceResourceNode *resourceNode;
+
+static int32_t SerializeCapAlginment(struct HdfSBuf *reply, Alginment *alginment)
+{
+ if (reply == NULL || alginment == NULL) {
+ HDF_LOGE("%{public}s: params null!", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ if (!HdfSbufWriteInt32(reply, alginment->widthAlginment)) {
+ HDF_LOGE("%{public}s: Write widthAlginment failed!", __func__);
+ return HDF_FAILURE;
+ }
+ if (!HdfSbufWriteInt32(reply, alginment->heightAlginment)) {
+ HDF_LOGE("%{public}s: Write heightAlginment failed!", __func__);
+ return HDF_FAILURE;
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t SerializeCapRect(struct HdfSBuf *reply, Rect *rectangle)
+{
+ if (reply == NULL || rectangle == NULL) {
+ HDF_LOGE("%{public}s: params null!", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ if (!HdfSbufWriteInt32(reply, rectangle->width)) {
+ HDF_LOGE("%{public}s: Write width failed!", __func__);
+ return HDF_FAILURE;
+ }
+ if (!HdfSbufWriteInt32(reply, rectangle->height)) {
+ HDF_LOGE("%{public}s: Write height failed!", __func__);
+ return HDF_FAILURE;
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t SerializeCapArray(struct HdfSBuf *reply, ResizableArray *resArr)
+{
+ if (reply == NULL || resArr == NULL) {
+ HDF_LOGE("%{public}s: params null!", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ if (!HdfSbufWriteUint32(reply, resArr->actualLen)) {
+ HDF_LOGE("%{public}s: Write actualLen failed!", __func__);
+ return HDF_FAILURE;
+ }
+ for (uint32_t i = 0; i < resArr->actualLen; i++) {
+ if (!HdfSbufWriteUint32(reply, resArr->element[i])) {
+ HDF_LOGE("%{public}s: Write HdfSubf failed!", __func__);
+ return HDF_FAILURE;
+ }
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t SerializeCodecCapbility(struct HdfSBuf *reply, CodecCapbility *cap)
+{
+ if (reply == NULL || cap == NULL) {
+ HDF_LOGE("%{public}s: params NULL!", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ if (!HdfSbufWriteUint32(reply, (uint32_t)cap->mime)) {
+ return HDF_FAILURE;
+ }
+ if (!HdfSbufWriteUint32(reply, (uint32_t)cap->type)) {
+ return HDF_FAILURE;
+ }
+ if (SerializeCapAlginment(reply, &cap->whAlignment) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+ if (SerializeCapRect(reply, &cap->minSize) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+ if (SerializeCapRect(reply, &cap->maxSize) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+ if (!HdfSbufWriteUint64(reply, cap->minBitRate)) {
+ return HDF_FAILURE;
+ }
+ if (!HdfSbufWriteUint64(reply, cap->maxBitRate)) {
+ return HDF_FAILURE;
+ }
+ if (SerializeCapArray(reply, &cap->supportProfiles) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+ if (SerializeCapArray(reply, &cap->supportLevels) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+ if (SerializeCapArray(reply, &cap->supportPixelFormats) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+ if (!HdfSbufWriteUint32(reply, cap->minInputBufferNum)) {
+ return HDF_FAILURE;
+ }
+ if (!HdfSbufWriteUint32(reply, cap->minOutputBufferNum)) {
+ return HDF_FAILURE;
+ }
+ if (!HdfSbufWriteUint32(reply, cap->allocateMask)) {
+ return HDF_FAILURE;
+ }
+ if (!HdfSbufWriteUint32(reply, cap->capsMask)) {
+ return HDF_FAILURE;
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t EnumrateCapablity(int32_t index, CodecCapbility **capability)
+{
+ int32_t loopIndex;
+ int32_t cursor = index;
+ CodecCapablityGroup *codeCapGroups[] = {&(codecCapabilites.videoHwEncoderGroup),
+ &(codecCapabilites.videoHwDecoderGroup),
+ &(codecCapabilites.videoSwEncoderGroup),
+ &(codecCapabilites.videoSwDecoderGroup),
+ &(codecCapabilites.audioHwEncoderGroup),
+ &(codecCapabilites.audioHwDecoderGroup),
+ &(codecCapabilites.audioSwEncoderGroup),
+ &(codecCapabilites.audioSwDecoderGroup)};
+
+ for (loopIndex = 0; loopIndex < CODEC_CAPABLITY_GROUP_NUM; loopIndex++) {
+ if (cursor + 1 <= codeCapGroups[loopIndex]->num) {
+ *capability = &(codeCapGroups[loopIndex]->capablitis[cursor]);
+ return HDF_SUCCESS;
+ } else {
+ cursor -= codeCapGroups[loopIndex]->num;
+ }
+ }
+
+ return HDF_FAILURE;
+}
+
+static int32_t GetCapability(AvCodecMime mime, CodecType type, uint32_t flag, CodecCapbility **capability)
+{
+ int32_t groupIndex;
+ int32_t capIndex;
+ CodecCapablityGroup *group;
+ CodecCapbility *cap;
+ bool flagMatched = false;
+ CodecCapablityGroup *codeCapGroups[] = {&(codecCapabilites.videoHwEncoderGroup),
+ &(codecCapabilites.videoHwDecoderGroup),
+ &(codecCapabilites.audioHwEncoderGroup),
+ &(codecCapabilites.audioHwDecoderGroup),
+ &(codecCapabilites.videoSwEncoderGroup),
+ &(codecCapabilites.videoSwDecoderGroup),
+ &(codecCapabilites.audioSwEncoderGroup),
+ &(codecCapabilites.audioSwDecoderGroup)};
+ const int32_t hardAndSoftSplitNumber = 4;
+
+ for (groupIndex = 0; groupIndex < CODEC_CAPABLITY_GROUP_NUM; groupIndex++) {
+ group = codeCapGroups[groupIndex];
+ for (capIndex = 0; capIndex < group->num; capIndex++) {
+ cap = &group->capablitis[capIndex];
+ flagMatched = flag == 0 ? groupIndex < hardAndSoftSplitNumber : groupIndex >= hardAndSoftSplitNumber;
+ if (mime == cap->mime && type == cap->type && flagMatched) {
+ *capability = &group->capablitis[capIndex];
+ return HDF_SUCCESS;
+ }
+ }
+ }
+
+ return HDF_FAILURE;
+}
+
+static int32_t ReloadCapabilities()
+{
+ ClearCapabilityGroup(&codecCapabilites);
+ LoadCodecCapabilityFromHcs(resourceNode, &codecCapabilites);
+ return HDF_SUCCESS;
+}
+
+static int32_t HandleEnumrateCmd(struct HdfSBuf *data, struct HdfSBuf *reply)
+{
+ CodecCapbility *capbility = NULL;
+ uint32_t index;
+
+ if (!HdfSbufReadUint32(data, &index)) {
+ HDF_LOGE("%{public}s: read index failed!", __func__);
+ return HDF_FAILURE;
+ }
+ if (!codecCapabilites.inited) {
+ return HDF_FAILURE;
+ }
+ if (EnumrateCapablity(index, &capbility) != HDF_SUCCESS) {
+ HDF_LOGE("%{public}s: EnumrateCapablity - no more capability to Enumrate!", __func__);
+ return HDF_FAILURE;
+ }
+ if (capbility->mime == MEDIA_MIMETYPE_INVALID) {
+ HDF_LOGE("%{public}s: Capablity invalid, discard!", __func__);
+ return HDF_FAILURE;
+ }
+ if (SerializeCodecCapbility(reply, capbility) != HDF_SUCCESS) {
+ HDF_LOGE("%{public}s: write capbility to sbuf failed!", __func__);
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t HandleGetCmd(struct HdfSBuf *data, struct HdfSBuf *reply)
+{
+ CodecCapbility *capbility = NULL;
+ AvCodecMime mime;
+ CodecType type;
+ uint32_t flags;
+
+ if (!HdfSbufReadUint32(data, (uint32_t*)&mime)) {
+ HDF_LOGE("%{public}s: read input mime failed!", __func__);
+ return HDF_FAILURE;
+ }
+ if (!HdfSbufReadUint32(data, (uint32_t*)&type)) {
+ HDF_LOGE("%{public}s: read input type failed!", __func__);
+ return HDF_FAILURE;
+ }
+ if (!HdfSbufReadUint32(data, &flags)) {
+ HDF_LOGE("%{public}s: read input flags failed!", __func__);
+ return HDF_FAILURE;
+ }
+ if (GetCapability(mime, type, flags, &capbility) != HDF_SUCCESS) {
+ HDF_LOGE("%{public}s: GetCapability - got nothing!", __func__);
+ return HDF_FAILURE;
+ }
+ if (SerializeCodecCapbility(reply, capbility) != HDF_SUCCESS) {
+ HDF_LOGE("%{public}s: write capbility to sbuf failed!", __func__);
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t CodecCapabilityDispatch(struct HdfDeviceIoClient *client, int id,
+ struct HdfSBuf *data, struct HdfSBuf *reply)
+{
+ int32_t result = HDF_SUCCESS;
+
+ if (client == NULL || data == NULL || reply == NULL) {
+ HDF_LOGE("%{public}s: params NULL!", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ if (!codecCapabilites.inited) {
+ ReloadCapabilities();
+ }
+
+ switch (id) {
+ case CODEC_CONFIG_CMD_ENUMERATE_CAP: {
+ result = HandleEnumrateCmd(data, reply);
+ break;
+ }
+
+ case CODEC_CONFIG_CMD_GET_CAP: {
+ result = HandleGetCmd(data, reply);
+ break;
+ }
+
+ default:
+ break;
+ }
+
+ return result;
+}
+
+static int32_t CodecCapabilityBind(struct HdfDeviceObject *deviceObject)
+{
+ if (deviceObject == NULL) {
+ return HDF_FAILURE;
+ }
+
+ static struct IDeviceIoService deviceIoService = {
+ .Dispatch = CodecCapabilityDispatch,
+ };
+ deviceObject->service = &deviceIoService;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t CodecCapabilityInit(struct HdfDeviceObject *deviceObject)
+{
+ if (deviceObject == NULL) {
+ return HDF_FAILURE;
+ }
+ resourceNode = deviceObject->property;
+ if (LoadCodecCapabilityFromHcs(deviceObject->property, &codecCapabilites) != HDF_SUCCESS) {
+ ClearCapabilityGroup(&codecCapabilites);
+ }
+ return HDF_SUCCESS;
+}
+
+static void CodecCapabilityRelease(struct HdfDeviceObject *deviceObject)
+{
+ ClearCapabilityGroup(&codecCapabilites);
+ return;
+}
+
+struct HdfDriverEntry g_codecConfigDriverEntry = {
+ .moduleVersion = 1,
+ .moduleName = "codec_capability_config", // corresponding serviceName is "codec_capability_config_service";
+ .Bind = CodecCapabilityBind,
+ .Init = CodecCapabilityInit,
+ .Release = CodecCapabilityRelease,
+};
+
+HDF_INIT(g_codecConfigDriverEntry);
diff --git a/codec/hal/config/capability_config/src/codec_config_reader.c b/codec/hal/config/capability_config/src/codec_config_reader.c
new file mode 100644
index 0000000000000000000000000000000000000000..682b95ecd474f7f06974660663be2cf24f628f4a
--- /dev/null
+++ b/codec/hal/config/capability_config/src/codec_config_reader.c
@@ -0,0 +1,249 @@
+/*
+ * Copyright (c) 2021 Shenzhen Kaihong DID Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "codec_config_reader.h"
+#include
+#include
+#include
+#include "config_parser.h"
+#include "codec_utils.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#define HDF_LOG_TAG "codec_config_client"
+
+static int32_t DeserializeCapAlignment(struct HdfSBuf *reply, Alginment *alginment)
+{
+ if (reply == NULL || alginment == NULL) {
+ HDF_LOGE("%{public}s: params NULL!", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ if (!HdfSbufReadInt32(reply, &alginment->widthAlginment)) {
+ HDF_LOGE("%{public}s: read widthAlginment failed!", __func__);
+ return HDF_FAILURE;
+ }
+ if (!HdfSbufReadInt32(reply, &alginment->heightAlginment)) {
+ HDF_LOGE("%{public}s: read heightAlginment failed!", __func__);
+ return HDF_FAILURE;
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t DeserializeCapRect(struct HdfSBuf *reply, Rect *rectangle)
+{
+ if (reply == NULL || rectangle == NULL) {
+ HDF_LOGE("%{public}s: params NULL!", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ if (!HdfSbufReadInt32(reply, &rectangle->width)) {
+ HDF_LOGE("%{public}s: read width failed!", __func__);
+ return HDF_FAILURE;
+ }
+ if (!HdfSbufReadInt32(reply, &rectangle->height)) {
+ HDF_LOGE("%{public}s: read height failed!", __func__);
+ return HDF_FAILURE;
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t DeserializeCapArray(struct HdfSBuf *reply, ResizableArray *resArr)
+{
+ if (reply == NULL || resArr == NULL) {
+ HDF_LOGE("%{public}s: params NULL!", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ resArr->actualLen = 0;
+ if (!HdfSbufReadUint32(reply, &resArr->actualLen)) {
+ HDF_LOGE("%{public}s: read actualLen failed!", __func__);
+ return HDF_FAILURE;
+ }
+ for (uint32_t i = 0; i < resArr->actualLen; i++) {
+ if (!HdfSbufReadUint32(reply, &resArr->element[i])) {
+ HDF_LOGE("%{public}s: read element failed!", __func__);
+ return HDF_FAILURE;
+ }
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t DeserializeCodecCapability(struct HdfSBuf *reply, CodecCapbility *cap)
+{
+ if (reply == NULL || cap == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+ if (!HdfSbufReadUint32(reply, (uint32_t*)&cap->mime)) {
+ return HDF_FAILURE;
+ }
+ if (!HdfSbufReadUint32(reply, (uint32_t*)&cap->type)) {
+ return HDF_FAILURE;
+ }
+ if (DeserializeCapAlignment(reply, &cap->whAlignment) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+ if (DeserializeCapRect(reply, &cap->minSize) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+ if (DeserializeCapRect(reply, &cap->maxSize) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+ if (!HdfSbufReadUint64(reply, &cap->minBitRate)) {
+ return HDF_FAILURE;
+ }
+ if (!HdfSbufReadUint64(reply, &cap->maxBitRate)) {
+ return HDF_FAILURE;
+ }
+ if (DeserializeCapArray(reply, &cap->supportProfiles) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+ if (DeserializeCapArray(reply, &cap->supportLevels) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+ if (DeserializeCapArray(reply, &cap->supportPixelFormats) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+ if (!HdfSbufReadUint32(reply, &cap->minInputBufferNum)) {
+ return HDF_FAILURE;
+ }
+ if (!HdfSbufReadUint32(reply, &cap->minOutputBufferNum)) {
+ return HDF_FAILURE;
+ }
+ if (!HdfSbufReadUint32(reply, &cap->allocateMask)) {
+ return HDF_FAILURE;
+ }
+ if (!HdfSbufReadUint32(reply, &cap->capsMask)) {
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+struct HdfRemoteService *GetConfigService(void)
+{
+ struct HDIServiceManager *serviceMgr = HDIServiceManagerGet();
+ if (serviceMgr == NULL) {
+ HDF_LOGE("%{public}s: HDIServiceManager not found!", __func__);
+ return NULL;
+ }
+
+ struct HdfRemoteService *remote = serviceMgr->GetService(serviceMgr, "codec_capability_config_service");
+ if (remote == NULL) {
+ HDF_LOGE("%{public}s: HdfRemoteService not found!", __func__);
+ return NULL;
+ }
+
+ return remote;
+}
+
+static void ReleaseSbuf(struct HdfSBuf *data, struct HdfSBuf *reply)
+{
+ if (data != NULL) {
+ HdfSBufRecycle(data);
+ }
+ if (reply != NULL) {
+ HdfSBufRecycle(reply);
+ }
+}
+
+int32_t EnumrateCapability(struct HdfRemoteService *remote, int index, CodecCapbility *cap)
+{
+ struct HdfSBuf *data = HdfSBufTypedObtain(SBUF_IPC);
+ if (data == NULL) {
+ HDF_LOGE("%{public}s: Failed to obtain", __func__);
+ return HDF_FAILURE;
+ }
+ struct HdfSBuf *reply = HdfSBufTypedObtain(SBUF_IPC);
+ if (reply == NULL) {
+ HDF_LOGE("%{public}s: Failed to obtain reply", __func__);
+ HdfSBufRecycle(data);
+ return HDF_FAILURE;
+ }
+
+ if (!HdfSbufWriteUint32(data, index)) {
+ HDF_LOGE("%{public}s: write input index failed!", __func__);
+ ReleaseSbuf(data, reply);
+ return HDF_FAILURE;
+ }
+
+ if (remote->dispatcher->Dispatch(remote, CODEC_CONFIG_CMD_ENUMERATE_CAP, data, reply) != HDF_SUCCESS) {
+ HDF_LOGE("%{public}s: dispatch request failed!", __func__);
+ ReleaseSbuf(data, reply);
+ return HDF_FAILURE;
+ }
+
+ if (DeserializeCodecCapability(reply, cap) != HDF_SUCCESS) {
+ HDF_LOGE("%{public}s: DeserializeCodecCapbility failed!", __func__);
+ ReleaseSbuf(data, reply);
+ return HDF_FAILURE;
+ }
+
+ ReleaseSbuf(data, reply);
+ return HDF_SUCCESS;
+}
+
+int32_t GetCapability(struct HdfRemoteService *remote,
+ AvCodecMime mime, CodecType type, uint32_t flags, CodecCapbility *cap)
+{
+ struct HdfSBuf *data = HdfSBufTypedObtain(SBUF_IPC);
+ if (data == NULL) {
+ HDF_LOGE("%{public}s: Failed to obtain", __func__);
+ return HDF_FAILURE;
+ }
+ struct HdfSBuf *reply = HdfSBufTypedObtain(SBUF_IPC);
+ if (reply == NULL) {
+ HDF_LOGE("%{public}s: Failed to obtain reply", __func__);
+ HdfSBufRecycle(data);
+ return HDF_FAILURE;
+ }
+
+ if (!HdfSbufWriteUint32(data, (uint32_t)mime)) {
+ HDF_LOGE("%{public}s: write input mime failed!", __func__);
+ ReleaseSbuf(data, reply);
+ return HDF_FAILURE;
+ }
+
+ if (!HdfSbufWriteUint32(data, (uint32_t)type)) {
+ HDF_LOGE("%{public}s: write input type failed!", __func__);
+ ReleaseSbuf(data, reply);
+ return HDF_FAILURE;
+ }
+
+ if (!HdfSbufWriteUint32(data, flags)) {
+ HDF_LOGE("%{public}s: write input flags failed!", __func__);
+ ReleaseSbuf(data, reply);
+ return HDF_FAILURE;
+ }
+
+ if (remote->dispatcher->Dispatch(remote, CODEC_CONFIG_CMD_GET_CAP, data, reply) != HDF_SUCCESS) {
+ HDF_LOGE("%{public}s: dispatch request failed!", __func__);
+ ReleaseSbuf(data, reply);
+ return HDF_FAILURE;
+ }
+
+ if (DeserializeCodecCapability(reply, cap) != HDF_SUCCESS) {
+ HDF_LOGE("%{public}s: DeserializeCodecCapbility failed!", __func__);
+ ReleaseSbuf(data, reply);
+ return HDF_FAILURE;
+ }
+
+ ReleaseSbuf(data, reply);
+ return HDF_SUCCESS;
+}
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
diff --git a/codec/hal/config/capability_config/src/config_parser.c b/codec/hal/config/capability_config/src/config_parser.c
new file mode 100644
index 0000000000000000000000000000000000000000..c1518115b7caaa50e839d56f08183d52ecf911e7
--- /dev/null
+++ b/codec/hal/config/capability_config/src/config_parser.c
@@ -0,0 +1,246 @@
+/*
+ * Copyright (c) 2021 Shenzhen Kaihong DID Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "config_parser.h"
+#include
+#include "hdf_base.h"
+#include "hdf_log.h"
+#include "codec_utils.h"
+
+#define HDF_LOG_TAG "codec_config_parser"
+
+static int32_t GetGroupCapabilitiesNumber(const struct DeviceResourceNode *node,
+ const char *nodeName, int32_t *num)
+{
+ int result = 0;
+ const struct DeviceResourceNode *codecGroupNode = NULL;
+ struct DeviceResourceNode *childNode = NULL;
+ struct DeviceResourceIface *iface = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
+
+ *num = 0;
+ if (iface ==NULL || node == NULL || nodeName == NULL) {
+ HDF_LOGE("%{public}s, failed for codecs %{public}s, variable NULL!", __func__, nodeName);
+ return HDF_FAILURE;
+ }
+
+ codecGroupNode = iface->GetChildNode(node, nodeName);
+ if (codecGroupNode == NULL) {
+ HDF_LOGE("%{public}s, failed to get child node %{public}s,!", __func__, nodeName);
+ return HDF_FAILURE;
+ }
+ DEV_RES_NODE_FOR_EACH_CHILD_NODE(codecGroupNode, childNode) {
+ result++;
+ }
+ *num = result;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t GetUintTableConfig(const struct DeviceResourceIface *iface,
+ const struct DeviceResourceNode *node, const char *attrName, ResizableArray *table)
+{
+ int32_t count = iface->GetElemNum(node, attrName);
+
+ table->actualLen = 0;
+ if (count <= 0) {
+ return HDF_FAILURE;
+ }
+ if (count > ELEMENT_MAX_LEN) {
+ HDF_LOGE("%{public}s, table size: %{public}d, exceeded max size %{public}d!",
+ __func__, count, ELEMENT_MAX_LEN);
+ return HDF_FAILURE;
+ }
+
+ iface->GetUint32Array(node, attrName, table->element, count, 0);
+ table->actualLen = count;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t GetMaskedConfig(const struct DeviceResourceIface *iface,
+ const struct DeviceResourceNode *node, const char *attrName, uint32_t *mask)
+{
+ int32_t index = 0;
+ uint32_t *values = NULL;
+ int32_t count = iface->GetElemNum(node, attrName);
+
+ *mask = 0;
+ if (count <= 0) {
+ return HDF_FAILURE;
+ }
+
+ values = (uint32_t *)OsalMemAlloc(sizeof(uint32_t) * count);
+ if (values == NULL) {
+ HDF_LOGE("%{public}s, failed to allocate mem for %{public}s!", __func__, attrName);
+ return HDF_FAILURE;
+ }
+ iface->GetUint32Array(node, attrName, values, count, 0);
+ for (index = 0; index < count; index++) {
+ *mask |= values[index];
+ }
+ OsalMemFree(values);
+
+ return HDF_SUCCESS;
+}
+
+static int32_t GetOneCapability(const struct DeviceResourceIface *iface,
+ const struct DeviceResourceNode *childNode, CodecCapbility *cap)
+{
+ if (iface == NULL || childNode == NULL || cap == NULL) {
+ return HDF_FAILURE;
+ }
+ if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_MIME,
+ (uint32_t*)&cap->mime, MEDIA_MIMETYPE_INVALID) != HDF_SUCCESS) {
+ cap->mime = MEDIA_MIMETYPE_INVALID;
+ HDF_LOGE("%{public}s, failed to get mime for: %{public}s! Discarded", __func__, childNode->name);
+ return HDF_FAILURE;
+ }
+
+ if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_TYPE, (uint32_t*)&cap->type, INVALID_TYPE) != HDF_SUCCESS) {
+ cap->mime = MEDIA_MIMETYPE_INVALID;
+ cap->type = INVALID_TYPE;
+ HDF_LOGE("%{public}s, failed to get type for: %{public}s! Discarded", __func__, childNode->name);
+ return HDF_FAILURE;
+ }
+
+ if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_WIDTH_ALGINMENT,
+ (uint32_t*)&cap->whAlignment.widthAlginment, 0) != HDF_SUCCESS
+ || iface->GetUint32(childNode, CODEC_CONFIG_KEY_HEIGHT_ALGINMENT,
+ (uint32_t*)&cap->whAlignment.heightAlginment, 0) != HDF_SUCCESS
+ || iface->GetUint32(childNode, CODEC_CONFIG_KEY_MIN_WIDTH, (uint32_t*)&cap->minSize.width, 0) != HDF_SUCCESS
+ || iface->GetUint32(childNode, CODEC_CONFIG_KEY_MIN_HEIGHT, (uint32_t*)&cap->minSize.height, 0) != HDF_SUCCESS
+ || iface->GetUint32(childNode, CODEC_CONFIG_KEY_MAX_WIDTH, (uint32_t*)&cap->maxSize.width, 0) != HDF_SUCCESS
+ || iface->GetUint32(childNode, CODEC_CONFIG_KEY_MAX_HEIGHT, (uint32_t*)&cap->maxSize.height, 0) != HDF_SUCCESS
+ || iface->GetUint32(childNode, CODEC_CONFIG_KEY_MIN_BITRATE, (uint32_t*)&cap->minBitRate, 0) != HDF_SUCCESS
+ || iface->GetUint32(childNode, CODEC_CONFIG_KEY_MAX_BITRATE, (uint32_t*)&cap->maxBitRate, 0) != HDF_SUCCESS
+ || GetUintTableConfig(iface, childNode, CODEC_CONFIG_KEY_SUPPORT_PROFILES,
+ &(cap->supportProfiles)) != HDF_SUCCESS
+ || GetUintTableConfig(iface, childNode, CODEC_CONFIG_KEY_SUPPORT_LEVELS, &(cap->supportLevels)) != HDF_SUCCESS
+ || GetUintTableConfig(iface, childNode, CODEC_CONFIG_KEY_SUPPORT_PIXELF_MTS,
+ &(cap->supportPixelFormats)) != HDF_SUCCESS
+ || iface->GetUint32(childNode, CODEC_CONFIG_KEY_MIN_INPUT_BUFFER_NUM,
+ &cap->minInputBufferNum, 0) != HDF_SUCCESS
+ || iface->GetUint32(childNode, CODEC_CONFIG_KEY_MIN_OUTPUT_BUFFER_NUM,
+ &cap->minOutputBufferNum, 0) != HDF_SUCCESS
+ || GetMaskedConfig(iface, childNode, CODEC_CONFIG_KEY_ALLOCATE_MASK, &cap->allocateMask) != HDF_SUCCESS
+ || GetMaskedConfig(iface, childNode, CODEC_CONFIG_KEY_CAPS_MASK, &cap->capsMask) != HDF_SUCCESS) {
+ cap->mime = MEDIA_MIMETYPE_INVALID;
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t GetGroupCapabilities(const struct DeviceResourceNode *node,
+ const char *nodeName, CodecCapablityGroup *capsGroup)
+{
+ CodecCapbility *cap;
+ int32_t index = 0;
+ const struct DeviceResourceNode *codecGroupNode = NULL;
+ struct DeviceResourceNode *childNode = NULL;
+ struct DeviceResourceIface *iface = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
+
+ if (iface ==NULL || node == NULL || nodeName == NULL) {
+ HDF_LOGE("%{public}s, failed for node %{public}s, variable NULL!", __func__, nodeName);
+ return HDF_FAILURE;
+ }
+
+ codecGroupNode = iface->GetChildNode(node, nodeName);
+ if (codecGroupNode == NULL) {
+ HDF_LOGE("%{public}s, failed to get child node: %{public}s!", __func__, nodeName);
+ return HDF_FAILURE;
+ }
+ DEV_RES_NODE_FOR_EACH_CHILD_NODE(codecGroupNode, childNode) {
+ cap = &(capsGroup->capablitis[index++]);
+ GetOneCapability(iface, childNode, cap);
+ }
+
+ return HDF_SUCCESS;
+}
+
+int32_t LoadCodecCapabilityFromHcs(const struct DeviceResourceNode *node, CodecCapablites *caps)
+{
+ CodecCapablityGroup *codecCapGroup;
+ int32_t index;
+ int32_t codecNum = 0;
+
+ if (node == NULL) {
+ HDF_LOGE("%{public}s, load capability failed, node is null!", __func__);
+ return HDF_FAILURE;
+ }
+
+ char *codecGroupsNodeName[] = {
+ NODE_VIDEO_HARDWARE_ENCODERS, NODE_VIDEO_HARDWARE_DECODERS,
+ NODE_VIDEO_SOFTWARE_ENCODERS, NODE_VIDEO_SOFTWARE_DECODERS,
+ NODE_AUDIO_HARDWARE_ENCODERS, NODE_AUDIO_HARDWARE_DECODERS,
+ NODE_AUDIO_SOFTWARE_ENCODERS, NODE_AUDIO_SOFTWARE_DECODERS
+ };
+ CodecCapablityGroup *codecCapGroups[] = {
+ &(caps->videoHwEncoderGroup), &(caps->videoHwDecoderGroup),
+ &(caps->videoSwEncoderGroup), &(caps->videoSwDecoderGroup),
+ &(caps->audioHwEncoderGroup), &(caps->audioHwDecoderGroup),
+ &(caps->audioSwEncoderGroup), &(caps->audioSwDecoderGroup)
+ };
+
+ for (index = 0; index < CODEC_CAPABLITY_GROUP_NUM; index++) {
+ if (GetGroupCapabilitiesNumber(node, codecGroupsNodeName[index], &codecNum) == HDF_SUCCESS) {
+ codecCapGroup = codecCapGroups[index];
+ codecCapGroup->num = codecNum;
+ if (codecNum > 0) {
+ codecCapGroup->capablitis
+ = (CodecCapbility *)OsalMemAlloc(sizeof(CodecCapbility) * codecNum);
+ } else {
+ codecCapGroup->capablitis = NULL;
+ }
+ if (codecNum > 0 && codecCapGroup->capablitis == NULL) {
+ codecCapGroup->num = 0;
+ HDF_LOGE("%{public}s, MemAlloc for capability group failed!", __func__);
+ return HDF_FAILURE;
+ }
+ }
+ }
+
+ for (index = 0; index < CODEC_CAPABLITY_GROUP_NUM; index++) {
+ if (GetGroupCapabilities(node, codecGroupsNodeName[index], codecCapGroups[index]) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+ }
+
+ caps->inited = true;
+ return HDF_SUCCESS;
+}
+
+int32_t ClearCapabilityGroup(CodecCapablites *caps)
+{
+ int32_t index;
+ CodecCapablityGroup *codecCapGroup;
+ CodecCapablityGroup *codecCapGroups[] = {
+ &(caps->videoHwEncoderGroup), &(caps->videoHwDecoderGroup),
+ &(caps->videoSwEncoderGroup), &(caps->videoSwDecoderGroup),
+ &(caps->audioHwEncoderGroup), &(caps->audioHwDecoderGroup),
+ &(caps->audioSwEncoderGroup), &(caps->audioSwDecoderGroup)
+ };
+ for (index = 0; index < CODEC_CAPABLITY_GROUP_NUM; index++) {
+ codecCapGroup = codecCapGroups[index];
+ if (codecCapGroup->capablitis != NULL) {
+ OsalMemFree(codecCapGroup->capablitis);
+ codecCapGroup->num = 0;
+ codecCapGroup->capablitis = NULL;
+ }
+ }
+ caps->inited = false;
+
+ return HDF_SUCCESS;
+}
\ No newline at end of file
diff --git a/codec/hal/config/common/include/codec_utils.h b/codec/hal/config/common/include/codec_utils.h
new file mode 100644
index 0000000000000000000000000000000000000000..bf4159b9aa36dd2968c20e0bc3d560a997fd9ccd
--- /dev/null
+++ b/codec/hal/config/common/include/codec_utils.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2021 Shenzhen Kaihong DID Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef DRIVERS_PERIPHERAL_CODEC_CONFIG_COMMON_UITLS_H_
+#define DRIVERS_PERIPHERAL_CODEC_CONFIG_COMMON_UITLS_H_
+
+#include "hdf_base.h"
+#include "codec_type.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+void PrintArray(const char *where, const char *name, ResizableArray *array);
+void PrintCapability(const char *where, CodecCapbility *cap);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif // DRIVERS_PERIPHERAL_CODEC_CONFIG_COMMON_UITLS_H_
\ No newline at end of file
diff --git a/codec/hal/config/common/src/codec_utils.c b/codec/hal/config/common/src/codec_utils.c
new file mode 100644
index 0000000000000000000000000000000000000000..0a8bc0343818ec585dd7bb290e3e0f278dde692b
--- /dev/null
+++ b/codec/hal/config/common/src/codec_utils.c
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2021 Shenzhen Kaihong DID Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "codec_utils.h"
+#include "hdf_log.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#define HDF_LOG_TAG "codec_config_common"
+
+void PrintArray(const char *where, const char *name, ResizableArray *array)
+{
+ uint32_t index;
+
+ if (array == NULL) {
+ return;
+ }
+ HDF_LOGI("%{public}s, %{public}s len: %{public}d", where, name, (int32_t)array->actualLen);
+ for (index = 0; index < array->actualLen; index++) {
+ HDF_LOGI("%{public}s, %{public}s-%{public}d: %{public}d",
+ where, name, index, (int32_t)array->element[index]);
+ }
+}
+
+void PrintCapability(const char *where, CodecCapbility *cap)
+{
+ int32_t mime = 0;
+ if (cap == NULL) {
+ HDF_LOGE("%{public}s, null capability!", where);
+ return;
+ }
+ mime = (int32_t)cap->mime;
+ if (mime < 0) {
+ HDF_LOGE("%{public}s, print invalid capability!", where);
+ return;
+ }
+
+ HDF_LOGI("%{public}s, --- start print cap ----------------------------", where);
+ HDF_LOGI("%{public}s, mime: %{public}d", where, (int32_t)cap->mime);
+ HDF_LOGI("%{public}s, type: %{public}d", where, (int32_t)cap->type);
+ HDF_LOGI("%{public}s, widthAlginment: %{public}d", where, (int32_t)cap->whAlignment.widthAlginment);
+ HDF_LOGI("%{public}s, heightAlginment: %{public}d", where, (int32_t)cap->whAlignment.heightAlginment);
+ HDF_LOGI("%{public}s, minwidth: %{public}d", where, (int32_t)cap->minSize.width);
+ HDF_LOGI("%{public}s, minHeight: %{public}d", where, (int32_t)cap->minSize.height);
+ HDF_LOGI("%{public}s, maxwidth: %{public}d", where, (int32_t)cap->maxSize.width);
+ HDF_LOGI("%{public}s, maxheight: %{public}d", where, (int32_t)cap->maxSize.height);
+ HDF_LOGI("%{public}s, minBitRate: %{public}d", where, (int32_t)cap->minBitRate);
+ HDF_LOGI("%{public}s, maxBitRate: %{public}d", where, (int32_t)cap->maxBitRate);
+ PrintArray(where, "supportProfiles", &(cap->supportProfiles));
+ PrintArray(where, "supportLevels", &(cap->supportLevels));
+ PrintArray(where, "supportPixelFormats", &(cap->supportPixelFormats));
+ HDF_LOGI("%{public}s, minInputBufferNum: %{public}d", where, (int32_t)cap->minInputBufferNum);
+ HDF_LOGI("%{public}s, minOutputBufferNum: %{public}d", where, (int32_t)cap->minOutputBufferNum);
+ HDF_LOGI("%{public}s, allocateMask: %{public}d", where, (int32_t)cap->allocateMask);
+ HDF_LOGI("%{public}s, capsMask: %{public}d", where, (int32_t)cap->capsMask);
+ HDF_LOGI("%{public}s, ------------------------------ end print cap ---", where);
+}
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
diff --git a/codec/test/BUILD.gn b/codec/test/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..b4af4ead30f6025ea4ad584192824776cf7d2022
--- /dev/null
+++ b/codec/test/BUILD.gn
@@ -0,0 +1,17 @@
+# Copyright (c) 2021 Shenzhen Kaihong DID Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+group("hdf_test_mediacodec") {
+ testonly = true
+ deps = [ "unittest:hdf_unittest_codec" ]
+}
diff --git a/codec/test/unittest/BUILD.gn b/codec/test/unittest/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..b294fa93592a49fb1919be04e32217d9cfa53243
--- /dev/null
+++ b/codec/test/unittest/BUILD.gn
@@ -0,0 +1,17 @@
+# Copyright (c) 2021 Shenzhen Kaihong DID Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+group("hdf_unittest_codec") {
+ testonly = true
+ deps = [ "config:codec_config_test" ]
+}
diff --git a/codec/test/unittest/config/BUILD.gn b/codec/test/unittest/config/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..8e314f9c04ee741e58e2ce7b132019596abe035f
--- /dev/null
+++ b/codec/test/unittest/config/BUILD.gn
@@ -0,0 +1,54 @@
+# Copyright (c) 2021 Shenzhen Kaihong DID Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build/ohos.gni")
+import("//build/test.gni")
+import("//drivers/adapter/uhdf2/uhdf.gni")
+
+ohos_unittest("codec_config_test") {
+ module_out_path = "hdf/codec"
+ include_dirs = [
+ "//drivers/adapter/uhdf2/include/hdi",
+ "//drivers/peripheral/codec/interfaces/include",
+ "//drivers/peripheral/codec/hal/config/capability_config/include",
+ "//drivers/peripheral/codec/hal/config/common/include",
+ ]
+ sources = [
+ "//drivers/peripheral/codec/hal/config/capability_config/src/codec_config_reader.c",
+ "//drivers/peripheral/codec/hal/config/common/src/codec_utils.c",
+ "codec_config_test.cpp",
+ ]
+
+ cflags = [
+ "-Wall",
+ "-Wextra",
+ "-Werror",
+ "-fsigned-char",
+ "-fno-common",
+ "-fno-strict-aliasing",
+ ]
+
+ deps = [
+ "//drivers/adapter/uhdf2/hdi:libhdi",
+ "//drivers/adapter/uhdf2/host:libhdf_host",
+ "//drivers/adapter/uhdf2/ipc:libhdf_ipc_adapter",
+ "//drivers/adapter/uhdf2/utils:libhdf_utils",
+ "//third_party/googletest:gtest_main",
+ ]
+
+ if (is_standard_system) {
+ external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
+ } else {
+ external_deps = [ "hilog:libhilog" ]
+ }
+}
diff --git a/codec/test/unittest/config/codec_config_test.cpp b/codec/test/unittest/config/codec_config_test.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..b30b4b0c7c21e98aeec1528ade9005454e06f023
--- /dev/null
+++ b/codec/test/unittest/config/codec_config_test.cpp
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2021 Shenzhen Kaihong DID Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include
+#include "hdf_io_service_if.h"
+#include "codec_config_reader.h"
+#include "codec_utils.h"
+#include "codec_type.h"
+
+using namespace std;
+using namespace testing::ext;
+
+namespace {
+class CodecConfigTest : public testing::Test {
+public:
+ static void SetUpTestCase() {}
+ static void TearDownTestCase() {}
+ void SetUp() {}
+ void TearDown() {}
+};
+
+HWTEST_F(CodecConfigTest, CodecConfigTest_001, TestSize.Level0)
+{
+ struct HdfRemoteService *remote = GetConfigService();
+ ASSERT_TRUE(remote != nullptr);
+
+ for (int index = 0; index < 9; index++) {
+ CodecCapbility cap;
+ if (EnumrateCapability(remote, index, &cap) == HDF_SUCCESS) {
+ PrintCapability("codec_config_utest", &cap);
+ }
+ }
+}
+
+HWTEST_F(CodecConfigTest, CodecConfigTest_002, TestSize.Level0)
+{
+ struct HdfRemoteService *remote = GetConfigService();
+ ASSERT_TRUE(remote != nullptr);
+
+ CodecCapbility cap;
+ if (GetCapability(remote, MEDIA_MIMETYPE_VIDEO_HEVC, VIDEO_ENCODER, 0, &cap) == HDF_SUCCESS) {
+ PrintCapability("codec_config_utest", &cap);
+ }
+}
+}