Received: by 2002:ac0:a874:0:0:0:0:0 with SMTP id c49csp603008ima; Fri, 15 Mar 2019 09:46:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqwk+N84aTGww8Q1cKdxxy+KfxIsRDKZszrpCRfE5NT+RHvlVjyXGCD6/ysE9fB9iEbt+rrO X-Received: by 2002:a62:6ec3:: with SMTP id j186mr5150982pfc.89.1552668361796; Fri, 15 Mar 2019 09:46:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552668361; cv=none; d=google.com; s=arc-20160816; b=h6XEd/FMc3MILdt+ZpCOkYGB5g26ZjHHxhKmrfNv3oLP4LzaLGVdxnKuSLgCc5wiYn b2WYyzicxsNa9us5ed2Q+joosP/nSQ8OScXceIe06Z2x8w4UTdSm8THMtUVJ0ktLi4X6 ellHmaep/hylRdhIHo3MiiDtWMooXxI8qLOPzx2+1TW1pOGHsndg6Ck4NxwlzHUj5d6z QEje6DpFk8+PJp8VkhSioVdNFmTRJp+DdmT8eToZz/ANJHaD5UYMu7brloMgcexEMauE rHaRZAlWjgydHw6O+Ud7p2LXaekVOnsGWTUdaUPwaTgujT47UmlI1lIUbkrUzsNgQW/D jj/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=nh225TdJm6JB/JzvKGOW9urS4lB1JdAiIx/Mcr5dr70=; b=SmCe+gBBpKNgSJXvvU3rmaJnHq2bXH93vB7CQDppPEchweGhje2O/eqoO5UonCM5FX nYUnysiggLLGRlML8k1rNWKnt/tZlt2KQj/8cQ7hLA3Kk9HIiaLDi/xs+coStfHFS8MM SJ4M9am1GGEjTTOMPLCbiP1sSAgPKmGec9N1KljqQP5zI7cPa9D628B9edUrIIw/6T4Y GVJNGKgMCVaIhhhcnLVczwdQWvilDSSteRx1y9BdyfklxYU+kIzEFeYgYzns4DmqcE6Y 0avgSRINR9me0WCyE1z3y9nFotjBbRej6uMJ2tguHtN9rdpwIg26J0pQQ2dbLbjXDYnl WGLA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z78si2357413pfi.51.2019.03.15.09.45.45; Fri, 15 Mar 2019 09:46:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729656AbfCOQpD (ORCPT + 99 others); Fri, 15 Mar 2019 12:45:03 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:48972 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728182AbfCOQpC (ORCPT ); Fri, 15 Mar 2019 12:45:02 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: tonyk) with ESMTPSA id E2325260215 From: =?UTF-8?q?Andr=C3=A9=20Almeida?= To: linux-media@vger.kernel.org Cc: mchehab@kernel.org, hverkuil@xs4all.nl, helen.koike@collabora.com, lucmaga@gmail.com, linux-kernel@vger.kernel.org, kernel@collabora.com Subject: [PATCH 01/16] media: Move sp2mp functions to v4l2-common Date: Fri, 15 Mar 2019 13:43:44 -0300 Message-Id: <20190315164359.626-2-andrealmeid@collabora.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190315164359.626-1-andrealmeid@collabora.com> References: <20190315164359.626-1-andrealmeid@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move sp2mp functions from vivid cote to v4l2-common as it will be reused by vimc driver for multiplanar support. Signed-off-by: André Almeida --- drivers/media/platform/vivid/vivid-vid-cap.c | 6 +- .../media/platform/vivid/vivid-vid-common.c | 59 ------------------ .../media/platform/vivid/vivid-vid-common.h | 9 --- drivers/media/platform/vivid/vivid-vid-out.c | 6 +- drivers/media/v4l2-core/v4l2-common.c | 62 +++++++++++++++++++ include/media/v4l2-common.h | 31 ++++++++++ 6 files changed, 99 insertions(+), 74 deletions(-) diff --git a/drivers/media/platform/vivid/vivid-vid-cap.c b/drivers/media/platform/vivid/vivid-vid-cap.c index 52eeda624d7e..b5ad71bbf7bf 100644 --- a/drivers/media/platform/vivid/vivid-vid-cap.c +++ b/drivers/media/platform/vivid/vivid-vid-cap.c @@ -815,7 +815,7 @@ int vidioc_g_fmt_vid_cap(struct file *file, void *priv, if (dev->multiplanar) return -ENOTTY; - return fmt_sp2mp_func(file, priv, f, vivid_g_fmt_vid_cap); + return v4l2_fmt_sp2mp_func(file, priv, f, vivid_g_fmt_vid_cap); } int vidioc_try_fmt_vid_cap(struct file *file, void *priv, @@ -825,7 +825,7 @@ int vidioc_try_fmt_vid_cap(struct file *file, void *priv, if (dev->multiplanar) return -ENOTTY; - return fmt_sp2mp_func(file, priv, f, vivid_try_fmt_vid_cap); + return v4l2_fmt_sp2mp_func(file, priv, f, vivid_try_fmt_vid_cap); } int vidioc_s_fmt_vid_cap(struct file *file, void *priv, @@ -835,7 +835,7 @@ int vidioc_s_fmt_vid_cap(struct file *file, void *priv, if (dev->multiplanar) return -ENOTTY; - return fmt_sp2mp_func(file, priv, f, vivid_s_fmt_vid_cap); + return v4l2_fmt_sp2mp_func(file, priv, f, vivid_s_fmt_vid_cap); } int vivid_vid_cap_g_selection(struct file *file, void *priv, diff --git a/drivers/media/platform/vivid/vivid-vid-common.c b/drivers/media/platform/vivid/vivid-vid-common.c index 74b83bcc6119..3dd3a05d2e67 100644 --- a/drivers/media/platform/vivid/vivid-vid-common.c +++ b/drivers/media/platform/vivid/vivid-vid-common.c @@ -674,65 +674,6 @@ void vivid_send_source_change(struct vivid_dev *dev, unsigned type) } } -/* - * Conversion function that converts a single-planar format to a - * single-plane multiplanar format. - */ -void fmt_sp2mp(const struct v4l2_format *sp_fmt, struct v4l2_format *mp_fmt) -{ - struct v4l2_pix_format_mplane *mp = &mp_fmt->fmt.pix_mp; - struct v4l2_plane_pix_format *ppix = &mp->plane_fmt[0]; - const struct v4l2_pix_format *pix = &sp_fmt->fmt.pix; - bool is_out = sp_fmt->type == V4L2_BUF_TYPE_VIDEO_OUTPUT; - - memset(mp->reserved, 0, sizeof(mp->reserved)); - mp_fmt->type = is_out ? V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE : - V4L2_CAP_VIDEO_CAPTURE_MPLANE; - mp->width = pix->width; - mp->height = pix->height; - mp->pixelformat = pix->pixelformat; - mp->field = pix->field; - mp->colorspace = pix->colorspace; - mp->xfer_func = pix->xfer_func; - /* Also copies hsv_enc */ - mp->ycbcr_enc = pix->ycbcr_enc; - mp->quantization = pix->quantization; - mp->num_planes = 1; - mp->flags = pix->flags; - ppix->sizeimage = pix->sizeimage; - ppix->bytesperline = pix->bytesperline; - memset(ppix->reserved, 0, sizeof(ppix->reserved)); -} - -int fmt_sp2mp_func(struct file *file, void *priv, - struct v4l2_format *f, fmtfunc func) -{ - struct v4l2_format fmt; - struct v4l2_pix_format_mplane *mp = &fmt.fmt.pix_mp; - struct v4l2_plane_pix_format *ppix = &mp->plane_fmt[0]; - struct v4l2_pix_format *pix = &f->fmt.pix; - int ret; - - /* Converts to a mplane format */ - fmt_sp2mp(f, &fmt); - /* Passes it to the generic mplane format function */ - ret = func(file, priv, &fmt); - /* Copies back the mplane data to the single plane format */ - pix->width = mp->width; - pix->height = mp->height; - pix->pixelformat = mp->pixelformat; - pix->field = mp->field; - pix->colorspace = mp->colorspace; - pix->xfer_func = mp->xfer_func; - /* Also copies hsv_enc */ - pix->ycbcr_enc = mp->ycbcr_enc; - pix->quantization = mp->quantization; - pix->sizeimage = ppix->sizeimage; - pix->bytesperline = ppix->bytesperline; - pix->flags = mp->flags; - return ret; -} - int vivid_vid_adjust_sel(unsigned flags, struct v4l2_rect *r) { unsigned w = r->width; diff --git a/drivers/media/platform/vivid/vivid-vid-common.h b/drivers/media/platform/vivid/vivid-vid-common.h index 29b6c0b40a1b..13adea56baa0 100644 --- a/drivers/media/platform/vivid/vivid-vid-common.h +++ b/drivers/media/platform/vivid/vivid-vid-common.h @@ -8,15 +8,6 @@ #ifndef _VIVID_VID_COMMON_H_ #define _VIVID_VID_COMMON_H_ -typedef int (*fmtfunc)(struct file *file, void *priv, struct v4l2_format *f); - -/* - * Conversion function that converts a single-planar format to a - * single-plane multiplanar format. - */ -void fmt_sp2mp(const struct v4l2_format *sp_fmt, struct v4l2_format *mp_fmt); -int fmt_sp2mp_func(struct file *file, void *priv, - struct v4l2_format *f, fmtfunc func); extern const struct v4l2_dv_timings_cap vivid_dv_timings_cap; diff --git a/drivers/media/platform/vivid/vivid-vid-out.c b/drivers/media/platform/vivid/vivid-vid-out.c index e61b91b414f9..c42ba5ade6cf 100644 --- a/drivers/media/platform/vivid/vivid-vid-out.c +++ b/drivers/media/platform/vivid/vivid-vid-out.c @@ -612,7 +612,7 @@ int vidioc_g_fmt_vid_out(struct file *file, void *priv, if (dev->multiplanar) return -ENOTTY; - return fmt_sp2mp_func(file, priv, f, vivid_g_fmt_vid_out); + return v4l2_fmt_sp2mp_func(file, priv, f, vivid_g_fmt_vid_out); } int vidioc_try_fmt_vid_out(struct file *file, void *priv, @@ -622,7 +622,7 @@ int vidioc_try_fmt_vid_out(struct file *file, void *priv, if (dev->multiplanar) return -ENOTTY; - return fmt_sp2mp_func(file, priv, f, vivid_try_fmt_vid_out); + return v4l2_fmt_sp2mp_func(file, priv, f, vivid_try_fmt_vid_out); } int vidioc_s_fmt_vid_out(struct file *file, void *priv, @@ -632,7 +632,7 @@ int vidioc_s_fmt_vid_out(struct file *file, void *priv, if (dev->multiplanar) return -ENOTTY; - return fmt_sp2mp_func(file, priv, f, vivid_s_fmt_vid_out); + return v4l2_fmt_sp2mp_func(file, priv, f, vivid_s_fmt_vid_out); } int vivid_vid_out_g_selection(struct file *file, void *priv, diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c index 779e44d6db43..d118f8f34d32 100644 --- a/drivers/media/v4l2-core/v4l2-common.c +++ b/drivers/media/v4l2-core/v4l2-common.c @@ -653,3 +653,65 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, int pixelformat, int width, return 0; } EXPORT_SYMBOL_GPL(v4l2_fill_pixfmt); + +/* + * Conversion functions that convert a single-planar format to a + * multi-planar format. + */ +void v4l2_fmt_sp2mp(const struct v4l2_format *sp_fmt, + struct v4l2_format *mp_fmt) +{ + struct v4l2_pix_format_mplane *mp = &mp_fmt->fmt.pix_mp; + struct v4l2_plane_pix_format *ppix = &mp->plane_fmt[0]; + const struct v4l2_pix_format *pix = &sp_fmt->fmt.pix; + bool is_out = sp_fmt->type == V4L2_BUF_TYPE_VIDEO_OUTPUT; + + memset(mp->reserved, 0, sizeof(mp->reserved)); + mp_fmt->type = is_out ? V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE : + V4L2_CAP_VIDEO_CAPTURE_MPLANE; + mp->width = pix->width; + mp->height = pix->height; + mp->pixelformat = pix->pixelformat; + mp->field = pix->field; + mp->colorspace = pix->colorspace; + mp->xfer_func = pix->xfer_func; + /* Also copies hsv_enc */ + mp->ycbcr_enc = pix->ycbcr_enc; + mp->quantization = pix->quantization; + mp->num_planes = 1; + mp->flags = pix->flags; + ppix->sizeimage = pix->sizeimage; + ppix->bytesperline = pix->bytesperline; + memset(ppix->reserved, 0, sizeof(ppix->reserved)); +} +EXPORT_SYMBOL_GPL(v4l2_fmt_sp2mp); + +int v4l2_fmt_sp2mp_func(struct file *file, void *priv, + struct v4l2_format *f, v4l2_fmtfunc func) +{ + struct v4l2_format fmt; + struct v4l2_pix_format_mplane *mp = &fmt.fmt.pix_mp; + struct v4l2_plane_pix_format *ppix = &mp->plane_fmt[0]; + struct v4l2_pix_format *pix = &f->fmt.pix; + int ret; + + /* Converts to a mplane format */ + v4l2_fmt_sp2mp(f, &fmt); + /* Passes it to the generic mplane format function */ + ret = func(file, priv, &fmt); + /* Copies back the mplane data to the single plane format */ + pix->width = mp->width; + pix->height = mp->height; + pix->pixelformat = mp->pixelformat; + pix->field = mp->field; + pix->colorspace = mp->colorspace; + pix->xfer_func = mp->xfer_func; + /* Also copies hsv_enc */ + pix->ycbcr_enc = mp->ycbcr_enc; + pix->quantization = mp->quantization; + pix->sizeimage = ppix->sizeimage; + pix->bytesperline = ppix->bytesperline; + pix->flags = mp->flags; + return ret; +} +EXPORT_SYMBOL_GPL(v4l2_fmt_sp2mp_func); diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h index 937b74a946cd..d106f36ebaf4 100644 --- a/include/media/v4l2-common.h +++ b/include/media/v4l2-common.h @@ -424,4 +424,35 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, int pixelformat, int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, int pixelformat, int width, int height); +/** + * v4l2_fmtfunc - type to be used by v4l2_fmt_sp2mp_func to pass the generic + * mp function as argument + * @file: device's descriptor file + * @priv: private data pointer + * @f: format that holds a mp pixel format + */ +typedef int (*v4l2_fmtfunc)(struct file *file, void *priv, + struct v4l2_format *f); + +/** + * v4l2_fmt_sp2mp - transforms a single-planar format struct into a multi-planar + * struct + * @sp_fmt: pointer to the single-planar format struct (in) + * @mp_fmt: pointer to the multi-planar format struct (out) + */ +void v4l2_fmt_sp2mp(const struct v4l2_format *sp_fmt, + struct v4l2_format *mp_fmt); + +/** + * v4l2_fmt_sp2mp_func - handler to call a generic multi-planar format function + * using single-planar format. It converts the sp to a mp, calls the + * function and converts mp back to sp. + * @file: device's descriptor file + * @priv: private data pointer + * @f: format that holds a sp pixel format + * @func: generic mp function + */ +int v4l2_fmt_sp2mp_func(struct file *file, void *priv, + struct v4l2_format *f, v4l2_fmtfunc func); + #endif /* V4L2_COMMON_H_ */ -- 2.21.0