• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_log.h>
17 #include <osal_mem.h>
18 #include "codec_callback_proxy.h"
19 #include "codec_interface.h"
20 #include "icodec.h"
21 #include "stub_msgproc.h"
22 
23 #define HDF_CODEC_NAME_LEN 50
24 
SerCodecInit(struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)25 static int32_t SerCodecInit(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
26 {
27     int32_t errNum = CodecInit();
28     if (errNum != HDF_SUCCESS) {
29         HDF_LOGE("%{public}s: call CodecInit fuc failed!", __func__);
30         return errNum;
31     }
32     if (!HdfSbufWriteUint32(reply, errNum)) {
33         HDF_LOGE("%{public}s: write errNum failed!", __func__);
34         return HDF_ERR_INVALID_PARAM;
35     }
36     return errNum;
37 }
38 
SerCodecDeinit(struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)39 static int32_t SerCodecDeinit(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
40 {
41     int32_t errNum = CodecDeinit();
42     if (errNum != HDF_SUCCESS) {
43         HDF_LOGE("%{public}s: call CodecDeinit fuc failed!", __func__);
44         return errNum;
45     }
46     if (!HdfSbufWriteUint32(reply, errNum)) {
47         HDF_LOGE("%{public}s: write errNum failed!", __func__);
48         return HDF_ERR_INVALID_PARAM;
49     }
50     return errNum;
51 }
SerCodecEnumerateCapbility(struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)52 static int32_t SerCodecEnumerateCapbility(struct HdfDeviceIoClient *client, struct HdfSBuf *data,
53                                           struct HdfSBuf *reply)
54 {
55     uint32_t index;
56     CodecCapbility capbility;
57 
58     if (!HdfSbufReadUint32(data, (uint32_t *)&index)) {
59         HDF_LOGE("%{public}s: read index data failed!", __func__);
60         return HDF_ERR_INVALID_PARAM;
61     }
62     int32_t errNum = HDF_SUCCESS; // CodecEnumerateCapbility(index, &capbility); libcodec.so undifined
63     if (errNum != HDF_SUCCESS) {
64         HDF_LOGE("%{public}s: call CodecEnumerateCapbility fuc failed!", __func__);
65         return errNum;
66     }
67     if (CodecSerPackCapbility(reply, &capbility) != HDF_SUCCESS) {
68         HDF_LOGE("%{public}s: write capbility failed!", __func__);
69         return HDF_ERR_INVALID_PARAM;
70     }
71     return errNum;
72 }
73 
SerCodecGetCapbility(struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)74 static int32_t SerCodecGetCapbility(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
75 {
76     uint32_t flags;
77     int32_t errNum;
78     AvCodecMime mime;
79     CodecType type;
80     CodecCapbility cap;
81 
82     if (!HdfSbufReadUint32(data, (uint32_t*)&mime)) {
83         HDF_LOGE("%{public}s: read input mime failed!", __func__);
84         return HDF_ERR_INVALID_PARAM;
85     }
86     if (!HdfSbufReadUint32(data, (uint32_t*)&type)) {
87         HDF_LOGE("%{public}s: read input type failed!", __func__);
88         return HDF_ERR_INVALID_PARAM;
89     }
90     if (!HdfSbufReadUint32(data, &flags)) {
91         HDF_LOGE("%{public}s: read input flags failed!", __func__);
92         return HDF_ERR_INVALID_PARAM;
93     }
94     errNum = CodecGetCapbility(mime, type, flags, &cap);
95     if (errNum != HDF_SUCCESS) {
96         HDF_LOGE("%{public}s: call CodecGetCapbility fuc failed!", __func__);
97         return errNum;
98     }
99     if (CodecSerPackCapbility(reply, &cap) != HDF_SUCCESS) {
100         HDF_LOGE("%{public}s: write cap failed!", __func__);
101         return HDF_ERR_INVALID_PARAM;
102     }
103     return errNum;
104 }
105 // todo handle+buffer
SerCodecCreate(struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)106 static int32_t SerCodecCreate(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
107 {
108     int32_t len = 0;
109     int32_t errNum;
110     uint32_t handle = 0;
111     uint32_t dateSize = 0;
112     const char *name = NULL;
113     Param attr;
114 
115     name = HdfSbufReadString(data);
116     if (name == NULL) {
117         HDF_LOGE("%{public}s: Read name failed!", __func__);
118         return HDF_ERR_INVALID_PARAM;
119     }
120     if (!HdfSbufReadUint32(data, (uint32_t *)&attr.key)) {
121         HDF_LOGE("%{public}s: Read name failed!", __func__);
122         return HDF_ERR_INVALID_PARAM;
123     }
124     if (!HdfSbufReadInt32(data, &attr.size)) {
125         HDF_LOGE("%{public}s: Read size failed!", __func__);
126         return HDF_ERR_INVALID_PARAM;
127     }
128     if (!HdfSbufReadBuffer(data, (const void **)&attr.val, &dateSize)) {
129         HDF_LOGE("%{public}s: struct attr's value Read failed", __func__);
130         return HDF_ERR_INVALID_PARAM;
131     }
132     if (!HdfSbufReadInt32(data, &len)) {
133         HDF_LOGE("%{public}s: Read name failed!", __func__);
134         return HDF_ERR_INVALID_PARAM;
135     }
136     if (!HdfSbufReadUint32(data, &handle)) {
137         HDF_LOGE("%{public}s: Read handle failed!", __func__);
138         return HDF_ERR_INVALID_PARAM;
139     }
140     errNum = CodecCreate(name, (const Param *)&attr, len, (CODEC_HANDLETYPE *)&handle);
141     if (errNum != HDF_SUCCESS) {
142         HDF_LOGE("%{public}s: call CodecCreate fuc failed!", __func__);
143         return errNum;
144     }
145     if (!HdfSbufWriteUint32(reply, handle)) {
146         HDF_LOGE("%{public}s: write handle failed!", __func__);
147         return HDF_ERR_INVALID_PARAM;
148     }
149     return errNum;
150 }
SerCodecDestroy(struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)151 static int32_t SerCodecDestroy(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
152 {
153     int32_t errNum;
154     uint32_t handle = 0;
155     if (!HdfSbufReadUint32(data, &handle)) {
156         HDF_LOGE("%{public}s: Read size failed!", __func__);
157         return HDF_ERR_INVALID_PARAM;
158     }
159     errNum = CodecDestroy((CODEC_HANDLETYPE)&handle);
160     if (errNum != HDF_SUCCESS) {
161         HDF_LOGE("%{public}s: call CodecDestroy fuc failed!", __func__);
162         return errNum;
163     }
164     return errNum;
165 }
166 
167 // todo handle
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 // todo handle
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, &paramCnt)) {
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, &params[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, &paramCnt)) {
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, &params[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, &params[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 = 0;
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     if (!HdfSbufReadInt32(data, &releaseFenceFd)) {
449         HDF_LOGE("%{public}s: read timeoutMs data failed!", __func__);
450         OsalMemFree(outInfo.buffers);
451         return HDF_ERR_INVALID_PARAM;
452     }
453     int32_t errNum = CodecQueueOutput((CODEC_HANDLETYPE)&handle, &outInfo, timeoutMs, releaseFenceFd);
454     if (errNum != HDF_SUCCESS) {
455         HDF_LOGE("%{public}s: call CodecQueueOutput fuc failed!", __func__);
456         OsalMemFree(outInfo.buffers);
457         return errNum;
458     }
459     OsalMemFree(outInfo.buffers);
460     return errNum;
461 }
SerCodecDequeueOutput(struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)462 static int32_t SerCodecDequeueOutput(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
463 {
464     uint32_t timeoutMs = 0;
465     int acquireFd = 0;
466     uint32_t handle = 0;
467     OutputInfo outInfo = {0};
468     if (!HdfSbufReadUint32(data, &handle)) {
469         HDF_LOGE("%{public}s: read handle data failed!", __func__);
470         return HDF_ERR_INVALID_PARAM;
471     }
472     if (!HdfSbufReadUint32(data, &timeoutMs)) {
473         HDF_LOGE("%{public}s: read timeoutMs data failed!", __func__);
474         return HDF_ERR_INVALID_PARAM;
475     }
476     if (!HdfSbufReadUint32(data, &outInfo.bufferCnt)) {
477         HDF_LOGE("%{public}s: read bufferCnt data failed!", __func__);
478         return HDF_ERR_INVALID_PARAM;
479     }
480     outInfo.buffers = (CodecBufferInfo *)OsalMemAlloc(sizeof(CodecBufferInfo) * (outInfo.bufferCnt));
481     if (outInfo.buffers == NULL) {
482         HDF_LOGE("%{public}s: OsalMemAlloc failed!", __func__);
483         return HDF_ERR_INVALID_PARAM;
484     }
485     int32_t errNum = CodecDequeueOutput((CODEC_HANDLETYPE)&handle, timeoutMs, &acquireFd, &outInfo);
486     if (errNum != HDF_SUCCESS) {
487         HDF_LOGE("%{public}s: call CodecDequeueOutput fuc failed!", __func__);
488         OsalMemFree(outInfo.buffers);
489         return errNum;
490     }
491     if (!HdfSbufWriteInt32(reply, acquireFd)) {
492         HDF_LOGE("%{public}s: write acquireFd failed!", __func__);
493         OsalMemFree(outInfo.buffers);
494         return HDF_ERR_INVALID_PARAM;
495     }
496     if (CodecSerPackOutputInfo(reply, &outInfo)) {
497         HDF_LOGE("%{public}s: write outInfo buffer failed!", __func__);
498         OsalMemFree(outInfo.buffers);
499         return HDF_ERR_INVALID_PARAM;
500     }
501     OsalMemFree(outInfo.buffers);
502     return errNum;
503 }
504 
SerCodecSetCallback(struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)505 static int32_t SerCodecSetCallback(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
506 {
507     uint32_t handle = 0;
508     UINTPTR instance;
509     struct ICodecCallback *cb = NULL;
510     if (!HdfSbufReadUint32(data, &handle)) {
511         HDF_LOGE("%{public}s: read handle data failed!", __func__);
512         return HDF_ERR_INVALID_PARAM;
513     }
514     struct HdfRemoteService *cbRemote = HdfSBufReadRemoteService(data);
515     if (cbRemote == NULL) {
516         HDF_LOGE("%{public}s: read cbRemote failed!", __func__);
517         return HDF_ERR_INVALID_PARAM;
518     }
519     cb = CodecProxyCallbackObtain(cbRemote);
520     if (!HdfSbufReadUint32(data, (uint32_t *)&instance)) {
521         HDF_LOGE("%{public}s: read instance data failed!", __func__);
522         return HDF_ERR_INVALID_PARAM;
523     }
524     int32_t errNum = CodecSetCallback((CODEC_HANDLETYPE)&handle, &cb->callback, instance);
525     if (errNum != HDF_SUCCESS) {
526         HDF_LOGE("%{public}s: call CodecSetCallback fuc failed!", __func__);
527         return errNum;
528     }
529     return errNum;
530 }
531 
CodecServiceOnRemoteRequest(struct HdfDeviceIoClient * client,int cmdId,struct HdfSBuf * data,struct HdfSBuf * reply)532 int32_t CodecServiceOnRemoteRequest(struct HdfDeviceIoClient *client, int cmdId,
533     struct HdfSBuf *data, struct HdfSBuf *reply)
534 {
535     switch (cmdId) {
536         case CMD_CODEC_INIT:
537             return SerCodecInit(client, data, reply);
538         case CMD_CODEC_DEINIT:
539             return SerCodecDeinit(client, data, reply);
540         case CMD_CODEC_ENUM_CAP:
541             return SerCodecEnumerateCapbility(client, data, reply);
542         case CMD_CODEC_GET_CAP:
543             return SerCodecGetCapbility(client, data, reply);
544         case CMD_CODEC_CREATE:
545             return SerCodecCreate(client, data, reply);
546         case CMD_CODEC_DESTROY:
547             return SerCodecDestroy(client, data, reply);
548         case CMD_CODEC_SET_MODE:
549             return SerCodecSetPortMode(client, data, reply);
550         case CMD_CODEC_SET_PARAMS:
551             return SerCodecSetParameter(client, data, reply);
552         case CMD_CODEC_GET_PARAMS:
553             return SerCodecGetParameter(client, data, reply);
554         case CMD_CODEC_START:
555             return SerCodecStart(client, data, reply);
556         case CMD_CODEC_STOP:
557             return SerCodecStop(client, data, reply);
558         case CMD_CODEC_FLUSH:
559             return SerCodecFlush(client, data, reply);
560         case CMD_CODEC_QUEQUE_INPUT:
561             return SerCodecQueueInput(client, data, reply);
562         case CMD_CODEC_DEQUEQUE_INPUT:
563             return SerCodecDequeInput(client, data, reply);
564         case CMD_CODEC_QUEQUE_OUTPUT:
565             return SerCodecQueueOutput(client, data, reply);
566         case CMD_CODEC_DEQUEQUE_OUTPUT:
567             return SerCodecDequeueOutput(client, data, reply);
568         case CMD_CODEC_SET_CBK:
569             return SerCodecSetCallback(client, data, reply);
570         default: {
571             HDF_LOGE("%{public}s: not support cmd %{public}d", __func__, cmdId);
572             return HDF_ERR_INVALID_PARAM;
573         }
574     }
575 }
576