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 <hdf_dlist.h>
17 #include <osal_mem.h>
18 #include <securec.h>
19 #include <servmgr_hdi.h>
20 #include "codec_component_if.h"
21 #include "codec_internal.h"
22 #include "codec_log_wrapper.h"
23 #include "codec_types.h"
24
25 struct CodecComponentTypeProxy {
26 struct CodecComponentType instance;
27 struct HdfRemoteService *remote;
28 };
29
ReleaseSbuf(struct HdfSBuf * data,struct HdfSBuf * reply)30 static void ReleaseSbuf(struct HdfSBuf *data, struct HdfSBuf *reply)
31 {
32 if (data != NULL) {
33 HdfSbufRecycle(data);
34 }
35 if (reply != NULL) {
36 HdfSbufRecycle(reply);
37 }
38 }
39
CodecComponentTypeProxyCall(struct CodecComponentType * self,int32_t id,struct HdfSBuf * data,struct HdfSBuf * reply)40 static int32_t CodecComponentTypeProxyCall(struct CodecComponentType *self, int32_t id, struct HdfSBuf *data,
41 struct HdfSBuf *reply)
42 {
43 struct HdfRemoteService *remote = self->AsObject(self);
44 if (remote == NULL || remote->dispatcher == NULL || remote->dispatcher->Dispatch == NULL ||
45 remote->dispatcher->DispatchAsync == NULL) {
46 CODEC_LOGE("Invalid HdfRemoteService obj");
47 return HDF_ERR_INVALID_OBJECT;
48 }
49 return remote->dispatcher->Dispatch(remote, id, data, reply);
50 }
ReadValuesForGetComponentVersion(struct HdfSBuf * reply,struct CompVerInfo * verInfo)51 static int32_t ReadValuesForGetComponentVersion(struct HdfSBuf *reply, struct CompVerInfo *verInfo)
52 {
53 struct CompVerInfo *verInfoCp = (struct CompVerInfo *)HdfSbufReadUnpadBuffer(reply, sizeof(struct CompVerInfo));
54 if (verInfoCp == NULL) {
55 CODEC_LOGE("read compVerInfo failed!");
56 return HDF_ERR_INVALID_PARAM;
57 }
58 int32_t ret = memcpy_s(verInfo, sizeof(struct CompVerInfo), verInfoCp, sizeof(struct CompVerInfo));
59 if (ret != EOK) {
60 CODEC_LOGE("memcpy_s compVersion failed, error code: %{public}d", ret);
61 return HDF_FAILURE;
62 }
63 return HDF_SUCCESS;
64 }
65
CodecComponentTypeProxyGetComponentVersion(struct CodecComponentType * self,struct CompVerInfo * verInfo)66 static int32_t CodecComponentTypeProxyGetComponentVersion(struct CodecComponentType *self, struct CompVerInfo *verInfo)
67 {
68 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
69 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
70 if (data == NULL || reply == NULL) {
71 CODEC_LOGE("HdfSubf malloc failed!");
72 ReleaseSbuf(data, reply);
73 return HDF_ERR_MALLOC_FAIL;
74 }
75
76 if (!HdfRemoteServiceWriteInterfaceToken(self->AsObject(self), data)) {
77 CODEC_LOGE("write interface token failed");
78 ReleaseSbuf(data, reply);
79 return HDF_FAILURE;
80 }
81
82 int32_t ret = CodecComponentTypeProxyCall(self, CMD_GET_COMPONENT_VERSION, data, reply);
83 if (ret != HDF_SUCCESS) {
84 CODEC_LOGE("call failed! error code is %{public}d", ret);
85 ReleaseSbuf(data, reply);
86 return ret;
87 }
88
89 ret = ReadValuesForGetComponentVersion(reply, verInfo);
90 ReleaseSbuf(data, reply);
91 return ret;
92 }
93
CodecComponentTypeProxySendCommand(struct CodecComponentType * self,enum OMX_COMMANDTYPE cmd,uint32_t param,int8_t * cmdData,uint32_t cmdDataLen)94 static int32_t CodecComponentTypeProxySendCommand(struct CodecComponentType *self,
95 enum OMX_COMMANDTYPE cmd, uint32_t param, int8_t *cmdData, uint32_t cmdDataLen)
96 {
97 int32_t ret;
98
99 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
100 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
101 if (data == NULL || reply == NULL) {
102 CODEC_LOGE("HdfSubf malloc failed!");
103 ReleaseSbuf(data, reply);
104 return HDF_ERR_MALLOC_FAIL;
105 }
106
107 if (!HdfRemoteServiceWriteInterfaceToken(self->AsObject(self), data)) {
108 CODEC_LOGE("write interface token failed");
109 ReleaseSbuf(data, reply);
110 return HDF_FAILURE;
111 }
112
113 if (!HdfSbufWriteUint32(data, (uint32_t)cmd)) {
114 CODEC_LOGE("write cmd failed!");
115 ReleaseSbuf(data, reply);
116 return HDF_ERR_INVALID_PARAM;
117 }
118
119 if (!HdfSbufWriteUint32(data, param)) {
120 CODEC_LOGE("write param failed!");
121 ReleaseSbuf(data, reply);
122 return HDF_ERR_INVALID_PARAM;
123 }
124
125 if (!HdfSbufWriteUint32(data, cmdDataLen)) {
126 CODEC_LOGE("write cmdData failed!");
127 ReleaseSbuf(data, reply);
128 return HDF_ERR_INVALID_PARAM;
129 }
130 for (uint32_t i = 0; i < cmdDataLen; i++) {
131 if (!HdfSbufWriteInt8(data, cmdData[i])) {
132 CODEC_LOGE("write cmdData[i] failed!");
133 ReleaseSbuf(data, reply);
134 return HDF_ERR_INVALID_PARAM;
135 }
136 }
137
138 ret = CodecComponentTypeProxyCall(self, CMD_SEND_COMMAND, data, reply);
139 if (ret != HDF_SUCCESS) {
140 CODEC_LOGE("call failed! error code is %{public}d", ret);
141 ReleaseSbuf(data, reply);
142 return ret;
143 }
144
145 ReleaseSbuf(data, reply);
146 return ret;
147 }
148
CodecComponentTypeProxyGetParameter(struct CodecComponentType * self,uint32_t paramIndex,int8_t * paramStruct,uint32_t paramStructLen)149 static int32_t CodecComponentTypeProxyGetParameter(struct CodecComponentType *self,
150 uint32_t paramIndex, int8_t *paramStruct, uint32_t paramStructLen)
151 {
152 int32_t ret;
153
154 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
155 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
156 if (data == NULL || reply == NULL) {
157 CODEC_LOGE("HdfSubf malloc failed!");
158 ReleaseSbuf(data, reply);
159 return HDF_ERR_MALLOC_FAIL;
160 }
161
162 if (!HdfRemoteServiceWriteInterfaceToken(self->AsObject(self), data)) {
163 CODEC_LOGE("write interface token failed");
164 ReleaseSbuf(data, reply);
165 return HDF_FAILURE;
166 }
167
168 if (!HdfSbufWriteUint32(data, paramIndex)) {
169 CODEC_LOGE("write paramIndex failed!");
170 ReleaseSbuf(data, reply);
171 return HDF_ERR_INVALID_PARAM;
172 }
173
174 if (!HdfSbufWriteUint32(data, paramStructLen)) {
175 CODEC_LOGE("write paramStructLen failed!");
176 ReleaseSbuf(data, reply);
177 return HDF_ERR_INVALID_PARAM;
178 }
179
180 for (uint32_t i = 0; i < paramStructLen; i++) {
181 if (!HdfSbufWriteInt8(data, paramStruct[i])) {
182 CODEC_LOGE("write paramStruct[i] failed!");
183 ReleaseSbuf(data, reply);
184 return HDF_ERR_INVALID_PARAM;
185 }
186 }
187
188 ret = CodecComponentTypeProxyCall(self, CMD_GET_PARAMETER, data, reply);
189 if (ret != HDF_SUCCESS) {
190 CODEC_LOGE("call failed! error code is %{public}d", ret);
191 ReleaseSbuf(data, reply);
192 return ret;
193 }
194
195 for (uint32_t i = 0; i < paramStructLen; i++) {
196 if (!HdfSbufReadInt8(reply, ¶mStruct[i])) {
197 CODEC_LOGE("read paramStruct[i] failed!");
198 ReleaseSbuf(data, reply);
199 return HDF_ERR_INVALID_PARAM;
200 }
201 }
202
203 ReleaseSbuf(data, reply);
204 return ret;
205 }
206
CodecComponentTypeProxySetParameter(struct CodecComponentType * self,uint32_t index,int8_t * paramStruct,uint32_t paramStructLen)207 static int32_t CodecComponentTypeProxySetParameter(struct CodecComponentType *self,
208 uint32_t index, int8_t *paramStruct, uint32_t paramStructLen)
209 {
210 int32_t ret;
211
212 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
213 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
214 if (data == NULL || reply == NULL) {
215 CODEC_LOGE("HdfSubf malloc failed!");
216 ReleaseSbuf(data, reply);
217 return HDF_ERR_MALLOC_FAIL;
218 }
219
220 if (!HdfRemoteServiceWriteInterfaceToken(self->AsObject(self), data)) {
221 CODEC_LOGE("write interface token failed");
222 ReleaseSbuf(data, reply);
223 return HDF_FAILURE;
224 }
225
226 if (!HdfSbufWriteUint32(data, index)) {
227 CODEC_LOGE("write index failed!");
228 ReleaseSbuf(data, reply);
229 return HDF_ERR_INVALID_PARAM;
230 }
231
232 if (!HdfSbufWriteUint32(data, paramStructLen)) {
233 CODEC_LOGE("write paramStruct failed!");
234 ReleaseSbuf(data, reply);
235 return HDF_ERR_INVALID_PARAM;
236 }
237 for (uint32_t i = 0; i < paramStructLen; i++) {
238 if (!HdfSbufWriteInt8(data, paramStruct[i])) {
239 CODEC_LOGE("write paramStruct[i] failed!");
240 ReleaseSbuf(data, reply);
241 return HDF_ERR_INVALID_PARAM;
242 }
243 }
244
245 ret = CodecComponentTypeProxyCall(self, CMD_SET_PARAMETER, data, reply);
246 if (ret != HDF_SUCCESS) {
247 CODEC_LOGE("call failed! error code is %{public}d", ret);
248 ReleaseSbuf(data, reply);
249 return ret;
250 }
251
252 ReleaseSbuf(data, reply);
253 return ret;
254 }
255
CodecComponentTypeProxyGetConfig(struct CodecComponentType * self,uint32_t index,int8_t * cfgStruct,uint32_t cfgStructLen)256 static int32_t CodecComponentTypeProxyGetConfig(struct CodecComponentType *self,
257 uint32_t index, int8_t *cfgStruct, uint32_t cfgStructLen)
258 {
259 int32_t ret;
260
261 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
262 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
263 if (data == NULL || reply == NULL) {
264 CODEC_LOGE("HdfSubf malloc failed!");
265 ReleaseSbuf(data, reply);
266 return HDF_ERR_MALLOC_FAIL;
267 }
268
269 if (!HdfRemoteServiceWriteInterfaceToken(self->AsObject(self), data)) {
270 CODEC_LOGE("write interface token failed");
271 ReleaseSbuf(data, reply);
272 return HDF_FAILURE;
273 }
274
275 if (!HdfSbufWriteUint32(data, index)) {
276 CODEC_LOGE("write index failed!");
277 ReleaseSbuf(data, reply);
278 return HDF_ERR_INVALID_PARAM;
279 }
280
281 if (!HdfSbufWriteUint32(data, cfgStructLen)) {
282 CODEC_LOGE("write cfgStructLen failed!");
283 ReleaseSbuf(data, reply);
284 return HDF_ERR_INVALID_PARAM;
285 }
286
287 for (uint32_t i = 0; i < cfgStructLen; i++) {
288 if (!HdfSbufWriteInt8(data, cfgStruct[i])) {
289 CODEC_LOGE("write cfgStruct[i] failed!");
290 ReleaseSbuf(data, reply);
291 return HDF_ERR_INVALID_PARAM;
292 }
293 }
294
295 ret = CodecComponentTypeProxyCall(self, CMD_GET_CONFIG, data, reply);
296 if (ret != HDF_SUCCESS) {
297 CODEC_LOGE("call failed! error code is %{public}d", ret);
298 ReleaseSbuf(data, reply);
299 return ret;
300 }
301
302 for (uint32_t i = 0; i < cfgStructLen; i++) {
303 if (!HdfSbufReadInt8(reply, &cfgStruct[i])) {
304 CODEC_LOGE("read cfgStruct[i] failed!");
305 ReleaseSbuf(data, reply);
306 return HDF_ERR_INVALID_PARAM;
307 }
308 }
309
310 ReleaseSbuf(data, reply);
311 return ret;
312 }
313
CodecComponentTypeProxySetConfig(struct CodecComponentType * self,uint32_t index,int8_t * cfgStruct,uint32_t cfgStructLen)314 static int32_t CodecComponentTypeProxySetConfig(struct CodecComponentType *self,
315 uint32_t index, int8_t *cfgStruct, uint32_t cfgStructLen)
316 {
317 int32_t ret;
318
319 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
320 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
321 if (data == NULL || reply == NULL) {
322 CODEC_LOGE("HdfSubf malloc failed!");
323 ReleaseSbuf(data, reply);
324 return HDF_ERR_MALLOC_FAIL;
325 }
326
327 if (!HdfRemoteServiceWriteInterfaceToken(self->AsObject(self), data)) {
328 CODEC_LOGE("write interface token failed");
329 ReleaseSbuf(data, reply);
330 return HDF_FAILURE;
331 }
332
333 if (!HdfSbufWriteUint32(data, index)) {
334 CODEC_LOGE("write index failed!");
335 ReleaseSbuf(data, reply);
336 return HDF_ERR_INVALID_PARAM;
337 }
338
339 if (!HdfSbufWriteUint32(data, cfgStructLen)) {
340 CODEC_LOGE("write cfgStruct failed!");
341 ReleaseSbuf(data, reply);
342 return HDF_ERR_INVALID_PARAM;
343 }
344 for (uint32_t i = 0; i < cfgStructLen; i++) {
345 if (!HdfSbufWriteInt8(data, cfgStruct[i])) {
346 CODEC_LOGE("write cfgStruct[i] failed!");
347 ReleaseSbuf(data, reply);
348 return HDF_ERR_INVALID_PARAM;
349 }
350 }
351
352 ret = CodecComponentTypeProxyCall(self, CMD_SET_CONFIG, data, reply);
353 if (ret != HDF_SUCCESS) {
354 CODEC_LOGE("call failed! error code is %{public}d", ret);
355 ReleaseSbuf(data, reply);
356 return ret;
357 }
358
359 ReleaseSbuf(data, reply);
360 return ret;
361 }
362
CodecComponentTypeProxyGetExtensionIndex(struct CodecComponentType * self,const char * paramName,uint32_t * indexType)363 static int32_t CodecComponentTypeProxyGetExtensionIndex(struct CodecComponentType *self,
364 const char *paramName, uint32_t *indexType)
365 {
366 int32_t ret;
367
368 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
369 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
370 if (data == NULL || reply == NULL) {
371 CODEC_LOGE("HdfSubf malloc failed!");
372 ReleaseSbuf(data, reply);
373 return HDF_ERR_MALLOC_FAIL;
374 }
375
376 if (!HdfRemoteServiceWriteInterfaceToken(self->AsObject(self), data)) {
377 CODEC_LOGE("write interface token failed");
378 ReleaseSbuf(data, reply);
379 return HDF_FAILURE;
380 }
381
382 if (!HdfSbufWriteString(data, paramName)) {
383 CODEC_LOGE("write paramName failed!");
384 ReleaseSbuf(data, reply);
385 return HDF_ERR_INVALID_PARAM;
386 }
387
388 ret = CodecComponentTypeProxyCall(self, CMD_GET_EXTENSION_INDEX, data, reply);
389 if (ret != HDF_SUCCESS) {
390 CODEC_LOGE("call failed! error code is %{public}d", ret);
391 ReleaseSbuf(data, reply);
392 return ret;
393 }
394
395 if (!HdfSbufReadUint32(reply, indexType)) {
396 CODEC_LOGE("read indexType failed!");
397 ReleaseSbuf(data, reply);
398 return HDF_ERR_INVALID_PARAM;
399 }
400
401 ReleaseSbuf(data, reply);
402 return ret;
403 }
404
CodecComponentTypeProxyGetState(struct CodecComponentType * self,enum OMX_STATETYPE * state)405 static int32_t CodecComponentTypeProxyGetState(struct CodecComponentType *self,
406 enum OMX_STATETYPE *state)
407 {
408 int32_t ret;
409
410 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
411 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
412 if (data == NULL || reply == NULL) {
413 CODEC_LOGE("HdfSubf malloc failed!");
414 ReleaseSbuf(data, reply);
415 return HDF_ERR_MALLOC_FAIL;
416 }
417
418 if (!HdfRemoteServiceWriteInterfaceToken(self->AsObject(self), data)) {
419 CODEC_LOGE("write interface token failed");
420 ReleaseSbuf(data, reply);
421 return HDF_FAILURE;
422 }
423
424 ret = CodecComponentTypeProxyCall(self, CMD_GET_STATE, data, reply);
425 if (ret != HDF_SUCCESS) {
426 CODEC_LOGE("call failed! error code is %{public}d", ret);
427 ReleaseSbuf(data, reply);
428 return ret;
429 }
430
431 if (!HdfSbufReadUint32(reply, (uint32_t*)state)) {
432 CODEC_LOGE("read state failed!");
433 ReleaseSbuf(data, reply);
434 return HDF_ERR_INVALID_PARAM;
435 }
436
437 ReleaseSbuf(data, reply);
438 return ret;
439 }
440
CodecComponentTypeProxyComponentTunnelRequest(struct CodecComponentType * self,uint32_t port,int32_t tunneledComp,uint32_t tunneledPort,struct OMX_TUNNELSETUPTYPE * tunnelSetup)441 static int32_t CodecComponentTypeProxyComponentTunnelRequest(struct CodecComponentType *self,
442 uint32_t port, int32_t tunneledComp, uint32_t tunneledPort, struct OMX_TUNNELSETUPTYPE *tunnelSetup)
443 {
444 int32_t ret;
445
446 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
447 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
448 if (data == NULL || reply == NULL) {
449 CODEC_LOGE("HdfSubf malloc failed!");
450 ReleaseSbuf(data, reply);
451 return HDF_ERR_MALLOC_FAIL;
452 }
453
454 if (!HdfRemoteServiceWriteInterfaceToken(self->AsObject(self), data)) {
455 CODEC_LOGE("write interface token failed");
456 ReleaseSbuf(data, reply);
457 return HDF_FAILURE;
458 }
459
460 if (!HdfSbufWriteUint32(data, port)) {
461 CODEC_LOGE("write port failed!");
462 ReleaseSbuf(data, reply);
463 return HDF_ERR_INVALID_PARAM;
464 }
465
466 if (!HdfSbufWriteInt32(data, tunneledComp)) {
467 CODEC_LOGE("write tunneledComp failed!");
468 ReleaseSbuf(data, reply);
469 return HDF_ERR_INVALID_PARAM;
470 }
471
472 if (!HdfSbufWriteUint32(data, tunneledPort)) {
473 CODEC_LOGE("write tunneledPort failed!");
474 ReleaseSbuf(data, reply);
475 return HDF_ERR_INVALID_PARAM;
476 }
477
478 if (!OMX_TUNNELSETUPTYPEBlockMarshalling(data, tunnelSetup)) {
479 CODEC_LOGE("write tunnelSetup failed!");
480 ReleaseSbuf(data, reply);
481 return HDF_ERR_INVALID_PARAM;
482 }
483
484 ret = CodecComponentTypeProxyCall(self, CMD_COMPONENT_TUNNEL_REQUEST, data, reply);
485 if (ret != HDF_SUCCESS) {
486 CODEC_LOGE("call failed! error code is %{public}d", ret);
487 ReleaseSbuf(data, reply);
488 return ret;
489 }
490
491 if (!OMX_TUNNELSETUPTYPEBlockUnmarshalling(reply, tunnelSetup)) {
492 CODEC_LOGE("read tunnelSetup failed!");
493 ReleaseSbuf(data, reply);
494 return HDF_ERR_INVALID_PARAM;
495 }
496
497 ReleaseSbuf(data, reply);
498 return ret;
499 }
500
CodecComponentTypeProxyUseBuffer(struct CodecComponentType * self,uint32_t portIndex,struct OmxCodecBuffer * buffer)501 static int32_t CodecComponentTypeProxyUseBuffer(struct CodecComponentType *self,
502 uint32_t portIndex, struct OmxCodecBuffer *buffer)
503 {
504 int32_t ret;
505
506 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
507 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
508 if (data == NULL || reply == NULL) {
509 CODEC_LOGE("HdfSubf malloc failed!");
510 ReleaseSbuf(data, reply);
511 return HDF_ERR_MALLOC_FAIL;
512 }
513
514 if (!HdfRemoteServiceWriteInterfaceToken(self->AsObject(self), data)) {
515 CODEC_LOGE("write interface token failed");
516 ReleaseSbuf(data, reply);
517 return HDF_FAILURE;
518 }
519
520 if (!HdfSbufWriteUint32(data, portIndex)) {
521 CODEC_LOGE("write portIndex failed!");
522 ReleaseSbuf(data, reply);
523 return HDF_ERR_INVALID_PARAM;
524 }
525
526 if (!OmxCodecBufferBlockMarshalling(data, buffer)) {
527 CODEC_LOGE("write buffer failed!");
528 ReleaseSbuf(data, reply);
529 return HDF_ERR_INVALID_PARAM;
530 }
531
532 ret = CodecComponentTypeProxyCall(self, CMD_USE_BUFFER, data, reply);
533 if (ret != HDF_SUCCESS) {
534 CODEC_LOGE("call failed! error code is %{public}d", ret);
535 ReleaseSbuf(data, reply);
536 return ret;
537 }
538
539 if (!OmxCodecBufferBlockUnmarshalling(reply, buffer)) {
540 CODEC_LOGE("read buffer failed!");
541 ReleaseSbuf(data, reply);
542 return HDF_ERR_INVALID_PARAM;
543 }
544
545 ReleaseSbuf(data, reply);
546 return ret;
547 }
548
CodecComponentTypeProxyAllocateBuffer(struct CodecComponentType * self,uint32_t portIndex,struct OmxCodecBuffer * buffer)549 static int32_t CodecComponentTypeProxyAllocateBuffer(struct CodecComponentType *self,
550 uint32_t portIndex, struct OmxCodecBuffer *buffer)
551 {
552 int32_t ret;
553
554 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
555 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
556 if (data == NULL || reply == NULL) {
557 CODEC_LOGE("HdfSubf malloc failed!");
558 ReleaseSbuf(data, reply);
559 return HDF_ERR_MALLOC_FAIL;
560 }
561
562 if (!HdfRemoteServiceWriteInterfaceToken(self->AsObject(self), data)) {
563 CODEC_LOGE("write interface token failed");
564 ReleaseSbuf(data, reply);
565 return HDF_FAILURE;
566 }
567
568 if (!HdfSbufWriteUint32(data, portIndex)) {
569 CODEC_LOGE("write portIndex failed!");
570 ReleaseSbuf(data, reply);
571 return HDF_ERR_INVALID_PARAM;
572 }
573
574 if (!OmxCodecBufferBlockMarshalling(data, buffer)) {
575 CODEC_LOGE("write buffer failed!");
576 ReleaseSbuf(data, reply);
577 return HDF_ERR_INVALID_PARAM;
578 }
579
580 ret = CodecComponentTypeProxyCall(self, CMD_ALLOCATE_BUFFER, data, reply);
581 if (ret != HDF_SUCCESS) {
582 CODEC_LOGE("call failed! error code is %{public}d", ret);
583 ReleaseSbuf(data, reply);
584 return ret;
585 }
586
587 if (!OmxCodecBufferBlockUnmarshalling(reply, buffer)) {
588 CODEC_LOGE("read buffer failed!");
589 ReleaseSbuf(data, reply);
590 return HDF_ERR_INVALID_PARAM;
591 }
592
593 ReleaseSbuf(data, reply);
594 return ret;
595 }
596
CodecComponentTypeProxyFreeBuffer(struct CodecComponentType * self,uint32_t portIndex,const struct OmxCodecBuffer * buffer)597 static int32_t CodecComponentTypeProxyFreeBuffer(struct CodecComponentType *self,
598 uint32_t portIndex, const struct OmxCodecBuffer *buffer)
599 {
600 int32_t ret;
601
602 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
603 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
604 if (data == NULL || reply == NULL) {
605 CODEC_LOGE("HdfSubf malloc failed!");
606 ReleaseSbuf(data, reply);
607 return HDF_ERR_MALLOC_FAIL;
608 }
609
610 if (!HdfRemoteServiceWriteInterfaceToken(self->AsObject(self), data)) {
611 CODEC_LOGE("write interface token failed");
612 ReleaseSbuf(data, reply);
613 return HDF_FAILURE;
614 }
615
616 if (!HdfSbufWriteUint32(data, portIndex)) {
617 CODEC_LOGE("write portIndex failed!");
618 ReleaseSbuf(data, reply);
619 return HDF_ERR_INVALID_PARAM;
620 }
621
622 if (!OmxCodecBufferBlockMarshalling(data, buffer)) {
623 CODEC_LOGE("write buffer failed!");
624 ReleaseSbuf(data, reply);
625 return HDF_ERR_INVALID_PARAM;
626 }
627
628 ret = CodecComponentTypeProxyCall(self, CMD_FREE_BUFFER, data, reply);
629 if (ret != HDF_SUCCESS) {
630 CODEC_LOGE("call failed! error code is %{public}d", ret);
631 ReleaseSbuf(data, reply);
632 return ret;
633 }
634
635 ReleaseSbuf(data, reply);
636 return ret;
637 }
638
CodecComponentTypeProxyEmptyThisBuffer(struct CodecComponentType * self,const struct OmxCodecBuffer * buffer)639 static int32_t CodecComponentTypeProxyEmptyThisBuffer(struct CodecComponentType *self,
640 const struct OmxCodecBuffer *buffer)
641 {
642 int32_t ret;
643
644 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
645 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
646 if (data == NULL || reply == NULL) {
647 CODEC_LOGE("HdfSubf malloc failed!");
648 ReleaseSbuf(data, reply);
649 return HDF_ERR_MALLOC_FAIL;
650 }
651
652 if (!HdfRemoteServiceWriteInterfaceToken(self->AsObject(self), data)) {
653 CODEC_LOGE("write interface token failed");
654 ReleaseSbuf(data, reply);
655 return HDF_FAILURE;
656 }
657
658 if (!OmxCodecBufferBlockMarshalling(data, buffer)) {
659 CODEC_LOGE("write buffer failed!");
660 ReleaseSbuf(data, reply);
661 return HDF_ERR_INVALID_PARAM;
662 }
663
664 ret = CodecComponentTypeProxyCall(self, CMD_EMPTY_THIS_BUFFER, data, reply);
665 if (ret != HDF_SUCCESS) {
666 CODEC_LOGE("call failed! error code is %{public}d", ret);
667 ReleaseSbuf(data, reply);
668 return ret;
669 }
670
671 ReleaseSbuf(data, reply);
672 return ret;
673 }
674
CodecComponentTypeProxyFillThisBuffer(struct CodecComponentType * self,const struct OmxCodecBuffer * buffer)675 static int32_t CodecComponentTypeProxyFillThisBuffer(struct CodecComponentType *self,
676 const struct OmxCodecBuffer *buffer)
677 {
678 int32_t ret;
679
680 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
681 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
682 if (data == NULL || reply == NULL) {
683 CODEC_LOGE("HdfSubf malloc failed!");
684 ReleaseSbuf(data, reply);
685 return HDF_ERR_MALLOC_FAIL;
686 }
687
688 if (!HdfRemoteServiceWriteInterfaceToken(self->AsObject(self), data)) {
689 CODEC_LOGE("write interface token failed");
690 ReleaseSbuf(data, reply);
691 return HDF_FAILURE;
692 }
693
694 if (!OmxCodecBufferBlockMarshalling(data, buffer)) {
695 CODEC_LOGE("write buffer failed!");
696 ReleaseSbuf(data, reply);
697 return HDF_ERR_INVALID_PARAM;
698 }
699
700 ret = CodecComponentTypeProxyCall(self, CMD_FILL_THIS_BUFFER, data, reply);
701 if (ret != HDF_SUCCESS) {
702 CODEC_LOGE("call failed! error code is %{public}d", ret);
703 ReleaseSbuf(data, reply);
704 return ret;
705 }
706
707 ReleaseSbuf(data, reply);
708 return ret;
709 }
710
CodecComponentTypeProxySetCallbacks(struct CodecComponentType * self,struct CodecCallbackType * callback,int64_t appData)711 static int32_t CodecComponentTypeProxySetCallbacks(struct CodecComponentType *self,
712 struct CodecCallbackType *callback, int64_t appData)
713 {
714 int32_t ret;
715
716 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
717 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
718 if (data == NULL || reply == NULL) {
719 CODEC_LOGE("HdfSubf malloc failed!");
720 ReleaseSbuf(data, reply);
721 return HDF_ERR_MALLOC_FAIL;
722 }
723
724 if (!HdfRemoteServiceWriteInterfaceToken(self->AsObject(self), data)) {
725 CODEC_LOGE("write interface token failed");
726 ReleaseSbuf(data, reply);
727 return HDF_FAILURE;
728 }
729
730 if (HdfSbufWriteRemoteService(data, callback->remote) != 0) {
731 CODEC_LOGE("write callback failed!");
732 ReleaseSbuf(data, reply);
733 return HDF_ERR_INVALID_PARAM;
734 }
735
736 if (!HdfSbufWriteInt64(data, appData)) {
737 CODEC_LOGE("write appData failed!");
738 ReleaseSbuf(data, reply);
739 return HDF_ERR_INVALID_PARAM;
740 }
741
742 ret = CodecComponentTypeProxyCall(self, CMD_SET_CALLBACKS, data, reply);
743 if (ret != HDF_SUCCESS) {
744 CODEC_LOGE("call failed! error code is %{public}d", ret);
745 ReleaseSbuf(data, reply);
746 return ret;
747 }
748
749 ReleaseSbuf(data, reply);
750 return ret;
751 }
752
CodecComponentTypeProxyComponentDeInit(struct CodecComponentType * self)753 static int32_t CodecComponentTypeProxyComponentDeInit(struct CodecComponentType *self)
754 {
755 int32_t ret;
756
757 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
758 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
759 if (data == NULL || reply == NULL) {
760 CODEC_LOGE("HdfSubf malloc failed!");
761 ReleaseSbuf(data, reply);
762 return HDF_ERR_MALLOC_FAIL;
763 }
764
765 if (!HdfRemoteServiceWriteInterfaceToken(self->AsObject(self), data)) {
766 CODEC_LOGE("write interface token failed");
767 ReleaseSbuf(data, reply);
768 return HDF_FAILURE;
769 }
770
771 ret = CodecComponentTypeProxyCall(self, CMD_COMPONENT_DE_INIT, data, reply);
772 if (ret != HDF_SUCCESS) {
773 CODEC_LOGE("call failed! error code is %{public}d", ret);
774 ReleaseSbuf(data, reply);
775 return ret;
776 }
777
778 ReleaseSbuf(data, reply);
779 return ret;
780 }
781
CodecComponentTypeProxyUseEglImage(struct CodecComponentType * self,struct OmxCodecBuffer * buffer,uint32_t portIndex,int8_t * eglImage,uint32_t eglImageLen)782 static int32_t CodecComponentTypeProxyUseEglImage(struct CodecComponentType *self,
783 struct OmxCodecBuffer *buffer, uint32_t portIndex, int8_t *eglImage, uint32_t eglImageLen)
784 {
785 int32_t ret;
786
787 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
788 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
789 if (data == NULL || reply == NULL) {
790 CODEC_LOGE("HdfSubf malloc failed!");
791 ReleaseSbuf(data, reply);
792 return HDF_ERR_MALLOC_FAIL;
793 }
794
795 if (!HdfRemoteServiceWriteInterfaceToken(self->AsObject(self), data)) {
796 CODEC_LOGE("write interface token failed");
797 ReleaseSbuf(data, reply);
798 return HDF_FAILURE;
799 }
800
801 if (!OmxCodecBufferBlockMarshalling(data, buffer)) {
802 CODEC_LOGE("write buffer failed!");
803 ReleaseSbuf(data, reply);
804 return HDF_ERR_INVALID_PARAM;
805 }
806
807 if (!HdfSbufWriteUint32(data, portIndex)) {
808 CODEC_LOGE("write portIndex failed!");
809 ReleaseSbuf(data, reply);
810 return HDF_ERR_INVALID_PARAM;
811 }
812
813 if (!HdfSbufWriteUint32(data, eglImageLen)) {
814 CODEC_LOGE("write eglImage failed!");
815 ReleaseSbuf(data, reply);
816 return HDF_ERR_INVALID_PARAM;
817 }
818 for (uint32_t i = 0; i < eglImageLen; i++) {
819 if (!HdfSbufWriteInt8(data, eglImage[i])) {
820 CODEC_LOGE("write eglImage[i] failed!");
821 ReleaseSbuf(data, reply);
822 return HDF_ERR_INVALID_PARAM;
823 }
824 }
825
826 ret = CodecComponentTypeProxyCall(self, CMD_USE_EGL_IMAGE, data, reply);
827 if (ret != HDF_SUCCESS) {
828 CODEC_LOGE("call failed! error code is %{public}d", ret);
829 ReleaseSbuf(data, reply);
830 return ret;
831 }
832
833 if (!OmxCodecBufferBlockUnmarshalling(reply, buffer)) {
834 CODEC_LOGE("read buffer failed!");
835 ReleaseSbuf(data, reply);
836 return HDF_ERR_INVALID_PARAM;
837 }
838
839 ReleaseSbuf(data, reply);
840 return ret;
841 }
842
CodecComponentTypeProxyComponentRoleEnum(struct CodecComponentType * self,uint8_t * role,uint32_t roleLen,uint32_t index)843 static int32_t CodecComponentTypeProxyComponentRoleEnum(struct CodecComponentType *self,
844 uint8_t *role, uint32_t roleLen, uint32_t index)
845 {
846 int32_t ret;
847
848 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
849 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
850 if (data == NULL || reply == NULL) {
851 CODEC_LOGE("HdfSubf malloc failed!");
852 ReleaseSbuf(data, reply);
853 return HDF_ERR_MALLOC_FAIL;
854 }
855
856 if (!HdfRemoteServiceWriteInterfaceToken(self->AsObject(self), data)) {
857 CODEC_LOGE("write interface token failed");
858 ReleaseSbuf(data, reply);
859 return HDF_FAILURE;
860 }
861
862 if (!HdfSbufWriteUint32(data, roleLen)) {
863 CODEC_LOGE("write roleLen failed!");
864 ReleaseSbuf(data, reply);
865 return HDF_ERR_INVALID_PARAM;
866 }
867
868 if (!HdfSbufWriteUint32(data, index)) {
869 CODEC_LOGE("write index failed!");
870 ReleaseSbuf(data, reply);
871 return HDF_ERR_INVALID_PARAM;
872 }
873
874 ret = CodecComponentTypeProxyCall(self, CMD_COMPONENT_ROLE_ENUM, data, reply);
875 if (ret != HDF_SUCCESS) {
876 CODEC_LOGE("call failed! error code is %{public}d", ret);
877 ReleaseSbuf(data, reply);
878 return ret;
879 }
880
881 for (uint32_t i = 0; i < roleLen; i++) {
882 if (!HdfSbufReadUint8(reply, &role[i])) {
883 CODEC_LOGE("read role[i] failed!");
884 ReleaseSbuf(data, reply);
885 return HDF_ERR_INVALID_PARAM;
886 }
887 }
888
889 ReleaseSbuf(data, reply);
890 return ret;
891 }
892
CodecComponentTypeProxyAsObject(struct CodecComponentType * self)893 static struct HdfRemoteService *CodecComponentTypeProxyAsObject(struct CodecComponentType *self)
894 {
895 if (self == NULL) {
896 return NULL;
897 }
898 struct CodecComponentTypeProxy *proxy = CONTAINER_OF(self, struct CodecComponentTypeProxy, instance);
899 return proxy->remote;
900 }
901
CodecComponentTypeProxyConstruct(struct CodecComponentType * instance)902 static void CodecComponentTypeProxyConstruct(struct CodecComponentType *instance)
903 {
904 instance->GetComponentVersion = CodecComponentTypeProxyGetComponentVersion;
905 instance->SendCommand = CodecComponentTypeProxySendCommand;
906 instance->GetParameter = CodecComponentTypeProxyGetParameter;
907 instance->SetParameter = CodecComponentTypeProxySetParameter;
908 instance->GetConfig = CodecComponentTypeProxyGetConfig;
909 instance->SetConfig = CodecComponentTypeProxySetConfig;
910 instance->GetExtensionIndex = CodecComponentTypeProxyGetExtensionIndex;
911 instance->GetState = CodecComponentTypeProxyGetState;
912 instance->ComponentTunnelRequest = CodecComponentTypeProxyComponentTunnelRequest;
913 instance->UseBuffer = CodecComponentTypeProxyUseBuffer;
914 instance->AllocateBuffer = CodecComponentTypeProxyAllocateBuffer;
915 instance->FreeBuffer = CodecComponentTypeProxyFreeBuffer;
916 instance->EmptyThisBuffer = CodecComponentTypeProxyEmptyThisBuffer;
917 instance->FillThisBuffer = CodecComponentTypeProxyFillThisBuffer;
918 instance->SetCallbacks = CodecComponentTypeProxySetCallbacks;
919 instance->ComponentDeInit = CodecComponentTypeProxyComponentDeInit;
920 instance->UseEglImage = CodecComponentTypeProxyUseEglImage;
921 instance->ComponentRoleEnum = CodecComponentTypeProxyComponentRoleEnum;
922 instance->AsObject = CodecComponentTypeProxyAsObject;
923 }
924
CodecComponentTypeGet(struct HdfRemoteService * remote)925 struct CodecComponentType *CodecComponentTypeGet(struct HdfRemoteService *remote)
926 {
927 if (remote == NULL) {
928 CODEC_LOGE("remote is null");
929 return NULL;
930 }
931
932 if (!HdfRemoteServiceSetInterfaceDesc(remote, CODEC_COMPONENT_INTERFACE_DESC)) {
933 CODEC_LOGE("set interface token failed!");
934 HdfRemoteServiceRecycle(remote);
935 return NULL;
936 }
937 struct CodecComponentTypeProxy *proxy =
938 (struct CodecComponentTypeProxy *)OsalMemAlloc(sizeof(struct CodecComponentTypeProxy));
939 if (proxy == NULL) {
940 CODEC_LOGE("malloc CodecComponentType proxy failed!");
941 HdfRemoteServiceRecycle(remote);
942 return NULL;
943 }
944
945 proxy->remote = remote;
946 CodecComponentTypeProxyConstruct(&proxy->instance);
947 return &proxy->instance;
948 }
949
CodecComponentTypeRelease(struct CodecComponentType * instance)950 void CodecComponentTypeRelease(struct CodecComponentType *instance)
951 {
952 CODEC_LOGE("enter!");
953 if (instance == NULL) {
954 return;
955 }
956 struct CodecComponentTypeProxy *proxy = CONTAINER_OF(instance, struct CodecComponentTypeProxy, instance);
957 if (proxy->remote) {
958 HdfRemoteServiceRecycle(proxy->remote);
959 proxy->remote = NULL;
960 }
961 OsalMemFree(proxy);
962 }
963