1 /*
2 * Copyright (c) 2021 Huawei Device 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 #include "codec_stub.h"
16 #include <hdf_device_object.h>
17 #include <hdf_log.h>
18 #include <osal_mem.h>
19 #include "codec_callback_proxy.h"
20 #include "codec_interface.h"
21 #include "icodec.h"
22 #include "stub_msgproc.h"
23
24 #define HDF_CODEC_NAME_LEN 50
25
SerCodecInit(struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)26 static int32_t SerCodecInit(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
27 {
28 int32_t errNum = CodecInit();
29 if (errNum != HDF_SUCCESS) {
30 HDF_LOGE("%{public}s: call CodecInit fuc failed!", __func__);
31 return errNum;
32 }
33 if (!HdfSbufWriteUint32(reply, errNum)) {
34 HDF_LOGE("%{public}s: write errNum failed!", __func__);
35 return HDF_ERR_INVALID_PARAM;
36 }
37 return errNum;
38 }
39
SerCodecDeinit(struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)40 static int32_t SerCodecDeinit(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
41 {
42 int32_t errNum = CodecDeinit();
43 if (errNum != HDF_SUCCESS) {
44 HDF_LOGE("%{public}s: call CodecDeinit fuc failed!", __func__);
45 return errNum;
46 }
47 if (!HdfSbufWriteUint32(reply, errNum)) {
48 HDF_LOGE("%{public}s: write errNum failed!", __func__);
49 return HDF_ERR_INVALID_PARAM;
50 }
51 return errNum;
52 }
SerCodecEnumerateCapbility(struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)53 static int32_t SerCodecEnumerateCapbility(struct HdfDeviceIoClient *client, struct HdfSBuf *data,
54 struct HdfSBuf *reply)
55 {
56 uint32_t index;
57 CodecCapbility capbility;
58
59 if (!HdfSbufReadUint32(data, (uint32_t *)&index)) {
60 HDF_LOGE("%{public}s: read index data failed!", __func__);
61 return HDF_ERR_INVALID_PARAM;
62 }
63 int32_t errNum = HDF_SUCCESS;
64 if (errNum != HDF_SUCCESS) {
65 HDF_LOGE("%{public}s: call CodecEnumerateCapbility fuc failed!", __func__);
66 return errNum;
67 }
68 if (CodecSerPackCapbility(reply, &capbility) != HDF_SUCCESS) {
69 HDF_LOGE("%{public}s: write capbility failed!", __func__);
70 return HDF_ERR_INVALID_PARAM;
71 }
72 return errNum;
73 }
74
SerCodecGetCapbility(struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)75 static int32_t SerCodecGetCapbility(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
76 {
77 uint32_t flags;
78 int32_t errNum;
79 AvCodecMime mime;
80 CodecType type;
81 CodecCapbility cap;
82
83 if (!HdfSbufReadUint32(data, (uint32_t*)&mime)) {
84 HDF_LOGE("%{public}s: read input mime failed!", __func__);
85 return HDF_ERR_INVALID_PARAM;
86 }
87 if (!HdfSbufReadUint32(data, (uint32_t*)&type)) {
88 HDF_LOGE("%{public}s: read input type failed!", __func__);
89 return HDF_ERR_INVALID_PARAM;
90 }
91 if (!HdfSbufReadUint32(data, &flags)) {
92 HDF_LOGE("%{public}s: read input flags failed!", __func__);
93 return HDF_ERR_INVALID_PARAM;
94 }
95 errNum = CodecGetCapbility(mime, type, flags, &cap);
96 if (errNum != HDF_SUCCESS) {
97 HDF_LOGE("%{public}s: call CodecGetCapbility fuc failed!", __func__);
98 return errNum;
99 }
100 if (CodecSerPackCapbility(reply, &cap) != HDF_SUCCESS) {
101 HDF_LOGE("%{public}s: write cap failed!", __func__);
102 return HDF_ERR_INVALID_PARAM;
103 }
104 return errNum;
105 }
106
SerCodecCreate(struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)107 static int32_t SerCodecCreate(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
108 {
109 int32_t len = 0;
110 int32_t errNum;
111 uint32_t handle = 0;
112 uint32_t dateSize = 0;
113 const char *name = NULL;
114 Param attr;
115
116 name = HdfSbufReadString(data);
117 if (name == NULL) {
118 HDF_LOGE("%{public}s: Read name failed!", __func__);
119 return HDF_ERR_INVALID_PARAM;
120 }
121 if (!HdfSbufReadUint32(data, (uint32_t *)&attr.key)) {
122 HDF_LOGE("%{public}s: Read name failed!", __func__);
123 return HDF_ERR_INVALID_PARAM;
124 }
125 if (!HdfSbufReadInt32(data, &attr.size)) {
126 HDF_LOGE("%{public}s: Read size failed!", __func__);
127 return HDF_ERR_INVALID_PARAM;
128 }
129 if (!HdfSbufReadBuffer(data, (const void **)&attr.val, &dateSize)) {
130 HDF_LOGE("%{public}s: struct attr's value Read failed", __func__);
131 return HDF_ERR_INVALID_PARAM;
132 }
133 if (!HdfSbufReadInt32(data, &len)) {
134 HDF_LOGE("%{public}s: Read name failed!", __func__);
135 return HDF_ERR_INVALID_PARAM;
136 }
137 if (!HdfSbufReadUint32(data, &handle)) {
138 HDF_LOGE("%{public}s: Read handle failed!", __func__);
139 return HDF_ERR_INVALID_PARAM;
140 }
141 errNum = CodecCreate(name, (const Param *)&attr, len, (CODEC_HANDLETYPE *)&handle);
142 if (errNum != HDF_SUCCESS) {
143 HDF_LOGE("%{public}s: call CodecCreate fuc failed!", __func__);
144 return errNum;
145 }
146 if (!HdfSbufWriteUint32(reply, handle)) {
147 HDF_LOGE("%{public}s: write handle failed!", __func__);
148 return HDF_ERR_INVALID_PARAM;
149 }
150 return errNum;
151 }
SerCodecDestroy(struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)152 static int32_t SerCodecDestroy(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
153 {
154 int32_t errNum;
155 uint32_t handle = 0;
156 if (!HdfSbufReadUint32(data, &handle)) {
157 HDF_LOGE("%{public}s: Read size failed!", __func__);
158 return HDF_ERR_INVALID_PARAM;
159 }
160 errNum = CodecDestroy((CODEC_HANDLETYPE)&handle);
161 if (errNum != HDF_SUCCESS) {
162 HDF_LOGE("%{public}s: call CodecDestroy fuc failed!", __func__);
163 return errNum;
164 }
165 return errNum;
166 }
167
SerCodecSetPortMode(struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)168 static int32_t SerCodecSetPortMode(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
169 {
170 int32_t errNum;
171 uint32_t handle = 0;
172 DirectionType type;
173 BufferMode mode;
174
175 if (!HdfSbufReadUint32(data, &handle)) {
176 HDF_LOGE("%{public}s: Read size failed!", __func__);
177 return HDF_ERR_INVALID_PARAM;
178 }
179 if (!HdfSbufReadUint32(data, (uint32_t*)&type)) {
180 HDF_LOGE("%{public}s: Read size failed!", __func__);
181 return HDF_ERR_INVALID_PARAM;
182 }
183 if (!HdfSbufReadUint32(data, (uint32_t*)&mode)) {
184 HDF_LOGE("%{public}s: Read size failed!", __func__);
185 return HDF_ERR_INVALID_PARAM;
186 }
187 errNum = CodecSetPortMode((CODEC_HANDLETYPE)&handle, type, mode);
188 if (errNum != HDF_SUCCESS) {
189 HDF_LOGE("%{public}s: call CodecSetPortMode fuc failed!", __func__);
190 return errNum;
191 }
192 return errNum;
193 }
194
SerCodecSetParameter(struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)195 static int32_t SerCodecSetParameter(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
196 {
197 int32_t errNum;
198 int32_t paramCnt = 0;
199 uint32_t handle = 0;
200 Param *params = NULL;
201
202 if (!HdfSbufReadUint32(data, &handle)) {
203 HDF_LOGE("%{public}s: Read handle failed!", __func__);
204 return HDF_ERR_INVALID_PARAM;
205 }
206 if (!HdfSbufReadInt32(data, ¶mCnt)) {
207 HDF_LOGE("%{public}s: Read paramCnt failed!", __func__);
208 return HDF_ERR_INVALID_PARAM;
209 }
210 if (paramCnt <= 0) {
211 HDF_LOGE("%{public}s: Param paramCnt err!", __func__);
212 return HDF_ERR_INVALID_PARAM;
213 }
214 params = (Param *)OsalMemAlloc(sizeof(Param)*paramCnt);
215 if (params == NULL) {
216 HDF_LOGE("%{public}s: OsalMemAlloc failed!", __func__);
217 return HDF_ERR_INVALID_PARAM;
218 }
219 for (int32_t i = 0; i < paramCnt; i++) {
220 if (CodecSerParseParam(data, ¶ms[i]) != HDF_SUCCESS) {
221 HDF_LOGE("%{public}s: Read params failed!", __func__);
222 OsalMemFree(params);
223 return HDF_FAILURE;
224 }
225 }
226 errNum = CodecSetParameter((CODEC_HANDLETYPE)&handle, params, paramCnt);
227 if (errNum != HDF_SUCCESS) {
228 HDF_LOGE("%{public}s: call CodecSetParameter fuc failed!", __func__);
229 }
230 OsalMemFree(params);
231 return errNum;
232 }
SerCodecGetParameter(struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)233 static int32_t SerCodecGetParameter(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
234 {
235 int32_t errNum;
236 int32_t paramCnt = 0;
237 uint32_t handle = 0;
238 Param *params = NULL;
239
240 if (!HdfSbufReadUint32(data, &handle)) {
241 HDF_LOGE("%{public}s: Read handle failed!", __func__);
242 return HDF_ERR_INVALID_PARAM;
243 }
244 if (!HdfSbufReadInt32(data, ¶mCnt)) {
245 HDF_LOGE("%{public}s: Read paramCnt failed!", __func__);
246 return HDF_ERR_INVALID_PARAM;
247 }
248 if (paramCnt <= 0) {
249 HDF_LOGE("%{public}s: Param paramCnt err!", __func__);
250 return HDF_ERR_INVALID_PARAM;
251 }
252 params = (Param *)OsalMemAlloc(sizeof(Param)*paramCnt);
253 if (params == NULL) {
254 HDF_LOGE("%{public}s: OsalMemAlloc failed!", __func__);
255 return HDF_ERR_INVALID_PARAM;
256 }
257 for (int32_t i = 0; i < paramCnt; i++) {
258 if (CodecSerParseParam(data, ¶ms[i]) != HDF_SUCCESS) {
259 HDF_LOGE("%{public}s: Read params failed!", __func__);
260 OsalMemFree(params);
261 return HDF_FAILURE;
262 }
263 }
264 errNum = CodecGetParameter((CODEC_HANDLETYPE)&handle, params, paramCnt);
265 if (errNum != HDF_SUCCESS) {
266 HDF_LOGE("%{public}s: call CodecGetParameter fuc failed!", __func__);
267 OsalMemFree(params);
268 return errNum;
269 }
270 for (int32_t i = 0; i < paramCnt; i++) {
271 if (CodecSerPackParam(reply, ¶ms[i]) != HDF_SUCCESS) {
272 HDF_LOGE("%{public}s: CodecSerPackParam err!", __func__);
273 OsalMemFree(params);
274 return HDF_FAILURE;
275 }
276 }
277 OsalMemFree(params);
278 return errNum;
279 }
SerCodecStart(struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)280 static int32_t SerCodecStart(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
281 {
282 int32_t errNum;
283 uint32_t handle = 0;
284
285 if (!HdfSbufReadUint32(data, &handle)) {
286 HDF_LOGE("%{public}s: Read handle failed!", __func__);
287 return HDF_ERR_INVALID_PARAM;
288 }
289 errNum = CodecStart((CODEC_HANDLETYPE)&handle);
290 if (errNum != HDF_SUCCESS) {
291 HDF_LOGE("%{public}s: call SerCodecStart fuc failed!", __func__);
292 return errNum;
293 }
294 return errNum;
295 }
296
SerCodecStop(struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)297 static int32_t SerCodecStop(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
298 {
299 uint32_t handle = 0;
300 if (!HdfSbufReadUint32(data, &handle)) {
301 HDF_LOGE("%{public}s: read handle data failed!", __func__);
302 return HDF_ERR_INVALID_PARAM;
303 }
304 int32_t errNum = CodecStop((CODEC_HANDLETYPE)&handle);
305 if (errNum != HDF_SUCCESS) {
306 HDF_LOGE("%{public}s: call CodecStop fuc failed!", __func__);
307 return errNum;
308 }
309 return errNum;
310 }
SerCodecFlush(struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)311 static int32_t SerCodecFlush(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
312 {
313 uint32_t handle = 0;
314 uint32_t directType = 0;
315 if (!HdfSbufReadUint32(data, &handle)) {
316 HDF_LOGE("%{public}s: read handle data failed!", __func__);
317 return HDF_ERR_INVALID_PARAM;
318 }
319 if (!HdfSbufReadUint32(data, &directType)) {
320 HDF_LOGE("%{public}s: read directType data failed!", __func__);
321 return HDF_ERR_INVALID_PARAM;
322 }
323 int32_t errNum = CodecFlush((CODEC_HANDLETYPE)&handle, (DirectionType)directType);
324 if (errNum != HDF_SUCCESS) {
325 HDF_LOGE("%{public}s: call CodecFlush fuc failed!", __func__);
326 return errNum;
327 }
328 return errNum;
329 }
SerCodecQueueInput(struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)330 int32_t SerCodecQueueInput(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
331 {
332 uint32_t timeoutMs = 0;
333 uint32_t handle = 0;
334 uint32_t bufCnt;
335 InputInfo inputData = {0};
336 if (!HdfSbufReadUint32(data, &handle)) {
337 HDF_LOGE("%{public}s: read handle data failed!", __func__);
338 return HDF_ERR_INVALID_PARAM;
339 }
340 if (!HdfSbufReadUint32(data, (uint32_t *)&inputData.bufferCnt)) {
341 HDF_LOGE("%{public}s: read bufferCnt failed!", __func__);
342 return HDF_ERR_INVALID_PARAM;
343 }
344 bufCnt = inputData.bufferCnt;
345 if (bufCnt <= 0) {
346 HDF_LOGE("%{public}s: Param bufCnt err!", __func__);
347 return HDF_ERR_INVALID_PARAM;
348 }
349 inputData.buffers = (CodecBufferInfo *)OsalMemAlloc(sizeof(CodecBufferInfo) * bufCnt);
350 if (inputData.buffers == NULL) {
351 HDF_LOGE("%{public}s: OsalMemAlloc failed!", __func__);
352 return HDF_ERR_INVALID_PARAM;
353 }
354 if (CodecSerParseInputInfo(data, &inputData)) {
355 HDF_LOGE("%{public}s: read inputData failed!", __func__);
356 OsalMemFree(inputData.buffers);
357 return HDF_ERR_INVALID_PARAM;
358 }
359 if (!HdfSbufReadUint32(data, &timeoutMs)) {
360 HDF_LOGE("%{public}s: read timeoutMs data failed!", __func__);
361 OsalMemFree(inputData.buffers);
362 return HDF_ERR_INVALID_PARAM;
363 }
364 int32_t errNum = CodecQueueInput((CODEC_HANDLETYPE)&handle, &inputData, timeoutMs);
365 if (errNum != HDF_SUCCESS) {
366 HDF_LOGE("%{public}s: call CodecQueueInput fuc failed!", __func__);
367 OsalMemFree(inputData.buffers);
368 return errNum;
369 }
370 OsalMemFree(inputData.buffers);
371 return errNum;
372 }
SerCodecDequeInput(struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)373 static int32_t SerCodecDequeInput(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
374 {
375 uint32_t timeoutMs = 0;
376 uint32_t handle = 0;
377 InputInfo inputData = {0};
378 if (!HdfSbufReadUint32(data, &handle)) {
379 HDF_LOGE("%{public}s: read handle data failed!", __func__);
380 return HDF_ERR_INVALID_PARAM;
381 }
382 if (!HdfSbufReadUint32(data, &timeoutMs)) {
383 HDF_LOGE("%{public}s: read timeoutMs data failed!", __func__);
384 return HDF_ERR_INVALID_PARAM;
385 }
386 if (!HdfSbufReadUint32(data, &inputData.bufferCnt)) {
387 HDF_LOGE("%{public}s: read bufferCnt data failed!", __func__);
388 return HDF_ERR_INVALID_PARAM;
389 }
390 if (inputData.bufferCnt <= 0) {
391 HDF_LOGE("%{public}s: Param bufferCnt err!", __func__);
392 return HDF_ERR_INVALID_PARAM;
393 }
394 inputData.buffers = (CodecBufferInfo *)OsalMemAlloc(sizeof(CodecBufferInfo) * (inputData.bufferCnt));
395 if (inputData.buffers == NULL) {
396 HDF_LOGE("%{public}s: OsalMemAlloc failed!", __func__);
397 return HDF_ERR_INVALID_PARAM;
398 }
399 int32_t errNum = CodecDequeInput((CODEC_HANDLETYPE)&handle, timeoutMs, &inputData);
400 if (errNum != HDF_SUCCESS) {
401 HDF_LOGE("%{public}s: call CodecDequeInput fuc failed!", __func__);
402 OsalMemFree(inputData.buffers);
403 return errNum;
404 }
405 if (CodecSerPackInputInfo(reply, &inputData)) {
406 HDF_LOGE("%{public}s: struct inputData write failed!", __func__);
407 OsalMemFree(inputData.buffers);
408 return HDF_ERR_INVALID_PARAM;
409 }
410 OsalMemFree(inputData.buffers);
411 return errNum;
412 }
SerCodecQueueOutput(struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)413 static int32_t SerCodecQueueOutput(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
414 {
415 uint32_t timeoutMs = 0;
416 int releaseFenceFd;
417 uint32_t handle = 0;
418 uint32_t bufCnt;
419 OutputInfo outInfo = {0};
420 if (!HdfSbufReadUint32(data, &handle)) {
421 HDF_LOGE("%{public}s: read handle data failed!", __func__);
422 return HDF_ERR_INVALID_PARAM;
423 }
424 if (!HdfSbufReadUint32(data, (uint32_t *)&outInfo.bufferCnt)) {
425 HDF_LOGE("%{public}s: read bufferCnt failed!", __func__);
426 return HDF_ERR_INVALID_PARAM;
427 }
428 bufCnt = outInfo.bufferCnt;
429 if (bufCnt <= 0) {
430 HDF_LOGE("%{public}s: Param bufferCnt err!", __func__);
431 return HDF_ERR_INVALID_PARAM;
432 }
433 outInfo.buffers = (CodecBufferInfo *)OsalMemAlloc(sizeof(CodecBufferInfo) * bufCnt);
434 if (outInfo.buffers == NULL) {
435 HDF_LOGE("%{public}s: OsalMemAlloc failed!", __func__);
436 return HDF_ERR_INVALID_PARAM;
437 }
438 if (CodecSerParseOutputInfo(data, &outInfo)) {
439 HDF_LOGE("%{public}s: read struct data failed!", __func__);
440 OsalMemFree(outInfo.buffers);
441 return HDF_ERR_INVALID_PARAM;
442 }
443 if (!HdfSbufReadUint32(data, &timeoutMs)) {
444 HDF_LOGE("%{public}s: read timeoutMs data failed!", __func__);
445 OsalMemFree(outInfo.buffers);
446 return HDF_ERR_INVALID_PARAM;
447 }
448 releaseFenceFd = HdfSbufReadFileDescriptor(data);
449 if (releaseFenceFd < 0) {
450 HDF_LOGE("%{public}s: read timeoutMs data failed!", __func__);
451 OsalMemFree(outInfo.buffers);
452 return HDF_ERR_INVALID_PARAM;
453 }
454 int32_t errNum = CodecQueueOutput((CODEC_HANDLETYPE)&handle, &outInfo, timeoutMs, releaseFenceFd);
455 if (errNum != HDF_SUCCESS) {
456 HDF_LOGE("%{public}s: call CodecQueueOutput fuc failed!", __func__);
457 OsalMemFree(outInfo.buffers);
458 return errNum;
459 }
460 OsalMemFree(outInfo.buffers);
461 return errNum;
462 }
SerCodecDequeueOutput(struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)463 static int32_t SerCodecDequeueOutput(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
464 {
465 uint32_t timeoutMs = 0;
466 int acquireFd = 0;
467 uint32_t handle = 0;
468 OutputInfo outInfo = {0};
469 if (!HdfSbufReadUint32(data, &handle)) {
470 HDF_LOGE("%{public}s: read handle data failed!", __func__);
471 return HDF_ERR_INVALID_PARAM;
472 }
473 if (!HdfSbufReadUint32(data, &timeoutMs)) {
474 HDF_LOGE("%{public}s: read timeoutMs data failed!", __func__);
475 return HDF_ERR_INVALID_PARAM;
476 }
477 if (!HdfSbufReadUint32(data, &outInfo.bufferCnt)) {
478 HDF_LOGE("%{public}s: read bufferCnt data failed!", __func__);
479 return HDF_ERR_INVALID_PARAM;
480 }
481 outInfo.buffers = (CodecBufferInfo *)OsalMemAlloc(sizeof(CodecBufferInfo) * (outInfo.bufferCnt));
482 if (outInfo.buffers == NULL) {
483 HDF_LOGE("%{public}s: OsalMemAlloc failed!", __func__);
484 return HDF_ERR_INVALID_PARAM;
485 }
486 int32_t errNum = CodecDequeueOutput((CODEC_HANDLETYPE)&handle, timeoutMs, &acquireFd, &outInfo);
487 if (errNum != HDF_SUCCESS) {
488 HDF_LOGE("%{public}s: call CodecDequeueOutput fuc failed!", __func__);
489 OsalMemFree(outInfo.buffers);
490 return errNum;
491 }
492 if (!HdfSbufWriteFileDescriptor(reply, acquireFd)) {
493 HDF_LOGE("%{public}s: write acquireFd failed!", __func__);
494 OsalMemFree(outInfo.buffers);
495 return HDF_ERR_INVALID_PARAM;
496 }
497 if (CodecSerPackOutputInfo(reply, &outInfo)) {
498 HDF_LOGE("%{public}s: write outInfo buffer failed!", __func__);
499 OsalMemFree(outInfo.buffers);
500 return HDF_ERR_INVALID_PARAM;
501 }
502 OsalMemFree(outInfo.buffers);
503 return errNum;
504 }
505
SerCodecSetCallback(struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)506 static int32_t SerCodecSetCallback(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
507 {
508 uint32_t handle = 0;
509 UINTPTR instance;
510 struct ICodecCallback *cb = NULL;
511 if (!HdfSbufReadUint32(data, &handle)) {
512 HDF_LOGE("%{public}s: read handle data failed!", __func__);
513 return HDF_ERR_INVALID_PARAM;
514 }
515 struct HdfRemoteService *cbRemote = HdfSbufReadRemoteService(data);
516 if (cbRemote == NULL) {
517 HDF_LOGE("%{public}s: read cbRemote failed!", __func__);
518 return HDF_ERR_INVALID_PARAM;
519 }
520 cb = CodecProxyCallbackObtain(cbRemote);
521 if (!HdfSbufReadUint32(data, (uint32_t *)&instance)) {
522 HDF_LOGE("%{public}s: read instance data failed!", __func__);
523 return HDF_ERR_INVALID_PARAM;
524 }
525 int32_t errNum = CodecSetCallback((CODEC_HANDLETYPE)&handle, &cb->callback, instance);
526 if (errNum != HDF_SUCCESS) {
527 HDF_LOGE("%{public}s: call CodecSetCallback fuc failed!", __func__);
528 return errNum;
529 }
530 return errNum;
531 }
532
CodecServiceOnRemoteRequest(struct HdfDeviceIoClient * client,int cmdId,struct HdfSBuf * data,struct HdfSBuf * reply)533 int32_t CodecServiceOnRemoteRequest(struct HdfDeviceIoClient *client, int cmdId,
534 struct HdfSBuf *data, struct HdfSBuf *reply)
535 {
536 if (!HdfDeviceObjectCheckInterfaceDesc(client->device, data)) {
537 HDF_LOGE("check interface token failed");
538 return HDF_ERR_INVALID_PARAM;
539 }
540 switch (cmdId) {
541 case CMD_CODEC_INIT:
542 return SerCodecInit(client, data, reply);
543 case CMD_CODEC_DEINIT:
544 return SerCodecDeinit(client, data, reply);
545 case CMD_CODEC_ENUM_CAP:
546 return SerCodecEnumerateCapbility(client, data, reply);
547 case CMD_CODEC_GET_CAP:
548 return SerCodecGetCapbility(client, data, reply);
549 case CMD_CODEC_CREATE:
550 return SerCodecCreate(client, data, reply);
551 case CMD_CODEC_DESTROY:
552 return SerCodecDestroy(client, data, reply);
553 case CMD_CODEC_SET_MODE:
554 return SerCodecSetPortMode(client, data, reply);
555 case CMD_CODEC_SET_PARAMS:
556 return SerCodecSetParameter(client, data, reply);
557 case CMD_CODEC_GET_PARAMS:
558 return SerCodecGetParameter(client, data, reply);
559 case CMD_CODEC_START:
560 return SerCodecStart(client, data, reply);
561 case CMD_CODEC_STOP:
562 return SerCodecStop(client, data, reply);
563 case CMD_CODEC_FLUSH:
564 return SerCodecFlush(client, data, reply);
565 case CMD_CODEC_QUEQUE_INPUT:
566 return SerCodecQueueInput(client, data, reply);
567 case CMD_CODEC_DEQUEQUE_INPUT:
568 return SerCodecDequeInput(client, data, reply);
569 case CMD_CODEC_QUEQUE_OUTPUT:
570 return SerCodecQueueOutput(client, data, reply);
571 case CMD_CODEC_DEQUEQUE_OUTPUT:
572 return SerCodecDequeueOutput(client, data, reply);
573 case CMD_CODEC_SET_CBK:
574 return SerCodecSetCallback(client, data, reply);
575 default: {
576 HDF_LOGE("%{public}s: not support cmd %{public}d", __func__, cmdId);
577 return HDF_ERR_INVALID_PARAM;
578 }
579 }
580 }
581