[{"id":11572,"web_url":"https://patchwork.libcamera.org/comment/11572/","msgid":"<20200724165958.GN5921@pendragon.ideasonboard.com>","date":"2020-07-24T16:59:58","subject":"Re: [libcamera-devel] [RFC PATCH 2/8] libcamera: buffer: Convert\n\tcopyFrom to use MappedFrameBuffer","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 Mon, Jul 20, 2020 at 11:42:26PM +0100, Kieran Bingham wrote:\n> Utilise the new MappedFrameBuffer helper to handle all mapping and\n> unmapping of the copyFrom helper function.\n> \n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n> \n> This shows how the MappedFrameBuffer can then be utilised, even though I\n> believe this particular copyFrom() function is expected to disappear\n> sometime soon.\n> \n>  src/libcamera/buffer.cpp | 37 ++++++++++++++-----------------------\n>  1 file changed, 14 insertions(+), 23 deletions(-)\n> \n> diff --git a/src/libcamera/buffer.cpp b/src/libcamera/buffer.cpp\n> index 28b43d937f57..af5345b91195 100644\n> --- a/src/libcamera/buffer.cpp\n> +++ b/src/libcamera/buffer.cpp\n> @@ -257,32 +257,23 @@ int FrameBuffer::copyFrom(const FrameBuffer *src)\n>  \t\t}\n>  \t}\n>  \n> -\tfor (unsigned int i = 0; i < planes_.size(); i++) {\n> -\t\tvoid *dstmem = mmap(nullptr, planes_[i].length, PROT_WRITE,\n> -\t\t\t\t    MAP_SHARED, planes_[i].fd.fd(), 0);\n> +\tMappedFrameBuffer source(src, PROT_READ);\n> +\tMappedFrameBuffer destination(this, PROT_WRITE);\n>  \n> -\t\tif (dstmem == MAP_FAILED) {\n> -\t\t\tLOG(Buffer, Error)\n> -\t\t\t\t<< \"Failed to map destination plane \" << i;\n> -\t\t\tmetadata_.status = FrameMetadata::FrameError;\n> -\t\t\treturn -EINVAL;\n> -\t\t}\n> -\n> -\t\tvoid *srcmem = mmap(nullptr, src->planes_[i].length, PROT_READ,\n> -\t\t\t\t    MAP_SHARED, src->planes_[i].fd.fd(), 0);\n> -\n> -\t\tif (srcmem == MAP_FAILED) {\n> -\t\t\tmunmap(dstmem, planes_[i].length);\n> -\t\t\tLOG(Buffer, Error)\n> -\t\t\t\t<< \"Failed to map source plane \" << i;\n> -\t\t\tmetadata_.status = FrameMetadata::FrameError;\n> -\t\t\treturn -EINVAL;\n> -\t\t}\n> +\tif (!source.isValid()) {\n> +\t\tLOG(Buffer, Error) << \"Failed to map source planes\";\n> +\t\treturn -EINVAL;\n> +\t}\n>  \n> -\t\tmemcpy(dstmem, srcmem, src->planes_[i].length);\n> +\tif (!destination.isValid()) {\n> +\t\tLOG(Buffer, Error) << \"Failed to map destination planes\";\n> +\t\treturn -EINVAL;\n> +\t}\n>  \n> -\t\tmunmap(srcmem, src->planes_[i].length);\n> -\t\tmunmap(dstmem, planes_[i].length);\n> +\tfor (unsigned int i = 0; i < planes_.size(); i++) {\n> +\t\tmemcpy(destination.maps()[i].address,\n> +\t\t       source.maps()[i].address,\n> +\t\t       source.maps()[i].length);\n>  \t}\n>  \n>  \tmetadata_ = src->metadata_;","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id CBA2FBD86F\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 24 Jul 2020 17:00:06 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9B2E961218;\n\tFri, 24 Jul 2020 19:00:06 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 91766605B2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 24 Jul 2020 19:00:05 +0200 (CEST)","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 2553B538;\n\tFri, 24 Jul 2020 19:00:05 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"XDYj72Ss\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1595610005;\n\tbh=4JmbpnB7k9M1JAgs6YgyBZFx6HsFb2BsGknt36Ry7mk=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=XDYj72SsC8UXpBf2q/0mEUjW2IHeN/F7NHcA6uu9U/E/ORVXBBBVbW59MBWnrdT2n\n\tk2lp7ZKLkSCu5pFjOHNmesMRuYDCii+oPAGrNAnF0m+USDNkf5NJOjXwExGx9TspLN\n\t2GMoQDgkjtP1ONuJMMNaZja9gwO+2j/VAfl2FV1s=","Date":"Fri, 24 Jul 2020 19:59:58 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<20200724165958.GN5921@pendragon.ideasonboard.com>","References":"<20200720224232.153717-1-kieran.bingham@ideasonboard.com>\n\t<20200720224232.153717-3-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20200720224232.153717-3-kieran.bingham@ideasonboard.com>","Subject":"Re: [libcamera-devel] [RFC PATCH 2/8] libcamera: buffer: Convert\n\tcopyFrom to use MappedFrameBuffer","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>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]