blob: 5b3bbabdeb5a5529f9e05d01a73e3bed95f460d7
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_vp9_parser.h" |
33 | #include "vdec_vp9_trigger.h" |
34 | |
35 | #define PREFIX_SIZE (16) |
36 | |
37 | #define NAL_TYPE(value) ((value) & 0x1F) |
38 | #define HEADER_BUFFER_SIZE (32 * 1024) |
39 | #define SYNC_CODE (0x498342) |
40 | |
41 | extern int vp9_need_prefix; |
42 | bool need_trigger; |
43 | int dump_cnt = 0; |
44 | |
45 | /** |
46 | * struct vp9_fb - vp9 decode frame buffer information |
47 | * @vdec_fb_va : virtual address of struct vdec_fb |
48 | * @y_fb_dma : dma address of Y frame buffer (luma) |
49 | * @c_fb_dma : dma address of C frame buffer (chroma) |
50 | * @poc : picture order count of frame buffer |
51 | * @reserved : for 8 bytes alignment |
52 | */ |
53 | struct vp9_fb { |
54 | uint64_t vdec_fb_va; |
55 | uint64_t y_fb_dma; |
56 | uint64_t c_fb_dma; |
57 | int32_t poc; |
58 | uint32_t reserved; |
59 | }; |
60 | |
61 | /** |
62 | * struct vdec_vp9_dec_info - decode information |
63 | * @dpb_sz : decoding picture buffer size |
64 | * @resolution_changed : resoltion change happen |
65 | * @reserved : for 8 bytes alignment |
66 | * @bs_dma : Input bit-stream buffer dma address |
67 | * @y_fb_dma : Y frame buffer dma address |
68 | * @c_fb_dma : C frame buffer dma address |
69 | * @vdec_fb_va : VDEC frame buffer struct virtual address |
70 | */ |
71 | struct vdec_vp9_dec_info { |
72 | uint32_t dpb_sz; |
73 | uint32_t resolution_changed; |
74 | uint32_t reserved; |
75 | uint64_t bs_dma; |
76 | uint64_t y_fb_dma; |
77 | uint64_t c_fb_dma; |
78 | uint64_t vdec_fb_va; |
79 | }; |
80 | |
81 | /** |
82 | * struct vdec_vp9_vsi - shared memory for decode information exchange |
83 | * between VPU and Host. |
84 | * The memory is allocated by VPU then mapping to Host |
85 | * in vpu_dec_init() and freed in vpu_dec_deinit() |
86 | * by VPU. |
87 | * AP-W/R : AP is writer/reader on this item |
88 | * VPU-W/R: VPU is write/reader on this item |
89 | * @hdr_buf : Header parsing buffer (AP-W, VPU-R) |
90 | * @list_free : free frame buffer ring list (AP-W/R, VPU-W) |
91 | * @list_disp : display frame buffer ring list (AP-R, VPU-W) |
92 | * @dec : decode information (AP-R, VPU-W) |
93 | * @pic : picture information (AP-R, VPU-W) |
94 | * @crop : crop information (AP-R, VPU-W) |
95 | */ |
96 | struct vdec_vp9_vsi { |
97 | char *header_buf; |
98 | int sps_size; |
99 | int pps_size; |
100 | int sei_size; |
101 | int head_offset; |
102 | struct vdec_vp9_dec_info dec; |
103 | struct vdec_pic_info pic; |
104 | struct vdec_pic_info cur_pic; |
105 | struct v4l2_rect crop; |
106 | bool is_combine; |
107 | int nalu_pos; |
108 | struct vp9_param_sets ps; |
109 | }; |
110 | |
111 | /** |
112 | * struct vdec_vp9_inst - vp9 decoder instance |
113 | * @num_nalu : how many nalus be decoded |
114 | * @ctx : point to aml_vcodec_ctx |
115 | * @vsi : VPU shared information |
116 | */ |
117 | struct vdec_vp9_inst { |
118 | unsigned int num_nalu; |
119 | struct aml_vcodec_ctx *ctx; |
120 | struct aml_vdec_adapt vdec; |
121 | struct vdec_vp9_vsi *vsi; |
122 | struct vcodec_vfm_s vfm; |
123 | struct completion comp; |
124 | }; |
125 | |
126 | static int vdec_write_nalu(struct vdec_vp9_inst *inst, |
127 | u8 *buf, u32 size, u64 ts); |
128 | |
129 | static void get_pic_info(struct vdec_vp9_inst *inst, |
130 | struct vdec_pic_info *pic) |
131 | { |
132 | *pic = inst->vsi->pic; |
133 | |
134 | aml_vcodec_debug(inst, "pic(%d, %d), buf(%d, %d)", |
135 | pic->visible_width, pic->visible_height, |
136 | pic->coded_width, pic->coded_height); |
137 | aml_vcodec_debug(inst, "Y(%d, %d), C(%d, %d)", pic->y_bs_sz, |
138 | pic->y_len_sz, pic->c_bs_sz, pic->c_len_sz); |
139 | } |
140 | |
141 | static void get_crop_info(struct vdec_vp9_inst *inst, struct v4l2_rect *cr) |
142 | { |
143 | cr->left = inst->vsi->crop.left; |
144 | cr->top = inst->vsi->crop.top; |
145 | cr->width = inst->vsi->crop.width; |
146 | cr->height = inst->vsi->crop.height; |
147 | |
148 | aml_vcodec_debug(inst, "l=%d, t=%d, w=%d, h=%d", |
149 | cr->left, cr->top, cr->width, cr->height); |
150 | } |
151 | |
152 | static void get_dpb_size(struct vdec_vp9_inst *inst, unsigned int *dpb_sz) |
153 | { |
154 | *dpb_sz = inst->vsi->dec.dpb_sz; |
155 | aml_vcodec_debug(inst, "sz=%d", *dpb_sz); |
156 | } |
157 | |
158 | static int vdec_vp9_init(struct aml_vcodec_ctx *ctx, unsigned long *h_vdec) |
159 | { |
160 | struct vdec_vp9_inst *inst = NULL; |
161 | int ret = -1; |
162 | |
163 | inst = kzalloc(sizeof(*inst), GFP_KERNEL); |
164 | if (!inst) |
165 | return -ENOMEM; |
166 | |
167 | inst->ctx = ctx; |
168 | |
169 | inst->vdec.video_type = VFORMAT_VP9; |
170 | inst->vdec.dev = ctx->dev->vpu_plat_dev; |
171 | inst->vdec.filp = ctx->dev->filp; |
172 | inst->vdec.ctx = ctx; |
173 | |
174 | /* set play mode.*/ |
175 | if (ctx->is_drm_mode) |
176 | inst->vdec.port.flag |= PORT_FLAG_DRM; |
177 | |
178 | /* to eable vp9 hw.*/ |
179 | inst->vdec.port.type = PORT_TYPE_HEVC; |
180 | |
181 | /* init vfm */ |
182 | inst->vfm.ctx = ctx; |
183 | inst->vfm.ada_ctx = &inst->vdec; |
184 | vcodec_vfm_init(&inst->vfm); |
185 | |
186 | /* probe info from the stream */ |
187 | inst->vsi = kzalloc(sizeof(struct vdec_vp9_vsi), GFP_KERNEL); |
188 | if (!inst->vsi) { |
189 | ret = -ENOMEM; |
190 | goto error_free_inst; |
191 | } |
192 | |
193 | /* alloc the header buffer to be used cache sps or spp etc.*/ |
194 | inst->vsi->header_buf = kzalloc(HEADER_BUFFER_SIZE, GFP_KERNEL); |
195 | if (!inst->vsi) { |
196 | ret = -ENOMEM; |
197 | goto error_free_vsi; |
198 | } |
199 | |
200 | inst->vsi->pic.visible_width = 1920; |
201 | inst->vsi->pic.visible_height = 1080; |
202 | inst->vsi->pic.coded_width = 1920; |
203 | inst->vsi->pic.coded_height = 1088; |
204 | inst->vsi->pic.y_bs_sz = 0; |
205 | inst->vsi->pic.y_len_sz = (1920 * 1088); |
206 | inst->vsi->pic.c_bs_sz = 0; |
207 | inst->vsi->pic.c_len_sz = (1920 * 1088 / 2); |
208 | |
209 | init_completion(&inst->comp); |
210 | |
211 | aml_vcodec_debug(inst, "vp9 Instance >> %p", inst); |
212 | |
213 | ctx->ada_ctx = &inst->vdec; |
214 | *h_vdec = (unsigned long)inst; |
215 | |
216 | /* init decoder. */ |
217 | ret = video_decoder_init(&inst->vdec); |
218 | if (ret) { |
219 | aml_vcodec_err(inst, "vdec_vp9 init err=%d", ret); |
220 | goto error_free_inst; |
221 | } |
222 | |
223 | //dump_init(); |
224 | |
225 | return 0; |
226 | |
227 | error_free_vsi: |
228 | kfree(inst->vsi); |
229 | error_free_inst: |
230 | kfree(inst); |
231 | *h_vdec = 0; |
232 | |
233 | return ret; |
234 | } |
235 | |
236 | #if 0 |
237 | static int refer_buffer_num(int level_idc, int poc_cnt, |
238 | int mb_width, int mb_height) |
239 | { |
240 | return 20; |
241 | } |
242 | #endif |
243 | |
244 | static void fill_vdec_params(struct vdec_vp9_inst *inst, |
245 | struct VP9Context *vp9_ctx) |
246 | { |
247 | struct vdec_pic_info *pic = &inst->vsi->pic; |
248 | struct vdec_vp9_dec_info *dec = &inst->vsi->dec; |
249 | struct v4l2_rect *rect = &inst->vsi->crop; |
250 | |
251 | /* fill visible area size that be used for EGL. */ |
252 | pic->visible_width = vp9_ctx->render_width; |
253 | pic->visible_height = vp9_ctx->render_height; |
254 | |
255 | /* calc visible ares. */ |
256 | rect->left = 0; |
257 | rect->top = 0; |
258 | rect->width = pic->visible_width; |
259 | rect->height = pic->visible_height; |
260 | |
261 | /* config canvas size that be used for decoder. */ |
262 | pic->coded_width = ALIGN(vp9_ctx->width, 32); |
263 | pic->coded_height = ALIGN(vp9_ctx->height, 32); |
264 | |
265 | pic->y_len_sz = pic->coded_width * pic->coded_height; |
266 | pic->c_len_sz = pic->y_len_sz >> 1; |
267 | |
268 | /* calc DPB size */ |
269 | dec->dpb_sz = 5;//refer_buffer_num(sps->level_idc, poc_cnt, mb_w, mb_h); |
270 | |
271 | aml_vcodec_debug(inst, "[%d] The stream infos, coded:(%d x %d), visible:(%d x %d), DPB: %d\n", |
272 | inst->ctx->id, pic->coded_width, pic->coded_height, |
273 | pic->visible_width, pic->visible_height, dec->dpb_sz); |
274 | } |
275 | |
276 | static int stream_parse_by_ucode(struct vdec_vp9_inst *inst, u8 *buf, u32 size) |
277 | { |
278 | int ret = 0; |
279 | |
280 | ret = vdec_write_nalu(inst, buf, size, 0); |
281 | if (ret < 0) { |
282 | pr_err("write frame data failed. err: %d\n", ret); |
283 | return ret; |
284 | } |
285 | |
286 | /* wait ucode parse ending. */ |
287 | wait_for_completion_timeout(&inst->comp, |
288 | msecs_to_jiffies(1000)); |
289 | |
290 | return inst->vsi->dec.dpb_sz ? 0 : -1; |
291 | } |
292 | |
293 | static int stream_parse(struct vdec_vp9_inst *inst, u8 *buf, u32 size) |
294 | { |
295 | int ret = 0; |
296 | struct vp9_param_sets *ps = NULL; |
297 | |
298 | ps = kzalloc(sizeof(struct vp9_param_sets), GFP_KERNEL); |
299 | if (ps == NULL) |
300 | return -ENOMEM; |
301 | |
302 | ret = vp9_decode_extradata_ps(buf, size, ps); |
303 | if (ret) { |
304 | pr_err("parse extra data failed. err: %d\n", ret); |
305 | goto out; |
306 | } |
307 | |
308 | if (ps->head_parsed) |
309 | fill_vdec_params(inst, &ps->ctx); |
310 | |
311 | ret = ps->head_parsed ? 0 : -1; |
312 | out: |
313 | kfree(ps); |
314 | |
315 | return ret; |
316 | } |
317 | |
318 | static int vdec_vp9_probe(unsigned long h_vdec, |
319 | struct aml_vcodec_mem *bs, void *out) |
320 | { |
321 | struct vdec_vp9_inst *inst = |
322 | (struct vdec_vp9_inst *)h_vdec; |
323 | struct stream_info *st; |
324 | u8 *buf = (u8 *)bs->vaddr; |
325 | u32 size = bs->size; |
326 | int ret = 0; |
327 | |
328 | st = (struct stream_info *)buf; |
329 | if (inst->ctx->is_drm_mode && (st->magic == DRMe || st->magic == DRMn)) |
330 | return 0; |
331 | |
332 | if (st->magic == NORe || st->magic == NORn) |
333 | ret = stream_parse(inst, st->data, st->length); |
334 | else { |
335 | if (inst->ctx->param_sets_from_ucode) |
336 | ret = stream_parse_by_ucode(inst, buf, size); |
337 | else |
338 | ret = stream_parse(inst, buf, size); |
339 | } |
340 | |
341 | inst->vsi->cur_pic = inst->vsi->pic; |
342 | |
343 | return ret; |
344 | } |
345 | |
346 | static void vdec_vp9_deinit(unsigned long h_vdec) |
347 | { |
348 | ulong flags; |
349 | struct vdec_vp9_inst *inst = (struct vdec_vp9_inst *)h_vdec; |
350 | struct aml_vcodec_ctx *ctx = inst->ctx; |
351 | |
352 | aml_vcodec_debug_enter(inst); |
353 | |
354 | video_decoder_release(&inst->vdec); |
355 | |
356 | vcodec_vfm_release(&inst->vfm); |
357 | |
358 | //dump_deinit(); |
359 | |
360 | spin_lock_irqsave(&ctx->slock, flags); |
361 | if (inst->vsi && inst->vsi->header_buf) |
362 | kfree(inst->vsi->header_buf); |
363 | |
364 | if (inst->vsi) |
365 | kfree(inst->vsi); |
366 | |
367 | kfree(inst); |
368 | |
369 | ctx->drv_handle = 0; |
370 | spin_unlock_irqrestore(&ctx->slock, flags); |
371 | |
372 | need_trigger = false; |
373 | dump_cnt = 0; |
374 | } |
375 | |
376 | static int vdec_vp9_get_fb(struct vdec_vp9_inst *inst, struct vdec_v4l2_buffer **out) |
377 | { |
378 | return get_fb_from_queue(inst->ctx, out); |
379 | } |
380 | |
381 | static void vdec_vp9_get_vf(struct vdec_vp9_inst *inst, struct vdec_v4l2_buffer **out) |
382 | { |
383 | struct vframe_s *vf = NULL; |
384 | struct vdec_v4l2_buffer *fb = NULL; |
385 | |
386 | vf = peek_video_frame(&inst->vfm); |
387 | if (!vf) { |
388 | aml_vcodec_debug(inst, "there is no vframe."); |
389 | *out = NULL; |
390 | return; |
391 | } |
392 | |
393 | vf = get_video_frame(&inst->vfm); |
394 | if (!vf) { |
395 | aml_vcodec_debug(inst, "the vframe is avalid."); |
396 | *out = NULL; |
397 | return; |
398 | } |
399 | |
400 | atomic_set(&vf->use_cnt, 1); |
401 | |
402 | fb = (struct vdec_v4l2_buffer *)vf->v4l_mem_handle; |
403 | fb->vf_handle = (unsigned long)vf; |
404 | fb->status = FB_ST_DISPLAY; |
405 | |
406 | *out = fb; |
407 | |
408 | //pr_info("%s, %d\n", __func__, fb->base_y.bytes_used); |
409 | //dump_write(fb->base_y.vaddr, fb->base_y.bytes_used); |
410 | //dump_write(fb->base_c.vaddr, fb->base_c.bytes_used); |
411 | |
412 | /* convert yuv format. */ |
413 | //swap_uv(fb->base_c.vaddr, fb->base_c.size); |
414 | } |
415 | |
416 | static void add_prefix_data(struct vp9_superframe_split *s, |
417 | u8 **out, u32 *out_size) |
418 | { |
419 | int i; |
420 | u8 *p = NULL; |
421 | u32 length; |
422 | |
423 | length = s->size + s->nb_frames * PREFIX_SIZE; |
424 | p = vzalloc(length); |
425 | if (!p) { |
426 | pr_err("alloc size %d failed.\n" ,length); |
427 | return; |
428 | } |
429 | |
430 | memcpy(p, s->data, s->size); |
431 | p += s->size; |
432 | |
433 | for (i = s->nb_frames; i > 0; i--) { |
434 | u32 frame_size = s->sizes[i - 1]; |
435 | u8 *prefix = NULL; |
436 | |
437 | p -= frame_size; |
438 | memmove(p + PREFIX_SIZE * i, p, frame_size); |
439 | prefix = p + PREFIX_SIZE * (i - 1); |
440 | |
441 | /*add amlogic frame headers.*/ |
442 | frame_size += 16; |
443 | prefix[0] = (frame_size >> 24) & 0xff; |
444 | prefix[1] = (frame_size >> 16) & 0xff; |
445 | prefix[2] = (frame_size >> 8 ) & 0xff; |
446 | prefix[3] = (frame_size >> 0 ) & 0xff; |
447 | prefix[4] = ((frame_size >> 24) & 0xff) ^ 0xff; |
448 | prefix[5] = ((frame_size >> 16) & 0xff) ^ 0xff; |
449 | prefix[6] = ((frame_size >> 8 ) & 0xff) ^ 0xff; |
450 | prefix[7] = ((frame_size >> 0 ) & 0xff) ^ 0xff; |
451 | prefix[8] = 0; |
452 | prefix[9] = 0; |
453 | prefix[10] = 0; |
454 | prefix[11] = 1; |
455 | prefix[12] = 'A'; |
456 | prefix[13] = 'M'; |
457 | prefix[14] = 'L'; |
458 | prefix[15] = 'V'; |
459 | frame_size -= 16; |
460 | } |
461 | |
462 | *out = p; |
463 | *out_size = length; |
464 | } |
465 | |
466 | static void trigger_decoder(struct aml_vdec_adapt *vdec) |
467 | { |
468 | int i, ret; |
469 | u32 frame_size = 0; |
470 | u8 *p = vp9_trigger_header; |
471 | |
472 | for (i = 0; i < ARRAY_SIZE(vp9_trigger_framesize); i++) { |
473 | frame_size = vp9_trigger_framesize[i]; |
474 | ret = vdec_vframe_write(vdec, p, |
475 | frame_size, 0); |
476 | pr_err("write trigger frame %d\n", ret); |
477 | p += frame_size; |
478 | } |
479 | } |
480 | |
481 | static int vdec_write_nalu(struct vdec_vp9_inst *inst, |
482 | u8 *buf, u32 size, u64 ts) |
483 | { |
484 | int ret = 0; |
485 | struct aml_vdec_adapt *vdec = &inst->vdec; |
486 | struct vp9_superframe_split s; |
487 | u8 *data = NULL; |
488 | u32 length = 0; |
489 | bool need_prefix = vp9_need_prefix; |
490 | |
491 | memset(&s, 0, sizeof(s)); |
492 | |
493 | /*trigger.*/ |
494 | if (0 && !need_trigger) { |
495 | trigger_decoder(vdec); |
496 | need_trigger = true; |
497 | } |
498 | |
499 | if (need_prefix) { |
500 | /*parse superframe.*/ |
501 | s.data = buf; |
502 | s.data_size = size; |
503 | ret = vp9_superframe_split_filter(&s); |
504 | if (ret) { |
505 | pr_err("parse frames failed.\n"); |
506 | return ret; |
507 | } |
508 | |
509 | /*add headers.*/ |
510 | add_prefix_data(&s, &data, &length); |
511 | ret = vdec_vframe_write(vdec, data, length, ts); |
512 | vfree(data); |
513 | } else { |
514 | ret = vdec_vframe_write(vdec, buf, size, ts); |
515 | } |
516 | |
517 | return ret; |
518 | } |
519 | |
520 | static bool monitor_res_change(struct vdec_vp9_inst *inst, u8 *buf, u32 size) |
521 | { |
522 | int ret = -1; |
523 | u8 *p = buf; |
524 | int len = size; |
525 | u32 synccode = vp9_need_prefix ? |
526 | ((p[1] << 16) | (p[2] << 8) | p[3]) : |
527 | ((p[17] << 16) | (p[18] << 8) | p[19]); |
528 | |
529 | if (synccode == SYNC_CODE) { |
530 | ret = stream_parse(inst, p, len); |
531 | if (!ret && (inst->vsi->cur_pic.coded_width != |
532 | inst->vsi->pic.coded_width || |
533 | inst->vsi->cur_pic.coded_height != |
534 | inst->vsi->pic.coded_height)) { |
535 | inst->vsi->cur_pic = inst->vsi->pic; |
536 | return true; |
537 | } |
538 | } |
539 | |
540 | return false; |
541 | } |
542 | |
543 | static int vdec_vp9_decode(unsigned long h_vdec, struct aml_vcodec_mem *bs, |
544 | u64 timestamp, bool *res_chg) |
545 | { |
546 | struct vdec_vp9_inst *inst = (struct vdec_vp9_inst *)h_vdec; |
547 | struct aml_vdec_adapt *vdec = &inst->vdec; |
548 | struct stream_info *st; |
549 | u8 *buf; |
550 | u32 size; |
551 | int ret = -1; |
552 | |
553 | /* bs NULL means flush decoder */ |
554 | if (bs == NULL) |
555 | return -1; |
556 | |
557 | buf = (u8 *)bs->vaddr; |
558 | size = bs->size; |
559 | st = (struct stream_info *)buf; |
560 | |
561 | if (inst->ctx->is_drm_mode && (st->magic == DRMe || st->magic == DRMn)) |
562 | ret = vdec_vbuf_write(vdec, st->m.buf, sizeof(st->m.drm)); |
563 | else if (st->magic == NORe) |
564 | ret = vdec_vbuf_write(vdec, st->data, st->length); |
565 | else if (st->magic == NORn) |
566 | ret = vdec_write_nalu(inst, st->data, st->length, timestamp); |
567 | else if (inst->ctx->is_stream_mode) |
568 | ret = vdec_vbuf_write(vdec, buf, size); |
569 | else { |
570 | /*checked whether the resolution changes.*/ |
571 | if ((*res_chg = monitor_res_change(inst, buf, size))) |
572 | return 0; |
573 | |
574 | ret = vdec_write_nalu(inst, buf, size, timestamp); |
575 | } |
576 | |
577 | return ret; |
578 | } |
579 | |
580 | static int vdec_vp9_get_param(unsigned long h_vdec, |
581 | enum vdec_get_param_type type, void *out) |
582 | { |
583 | int ret = 0; |
584 | struct vdec_vp9_inst *inst = (struct vdec_vp9_inst *)h_vdec; |
585 | |
586 | if (!inst) { |
587 | pr_err("the vp9 inst of dec is invalid.\n"); |
588 | return -1; |
589 | } |
590 | |
591 | switch (type) { |
592 | case GET_PARAM_DISP_FRAME_BUFFER: |
593 | vdec_vp9_get_vf(inst, out); |
594 | break; |
595 | |
596 | case GET_PARAM_FREE_FRAME_BUFFER: |
597 | ret = vdec_vp9_get_fb(inst, out); |
598 | break; |
599 | |
600 | case GET_PARAM_PIC_INFO: |
601 | get_pic_info(inst, out); |
602 | break; |
603 | |
604 | case GET_PARAM_DPB_SIZE: |
605 | get_dpb_size(inst, out); |
606 | break; |
607 | |
608 | case GET_PARAM_CROP_INFO: |
609 | get_crop_info(inst, out); |
610 | break; |
611 | |
612 | default: |
613 | aml_vcodec_err(inst, "invalid get parameter type=%d", type); |
614 | ret = -EINVAL; |
615 | } |
616 | |
617 | return ret; |
618 | } |
619 | |
620 | static void set_param_write_sync(struct vdec_vp9_inst *inst) |
621 | { |
622 | complete(&inst->comp); |
623 | } |
624 | |
625 | static void set_param_pic_info(struct vdec_vp9_inst *inst, |
626 | struct aml_vdec_pic_infos *info) |
627 | { |
628 | struct vdec_pic_info *pic = &inst->vsi->pic; |
629 | struct vdec_vp9_dec_info *dec = &inst->vsi->dec; |
630 | struct v4l2_rect *rect = &inst->vsi->crop; |
631 | |
632 | /* fill visible area size that be used for EGL. */ |
633 | pic->visible_width = info->visible_width; |
634 | pic->visible_height = info->visible_height; |
635 | |
636 | /* calc visible ares. */ |
637 | rect->left = 0; |
638 | rect->top = 0; |
639 | rect->width = pic->visible_width; |
640 | rect->height = pic->visible_height; |
641 | |
642 | /* config canvas size that be used for decoder. */ |
643 | pic->coded_width = info->coded_width; |
644 | pic->coded_height = info->coded_height; |
645 | |
646 | pic->y_len_sz = pic->coded_width * pic->coded_height; |
647 | pic->c_len_sz = pic->y_len_sz >> 1; |
648 | |
649 | /* calc DPB size */ |
650 | dec->dpb_sz = 5; |
651 | |
652 | /*wake up*/ |
653 | complete(&inst->comp); |
654 | |
655 | pr_info("Parse from ucode, crop(%d x %d), coded(%d x %d) dpb: %d\n", |
656 | info->visible_width, info->visible_height, |
657 | info->coded_width, info->coded_height, |
658 | info->dpb_size); |
659 | } |
660 | |
661 | static int vdec_vp9_set_param(unsigned long h_vdec, |
662 | enum vdec_set_param_type type, void *in) |
663 | { |
664 | int ret = 0; |
665 | struct vdec_vp9_inst *inst = (struct vdec_vp9_inst *)h_vdec; |
666 | |
667 | if (!inst) { |
668 | pr_err("the vp9 inst of dec is invalid.\n"); |
669 | return -1; |
670 | } |
671 | |
672 | switch (type) { |
673 | case SET_PARAM_WRITE_FRAME_SYNC: |
674 | set_param_write_sync(inst); |
675 | break; |
676 | |
677 | case SET_PARAM_PIC_INFO: |
678 | set_param_pic_info(inst, in); |
679 | break; |
680 | |
681 | default: |
682 | aml_vcodec_err(inst, "invalid set parameter type=%d", type); |
683 | ret = -EINVAL; |
684 | } |
685 | |
686 | return ret; |
687 | } |
688 | |
689 | static struct vdec_common_if vdec_vp9_if = { |
690 | .init = vdec_vp9_init, |
691 | .probe = vdec_vp9_probe, |
692 | .decode = vdec_vp9_decode, |
693 | .get_param = vdec_vp9_get_param, |
694 | .set_param = vdec_vp9_set_param, |
695 | .deinit = vdec_vp9_deinit, |
696 | }; |
697 | |
698 | struct vdec_common_if *get_vp9_dec_comm_if(void); |
699 | |
700 | struct vdec_common_if *get_vp9_dec_comm_if(void) |
701 | { |
702 | return &vdec_vp9_if; |
703 | } |
704 | |
705 |