From patchwork Fri Apr 26 01:22:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Almeida?= X-Patchwork-Id: 10917909 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 63341933 for ; Fri, 26 Apr 2019 01:24:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E59428D3A for ; Fri, 26 Apr 2019 01:24:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4278728D48; Fri, 26 Apr 2019 01:24:28 +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.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY 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 CA65D28D3A for ; Fri, 26 Apr 2019 01:24:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730442AbfDZBY1 (ORCPT ); Thu, 25 Apr 2019 21:24:27 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:36598 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726427AbfDZBY1 (ORCPT ); Thu, 25 Apr 2019 21:24:27 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: tonyk) with ESMTPSA id 559FF2817AB From: =?utf-8?q?Andr=C3=A9_Almeida?= To: linux-media@vger.kernel.org Cc: mchehab@kernel.org, hverkuil@xs4all.nl, helen.koike@collabora.com, kernel@collabora.com, lucmaga@gmail.com, lkcamp@lists.libreplanetbr.org, =?utf-8?q?Andr=C3=A9_Almeida?= Subject: [PATCH v4 05/14] media: vimc: cap: refactor singleplanar as a subset of multiplanar Date: Thu, 25 Apr 2019 22:22:14 -0300 Message-Id: <20190426012223.17826-6-andrealmeid@collabora.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190426012223.17826-1-andrealmeid@collabora.com> References: <20190426012223.17826-1-andrealmeid@collabora.com> 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 Since multiplanar is a superset of single planar formats, instead of having different implementations for them, treat all formats as multiplanar. If we need to work with single planar formats, convert them to multiplanar (with num_planes = 1), re-use the multiplanar code, and transform them back to single planar. This is implemented with v4l2_fmt_sp2mp_func(). Signed-off-by: André Almeida Acked-by: Helen Koike --- Changes in v4: - Add comment that was in wrong commit - Check the return of try_fmt function Changes in v3: - Commit title renamed - Get rid of `if (IS_MULTIPLANAR(vcap))` checks and functions to do this check Changes in v2: - Make more clear that the generic function _vimc_cap_try_fmt_vid_cap_mp expects a multiplanar format as input drivers/media/platform/vimc/vimc-capture.c | 57 ++++++++++++++-------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/drivers/media/platform/vimc/vimc-capture.c b/drivers/media/platform/vimc/vimc-capture.c index ae703c52d3f8..fa0d75eb06e8 100644 --- a/drivers/media/platform/vimc/vimc-capture.c +++ b/drivers/media/platform/vimc/vimc-capture.c @@ -118,6 +118,9 @@ static void vimc_cap_get_format(struct vimc_ent_device *ved, *fmt = vcap->format.fmt.pix; } +/* + * Functions to handle both single- and multi-planar VIDIOC FMT + */ static int vimc_cap_g_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) { @@ -128,10 +131,10 @@ static int vimc_cap_g_fmt_vid_cap(struct file *file, void *priv, return 0; } -static int vimc_cap_try_fmt_vid_cap(struct file *file, void *priv, - struct v4l2_format *f) +static int vimc_cap_try_fmt_vid_cap_mp(struct file *file, void *priv, + struct v4l2_format *f) { - struct v4l2_pix_format *format = &f->fmt.pix; + struct v4l2_pix_format_mplane *format = &f->fmt.pix_mp; format->width = clamp_t(u32, format->width, VIMC_FRAME_MIN_WIDTH, VIMC_FRAME_MAX_WIDTH) & ~1; @@ -149,20 +152,43 @@ static int vimc_cap_try_fmt_vid_cap(struct file *file, void *priv, if (!v4l2_format_info(format->pixelformat)) format->pixelformat = fmt_default.fmt.pix.pixelformat; - return v4l2_fill_pixfmt(format, format->pixelformat, - format->width, format->height); + return v4l2_fill_pixfmt_mp(format, format->pixelformat, + format->width, format->height); } -static int vimc_cap_s_fmt_vid_cap(struct file *file, void *priv, - struct v4l2_format *f) +static int vimc_cap_enum_fmt_vid_cap(struct file *file, void *priv, + struct v4l2_fmtdesc *f) +{ + if (f->index >= ARRAY_SIZE(vimc_cap_supported_pixfmt)) + return -EINVAL; + + f->pixelformat = vimc_cap_supported_pixfmt[f->index]; + + return 0; +} + +/* + * VIDIOC FMT handlers for single-planar + */ +static int vimc_cap_try_fmt_vid_cap_sp(struct file *file, void *priv, + struct v4l2_format *f) +{ + return v4l2_fmt_sp2mp_func(file, priv, f, vimc_cap_try_fmt_vid_cap_mp); +} + +static int vimc_cap_s_fmt_vid_cap_sp(struct file *file, void *priv, + struct v4l2_format *f) { struct vimc_cap_device *vcap = video_drvdata(file); + int ret; /* Do not change the format while stream is on */ if (vb2_is_busy(&vcap->queue)) return -EBUSY; - vimc_cap_try_fmt_vid_cap(file, priv, f); + ret = v4l2_fmt_sp2mp_func(file, priv, f, vimc_cap_try_fmt_vid_cap_mp); + if (ret) + return ret; dev_dbg(vcap->dev, "%s: format update: " "old:%dx%d (0x%x, %d, %d, %d, %d) " @@ -185,17 +211,6 @@ static int vimc_cap_s_fmt_vid_cap(struct file *file, void *priv, return 0; } -static int vimc_cap_enum_fmt_vid_cap(struct file *file, void *priv, - struct v4l2_fmtdesc *f) -{ - if (f->index >= ARRAY_SIZE(vimc_cap_supported_pixfmt)) - return -EINVAL; - - f->pixelformat = vimc_cap_supported_pixfmt[f->index]; - - return 0; -} - static bool vimc_cap_is_pixfmt_supported(u32 pixelformat) { unsigned int i; @@ -240,8 +255,8 @@ static const struct v4l2_ioctl_ops vimc_cap_ioctl_ops = { .vidioc_querycap = vimc_cap_querycap, .vidioc_g_fmt_vid_cap = vimc_cap_g_fmt_vid_cap, - .vidioc_s_fmt_vid_cap = vimc_cap_s_fmt_vid_cap, - .vidioc_try_fmt_vid_cap = vimc_cap_try_fmt_vid_cap, + .vidioc_s_fmt_vid_cap = vimc_cap_s_fmt_vid_cap_sp, + .vidioc_try_fmt_vid_cap = vimc_cap_try_fmt_vid_cap_sp, .vidioc_enum_fmt_vid_cap = vimc_cap_enum_fmt_vid_cap, .vidioc_enum_framesizes = vimc_cap_enum_framesizes,