Patch Detail
Show a patch.
GET /api/patches/1535/?format=api
{ "id": 1535, "url": "https://patchwork.libcamera.org/api/patches/1535/?format=api", "web_url": "https://patchwork.libcamera.org/patch/1535/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20190630181049.9548-3-jacopo@jmondi.org>", "date": "2019-06-30T18:10:43", "name": "[libcamera-devel,RFC,2/8] libcamera: stream: Provide accessors to buffers", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "7e990392d84203db0ddd96f7722bfbb92aeb741e", "submitter": { "id": 3, "url": "https://patchwork.libcamera.org/api/people/3/?format=api", "name": "Jacopo Mondi", "email": "jacopo@jmondi.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/1535/mbox/", "series": [ { "id": 383, "url": "https://patchwork.libcamera.org/api/series/383/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=383", "date": "2019-06-30T18:10:41", "name": "libcamera: Add support for importing external memory buffers", "version": 1, "mbox": "https://patchwork.libcamera.org/series/383/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/1535/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/1535/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 B6E8561EB4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 30 Jun 2019 20:09:38 +0200 (CEST)", "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 5B8F7200004;\n\tSun, 30 Jun 2019 18:09:38 +0000 (UTC)" ], "From": "Jacopo Mondi <jacopo@jmondi.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Sun, 30 Jun 2019 20:10:43 +0200", "Message-Id": "<20190630181049.9548-3-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.21.0", "In-Reply-To": "<20190630181049.9548-1-jacopo@jmondi.org>", "References": "<20190630181049.9548-1-jacopo@jmondi.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [RFC 2/8] libcamera: stream: Provide accessors to\n\tbuffers", "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": "Sun, 30 Jun 2019 18:09:38 -0000" }, "content": "All interactions with the Stream's buffers currently go through the\nBufferPool. In order to shorten accessing the buffers array, and\nrestrict access to the Stream's internal buffer pool, provide operations\nto access the buffers, create and destriy them.\n\nIt is still possible to access the pool for pipeline handlers to\npopulate it by exporting buffers from a video device to the pool.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n include/libcamera/stream.h | 12 ++++++++++\n src/cam/capture.cpp | 4 ++--\n src/libcamera/camera.cpp | 6 ++---\n src/libcamera/pipeline/ipu3/ipu3.cpp | 4 ++--\n src/libcamera/stream.cpp | 35 +++++++++++++++++++++++-----\n src/qcam/main_window.cpp | 4 +---\n test/camera/capture.cpp | 3 +--\n test/camera/statemachine.cpp | 3 +--\n 8 files changed, 51 insertions(+), 20 deletions(-)", "diff": "diff --git a/include/libcamera/stream.h b/include/libcamera/stream.h\nindex 5b4fea324ce4..fa7d6ba4987c 100644\n--- a/include/libcamera/stream.h\n+++ b/include/libcamera/stream.h\n@@ -66,12 +66,24 @@ class Stream\n {\n public:\n \tStream();\n+\t/*\n+\t * FIXME:\n+\t * If I could find a way to export buffers in pipeline handlers\n+\t * without accessing the pool with\n+\t * \tvideo_->exportBuffers(&stream->bufferPool());\n+\t * we could remove access to the internal pool completely.\n+\t */\n \tBufferPool &bufferPool() { return bufferPool_; }\n+\tstd::vector<Buffer> &buffers() { return bufferPool_.buffers(); }\n+\tunsigned int bufferCount() const { return bufferPool_.count(); }\n \tconst StreamConfiguration &configuration() const { return configuration_; }\n \n protected:\n \tfriend class Camera;\n \n+\tvoid createBuffers(unsigned int count);\n+\tvoid destroyBuffers();\n+\n \tBufferPool bufferPool_;\n \tStreamConfiguration configuration_;\n };\ndiff --git a/src/cam/capture.cpp b/src/cam/capture.cpp\nindex 6b842d73390d..1bcc9c7e9cf4 100644\n--- a/src/cam/capture.cpp\n+++ b/src/cam/capture.cpp\n@@ -76,7 +76,7 @@ int Capture::capture(EventLoop *loop)\n \tunsigned int nbuffers = UINT_MAX;\n \tfor (StreamConfiguration &cfg : *config_) {\n \t\tStream *stream = cfg.stream();\n-\t\tnbuffers = std::min(nbuffers, stream->bufferPool().count());\n+\t\tnbuffers = std::min(nbuffers, stream->bufferCount());\n \t}\n \n \t/*\n@@ -95,7 +95,7 @@ int Capture::capture(EventLoop *loop)\n \t\tstd::map<Stream *, Buffer *> map;\n \t\tfor (StreamConfiguration &cfg : *config_) {\n \t\t\tStream *stream = cfg.stream();\n-\t\t\tmap[stream] = &stream->bufferPool().buffers()[i];\n+\t\t\tmap[stream] = &stream->buffers()[i];\n \t\t}\n \n \t\tret = request->setBuffers(map);\ndiff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\nindex 617ea99cdf71..023ae53e5f9d 100644\n--- a/src/libcamera/camera.cpp\n+++ b/src/libcamera/camera.cpp\n@@ -671,7 +671,7 @@ int Camera::configure(CameraConfiguration *config)\n \t\t * Allocate buffer objects in the pool.\n \t\t * Memory will be allocated and assigned later.\n \t\t */\n-\t\tstream->bufferPool().createBuffers(cfg.bufferCount);\n+\t\tstream->createBuffers(cfg.bufferCount);\n \t}\n \n \tstate_ = CameraConfigured;\n@@ -728,14 +728,14 @@ int Camera::freeBuffers()\n \t\treturn -EACCES;\n \n \tfor (Stream *stream : activeStreams_) {\n-\t\tif (!stream->bufferPool().count())\n+\t\tif (!stream->bufferCount())\n \t\t\tcontinue;\n \n \t\t/*\n \t\t * All mappings must be destroyed before buffers can be freed\n \t\t * by the V4L2 device that has allocated them.\n \t\t */\n-\t\tstream->bufferPool().destroyBuffers();\n+\t\tstream->destroyBuffers();\n \t}\n \n \tstate_ = CameraConfigured;\ndiff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex e4efb9722f76..2de0892138a8 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -634,7 +634,7 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera,\n \t * of buffers as the active ones.\n \t */\n \tif (!outStream->active_) {\n-\t\tbufferCount = vfStream->bufferPool().count();\n+\t\tbufferCount = vfStream->bufferCount();\n \t\toutStream->device_->pool->createBuffers(bufferCount);\n \t\tret = imgu->exportBuffers(outStream->device_,\n \t\t\t\t\t outStream->device_->pool);\n@@ -643,7 +643,7 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera,\n \t}\n \n \tif (!vfStream->active_) {\n-\t\tbufferCount = outStream->bufferPool().count();\n+\t\tbufferCount = outStream->bufferCount();\n \t\tvfStream->device_->pool->createBuffers(bufferCount);\n \t\tret = imgu->exportBuffers(vfStream->device_,\n \t\t\t\t\t vfStream->device_->pool);\ndiff --git a/src/libcamera/stream.cpp b/src/libcamera/stream.cpp\nindex d8e87c62281c..c6701e5f9921 100644\n--- a/src/libcamera/stream.cpp\n+++ b/src/libcamera/stream.cpp\n@@ -408,14 +408,12 @@ Stream::Stream()\n }\n \n /**\n- * \\fn Stream::bufferPool()\n- * \\brief Retrieve the buffer pool for the stream\n+ * \\fn Stream::buffers()\n+ * \\brief Retrieve the stream's buffers\n *\n- * The buffer pool handles the buffers used to capture frames at the output of\n- * the stream. It is initially created empty and shall be populated with\n- * buffers before being used.\n+ * \\todo\n *\n- * \\return A reference to the buffer pool\n+ * \\return The list of stream's buffers\n */\n \n /**\n@@ -424,6 +422,31 @@ Stream::Stream()\n * \\return The active configuration of the stream\n */\n \n+/**\n+ * \\brief Create buffers for the stream\n+ *\n+ * \\todo\n+ */\n+void Stream::createBuffers(unsigned int count)\n+{\n+\tbufferPool_.destroyBuffers();\n+\n+\tif (count == 0)\n+\t\treturn;\n+\n+\tbufferPool_.createBuffers(count);\n+}\n+\n+/**\n+ * \\brief Destroy buffers in the stream\n+ *\n+ * \\todo\n+ */\n+void Stream::destroyBuffers()\n+{\n+\tcreateBuffers(0);\n+}\n+\n /**\n * \\var Stream::bufferPool_\n * \\brief The pool of buffers associated with the stream\ndiff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp\nindex 16b123132dd9..a0703b322c16 100644\n--- a/src/qcam/main_window.cpp\n+++ b/src/qcam/main_window.cpp\n@@ -122,10 +122,8 @@ int MainWindow::startCapture()\n \t\treturn ret;\n \t}\n \n-\tBufferPool &pool = stream->bufferPool();\n \tstd::vector<Request *> requests;\n-\n-\tfor (Buffer &buffer : pool.buffers()) {\n+\tfor (Buffer &buffer : stream->buffers()) {\n \t\tRequest *request = camera_->createRequest();\n \t\tif (!request) {\n \t\t\tstd::cerr << \"Can't create request\" << std::endl;\ndiff --git a/test/camera/capture.cpp b/test/camera/capture.cpp\nindex 7ce247cc482d..a0385ec2c74d 100644\n--- a/test/camera/capture.cpp\n+++ b/test/camera/capture.cpp\n@@ -76,9 +76,8 @@ protected:\n \t\t}\n \n \t\tStream *stream = cfg.stream();\n-\t\tBufferPool &pool = stream->bufferPool();\n \t\tstd::vector<Request *> requests;\n-\t\tfor (Buffer &buffer : pool.buffers()) {\n+\t\tfor (Buffer &buffer : stream->buffers()) {\n \t\t\tRequest *request = camera_->createRequest();\n \t\t\tif (!request) {\n \t\t\t\tcout << \"Failed to create request\" << endl;\ndiff --git a/test/camera/statemachine.cpp b/test/camera/statemachine.cpp\nindex 84d2a6fab5f0..c23455b5bb21 100644\n--- a/test/camera/statemachine.cpp\n+++ b/test/camera/statemachine.cpp\n@@ -211,8 +211,7 @@ protected:\n \t\t\treturn TestFail;\n \n \t\tStream *stream = *camera_->streams().begin();\n-\t\tBufferPool &pool = stream->bufferPool();\n-\t\tBuffer &buffer = pool.buffers().front();\n+\t\tBuffer &buffer = stream->buffers().front();\n \t\tstd::map<Stream *, Buffer *> map = { { stream, &buffer } };\n \t\tif (request->setBuffers(map))\n \t\t\treturn TestFail;\n", "prefixes": [ "libcamera-devel", "RFC", "2/8" ] }