hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
kernel/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
....@@ -1,16 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * Copyright (c) 2016 MediaTek Inc.
34 * Author: PC Chen <pc.chen@mediatek.com>
45 * Tiffany Lin <tiffany.lin@mediatek.com>
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License version 2 as
8
- * published by the Free Software Foundation.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
146 */
157
168 #include <media/v4l2-event.h>
....@@ -32,21 +24,24 @@
3224 #define DFT_CFG_WIDTH MTK_VDEC_MIN_W
3325 #define DFT_CFG_HEIGHT MTK_VDEC_MIN_H
3426
35
-static struct mtk_video_fmt mtk_video_formats[] = {
27
+static const struct mtk_video_fmt mtk_video_formats[] = {
3628 {
3729 .fourcc = V4L2_PIX_FMT_H264,
3830 .type = MTK_FMT_DEC,
3931 .num_planes = 1,
32
+ .flags = V4L2_FMT_FLAG_DYN_RESOLUTION,
4033 },
4134 {
4235 .fourcc = V4L2_PIX_FMT_VP8,
4336 .type = MTK_FMT_DEC,
4437 .num_planes = 1,
38
+ .flags = V4L2_FMT_FLAG_DYN_RESOLUTION,
4539 },
4640 {
4741 .fourcc = V4L2_PIX_FMT_VP9,
4842 .type = MTK_FMT_DEC,
4943 .num_planes = 1,
44
+ .flags = V4L2_FMT_FLAG_DYN_RESOLUTION,
5045 },
5146 {
5247 .fourcc = V4L2_PIX_FMT_MT21C,
....@@ -76,9 +71,9 @@
7671 #define NUM_SUPPORTED_FRAMESIZE ARRAY_SIZE(mtk_vdec_framesizes)
7772 #define NUM_FORMATS ARRAY_SIZE(mtk_video_formats)
7873
79
-static struct mtk_video_fmt *mtk_vdec_find_format(struct v4l2_format *f)
74
+static const struct mtk_video_fmt *mtk_vdec_find_format(struct v4l2_format *f)
8075 {
81
- struct mtk_video_fmt *fmt;
76
+ const struct mtk_video_fmt *fmt;
8277 unsigned int k;
8378
8479 for (k = 0; k < NUM_FORMATS; k++) {
....@@ -109,6 +104,7 @@
109104 {
110105 struct vdec_fb *disp_frame_buffer = NULL;
111106 struct mtk_video_dec_buf *dstbuf;
107
+ struct vb2_v4l2_buffer *vb;
112108
113109 mtk_v4l2_debug(3, "[%d]", ctx->id);
114110 if (vdec_if_get_param(ctx,
....@@ -126,26 +122,26 @@
126122
127123 dstbuf = container_of(disp_frame_buffer, struct mtk_video_dec_buf,
128124 frame_buffer);
125
+ vb = &dstbuf->m2m_buf.vb;
129126 mutex_lock(&ctx->lock);
130127 if (dstbuf->used) {
131
- vb2_set_plane_payload(&dstbuf->vb.vb2_buf, 0,
132
- ctx->picinfo.y_bs_sz);
133
- vb2_set_plane_payload(&dstbuf->vb.vb2_buf, 1,
134
- ctx->picinfo.c_bs_sz);
135
-
136
- dstbuf->ready_to_display = true;
128
+ vb2_set_plane_payload(&vb->vb2_buf, 0,
129
+ ctx->picinfo.fb_sz[0]);
130
+ if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 2)
131
+ vb2_set_plane_payload(&vb->vb2_buf, 1,
132
+ ctx->picinfo.fb_sz[1]);
137133
138134 mtk_v4l2_debug(2,
139135 "[%d]status=%x queue id=%d to done_list %d",
140136 ctx->id, disp_frame_buffer->status,
141
- dstbuf->vb.vb2_buf.index,
137
+ vb->vb2_buf.index,
142138 dstbuf->queued_in_vb2);
143139
144
- v4l2_m2m_buf_done(&dstbuf->vb, VB2_BUF_STATE_DONE);
140
+ v4l2_m2m_buf_done(vb, VB2_BUF_STATE_DONE);
145141 ctx->decoded_frame_cnt++;
146142 }
147143 mutex_unlock(&ctx->lock);
148
- return &dstbuf->vb.vb2_buf;
144
+ return &vb->vb2_buf;
149145 }
150146
151147 /*
....@@ -160,6 +156,7 @@
160156 {
161157 struct mtk_video_dec_buf *dstbuf;
162158 struct vdec_fb *free_frame_buffer = NULL;
159
+ struct vb2_v4l2_buffer *vb;
163160
164161 if (vdec_if_get_param(ctx,
165162 GET_PARAM_FREE_FRAME_BUFFER,
....@@ -177,6 +174,7 @@
177174
178175 dstbuf = container_of(free_frame_buffer, struct mtk_video_dec_buf,
179176 frame_buffer);
177
+ vb = &dstbuf->m2m_buf.vb;
180178
181179 mutex_lock(&ctx->lock);
182180 if (dstbuf->used) {
....@@ -193,11 +191,10 @@
193191 mtk_v4l2_debug(2,
194192 "[%d]status=%x queue id=%d to rdy_queue %d",
195193 ctx->id, free_frame_buffer->status,
196
- dstbuf->vb.vb2_buf.index,
194
+ vb->vb2_buf.index,
197195 dstbuf->queued_in_vb2);
198
- v4l2_m2m_buf_queue(ctx->m2m_ctx, &dstbuf->vb);
199
- } else if ((dstbuf->queued_in_vb2 == false) &&
200
- (dstbuf->queued_in_v4l2 == true)) {
196
+ v4l2_m2m_buf_queue(ctx->m2m_ctx, vb);
197
+ } else if (!dstbuf->queued_in_vb2 && dstbuf->queued_in_v4l2) {
201198 /*
202199 * If buffer in v4l2 driver but not in vb2 queue yet,
203200 * and we get this buffer from free_list, it means
....@@ -211,8 +208,8 @@
211208 mtk_v4l2_debug(2,
212209 "[%d]status=%x queue id=%d to rdy_queue",
213210 ctx->id, free_frame_buffer->status,
214
- dstbuf->vb.vb2_buf.index);
215
- v4l2_m2m_buf_queue(ctx->m2m_ctx, &dstbuf->vb);
211
+ vb->vb2_buf.index);
212
+ v4l2_m2m_buf_queue(ctx->m2m_ctx, vb);
216213 dstbuf->queued_in_vb2 = true;
217214 } else {
218215 /*
....@@ -225,14 +222,14 @@
225222 */
226223 mtk_v4l2_debug(3, "[%d]status=%x err queue id=%d %d %d",
227224 ctx->id, free_frame_buffer->status,
228
- dstbuf->vb.vb2_buf.index,
225
+ vb->vb2_buf.index,
229226 dstbuf->queued_in_vb2,
230227 dstbuf->queued_in_v4l2);
231228 }
232229 dstbuf->used = false;
233230 }
234231 mutex_unlock(&ctx->lock);
235
- return &dstbuf->vb.vb2_buf;
232
+ return &vb->vb2_buf;
236233 }
237234
238235 static void clean_display_buffer(struct mtk_vcodec_ctx *ctx)
....@@ -278,6 +275,27 @@
278275 clean_free_buffer(ctx);
279276 }
280277
278
+static void mtk_vdec_update_fmt(struct mtk_vcodec_ctx *ctx,
279
+ unsigned int pixelformat)
280
+{
281
+ const struct mtk_video_fmt *fmt;
282
+ struct mtk_q_data *dst_q_data;
283
+ unsigned int k;
284
+
285
+ dst_q_data = &ctx->q_data[MTK_Q_DATA_DST];
286
+ for (k = 0; k < NUM_FORMATS; k++) {
287
+ fmt = &mtk_video_formats[k];
288
+ if (fmt->fourcc == pixelformat) {
289
+ mtk_v4l2_debug(1, "Update cap fourcc(%d -> %d)",
290
+ dst_q_data->fmt->fourcc, pixelformat);
291
+ dst_q_data->fmt = fmt;
292
+ return;
293
+ }
294
+ }
295
+
296
+ mtk_v4l2_err("Cannot get fourcc(%d), using init value", pixelformat);
297
+}
298
+
281299 static int mtk_vdec_pic_info_update(struct mtk_vcodec_ctx *ctx)
282300 {
283301 unsigned int dpbsize = 0;
....@@ -298,6 +316,10 @@
298316 mtk_v4l2_err("Cannot get correct pic info");
299317 return -EINVAL;
300318 }
319
+
320
+ if (ctx->last_decoded_picinfo.cap_fourcc != ctx->picinfo.cap_fourcc &&
321
+ ctx->picinfo.cap_fourcc != 0)
322
+ mtk_vdec_update_fmt(ctx, ctx->picinfo.cap_fourcc);
301323
302324 if ((ctx->last_decoded_picinfo.pic_w == ctx->picinfo.pic_w) ||
303325 (ctx->last_decoded_picinfo.pic_h == ctx->picinfo.pic_h))
....@@ -325,13 +347,12 @@
325347 struct mtk_vcodec_ctx *ctx = container_of(work, struct mtk_vcodec_ctx,
326348 decode_work);
327349 struct mtk_vcodec_dev *dev = ctx->dev;
328
- struct vb2_buffer *src_buf, *dst_buf;
350
+ struct vb2_v4l2_buffer *src_buf, *dst_buf;
329351 struct mtk_vcodec_mem buf;
330352 struct vdec_fb *pfb;
331353 bool res_chg = false;
332354 int ret;
333355 struct mtk_video_dec_buf *dst_buf_info, *src_buf_info;
334
- struct vb2_v4l2_buffer *dst_vb2_v4l2, *src_vb2_v4l2;
335356
336357 src_buf = v4l2_m2m_next_src_buf(ctx->m2m_ctx);
337358 if (src_buf == NULL) {
....@@ -347,26 +368,25 @@
347368 return;
348369 }
349370
350
- src_vb2_v4l2 = container_of(src_buf, struct vb2_v4l2_buffer, vb2_buf);
351
- src_buf_info = container_of(src_vb2_v4l2, struct mtk_video_dec_buf, vb);
352
-
353
- dst_vb2_v4l2 = container_of(dst_buf, struct vb2_v4l2_buffer, vb2_buf);
354
- dst_buf_info = container_of(dst_vb2_v4l2, struct mtk_video_dec_buf, vb);
371
+ src_buf_info = container_of(src_buf, struct mtk_video_dec_buf,
372
+ m2m_buf.vb);
373
+ dst_buf_info = container_of(dst_buf, struct mtk_video_dec_buf,
374
+ m2m_buf.vb);
355375
356376 pfb = &dst_buf_info->frame_buffer;
357
- pfb->base_y.va = vb2_plane_vaddr(dst_buf, 0);
358
- pfb->base_y.dma_addr = vb2_dma_contig_plane_dma_addr(dst_buf, 0);
359
- pfb->base_y.size = ctx->picinfo.y_bs_sz + ctx->picinfo.y_len_sz;
377
+ pfb->base_y.va = vb2_plane_vaddr(&dst_buf->vb2_buf, 0);
378
+ pfb->base_y.dma_addr = vb2_dma_contig_plane_dma_addr(&dst_buf->vb2_buf, 0);
379
+ pfb->base_y.size = ctx->picinfo.fb_sz[0];
360380
361
- pfb->base_c.va = vb2_plane_vaddr(dst_buf, 1);
362
- pfb->base_c.dma_addr = vb2_dma_contig_plane_dma_addr(dst_buf, 1);
363
- pfb->base_c.size = ctx->picinfo.c_bs_sz + ctx->picinfo.c_len_sz;
381
+ pfb->base_c.va = vb2_plane_vaddr(&dst_buf->vb2_buf, 1);
382
+ pfb->base_c.dma_addr = vb2_dma_contig_plane_dma_addr(&dst_buf->vb2_buf, 1);
383
+ pfb->base_c.size = ctx->picinfo.fb_sz[1];
364384 pfb->status = 0;
365385 mtk_v4l2_debug(3, "===>[%d] vdec_if_decode() ===>", ctx->id);
366386
367387 mtk_v4l2_debug(3,
368388 "id=%d Framebuf pfb=%p VA=%p Y_DMA=%pad C_DMA=%pad Size=%zx",
369
- dst_buf->index, pfb,
389
+ dst_buf->vb2_buf.index, pfb,
370390 pfb->base_y.va, &pfb->base_y.dma_addr,
371391 &pfb->base_c.dma_addr, pfb->base_y.size);
372392
....@@ -382,29 +402,28 @@
382402
383403 vdec_if_decode(ctx, NULL, NULL, &res_chg);
384404 clean_display_buffer(ctx);
385
- vb2_set_plane_payload(&dst_buf_info->vb.vb2_buf, 0, 0);
386
- vb2_set_plane_payload(&dst_buf_info->vb.vb2_buf, 1, 0);
387
- dst_vb2_v4l2->flags |= V4L2_BUF_FLAG_LAST;
388
- v4l2_m2m_buf_done(&dst_buf_info->vb, VB2_BUF_STATE_DONE);
405
+ vb2_set_plane_payload(&dst_buf->vb2_buf, 0, 0);
406
+ if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 2)
407
+ vb2_set_plane_payload(&dst_buf->vb2_buf, 1, 0);
408
+ dst_buf->flags |= V4L2_BUF_FLAG_LAST;
409
+ v4l2_m2m_buf_done(dst_buf, VB2_BUF_STATE_DONE);
389410 clean_free_buffer(ctx);
390411 v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx);
391412 return;
392413 }
393
- buf.va = vb2_plane_vaddr(src_buf, 0);
394
- buf.dma_addr = vb2_dma_contig_plane_dma_addr(src_buf, 0);
395
- buf.size = (size_t)src_buf->planes[0].bytesused;
414
+ buf.va = vb2_plane_vaddr(&src_buf->vb2_buf, 0);
415
+ buf.dma_addr = vb2_dma_contig_plane_dma_addr(&src_buf->vb2_buf, 0);
416
+ buf.size = (size_t)src_buf->vb2_buf.planes[0].bytesused;
396417 if (!buf.va) {
397418 v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx);
398419 mtk_v4l2_err("[%d] id=%d src_addr is NULL!!",
399
- ctx->id, src_buf->index);
420
+ ctx->id, src_buf->vb2_buf.index);
400421 return;
401422 }
402423 mtk_v4l2_debug(3, "[%d] Bitstream VA=%p DMA=%pad Size=%zx vb=%p",
403424 ctx->id, buf.va, &buf.dma_addr, buf.size, src_buf);
404
- dst_buf_info->vb.vb2_buf.timestamp
405
- = src_buf_info->vb.vb2_buf.timestamp;
406
- dst_buf_info->vb.timecode
407
- = src_buf_info->vb.timecode;
425
+ dst_buf->vb2_buf.timestamp = src_buf->vb2_buf.timestamp;
426
+ dst_buf->timecode = src_buf->timecode;
408427 mutex_lock(&ctx->lock);
409428 dst_buf_info->used = true;
410429 mutex_unlock(&ctx->lock);
....@@ -416,10 +435,10 @@
416435 mtk_v4l2_err(
417436 " <===[%d], src_buf[%d] sz=0x%zx pts=%llu dst_buf[%d] vdec_if_decode() ret=%d res_chg=%d===>",
418437 ctx->id,
419
- src_buf->index,
438
+ src_buf->vb2_buf.index,
420439 buf.size,
421
- src_buf_info->vb.vb2_buf.timestamp,
422
- dst_buf->index,
440
+ src_buf->vb2_buf.timestamp,
441
+ dst_buf->vb2_buf.index,
423442 ret, res_chg);
424443 src_buf = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
425444 if (ret == -EIO) {
....@@ -427,14 +446,14 @@
427446 src_buf_info->error = true;
428447 mutex_unlock(&ctx->lock);
429448 }
430
- v4l2_m2m_buf_done(&src_buf_info->vb, VB2_BUF_STATE_ERROR);
431
- } else if (res_chg == false) {
449
+ v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_ERROR);
450
+ } else if (!res_chg) {
432451 /*
433452 * we only return src buffer with VB2_BUF_STATE_DONE
434453 * when decode success without resolution change
435454 */
436455 src_buf = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
437
- v4l2_m2m_buf_done(&src_buf_info->vb, VB2_BUF_STATE_DONE);
456
+ v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_DONE);
438457 }
439458
440459 dst_buf = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx);
....@@ -506,7 +525,8 @@
506525 mtk_v4l2_debug(1, "Capture stream is off. No need to flush.");
507526 return 0;
508527 }
509
- v4l2_m2m_buf_queue(ctx->m2m_ctx, &ctx->empty_flush_buf->vb);
528
+ v4l2_m2m_buf_queue(ctx->m2m_ctx,
529
+ &ctx->empty_flush_buf->m2m_buf.vb);
510530 v4l2_m2m_try_schedule(ctx->m2m_ctx);
511531 break;
512532
....@@ -613,9 +633,9 @@
613633 static int vidioc_vdec_querycap(struct file *file, void *priv,
614634 struct v4l2_capability *cap)
615635 {
616
- strlcpy(cap->driver, MTK_VCODEC_DEC_NAME, sizeof(cap->driver));
617
- strlcpy(cap->bus_info, MTK_PLATFORM_STR, sizeof(cap->bus_info));
618
- strlcpy(cap->card, MTK_PLATFORM_STR, sizeof(cap->card));
636
+ strscpy(cap->driver, MTK_VCODEC_DEC_NAME, sizeof(cap->driver));
637
+ strscpy(cap->bus_info, MTK_PLATFORM_STR, sizeof(cap->bus_info));
638
+ strscpy(cap->card, MTK_PLATFORM_STR, sizeof(cap->card));
619639
620640 return 0;
621641 }
....@@ -633,7 +653,8 @@
633653 }
634654 }
635655
636
-static int vidioc_try_fmt(struct v4l2_format *f, struct mtk_video_fmt *fmt)
656
+static int vidioc_try_fmt(struct v4l2_format *f,
657
+ const struct mtk_video_fmt *fmt)
637658 {
638659 struct v4l2_pix_format_mplane *pix_fmt_mp = &f->fmt.pix_mp;
639660 int i;
....@@ -706,7 +727,7 @@
706727 static int vidioc_try_fmt_vid_cap_mplane(struct file *file, void *priv,
707728 struct v4l2_format *f)
708729 {
709
- struct mtk_video_fmt *fmt;
730
+ const struct mtk_video_fmt *fmt;
710731
711732 fmt = mtk_vdec_find_format(f);
712733 if (!fmt) {
....@@ -721,7 +742,7 @@
721742 struct v4l2_format *f)
722743 {
723744 struct v4l2_pix_format_mplane *pix_fmt_mp = &f->fmt.pix_mp;
724
- struct mtk_video_fmt *fmt;
745
+ const struct mtk_video_fmt *fmt;
725746
726747 fmt = mtk_vdec_find_format(f);
727748 if (!fmt) {
....@@ -815,7 +836,7 @@
815836 struct v4l2_pix_format_mplane *pix_mp;
816837 struct mtk_q_data *q_data;
817838 int ret = 0;
818
- struct mtk_video_fmt *fmt;
839
+ const struct mtk_video_fmt *fmt;
819840
820841 mtk_v4l2_debug(3, "[%d]", ctx->id);
821842
....@@ -824,12 +845,20 @@
824845 return -EINVAL;
825846
826847 pix_mp = &f->fmt.pix_mp;
848
+ /*
849
+ * Setting OUTPUT format after OUTPUT buffers are allocated is invalid
850
+ * if using the stateful API.
851
+ */
827852 if ((f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) &&
828853 vb2_is_busy(&ctx->m2m_ctx->out_q_ctx.q)) {
829854 mtk_v4l2_err("out_q_ctx buffers already requested");
830855 ret = -EBUSY;
831856 }
832857
858
+ /*
859
+ * Setting CAPTURE format after CAPTURE buffers are allocated is
860
+ * invalid.
861
+ */
833862 if ((f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) &&
834863 vb2_is_busy(&ctx->m2m_ctx->cap_q_ctx.q)) {
835864 mtk_v4l2_err("cap_q_ctx buffers already requested");
....@@ -848,6 +877,8 @@
848877 fmt = mtk_vdec_find_format(f);
849878 }
850879 }
880
+ if (fmt == NULL)
881
+ return -EINVAL;
851882
852883 q_data->fmt = fmt;
853884 vidioc_try_fmt(f, q_data->fmt);
....@@ -856,10 +887,10 @@
856887 q_data->coded_width = pix_mp->width;
857888 q_data->coded_height = pix_mp->height;
858889
859
- ctx->colorspace = f->fmt.pix_mp.colorspace;
860
- ctx->ycbcr_enc = f->fmt.pix_mp.ycbcr_enc;
861
- ctx->quantization = f->fmt.pix_mp.quantization;
862
- ctx->xfer_func = f->fmt.pix_mp.xfer_func;
890
+ ctx->colorspace = pix_mp->colorspace;
891
+ ctx->ycbcr_enc = pix_mp->ycbcr_enc;
892
+ ctx->quantization = pix_mp->quantization;
893
+ ctx->xfer_func = pix_mp->xfer_func;
863894
864895 if (ctx->state == MTK_STATE_FREE) {
865896 ret = vdec_if_init(ctx, q_data->fmt->fourcc);
....@@ -914,7 +945,7 @@
914945
915946 static int vidioc_enum_fmt(struct v4l2_fmtdesc *f, bool output_queue)
916947 {
917
- struct mtk_video_fmt *fmt;
948
+ const struct mtk_video_fmt *fmt;
918949 int i, j = 0;
919950
920951 for (i = 0; i < NUM_FORMATS; i++) {
....@@ -934,18 +965,19 @@
934965
935966 fmt = &mtk_video_formats[i];
936967 f->pixelformat = fmt->fourcc;
968
+ f->flags = fmt->flags;
937969
938970 return 0;
939971 }
940972
941
-static int vidioc_vdec_enum_fmt_vid_cap_mplane(struct file *file, void *pirv,
942
- struct v4l2_fmtdesc *f)
973
+static int vidioc_vdec_enum_fmt_vid_cap(struct file *file, void *priv,
974
+ struct v4l2_fmtdesc *f)
943975 {
944976 return vidioc_enum_fmt(f, false);
945977 }
946978
947
-static int vidioc_vdec_enum_fmt_vid_out_mplane(struct file *file, void *priv,
948
- struct v4l2_fmtdesc *f)
979
+static int vidioc_vdec_enum_fmt_vid_out(struct file *file, void *priv,
980
+ struct v4l2_fmtdesc *f)
949981 {
950982 return vidioc_enum_fmt(f, true);
951983 }
....@@ -980,14 +1012,13 @@
9801012 * So we just return picinfo yet, and update picinfo in
9811013 * stop_streaming hook function
9821014 */
983
- q_data->sizeimage[0] = ctx->picinfo.y_bs_sz +
984
- ctx->picinfo.y_len_sz;
985
- q_data->sizeimage[1] = ctx->picinfo.c_bs_sz +
986
- ctx->picinfo.c_len_sz;
1015
+ q_data->sizeimage[0] = ctx->picinfo.fb_sz[0];
1016
+ q_data->sizeimage[1] = ctx->picinfo.fb_sz[1];
9871017 q_data->bytesperline[0] = ctx->last_decoded_picinfo.buf_w;
9881018 q_data->bytesperline[1] = ctx->last_decoded_picinfo.buf_w;
9891019 q_data->coded_width = ctx->picinfo.buf_w;
9901020 q_data->coded_height = ctx->picinfo.buf_h;
1021
+ ctx->last_decoded_picinfo.cap_fourcc = q_data->fmt->fourcc;
9911022
9921023 /*
9931024 * Width and height are set to the dimensions
....@@ -1103,14 +1134,15 @@
11031134
11041135 static void vb2ops_vdec_buf_queue(struct vb2_buffer *vb)
11051136 {
1106
- struct vb2_buffer *src_buf;
1137
+ struct vb2_v4l2_buffer *src_buf;
11071138 struct mtk_vcodec_mem src_mem;
11081139 bool res_chg = false;
11091140 int ret = 0;
1110
- unsigned int dpbsize = 1;
1141
+ unsigned int dpbsize = 1, i = 0;
11111142 struct mtk_vcodec_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
11121143 struct vb2_v4l2_buffer *vb2_v4l2 = NULL;
11131144 struct mtk_video_dec_buf *buf = NULL;
1145
+ struct mtk_q_data *dst_q_data;
11141146
11151147 mtk_v4l2_debug(3, "[%d] (%d) id=%d, vb=%p",
11161148 ctx->id, vb->vb2_queue->type,
....@@ -1120,17 +1152,16 @@
11201152 */
11211153 if (vb->vb2_queue->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
11221154 vb2_v4l2 = to_vb2_v4l2_buffer(vb);
1123
- buf = container_of(vb2_v4l2, struct mtk_video_dec_buf, vb);
1155
+ buf = container_of(vb2_v4l2, struct mtk_video_dec_buf,
1156
+ m2m_buf.vb);
11241157 mutex_lock(&ctx->lock);
1125
- if (buf->used == false) {
1158
+ if (!buf->used) {
11261159 v4l2_m2m_buf_queue(ctx->m2m_ctx, vb2_v4l2);
11271160 buf->queued_in_vb2 = true;
11281161 buf->queued_in_v4l2 = true;
1129
- buf->ready_to_display = false;
11301162 } else {
11311163 buf->queued_in_vb2 = false;
11321164 buf->queued_in_v4l2 = true;
1133
- buf->ready_to_display = false;
11341165 }
11351166 mutex_unlock(&ctx->lock);
11361167 return;
....@@ -1149,8 +1180,7 @@
11491180 mtk_v4l2_err("No src buffer");
11501181 return;
11511182 }
1152
- vb2_v4l2 = to_vb2_v4l2_buffer(src_buf);
1153
- buf = container_of(vb2_v4l2, struct mtk_video_dec_buf, vb);
1183
+ buf = container_of(src_buf, struct mtk_video_dec_buf, m2m_buf.vb);
11541184 if (buf->lastframe) {
11551185 /* This shouldn't happen. Just in case. */
11561186 mtk_v4l2_err("Invalid flush buffer.");
....@@ -1158,19 +1188,19 @@
11581188 return;
11591189 }
11601190
1161
- src_mem.va = vb2_plane_vaddr(src_buf, 0);
1162
- src_mem.dma_addr = vb2_dma_contig_plane_dma_addr(src_buf, 0);
1163
- src_mem.size = (size_t)src_buf->planes[0].bytesused;
1191
+ src_mem.va = vb2_plane_vaddr(&src_buf->vb2_buf, 0);
1192
+ src_mem.dma_addr = vb2_dma_contig_plane_dma_addr(&src_buf->vb2_buf, 0);
1193
+ src_mem.size = (size_t)src_buf->vb2_buf.planes[0].bytesused;
11641194 mtk_v4l2_debug(2,
11651195 "[%d] buf id=%d va=%p dma=%pad size=%zx",
1166
- ctx->id, src_buf->index,
1196
+ ctx->id, src_buf->vb2_buf.index,
11671197 src_mem.va, &src_mem.dma_addr,
11681198 src_mem.size);
11691199
11701200 ret = vdec_if_decode(ctx, &src_mem, NULL, &res_chg);
11711201 if (ret || !res_chg) {
11721202 /*
1173
- * fb == NULL menas to parse SPS/PPS header or
1203
+ * fb == NULL means to parse SPS/PPS header or
11741204 * resolution info in src_mem. Decode can fail
11751205 * if there is no SPS header or picture info
11761206 * in bs
....@@ -1181,15 +1211,13 @@
11811211 mtk_v4l2_err("[%d] Unrecoverable error in vdec_if_decode.",
11821212 ctx->id);
11831213 ctx->state = MTK_STATE_ABORT;
1184
- v4l2_m2m_buf_done(to_vb2_v4l2_buffer(src_buf),
1185
- VB2_BUF_STATE_ERROR);
1214
+ v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_ERROR);
11861215 } else {
1187
- v4l2_m2m_buf_done(to_vb2_v4l2_buffer(src_buf),
1188
- VB2_BUF_STATE_DONE);
1216
+ v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_DONE);
11891217 }
11901218 mtk_v4l2_debug(ret ? 0 : 1,
11911219 "[%d] vdec_if_decode() src_buf=%d, size=%zu, fail=%d, res_chg=%d",
1192
- ctx->id, src_buf->index,
1220
+ ctx->id, src_buf->vb2_buf.index,
11931221 src_mem.size, ret, res_chg);
11941222 return;
11951223 }
....@@ -1201,21 +1229,18 @@
12011229 }
12021230
12031231 ctx->last_decoded_picinfo = ctx->picinfo;
1204
- ctx->q_data[MTK_Q_DATA_DST].sizeimage[0] =
1205
- ctx->picinfo.y_bs_sz +
1206
- ctx->picinfo.y_len_sz;
1207
- ctx->q_data[MTK_Q_DATA_DST].bytesperline[0] =
1208
- ctx->picinfo.buf_w;
1209
- ctx->q_data[MTK_Q_DATA_DST].sizeimage[1] =
1210
- ctx->picinfo.c_bs_sz +
1211
- ctx->picinfo.c_len_sz;
1212
- ctx->q_data[MTK_Q_DATA_DST].bytesperline[1] = ctx->picinfo.buf_w;
1232
+ dst_q_data = &ctx->q_data[MTK_Q_DATA_DST];
1233
+ for (i = 0; i < dst_q_data->fmt->num_planes; i++) {
1234
+ dst_q_data->sizeimage[i] = ctx->picinfo.fb_sz[i];
1235
+ dst_q_data->bytesperline[i] = ctx->picinfo.buf_w;
1236
+ }
1237
+
12131238 mtk_v4l2_debug(2, "[%d] vdec_if_init() OK wxh=%dx%d pic wxh=%dx%d sz[0]=0x%x sz[1]=0x%x",
12141239 ctx->id,
12151240 ctx->picinfo.buf_w, ctx->picinfo.buf_h,
12161241 ctx->picinfo.pic_w, ctx->picinfo.pic_h,
1217
- ctx->q_data[MTK_Q_DATA_DST].sizeimage[0],
1218
- ctx->q_data[MTK_Q_DATA_DST].sizeimage[1]);
1242
+ dst_q_data->sizeimage[0],
1243
+ dst_q_data->sizeimage[1]);
12191244
12201245 ret = vdec_if_get_param(ctx, GET_PARAM_DPB_SIZE, &dpbsize);
12211246 if (dpbsize == 0)
....@@ -1236,7 +1261,7 @@
12361261 bool buf_error;
12371262
12381263 vb2_v4l2 = container_of(vb, struct vb2_v4l2_buffer, vb2_buf);
1239
- buf = container_of(vb2_v4l2, struct mtk_video_dec_buf, vb);
1264
+ buf = container_of(vb2_v4l2, struct mtk_video_dec_buf, m2m_buf.vb);
12401265 mutex_lock(&ctx->lock);
12411266 if (vb->vb2_queue->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
12421267 buf->queued_in_v4l2 = false;
....@@ -1256,11 +1281,10 @@
12561281 struct vb2_v4l2_buffer *vb2_v4l2 = container_of(vb,
12571282 struct vb2_v4l2_buffer, vb2_buf);
12581283 struct mtk_video_dec_buf *buf = container_of(vb2_v4l2,
1259
- struct mtk_video_dec_buf, vb);
1284
+ struct mtk_video_dec_buf, m2m_buf.vb);
12601285
12611286 if (vb->vb2_queue->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
12621287 buf->used = false;
1263
- buf->ready_to_display = false;
12641288 buf->queued_in_v4l2 = false;
12651289 } else {
12661290 buf->lastframe = false;
....@@ -1281,7 +1305,7 @@
12811305
12821306 static void vb2ops_vdec_stop_streaming(struct vb2_queue *q)
12831307 {
1284
- struct vb2_buffer *src_buf = NULL, *dst_buf = NULL;
1308
+ struct vb2_v4l2_buffer *src_buf = NULL, *dst_buf = NULL;
12851309 struct mtk_vcodec_ctx *ctx = vb2_get_drv_priv(q);
12861310
12871311 mtk_v4l2_debug(3, "[%d] (%d) state=(%x) ctx->decoded_frame_cnt=%d",
....@@ -1289,12 +1313,10 @@
12891313
12901314 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
12911315 while ((src_buf = v4l2_m2m_src_buf_remove(ctx->m2m_ctx))) {
1292
- struct vb2_v4l2_buffer *vb2_v4l2 =
1293
- to_vb2_v4l2_buffer(src_buf);
12941316 struct mtk_video_dec_buf *buf_info = container_of(
1295
- vb2_v4l2, struct mtk_video_dec_buf, vb);
1317
+ src_buf, struct mtk_video_dec_buf, m2m_buf.vb);
12961318 if (!buf_info->lastframe)
1297
- v4l2_m2m_buf_done(vb2_v4l2,
1319
+ v4l2_m2m_buf_done(src_buf,
12981320 VB2_BUF_STATE_ERROR);
12991321 }
13001322 return;
....@@ -1323,10 +1345,10 @@
13231345 ctx->state = MTK_STATE_FLUSH;
13241346
13251347 while ((dst_buf = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx))) {
1326
- vb2_set_plane_payload(dst_buf, 0, 0);
1327
- vb2_set_plane_payload(dst_buf, 1, 0);
1328
- v4l2_m2m_buf_done(to_vb2_v4l2_buffer(dst_buf),
1329
- VB2_BUF_STATE_ERROR);
1348
+ vb2_set_plane_payload(&dst_buf->vb2_buf, 0, 0);
1349
+ if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 2)
1350
+ vb2_set_plane_payload(&dst_buf->vb2_buf, 1, 0);
1351
+ v4l2_m2m_buf_done(dst_buf, VB2_BUF_STATE_ERROR);
13301352 }
13311353
13321354 }
....@@ -1454,8 +1476,8 @@
14541476
14551477 .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs,
14561478
1457
- .vidioc_enum_fmt_vid_cap_mplane = vidioc_vdec_enum_fmt_vid_cap_mplane,
1458
- .vidioc_enum_fmt_vid_out_mplane = vidioc_vdec_enum_fmt_vid_out_mplane,
1479
+ .vidioc_enum_fmt_vid_cap = vidioc_vdec_enum_fmt_vid_cap,
1480
+ .vidioc_enum_fmt_vid_out = vidioc_vdec_enum_fmt_vid_out,
14591481 .vidioc_enum_framesizes = vidioc_enum_framesizes,
14601482
14611483 .vidioc_querycap = vidioc_vdec_querycap,
....@@ -1502,10 +1524,8 @@
15021524 dst_vq->dev = &ctx->dev->plat_dev->dev;
15031525
15041526 ret = vb2_queue_init(dst_vq);
1505
- if (ret) {
1506
- vb2_queue_release(src_vq);
1527
+ if (ret)
15071528 mtk_v4l2_err("Failed to initialize videobuf2 queue(capture)");
1508
- }
15091529
15101530 return ret;
15111531 }