diff --git a/codec/hal/idl_service/include/codec_component_config.h b/codec/hal/idl_service/include/codec_component_config.h index 47f20ed8d36160c258b4c3626cda3e1c8ddd83e7..29cf4d44e65bedfac4934368a95dda803da98cfa 100644 --- a/codec/hal/idl_service/include/codec_component_config.h +++ b/codec/hal/idl_service/include/codec_component_config.h @@ -14,6 +14,7 @@ */ #ifndef CODEC_CONFIG_H +#define CODEC_CONFIG_H #include #include "v1_0/codec_types.h" #include "device_resource_if.h" @@ -23,7 +24,7 @@ namespace Codec { namespace Omx { typedef struct { std::string attrName; - int32_t &value; + int32_t value; uint32_t defaultValue; } ConfigUintNodeAttr; typedef struct { @@ -66,5 +67,4 @@ private: } // namespace Omx } // namespace Codec } // namespace OHOS -#define CODEC_CONFIG_H #endif // CODEC_CONFIG_H \ No newline at end of file diff --git a/codec/hal/idl_service/include/codec_component_service.h b/codec/hal/idl_service/include/codec_component_service.h index d25c01758c383292a16524a573030e2013f38699..ba1ba4092d88d4e17a99585ef75c4a03878fd05d 100644 --- a/codec/hal/idl_service/include/codec_component_service.h +++ b/codec/hal/idl_service/include/codec_component_service.h @@ -51,7 +51,7 @@ public: const std::vector &eglImage) override; int32_t ComponentRoleEnum(std::vector &role, uint32_t index) override; - std::string &GetComponentCompName(); + const std::string &GetComponentCompName() const; void GetComponentNode(std::shared_ptr &dumpNode_); private: void SetComponentRole(); diff --git a/codec/hal/idl_service/include/codec_dfx_service.h b/codec/hal/idl_service/include/codec_dfx_service.h index a1f622cac4b50d97b15fef8b7e38d754c91a11a9..bba06008afcb91c1411b21871ea889be411d5461 100644 --- a/codec/hal/idl_service/include/codec_dfx_service.h +++ b/codec/hal/idl_service/include/codec_dfx_service.h @@ -33,7 +33,6 @@ public: static CodecDfxService &GetInstance(); static HdfSBuf* GetReply(); void SetComponentManager(sptr manager); - static void GetBuffCount(); static int32_t DevCodecHostDump(struct HdfSBuf *data, struct HdfSBuf *reply); static int32_t GetCodecComponentListInfo(struct HdfSBuf *reply); static void GetCodecMemoryInfo(); @@ -42,10 +41,9 @@ protected: CodecDfxService() = default; private: - static uint32_t inputBuffCount; - static uint32_t outputBuffCount; + void GetBuffCount(const std::shared_ptr &dumpNode, + uint32_t &inputBuffCount, uint32_t &outputBuffCount); sptr managerService_; - static std::shared_ptr dumpNode; static CodecDfxService dfxInstance_; static HdfSBuf *reply_; }; diff --git a/codec/hal/idl_service/include/component_node.h b/codec/hal/idl_service/include/component_node.h index 2feb8c604bba51c97206cb1b5e6934614227ab0e..0bdde1aa62c6af470efd3dca57b0b6d93b272fce 100644 --- a/codec/hal/idl_service/include/component_node.h +++ b/codec/hal/idl_service/include/component_node.h @@ -63,7 +63,7 @@ public: uint32_t data2, void *eventData); OMX_ERRORTYPE static OnEmptyBufferDone(OMX_HANDLETYPE component, void *appData, OMX_BUFFERHEADERTYPE *buffer); OMX_ERRORTYPE static OnFillBufferDone(OMX_HANDLETYPE component, void *appData, OMX_BUFFERHEADERTYPE *buffer); - std::map &GetBufferMapCount(); + const std::map &GetBufferMapCount(); void ReleaseOMXResource(); public: diff --git a/codec/hal/idl_service/include/icodec_buffer.h b/codec/hal/idl_service/include/icodec_buffer.h index bfa51e01609d0a4b141edd4b5024a3c0bf467739..398f4638d67945c03b7c657cf89b2b2637555a8a 100644 --- a/codec/hal/idl_service/include/icodec_buffer.h +++ b/codec/hal/idl_service/include/icodec_buffer.h @@ -43,6 +43,11 @@ struct DynamicBuffer { } bufferHandle = nullptr; } + + DynamicBuffer(const DynamicBuffer& other) = delete; + DynamicBuffer(DynamicBuffer&& other) = delete; + DynamicBuffer& operator=(const DynamicBuffer& other) = delete; + DynamicBuffer& operator=(DynamicBuffer&& other) = delete; }; class ICodecBuffer : public RefBase { diff --git a/codec/hal/idl_service/src/codec_component_config.cpp b/codec/hal/idl_service/src/codec_component_config.cpp index 471cdfb6bfa61b8f80040727e6ad0fd3456ceacf..001d39115de6ac9cd8945151e9de63cef1a2e588 100644 --- a/codec/hal/idl_service/src/codec_component_config.cpp +++ b/codec/hal/idl_service/src/codec_component_config.cpp @@ -85,10 +85,10 @@ CodecComponentConfig::CodecComponentConfig() void CodecComponentConfig::Init(const DeviceResourceNode &node) { node_ = node; - std::string 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}; + const std::string 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 }; int count = sizeof(codecGroupsNodeName) / sizeof(std::string); for (int index = 0; index < count; index++) { if (GetGroupCapabilities(codecGroupsNodeName[index]) != HDF_SUCCESS) { @@ -146,16 +146,16 @@ int32_t CodecComponentConfig::GetComponentCapabilityList(std::vectorGetUint32 == nullptr) || (iface->GetBool == nullptr) || (iface->GetString == nullptr)) { + CODEC_LOGE(" failed, iface or its GetUint32 or GetBool or GetString is nullptr!"); return HDF_ERR_INVALID_PARAM; } codecGroupNode = iface->GetChildNode(&node_, nodeName.c_str()); - if (codecGroupNode == NULL) { + if (codecGroupNode == nullptr) { CODEC_LOGE("failed to get child node: %{public}s!", nodeName.c_str()); return HDF_FAILURE; } @@ -177,8 +177,7 @@ int32_t CodecComponentConfig::GetGroupCapabilities(const std::string &nodeName) } int32_t CodecComponentConfig::GetOneCapability(const struct DeviceResourceIface &iface, - const struct DeviceResourceNode &childNode, CodecCompCapability &cap, - bool isVideoGroup) + const struct DeviceResourceNode &childNode, CodecCompCapability &cap, bool isVideoGroup) { if (iface.GetUint32(&childNode, CODEC_CONFIG_KEY_ROLE, reinterpret_cast(&cap.role), MEDIA_ROLETYPE_INVALID) != HDF_SUCCESS) { @@ -186,7 +185,6 @@ int32_t CodecComponentConfig::GetOneCapability(const struct DeviceResourceIface CODEC_LOGE("failed to get mime for: %{public}s! Discarded", childNode.name); return HDF_FAILURE; } - if (iface.GetUint32(&childNode, CODEC_CONFIG_KEY_TYPE, reinterpret_cast(&cap.type), INVALID_TYPE) != HDF_SUCCESS) { cap.role = MEDIA_ROLETYPE_INVALID; @@ -195,15 +193,15 @@ int32_t CodecComponentConfig::GetOneCapability(const struct DeviceResourceIface return HDF_FAILURE; } - const char *compName = NULL; + const char *compName = nullptr; if (iface.GetString(&childNode, CODEC_CONFIG_KEY_NAME, &compName, "") != HDF_SUCCESS) { cap.role = MEDIA_ROLETYPE_INVALID; CODEC_LOGE("get attr %{public}s err!", CODEC_CONFIG_KEY_NAME); return HDF_FAILURE; } - if (compName == NULL || strlen(compName) == 0) { + if (compName == nullptr || strlen(compName) == 0) { cap.role = MEDIA_ROLETYPE_INVALID; - CODEC_LOGE("compName is null or empty!"); + CODEC_LOGE("compName is nullptr or empty!"); return HDF_FAILURE; } cap.compName = compName; @@ -216,7 +214,6 @@ int32_t CodecComponentConfig::GetOneCapability(const struct DeviceResourceIface CODEC_LOGE("get misc cap err!"); return HDF_FAILURE; } - if (isVideoGroup) { if (GetVideoPortCapability(iface, childNode, cap) != HDF_SUCCESS) { cap.role = MEDIA_ROLETYPE_INVALID; diff --git a/codec/hal/idl_service/src/codec_component_service.cpp b/codec/hal/idl_service/src/codec_component_service.cpp index 82dceeee7ec94bfcabc58c89623dadd9ec2e4aca..6abd1140b1ad7e3e734b8f6876116c18a9f3c6f5 100644 --- a/codec/hal/idl_service/src/codec_component_service.cpp +++ b/codec/hal/idl_service/src/codec_component_service.cpp @@ -212,7 +212,7 @@ void CodecComponentService::SetComponentRole() } } -std::string &CodecComponentService::GetComponentCompName() +const std::string &CodecComponentService::GetComponentCompName() const { return name_; } diff --git a/codec/hal/idl_service/src/codec_death_recipient.cpp b/codec/hal/idl_service/src/codec_death_recipient.cpp index f77e5f692d3171b6a08dd915eaf4eec3c741c99a..90c636cea1733fc2a9bee9a4bdc06a6c1f8b2be9 100644 --- a/codec/hal/idl_service/src/codec_death_recipient.cpp +++ b/codec/hal/idl_service/src/codec_death_recipient.cpp @@ -76,6 +76,7 @@ void RegisterDeathRecipientService(const sptr callbacks, uint32_ void RemoveMapperOfDestoryedComponent(uint32_t componentId) { + std::lock_guard lk(g_mutex); auto compRemote = g_compRemoteMap.find(componentId); if (compRemote == g_compRemoteMap.end()) { return; diff --git a/codec/hal/idl_service/src/codec_dfx_service.cpp b/codec/hal/idl_service/src/codec_dfx_service.cpp index 394a0b48d53dbd1c4e797f76030050f702216375..02c437dba58e3694cf36ebdc99f986c9d91d5bf5 100644 --- a/codec/hal/idl_service/src/codec_dfx_service.cpp +++ b/codec/hal/idl_service/src/codec_dfx_service.cpp @@ -24,11 +24,9 @@ namespace V1_0 { #define INPUT_PORT_INDEX 0 #define OUTPUT_PORT_INDEX 1 CodecDfxService CodecDfxService::dfxInstance_; -uint32_t CodecDfxService::inputBuffCount; -uint32_t CodecDfxService::outputBuffCount; -std::shared_ptr CodecDfxService::dumpNode; HdfSBuf *CodecDfxService::reply_; -void CodecDfxService::GetBuffCount() +void CodecDfxService::GetBuffCount(const std::shared_ptr &dumpNode, + uint32_t &inputBuffCount, uint32_t &outputBuffCount) { auto iter = dumpNode->GetBufferMapCount().begin(); while (iter != dumpNode->GetBufferMapCount().end()) { @@ -44,6 +42,9 @@ void CodecDfxService::GetBuffCount() int32_t CodecDfxService::GetCodecComponentListInfo(struct HdfSBuf *reply) { CodecStateType state; + uint32_t inputBuffCount = 0; + uint32_t outputBuffCount = 0; + std::shared_ptr dumpNode = nullptr; std::map> dumpMap = {}; GetInstance().managerService_->GetManagerMap(dumpMap); @@ -61,7 +62,7 @@ int32_t CodecDfxService::GetCodecComponentListInfo(struct HdfSBuf *reply) componentService->GetComponentNode(dumpNode); dumpNode->GetState(state); dump.append(std::to_string(state)); - GetInstance().GetBuffCount(); + GetInstance().GetBuffCount(dumpNode, inputBuffCount, outputBuffCount); dump.append(", inputPortIndex = ") .append(std::to_string(INPUT_PORT_INDEX)) .append(", inputBuffCount = ") @@ -130,6 +131,10 @@ int32_t CodecDfxService::DevCodecHostDump(struct HdfSBuf *data, struct HdfSBuf * } const char *para = HdfSbufReadString(data); + if (para == nullptr) { + CODEC_LOGE("read string data failed"); + return HDF_ERR_INVALID_PARAM; + } if (strcmp(para, "-h") == EOK) { if (!HdfSbufWriteString(reply, "-h: codec dump help! \n")) { CODEC_LOGE("-h write Fail!"); diff --git a/codec/hal/idl_service/src/codec_omx_core.cpp b/codec/hal/idl_service/src/codec_omx_core.cpp index 266c5feac0299273394d3118de408759909d178b..115d1b3453c8168b17f7fa05f4227e78135a7dfd 100644 --- a/codec/hal/idl_service/src/codec_omx_core.cpp +++ b/codec/hal/idl_service/src/codec_omx_core.cpp @@ -78,6 +78,10 @@ int32_t CodecOMXCore::GetHandle(OMX_HANDLETYPE &handle, std::string &compName, O CODEC_LOGE("getHandle_ is nullptr."); return HDF_ERR_INVALID_PARAM; } + if (compName.empty()) { + CODEC_LOGE("invalid component name"); + return HDF_ERR_INVALID_PARAM; + } return (*getHandle_)(&handle, const_cast(compName.c_str()), appData, (OMX_CALLBACKTYPE *)&callbacks); } @@ -109,6 +113,10 @@ int32_t CodecOMXCore::GetRolesOfComponent(std::string &name, std::vector(name.c_str()), &roleCount, nullptr); if (err != HDF_SUCCESS) { diff --git a/codec/hal/idl_service/src/component_node.cpp b/codec/hal/idl_service/src/component_node.cpp index 756d82e3c89305d4500c72d9a16fb6db1c9a2499..5b6e07b6eb59a46ebbff7a20658053cfa86e60fa 100644 --- a/codec/hal/idl_service/src/component_node.cpp +++ b/codec/hal/idl_service/src/component_node.cpp @@ -567,17 +567,18 @@ void ComponentNode::WaitStateChange(CodecStateType objState, CodecStateType &sta { int32_t ret = GetState(status); uint32_t count = 0; - while (status != objState && count++ < maxStateWaitCount) { + while (status != objState && count < maxStateWaitCount) { usleep(maxStateWaitTime); ret = GetState(status); if (ret != HDF_SUCCESS) { HDF_LOGE("%{public}s: GetState error [%{public}x]", __func__, ret); return; } + count++; } } -std::map &ComponentNode::GetBufferMapCount() +const std::map &ComponentNode::GetBufferMapCount() { return portIndexMap_; } @@ -588,7 +589,7 @@ void ComponentNode::ReleaseOMXResource() return; } CodecStateType status = CODEC_STATE_INVALID; - int32_t ret = GetState(status); + int32_t ret = 0; if (ret != HDF_SUCCESS) { HDF_LOGE("ReleaseOMXResource GetState error [%{public}x]", ret); return; @@ -599,7 +600,7 @@ void ComponentNode::ReleaseOMXResource() } if (status == CODEC_STATE_IDLE) { SendCommand(CODEC_COMMAND_STATE_SET, CODEC_STATE_LOADED, NULL); - auto ret = ReleaseAllBuffer(); + ret = ReleaseAllBuffer(); if (ret != HDF_SUCCESS) { HDF_LOGE("ReleaseAllBuffer err [%{public}x]", ret); return; diff --git a/codec/hal/v2.0/hdi_impl/src/codec_omx_core.cpp b/codec/hal/v2.0/hdi_impl/src/codec_omx_core.cpp index 2bf54461a7bc4f315dd03c7aa9f9936929c2c788..27f7def974b8b04e40a83eceb7c74010c2ae11fb 100644 --- a/codec/hal/v2.0/hdi_impl/src/codec_omx_core.cpp +++ b/codec/hal/v2.0/hdi_impl/src/codec_omx_core.cpp @@ -77,6 +77,10 @@ int32_t CodecOMXCore::GetHandle(OMX_HANDLETYPE &handle, std::string &compName, O CODEC_LOGE("getHandle is null."); return HDF_ERR_INVALID_PARAM; } + if (compName.empty()) { + CODEC_LOGE("invalid component name"); + return HDF_ERR_INVALID_PARAM; + } return (*getHandle_)(&handle, const_cast(compName.c_str()), appData, (OMX_CALLBACKTYPE *)&callbacks); } @@ -109,6 +113,10 @@ int32_t CodecOMXCore::GetRolesOfComponent(std::string &name, std::vector(name.c_str()), &roleCount, nullptr); if (err != HDF_SUCCESS) { diff --git a/codec/image/hdi_service/src/codec_image_driver.cpp b/codec/image/hdi_service/src/codec_image_driver.cpp index 5a2a5413202912c6b4ee211d7c14f9cc9f2d378d..53e4554610fb1b1e9ee3abc18367cfc8710680b4 100644 --- a/codec/image/hdi_service/src/codec_image_driver.cpp +++ b/codec/image/hdi_service/src/codec_image_driver.cpp @@ -101,7 +101,7 @@ static void HdfCodecImageDriverRelease(struct HdfDeviceObject *deviceObject) } } -struct HdfDriverEntry g_CodecImageDriverEntry = { +static struct HdfDriverEntry g_CodecImageDriverEntry = { .moduleVersion = 1, .moduleName = "libcodec_image_service", .Bind = HdfCodecImageDriverBind,