From patchwork Tue Feb 26 02:18:50 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: 621 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 8E196601E2 for ; Tue, 26 Feb 2019 03:19:15 +0100 (CET) X-Halon-ID: e9302da2-396c-11e9-985a-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 e9302da2-396c-11e9-985a-005056917f90; Tue, 26 Feb 2019 03:19:14 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Feb 2019 03:18:50 +0100 Message-Id: <20190226021857.28255-2-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190226021857.28255-1-niklas.soderlund@ragnatech.se> References: <20190226021857.28255-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/8] libcamera: camera: fix bug in error check for streamConfiguration() 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, 26 Feb 2019 02:19:16 -0000 The return statement is missing altogether and an error is silently ignored. Fix this and also update the empty map to use the correct type for the map key. Fixes: 65ea2422d24a3073 ("libcamera: camera: extend camera object to support configuration of streams") Signed-off-by: Niklas Söderlund Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/libcamera/camera.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 1acb399c80a6fd3e..6409d10ff88b2189 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -213,7 +213,7 @@ std::map Camera::streamConfiguration(std::vector &streams) { if (disconnected_ || !streams.size()) - std::map {}; + return std::map{}; return pipe_->streamConfiguration(this, streams); } From patchwork Tue Feb 26 02:18:51 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: 623 Return-Path: Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 62A56610BB for ; Tue, 26 Feb 2019 03:19:17 +0100 (CET) X-Halon-ID: e98efad2-396c-11e9-985a-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 e98efad2-396c-11e9-985a-005056917f90; Tue, 26 Feb 2019 03:19:15 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Feb 2019 03:18:51 +0100 Message-Id: <20190226021857.28255-3-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190226021857.28255-1-niklas.soderlund@ragnatech.se> References: <20190226021857.28255-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/8] libcamera: align the documentation for numeric error codes 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, 26 Feb 2019 02:19:17 -0000 Rapid growth of the library have resulted in slightly different wording to document that a function returns 0 on success or a negative error code. Align all different variations. Signed-off-by: Niklas Söderlund Reviewed-by: Jacopo Mondi Acked-by: Laurent Pinchart --- src/libcamera/buffer.cpp | 6 +++--- src/libcamera/camera.cpp | 12 ++++++------ src/libcamera/camera_manager.cpp | 2 +- src/libcamera/device_enumerator.cpp | 7 +++---- src/libcamera/media_device.cpp | 8 ++++---- src/libcamera/media_object.cpp | 5 ++--- src/libcamera/pipeline_handler.cpp | 10 +++++----- src/libcamera/request.cpp | 2 +- src/libcamera/v4l2_device.cpp | 16 ++++++++-------- src/libcamera/v4l2_subdevice.cpp | 10 +++++----- 10 files changed, 38 insertions(+), 40 deletions(-) diff --git a/src/libcamera/buffer.cpp b/src/libcamera/buffer.cpp index 9ec372c2981b5b02..f7c5f0e6a3fe0e55 100644 --- a/src/libcamera/buffer.cpp +++ b/src/libcamera/buffer.cpp @@ -71,7 +71,7 @@ Plane::~Plane() * The \a fd dmabuf file handle is duplicated and stored. The caller may close * the original file handle. * - * \return 0 on success or a negative error value otherwise. + * \return 0 on success or a negative error code */ int Plane::setDmabuf(int fd, unsigned int length) { @@ -106,7 +106,7 @@ int Plane::setDmabuf(int fd, unsigned int length) * * \sa setDmaBuf() * - * \return 0 on success or a negative error value otherwise. + * \return 0 on success or a negative error code */ int Plane::mmap() { @@ -133,7 +133,7 @@ int Plane::mmap() * * Unmap the memory mapped by an earlier call to mmap(). * - * \return 0 on success or a negative error value otherwise. + * \return 0 on success or a negative error code */ int Plane::munmap() { diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 6409d10ff88b2189..e2372fea31e2921a 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -157,7 +157,7 @@ void Camera::disconnect() * * \todo Implement exclusive access across processes. * - * \return 0 on success or a negative error code on error. + * \return 0 on success or a negative error code */ int Camera::acquire() { @@ -235,7 +235,7 @@ Camera::streamConfiguration(std::vector &streams) * Exclusive access to the camera shall be ensured by a call to acquire() prior * to calling this function, otherwise an -EACCES error will be returned. * - * \return 0 on success or a negative error code on error. + * \return 0 on success or a negative error code * \retval -ENODEV The camera is not connected to any hardware * \retval -EACCES The user has not acquired exclusive access to the camera * \retval -EINVAL The configuration is not valid @@ -278,7 +278,7 @@ int Camera::configureStreams(std::map &config) /** * \brief Allocate buffers for all configured streams - * \return 0 on success or a negative error code otherwise + * \return 0 on success or a negative error code */ int Camera::allocateBuffers() { @@ -350,7 +350,7 @@ Request *Camera::createRequest() * Ownership of the request is transferred to the camera. It will be deleted * automatically after it completes. * - * \return 0 on success or a negative error code on error + * \return 0 on success or a negative error code */ int Camera::queueRequest(Request *request) { @@ -376,7 +376,7 @@ int Camera::queueRequest(Request *request) * can queue requests to the camera to process and return to the application * until the capture session is terminated with \a stop(). * - * \return 0 on success or a negative error code on error + * \return 0 on success or a negative error code */ int Camera::start() { @@ -395,7 +395,7 @@ int Camera::start() * This method stops capturing and processing requests immediately. All pending * requests are cancelled and complete synchronously in an error state. * - * \return 0 on success or a negative error code on error + * \return 0 on success or a negative error code */ int Camera::stop() { diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index f90201ade18b61dd..6878cc7e26b24ca4 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -74,7 +74,7 @@ CameraManager::~CameraManager() * interact with cameras in the system until either the camera manager * is stopped or the camera is unplugged from the system. * - * \return 0 on successful start, or a negative error code otherwise + * \return 0 on success or a negative error code */ int CameraManager::start() { diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp index 66819f077c16c721..b35ac2bb626ec3c6 100644 --- a/src/libcamera/device_enumerator.cpp +++ b/src/libcamera/device_enumerator.cpp @@ -178,7 +178,7 @@ DeviceEnumerator::~DeviceEnumerator() /** * \fn DeviceEnumerator::init() * \brief Initialize the enumerator - * \return 0 on success, or a negative error code otherwise + * \return 0 on success or a negative error code * \retval -EBUSY the enumerator has already been initialized * \retval -ENODEV the enumerator can't enumerate devices */ @@ -195,7 +195,7 @@ DeviceEnumerator::~DeviceEnumerator() * with a warning message logged, without returning an error. Only errors that * prevent enumeration altogether shall be fatal. * - * \return 0 on success, or a negative error code on fatal errors. + * \return 0 on success or a negative error code */ /** @@ -206,8 +206,7 @@ DeviceEnumerator::~DeviceEnumerator() * and look up device nodes associated with all entities. Store the media device * in the internal list for later matching with pipeline handlers. * - * \return 0 on success, or a negative error code if the media device can't be - * created or populated + * \return 0 on success or a negative error code */ int DeviceEnumerator::addDevice(const std::string &deviceNode) { diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp index 800ed330fe6d8d6f..4f494e316867a55c 100644 --- a/src/libcamera/media_device.cpp +++ b/src/libcamera/media_device.cpp @@ -136,7 +136,7 @@ bool MediaDevice::acquire() * * If the device is already open the function returns -EBUSY. * - * \return 0 on success or a negative error code otherwise + * \return 0 on success or a negative error code */ int MediaDevice::open() { @@ -206,7 +206,7 @@ void MediaDevice::close() * while pads are accessible from the entity they belong to and links from the * pads they connect. * - * \return 0 on success, a negative error code otherwise + * \return 0 on success or a negative error code */ int MediaDevice::populate() { @@ -405,7 +405,7 @@ MediaLink *MediaDevice::link(const MediaPad *source, const MediaPad *sink) * Disable all the media device links, clearing the MEDIA_LNK_FL_ENABLED flag * on links which are not flagged as IMMUTABLE. * - * \return 0 on success, or a negative error code otherwise + * \return 0 on success or a negative error code */ int MediaDevice::disableLinks() { @@ -705,7 +705,7 @@ void MediaDevice::fixupEntityFlags(struct media_v2_entity *entity) * * \sa MediaLink::setEnabled(bool enable) * - * \return 0 on success, or a negative error code otherwise + * \return 0 on success or a negative error code */ int MediaDevice::setupLink(const MediaLink *link, unsigned int flags) { diff --git a/src/libcamera/media_object.cpp b/src/libcamera/media_object.cpp index f6abcd8676a3866d..79126124caf98497 100644 --- a/src/libcamera/media_object.cpp +++ b/src/libcamera/media_object.cpp @@ -111,7 +111,7 @@ LOG_DECLARE_CATEGORY(MediaDevice) * Enabling a link establishes a data connection between two pads, while * disabling it interrupts that connection. * - * \return 0 on success, or a negative error code otherwise + * \return 0 on success or a negative error code */ int MediaLink::setEnabled(bool enable) { @@ -337,8 +337,7 @@ const MediaPad *MediaEntity::getPadById(unsigned int id) const /** * \brief Set the path to the device node for the associated interface * \param deviceNode The interface device node path associated with this entity - * \return 0 on success, or a negative error code if the device node can't be - * accessed + * \return 0 on success or a negative error code */ int MediaEntity::setDeviceNode(const std::string &deviceNode) { diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index dad0a2964486c5d4..0a858fbe13257c7f 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -144,7 +144,7 @@ PipelineHandler::~PipelineHandler() * configuration of a subset of the streams can't be satisfied, the * whole configuration is considered invalid. * - * \return 0 on success or a negative error code on error. + * \return 0 on success or a negative error code */ /** @@ -158,7 +158,7 @@ PipelineHandler::~PipelineHandler() * * The intended caller of this method is the Camera class. * - * \return 0 on success or a negative error code on error + * \return 0 on success or a negative error code */ /** @@ -172,7 +172,7 @@ PipelineHandler::~PipelineHandler() * * The intended caller of this method is the Camera class. * - * \return 0 on success or a negative error code on error + * \return 0 on success or a negative error code */ /** @@ -185,7 +185,7 @@ PipelineHandler::~PipelineHandler() * class which will in turn be called from the application to indicate that it * has configured the streams and is ready to capture. * - * \return 0 on success or a negative error code on error + * \return 0 on success or a negative error code */ /** @@ -211,7 +211,7 @@ PipelineHandler::~PipelineHandler() * parameters will be applied to the frames captured in the buffers provided in * the request. * - * \return 0 on success or a negative error code on error + * \return 0 on success or a negative error code */ /** diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp index d76db24de0e279e5..a219b061d8814001 100644 --- a/src/libcamera/request.cpp +++ b/src/libcamera/request.cpp @@ -43,7 +43,7 @@ Request::Request(Camera *camera) /** * \brief Set the streams to capture with associated buffers * \param[in] streamMap The map of streams to buffers - * \return 0 on success or a negative error code otherwise + * \return 0 on success or a negative error code * \retval -EBUSY Buffers have already been set */ int Request::setBuffers(const std::map &streamMap) diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 24e115554a997325..8024e041f9b8124a 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -247,7 +247,7 @@ V4L2Device::~V4L2Device() /** * \brief Open a V4L2 device and query its capabilities - * \return 0 on success, or a negative error code otherwise + * \return 0 on success or a negative error code */ int V4L2Device::open() { @@ -365,7 +365,7 @@ std::string V4L2Device::logPrefix() const * \brief Retrieve the image format set on the V4L2 device * \param[out] format The image format applied on the device * - * \return 0 for success, a negative error code otherwise + * \return 0 on success or a negative error code */ int V4L2Device::getFormat(V4L2DeviceFormat *format) { @@ -380,7 +380,7 @@ int V4L2Device::getFormat(V4L2DeviceFormat *format) * Apply the supplied \a format to the device, and return the actually * applied format parameters, as \ref V4L2Device::getFormat would do. * - * \return 0 for success, a negative error code otherwise + * \return 0 on success or a negative error code */ int V4L2Device::setFormat(V4L2DeviceFormat *format) { @@ -541,7 +541,7 @@ int V4L2Device::requestBuffers(unsigned int count) * \brief Request buffers to be allocated from the device and stored in the * buffer pool provided. * \param[out] pool BufferPool to populate with buffers - * \return 0 on success or a negative error code otherwise + * \return 0 on success or a negative error code */ int V4L2Device::exportBuffers(BufferPool *pool) { @@ -645,7 +645,7 @@ int V4L2Device::createPlane(Buffer *buffer, unsigned int planeIndex, /** * \brief Import the externally allocated \a pool of buffers * \param[in] pool BufferPool of buffers to import - * \return 0 on success or a negative error code otherwise + * \return 0 on success or a negative error code */ int V4L2Device::importBuffers(BufferPool *pool) { @@ -697,7 +697,7 @@ int V4L2Device::releaseBuffers() * \todo Support output devices (bytesused, ...) * \todo Support imported buffers (dmabuf fd) * - * \return 0 on success or a negative error number otherwise + * \return 0 on success or a negative error code */ int V4L2Device::queueBuffer(Buffer *buffer) { @@ -830,7 +830,7 @@ void V4L2Device::bufferAvailable(EventNotifier *notifier) /** * \brief Start the video stream * - * \return 0 on success or a negative error code otherwise + * \return 0 on success or a negative error code */ int V4L2Device::streamOn() { @@ -852,7 +852,7 @@ int V4L2Device::streamOn() * * \todo Ensure completion notifications are sent for all queued buffers * - * \return 0 on success or a negative error code otherwise + * \return 0 on success or a negative error code */ int V4L2Device::streamOff() { diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index b436f73cc75fe307..b31eac2ed9bd2502 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -95,7 +95,7 @@ V4L2Subdevice::V4L2Subdevice(const MediaEntity *entity) /** * \brief Open a V4L2 subdevice * - * \return 0 on success, a negative error code otherwise + * \return 0 on success or a negative error code */ int V4L2Subdevice::open() { @@ -152,7 +152,7 @@ void V4L2Subdevice::close() * \param[in] pad The 0-indexed pad number the rectangle is to be applied to * \param[inout] rect The rectangle describing crop target area * - * \return 0 on success, or a negative error code otherwise + * \return 0 on success or a negative error code */ int V4L2Subdevice::setCrop(unsigned int pad, Rectangle *rect) { @@ -164,7 +164,7 @@ int V4L2Subdevice::setCrop(unsigned int pad, Rectangle *rect) * \param[in] pad The 0-indexed pad number the rectangle is to be applied to * \param[inout] rect The rectangle describing the compose target area * - * \return 0 on success, or a negative error code otherwise + * \return 0 on success or a negative error code */ int V4L2Subdevice::setCompose(unsigned int pad, Rectangle *rect) { @@ -176,7 +176,7 @@ int V4L2Subdevice::setCompose(unsigned int pad, Rectangle *rect) * \param[in] pad The 0-indexed pad number the format is to be retrieved from * \param[out] format The image bus format * - * \return 0 for success, a negative error code otherwise + * \return 0 on success or a negative error code */ int V4L2Subdevice::getFormat(unsigned int pad, V4L2SubdeviceFormat *format) { @@ -209,7 +209,7 @@ int V4L2Subdevice::getFormat(unsigned int pad, V4L2SubdeviceFormat *format) * actually applied format parameters, as \ref V4L2Subdevice::getFormat would * do. * - * \return 0 for success, a negative error code otherwise + * \return 0 on success or a negative error code */ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format) { From patchwork Tue Feb 26 02:18:52 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: 624 Return-Path: Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C7994610BB for ; Tue, 26 Feb 2019 03:19:18 +0100 (CET) X-Halon-ID: eab9f82b-396c-11e9-985a-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 eab9f82b-396c-11e9-985a-005056917f90; Tue, 26 Feb 2019 03:19:17 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Feb 2019 03:18:52 +0100 Message-Id: <20190226021857.28255-4-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190226021857.28255-1-niklas.soderlund@ragnatech.se> References: <20190226021857.28255-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/8] libcamera: camera: document return values for application facing functions 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, 26 Feb 2019 02:19:19 -0000 In preparation for adding a state machine to control access to the functions facing the application document the error codes which will be returned once it's in place. Signed-off-by: Niklas Söderlund --- src/libcamera/camera.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index e2372fea31e2921a..d4258fe3c7551af3 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -158,6 +158,7 @@ void Camera::disconnect() * \todo Implement exclusive access across processes. * * \return 0 on success or a negative error code + * \retval -EBUSY The camera is not free and can't be acquired by the caller. */ int Camera::acquire() { @@ -236,9 +237,8 @@ Camera::streamConfiguration(std::vector &streams) * to calling this function, otherwise an -EACCES error will be returned. * * \return 0 on success or a negative error code - * \retval -ENODEV The camera is not connected to any hardware - * \retval -EACCES The user has not acquired exclusive access to the camera - * \retval -EINVAL The configuration is not valid + * \retval -EACCES The camera is not in a state where it can be configured. + * \retval -EINVAL The configuration is not valid. */ int Camera::configureStreams(std::map &config) { @@ -279,6 +279,8 @@ int Camera::configureStreams(std::map &config) /** * \brief Allocate buffers for all configured streams * \return 0 on success or a negative error code + * \retval -EACCES The camera is not in a state where it can allocate buffers. + * \retval -EINVAL The configuration is not valid. */ int Camera::allocateBuffers() { @@ -330,6 +332,7 @@ void Camera::freeBuffers() * responsible for either queueing the request or deleting it. * * \return A pointer to the newly created request, or nullptr on error + * \retval -EACCES The camera is not in a state where requests can be created. */ Request *Camera::createRequest() { @@ -351,6 +354,7 @@ Request *Camera::createRequest() * automatically after it completes. * * \return 0 on success or a negative error code + * \retval -EACCES The camera is not running so requests can't be queued. */ int Camera::queueRequest(Request *request) { @@ -377,6 +381,7 @@ int Camera::queueRequest(Request *request) * until the capture session is terminated with \a stop(). * * \return 0 on success or a negative error code + * \retval -EACCES The camera is not in a state where it can be started. */ int Camera::start() { @@ -396,6 +401,7 @@ int Camera::start() * requests are cancelled and complete synchronously in an error state. * * \return 0 on success or a negative error code + * \retval -EACCES The camera is not running so can't be stopped. */ int Camera::stop() { From patchwork Tue Feb 26 02:18:53 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: 625 Return-Path: Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 72BE5610BF for ; Tue, 26 Feb 2019 03:19:20 +0100 (CET) X-Halon-ID: eb4b0e63-396c-11e9-985a-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 eb4b0e63-396c-11e9-985a-005056917f90; Tue, 26 Feb 2019 03:19:19 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Feb 2019 03:18:53 +0100 Message-Id: <20190226021857.28255-5-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190226021857.28255-1-niklas.soderlund@ragnatech.se> References: <20190226021857.28255-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/8] cam: fix order camera is operated on 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, 26 Feb 2019 02:19:20 -0000 Upcoming enforcing of order the camera shall be operate on is not compatible with the cam utility. Requests shall be queued after the camera is started, not before. Signed-off-by: Niklas Söderlund --- src/cam/main.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/cam/main.cpp b/src/cam/main.cpp index 4c2df583fe8e99b7..8df8844c33a2d052 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -133,6 +133,7 @@ static int capture() int ret; std::vector streams = camera->streams(); + std::vector requests; ret = configureStreams(camera.get(), streams); if (ret < 0) { @@ -169,21 +170,24 @@ static int capture() goto out; } - ret = camera->queueRequest(request); - if (ret < 0) { - std::cerr << "Can't queue request" << std::endl; - goto out; - } + requests.push_back(request); } - std::cout << "Capture until user interrupts by SIGINT" << std::endl; - ret = camera->start(); if (ret) { std::cout << "Failed to start capture" << std::endl; goto out; } + for (Request *request : requests) { + ret = camera->queueRequest(request); + if (ret < 0) { + std::cerr << "Can't queue request" << std::endl; + goto out; + } + } + + std::cout << "Capture until user interrupts by SIGINT" << std::endl; ret = loop->exec(); ret = camera->stop(); From patchwork Tue Feb 26 02:18:54 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: 626 Return-Path: Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 02E08601E2 for ; Tue, 26 Feb 2019 03:19:24 +0100 (CET) X-Halon-ID: ecc5dd6a-396c-11e9-985a-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 ecc5dd6a-396c-11e9-985a-005056917f90; Tue, 26 Feb 2019 03:19:22 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Feb 2019 03:18:54 +0100 Message-Id: <20190226021857.28255-6-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190226021857.28255-1-niklas.soderlund@ragnatech.se> References: <20190226021857.28255-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 5/8] libcamera: camera: add state machine to control access from applications 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, 26 Feb 2019 02:19:25 -0000 There is a need to better control the order of operations an application perform on a camera for it to function correctly. Add a basic state machine to ensure applications perform operations on the camera in good order. Internal to the Camera four states are added; Disconnected, Free, Acquired and Running. Each state represents a higher state of configuration of the camera ultimately leading to the highest state where the camera is capturing frames. Each state supports a subset of operations the application can perform. * Disconnected Is the lowest state a camera can be in. It indicates that the camera have been disconnected from the system and the only operations an application shall do at this point is clean up and release the camera so it can be removed from libcamera as well. * Free Is the base state of a camera, an application can inspect the properties of the camera to determine if it wish to use it or not. If an application wish to use a camera it should acquire it to proceed to the next state. * Acquired When an application have acquired a camera it have exclusive access to it and can modify the cameras parameters to prepare it for capturing. Once the application is done configure the camera it may be started to progress to the running state. Once the camera is started it can not be reconfigured until it's stopped. * Running In this state the camera is running and able to process requests queued to it by the application. Once an application finish capturing the camera shall be stopped to change the state to acquired where it can be reconfigured or released. Signed-off-by: Niklas Söderlund --- include/libcamera/camera.h | 14 ++++- src/libcamera/camera.cpp | 110 +++++++++++++++++++++++-------------- 2 files changed, 80 insertions(+), 44 deletions(-) diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index bf70255a6a5ea364..8c8545b074e8ae13 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -55,20 +55,28 @@ public: int stop(); private: + enum State { + Disconnected, + Free, + Acquired, + Running, + }; + Camera(PipelineHandler *pipe, const std::string &name); ~Camera(); + bool stateIs(State state) const; + bool stateIsAtleast(State state) const; + friend class PipelineHandler; void disconnect(); - int exclusiveAccess(); std::shared_ptr pipe_; std::string name_; std::vector streams_; std::vector activeStreams_; - bool acquired_; - bool disconnected_; + State state_; }; } /* namespace libcamera */ diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index d4258fe3c7551af3..c50b14bbd904fc1c 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -116,17 +116,47 @@ const std::string &Camera::name() const */ Camera::Camera(PipelineHandler *pipe, const std::string &name) - : pipe_(pipe->shared_from_this()), name_(name), acquired_(false), - disconnected_(false) + : pipe_(pipe->shared_from_this()), name_(name), state_(Free) { } Camera::~Camera() { - if (acquired_) + if (state_ > Free) LOG(Camera, Error) << "Removing camera while still in use"; } +static const std::string stateNames[] = { + "Disconnected", + "Free", + "Acquired", + "Running", +}; + +bool Camera::stateIs(State state) const +{ + if (state_ == state) + return true; + + LOG(Camera, Error) << "Camera in " << stateNames[state_] + << " state trying operation requiering " + << stateNames[state] << " state"; + + return false; +} + +bool Camera::stateIsAtleast(State state) const +{ + if (state_ >= state) + return true; + + LOG(Camera, Error) << "Camera in " << stateNames[state_] + << " state trying operation requiering at least " + << stateNames[state] << " state"; + + return false; +} + /** * \brief Notify camera disconnection * @@ -140,7 +170,7 @@ void Camera::disconnect() { LOG(Camera, Debug) << "Disconnecting camera " << name_; - disconnected_ = true; + state_ = Disconnected; disconnected.emit(this); } @@ -162,10 +192,11 @@ void Camera::disconnect() */ int Camera::acquire() { - if (acquired_) + if (!stateIs(Free)) return -EBUSY; - acquired_ = true; + state_ = Acquired; + return 0; } @@ -177,7 +208,10 @@ int Camera::acquire() */ void Camera::release() { - acquired_ = false; + if (!stateIs(Acquired)) + return; + + state_ = Free; } /** @@ -191,6 +225,9 @@ void Camera::release() */ const std::vector &Camera::streams() const { + if (!stateIsAtleast(Free)) + std::vector{}; + return streams_; } @@ -213,7 +250,7 @@ const std::vector &Camera::streams() const std::map Camera::streamConfiguration(std::vector &streams) { - if (disconnected_ || !streams.size()) + if (!stateIsAtleast(Free) || !streams.size()) return std::map{}; return pipe_->streamConfiguration(this, streams); @@ -244,9 +281,8 @@ int Camera::configureStreams(std::map &config) { int ret; - ret = exclusiveAccess(); - if (ret) - return ret; + if (!stateIs(Acquired)) + return -EACCES; if (!config.size()) { LOG(Camera, Error) @@ -284,11 +320,8 @@ int Camera::configureStreams(std::map &config) */ int Camera::allocateBuffers() { - int ret; - - ret = exclusiveAccess(); - if (ret) - return ret; + if (!stateIs(Acquired)) + return -EACCES; if (activeStreams_.empty()) { LOG(Camera, Error) @@ -297,7 +330,7 @@ int Camera::allocateBuffers() } for (Stream *stream : activeStreams_) { - ret = pipe_->allocateBuffers(this, stream); + int ret = pipe_->allocateBuffers(this, stream); if (ret) { LOG(Camera, Error) << "Failed to allocate buffers"; freeBuffers(); @@ -313,6 +346,9 @@ int Camera::allocateBuffers() */ void Camera::freeBuffers() { + if (!stateIs(Acquired)) + return; + for (Stream *stream : activeStreams_) { if (!stream->bufferPool().count()) continue; @@ -336,7 +372,7 @@ void Camera::freeBuffers() */ Request *Camera::createRequest() { - if (exclusiveAccess()) + if (!stateIsAtleast(Acquired)) return nullptr; return new Request(this); @@ -358,13 +394,10 @@ Request *Camera::createRequest() */ int Camera::queueRequest(Request *request) { - int ret; + if (!stateIs(Running)) + return -EACCES; - ret = exclusiveAccess(); - if (ret) - return ret; - - ret = request->prepare(); + int ret = request->prepare(); if (ret) { LOG(Camera, Error) << "Failed to prepare request"; return ret; @@ -385,13 +418,18 @@ int Camera::queueRequest(Request *request) */ int Camera::start() { - int ret = exclusiveAccess(); - if (ret) - return ret; + if (!stateIs(Acquired)) + return -EACCES; LOG(Camera, Debug) << "Starting capture"; - return pipe_->start(this); + int ret = pipe_->start(this); + if (ret) + return ret; + + state_ = Running; + + return 0; } /** @@ -405,24 +443,14 @@ int Camera::start() */ int Camera::stop() { - int ret = exclusiveAccess(); - if (ret) - return ret; + if (!stateIs(Running)) + return -EACCES; LOG(Camera, Debug) << "Stopping capture"; pipe_->stop(this); - return 0; -} - -int Camera::exclusiveAccess() -{ - if (disconnected_) - return -ENODEV; - - if (!acquired_) - return -EACCES; + state_ = Acquired; return 0; } From patchwork Tue Feb 26 02:18:55 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: 627 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 7DB67601E2 for ; Tue, 26 Feb 2019 03:19:25 +0100 (CET) X-Halon-ID: ef0531c2-396c-11e9-985a-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 ef0531c2-396c-11e9-985a-005056917f90; Tue, 26 Feb 2019 03:19:24 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Feb 2019 03:18:55 +0100 Message-Id: <20190226021857.28255-7-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190226021857.28255-1-niklas.soderlund@ragnatech.se> References: <20190226021857.28255-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 6/8] libcamera: store stream pointers in sets instead of a vectors 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, 26 Feb 2019 02:19:25 -0000 The arrays that store Stream pointers shall always contain unique values. Storing them in vectors opens up for the same stream pointer appearing twice. Remove this possibility by storing them in a set which grantees each element is unique. Signed-off-by: Niklas Söderlund Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- include/libcamera/camera.h | 11 ++++++----- src/cam/main.cpp | 10 +++++----- src/libcamera/camera.cpp | 10 +++++----- src/libcamera/include/pipeline_handler.h | 2 +- src/libcamera/pipeline/ipu3/ipu3.cpp | 6 +++--- src/libcamera/pipeline/uvcvideo.cpp | 6 +++--- src/libcamera/pipeline/vimc.cpp | 6 +++--- 7 files changed, 26 insertions(+), 25 deletions(-) diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index 8c8545b074e8ae13..1e75a6dafa4e7c5f 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -27,7 +28,7 @@ class Camera final public: static std::shared_ptr create(PipelineHandler *pipe, const std::string &name, - const std::vector &streams); + const std::set &streams); Camera(const Camera &) = delete; Camera &operator=(const Camera &) = delete; @@ -40,9 +41,9 @@ public: int acquire(); void release(); - const std::vector &streams() const; + const std::set &streams() const; std::map - streamConfiguration(std::vector &streams); + streamConfiguration(std::set &streams); int configureStreams(std::map &config); int allocateBuffers(); @@ -73,8 +74,8 @@ private: std::shared_ptr pipe_; std::string name_; - std::vector streams_; - std::vector activeStreams_; + std::set streams_; + std::set activeStreams_; State state_; }; diff --git a/src/cam/main.cpp b/src/cam/main.cpp index 8df8844c33a2d052..13aa35968f38964d 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -75,10 +75,10 @@ static int parseOptions(int argc, char *argv[]) return 0; } -static int configureStreams(Camera *camera, std::vector &streams) +static int configureStreams(Camera *camera, std::set &streams) { KeyValueParser::Options format = options[OptFormat]; - Stream *id = streams.front(); + Stream *id = *streams.begin(); std::map config = camera->streamConfiguration(streams); @@ -132,7 +132,7 @@ static int capture() { int ret; - std::vector streams = camera->streams(); + std::set streams = camera->streams(); std::vector requests; ret = configureStreams(camera.get(), streams); @@ -141,7 +141,7 @@ static int capture() return ret; } - Stream *stream = streams.front(); + Stream *stream = *streams.begin(); ret = camera->allocateBuffers(); if (ret) { @@ -237,7 +237,7 @@ int main(int argc, char **argv) goto out; } - const std::vector &streams = camera->streams(); + const std::set &streams = camera->streams(); if (streams.size() != 1) { std::cout << "Camera has " << streams.size() << " streams, only 1 is supported" diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index c50b14bbd904fc1c..938f21fe80ef8ceb 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -66,7 +66,7 @@ LOG_DECLARE_CATEGORY(Camera) */ std::shared_ptr Camera::create(PipelineHandler *pipe, const std::string &name, - const std::vector &streams) + const std::set &streams) { struct Allocator : std::allocator { void construct(void *p, PipelineHandler *pipe, @@ -223,10 +223,10 @@ void Camera::release() * * \return An array of all the camera's streams. */ -const std::vector &Camera::streams() const +const std::set &Camera::streams() const { if (!stateIsAtleast(Free)) - std::vector{}; + std::set{}; return streams_; } @@ -248,7 +248,7 @@ const std::vector &Camera::streams() const * empty list on error. */ std::map -Camera::streamConfiguration(std::vector &streams) +Camera::streamConfiguration(std::set &streams) { if (!stateIsAtleast(Free) || !streams.size()) return std::map{}; @@ -300,7 +300,7 @@ int Camera::configureStreams(std::map &config) const StreamConfiguration &cfg = iter.second; stream->configuration_ = cfg; - activeStreams_.push_back(stream); + activeStreams_.insert(stream); /* * Allocate buffer objects in the pool. diff --git a/src/libcamera/include/pipeline_handler.h b/src/libcamera/include/pipeline_handler.h index 4363dcd8ed8ead97..4cd9b90c609c067e 100644 --- a/src/libcamera/include/pipeline_handler.h +++ b/src/libcamera/include/pipeline_handler.h @@ -45,7 +45,7 @@ public: virtual bool match(DeviceEnumerator *enumerator) = 0; virtual std::map - streamConfiguration(Camera *camera, std::vector &streams) = 0; + streamConfiguration(Camera *camera, std::set &streams) = 0; virtual int configureStreams(Camera *camera, std::map &config) = 0; diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 9694d0ce51abda41..1066fbe350d934a0 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -32,7 +32,7 @@ public: std::map streamConfiguration(Camera *camera, - std::vector &streams) override; + std::set &streams) override; int configureStreams(Camera *camera, std::map &config) override; @@ -95,7 +95,7 @@ PipelineHandlerIPU3::~PipelineHandlerIPU3() std::map PipelineHandlerIPU3::streamConfiguration(Camera *camera, - std::vector &streams) + std::set &streams) { IPU3CameraData *data = cameraData(camera); std::map configs; @@ -374,7 +374,7 @@ void PipelineHandlerIPU3::registerCameras() std::unique_ptr data = utils::make_unique(); std::string cameraName = sensor->name() + " " + std::to_string(id); - std::vector streams{ &data->stream_ }; + std::set streams{ &data->stream_ }; std::shared_ptr camera = Camera::create(this, cameraName, streams); /* diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp index b7b8ff109109e9c5..7b697c0685630d92 100644 --- a/src/libcamera/pipeline/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo.cpp @@ -27,7 +27,7 @@ public: std::map streamConfiguration(Camera *camera, - std::vector &streams) override; + std::set &streams) override; int configureStreams(Camera *camera, std::map &config) override; @@ -63,7 +63,7 @@ PipelineHandlerUVC::~PipelineHandlerUVC() std::map PipelineHandlerUVC::streamConfiguration(Camera *camera, - std::vector &streams) + std::set &streams) { std::map configs; @@ -171,7 +171,7 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator) return false; } - std::vector streams{ &stream_ }; + std::set streams{ &stream_ }; std::shared_ptr camera = Camera::create(this, media_->model(), streams); registerCamera(std::move(camera)); hotplugMediaDevice(media_.get()); diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp index 812777cffbb3e618..9ba96323d335e010 100644 --- a/src/libcamera/pipeline/vimc.cpp +++ b/src/libcamera/pipeline/vimc.cpp @@ -27,7 +27,7 @@ public: std::map streamConfiguration(Camera *camera, - std::vector &streams) override; + std::set &streams) override; int configureStreams(Camera *camera, std::map &config) override; @@ -62,7 +62,7 @@ PipelineHandlerVimc::~PipelineHandlerVimc() std::map PipelineHandlerVimc::streamConfiguration(Camera *camera, - std::vector &streams) + std::set &streams) { std::map configs; @@ -171,7 +171,7 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator) return false; } - std::vector streams{ &stream_ }; + std::set streams{ &stream_ }; std::shared_ptr camera = Camera::create(this, "VIMC Sensor B", streams); registerCamera(std::move(camera)); From patchwork Tue Feb 26 02:18:56 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: 628 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 8D8FC601E2 for ; Tue, 26 Feb 2019 03:19:29 +0100 (CET) X-Halon-ID: efd1ff10-396c-11e9-985a-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 efd1ff10-396c-11e9-985a-005056917f90; Tue, 26 Feb 2019 03:19:27 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Feb 2019 03:18:56 +0100 Message-Id: <20190226021857.28255-8-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190226021857.28255-1-niklas.soderlund@ragnatech.se> References: <20190226021857.28255-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 7/8] libcamera: camera: ensure streams belong to camera 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, 26 Feb 2019 02:19:29 -0000 Before calling into the pipeline handler make sure the streams provided by the application actually belongs to the camera. Signed-off-by: Niklas Söderlund Reviewed-by: Jacopo Mondi --- src/libcamera/camera.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 938f21fe80ef8ceb..ba8638009992170f 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -253,6 +253,10 @@ Camera::streamConfiguration(std::set &streams) if (!stateIsAtleast(Free) || !streams.size()) return std::map{}; + for (Stream *stream : streams) + if (streams_.find(stream) == streams_.end()) + return std::map{}; + return pipe_->streamConfiguration(this, streams); } @@ -290,6 +294,10 @@ int Camera::configureStreams(std::map &config) return -EINVAL; } + for (auto const &iter : config) + if (streams_.find(iter.first) == streams_.end()) + return -EINVAL; + ret = pipe_->configureStreams(this, config); if (ret) return ret; From patchwork Tue Feb 26 02:18:57 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: 629 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 A1ED0610B7 for ; Tue, 26 Feb 2019 03:19:30 +0100 (CET) X-Halon-ID: f22da30a-396c-11e9-985a-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 f22da30a-396c-11e9-985a-005056917f90; Tue, 26 Feb 2019 03:19:29 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Feb 2019 03:18:57 +0100 Message-Id: <20190226021857.28255-9-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190226021857.28255-1-niklas.soderlund@ragnatech.se> References: <20190226021857.28255-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 8/8] libcamera: camera: make sure camera is configured before starting 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, 26 Feb 2019 02:19:30 -0000 If the camera is not configured there is little use to start it. Add a check to make sure the camera is configured before it's started. Signed-off-by: Niklas Söderlund Reviewed-by: Jacopo Mondi --- src/libcamera/camera.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index ba8638009992170f..cbc34599d25e5ed5 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -423,12 +423,19 @@ int Camera::queueRequest(Request *request) * * \return 0 on success or a negative error code * \retval -EACCES The camera is not in a state where it can be started. + * \retval -EINVAL The camera is not configured. */ int Camera::start() { if (!stateIs(Acquired)) return -EACCES; + if (activeStreams_.empty()) { + LOG(Camera, Error) + << "Can't start camera without configuration"; + return -EINVAL; + } + LOG(Camera, Debug) << "Starting capture"; int ret = pipe_->start(this);