From patchwork Fri Nov 13 08:56:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 10422 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 58176BE082 for ; Fri, 13 Nov 2020 08:57:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 20FA0631BC; Fri, 13 Nov 2020 09:57:05 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="VTa/ZBeW"; dkim-atps=neutral Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D70CE631BC for ; Fri, 13 Nov 2020 09:57:02 +0100 (CET) Received: by mail-wr1-x42e.google.com with SMTP id d12so8821317wrr.13 for ; Fri, 13 Nov 2020 00:57:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MFxOD1RHH9DUpvo3uH9tZAAzL14TCR0C3W6cmDAUVGs=; b=VTa/ZBeWRbcUyGiUK6RC1wSgXbocFoyQ5OGG4OxKLmBUhoaunnlHGSz1htD7gg4q9p n98Z0Eteb5lJaEggr2U9QQbOpGqTCWiRlAxz2qhQuGR6BDsgOqVmQR4KhD4X6iyEplJL BGTG6chnyyk54Qd6OcoAwKQWijSThIYm0sium06FA+w6HfdKDPHv9txV7tnok4Qmnr11 PjnEooWop2pAiAuper5tBOFN3qpOUPTNzAjY7BYlac4ssVHHhoL6jBsMNGGdvBUyAGSt ddGHh6xfutmiUGsRHNCwe2i1wrfUxTIFVmfJ4t+yr0rkGycx/yZzIAMdG3DjF139uGgz YY6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MFxOD1RHH9DUpvo3uH9tZAAzL14TCR0C3W6cmDAUVGs=; b=mmOJ51Ap0zZ5ICbww9MJ1lAGA+n4AjTpvi5/XFqHOVg78aXd1lYSqhdsW+0bRPgufx 2RLDZLGfZoMiEZ/ErOswG3nagQriR2sA4iry0bexf9VasWfI5GpOeEu+TNyXILOuCbLf zMqI3I9ZKD6Y+o2oRau/uetmJQ7WvkXVcIWv9QuNQnqRG7NRS9MvomhHnWyVH2vURf1j r0wPtx4BY74ouOU3516pdhuJQEJVBflPd8y2Xkl0rp3WODEG1/W+bw9cw29zCsLwH7al pdk9LWefF7NDy0RKAFRn+6o9dwIQphHneeFTJ4GNP98+xa5dy++qyEDJVpSBDzRXvKqH Qzwg== X-Gm-Message-State: AOAM5319eleKTxRBEB7SFxLHTnIGOlXdG9laoA1O2nSyxharXpwfk6uL T9uBgeafNnS2Z+3W1XeUoZMXGLHrBw/y5e1w X-Google-Smtp-Source: ABdhPJylizeOEmH0zTxH2irylsJftS8Mzi6+M8V887zLRzFYHcDwKp3mC2aUKymcMj6E3dEQDCV8Mw== X-Received: by 2002:a5d:510a:: with SMTP id s10mr2004024wrt.402.1605257822172; Fri, 13 Nov 2020 00:57:02 -0800 (PST) Received: from naushir-VirtualBox.pitowers.org ([2a00:1098:3142:14:a00:27ff:fe4d:f6a2]) by smtp.gmail.com with ESMTPSA id v8sm9266184wmg.28.2020.11.13.00.57.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2020 00:57:01 -0800 (PST) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Fri, 13 Nov 2020 08:56:57 +0000 Message-Id: <20201113085657.34086-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201113085657.34086-1-naush@raspberrypi.com> References: <20201113085657.34086-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/2] ipa: raspberrypi: Use MappedFrameBuffer for the IPA buffers 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" Instead of directly mmaping/unmapping buffers passed to the IPA, use a MappedFrameBuffer. The latter is a cleaner interface, and avoid code duplication. Signed-off-by: Naushir Patuck Reviewed-by: Kieran Bingham --- src/ipa/raspberrypi/raspberrypi.cpp | 41 +++++++++++------------------ 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 1c255aa2..6bb45b75 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -24,6 +24,7 @@ #include +#include "libcamera/internal/buffer.h" #include "libcamera/internal/camera_sensor.h" #include "libcamera/internal/log.h" #include "libcamera/internal/utils.h" @@ -110,8 +111,7 @@ private: void applyLS(const struct AlscStatus *lsStatus, ControlList &ctrls); void resampleTable(uint16_t dest[], double const src[12][16], int destW, int destH); - std::map buffers_; - std::map buffersMemory_; + std::map buffers_; ControlInfoMap unicamCtrls_; ControlInfoMap ispCtrls_; @@ -319,31 +319,18 @@ void IPARPi::configure(const CameraSensorInfo &sensorInfo, void IPARPi::mapBuffers(const std::vector &buffers) { for (const IPABuffer &buffer : buffers) { - auto elem = buffers_.emplace(std::piecewise_construct, - std::forward_as_tuple(buffer.id), - std::forward_as_tuple(buffer.planes)); - const FrameBuffer &fb = elem.first->second; - - buffersMemory_[buffer.id] = mmap(nullptr, fb.planes()[0].length, - PROT_READ | PROT_WRITE, MAP_SHARED, - fb.planes()[0].fd.fd(), 0); - - if (buffersMemory_[buffer.id] == MAP_FAILED) { - int ret = -errno; - LOG(IPARPI, Fatal) << "Failed to mmap buffer: " << strerror(-ret); - } + const FrameBuffer fb = FrameBuffer(buffer.planes); + buffers_.emplace(buffer.id, MappedFrameBuffer(&fb, PROT_READ | PROT_WRITE)); } } void IPARPi::unmapBuffers(const std::vector &ids) { for (unsigned int id : ids) { - const auto fb = buffers_.find(id); - if (fb == buffers_.end()) + auto it = buffers_.find(id); + if (it == buffers_.end()) continue; - munmap(buffersMemory_[id], fb->second.planes()[0].length); - buffersMemory_.erase(id); buffers_.erase(id); } } @@ -785,15 +772,16 @@ void IPARPi::prepareISP(unsigned int bufferId) bool IPARPi::parseEmbeddedData(unsigned int bufferId, struct DeviceStatus &deviceStatus) { - auto it = buffersMemory_.find(bufferId); - if (it == buffersMemory_.end()) { + auto it = buffers_.find(bufferId); + if (it == buffers_.end()) { LOG(IPARPI, Error) << "Could not find embedded buffer!"; return false; } - int size = buffers_.find(bufferId)->second.planes()[0].length; + int size = buffers_.find(bufferId)->second.maps()[0].size(); + void *ptr = buffers_.find(bufferId)->second.maps()[0].data(); helper_->Parser().SetBufferSize(size); - RPiController::MdParser::Status status = helper_->Parser().Parse(it->second); + RPiController::MdParser::Status status = helper_->Parser().Parse(ptr); if (status != RPiController::MdParser::Status::OK) { LOG(IPARPI, Error) << "Embedded Buffer parsing failed, error " << status; } else { @@ -820,13 +808,14 @@ bool IPARPi::parseEmbeddedData(unsigned int bufferId, struct DeviceStatus &devic void IPARPi::processStats(unsigned int bufferId) { - auto it = buffersMemory_.find(bufferId); - if (it == buffersMemory_.end()) { + auto it = buffers_.find(bufferId); + if (it == buffers_.end()) { LOG(IPARPI, Error) << "Could not find stats buffer!"; return; } - bcm2835_isp_stats *stats = static_cast(it->second); + void *ptr = buffers_.find(bufferId)->second.maps()[0].data(); + bcm2835_isp_stats *stats = static_cast(ptr); RPiController::StatisticsPtr statistics = std::make_shared(*stats); controller_.Process(statistics, &rpiMetadata_);