From patchwork Tue Jun 23 19:08:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 4175 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3A971609C4 for ; Tue, 23 Jun 2020 21:09:05 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="BJnDKxK1"; dkim-atps=neutral Received: from jade.rasen.tech (unknown [IPv6:2400:4051:61:600:8147:f2a2:a8c6:9087]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 481C42A9; Tue, 23 Jun 2020 21:09:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1592939344; bh=VeCFJATKtInuOjDMzMyeOpt7r0xRQBA/flQvr3Jr5ic=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BJnDKxK1+hGHP9gdfeYdYjBEhKOUOU1DQFF6uc/LTSWQM9cmlPymnq6RU+fqiOacb IzkG0IxJdlHJ6y2Hqds9Wxu9deAAxFqsvdIMZkZtLj+UrgC6A+4/4MTgTPHtWd/+fH G7OGXbbW8F8plOONsh0nLzY56r9Q0hxiQn099fVE= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Wed, 24 Jun 2020 04:08:15 +0900 Message-Id: <20200623190836.53446-2-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200623190836.53446-1-paul.elder@ideasonboard.com> References: <20200623190836.53446-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 01/22] v4l2: v4l2_camera_file: Add V4L2CameraFile to model the opened camera file 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: Tue, 23 Jun 2020 19:09:05 -0000 With relation to opening files, the kernel has three objects related to files: - inodes, that represent files on disk - file objects, that are allocated at open() time and store all data related to the open file - file descriptors, that are integers that map to a file In the V4L2 compatibility layer, V4L2CameraProxy, which wraps a single libcamera camera via V4L2Camera, is more or less equivalent to the inode. We also already have file descriptors (that are really eventfds) that mirror the file descriptors. Here we create a V4L2CameraFile to model the file objects, to contain information related to the open file, namely if the file has been opened as non-blocking, and the V4L2 priority (to support VIDIOC_G/S_PRIORITY later on). This new class allows us to more cleanly support multiple open later on, since we can move out of V4L2CameraProxy the handling of mapping the fd to the open file information. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart --- Changes in v3: - cosmetic changes - change public V4L2CameraFile::priority_ to private with public getter and setter New in v2 --- src/v4l2/meson.build | 1 + src/v4l2/v4l2_camera_file.cpp | 26 ++++++++++++++++++++++++ src/v4l2/v4l2_camera_file.h | 37 +++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 src/v4l2/v4l2_camera_file.cpp create mode 100644 src/v4l2/v4l2_camera_file.h diff --git a/src/v4l2/meson.build b/src/v4l2/meson.build index f2e4aaf..e3838f0 100644 --- a/src/v4l2/meson.build +++ b/src/v4l2/meson.build @@ -2,6 +2,7 @@ v4l2_compat_sources = files([ 'v4l2_camera.cpp', + 'v4l2_camera_file.cpp', 'v4l2_camera_proxy.cpp', 'v4l2_compat.cpp', 'v4l2_compat_manager.cpp', diff --git a/src/v4l2/v4l2_camera_file.cpp b/src/v4l2/v4l2_camera_file.cpp new file mode 100644 index 0000000..d3232ab --- /dev/null +++ b/src/v4l2/v4l2_camera_file.cpp @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2020, Google Inc. + * + * v4l2_camera_file.h - V4L2 compatibility camera file information + */ + +#include "v4l2_camera_file.h" + +#include + +#include "v4l2_camera_proxy.h" + +using namespace libcamera; + +V4L2CameraFile::V4L2CameraFile(int efd, bool nonBlocking, V4L2CameraProxy *proxy) + : proxy_(proxy), nonBlocking_(nonBlocking), efd_(efd), + priority_(V4L2_PRIORITY_DEFAULT) +{ + proxy_->open(nonBlocking); +} + +V4L2CameraFile::~V4L2CameraFile() +{ + proxy_->close(); +} diff --git a/src/v4l2/v4l2_camera_file.h b/src/v4l2/v4l2_camera_file.h new file mode 100644 index 0000000..8f4670a --- /dev/null +++ b/src/v4l2/v4l2_camera_file.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2020, Google Inc. + * + * v4l2_camera_file.h - V4L2 compatibility camera file information + */ + +#ifndef __V4L2_CAMERA_FILE_H__ +#define __V4L2_CAMERA_FILE_H__ + +#include + +class V4L2CameraProxy; + +class V4L2CameraFile +{ +public: + V4L2CameraFile(int efd, bool nonBlocking, V4L2CameraProxy *proxy); + ~V4L2CameraFile(); + + V4L2CameraProxy *proxy() const { return proxy_; } + + bool nonBlocking() const { return nonBlocking_; } + int efd() const { return efd_; } + + enum v4l2_priority priority() const { return priority_; } + void setPriority(enum v4l2_priority priority) { priority_ = priority; } + +private: + V4L2CameraProxy *proxy_; + + bool nonBlocking_; + int efd_; + enum v4l2_priority priority_; +}; + +#endif /* __V4L2_CAMERA_FILE_H__ */