blob: 0870da7e20bd07511b5a8cd0e9d2fea6dfe059a7
1 | /* |
2 | * Copyright (C) 2017 Amlogic, Inc. All rights reserved. |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License as published by |
6 | * the Free Software Foundation; either version 2 of the License, or |
7 | * (at your option) any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
12 | * more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License along |
15 | * with this program; if not, write to the Free Software Foundation, Inc., |
16 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
17 | * |
18 | * Description: |
19 | */ |
20 | #include <linux/module.h> |
21 | #include <linux/slab.h> |
22 | #include <linux/timer.h> |
23 | #include <linux/delay.h> |
24 | #include <linux/kernel.h> |
25 | #include <uapi/linux/swab.h> |
26 | #include "../vdec_drv_if.h" |
27 | #include "../aml_vcodec_util.h" |
28 | #include "../aml_vcodec_dec.h" |
29 | #include "../aml_vcodec_adapt.h" |
30 | #include "../vdec_drv_base.h" |
31 | #include "../aml_vcodec_vfm.h" |
32 | #include "aml_hevc_parser.h" |
33 | |
34 | #define NAL_TYPE(value) ((value) & 0x1F) |
35 | #define HEADER_BUFFER_SIZE (32 * 1024) |
36 | |
37 | /** |
38 | * struct hevc_fb - hevc decode frame buffer information |
39 | * @vdec_fb_va : virtual address of struct vdec_fb |
40 | * @y_fb_dma : dma address of Y frame buffer (luma) |
41 | * @c_fb_dma : dma address of C frame buffer (chroma) |
42 | * @poc : picture order count of frame buffer |
43 | * @reserved : for 8 bytes alignment |
44 | */ |
45 | struct hevc_fb { |
46 | uint64_t vdec_fb_va; |
47 | uint64_t y_fb_dma; |
48 | uint64_t c_fb_dma; |
49 | int32_t poc; |
50 | uint32_t reserved; |
51 | }; |
52 | |
53 | /** |
54 | * struct vdec_hevc_dec_info - decode information |
55 | * @dpb_sz : decoding picture buffer size |
56 | * @resolution_changed : resoltion change happen |
57 | * @reserved : for 8 bytes alignment |
58 | * @bs_dma : Input bit-stream buffer dma address |
59 | * @y_fb_dma : Y frame buffer dma address |
60 | * @c_fb_dma : C frame buffer dma address |
61 | * @vdec_fb_va : VDEC frame buffer struct virtual address |
62 | */ |
63 | struct vdec_hevc_dec_info { |
64 | uint32_t dpb_sz; |
65 | uint32_t resolution_changed; |
66 | uint32_t reserved; |
67 | uint64_t bs_dma; |
68 | uint64_t y_fb_dma; |
69 | uint64_t c_fb_dma; |
70 | uint64_t vdec_fb_va; |
71 | }; |
72 | |
73 | /** |
74 | * struct vdec_hevc_vsi - shared memory for decode information exchange |
75 | * between VPU and Host. |
76 | * The memory is allocated by VPU then mapping to Host |
77 | * in vpu_dec_init() and freed in vpu_dec_deinit() |
78 | * by VPU. |
79 | * AP-W/R : AP is writer/reader on this item |
80 | * VPU-W/R: VPU is write/reader on this item |
81 | * @hdr_buf : Header parsing buffer (AP-W, VPU-R) |
82 | * @list_free : free frame buffer ring list (AP-W/R, VPU-W) |
83 | * @list_disp : display frame buffer ring list (AP-R, VPU-W) |
84 | * @dec : decode information (AP-R, VPU-W) |
85 | * @pic : picture information (AP-R, VPU-W) |
86 | * @crop : crop information (AP-R, VPU-W) |
87 | */ |
88 | struct vdec_hevc_vsi { |
89 | char *header_buf; |
90 | int sps_size; |
91 | int pps_size; |
92 | int sei_size; |
93 | int head_offset; |
94 | struct vdec_hevc_dec_info dec; |
95 | struct vdec_pic_info pic; |
96 | struct v4l2_rect crop; |
97 | bool is_combine; |
98 | int nalu_pos; |
99 | struct HEVCParamSets ps; |
100 | }; |
101 | |
102 | /** |
103 | * struct vdec_hevc_inst - hevc decoder instance |
104 | * @num_nalu : how many nalus be decoded |
105 | * @ctx : point to aml_vcodec_ctx |
106 | * @vsi : VPU shared information |
107 | */ |
108 | struct vdec_hevc_inst { |
109 | unsigned int num_nalu; |
110 | struct aml_vcodec_ctx *ctx; |
111 | struct aml_vdec_adapt vdec; |
112 | struct vdec_hevc_vsi *vsi; |
113 | struct vcodec_vfm_s vfm; |
114 | }; |
115 | |
116 | #if 0 |
117 | #define DUMP_FILE_NAME "/data/dump/dump.tmp" |
118 | static struct file *filp; |
119 | static loff_t file_pos; |
120 | |
121 | void dump_write(const char __user *buf, size_t count) |
122 | { |
123 | mm_segment_t old_fs; |
124 | |
125 | if (!filp) |
126 | return; |
127 | |
128 | old_fs = get_fs(); |
129 | set_fs(KERNEL_DS); |
130 | |
131 | if (count != vfs_write(filp, buf, count, &file_pos)) |
132 | pr_err("Failed to write file\n"); |
133 | |
134 | set_fs(old_fs); |
135 | } |
136 | |
137 | void dump_init(void) |
138 | { |
139 | filp = filp_open(DUMP_FILE_NAME, O_CREAT | O_RDWR, 0644); |
140 | if (IS_ERR(filp)) { |
141 | pr_err("open dump file failed\n"); |
142 | filp = NULL; |
143 | } |
144 | } |
145 | |
146 | void dump_deinit(void) |
147 | { |
148 | if (filp) { |
149 | filp_close(filp, current->files); |
150 | filp = NULL; |
151 | file_pos = 0; |
152 | } |
153 | } |
154 | |
155 | void swap_uv(void *uv, int size) |
156 | { |
157 | int i; |
158 | __u16 *p = uv; |
159 | |
160 | size /= 2; |
161 | |
162 | for (i = 0; i < size; i++, p++) |
163 | *p = __swab16(*p); |
164 | } |
165 | #endif |
166 | |
167 | static void get_pic_info(struct vdec_hevc_inst *inst, |
168 | struct vdec_pic_info *pic) |
169 | { |
170 | *pic = inst->vsi->pic; |
171 | |
172 | aml_vcodec_debug(inst, "pic(%d, %d), buf(%d, %d)", |
173 | pic->visible_width, pic->visible_height, |
174 | pic->coded_width, pic->coded_height); |
175 | aml_vcodec_debug(inst, "Y(%d, %d), C(%d, %d)", pic->y_bs_sz, |
176 | pic->y_len_sz, pic->c_bs_sz, pic->c_len_sz); |
177 | } |
178 | |
179 | static void get_crop_info(struct vdec_hevc_inst *inst, struct v4l2_rect *cr) |
180 | { |
181 | cr->left = inst->vsi->crop.left; |
182 | cr->top = inst->vsi->crop.top; |
183 | cr->width = inst->vsi->crop.width; |
184 | cr->height = inst->vsi->crop.height; |
185 | |
186 | aml_vcodec_debug(inst, "l=%d, t=%d, w=%d, h=%d", |
187 | cr->left, cr->top, cr->width, cr->height); |
188 | } |
189 | |
190 | static void get_dpb_size(struct vdec_hevc_inst *inst, unsigned int *dpb_sz) |
191 | { |
192 | *dpb_sz = 20;//inst->vsi->dec.dpb_sz; |
193 | aml_vcodec_debug(inst, "sz=%d", *dpb_sz); |
194 | } |
195 | |
196 | static int find_start_code(unsigned char *data, unsigned int data_sz) |
197 | { |
198 | if (data_sz > 3 && data[0] == 0 && data[1] == 0 && data[2] == 1) |
199 | return 3; |
200 | |
201 | if (data_sz > 4 && data[0] == 0 && data[1] == 0 && data[2] == 0 && |
202 | data[3] == 1) |
203 | return 4; |
204 | |
205 | return -1; |
206 | } |
207 | |
208 | static int vdec_hevc_init(struct aml_vcodec_ctx *ctx, unsigned long *h_vdec) |
209 | { |
210 | struct vdec_hevc_inst *inst = NULL; |
211 | int ret = -1; |
212 | |
213 | inst = kzalloc(sizeof(*inst), GFP_KERNEL); |
214 | if (!inst) |
215 | return -ENOMEM; |
216 | |
217 | inst->ctx = ctx; |
218 | |
219 | inst->vdec.format = VFORMAT_HEVC; |
220 | inst->vdec.dev = ctx->dev->vpu_plat_dev; |
221 | inst->vdec.filp = ctx->dev->filp; |
222 | inst->vdec.ctx = ctx; |
223 | |
224 | /* set play mode.*/ |
225 | if (ctx->is_drm_mode) |
226 | inst->vdec.port.flag |= PORT_FLAG_DRM; |
227 | |
228 | /* to eable hevc hw.*/ |
229 | inst->vdec.port.type = PORT_TYPE_HEVC; |
230 | |
231 | /* init vfm */ |
232 | inst->vfm.ctx = ctx; |
233 | inst->vfm.ada_ctx = &inst->vdec; |
234 | vcodec_vfm_init(&inst->vfm); |
235 | |
236 | ret = video_decoder_init(&inst->vdec); |
237 | if (ret) { |
238 | aml_vcodec_err(inst, "vdec_hevc init err=%d", ret); |
239 | goto error_free_inst; |
240 | } |
241 | |
242 | /* probe info from the stream */ |
243 | inst->vsi = kzalloc(sizeof(struct vdec_hevc_vsi), GFP_KERNEL); |
244 | if (!inst->vsi) { |
245 | ret = -ENOMEM; |
246 | goto error_free_inst; |
247 | } |
248 | |
249 | /* alloc the header buffer to be used cache sps or spp etc.*/ |
250 | inst->vsi->header_buf = kzalloc(HEADER_BUFFER_SIZE, GFP_KERNEL); |
251 | if (!inst->vsi) { |
252 | ret = -ENOMEM; |
253 | goto error_free_vsi; |
254 | } |
255 | |
256 | inst->vsi->pic.visible_width = 1920; |
257 | inst->vsi->pic.visible_height = 1080; |
258 | inst->vsi->pic.coded_width = 1920; |
259 | inst->vsi->pic.coded_height = 1088; |
260 | inst->vsi->pic.y_bs_sz = 0; |
261 | inst->vsi->pic.y_len_sz = (1920 * 1088); |
262 | inst->vsi->pic.c_bs_sz = 0; |
263 | inst->vsi->pic.c_len_sz = (1920 * 1088 / 2); |
264 | |
265 | aml_vcodec_debug(inst, "hevc Instance >> %p", inst); |
266 | |
267 | ctx->ada_ctx = &inst->vdec; |
268 | *h_vdec = (unsigned long)inst; |
269 | |
270 | //dump_init(); |
271 | |
272 | return 0; |
273 | |
274 | error_free_vsi: |
275 | kfree(inst->vsi); |
276 | error_free_inst: |
277 | kfree(inst); |
278 | *h_vdec = 0; |
279 | |
280 | return ret; |
281 | } |
282 | |
283 | #if 0 |
284 | static int refer_buffer_num(int level_idc, int poc_cnt, |
285 | int mb_width, int mb_height) |
286 | { |
287 | return 20; |
288 | } |
289 | #endif |
290 | |
291 | //static void fill_vdec_params(struct vdec_hevc_inst *inst, struct hevc_SPS_t *sps) |
292 | static void fill_vdec_params(struct vdec_hevc_inst *inst) |
293 | { |
294 | struct vdec_pic_info *pic = &inst->vsi->pic; |
295 | struct vdec_hevc_dec_info *dec = &inst->vsi->dec; |
296 | struct v4l2_rect *rect = &inst->vsi->crop; |
297 | unsigned int mb_w = 0, mb_h = 0, width, height; |
298 | //unsigned int crop_unit_x = 0, crop_unit_y = 0; |
299 | //unsigned int poc_cnt = 0; |
300 | |
301 | /* calc width & height. */ |
302 | width = 1920; |
303 | height = 1080; |
304 | |
305 | /* fill visible area size that be used for EGL. */ |
306 | pic->visible_width = width; |
307 | pic->visible_height = height; |
308 | |
309 | /* calc visible ares. */ |
310 | rect->left = 0; |
311 | rect->top = 0; |
312 | rect->width = pic->visible_width; |
313 | rect->height = pic->visible_height; |
314 | |
315 | /* config canvas size that be used for decoder. */ |
316 | pic->coded_width = ALIGN(mb_w, 4) << 4; |
317 | pic->coded_height = ALIGN(mb_h, 4) << 4; |
318 | |
319 | pic->coded_width = 1920; |
320 | pic->coded_height = 1088;//temp |
321 | |
322 | pic->y_len_sz = pic->coded_width * pic->coded_height; |
323 | pic->c_len_sz = pic->y_len_sz >> 1; |
324 | |
325 | /* calc DPB size */ |
326 | dec->dpb_sz = 20;//refer_buffer_num(sps->level_idc, poc_cnt, mb_w, mb_h); |
327 | |
328 | pr_info("[%d] The stream infos, coded:(%d x %d), visible:(%d x %d), DPB: %d\n", |
329 | inst->ctx->id, pic->coded_width, pic->coded_height, |
330 | pic->visible_width, pic->visible_height, dec->dpb_sz); |
331 | } |
332 | |
333 | static int hevc_parse_nal_header(u32 val) |
334 | { |
335 | if (val & 0x80) { |
336 | pr_err("the nal data is invalid.\n"); |
337 | return -1; |
338 | } |
339 | |
340 | return (val & 0x7f) >> 1; |
341 | } |
342 | |
343 | static void hevc_parse(struct HEVCParamSets *ps, u8 *buf, u32 size) |
344 | { |
345 | //int ret = -1; |
346 | int i = 0, j = 0, cnt = 0; |
347 | int pos, nal_size, nal_type; |
348 | u8 *p = buf; |
349 | |
350 | for (i = 4; i < size; i++) { |
351 | j = find_start_code(p, i); |
352 | if (j > 0) { |
353 | pos = p - buf + j; |
354 | nal_size = size - pos; |
355 | nal_type = hevc_parse_nal_header(buf[pos]); |
356 | |
357 | switch (nal_type) { |
358 | case HEVC_NAL_VPS: |
359 | //ret = hevc_parse_nal_vps(&ps->vps, p, nal_size); |
360 | //if (!ret) |
361 | //ps->vps_parsed = true; |
362 | pr_err("------%s,%d nal type: %u\n",__func__, __LINE__,nal_type); |
363 | break; |
364 | case HEVC_NAL_SPS: |
365 | //ret = hevc_parse_nal_sps(&ps->sps, p, nal_size); |
366 | //if (!ret) |
367 | ps->sps_parsed = true; |
368 | pr_err("------%s,%d nal type: %u\n",__func__, __LINE__,nal_type); |
369 | break; |
370 | case HEVC_NAL_PPS: |
371 | //ret = hevc_parse_nal_pps(&ps->pps, p, nal_size); |
372 | //if (!ret) |
373 | //ps->sps_parsed = true; |
374 | pr_err("------%s,%d nal type: %u\n",__func__, __LINE__,nal_type); |
375 | break; |
376 | case HEVC_NAL_SEI_PREFIX: |
377 | case HEVC_NAL_SEI_SUFFIX: |
378 | //ret = hevc_parse_nal_sei(&ps->sei, p, nal_size); |
379 | //if (!ret) |
380 | //ps->sei_parsed = true; |
381 | pr_err("------%s,%d nal type: %u\n",__func__, __LINE__,nal_type); |
382 | break; |
383 | default: |
384 | pr_info("ignoring NAL type %d in extradata\n", nal_type); |
385 | break; |
386 | } |
387 | |
388 | cnt++; |
389 | p += j; |
390 | i = pos; |
391 | } |
392 | p++; |
393 | } |
394 | } |
395 | |
396 | static int stream_parse(struct vdec_hevc_inst *inst, u8 *buf, u32 size) |
397 | { |
398 | //struct hevc_stream_t s; |
399 | //struct hevc_SPS_t *sps; |
400 | //unsigned int nal_type; |
401 | int nal_idx = 0; |
402 | int real_data_pos, real_data_size; |
403 | bool is_combine = false; |
404 | |
405 | hevc_parse(&inst->vsi->ps, buf, size); |
406 | |
407 | if (!inst->vsi->ps.sps_parsed) |
408 | return -1; |
409 | |
410 | /* if the st compose from csd + slice that is the combine data. */ |
411 | inst->vsi->is_combine = is_combine; |
412 | inst->vsi->nalu_pos = nal_idx; |
413 | |
414 | /* start code plus nal type. */ |
415 | real_data_pos = nal_idx + 1; |
416 | real_data_size = size - real_data_pos; |
417 | |
418 | //sps = kzalloc(sizeof(struct hevc_SPS_t), GFP_KERNEL); |
419 | //if (sps == NULL) |
420 | //return -ENOMEM; |
421 | |
422 | /* the extra data would be parsed. */ |
423 | //hevc_stream_set(&s, &buf[real_data_pos], real_data_size); |
424 | //hevc_sps_parse(&s, sps); |
425 | //hevc_sps_info(sps); |
426 | |
427 | //fill_vdec_params(inst, sps); |
428 | fill_vdec_params(inst); |
429 | |
430 | //kfree(sps); |
431 | |
432 | return 0; |
433 | } |
434 | |
435 | static int vdec_hevc_probe(unsigned long h_vdec, |
436 | struct aml_vcodec_mem *bs, void *out) |
437 | { |
438 | struct vdec_hevc_inst *inst = |
439 | (struct vdec_hevc_inst *)h_vdec; |
440 | struct stream_info *st; |
441 | u8 *buf = (u8 *)bs->va; |
442 | u32 size = bs->size; |
443 | int ret = 0; |
444 | |
445 | st = (struct stream_info *)buf; |
446 | if (inst->ctx->is_drm_mode && (st->magic == DRMe || st->magic == DRMn)) |
447 | return 0; |
448 | |
449 | if (st->magic == NORe || st->magic == NORn) |
450 | ret = stream_parse(inst, st->data, st->length); |
451 | else |
452 | ret = stream_parse(inst, buf, size); |
453 | |
454 | return ret; |
455 | } |
456 | |
457 | static void vdec_hevc_deinit(unsigned long h_vdec) |
458 | { |
459 | struct vdec_hevc_inst *inst = (struct vdec_hevc_inst *)h_vdec; |
460 | |
461 | if (!inst) |
462 | return; |
463 | |
464 | aml_vcodec_debug_enter(inst); |
465 | |
466 | video_decoder_release(&inst->vdec); |
467 | |
468 | vcodec_vfm_release(&inst->vfm); |
469 | |
470 | //dump_deinit(); |
471 | |
472 | if (inst->vsi && inst->vsi->header_buf) |
473 | kfree(inst->vsi->header_buf); |
474 | |
475 | if (inst->vsi) |
476 | kfree(inst->vsi); |
477 | |
478 | kfree(inst); |
479 | } |
480 | |
481 | static int vdec_hevc_get_fb(struct vdec_hevc_inst *inst, struct vdec_fb **out) |
482 | { |
483 | return get_fb_from_queue(inst->ctx, out); |
484 | } |
485 | |
486 | static void vdec_hevc_get_vf(struct vdec_hevc_inst *inst, struct vdec_fb **out) |
487 | { |
488 | struct vframe_s *vf = NULL; |
489 | struct vdec_fb *fb = NULL; |
490 | |
491 | aml_vcodec_debug(inst, "%s() [%d], vfm: %p", |
492 | __func__, __LINE__, &inst->vfm); |
493 | |
494 | vf = peek_video_frame(&inst->vfm); |
495 | if (!vf) { |
496 | aml_vcodec_debug(inst, "there is no vframe."); |
497 | *out = NULL; |
498 | return; |
499 | } |
500 | |
501 | vf = get_video_frame(&inst->vfm); |
502 | if (!vf) { |
503 | aml_vcodec_debug(inst, "the vframe is avalid."); |
504 | *out = NULL; |
505 | return; |
506 | } |
507 | |
508 | atomic_set(&vf->use_cnt, 1); |
509 | |
510 | aml_vcodec_debug(inst, "%s() [%d], vf: %p, v4l_mem_handle: %lx, idx: %d\n", |
511 | __func__, __LINE__, vf, vf->v4l_mem_handle, vf->index); |
512 | |
513 | fb = (struct vdec_fb *)vf->v4l_mem_handle; |
514 | fb->vf_handle = (unsigned long)vf; |
515 | fb->status = FB_ST_DISPLAY; |
516 | |
517 | *out = fb; |
518 | |
519 | //pr_info("%s, %d\n", __func__, fb->base_y.bytes_used); |
520 | //dump_write(fb->base_y.va, fb->base_y.bytes_used); |
521 | //dump_write(fb->base_c.va, fb->base_c.bytes_used); |
522 | |
523 | /* convert yuv format. */ |
524 | //swap_uv(fb->base_c.va, fb->base_c.size); |
525 | |
526 | aml_vcodec_debug(inst, "%s() [%d], va: %p, phy: %x, size: %zu", |
527 | __func__, __LINE__, fb->base_y.va, |
528 | (unsigned int)virt_to_phys(fb->base_y.va), fb->base_y.size); |
529 | aml_vcodec_debug(inst, "%s() [%d], va: %p, phy: %x, size: %zu", |
530 | __func__, __LINE__, fb->base_c.va, |
531 | (unsigned int)virt_to_phys(fb->base_c.va), fb->base_c.size); |
532 | } |
533 | |
534 | static int vdec_write_nalu(struct vdec_hevc_inst *inst, |
535 | u8 *buf, u32 size, u64 ts) |
536 | { |
537 | int ret = 0, err = 0; |
538 | struct aml_vdec_adapt *vdec = &inst->vdec; |
539 | bool is_combine = true;//inst->vsi->is_combine; |
540 | int nalu_pos; |
541 | u32 nal_type; |
542 | |
543 | nalu_pos = find_start_code(buf, size); |
544 | if (nalu_pos < 0) |
545 | goto err; |
546 | |
547 | nal_type = hevc_parse_nal_header(buf[nalu_pos]); |
548 | aml_vcodec_debug(inst, "NALU type: %d, size: %u\n", nal_type, size); |
549 | |
550 | if (nal_type == HEVC_NAL_SPS && !is_combine) { |
551 | if (inst->vsi->head_offset + size > HEADER_BUFFER_SIZE) { |
552 | ret = -EILSEQ; |
553 | goto err; |
554 | } |
555 | inst->vsi->sps_size = size; |
556 | memcpy(inst->vsi->header_buf + inst->vsi->head_offset, buf, size); |
557 | inst->vsi->head_offset += inst->vsi->sps_size; |
558 | } else if (nal_type == HEVC_NAL_PPS && !is_combine) { |
559 | //buf_sz -= nal_start_idx; |
560 | if (inst->vsi->head_offset + size > HEADER_BUFFER_SIZE) { |
561 | ret = -EILSEQ; |
562 | goto err; |
563 | } |
564 | inst->vsi->pps_size = size; |
565 | memcpy(inst->vsi->header_buf + inst->vsi->head_offset, buf, size); |
566 | inst->vsi->head_offset += inst->vsi->pps_size; |
567 | } else if (nal_type == HEVC_NAL_SEI_PREFIX && !is_combine) { |
568 | if (inst->vsi->head_offset + size > HEADER_BUFFER_SIZE) { |
569 | ret = -EILSEQ; |
570 | goto err; |
571 | } |
572 | inst->vsi->sei_size = size; |
573 | memcpy(inst->vsi->header_buf + inst->vsi->head_offset, buf, size); |
574 | inst->vsi->head_offset += inst->vsi->sei_size; |
575 | } else { |
576 | char *write_buf = vmalloc(inst->vsi->head_offset + size); |
577 | |
578 | memcpy(write_buf, inst->vsi->header_buf, inst->vsi->head_offset); |
579 | memcpy(write_buf + inst->vsi->head_offset, buf, size); |
580 | |
581 | ret = vdec_vframe_write(vdec, write_buf, |
582 | inst->vsi->head_offset + size, ts); |
583 | |
584 | aml_vcodec_debug(inst, "buf: %p, buf size: %u, write to: %d", |
585 | write_buf, inst->vsi->head_offset + size, ret); |
586 | |
587 | memset(inst->vsi->header_buf, 0, HEADER_BUFFER_SIZE); |
588 | inst->vsi->head_offset = 0; |
589 | inst->vsi->sps_size = 0; |
590 | inst->vsi->pps_size = 0; |
591 | inst->vsi->sei_size = 0; |
592 | |
593 | vfree(write_buf); |
594 | } |
595 | |
596 | return 0; |
597 | err: |
598 | aml_vcodec_err(inst, "%s err(%d)", __func__, err); |
599 | |
600 | return err; |
601 | } |
602 | |
603 | static int vdec_hevc_decode(unsigned long h_vdec, struct aml_vcodec_mem *bs, |
604 | unsigned long int timestamp, bool *res_chg) |
605 | { |
606 | struct vdec_hevc_inst *inst = (struct vdec_hevc_inst *)h_vdec; |
607 | struct aml_vdec_adapt *vdec = &inst->vdec; |
608 | struct stream_info *st; |
609 | u8 *buf; |
610 | u32 size; |
611 | int ret = 0; |
612 | |
613 | /* bs NULL means flush decoder */ |
614 | if (bs == NULL) |
615 | return 0; |
616 | |
617 | buf = (u8 *)bs->va; |
618 | size = bs->size; |
619 | st = (struct stream_info *)buf; |
620 | |
621 | if (inst->ctx->is_drm_mode && (st->magic == DRMe || st->magic == DRMn)) |
622 | ret = vdec_vbuf_write(vdec, st->m.buf, sizeof(st->m.drm)); |
623 | else if (st->magic == NORe) |
624 | ret = vdec_vbuf_write(vdec, st->data, st->length); |
625 | else if (st->magic == NORn) |
626 | ret = vdec_write_nalu(inst, st->data, st->length, timestamp); |
627 | else if (inst->ctx->is_stream_mode) |
628 | ret = vdec_vbuf_write(vdec, buf, size); |
629 | else |
630 | ret = vdec_write_nalu(inst, buf, size, timestamp); |
631 | |
632 | return ret; |
633 | } |
634 | |
635 | static int vdec_hevc_get_param(unsigned long h_vdec, |
636 | enum vdec_get_param_type type, void *out) |
637 | { |
638 | int ret = 0; |
639 | struct vdec_hevc_inst *inst = (struct vdec_hevc_inst *)h_vdec; |
640 | |
641 | if (!inst) { |
642 | pr_err("the hevc inst of dec is invalid.\n"); |
643 | return -1; |
644 | } |
645 | |
646 | switch (type) { |
647 | case GET_PARAM_DISP_FRAME_BUFFER: |
648 | vdec_hevc_get_vf(inst, out); |
649 | break; |
650 | |
651 | case GET_PARAM_FREE_FRAME_BUFFER: |
652 | ret = vdec_hevc_get_fb(inst, out); |
653 | break; |
654 | |
655 | case GET_PARAM_PIC_INFO: |
656 | get_pic_info(inst, out); |
657 | break; |
658 | |
659 | case GET_PARAM_DPB_SIZE: |
660 | get_dpb_size(inst, out); |
661 | break; |
662 | |
663 | case GET_PARAM_CROP_INFO: |
664 | get_crop_info(inst, out); |
665 | break; |
666 | |
667 | default: |
668 | aml_vcodec_err(inst, "invalid get parameter type=%d", type); |
669 | ret = -EINVAL; |
670 | } |
671 | |
672 | return ret; |
673 | } |
674 | |
675 | static struct vdec_common_if vdec_hevc_if = { |
676 | vdec_hevc_init, |
677 | vdec_hevc_probe, |
678 | vdec_hevc_decode, |
679 | vdec_hevc_get_param, |
680 | vdec_hevc_deinit, |
681 | }; |
682 | |
683 | struct vdec_common_if *get_hevc_dec_comm_if(void); |
684 | |
685 | struct vdec_common_if *get_hevc_dec_comm_if(void) |
686 | { |
687 | return &vdec_hevc_if; |
688 | } |
689 |