{"id":13094,"url":"https://patchwork.libcamera.org/api/1.1/patches/13094/?format=json","web_url":"https://patchwork.libcamera.org/patch/13094/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210723040036.32346-9-laurent.pinchart@ideasonboard.com>","date":"2021-07-23T04:00:27","name":"[libcamera-devel,RFC,08/17] libcamera: camera: Pass Private pointer to Camera constructor","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"05ea75b7cf3dbc21fec61abdbc857d245a0c8fe5","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/13094/mbox/","series":[{"id":2270,"url":"https://patchwork.libcamera.org/api/1.1/series/2270/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2270","date":"2021-07-23T04:00:19","name":"libcamera: Replace CameraData with Camera::Private","version":1,"mbox":"https://patchwork.libcamera.org/series/2270/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/13094/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/13094/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 18F64C322B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 23 Jul 2021 04:00:54 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9C884687A6;\n\tFri, 23 Jul 2021 06:00:53 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A10DD687B3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 23 Jul 2021 06:00:45 +0200 (CEST)","from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 4886C255\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 23 Jul 2021 06:00:45 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"gXYFxuDT\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1627012845;\n\tbh=4dx/v2c8jRR9FRY0TwaObkwD357G4HhrpQ0on5oxlW0=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=gXYFxuDTQV4ImzNSZixPpP38wYtkn3Oh/yDEUD9PVf9eGuMFE6mjX8zjtzWiVPonE\n\t/3Lyyyve0WbCTO4LXygvvuflNLCAvGko7iyH0hWQgWfDzuOCdR7/q6uTmIQviJfYUV\n\t2mVOCku3XxL2mf06hOxu4R0P5XeY1EsxhPgi5Eug=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 23 Jul 2021 07:00:27 +0300","Message-Id":"<20210723040036.32346-9-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.31.1","In-Reply-To":"<20210723040036.32346-1-laurent.pinchart@ideasonboard.com>","References":"<20210723040036.32346-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [RFC PATCH 08/17] libcamera: camera: Pass Private\n\tpointer to Camera constructor","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"In order to allow subclassing Camera::Private in pipeline handlers, pass\nthe pointer to the private data to the Camera constructor, and to the\nCamera::createCamera() function.\n\nThe Camera::Private id_ and streams_ members now need to be initialized\nby the Camera constructor instead of the Camera::Private constructor, to\nallow storage of the streams in a pipeline handler-specific subclass of\nCamera::Private.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/camera.h                    |  5 ++--\n include/libcamera/internal/camera.h           |  3 +--\n src/libcamera/camera.cpp                      | 26 ++++++++++++-------\n src/libcamera/pipeline/ipu3/ipu3.cpp          |  4 ++-\n .../pipeline/raspberrypi/raspberrypi.cpp      |  4 ++-\n src/libcamera/pipeline/rkisp1/rkisp1.cpp      |  4 ++-\n src/libcamera/pipeline/simple/simple.cpp      |  4 ++-\n src/libcamera/pipeline/uvcvideo/uvcvideo.cpp  |  4 ++-\n src/libcamera/pipeline/vimc/vimc.cpp          |  4 ++-\n 9 files changed, 37 insertions(+), 21 deletions(-)","diff":"diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h\nindex b081907e0cb1..17ddddc2722a 100644\n--- a/include/libcamera/camera.h\n+++ b/include/libcamera/camera.h\n@@ -78,8 +78,7 @@ class Camera final : public Object, public std::enable_shared_from_this<Camera>,\n \tLIBCAMERA_DECLARE_PRIVATE()\n \n public:\n-\tstatic std::shared_ptr<Camera> create(PipelineHandler *pipe,\n-\t\t\t\t\t      const std::string &id,\n+\tstatic std::shared_ptr<Camera> create(Private *d, const std::string &id,\n \t\t\t\t\t      const std::set<Stream *> &streams);\n \n \tconst std::string &id() const;\n@@ -107,7 +106,7 @@ public:\n private:\n \tLIBCAMERA_DISABLE_COPY(Camera)\n \n-\tCamera(PipelineHandler *pipe, const std::string &id,\n+\tCamera(Private *d, const std::string &id,\n \t       const std::set<Stream *> &streams);\n \t~Camera();\n \ndiff --git a/include/libcamera/internal/camera.h b/include/libcamera/internal/camera.h\nindex b60ed140356a..9ec8321a9a21 100644\n--- a/include/libcamera/internal/camera.h\n+++ b/include/libcamera/internal/camera.h\n@@ -26,8 +26,7 @@ class Camera::Private : public Extensible::Private\n \tLIBCAMERA_DECLARE_PUBLIC(Camera)\n \n public:\n-\tPrivate(PipelineHandler *pipe, const std::string &id,\n-\t\tconst std::set<Stream *> &streams);\n+\tPrivate(PipelineHandler *pipe);\n \t~Private();\n \n private:\ndiff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\nindex 4b5bc891fc37..a5bb60c698bc 100644\n--- a/src/libcamera/camera.cpp\n+++ b/src/libcamera/camera.cpp\n@@ -332,11 +332,13 @@ std::size_t CameraConfiguration::size() const\n  * \\brief The vector of stream configurations\n  */\n \n-Camera::Private::Private(PipelineHandler *pipe,\n-\t\t\t const std::string &id,\n-\t\t\t const std::set<Stream *> &streams)\n-\t: pipe_(pipe->shared_from_this()), id_(id), streams_(streams),\n-\t  disconnected_(false), state_(CameraAvailable)\n+/**\n+ * \\brief Construct a Camera::Private instance\n+ * \\param[in] pipe The pipeline handler responsible for the camera device\n+ */\n+Camera::Private::Private(PipelineHandler *pipe)\n+\t: pipe_(pipe->shared_from_this()), disconnected_(false),\n+\t  state_(CameraAvailable)\n {\n }\n \n@@ -513,7 +515,7 @@ void Camera::Private::setState(State state)\n \n /**\n  * \\brief Create a camera instance\n- * \\param[in] pipe The pipeline handler responsible for the camera device\n+ * \\param[in] d Camera private data\n  * \\param[in] id The ID of the camera device\n  * \\param[in] streams Array of streams the camera provides\n  *\n@@ -527,10 +529,12 @@ void Camera::Private::setState(State state)\n  *\n  * \\return A shared pointer to the newly created camera object\n  */\n-std::shared_ptr<Camera> Camera::create(PipelineHandler *pipe,\n+std::shared_ptr<Camera> Camera::create(Private *d,\n \t\t\t\t       const std::string &id,\n \t\t\t\t       const std::set<Stream *> &streams)\n {\n+\tASSERT(d);\n+\n \tstruct Deleter : std::default_delete<Camera> {\n \t\tvoid operator()(Camera *camera)\n \t\t{\n@@ -541,7 +545,7 @@ std::shared_ptr<Camera> Camera::create(PipelineHandler *pipe,\n \t\t}\n \t};\n \n-\tCamera *camera = new Camera(pipe, id, streams);\n+\tCamera *camera = new Camera(d, id, streams);\n \n \treturn std::shared_ptr<Camera>(camera, Deleter());\n }\n@@ -594,10 +598,12 @@ const std::string &Camera::id() const\n  * application API calls by returning errors immediately.\n  */\n \n-Camera::Camera(PipelineHandler *pipe, const std::string &id,\n+Camera::Camera(Private *d, const std::string &id,\n \t       const std::set<Stream *> &streams)\n-\t: Extensible(new Private(pipe, id, streams))\n+\t: Extensible(d)\n {\n+\td->id_ = id;\n+\td->streams_ = streams;\n }\n \n Camera::~Camera()\ndiff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex 76c3bb3d8aa9..15d6cca609ff 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -23,6 +23,7 @@\n #include <libcamera/request.h>\n #include <libcamera/stream.h>\n \n+#include \"libcamera/internal/camera.h\"\n #include \"libcamera/internal/camera_sensor.h\"\n #include \"libcamera/internal/delayed_controls.h\"\n #include \"libcamera/internal/device_enumerator.h\"\n@@ -1185,7 +1186,8 @@ int PipelineHandlerIPU3::registerCameras()\n \t\t/* Create and register the Camera instance. */\n \t\tstd::string cameraId = cio2->sensor()->id();\n \t\tstd::shared_ptr<Camera> camera =\n-\t\t\tCamera::create(this, cameraId, streams);\n+\t\t\tCamera::create(new Camera::Private(this), cameraId,\n+\t\t\t\t       streams);\n \n \t\tregisterCamera(std::move(camera), std::move(data));\n \ndiff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex f821d8fe1b6c..2411f73f48e0 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -30,6 +30,7 @@\n #include <linux/videodev2.h>\n \n #include \"libcamera/internal/bayer_format.h\"\n+#include \"libcamera/internal/camera.h\"\n #include \"libcamera/internal/camera_sensor.h\"\n #include \"libcamera/internal/delayed_controls.h\"\n #include \"libcamera/internal/device_enumerator.h\"\n@@ -1106,7 +1107,8 @@ bool PipelineHandlerRPi::match(DeviceEnumerator *enumerator)\n \n \t/* Create and register the camera. */\n \tstd::shared_ptr<Camera> camera =\n-\t\tCamera::create(this, data->sensor_->id(), streams);\n+\t\tCamera::create(new Camera::Private(this), data->sensor_->id(),\n+\t\t\t       streams);\n \tregisterCamera(std::move(camera), std::move(data));\n \n \treturn true;\ndiff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\nindex 42911a8fdfdb..4a8ac97d5ef0 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n@@ -27,6 +27,7 @@\n #include <libcamera/request.h>\n #include <libcamera/stream.h>\n \n+#include \"libcamera/internal/camera.h\"\n #include \"libcamera/internal/camera_sensor.h\"\n #include \"libcamera/internal/delayed_controls.h\"\n #include \"libcamera/internal/device_enumerator.h\"\n@@ -970,7 +971,8 @@ int PipelineHandlerRkISP1::createCamera(MediaEntity *sensor)\n \t\t&data->selfPathStream_,\n \t};\n \tstd::shared_ptr<Camera> camera =\n-\t\tCamera::create(this, data->sensor_->id(), streams);\n+\t\tCamera::create(new Camera::Private(this), data->sensor_->id(),\n+\t\t\t       streams);\n \tregisterCamera(std::move(camera), std::move(data));\n \n \treturn 0;\ndiff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp\nindex b29fff9820e5..43af3fafa475 100644\n--- a/src/libcamera/pipeline/simple/simple.cpp\n+++ b/src/libcamera/pipeline/simple/simple.cpp\n@@ -28,6 +28,7 @@\n #include <libcamera/request.h>\n #include <libcamera/stream.h>\n \n+#include \"libcamera/internal/camera.h\"\n #include \"libcamera/internal/camera_sensor.h\"\n #include \"libcamera/internal/device_enumerator.h\"\n #include \"libcamera/internal/media_device.h\"\n@@ -1046,7 +1047,8 @@ bool SimplePipelineHandler::match(DeviceEnumerator *enumerator)\n \t\t\t       [](Stream &stream) { return &stream; });\n \n \t\tstd::shared_ptr<Camera> camera =\n-\t\t\tCamera::create(this, data->sensor_->id(), streams);\n+\t\t\tCamera::create(new Camera::Private(this),\n+\t\t\t\t       data->sensor_->id(), streams);\n \t\tregisterCamera(std::move(camera), std::move(data));\n \t\tregistered = true;\n \t}\ndiff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\nindex 0f634b8da609..63cb1daaae22 100644\n--- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n+++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n@@ -22,6 +22,7 @@\n #include <libcamera/request.h>\n #include <libcamera/stream.h>\n \n+#include \"libcamera/internal/camera.h\"\n #include \"libcamera/internal/device_enumerator.h\"\n #include \"libcamera/internal/media_device.h\"\n #include \"libcamera/internal/pipeline_handler.h\"\n@@ -470,7 +471,8 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator)\n \t}\n \n \tstd::set<Stream *> streams{ &data->stream_ };\n-\tstd::shared_ptr<Camera> camera = Camera::create(this, id, streams);\n+\tstd::shared_ptr<Camera> camera =\n+\t\tCamera::create(new Camera::Private(this), id, streams);\n \tregisterCamera(std::move(camera), std::move(data));\n \n \t/* Enable hot-unplug notifications. */\ndiff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp\nindex 12f7517fd0ae..d63562b1ee54 100644\n--- a/src/libcamera/pipeline/vimc/vimc.cpp\n+++ b/src/libcamera/pipeline/vimc/vimc.cpp\n@@ -29,6 +29,7 @@\n #include <libcamera/ipa/vimc_ipa_interface.h>\n #include <libcamera/ipa/vimc_ipa_proxy.h>\n \n+#include \"libcamera/internal/camera.h\"\n #include \"libcamera/internal/camera_sensor.h\"\n #include \"libcamera/internal/device_enumerator.h\"\n #include \"libcamera/internal/ipa_manager.h\"\n@@ -438,7 +439,8 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator)\n \t/* Create and register the camera. */\n \tstd::set<Stream *> streams{ &data->stream_ };\n \tstd::shared_ptr<Camera> camera =\n-\t\tCamera::create(this, data->sensor_->id(), streams);\n+\t\tCamera::create(new Camera::Private(this), data->sensor_->id(),\n+\t\t\t       streams);\n \tregisterCamera(std::move(camera), std::move(data));\n \n \treturn true;\n","prefixes":["libcamera-devel","RFC","08/17"]}