[{"id":764,"web_url":"https://patchwork.libcamera.org/comment/764/","msgid":"<20190207221619.ikmm5ybobllfp3ve@uno.localdomain>","date":"2019-02-07T22:16:19","subject":"Re: [libcamera-devel] [PATCH 2/5] libcamera: v4l2_device:\n\timportBuffers support","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Kieran,\n\nOn Thu, Feb 07, 2019 at 09:21:16PM +0000, Kieran Bingham wrote:\n> Provide the ability to import a BufferPool into the V4L2Device allowing\n> external dmabuf backed buffers to be queued.\n>\n> Signed-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(-)\n>\n> diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h\n> index 988e646c5de1..3acb5e466d64 100644\n> --- a/src/libcamera/include/v4l2_device.h\n> +++ b/src/libcamera/include/v4l2_device.h\n> @@ -98,6 +98,7 @@ public:\n>  \tint setFormat(V4L2DeviceFormat *format);\n>\n>  \tint exportBuffers(unsigned int count, BufferPool *pool);\n> +\tint importBuffers(BufferPool *pool);\n>  \tint releaseBuffers();\n>\n>  \tint queueBuffer(Buffer *buffer);\n> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\n> index 64325ff9f5d9..c654e6dd7b8d 100644\n> --- a/src/libcamera/v4l2_device.cpp\n> +++ b/src/libcamera/v4l2_device.cpp\n> @@ -633,6 +633,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\n\"an externally allocated\" maybe?\n\n> + * \\param[in] pool BufferPool of buffers to import\n> + * \\return 0 on success or a negative error code otherwise\n\n\"A pool of buffer to import\" ?\n\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\nWhat is allocatedBuffers used for?\nCould you drop it and compare with ret here below?\n\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> @@ -670,7 +700,20 @@ int V4L2Device::queueBuffer(Buffer *buffer)\n>  \tbuf.type = bufferType_;\n>  \tbuf.memory = memoryType_;\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\nThis change looks good to me!\n\nThanks\n   j\n\n>  \t\tbuf.length = buffer->planes().size();\n>  \t\tbuf.m.planes = planes;\n>  \t}\n> --\n> 2.19.1\n>\n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net\n\t[217.70.183.201])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 803F4610B2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  7 Feb 2019 23:15:59 +0100 (CET)","from uno.localdomain (d51A4137F.access.telenet.be [81.164.19.127])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay8-d.mail.gandi.net (Postfix) with ESMTPSA id CABDC1BF208;\n\tThu,  7 Feb 2019 22:15:58 +0000 (UTC)"],"X-Originating-IP":"81.164.19.127","Date":"Thu, 7 Feb 2019 23:16:19 +0100","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"LibCamera Devel <libcamera-devel@lists.libcamera.org>","Message-ID":"<20190207221619.ikmm5ybobllfp3ve@uno.localdomain>","References":"<20190207212119.30299-1-kieran.bingham@ideasonboard.com>\n\t<20190207212119.30299-3-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"ftaeehzwpxfjfehk\"","Content-Disposition":"inline","In-Reply-To":"<20190207212119.30299-3-kieran.bingham@ideasonboard.com>","User-Agent":"NeoMutt/20180716","Subject":"Re: [libcamera-devel] [PATCH 2/5] 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":"Thu, 07 Feb 2019 22:15:59 -0000"}},{"id":770,"web_url":"https://patchwork.libcamera.org/comment/770/","msgid":"<20190208155044.GG4562@pendragon.ideasonboard.com>","date":"2019-02-08T15:50:44","subject":"Re: [libcamera-devel] [PATCH 2/5] libcamera: v4l2_device:\n\timportBuffers support","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kieran,\n\nThank you for the patch.\n\nOn Thu, Feb 07, 2019 at 09:21:16PM +0000, Kieran Bingham wrote:\n> Provide the ability to import a BufferPool into the V4L2Device allowing\n> external dmabuf backed buffers to be queued.\n> \n> Signed-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(-)\n> \n> diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h\n> index 988e646c5de1..3acb5e466d64 100644\n> --- a/src/libcamera/include/v4l2_device.h\n> +++ b/src/libcamera/include/v4l2_device.h\n> @@ -98,6 +98,7 @@ public:\n>  \tint setFormat(V4L2DeviceFormat *format);\n>  \n>  \tint exportBuffers(unsigned int count, BufferPool *pool);\n> +\tint importBuffers(BufferPool *pool);\n>  \tint releaseBuffers();\n>  \n>  \tint queueBuffer(Buffer *buffer);\n> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\n> index 64325ff9f5d9..c654e6dd7b8d 100644\n> --- a/src/libcamera/v4l2_device.cpp\n> +++ b/src/libcamera/v4l2_device.cpp\n> @@ -633,6 +633,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\nShould we use VIDIOC_PREPARE_BUF to already associate the dmabuf fds\nwith V4L2 buffers ?\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> @@ -670,7 +700,20 @@ int V4L2Device::queueBuffer(Buffer *buffer)\n>  \tbuf.type = bufferType_;\n>  \tbuf.memory = memoryType_;\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}","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5E6496101F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  8 Feb 2019 16:50:46 +0100 (CET)","from pendragon.ideasonboard.com (d51A4137F.access.telenet.be\n\t[81.164.19.127])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A2767F9;\n\tFri,  8 Feb 2019 16:50:45 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1549641045;\n\tbh=pn5+ztisVUDS3DlbCFZmkFt+n9gmkvHBoZMJ245xNOw=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=fdrT9JfaoRRunJudktMzGT06z5083L8JFxDMl+C7DXSRQehm6aaNPV4Y52apGfT6/\n\tkcCMrZnDB3WiHzRRIDpPAcB54Mc2NOeAhGzZxauOr3lOtYFAhDb6BUPLGqgUxKQ6NN\n\t5//gpb2Zy+4NSvaqpTp23WEz3bUP0sPR0FLO9tBc=","Date":"Fri, 8 Feb 2019 17:50:44 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"LibCamera Devel <libcamera-devel@lists.libcamera.org>","Message-ID":"<20190208155044.GG4562@pendragon.ideasonboard.com>","References":"<20190207212119.30299-1-kieran.bingham@ideasonboard.com>\n\t<20190207212119.30299-3-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20190207212119.30299-3-kieran.bingham@ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 2/5] 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":"Fri, 08 Feb 2019 15:50:46 -0000"}}]