{"id":767,"url":"https://patchwork.libcamera.org/api/patches/767/?format=json","web_url":"https://patchwork.libcamera.org/patch/767/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20190320163055.22056-22-jacopo@jmondi.org>","date":"2019-03-20T16:30:45","name":"[libcamera-devel,v4,21/31] RFC: libcamera: pipeline_handlers: Add preAllocateBuffers","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"d3f7d84f22ce0e6dc2ee95f73bfb648813046b58","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/767/mbox/","series":[{"id":214,"url":"https://patchwork.libcamera.org/api/series/214/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=214","date":"2019-03-20T16:30:24","name":"libcamera: ipu3: Add ImgU support + multiple streams","version":4,"mbox":"https://patchwork.libcamera.org/series/214/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/767/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/767/checks/","tags":{},"headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay12.mail.gandi.net (relay12.mail.gandi.net\n\t[217.70.178.232])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1AD50611B4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 20 Mar 2019 17:30:41 +0100 (CET)","from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay12.mail.gandi.net (Postfix) with ESMTPSA id A2582200012;\n\tWed, 20 Mar 2019 16:30:40 +0000 (UTC)"],"From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed, 20 Mar 2019 17:30:45 +0100","Message-Id":"<20190320163055.22056-22-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.21.0","In-Reply-To":"<20190320163055.22056-1-jacopo@jmondi.org>","References":"<20190320163055.22056-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v4 21/31] RFC: libcamera:\n\tpipeline_handlers: Add preAllocateBuffers","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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>","X-List-Received-Date":"Wed, 20 Mar 2019 16:30:41 -0000"},"content":"Add a preAllocateBuffers virtual method to the PipelineHandler base\nclass and call it before performing per-stream memory allocation.\n\nImplement the method in the IPU3 pipeline handler to perform memory\nallocation on the CIO2 unit and the ImgU input and stat video devices.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/camera.cpp                 | 10 ++++-\n src/libcamera/include/pipeline_handler.h |  5 +++\n src/libcamera/pipeline/ipu3/ipu3.cpp     | 54 ++++++++++++++----------\n src/libcamera/pipeline_handler.cpp       | 21 ++++++++-\n 4 files changed, 66 insertions(+), 24 deletions(-)","diff":"diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\nindex 8ee9cc086616..8020dff8f8ea 100644\n--- a/src/libcamera/camera.cpp\n+++ b/src/libcamera/camera.cpp\n@@ -455,6 +455,8 @@ int Camera::configureStreams(std::map<Stream *, StreamConfiguration> &config)\n  */\n int Camera::allocateBuffers()\n {\n+\tint ret;\n+\n \tif (disconnected_)\n \t\treturn -ENODEV;\n \n@@ -467,8 +469,14 @@ int Camera::allocateBuffers()\n \t\treturn -EINVAL;\n \t}\n \n+\tret = pipe_->preAllocateBuffers(this, activeStreams_);\n+\tif (ret) {\n+\t\tLOG(Camera, Error) << \"Buffers pre-allocation failed\";\n+\t\treturn ret;\n+\t}\n+\n \tfor (Stream *stream : activeStreams_) {\n-\t\tint ret = pipe_->allocateBuffers(this, stream);\n+\t\tret = pipe_->allocateBuffers(this, stream);\n \t\tif (ret) {\n \t\t\tLOG(Camera, Error) << \"Failed to allocate buffers\";\n \t\t\tfreeBuffers();\ndiff --git a/src/libcamera/include/pipeline_handler.h b/src/libcamera/include/pipeline_handler.h\nindex acb376e07030..7ce5b67cc7fc 100644\n--- a/src/libcamera/include/pipeline_handler.h\n+++ b/src/libcamera/include/pipeline_handler.h\n@@ -57,6 +57,11 @@ public:\n \tvirtual int configureStreams(Camera *camera,\n \t\t\t\t     std::map<Stream *, StreamConfiguration> &config) = 0;\n \n+\tvirtual int preAllocateBuffers(Camera *camera,\n+\t\t\t\t       const std::set<Stream *> &activeStreams)\n+\t{\n+\t\treturn 0;\n+\t}\n \tvirtual int allocateBuffers(Camera *camera, Stream *stream) = 0;\n \tvirtual int freeBuffers(Camera *camera, Stream *stream) = 0;\n \ndiff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex 0507fc380e68..5f323888d84f 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -105,6 +105,8 @@ public:\n \tint configureStreams(Camera *camera,\n \t\t\t     std::map<Stream *, StreamConfiguration> &config) override;\n \n+\tint preAllocateBuffers(Camera *camera,\n+\t\t\t       const std::set<Stream *> &activeStreams) override;\n \tint allocateBuffers(Camera *camera, Stream *stream) override;\n \tint freeBuffers(Camera *camera, Stream *stream) override;\n \n@@ -451,40 +453,48 @@ int PipelineHandlerIPU3::configureStreams(Camera *camera,\n \treturn 0;\n }\n \n-int PipelineHandlerIPU3::allocateBuffers(Camera *camera, Stream *stream)\n+int PipelineHandlerIPU3::preAllocateBuffers(Camera *camera,\n+\t\t\t\t\t    const std::set<Stream *> &activeStreams)\n {\n \tIPU3CameraData *data = cameraData(camera);\n-\tV4L2Device *viewfinder = data->imgu->viewfinder;\n-\tV4L2Device *output = data->imgu->output;\n \tV4L2Device *input = data->imgu->input;\n \tV4L2Device *cio2 = data->cio2.output;\n \tV4L2Device *stat = data->imgu->stat;\n \tImgUDevice *imgu = data->imgu;\n \tint ret;\n \n-\tif (data->cio2.pool.count() == 0) {\n-\t\t/* Share buffers between CIO2 output and ImgU input. */\n-\t\tdata->cio2.pool.createBuffers(IPU3_CIO2_BUFFER_COUNT);\n-\t\tret = cio2->exportBuffers(&data->cio2.pool);\n-\t\tif (ret) {\n-\t\t\tLOG(IPU3, Error) << \"Failed to reserve CIO2 memory\";\n-\t\t\treturn ret;\n-\t\t}\n+\t/* Share buffers between CIO2 output and ImgU input. */\n+\tdata->cio2.pool.createBuffers(IPU3_CIO2_BUFFER_COUNT);\n+\tret = cio2->exportBuffers(&data->cio2.pool);\n+\tif (ret) {\n+\t\tLOG(IPU3, Error) << \"Failed to reserve CIO2 memory\";\n+\t\treturn ret;\n+\t}\n \n-\t\tret = input->importBuffers(&data->cio2.pool);\n-\t\tif (ret) {\n-\t\t\tLOG(IPU3, Error) << \"Failed to import ImgU memory\";\n-\t\t\treturn ret;\n-\t\t}\n+\tret = input->importBuffers(&data->cio2.pool);\n+\tif (ret) {\n+\t\tLOG(IPU3, Error) << \"Failed to import ImgU memory\";\n+\t\treturn ret;\n+\t}\n \n-\t\timgu->statPool.createBuffers(IPU3_IMGU_BUFFER_COUNT);\n-\t\tret = stat->exportBuffers(&imgu->statPool);\n-\t\tif (ret) {\n-\t\t\tLOG(IPU3, Error) << \"Failed to reserve ImgU stat memory\";\n-\t\t\treturn ret;\n-\t\t}\n+\timgu->statPool.createBuffers(IPU3_IMGU_BUFFER_COUNT);\n+\tret = stat->exportBuffers(&imgu->statPool);\n+\tif (ret) {\n+\t\tLOG(IPU3, Error) << \"Failed to reserve ImgU stat memory\";\n+\t\treturn ret;\n \t}\n \n+\treturn 0;\n+}\n+\n+int PipelineHandlerIPU3::allocateBuffers(Camera *camera, Stream *stream)\n+{\n+\tIPU3CameraData *data = cameraData(camera);\n+\tV4L2Device *viewfinder = data->imgu->viewfinder;\n+\tV4L2Device *output = data->imgu->output;\n+\tImgUDevice *imgu = data->imgu;\n+\tint ret;\n+\n \tif (isOutput(data, stream)) {\n \t\t/* Export ImgU output buffers to the stream's pool. */\n \t\tret = output->exportBuffers(&stream->bufferPool());\ndiff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp\nindex 1a858f2638ce..1f556ed789b6 100644\n--- a/src/libcamera/pipeline_handler.cpp\n+++ b/src/libcamera/pipeline_handler.cpp\n@@ -189,6 +189,24 @@ PipelineHandler::~PipelineHandler()\n  * \\return 0 on success or a negative error code otherwise\n  */\n \n+/**\n+ * \\fn PipelineHandler::preAllocateBuffers()\n+ * \\brief Perform operations to prepare for memory allocation. Optional for\n+ * pipeline handlers to implement\n+ * \\param[in] camera The camera the streams belongs to\n+ * \\param[in] activeStreams The set of active streams\n+ *\n+ * If operations to prepare for the per-stream memory allocation are required,\n+ * this virtual method provides an entry point for pipeline handlers to do so.\n+ *\n+ * This method is optional to implement for pipeline handlers, and its intended\n+ * caller is the Camera class, which calls it once before performing per-stream\n+ * memory allocation by calling the PipelineHandler::allocateBuffers() method\n+ * once per each active stream.\n+ *\n+ * \\return 0 on success or a negative error code otherwise\n+ */\n+\n /**\n  * \\fn PipelineHandler::allocateBuffers()\n  * \\brief Allocate buffers for a stream\n@@ -198,7 +216,8 @@ PipelineHandler::~PipelineHandler()\n  * This method allocates buffers internally in the pipeline handler and\n  * associates them with the stream's buffer pool.\n  *\n- * The intended caller of this method is the Camera class.\n+ * The intended caller of this method is the Camera class which calls it\n+ * once per each active stream.\n  *\n  * \\return 0 on success or a negative error code otherwise\n  */\n","prefixes":["libcamera-devel","v4","21/31"]}