• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 <shared_mutex>
23 #include <nocopyable.h>
24 #include <osal_mem.h>
25 #include <vector>
26 #include "icodec_buffer.h"
27 #include "v1_0/icodec_callback.h"
28 #include "v1_0/icodec_component.h"
29 #include "component_mgr.h"
30 using OHOS::HDI::Codec::V1_0::CompVerInfo;
31 using OHOS::HDI::Codec::V1_0::ICodecCallback;
32 using OHOS::HDI::Codec::V1_0::OmxCodecBuffer;
33 namespace OHOS {
34 namespace Codec {
35 namespace Omx {
36 class ComponentNode : NoCopyable {
37 public:
38     ComponentNode(const sptr<ICodecCallback> &callbacks, int64_t appData, std::shared_ptr<ComponentMgr>& mgr);
39     ~ComponentNode();
40     int32_t OpenHandle(const std::string& name);
41     int32_t CloseHandle();
42     int32_t GetComponentVersion(CompVerInfo &verInfo);
43     int32_t SendCommand(HDI::Codec::V1_0::CodecCommandType cmd, uint32_t param, int8_t *cmdData);
44     int32_t GetParameter(OMX_INDEXTYPE paramIndex, int8_t *param);
45     int32_t SetParameter(OMX_INDEXTYPE paramIndex, const int8_t *param);
46     int32_t GetConfig(OMX_INDEXTYPE index, int8_t *config);
47     int32_t SetConfig(OMX_INDEXTYPE index, const int8_t *config);
48     int32_t GetExtensionIndex(const char *parameterName, uint32_t& index);
49     int32_t GetState(HDI::Codec::V1_0::CodecStateType &state);
50     int32_t ComponentTunnelRequest(uint32_t port, int32_t omxHandleTypeTunneledComp, uint32_t tunneledPort,
51                                    OHOS::HDI::Codec::V1_0::CodecTunnelSetupType &tunnelSetup);
52     int32_t UseBuffer(uint32_t portIndex, OmxCodecBuffer &buffer);
53     int32_t AllocateBuffer(uint32_t portIndex, OmxCodecBuffer &buffer);
54     int32_t FreeBuffer(uint32_t portIndex, const OmxCodecBuffer &buffer);
55     int32_t EmptyThisBuffer(OmxCodecBuffer &buffer);
56     int32_t FillThisBuffer(OmxCodecBuffer &buffer);
57     int32_t SetCallbacks(const sptr<ICodecCallback> &callbacks, int64_t appData);
58     int32_t UseEglImage(struct OmxCodecBuffer &buffer, uint32_t portIndex, const int8_t *eglImage);
59     int32_t ComponentRoleEnum(std::vector<uint8_t> &role, uint32_t index);
60     int32_t ComponentDeInit();
61     OMX_ERRORTYPE static OnEvent(OMX_HANDLETYPE component, void *appData, OMX_EVENTTYPE event, uint32_t data1,
62                                  uint32_t data2, void *eventData);
63     OMX_ERRORTYPE static OnEmptyBufferDone(OMX_HANDLETYPE component, void *appData, OMX_BUFFERHEADERTYPE *buffer);
64     OMX_ERRORTYPE static OnFillBufferDone(OMX_HANDLETYPE component, void *appData, OMX_BUFFERHEADERTYPE *buffer);
65     std::map<OMX_BUFFERHEADERTYPE *, uint32_t> &GetBufferMapCount();
66 
67 public:
68     static OMX_CALLBACKTYPE callbacks_;  // callbacks
69 
70 private:
71     int32_t OnEvent(HDI::Codec::V1_0::CodecEventType event, uint32_t data1, uint32_t data2, void *eventData);
72     int32_t OnEmptyBufferDone(OMX_BUFFERHEADERTYPE *buffer);
73     int32_t OnFillBufferDone(OMX_BUFFERHEADERTYPE *buffer);
74     uint32_t GenerateBufferId();
75     sptr<ICodecBuffer> GetBufferInfoByHeader(OMX_BUFFERHEADERTYPE *buffer);
76     bool GetBufferById(uint32_t bufferId, sptr<ICodecBuffer> &codecBuffer, OMX_BUFFERHEADERTYPE *&bufferHdrType);
77     void ReleaseCodecBuffer(struct OmxCodecBuffer &buffer);
78 private:
79     OMX_HANDLETYPE comp_;  // Compnent handle
80     sptr<ICodecCallback> omxCallback_;
81     int64_t appData_;
82     std::map<uint32_t, sptr<ICodecBuffer>> codecBufferMap_;       // Key is buffferID
83     std::map<OMX_BUFFERHEADERTYPE *, uint32_t> portIndexMap_;
84     std::map<OMX_BUFFERHEADERTYPE *, uint32_t> bufferHeaderMap_;  // Key is omx buffer header type
85     uint32_t bufferIdCount_;
86     std::shared_ptr<ComponentMgr> mgr_;
87     std::shared_mutex mapMutex_;
88 };
89 }  // namespace Omx
90 }  // namespace Codec
91 }  // namespace OHOS
92 #endif /* COMPONENT_NODE_H */