Patch Detail
Show a patch.
GET /api/1.1/patches/1686/?format=api
{ "id": 1686, "url": "https://patchwork.libcamera.org/api/1.1/patches/1686/?format=api", "web_url": "https://patchwork.libcamera.org/patch/1686/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/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": "<20190713172351.25452-6-laurent.pinchart@ideasonboard.com>", "date": "2019-07-13T17:23:40", "name": "[libcamera-devel,v2,05/16] libcamera: v4l2_videodevice: Add helper to queue all buffers", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "0048f751c5b9a6e93ee3575961570835a357da80", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/1686/mbox/", "series": [ { "id": 430, "url": "https://patchwork.libcamera.org/api/1.1/series/430/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=430", "date": "2019-07-13T17:23:35", "name": "Add support for external buffers", "version": 2, "mbox": "https://patchwork.libcamera.org/series/430/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/1686/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/1686/checks/", "tags": {}, "headers": { "Return-Path": "<laurent.pinchart@ideasonboard.com>", "Received": [ "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E8EB36175D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 13 Jul 2019 19:24:32 +0200 (CEST)", "from pendragon.ideasonboard.com (softbank126209254147.bbtec.net\n\t[126.209.254.147])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id AB4AD443\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 13 Jul 2019 19:24:31 +0200 (CEST)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1563038672;\n\tbh=/T/maYXqvjknYjID7loUR6hiI9T0SX+2uWGMy9JT7iY=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=Zr9CozOF0b1i8JgtzKEHryg5g8xgzJdzSMo0mBXaZXt4hXH3CH+PiwSKhCh1KRMOr\n\tlh1uoFsWMiIETKJxxNdvcEmQEOmtfD74GAvipsZnog5Nomy2ucK3chKcEzIp8OQVVw\n\tOUUUfZf/WPkSwXUFKNnJROZCEHGIEEbWHMlElW44=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Sat, 13 Jul 2019 20:23:40 +0300", "Message-Id": "<20190713172351.25452-6-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.21.0", "In-Reply-To": "<20190713172351.25452-1-laurent.pinchart@ideasonboard.com>", "References": "<20190713172351.25452-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2 05/16] libcamera: v4l2_videodevice: Add\n\thelper to queue all buffers", "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": "Sat, 13 Jul 2019 17:24:33 -0000" }, "content": "When starting the stream on a capture video device it is often needed to\nqueue all the allocated buffers. Add a helper method to do so, and\nrefactor the existing queueBuffer() method to make it clearer.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/include/v4l2_videodevice.h | 1 +\n src/libcamera/pipeline/ipu3/ipu3.cpp | 13 ++---\n src/libcamera/v4l2_videodevice.cpp | 63 +++++++++++++++++++++---\n test/v4l2_videodevice/buffer_sharing.cpp | 8 ++-\n test/v4l2_videodevice/capture_async.cpp | 8 ++-\n 5 files changed, 69 insertions(+), 24 deletions(-)", "diff": "diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h\nindex b92df882568f..f948a41fb8c1 100644\n--- a/src/libcamera/include/v4l2_videodevice.h\n+++ b/src/libcamera/include/v4l2_videodevice.h\n@@ -139,6 +139,7 @@ public:\n \tint releaseBuffers();\n \n \tint queueBuffer(Buffer *buffer);\n+\tint queueAllBuffers(std::vector<std::unique_ptr<Buffer>> *buffers);\n \tSignal<Buffer *> bufferReady;\n \n \tint streamOn();\ndiff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex 1abd20e5fee5..50457891e288 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -131,6 +131,7 @@ public:\n \tCameraSensor *sensor_;\n \n \tBufferPool pool_;\n+\tstd::vector<std::unique_ptr<Buffer>> buffers_;\n };\n \n class IPU3Stream : public Stream\n@@ -1430,11 +1431,9 @@ int CIO2Device::start()\n {\n \tint ret;\n \n-\tfor (Buffer &buffer : pool_.buffers()) {\n-\t\tret = output_->queueBuffer(&buffer);\n-\t\tif (ret)\n-\t\t\treturn ret;\n-\t}\n+\tret = output_->queueAllBuffers(&buffers_);\n+\tif (ret)\n+\t\treturn ret;\n \n \tret = output_->streamOn();\n \tif (ret)\n@@ -1445,7 +1444,9 @@ int CIO2Device::start()\n \n int CIO2Device::stop()\n {\n-\treturn output_->streamOff();\n+\tint ret = output_->streamOff();\n+\tbuffers_.clear();\n+\treturn ret;\n }\n \n int CIO2Device::mediaBusToFormat(unsigned int code)\ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 2d1e87a76c6f..af5ba803de45 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -894,8 +894,8 @@ int V4L2VideoDevice::releaseBuffers()\n */\n int V4L2VideoDevice::queueBuffer(Buffer *buffer)\n {\n+\tstruct v4l2_plane v4l2Planes[VIDEO_MAX_PLANES] = {};\n \tstruct v4l2_buffer buf = {};\n-\tstruct v4l2_plane planes[VIDEO_MAX_PLANES] = {};\n \tint ret;\n \n \tbuf.index = buffer->index();\n@@ -904,21 +904,20 @@ int V4L2VideoDevice::queueBuffer(Buffer *buffer)\n \tbuf.field = V4L2_FIELD_NONE;\n \n \tbool multiPlanar = V4L2_TYPE_IS_MULTIPLANAR(buf.type);\n+\tconst std::vector<Plane> &planes = buffer->planes();\n \n \tif (buf.memory == V4L2_MEMORY_DMABUF) {\n \t\tif (multiPlanar) {\n-\t\t\tfor (unsigned int p = 0;\n-\t\t\t p < buffer->planes().size();\n-\t\t\t p++)\n-\t\t\t\tplanes[p].m.fd = buffer->planes()[p].dmabuf();\n+\t\t\tfor (unsigned int p = 0; p < planes.size(); ++p)\n+\t\t\t\tv4l2Planes[p].m.fd = planes[p].dmabuf();\n \t\t} else {\n-\t\t\tbuf.m.fd = buffer->planes()[0].dmabuf();\n+\t\t\tbuf.m.fd = planes[0].dmabuf();\n \t\t}\n \t}\n \n \tif (multiPlanar) {\n-\t\tbuf.length = buffer->planes().size();\n-\t\tbuf.m.planes = planes;\n+\t\tbuf.length = planes.size();\n+\t\tbuf.m.planes = v4l2Planes;\n \t}\n \n \tif (V4L2_TYPE_IS_OUTPUT(bufferType_)) {\n@@ -944,6 +943,54 @@ int V4L2VideoDevice::queueBuffer(Buffer *buffer)\n \treturn 0;\n }\n \n+/**\n+ * \\brief Queue all buffers into the video device\n+ * \\param[out] buffers A vector of queued Buffer instances\n+ *\n+ * When starting video capture users of the video device often need to queue\n+ * all allocated buffers to the device. This helper method simplifies the\n+ * implementation of the user by queuing all buffers and populating the\n+ * \\a buffers vector with Buffer instances for each queued buffer.\n+ *\n+ * This method is meant to be used with video capture devices internal to a\n+ * pipeline handler, such as ISP statistics capture devices, or raw CSI-2\n+ * receivers. For video capture devices facing applications, buffers shall\n+ * instead be queued when requests are received, and for video output devices,\n+ * buffers shall be queued when frames are ready to be output.\n+ *\n+ * The caller shall ensure that the \\a buffers vector remains valid until all\n+ * the queued buffers are dequeued, either during capture, or by stopping the\n+ * video device.\n+ *\n+ * Calling this method on an output device or on a device that has buffers\n+ * already queued is an error and will return -EINVAL.\n+ *\n+ * \\return 0 on success or a negative error code otherwise\n+ */\n+int V4L2VideoDevice::queueAllBuffers(std::vector<std::unique_ptr<Buffer>> *buffers)\n+{\n+\tint ret;\n+\n+\tif (queuedBuffersCount_)\n+\t\treturn -EINVAL;\n+\n+\tif (V4L2_TYPE_IS_OUTPUT(bufferType_))\n+\t\treturn -EINVAL;\n+\n+\tbuffers->clear();\n+\n+\tfor (unsigned int i = 0; i < bufferPool_->count(); ++i) {\n+\t\tBuffer *buffer = new Buffer();\n+\t\tbuffer->index_ = i;\n+\t\tbuffers->emplace_back(buffer);\n+\t\tret = queueBuffer(buffer);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\t}\n+\n+\treturn 0;\n+}\n+\n /**\n * \\brief Dequeue the next available buffer from the video device\n *\ndiff --git a/test/v4l2_videodevice/buffer_sharing.cpp b/test/v4l2_videodevice/buffer_sharing.cpp\nindex cc724b226619..459bd238fe97 100644\n--- a/test/v4l2_videodevice/buffer_sharing.cpp\n+++ b/test/v4l2_videodevice/buffer_sharing.cpp\n@@ -117,11 +117,9 @@ protected:\n \t\tcapture_->bufferReady.connect(this, &BufferSharingTest::captureBufferReady);\n \t\toutput_->bufferReady.connect(this, &BufferSharingTest::outputBufferReady);\n \n-\t\t/* Queue all the buffers to the capture device. */\n-\t\tfor (Buffer &buffer : pool_.buffers()) {\n-\t\t\tif (capture_->queueBuffer(&buffer))\n-\t\t\t\treturn TestFail;\n-\t\t}\n+\t\tstd::vector<std::unique_ptr<Buffer>> buffers;\n+\t\tif (capture_->queueAllBuffers(&buffers))\n+\t\t\treturn TestFail;\n \n \t\tret = capture_->streamOn();\n \t\tif (ret) {\ndiff --git a/test/v4l2_videodevice/capture_async.cpp b/test/v4l2_videodevice/capture_async.cpp\nindex cea4fffbf7a5..c6d6ec6b74bd 100644\n--- a/test/v4l2_videodevice/capture_async.cpp\n+++ b/test/v4l2_videodevice/capture_async.cpp\n@@ -46,11 +46,9 @@ protected:\n \n \t\tcapture_->bufferReady.connect(this, &CaptureAsyncTest::receiveBuffer);\n \n-\t\t/* Queue all the buffers to the device. */\n-\t\tfor (Buffer &b : pool_.buffers()) {\n-\t\t\tif (capture_->queueBuffer(&b))\n-\t\t\t\treturn TestFail;\n-\t\t}\n+\t\tstd::vector<std::unique_ptr<Buffer>> buffers;\n+\t\tif (capture_->queueAllBuffers(&buffers))\n+\t\t\treturn TestFail;\n \n \t\tret = capture_->streamOn();\n \t\tif (ret)\n", "prefixes": [ "libcamera-devel", "v2", "05/16" ] }