{"id":576,"url":"https://patchwork.libcamera.org/api/1.1/patches/576/?format=json","web_url":"https://patchwork.libcamera.org/patch/576/","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":"<20190213151027.6376-8-kieran.bingham@ideasonboard.com>","date":"2019-02-13T15:10:26","name":"[libcamera-devel,v2,7/8] libcamera: v4l2_device: importBuffers support","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"8593ae369808f04d8e722e2ae8f81dbec6eea907","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/1.1/people/4/?format=json","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/576/mbox/","series":[{"id":181,"url":"https://patchwork.libcamera.org/api/1.1/series/181/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=181","date":"2019-02-13T15:10:19","name":"libcamera: v4l2_device buffer sharing","version":2,"mbox":"https://patchwork.libcamera.org/series/181/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/576/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/576/checks/","tags":{},"headers":{"Return-Path":"<kieran.bingham@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 67BAB610BA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 13 Feb 2019 16:10:34 +0100 (CET)","from localhost.localdomain\n\t(cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0B2825B6;\n\tWed, 13 Feb 2019 16:10:34 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1550070634;\n\tbh=Ws+N0xCxnDs84aCFjzVjARruxTpC8rxo6wO4uCAtdwQ=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=FRbucWtGE7PlzdHp/y0Aqa7ApBy90gc/Sre7vE/5xmr1xugTssrgR4bOpUMachbfK\n\tDWOzNFkCvLowjpj3qEZBt/dzzS2DU5SdvJaZFdh8o3yTqVHFW5merakGkWF1GCRVjA\n\tmVb/jb0TAqVGUdYiGF/CB7sOgA4AOFNVO4lDtqow=","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"LibCamera Devel <libcamera-devel@lists.libcamera.org>","Date":"Wed, 13 Feb 2019 15:10:26 +0000","Message-Id":"<20190213151027.6376-8-kieran.bingham@ideasonboard.com>","X-Mailer":"git-send-email 2.19.1","In-Reply-To":"<20190213151027.6376-1-kieran.bingham@ideasonboard.com>","References":"<20190213151027.6376-1-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 7/8] libcamera: v4l2_device:\n\timportBuffers support","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, 13 Feb 2019 15:10:35 -0000"},"content":"Provide the ability to import a BufferPool into the V4L2Device allowing\nexternal dmabuf backed buffers to be queued.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n src/libcamera/include/v4l2_device.h |  1 +\n src/libcamera/v4l2_device.cpp       | 45 ++++++++++++++++++++++++++++-\n 2 files changed, 45 insertions(+), 1 deletion(-)","diff":"diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h\nindex 5a536393a5b5..1d31d1b403bc 100644\n--- a/src/libcamera/include/v4l2_device.h\n+++ b/src/libcamera/include/v4l2_device.h\n@@ -100,6 +100,7 @@ public:\n \tint setFormat(V4L2DeviceFormat *format);\n \n \tint exportBuffers(BufferPool *pool);\n+\tint importBuffers(BufferPool *pool);\n \tint releaseBuffers();\n \n \tint queueBuffer(Buffer *buffer);\ndiff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nindex 152bd9930a70..2d0ce7011d8a 100644\n--- a/src/libcamera/v4l2_device.cpp\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -642,6 +642,36 @@ int V4L2Device::createPlane(Buffer *buffer, unsigned int planeIndex,\n \treturn 0;\n }\n \n+/**\n+ * \\brief Import the externally allocated \\a pool of buffers\n+ * \\param[in] pool BufferPool of buffers to import\n+ * \\return 0 on success or a negative error code otherwise\n+ */\n+int V4L2Device::importBuffers(BufferPool *pool)\n+{\n+\tunsigned int allocatedBuffers;\n+\tint ret;\n+\n+\tmemoryType_ = V4L2_MEMORY_DMABUF;\n+\n+\tret = requestBuffers(pool->count());\n+\tif (ret < 0)\n+\t\treturn ret;\n+\n+\tallocatedBuffers = ret;\n+\tif (allocatedBuffers < pool->count()) {\n+\t\tLOG(V4L2, Error)\n+\t\t\t<< \"Not enough buffers provided by V4L2Device\";\n+\t\trequestBuffers(0);\n+\t\treturn -ENOMEM;\n+\t}\n+\n+\tLOG(V4L2, Debug) << \"Device using an externally provided pool\";\n+\tbufferPool_ = pool;\n+\n+\treturn 0;\n+}\n+\n /**\n  * \\brief Release all internally allocated buffers\n  */\n@@ -682,7 +712,20 @@ int V4L2Device::queueBuffer(Buffer *buffer)\n \tbuf.memory = memoryType_;\n \tbuf.field = V4L2_FIELD_NONE;\n \n-\tif (V4L2_TYPE_IS_MULTIPLANAR(buf.type)) {\n+\tbool multiPlanar = V4L2_TYPE_IS_MULTIPLANAR(buf.type);\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} else {\n+\t\t\tbuf.m.fd = buffer->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}\n","prefixes":["libcamera-devel","v2","7/8"]}