• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
25 #include "icodec_buffer.h"
26 #include "codec_callback_if.h"
27 #include "codec_component_type.h"
28 
29 namespace OHOS {
30 namespace Codec {
31 namespace Omx {
32 class ComponentNode : NoCopyable {
33 public:
34     ComponentNode(struct CodecCallbackType *callback, int64_t appData);
35 
36     ~ComponentNode();
37 
38     int32_t GetComponentVersion(struct CompVerInfo &verInfo);
39 
40     int32_t SendCommand(OMX_COMMANDTYPE cmd, uint32_t param, int8_t *cmdData, uint32_t cmdDataLen);
41 
42     int32_t GetParameter(OMX_INDEXTYPE paramIndex, int8_t *param, uint32_t paramLen);
43 
44     int32_t SetParameter(OMX_INDEXTYPE paramIndex, int8_t *param, uint32_t paramLen);
45 
46     int32_t GetConfig(OMX_INDEXTYPE index, int8_t *config, uint32_t configLen);
47 
48     int32_t SetConfig(OMX_INDEXTYPE index, int8_t *config, uint32_t configLen);
49 
50     int32_t GetExtensionIndex(const char *parameterName, OMX_INDEXTYPE *indexType);
51 
52     int32_t GetState(OMX_STATETYPE *state);
53 
54     int32_t ComponentTunnelRequest(uint32_t port, int32_t omxHandleTypeTunneledComp, uint32_t tunneledPort,
55                                    struct OMX_TUNNELSETUPTYPE *tunnelSetup);
56 
57     int32_t UseBuffer(uint32_t portIndex, struct OmxCodecBuffer &buffer);
58 
59     int32_t AllocateBuffer(uint32_t portIndex, struct OmxCodecBuffer &buffer);
60 
61     int32_t FreeBuffer(uint32_t portIndex, struct OmxCodecBuffer &buffer);
62 
63     int32_t EmptyThisBuffer(struct OmxCodecBuffer &buffer);
64 
65     int32_t FillThisBuffer(struct OmxCodecBuffer &buffer);
66 
67     int32_t SetCallbacks(struct CodecCallbackType *omxCallback, int64_t appData);
68 
69     int32_t UseEglImage(struct OmxCodecBuffer &buffer, uint32_t portIndex, int8_t *eglImage, uint32_t eglImageLen);
70 
71     int32_t ComponentRoleEnum(uint8_t *role, uint32_t roleLen, uint32_t index);
72 
73     int32_t DeInit();
74 
75     OMX_ERRORTYPE static OnEvent(OMX_HANDLETYPE component, void *appData, OMX_EVENTTYPE event, uint32_t data1,
76                                  uint32_t data2, void *eventData);
77 
78     OMX_ERRORTYPE static OnEmptyBufferDone(OMX_HANDLETYPE component, void *appData, OMX_BUFFERHEADERTYPE *buffer);
79 
80     OMX_ERRORTYPE static OnFillBufferDone(OMX_HANDLETYPE component, void *appData, OMX_BUFFERHEADERTYPE *buffer);
81 
SetHandle(OMX_HANDLETYPE comp)82     void SetHandle(OMX_HANDLETYPE comp)
83     {
84         this->comp_ = comp;
85     }
86 
GetHandle()87     OMX_HANDLETYPE GetHandle()
88     {
89         return comp_;
90     }
91 
92 public:
93     static OMX_CALLBACKTYPE callbacks_;  // callbacks
94 
95 private:
96     int32_t OnEvent(OMX_EVENTTYPE event, uint32_t data1, uint32_t data2, void *eventData);
97 
98     int32_t OnEmptyBufferDone(OMX_BUFFERHEADERTYPE *buffer);
99 
100     int32_t OnFillBufferDone(OMX_BUFFERHEADERTYPE *buffer);
101 
102     uint32_t GenerateBufferId();
103     sptr<ICodecBuffer> GetBufferInfoByHeader(OMX_BUFFERHEADERTYPE *buffer);
104     bool GetBufferById(uint32_t bufferId, sptr<ICodecBuffer> &codecBuffer, OMX_BUFFERHEADERTYPE *&bufferHdrType);
105 
106 private:
107     OMX_HANDLETYPE comp_;                                         // Component handle
108     struct CodecCallbackType *omxCallback_;                       // Callbacks in HDI
109     int64_t appData_;                                             // Use data, default is 0
110     std::map<uint32_t, sptr<ICodecBuffer>> codecBufferMap_;       // Key is buffferID
111     std::map<OMX_BUFFERHEADERTYPE *, uint32_t> bufferHeaderMap_;  // Key is omx buffer header type
112     uint32_t bufferIdCount_;
113 };
114 }  // namespace Omx
115 }  // namespace Codec
116 }  // namespace OHOS
117 #endif /* COMPONENT_NODE_H */