From patchwork Tue Aug 13 09:40:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 1800 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3819060E2E for ; Tue, 13 Aug 2019 11:40:25 +0200 (CEST) Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7F7D5327; Tue, 13 Aug 2019 11:40:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1565689224; bh=xI2XcWja3BLJ6a0uba0Qub2XZnAnpLCWWkJyhpEgTXM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l23AjlQbYzPz+56z+lqA/dbwag8evyov10QUHJ5YheOmenB7BWG+gLk2pnX+etQjF gRBmDFt26D88OoppIM0c4Qh+j8NCTVtSXWuFqdXjaH8QGWmvNJvgrjzynDTVJpnUkx g/SzTzcH6tt8wGZ995GesK60hhiZbGQ32F/KoZ2I= From: Kieran Bingham To: LibCamera Devel Date: Tue, 13 Aug 2019 10:40:15 +0100 Message-Id: <20190813094020.10277-2-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190813094020.10277-1-kieran.bingham@ideasonboard.com> References: <20190813094020.10277-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 1/6] libcamera: v4l2_device: Add setFd() X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Aug 2019 09:40:25 -0000 Provide a means for V4L2 device instances to set the fd_ explicitly. This allows for V4L2Devices to operate when they must use an external open() call. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- src/libcamera/include/v4l2_device.h | 1 + src/libcamera/v4l2_device.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h index e7e9829cb05f..75a52c33d821 100644 --- a/src/libcamera/include/v4l2_device.h +++ b/src/libcamera/include/v4l2_device.h @@ -35,6 +35,7 @@ protected: ~V4L2Device(); int open(unsigned int flags); + int setFd(int fd); int ioctl(unsigned long request, void *argp); diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 9a00566a532b..f89546610ac6 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -88,6 +88,32 @@ int V4L2Device::open(unsigned int flags) return 0; } +/** + * \brief Set the file descriptor of a V4L2 device + * \param[in] fd The file descriptor handle + * + * This method allows a device to provide an already opened file descriptor + * referring to the V4L2 device node, instead of opening it with open(). This + * can be used for V4L2 M2M devices where a single video device node is used for + * both the output and capture devices, or when receiving an open file + * descriptor in a context that doesn't have permission to open the device node + * itself. + * + * This method and the open() method are mutually exclusive, only one of the two + * shall be used for a V4L2Device instance. + * + * \return 0 on success or a negative error code otherwise + */ +int V4L2Device::setFd(int fd) +{ + if (isOpen()) + return -EBUSY; + + fd_ = fd; + + return 0; +} + /** * \brief Close the device node *