Patch Detail
Show a patch.
GET /api/1.1/patches/2370/?format=api
{ "id": 2370, "url": "https://patchwork.libcamera.org/api/1.1/patches/2370/?format=api", "web_url": "https://patchwork.libcamera.org/patch/2370/", "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": "<20191126233620.1695316-23-niklas.soderlund@ragnatech.se>", "date": "2019-11-26T23:36:12", "name": "[libcamera-devel,22/30] libcamera: v4l2_videodevice: Add V4L2Stream to facilitate buffers", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "43f9e6f4a311a820f622209e7a3c3bddf72fa79e", "submitter": { "id": 5, "url": "https://patchwork.libcamera.org/api/1.1/people/5/?format=api", "name": "Niklas Söderlund", "email": "niklas.soderlund@ragnatech.se" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/2370/mbox/", "series": [ { "id": 579, "url": "https://patchwork.libcamera.org/api/1.1/series/579/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=579", "date": "2019-11-26T23:35:50", "name": "libcamera: Rework buffer API", "version": 1, "mbox": "https://patchwork.libcamera.org/series/579/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/2370/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/2370/checks/", "tags": {}, "headers": { "Return-Path": "<niklas.soderlund@ragnatech.se>", "Received": [ "from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net\n\t[195.74.38.229])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7B2F361C65\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 27 Nov 2019 00:39:43 +0100 (CET)", "from bismarck.berto.se (p54ac5865.dip0.t-ipconnect.de\n\t[84.172.88.101]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA\n\tid 03c6c4dd-10a6-11ea-a0b9-005056917f90;\n\tWed, 27 Nov 2019 00:39:41 +0100 (CET)" ], "X-Halon-ID": "03c6c4dd-10a6-11ea-a0b9-005056917f90", "Authorized-sender": "niklas@soderlund.pp.se", "From": "=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Wed, 27 Nov 2019 00:36:12 +0100", "Message-Id": "<20191126233620.1695316-23-niklas.soderlund@ragnatech.se>", "X-Mailer": "git-send-email 2.24.0", "In-Reply-To": "<20191126233620.1695316-1-niklas.soderlund@ragnatech.se>", "References": "<20191126233620.1695316-1-niklas.soderlund@ragnatech.se>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH 22/30] libcamera: v4l2_videodevice: Add\n\tV4L2Stream to facilitate buffers", "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>", "X-List-Received-Date": "Tue, 26 Nov 2019 23:39:43 -0000" }, "content": "In the FrameBuffer interface the streams and not the pipelines abstracts\nthe knowledge about how and if buffers needs to be allocated or prepared\nbefore a capture session is started.\n\nThe rational behind this model is the V4L2 API where if applications\nneeds to allocate memory for buffers it do that using a video node and\nnot using a external allocator. As the video node needs to be prepared\nin different ways depending on if it have been used for memory\nallocation or not each streams facing applications needs not only be\navailable to be used to allocated buffers but track if they have been so\nin order to be started correctly.\n\nThis change implements the interface for cameras backed by V4L2 video\ndevices to function with the FrameBuffer interface.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n src/libcamera/include/v4l2_videodevice.h | 24 +++++++\n src/libcamera/v4l2_videodevice.cpp | 90 ++++++++++++++++++++++++\n 2 files changed, 114 insertions(+)", "diff": "diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h\nindex f4cbcfbd26ea540c..0e94c3f71d0b1208 100644\n--- a/src/libcamera/include/v4l2_videodevice.h\n+++ b/src/libcamera/include/v4l2_videodevice.h\n@@ -16,6 +16,7 @@\n #include <libcamera/geometry.h>\n #include <libcamera/pixelformats.h>\n #include <libcamera/signal.h>\n+#include <libcamera/stream.h>\n \n #include \"formats.h\"\n #include \"log.h\"\n@@ -236,6 +237,29 @@ private:\n \tV4L2VideoDevice *capture_;\n };\n \n+class V4L2Stream : public Stream\n+{\n+public:\n+\tV4L2Stream(V4L2VideoDevice *video);\n+\n+protected:\n+\tint allocateBuffers(const StreamConfiguration &config,\n+\t\t\t std::vector<FrameBuffer *> *buffers) override;\n+\tvoid releaseBuffers() override;\n+\tint start() override;\n+\tvoid stop() override;\n+\n+private:\n+\tenum BufferType {\n+\t\tNoBuffers,\n+\t\tAllocatedBuffers,\n+\t\tExternalBuffers,\n+\t};\n+\n+\tV4L2VideoDevice *video_;\n+\tBufferType bufferType_;\n+};\n+\n } /* namespace libcamera */\n \n #endif /* __LIBCAMERA_V4L2_VIDEODEVICE_H__ */\ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 9fe66018ec502626..f5810956b2040ce6 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -1711,4 +1711,94 @@ void V4L2M2MDevice::close()\n \toutput_->close();\n }\n \n+/**\n+ * \\class V4L2Stream\n+ * \\brief V4L2 Video stream for a camera\n+ *\n+ * The V4l2Stream implemets the interfaces mandated by Stream to allow buffers\n+ * to be allocoated from a video device and presented to the user as if they\n+ * where allocated externaly.\n+ */\n+\n+/**\n+ * \\brief Create a stream around a V4L2 video device\n+ * \\param[in] video V4L2 video device to serve\n+ *\n+ * Create a stream which will manage the application visible buffers for a V4L2\n+ * video device.\n+ */\n+V4L2Stream::V4L2Stream(V4L2VideoDevice *video)\n+\t: Stream(), video_(video), bufferType_(NoBuffers)\n+{\n+}\n+\n+int V4L2Stream::allocateBuffers(const StreamConfiguration &config,\n+\t\t\t\tstd::vector<FrameBuffer *> *buffers)\n+{\n+\tif (bufferType_ != NoBuffers)\n+\t\treturn -EINVAL;\n+\n+\tif (!buffers)\n+\t\treturn -EINVAL;\n+\n+\t/*\n+\t * \\todo: Extend V4L2VideoDevice to support VIDIOC_CREATE_BUFS which\n+\t * can take the whole configuration into account, until then use as\n+\t * much as possible (number of buffers) with VIDIOC_QUERYBUF.\n+\t *\n+\t * For this reason check that the format of the video device is the\n+\t * same as the one request or fail. This will allow for a applicaiton\n+\t * facing API that will work with VIDIOC_CREATE_BUFS.\n+\t */\n+\tV4L2DeviceFormat format;\n+\tint ret = video_->getFormat(&format);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tif (config.size != format.size ||\n+\t config.pixelFormat != V4L2VideoDevice::toPixelFormat(format.fourcc))\n+\t\treturn -EINVAL;\n+\n+\tret = video_->allocateBuffers(config.bufferCount, buffers);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tbufferType_ = AllocatedBuffers;\n+\n+\treturn ret;\n+}\n+\n+void V4L2Stream::releaseBuffers()\n+{\n+\tif (bufferType_ == NoBuffers)\n+\t\treturn;\n+\n+\tvideo_->releaseBuffers();\n+\tbufferType_ = NoBuffers;\n+}\n+\n+int V4L2Stream::start()\n+{\n+\t/* If internal buffers is already allocated nothing to do. */\n+\tif (bufferType_ == AllocatedBuffers)\n+\t\treturn 0;\n+\n+\tint ret = video_->externalBuffers(configuration_.bufferCount);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tbufferType_ = ExternalBuffers;\n+\n+\treturn ret;\n+}\n+\n+void V4L2Stream::stop()\n+{\n+\t/* Only need to clean up if external buffers is used. */\n+\tif (bufferType_ != ExternalBuffers)\n+\t\treturn;\n+\n+\treleaseBuffers();\n+}\n+\n } /* namespace libcamera */\n", "prefixes": [ "libcamera-devel", "22/30" ] }