[{"id":24983,"web_url":"https://patchwork.libcamera.org/comment/24983/","msgid":"<20220914092147.ywwdbz3ftgooedzf@uno.localdomain>","date":"2022-09-14T09:21:47","subject":"Re: [libcamera-devel] [PATCH 02/14] libcamera: v4l2_device:\n\tOverload open() to duplicate File descriptor","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"On Thu, Sep 08, 2022 at 08:48:38PM +0200, Xavier Roumegue via libcamera-devel wrote:\n> Signed-off-by: Xavier Roumegue <xavier.roumegue@oss.nxp.com>\n> ---\n>  include/libcamera/internal/v4l2_device.h |  2 ++\n>  src/libcamera/v4l2_device.cpp            | 33 ++++++++++++++++++++++++\n>  2 files changed, 35 insertions(+)\n>\n> diff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h\n> index 75304be1..8b759311 100644\n> --- a/include/libcamera/internal/v4l2_device.h\n> +++ b/include/libcamera/internal/v4l2_device.h\n> @@ -15,6 +15,7 @@\n>  #include <linux/videodev2.h>\n>\n>  #include <libcamera/base/log.h>\n> +#include <libcamera/base/shared_fd.h>\n>  #include <libcamera/base/signal.h>\n>  #include <libcamera/base/span.h>\n>  #include <libcamera/base/unique_fd.h>\n> @@ -54,6 +55,7 @@ protected:\n>  \t~V4L2Device();\n>\n>  \tint open(unsigned int flags);\n> +\tint open(SharedFD handle);\n>  \tint setFd(UniqueFD fd);\n>\n>  \tint ioctl(unsigned long request, void *argp);\n> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\n> index 756188ea..67847bb0 100644\n> --- a/src/libcamera/v4l2_device.cpp\n> +++ b/src/libcamera/v4l2_device.cpp\n> @@ -102,6 +102,39 @@ int V4L2Device::open(unsigned int flags)\n>  \treturn 0;\n>  }\n>\n> +/**\n> + * \\brief Open a V4L2 device node\n\n\" from a shared file descriptor\"\n\n> + * \\param[in] Shared File descriptor Handle\n\nEither \"FileDescriptor\" or \"file descriptor\"\n\n> + *\n> + * Duplicate a shared file descriptor handle and use it for further device\n> + * syscalls\n\n'.' at the end of the line.\n\nDo we need to specify what is the intended use case instead of saying\nwhat the function does ?\n\n\"Open a V4L2 device from a shared file descriptor. This function is\nused by V4L2 memory-to-memory device where a single video device node\nrepresents multiple capture/output queues.\n\nWith comment on patch 3 addressed\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\nThanks\n  j\n\n> + *\n> + * \\return 0 on success or a negative error code otherwise\n> + */\n> +int V4L2Device::open(SharedFD handle)\n> +{\n> +\tint ret;\n> +\n> +\tUniqueFD newFd = handle.dup();\n> +\tif (!newFd.isValid()) {\n> +\t\tret = -errno;\n> +\t\tLOG(V4L2, Error) << \"Failed to duplicate file handle: \"\n> +\t\t\t\t << strerror(-ret);\n> +\t\treturn ret;\n> +\t}\n> +\n> +\tret = setFd(std::move(newFd));\n> +\tif (ret < 0) {\n> +\t\tLOG(V4L2, Error) << \"Failed to set file handle: \"\n> +\t\t\t\t << strerror(-ret);\n> +\t\treturn ret;\n> +\t}\n> +\n> +\tlistControls();\n> +\n> +\treturn 0;\n> +}\n> +\n>  /**\n>   * \\brief Set the file descriptor of a V4L2 device\n>   * \\param[in] fd The file descriptor handle\n> --\n> 2.37.3\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id DC62AC3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 14 Sep 2022 09:21:52 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 12CE861FA5;\n\tWed, 14 Sep 2022 11:21:52 +0200 (CEST)","from relay10.mail.gandi.net (relay10.mail.gandi.net\n\t[217.70.178.230])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9E3BB6099B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 14 Sep 2022 11:21:49 +0200 (CEST)","(Authenticated sender: jacopo@jmondi.org)\n\tby mail.gandi.net (Postfix) with ESMTPSA id 0849C24000F;\n\tWed, 14 Sep 2022 09:21:48 +0000 (UTC)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1663147312;\n\tbh=nBY+jLleDbo1j6qjP2N42JBjg7PKheAlKLwcOOUfEtI=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=UORyFDryHEFDkcGy4+ZF3xSKs7XPL9mnkixWJdUCyVCbAHilT2+VB1FTNap6fDAsx\n\t7vwL3zMbUQwVOB7Q5L4aFPMQupCjysopbAmC0I8J2s/F+qCEZxRUMoMdcgWEdADoGe\n\tdGgCz1atKOi92v1Y8gxOBuiCs9AjFlGlS1+P+QDV827FMT+ZkTw/qX3ZyEhD866P3G\n\tL6OduFHyIL4j/a4aqZNtGRCwc/cmotRJVrci5WvlPq4/D+8cXxAIAofjONKK1zgxCJ\n\tZb0a0MgiJbWlN7fvjNtINsSY3eRYKBjhLQbMiv/D3/iduwnfPlBsyvA/fuZkVmGzp9\n\tkvJYDopqhhwyw==","Date":"Wed, 14 Sep 2022 11:21:47 +0200","To":"Xavier Roumegue <xavier.roumegue@oss.nxp.com>","Message-ID":"<20220914092147.ywwdbz3ftgooedzf@uno.localdomain>","References":"<20220908184850.1874303-1-xavier.roumegue@oss.nxp.com>\n\t<20220908184850.1874303-3-xavier.roumegue@oss.nxp.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220908184850.1874303-3-xavier.roumegue@oss.nxp.com>","Subject":"Re: [libcamera-devel] [PATCH 02/14] libcamera: v4l2_device:\n\tOverload open() to duplicate File descriptor","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Jacopo Mondi via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]