From patchwork Tue May 9 23:07:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 18611 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 20E3FBD16B for ; Tue, 9 May 2023 23:08:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 976CF633B4; Wed, 10 May 2023 01:08:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1683673682; bh=y4gdikqAQXqT9tbF4elr9Dkg8CS6F+IIsBjlQB9Xfsc=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=JsSv0kiFtMV20imYpYKkbW9GBV3nkUsRGTICwLxmL8Fiae0WP3Z4G0/pYJPUJ/0rR gN8wcgo8pBp+SlX7I0QjmD96Bio8CGKqzA6TEkqyW+5zM3qoqsiHyrtXzyaHjXKmxZ jzsXajLY2OmMyv2I/hWOxDjGSEjidzu9qnGeqdyl5dM2L3L2ekB85bIHsnNKJYl1vJ mlz907dQm761sH44rThotbn0wic1Q/KvSvR5o4xxsEkmzxVLHEPzY5jA7Zvo6Qq8Ym YWoqpRgrITsFz8NKwi+Nv+4nbC5ljmN6gW1m0hVZA5ud/s2bsPYmJMxXRb9a1bXWX5 FAqqnA87T5CVA== Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 96E326053A for ; Wed, 10 May 2023 01:08:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=protonmail.com header.i=@protonmail.com header.b="vZ6pcOgP"; dkim-atps=neutral Date: Tue, 09 May 2023 23:07:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1683673680; x=1683932880; bh=bqIfTx04M2uRIjtb7Dz5brDHuZe/evsnekI4o3C956w=; h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=vZ6pcOgPN1tV/UzgoRXe/KDKhVlDyF1gVfdKJIJ0uwFG+XeisvoY2oehDbZsYRe+M T/wcMNzkL2VnW8uhziMBG3jqMxN37wZGYkUn4ba6buzlI0dLxoWwSWzBJcsVJEZO6Y PzvKhBVmigD3bgRdo+H53z5i3eapCq9SP3RVPhCfrXgizPcIEnEr8JmG80Qnt1vxqG ETqyWC0rOVWTvnO1YDyAsIEOWTfICrpYIQroTuUJUl5+9RasFVKywZMV1tfnssGtgT /9Wk1uxAtW/TYVl2Xj5b0xoAtFDRjFkCfJoln8rtg94/P+5JmKs5qwxFrXn/dktbhh Q+cTkWFTaZKYA== To: libcamera-devel@lists.libcamera.org Message-ID: <20230509221750.1116531-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH v3 1/2] libcamera: camera: Take span of StreamRole instead of vector 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-Patchwork-Original-From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze_via_libcamera-devel?= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Change the parameter type of `generateConfiguration()` from `const std::vector&` to `libcamera::Span`. A span is almost always preferable to a const vector ref because it does not force dynamic allocation when none are needed, and it allows any contiguous container to be used. A new overload is added that accepts an initializer list so that cam->generateConfiguration({ ... }) keeps working. There is no API break since a span can be constructed from a vector and the initializer list overload takes care of the initializer lists, but this change causes an ABI break. Signed-off-by: Barnabás Pőcze Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- Documentation/guides/pipeline-handler.rst | 4 ++-- include/libcamera/camera.h | 12 +++++++++++- include/libcamera/internal/pipeline_handler.h | 2 +- src/libcamera/camera.cpp | 8 +++++++- src/libcamera/pipeline/imx8-isi/imx8-isi.cpp | 4 ++-- src/libcamera/pipeline/ipu3/ipu3.cpp | 4 ++-- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 4 ++-- src/libcamera/pipeline/rpi/common/pipeline_base.cpp | 2 +- src/libcamera/pipeline/rpi/common/pipeline_base.h | 2 +- src/libcamera/pipeline/simple/simple.cpp | 4 ++-- src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 4 ++-- src/libcamera/pipeline/vimc/vimc.cpp | 4 ++-- src/py/libcamera/py_main.cpp | 5 ++++- 13 files changed, 39 insertions(+), 20 deletions(-) diff --git a/Documentation/guides/pipeline-handler.rst b/Documentation/guides/pipeline-handler.rst index 57644534..10b9c75c 100644 --- a/Documentation/guides/pipeline-handler.rst +++ b/Documentation/guides/pipeline-handler.rst @@ -203,7 +203,7 @@ implementations for the overridden class members. PipelineHandlerVivid(CameraManager *manager); CameraConfiguration *generateConfiguration(Camera *camera, - const StreamRoles &roles) override; + Span roles) override; int configure(Camera *camera, CameraConfiguration *config) override; int exportFrameBuffers(Camera *camera, Stream *stream, @@ -223,7 +223,7 @@ implementations for the overridden class members. } CameraConfiguration *PipelineHandlerVivid::generateConfiguration(Camera *camera, - const StreamRoles &roles) + Span roles) { return nullptr; } diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index 5bb06584..004bc894 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -7,6 +7,7 @@ #pragma once +#include #include #include #include @@ -105,7 +106,16 @@ public: const ControlList &properties() const; const std::set &streams() const; - std::unique_ptr generateConfiguration(const StreamRoles &roles = {}); + + std::unique_ptr + generateConfiguration(Span roles = {}); + + std::unique_ptr + generateConfiguration(std::initializer_list roles) + { + return generateConfiguration(Span(roles.begin(), roles.end())); + } + int configure(CameraConfiguration *config); std::unique_ptr createRequest(uint64_t cookie = 0); diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h index 4c4dfe62..aaeb3a9e 100644 --- a/include/libcamera/internal/pipeline_handler.h +++ b/include/libcamera/internal/pipeline_handler.h @@ -49,7 +49,7 @@ public: void release(Camera *camera); virtual std::unique_ptr generateConfiguration(Camera *camera, - const StreamRoles &roles) = 0; + Span roles) = 0; virtual int configure(Camera *camera, CameraConfiguration *config) = 0; virtual int exportFrameBuffers(Camera *camera, Stream *stream, diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 99683e49..cf9ca01e 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -938,7 +938,7 @@ const std::set &Camera::streams() const * \return A CameraConfiguration if the requested roles can be satisfied, or a * null pointer otherwise. */ -std::unique_ptr Camera::generateConfiguration(const StreamRoles &roles) +std::unique_ptr Camera::generateConfiguration(Span roles) { Private *const d = _d(); @@ -971,6 +971,12 @@ std::unique_ptr Camera::generateConfiguration(const StreamR return config; } +/** + * \fn std::unique_ptr \ + * Camera::generateConfiguration(std::initializer_list roles) + * \overload + */ + /** * \brief Configure the camera prior to capture * \param[in] config The camera configurations to setup diff --git a/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp b/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp index 449d9012..9bdfff0b 100644 --- a/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp +++ b/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp @@ -104,7 +104,7 @@ public: bool match(DeviceEnumerator *enumerator) override; std::unique_ptr - generateConfiguration(Camera *camera, const StreamRoles &roles) override; + generateConfiguration(Camera *camera, Span roles) override; int configure(Camera *camera, CameraConfiguration *config) override; int exportFrameBuffers(Camera *camera, Stream *stream, @@ -739,7 +739,7 @@ StreamConfiguration PipelineHandlerISI::generateRawConfiguration(Camera *camera) std::unique_ptr PipelineHandlerISI::generateConfiguration(Camera *camera, - const StreamRoles &roles) + Span roles) { ISICameraData *data = cameraData(camera); std::unique_ptr config = diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 355cb0cb..ada8c272 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -135,7 +135,7 @@ public: PipelineHandlerIPU3(CameraManager *manager); std::unique_ptr generateConfiguration(Camera *camera, - const StreamRoles &roles) override; + Span roles) override; int configure(Camera *camera, CameraConfiguration *config) override; int exportFrameBuffers(Camera *camera, Stream *stream, @@ -390,7 +390,7 @@ PipelineHandlerIPU3::PipelineHandlerIPU3(CameraManager *manager) } std::unique_ptr -PipelineHandlerIPU3::generateConfiguration(Camera *camera, const StreamRoles &roles) +PipelineHandlerIPU3::generateConfiguration(Camera *camera, Span roles) { IPU3CameraData *data = cameraData(camera); std::unique_ptr config = diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 8a30fe06..1fdfde7b 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -148,7 +148,7 @@ public: PipelineHandlerRkISP1(CameraManager *manager); std::unique_ptr generateConfiguration(Camera *camera, - const StreamRoles &roles) override; + Span roles) override; int configure(Camera *camera, CameraConfiguration *config) override; int exportFrameBuffers(Camera *camera, Stream *stream, @@ -609,7 +609,7 @@ PipelineHandlerRkISP1::PipelineHandlerRkISP1(CameraManager *manager) std::unique_ptr PipelineHandlerRkISP1::generateConfiguration(Camera *camera, - const StreamRoles &roles) + Span roles) { RkISP1CameraData *data = cameraData(camera); diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index ba1797bc..d7f1d547 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -381,7 +381,7 @@ V4L2DeviceFormat PipelineHandlerBase::toV4L2DeviceFormat(const V4L2VideoDevice * } std::unique_ptr -PipelineHandlerBase::generateConfiguration(Camera *camera, const StreamRoles &roles) +PipelineHandlerBase::generateConfiguration(Camera *camera, Span roles) { CameraData *data = cameraData(camera); std::unique_ptr config = diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h index 6b19b56c..f648e810 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.h +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h @@ -214,7 +214,7 @@ public: BayerFormat::Packing packingReq); std::unique_ptr - generateConfiguration(Camera *camera, const StreamRoles &roles) override; + generateConfiguration(Camera *camera, Span roles) override; int configure(Camera *camera, CameraConfiguration *config) override; int exportFrameBuffers(Camera *camera, libcamera::Stream *stream, diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index 050285fd..b9858353 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -316,7 +316,7 @@ public: SimplePipelineHandler(CameraManager *manager); std::unique_ptr generateConfiguration(Camera *camera, - const StreamRoles &roles) override; + Span roles) override; int configure(Camera *camera, CameraConfiguration *config) override; int exportFrameBuffers(Camera *camera, Stream *stream, @@ -1044,7 +1044,7 @@ SimplePipelineHandler::SimplePipelineHandler(CameraManager *manager) } std::unique_ptr -SimplePipelineHandler::generateConfiguration(Camera *camera, const StreamRoles &roles) +SimplePipelineHandler::generateConfiguration(Camera *camera, Span roles) { SimpleCameraData *data = cameraData(camera); std::unique_ptr config = diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp index 277465b7..03935876 100644 --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp @@ -75,7 +75,7 @@ public: PipelineHandlerUVC(CameraManager *manager); std::unique_ptr generateConfiguration(Camera *camera, - const StreamRoles &roles) override; + Span roles) override; int configure(Camera *camera, CameraConfiguration *config) override; int exportFrameBuffers(Camera *camera, Stream *stream, @@ -180,7 +180,7 @@ PipelineHandlerUVC::PipelineHandlerUVC(CameraManager *manager) std::unique_ptr PipelineHandlerUVC::generateConfiguration(Camera *camera, - const StreamRoles &roles) + Span roles) { UVCCameraData *data = cameraData(camera); std::unique_ptr config = diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp index 204f5ad7..49ee949f 100644 --- a/src/libcamera/pipeline/vimc/vimc.cpp +++ b/src/libcamera/pipeline/vimc/vimc.cpp @@ -85,7 +85,7 @@ public: PipelineHandlerVimc(CameraManager *manager); std::unique_ptr generateConfiguration(Camera *camera, - const StreamRoles &roles) override; + Span roles) override; int configure(Camera *camera, CameraConfiguration *config) override; int exportFrameBuffers(Camera *camera, Stream *stream, @@ -191,7 +191,7 @@ PipelineHandlerVimc::PipelineHandlerVimc(CameraManager *manager) std::unique_ptr PipelineHandlerVimc::generateConfiguration(Camera *camera, - const StreamRoles &roles) + Span roles) { VimcCameraData *data = cameraData(camera); std::unique_ptr config = diff --git a/src/py/libcamera/py_main.cpp b/src/py/libcamera/py_main.cpp index d14e18e2..3f04871f 100644 --- a/src/py/libcamera/py_main.cpp +++ b/src/py/libcamera/py_main.cpp @@ -156,7 +156,10 @@ PYBIND11_MODULE(_libcamera, m) }) /* Keep the camera alive, as StreamConfiguration contains a Stream* */ - .def("generate_configuration", &Camera::generateConfiguration, py::keep_alive<0, 1>()) + .def("generate_configuration", [](Camera &self, const std::vector &roles) { + return self.generateConfiguration(roles); + }, py::keep_alive<0, 1>()) + .def("configure", &Camera::configure) .def("create_request", &Camera::createRequest, py::arg("cookie") = 0)