From patchwork Mon Aug 3 16:18:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 9144 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 73C0BBD86F for ; Mon, 3 Aug 2020 16:18:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3B38F60396; Mon, 3 Aug 2020 18:18:27 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="W6VsN1L+"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 389A66199D for ; Mon, 3 Aug 2020 18:18:23 +0200 (CEST) Received: from Q.local (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B8FD3B27; Mon, 3 Aug 2020 18:18:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1596471502; bh=ogy899GEHQ2j1b5E66u6H0gWtBw2hIdVmT+pTTs87Pw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W6VsN1L+AQz8JTKK1fH/lraVX0V77WQx/YyE6HMrI1uIt4LUAKpueT8+RBVLaAQ7o 8bgYL9WiGCiMwdEyGr7IAzdqCwq0lXEH4zSbpMeN+vKiYMxyhC8oCFpAb94v5nhqBG Rb+dIxZsrwjPTRs6JqWxh41EF67fant7U7LnUKFs= From: Kieran Bingham To: libcamera devel Date: Mon, 3 Aug 2020 17:18:08 +0100 Message-Id: <20200803161816.107113-5-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200803161816.107113-1-kieran.bingham@ideasonboard.com> References: <20200803161816.107113-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 04/12] libcamera: buffer: Convert copyFrom to use MappedFrameBuffer X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Utilise the new MappedFrameBuffer helper to handle all mapping and unmapping of the copyFrom helper function. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/libcamera/buffer.cpp | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/src/libcamera/buffer.cpp b/src/libcamera/buffer.cpp index 2f667db42922..fc15fc1c8ec4 100644 --- a/src/libcamera/buffer.cpp +++ b/src/libcamera/buffer.cpp @@ -258,32 +258,23 @@ int FrameBuffer::copyFrom(const FrameBuffer *src) } } - for (unsigned int i = 0; i < planes_.size(); i++) { - void *dstmem = mmap(nullptr, planes_[i].length, PROT_WRITE, - MAP_SHARED, planes_[i].fd.fd(), 0); + MappedFrameBuffer source(src, PROT_READ); + MappedFrameBuffer destination(this, PROT_WRITE); - if (dstmem == MAP_FAILED) { - LOG(Buffer, Error) - << "Failed to map destination plane " << i; - metadata_.status = FrameMetadata::FrameError; - return -EINVAL; - } - - void *srcmem = mmap(nullptr, src->planes_[i].length, PROT_READ, - MAP_SHARED, src->planes_[i].fd.fd(), 0); - - if (srcmem == MAP_FAILED) { - munmap(dstmem, planes_[i].length); - LOG(Buffer, Error) - << "Failed to map source plane " << i; - metadata_.status = FrameMetadata::FrameError; - return -EINVAL; - } + if (!source.isValid()) { + LOG(Buffer, Error) << "Failed to map source planes"; + return -EINVAL; + } - memcpy(dstmem, srcmem, src->planes_[i].length); + if (!destination.isValid()) { + LOG(Buffer, Error) << "Failed to map destination planes"; + return -EINVAL; + } - munmap(srcmem, src->planes_[i].length); - munmap(dstmem, planes_[i].length); + for (unsigned int i = 0; i < planes_.size(); i++) { + memcpy(destination.maps()[i].data(), + source.maps()[i].data(), + source.maps()[i].size()); } metadata_ = src->metadata_;