From aa898ea925e009827512d4c1b57e1511794669c6 Mon Sep 17 00:00:00 2001 From: zhangguorong Date: Tue, 8 Mar 2022 19:38:18 +0800 Subject: [PATCH 1/2] feat: add hdf codec hdi compatible with open max Signed-off-by: zhangguorong --- codec/BUILD.gn | 7 +- codec/bundle.json | 3 +- codec/hal/BUILD.gn | 144 +++ .../hal/include/codec_callback_type_service.h | 31 + codec/hal/include/codec_callback_type_stub.h | 33 + .../codec_component_capability_config.h | 36 + .../include/codec_component_type_service.h | 32 + codec/hal/include/codec_component_type_stub.h | 45 + codec/hal/include/codec_config_parser.h | 97 ++ codec/hal/include/codec_internal.h | 69 ++ codec/hal/include/codec_types.h | 72 ++ codec/hal/src/codec_callback_type_proxy.c | 252 +++++ codec/hal/src/codec_callback_type_service.c | 48 + codec/hal/src/codec_callback_type_stub.c | 306 ++++++ .../src/codec_component_capability_config.c | 101 ++ codec/hal/src/codec_component_manager_proxy.c | 231 +++++ codec/hal/src/codec_component_type_driver.c | 92 ++ codec/hal/src/codec_component_type_proxy.c | 886 ++++++++++++++++ codec/hal/src/codec_component_type_service.c | 184 ++++ codec/hal/src/codec_component_type_stub.c | 971 ++++++++++++++++++ codec/hal/src/codec_config_parser.c | 401 ++++++++ codec/hal/src/codec_types.c | 658 ++++++++++++ codec/interfaces/include/codec_callback_if.h | 1 + codec/test/BUILD.gn | 2 +- 24 files changed, 4698 insertions(+), 4 deletions(-) create mode 100644 codec/hal/BUILD.gn create mode 100644 codec/hal/include/codec_callback_type_service.h create mode 100644 codec/hal/include/codec_callback_type_stub.h create mode 100644 codec/hal/include/codec_component_capability_config.h create mode 100644 codec/hal/include/codec_component_type_service.h create mode 100644 codec/hal/include/codec_component_type_stub.h create mode 100644 codec/hal/include/codec_config_parser.h create mode 100644 codec/hal/include/codec_internal.h create mode 100644 codec/hal/include/codec_types.h create mode 100644 codec/hal/src/codec_callback_type_proxy.c create mode 100644 codec/hal/src/codec_callback_type_service.c create mode 100644 codec/hal/src/codec_callback_type_stub.c create mode 100644 codec/hal/src/codec_component_capability_config.c create mode 100644 codec/hal/src/codec_component_manager_proxy.c create mode 100644 codec/hal/src/codec_component_type_driver.c create mode 100644 codec/hal/src/codec_component_type_proxy.c create mode 100644 codec/hal/src/codec_component_type_service.c create mode 100644 codec/hal/src/codec_component_type_stub.c create mode 100644 codec/hal/src/codec_config_parser.c create mode 100644 codec/hal/src/codec_types.c diff --git a/codec/BUILD.gn b/codec/BUILD.gn index 701cf25b57..7d842d3e85 100644 --- a/codec/BUILD.gn +++ b/codec/BUILD.gn @@ -14,6 +14,9 @@ import("//build/ohos.gni") import("//drivers/adapter/uhdf2/uhdf.gni") -group("hdf_mediacodec") { - deps = [ "//drivers/peripheral/codec/hal/config:codec_capability_config" ] +group("hdf_media_codec") { + deps = [ + "hal:codec_hdi_omx", + "hal/config:codec_capability_config", + ] } diff --git a/codec/bundle.json b/codec/bundle.json index de0c93edd2..86bd6635f6 100755 --- a/codec/bundle.json +++ b/codec/bundle.json @@ -22,7 +22,8 @@ "build": { "sub_component": [ "//drivers/peripheral/codec/hdi_service:codec_client", - "//drivers/peripheral/codec/hdi_service:codec_service" + "//drivers/peripheral/codec/hdi_service:codec_service", + "//drivers/peripheral/codec:hdf_media_codec" ] } } diff --git a/codec/hal/BUILD.gn b/codec/hal/BUILD.gn new file mode 100644 index 0000000000..7816922593 --- /dev/null +++ b/codec/hal/BUILD.gn @@ -0,0 +1,144 @@ +# Copyright (c) 2022 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_hdi_omx_server") { + include_dirs = [ + "//drivers/adapter/uhdf2/include/hdi", + "//drivers/peripheral/codec/interfaces/include", + "//drivers/peripheral/codec/hal/include", + "//third_party/openmax/api/1.1.2", + ] + sources = [ + "src/codec_callback_type_proxy.c", + "src/codec_component_capability_config.c", + "src/codec_component_type_driver.c", + "src/codec_component_type_stub.c", + "src/codec_config_parser.c", + "src/codec_types.c", + ] + + if (is_standard_system) { + external_deps = [ + "device_driver_framework:libhdf_host", + "device_driver_framework:libhdf_ipc_adapter", + "device_driver_framework:libhdf_utils", + "device_driver_framework:libhdi", + "hiviewdfx_hilog_native:libhilog", + "utils_base:utils", + ] + } else { + external_deps = [ "hilog:libhilog" ] + } + + install_images = [ chipset_base_dir ] + subsystem_name = "hdf" + part_name = "codec_device_driver" +} + +ohos_shared_library("libcodec_hdi_omx_client") { + include_dirs = [ + "//drivers/adapter/uhdf2/include/hdi", + "//drivers/peripheral/codec/interfaces/include", + "//drivers/peripheral/codec/hal/include", + "//third_party/openmax/api/1.1.2", + ] + sources = [ + "src/codec_callback_type_stub.c", + "src/codec_component_manager_proxy.c", + "src/codec_component_type_proxy.c", + "src/codec_types.c", + ] + + if (is_standard_system) { + external_deps = [ + "device_driver_framework:libhdf_host", + "device_driver_framework:libhdf_ipc_adapter", + "device_driver_framework:libhdf_utils", + "device_driver_framework:libhdi", + "hiviewdfx_hilog_native:libhilog", + "utils_base:utils", + ] + } else { + external_deps = [ "hilog:libhilog" ] + } + + install_images = [ chipset_base_dir ] + subsystem_name = "hdf" + part_name = "codec_device_driver" +} + +ohos_shared_library("libcodec_hdi_omx_service_impl") { + include_dirs = [ + "//drivers/adapter/uhdf2/include/hdi", + "//drivers/peripheral/codec/interfaces/include", + "//drivers/peripheral/codec/hal/include", + "//third_party/openmax/api/1.1.2", + ] + sources = [ "src/codec_component_type_service.c" ] + + if (is_standard_system) { + external_deps = [ + "device_driver_framework:libhdf_host", + "device_driver_framework:libhdf_ipc_adapter", + "device_driver_framework:libhdf_utils", + "device_driver_framework:libhdi", + "hiviewdfx_hilog_native:libhilog", + "utils_base:utils", + ] + } else { + external_deps = [ "hilog:libhilog" ] + } + + install_images = [ chipset_base_dir ] + subsystem_name = "hdf" + part_name = "codec_device_driver" +} + +ohos_shared_library("libcodec_hdi_omx_callback_type_service_impl") { + include_dirs = [ + "//drivers/adapter/uhdf2/include/hdi", + "//drivers/peripheral/codec/interfaces/include", + "//drivers/peripheral/codec/hal/include", + "//third_party/openmax/api/1.1.2", + ] + sources = [ "src/codec_callback_type_service.c" ] + + if (is_standard_system) { + external_deps = [ + "device_driver_framework:libhdf_host", + "device_driver_framework:libhdf_ipc_adapter", + "device_driver_framework:libhdf_utils", + "device_driver_framework:libhdi", + "hiviewdfx_hilog_native:libhilog", + "utils_base:utils", + ] + } else { + external_deps = [ "hilog:libhilog" ] + } + + install_images = [ chipset_base_dir ] + subsystem_name = "hdf" + part_name = "codec_device_driver" +} + +group("codec_hdi_omx") { + deps = [ + ":libcodec_hdi_omx_callback_type_service_impl", + ":libcodec_hdi_omx_client", + ":libcodec_hdi_omx_server", + ":libcodec_hdi_omx_service_impl", + ] +} diff --git a/codec/hal/include/codec_callback_type_service.h b/codec/hal/include/codec_callback_type_service.h new file mode 100644 index 0000000000..8c5d68db10 --- /dev/null +++ b/codec/hal/include/codec_callback_type_service.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2022 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 HDI_OMXCALLBACKTYPESERVICE_H +#define HDI_OMXCALLBACKTYPESERVICE_H + +#include "codec_callback_if.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +void CodecCallbackTypeServiceConstruct(struct CodecCallbackType* service); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif // HDI_OMXCALLBACKTYPESERVICE_H \ No newline at end of file diff --git a/codec/hal/include/codec_callback_type_stub.h b/codec/hal/include/codec_callback_type_stub.h new file mode 100644 index 0000000000..86598dec0e --- /dev/null +++ b/codec/hal/include/codec_callback_type_stub.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2022 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 HDI_OMXCALLBACKTYPESTUB_H +#define HDI_OMXCALLBACKTYPESTUB_H + +#include "codec_callback_if.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +struct CodecCallbackType* CodecCallbackTypeStubGetInstance(void); + +void CodecCallbackTypeStubRelease(struct CodecCallbackType *instance); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif // HDI_OMXCALLBACKTYPESTUB_H \ No newline at end of file diff --git a/codec/hal/include/codec_component_capability_config.h b/codec/hal/include/codec_component_capability_config.h new file mode 100644 index 0000000000..f520253db0 --- /dev/null +++ b/codec/hal/include/codec_component_capability_config.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2022 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 HDI_CODEC_COMPONENT_CAPABILITY_CONFIG_H +#define HDI_CODEC_COMPONENT_CAPABILITY_CONFIG_H + +#include "device_resource_if.h" +#include "hdf_sbuf.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +int32_t InitDataNode(const struct DeviceResourceNode *node); +int32_t LoadCapabilityData(); +int32_t ClearCapabilityData(); +int32_t HandleGetNumCmd(struct HdfSBuf *reply); +int32_t HandleGetAllCapablityListCmd(struct HdfSBuf *reply); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif // HDI_CODEC_COMPONENT_CAPABILITY_CONFIG_H \ No newline at end of file diff --git a/codec/hal/include/codec_component_type_service.h b/codec/hal/include/codec_component_type_service.h new file mode 100644 index 0000000000..3398eb4215 --- /dev/null +++ b/codec/hal/include/codec_component_type_service.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2022 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 HDI_OMXCOMPONENTTYPESERVICE_H +#define HDI_OMXCOMPONENTTYPESERVICE_H + +#include "codec_component_if.h" +#include "codec_internal.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +void CodecComponentTypeServiceConstruct(struct OmxComponentManager *manager, struct CodecComponentType* service); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif // HDI_OMXCOMPONENTTYPESERVICE_H \ No newline at end of file diff --git a/codec/hal/include/codec_component_type_stub.h b/codec/hal/include/codec_component_type_stub.h new file mode 100644 index 0000000000..df2a8413b4 --- /dev/null +++ b/codec/hal/include/codec_component_type_stub.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 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 HDI_OMXCOMPONENTTYPESTUB_H +#define HDI_OMXCOMPONENTTYPESTUB_H + +#include "codec_component_if.h" +#include "codec_internal.h" +#include "codec_types.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +struct CodecComponentTypeStub { + struct CodecComponentType service; + struct OmxComponentManager managerService; + void *dlHandler; + OMX_HANDLETYPE componentHandle; +}; + +int32_t CodecComponentTypeServiceOnRemoteRequest(struct CodecComponentTypeStub *service, + int32_t cmdId, struct HdfSBuf *data, struct HdfSBuf *reply); + +struct CodecComponentTypeStub* CodecComponentTypeStubGetInstance(void); + +void CodecComponentTypeStubRelease(struct CodecComponentTypeStub *instance); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif // HDI_OMXCOMPONENTTYPESTUB_H \ No newline at end of file diff --git a/codec/hal/include/codec_config_parser.h b/codec/hal/include/codec_config_parser.h new file mode 100644 index 0000000000..9cf05f2061 --- /dev/null +++ b/codec/hal/include/codec_config_parser.h @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2022 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 HDI_CODECCONFIGPARSER_H +#define HDI_CODECCONFIGPARSER_H + +#include "codec_component_type.h" +#include "device_resource_if.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_ROLE "role" +#define CODEC_CONFIG_KEY_TYPE "type" +#define CODEC_CONFIG_KEY_NAME "name" +#define CODEC_CONFIG_KEY_SUPPORT_PROFILES "supportProfiles" +#define CODEC_CONFIG_KEY_MAX_INST "maxInst" +#define CODEC_CONFIG_KEY_IS_SOFTWARE_CODEC "isSoftwareCodec" +#define CODEC_CONFIG_KEY_PROCESS_MODE_MASK "processModeMask" +#define CODEC_CONFIG_KEY_CAPS_MASK "capsMask" +#define CODEC_CONFIG_KEY_MIN_BITRATE "minBitRate" +#define CODEC_CONFIG_KEY_MAX_BITRATE "maxBitRate" + +#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_MIN_BLOCK_COUNT "minBlockCount" +#define CODEC_CONFIG_KEY_MAX_BLOCK_COUNT "maxBlockCount" +#define CODEC_CONFIG_KEY_MIN_BLOCKS_PER_SECOND "minBlocksPerSecond" +#define CODEC_CONFIG_KEY_MAX_BLOCKS_PER_SECOND "maxBlocksPerSecond" +#define CODEC_CONFIG_KEY_SUPPORT_PIXEL_FMTS "supportPixelFmts" +#define CODEC_CONFIG_KEY_BLOCK_SIZE_WIDTH "blockSizeWidth" +#define CODEC_CONFIG_KEY_BLOCK_SIZE_HEIGHT "blockSizeHeight" + +#define CODEC_CONFIG_KEY_SAMPLE_FORMATS "sampleFormats" +#define CODEC_CONFIG_KEY_SAMPLE_RATE "sampleRate" +#define CODEC_CONFIG_KEY_CHANNEL_LAYOUTS "channelLayouts" +#define CODEC_CONFIG_KEY_CHANNEL_COUNT "channelCount" + +#define CODEC_CAPABLITY_GROUP_NUM 8 + +typedef struct { + int32_t num; + CodecCompCapability *capablitis; +} CodecCapablityGroup; + +typedef struct { + CodecCapablityGroup videoHwEncoderGroup; + CodecCapablityGroup videoHwDecoderGroup; + CodecCapablityGroup videoSwEncoderGroup; + CodecCapablityGroup videoSwDecoderGroup; + CodecCapablityGroup audioHwEncoderGroup; + CodecCapablityGroup audioHwDecoderGroup; + CodecCapablityGroup audioSwEncoderGroup; + CodecCapablityGroup audioSwDecoderGroup; + int32_t total; + bool inited; +} CodecCapablites; + +typedef struct { + const char *attrName; + uint32_t *valueAddr; + uint32_t defaultValue; +} ConfigUintNodeAttr; + +typedef struct { + const char *attrName; + int32_t *array; + int32_t length; + int32_t endValue; +} ConfigUintArrayNodeAttr; + +int32_t LoadCodecCapabilityFromHcs(const struct DeviceResourceNode *node, CodecCapablites *caps); +int32_t ClearCapabilityGroup(CodecCapablites *caps); + +#endif // HDI_CODECCONFIGPARSER_H diff --git a/codec/hal/include/codec_internal.h b/codec/hal/include/codec_internal.h new file mode 100644 index 0000000000..e57685d4c8 --- /dev/null +++ b/codec/hal/include/codec_internal.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2022 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 HDI_CODECINTERNAL_H +#define HDI_CODECINTERNAL_H + +#include +#include "codec_callback_if.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#define CODEC_HDI_OMX_SERVICE_NAME "codec_hdi_omx_service" + +enum ComponentDispatchCmd { + CMD_CODEC_GET_COMPONENT_NUM, + CMD_CODEC_GET_COMPONENT_CAPABILITY_LIST, + CMD_CREATE_COMPONENT, + CMD_DESTROY_COMPONENT, + CMD_GET_COMPONENT_VERSION, + CMD_SEND_COMMAND, + CMD_GET_PARAMETER, + CMD_SET_PARAMETER, + CMD_GET_CONFIG, + CMD_SET_CONFIG, + CMD_GET_EXTENSION_INDEX, + CMD_GET_STATE, + CMD_COMPONENT_TUNNEL_REQUEST, + CMD_USE_BUFFER, + CMD_ALLOCATE_BUFFER, + CMD_FREE_BUFFER, + CMD_EMPTY_THIS_BUFFER, + CMD_FILL_THIS_BUFFER, + CMD_SET_CALLBACKS, + CMD_COMPONENT_DE_INIT, + CMD_USE_EGL_IMAGE, + CMD_COMPONENT_ROLE_ENUM, +}; + +enum CallbackDispatchCmd { + CMD_EVENT_HANDLER, + CMD_EMPTY_BUFFER_DONE, + CMD_FILL_BUFFER_DONE, +}; + +struct OmxComponentManager { + int32_t (*CreateComponent)(OMX_HANDLETYPE *compHandle, char *compName, void *appData, + int32_t appDataSize, struct CodecCallbackType *callbacks); + int32_t (*DestoryComponent)(OMX_HANDLETYPE compHandle); +}; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif // HDI_OMXCOMPONENTTYPE_H \ No newline at end of file diff --git a/codec/hal/include/codec_types.h b/codec/hal/include/codec_types.h new file mode 100644 index 0000000000..83f6d831c1 --- /dev/null +++ b/codec/hal/include/codec_types.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2022 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 HDI_CODECTYPES_H +#define HDI_CODECTYPES_H + +#include "codec_component_type.h" +#include "hdf_sbuf.h" +#include "OMX_Core.h" +#include "OMX_Index.h" +#include "OMX_Types.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +bool OMX_TUNNELSETUPTYPEBlockMarshalling(struct HdfSBuf *data, const struct OMX_TUNNELSETUPTYPE *dataBlock); + +bool OMX_TUNNELSETUPTYPEBlockUnmarshalling(struct HdfSBuf *data, struct OMX_TUNNELSETUPTYPE *dataBlock); + +void OMX_TUNNELSETUPTYPEFree(struct OMX_TUNNELSETUPTYPE *dataBlock, bool freeSelf); + +bool OmxCodecBufferBlockMarshalling(struct HdfSBuf *data, const struct OmxCodecBuffer *dataBlock); + +bool OmxCodecBufferBlockUnmarshalling(struct HdfSBuf *data, struct OmxCodecBuffer *dataBlock); + +// for config marshall +bool RangeValueBlockMarshalling(struct HdfSBuf *data, const RangeValue *dataBlock); + +bool RangeValueBlockUnmarshalling(struct HdfSBuf *data, RangeValue *dataBlock); + +bool RectBlockMarshalling(struct HdfSBuf *data, const Rect *dataBlock); + +bool RectBlockUnmarshalling(struct HdfSBuf *data, Rect *dataBlock); + +bool AlginmentBlockMarshalling(struct HdfSBuf *data, const Alginment *dataBlock); + +bool AlginmentBlockUnmarshalling(struct HdfSBuf *data, Alginment *dataBlock); + +bool VideoPortCapBlockMarshalling(struct HdfSBuf *data, const VideoPortCap *dataBlock); + +bool VideoPortCapBlockUnmarshalling(struct HdfSBuf *data, VideoPortCap *dataBlock); + +void VideoPortCapFree(VideoPortCap *dataBlock, bool freeSelf); + +bool AudioPortCapBlockMarshalling(struct HdfSBuf *data, const AudioPortCap *dataBlock); + +bool AudioPortCapBlockUnmarshalling(struct HdfSBuf *data, AudioPortCap *dataBlock); + +void AudioPortCapFree(AudioPortCap *dataBlock, bool freeSelf); + +bool CodecCompCapabilityBlockMarshalling(struct HdfSBuf *data, const CodecCompCapability *dataBlock); + +bool CodecCompCapabilityBlockUnmarshalling(struct HdfSBuf *data, CodecCompCapability *dataBlock); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif // HDI_CODECTYPES_H \ No newline at end of file diff --git a/codec/hal/src/codec_callback_type_proxy.c b/codec/hal/src/codec_callback_type_proxy.c new file mode 100644 index 0000000000..8b8642fcde --- /dev/null +++ b/codec/hal/src/codec_callback_type_proxy.c @@ -0,0 +1,252 @@ +/* + * Copyright (c) 2022 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 +#include "codec_callback_if.h" +#include "codec_internal.h" +#include "codec_types.h" + +#define HDF_LOG_TAG codec_hdi_cb_client + +struct CodecCallbackTypeProxy { + struct CodecCallbackType instance; + struct HdfRemoteService *remote; +}; + +static void ReleaseSbuf(struct HdfSBuf *data, struct HdfSBuf *reply) +{ + if (data != NULL) { + HdfSbufRecycle(data); + } + if (reply != NULL) { + HdfSbufRecycle(reply); + } +} + +static int32_t CodecCallbackTypeProxyCall(struct CodecCallbackType *self, int32_t id, struct HdfSBuf *data, + struct HdfSBuf *reply) +{ + if (self->remote == NULL || + self->remote->dispatcher == NULL || + self->remote->dispatcher->Dispatch == NULL) { + HDF_LOGE("%{public}s: obj is null", __func__); + return HDF_ERR_INVALID_OBJECT; + } + return self->remote->dispatcher->Dispatch(self->remote, id, data, reply); +} + +static int32_t WriteArray(struct HdfSBuf *data, int8_t *array, uint32_t arrayLen) +{ + if (!HdfSbufWriteUint32(data, arrayLen)) { + HDF_LOGE("%{public}s: write appData failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + for (uint32_t i = 0; i < arrayLen; i++) { + if (!HdfSbufWriteInt8(data, array[i])) { + HDF_LOGE("%{public}s: write array[i] failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + } + return HDF_SUCCESS; +} + +static int32_t WriteEventData(struct HdfSBuf *data, enum OMX_EVENTTYPE eEvent, uint32_t data1, uint32_t data2) +{ + if (!HdfSbufWriteUint32(data, (uint32_t)eEvent)) { + HDF_LOGE("%{public}s: write eEvent failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!HdfSbufWriteUint32(data, data1)) { + HDF_LOGE("%{public}s: write data1 failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!HdfSbufWriteUint32(data, data2)) { + HDF_LOGE("%{public}s: write data2 failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return HDF_SUCCESS; +} + +static int32_t CodecCallbackTypeProxyEventHandler(struct CodecCallbackType *self, + int8_t *appData, uint32_t appDataLen, enum OMX_EVENTTYPE eEvent, uint32_t data1, + uint32_t data2, int8_t *eventData, uint32_t eventDataLen) +{ + int32_t ret; + + struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); + struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); + if (data == NULL || reply == NULL) { + HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_MALLOC_FAIL; + } + + ret = WriteArray(data, appData, appDataLen); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: write appData failed!", __func__); + ReleaseSbuf(data, reply); + return ret; + } + + ret = WriteEventData(data, eEvent, data1, data2); + if (ret != HDF_SUCCESS) { + ReleaseSbuf(data, reply); + return ret; + } + + ret = WriteArray(data, eventData, eventDataLen); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: write eventData failed!", __func__); + ReleaseSbuf(data, reply); + return ret; + } + + for (uint32_t i = 0; i < eventDataLen; i++) { + if (!HdfSbufWriteInt8(data, eventData[i])) { + HDF_LOGE("%{public}s: write eventData[i] failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + } + + ret = CodecCallbackTypeProxyCall(self, CMD_EVENT_HANDLER, data, reply); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ret); + ReleaseSbuf(data, reply); + return ret; + } + + ReleaseSbuf(data, reply); + return ret; +} + +static int32_t CodecCallbackTypeProxyEmptyBufferDone(struct CodecCallbackType *self, + int8_t *appData, uint32_t appDataLen, const struct OmxCodecBuffer *buffer) +{ + int32_t ret; + + struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); + struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); + if (data == NULL || reply == NULL) { + HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_MALLOC_FAIL; + } + + if (!HdfSbufWriteUint32(data, appDataLen)) { + HDF_LOGE("%{public}s: write appData failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + for (uint32_t i = 0; i < appDataLen; i++) { + if (!HdfSbufWriteInt8(data, appData[i])) { + HDF_LOGE("%{public}s: write appData[i] failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + } + + if (!OmxCodecBufferBlockMarshalling(data, buffer)) { + HDF_LOGE("%{public}s: write buffer failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + ret = CodecCallbackTypeProxyCall(self, CMD_EMPTY_BUFFER_DONE, data, reply); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ret); + ReleaseSbuf(data, reply); + return ret; + } + + ReleaseSbuf(data, reply); + return ret; +} + +static int32_t CodecCallbackTypeProxyFillBufferDone(struct CodecCallbackType *self, + int8_t* appData, uint32_t appDataLen, struct OmxCodecBuffer* buffer) +{ + int32_t ret; + + struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); + struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); + if (data == NULL || reply == NULL) { + HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_MALLOC_FAIL; + } + + if (!HdfSbufWriteUint32(data, appDataLen)) { + HDF_LOGE("%{public}s: write appData failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + for (uint32_t i = 0; i < appDataLen; i++) { + if (!HdfSbufWriteInt8(data, appData[i])) { + HDF_LOGE("%{public}s: write appData[i] failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + } + + if (!OmxCodecBufferBlockMarshalling(data, buffer)) { + HDF_LOGE("%{public}s: write buffer failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + ret = CodecCallbackTypeProxyCall(self, CMD_FILL_BUFFER_DONE, data, reply); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ret); + ReleaseSbuf(data, reply); + return ret; + } + + ReleaseSbuf(data, reply); + return ret; +} + +static void CodecCallbackTypeProxyConstruct(struct CodecCallbackType *instance) +{ + instance->EventHandler = CodecCallbackTypeProxyEventHandler; + instance->EmptyBufferDone = CodecCallbackTypeProxyEmptyBufferDone; + instance->FillBufferDone = CodecCallbackTypeProxyFillBufferDone; +} + +struct CodecCallbackType *CodecCallbackTypeGet(struct HdfRemoteService *remote) +{ + struct CodecCallbackType *instance = (struct CodecCallbackType*)OsalMemAlloc(sizeof(struct CodecCallbackType)); + if (instance == NULL) { + HDF_LOGE("%{public}s: OsalMemAlloc failed!", __func__); + return NULL; + } + + instance->remote = remote; + CodecCallbackTypeProxyConstruct(instance); + return instance; +} + +void CodecCallbackTypeRelease(struct CodecCallbackType *instance) +{ + if (instance == NULL) { + return; + } + OsalMemFree(instance); +} diff --git a/codec/hal/src/codec_callback_type_service.c b/codec/hal/src/codec_callback_type_service.c new file mode 100644 index 0000000000..4efa283f30 --- /dev/null +++ b/codec/hal/src/codec_callback_type_service.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2022 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_callback_type_service.h" +#include +#include + +#define HDF_LOG_TAG codec_hdi_cb_server + +int32_t CodecCallbackTypeEventHandler(struct CodecCallbackType *self, int8_t *appData, uint32_t appDataLen, + enum OMX_EVENTTYPE eEvent, uint32_t data1, uint32_t data2, int8_t *eventData, uint32_t eventDataLen) +{ + HDF_LOGI("%{public}s, callback service impl", __func__); + return HDF_SUCCESS; +} + +int32_t CodecCallbackTypeEmptyBufferDone(struct CodecCallbackType *self, + int8_t *appData, uint32_t appDataLen, const struct OmxCodecBuffer *buffer) +{ + HDF_LOGI("%{public}s, callback service impl", __func__); + return HDF_SUCCESS; +} + +int32_t CodecCallbackTypeFillBufferDone(struct CodecCallbackType *self, + int8_t* appData, uint32_t appDataLen, struct OmxCodecBuffer *buffer) +{ + HDF_LOGI("%{public}s, callback service impl", __func__); + return HDF_SUCCESS; +} + +void CodecCallbackTypeServiceConstruct(struct CodecCallbackType *instance) +{ + instance->EventHandler = CodecCallbackTypeEventHandler; + instance->EmptyBufferDone = CodecCallbackTypeEmptyBufferDone; + instance->FillBufferDone = CodecCallbackTypeFillBufferDone; +} diff --git a/codec/hal/src/codec_callback_type_stub.c b/codec/hal/src/codec_callback_type_stub.c new file mode 100644 index 0000000000..55858f66de --- /dev/null +++ b/codec/hal/src/codec_callback_type_stub.c @@ -0,0 +1,306 @@ +/* + * Copyright (c) 2022 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_callback_type_stub.h" +#include +#include +#include +#include +#include +#include +#include +#include "codec_callback_type_service.h" +#include "codec_internal.h" +#include "codec_types.h" + +#define HDF_LOG_TAG codec_hdi_cb_server + +#ifdef __ARM64__ +#define DRIVER_PATH "/vendor/lib64" +#else +#define DRIVER_PATH "/vendor/lib" +#endif +#define OMX_CALLBACK_IMPLEMENT "libcodec_hdi_omx_callback_type_service_impl" + +typedef void (*SERVICE_CONSTRUCT_FUNC)(struct CodecCallbackType *); + +struct CodecCallbackTypeStub { + struct CodecCallbackType service; + struct HdfRemoteDispatcher dispatcher; + void *dlHandler; +}; + +static void FreeMem(int8_t *mem, uint32_t memLen) +{ + if (memLen > 0 && mem != NULL) { + OsalMemFree(mem); + } +} + +static int32_t ReadArray(struct HdfSBuf *data, int8_t **array, uint32_t *arrayLen) +{ + int8_t *buffer = NULL; + uint32_t bufferLen = 0; + if (!HdfSbufReadUint32(data, &bufferLen)) { + HDF_LOGE("%{public}s: read buffer size failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (bufferLen > 0) { + buffer = (int8_t*)OsalMemCalloc(sizeof(int8_t) * bufferLen); + if (buffer == NULL) { + return HDF_ERR_MALLOC_FAIL; + } + + for (uint32_t i = 0; i < bufferLen; i++) { + if (!HdfSbufReadInt8(data, &buffer[i])) { + HDF_LOGE("%{public}s: read &buffer[i] failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + } + } + + *array = buffer; + *arrayLen = bufferLen; + return HDF_SUCCESS; +} + +static int32_t SerStubEventHandler(struct CodecCallbackType *serviceImpl, + struct HdfSBuf *data, struct HdfSBuf *reply) +{ + int32_t ret; + int8_t *appData = NULL; + uint32_t appDataLen = 0; + enum OMX_EVENTTYPE eEvent; + uint32_t data1 = 0; + uint32_t data2 = 0; + int8_t *eventData = NULL; + uint32_t eventDataLen = 0; + + ret = ReadArray(data, &appData, &appDataLen); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: read appData failed!", __func__); + FreeMem(appData, appDataLen); + return ret; + } + + if (!HdfSbufReadUint32(data, (uint32_t*)&eEvent)) { + HDF_LOGE("%{public}s: read &eEvent failed!", __func__); + FreeMem(appData, appDataLen); + return HDF_ERR_INVALID_PARAM; + } + + if (!HdfSbufReadUint32(data, &data1)) { + HDF_LOGE("%{public}s: read &data1 failed!", __func__); + FreeMem(appData, appDataLen); + return HDF_ERR_INVALID_PARAM; + } + + if (!HdfSbufReadUint32(data, &data2)) { + HDF_LOGE("%{public}s: read &data2 failed!", __func__); + FreeMem(appData, appDataLen); + return HDF_ERR_INVALID_PARAM; + } + + ret = ReadArray(data, &eventData, &eventDataLen); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: read eventData failed!", __func__); + FreeMem(appData, appDataLen); + FreeMem(eventData, eventDataLen); + return ret; + } + + ret = serviceImpl->EventHandler(serviceImpl, appData, appDataLen, eEvent, data1, data2, eventData, eventDataLen); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call EventHandler function failed!", __func__); + FreeMem(appData, appDataLen); + FreeMem(eventData, eventDataLen); + return ret; + } + + FreeMem(appData, appDataLen); + FreeMem(eventData, eventDataLen); + return ret; +} + +static int32_t SerStubEmptyBufferDone(struct CodecCallbackType *serviceImpl, + struct HdfSBuf *data, struct HdfSBuf *reply) +{ + int32_t ret; + int8_t *appData = NULL; + uint32_t appDataLen = 0; + struct OmxCodecBuffer buffer; + + if (!HdfSbufReadUint32(data, &appDataLen)) { + HDF_LOGE("%{public}s: read appData size failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (appDataLen > 0) { + appData = (int8_t*)OsalMemCalloc(sizeof(int8_t) * (appDataLen)); + if (appData == NULL) { + return HDF_ERR_MALLOC_FAIL; + } + + for (uint32_t i = 0; i < appDataLen; i++) { + if (!HdfSbufReadInt8(data, &appData[i])) { + HDF_LOGE("%{public}s: read &appData[i] failed!", __func__); + FreeMem(appData, appDataLen); + return HDF_ERR_INVALID_PARAM; + } + } + } + + if (!OmxCodecBufferBlockUnmarshalling(data, &buffer)) { + HDF_LOGE("%{public}s: read buffer failed!", __func__); + FreeMem(appData, appDataLen); + return HDF_ERR_INVALID_PARAM; + } + + ret = serviceImpl->EmptyBufferDone(serviceImpl, appData, appDataLen, &buffer); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call EmptyBufferDone function failed!", __func__); + FreeMem(appData, appDataLen); + return ret; + } + + FreeMem(appData, appDataLen); + return ret; +} + +static int32_t SerStubFillBufferDone(struct CodecCallbackType *serviceImpl, + struct HdfSBuf *data, struct HdfSBuf *reply) +{ + int32_t ret; + int8_t *appData = NULL; + uint32_t appDataLen = 0; + struct OmxCodecBuffer buffer; + + if (!HdfSbufReadUint32(data, &appDataLen)) { + HDF_LOGE("%{public}s: read appData size failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (appDataLen > 0) { + appData = (int8_t*)OsalMemCalloc(sizeof(int8_t) * (appDataLen)); + if (appData == NULL) { + return HDF_ERR_MALLOC_FAIL; + } + + for (uint32_t i = 0; i < appDataLen; i++) { + if (!HdfSbufReadInt8(data, &appData[i])) { + HDF_LOGE("%{public}s: read &appData[i] failed!", __func__); + FreeMem(appData, appDataLen); + return HDF_ERR_INVALID_PARAM; + } + } + } + + if (!OmxCodecBufferBlockUnmarshalling(data, &buffer)) { + HDF_LOGE("%{public}s: read buffer failed!", __func__); + FreeMem(appData, appDataLen); + return HDF_ERR_INVALID_PARAM; + } + + ret = serviceImpl->FillBufferDone(serviceImpl, appData, appDataLen, &buffer); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call FillBufferDone function failed!", __func__); + FreeMem(appData, appDataLen); + return ret; + } + + FreeMem(appData, appDataLen); + return ret; +} + +int32_t CodecCallbackTypeServiceOnRemoteRequest(struct HdfRemoteService *service, int32_t code, + struct HdfSBuf *data, struct HdfSBuf *reply) +{ + struct CodecCallbackType *serviceImpl = (struct CodecCallbackType*)service; + switch (code) { + case CMD_EVENT_HANDLER: + return SerStubEventHandler(serviceImpl, data, reply); + case CMD_EMPTY_BUFFER_DONE: + return SerStubEmptyBufferDone(serviceImpl, data, reply); + case CMD_FILL_BUFFER_DONE: + return SerStubFillBufferDone(serviceImpl, data, reply); + default: { + HDF_LOGE("%{public}s: not support cmd %{public}d", __func__, code); + return HDF_ERR_INVALID_PARAM; + } + } +} + +static void *LoadServiceHandler(void) +{ + char *libPath = NULL; + void *handler = NULL; + + libPath = HDF_LIBRARY_FULL_PATH(OMX_CALLBACK_IMPLEMENT); + handler = dlopen(libPath, RTLD_LAZY); + if (handler == NULL) { + HDF_LOGE("%{public}s: dlopen failed %{public}s", __func__, dlerror()); + return NULL; + } + + return handler; +} + +struct CodecCallbackType *CodecCallbackTypeStubGetInstance(void) +{ + SERVICE_CONSTRUCT_FUNC serviceConstructFunc = NULL; + struct CodecCallbackTypeStub *stub + = (struct CodecCallbackTypeStub *)OsalMemAlloc(sizeof(struct CodecCallbackTypeStub)); + if (stub == NULL) { + HDF_LOGE("%{public}s: OsalMemAlloc obj failed!", __func__); + return NULL; + } + + stub->dispatcher.Dispatch = CodecCallbackTypeServiceOnRemoteRequest; + stub->service.remote = HdfRemoteServiceObtain((struct HdfObject*)stub, &(stub->dispatcher)); + if (stub->service.remote == NULL) { + HDF_LOGE("%{public}s: stub->service.remote is null", __func__); + OsalMemFree(stub); + return NULL; + } + + stub->dlHandler = LoadServiceHandler(); + if (stub->dlHandler == NULL) { + HDF_LOGE("%{public}s: stub->dlHanlder is null", __func__); + OsalMemFree(stub); + return NULL; + } + + serviceConstructFunc = (SERVICE_CONSTRUCT_FUNC)dlsym(stub->dlHandler, "CodecCallbackTypeServiceConstruct"); + if (serviceConstructFunc == NULL) { + HDF_LOGE("%{public}s: dlsym failed %{public}s", __func__, dlerror()); + dlclose(stub->dlHandler); + OsalMemFree(stub); + return NULL; + } + + serviceConstructFunc(&stub->service); + return &stub->service; +} + +void CodecCallbackTypeStubRelease(struct CodecCallbackType *instance) +{ + if (instance == NULL) { + return; + } + struct CodecCallbackTypeStub *stub = CONTAINER_OF(instance, struct CodecCallbackTypeStub, service); + dlclose(stub->dlHandler); + OsalMemFree(stub); +} \ No newline at end of file diff --git a/codec/hal/src/codec_component_capability_config.c b/codec/hal/src/codec_component_capability_config.c new file mode 100644 index 0000000000..5471cff8aa --- /dev/null +++ b/codec/hal/src/codec_component_capability_config.c @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2022 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_component_capability_config.h" +#include +#include "codec_config_parser.h" +#include "codec_types.h" + +#define HDF_LOG_TAG codec_hdi_server + +static CodecCapablites g_codecCapabilites = {0}; +static const struct DeviceResourceNode *g_resourceNode = NULL; + +static int32_t AllCapabilityMarshalling(struct HdfSBuf *reply) +{ + int32_t groupIndex; + int32_t capIndex; + CodecCapablityGroup *group = NULL; + CodecCompCapability *cap = NULL; + CodecCapablityGroup *codeCapGroups[] = { + &(g_codecCapabilites.videoHwEncoderGroup), &(g_codecCapabilites.videoHwDecoderGroup), + &(g_codecCapabilites.audioHwEncoderGroup), &(g_codecCapabilites.audioHwDecoderGroup), + &(g_codecCapabilites.videoSwEncoderGroup), &(g_codecCapabilites.videoSwDecoderGroup), + &(g_codecCapabilites.audioSwEncoderGroup), &(g_codecCapabilites.audioSwDecoderGroup) + }; + + for (groupIndex = 0; groupIndex < CODEC_CAPABLITY_GROUP_NUM; groupIndex++) { + group = codeCapGroups[groupIndex]; + for (capIndex = 0; capIndex < group->num; capIndex++) { + cap = &group->capablitis[capIndex]; + if (!CodecCompCapabilityBlockMarshalling(reply, cap)) { + HDF_LOGE("%{public}s: write capbility to sbuf failed!", __func__); + return HDF_FAILURE; + } + } + } + + return HDF_SUCCESS; +} + +int32_t InitDataNode(const struct DeviceResourceNode *node) +{ + if (node == NULL) { + HDF_LOGE("%{public}s: data node is null!", __func__); + return HDF_FAILURE; + } + g_resourceNode = node; + return HDF_SUCCESS; +} + +int32_t ClearCapabilityData() +{ + return ClearCapabilityGroup(&g_codecCapabilites); +} + +int32_t LoadCapabilityData() +{ + return LoadCodecCapabilityFromHcs(g_resourceNode, &g_codecCapabilites); +} + +int32_t HandleGetNumCmd(struct HdfSBuf *reply) +{ + if (!g_codecCapabilites.inited) { + HDF_LOGE("%{public}s: g_codecCapabilites not init!", __func__); + return HDF_FAILURE; + } + + if (!HdfSbufWriteInt32(reply, g_codecCapabilites.total)) { + HDF_LOGE("%{public}s: write num failed!", __func__); + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} + +int32_t HandleGetAllCapablityListCmd(struct HdfSBuf *reply) +{ + if (!g_codecCapabilites.inited) { + HDF_LOGE("%{public}s: g_codecCapabilites not init!", __func__); + return HDF_FAILURE; + } + + if (AllCapabilityMarshalling(reply) != HDF_SUCCESS) { + HDF_LOGE("%{public}s: write all capbility to sbuf failed!", __func__); + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} diff --git a/codec/hal/src/codec_component_manager_proxy.c b/codec/hal/src/codec_component_manager_proxy.c new file mode 100644 index 0000000000..098d23de9f --- /dev/null +++ b/codec/hal/src/codec_component_manager_proxy.c @@ -0,0 +1,231 @@ +/* + * Copyright (c) 2022 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 +#include "codec_component_manager.h" +#include "codec_internal.h" +#include "codec_types.h" + +#define HDF_LOG_TAG codec_hdi_client + +struct CodecComponentManagerProxy { + struct CodecComponentManager instance; + struct HdfRemoteService *remoteOmx; +}; + +static struct CodecComponentManagerProxy g_codecComponentManagerProxy = {0}; + +static void ReleaseSbuf(struct HdfSBuf *data, struct HdfSBuf *reply) +{ + if (data != NULL) { + HdfSbufRecycle(data); + } + if (reply != NULL) { + HdfSbufRecycle(reply); + } +} + +static int32_t GetComponentNum() +{ + int32_t num = 0; + 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 (g_codecComponentManagerProxy.remoteOmx->dispatcher->Dispatch(g_codecComponentManagerProxy.remoteOmx, + CMD_CODEC_GET_COMPONENT_NUM, data, reply) != HDF_SUCCESS) { + HDF_LOGE("%{public}s: dispatch request failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_FAILURE; + } + + if (!HdfSbufReadInt32(reply, &num)) { + HDF_LOGE("%{public}s: read dataBlock->role failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_FAILURE; + } + + ReleaseSbuf(data, reply); + return num; +} + +static int32_t GetComponentCapabilityList(CodecCompCapability *capList, int32_t count) +{ + 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 (g_codecComponentManagerProxy.remoteOmx->dispatcher->Dispatch(g_codecComponentManagerProxy.remoteOmx, + CMD_CODEC_GET_COMPONENT_CAPABILITY_LIST, data, reply) != HDF_SUCCESS) { + HDF_LOGE("%{public}s: dispatch request failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_FAILURE; + } + + if (count <= 0) { + ReleaseSbuf(data, reply); + return HDF_FAILURE; + } + + for (int32_t i = 0; i < count; i++) { + if (!CodecCompCapabilityBlockUnmarshalling(reply, &(capList)[i])) { + HDF_LOGE("%{public}s: read capbility %{public}d from sbuf failed!", __func__, i); + ReleaseSbuf(data, reply); + return HDF_FAILURE; + } + } + + ReleaseSbuf(data, reply); + return HDF_SUCCESS; +} + +static int32_t CreateComponent(struct CodecComponentType **component, char *compName, void *appData, + int32_t appDataSize, struct CodecCallbackType *callback) +{ + int32_t ret; + + struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); + struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); + if (data == NULL || reply == NULL) { + HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_MALLOC_FAIL; + } + + if (!HdfSbufWriteString(data, compName)) { + HDF_LOGE("%{public}s: write paramName failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + int8_t *priAppData = (int8_t*)appData; + if (!HdfSbufWriteInt32(data, appDataSize)) { + HDF_LOGE("%{public}s: write appDataSize failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + for (int32_t i = 0; i < appDataSize; i++) { + if (!HdfSbufWriteInt8(data, priAppData[i])) { + HDF_LOGE("%{public}s: write priAppData[%{public}d] failed!", __func__, i); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + } + + if (HdfSbufWriteRemoteService(data, callback->remote) != 0) { + HDF_LOGE("%{public}s: write callback failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + ret = g_codecComponentManagerProxy.remoteOmx->dispatcher->Dispatch(g_codecComponentManagerProxy.remoteOmx, + CMD_CREATE_COMPONENT, data, reply); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ret); + ReleaseSbuf(data, reply); + return ret; + } + *component = CodecComponentTypeGet(g_codecComponentManagerProxy.remoteOmx); + + ReleaseSbuf(data, reply); + return ret; +} + +static int32_t DestoryComponent(struct CodecComponentType *component) +{ + int32_t ret; + + struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); + struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); + if (data == NULL || reply == NULL) { + HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_MALLOC_FAIL; + } + + ret = g_codecComponentManagerProxy.remoteOmx->dispatcher->Dispatch(g_codecComponentManagerProxy.remoteOmx, + CMD_DESTROY_COMPONENT, data, reply); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ret); + ReleaseSbuf(data, reply); + return ret; + } + CodecComponentTypeRelease(component); + + ReleaseSbuf(data, reply); + return ret; +} + +static int32_t InitCodecComponentManagerProxy(void) +{ + if (g_codecComponentManagerProxy.remoteOmx != NULL) { + return HDF_SUCCESS; + } + + struct HDIServiceManager *serviceMgr = HDIServiceManagerGet(); + if (serviceMgr == NULL) { + HDF_LOGE("%{public}s: HDIServiceManager not found!", __func__); + return HDF_FAILURE; + } + + struct HdfRemoteService *remoteOmx = serviceMgr->GetService(serviceMgr, CODEC_HDI_OMX_SERVICE_NAME); + HDIServiceManagerRelease(serviceMgr); + if (remoteOmx == NULL) { + HDF_LOGE("%{public}s: CodecComponentTypeService not found!", __func__); + return HDF_FAILURE; + } + + // remoteConfig + g_codecComponentManagerProxy.remoteOmx = remoteOmx; + g_codecComponentManagerProxy.instance.GetComponentNum = GetComponentNum; + g_codecComponentManagerProxy.instance.GetComponentCapabilityList = GetComponentCapabilityList; + g_codecComponentManagerProxy.instance.CreateComponent = CreateComponent; + g_codecComponentManagerProxy.instance.DestoryComponent = DestoryComponent; + + return HDF_SUCCESS; +} + +struct CodecComponentManager *GetCodecComponentManager(void) +{ + if (InitCodecComponentManagerProxy() != HDF_SUCCESS) { + return NULL; + } + return &g_codecComponentManagerProxy.instance; +} + +void CodecComponentManagerRelease(void) +{ + if (g_codecComponentManagerProxy.remoteOmx != NULL) { + HdfRemoteServiceRecycle(g_codecComponentManagerProxy.remoteOmx); + } +} \ No newline at end of file diff --git a/codec/hal/src/codec_component_type_driver.c b/codec/hal/src/codec_component_type_driver.c new file mode 100644 index 0000000000..58708ff6dd --- /dev/null +++ b/codec/hal/src/codec_component_type_driver.c @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2022 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 +#include "codec_component_type_stub.h" +#include "codec_component_capability_config.h" + +#define HDF_LOG_TAG codec_hdi_server + +struct HdfCodecComponentTypeHost { + struct IDeviceIoService ioservice; + struct CodecComponentTypeStub *instance; +}; + +static int32_t CodecComponentTypeDriverDispatch(struct HdfDeviceIoClient *client, int32_t cmdId, + struct HdfSBuf *data, struct HdfSBuf *reply) +{ + struct HdfCodecComponentTypeHost *omxcomponenttypeHost = CONTAINER_OF( + client->device->service, struct HdfCodecComponentTypeHost, ioservice); + return CodecComponentTypeServiceOnRemoteRequest(omxcomponenttypeHost->instance, cmdId, data, reply); +} + +int32_t HdfCodecComponentTypeDriverInit(struct HdfDeviceObject *deviceObject) +{ + HDF_LOGI("HdfCodecComponentTypeDriverInit enter."); + if (deviceObject == NULL) { + return HDF_FAILURE; + } + InitDataNode(deviceObject->property); + if (LoadCapabilityData() != HDF_SUCCESS) { + ClearCapabilityData(); + } + return HDF_SUCCESS; +} + +int32_t HdfCodecComponentTypeDriverBind(struct HdfDeviceObject *deviceObject) +{ + HDF_LOGI("HdfCodecComponentTypeDriverBind enter."); + + struct HdfCodecComponentTypeHost *omxcomponenttypeHost = (struct HdfCodecComponentTypeHost *)OsalMemAlloc( + sizeof(struct HdfCodecComponentTypeHost)); + if (omxcomponenttypeHost == NULL) { + HDF_LOGE("HdfCodecComponentTypeDriverBind OsalMemAlloc HdfCodecComponentTypeHost failed!"); + return HDF_FAILURE; + } + + omxcomponenttypeHost->ioservice.Dispatch = CodecComponentTypeDriverDispatch; + omxcomponenttypeHost->ioservice.Open = NULL; + omxcomponenttypeHost->ioservice.Release = NULL; + omxcomponenttypeHost->instance = CodecComponentTypeStubGetInstance(); + if (omxcomponenttypeHost->instance == NULL) { + OsalMemFree(omxcomponenttypeHost); + return HDF_FAILURE; + } + + deviceObject->service = &omxcomponenttypeHost->ioservice; + return HDF_SUCCESS; +} + +void HdfCodecComponentTypeDriverRelease(struct HdfDeviceObject *deviceObject) +{ + HDF_LOGI("HdfCodecComponentTypeDriverRelease enter."); + struct HdfCodecComponentTypeHost *omxcomponenttypeHost + = CONTAINER_OF(deviceObject->service, struct HdfCodecComponentTypeHost, ioservice); + CodecComponentTypeStubRelease(omxcomponenttypeHost->instance); + OsalMemFree(omxcomponenttypeHost); + ClearCapabilityData(); +} + +struct HdfDriverEntry g_omxcomponenttypeDriverEntry = { + .moduleVersion = 1, + .moduleName = "codec_hdi_omx_server", + .Bind = HdfCodecComponentTypeDriverBind, + .Init = HdfCodecComponentTypeDriverInit, + .Release = HdfCodecComponentTypeDriverRelease, +}; + +HDF_INIT(g_omxcomponenttypeDriverEntry); \ No newline at end of file diff --git a/codec/hal/src/codec_component_type_proxy.c b/codec/hal/src/codec_component_type_proxy.c new file mode 100644 index 0000000000..8eca6deca9 --- /dev/null +++ b/codec/hal/src/codec_component_type_proxy.c @@ -0,0 +1,886 @@ +/* + * Copyright (c) 2022 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 +#include +#include +#include "codec_component_if.h" +#include "codec_internal.h" +#include "codec_types.h" + +#define HDF_LOG_TAG codec_hdi_client + +struct CodecComponentTypeProxy { + struct CodecComponentType instance; + struct HdfRemoteService *remote; +}; + +static void ReleaseSbuf(struct HdfSBuf *data, struct HdfSBuf *reply) +{ + if (data != NULL) { + HdfSbufRecycle(data); + } + if (reply != NULL) { + HdfSbufRecycle(reply); + } +} + +static int32_t CodecComponentTypeProxyCall(struct CodecComponentType *self, int32_t id, struct HdfSBuf *data, + struct HdfSBuf *reply) +{ + struct CodecComponentTypeProxy *proxy = CONTAINER_OF(self, struct CodecComponentTypeProxy, instance); + if (proxy->remote == NULL || + proxy->remote->dispatcher == NULL || + proxy->remote->dispatcher->Dispatch == NULL) { + HDF_LOGE("%{public}s: obj is null", __func__); + return HDF_ERR_INVALID_OBJECT; + } + return proxy->remote->dispatcher->Dispatch(proxy->remote, id, data, reply); +} + +static int32_t ReadValuesForGetComponentVersion(struct HdfSBuf *reply, char *compName, + union OMX_VERSIONTYPE *compVersion, union OMX_VERSIONTYPE *specVersion, uint8_t *compUUID) +{ + int32_t ret; + + const char *componentNameCopy = HdfSbufReadString(reply); + if (componentNameCopy == NULL) { + HDF_LOGE("%{public}s: read componentNameCopy failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + ret = strcpy_s(compName, OMX_MAX_STRINGNAME_SIZE, componentNameCopy); + if (ret != EOK) { + HDF_LOGE("%{public}s: strcpy_s compName failed, error code: %{public}d", __func__, ret); + return HDF_FAILURE; + } + + const union OMX_VERSIONTYPE *componentVersionCp + = (union OMX_VERSIONTYPE *)HdfSbufReadUnpadBuffer(reply, sizeof(union OMX_VERSIONTYPE)); + if (componentVersionCp == NULL) { + HDF_LOGE("%{public}s: read componentVersionCp failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + ret = memcpy_s(compVersion, sizeof(union OMX_VERSIONTYPE), componentVersionCp, sizeof(union OMX_VERSIONTYPE)); + if (ret != EOK) { + HDF_LOGE("%{public}s: memcpy_s compVersion failed, error code: %{public}d", __func__, ret); + return HDF_FAILURE; + } + + const union OMX_VERSIONTYPE *specVersionCp + = (union OMX_VERSIONTYPE *)HdfSbufReadUnpadBuffer(reply, sizeof(union OMX_VERSIONTYPE)); + if (specVersionCp == NULL) { + HDF_LOGE("%{public}s: read specVersionCp failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + ret = memcpy_s(specVersion, sizeof(union OMX_VERSIONTYPE), specVersionCp, sizeof(union OMX_VERSIONTYPE)); + if (ret != EOK) { + HDF_LOGE("%{public}s: memcpy_s specVersion failed, error code: %{public}d", __func__, ret); + return HDF_FAILURE; + } + + uint32_t compUUIDLen = sizeof(OMX_UUIDTYPE); + for (uint32_t i = 0; i < compUUIDLen; i++) { + if (!HdfSbufReadUint8(reply, &compUUID[i])) { + HDF_LOGE("%{public}s: read compUUID[i] failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + } + + return HDF_SUCCESS; +} + +static int32_t CodecComponentTypeProxyGetComponentVersion(struct CodecComponentType *self, char *compName, + union OMX_VERSIONTYPE *compVersion, union OMX_VERSIONTYPE *specVersion, uint8_t *compUUID, uint32_t compUUIDLen) +{ + int32_t ret; + + struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); + struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); + if (data == NULL || reply == NULL) { + HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_MALLOC_FAIL; + } + + if (!HdfSbufWriteUint32(data, compUUIDLen)) { + HDF_LOGE("%{public}s: write compUUIDLen failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + ret = CodecComponentTypeProxyCall(self, CMD_GET_COMPONENT_VERSION, data, reply); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ret); + ReleaseSbuf(data, reply); + return ret; + } + + ret = ReadValuesForGetComponentVersion(reply, compName, compVersion, specVersion, compUUID); + ReleaseSbuf(data, reply); + return ret; +} + +static int32_t CodecComponentTypeProxySendCommand(struct CodecComponentType *self, + enum OMX_COMMANDTYPE cmd, uint32_t param, int8_t *cmdData, uint32_t cmdDataLen) +{ + int32_t ret; + + struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); + struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); + if (data == NULL || reply == NULL) { + HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_MALLOC_FAIL; + } + + if (!HdfSbufWriteUint32(data, (uint32_t)cmd)) { + HDF_LOGE("%{public}s: write cmd failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + if (!HdfSbufWriteUint32(data, param)) { + HDF_LOGE("%{public}s: write param failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + if (!HdfSbufWriteUint32(data, cmdDataLen)) { + HDF_LOGE("%{public}s: write cmdData failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + for (uint32_t i = 0; i < cmdDataLen; i++) { + if (!HdfSbufWriteInt8(data, cmdData[i])) { + HDF_LOGE("%{public}s: write cmdData[i] failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + } + + ret = CodecComponentTypeProxyCall(self, CMD_SEND_COMMAND, data, reply); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ret); + ReleaseSbuf(data, reply); + return ret; + } + + ReleaseSbuf(data, reply); + return ret; +} + +static int32_t CodecComponentTypeProxyGetParameter(struct CodecComponentType *self, + uint32_t paramIndex, int8_t *paramStruct, uint32_t paramStructLen) +{ + int32_t ret; + + struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); + struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); + if (data == NULL || reply == NULL) { + HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_MALLOC_FAIL; + } + + if (!HdfSbufWriteUint32(data, paramIndex)) { + HDF_LOGE("%{public}s: write paramIndex failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + if (!HdfSbufWriteUint32(data, paramStructLen)) { + HDF_LOGE("%{public}s: write paramStructLen failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + for (uint32_t i = 0; i < paramStructLen; i++) { + if (!HdfSbufWriteInt8(data, paramStruct[i])) { + HDF_LOGE("%{public}s: write paramStruct[i] failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + } + + ret = CodecComponentTypeProxyCall(self, CMD_GET_PARAMETER, data, reply); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ret); + ReleaseSbuf(data, reply); + return ret; + } + + for (uint32_t i = 0; i < paramStructLen; i++) { + if (!HdfSbufReadInt8(reply, ¶mStruct[i])) { + HDF_LOGE("%{public}s: read paramStruct[i] failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + } + + ReleaseSbuf(data, reply); + return ret; +} + +static int32_t CodecComponentTypeProxySetParameter(struct CodecComponentType *self, + uint32_t index, int8_t *paramStruct, uint32_t paramStructLen) +{ + int32_t ret; + + struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); + struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); + if (data == NULL || reply == NULL) { + HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_MALLOC_FAIL; + } + + if (!HdfSbufWriteUint32(data, index)) { + HDF_LOGE("%{public}s: write index failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + if (!HdfSbufWriteUint32(data, paramStructLen)) { + HDF_LOGE("%{public}s: write paramStruct failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + for (uint32_t i = 0; i < paramStructLen; i++) { + if (!HdfSbufWriteInt8(data, paramStruct[i])) { + HDF_LOGE("%{public}s: write paramStruct[i] failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + } + + ret = CodecComponentTypeProxyCall(self, CMD_SET_PARAMETER, data, reply); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ret); + ReleaseSbuf(data, reply); + return ret; + } + + ReleaseSbuf(data, reply); + return ret; +} + +static int32_t CodecComponentTypeProxyGetConfig(struct CodecComponentType *self, + uint32_t index, int8_t *cfgStruct, uint32_t cfgStructLen) +{ + int32_t ret; + + struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); + struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); + if (data == NULL || reply == NULL) { + HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_MALLOC_FAIL; + } + + if (!HdfSbufWriteUint32(data, index)) { + HDF_LOGE("%{public}s: write index failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + if (!HdfSbufWriteUint32(data, cfgStructLen)) { + HDF_LOGE("%{public}s: write cfgStructLen failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + for (uint32_t i = 0; i < cfgStructLen; i++) { + if (!HdfSbufWriteInt8(data, cfgStruct[i])) { + HDF_LOGE("%{public}s: write cfgStruct[i] failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + } + + ret = CodecComponentTypeProxyCall(self, CMD_GET_CONFIG, data, reply); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ret); + ReleaseSbuf(data, reply); + return ret; + } + + for (uint32_t i = 0; i < cfgStructLen; i++) { + if (!HdfSbufReadInt8(reply, &cfgStruct[i])) { + HDF_LOGE("%{public}s: read cfgStruct[i] failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + } + + ReleaseSbuf(data, reply); + return ret; +} + +static int32_t CodecComponentTypeProxySetConfig(struct CodecComponentType *self, + uint32_t index, int8_t *cfgStruct, uint32_t cfgStructLen) +{ + int32_t ret; + + struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); + struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); + if (data == NULL || reply == NULL) { + HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_MALLOC_FAIL; + } + + if (!HdfSbufWriteUint32(data, index)) { + HDF_LOGE("%{public}s: write index failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + if (!HdfSbufWriteUint32(data, cfgStructLen)) { + HDF_LOGE("%{public}s: write cfgStruct failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + for (uint32_t i = 0; i < cfgStructLen; i++) { + if (!HdfSbufWriteInt8(data, cfgStruct[i])) { + HDF_LOGE("%{public}s: write cfgStruct[i] failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + } + + ret = CodecComponentTypeProxyCall(self, CMD_SET_CONFIG, data, reply); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ret); + ReleaseSbuf(data, reply); + return ret; + } + + ReleaseSbuf(data, reply); + return ret; +} + +static int32_t CodecComponentTypeProxyGetExtensionIndex(struct CodecComponentType *self, + const char *paramName, uint32_t *indexType) +{ + int32_t ret; + + struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); + struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); + if (data == NULL || reply == NULL) { + HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_MALLOC_FAIL; + } + + if (!HdfSbufWriteString(data, paramName)) { + HDF_LOGE("%{public}s: write paramName failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + ret = CodecComponentTypeProxyCall(self, CMD_GET_EXTENSION_INDEX, data, reply); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ret); + ReleaseSbuf(data, reply); + return ret; + } + + if (!HdfSbufReadUint32(reply, indexType)) { + HDF_LOGE("%{public}s: read indexType failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + ReleaseSbuf(data, reply); + return ret; +} + +static int32_t CodecComponentTypeProxyGetState(struct CodecComponentType *self, + enum OMX_STATETYPE *state) +{ + int32_t ret; + + struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); + struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); + if (data == NULL || reply == NULL) { + HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_MALLOC_FAIL; + } + + ret = CodecComponentTypeProxyCall(self, CMD_GET_STATE, data, reply); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ret); + ReleaseSbuf(data, reply); + return ret; + } + + if (!HdfSbufReadUint32(reply, (uint32_t*)state)) { + HDF_LOGE("%{public}s: read state failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + ReleaseSbuf(data, reply); + return ret; +} + +static int32_t CodecComponentTypeProxyComponentTunnelRequest(struct CodecComponentType *self, + uint32_t port, int32_t tunneledComp, uint32_t tunneledPort, struct OMX_TUNNELSETUPTYPE *tunnelSetup) +{ + int32_t ret; + + struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); + struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); + if (data == NULL || reply == NULL) { + HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_MALLOC_FAIL; + } + + if (!HdfSbufWriteUint32(data, port)) { + HDF_LOGE("%{public}s: write port failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + if (!HdfSbufWriteInt32(data, tunneledComp)) { + HDF_LOGE("%{public}s: write tunneledComp failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + if (!HdfSbufWriteUint32(data, tunneledPort)) { + HDF_LOGE("%{public}s: write tunneledPort failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + if (!OMX_TUNNELSETUPTYPEBlockMarshalling(data, tunnelSetup)) { + HDF_LOGE("%{public}s: write tunnelSetup failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + ret = CodecComponentTypeProxyCall(self, CMD_COMPONENT_TUNNEL_REQUEST, data, reply); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ret); + ReleaseSbuf(data, reply); + return ret; + } + + if (!OMX_TUNNELSETUPTYPEBlockUnmarshalling(reply, tunnelSetup)) { + HDF_LOGE("%{public}s: read tunnelSetup failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + ReleaseSbuf(data, reply); + return ret; +} + +static int32_t CodecComponentTypeProxyUseBuffer(struct CodecComponentType *self, + uint32_t portIndex, struct OmxCodecBuffer *buffer) +{ + int32_t ret; + + struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); + struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); + if (data == NULL || reply == NULL) { + HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_MALLOC_FAIL; + } + + if (!HdfSbufWriteUint32(data, portIndex)) { + HDF_LOGE("%{public}s: write portIndex failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + if (!OmxCodecBufferBlockMarshalling(data, buffer)) { + HDF_LOGE("%{public}s: write buffer failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + ret = CodecComponentTypeProxyCall(self, CMD_USE_BUFFER, data, reply); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ret); + ReleaseSbuf(data, reply); + return ret; + } + + if (!OmxCodecBufferBlockUnmarshalling(reply, buffer)) { + HDF_LOGE("%{public}s: read buffer failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + ReleaseSbuf(data, reply); + return ret; +} + +static int32_t CodecComponentTypeProxyAllocateBuffer(struct CodecComponentType *self, + struct OmxCodecBuffer *buffer, uint32_t portIndex) +{ + int32_t ret; + + struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); + struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); + if (data == NULL || reply == NULL) { + HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_MALLOC_FAIL; + } + + if (!OmxCodecBufferBlockMarshalling(data, buffer)) { + HDF_LOGE("%{public}s: write buffer failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + if (!HdfSbufWriteUint32(data, portIndex)) { + HDF_LOGE("%{public}s: write portIndex failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + ret = CodecComponentTypeProxyCall(self, CMD_ALLOCATE_BUFFER, data, reply); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ret); + ReleaseSbuf(data, reply); + return ret; + } + + if (!OmxCodecBufferBlockUnmarshalling(reply, buffer)) { + HDF_LOGE("%{public}s: read buffer failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + ReleaseSbuf(data, reply); + return ret; +} + +static int32_t CodecComponentTypeProxyFreeBuffer(struct CodecComponentType *self, + uint32_t portIndex, const struct OmxCodecBuffer *buffer) +{ + int32_t ret; + + struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); + struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); + if (data == NULL || reply == NULL) { + HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_MALLOC_FAIL; + } + + if (!HdfSbufWriteUint32(data, portIndex)) { + HDF_LOGE("%{public}s: write portIndex failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + if (!OmxCodecBufferBlockMarshalling(data, buffer)) { + HDF_LOGE("%{public}s: write buffer failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + ret = CodecComponentTypeProxyCall(self, CMD_FREE_BUFFER, data, reply); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ret); + ReleaseSbuf(data, reply); + return ret; + } + + ReleaseSbuf(data, reply); + return ret; +} + +static int32_t CodecComponentTypeProxyEmptyThisBuffer(struct CodecComponentType *self, + const struct OmxCodecBuffer *buffer) +{ + int32_t ret; + + struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); + struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); + if (data == NULL || reply == NULL) { + HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_MALLOC_FAIL; + } + + if (!OmxCodecBufferBlockMarshalling(data, buffer)) { + HDF_LOGE("%{public}s: write buffer failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + ret = CodecComponentTypeProxyCall(self, CMD_EMPTY_THIS_BUFFER, data, reply); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ret); + ReleaseSbuf(data, reply); + return ret; + } + + ReleaseSbuf(data, reply); + return ret; +} + +static int32_t CodecComponentTypeProxyFillThisBuffer(struct CodecComponentType *self, + const struct OmxCodecBuffer *buffer) +{ + int32_t ret; + + struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); + struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); + if (data == NULL || reply == NULL) { + HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_MALLOC_FAIL; + } + + if (!OmxCodecBufferBlockMarshalling(data, buffer)) { + HDF_LOGE("%{public}s: write buffer failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + ret = CodecComponentTypeProxyCall(self, CMD_FILL_THIS_BUFFER, data, reply); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ret); + ReleaseSbuf(data, reply); + return ret; + } + + ReleaseSbuf(data, reply); + return ret; +} + +static int32_t CodecComponentTypeProxySetCallbacks(struct CodecComponentType *self, + struct CodecCallbackType *callback, int8_t *appData, uint32_t appDataLen) +{ + int32_t ret; + + struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); + struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); + if (data == NULL || reply == NULL) { + HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_MALLOC_FAIL; + } + + if (HdfSbufWriteRemoteService(data, callback->remote) != 0) { + HDF_LOGE("%{public}s: write callback failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + if (!HdfSbufWriteUint32(data, appDataLen)) { + HDF_LOGE("%{public}s: write appData failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + for (uint32_t i = 0; i < appDataLen; i++) { + if (!HdfSbufWriteInt8(data, appData[i])) { + HDF_LOGE("%{public}s: write appData[i] failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + } + + ret = CodecComponentTypeProxyCall(self, CMD_SET_CALLBACKS, data, reply); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ret); + ReleaseSbuf(data, reply); + return ret; + } + + ReleaseSbuf(data, reply); + return ret; +} + +static int32_t CodecComponentTypeProxyComponentDeInit(struct CodecComponentType *self) +{ + int32_t ret; + + struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); + struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); + if (data == NULL || reply == NULL) { + HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_MALLOC_FAIL; + } + + ret = CodecComponentTypeProxyCall(self, CMD_COMPONENT_DE_INIT, data, reply); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ret); + ReleaseSbuf(data, reply); + return ret; + } + + ReleaseSbuf(data, reply); + return ret; +} + +static int32_t CodecComponentTypeProxyUseEglImage(struct CodecComponentType *self, + struct OmxCodecBuffer *buffer, uint32_t portIndex, int8_t *eglImage, uint32_t eglImageLen) +{ + int32_t ret; + + struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); + struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); + if (data == NULL || reply == NULL) { + HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_MALLOC_FAIL; + } + + if (!OmxCodecBufferBlockMarshalling(data, buffer)) { + HDF_LOGE("%{public}s: write buffer failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + if (!HdfSbufWriteUint32(data, portIndex)) { + HDF_LOGE("%{public}s: write portIndex failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + if (!HdfSbufWriteUint32(data, eglImageLen)) { + HDF_LOGE("%{public}s: write eglImage failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + for (uint32_t i = 0; i < eglImageLen; i++) { + if (!HdfSbufWriteInt8(data, eglImage[i])) { + HDF_LOGE("%{public}s: write eglImage[i] failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + } + + ret = CodecComponentTypeProxyCall(self, CMD_USE_EGL_IMAGE, data, reply); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ret); + ReleaseSbuf(data, reply); + return ret; + } + + if (!OmxCodecBufferBlockUnmarshalling(reply, buffer)) { + HDF_LOGE("%{public}s: read buffer failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + ReleaseSbuf(data, reply); + return ret; +} + +static int32_t CodecComponentTypeProxyComponentRoleEnum(struct CodecComponentType *self, + uint8_t *role, uint32_t roleLen, uint32_t index) +{ + int32_t ret; + + struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); + struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC); + if (data == NULL || reply == NULL) { + HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_MALLOC_FAIL; + } + + if (!HdfSbufWriteUint32(data, roleLen)) { + HDF_LOGE("%{public}s: write roleLen failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + if (!HdfSbufWriteUint32(data, index)) { + HDF_LOGE("%{public}s: write index failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + + ret = CodecComponentTypeProxyCall(self, CMD_COMPONENT_ROLE_ENUM, data, reply); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ret); + ReleaseSbuf(data, reply); + return ret; + } + + for (uint32_t i = 0; i < roleLen; i++) { + if (!HdfSbufReadUint8(reply, &role[i])) { + HDF_LOGE("%{public}s: read role[i] failed!", __func__); + ReleaseSbuf(data, reply); + return HDF_ERR_INVALID_PARAM; + } + } + + ReleaseSbuf(data, reply); + return ret; +} + +static void CodecComponentTypeProxyConstruct(struct CodecComponentType *instance) +{ + instance->GetComponentVersion = CodecComponentTypeProxyGetComponentVersion; + instance->SendCommand = CodecComponentTypeProxySendCommand; + instance->GetParameter = CodecComponentTypeProxyGetParameter; + instance->SetParameter = CodecComponentTypeProxySetParameter; + instance->GetConfig = CodecComponentTypeProxyGetConfig; + instance->SetConfig = CodecComponentTypeProxySetConfig; + instance->GetExtensionIndex = CodecComponentTypeProxyGetExtensionIndex; + instance->GetState = CodecComponentTypeProxyGetState; + instance->ComponentTunnelRequest = CodecComponentTypeProxyComponentTunnelRequest; + instance->UseBuffer = CodecComponentTypeProxyUseBuffer; + instance->AllocateBuffer = CodecComponentTypeProxyAllocateBuffer; + instance->FreeBuffer = CodecComponentTypeProxyFreeBuffer; + instance->EmptyThisBuffer = CodecComponentTypeProxyEmptyThisBuffer; + instance->FillThisBuffer = CodecComponentTypeProxyFillThisBuffer; + instance->SetCallbacks = CodecComponentTypeProxySetCallbacks; + instance->ComponentDeInit = CodecComponentTypeProxyComponentDeInit; + instance->UseEglImage = CodecComponentTypeProxyUseEglImage; + instance->ComponentRoleEnum = CodecComponentTypeProxyComponentRoleEnum; +} + +struct CodecComponentType *CodecComponentTypeGet(struct HdfRemoteService *remote) +{ + struct CodecComponentTypeProxy *proxy + = (struct CodecComponentTypeProxy *)OsalMemAlloc(sizeof(struct CodecComponentTypeProxy)); + if (proxy == NULL) { + HDF_LOGE("%{public}s: malloc CodecComponentType proxy failed!", __func__); + HdfRemoteServiceRecycle(remote); + return NULL; + } + + proxy->remote = remote; + CodecComponentTypeProxyConstruct(&proxy->instance); + return &proxy->instance; +} + +void CodecComponentTypeRelease(struct CodecComponentType *instance) +{ + HDF_LOGE("%{public}s !", __func__); + if (instance == NULL) { + return; + } + struct CodecComponentTypeProxy *proxy = CONTAINER_OF(instance, struct CodecComponentTypeProxy, instance); + OsalMemFree(proxy); +} diff --git a/codec/hal/src/codec_component_type_service.c b/codec/hal/src/codec_component_type_service.c new file mode 100644 index 0000000000..894968e2eb --- /dev/null +++ b/codec/hal/src/codec_component_type_service.c @@ -0,0 +1,184 @@ +/* + * Copyright (c) 2022 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_component_type_service.h" +#include +#include + +#define HDF_LOG_TAG codec_hdi_server + +int32_t OmxManagerCreateComponent(OMX_HANDLETYPE *compHandle, char *compName, void *appData, int32_t appDataSize, + struct CodecCallbackType *callbacks) +{ + HDF_LOGI("%{public}s, service impl!", __func__); + return HDF_SUCCESS; +} + +int32_t OmxManagerDestroyComponent(OMX_HANDLETYPE compHandle) +{ + HDF_LOGI("%{public}s, service impl!", __func__); + return HDF_SUCCESS; +} + +int32_t CodecComponentTypeGetComponentVersion(struct CodecComponentType *self, + char* compName, union OMX_VERSIONTYPE *compVersion, union OMX_VERSIONTYPE *specVersion, + uint8_t *compUUID, uint32_t compUUIDLen) +{ + HDF_LOGI("%{public}s, service impl!", __func__); + return HDF_SUCCESS; +} + +int32_t CodecComponentTypeSendCommand(struct CodecComponentType *self, + enum OMX_COMMANDTYPE cmd, uint32_t param, int8_t *cmdData, uint32_t cmdDataLen) +{ + HDF_LOGI("%{public}s, service impl!", __func__); + return HDF_SUCCESS; +} + +int32_t CodecComponentTypeGetParameter(struct CodecComponentType *self, + uint32_t paramIndex, int8_t *paramStruct, uint32_t paramStructLen) +{ + HDF_LOGI("%{public}s, service impl!", __func__); + return HDF_SUCCESS; +} + +int32_t CodecComponentTypeSetParameter(struct CodecComponentType *self, + uint32_t index, int8_t *paramStruct, uint32_t paramStructLen) +{ + HDF_LOGI("%{public}s, service impl!", __func__); + return HDF_SUCCESS; +} + +int32_t CodecComponentTypeGetConfig(struct CodecComponentType *self, + uint32_t index, int8_t *cfgStruct, uint32_t cfgStructLen) +{ + HDF_LOGI("%{public}s, service impl!", __func__); + return HDF_SUCCESS; +} + +int32_t CodecComponentTypeSetConfig(struct CodecComponentType *self, + uint32_t index, int8_t *cfgStruct, uint32_t cfgStructLen) +{ + HDF_LOGI("%{public}s, service impl!", __func__); + return HDF_SUCCESS; +} + +int32_t CodecComponentTypeGetExtensionIndex(struct CodecComponentType *self, + const char *paramName, uint32_t *indexType) +{ + HDF_LOGI("%{public}s, service impl!", __func__); + return HDF_SUCCESS; +} + +int32_t CodecComponentTypeGetState(struct CodecComponentType *self, + enum OMX_STATETYPE *state) +{ + HDF_LOGI("%{public}s, service impl!", __func__); + return HDF_SUCCESS; +} + +int32_t CodecComponentTypeComponentTunnelRequest(struct CodecComponentType *self, + uint32_t port, int32_t tunneledComp, uint32_t tunneledPort, + struct OMX_TUNNELSETUPTYPE *tunnelSetup) +{ + HDF_LOGI("%{public}s, service impl!", __func__); + return HDF_SUCCESS; +} + +int32_t CodecComponentTypeUseBuffer(struct CodecComponentType *self, + uint32_t portIndex, struct OmxCodecBuffer *buffer) +{ + HDF_LOGI("%{public}s, service impl!", __func__); + return HDF_SUCCESS; +} + +int32_t CodecComponentTypeAllocateBuffer(struct CodecComponentType *self, + struct OmxCodecBuffer *buffer, uint32_t portIndex) +{ + HDF_LOGI("%{public}s, service impl!", __func__); + return HDF_SUCCESS; +} + +int32_t CodecComponentTypeFreeBuffer(struct CodecComponentType *self, uint32_t portIndex, + const struct OmxCodecBuffer *buffer) +{ + HDF_LOGI("%{public}s, service impl!", __func__); + return HDF_SUCCESS; +} + +int32_t CodecComponentTypeEmptyThisBuffer(struct CodecComponentType *self, + const struct OmxCodecBuffer *buffer) +{ + HDF_LOGI("%{public}s, service impl!", __func__); + return HDF_SUCCESS; +} + +int32_t CodecComponentTypeFillThisBuffer(struct CodecComponentType *self, + const struct OmxCodecBuffer *buffer) +{ + HDF_LOGI("%{public}s, service impl!", __func__); + return HDF_SUCCESS; +} + +int32_t CodecComponentTypeSetCallbacks(struct CodecComponentType *self, + struct CodecCallbackType* callback, int8_t *appData, uint32_t appDataLen) +{ + HDF_LOGI("%{public}s, service impl!", __func__); + return HDF_SUCCESS; +} + +int32_t CodecComponentTypeComponentDeInit(struct CodecComponentType *self) +{ + HDF_LOGI("%{public}s, service impl!", __func__); + return HDF_SUCCESS; +} + +int32_t CodecComponentTypeUseEglImage(struct CodecComponentType *self, + struct OmxCodecBuffer *buffer, uint32_t portIndex, int8_t *eglImage, uint32_t eglImageLen) +{ + HDF_LOGI("%{public}s, service impl!", __func__); + return HDF_SUCCESS; +} + +int32_t CodecComponentTypeComponentRoleEnum(struct CodecComponentType *self, + uint8_t *role, uint32_t roleLen, uint32_t index) +{ + HDF_LOGI("%{public}s, service impl!", __func__); + return HDF_SUCCESS; +} + +void CodecComponentTypeServiceConstruct(struct OmxComponentManager *manager, struct CodecComponentType *instance) +{ + manager->CreateComponent = OmxManagerCreateComponent; + manager->DestoryComponent = OmxManagerDestroyComponent; + instance->GetComponentVersion = CodecComponentTypeGetComponentVersion; + instance->SendCommand = CodecComponentTypeSendCommand; + instance->GetParameter = CodecComponentTypeGetParameter; + instance->SetParameter = CodecComponentTypeSetParameter; + instance->GetConfig = CodecComponentTypeGetConfig; + instance->SetConfig = CodecComponentTypeSetConfig; + instance->GetExtensionIndex = CodecComponentTypeGetExtensionIndex; + instance->GetState = CodecComponentTypeGetState; + instance->ComponentTunnelRequest = CodecComponentTypeComponentTunnelRequest; + instance->UseBuffer = CodecComponentTypeUseBuffer; + instance->AllocateBuffer = CodecComponentTypeAllocateBuffer; + instance->FreeBuffer = CodecComponentTypeFreeBuffer; + instance->EmptyThisBuffer = CodecComponentTypeEmptyThisBuffer; + instance->FillThisBuffer = CodecComponentTypeFillThisBuffer; + instance->SetCallbacks = CodecComponentTypeSetCallbacks; + instance->ComponentDeInit = CodecComponentTypeComponentDeInit; + instance->UseEglImage = CodecComponentTypeUseEglImage; + instance->ComponentRoleEnum = CodecComponentTypeComponentRoleEnum; +} \ No newline at end of file diff --git a/codec/hal/src/codec_component_type_stub.c b/codec/hal/src/codec_component_type_stub.c new file mode 100644 index 0000000000..9c4435bb09 --- /dev/null +++ b/codec/hal/src/codec_component_type_stub.c @@ -0,0 +1,971 @@ +/* + * Copyright (c) 2022 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_component_type_stub.h" +#include +#include +#include +#include +#include +#include "codec_callback_if.h" +#include "codec_component_capability_config.h" + +#define HDF_LOG_TAG codec_hdi_server + +#ifdef __ARM64__ +#define DRIVER_PATH "/vendor/lib64" +#else +#define DRIVER_PATH "/vendor/lib" +#endif +#define CODEC_SERVICE_IMPL "libcodec_hdi_omx_service_impl" + +typedef void (*SERVICE_CONSTRUCT_FUNC)(struct OmxComponentManager *, struct CodecComponentType *); + +static const int COMPONENT_NAME_LENGTH = 128; + +static void FreeMem(int8_t *mem, uint32_t memLen) +{ + if (memLen > 0 && mem != NULL) { + OsalMemFree(mem); + } +} + +static int32_t SerStubGetComponentNum(struct CodecComponentTypeStub *stub, + struct HdfSBuf *data, struct HdfSBuf *reply) +{ + return HandleGetNumCmd(reply); +} + +static int32_t SerStubGetComponentCapablityList(struct CodecComponentTypeStub *stub, + struct HdfSBuf *data, struct HdfSBuf *reply) +{ + return HandleGetAllCapablityListCmd(reply); +} + +static int32_t ReadParamsForCreateComponent(struct HdfSBuf *data, char **compName, int8_t **appData, + uint32_t *appDataSize, struct CodecCallbackType **callback) +{ + const char *compNameCp = HdfSbufReadString(data); + if (compNameCp == NULL) { + HDF_LOGE("%{public}s: read compNameCp failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!HdfSbufReadUint32(data, appDataSize)) { + HDF_LOGE("%{public}s: read appData size failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + *compName = strdup(compNameCp); + + if (*appDataSize > 0) { + *appData = (int8_t*)OsalMemCalloc(sizeof(int8_t) * (*appDataSize)); + if (*appData == NULL) { + HDF_LOGE("%{public}s: HDF_ERR_MALLOC_FAIL!", __func__); + return HDF_ERR_MALLOC_FAIL; + } + + for (uint32_t i = 0; i < *appDataSize; i++) { + if (!HdfSbufReadInt8(data, &(*appData)[i])) { + HDF_LOGE("%{public}s: read appData[i] failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + } + } + + struct HdfRemoteService *callbackRemote = HdfSbufReadRemoteService(data); + if (callbackRemote == NULL) { + HDF_LOGE("%{public}s: read callbackRemote failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + *callback = CodecCallbackTypeGet(callbackRemote); + + return HDF_SUCCESS; +} + +static int32_t SerStubCreateComponent(struct CodecComponentTypeStub *stub, + struct HdfSBuf *data, struct HdfSBuf *reply) +{ + int32_t ret; + OMX_HANDLETYPE componentHandle; + int8_t *appData = NULL; + uint32_t appDataSize = 0; + struct CodecCallbackType *callback = NULL; + char *compName = NULL; + + ret = ReadParamsForCreateComponent(data, &compName, &appData, &appDataSize, &callback); + if (ret != HDF_SUCCESS) { + if (compName != NULL) { + OsalMemFree(compName); + compName = NULL; + } + if (appDataSize > 0 && appData != NULL) { + OsalMemFree(appData); + } + return ret; + } + + ret = stub->managerService.CreateComponent(&componentHandle, compName, appData, appDataSize, callback); + if (compName != NULL) { + OsalMemFree(compName); + compName = NULL; + } + if (appDataSize > 0 && appData != NULL) { + OsalMemFree(appData); + } + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call CreateComponent function failed!", __func__); + return ret; + } + stub->componentHandle = componentHandle; + + return ret; +} + +static int32_t SerStubDestroyComponent(struct CodecComponentTypeStub *stub, + struct HdfSBuf *data, struct HdfSBuf *reply) +{ + int32_t ret; + + ret = stub->managerService.DestoryComponent(stub->componentHandle); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call DestroyComponent function failed!", __func__); + } + + return ret; +} + +static int32_t SerStubGetComponentVersion(struct CodecComponentTypeStub *stub, + struct HdfSBuf *data, struct HdfSBuf *reply) +{ + int32_t ret; + char compName[COMPONENT_NAME_LENGTH] = {0}; + union OMX_VERSIONTYPE compVersion; + union OMX_VERSIONTYPE specVersion; + uint8_t *compUUID = NULL; + uint32_t compUUIDLen = 0; + + if (!HdfSbufReadUint32(data, &compUUIDLen)) { + HDF_LOGE("%{public}s: read compUUIDLen failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + compUUID = (uint8_t*)OsalMemCalloc(sizeof(uint8_t) * (compUUIDLen)); + if (compUUID == NULL) { + HDF_LOGE("%{public}s: HDF_ERR_MALLOC_FAIL!", __func__); + return HDF_ERR_MALLOC_FAIL; + } + ret = stub->service.GetComponentVersion(&stub->service, compName, + &compVersion, &specVersion, compUUID, compUUIDLen); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call GetComponentVersion function failed!", __func__); + FreeMem((int8_t*)compUUID, compUUIDLen); + return ret; + } + + if (!HdfSbufWriteString(reply, compName)) { + HDF_LOGE("%{public}s: write compName failed!", __func__); + FreeMem((int8_t*)compUUID, compUUIDLen); + return HDF_ERR_INVALID_PARAM; + } + + if (!HdfSbufWriteUnpadBuffer(reply, (const uint8_t *)&compVersion, sizeof(union OMX_VERSIONTYPE))) { + HDF_LOGE("%{public}s: write compVersion failed!", __func__); + FreeMem((int8_t*)compUUID, compUUIDLen); + return HDF_ERR_INVALID_PARAM; + } + + if (!HdfSbufWriteUnpadBuffer(reply, (const uint8_t *)&specVersion, sizeof(union OMX_VERSIONTYPE))) { + HDF_LOGE("%{public}s: write specVersion failed!", __func__); + FreeMem((int8_t*)compUUID, compUUIDLen); + return HDF_ERR_INVALID_PARAM; + } + + for (uint32_t i = 0; i < compUUIDLen; i++) { + if (!HdfSbufWriteUint8(reply, compUUID[i])) { + HDF_LOGE("%{public}s: write compUUID[i] failed!", __func__); + FreeMem((int8_t*)compUUID, compUUIDLen); + return HDF_ERR_INVALID_PARAM; + } + } + + FreeMem((int8_t*)compUUID, compUUIDLen); + return HDF_SUCCESS; +} + +static int32_t SerStubSendCommand(struct CodecComponentTypeStub *stub, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + int32_t ret; + enum OMX_COMMANDTYPE cmd; + uint32_t param = 0; + int8_t *cmdData = NULL; + uint32_t cmdDataLen = 0; + + if (!HdfSbufReadUint32(data, (uint32_t*)&cmd)) { + HDF_LOGE("%{public}s: read &cmd failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!HdfSbufReadUint32(data, ¶m)) { + HDF_LOGE("%{public}s: read ¶m failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!HdfSbufReadUint32(data, &cmdDataLen)) { + HDF_LOGE("%{public}s: read cmdData size failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (cmdDataLen > 0) { + cmdData = (int8_t*)OsalMemCalloc(sizeof(int8_t) * (cmdDataLen)); + if (cmdData == NULL) { + HDF_LOGE("%{public}s: HDF_ERR_MALLOC_FAIL!", __func__); + return HDF_ERR_MALLOC_FAIL; + } + + for (uint32_t i = 0; i < cmdDataLen; i++) { + if (!HdfSbufReadInt8(data, &cmdData[i])) { + HDF_LOGE("%{public}s: read &cmdData[i] failed!", __func__); + FreeMem(cmdData, cmdDataLen); + return HDF_ERR_INVALID_PARAM; + } + } + } + + ret = stub->service.SendCommand(&stub->service, cmd, param, cmdData, cmdDataLen); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call SendCommand function failed!", __func__); + FreeMem(cmdData, cmdDataLen); + return ret; + } + + FreeMem(cmdData, cmdDataLen); + return HDF_SUCCESS; +} + +static int32_t SerStubGetParameter(struct CodecComponentTypeStub *stub, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + int32_t ret; + uint32_t paramIndex = 0; + int8_t *paramStruct = NULL; + uint32_t paramStructLen = 0; + + if (!HdfSbufReadUint32(data, ¶mIndex)) { + HDF_LOGE("%{public}s: read paramIndex failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!HdfSbufReadUint32(data, ¶mStructLen)) { + HDF_LOGE("%{public}s: read paramStructLen failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + paramStruct = (int8_t*)OsalMemCalloc(sizeof(int8_t) * (paramStructLen)); + if (paramStruct == NULL) { + HDF_LOGE("%{public}s: HDF_ERR_MALLOC_FAIL!", __func__); + return HDF_ERR_MALLOC_FAIL; + } + + for (uint32_t i = 0; i < paramStructLen; i++) { + if (!HdfSbufReadInt8(data, ¶mStruct[i])) { + HDF_LOGE("%{public}s: read paramStruct[%{public}d] failed!", __func__, i); + FreeMem(paramStruct, paramStructLen); + return HDF_ERR_INVALID_PARAM; + } + } + + ret = stub->service.GetParameter(&stub->service, paramIndex, paramStruct, paramStructLen); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call GetParameter function failed!", __func__); + FreeMem(paramStruct, paramStructLen); + return ret; + } + + for (uint32_t i = 0; i < paramStructLen; i++) { + if (!HdfSbufWriteInt8(reply, paramStruct[i])) { + HDF_LOGE("%{public}s: write paramStruct[i] failed!", __func__); + FreeMem(paramStruct, paramStructLen); + return HDF_ERR_INVALID_PARAM; + } + } + + FreeMem(paramStruct, paramStructLen); + return HDF_SUCCESS; +} + +static int32_t SerStubSetParameter(struct CodecComponentTypeStub *stub, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + int32_t ret; + uint32_t index = 0; + int8_t *paramStruct = NULL; + uint32_t paramStructLen = 0; + + if (!HdfSbufReadUint32(data, &index)) { + HDF_LOGE("%{public}s: read &index failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!HdfSbufReadUint32(data, ¶mStructLen)) { + HDF_LOGE("%{public}s: read paramStruct size failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (paramStructLen > 0) { + paramStruct = (int8_t*)OsalMemCalloc(sizeof(int8_t) * (paramStructLen)); + if (paramStruct == NULL) { + HDF_LOGE("%{public}s: HDF_ERR_MALLOC_FAIL!", __func__); + return HDF_ERR_MALLOC_FAIL; + } + + for (uint32_t i = 0; i < paramStructLen; i++) { + if (!HdfSbufReadInt8(data, ¶mStruct[i])) { + HDF_LOGE("%{public}s: read ¶mStruct[i] failed!", __func__); + FreeMem(paramStruct, paramStructLen); + return HDF_ERR_INVALID_PARAM; + } + } + } + + ret = stub->service.SetParameter(&stub->service, index, paramStruct, paramStructLen); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call SetParameter function failed!", __func__); + FreeMem(paramStruct, paramStructLen); + return ret; + } + + FreeMem(paramStruct, paramStructLen); + return HDF_SUCCESS; +} + +static int32_t SerStubGetConfig(struct CodecComponentTypeStub *stub, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + int32_t ret; + uint32_t index = 0; + int8_t *cfgStruct = NULL; + uint32_t cfgStructLen = 0; + + if (!HdfSbufReadUint32(data, &index)) { + HDF_LOGE("%{public}s: read &index failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!HdfSbufReadUint32(data, &cfgStructLen)) { + HDF_LOGE("%{public}s: read cfgStructLen failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + cfgStruct = (int8_t*)OsalMemCalloc(sizeof(int8_t) * (cfgStructLen)); + if (cfgStruct == NULL) { + HDF_LOGE("%{public}s: HDF_ERR_MALLOC_FAIL!", __func__); + return HDF_ERR_MALLOC_FAIL; + } + + for (uint32_t i = 0; i < cfgStructLen; i++) { + if (!HdfSbufReadInt8(data, &cfgStruct[i])) { + HDF_LOGE("%{public}s: read cfgStruct[i] failed!", __func__); + FreeMem(cfgStruct, cfgStructLen); + return HDF_ERR_INVALID_PARAM; + } + } + + ret = stub->service.GetConfig(&stub->service, index, cfgStruct, cfgStructLen); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call GetConfig function failed!", __func__); + FreeMem(cfgStruct, cfgStructLen); + return ret; + } + + for (uint32_t i = 0; i < cfgStructLen; i++) { + if (!HdfSbufWriteInt8(reply, cfgStruct[i])) { + HDF_LOGE("%{public}s: write cfgStruct[i] failed!", __func__); + FreeMem(cfgStruct, cfgStructLen); + return HDF_ERR_INVALID_PARAM; + } + } + + FreeMem(cfgStruct, cfgStructLen); + return ret; +} + +static int32_t SerStubSetConfig(struct CodecComponentTypeStub *stub, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + int32_t ret; + uint32_t index = 0; + int8_t *cfgStruct = NULL; + uint32_t cfgStructLen = 0; + + if (!HdfSbufReadUint32(data, &index)) { + HDF_LOGE("%{public}s: read &index failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!HdfSbufReadUint32(data, &cfgStructLen)) { + HDF_LOGE("%{public}s: read cfgStruct size failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (cfgStructLen > 0) { + cfgStruct = (int8_t*)OsalMemCalloc(sizeof(int8_t) * (cfgStructLen)); + if (cfgStruct == NULL) { + HDF_LOGE("%{public}s: HDF_ERR_MALLOC_FAIL!", __func__); + return HDF_ERR_MALLOC_FAIL; + } + + for (uint32_t i = 0; i < cfgStructLen; i++) { + if (!HdfSbufReadInt8(data, &cfgStruct[i])) { + HDF_LOGE("%{public}s: read &cfgStruct[i] failed!", __func__); + FreeMem(cfgStruct, cfgStructLen); + return HDF_ERR_INVALID_PARAM; + } + } + } + + ret = stub->service.SetConfig(&stub->service, index, cfgStruct, cfgStructLen); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call SetConfig function failed!", __func__); + FreeMem(cfgStruct, cfgStructLen); + return ret; + } + + FreeMem(cfgStruct, cfgStructLen); + return ret; +} + +static int32_t SerStubGetExtensionIndex(struct CodecComponentTypeStub *stub, + struct HdfSBuf *data, struct HdfSBuf *reply) +{ + int32_t ret; + char *paramName = NULL; + uint32_t indexType = 0; + + const char *paramNameCp = HdfSbufReadString(data); + if (paramNameCp == NULL) { + HDF_LOGE("%{public}s: read paramNameCp failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + paramName = strdup(paramNameCp); + + ret = stub->service.GetExtensionIndex(&stub->service, paramName, &indexType); + if (paramName != NULL) { + OsalMemFree(paramName); + paramName = NULL; + } + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call GetExtensionIndex function failed!", __func__); + return ret; + } + + if (!HdfSbufWriteUint32(reply, indexType)) { + HDF_LOGE("%{public}s: write indexType failed!", __func__); + ret = HDF_ERR_INVALID_PARAM; + } + + return ret; +} + +static int32_t SerStubGetState(struct CodecComponentTypeStub *stub, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + int32_t ret; + enum OMX_STATETYPE state; + + ret = stub->service.GetState(&stub->service, &state); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call GetState function failed!", __func__); + return ret; + } + + if (!HdfSbufWriteUint32(reply, (uint32_t)state)) { + HDF_LOGE("%{public}s: write state failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return ret; +} + +static int32_t SerStubComponentTunnelRequest(struct CodecComponentTypeStub *stub, + struct HdfSBuf *data, struct HdfSBuf *reply) +{ + int32_t ret; + uint32_t port = 0; + int32_t tunneledComp = 0; + uint32_t tunneledPort = 0; + struct OMX_TUNNELSETUPTYPE tunnelSetup; + + if (!HdfSbufReadUint32(data, &port)) { + HDF_LOGE("%{public}s: read &port failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!HdfSbufReadInt32(data, &tunneledComp)) { + HDF_LOGE("%{public}s: read &tunneledComp failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!HdfSbufReadUint32(data, &tunneledPort)) { + HDF_LOGE("%{public}s: read &tunneledPort failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!OMX_TUNNELSETUPTYPEBlockUnmarshalling(data, &tunnelSetup)) { + HDF_LOGE("%{public}s: read tunnelSetup failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + ret = stub->service.ComponentTunnelRequest(&stub->service, port, tunneledComp, tunneledPort, &tunnelSetup); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call ComponentTunnelRequest function failed!", __func__); + return ret; + } + + if (!OMX_TUNNELSETUPTYPEBlockMarshalling(reply, &tunnelSetup)) { + HDF_LOGE("%{public}s: write tunnelSetup failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return ret; +} + +static int32_t SerStubUseBuffer(struct CodecComponentTypeStub *stub, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + int32_t ret; + struct OmxCodecBuffer buffer; + uint32_t portIndex = 0; + + if (!HdfSbufReadUint32(data, &portIndex)) { + HDF_LOGE("%{public}s: read &portIndex failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!OmxCodecBufferBlockUnmarshalling(data, &buffer)) { + HDF_LOGE("%{public}s: read buffer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + ret = stub->service.UseBuffer(&stub->service, portIndex, &buffer); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call UseBuffer function failed!", __func__); + return ret; + } + + if (!OmxCodecBufferBlockMarshalling(reply, &buffer)) { + HDF_LOGE("%{public}s: write buffer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return ret; +} + +static int32_t SerStubAllocateBuffer(struct CodecComponentTypeStub *stub, + struct HdfSBuf *data, struct HdfSBuf *reply) +{ + int32_t ret; + struct OmxCodecBuffer buffer; + uint32_t portIndex = 0; + + if (!OmxCodecBufferBlockUnmarshalling(data, &buffer)) { + HDF_LOGE("%{public}s: read buffer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!HdfSbufReadUint32(data, &portIndex)) { + HDF_LOGE("%{public}s: read &portIndex failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + ret = stub->service.AllocateBuffer(&stub->service, &buffer, portIndex); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call AllocateBuffer function failed!", __func__); + return ret; + } + + if (!OmxCodecBufferBlockMarshalling(reply, &buffer)) { + HDF_LOGE("%{public}s: write buffer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return ret; +} + +static int32_t SerStubFreeBuffer(struct CodecComponentTypeStub *stub, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + int32_t ret; + uint32_t portIndex = 0; + struct OmxCodecBuffer buffer; + + if (!HdfSbufReadUint32(data, &portIndex)) { + HDF_LOGE("%{public}s: read &portIndex failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!OmxCodecBufferBlockUnmarshalling(data, &buffer)) { + HDF_LOGE("%{public}s: read buffer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + ret = stub->service.FreeBuffer(&stub->service, portIndex, &buffer); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call FreeBuffer function failed!", __func__); + return ret; + } + + return ret; +} + +static int32_t SerStubEmptyThisBuffer(struct CodecComponentTypeStub *stub, + struct HdfSBuf *data, struct HdfSBuf *reply) +{ + int32_t ret; + struct OmxCodecBuffer buffer; + + if (!OmxCodecBufferBlockUnmarshalling(data, &buffer)) { + HDF_LOGE("%{public}s: read buffer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + ret = stub->service.EmptyThisBuffer(&stub->service, &buffer); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call EmptyThisBuffer function failed!", __func__); + return ret; + } + + return ret; +} + +static int32_t SerStubFillThisBuffer(struct CodecComponentTypeStub *stub, + struct HdfSBuf *data, struct HdfSBuf *reply) +{ + int32_t ret; + struct OmxCodecBuffer buffer; + + if (!OmxCodecBufferBlockUnmarshalling(data, &buffer)) { + HDF_LOGE("%{public}s: read buffer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + ret = stub->service.FillThisBuffer(&stub->service, &buffer); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call FillThisBuffer function failed!", __func__); + return ret; + } + + return ret; +} + +static int32_t SerStubSetCallbacks(struct CodecComponentTypeStub *stub, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + int32_t ret; + struct CodecCallbackType* callback = NULL; + int8_t *appData = NULL; + uint32_t appDataLen = 0; + + struct HdfRemoteService *callbackRemote = HdfSbufReadRemoteService(data); + if (callbackRemote == NULL) { + HDF_LOGE("%{public}s: read callbackRemote failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + callback = CodecCallbackTypeGet(callbackRemote); + + if (!HdfSbufReadUint32(data, &appDataLen)) { + HDF_LOGE("%{public}s: read appData size failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (appDataLen > 0) { + appData = (int8_t*)OsalMemCalloc(sizeof(int8_t) * (appDataLen)); + if (appData == NULL) { + HDF_LOGE("%{public}s: HDF_ERR_MALLOC_FAIL!", __func__); + return HDF_ERR_MALLOC_FAIL; + } + + for (uint32_t i = 0; i < appDataLen; i++) { + if (!HdfSbufReadInt8(data, &appData[i])) { + HDF_LOGE("%{public}s: read &appData[i] failed!", __func__); + FreeMem(appData, appDataLen); + return HDF_ERR_INVALID_PARAM; + } + } + } + + ret = stub->service.SetCallbacks(&stub->service, callback, appData, appDataLen); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call SetCallbacks function failed!", __func__); + FreeMem(appData, appDataLen); + return ret; + } + + FreeMem(appData, appDataLen); + return ret; +} + +static int32_t SerStubComponentDeInit(struct CodecComponentTypeStub *stub, + struct HdfSBuf *data, struct HdfSBuf *reply) +{ + int32_t ret; + + ret = stub->service.ComponentDeInit(&stub->service); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call ComponentDeInit function failed!", __func__); + } + + return ret; +} + +static int32_t SerStubUseEglImage(struct CodecComponentTypeStub *stub, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + int32_t ret; + struct OmxCodecBuffer buffer; + uint32_t portIndex = 0; + int8_t *eglImage = NULL; + uint32_t eglImageLen = 0; + + if (!OmxCodecBufferBlockUnmarshalling(data, &buffer)) { + HDF_LOGE("%{public}s: read buffer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!HdfSbufReadUint32(data, &portIndex)) { + HDF_LOGE("%{public}s: read &portIndex failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!HdfSbufReadUint32(data, &eglImageLen)) { + HDF_LOGE("%{public}s: read eglImage size failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (eglImageLen > 0) { + eglImage = (int8_t*)OsalMemCalloc(sizeof(int8_t) * (eglImageLen)); + if (eglImage == NULL) { + HDF_LOGE("%{public}s: HDF_ERR_MALLOC_FAIL!", __func__); + return HDF_ERR_MALLOC_FAIL; + } + + for (uint32_t i = 0; i < eglImageLen; i++) { + if (!HdfSbufReadInt8(data, &eglImage[i])) { + HDF_LOGE("%{public}s: read &eglImage[i] failed!", __func__); + FreeMem(eglImage, eglImageLen); + return HDF_ERR_INVALID_PARAM; + } + } + } + + ret = stub->service.UseEglImage(&stub->service, &buffer, portIndex, eglImage, eglImageLen); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call UseEglImage function failed!", __func__); + FreeMem(eglImage, eglImageLen); + return ret; + } + + if (!OmxCodecBufferBlockMarshalling(reply, &buffer)) { + HDF_LOGE("%{public}s: write buffer failed!", __func__); + FreeMem(eglImage, eglImageLen); + return HDF_ERR_INVALID_PARAM; + } + + FreeMem(eglImage, eglImageLen); + return ret; +} + +static int32_t SerStubComponentRoleEnum(struct CodecComponentTypeStub *stub, + struct HdfSBuf *data, struct HdfSBuf *reply) +{ + int32_t ret; + uint8_t *role = NULL; + uint32_t roleLen = 0; + uint32_t index = 0; + + if (!HdfSbufReadUint32(data, &roleLen)) { + HDF_LOGE("%{public}s: read &roleLen failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + role = (uint8_t*)OsalMemCalloc(sizeof(uint8_t) * (roleLen)); + if (role == NULL) { + HDF_LOGE("%{public}s: HDF_ERR_MALLOC_FAIL!", __func__); + return HDF_ERR_MALLOC_FAIL; + } + + if (!HdfSbufReadUint32(data, &index)) { + HDF_LOGE("%{public}s: read &index failed!", __func__); + FreeMem((int8_t*)role, roleLen); + return HDF_ERR_INVALID_PARAM; + } + + ret = stub->service.ComponentRoleEnum(&stub->service, role, roleLen, index); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call ComponentRoleEnum function failed!", __func__); + FreeMem((int8_t*)role, roleLen); + return ret; + } + + for (uint32_t i = 0; i < roleLen; i++) { + if (!HdfSbufWriteUint8(reply, role[i])) { + HDF_LOGE("%{public}s: write role[i] failed!", __func__); + FreeMem((int8_t*)role, roleLen); + return HDF_ERR_INVALID_PARAM; + } + } + + FreeMem((int8_t*)role, roleLen); + return ret; +} + +static int32_t HandleComponentManagerCmd(struct CodecComponentTypeStub *stub, + int32_t cmdId, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + switch (cmdId) { + case CMD_CODEC_GET_COMPONENT_NUM: + return SerStubGetComponentNum(stub, data, reply); + case CMD_CODEC_GET_COMPONENT_CAPABILITY_LIST: + return SerStubGetComponentCapablityList(stub, data, reply); + case CMD_CREATE_COMPONENT: + return SerStubCreateComponent(stub, data, reply); + case CMD_DESTROY_COMPONENT: + return SerStubDestroyComponent(stub, data, reply); + default: + HDF_LOGE("%{public}s: not support cmd %{public}d", __func__, cmdId); + return HDF_ERR_INVALID_PARAM; + } +} + +static int32_t HandleComponentCmd(struct CodecComponentTypeStub *stub, + int32_t cmdId, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + switch (cmdId) { + case CMD_GET_COMPONENT_VERSION: + return SerStubGetComponentVersion(stub, data, reply); + case CMD_SEND_COMMAND: + return SerStubSendCommand(stub, data, reply); + case CMD_GET_PARAMETER: + return SerStubGetParameter(stub, data, reply); + case CMD_SET_PARAMETER: + return SerStubSetParameter(stub, data, reply); + case CMD_GET_CONFIG: + return SerStubGetConfig(stub, data, reply); + case CMD_SET_CONFIG: + return SerStubSetConfig(stub, data, reply); + case CMD_GET_EXTENSION_INDEX: + return SerStubGetExtensionIndex(stub, data, reply); + case CMD_GET_STATE: + return SerStubGetState(stub, data, reply); + case CMD_COMPONENT_TUNNEL_REQUEST: + return SerStubComponentTunnelRequest(stub, data, reply); + case CMD_USE_BUFFER: + return SerStubUseBuffer(stub, data, reply); + case CMD_ALLOCATE_BUFFER: + return SerStubAllocateBuffer(stub, data, reply); + case CMD_FREE_BUFFER: + return SerStubFreeBuffer(stub, data, reply); + case CMD_EMPTY_THIS_BUFFER: + return SerStubEmptyThisBuffer(stub, data, reply); + case CMD_FILL_THIS_BUFFER: + return SerStubFillThisBuffer(stub, data, reply); + case CMD_SET_CALLBACKS: + return SerStubSetCallbacks(stub, data, reply); + case CMD_COMPONENT_DE_INIT: + return SerStubComponentDeInit(stub, data, reply); + case CMD_USE_EGL_IMAGE: + return SerStubUseEglImage(stub, data, reply); + case CMD_COMPONENT_ROLE_ENUM: + return SerStubComponentRoleEnum(stub, data, reply); + default: + HDF_LOGE("%{public}s: not support cmd %{public}d", __func__, cmdId); + return HDF_ERR_INVALID_PARAM; + } +} + +int32_t CodecComponentTypeServiceOnRemoteRequest(struct CodecComponentTypeStub *service, + int32_t cmdId, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + switch (cmdId) { + case CMD_CODEC_GET_COMPONENT_NUM: + case CMD_CODEC_GET_COMPONENT_CAPABILITY_LIST: + case CMD_CREATE_COMPONENT: + case CMD_DESTROY_COMPONENT: + return HandleComponentManagerCmd(service, cmdId, data, reply); + case CMD_GET_COMPONENT_VERSION: + case CMD_SEND_COMMAND: + case CMD_GET_PARAMETER: + case CMD_SET_PARAMETER: + case CMD_GET_CONFIG: + case CMD_SET_CONFIG: + case CMD_GET_EXTENSION_INDEX: + case CMD_GET_STATE: + case CMD_COMPONENT_TUNNEL_REQUEST: + case CMD_USE_BUFFER: + case CMD_ALLOCATE_BUFFER: + case CMD_FREE_BUFFER: + case CMD_EMPTY_THIS_BUFFER: + case CMD_FILL_THIS_BUFFER: + case CMD_SET_CALLBACKS: + case CMD_COMPONENT_DE_INIT: + case CMD_USE_EGL_IMAGE: + case CMD_COMPONENT_ROLE_ENUM: + return HandleComponentCmd(service, cmdId, data, reply); + default: + HDF_LOGE("%{public}s: not support cmd %{public}d", __func__, cmdId); + return HDF_ERR_INVALID_PARAM; + } +} + +static void *LoadServiceHandler(void) +{ + char *libPath = NULL; + void *handler = NULL; + + libPath = HDF_LIBRARY_FULL_PATH(CODEC_SERVICE_IMPL); + handler = dlopen(libPath, RTLD_LAZY); + if (handler == NULL) { + HDF_LOGE("%{public}s: dlopen failed %{public}s", __func__, dlerror()); + return NULL; + } + + return handler; +} + +struct CodecComponentTypeStub *CodecComponentTypeStubGetInstance(void) +{ + SERVICE_CONSTRUCT_FUNC serviceConstructFunc = NULL; + struct CodecComponentTypeStub *stub + = (struct CodecComponentTypeStub *)OsalMemAlloc(sizeof(struct CodecComponentTypeStub)); + if (stub == NULL) { + HDF_LOGE("%{public}s: OsalMemAlloc obj failed!", __func__); + return NULL; + } + + stub->dlHandler = LoadServiceHandler(); + if (stub->dlHandler == NULL) { + HDF_LOGE("%{public}s: stub->dlHanlder is null", __func__); + OsalMemFree(stub); + return NULL; + } + + serviceConstructFunc = (SERVICE_CONSTRUCT_FUNC)dlsym(stub->dlHandler, "CodecComponentTypeServiceConstruct"); + if (serviceConstructFunc == NULL) { + HDF_LOGE("%{public}s: dlsym failed %{public}s", __func__, dlerror()); + dlclose(stub->dlHandler); + OsalMemFree(stub); + return NULL; + } + + serviceConstructFunc(&stub->managerService, &stub->service); + return stub; +} + +void CodecComponentTypeStubRelease(struct CodecComponentTypeStub *instance) +{ + if (instance == NULL) { + return; + } + + dlclose(instance->dlHandler); + OsalMemFree(instance); +} \ No newline at end of file diff --git a/codec/hal/src/codec_config_parser.c b/codec/hal/src/codec_config_parser.c new file mode 100644 index 0000000000..e883988744 --- /dev/null +++ b/codec/hal/src/codec_config_parser.c @@ -0,0 +1,401 @@ +/* + * Copyright (c) 2022 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_parser.h" +#include +#include +#include +#include + +#define HDF_LOG_TAG codec_config_parser +#ifdef __ARM64__ +#define MASK_NUM_LIMIT 64 +#else +#define MASK_NUM_LIMIT 32 +#endif + +static int32_t GetGroupCapabilitiesNumber(const struct DeviceResourceNode *node, + const char *nodeName, int32_t *num) +{ + if (node == NULL || nodeName == NULL || num == NULL) { + HDF_LOGE("%{public}s, failed for codec %{public}s, invalid param!", __func__, nodeName); + return HDF_ERR_INVALID_PARAM; + } + + int32_t result = 0; + *num = result; + const struct DeviceResourceNode *codecGroupNode = NULL; + struct DeviceResourceNode *childNode = NULL; + struct DeviceResourceIface *iface = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + if (iface ==NULL) { + HDF_LOGE("%{public}s, failed, iface NULL!", __func__); + 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, ConfigUintArrayNodeAttr *attr) +{ + if (iface == NULL || node == NULL || attr == NULL) { + HDF_LOGE("%{public}s, failed, invalid param!", __func__); + return HDF_ERR_INVALID_PARAM; + } + if (attr->array == NULL || attr->attrName == NULL) { + HDF_LOGE("%{public}s, failed, invalid attr!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + int32_t count = iface->GetElemNum(node, attr->attrName); + if (count < 0 || count >= attr->length) { + HDF_LOGE("%{public}s, %{public}s table size: %{public}d incorrect or exceed max size %{public}d!", + __func__, attr->attrName, count, attr->length - 1); + return HDF_FAILURE; + } + + if (count > 0) { + iface->GetUint32Array(node, attr->attrName, (uint32_t *)attr->array, count, 0); + } + attr->array[count] = attr->endValue; + + return HDF_SUCCESS; +} + +static int32_t GetMaskedConfig(const struct DeviceResourceIface *iface, + const struct DeviceResourceNode *node, const char *attrName, uint32_t *mask) +{ + if (iface == NULL || node == NULL || attrName == NULL || mask == NULL) { + HDF_LOGE("%{public}s, failed, invalid param!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + uint32_t *values = NULL; + int32_t count = iface->GetElemNum(node, attrName); + + *mask = 0; + if (count < 0 || count > MASK_NUM_LIMIT) { + HDF_LOGE("%{public}s, failed, count %{public}d incorrect!", __func__, count); + return HDF_FAILURE; + } + + if (count > 0) { + 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 (int32_t index = 0; index < count; index++) { + *mask |= values[index]; + } + OsalMemFree(values); + } + + return HDF_SUCCESS; +} + +static int32_t GetVideoPortCapability(const struct DeviceResourceIface *iface, + const struct DeviceResourceNode *childNode, CodecCompCapability *cap) +{ + if (iface == NULL || childNode == NULL || cap == NULL) { + HDF_LOGE("%{public}s, failed, invalid param!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + ConfigUintNodeAttr nodeAttrs[] = { + {CODEC_CONFIG_KEY_MIN_WIDTH, (uint32_t*)&cap->port.video.minSize.width, 0}, + {CODEC_CONFIG_KEY_MIN_HEIGHT, (uint32_t*)&cap->port.video.minSize.height, 0}, + {CODEC_CONFIG_KEY_MAX_WIDTH, (uint32_t*)&cap->port.video.maxSize.width, 0}, + {CODEC_CONFIG_KEY_MAX_HEIGHT, (uint32_t*)&cap->port.video.maxSize.height, 0}, + {CODEC_CONFIG_KEY_WIDTH_ALGINMENT, (uint32_t*)&cap->port.video.whAlignment.widthAlginment, 0}, + {CODEC_CONFIG_KEY_HEIGHT_ALGINMENT, (uint32_t*)&cap->port.video.whAlignment.heightAlginment, 0}, + {CODEC_CONFIG_KEY_MIN_BLOCK_COUNT, (uint32_t*)&cap->port.video.blockCount.min, 0}, + {CODEC_CONFIG_KEY_MAX_BLOCK_COUNT, (uint32_t*)&cap->port.video.blockCount.max, 0}, + {CODEC_CONFIG_KEY_MIN_BLOCKS_PER_SECOND, (uint32_t*)&cap->port.video.blocksPerSecond.min, 0}, + {CODEC_CONFIG_KEY_MAX_BLOCKS_PER_SECOND, (uint32_t*)&cap->port.video.blocksPerSecond.max, 0}, + {CODEC_CONFIG_KEY_BLOCK_SIZE_WIDTH, (uint32_t*)&cap->port.video.blockSize.width, 0}, + {CODEC_CONFIG_KEY_BLOCK_SIZE_HEIGHT, (uint32_t*)&cap->port.video.blockSize.height, 0} + }; + + int32_t count = sizeof(nodeAttrs) / sizeof(ConfigUintNodeAttr); + for (int32_t i = 0; i < count; i++) { + if (iface->GetUint32(childNode, nodeAttrs[i].attrName, nodeAttrs[i].valueAddr, + nodeAttrs[i].defaultValue) != HDF_SUCCESS) { + HDF_LOGE("%{public}s, failed to get %{public}s.%{public}s!", + __func__, childNode->name, nodeAttrs[i].attrName); + return HDF_FAILURE; + } + } + + ConfigUintArrayNodeAttr attr = {CODEC_CONFIG_KEY_SUPPORT_PIXEL_FMTS, + cap->port.video.supportPixFmts, PIX_FORMAT_NUM, OMX_COLOR_FormatUnused}; + if (GetUintTableConfig(iface, childNode, &attr) != HDF_SUCCESS) { + HDF_LOGE("%{public}s, failed to get %{public}s.%{public}s!", + __func__, childNode->name, CODEC_CONFIG_KEY_SUPPORT_PIXEL_FMTS); + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} + +static int32_t GetAudioPortCapability(const struct DeviceResourceIface *iface, + const struct DeviceResourceNode *childNode, CodecCompCapability *cap) +{ + if (iface == NULL || childNode == NULL || cap == NULL) { + HDF_LOGE("%{public}s, failed, invalid param!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + ConfigUintArrayNodeAttr arrayAttrs[] = { + {CODEC_CONFIG_KEY_SAMPLE_FORMATS, cap->port.audio.sampleFormats, SAMPLE_FMT_NUM, AUDIO_SAMPLE_FMT_INVALID}, + {CODEC_CONFIG_KEY_SAMPLE_RATE, cap->port.audio.sampleRate, SAMPLE_RATE_NUM, AUD_SAMPLE_RATE_INVALID}, + {CODEC_CONFIG_KEY_CHANNEL_LAYOUTS, cap->port.audio.channelLayouts, CHANNEL_NUM, -1}, + {CODEC_CONFIG_KEY_CHANNEL_COUNT, cap->port.audio.channelCount, CHANNEL_NUM, -1} + }; + + int32_t count = sizeof(arrayAttrs) / sizeof(ConfigUintArrayNodeAttr); + for (int32_t i = 0; i < count; i++) { + if (GetUintTableConfig(iface, childNode, &arrayAttrs[i]) != HDF_SUCCESS) { + HDF_LOGE("%{public}s, failed to get %{public}s.%{public}s!", + __func__, childNode->name, arrayAttrs[i].attrName); + return HDF_FAILURE; + } + } + + return HDF_SUCCESS; +} + +static int32_t GetMiscOfCapability(const struct DeviceResourceIface *iface, + const struct DeviceResourceNode *childNode, CodecCompCapability *cap) +{ + if (iface == NULL || childNode == NULL || cap == NULL) { + HDF_LOGE("%{public}s, failed, invalid param!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + ConfigUintArrayNodeAttr attr = {CODEC_CONFIG_KEY_SUPPORT_PROFILES, + cap->supportProfiles, PROFILE_NUM, INVALID_PROFILE}; + if (GetUintTableConfig(iface, childNode, &attr) != HDF_SUCCESS) { + return HDF_FAILURE; + } + if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_MAX_INST, (uint32_t*)&cap->maxInst, 0) != HDF_SUCCESS) { + return HDF_FAILURE; + } + if (GetMaskedConfig(iface, childNode, CODEC_CONFIG_KEY_PROCESS_MODE_MASK, + (uint32_t *)&cap->processModeMask) != HDF_SUCCESS) { + return HDF_FAILURE; + } + if (GetMaskedConfig(iface, childNode, CODEC_CONFIG_KEY_CAPS_MASK, &cap->capsMask) != HDF_SUCCESS) { + return HDF_FAILURE; + } + if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_MIN_BITRATE, (uint32_t*)&(cap->bitRate.min), 0) != HDF_SUCCESS) { + return HDF_FAILURE; + } + if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_MAX_BITRATE, (uint32_t*)&(cap->bitRate.max), 0) != HDF_SUCCESS) { + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} + +static int32_t GetOneCapability(const struct DeviceResourceIface *iface, + const struct DeviceResourceNode *childNode, CodecCompCapability *cap, bool isVideoGroup) +{ + if (iface == NULL || childNode == NULL || cap == NULL) { + HDF_LOGE("%{public}s, failed, invalid param!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_ROLE, + (uint32_t*)&cap->role, MEDIA_ROLETYPE_INVALID) != HDF_SUCCESS) { + cap->role = MEDIA_ROLETYPE_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->role = MEDIA_ROLETYPE_INVALID; + cap->type = INVALID_TYPE; + HDF_LOGE("%{public}s, failed to get type for: %{public}s! Discarded", __func__, childNode->name); + return HDF_FAILURE; + } + + const char *compName = NULL; + if (iface->GetString(childNode, CODEC_CONFIG_KEY_NAME, &compName, "") != HDF_SUCCESS) { + cap->role = MEDIA_ROLETYPE_INVALID; + return HDF_FAILURE; + } + if (compName == NULL || strlen(compName) >= NAME_LENGTH || strlen(compName) == 0) { + cap->role = MEDIA_ROLETYPE_INVALID; + return HDF_FAILURE; + } + int32_t ret = strcpy_s(cap->compName, NAME_LENGTH, compName); + if (ret != EOK) { + HDF_LOGE("%{public}s, strcpy_s is failed, error code: %{public}d!", __func__, ret); + return HDF_FAILURE; + } + cap->isSoftwareCodec = iface->GetBool(childNode, CODEC_CONFIG_KEY_IS_SOFTWARE_CODEC); + + if (GetMiscOfCapability(iface, childNode, cap) != HDF_SUCCESS) { + cap->role = MEDIA_ROLETYPE_INVALID; + return HDF_FAILURE; + } + + if (isVideoGroup) { + if (GetVideoPortCapability(iface, childNode, cap) != HDF_SUCCESS) { + cap->role = MEDIA_ROLETYPE_INVALID; + return HDF_FAILURE; + } + } else { + if (GetAudioPortCapability(iface, childNode, cap) != HDF_SUCCESS) { + cap->role = MEDIA_ROLETYPE_INVALID; + return HDF_FAILURE; + } + } + + return HDF_SUCCESS; +} + +static int32_t GetGroupCapabilities(const struct DeviceResourceNode *node, + const char *nodeName, CodecCapablityGroup *capsGroup) +{ + if (node == NULL || nodeName == NULL || capsGroup == NULL) { + HDF_LOGE("%{public}s, failed, invalid param!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + CodecCompCapability *cap = NULL; + int32_t index = 0; + bool isVideoGroup = true; + const struct DeviceResourceNode *codecGroupNode = NULL; + struct DeviceResourceNode *childNode = NULL; + struct DeviceResourceIface *iface = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + if (iface ==NULL) { + HDF_LOGE("%{public}s, failed, iface NULL!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + codecGroupNode = iface->GetChildNode(node, nodeName); + if (codecGroupNode == NULL) { + HDF_LOGE("%{public}s, failed to get child node: %{public}s!", __func__, nodeName); + return HDF_FAILURE; + } + + if (strstr(nodeName, "Video") == NULL) { + isVideoGroup = false; + } + DEV_RES_NODE_FOR_EACH_CHILD_NODE(codecGroupNode, childNode) { + cap = &(capsGroup->capablitis[index++]); + if (GetOneCapability(iface, childNode, cap, isVideoGroup) != HDF_SUCCESS) { + HDF_LOGE("%{public}s, GetOneCapability failed, role is %{public}d!", __func__, cap->role); + } + } + + return HDF_SUCCESS; +} + +int32_t LoadCodecCapabilityFromHcs(const struct DeviceResourceNode *node, CodecCapablites *caps) +{ + if (node == NULL || caps == NULL) { + HDF_LOGE("%{public}s, failed, invalid param!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + CodecCapablityGroup *codecCapGroup = NULL; + int32_t index; + int32_t codecNum = 0; + + 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]; + if (codecNum > 0) { + codecCapGroup->num = codecNum; + codecCapGroup->capablitis + = (CodecCompCapability *)OsalMemAlloc(sizeof(CodecCompCapability) * codecNum); + } else { + codecCapGroup->capablitis = NULL; + codecCapGroup->num = 0; + } + if (codecNum > 0 && codecCapGroup->capablitis == NULL) { + codecCapGroup->num = 0; + HDF_LOGE("%{public}s, MemAlloc for capability group failed!", __func__); + return HDF_FAILURE; + } + caps->total += codecCapGroup->num; + } + } + + for (index = 0; index < CODEC_CAPABLITY_GROUP_NUM; index++) { + if (GetGroupCapabilities(node, codecGroupsNodeName[index], codecCapGroups[index]) != HDF_SUCCESS) { + HDF_LOGE("%{public}s, GetGroupCapabilities failed index: %{public}d!", __func__, index); + return HDF_FAILURE; + } + } + + caps->inited = true; + return HDF_SUCCESS; +} + +int32_t ClearCapabilityGroup(CodecCapablites *caps) +{ + if (caps == NULL) { + HDF_LOGE("%{public}s, failed, invalid param!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + int32_t index; + CodecCapablityGroup *codecCapGroup = NULL; + 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; + caps->total = 0; + return HDF_SUCCESS; +} \ No newline at end of file diff --git a/codec/hal/src/codec_types.c b/codec/hal/src/codec_types.c new file mode 100644 index 0000000000..e78d4d3a1f --- /dev/null +++ b/codec/hal/src/codec_types.c @@ -0,0 +1,658 @@ +/* + * Copyright (c) 2022 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_types.h" +#include +#include +#include + +bool OMX_TUNNELSETUPTYPEBlockMarshalling(struct HdfSBuf *data, const struct OMX_TUNNELSETUPTYPE *dataBlock) +{ + if (!HdfSbufWriteUint32(data, dataBlock->nTunnelFlags)) { + HDF_LOGE("%{public}s: write dataBlock->nTunnelFlags failed!", __func__); + return false; + } + + if (!HdfSbufWriteInt32(data, (int32_t)dataBlock->eSupplier)) { + HDF_LOGE("%{public}s: write dataBlock->eSupplier failed!", __func__); + return false; + } + + return true; +} + +bool OMX_TUNNELSETUPTYPEBlockUnmarshalling(struct HdfSBuf *data, struct OMX_TUNNELSETUPTYPE *dataBlock) +{ + if (dataBlock == NULL) { + return false; + } + if (!HdfSbufReadUint32(data, &dataBlock->nTunnelFlags)) { + HDF_LOGE("%{public}s: read dataBlock->nTunnelFlags failed!", __func__); + return false; + } + + if (!HdfSbufReadInt32(data, (int32_t*)&dataBlock->eSupplier)) { + HDF_LOGE("%{public}s: read dataBlock->eSupplier failed!", __func__); + return false; + } + + return true; +} + +void OMX_TUNNELSETUPTYPEFree(struct OMX_TUNNELSETUPTYPE *dataBlock, bool freeSelf) +{ + if (dataBlock == NULL) { + return; + } + + if (freeSelf) { + OsalMemFree(dataBlock); + } +} + +static bool CodecBufferMarshalling(struct HdfSBuf *data, const struct OmxCodecBuffer *dataBlock) +{ + if (!HdfSbufWriteInt32(data, (int32_t)dataBlock->bufferType)) { + HDF_LOGE("%{public}s: write dataBlock->bufferType failed!", __func__); + return false; + } + + if (!HdfSbufWriteUint32(data, dataBlock->bufferLen)) { + HDF_LOGE("%{public}s: write dataBlock->bufferLen failed!", __func__); + return false; + } + + if (dataBlock->bufferType == BUFFER_TYPE_AVSHARE_MEM_FD) { + int32_t fd = (int32_t)dataBlock->buffer; + if (!HdfSbufWriteFileDescriptor(data, fd)) { + HDF_LOGE("%{public}s: write fd failed!", __func__); + return false; + } + } else { + for (uint32_t i = 0; i < dataBlock->bufferLen; i++) { + if (!HdfSbufWriteUint8(data, (dataBlock->buffer)[i])) { + HDF_LOGE("%{public}s: write (dataBlock->buffer)[i] failed!", __func__); + return false; + } + } + } + return true; +} + +bool OmxCodecBufferBlockMarshalling(struct HdfSBuf *data, const struct OmxCodecBuffer *dataBlock) +{ + if (!HdfSbufWriteUint32(data, dataBlock->bufferId)) { + HDF_LOGE("%{public}s: write dataBlock->bufferId failed!", __func__); + return false; + } + + if (!HdfSbufWriteUint32(data, dataBlock->size)) { + HDF_LOGE("%{public}s: write dataBlock->size failed!", __func__); + return false; + } + + if (!HdfSbufWriteUnpadBuffer(data, (const uint8_t *)&dataBlock->version, sizeof(union OMX_VERSIONTYPE))) { + HDF_LOGE("%{public}s: write dataBlock->version failed!", __func__); + return false; + } + + if (!CodecBufferMarshalling(data, dataBlock)) { + return false; + } + + if (!HdfSbufWriteUint32(data, dataBlock->allocLen)) { + HDF_LOGE("%{public}s: write dataBlock->allocLen failed!", __func__); + return false; + } + + if (!HdfSbufWriteUint32(data, dataBlock->filledLen)) { + HDF_LOGE("%{public}s: write dataBlock->filledLen failed!", __func__); + return false; + } + + if (!HdfSbufWriteUint32(data, dataBlock->offset)) { + HDF_LOGE("%{public}s: write dataBlock->offset failed!", __func__); + return false; + } + + if (!HdfSbufWriteInt32(data, dataBlock->fenceFd)) { + HDF_LOGE("%{public}s: write dataBlock->fenceFd failed!", __func__); + return false; + } + + if (!HdfSbufWriteInt32(data, (int32_t)dataBlock->type)) { + HDF_LOGE("%{public}s: write dataBlock->type failed!", __func__); + return false; + } + + if (!HdfSbufWriteInt64(data, dataBlock->pts)) { + HDF_LOGE("%{public}s: write dataBlock->pts failed!", __func__); + return false; + } + + if (!HdfSbufWriteUint32(data, dataBlock->flag)) { + HDF_LOGE("%{public}s: write dataBlock->flag failed!", __func__); + return false; + } + + return true; +} + +static bool CodecBufferUnmarshalling(struct HdfSBuf *data, struct OmxCodecBuffer *dataBlock) +{ + if (!HdfSbufReadInt32(data, (int32_t*)&dataBlock->bufferType)) { + HDF_LOGE("%{public}s: read dataBlock->bufferType failed!", __func__); + return false; + } + + uint32_t bufferCpLen = 0; + if (!HdfSbufReadUint32(data, &bufferCpLen)) { + HDF_LOGE("%{public}s: read bufferCpLen failed!", __func__); + return false; + } + dataBlock->bufferLen = bufferCpLen; + + if (dataBlock->bufferType == BUFFER_TYPE_AVSHARE_MEM_FD) { + int32_t fd = HdfSbufReadFileDescriptor(data); + if (fd < 0) { + HDF_LOGE("%{public}s: read fd failed!", __func__); + return false; + } + dataBlock->buffer = (uint8_t*)(unsigned long)fd; + } else { + uint8_t* bufferCp = NULL; + if (bufferCpLen > 0) { + bufferCp = (uint8_t*)OsalMemCalloc(sizeof(uint8_t) * bufferCpLen); + } + if (bufferCp == NULL) { + return false; + } + for (uint32_t i = 0; i < bufferCpLen; i++) { + if (!HdfSbufReadUint8(data, &bufferCp[i])) { + HDF_LOGE("%{public}s: read bufferCp[i] failed!", __func__); + OsalMemFree(bufferCp); + return false; + } + } + dataBlock->buffer = bufferCp; + } + return true; +} + +bool OmxCodecBufferBlockUnmarshalling(struct HdfSBuf *data, struct OmxCodecBuffer *dataBlock) +{ + if (dataBlock == NULL) { + return false; + } + if (!HdfSbufReadUint32(data, &dataBlock->bufferId)) { + HDF_LOGE("%{public}s: read dataBlock->bufferId failed!", __func__); + return false; + } + + if (!HdfSbufReadUint32(data, &dataBlock->size)) { + HDF_LOGE("%{public}s: read dataBlock->size failed!", __func__); + return false; + } + + const union OMX_VERSIONTYPE *versionCp = + (const union OMX_VERSIONTYPE *)HdfSbufReadUnpadBuffer(data, sizeof(union OMX_VERSIONTYPE)); + if (versionCp == NULL) { + HDF_LOGE("%{public}s: read versionCp failed!", __func__); + return false; + } + (void)memcpy_s(&dataBlock->version, sizeof(union OMX_VERSIONTYPE), versionCp, sizeof(union OMX_VERSIONTYPE)); + + if (!CodecBufferUnmarshalling(data, dataBlock)) { + return false; + } + + if (!HdfSbufReadUint32(data, &dataBlock->allocLen)) { + HDF_LOGE("%{public}s: read dataBlock->allocLen failed!", __func__); + return false; + } + + if (!HdfSbufReadUint32(data, &dataBlock->filledLen)) { + HDF_LOGE("%{public}s: read dataBlock->filledLen failed!", __func__); + return false; + } + + if (!HdfSbufReadUint32(data, &dataBlock->offset)) { + HDF_LOGE("%{public}s: read dataBlock->offset failed!", __func__); + return false; + } + + if (!HdfSbufReadInt32(data, &dataBlock->fenceFd)) { + HDF_LOGE("%{public}s: read dataBlock->fenceFd failed!", __func__); + return false; + } + + if (!HdfSbufReadInt32(data, (int32_t*)&dataBlock->type)) { + HDF_LOGE("%{public}s: read dataBlock->type failed!", __func__); + return false; + } + + if (!HdfSbufReadInt64(data, &dataBlock->pts)) { + HDF_LOGE("%{public}s: read dataBlock->pts failed!", __func__); + return false; + } + + if (!HdfSbufReadUint32(data, &dataBlock->flag)) { + HDF_LOGE("%{public}s: read dataBlock->flag failed!", __func__); + return false; + } + + return true; +} + +bool RangeValueBlockMarshalling(struct HdfSBuf *data, const RangeValue *dataBlock) +{ + if (!HdfSbufWriteInt32(data, dataBlock->min)) { + HDF_LOGE("%{public}s: write dataBlock->min failed!", __func__); + return false; + } + + if (!HdfSbufWriteInt32(data, dataBlock->max)) { + HDF_LOGE("%{public}s: write dataBlock->max failed!", __func__); + return false; + } + + return true; +} + +bool RangeValueBlockUnmarshalling(struct HdfSBuf *data, RangeValue *dataBlock) +{ + if (dataBlock == NULL) { + return false; + } + if (!HdfSbufReadInt32(data, &dataBlock->min)) { + HDF_LOGE("%{public}s: read dataBlock->min failed!", __func__); + return false; + } + + if (!HdfSbufReadInt32(data, &dataBlock->max)) { + HDF_LOGE("%{public}s: read dataBlock->max failed!", __func__); + return false; + } + + return true; +} + +void RangeValueFree(RangeValue *dataBlock, bool freeSelf) +{ + if (dataBlock == NULL) { + return; + } + + if (freeSelf) { + OsalMemFree(dataBlock); + } +} + +bool RectBlockMarshalling(struct HdfSBuf *data, const Rect *dataBlock) +{ + if (!HdfSbufWriteInt32(data, dataBlock->width)) { + HDF_LOGE("%{public}s: write dataBlock->width failed!", __func__); + return false; + } + + if (!HdfSbufWriteInt32(data, dataBlock->height)) { + HDF_LOGE("%{public}s: write dataBlock->height failed!", __func__); + return false; + } + + return true; +} + +bool RectBlockUnmarshalling(struct HdfSBuf *data, Rect *dataBlock) +{ + if (dataBlock == NULL) { + return false; + } + if (!HdfSbufReadInt32(data, &dataBlock->width)) { + HDF_LOGE("%{public}s: read dataBlock->width failed!", __func__); + return false; + } + + if (!HdfSbufReadInt32(data, &dataBlock->height)) { + HDF_LOGE("%{public}s: read dataBlock->height failed!", __func__); + return false; + } + + return true; +} + +bool AlginmentBlockMarshalling(struct HdfSBuf *data, const Alginment *dataBlock) +{ + if (!HdfSbufWriteInt32(data, dataBlock->widthAlginment)) { + HDF_LOGE("%{public}s: write dataBlock->widthAlginment failed!", __func__); + return false; + } + + if (!HdfSbufWriteInt32(data, dataBlock->heightAlginment)) { + HDF_LOGE("%{public}s: write dataBlock->heightAlginment failed!", __func__); + return false; + } + + return true; +} + +bool AlginmentBlockUnmarshalling(struct HdfSBuf *data, Alginment *dataBlock) +{ + if (dataBlock == NULL) { + return false; + } + if (!HdfSbufReadInt32(data, &dataBlock->widthAlginment)) { + HDF_LOGE("%{public}s: read dataBlock->widthAlginment failed!", __func__); + return false; + } + + if (!HdfSbufReadInt32(data, &dataBlock->heightAlginment)) { + HDF_LOGE("%{public}s: read dataBlock->heightAlginment failed!", __func__); + return false; + } + + return true; +} + +bool VideoPortCapBlockMarshalling(struct HdfSBuf *data, const VideoPortCap *dataBlock) +{ + if (!RectBlockMarshalling(data, &dataBlock->minSize)) { + HDF_LOGE("%{public}s: write dataBlock->minSize failed!", __func__); + return false; + } + + if (!RectBlockMarshalling(data, &dataBlock->maxSize)) { + HDF_LOGE("%{public}s: write dataBlock->maxSize failed!", __func__); + return false; + } + + if (!AlginmentBlockMarshalling(data, &dataBlock->whAlignment)) { + HDF_LOGE("%{public}s: write dataBlock->whAlignment failed!", __func__); + return false; + } + + if (!RangeValueBlockMarshalling(data, &dataBlock->blockCount)) { + HDF_LOGE("%{public}s: write dataBlock->blockCount failed!", __func__); + return false; + } + + if (!RangeValueBlockMarshalling(data, &dataBlock->blocksPerSecond)) { + HDF_LOGE("%{public}s: write dataBlock->blocksPerSecond failed!", __func__); + return false; + } + + if (!RectBlockMarshalling(data, &dataBlock->blockSize)) { + HDF_LOGE("%{public}s: write dataBlock->blockSize failed!", __func__); + return false; + } + + for (uint32_t i = 0; i < PIX_FORMAT_NUM; i++) { + if (!HdfSbufWriteInt32(data, (dataBlock->supportPixFmts)[i])) { + HDF_LOGE("%{public}s: write (dataBlock->supportPixFmts)[i] failed!", __func__); + return false; + } + } + + return true; +} + +bool VideoPortCapBlockUnmarshalling(struct HdfSBuf *data, VideoPortCap *dataBlock) +{ + if (dataBlock == NULL) { + return false; + } + if (!RectBlockUnmarshalling(data, &dataBlock->minSize)) { + HDF_LOGE("%{public}s: read &dataBlock->minSize failed!", __func__); + return false; + } + + if (!RectBlockUnmarshalling(data, &dataBlock->maxSize)) { + HDF_LOGE("%{public}s: read &dataBlock->maxSize failed!", __func__); + return false; + } + + if (!AlginmentBlockUnmarshalling(data, &dataBlock->whAlignment)) { + HDF_LOGE("%{public}s: read &dataBlock->whAlignment failed!", __func__); + return false; + } + + if (!RangeValueBlockUnmarshalling(data, &dataBlock->blockCount)) { + HDF_LOGE("%{public}s: read &dataBlock->blockCount failed!", __func__); + return false; + } + + if (!RangeValueBlockUnmarshalling(data, &dataBlock->blocksPerSecond)) { + HDF_LOGE("%{public}s: read &dataBlock->blocksPerSecond failed!", __func__); + return false; + } + + if (!RectBlockUnmarshalling(data, &dataBlock->blockSize)) { + HDF_LOGE("%{public}s: read &dataBlock->blockSize failed!", __func__); + return false; + } + + for (uint32_t i = 0; i < PIX_FORMAT_NUM; i++) { + if (!HdfSbufReadInt32(data, &(dataBlock->supportPixFmts)[i])) { + HDF_LOGE("%{public}s: read supportPixFmts[i] failed!", __func__); + return false; + } + } + + return true; +} + +bool AudioPortCapBlockMarshalling(struct HdfSBuf *data, const AudioPortCap *dataBlock) +{ + for (uint32_t i = 0; i < SAMPLE_FORMAT_NUM; i++) { + if (!HdfSbufWriteInt32(data, (dataBlock->sampleFormats)[i])) { + HDF_LOGE("%{public}s: write (dataBlock->sampleFormats)[i] failed!", __func__); + return false; + } + } + + for (uint32_t i = 0; i < SAMPLE_RATE_NUM; i++) { + if (!HdfSbufWriteInt32(data, (dataBlock->sampleRate)[i])) { + HDF_LOGE("%{public}s: write (dataBlock->sampleRate)[i] failed!", __func__); + return false; + } + } + + for (uint32_t i = 0; i < CHANNEL_NUM; i++) { + if (!HdfSbufWriteInt32(data, (dataBlock->channelLayouts)[i])) { + HDF_LOGE("%{public}s: write (dataBlock->channelLayouts)[i] failed!", __func__); + return false; + } + } + + for (uint32_t i = 0; i < CHANNEL_NUM; i++) { + if (!HdfSbufWriteInt32(data, (dataBlock->channelCount)[i])) { + HDF_LOGE("%{public}s: write (dataBlock->channelCount)[i] failed!", __func__); + return false; + } + } + + return true; +} + +bool AudioPortCapBlockUnmarshalling(struct HdfSBuf *data, AudioPortCap *dataBlock) +{ + if (dataBlock == NULL) { + return false; + } + + for (uint32_t i = 0; i < SAMPLE_FORMAT_NUM; i++) { + if (!HdfSbufReadInt32(data, &(dataBlock->sampleFormats)[i])) { + HDF_LOGE("%{public}s: read sampleFormats[i] failed!", __func__); + return false; + } + } + + for (uint32_t i = 0; i < SAMPLE_RATE_NUM; i++) { + if (!HdfSbufReadInt32(data, &(dataBlock->sampleRate)[i])) { + HDF_LOGE("%{public}s: read sampleRate[i] failed!", __func__); + return false; + } + } + + for (uint32_t i = 0; i < CHANNEL_NUM; i++) { + if (!HdfSbufReadInt32(data, &(dataBlock->channelLayouts)[i])) { + HDF_LOGE("%{public}s: read channelLayouts[i] failed!", __func__); + return false; + } + } + + for (uint32_t i = 0; i < CHANNEL_NUM; i++) { + if (!HdfSbufReadInt32(data, &(dataBlock->channelCount)[i])) { + HDF_LOGE("%{public}s: read channelCount[i] failed!", __func__); + return false; + } + } + + return true; +} + +void AudioPortCapFree(AudioPortCap *dataBlock, bool freeSelf) +{ + if (dataBlock == NULL) { + return; + } + + if (freeSelf) { + OsalMemFree(dataBlock); + } +} + +bool CodecCompCapabilityBlockMarshalling(struct HdfSBuf *data, const CodecCompCapability *dataBlock) +{ + if (!HdfSbufWriteInt32(data, (int32_t)dataBlock->role)) { + HDF_LOGE("%{public}s: write dataBlock->role failed!", __func__); + return false; + } + + if (!HdfSbufWriteInt32(data, (int32_t)dataBlock->type)) { + HDF_LOGE("%{public}s: write dataBlock->type failed!", __func__); + return false; + } + + for (uint32_t i = 0; i < NAME_LENGTH; i++) { + if (!HdfSbufWriteUint8(data, (uint8_t)(dataBlock->compName)[i])) { + HDF_LOGE("%{public}s: write (dataBlock->compName)[i] failed!", __func__); + return false; + } + } + + for (uint32_t i = 0; i < PROFILE_NUM; i++) { + if (!HdfSbufWriteInt32(data, (dataBlock->supportProfiles)[i])) { + HDF_LOGE("%{public}s: write (dataBlock->supportProfiles)[i] failed!", __func__); + return false; + } + } + + if (!HdfSbufWriteInt32(data, dataBlock->maxInst)) { + HDF_LOGE("%{public}s: write dataBlock->maxInst failed!", __func__); + return false; + } + + if (!HdfSbufWriteInt8(data, dataBlock->isSoftwareCodec ? 1 : 0)) { + HDF_LOGE("%{public}s: write dataBlock->isSoftwareCodec failed!", __func__); + return false; + } + + if (!HdfSbufWriteInt32(data, dataBlock->processModeMask)) { + HDF_LOGE("%{public}s: write dataBlock->processModeMask failed!", __func__); + return false; + } + + if (!HdfSbufWriteUint32(data, dataBlock->capsMask)) { + HDF_LOGE("%{public}s: write dataBlock->capsMask failed!", __func__); + return false; + } + + if (!RangeValueBlockMarshalling(data, &dataBlock->bitRate)) { + HDF_LOGE("%{public}s: write dataBlock->bitRate failed!", __func__); + return false; + } + + if (!HdfSbufWriteUnpadBuffer(data, (const uint8_t *)&dataBlock->port, sizeof(PortCap))) { + HDF_LOGE("%{public}s: write dataBlock->port failed!", __func__); + return false; + } + + return true; +} + +bool CodecCompCapabilityBlockUnmarshalling(struct HdfSBuf *data, CodecCompCapability *dataBlock) +{ + if (dataBlock == NULL) { + return false; + } + if (!HdfSbufReadInt32(data, (int32_t*)&dataBlock->role)) { + HDF_LOGE("%{public}s: read dataBlock->role failed!", __func__); + return false; + } + + if (!HdfSbufReadInt32(data, (int32_t*)&dataBlock->type)) { + HDF_LOGE("%{public}s: read dataBlock->type failed!", __func__); + return false; + } + + for (uint32_t i = 0; i < NAME_LENGTH; i++) { + if (!HdfSbufReadUint8(data, (uint8_t*)&(dataBlock->compName)[i])) { + HDF_LOGE("%{public}s: read compName[i] failed!", __func__); + return false; + } + } + + for (uint32_t j = 0; j < PROFILE_NUM; j++) { + if (!HdfSbufReadInt32(data, &(dataBlock->supportProfiles)[j])) { + HDF_LOGE("%{public}s: read supportProfiles[i] failed!", __func__); + return false; + } + } + + if (!HdfSbufReadInt32(data, &dataBlock->maxInst)) { + HDF_LOGE("%{public}s: read dataBlock->maxInst failed!", __func__); + return false; + } + + if (!HdfSbufReadInt8(data, (int8_t *)&dataBlock->isSoftwareCodec)) { + HDF_LOGE("%{public}s: read dataBlock->isSoftwareCodec failed!", __func__); + return false; + } + + if (!HdfSbufReadInt32(data, &dataBlock->processModeMask)) { + HDF_LOGE("%{public}s: read dataBlock->processModeMask failed!", __func__); + return false; + } + + if (!HdfSbufReadUint32(data, &dataBlock->capsMask)) { + HDF_LOGE("%{public}s: read dataBlock->capsMask failed!", __func__); + return false; + } + + if (!RangeValueBlockUnmarshalling(data, &dataBlock->bitRate)) { + HDF_LOGE("%{public}s: read &dataBlock->bitRate failed!", __func__); + return false; + } + + const PortCap *portCp = (const PortCap *)HdfSbufReadUnpadBuffer(data, sizeof(PortCap)); + if (portCp == NULL) { + HDF_LOGE("%{public}s: read portCp failed!", __func__); + return false; + } + (void)memcpy_s(&dataBlock->port, sizeof(PortCap), portCp, sizeof(PortCap)); + + return true; +} diff --git a/codec/interfaces/include/codec_callback_if.h b/codec/interfaces/include/codec_callback_if.h index f2fdda7c4e..70f1728446 100755 --- a/codec/interfaces/include/codec_callback_if.h +++ b/codec/interfaces/include/codec_callback_if.h @@ -19,6 +19,7 @@ #include #include #include "codec_component_type.h" +#include "OMX_Core.h" #ifdef __cplusplus extern "C" { diff --git a/codec/test/BUILD.gn b/codec/test/BUILD.gn index b4af4ead30..783a437f96 100644 --- a/codec/test/BUILD.gn +++ b/codec/test/BUILD.gn @@ -11,7 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -group("hdf_test_mediacodec") { +group("hdf_test_media_codec") { testonly = true deps = [ "unittest:hdf_unittest_codec" ] } -- Gitee From 3be197a0a5a380eed505d6ef1da15e0977513257 Mon Sep 17 00:00:00 2001 From: zhangguorong Date: Tue, 8 Mar 2022 19:48:32 +0800 Subject: [PATCH 2/2] feat: add unittest ocdec for hdf codec hdi compatible with open max Signed-off-by: zhangguorong --- codec/test/unittest/BUILD.gn | 5 +- codec/test/unittest/hdi_omx/BUILD.gn | 54 +++ .../unittest/hdi_omx/codec_hdi_omx_test.cpp | 384 ++++++++++++++++++ 3 files changed, 442 insertions(+), 1 deletion(-) create mode 100644 codec/test/unittest/hdi_omx/BUILD.gn create mode 100644 codec/test/unittest/hdi_omx/codec_hdi_omx_test.cpp diff --git a/codec/test/unittest/BUILD.gn b/codec/test/unittest/BUILD.gn index b294fa9359..d5bf08202d 100644 --- a/codec/test/unittest/BUILD.gn +++ b/codec/test/unittest/BUILD.gn @@ -13,5 +13,8 @@ group("hdf_unittest_codec") { testonly = true - deps = [ "config:codec_config_test" ] + deps = [ + "config:codec_config_test", + "hdi_omx:codec_hdi_omx_test", + ] } diff --git a/codec/test/unittest/hdi_omx/BUILD.gn b/codec/test/unittest/hdi_omx/BUILD.gn new file mode 100644 index 0000000000..ea89d5be10 --- /dev/null +++ b/codec/test/unittest/hdi_omx/BUILD.gn @@ -0,0 +1,54 @@ +# Copyright (c) 2022 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_hdi_omx_test") { + module_out_path = "hdf/codec" + include_dirs = [ + "//drivers/adapter/uhdf2/include/hdi", + "//drivers/peripheral/codec/interfaces/include", + "//drivers/peripheral/codec/hal/include", + "//third_party/openmax/api/1.1.2", + ] + sources = [ "codec_hdi_omx_test.cpp" ] + + cflags = [ + "-Wall", + "-Wextra", + "-Werror", + "-fsigned-char", + "-fno-common", + "-fno-strict-aliasing", + ] + + deps = [ + "//drivers/peripheral/codec/hal:codec_hdi_omx", + "//third_party/googletest:gtest_main", + ] + + if (is_standard_system) { + external_deps = [ + "device_driver_framework:libhdf_host", + "device_driver_framework:libhdf_ipc_adapter", + "device_driver_framework:libhdf_utils", + "device_driver_framework:libhdi", + "hiviewdfx_hilog_native:libhilog", + "utils_base:utils", + ] + } else { + external_deps = [ "hilog:libhilog" ] + } +} diff --git a/codec/test/unittest/hdi_omx/codec_hdi_omx_test.cpp b/codec/test/unittest/hdi_omx/codec_hdi_omx_test.cpp new file mode 100644 index 0000000000..534c951127 --- /dev/null +++ b/codec/test/unittest/hdi_omx/codec_hdi_omx_test.cpp @@ -0,0 +1,384 @@ +/* + * 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 +#include +#include +#include "codec_callback_type_stub.h" +#include "codec_component_type.h" +#include "codec_component_manager.h" +#include "hdf_io_service_if.h" + +#define HDF_LOG_TAG codec_hdi_test + +using namespace std; +using namespace testing::ext; + +namespace { +struct CodecComponentManager *g_manager = nullptr; +struct CodecComponentType *g_component = nullptr; +int32_t g_count = 0; + +const int32_t DATA_BUFFERID = 10; +const int32_t DATA_SIZE = 20; +const int32_t DATA_VERSION_NVERSION = 30; +const int32_t DATA_BUFFERTYPE = 40; +const int32_t DATA_BUFFERLEN = 50; +const int32_t DATA_ALLOCLEN = 60; +const int32_t DATA_FILLEDLEN = 70; +const int32_t DATA_OFFSET = 80; +const int32_t DATA_FENCEFD = 90; +const int32_t DATA_TYPE = 100; +const int32_t DATA_PTS = 200; +const int32_t DATA_FLAG = 300; +const int32_t ARRAY_TO_STR_LEN = 1000; +const int32_t INT_TO_STR_LEN = 32; + +class CodecHdiOmxTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() {} + void TearDown() {} +}; + +static void FillDataOmxCodecBuffer(struct OmxCodecBuffer *data) +{ + data->bufferId = DATA_BUFFERID; + data->size = DATA_SIZE; + data->version.nVersion = DATA_VERSION_NVERSION; + data->bufferType = (enum BufferType)DATA_BUFFERTYPE; + data->buffer = (uint8_t*)OsalMemAlloc(DATA_BUFFERLEN); + data->bufferLen = DATA_BUFFERLEN; + data->allocLen = DATA_ALLOCLEN; + data->filledLen = DATA_FILLEDLEN; + data->offset = DATA_OFFSET; + data->fenceFd = DATA_FENCEFD; + data->type = (enum ShareMemTypes)DATA_TYPE; + data->pts = DATA_PTS; + data->flag = DATA_FLAG; +} + +static char arrayStr[ARRAY_TO_STR_LEN]; +static char* GetArrayStr(int32_t *array, int32_t arrayLen, int32_t endValue) +{ + int32_t len = 0; + int32_t totalLen = 0; + int32_t ret; + char value[INT_TO_STR_LEN]; + ret = memset_s(arrayStr, sizeof(arrayStr), 0, sizeof(arrayStr)); + if (ret != EOK) { + HDF_LOGE("%{public}s: memset_s arrayStr failed, error code: %{public}d", __func__, ret); + return arrayStr; + } + for (int32_t i = 0; i < arrayLen; i++) { + if (array[i] == endValue) { + break; + } + ret = memset_s(value, sizeof(value), 0, sizeof(value)); + if (ret != EOK) { + HDF_LOGE("%{public}s: memset_s value failed, error code: %{public}d", __func__, ret); + return arrayStr; + } + ret = sprintf_s(value, sizeof(value) - 1, "0x0%X, ", array[i]); + if (ret < 0) { + HDF_LOGE("%{public}s: sprintf_s value failed, error code: %{public}d", __func__, ret); + return arrayStr; + } + len = strlen(value); + ret = memcpy_s(arrayStr + totalLen, len, value, len); + if (ret != EOK) { + HDF_LOGE("%{public}s: memcpy_s arrayStr failed, error code: %{public}d", __func__, ret); + return arrayStr; + } + totalLen += len; + } + return arrayStr; +} + +static void PrintCapability(CodecCompCapability *cap, int32_t index) +{ + HDF_LOGI("---------------------- component capability %{public}d ---------------------", index + 1); + HDF_LOGI("role:%{public}d", cap->role); + HDF_LOGI("type:%{public}d", cap->type); + HDF_LOGI("compName:%{public}s", cap->compName); + HDF_LOGI("supportProfiles:%{public}s", GetArrayStr(cap->supportProfiles, PROFILE_NUM, INVALID_PROFILE)); + HDF_LOGI("maxInst:%{public}d", cap->maxInst); + HDF_LOGI("isSoftwareCodec:%{public}d", cap->isSoftwareCodec); + HDF_LOGI("processModeMask:0x0%{public}x", cap->processModeMask); + HDF_LOGI("capsMask:0x0%{public}x", cap->capsMask); + HDF_LOGI("bitRate.min:%{public}d", cap->bitRate.min); + HDF_LOGI("bitRate.max:%{public}d", cap->bitRate.max); + if (strstr(cap->compName, "video") != NULL) { + HDF_LOGI("minSize.width:%{public}d", cap->port.video.minSize.width); + HDF_LOGI("minSize.height:%{public}d", cap->port.video.minSize.height); + HDF_LOGI("maxSize.width:%{public}d", cap->port.video.maxSize.width); + HDF_LOGI("maxSize.height:%{public}d", cap->port.video.maxSize.height); + HDF_LOGI("widthAlginment:%{public}d", cap->port.video.whAlignment.widthAlginment); + HDF_LOGI("heightAlginment:%{public}d", cap->port.video.whAlignment.heightAlginment); + HDF_LOGI("blockCount.min:%{public}d", cap->port.video.blockCount.min); + HDF_LOGI("blockCount.max:%{public}d", cap->port.video.blockCount.max); + HDF_LOGI("blocksPerSecond.min:%{public}d", cap->port.video.blocksPerSecond.min); + HDF_LOGI("blocksPerSecond.max:%{public}d", cap->port.video.blocksPerSecond.max); + HDF_LOGI("blockSize.width:%{public}d", cap->port.video.blockSize.width); + HDF_LOGI("blockSize.height:%{public}d", cap->port.video.blockSize.height); + HDF_LOGI("supportPixFmts:%{public}s", GetArrayStr(cap->port.video.supportPixFmts, PIX_FORMAT_NUM, 0)); + } else { + HDF_LOGI(":%{public}s", GetArrayStr(cap->port.audio.sampleFormats, SAMPLE_FMT_NUM, AUDIO_SAMPLE_FMT_INVALID)); + HDF_LOGI(":%{public}s", GetArrayStr(cap->port.audio.sampleRate, SAMPLE_RATE_NUM, AUD_SAMPLE_RATE_INVALID)); + HDF_LOGI(":%{public}s", GetArrayStr(cap->port.audio.channelLayouts, CHANNEL_NUM, -1)); + HDF_LOGI(":%{public}s", GetArrayStr(cap->port.audio.channelCount, CHANNEL_NUM, -1)); + } + HDF_LOGI("-------------------------------------------------------------------"); +} + +HWTEST_F(CodecHdiOmxTest, HdfCodecHdiOmxTest_001, TestSize.Level1) +{ + const int32_t componentCount = 9; + g_manager = GetCodecComponentManager(); + ASSERT_TRUE(g_manager != nullptr); + + g_count = g_manager->GetComponentNum(); + ASSERT_EQ(g_count, componentCount); +} + +HWTEST_F(CodecHdiOmxTest, HdfCodecHdiOmxTest_002, TestSize.Level1) +{ + ASSERT_TRUE(g_count > 0); + CodecCompCapability *capList = (CodecCompCapability *)OsalMemAlloc(sizeof(CodecCompCapability) * g_count); + g_manager->GetComponentCapabilityList(capList, g_count); + for (int32_t i = 0; i < g_count; i++) { + PrintCapability(&capList[i], i); + } +} + +HWTEST_F(CodecHdiOmxTest, HdfCodecHdiOmxTest_003, TestSize.Level1) +{ + const int32_t testingAppData = 33; + CodecCallbackType* callback = CodecCallbackTypeStubGetInstance(); + int32_t appData = testingAppData; + int32_t ret = g_manager->CreateComponent(&g_component, (char*)"compName", &appData, sizeof(appData), callback); + HDF_LOGE("%{public}s: after CreateComponent!", __func__); + ASSERT_EQ(ret, HDF_SUCCESS); + ASSERT_TRUE(g_component != nullptr); +} + +HWTEST_F(CodecHdiOmxTest, HdfCodecHdiOmxTest_004, TestSize.Level1) +{ + const int32_t componentNameLength = 128; + const int32_t componentUuidLength = 128; + const uint32_t compVersionNum = 10; + const uint32_t specVersionNum = 1; + const uint8_t uuidValue = 127; + char compName[componentNameLength]; + OMX_VERSIONTYPE compVersion; + OMX_VERSIONTYPE specVersion; + unsigned char compUuid[componentUuidLength]; + int32_t ret = g_component->GetComponentVersion(g_component, compName, &compVersion, &specVersion, + compUuid, componentUuidLength); + ASSERT_EQ(ret, HDF_SUCCESS); + ASSERT_EQ(compVersion.nVersion, compVersionNum); + ASSERT_EQ(specVersion.nVersion, specVersionNum); + ASSERT_EQ(compUuid[0], uuidValue); +} + +HWTEST_F(CodecHdiOmxTest, HdfCodecHdiOmxTest_005, TestSize.Level1) +{ + const uint32_t param = 101; + const int8_t dataLen = 10; + OMX_COMMANDTYPE cmd = OMX_CommandStateSet; + int8_t cmdData[dataLen]; + for (int8_t i = 0; i < dataLen; i++) { + cmdData[i] = i; + } + int32_t ret = g_component->SendCommand(g_component, cmd, param, cmdData, (uint32_t)dataLen); + ASSERT_EQ(ret, HDF_SUCCESS); +} + +HWTEST_F(CodecHdiOmxTest, HdfCodecHdiOmxTest_006, TestSize.Level1) +{ + const uint32_t paramLen = 5; + const int8_t paramValue = 3; + int8_t param[paramLen]; + param[1] = 1; + int32_t ret = g_component->GetParameter(g_component, OMX_IndexParamAudioInit, param, paramLen); + ASSERT_EQ(param[0], paramValue); + ASSERT_EQ(ret, HDF_SUCCESS); +} + +HWTEST_F(CodecHdiOmxTest, HdfCodecHdiOmxTest_007, TestSize.Level1) +{ + const uint32_t paramLen = 5; + int8_t param[paramLen]; + param[1] = 1; + int32_t ret = g_component->SetParameter(g_component, OMX_IndexParamAudioInit, param, paramLen); + ASSERT_EQ(ret, HDF_SUCCESS); +} + +HWTEST_F(CodecHdiOmxTest, HdfCodecHdiOmxTest_008, TestSize.Level1) +{ + const uint32_t configLen = 5; + const int8_t configValue = 3; + int8_t config[configLen]; + config[1] = 1; + int32_t ret = g_component->GetConfig(g_component, OMX_IndexParamAudioInit, config, configLen); + ASSERT_EQ(config[0], configValue); + ASSERT_EQ(ret, HDF_SUCCESS); +} + +HWTEST_F(CodecHdiOmxTest, HdfCodecHdiOmxTest_009, TestSize.Level1) +{ + const uint32_t configLen = 5; + int8_t config[configLen]; + config[1] = 1; + int32_t ret = g_component->SetConfig(g_component, OMX_IndexParamAudioInit, config, configLen); + ASSERT_EQ(ret, HDF_SUCCESS); +} + +HWTEST_F(CodecHdiOmxTest, HdfCodecHdiOmxTest_010, TestSize.Level1) +{ + OMX_INDEXTYPE indexType; + int32_t ret = g_component->GetExtensionIndex(g_component, "prarmName", (uint32_t *)&indexType); + ASSERT_EQ(indexType, OMX_IndexParamNumAvailableStreams); + ASSERT_EQ(ret, HDF_SUCCESS); +} + +HWTEST_F(CodecHdiOmxTest, HdfCodecHdiOmxTest_011, TestSize.Level1) +{ + OMX_STATETYPE state; + int32_t ret = g_component->GetState(g_component, &state); + ASSERT_EQ(state, OMX_StateLoaded); + ASSERT_EQ(ret, HDF_SUCCESS); +} + +HWTEST_F(CodecHdiOmxTest, HdfCodecHdiOmxTest_012, TestSize.Level1) +{ + const uint32_t portNum = 11; + const int32_t tunneledComp = 1002; + const uint32_t tunneledPort = 101; + const uint32_t tunnelFlags = 1200; + OMX_TUNNELSETUPTYPE tunnelSetup; + tunnelSetup.eSupplier = OMX_BufferSupplyInput; + + int32_t ret = g_component->ComponentTunnelRequest(g_component, portNum, tunneledComp, tunneledPort, &tunnelSetup); + ASSERT_EQ(tunnelSetup.nTunnelFlags, tunnelFlags); + ASSERT_EQ(ret, HDF_SUCCESS); +} + +HWTEST_F(CodecHdiOmxTest, HdfCodecHdiOmxTest_013, TestSize.Level1) +{ + const uint32_t portIndex = 101; + const uint32_t bufferId = 11; + struct OmxCodecBuffer buffer; + FillDataOmxCodecBuffer(&buffer); + int32_t ret = g_component->UseBuffer(g_component, portIndex, &buffer); + ASSERT_EQ(buffer.bufferId, bufferId); + ASSERT_EQ(ret, HDF_SUCCESS); +} + +HWTEST_F(CodecHdiOmxTest, HdfCodecHdiOmxTest_014, TestSize.Level1) +{ + const uint32_t portIndex = 101; + const uint32_t bufferId = 11; + struct OmxCodecBuffer buffer; + FillDataOmxCodecBuffer(&buffer); + int32_t ret = g_component->AllocateBuffer(g_component, &buffer, portIndex); + ASSERT_EQ(buffer.bufferId, bufferId); + ASSERT_EQ(ret, HDF_SUCCESS); +} + +HWTEST_F(CodecHdiOmxTest, HdfCodecHdiOmxTest_015, TestSize.Level1) +{ + const uint32_t portIndex = 101; + struct OmxCodecBuffer buffer; + FillDataOmxCodecBuffer(&buffer); + int32_t ret = g_component->FreeBuffer(g_component, portIndex, &buffer); + ASSERT_EQ(ret, HDF_SUCCESS); +} + +HWTEST_F(CodecHdiOmxTest, HdfCodecHdiOmxTest_016, TestSize.Level1) +{ + struct OmxCodecBuffer buffer; + FillDataOmxCodecBuffer(&buffer); + int32_t ret = g_component->EmptyThisBuffer(g_component, &buffer); + ASSERT_EQ(ret, HDF_SUCCESS); +} + +HWTEST_F(CodecHdiOmxTest, HdfCodecHdiOmxTest_017, TestSize.Level1) +{ + struct OmxCodecBuffer buffer; + FillDataOmxCodecBuffer(&buffer); + int32_t ret = g_component->FillThisBuffer(g_component, &buffer); + ASSERT_EQ(ret, HDF_SUCCESS); +} + +HWTEST_F(CodecHdiOmxTest, HdfCodecHdiOmxTest_018, TestSize.Level1) +{ + const int32_t appDataLen = 10; + CodecCallbackType* callback = CodecCallbackTypeStubGetInstance(); + int8_t appData[appDataLen]; + for (int8_t i = 0; i < appDataLen; i++) { + appData[i] = i; + } + int32_t ret = g_component->SetCallbacks(g_component, callback, appData, (uint32_t)appDataLen); + ASSERT_EQ(ret, HDF_SUCCESS); +} + +HWTEST_F(CodecHdiOmxTest, HdfCodecHdiOmxTest_019, TestSize.Level1) +{ + int32_t ret = g_component->ComponentDeInit(g_component); + ASSERT_EQ(ret, HDF_SUCCESS); +} + +HWTEST_F(CodecHdiOmxTest, HdfCodecHdiOmxTest_020, TestSize.Level1) +{ + const int32_t eglImgDataLen = 10; + const uint32_t portIndex = 101; + const uint32_t bufferId = 11; + struct OmxCodecBuffer buffer; + FillDataOmxCodecBuffer(&buffer); + int8_t eglImg[eglImgDataLen]; + for (int8_t i = 0; i < eglImgDataLen; i++) { + eglImg[i] = i; + } + int32_t ret = g_component->UseEglImage(g_component, &buffer, portIndex, eglImg, (uint32_t)eglImgDataLen); + ASSERT_EQ(buffer.bufferId, bufferId); + ASSERT_EQ(ret, HDF_SUCCESS); +} + +HWTEST_F(CodecHdiOmxTest, HdfCodecHdiOmxTest_021, TestSize.Level1) +{ + const uint32_t roleLen = 3; + const uint32_t roleIndex = 102; + uint8_t role[roleLen]; + int32_t ret = g_component->ComponentRoleEnum(g_component, role, roleLen, roleIndex); + int32_t index = 0; + ASSERT_EQ(role[index], index + 1); + index++; + ASSERT_EQ(role[index], index + 1); + index++; + ASSERT_EQ(role[index], index + 1); + ASSERT_EQ(ret, HDF_SUCCESS); +} + +HWTEST_F(CodecHdiOmxTest, HdfCodecHdiOmxTest_022, TestSize.Level1) +{ + int32_t ret = g_manager->DestoryComponent(g_component); + ASSERT_EQ(ret, HDF_SUCCESS); + CodecComponentManagerRelease(); +} +} -- Gitee