[{"id":3405,"web_url":"https://patchwork.libcamera.org/comment/3405/","msgid":"<20200111001645.GH4859@pendragon.ideasonboard.com>","date":"2020-01-11T00:16:45","subject":"Re: [libcamera-devel] [PATCH v3 28/33] libcamera: v4l2_videodevice:\n\tUse FileDescriptor where appropriate","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Niklas,\n\nOn Fri, Jan 10, 2020 at 08:38:03PM +0100, Niklas Söderlund wrote:\n> From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> \n> Return a FileDescriptor instead of a numerical fd from exportDmabufFd().\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\nFeel free to squash this with the patch that introduced\nexportDmabufFd(). If the rebase gets too messy I'm fine keeping it\nseparate, but please let me know explicitly in this case.\n\n> ---\n>  src/libcamera/include/v4l2_videodevice.h |  2 +-\n>  src/libcamera/v4l2_videodevice.cpp       | 14 ++++++--------\n>  2 files changed, 7 insertions(+), 9 deletions(-)\n> \n> diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h\n> index 6959b87a35496b9a..172d670c328b2345 100644\n> --- a/src/libcamera/include/v4l2_videodevice.h\n> +++ b/src/libcamera/include/v4l2_videodevice.h\n> @@ -217,7 +217,7 @@ private:\n>  \n>  \tint requestBuffers(unsigned int count);\n>  \tstd::unique_ptr<FrameBuffer> createBuffer(const struct v4l2_buffer &buf);\n> -\tint exportDmabufFd(unsigned int index, unsigned int plane);\n> +\tFileDescriptor exportDmabufFd(unsigned int index, unsigned int plane);\n>  \n>  \tvoid bufferAvailable(EventNotifier *notifier);\n>  \tFrameBuffer *dequeueBuffer();\n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index 59a6d1b5537d776f..c0381d3980063799 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -1041,24 +1041,22 @@ V4L2VideoDevice::createBuffer(const struct v4l2_buffer &buf)\n>  \n>  \tstd::vector<FrameBuffer::Plane> planes;\n>  \tfor (unsigned int nplane = 0; nplane < numPlanes; nplane++) {\n> -\t\tint fd = exportDmabufFd(buf.index, nplane);\n> -\t\tif (fd < 0)\n> +\t\tFileDescriptor fd = exportDmabufFd(buf.index, nplane);\n> +\t\tif (fd.fd() < 0)\n>  \t\t\treturn nullptr;\n>  \n>  \t\tFrameBuffer::Plane plane;\n> -\t\tplane.fd = FileDescriptor(fd);\n> +\t\tplane.fd = std::move(fd);\n>  \t\tplane.length = multiPlanar ?\n>  \t\t\tbuf.m.planes[nplane].length : buf.length;\n>  \n>  \t\tplanes.push_back(std::move(plane));\n> -\n> -\t\t::close(fd);\n>  \t}\n>  \n>  \treturn utils::make_unique<FrameBuffer>(std::move(planes));\n>  }\n>  \n> -int V4L2VideoDevice::exportDmabufFd(unsigned int index, unsigned int plane)\n> +FileDescriptor V4L2VideoDevice::exportDmabufFd(unsigned int index, unsigned int plane)\n>  {\n>  \tstruct v4l2_exportbuffer expbuf = {};\n>  \tint ret;\n> @@ -1072,10 +1070,10 @@ int V4L2VideoDevice::exportDmabufFd(unsigned int index, unsigned int plane)\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\treturn FileDescriptor();\n>  \t}\n>  \n> -\treturn expbuf.fd;\n> +\treturn FileDescriptor(expbuf.fd);\n>  }\n>  \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 6818F6067C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 11 Jan 2020 01:17:00 +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 D827952F;\n\tSat, 11 Jan 2020 01:16:59 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1578701820;\n\tbh=diN0zOpaUO07Krgii+gzvtNZgMg5ni9cGFsF9epAtbw=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=uZUOg17OJ2Dzhdkg1BkxbN0rffgParIxo9OPM5+TpZaVNdL7ekc05C2Gn3sLY/syk\n\tHDxfAbtamZlzz89EXgs9hTrPuNrMNDRbtxzpvX9WnGG2i+LXdiSuq0Ta0hvsS/2odx\n\t/UbvKuHxdBb28Wcoz2Z8MyFEOT4r21biiN9nwXaU=","Date":"Sat, 11 Jan 2020 02:16:45 +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","Message-ID":"<20200111001645.GH4859@pendragon.ideasonboard.com>","References":"<20200110193808.2266294-1-niklas.soderlund@ragnatech.se>\n\t<20200110193808.2266294-29-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-29-niklas.soderlund@ragnatech.se>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v3 28/33] libcamera: v4l2_videodevice:\n\tUse FileDescriptor where appropriate","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:00 -0000"}}]