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