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 "stub_msgproc.h"
16 #include <hdf_log.h>
17 #include <osal_mem.h>
18 #include "codec_interface.h"
19
CodecSerPackAlginment(struct HdfSBuf * reply,Alginment * alginment)20 int32_t CodecSerPackAlginment(struct HdfSBuf *reply, Alginment *alginment)
21 {
22 if (reply == NULL || alginment == NULL) {
23 HDF_LOGE("%{public}s: params null!", __func__);
24 return HDF_ERR_INVALID_PARAM;
25 }
26 if (!HdfSbufWriteInt32(reply, alginment->widthAlginment)) {
27 HDF_LOGE("%{public}s: Write widthAlginment failed!", __func__);
28 return HDF_FAILURE;
29 }
30 if (!HdfSbufWriteInt32(reply, alginment->heightAlginment)) {
31 HDF_LOGE("%{public}s: Write heightAlginment failed!", __func__);
32 return HDF_FAILURE;
33 }
34 return HDF_SUCCESS;
35 }
36
CodecSerPackRect(struct HdfSBuf * reply,Rect * rectangle)37 int32_t CodecSerPackRect(struct HdfSBuf *reply, Rect *rectangle)
38 {
39 if (reply == NULL || rectangle == NULL) {
40 HDF_LOGE("%{public}s: params null!", __func__);
41 return HDF_ERR_INVALID_PARAM;
42 }
43 if (!HdfSbufWriteInt32(reply, rectangle->width)) {
44 HDF_LOGE("%{public}s: Write width failed!", __func__);
45 return HDF_FAILURE;
46 }
47 if (!HdfSbufWriteInt32(reply, rectangle->height)) {
48 HDF_LOGE("%{public}s: Write height failed!", __func__);
49 return HDF_FAILURE;
50 }
51 return HDF_SUCCESS;
52 }
53
CodecSerPackArray(struct HdfSBuf * reply,ResizableArray * resArr)54 int32_t CodecSerPackArray(struct HdfSBuf *reply, ResizableArray *resArr)
55 {
56 if (reply == NULL || resArr == NULL) {
57 HDF_LOGE("%{public}s: params null!", __func__);
58 return HDF_ERR_INVALID_PARAM;
59 }
60
61 resArr->actualLen = 0;
62 if (!HdfSbufWriteUint32(reply, resArr->actualLen)) {
63 HDF_LOGE("%{public}s: Write actualLen failed!", __func__);
64 return HDF_FAILURE;
65 }
66 for (uint32_t i = 0; i < resArr->actualLen; i++) {
67 if (!HdfSbufWriteUint32(reply, resArr->element[i])) {
68 HDF_LOGE("%{public}s: Write HdfSubf failed!", __func__);
69 return HDF_FAILURE;
70 }
71 }
72 return HDF_SUCCESS;
73 }
74
CodecSerPackCapbility(struct HdfSBuf * reply,CodecCapbility * cap)75 int32_t CodecSerPackCapbility(struct HdfSBuf *reply, CodecCapbility *cap)
76 {
77 if (reply == NULL || cap == NULL) {
78 HDF_LOGE("%{public}s: params null!", __func__);
79 return HDF_ERR_INVALID_PARAM;
80 }
81 if (!HdfSbufWriteUint32(reply, (uint32_t)cap->mime)) {
82 return HDF_FAILURE;
83 }
84 if (!HdfSbufWriteUint32(reply, (uint32_t)cap->type)) {
85 return HDF_FAILURE;
86 }
87 if (CodecSerPackAlginment(reply, &cap->whAlignment) != HDF_SUCCESS) {
88 return HDF_FAILURE;
89 }
90 if (CodecSerPackRect(reply, &cap->minSize) != HDF_SUCCESS) {
91 return HDF_FAILURE;
92 }
93 if (CodecSerPackRect(reply, &cap->maxSize) != HDF_SUCCESS) {
94 return HDF_FAILURE;
95 }
96 if (!HdfSbufWriteUint64(reply, cap->minBitRate)) {
97 return HDF_FAILURE;
98 }
99 if (!HdfSbufWriteUint64(reply, cap->maxBitRate)) {
100 return HDF_FAILURE;
101 }
102 if (CodecSerPackArray(reply, &cap->supportProfiles) != HDF_SUCCESS) {
103 return HDF_FAILURE;
104 }
105 if (CodecSerPackArray(reply, &cap->supportLevels) != HDF_SUCCESS) {
106 return HDF_FAILURE;
107 }
108 if (CodecSerPackArray(reply, &cap->supportPixelFormats) != HDF_SUCCESS) {
109 return HDF_FAILURE;
110 }
111 if (!HdfSbufWriteUint32(reply, cap->minInputBufferNum)) {
112 return HDF_FAILURE;
113 }
114 if (!HdfSbufWriteUint32(reply, cap->minOutputBufferNum)) {
115 return HDF_FAILURE;
116 }
117 if (!HdfSbufWriteUint32(reply, cap->allocateMask)) {
118 return HDF_FAILURE;
119 }
120 if (!HdfSbufWriteUint32(reply, cap->capsMask)) {
121 return HDF_FAILURE;
122 }
123 return HDF_SUCCESS;
124 }
125
126
127 // todo val 类型,决定read类型
CodecSerParseParam(struct HdfSBuf * data,Param * param)128 int32_t CodecSerParseParam(struct HdfSBuf *data, Param *param)
129 {
130 if (data == NULL || param == NULL) {
131 HDF_LOGE("%{public}s: params null!", __func__);
132 return HDF_ERR_INVALID_PARAM;
133 }
134 if (!HdfSbufReadUint32(data, (uint32_t *)¶m->key)) {
135 HDF_LOGE("%{public}s: Read key failed!", __func__);
136 return HDF_FAILURE;
137 }
138 if (!HdfSbufReadUint32(data, (uint32_t *)¶m->val)) {
139 HDF_LOGE("%{public}s: Read val failed!", __func__);
140 return HDF_FAILURE;
141 }
142 if (!HdfSbufReadInt32(data, (int32_t*)¶m->size)) {
143 HDF_LOGE("%{public}s: Read size failed!", __func__);
144 return HDF_FAILURE;
145 }
146 return HDF_SUCCESS;
147 }
148
149 // todo val 类型,决定read类型
CodecSerPackParam(struct HdfSBuf * reply,Param * param)150 int32_t CodecSerPackParam(struct HdfSBuf *reply, Param *param)
151 {
152 if (reply == NULL || param == NULL) {
153 HDF_LOGE("%{public}s: params null!", __func__);
154 return HDF_ERR_INVALID_PARAM;
155 }
156 if (!HdfSbufWriteUint32(reply, (uint32_t)param->key)) {
157 HDF_LOGE("%{public}s: write key failed!", __func__);
158 return HDF_FAILURE;
159 }
160 if (!HdfSbufWriteUint32(reply, (uint32_t)¶m->val)) {
161 HDF_LOGE("%{public}s: Write val failed!", __func__);
162 return HDF_FAILURE;
163 }
164 if (!HdfSbufWriteInt32(reply, param->size)) {
165 HDF_LOGE("%{public}s: write size failed!", __func__);
166 return HDF_FAILURE;
167 }
168 return HDF_SUCCESS;
169 }
170
CodecSerPackBufferHandle(struct HdfSBuf * reply,CodecBufferHandle * bufferHandle)171 int32_t CodecSerPackBufferHandle(struct HdfSBuf *reply, CodecBufferHandle *bufferHandle)
172 {
173 if (reply == NULL || bufferHandle == NULL) {
174 HDF_LOGE("%{public}s: params null!", __func__);
175 return HDF_ERR_INVALID_PARAM;
176 }
177 if (!HdfSbufWriteUint8(reply, (uint8_t)&bufferHandle->virAddr)) {
178 HDF_LOGE("%{public}s: Write virAddr failed!", __func__);
179 return HDF_FAILURE;
180 }
181 if (!HdfSbufWriteUint32(reply, (uint32_t)bufferHandle->handle)) {
182 HDF_LOGE("%{public}s: Write handle failed!", __func__);
183 return HDF_FAILURE;
184 }
185 return HDF_SUCCESS;
186 }
187
CodecSerPackBufferInfo(struct HdfSBuf * reply,CodecBufferInfo * buffers)188 int32_t CodecSerPackBufferInfo(struct HdfSBuf *reply, CodecBufferInfo *buffers)
189 {
190 if (reply == NULL || buffers == NULL) {
191 HDF_LOGE("%{public}s: params null!", __func__);
192 return HDF_FAILURE;
193 }
194 if (!HdfSbufWriteUint32(reply, buffers->type)) {
195 HDF_LOGE("%{public}s: Write tempType failed!", __func__);
196 return HDF_FAILURE;
197 }
198 if (buffers->type == BUFFER_TYPE_VIRTUAL) {
199 if (!HdfSbufWriteUint8(reply, (uint8_t)&buffers->addr)) {
200 HDF_LOGE("%{public}s: Write addr failed!", __func__);
201 return HDF_FAILURE;
202 }
203 } else if (buffers->type == BUFFER_TYPE_FD) {
204 if (!HdfSbufWriteInt32(reply, buffers->fd)) {
205 HDF_LOGE("%{public}s: Write fd failed!", __func__);
206 return HDF_FAILURE;
207 }
208 } else if (buffers->type == BUFFER_TYPE_HANDLE) {
209 if (CodecSerPackBufferHandle(reply, &buffers->handle)) {
210 HDF_LOGE("%{public}s: Write handle failed!", __func__);
211 return HDF_FAILURE;
212 }
213 }
214 if (!HdfSbufWriteUint32(reply, buffers->offset)) {
215 HDF_LOGE("%{public}s: Write offset failed!", __func__);
216 return HDF_FAILURE;
217 }
218 if (!HdfSbufWriteUint32(reply, buffers->length)) {
219 HDF_LOGE("%{public}s: Write length failed!", __func__);
220 return HDF_FAILURE;
221 }
222 if (!HdfSbufWriteUint32(reply, buffers->size)) {
223 HDF_LOGE("%{public}s: Write size failed!", __func__);
224 return HDF_FAILURE;
225 }
226 return HDF_SUCCESS;
227 }
228
CodecSerPackInputInfo(struct HdfSBuf * reply,InputInfo * inputData)229 int32_t CodecSerPackInputInfo(struct HdfSBuf *reply, InputInfo *inputData)
230 {
231 if (reply == NULL || inputData == NULL || inputData->buffers == NULL) {
232 HDF_LOGE("%{public}s: params null!", __func__);
233 return HDF_FAILURE;
234 }
235 for (uint32_t i = 0; i < inputData->bufferCnt; i++) {
236 if (CodecSerPackBufferInfo(reply, &inputData->buffers[i])) {
237 HDF_LOGE("%{public}s: Write buffers failed!", __func__);
238 return HDF_FAILURE;
239 }
240 }
241 if (!HdfSbufWriteInt64(reply, inputData->pts)) {
242 HDF_LOGE("%{public}s: Write pts failed!", __func__);
243 return HDF_FAILURE;
244 }
245 if (!HdfSbufWriteInt32(reply, inputData->flag)) {
246 HDF_LOGE("%{public}s: Write flag failed!", __func__);
247 return HDF_FAILURE;
248 }
249 return HDF_SUCCESS;
250 }
251
CodecSerParseBufferHandle(struct HdfSBuf * reply,CodecBufferHandle * bufferHandle)252 int32_t CodecSerParseBufferHandle(struct HdfSBuf *reply, CodecBufferHandle *bufferHandle)
253 {
254 if (reply == NULL || bufferHandle == NULL) {
255 HDF_LOGE("%{public}s: params null!", __func__);
256 return HDF_FAILURE;
257 }
258 if (!HdfSbufReadUint8(reply, bufferHandle->virAddr)) {
259 HDF_LOGE("%{public}s: read virAddr failed!", __func__);
260 return HDF_FAILURE;
261 }
262 if (!HdfSbufReadUint32(reply, (uint32_t *)&bufferHandle->handle)) {
263 HDF_LOGE("%{public}s: read handle failed!", __func__);
264 return HDF_FAILURE;
265 }
266 return HDF_SUCCESS;
267 }
268
CodecSerParseBufferInfo(struct HdfSBuf * data,CodecBufferInfo * buffers)269 int32_t CodecSerParseBufferInfo(struct HdfSBuf *data, CodecBufferInfo *buffers)
270 {
271 if (data == NULL || buffers == NULL) {
272 HDF_LOGE("%{public}s: params null!", __func__);
273 return HDF_FAILURE;
274 }
275 uint32_t tempType = 0;
276 if (buffers == NULL) {
277 HDF_LOGE("%{public}s: buffers is NULL!", __func__);
278 return HDF_FAILURE;
279 }
280 if (!HdfSbufReadUint32(data, &tempType)) {
281 HDF_LOGE("%{public}s: read type failed!", __func__);
282 return HDF_FAILURE;
283 }
284 buffers->type = (BufferType)tempType;
285 if (buffers->type == BUFFER_TYPE_VIRTUAL) {
286 if (!HdfSbufReadUint8(data, buffers->addr)) {
287 HDF_LOGE("%{public}s: read addr failed!", __func__);
288 return HDF_FAILURE;
289 }
290 } else if (buffers->type == BUFFER_TYPE_FD) {
291 if (!HdfSbufReadInt32(data, &buffers->fd)) {
292 HDF_LOGE("%{public}s: read fd failed!", __func__);
293 return HDF_FAILURE;
294 }
295 } else if (buffers->type == BUFFER_TYPE_HANDLE) {
296 if (CodecSerParseBufferHandle(data, &buffers->handle)) {
297 HDF_LOGE("%{public}s: read handle failed!", __func__);
298 return HDF_FAILURE;
299 }
300 }
301 if (!HdfSbufReadUint32(data, &buffers->offset)) {
302 HDF_LOGE("%{public}s: read offset failed!", __func__);
303 return HDF_FAILURE;
304 }
305 if (!HdfSbufReadUint32(data, &buffers->length)) {
306 HDF_LOGE("%{public}s: read length failed!", __func__);
307 return HDF_FAILURE;
308 }
309 if (!HdfSbufReadUint32(data, &buffers->size)) {
310 HDF_LOGE("%{public}s: read size failed!", __func__);
311 return HDF_FAILURE;
312 }
313 return HDF_SUCCESS;
314 }
315
CodecSerParseInputInfo(struct HdfSBuf * data,InputInfo * inputData)316 int32_t CodecSerParseInputInfo(struct HdfSBuf *data, InputInfo *inputData)
317 {
318 if (data == NULL || inputData == NULL || inputData->buffers == NULL) {
319 HDF_LOGE("%{public}s: params NULL!", __func__);
320 return HDF_FAILURE;
321 }
322 for (uint32_t i = 0; i < inputData->bufferCnt; i++) {
323 if (CodecSerParseBufferInfo(data, &inputData->buffers[i])) {
324 HDF_LOGE("%{public}s: read buffers failed!", __func__);
325 return HDF_FAILURE;
326 }
327 }
328 if (!HdfSbufReadInt64(data, &inputData->pts)) {
329 HDF_LOGE("%{public}s: read pts failed!", __func__);
330 return HDF_FAILURE;
331 }
332 if (!HdfSbufReadInt32(data, &inputData->flag)) {
333 HDF_LOGE("%{public}s: read flag failed!", __func__);
334 return HDF_FAILURE;
335 }
336 return HDF_SUCCESS;
337 }
338
CodecSerParseOutputInfo(struct HdfSBuf * data,OutputInfo * outInfo)339 int32_t CodecSerParseOutputInfo(struct HdfSBuf *data, OutputInfo *outInfo)
340 {
341 if (data == NULL || outInfo == NULL || outInfo->buffers == NULL) {
342 HDF_LOGE("%{public}s: params null!", __func__);
343 return HDF_FAILURE;
344 }
345 for (uint32_t i = 0; i < outInfo->bufferCnt; i++) {
346 if (CodecSerParseBufferInfo(data, &outInfo->buffers[i])) {
347 HDF_LOGE("%{public}s: read buffers failed!", __func__);
348 return HDF_FAILURE;
349 }
350 }
351 if (!HdfSbufReadInt64(data, &outInfo->timeStamp)) {
352 HDF_LOGE("%{public}s: read timeStamp failed!", __func__);
353 return HDF_FAILURE;
354 }
355 if (!HdfSbufReadUint32(data, &outInfo->sequence)) {
356 HDF_LOGE("%{public}s: read sequence failed!", __func__);
357 return HDF_FAILURE;
358 }
359 if (!HdfSbufReadUint32(data, &outInfo->flag)) {
360 HDF_LOGE("%{public}s: read flag failed!", __func__);
361 return HDF_FAILURE;
362 }
363 uint32_t tempType = 0;
364 if (!HdfSbufReadUint32(data, &tempType)) {
365 HDF_LOGE("%{public}s: read tempType failed!", __func__);
366 return HDF_FAILURE;
367 }
368 outInfo->type = (CodecType)tempType;
369 if (!HdfSbufReadUint64(data, (uint64_t *)&outInfo->vendorPrivate)) {
370 HDF_LOGE("%{public}s: read vendorPrivate failed!", __func__);
371 return HDF_FAILURE;
372 }
373 return HDF_SUCCESS;
374 }
CodecSerPackOutputInfo(struct HdfSBuf * reply,OutputInfo * outInfo)375 int32_t CodecSerPackOutputInfo(struct HdfSBuf *reply, OutputInfo *outInfo)
376 {
377 if (reply == NULL || outInfo == NULL || outInfo->buffers == NULL) {
378 HDF_LOGE("%{public}s: params null!", __func__);
379 return HDF_FAILURE;
380 }
381 for (uint32_t i = 0; i < outInfo->bufferCnt; i++) {
382 if (CodecSerPackBufferInfo(reply, &outInfo->buffers[i])) {
383 HDF_LOGE("%{public}s: write buffers failed!", __func__);
384 return HDF_FAILURE;
385 }
386 }
387 if (!HdfSbufWriteInt64(reply, outInfo->timeStamp)) {
388 HDF_LOGE("%{public}s: write timeStamp failed!", __func__);
389 return HDF_FAILURE;
390 }
391 if (!HdfSbufWriteUint32(reply, outInfo->sequence)) {
392 HDF_LOGE("%{public}s: write sequence failed!", __func__);
393 return HDF_FAILURE;
394 }
395 if (!HdfSbufWriteUint32(reply, outInfo->flag)) {
396 HDF_LOGE("%{public}s: write flag failed!", __func__);
397 return HDF_FAILURE;
398 }
399 if (!HdfSbufWriteUint32(reply, outInfo->type)) {
400 HDF_LOGE("%{public}s: write outInfo->type failed!", __func__);
401 return HDF_FAILURE;
402 }
403 if (!HdfSbufWriteUint64(reply, (uint64_t)&outInfo->vendorPrivate)) {
404 HDF_LOGE("%{public}s: write vendorPrivate failed!", __func__);
405 return HDF_FAILURE;
406 }
407 return HDF_SUCCESS;
408 }