[{"id":814,"web_url":"https://patchwork.libcamera.org/comment/814/","msgid":"<20190213154939.GI5332@pendragon.ideasonboard.com>","date":"2019-02-13T15:49:39","subject":"Re: [libcamera-devel] [PATCH v2 7/8] 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 Wed, Feb 13, 2019 at 03:10:26PM +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 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);\n> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\n> index 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\nMaybe\n\n\t\"... provided pool of \" << pool->count() << \" buffers\";\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\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}","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 04A6C610AE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 13 Feb 2019 16:49:43 +0100 (CET)","from pendragon.ideasonboard.com\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 6A1A585;\n\tWed, 13 Feb 2019 16:49:42 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1550072982;\n\tbh=6gtT5Bz013AcK9zjjnsoLScBhkB+4BYsA89JxqCD/SE=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=asLJAsURlQwZeQqQJUmQm3Tc6hlwfdVVsF1aEVsR2VrK8Pe5UvotobCVV0+WaDiPt\n\tPWUo+sa/v209Gt/+ZRz4o+mrzCeWT4ssPe59lw+OmR7pJ4ToxFpO3CfN38ioHkVZP5\n\tQGOwmllrqdpPklJeXnlnrEYC0hTHq8Q49zZ0b3A4=","Date":"Wed, 13 Feb 2019 17:49:39 +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":"<20190213154939.GI5332@pendragon.ideasonboard.com>","References":"<20190213151027.6376-1-kieran.bingham@ideasonboard.com>\n\t<20190213151027.6376-8-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20190213151027.6376-8-kieran.bingham@ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [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:49:43 -0000"}}]