• 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 
16 #include "codec_component_type_service.h"
17 #include <hdf_base.h>
18 #include <osal_mem.h>
19 #include <securec.h>
20 #include <unistd.h>
21 #include "codec_adapter_interface.h"
22 #include "codec_component_type_stub.h"
23 #include "codec_log_wrapper.h"
24 
25 struct CodecComponentTypeService {
26     struct CodecComponentTypeStub stub;
27     struct CodecComponentNode *codecNode;
28 };
29 
CodecComponentTypeGetComponentVersion(struct CodecComponentType * self,struct CompVerInfo * verInfo)30 static int32_t CodecComponentTypeGetComponentVersion(struct CodecComponentType *self, struct CompVerInfo *verInfo)
31 {
32     CODEC_LOGI("service impl!");
33     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
34     return OmxAdapterComponentVersion(service->codecNode, verInfo);
35 }
36 
CodecComponentTypeSendCommand(struct CodecComponentType * self,enum OMX_COMMANDTYPE cmd,uint32_t param,int8_t * cmdData,uint32_t cmdDataLen)37 static int32_t CodecComponentTypeSendCommand(struct CodecComponentType *self,
38     enum OMX_COMMANDTYPE cmd, uint32_t param, int8_t *cmdData, uint32_t cmdDataLen)
39 {
40     CODEC_LOGI("service impl!, type [%{public}d], cmd [%{public}d]", (uint32_t)cmd, param);
41 
42     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
43     return OmxAdapterSendCommand(service->codecNode, cmd, param, cmdData, cmdDataLen);
44 }
45 
CodecComponentTypeGetParameter(struct CodecComponentType * self,uint32_t paramIndex,int8_t * paramStruct,uint32_t paramStructLen)46 static int32_t CodecComponentTypeGetParameter(struct CodecComponentType *self,
47     uint32_t paramIndex, int8_t *paramStruct, uint32_t paramStructLen)
48 {
49     CODEC_LOGI("service impl, index [%{public}x]!", paramIndex);
50 
51     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
52     int32_t err = OmxAdapterGetParameter(service->codecNode, paramIndex, paramStruct, paramStructLen);
53     if (err != HDF_SUCCESS) {
54         CODEC_LOGE("index [%{public}u], ret value [%{public}x]!", paramIndex, err);
55     }
56 
57     return err;
58 }
59 
CodecComponentTypeSetParameter(struct CodecComponentType * self,uint32_t index,int8_t * paramStruct,uint32_t paramStructLen)60 static int32_t CodecComponentTypeSetParameter(struct CodecComponentType *self,
61     uint32_t index, int8_t *paramStruct, uint32_t paramStructLen)
62 {
63     CODEC_LOGI("service impl, index [%{public}x]!", index);
64 
65     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
66     int32_t err = OmxAdapterSetParameter(service->codecNode, index, paramStruct, paramStructLen);
67     if (err != HDF_SUCCESS) {
68         CODEC_LOGE("index [%{public}u], ret value [%{public}x]!", index, err);
69     }
70     return err;
71 }
72 
CodecComponentTypeGetConfig(struct CodecComponentType * self,uint32_t index,int8_t * cfgStruct,uint32_t cfgStructLen)73 static int32_t CodecComponentTypeGetConfig(struct CodecComponentType *self,
74     uint32_t index, int8_t *cfgStruct, uint32_t cfgStructLen)
75 {
76     CODEC_LOGI("service impl, index [%{public}x]!", index);
77 
78     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
79     int32_t err = OmxAdapterGetConfig(service->codecNode, index, cfgStruct, cfgStructLen);
80     if (err != HDF_SUCCESS) {
81         CODEC_LOGE("index [%{public}u], ret value [%{public}x]!", index, err);
82     }
83     return err;
84 }
85 
CodecComponentTypeSetConfig(struct CodecComponentType * self,uint32_t index,int8_t * cfgStruct,uint32_t cfgStructLen)86 static int32_t CodecComponentTypeSetConfig(struct CodecComponentType *self,
87     uint32_t index, int8_t *cfgStruct, uint32_t cfgStructLen)
88 {
89     CODEC_LOGI("service impl, index [%{public}x]!", index);
90 
91     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
92     int32_t err = OmxAdapterSetConfig(service->codecNode, index, cfgStruct, cfgStructLen);
93     if (err != HDF_SUCCESS) {
94         CODEC_LOGE("index [%{public}u], ret value [%{public}x]!", index, err);
95     }
96     return err;
97 }
98 
CodecComponentTypeGetExtensionIndex(struct CodecComponentType * self,const char * paramName,uint32_t * indexType)99 static int32_t CodecComponentTypeGetExtensionIndex(struct CodecComponentType *self,
100     const char *paramName, uint32_t *indexType)
101 {
102     CODEC_LOGI("service impl!");
103     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
104     return OmxAdapterGetExtensionIndex(service->codecNode, paramName, (enum OMX_INDEXTYPE *)indexType);
105 }
106 
CodecComponentTypeGetState(struct CodecComponentType * self,enum OMX_STATETYPE * state)107 static int32_t CodecComponentTypeGetState(struct CodecComponentType *self, enum OMX_STATETYPE *state)
108 {
109     CODEC_LOGI("service impl!");
110 
111     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
112     return OmxAdapterGetState(service->codecNode, state);
113 }
114 
CodecComponentTypeComponentTunnelRequest(struct CodecComponentType * self,uint32_t port,int32_t tunneledComp,uint32_t tunneledPort,struct OMX_TUNNELSETUPTYPE * tunnelSetup)115 static int32_t CodecComponentTypeComponentTunnelRequest(struct CodecComponentType *self,
116     uint32_t port, int32_t tunneledComp, uint32_t tunneledPort,
117     struct OMX_TUNNELSETUPTYPE *tunnelSetup)
118 {
119     CODEC_LOGI("service impl!");
120 
121     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
122     return OmxAdapterComponentTunnelRequest(service->codecNode, port, tunneledComp, tunneledPort, tunnelSetup);
123 }
124 
CodecComponentTypeUseBuffer(struct CodecComponentType * self,uint32_t portIndex,struct OmxCodecBuffer * buffer)125 static int32_t CodecComponentTypeUseBuffer(struct CodecComponentType *self,
126     uint32_t portIndex, struct OmxCodecBuffer *buffer)
127 {
128     CODEC_LOGI("service impl, portIndex: [%{public}d]!", portIndex);
129 
130     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
131     return OmxAdapterUseBuffer(service->codecNode, portIndex, buffer);
132 }
133 
CodecComponentTypeAllocateBuffer(struct CodecComponentType * self,uint32_t portIndex,struct OmxCodecBuffer * buffer)134 static int32_t CodecComponentTypeAllocateBuffer(struct CodecComponentType *self,
135     uint32_t portIndex, struct OmxCodecBuffer *buffer)
136 {
137     CODEC_LOGI("service impl, portIndex: [%{public}d]!", portIndex);
138 
139     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
140     return OmxAdapterAllocateBuffer(service->codecNode, portIndex, buffer);
141 }
142 
CodecComponentTypeFreeBuffer(struct CodecComponentType * self,uint32_t portIndex,const struct OmxCodecBuffer * buffer)143 static int32_t CodecComponentTypeFreeBuffer(struct CodecComponentType *self, uint32_t portIndex,
144     const struct OmxCodecBuffer *buffer)
145 {
146     CODEC_LOGI("service impl, portIndex: [%{public}d], bufferId: [%{public}d]!",
147         portIndex, buffer->bufferId);
148 
149     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
150     return OmxAdapterFreeBuffer(service->codecNode, portIndex, (struct OmxCodecBuffer *)buffer);
151 }
152 
CodecComponentTypeEmptyThisBuffer(struct CodecComponentType * self,const struct OmxCodecBuffer * buffer)153 static int32_t CodecComponentTypeEmptyThisBuffer(struct CodecComponentType *self,
154     const struct OmxCodecBuffer *buffer)
155 {
156     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
157     return OmxAdapterEmptyThisBuffer(service->codecNode, (struct OmxCodecBuffer *)buffer);
158 }
159 
CodecComponentTypeFillThisBuffer(struct CodecComponentType * self,const struct OmxCodecBuffer * buffer)160 static int32_t CodecComponentTypeFillThisBuffer(struct CodecComponentType *self,
161     const struct OmxCodecBuffer *buffer)
162 {
163     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
164     return OmxAdapterFillThisBuffer(service->codecNode, (struct OmxCodecBuffer *)buffer);
165 }
166 
CodecComponentTypeSetCallbacks(struct CodecComponentType * self,struct CodecCallbackType * callback,int64_t appData)167 static int32_t CodecComponentTypeSetCallbacks(struct CodecComponentType *self, struct CodecCallbackType *callback,
168                                               int64_t appData)
169 {
170     CODEC_LOGI("service impl!");
171 
172     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
173     return OmxAdapterSetCallbacks(service->codecNode, callback, appData);
174 }
175 
CodecComponentTypeComponentDeInit(struct CodecComponentType * self)176 static int32_t CodecComponentTypeComponentDeInit(struct CodecComponentType *self)
177 {
178     CODEC_LOGI("service impl!");
179 
180     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
181     return OmxAdapterDeInit(service->codecNode);
182 }
183 
CodecComponentTypeUseEglImage(struct CodecComponentType * self,struct OmxCodecBuffer * buffer,uint32_t portIndex,int8_t * eglImage,uint32_t eglImageLen)184 static int32_t CodecComponentTypeUseEglImage(struct CodecComponentType *self,
185     struct OmxCodecBuffer *buffer, uint32_t portIndex, int8_t *eglImage, uint32_t eglImageLen)
186 {
187     CODEC_LOGI("service impl!");
188 
189     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
190     return OmxAdapterUseEglImage(service->codecNode, buffer, portIndex, eglImage, eglImageLen);
191 }
192 
CodecComponentTypeComponentRoleEnum(struct CodecComponentType * self,uint8_t * role,uint32_t roleLen,uint32_t index)193 static int32_t CodecComponentTypeComponentRoleEnum(struct CodecComponentType *self,
194     uint8_t *role, uint32_t roleLen, uint32_t index)
195 {
196     CODEC_LOGI("service impl!");
197 
198     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
199     return OmxAdapterComponentRoleEnum(service->codecNode, role, roleLen, index);
200 }
201 
CodecComponentTypeServiceConstruct(struct CodecComponentType * instance)202 void CodecComponentTypeServiceConstruct(struct CodecComponentType *instance)
203 {
204     instance->GetComponentVersion = CodecComponentTypeGetComponentVersion;
205     instance->SendCommand = CodecComponentTypeSendCommand;
206     instance->GetParameter = CodecComponentTypeGetParameter;
207     instance->SetParameter = CodecComponentTypeSetParameter;
208     instance->GetConfig = CodecComponentTypeGetConfig;
209     instance->SetConfig = CodecComponentTypeSetConfig;
210     instance->GetExtensionIndex = CodecComponentTypeGetExtensionIndex;
211     instance->GetState = CodecComponentTypeGetState;
212     instance->ComponentTunnelRequest = CodecComponentTypeComponentTunnelRequest;
213     instance->UseBuffer = CodecComponentTypeUseBuffer;
214     instance->AllocateBuffer = CodecComponentTypeAllocateBuffer;
215     instance->FreeBuffer = CodecComponentTypeFreeBuffer;
216     instance->EmptyThisBuffer = CodecComponentTypeEmptyThisBuffer;
217     instance->FillThisBuffer = CodecComponentTypeFillThisBuffer;
218     instance->SetCallbacks = CodecComponentTypeSetCallbacks;
219     instance->ComponentDeInit = CodecComponentTypeComponentDeInit;
220     instance->UseEglImage = CodecComponentTypeUseEglImage;
221     instance->ComponentRoleEnum = CodecComponentTypeComponentRoleEnum;
222 }
CodecComponentTypeServiceGet(void)223 struct CodecComponentType *CodecComponentTypeServiceGet(void)
224 {
225     struct CodecComponentTypeService *service =
226         (struct CodecComponentTypeService *)OsalMemCalloc(sizeof(struct CodecComponentTypeService));
227     if (service == NULL) {
228         CODEC_LOGE("malloc CodecComponentTypeService obj failed!");
229         return NULL;
230     }
231 
232     if (!CodecComponentTypeStubConstruct(&service->stub)) {
233         CODEC_LOGE("construct CodecComponentTypeStub obj failed!");
234         OsalMemFree(service);
235         return NULL;
236     }
237     CodecComponentTypeServiceConstruct(&service->stub.interface);
238     return &service->stub.interface;
239 }
240 
CodecComponentTypeServiceRelease(struct CodecComponentType * self)241 void CodecComponentTypeServiceRelease(struct CodecComponentType *self)
242 {
243     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
244     if (service == NULL) {
245         return;
246     }
247 
248     CodecComponentTypeStubRelease(&service->stub);
249     service->codecNode = NULL;
250     OsalMemFree(service);
251 }
252 
CodecComponentTypeServiceSetCodecNode(struct CodecComponentType * self,struct CodecComponentNode * codecNode)253 void CodecComponentTypeServiceSetCodecNode(struct CodecComponentType *self, struct CodecComponentNode *codecNode)
254 {
255     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
256     if (service == NULL) {
257         return;
258     }
259     service->codecNode = codecNode;
260 }
261 
CodecComponentTypeServiceGetCodecNode(struct CodecComponentType * self)262 struct CodecComponentNode *CodecComponentTypeServiceGetCodecNode(struct CodecComponentType *self)
263 {
264     struct CodecComponentTypeService *service = (struct CodecComponentTypeService *)self;
265     if (service == NULL) {
266         return NULL;
267     }
268     return service->codecNode;
269 }