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