vdec: fix coverity issues [1/1]
[GitHub/LineageOS/G12/android_hardware_amlogic_kernel-modules_media.git] / drivers / amvdec_ports / decoder / vdec_mpeg12_if.c
CommitLineData
0fb7e163
NQ
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_mpeg12_parser.h"
33
34#define NAL_TYPE(value) ((value) & 0x1F)
35#define HEADER_BUFFER_SIZE (32 * 1024)
36
37/**
38 * struct mpeg12_fb - mpeg12 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 */
45struct mpeg12_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_mpeg12_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 */
63struct vdec_mpeg12_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_mpeg12_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 */
88struct vdec_mpeg12_vsi {
89 char *header_buf;
90 int sps_size;
91 int pps_size;
92 int sei_size;
93 int head_offset;
94 struct vdec_mpeg12_dec_info dec;
95 struct vdec_pic_info pic;
17310557 96 struct vdec_pic_info cur_pic;
0fb7e163
NQ
97 struct v4l2_rect crop;
98 bool is_combine;
99 int nalu_pos;
100 //struct mpeg12_param_sets ps;
101};
102
103/**
104 * struct vdec_mpeg12_inst - mpeg12 decoder instance
105 * @num_nalu : how many nalus be decoded
106 * @ctx : point to aml_vcodec_ctx
107 * @vsi : VPU shared information
108 */
109struct vdec_mpeg12_inst {
110 unsigned int num_nalu;
111 struct aml_vcodec_ctx *ctx;
112 struct aml_vdec_adapt vdec;
113 struct vdec_mpeg12_vsi *vsi;
114 struct vcodec_vfm_s vfm;
68fcded9
SZ
115 struct aml_dec_params parms;
116 struct completion comp;
0fb7e163
NQ
117};
118
119static void get_pic_info(struct vdec_mpeg12_inst *inst,
120 struct vdec_pic_info *pic)
121{
122 *pic = inst->vsi->pic;
123
17310557 124 v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_EXINFO,
4eed6421
NQ
125 "pic(%d, %d), buf(%d, %d)\n",
126 pic->visible_width, pic->visible_height,
127 pic->coded_width, pic->coded_height);
17310557 128 v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_EXINFO,
4eed6421
NQ
129 "Y(%d, %d), C(%d, %d)\n",
130 pic->y_bs_sz, pic->y_len_sz,
131 pic->c_bs_sz, pic->c_len_sz);
0fb7e163
NQ
132}
133
134static void get_crop_info(struct vdec_mpeg12_inst *inst, struct v4l2_rect *cr)
135{
136 cr->left = inst->vsi->crop.left;
137 cr->top = inst->vsi->crop.top;
138 cr->width = inst->vsi->crop.width;
139 cr->height = inst->vsi->crop.height;
140
17310557 141 v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_EXINFO,
4eed6421
NQ
142 "l=%d, t=%d, w=%d, h=%d\n",
143 cr->left, cr->top, cr->width, cr->height);
0fb7e163
NQ
144}
145
146static void get_dpb_size(struct vdec_mpeg12_inst *inst, unsigned int *dpb_sz)
147{
148 *dpb_sz = inst->vsi->dec.dpb_sz;
17310557 149 v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_EXINFO, "sz=%d\n", *dpb_sz);
0fb7e163
NQ
150}
151
68fcded9
SZ
152static u32 vdec_config_default_parms(u8 *parm)
153{
154 u8 *pbuf = parm;
155
156 pbuf += sprintf(pbuf, "parm_v4l_codec_enable:1;");
157 pbuf += sprintf(pbuf, "parm_v4l_canvas_mem_mode:0;");
158 pbuf += sprintf(pbuf, "parm_v4l_buffer_margin:0;");
159
160 return pbuf - parm;
161}
162
163static void vdec_parser_parms(struct vdec_mpeg12_inst *inst)
164{
165 struct aml_vcodec_ctx *ctx = inst->ctx;
166
167 if (ctx->config.parm.dec.parms_status &
168 V4L2_CONFIG_PARM_DECODE_CFGINFO) {
169 u8 *pbuf = ctx->config.buf;
170
171 pbuf += sprintf(pbuf, "parm_v4l_codec_enable:1;");
172 pbuf += sprintf(pbuf, "parm_v4l_canvas_mem_mode:%d;",
173 ctx->config.parm.dec.cfg.canvas_mem_mode);
174 pbuf += sprintf(pbuf, "parm_v4l_buffer_margin:%d;",
175 ctx->config.parm.dec.cfg.ref_buf_margin);
176 ctx->config.length = pbuf - ctx->config.buf;
177 } else {
178 ctx->config.length = vdec_config_default_parms(ctx->config.buf);
179 }
180
181 inst->vdec.config = ctx->config;
182 inst->parms.cfg = ctx->config.parm.dec.cfg;
183 inst->parms.parms_status |= V4L2_CONFIG_PARM_DECODE_CFGINFO;
184}
17310557 185
0fb7e163
NQ
186static int vdec_mpeg12_init(struct aml_vcodec_ctx *ctx, unsigned long *h_vdec)
187{
188 struct vdec_mpeg12_inst *inst = NULL;
189 int ret = -1;
e9ee0ea8 190 bool dec_init = false;
0fb7e163
NQ
191
192 inst = kzalloc(sizeof(*inst), GFP_KERNEL);
193 if (!inst)
194 return -ENOMEM;
195
75803959
NQ
196 inst->vdec.video_type = VFORMAT_MPEG12;
197 inst->vdec.dev = ctx->dev->vpu_plat_dev;
198 inst->vdec.filp = ctx->dev->filp;
199 inst->vdec.config = ctx->config;
200 inst->vdec.ctx = ctx;
201 inst->ctx = ctx;
0fb7e163 202
68fcded9
SZ
203 vdec_parser_parms(inst);
204
0fb7e163
NQ
205 /* set play mode.*/
206 if (ctx->is_drm_mode)
207 inst->vdec.port.flag |= PORT_FLAG_DRM;
208
209 /* to eable mpeg12 hw.*/
210 inst->vdec.port.type = PORT_TYPE_VIDEO;
211
212 /* init vfm */
75803959
NQ
213 inst->vfm.ctx = ctx;
214 inst->vfm.ada_ctx = &inst->vdec;
ed3dcdaf
PY
215 ret = vcodec_vfm_init(&inst->vfm);
216 if (ret) {
217 v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_ERROR,
218 "init vfm failed.\n");
219 goto err;
220 }
0fb7e163
NQ
221
222 ret = video_decoder_init(&inst->vdec);
223 if (ret) {
4eed6421
NQ
224 v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_ERROR,
225 "vdec_mpeg12 init err=%d\n", ret);
ed3dcdaf 226 goto err;
0fb7e163 227 }
e9ee0ea8 228 dec_init = true;
0fb7e163
NQ
229
230 /* probe info from the stream */
231 inst->vsi = kzalloc(sizeof(struct vdec_mpeg12_vsi), GFP_KERNEL);
232 if (!inst->vsi) {
233 ret = -ENOMEM;
ed3dcdaf 234 goto err;
0fb7e163
NQ
235 }
236
237 /* alloc the header buffer to be used cache sps or spp etc.*/
238 inst->vsi->header_buf = kzalloc(HEADER_BUFFER_SIZE, GFP_KERNEL);
ed3dcdaf 239 if (!inst->vsi->header_buf) {
0fb7e163 240 ret = -ENOMEM;
ed3dcdaf 241 goto err;
0fb7e163
NQ
242 }
243
4eed6421
NQ
244 v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_PRINFO,
245 "mpeg12 Instance >> %lx\n", (ulong) inst);
ed3dcdaf 246 init_completion(&inst->comp);
75803959
NQ
247 ctx->ada_ctx = &inst->vdec;
248 *h_vdec = (unsigned long)inst;
0fb7e163
NQ
249
250 //dump_init();
251
252 return 0;
253
ed3dcdaf 254err:
e9ee0ea8
SZ
255 if (dec_init)
256 video_decoder_release(&inst->vdec);
ed3dcdaf
PY
257 if (inst)
258 vcodec_vfm_release(&inst->vfm);
259 if (inst && inst->vsi && inst->vsi->header_buf)
260 kfree(inst->vsi->header_buf);
261 if (inst && inst->vsi)
262 kfree(inst->vsi);
263 if (inst)
264 kfree(inst);
0fb7e163
NQ
265 *h_vdec = 0;
266
267 return ret;
268}
269
270static void fill_vdec_params(struct vdec_mpeg12_inst *inst,
271 struct MpvParseContext *dec_ps)
272{
273 struct vdec_pic_info *pic = &inst->vsi->pic;
274 struct vdec_mpeg12_dec_info *dec = &inst->vsi->dec;
275 struct v4l2_rect *rect = &inst->vsi->crop;
276
277 /* fill visible area size that be used for EGL. */
278 pic->visible_width = dec_ps->width;
279 pic->visible_height = dec_ps->height;
280
281 /* calc visible ares. */
282 rect->left = 0;
283 rect->top = 0;
284 rect->width = pic->visible_width;
285 rect->height = pic->visible_height;
286
287 /* config canvas size that be used for decoder. */
288 pic->coded_width = ALIGN(dec_ps->coded_width, 64);
68fcded9 289 pic->coded_height = ALIGN(dec_ps->coded_height, 32);
0fb7e163
NQ
290
291 pic->y_len_sz = pic->coded_width * pic->coded_height;
292 pic->c_len_sz = pic->y_len_sz >> 1;
293
ed3dcdaf
PY
294 /*7(parm_v4l_buffer_margin) + 8(DECODE_BUFFER_NUM_DEF)*/
295 dec->dpb_sz = 15;
0fb7e163 296
17310557 297 v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_BUFMGR,
4eed6421
NQ
298 "The stream infos, coded:(%d x %d), visible:(%d x %d), DPB: %d\n",
299 pic->coded_width, pic->coded_height,
0fb7e163
NQ
300 pic->visible_width, pic->visible_height, dec->dpb_sz);
301}
302
372ed7e8
NQ
303static int parse_stream_ucode(struct vdec_mpeg12_inst *inst,
304 u8 *buf, u32 size, u64 timestamp)
68fcded9
SZ
305{
306 int ret = 0;
307 struct aml_vdec_adapt *vdec = &inst->vdec;
308
372ed7e8 309 ret = vdec_vframe_write(vdec, buf, size, timestamp);
68fcded9 310 if (ret < 0) {
17310557
NQ
311 v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_ERROR,
312 "write frame data failed. err: %d\n", ret);
68fcded9
SZ
313 return ret;
314 }
315
316 /* wait ucode parse ending. */
317 wait_for_completion_timeout(&inst->comp,
318 msecs_to_jiffies(1000));
319
320 return inst->vsi->dec.dpb_sz ? 0 : -1;
321}
322
17310557 323static int parse_stream_ucode_dma(struct vdec_mpeg12_inst *inst,
372ed7e8 324 ulong buf, u32 size, u64 timestamp, u32 handle)
17310557
NQ
325{
326 int ret = 0;
327 struct aml_vdec_adapt *vdec = &inst->vdec;
328
d04e649b
SZ
329 ret = vdec_vframe_write_with_dma(vdec, buf, size, timestamp, handle,
330 vdec_vframe_input_free, inst->ctx);
17310557
NQ
331 if (ret < 0) {
332 v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_ERROR,
333 "write frame data failed. err: %d\n", ret);
334 return ret;
335 }
336
337 /* wait ucode parse ending. */
338 wait_for_completion_timeout(&inst->comp,
339 msecs_to_jiffies(1000));
340
341 return inst->vsi->dec.dpb_sz ? 0 : -1;
342}
343
344static int parse_stream_cpu(struct vdec_mpeg12_inst *inst, u8 *buf, u32 size)
0fb7e163
NQ
345{
346 int ret = 0;
347 struct mpeg12_param_sets *ps = NULL;
348
349 ps = kzalloc(sizeof(struct mpeg12_param_sets), GFP_KERNEL);
350 if (ps == NULL)
351 return -ENOMEM;
352
353 ret = mpeg12_decode_extradata_ps(buf, size, ps);
354 if (ret) {
4eed6421
NQ
355 v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_ERROR,
356 "parse extra data failed. err: %d\n", ret);
0fb7e163
NQ
357 goto out;
358 }
359
360 if (ps->head_parsed)
361 fill_vdec_params(inst, &ps->dec_ps);
362
363 ret = ps->head_parsed ? 0 : -1;
364out:
365 kfree(ps);
366
367 return ret;
368}
369
370static int vdec_mpeg12_probe(unsigned long h_vdec,
371 struct aml_vcodec_mem *bs, void *out)
372{
373 struct vdec_mpeg12_inst *inst =
374 (struct vdec_mpeg12_inst *)h_vdec;
0fb7e163
NQ
375 u8 *buf = (u8 *)bs->vaddr;
376 u32 size = bs->size;
377 int ret = 0;
378
17310557
NQ
379 if (inst->ctx->is_drm_mode) {
380 if (bs->model == VB2_MEMORY_MMAP) {
381 struct aml_video_stream *s =
382 (struct aml_video_stream *) buf;
383
384 if ((s->magic != AML_VIDEO_MAGIC) &&
385 (s->type != V4L_STREAM_TYPE_MATEDATA))
386 return -1;
387
388 if (inst->ctx->param_sets_from_ucode) {
372ed7e8
NQ
389 ret = parse_stream_ucode(inst, s->data,
390 s->len, bs->timestamp);
17310557
NQ
391 } else {
392 ret = parse_stream_cpu(inst, s->data, s->len);
393 }
394 } else if (bs->model == VB2_MEMORY_DMABUF ||
395 bs->model == VB2_MEMORY_USERPTR) {
396 ret = parse_stream_ucode_dma(inst, bs->addr, size,
372ed7e8 397 bs->timestamp, BUFF_IDX(bs, bs->index));
17310557
NQ
398 }
399 } else {
400 if (inst->ctx->param_sets_from_ucode) {
372ed7e8 401 ret = parse_stream_ucode(inst, buf, size, bs->timestamp);
17310557
NQ
402 } else {
403 ret = parse_stream_cpu(inst, buf, size);
404 }
405 }
0fb7e163 406
17310557 407 inst->vsi->cur_pic = inst->vsi->pic;
0fb7e163
NQ
408
409 return ret;
410}
411
412static void vdec_mpeg12_deinit(unsigned long h_vdec)
413{
414 struct vdec_mpeg12_inst *inst = (struct vdec_mpeg12_inst *)h_vdec;
415
416 if (!inst)
417 return;
418
0fb7e163
NQ
419 video_decoder_release(&inst->vdec);
420
421 vcodec_vfm_release(&inst->vfm);
422
423 //dump_deinit();
424
425 if (inst->vsi && inst->vsi->header_buf)
426 kfree(inst->vsi->header_buf);
427
428 if (inst->vsi)
429 kfree(inst->vsi);
430
431 kfree(inst);
432}
433
434static int vdec_mpeg12_get_fb(struct vdec_mpeg12_inst *inst, struct vdec_v4l2_buffer **out)
435{
436 return get_fb_from_queue(inst->ctx, out);
437}
438
439static void vdec_mpeg12_get_vf(struct vdec_mpeg12_inst *inst, struct vdec_v4l2_buffer **out)
440{
441 struct vframe_s *vf = NULL;
442 struct vdec_v4l2_buffer *fb = NULL;
443
444 vf = peek_video_frame(&inst->vfm);
445 if (!vf) {
4eed6421
NQ
446 v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_ERROR,
447 "there is no vframe.\n");
0fb7e163
NQ
448 *out = NULL;
449 return;
450 }
451
452 vf = get_video_frame(&inst->vfm);
453 if (!vf) {
4eed6421
NQ
454 v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_ERROR,
455 "the vframe is avalid.\n");
0fb7e163
NQ
456 *out = NULL;
457 return;
458 }
459
460 atomic_set(&vf->use_cnt, 1);
461
462 fb = (struct vdec_v4l2_buffer *)vf->v4l_mem_handle;
463 fb->vf_handle = (unsigned long)vf;
464 fb->status = FB_ST_DISPLAY;
465
466 *out = fb;
467
468 //pr_info("%s, %d\n", __func__, fb->base_y.bytes_used);
469 //dump_write(fb->base_y.va, fb->base_y.bytes_used);
470 //dump_write(fb->base_c.va, fb->base_c.bytes_used);
471
472 /* convert yuv format. */
473 //swap_uv(fb->base_c.va, fb->base_c.size);
474}
475
476static int vdec_write_nalu(struct vdec_mpeg12_inst *inst,
477 u8 *buf, u32 size, u64 ts)
478{
479 int ret = 0;
480 struct aml_vdec_adapt *vdec = &inst->vdec;
481
482 ret = vdec_vframe_write(vdec, buf, size, ts);
483
484 return ret;
485}
486
372ed7e8
NQ
487static int vdec_mpeg12_decode(unsigned long h_vdec,
488 struct aml_vcodec_mem *bs, bool *res_chg)
0fb7e163
NQ
489{
490 struct vdec_mpeg12_inst *inst = (struct vdec_mpeg12_inst *)h_vdec;
491 struct aml_vdec_adapt *vdec = &inst->vdec;
17310557
NQ
492 u8 *buf = (u8 *) bs->vaddr;
493 u32 size = bs->size;
494 int ret = -1;
0fb7e163 495
17310557
NQ
496 if (vdec_input_full(vdec))
497 return -EAGAIN;
498
499 if (inst->ctx->is_drm_mode) {
500 if (bs->model == VB2_MEMORY_MMAP) {
501 struct aml_video_stream *s =
502 (struct aml_video_stream *) buf;
503
504 if (s->magic != AML_VIDEO_MAGIC)
505 return -1;
506
507 ret = vdec_vframe_write(vdec,
508 s->data,
509 s->len,
372ed7e8 510 bs->timestamp);
17310557
NQ
511 } else if (bs->model == VB2_MEMORY_DMABUF ||
512 bs->model == VB2_MEMORY_USERPTR) {
513 ret = vdec_vframe_write_with_dma(vdec,
372ed7e8 514 bs->addr, size, bs->timestamp,
d04e649b
SZ
515 BUFF_IDX(bs, bs->index),
516 vdec_vframe_input_free, inst->ctx);
17310557
NQ
517 }
518 } else {
372ed7e8 519 ret = vdec_write_nalu(inst, buf, size, bs->timestamp);
17310557 520 }
0fb7e163
NQ
521
522 return ret;
523}
524
525static int vdec_mpeg12_get_param(unsigned long h_vdec,
526 enum vdec_get_param_type type, void *out)
527{
528 int ret = 0;
529 struct vdec_mpeg12_inst *inst = (struct vdec_mpeg12_inst *)h_vdec;
530
531 if (!inst) {
b93666f1 532 v4l_dbg(0, V4L_DEBUG_CODEC_ERROR,
4eed6421 533 "the mpeg12 inst of dec is invalid.\n");
0fb7e163
NQ
534 return -1;
535 }
536
537 switch (type) {
538 case GET_PARAM_DISP_FRAME_BUFFER:
539 vdec_mpeg12_get_vf(inst, out);
540 break;
541
542 case GET_PARAM_FREE_FRAME_BUFFER:
543 ret = vdec_mpeg12_get_fb(inst, out);
544 break;
545
546 case GET_PARAM_PIC_INFO:
547 get_pic_info(inst, out);
548 break;
549
550 case GET_PARAM_DPB_SIZE:
551 get_dpb_size(inst, out);
552 break;
553
554 case GET_PARAM_CROP_INFO:
555 get_crop_info(inst, out);
556 break;
557
558 default:
4eed6421
NQ
559 v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_ERROR,
560 "invalid get parameter type=%d\n", type);
0fb7e163
NQ
561 ret = -EINVAL;
562 }
563
564 return ret;
565}
566
68fcded9
SZ
567static void set_param_write_sync(struct vdec_mpeg12_inst *inst)
568{
569 complete(&inst->comp);
570}
571
8e9fb312
NQ
572static void set_param_ps_info(struct vdec_mpeg12_inst *inst,
573 struct aml_vdec_ps_infos *ps)
0fb7e163 574{
68fcded9
SZ
575 struct vdec_pic_info *pic = &inst->vsi->pic;
576 struct vdec_mpeg12_dec_info *dec = &inst->vsi->dec;
577 struct v4l2_rect *rect = &inst->vsi->crop;
578
579 /* fill visible area size that be used for EGL. */
580 pic->visible_width = ps->visible_width;
581 pic->visible_height = ps->visible_height;
582
583 /* calc visible ares. */
584 rect->left = 0;
585 rect->top = 0;
586 rect->width = pic->visible_width;
587 rect->height = pic->visible_height;
588
589 /* config canvas size that be used for decoder. */
590 pic->coded_width = ps->coded_width;
591 pic->coded_height = ps->coded_height;
592 pic->y_len_sz = pic->coded_width * pic->coded_height;
593 pic->c_len_sz = pic->y_len_sz >> 1;
594
ed3dcdaf 595 dec->dpb_sz = ps->dpb_size;
68fcded9
SZ
596
597 inst->parms.ps = *ps;
598 inst->parms.parms_status |=
599 V4L2_CONFIG_PARM_DECODE_PSINFO;
600
601 /*wake up*/
602 complete(&inst->comp);
603
604 v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_PRINFO,
605 "Parse from ucode, crop(%d x %d), coded(%d x %d) dpb: %d\n",
606 ps->visible_width, ps->visible_height,
607 ps->coded_width, ps->coded_height,
608 dec->dpb_sz);
0fb7e163
NQ
609}
610
611static int vdec_mpeg12_set_param(unsigned long h_vdec,
612 enum vdec_set_param_type type, void *in)
613{
614 int ret = 0;
615 struct vdec_mpeg12_inst *inst = (struct vdec_mpeg12_inst *)h_vdec;
616
617 if (!inst) {
b93666f1 618 v4l_dbg(0, V4L_DEBUG_CODEC_ERROR,
4eed6421 619 "the mpeg12 inst of dec is invalid.\n");
0fb7e163
NQ
620 return -1;
621 }
622
623 switch (type) {
68fcded9
SZ
624 case SET_PARAM_WRITE_FRAME_SYNC:
625 set_param_write_sync(inst);
626 break;
8e9fb312
NQ
627 case SET_PARAM_PS_INFO:
628 set_param_ps_info(inst, in);
0fb7e163
NQ
629 break;
630
631 default:
4eed6421
NQ
632 v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_ERROR,
633 "invalid set parameter type=%d\n", type);
0fb7e163
NQ
634 ret = -EINVAL;
635 }
636
637 return ret;
638}
639
640static struct vdec_common_if vdec_mpeg12_if = {
641 .init = vdec_mpeg12_init,
642 .probe = vdec_mpeg12_probe,
643 .decode = vdec_mpeg12_decode,
644 .get_param = vdec_mpeg12_get_param,
645 .set_param = vdec_mpeg12_set_param,
646 .deinit = vdec_mpeg12_deinit,
647};
648
649struct vdec_common_if *get_mpeg12_dec_comm_if(void);
650
651struct vdec_common_if *get_mpeg12_dec_comm_if(void)
652{
653 return &vdec_mpeg12_if;
654}