From patchwork Mon Jan 21 23:06:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 317 Return-Path: Received: from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net [195.74.38.229]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5D08360B2D for ; Tue, 22 Jan 2019 00:07:15 +0100 (CET) X-Halon-ID: 4916dae7-1dd1-11e9-874f-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id 4916dae7-1dd1-11e9-874f-005056917f90; Tue, 22 Jan 2019 00:07:12 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 22 Jan 2019 00:06:37 +0100 Message-Id: <20190121230640.8783-2-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190121230640.8783-1-niklas.soderlund@ragnatech.se> References: <20190121230640.8783-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC 1/4] libcamera: camera: Add acquire() and release() 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: Mon, 21 Jan 2019 23:07:15 -0000 From: Laurent Pinchart --- include/libcamera/camera.h | 5 +++++ src/libcamera/camera.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index 2ea1a6883311cf9f..03b285c840c246e1 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -22,11 +22,16 @@ public: const std::string &name() const; + int acquire(); + void release(); + private: explicit Camera(const std::string &name); ~Camera(); std::string name_; + + bool acquired_; }; } /* namespace libcamera */ diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index acf912bee95cbec4..b80bc36e410a6e0a 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -92,4 +92,37 @@ Camera::~Camera() { } +/** + * \brief Acquire the camera device for exclusive access + * + * After opening the device with open(), exclusive access must be obtained + * before performing operations that change the device state. This function is + * not blocking, if the device has already been acquired (by the same or another + * process) the -EBUSY error code is returned. + * + * Once exclusive access isn't needed anymore, the device should be released + * with a call to the release() function. + * + * \return 0 on success or a negative error code on error. + */ +int Camera::acquire() +{ + if (acquired_) + return -EBUSY; + + acquired_ = true; + return 0; +} + +/** + * \brief Release exclusive access to the camera device + * + * Releasing the camera device allows other users to acquire exclusive access + * with the acquire() function. + */ +void Camera::release() +{ + acquired_ = false; +} + } /* namespace libcamera */ From patchwork Mon Jan 21 23:06:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 318 Return-Path: Received: from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net [195.74.38.229]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AEE1760B2D for ; Tue, 22 Jan 2019 00:07:15 +0100 (CET) X-Halon-ID: 497f7b30-1dd1-11e9-874f-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id 497f7b30-1dd1-11e9-874f-005056917f90; Tue, 22 Jan 2019 00:07:13 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 22 Jan 2019 00:06:38 +0100 Message-Id: <20190121230640.8783-3-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190121230640.8783-1-niklas.soderlund@ragnatech.se> References: <20190121230640.8783-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC 2/4] libcamera: stream: add basic stream class 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: Mon, 21 Jan 2019 23:07:15 -0000 Add a extremely simple Stream implementation. The idea is that once capability support is added to the library each stream would describe it's capabilities using this class. A application would then select one or more streams based on these capabilities and using there numerical ID configure and capture those streams. At this stage all the Stream class provides is a way for a Camera object to communicate which stream IDs it's able to operate on. This basically limits the usefulness of the object to cameras which only provides one stream per camera. Signed-off-by: Niklas Söderlund --- include/libcamera/libcamera.h | 1 + include/libcamera/meson.build | 1 + include/libcamera/stream.h | 25 +++++++++++++++ src/libcamera/meson.build | 1 + src/libcamera/stream.cpp | 58 +++++++++++++++++++++++++++++++++++ 5 files changed, 86 insertions(+) create mode 100644 include/libcamera/stream.h create mode 100644 src/libcamera/stream.cpp diff --git a/include/libcamera/libcamera.h b/include/libcamera/libcamera.h index c0511cf6d662b63f..272dfd5e4a67d5de 100644 --- a/include/libcamera/libcamera.h +++ b/include/libcamera/libcamera.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #endif /* __LIBCAMERA_LIBCAMERA_H__ */ diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build index d7cb55ba4a49e1e8..54a680787e5c17aa 100644 --- a/include/libcamera/meson.build +++ b/include/libcamera/meson.build @@ -5,6 +5,7 @@ libcamera_api = files([ 'event_notifier.h', 'libcamera.h', 'signal.h', + 'stream.h', 'timer.h', ]) diff --git a/include/libcamera/stream.h b/include/libcamera/stream.h new file mode 100644 index 0000000000000000..8386c68e33fe57d0 --- /dev/null +++ b/include/libcamera/stream.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * stream.h - Stream object interface + */ +#ifndef __LIBCAMERA_STREAM_H__ +#define __LIBCAMERA_STREAM_H__ + +namespace libcamera { + +class Stream final +{ +public: + Stream(unsigned int id); + + unsigned int id() { return id_; }; + +private: + unsigned int id_; +}; + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_STREAM_H__ */ diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index f9f25c0ecf1564cc..9f6ff99eebe2f5bc 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -10,6 +10,7 @@ libcamera_sources = files([ 'media_object.cpp', 'pipeline_handler.cpp', 'signal.cpp', + 'stream.cpp', 'timer.cpp', 'v4l2_device.cpp', ]) diff --git a/src/libcamera/stream.cpp b/src/libcamera/stream.cpp new file mode 100644 index 0000000000000000..db47c24760b360b4 --- /dev/null +++ b/src/libcamera/stream.cpp @@ -0,0 +1,58 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * stream.cpp - Stream information + */ + +#include + +/** + * \file stream.h + * \brief Stream information handling + * + * Each camera device is composed of one or multiple video stream connected + * to one image source. The Stream class holds all static information about + * a stream belonging to a camera device. A camera should provide a separate + * Stream object for every stream it can support. + * + * Camera devices expose at least one stream, and may expose additional streams + * based on the device capabilities. This can be used, for instance, to + * implement concurrent viewfinder and video capture, or concurrent viewfinder, + * video capture and still image capture. + */ + +namespace libcamera { + +/** + * \class Stream + * \brief Stream information carrier + * + * The Stream class is a model of all static information which can be + * associated with a video stream. It provides the mapping of a stream + * capabilities to a numerical ID which should be used when configuring + * the camera which might contain a collections of streams. + * + * \todo Add capabilities to the Stream API. Without this the Stream class + * only serves to map streams of unknown capabilities to a stream ID. + * This in it self is important as it allows applications to configure + * and capture from one or more streams even if it won't be able to + * select the optimal stream for the task. + */ + +/** + * \brief Create a new stream with a ID + * \param[in] id Numerical ID which should be unique for the camera device the stream belongs to. + */ +Stream::Stream(unsigned int id) + : id_(id) +{ +} + +/** + * \fn Stream::id() + * \brief Retrieve the streams ID + * \return The stream ID + */ + +} /* namespace libcamera */ From patchwork Mon Jan 21 23:06:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 319 Return-Path: Received: from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net [195.74.38.229]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9814860C9D for ; Tue, 22 Jan 2019 00:07:16 +0100 (CET) X-Halon-ID: 4a0eb00f-1dd1-11e9-874f-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id 4a0eb00f-1dd1-11e9-874f-005056917f90; Tue, 22 Jan 2019 00:07:14 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 22 Jan 2019 00:06:39 +0100 Message-Id: <20190121230640.8783-4-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190121230640.8783-1-niklas.soderlund@ragnatech.se> References: <20190121230640.8783-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC 3/4] libcamera: streamformat: add basic class for stream formats 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: Mon, 21 Jan 2019 23:07:17 -0000 Each stream in a camera object have its own format specification. The StreamFormat class holds all this information and should be filled in by the application to configure a camera. Signed-off-by: Niklas Söderlund --- include/libcamera/libcamera.h | 1 + include/libcamera/meson.build | 1 + include/libcamera/stream_format.h | 32 ++++++++++++ src/libcamera/meson.build | 1 + src/libcamera/stream_format.cpp | 82 +++++++++++++++++++++++++++++++ 5 files changed, 117 insertions(+) create mode 100644 include/libcamera/stream_format.h create mode 100644 src/libcamera/stream_format.cpp diff --git a/include/libcamera/libcamera.h b/include/libcamera/libcamera.h index 272dfd5e4a67d5de..7aefdcee51eca69c 100644 --- a/include/libcamera/libcamera.h +++ b/include/libcamera/libcamera.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #endif /* __LIBCAMERA_LIBCAMERA_H__ */ diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build index 54a680787e5c17aa..ca4e43fe70e42277 100644 --- a/include/libcamera/meson.build +++ b/include/libcamera/meson.build @@ -6,6 +6,7 @@ libcamera_api = files([ 'libcamera.h', 'signal.h', 'stream.h', + 'stream_format.h', 'timer.h', ]) diff --git a/include/libcamera/stream_format.h b/include/libcamera/stream_format.h new file mode 100644 index 0000000000000000..34d93c1c56284e6a --- /dev/null +++ b/include/libcamera/stream_format.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * stream_format.h - Stream format interface + */ +#ifndef __LIBCAMERA_STREAM_FORMAT_H__ +#define __LIBCAMERA_STREAM_FORMAT_H__ + +namespace libcamera { + +class StreamFormat final +{ +public: + StreamFormat(); + + unsigned int width() const { return width_; }; + unsigned int height() const { return height_; }; + unsigned int pixelformat() const { return pixelformat_; }; + + void setDimension(unsigned int width, unsigned int height); + void setPixelFormat(unsigned int pixelformat); + +private: + unsigned int width_; + unsigned int height_; + unsigned int pixelformat_; +}; + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_STREAM_FORMAT_H__ */ diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index 9f6ff99eebe2f5bc..819b92a511c3ee09 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -11,6 +11,7 @@ libcamera_sources = files([ 'pipeline_handler.cpp', 'signal.cpp', 'stream.cpp', + 'stream_format.cpp', 'timer.cpp', 'v4l2_device.cpp', ]) diff --git a/src/libcamera/stream_format.cpp b/src/libcamera/stream_format.cpp new file mode 100644 index 0000000000000000..9171980907b7a840 --- /dev/null +++ b/src/libcamera/stream_format.cpp @@ -0,0 +1,82 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * stream_format.cpp - Stream image format settings + */ + +#include + +/** + * \file stream_format.h + * \brief Stream format specification + * + * A camera device can provide frames in different resolutions and formats + * concurrently from a single image source. The StreamFormat class represents + * one of the multiple concurrent streams format. + * + * All streams exposed by a camera device share the same image source and are + * thus not fully independent. Parameters related to the image source, such as + * the exposure time or flash control, are common to all streams. Other + * parameters, such as format or resolution, may be specified per-stream, + * depending on the capabilities of the camera device. + */ + +namespace libcamera { + +/** + * \class StreamFormat + * \brief Stream format settings + * + * The StreamFormat class models all parameters which an application can set + * for a individual stream which is part of a camera device. + */ + +/** + * \brief Create a stream format information carrier + */ +StreamFormat::StreamFormat() + : width_(0), height_(0), pixelformat_(0) +{ +} + +/** + * \fn StreamFormat::width() + * \brief Retrieve the Stream width + * \return The stream width + */ + +/** + * \fn StreamFormat::height() + * \brief Retrieve the Stream height + * \return The stream height + */ + +/** + * \fn StreamFormat::pixelformat() + * \brief Retrieve the Stream pixelformat + * \return The stream pixelformat + */ + +/** + * \brief Set the width and height of the stream format + * \param[in] width The desired width of the stream + * \param[in] height The desired height of the stream + */ +void StreamFormat::setDimension(unsigned int width, unsigned int height) +{ + width_ = width; + height_ = height; +} + +/** + * \brief Set the pixelformat of the stream format + * \param[in] pixelformat The desired pixelformat of the stream + */ +void StreamFormat::setPixelFormat(unsigned int pixelformat) +{ + pixelformat_ = pixelformat; +} + + +} /* namespace libcamera */ From patchwork Mon Jan 21 23:06:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 320 Return-Path: Received: from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net [195.74.38.229]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4220460C83 for ; Tue, 22 Jan 2019 00:07:20 +0100 (CET) X-Halon-ID: 4a933f3d-1dd1-11e9-874f-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id 4a933f3d-1dd1-11e9-874f-005056917f90; Tue, 22 Jan 2019 00:07:16 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 22 Jan 2019 00:06:40 +0100 Message-Id: <20190121230640.8783-5-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190121230640.8783-1-niklas.soderlund@ragnatech.se> References: <20190121230640.8783-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC 4/4] libcamera: camera: integrate streams and configuration 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: Mon, 21 Jan 2019 23:07:20 -0000 Implement stubs for retrieving the streams of a camera and configuration of the same. This just add stubs and further building blocks are needed to make this useful. Signed-off-by: Niklas Söderlund --- include/libcamera/camera.h | 9 ++++++++ src/libcamera/camera.cpp | 46 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index 03b285c840c246e1..13395d994bade85a 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -7,11 +7,16 @@ #ifndef __LIBCAMERA_CAMERA_H__ #define __LIBCAMERA_CAMERA_H__ +#include #include #include +#include namespace libcamera { +class Stream; +class StreamFormat; + class Camera final { public: @@ -22,6 +27,10 @@ public: const std::string &name() const; + std::vector streams() const; + + int configure(const std::map &config); + int acquire(); void release(); diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index b80bc36e410a6e0a..ad9cf948135c03bd 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -6,6 +6,7 @@ */ #include +#include #include "log.h" @@ -83,6 +84,51 @@ const std::string &Camera::name() const return name_; } +/** + * \brief Retrieve the supported streams of the camera + * + * \return An array of streams supported by the camera device + */ +std::vector Camera::streams() const +{ + std::vector streams; + + /* TODO: Call into pipeline handler and get streams. */ + /* HACK: Hard code a single stream with ID 0. */ + streams.push_back(Stream(0)); + + return streams; +} + +/** + * \brief Configure the camera device prior to capture + * + * Prior to starting capture, the camera device must be configured to select a + * set of streams. + * + * The requested configuration \a config shall contain at least one stream and + * may contain multiple streams. For each stream an associated StreamFormat + * shall be supplied. Streams supported by the camera device not part of the + * \a config will be disabled. + * + * Exclusive access to the camera device shall be ensured by a call to + * Camera::acquire() before calling this function, otherwise an -EACCES error + * will be returned. + * + * \param[in] config Array of stream configurations to setup + * + * \return 0 on success or a negative error code on error. + */ +int Camera::configure(const std::map &config) +{ + if (!acquired_) + return -EACCES; + + /* TODO: Call into pipeline handler to configure the hardware. */ + + return 0; +} + Camera::Camera(const std::string &name) : name_(name) {