From patchwork Fri Nov 13 08:56:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 10421 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 5FE2BBE082 for ; Fri, 13 Nov 2020 08:57:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A8B46631BA; Fri, 13 Nov 2020 09:57:02 +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="BzCxogPO"; dkim-atps=neutral Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9DFE1631B0 for ; Fri, 13 Nov 2020 09:57:01 +0100 (CET) Received: by mail-wm1-x336.google.com with SMTP id w24so7700632wmi.0 for ; Fri, 13 Nov 2020 00:57:01 -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:mime-version :content-transfer-encoding; bh=UJdolys+WSJVKPXmuVms/SsEXhD62UGdUH3Pqy0i8ag=; b=BzCxogPOgSTXmQ0rKVDo9x6U2Rzd6BemQZiczcVY38u4JQ/82rCfaf9QNuHROdmrq1 BXK3y+0WCRzXI7abyEDiivNQ3yPb5QvwX7dE/kpKfZk8FlA2FcmZ2kU39GDaUUuy9tMl CSJ6XmTI+0zITs6qdasNOwmYzVztY8QTjnqrTgZOL3fsKVN2HpN5t/ih8t3xH7at4n7w YwhMhKhskU82RppCmoskOrNgtVsPXHpgjHn8I4PtK3Sg5mAIXXvTb2mIYU5LvogOuKOX 6PxtK7Mfs6RiOJJKdF8bkyV+ES21SI8Qs4WzdzplyzxaWSyWULWdajy2QeFSvUPj+kn1 5iLQ== 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:mime-version :content-transfer-encoding; bh=UJdolys+WSJVKPXmuVms/SsEXhD62UGdUH3Pqy0i8ag=; b=JqfCzPpNix006+KimsQvIJxrOhm2FkGk3U0CrjjCfN5+oxtLYSAA9raQU9l/tHZPt8 fdaOcIW12v/pdY3xYt+WA5fySLfuaCDdlmZ98G02wef6Zh/7PmGpXCaR4BQGUw/Ofict XZ73S+xm5NPqLgBocjnpNHUfN/XX4xtRSYHslO08xQpLtaZGP70/R6/q4hFAcCJG9SRV OIqJ4sxw0tlxVFLFdEy/sZ74o0B8FwlIE8rdVvb4v9A/FZ/RFqcDI17sfWx+rd9UzKZ8 Nt9kQG8fghon1JlMyAPc8hEskWPPne3W/xwNXe9pHbYDYBNntVYQ4Sv380pONXamxj1N KQcA== X-Gm-Message-State: AOAM5319e32NMxCMfttsgxIZiEaCZ1nqU3LS8CePq331a46ZpNmzC6uk LuwEgjQ6t7w1uFSnPJ7ywvLhu39P0doY7OZ2 X-Google-Smtp-Source: ABdhPJyWZGLvMSh19r9ePaoXzah0BlFjdl+t1RRTOcjUXf3c+LHUzQSEe09vV90R/JL2at/t1xR0KA== X-Received: by 2002:a05:600c:288:: with SMTP id 8mr1437382wmk.106.1605257820915; Fri, 13 Nov 2020 00:57:00 -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.56.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2020 00:57:00 -0800 (PST) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Fri, 13 Nov 2020 08:56:56 +0000 Message-Id: <20201113085657.34086-1-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/2] pipeline: raspberrypi: Use MappedFrameBuffer for embedded data 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" Use a MappedFrameBuffer to mmap embedded data buffers for the pipeline handler to use in the cases where the sensor does not fill it in. This avoids the need to mmap and unmap on every frame. Signed-off-by: Naushir Patuck Reviewed-by: Kieran Bingham --- .../pipeline/raspberrypi/raspberrypi.cpp | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index dd62dfc7..faa06c00 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -24,6 +24,7 @@ #include #include "libcamera/internal/bayer_format.h" +#include "libcamera/internal/buffer.h" #include "libcamera/internal/camera_sensor.h" #include "libcamera/internal/device_enumerator.h" #include "libcamera/internal/ipa_manager.h" @@ -165,6 +166,12 @@ public: /* Stores the ids of the buffers mapped in the IPA. */ std::unordered_set ipaBuffers_; + /* + * Map of (internal) mmaped embedded data buffers, to avoid having to + * map/unmap on every frame. + */ + std::map mappedEmbeddedBuffers_; + /* DMAHEAP allocation helper. */ RPi::DmaHeap dmaHeap_; FileDescriptor lsTable_; @@ -1040,6 +1047,13 @@ int PipelineHandlerRPi::prepareBuffers(Camera *camera) return ret; } + if (!data->sensorMetadata_) { + for (auto const &it : data->unicam_[Unicam::Embedded].getBuffers()) { + data->mappedEmbeddedBuffers_.emplace(it.first, + MappedFrameBuffer(it.second, PROT_READ | PROT_WRITE)); + } + } + /* * Pass the stats and embedded data buffers to the IPA. No other * buffers need to be passed. @@ -1078,6 +1092,7 @@ void PipelineHandlerRPi::freeBuffers(Camera *camera) std::vector ipaBuffers(data->ipaBuffers_.begin(), data->ipaBuffers_.end()); data->ipa_->unmapBuffers(ipaBuffers); data->ipaBuffers_.clear(); + data->mappedEmbeddedBuffers_.clear(); for (auto const stream : data->streams_) stream->releaseBuffers(); @@ -1310,14 +1325,16 @@ void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer) * metadata buffer. */ if (!sensorMetadata_) { - const FrameBuffer &fb = buffer->planes(); - uint32_t *mem = static_cast(::mmap(nullptr, fb.planes()[0].length, - PROT_READ | PROT_WRITE, - MAP_SHARED, - fb.planes()[0].fd.fd(), 0)); - mem[0] = ctrl[V4L2_CID_EXPOSURE]; - mem[1] = ctrl[V4L2_CID_ANALOGUE_GAIN]; - munmap(mem, fb.planes()[0].length); + unsigned int bufferId = unicam_[Unicam::Embedded].getBufferId(buffer); + auto it = mappedEmbeddedBuffers_.find(bufferId); + if (it != mappedEmbeddedBuffers_.end()) { + uint32_t *mem = reinterpret_cast(it->second.maps()[0].data()); + mem[0] = ctrl[V4L2_CID_EXPOSURE]; + mem[1] = ctrl[V4L2_CID_ANALOGUE_GAIN]; + } else { + LOG(RPI, Warning) << "Failed to find embedded buffer " + << bufferId; + } } }