From patchwork Fri Mar 1 13:24:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 10835311 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6792C1880 for ; Fri, 1 Mar 2019 13:24:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 56B1B2EE31 for ; Fri, 1 Mar 2019 13:24:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4B0602EE4A; Fri, 1 Mar 2019 13:24:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 93C332EE31 for ; Fri, 1 Mar 2019 13:24:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387578AbfCANYb (ORCPT ); Fri, 1 Mar 2019 08:24:31 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:50508 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727052AbfCANYa (ORCPT ); Fri, 1 Mar 2019 08:24:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=aoUbFgYWIgUF7eB8YKn8uiGH24UX8J/20ex9NVexCc4=; b=lnqrMiqK6Ib2bjEwPgBT+aUS7f Za/qdxLY2aRBQVuUmtGW57DtUNJEY0cPSAVlc8CAL+tvfvZDNoL+FNXU0Yh+IZqqtbs4ejD6Txrbf 2aMDqRFat9YmYuy+Xh6+a1lVuPf/kHVul/MLemWMjrs5Jxubjr8QNNo0zwI8OEED8OfUMoqJ2nvvC wDWQbN+UgqPA1HhFx0H3SUyOwwjDGOOpTVgLOkFw2NYKFPCiqvgmDBJbDJwDIhKAUQH3Ii1KTR3cG D2IZvmcfUpuTc484gnH71FgzopHs7VIUdbtFinMXzf+Eb5qWWoOD/pTwfOzqp+LGSnPDuvSsJKy8u cApyjiQQ==; Received: from 177.41.113.159.dynamic.adsl.gvt.net.br ([177.41.113.159] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gzi9N-0003xw-Qy; Fri, 01 Mar 2019 13:24:29 +0000 Received: from mchehab by bombadil.infradead.org with local (Exim 4.92) (envelope-from ) id 1gzi9L-0002N3-O5; Fri, 01 Mar 2019 10:24:27 -0300 From: Mauro Carvalho Chehab To: Linux Media Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , Hans Verkuil , Ezequiel Garcia Subject: [PATCH 01/10] media: vim2m: add bayer capture formats Date: Fri, 1 Mar 2019 10:24:17 -0300 Message-Id: <06f1340a1d2e03f5500b160c80845e0867a0d8d0.1551446121.git.mchehab+samsung@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The vim2m device is interesting to simulate a webcam. As most sensors are arranged using bayer formats, the best is to support to output data using those formats. So, add support for them. All 4 8-bit bayer formats tested with: $ qvidcap -p & $ v4l2-ctl --stream-mmap --stream-out-mmap --stream-to-host localhost --stream-lossless --stream-out-hor-speed 1 -v pixelformat=RGGB It was tested also with GStreamer with: $ gst-validate-1.0 filesrc location=some_video.mp4 ! qtdemux ! avdec_h264 ! videoconvert ! videoscale ! v4l2convert disable-passthrough=1 extra-controls="s,horizontal_flip=0,vertical_flip=0" ! bayer2rgb ! videoconvert ! xvimagesink For all possible HFLIP/VFLIP values. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/platform/vim2m.c | 102 ++++++++++++++++++++++++++++++--- 1 file changed, 95 insertions(+), 7 deletions(-) diff --git a/drivers/media/platform/vim2m.c b/drivers/media/platform/vim2m.c index a27d3052bb62..d95a905bdfc5 100644 --- a/drivers/media/platform/vim2m.c +++ b/drivers/media/platform/vim2m.c @@ -82,24 +82,47 @@ static struct platform_device vim2m_pdev = { struct vim2m_fmt { u32 fourcc; int depth; + /* Types the format can be used for */ + u32 types; }; static struct vim2m_fmt formats[] = { { .fourcc = V4L2_PIX_FMT_RGB565, /* rrrrrggg gggbbbbb */ .depth = 16, + .types = MEM2MEM_CAPTURE | MEM2MEM_OUTPUT, }, { .fourcc = V4L2_PIX_FMT_RGB565X, /* gggbbbbb rrrrrggg */ .depth = 16, + .types = MEM2MEM_CAPTURE | MEM2MEM_OUTPUT, }, { .fourcc = V4L2_PIX_FMT_RGB24, .depth = 24, + .types = MEM2MEM_CAPTURE | MEM2MEM_OUTPUT, }, { .fourcc = V4L2_PIX_FMT_BGR24, .depth = 24, + .types = MEM2MEM_CAPTURE | MEM2MEM_OUTPUT, }, { .fourcc = V4L2_PIX_FMT_YUYV, .depth = 16, + .types = MEM2MEM_CAPTURE | MEM2MEM_OUTPUT, + }, { + .fourcc = V4L2_PIX_FMT_SBGGR8, + .depth = 8, + .types = MEM2MEM_CAPTURE, + }, { + .fourcc = V4L2_PIX_FMT_SGBRG8, + .depth = 8, + .types = MEM2MEM_CAPTURE, + }, { + .fourcc = V4L2_PIX_FMT_SGRBG8, + .depth = 8, + .types = MEM2MEM_CAPTURE, + }, { + .fourcc = V4L2_PIX_FMT_SRGGB8, + .depth = 8, + .types = MEM2MEM_CAPTURE, }, }; @@ -208,7 +231,7 @@ static struct vim2m_q_data *get_q_data(struct vim2m_ctx *ctx, (u8)(((__color) > 0xff) ? 0xff : (((__color) < 0) ? 0 : (__color))) static void copy_two_pixels(struct vim2m_fmt *in, struct vim2m_fmt *out, - u8 **src, u8 **dst, bool reverse) + u8 **src, u8 **dst, int ypos, bool reverse) { u8 _r[2], _g[2], _b[2], *r, *g, *b; int i, step; @@ -379,7 +402,8 @@ static void copy_two_pixels(struct vim2m_fmt *in, struct vim2m_fmt *out, *(*dst)++ = *r++; } return; - default: /* V4L2_PIX_FMT_YUYV */ + case V4L2_PIX_FMT_YUYV: + default: { u8 y, y1, u, v; @@ -399,6 +423,42 @@ static void copy_two_pixels(struct vim2m_fmt *in, struct vim2m_fmt *out, *(*dst)++ = v; return; } + case V4L2_PIX_FMT_SBGGR8: + if (!(ypos & 1)) { + *(*dst)++ = *b; + *(*dst)++ = *++g; + } else { + *(*dst)++ = *g; + *(*dst)++ = *++r; + } + return; + case V4L2_PIX_FMT_SGBRG8: + if (!(ypos & 1)) { + *(*dst)++ = *g; + *(*dst)++ = *++b; + } else { + *(*dst)++ = *r; + *(*dst)++ = *++g; + } + return; + case V4L2_PIX_FMT_SGRBG8: + if (!(ypos & 1)) { + *(*dst)++ = *g; + *(*dst)++ = *++r; + } else { + *(*dst)++ = *b; + *(*dst)++ = *++g; + } + return; + case V4L2_PIX_FMT_SRGGB8: + if (!(ypos & 1)) { + *(*dst)++ = *r; + *(*dst)++ = *++g; + } else { + *(*dst)++ = *g; + *(*dst)++ = *++b; + } + return; } } @@ -409,7 +469,7 @@ static int device_process(struct vim2m_ctx *ctx, struct vim2m_dev *dev = ctx->dev; struct vim2m_q_data *q_data_in, *q_data_out; u8 *p_in, *p, *p_out; - int width, height, bytesperline, x, y, start, end, step; + int width, height, bytesperline, x, y, y_out, start, end, step; struct vim2m_fmt *in, *out; q_data_in = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); @@ -443,13 +503,14 @@ static int device_process(struct vim2m_ctx *ctx, end = height; step = 1; } - for (y = start; y != end; y += step) { + y_out = 0; + for (y = start; y != end; y += step, y_out++) { p = p_in + (y * bytesperline); if (ctx->mode & MEM2MEM_HFLIP) p += bytesperline - (q_data_in->fmt->depth >> 3); for (x = 0; x < width >> 1; x++) - copy_two_pixels(in, out, &p, &p_out, + copy_two_pixels(in, out, &p, &p_out, y_out, ctx->mode & MEM2MEM_HFLIP); } @@ -563,11 +624,25 @@ static int vidioc_querycap(struct file *file, void *priv, static int enum_fmt(struct v4l2_fmtdesc *f, u32 type) { + int i, num; struct vim2m_fmt *fmt; - if (f->index < NUM_FORMATS) { + num = 0; + + for (i = 0; i < NUM_FORMATS; ++i) { + if (formats[i].types & type) { + /* index-th format of type type found ? */ + if (num == f->index) + break; + /* Correct type but haven't reached our index yet, + * just increment per-type index */ + ++num; + } + } + + if (i < NUM_FORMATS) { /* Format found */ - fmt = &formats[f->index]; + fmt = &formats[i]; f->pixelformat = fmt->fourcc; return 0; } @@ -658,6 +733,12 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, f->fmt.pix.pixelformat = formats[0].fourcc; fmt = find_format(f); } + if (!(fmt->types & MEM2MEM_CAPTURE)) { + v4l2_err(&ctx->dev->v4l2_dev, + "Fourcc format (0x%08x) invalid.\n", + f->fmt.pix.pixelformat); + return -EINVAL; + } f->fmt.pix.colorspace = ctx->colorspace; f->fmt.pix.xfer_func = ctx->xfer_func; f->fmt.pix.ycbcr_enc = ctx->ycbcr_enc; @@ -670,12 +751,19 @@ static int vidioc_try_fmt_vid_out(struct file *file, void *priv, struct v4l2_format *f) { struct vim2m_fmt *fmt; + struct vim2m_ctx *ctx = file2ctx(file); fmt = find_format(f); if (!fmt) { f->fmt.pix.pixelformat = formats[0].fourcc; fmt = find_format(f); } + if (!(fmt->types & MEM2MEM_OUTPUT)) { + v4l2_err(&ctx->dev->v4l2_dev, + "Fourcc format (0x%08x) invalid.\n", + f->fmt.pix.pixelformat); + return -EINVAL; + } if (!f->fmt.pix.colorspace) f->fmt.pix.colorspace = V4L2_COLORSPACE_REC709; From patchwork Fri Mar 1 13:24:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 10835329 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 505FB1880 for ; Fri, 1 Mar 2019 13:24:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DF712DD97 for ; Fri, 1 Mar 2019 13:24:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 31FAE2EE30; Fri, 1 Mar 2019 13:24:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8D892EE41 for ; Fri, 1 Mar 2019 13:24:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387632AbfCANYh (ORCPT ); Fri, 1 Mar 2019 08:24:37 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:50514 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728243AbfCANYa (ORCPT ); Fri, 1 Mar 2019 08:24:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=tRA8AkkG0iuLBuq01lOc3rbEsef0pSN2qI3B6m0cxCg=; b=cNTAawoh6ok+G/chwlb/1LLM1l awvHXGJy6Ci5pAK1nrJvgYMgDGrQjnAFzjoRQ4hcCzb1Jp6GnzOlU0gLPu/bt2rh8mpGmlMeKbVhP +g1WncDdsbQ0qCwfhgrTWRfQFZjfzYKsvb1udKUvuu3ZkrOG5edox7pFeJJl+ID8GugusfTECdstZ O1g3nOc5RpQe4syldYxdKxJSXw7Jdu5Hu9lLJHvsLTE54FhFfsy2Il8WchdqevgwVM8KZi6DadOkN yF6YWgfAsVxGnBWzl+wTW8Tkyy+3uQ6xJ+EnBhJD4VRYpET+mpQg9ZCYcgtlkXBt/AdWKK6T1uTKO hwk2YlHg==; Received: from 177.41.113.159.dynamic.adsl.gvt.net.br ([177.41.113.159] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gzi9N-0003xx-Rf; Fri, 01 Mar 2019 13:24:29 +0000 Received: from mchehab by bombadil.infradead.org with local (Exim 4.92) (envelope-from ) id 1gzi9L-0002N8-Ow; Fri, 01 Mar 2019 10:24:27 -0300 From: Mauro Carvalho Chehab To: Linux Media Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , Hans Verkuil , Ezequiel Garcia Subject: [PATCH 02/10] media: vim2m: improve debug messages Date: Fri, 1 Mar 2019 10:24:18 -0300 Message-Id: <45274f421cd11059d008c8229c7f4e17751c0a4f.1551446121.git.mchehab+samsung@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 1) Use two levels for debug: - level 1: setup stuff - level 2: add queue/dequeue messages 2) Better display the debug output, translating buffer type, fourcc and making some messages clearer. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/platform/vim2m.c | 46 +++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/drivers/media/platform/vim2m.c b/drivers/media/platform/vim2m.c index d95a905bdfc5..17d40cec2d95 100644 --- a/drivers/media/platform/vim2m.c +++ b/drivers/media/platform/vim2m.c @@ -39,7 +39,7 @@ MODULE_ALIAS("mem2mem_testdev"); static unsigned debug; module_param(debug, uint, 0644); -MODULE_PARM_DESC(debug, "activates debug info"); +MODULE_PARM_DESC(debug, "debug level"); /* Default transaction time in msec */ static unsigned int default_transtime = 40; /* Max 25 fps */ @@ -67,8 +67,8 @@ MODULE_PARM_DESC(default_transtime, "default transaction time in ms"); #define MEM2MEM_HFLIP (1 << 0) #define MEM2MEM_VFLIP (1 << 1) -#define dprintk(dev, fmt, arg...) \ - v4l2_dbg(1, debug, &dev->v4l2_dev, "%s: " fmt, __func__, ## arg) +#define dprintk(dev, lvl, fmt, arg...) \ + v4l2_dbg(lvl, debug, &dev->v4l2_dev, "%s: " fmt, __func__, ## arg) static void vim2m_dev_release(struct device *dev) @@ -227,6 +227,18 @@ static struct vim2m_q_data *get_q_data(struct vim2m_ctx *ctx, return NULL; } +static const char *type_name(enum v4l2_buf_type type) +{ + switch (type) { + case V4L2_BUF_TYPE_VIDEO_OUTPUT: + return "Output"; + case V4L2_BUF_TYPE_VIDEO_CAPTURE: + return "Capture"; + default: + return "Invalid"; + } +} + #define CLIP(__color) \ (u8)(((__color) > 0xff) ? 0xff : (((__color) < 0) ? 0 : (__color))) @@ -530,7 +542,7 @@ static int job_ready(void *priv) if (v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) < ctx->translen || v4l2_m2m_num_dst_bufs_ready(ctx->fh.m2m_ctx) < ctx->translen) { - dprintk(ctx->dev, "Not enough buffers available\n"); + dprintk(ctx->dev, 1, "Not enough buffers available\n"); return 0; } @@ -601,7 +613,7 @@ static void device_work(struct work_struct *w) if (curr_ctx->num_processed == curr_ctx->translen || curr_ctx->aborting) { - dprintk(curr_ctx->dev, "Finishing transaction\n"); + dprintk(curr_ctx->dev, 2, "Finishing capture buffer fill\n"); curr_ctx->num_processed = 0; v4l2_m2m_job_finish(vim2m_dev->m2m_dev, curr_ctx->fh.m2m_ctx); } else { @@ -794,9 +806,14 @@ static int vidioc_s_fmt(struct vim2m_ctx *ctx, struct v4l2_format *f) q_data->sizeimage = q_data->width * q_data->height * q_data->fmt->depth >> 3; - dprintk(ctx->dev, - "Setting format for type %d, wxh: %dx%d, fmt: %d\n", - f->type, q_data->width, q_data->height, q_data->fmt->fourcc); + dprintk(ctx->dev, 1, + "Format for type %s: %dx%d (%d bpp), fmt: %c%c%c%c\n", + type_name(f->type), q_data->width, q_data->height, + q_data->fmt->depth, + (q_data->fmt->fourcc & 0xff), + (q_data->fmt->fourcc >> 8) & 0xff, + (q_data->fmt->fourcc >> 16) & 0xff, + (q_data->fmt->fourcc >> 24) & 0xff); return 0; } @@ -931,7 +948,8 @@ static int vim2m_queue_setup(struct vb2_queue *vq, *nplanes = 1; sizes[0] = size; - dprintk(ctx->dev, "get %d buffer(s) of size %d each.\n", count, size); + dprintk(ctx->dev, 1, "%s: get %d buffer(s) of size %d each.\n", + type_name(vq->type), count, size); return 0; } @@ -944,7 +962,7 @@ static int vim2m_buf_out_validate(struct vb2_buffer *vb) if (vbuf->field == V4L2_FIELD_ANY) vbuf->field = V4L2_FIELD_NONE; if (vbuf->field != V4L2_FIELD_NONE) { - dprintk(ctx->dev, "%s field isn't supported\n", __func__); + dprintk(ctx->dev, 1, "%s field isn't supported\n", __func__); return -EINVAL; } @@ -956,11 +974,11 @@ static int vim2m_buf_prepare(struct vb2_buffer *vb) struct vim2m_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); struct vim2m_q_data *q_data; - dprintk(ctx->dev, "type: %d\n", vb->vb2_queue->type); + dprintk(ctx->dev, 2, "type: %s\n", type_name(vb->vb2_queue->type)); q_data = get_q_data(ctx, vb->vb2_queue->type); if (vb2_plane_size(vb, 0) < q_data->sizeimage) { - dprintk(ctx->dev, "%s data will not fit into plane (%lu < %lu)\n", + dprintk(ctx->dev, 1, "%s data will not fit into plane (%lu < %lu)\n", __func__, vb2_plane_size(vb, 0), (long)q_data->sizeimage); return -EINVAL; } @@ -1147,7 +1165,7 @@ static int vim2m_open(struct file *file) v4l2_fh_add(&ctx->fh); atomic_inc(&dev->num_inst); - dprintk(dev, "Created instance: %p, m2m_ctx: %p\n", + dprintk(dev, 1, "Created instance: %p, m2m_ctx: %p\n", ctx, ctx->fh.m2m_ctx); open_unlock: @@ -1160,7 +1178,7 @@ static int vim2m_release(struct file *file) struct vim2m_dev *dev = video_drvdata(file); struct vim2m_ctx *ctx = file2ctx(file); - dprintk(dev, "Releasing instance %p\n", ctx); + dprintk(dev, 1, "Releasing instance %p\n", ctx); v4l2_fh_del(&ctx->fh); v4l2_fh_exit(&ctx->fh); From patchwork Fri Mar 1 13:24:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 10835323 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A89B31390 for ; Fri, 1 Mar 2019 13:24:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9798E2DD97 for ; Fri, 1 Mar 2019 13:24:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C3532EE31; Fri, 1 Mar 2019 13:24:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 38A502DD97 for ; Fri, 1 Mar 2019 13:24:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387569AbfCANYb (ORCPT ); Fri, 1 Mar 2019 08:24:31 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:50518 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728259AbfCANYa (ORCPT ); Fri, 1 Mar 2019 08:24:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=xh22J4XA+hjblSGFGgRDqvYC0M0Uy/7E1aW07Lwqh1s=; b=cwib5UptaN11AONipJCEFyCasm XdwKP/T4V3XVJj97HX6fyT/nUwmd7rHZpgJXd74DQLmJOx/wW/cqF4hgAc5+vDs5FxPYnBPm6khMW MJ8xMDd1SYBuVlpXmSTCZJ6MrPE1+G8MAN1mCNp58jHnJjz2dTETimv7R9n6P1rl+wHPecUBDt7sK WCDjIRepNG1w8NgTVQSkaiqVP6Jv0rcNKq/DejApQxsBfADmiDHcmUpdx1+3w+IDytECKzU9pVulD yaQYe5svCzhnZ5C8ZSqRTSwUuY0n4CyGd7mxKHqYz0xDLdTptTWCJRsk6ETJGlUSHX0CSvNd5uwy8 52Gu+kpA==; Received: from 177.41.113.159.dynamic.adsl.gvt.net.br ([177.41.113.159] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gzi9N-0003xy-SX; Fri, 01 Mar 2019 13:24:29 +0000 Received: from mchehab by bombadil.infradead.org with local (Exim 4.92) (envelope-from ) id 1gzi9L-0002ND-Pl; Fri, 01 Mar 2019 10:24:27 -0300 From: Mauro Carvalho Chehab To: Linux Media Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , Hans Verkuil , Ezequiel Garcia Subject: [PATCH 03/10] media: vim2m: ensure that width is multiple of two Date: Fri, 1 Mar 2019 10:24:19 -0300 Message-Id: <6786af5ad640e0e7caace2168e8a24323434f382.1551446121.git.mchehab+samsung@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The copy logic assumes that the data width is multiple of two, as this is needed in order to support YUYV. There's no reason to force it to be 8-pixel aligned, as 2-pixel alignment is enough. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/platform/vim2m.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/platform/vim2m.c b/drivers/media/platform/vim2m.c index 17d40cec2d95..fb736356ee6b 100644 --- a/drivers/media/platform/vim2m.c +++ b/drivers/media/platform/vim2m.c @@ -50,7 +50,7 @@ MODULE_PARM_DESC(default_transtime, "default transaction time in ms"); #define MIN_H 32 #define MAX_W 640 #define MAX_H 480 -#define DIM_ALIGN_MASK 7 /* 8-byte alignment for line length */ +#define DIM_ALIGN_MASK 1 /* 2-byte alignment */ /* Flags that indicate a format can be used for capture/output */ #define MEM2MEM_CAPTURE (1 << 0) From patchwork Fri Mar 1 13:24:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 10835309 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EB1761575 for ; Fri, 1 Mar 2019 13:24:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D597E2DD97 for ; Fri, 1 Mar 2019 13:24:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C730F2EE4A; Fri, 1 Mar 2019 13:24:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 41A612DD97 for ; Fri, 1 Mar 2019 13:24:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387575AbfCANYb (ORCPT ); Fri, 1 Mar 2019 08:24:31 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:50520 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728296AbfCANYa (ORCPT ); Fri, 1 Mar 2019 08:24:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=2oOf3LXlE7pTjNSawPk9D91Kk3ECJHCRMuRpc8Q8lu8=; b=P4oaKRcIb0xBF8ekI1e71/Pcqm NvbIwJRgkRxa3JTx/mmJe7DwTqywCG+/sP81TFD4kXKMU3lyrEfxnQgw8SZkyzTGfz9PKSbQK5cXA ItTZ9EpxN4WvDVLCUXRfNM9B6f2cAS7z/nX0rIffZw7x0c4K898ccDmCDQeAbKlYPHxrU///QBQaB JQcBjzacKN27mopDp7T6A3usPYj/a3VRszmnU/hfUUbP7KV2+D4N7xYhw8Z/l3qFDNrOxYjYmPYkU iN2Qx5CkxlIym0fRm1g6hG9javDXqszlPmqVTQOAsDZi3TCUZmIDPxxmwxC/qX7EPNwcrJIND1wA7 mypi3PUg==; Received: from 177.41.113.159.dynamic.adsl.gvt.net.br ([177.41.113.159] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gzi9N-0003xz-Sd; Fri, 01 Mar 2019 13:24:29 +0000 Received: from mchehab by bombadil.infradead.org with local (Exim 4.92) (envelope-from ) id 1gzi9L-0002NI-Qb; Fri, 01 Mar 2019 10:24:27 -0300 From: Mauro Carvalho Chehab To: Linux Media Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , Hans Verkuil , Ezequiel Garcia Subject: [PATCH 04/10] media: vim2m: add support for VIDIOC_ENUM_FRAMESIZES Date: Fri, 1 Mar 2019 10:24:20 -0300 Message-Id: <23f04fcc0b8b7a8388ac41ecb1422053190ed1ba.1551446121.git.mchehab+samsung@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP As we do alignments for width, expose it via V4L2 API. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/platform/vim2m.c | 38 ++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/drivers/media/platform/vim2m.c b/drivers/media/platform/vim2m.c index fb736356ee6b..bac9d4733d65 100644 --- a/drivers/media/platform/vim2m.c +++ b/drivers/media/platform/vim2m.c @@ -50,7 +50,7 @@ MODULE_PARM_DESC(default_transtime, "default transaction time in ms"); #define MIN_H 32 #define MAX_W 640 #define MAX_H 480 -#define DIM_ALIGN_MASK 1 /* 2-byte alignment */ +#define WIDTH_ALIGN 2 /* 2-byte alignment */ /* Flags that indicate a format can be used for capture/output */ #define MEM2MEM_CAPTURE (1 << 0) @@ -145,14 +145,14 @@ enum { #define V4L2_CID_TRANS_TIME_MSEC (V4L2_CID_USER_BASE + 0x1000) #define V4L2_CID_TRANS_NUM_BUFS (V4L2_CID_USER_BASE + 0x1001) -static struct vim2m_fmt *find_format(struct v4l2_format *f) +static struct vim2m_fmt *find_format(u32 fourcc) { struct vim2m_fmt *fmt; unsigned int k; for (k = 0; k < NUM_FORMATS; k++) { fmt = &formats[k]; - if (fmt->fourcc == f->fmt.pix.pixelformat) + if (fmt->fourcc == fourcc) break; } @@ -675,6 +675,25 @@ static int vidioc_enum_fmt_vid_out(struct file *file, void *priv, return enum_fmt(f, MEM2MEM_OUTPUT); } +static int vidioc_enum_framesizes(struct file *file, void *priv, + struct v4l2_frmsizeenum *fsize) +{ + if (fsize->index != 0) + return -EINVAL; + + if (!find_format(fsize->pixel_format)) + return -EINVAL; + + fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE; + fsize->stepwise.min_width = MIN_W; + fsize->stepwise.min_height =MIN_H; + fsize->stepwise.max_width = MAX_W; + fsize->stepwise.max_height = MAX_H; + fsize->stepwise.step_width = WIDTH_ALIGN; + fsize->stepwise.step_height = 1; + return 0; +} + static int vidioc_g_fmt(struct vim2m_ctx *ctx, struct v4l2_format *f) { struct vb2_queue *vq; @@ -726,7 +745,7 @@ static int vidioc_try_fmt(struct v4l2_format *f, struct vim2m_fmt *fmt) else if (f->fmt.pix.width > MAX_W) f->fmt.pix.width = MAX_W; - f->fmt.pix.width &= ~DIM_ALIGN_MASK; + f->fmt.pix.width &= ~(WIDTH_ALIGN - 1); f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3; f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; f->fmt.pix.field = V4L2_FIELD_NONE; @@ -740,10 +759,10 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, struct vim2m_fmt *fmt; struct vim2m_ctx *ctx = file2ctx(file); - fmt = find_format(f); + fmt = find_format(f->fmt.pix.pixelformat); if (!fmt) { f->fmt.pix.pixelformat = formats[0].fourcc; - fmt = find_format(f); + fmt = find_format(f->fmt.pix.pixelformat); } if (!(fmt->types & MEM2MEM_CAPTURE)) { v4l2_err(&ctx->dev->v4l2_dev, @@ -765,10 +784,10 @@ static int vidioc_try_fmt_vid_out(struct file *file, void *priv, struct vim2m_fmt *fmt; struct vim2m_ctx *ctx = file2ctx(file); - fmt = find_format(f); + fmt = find_format(f->fmt.pix.pixelformat); if (!fmt) { f->fmt.pix.pixelformat = formats[0].fourcc; - fmt = find_format(f); + fmt = find_format(f->fmt.pix.pixelformat); } if (!(fmt->types & MEM2MEM_OUTPUT)) { v4l2_err(&ctx->dev->v4l2_dev, @@ -800,7 +819,7 @@ static int vidioc_s_fmt(struct vim2m_ctx *ctx, struct v4l2_format *f) return -EBUSY; } - q_data->fmt = find_format(f); + q_data->fmt = find_format(f->fmt.pix.pixelformat); q_data->width = f->fmt.pix.width; q_data->height = f->fmt.pix.height; q_data->sizeimage = q_data->width * q_data->height @@ -897,6 +916,7 @@ static const struct v4l2_ioctl_ops vim2m_ioctl_ops = { .vidioc_querycap = vidioc_querycap, .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, + .vidioc_enum_framesizes = vidioc_enum_framesizes, .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, From patchwork Fri Mar 1 13:24:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 10835327 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ABE211575 for ; Fri, 1 Mar 2019 13:24:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A9042DD97 for ; Fri, 1 Mar 2019 13:24:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8EED72EE31; Fri, 1 Mar 2019 13:24:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E3892EE30 for ; Fri, 1 Mar 2019 13:24:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387556AbfCANYa (ORCPT ); Fri, 1 Mar 2019 08:24:30 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:50528 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732895AbfCANYa (ORCPT ); Fri, 1 Mar 2019 08:24:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=UYfddN859fhkWKFQi0QZbxnqnhkIt0SRRwZ5Q1g+icQ=; b=dYqlg8W9yTIlO8yHtgHqltxsdN 9bYbNhDxgpaBN1d+azRvP7mEO2f6PQ6DzeDIwm8ARynBxFGwyTdYhQIkbTuwOJ8RZ/aNeiM2FTlqx m6dvOijLlX3Gb96/pGVab1WcXLgq1/cVxwVICYO+CtE1qKt8nCYlxMx9x96JwiJ68eXyS3M0hzzbC 9vyZybDA2DAvhGc3JPjk7guJKjt0mLeCfwkGrDkbI4qK+gRjYEBrF/NKkbJ8Q0ee/eKwU/H5Vtkqa i7SApA5gNCAxYbYIJiPK8CSOLAe2vrHyX1VwSKqvMJXP6j0DrU8frVW0HpJEL64D9ZZpwDiNQtlhi zdO5zPNQ==; Received: from 177.41.113.159.dynamic.adsl.gvt.net.br ([177.41.113.159] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gzi9N-0003y0-So; Fri, 01 Mar 2019 13:24:29 +0000 Received: from mchehab by bombadil.infradead.org with local (Exim 4.92) (envelope-from ) id 1gzi9L-0002NN-RO; Fri, 01 Mar 2019 10:24:27 -0300 From: Mauro Carvalho Chehab To: Linux Media Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , Hans Verkuil , Ezequiel Garcia Subject: [PATCH 05/10] media: vim2m: use different framesizes for bayer formats Date: Fri, 1 Mar 2019 10:24:21 -0300 Message-Id: <52c07fa56e91243f05022ebae6a65da26e44e1f3.1551446121.git.mchehab+samsung@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The only real restriction at vim2m is that width should be multiple of two, as the copy routine always copy two pixels each time. However, Bayer formats are defined as having a 2x2 matrix. So, odd vertical numbers would cause color distortions at the last line. So, it makes sense to use step 2 for vertical alignment on Bayer. With this patch, the reported formats for video capture will be: [0]: 'RGBP' (16-bit RGB 5-6-5) Size: Stepwise 32x32 - 640x480 with step 2/1 [1]: 'RGBR' (16-bit RGB 5-6-5 BE) Size: Stepwise 32x32 - 640x480 with step 2/1 [2]: 'RGB3' (24-bit RGB 8-8-8) Size: Stepwise 32x32 - 640x480 with step 2/1 [3]: 'BGR3' (24-bit BGR 8-8-8) Size: Stepwise 32x32 - 640x480 with step 2/1 [4]: 'YUYV' (YUYV 4:2:2) Size: Stepwise 32x32 - 640x480 with step 2/1 [5]: 'BA81' (8-bit Bayer BGBG/GRGR) Size: Stepwise 32x32 - 640x480 with step 2/2 [6]: 'GBRG' (8-bit Bayer GBGB/RGRG) Size: Stepwise 32x32 - 640x480 with step 2/2 [7]: 'GRBG' (8-bit Bayer GRGR/BGBG) Size: Stepwise 32x32 - 640x480 with step 2/2 [8]: 'RGGB' (8-bit Bayer RGRG/GBGB) Size: Stepwise 32x32 - 640x480 with step 2/2 Signed-off-by: Mauro Carvalho Chehab --- drivers/media/platform/vim2m.c | 38 ++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/vim2m.c b/drivers/media/platform/vim2m.c index bac9d4733d65..5157a59aeb58 100644 --- a/drivers/media/platform/vim2m.c +++ b/drivers/media/platform/vim2m.c @@ -50,7 +50,14 @@ MODULE_PARM_DESC(default_transtime, "default transaction time in ms"); #define MIN_H 32 #define MAX_W 640 #define MAX_H 480 -#define WIDTH_ALIGN 2 /* 2-byte alignment */ + +/* Pixel alignment for non-bayer formats */ +#define WIDTH_ALIGN 2 +#define HEIGHT_ALIGN 1 + +/* Pixel alignment for bayer formats */ +#define BAYER_WIDTH_ALIGN 2 +#define BAYER_HEIGHT_ALIGN 2 /* Flags that indicate a format can be used for capture/output */ #define MEM2MEM_CAPTURE (1 << 0) @@ -162,6 +169,24 @@ static struct vim2m_fmt *find_format(u32 fourcc) return &formats[k]; } +void static get_alignment(u32 fourcc, + unsigned int *walign, unsigned int *halign) +{ + switch(fourcc) { + case V4L2_PIX_FMT_SBGGR8: + case V4L2_PIX_FMT_SGBRG8: + case V4L2_PIX_FMT_SGRBG8: + case V4L2_PIX_FMT_SRGGB8: + *walign = BAYER_WIDTH_ALIGN; + *halign = BAYER_HEIGHT_ALIGN; + return; + default: + *walign = WIDTH_ALIGN; + *halign = HEIGHT_ALIGN; + return; + } +} + struct vim2m_dev { struct v4l2_device v4l2_dev; struct video_device vfd; @@ -689,8 +714,10 @@ static int vidioc_enum_framesizes(struct file *file, void *priv, fsize->stepwise.min_height =MIN_H; fsize->stepwise.max_width = MAX_W; fsize->stepwise.max_height = MAX_H; - fsize->stepwise.step_width = WIDTH_ALIGN; - fsize->stepwise.step_height = 1; + + get_alignment(fsize->pixel_format, + &fsize->stepwise.step_width, + &fsize->stepwise.step_height); return 0; } @@ -733,6 +760,7 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, static int vidioc_try_fmt(struct v4l2_format *f, struct vim2m_fmt *fmt) { + int walign, halign; /* V4L2 specification suggests the driver corrects the format struct * if any of the dimensions is unsupported */ if (f->fmt.pix.height < MIN_H) @@ -745,7 +773,9 @@ static int vidioc_try_fmt(struct v4l2_format *f, struct vim2m_fmt *fmt) else if (f->fmt.pix.width > MAX_W) f->fmt.pix.width = MAX_W; - f->fmt.pix.width &= ~(WIDTH_ALIGN - 1); + get_alignment(f->fmt.pix.pixelformat, &walign, &halign); + f->fmt.pix.width &= ~(walign - 1); + f->fmt.pix.height &= ~(halign - 1); f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3; f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; f->fmt.pix.field = V4L2_FIELD_NONE; From patchwork Fri Mar 1 13:24:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 10835319 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 47C441575 for ; Fri, 1 Mar 2019 13:24:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 365EF2DD97 for ; Fri, 1 Mar 2019 13:24:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A9EC2EE31; Fri, 1 Mar 2019 13:24:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9377A2DD97 for ; Fri, 1 Mar 2019 13:24:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387601AbfCANYd (ORCPT ); Fri, 1 Mar 2019 08:24:33 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:50534 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732910AbfCANYa (ORCPT ); Fri, 1 Mar 2019 08:24:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=BHHrEQZI+5S4/LwUdO/s8e2FpWWYq4AOxIetfF7icw0=; b=Cx4Ital9N2dP3j067oN9A4Wxfy DkwidvhlA167bsIBuXgKbxon9pnPjFqi5ze/DB4NGxUrVi8Onlk074Qn7Xpzb1CiFrPQo30JytqGe QrMun5qXbI5tdmeHEhnXLO1vgJFzz7dxQZFuWoXbfo3aPB/Pg5GN1tUThpuv6/il9OPl9s87E+jTx GdoWbqYwsbgHtxtbfdiCz/BimQVsgF7nl5f6l+xFcGLusYHz8zaW8YJedk1gMNlx7OmVXhXRVbU1I hyvuhTsWKbpM66SySO44jzLOh7NTkyx0rTQBrjj9v2IaV6sTXLm6jEaB5lJ0L6oGz4WBGLufjT0du jxuwNzvQ==; Received: from 177.41.113.159.dynamic.adsl.gvt.net.br ([177.41.113.159] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gzi9N-0003y1-VO; Fri, 01 Mar 2019 13:24:29 +0000 Received: from mchehab by bombadil.infradead.org with local (Exim 4.92) (envelope-from ) id 1gzi9L-0002NS-SB; Fri, 01 Mar 2019 10:24:27 -0300 From: Mauro Carvalho Chehab To: Linux Media Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , Hans Verkuil , Ezequiel Garcia Subject: [PATCH 06/10] media: vim2m: better handle cap/out buffers with different sizes Date: Fri, 1 Mar 2019 10:24:22 -0300 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The vim2m driver doesn't enforce that the capture and output buffers would have the same size. Do the right thing if the buffers are different, zeroing the buffer before writing, ensuring that lines will be aligned and it won't write past the buffer area. This is a temporary fix. A proper fix is to either implement a simple scaler at vim2m, or to better define the behaviour of M2M transform drivers at V4L2 API with regards to its capability of scaling the image or not. In any case, such changes would deserve a separate patch anyway, as it would imply on some behavoral change. Also, as we have an actual bug of writing data at wrong places, let's fix this here, and add a mental note that we need to properly address it. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/platform/vim2m.c | 117 +++++++++++++++++++++++---------- 1 file changed, 81 insertions(+), 36 deletions(-) diff --git a/drivers/media/platform/vim2m.c b/drivers/media/platform/vim2m.c index 5157a59aeb58..ec177de144b6 100644 --- a/drivers/media/platform/vim2m.c +++ b/drivers/media/platform/vim2m.c @@ -267,46 +267,66 @@ static const char *type_name(enum v4l2_buf_type type) #define CLIP(__color) \ (u8)(((__color) > 0xff) ? 0xff : (((__color) < 0) ? 0 : (__color))) -static void copy_two_pixels(struct vim2m_fmt *in, struct vim2m_fmt *out, +static int fast_copy_two_pixels(struct vim2m_q_data *q_data_in, + struct vim2m_q_data *q_data_out, + u8 **src, u8 **dst, int ypos, bool reverse) +{ + int depth = q_data_out->fmt->depth >> 3; + + /* Only do fast copy when format and resolution are identical */ + if (q_data_in->fmt->fourcc != q_data_out->fmt->fourcc || + q_data_in->width != q_data_out->width || + q_data_in->height != q_data_out->height) + return 0; + + if (!reverse) { + memcpy(*dst, *src, depth << 1); + *src += depth << 1; + *dst += depth << 1; + return 1; + } + + /* Copy line at reverse order - YUYV format */ + if (q_data_in->fmt->fourcc == V4L2_PIX_FMT_YUYV) { + int u, v, y, y1; + + *src -= 2; + + y1 = (*src)[0]; /* copy as second point */ + u = (*src)[1]; + y = (*src)[2]; /* copy as first point */ + v = (*src)[3]; + + *src -= 2; + + *(*dst)++ = y; + *(*dst)++ = u; + *(*dst)++ = y1; + *(*dst)++ = v; + return 1; + } + + /* copy RGB formats in reverse order */ + memcpy(*dst, *src, depth); + memcpy(*dst + depth, *src - depth, depth); + *src -= depth << 1; + *dst += depth << 1; + return 1; +} + +static void copy_two_pixels(struct vim2m_q_data *q_data_in, + struct vim2m_q_data *q_data_out, u8 **src, u8 **dst, int ypos, bool reverse) { + struct vim2m_fmt *out = q_data_out->fmt; + struct vim2m_fmt *in = q_data_in->fmt; u8 _r[2], _g[2], _b[2], *r, *g, *b; int i, step; // If format is the same just copy the data, respecting the width - if (in->fourcc == out->fourcc) { - int depth = out->depth >> 3; - - if (reverse) { - if (in->fourcc == V4L2_PIX_FMT_YUYV) { - int u, v, y, y1; - - *src -= 2; - - y1 = (*src)[0]; /* copy as second point */ - u = (*src)[1]; - y = (*src)[2]; /* copy as first point */ - v = (*src)[3]; - - *src -= 2; - - *(*dst)++ = y; - *(*dst)++ = u; - *(*dst)++ = y1; - *(*dst)++ = v; - return; - } - - memcpy(*dst, *src, depth); - memcpy(*dst + depth, *src - depth, depth); - *src -= depth << 1; - } else { - memcpy(*dst, *src, depth << 1); - *src += depth << 1; - } - *dst += depth << 1; - return; - } + if (fast_copy_two_pixels(q_data_in, q_data_out, + src, dst, ypos, reverse)) + return; /* Step 1: read two consecutive pixels from src pointer */ @@ -506,7 +526,9 @@ static int device_process(struct vim2m_ctx *ctx, struct vim2m_dev *dev = ctx->dev; struct vim2m_q_data *q_data_in, *q_data_out; u8 *p_in, *p, *p_out; - int width, height, bytesperline, x, y, y_out, start, end, step; + unsigned int width, height, bytesperline, bytesperline_out; + unsigned int x, y, y_out; + int start, end, step; struct vim2m_fmt *in, *out; q_data_in = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); @@ -516,8 +538,15 @@ static int device_process(struct vim2m_ctx *ctx, bytesperline = (q_data_in->width * q_data_in->fmt->depth) >> 3; q_data_out = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); + bytesperline_out = (q_data_out->width * q_data_out->fmt->depth) >> 3; out = q_data_out->fmt; + /* Crop to the limits of the destination image */ + if (width > q_data_out->width) + width = q_data_out->width; + if (height > q_data_out->height) + height = q_data_out->height; + p_in = vb2_plane_vaddr(&in_vb->vb2_buf, 0); p_out = vb2_plane_vaddr(&out_vb->vb2_buf, 0); if (!p_in || !p_out) { @@ -526,6 +555,17 @@ static int device_process(struct vim2m_ctx *ctx, return -EFAULT; } + /* + * FIXME: instead of cropping the image and zeroing any + * extra data, the proper behavior is to either scale the + * data or report that scale is not supported (with depends + * on some API for such purpose). + */ + + /* Image size is different. Zero buffer first */ + if (q_data_in->width != q_data_out->width || + q_data_in->height != q_data_out->height) + memset(p_out, 0, q_data_out->sizeimage); out_vb->sequence = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE)->sequence++; in_vb->sequence = q_data_in->sequence++; @@ -547,8 +587,13 @@ static int device_process(struct vim2m_ctx *ctx, p += bytesperline - (q_data_in->fmt->depth >> 3); for (x = 0; x < width >> 1; x++) - copy_two_pixels(in, out, &p, &p_out, y_out, + copy_two_pixels(q_data_in, q_data_out, &p, &p_out, y_out, ctx->mode & MEM2MEM_HFLIP); + + /* Go to the next line at the out buffer */ + if (width < q_data_out->width) + p_out += ((q_data_out->width - width) + * q_data_out->fmt->depth) >> 3; } return 0; From patchwork Fri Mar 1 13:24:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 10835321 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6E9091575 for ; Fri, 1 Mar 2019 13:24:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5FF0F2DD97 for ; Fri, 1 Mar 2019 13:24:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 545542EE31; Fri, 1 Mar 2019 13:24:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE15B2DD97 for ; Fri, 1 Mar 2019 13:24:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387620AbfCANYe (ORCPT ); Fri, 1 Mar 2019 08:24:34 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:50524 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728320AbfCANYb (ORCPT ); Fri, 1 Mar 2019 08:24:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=DBRD7UTN1XhladlTOP+IXaVBu2F0f0sqVvhVFqagqm0=; b=aeRgaycchxPqFH7O7fd94OWgAi DKyp10vJt21Gw+NnunWZ889CbB40ZoNEtGxLWAAJSLUQZ7Yqx5Dw7qVb/GAqw0IupSTXpyoSjZXT2 iv5csGA8kWX+ozbBzoHYVw2JlX6MR4+0QE3OK8W2gt4+BGHpvzp/j1tXIN1y3vx1yjatpfCRQLxeW 9cQWNW6v1pKdDnVcosyLnRrqR1zaCuDefHXk+m/tCKJlpHztC14vTzLhi+kNj1/VqO0shqZnduwl/ zJYeCsNARtGCTr7kRFTcTmgsl9dGmueWaKnOWROvzS0p7SFCRKk9hqWxivR8aV182lzwZQZxwIAwl 93sMBh8w==; Received: from 177.41.113.159.dynamic.adsl.gvt.net.br ([177.41.113.159] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gzi9N-0003y2-Ub; Fri, 01 Mar 2019 13:24:29 +0000 Received: from mchehab by bombadil.infradead.org with local (Exim 4.92) (envelope-from ) id 1gzi9L-0002NX-T0; Fri, 01 Mar 2019 10:24:27 -0300 From: Mauro Carvalho Chehab To: Linux Media Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , Hans Verkuil , Ezequiel Garcia Subject: [PATCH 07/10] media: vim2m: add vertical linear scaler Date: Fri, 1 Mar 2019 10:24:23 -0300 Message-Id: <8d53fe1c2d8305dda9a360ace275c63dfacc3b1f.1551446121.git.mchehab+samsung@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When resolutions are different, the expected behavior is to scale the image. Implement a vertical scaler as the first step. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/platform/vim2m.c | 65 +++++++++++++++++----------------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/drivers/media/platform/vim2m.c b/drivers/media/platform/vim2m.c index ec177de144b6..1708becbaa9d 100644 --- a/drivers/media/platform/vim2m.c +++ b/drivers/media/platform/vim2m.c @@ -267,23 +267,17 @@ static const char *type_name(enum v4l2_buf_type type) #define CLIP(__color) \ (u8)(((__color) > 0xff) ? 0xff : (((__color) < 0) ? 0 : (__color))) -static int fast_copy_two_pixels(struct vim2m_q_data *q_data_in, +static void fast_copy_two_pixels(struct vim2m_q_data *q_data_in, struct vim2m_q_data *q_data_out, - u8 **src, u8 **dst, int ypos, bool reverse) + u8 **src, u8 **dst, bool reverse) { int depth = q_data_out->fmt->depth >> 3; - /* Only do fast copy when format and resolution are identical */ - if (q_data_in->fmt->fourcc != q_data_out->fmt->fourcc || - q_data_in->width != q_data_out->width || - q_data_in->height != q_data_out->height) - return 0; - if (!reverse) { memcpy(*dst, *src, depth << 1); *src += depth << 1; *dst += depth << 1; - return 1; + return; } /* Copy line at reverse order - YUYV format */ @@ -303,7 +297,7 @@ static int fast_copy_two_pixels(struct vim2m_q_data *q_data_in, *(*dst)++ = u; *(*dst)++ = y1; *(*dst)++ = v; - return 1; + return; } /* copy RGB formats in reverse order */ @@ -311,7 +305,7 @@ static int fast_copy_two_pixels(struct vim2m_q_data *q_data_in, memcpy(*dst + depth, *src - depth, depth); *src -= depth << 1; *dst += depth << 1; - return 1; + return; } static void copy_two_pixels(struct vim2m_q_data *q_data_in, @@ -323,11 +317,6 @@ static void copy_two_pixels(struct vim2m_q_data *q_data_in, u8 _r[2], _g[2], _b[2], *r, *g, *b; int i, step; - // If format is the same just copy the data, respecting the width - if (fast_copy_two_pixels(q_data_in, q_data_out, - src, dst, ypos, reverse)) - return; - /* Step 1: read two consecutive pixels from src pointer */ r = _r; @@ -527,25 +516,25 @@ static int device_process(struct vim2m_ctx *ctx, struct vim2m_q_data *q_data_in, *q_data_out; u8 *p_in, *p, *p_out; unsigned int width, height, bytesperline, bytesperline_out; - unsigned int x, y, y_out; + unsigned int x, y, y_in, y_out; int start, end, step; struct vim2m_fmt *in, *out; q_data_in = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in = q_data_in->fmt; - width = q_data_in->width; - height = q_data_in->height; bytesperline = (q_data_in->width * q_data_in->fmt->depth) >> 3; q_data_out = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); bytesperline_out = (q_data_out->width * q_data_out->fmt->depth) >> 3; out = q_data_out->fmt; + /* As we're doing vertical scaling use the out height here */ + height = q_data_out->height; + /* Crop to the limits of the destination image */ + width = q_data_in->width; if (width > q_data_out->width) width = q_data_out->width; - if (height > q_data_out->height) - height = q_data_out->height; p_in = vb2_plane_vaddr(&in_vb->vb2_buf, 0); p_out = vb2_plane_vaddr(&out_vb->vb2_buf, 0); @@ -555,17 +544,6 @@ static int device_process(struct vim2m_ctx *ctx, return -EFAULT; } - /* - * FIXME: instead of cropping the image and zeroing any - * extra data, the proper behavior is to either scale the - * data or report that scale is not supported (with depends - * on some API for such purpose). - */ - - /* Image size is different. Zero buffer first */ - if (q_data_in->width != q_data_out->width || - q_data_in->height != q_data_out->height) - memset(p_out, 0, q_data_out->sizeimage); out_vb->sequence = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE)->sequence++; in_vb->sequence = q_data_in->sequence++; @@ -581,8 +559,29 @@ static int device_process(struct vim2m_ctx *ctx, step = 1; } y_out = 0; + + /* Faster copy logic, when format and resolution are identical */ + if (q_data_in->fmt->fourcc == q_data_out->fmt->fourcc && + q_data_in->width == q_data_out->width && + q_data_in->height == q_data_out->height) { + for (y = start; y != end; y += step, y_out++) { + p = p_in + (y * bytesperline); + if (ctx->mode & MEM2MEM_HFLIP) + p += bytesperline - (q_data_in->fmt->depth >> 3); + + for (x = 0; x < width >> 1; x++) + fast_copy_two_pixels(q_data_in, q_data_out, + &p, &p_out, + ctx->mode & MEM2MEM_HFLIP); + } + return 0; + } + + /* Slower algorithm with format conversion and scaler */ for (y = start; y != end; y += step, y_out++) { - p = p_in + (y * bytesperline); + y_in = (y * q_data_in->height) / q_data_out->height; + + p = p_in + (y_in * bytesperline); if (ctx->mode & MEM2MEM_HFLIP) p += bytesperline - (q_data_in->fmt->depth >> 3); From patchwork Fri Mar 1 13:24:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 10835315 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 583391880 for ; Fri, 1 Mar 2019 13:24:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49A9B2DD97 for ; Fri, 1 Mar 2019 13:24:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3DC272EE41; Fri, 1 Mar 2019 13:24:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 233F42DD97 for ; Fri, 1 Mar 2019 13:24:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387588AbfCANYb (ORCPT ); Fri, 1 Mar 2019 08:24:31 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:50544 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387550AbfCANYa (ORCPT ); Fri, 1 Mar 2019 08:24:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=7q+FhjWdYXA1o+3VwsL572UHQ/YkxZUbnx9oC112dvQ=; b=u1tstb+HPFPaLQvXLJSgECz+f3 4qXmZTwH2DDvjpeTvG3fPTbRLNbarIS9pjqIkuHGyX427xpooRSuSruK1382ts/O62ZaB6zRHNgOf ui2/fzRArO0R3C6tchdMQwnVeEyM/7S/MGqZpQv/u2UceXymeEunoucnQcV5HXjiC0kDbFZdwYQQt 8zB85NctrtsY5Jw/ePKNAg4qjjT4XjnAx9S1/ABGuiZqVqYsC1PWfziB/W4svDFUCqQtobbBy6q5H dyrgG7HqUosCXG98UI1dek4tazIQ3YKcIHF6iPThcuixATLgD+V4Yy9I9/ecc2yrXfVSIGgtcZI6G TJQm00XQ==; Received: from 177.41.113.159.dynamic.adsl.gvt.net.br ([177.41.113.159] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gzi9O-0003y3-0l; Fri, 01 Mar 2019 13:24:30 +0000 Received: from mchehab by bombadil.infradead.org with local (Exim 4.92) (envelope-from ) id 1gzi9L-0002Nc-Tm; Fri, 01 Mar 2019 10:24:27 -0300 From: Mauro Carvalho Chehab To: Linux Media Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , Hans Verkuil , Ezequiel Garcia Subject: [PATCH 08/10] media: vim2m: don't accept YUYV anymore as output format Date: Fri, 1 Mar 2019 10:24:24 -0300 Message-Id: <906312367485f0e67e16bc4fb12c239885b61dbc.1551446121.git.mchehab+samsung@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Handling any Y,Cr,Cb formats require some extra logic, as it handles a group of two pixels. That's easy while we don't do horizontal scaling. However, doing horizontal scaling with such formats would require a lot more code, in order to avoid distortions, as, if it scales to two non-consecutive points, the logic would need to read 4 points in order to properly convert to RGB. As this is just a test driver, and we want fast algorithms, let's just get rid of this format as an output one. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/platform/vim2m.c | 57 ++-------------------------------- 1 file changed, 2 insertions(+), 55 deletions(-) diff --git a/drivers/media/platform/vim2m.c b/drivers/media/platform/vim2m.c index 1708becbaa9d..a0e52eb205e3 100644 --- a/drivers/media/platform/vim2m.c +++ b/drivers/media/platform/vim2m.c @@ -113,7 +113,7 @@ static struct vim2m_fmt formats[] = { }, { .fourcc = V4L2_PIX_FMT_YUYV, .depth = 16, - .types = MEM2MEM_CAPTURE | MEM2MEM_OUTPUT, + .types = MEM2MEM_CAPTURE, }, { .fourcc = V4L2_PIX_FMT_SBGGR8, .depth = 8, @@ -280,26 +280,6 @@ static void fast_copy_two_pixels(struct vim2m_q_data *q_data_in, return; } - /* Copy line at reverse order - YUYV format */ - if (q_data_in->fmt->fourcc == V4L2_PIX_FMT_YUYV) { - int u, v, y, y1; - - *src -= 2; - - y1 = (*src)[0]; /* copy as second point */ - u = (*src)[1]; - y = (*src)[2]; /* copy as first point */ - v = (*src)[3]; - - *src -= 2; - - *(*dst)++ = y; - *(*dst)++ = u; - *(*dst)++ = y1; - *(*dst)++ = v; - return; - } - /* copy RGB formats in reverse order */ memcpy(*dst, *src, depth); memcpy(*dst + depth, *src - depth, depth); @@ -352,6 +332,7 @@ static void copy_two_pixels(struct vim2m_q_data *q_data_in, *src += step << 1; } break; + default: case V4L2_PIX_FMT_RGB24: for (i = 0; i < 2; i++) { *r++ = (*src)[0]; @@ -370,40 +351,6 @@ static void copy_two_pixels(struct vim2m_q_data *q_data_in, *src += step * 3; } break; - default: /* V4L2_PIX_FMT_YUYV */ - { - int u, v, y, y1, u1, v1, tmp; - - if (reverse) { - *src -= 2; - - y1 = (*src)[0]; /* copy as second point */ - u = (*src)[1]; - y = (*src)[2]; /* copy as first point */ - v = (*src)[3]; - - *src -= 2; - } else { - y = *(*src)++; - u = *(*src)++; - y1 = *(*src)++; - v = *(*src)++; - } - - u1 = (((u - 128) << 7) + (u - 128)) >> 6; - tmp = (((u - 128) << 1) + (u - 128) + - ((v - 128) << 2) + ((v - 128) << 1)) >> 3; - v1 = (((v - 128) << 1) + (v - 128)) >> 1; - - *r++ = CLIP(y + v1); - *g++ = CLIP(y - tmp); - *b++ = CLIP(y + u1); - - *r = CLIP(y1 + v1); - *g = CLIP(y1 - tmp); - *b = CLIP(y1 + u1); - break; - } } /* Step 2: store two consecutive points, reversing them if needed */ From patchwork Fri Mar 1 13:24:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 10835317 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 103681390 for ; Fri, 1 Mar 2019 13:24:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 01F1E2EE30 for ; Fri, 1 Mar 2019 13:24:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA6062EE41; Fri, 1 Mar 2019 13:24:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B761E2EE31 for ; Fri, 1 Mar 2019 13:24:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387600AbfCANYc (ORCPT ); Fri, 1 Mar 2019 08:24:32 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:50542 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387518AbfCANYa (ORCPT ); Fri, 1 Mar 2019 08:24:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ZQL9nvcw/a6aK+gKT6rbweNSeFBeJyzcGcYPj7/uASk=; b=IfGeaOCWxpsTRcWyh8fTsU7Pkl xjwhvO6pLYAcKWNcFc5rmpVeBzST6OUiB8c3m/TG8LTFlI9X9Nr+mYxUizfw+zudlNxYhRGAhEkri 4tRG222kg4w1mTltEvL29rf5/bzlSnW0jLVplYKPCn9YZ6B8tGpWTNRjUPkaN16FN6eGebHg8B2Cy 5Pg2QZWQvwaA6nyGRvX44gEQUl9x/amyz7NKK10kSuq1r+YjLpRzP+PanDRQWatLMsYlCyWotpeyY m3qPSKA/Svr4hjs+OFf2QkaWN1ABo8zYIgWa/2OM065FiA4ABWarh31rB/sl6CPuEx2vp4bEVIHF/ ogcHcSzQ==; Received: from 177.41.113.159.dynamic.adsl.gvt.net.br ([177.41.113.159] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gzi9O-0003y4-1I; Fri, 01 Mar 2019 13:24:30 +0000 Received: from mchehab by bombadil.infradead.org with local (Exim 4.92) (envelope-from ) id 1gzi9L-0002Nh-Ut; Fri, 01 Mar 2019 10:24:27 -0300 From: Mauro Carvalho Chehab To: Linux Media Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , Hans Verkuil , Ezequiel Garcia Subject: [PATCH 09/10] media: vim2m: add an horizontal scaler Date: Fri, 1 Mar 2019 10:24:25 -0300 Message-Id: <4f7af5730361937a48557822050005d707a3762c.1551446121.git.mchehab+samsung@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add an horizontal linear scaler using Breseham algorithm in order to speep up its calculus. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/platform/vim2m.c | 95 ++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 40 deletions(-) diff --git a/drivers/media/platform/vim2m.c b/drivers/media/platform/vim2m.c index a0e52eb205e3..6bcc0c9f9910 100644 --- a/drivers/media/platform/vim2m.c +++ b/drivers/media/platform/vim2m.c @@ -290,12 +290,12 @@ static void fast_copy_two_pixels(struct vim2m_q_data *q_data_in, static void copy_two_pixels(struct vim2m_q_data *q_data_in, struct vim2m_q_data *q_data_out, - u8 **src, u8 **dst, int ypos, bool reverse) + u8 *src[2], u8 **dst, int ypos, bool reverse) { struct vim2m_fmt *out = q_data_out->fmt; struct vim2m_fmt *in = q_data_in->fmt; u8 _r[2], _g[2], _b[2], *r, *g, *b; - int i, step; + int i; /* Step 1: read two consecutive pixels from src pointer */ @@ -303,52 +303,39 @@ static void copy_two_pixels(struct vim2m_q_data *q_data_in, g = _g; b = _b; - if (reverse) - step = -1; - else - step = 1; - switch (in->fourcc) { case V4L2_PIX_FMT_RGB565: /* rrrrrggg gggbbbbb */ for (i = 0; i < 2; i++) { - u16 pix = *(u16 *)*src; + u16 pix = *(u16 *)(src[i]); *r++ = (u8)(((pix & 0xf800) >> 11) << 3) | 0x07; *g++ = (u8)((((pix & 0x07e0) >> 5)) << 2) | 0x03; *b++ = (u8)((pix & 0x1f) << 3) | 0x07; - - *src += step << 1; } break; case V4L2_PIX_FMT_RGB565X: /* gggbbbbb rrrrrggg */ for (i = 0; i < 2; i++) { - u16 pix = *(u16 *)*src; + u16 pix = *(u16 *)(src[i]); *r++ = (u8)(((0x00f8 & pix) >> 3) << 3) | 0x07; *g++ = (u8)(((pix & 0x7) << 2) | ((pix & 0xe000) >> 5)) | 0x03; *b++ = (u8)(((pix & 0x1f00) >> 8) << 3) | 0x07; - - *src += step << 1; } break; default: case V4L2_PIX_FMT_RGB24: for (i = 0; i < 2; i++) { - *r++ = (*src)[0]; - *g++ = (*src)[1]; - *b++ = (*src)[2]; - - *src += step * 3; + *r++ = src[i][0]; + *g++ = src[i][1]; + *b++ = src[i][2]; } break; case V4L2_PIX_FMT_BGR24: for (i = 0; i < 2; i++) { - *b++ = (*src)[0]; - *g++ = (*src)[1]; - *r++ = (*src)[2]; - - *src += step * 3; + *b++ = src[i][0]; + *g++ = src[i][1]; + *r++ = src[i][2]; } break; } @@ -461,27 +448,24 @@ static int device_process(struct vim2m_ctx *ctx, { struct vim2m_dev *dev = ctx->dev; struct vim2m_q_data *q_data_in, *q_data_out; - u8 *p_in, *p, *p_out; - unsigned int width, height, bytesperline, bytesperline_out; - unsigned int x, y, y_in, y_out; + u8 *p_in, *p_line, *p_in_x[2], *p, *p_out; + unsigned int width, height, bytesperline, bytesperline_out, bytes_per_pixel; + unsigned int x, y, y_in, y_out, x_int, x_fract, x_err, x_offset; int start, end, step; struct vim2m_fmt *in, *out; q_data_in = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in = q_data_in->fmt; bytesperline = (q_data_in->width * q_data_in->fmt->depth) >> 3; + bytes_per_pixel = q_data_in->fmt->depth >> 3; q_data_out = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); bytesperline_out = (q_data_out->width * q_data_out->fmt->depth) >> 3; out = q_data_out->fmt; - /* As we're doing vertical scaling use the out height here */ + /* As we're doing scaling, use the output dimensions here */ height = q_data_out->height; - - /* Crop to the limits of the destination image */ - width = q_data_in->width; - if (width > q_data_out->width) - width = q_data_out->width; + width = q_data_out->width; p_in = vb2_plane_vaddr(&in_vb->vb2_buf, 0); p_out = vb2_plane_vaddr(&out_vb->vb2_buf, 0); @@ -525,21 +509,52 @@ static int device_process(struct vim2m_ctx *ctx, } /* Slower algorithm with format conversion and scaler */ + + /* To speed scaler up, use Bresenham for X dimension */ + x_int = q_data_in->width / q_data_out->width; + x_fract = q_data_in->width % q_data_out->width; + for (y = start; y != end; y += step, y_out++) { y_in = (y * q_data_in->height) / q_data_out->height; + x_offset = 0; + x_err = 0; - p = p_in + (y_in * bytesperline); + p_line = p_in + (y_in * bytesperline); if (ctx->mode & MEM2MEM_HFLIP) - p += bytesperline - (q_data_in->fmt->depth >> 3); + p_line += bytesperline - (q_data_in->fmt->depth >> 3); + p_in_x[0] = p_line; - for (x = 0; x < width >> 1; x++) - copy_two_pixels(q_data_in, q_data_out, &p, &p_out, y_out, + for (x = 0; x < width >> 1; x++) { + x_offset += x_int; + x_err += x_fract; + if (x_err > width) { + x_offset++; + x_err -= width; + } + + if (ctx->mode & MEM2MEM_HFLIP) + p_in_x[1] = p_line - x_offset * bytes_per_pixel; + else + p_in_x[1] = p_line + x_offset * bytes_per_pixel; + + copy_two_pixels(q_data_in, q_data_out, + p_in_x, &p_out, y_out, ctx->mode & MEM2MEM_HFLIP); - /* Go to the next line at the out buffer */ - if (width < q_data_out->width) - p_out += ((q_data_out->width - width) - * q_data_out->fmt->depth) >> 3; + /* Calculate the next p_in_x0 */ + x_offset += x_int; + x_err += x_fract; + if (x_err > width) { + x_offset++; + x_err -= width; + } + + if (ctx->mode & MEM2MEM_HFLIP) + p_in_x[0] = p_line - x_offset * bytes_per_pixel; + else + p_in_x[0] = p_line + x_offset * bytes_per_pixel; + } + } return 0; From patchwork Fri Mar 1 13:24:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 10835313 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 39A8E1390 for ; Fri, 1 Mar 2019 13:24:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C5862EE41 for ; Fri, 1 Mar 2019 13:24:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 20BA02EE46; Fri, 1 Mar 2019 13:24:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6646E2EE30 for ; Fri, 1 Mar 2019 13:24:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387586AbfCANYb (ORCPT ); Fri, 1 Mar 2019 08:24:31 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:50538 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733255AbfCANYa (ORCPT ); Fri, 1 Mar 2019 08:24:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=HdAOrrKQq4G6AGeh+JxepzrSNVzIO/5cEm4xowGAM6Q=; b=Ci28T2GN9pA7tlQ0ocEfQepES4 VdezuzVk/BWP+PjuF+UdE8G8+afeIOhZthYjAc0NPkM2deZbi8aLMTEt73z6dmN4SDiifXkyB8rFN Mp7Euy4MsMU+CQfSWFmYwpmYvhLeG/R03+UXpsAAxg8jaLniLU+DZvb3bpKONfpQRaczoL2ONvUYT LtTJ6+IHLaY2zLTF7yGxwrg5FnQJZCadB/r18L+Sm1voqwpkgG1NpRHtqnJN3wqghBRoS7jGkkfEa v/6tXWggpYv4XICqCXnUI+TTJpCBn62G27viywAk/zcWnDsDvbxrXxzFHS1kxySvI6Xfy/LtHJ9Dr E/+gED2w==; Received: from 177.41.113.159.dynamic.adsl.gvt.net.br ([177.41.113.159] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gzi9O-0003y5-2Q; Fri, 01 Mar 2019 13:24:30 +0000 Received: from mchehab by bombadil.infradead.org with local (Exim 4.92) (envelope-from ) id 1gzi9L-0002Nm-W5; Fri, 01 Mar 2019 10:24:27 -0300 From: Mauro Carvalho Chehab To: Linux Media Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , Hans Verkuil , Ezequiel Garcia Subject: [PATCH 10/10] media: vim2m: speedup passthrough copy Date: Fri, 1 Mar 2019 10:24:26 -0300 Message-Id: <6f5f188f02ad43bd7b9b4affade082d84e1805ad.1551446121.git.mchehab+samsung@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When in passthrough mode, copy the entire line at once, in order to make it faster (if not HFLIP). Signed-off-by: Mauro Carvalho Chehab --- drivers/media/platform/vim2m.c | 37 ++++++++++++++++------------------ 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/drivers/media/platform/vim2m.c b/drivers/media/platform/vim2m.c index 6bcc0c9f9910..e98dc8f99e3e 100644 --- a/drivers/media/platform/vim2m.c +++ b/drivers/media/platform/vim2m.c @@ -267,25 +267,22 @@ static const char *type_name(enum v4l2_buf_type type) #define CLIP(__color) \ (u8)(((__color) > 0xff) ? 0xff : (((__color) < 0) ? 0 : (__color))) -static void fast_copy_two_pixels(struct vim2m_q_data *q_data_in, - struct vim2m_q_data *q_data_out, - u8 **src, u8 **dst, bool reverse) +static void copy_line(struct vim2m_q_data *q_data_out, + u8 *src, u8 *dst, bool reverse) { - int depth = q_data_out->fmt->depth >> 3; + int x, depth = q_data_out->fmt->depth >> 3; if (!reverse) { - memcpy(*dst, *src, depth << 1); - *src += depth << 1; - *dst += depth << 1; + memcpy(dst, src, q_data_out->width * depth); + } else { + for (x = 0; x < q_data_out->width >> 1; x++) { + memcpy(dst, src, depth); + memcpy(dst + depth, src - depth, depth); + src -= depth << 1; + dst += depth << 1; + } return; } - - /* copy RGB formats in reverse order */ - memcpy(*dst, *src, depth); - memcpy(*dst + depth, *src - depth, depth); - *src -= depth << 1; - *dst += depth << 1; - return; } static void copy_two_pixels(struct vim2m_q_data *q_data_in, @@ -491,7 +488,7 @@ static int device_process(struct vim2m_ctx *ctx, } y_out = 0; - /* Faster copy logic, when format and resolution are identical */ + /* When format and resolution are identical, we can use a faster copy logic */ if (q_data_in->fmt->fourcc == q_data_out->fmt->fourcc && q_data_in->width == q_data_out->width && q_data_in->height == q_data_out->height) { @@ -500,15 +497,15 @@ static int device_process(struct vim2m_ctx *ctx, if (ctx->mode & MEM2MEM_HFLIP) p += bytesperline - (q_data_in->fmt->depth >> 3); - for (x = 0; x < width >> 1; x++) - fast_copy_two_pixels(q_data_in, q_data_out, - &p, &p_out, - ctx->mode & MEM2MEM_HFLIP); + copy_line(q_data_out, p, p_out, + ctx->mode & MEM2MEM_HFLIP); + + p_out += bytesperline; } return 0; } - /* Slower algorithm with format conversion and scaler */ + /* Slower algorithm with format conversion, hflip, vflip and scaler */ /* To speed scaler up, use Bresenham for X dimension */ x_int = q_data_in->width / q_data_out->width;