From patchwork Wed Jan 8 10:17:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2529 Return-Path: Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 377BD6045F for ; Wed, 8 Jan 2020 11:15:07 +0100 (CET) Received: from uno.lan (93-34-114-233.ip49.fastwebnet.it [93.34.114.233]) (Authenticated sender: jacopo@jmondi.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 81371100011; Wed, 8 Jan 2020 10:15:06 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 8 Jan 2020 11:17:23 +0100 Message-Id: <20200108101725.6404-2-jacopo@jmondi.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200108101725.6404-1-jacopo@jmondi.org> References: <20200108101725.6404-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/3] v4l2: camera_proxy: Fix try_fmt format conversion X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Jan 2020 10:15:07 -0000 The set pixelformat field of struct v4l2_pix_format structure was wrongly converted to PixelFormat by calling v4l2ToDrm(), with an already converted 'format' argument. Fix this by calling the right drmToV4l2() conversion function. Fixes: 0ce8f2390b52 ("v4l2: v4l2_compat: Add V4L2 compatibility layer") Reviewed-by: Laurent Pinchart Signed-off-by: Jacopo Mondi --- src/v4l2/v4l2_camera_proxy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp index 8d1b40da7367..0f1d5ea4be39 100644 --- a/src/v4l2/v4l2_camera_proxy.cpp +++ b/src/v4l2/v4l2_camera_proxy.cpp @@ -282,7 +282,7 @@ int V4L2CameraProxy::vidioc_try_fmt(struct v4l2_format *arg) arg->fmt.pix.width = size.width; arg->fmt.pix.height = size.height; - arg->fmt.pix.pixelformat = v4l2ToDrm(format); + arg->fmt.pix.pixelformat = drmToV4L2(format); arg->fmt.pix.field = V4L2_FIELD_NONE; arg->fmt.pix.bytesperline = bplMultiplier(drmToV4L2(format)) * arg->fmt.pix.width; From patchwork Wed Jan 8 10:17:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2530 Return-Path: Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3C59B60668 for ; Wed, 8 Jan 2020 11:15:08 +0100 (CET) Received: from uno.lan (93-34-114-233.ip49.fastwebnet.it [93.34.114.233]) (Authenticated sender: jacopo@jmondi.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 7FB77100010; Wed, 8 Jan 2020 10:15:07 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 8 Jan 2020 11:17:24 +0100 Message-Id: <20200108101725.6404-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200108101725.6404-1-jacopo@jmondi.org> References: <20200108101725.6404-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/3] v4l2: camera_proxy: Break out try_fmt X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Jan 2020 10:15:08 -0000 Calling vidioc_s_fmt() calls vidioc_try_fmt() duplicating prinouts. Breakout try format procedure and call it from both functions. Reviewed-by: Laurent Pinchart Signed-off-by: Jacopo Mondi --- src/v4l2/v4l2_camera_proxy.cpp | 54 +++++++++++++++++++--------------- src/v4l2/v4l2_camera_proxy.h | 1 + 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp index 0f1d5ea4be39..f3a49fea2a5a 100644 --- a/src/v4l2/v4l2_camera_proxy.cpp +++ b/src/v4l2/v4l2_camera_proxy.cpp @@ -235,13 +235,39 @@ int V4L2CameraProxy::vidioc_g_fmt(struct v4l2_format *arg) return 0; } +void V4L2CameraProxy::tryFormat(struct v4l2_format *arg) +{ + PixelFormat format = v4l2ToDrm(arg->fmt.pix.pixelformat); + const std::vector &formats = + streamConfig_.formats().pixelformats(); + if (std::find(formats.begin(), formats.end(), format) == formats.end()) + format = streamConfig_.formats().pixelformats()[0]; + + Size size(arg->fmt.pix.width, arg->fmt.pix.height); + const std::vector &sizes = streamConfig_.formats().sizes(format); + if (std::find(sizes.begin(), sizes.end(), size) == sizes.end()) + size = streamConfig_.formats().sizes(format)[0]; + + arg->fmt.pix.width = size.width; + arg->fmt.pix.height = size.height; + arg->fmt.pix.pixelformat = drmToV4L2(format); + arg->fmt.pix.field = V4L2_FIELD_NONE; + arg->fmt.pix.bytesperline = bplMultiplier(drmToV4L2(format)) * + arg->fmt.pix.width; + arg->fmt.pix.sizeimage = imageSize(drmToV4L2(format), + arg->fmt.pix.width, + arg->fmt.pix.height); + arg->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB; +} + int V4L2CameraProxy::vidioc_s_fmt(struct v4l2_format *arg) { LOG(V4L2Compat, Debug) << "Servicing vidioc_s_fmt"; - int ret = vidioc_try_fmt(arg); - if (ret < 0) - return ret; + if (!validateBufferType(arg->type)) + return -EINVAL; + + tryFormat(arg); Size size(arg->fmt.pix.width, arg->fmt.pix.height); ret = vcam_->invokeMethod(&V4L2Camera::configure, @@ -269,27 +295,7 @@ int V4L2CameraProxy::vidioc_try_fmt(struct v4l2_format *arg) if (!validateBufferType(arg->type)) return -EINVAL; - PixelFormat format = v4l2ToDrm(arg->fmt.pix.pixelformat); - const std::vector &formats = - streamConfig_.formats().pixelformats(); - if (std::find(formats.begin(), formats.end(), format) == formats.end()) - format = streamConfig_.formats().pixelformats()[0]; - - Size size(arg->fmt.pix.width, arg->fmt.pix.height); - const std::vector &sizes = streamConfig_.formats().sizes(format); - if (std::find(sizes.begin(), sizes.end(), size) == sizes.end()) - size = streamConfig_.formats().sizes(format)[0]; - - arg->fmt.pix.width = size.width; - arg->fmt.pix.height = size.height; - arg->fmt.pix.pixelformat = drmToV4L2(format); - arg->fmt.pix.field = V4L2_FIELD_NONE; - arg->fmt.pix.bytesperline = bplMultiplier(drmToV4L2(format)) * - arg->fmt.pix.width; - arg->fmt.pix.sizeimage = imageSize(drmToV4L2(format), - arg->fmt.pix.width, - arg->fmt.pix.height); - arg->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB; + tryFormat(arg); return 0; } diff --git a/src/v4l2/v4l2_camera_proxy.h b/src/v4l2/v4l2_camera_proxy.h index 3d702084f8ff..b59d19d70759 100644 --- a/src/v4l2/v4l2_camera_proxy.h +++ b/src/v4l2/v4l2_camera_proxy.h @@ -39,6 +39,7 @@ private: void setFmtFromConfig(StreamConfiguration &streamConfig); unsigned int calculateSizeImage(StreamConfiguration &streamConfig); void querycap(std::shared_ptr camera); + void tryFormat(struct v4l2_format *arg); void updateBuffers(); int freeBuffers(); From patchwork Wed Jan 8 10:17:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2531 Return-Path: Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D234B60668 for ; Wed, 8 Jan 2020 11:15:08 +0100 (CET) Received: from uno.lan (93-34-114-233.ip49.fastwebnet.it [93.34.114.233]) (Authenticated sender: jacopo@jmondi.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 6ED2D10000F; Wed, 8 Jan 2020 10:15:08 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 8 Jan 2020 11:17:25 +0100 Message-Id: <20200108101725.6404-4-jacopo@jmondi.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200108101725.6404-1-jacopo@jmondi.org> References: <20200108101725.6404-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/3] v4l2: camera_proxy: Align trace message style X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Jan 2020 10:15:09 -0000 Most of the ioctl handlers in the V4L2CameraProxy class have an empty line between the tracing printouts and the immediately following buffer type validation. Align the two ones where such an empy line is missing with the others. Cosmetic change only. Signed-off-by: Jacopo Mondi Reviewed-by: Kieran Bingham --- src/v4l2/v4l2_camera_proxy.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp index f3a49fea2a5a..89dd7166ca52 100644 --- a/src/v4l2/v4l2_camera_proxy.cpp +++ b/src/v4l2/v4l2_camera_proxy.cpp @@ -292,6 +292,7 @@ int V4L2CameraProxy::vidioc_s_fmt(struct v4l2_format *arg) int V4L2CameraProxy::vidioc_try_fmt(struct v4l2_format *arg) { LOG(V4L2Compat, Debug) << "Servicing vidioc_try_fmt"; + if (!validateBufferType(arg->type)) return -EINVAL; @@ -321,6 +322,7 @@ int V4L2CameraProxy::vidioc_reqbufs(struct v4l2_requestbuffers *arg) int ret; LOG(V4L2Compat, Debug) << "Servicing vidioc_reqbufs"; + if (!validateBufferType(arg->type) || !validateMemoryType(arg->memory)) return -EINVAL;