[{"id":3150,"web_url":"https://patchwork.libcamera.org/comment/3150/","msgid":"<20191127145352.vtsgxqvkpvmyqwpq@uno.localdomain>","date":"2019-11-27T14:53:52","subject":"Re: [libcamera-devel] [PATCH 13/30] libcamera: v4l2_videodevice:\n\tExtract exportDmaBuffer() to export DMA buffer","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Niklas,\n\nOn Wed, Nov 27, 2019 at 12:36:03AM +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> own function.\n>\n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\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..34bbff41760753bd 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 exportDmaBuffer(unsigned int index, unsigned int plane);\n\nI would have named this exportBuffer()\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 644e4545a2f33b2e..cc0a1c9382a2b1ed 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -901,28 +901,19 @@ 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 = exportDmaBuffer(index, planeIndex);\n> +\tif (fd < 0)\n> +\t\treturn fd;\n>\n> -\tbuffer->planes().emplace_back(expbuf.fd, length);\n> -\t::close(expbuf.fd);\n> +\tbuffer->planes().emplace_back(fd, length);\n> +\t::close(fd);\n>\n>  \treturn 0;\n>  }\n> @@ -948,6 +939,26 @@ int V4L2VideoDevice::importBuffers(BufferPool *pool)\n>  \treturn 0;\n>  }\n>\n> +int V4L2VideoDevice::exportDmaBuffer(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\nDo you need the usual ret = -errno dance to avoid errno being\noverwritten by LOG() ?\n\n> +\t\tLOG(V4L2, Error)\n> +\t\t\t<< \"Failed to export buffer: \" << strerror(-ret);\n\nAh, you really need to assign ret before this one :)\n> +\t\treturn ret;\n> +\t}\n> +\n> +\treturn expbuf.fd;\n> +}\n> +\n\nWith this addressed\n\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\nThanks\n  j\n\n>  /**\n>   * \\brief Release all internally allocated buffers\n>   */\n> --\n> 2.24.0\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 24EF460C33\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 27 Nov 2019 15:51:47 +0100 (CET)","from uno.localdomain (93-34-114-233.ip49.fastwebnet.it\n\t[93.34.114.233]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 71C851BF20B;\n\tWed, 27 Nov 2019 14:51:45 +0000 (UTC)"],"X-Originating-IP":"93.34.114.233","Date":"Wed, 27 Nov 2019 15:53:52 +0100","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20191127145352.vtsgxqvkpvmyqwpq@uno.localdomain>","References":"<20191126233620.1695316-1-niklas.soderlund@ragnatech.se>\n\t<20191126233620.1695316-14-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"fpwgqn7j3deul622\"","Content-Disposition":"inline","In-Reply-To":"<20191126233620.1695316-14-niklas.soderlund@ragnatech.se>","User-Agent":"NeoMutt/20180716","Subject":"Re: [libcamera-devel] [PATCH 13/30] libcamera: v4l2_videodevice:\n\tExtract exportDmaBuffer() to export DMA buffer","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":"Wed, 27 Nov 2019 14:51:47 -0000"}},{"id":3234,"web_url":"https://patchwork.libcamera.org/comment/3234/","msgid":"<20191209184002.GD18060@pendragon.ideasonboard.com>","date":"2019-12-09T18:40:02","subject":"Re: [libcamera-devel] [PATCH 13/30] libcamera: v4l2_videodevice:\n\tExtract exportDmaBuffer() to export DMA buffer","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hello,\n\nOn Wed, Nov 27, 2019 at 03:53:52PM +0100, Jacopo Mondi wrote:\n> On Wed, Nov 27, 2019 at 12:36:03AM +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> > own function.\n\n\"its own function\" or \"a separate function\".\n\n> >\n> > Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\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..34bbff41760753bd 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 exportDmaBuffer(unsigned int index, unsigned int plane);\n> \n> I would have named this exportBuffer()\n\nexportBuffer() can be interpreted to refer to either the Buffer class\n(which isn't correct here), or to a v4l2_buffer, and thus multiple\ndmabuf instances (which is also equally incorrect). exportDmaBuffer(),\non the other hand, is clearer, but doesn't follow any common naming\nscheme. I think the right function name here, given the Dmabuf class, is\nexportDmabuf(). But then one would ask the question of why this function\ndoesn't return a Dmabuf :-)\n\nWe clearly need to standardize on common terms. If the method can't be\nmodified to return a Dmabuf, I would name it exportDmabufFd().\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 644e4545a2f33b2e..cc0a1c9382a2b1ed 100644\n> > --- a/src/libcamera/v4l2_videodevice.cpp\n> > +++ b/src/libcamera/v4l2_videodevice.cpp\n> > @@ -901,28 +901,19 @@ 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 = exportDmaBuffer(index, planeIndex);\n> > +\tif (fd < 0)\n> > +\t\treturn fd;\n> >\n> > -\tbuffer->planes().emplace_back(expbuf.fd, length);\n> > -\t::close(expbuf.fd);\n> > +\tbuffer->planes().emplace_back(fd, length);\n> > +\t::close(fd);\n> >\n> >  \treturn 0;\n> >  }\n> > @@ -948,6 +939,26 @@ int V4L2VideoDevice::importBuffers(BufferPool *pool)\n> >  \treturn 0;\n> >  }\n> >\n> > +int V4L2VideoDevice::exportDmaBuffer(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> \n> Do you need the usual ret = -errno dance to avoid errno being\n> overwritten by LOG() ?\n> \n> > +\t\tLOG(V4L2, Error)\n> > +\t\t\t<< \"Failed to export buffer: \" << strerror(-ret);\n> \n> Ah, you really need to assign ret before this one :)\n\nThe ioctl() call above is a member function of V4L2Device, it's not\n::ioctl(). It returns the error code directly.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> > +\t\treturn ret;\n> > +\t}\n> > +\n> > +\treturn expbuf.fd;\n> > +}\n> > +\n> \n> With this addressed\n> \n> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>\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[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 903E960BDB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  9 Dec 2019 19:40:09 +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 0740511B7;\n\tMon,  9 Dec 2019 19:40:08 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1575916809;\n\tbh=xl/SbAFXc5HX4euWhu1kRkV3l5rDxun2REPxQ2AOSBg=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=N3BKeUraj+xooDqdXoxGdCtEEiNiHMd4aneDUlEA9/xIKja1PKskjGjl+/tdRM6+l\n\tmRDJ4S7/OIWOSg9ppAc16vrSslpnRhpTv6TkjaiapADnIVwZwEJZdGgtnFk2rFkThY\n\tzKnBbiCSB2OzTC/j/z2XOZipIy8LcM2dVZdMaBUE=","Date":"Mon, 9 Dec 2019 20:40:02 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>,\n\tlibcamera-devel@lists.libcamera.org","Message-ID":"<20191209184002.GD18060@pendragon.ideasonboard.com>","References":"<20191126233620.1695316-1-niklas.soderlund@ragnatech.se>\n\t<20191126233620.1695316-14-niklas.soderlund@ragnatech.se>\n\t<20191127145352.vtsgxqvkpvmyqwpq@uno.localdomain>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20191127145352.vtsgxqvkpvmyqwpq@uno.localdomain>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 13/30] libcamera: v4l2_videodevice:\n\tExtract exportDmaBuffer() to export DMA buffer","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":"Mon, 09 Dec 2019 18:40:09 -0000"}}]