1 /* 2 * Copyright 2022 Shenzhen Kaihong DID Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef COMPONENT_NODE_H 16 #define COMPONENT_NODE_H 17 #include <OMX_Component.h> 18 #include <OMX_Core.h> 19 #include <OMX_Types.h> 20 #include <map> 21 #include <memory> 22 #include <nocopyable.h> 23 #include <osal_mem.h> 24 #include <vector> 25 #include "icodec_buffer.h" 26 #include "v1_0/icodec_callback.h" 27 #include "v1_0/icodec_component.h" 28 #include "component_mgr.h" 29 using OHOS::HDI::Codec::V1_0::CompVerInfo; 30 using OHOS::HDI::Codec::V1_0::ICodecCallback; 31 using OHOS::HDI::Codec::V1_0::OmxCodecBuffer; 32 namespace OHOS { 33 namespace Codec { 34 namespace Omx { 35 class ComponentNode : NoCopyable { 36 public: 37 ComponentNode(const sptr<ICodecCallback> &callbacks, int64_t appData, std::shared_ptr<ComponentMgr>& mgr); 38 ~ComponentNode(); 39 int32_t OpenHandle(const std::string& name); 40 int32_t GetComponentVersion(CompVerInfo &verInfo); 41 int32_t SendCommand(OHOS::HDI::Codec::V1_0::OMX_COMMANDTYPE cmd, uint32_t param, int8_t *cmdData); 42 int32_t GetParameter(OMX_INDEXTYPE paramIndex, int8_t *param); 43 int32_t SetParameter(OMX_INDEXTYPE paramIndex, const int8_t *param); 44 int32_t GetConfig(OMX_INDEXTYPE index, int8_t *config); 45 int32_t SetConfig(OMX_INDEXTYPE index, const int8_t *config); 46 int32_t GetExtensionIndex(const char *parameterName, uint32_t& index); 47 int32_t GetState(OHOS::HDI::Codec::V1_0::OMX_STATETYPE &state); 48 int32_t ComponentTunnelRequest(uint32_t port, int32_t omxHandleTypeTunneledComp, uint32_t tunneledPort, 49 OHOS::HDI::Codec::V1_0::OMX_TUNNELSETUPTYPE &tunnelSetup); 50 int32_t UseBuffer(uint32_t portIndex, OmxCodecBuffer &buffer); 51 int32_t AllocateBuffer(uint32_t portIndex, OmxCodecBuffer &buffer); 52 int32_t FreeBuffer(uint32_t portIndex, const OmxCodecBuffer &buffer); 53 int32_t EmptyThisBuffer(OmxCodecBuffer &buffer); 54 int32_t FillThisBuffer(OmxCodecBuffer &buffer); 55 int32_t SetCallbacks(const sptr<ICodecCallback> &callbacks, int64_t appData); 56 int32_t UseEglImage(struct OmxCodecBuffer &buffer, uint32_t portIndex, const int8_t *eglImage); 57 int32_t ComponentRoleEnum(std::vector<uint8_t> &role, uint32_t index); 58 int32_t ComponentDeInit(); 59 OMX_ERRORTYPE static OnEvent(OMX_HANDLETYPE component, void *appData, OMX_EVENTTYPE event, uint32_t data1, 60 uint32_t data2, void *eventData); 61 OMX_ERRORTYPE static OnEmptyBufferDone(OMX_HANDLETYPE component, void *appData, OMX_BUFFERHEADERTYPE *buffer); 62 OMX_ERRORTYPE static OnFillBufferDone(OMX_HANDLETYPE component, void *appData, OMX_BUFFERHEADERTYPE *buffer); 63 64 public: 65 static OMX_CALLBACKTYPE callbacks_; // callbacks 66 67 private: 68 int32_t OnEvent(OMX_EVENTTYPE event, uint32_t data1, uint32_t data2, void *eventData); 69 int32_t OnEmptyBufferDone(OMX_BUFFERHEADERTYPE *buffer); 70 int32_t OnFillBufferDone(OMX_BUFFERHEADERTYPE *buffer); 71 uint32_t GenerateBufferId(); 72 sptr<ICodecBuffer> GetBufferInfoByHeader(OMX_BUFFERHEADERTYPE *buffer); 73 bool GetBufferById(uint32_t bufferId, sptr<ICodecBuffer> &codecBuffer, OMX_BUFFERHEADERTYPE *&bufferHdrType); 74 void ReleaseCodecBuffer(struct OmxCodecBuffer &buffer); 75 private: 76 OMX_HANDLETYPE comp_; // Compnent handle 77 sptr<ICodecCallback> omxCallback_; 78 int64_t appData_; 79 std::map<uint32_t, sptr<ICodecBuffer>> codecBufferMap_; // Key is buffferID 80 std::map<OMX_BUFFERHEADERTYPE *, uint32_t> bufferHeaderMap_; // Key is omx buffer header type 81 uint32_t bufferIdCount_; 82 std::shared_ptr<ComponentMgr> mgr_; 83 }; 84 } // namespace Omx 85 } // namespace Codec 86 } // namespace OHOS 87 #endif /* COMPONENT_NODE_H */