From patchwork Wed Feb 9 07:19:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 15346 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id C8353C3262 for ; Wed, 9 Feb 2022 07:19:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 32390610EF; Wed, 9 Feb 2022 08:19:31 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="RC/v7GzU"; dkim-atps=neutral Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id ED3DA60E66 for ; Wed, 9 Feb 2022 08:19:29 +0100 (CET) Received: by mail-pl1-x62a.google.com with SMTP id x3so1479000pll.3 for ; Tue, 08 Feb 2022 23:19:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=26FibggvqYPF43PLWR4Cxku84PjjPkOG3Xu8PZWi+7Q=; b=RC/v7GzUm4/FhiQhjjzwH7i+cc/xop0+t7cQkDYk4NxUJh/X2km/T3wjvcDstmPpiR pCrXLaGvPdIitVGn3VzZhuYl/09BCCamw/KVXsLxH7A971G8PyGIbaxL/XhYPoy7MirA yYZNcrLPtDDl4y+UsvoKKJSbWOxOe+BSTLiuI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=26FibggvqYPF43PLWR4Cxku84PjjPkOG3Xu8PZWi+7Q=; b=sGKzCiQ2IPdcyHgxU/4MYrWQSvPZu0d46bE3Bn7sx2RzyHcpfz4yrQoluxQI1gR81b IfD/ePdnlRVYktXQ+wq3p1OtZLHKe8zM/97piirHkeW3ZwNzS1b04EfINcVQdKrTe313 TzS+Yhby49l8adEXeE9MOJPI7kczPNncH8fGZU4iQypkt/x1kW/e/UNQvSFd1FajtyVO gtEzgj+MH/0+wsKyHWVGEZHFd+43Wa8PcqnjWVTF9+SXfsk4C5elVO6y4vfwtGe1p9hY r5sdb6mEBwQn6KBLBxgyed4zCzs0v8tsLk9Ygf+Aw5QeTnAdnt96cnp2JFDB/bJhHNNK 9PJA== X-Gm-Message-State: AOAM532S1cY9W07C706/hFjhEWDmo1JHgGo5cYXL7KDGJSNOJpHG7rc9 UQ2aMW8XokkOC6RExnfpw31biRRZgCix4Q== X-Google-Smtp-Source: ABdhPJyyBucaJsgWM99vyP2VEd+Etg1CUNup3Hxfoixt6z3MAY0Ki4lViR5cxvD9atu+vS/uj+1nEA== X-Received: by 2002:a17:902:e80c:: with SMTP id u12mr1125550plg.159.1644391168337; Tue, 08 Feb 2022 23:19:28 -0800 (PST) Received: from localhost ([2401:fa00:1:10:a5cf:9a43:1c6d:824]) by smtp.gmail.com with UTF8SMTPSA id n22sm18873823pfu.77.2022.02.08.23.19.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 08 Feb 2022 23:19:28 -0800 (PST) From: Han-Lin Chen To: libcamera-devel@lists.libcamera.org Date: Wed, 9 Feb 2022 15:19:10 +0800 Message-Id: <20220209071917.559993-3-hanlinchen@chromium.org> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220209071917.559993-1-hanlinchen@chromium.org> References: <20220209071917.559993-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/9] libcamera: Add options() and setOptions() operations to Camera 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add options() and setOptions() operations to Camera. Both operations takes a camera instance and reads or writes the options to it. Because an option might change the supported characteristics of a camera module, it could only be set before configuring. Signed-off-by: Han-Lin Chen --- include/libcamera/camera.h | 3 + include/libcamera/internal/camera.h | 2 + include/libcamera/internal/pipeline_handler.h | 2 + src/libcamera/camera.cpp | 59 +++++++++++++++++++ src/libcamera/pipeline_handler.cpp | 26 ++++++++ 5 files changed, 92 insertions(+) diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index 5bb06584..1bb80a6d 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -98,9 +98,12 @@ public: Signal requestCompleted; Signal<> disconnected; + int setOptions(const ControlList *options = nullptr); + int acquire(); int release(); + const ControlInfoMap &options() const; const ControlInfoMap &controls() const; const ControlList &properties() const; diff --git a/include/libcamera/internal/camera.h b/include/libcamera/internal/camera.h index 597426a6..c3cb1865 100644 --- a/include/libcamera/internal/camera.h +++ b/include/libcamera/internal/camera.h @@ -34,6 +34,8 @@ public: PipelineHandler *pipe() { return pipe_.get(); } std::list queuedRequests_; + + ControlInfoMap optionInfo_; ControlInfoMap controlInfo_; ControlList properties_; diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h index c3e4c258..184e4b9a 100644 --- a/include/libcamera/internal/pipeline_handler.h +++ b/include/libcamera/internal/pipeline_handler.h @@ -45,6 +45,8 @@ public: MediaDevice *acquireMediaDevice(DeviceEnumerator *enumerator, const DeviceMatch &dm); + virtual int setOptions(Camera *camera, const ControlList *options); + bool lock(); void unlock(); diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index bb856d60..9e95e6cc 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -480,6 +480,16 @@ Camera::Private::~Private() * well, when implementing official support for control info updates. */ +/** + * \var Camera::Private::optionInfo_ + * \brief The set of options supported by the camera + * + * The optionInfo_ information shall be initialised by the pipeline handler when + * creating the camera. + * + * This member was meant to stay constant after the camera is created. + */ + /** * \var Camera::Private::properties_ * \brief The list of properties supported by the camera @@ -802,6 +812,40 @@ int Camera::exportFrameBuffers(Stream *stream, buffers); } +/** + * \brief Set Options for a camera. + * \param[in] options Options to be applied before configuring a camera + * + * Prior to configuring a camera, it's optional to set options to a camera to + * change its characteristics or internal behaviors. The supported options are + * depended on the platform. The caller should iterate supported Options by + * options() before setting them. + * + * Options might change the internal behavior of configure() and capturing + * images, and thus the function can only be called before configure(). + * It's encouraged to re-check the results of controls(), properties() and + * generateConfiguration() after setting options to a camera. + * + * \context This function shall be synchronized by the caller with other + * functions that affect the camera state. + * + * \return 0 on success or a negative error code otherwise + * \retval -EACCES The camera is not in a state where it can set options + * \retval -EINVAL The options is not valid + */ +int Camera::setOptions(const ControlList *options) +{ + Private *const d = _d(); + + int ret = d->isAccessAllowed(Private::CameraAvailable, + Private::CameraAcquired); + if (ret < 0) + return -EACCES; + + return d->pipe_->invokeMethod(&PipelineHandler::setOptions, + ConnectionTypeBlocking, this, options); +} + /** * \brief Acquire the camera device for exclusive access * @@ -894,6 +938,21 @@ const ControlInfoMap &Camera::controls() const return _d()->controlInfo_; } +/** + * \brief Retrieve the list of options supported by the camera + * + * The list of options supported by the camera and their associated + * constraints remain constant through the lifetime of the Camera object. + * + * \context This function is \threadsafe. + * + * \return A ControlInfoMap listing the options supported by the camera + */ +const ControlInfoMap &Camera::options() const +{ + return _d()->optionInfo_; +} + /** * \brief Retrieve the list of properties of the camera * diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index 7ebd76ad..1f2a6d7e 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -142,6 +142,32 @@ MediaDevice *PipelineHandler::acquireMediaDevice(DeviceEnumerator *enumerator, return media.get(); } +/** + * \fn PipelineHandler::setOptions() + * \brief Set options for camera + * \param[in] camera The camera to set options + * \param[in] options Options to be applied to the Camera + * + * Set options to the camera. The supported options are different for each + * pipeline handler. The intended caller of the this function could iterate + * options supported by the camera with Camera::options(). + * + * The intended caller of this function is the Camera class which will in turn + * be called from the application to indicate that a set of options should be + * applied. The user should check supported options with Camera::options() + * before setting them. + * + * \context This function is called from the CameraManager thread. + * + * \return 0 on success or a negative error code otherwise + */ +int PipelineHandler::setOptions([[maybe_unused]] Camera *camera, + [[maybe_unused]] const ControlList *options) +{ + /* The default implementation which supported no options. */ + return -EINVAL; +} + /** * \brief Lock all media devices acquired by the pipeline *