[{"id":3406,"web_url":"https://patchwork.libcamera.org/comment/3406/","msgid":"<20200111001742.GI4859@pendragon.ideasonboard.com>","date":"2020-01-11T00:17:42","subject":"Re: [libcamera-devel] [PATCH v3 14/33] libcamera: v4l2_videodevice:\n\tExtract exportDmabufFd()","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Niklas,\n\nThank you for the patch.\n\nOn Fri, Jan 10, 2020 at 08:37:49PM +0100, Niklas Söderlund wrote:\n> The part in createPlane() that exports a dma buffer from a video device\n> will be used directly by the FrameBuffer interface. Break it out to a\n> separate function.\n> \n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n> * Changes since v1\n> - Rename exportDmaBuffer() to exportDmabufFd()\n> ---\n>  src/libcamera/include/v4l2_videodevice.h |  1 +\n>  src/libcamera/v4l2_videodevice.cpp       | 41 +++++++++++++++---------\n>  2 files changed, 27 insertions(+), 15 deletions(-)\n> \n> diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h\n> index fdf11b3a6ec9b702..1f52fe0120831fa3 100644\n> --- a/src/libcamera/include/v4l2_videodevice.h\n> +++ b/src/libcamera/include/v4l2_videodevice.h\n> @@ -179,6 +179,7 @@ private:\n>  \tint requestBuffers(unsigned int count);\n>  \tint createPlane(BufferMemory *buffer, unsigned int index,\n>  \t\t\tunsigned int plane, unsigned int length);\n> +\tint exportDmabufFd(unsigned int index, unsigned int plane);\n\nI think you can squash 28/33 with this patch.\n\n>  \n>  \tBuffer *dequeueBuffer();\n>  \tvoid bufferAvailable(EventNotifier *notifier);\n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index 81d999e354a16bd0..7c9014af4ddea31a 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -902,31 +902,22 @@ int V4L2VideoDevice::exportBuffers(BufferPool *pool)\n>  int V4L2VideoDevice::createPlane(BufferMemory *buffer, unsigned int index,\n>  \t\t\t\t unsigned int planeIndex, unsigned int length)\n>  {\n> -\tstruct v4l2_exportbuffer expbuf = {};\n> -\tint ret;\n> +\tint fd;\n>  \n>  \tLOG(V4L2, Debug)\n>  \t\t<< \"Buffer \" << index\n>  \t\t<< \" plane \" << planeIndex\n>  \t\t<< \": length=\" << length;\n>  \n> -\texpbuf.type = bufferType_;\n> -\texpbuf.index = index;\n> -\texpbuf.plane = planeIndex;\n> -\texpbuf.flags = O_RDWR;\n> -\n> -\tret = ioctl(VIDIOC_EXPBUF, &expbuf);\n> -\tif (ret < 0) {\n> -\t\tLOG(V4L2, Error)\n> -\t\t\t<< \"Failed to export buffer: \" << strerror(-ret);\n> -\t\treturn ret;\n> -\t}\n> +\tfd = exportDmabufFd(index, planeIndex);\n> +\tif (fd < 0)\n> +\t\treturn fd;\n>  \n>  \tFrameBuffer::Plane plane;\n> -\tplane.fd = FileDescriptor(expbuf.fd);\n> +\tplane.fd = FileDescriptor(fd);\n>  \tplane.length = length;\n>  \tbuffer->planes().push_back(plane);\n> -\t::close(expbuf.fd);\n> +\t::close(fd);\n>  \n>  \treturn 0;\n>  }\n> @@ -952,6 +943,26 @@ int V4L2VideoDevice::importBuffers(BufferPool *pool)\n>  \treturn 0;\n>  }\n>  \n> +int V4L2VideoDevice::exportDmabufFd(unsigned int index, unsigned int plane)\n> +{\n> +\tstruct v4l2_exportbuffer expbuf = {};\n> +\tint ret;\n> +\n> +\texpbuf.type = bufferType_;\n> +\texpbuf.index = index;\n> +\texpbuf.plane = plane;\n> +\texpbuf.flags = O_RDWR;\n> +\n> +\tret = ioctl(VIDIOC_EXPBUF, &expbuf);\n> +\tif (ret < 0) {\n> +\t\tLOG(V4L2, Error)\n> +\t\t\t<< \"Failed to export buffer: \" << strerror(-ret);\n> +\t\treturn ret;\n> +\t}\n> +\n> +\treturn expbuf.fd;\n> +}\n> +\n>  /**\n>   * \\brief Release all internally allocated buffers\n>   */","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 3E7726067C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 11 Jan 2020 01:17:57 +0100 (CET)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id BF0E952F;\n\tSat, 11 Jan 2020 01:17:56 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1578701876;\n\tbh=MzKioJsIcX/aLV8b5ilKnnYps35TsMoz4foaim+4Ygs=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=cRgKm0KjRDITcmzoo0nhtiQHGEuIdefca52EpDL61LFFkXno9Z1K8Rv+30bg7GDdh\n\tE0NktSy9UTvuObjqhznr11qTrhzWwTZt0tBitwYxTbxQZBK6tu4r9qoaJ0vGfIQfGz\n\tM/7SqFPTTi4uZhq2OsWhilzOUbWxTWtOc379rPzE=","Date":"Sat, 11 Jan 2020 02:17:42 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Cc":"libcamera-devel@lists.libcamera.org, Jacopo Mondi <jacopo@jmondi.org>","Message-ID":"<20200111001742.GI4859@pendragon.ideasonboard.com>","References":"<20200110193808.2266294-1-niklas.soderlund@ragnatech.se>\n\t<20200110193808.2266294-15-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20200110193808.2266294-15-niklas.soderlund@ragnatech.se>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v3 14/33] libcamera: v4l2_videodevice:\n\tExtract exportDmabufFd()","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":"Sat, 11 Jan 2020 00:17:57 -0000"}}]