[{"id":19017,"web_url":"https://patchwork.libcamera.org/comment/19017/","msgid":"<YSQpsVkiZQiTRLjf@pendragon.ideasonboard.com>","date":"2021-08-23T23:05:21","subject":"Re: [libcamera-devel] [RFC PATCH v2 06/10] qcam: main_window: Use\n\toffset mapping FrameBuffer","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Hiro,\n\nThank you for the patch.\n\nOn Mon, Aug 23, 2021 at 10:12:17PM +0900, Hirokazu Honda wrote:\n> FrameBuffer::Plane has offset info now. This uses the offset\n> in mapping FrameBuffer in MainWindow.\n> \n> Signed-off-by: Hirokazu Honda <hiroh@chromium.org>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  src/qcam/main_window.cpp | 16 +++++++++++-----\n>  src/qcam/main_window.h   |  1 +\n>  2 files changed, 12 insertions(+), 5 deletions(-)\n> \n> diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp\n> index 39d034de..7fdec4a8 100644\n> --- a/src/qcam/main_window.cpp\n> +++ b/src/qcam/main_window.cpp\n> @@ -10,6 +10,7 @@\n>  #include <iomanip>\n>  #include <string>\n>  #include <sys/mman.h>\n> +#include <unistd.h>\n>  \n>  #include <QComboBox>\n>  #include <QCoreApplication>\n> @@ -472,9 +473,12 @@ int MainWindow::startCapture()\n>  \t\tfor (const std::unique_ptr<FrameBuffer> &buffer : allocator_->buffers(stream)) {\n>  \t\t\t/* Map memory buffers and cache the mappings. */\n>  \t\t\tconst FrameBuffer::Plane &plane = buffer->planes().front();\n> -\t\t\tvoid *memory = mmap(NULL, plane.length, PROT_READ, MAP_SHARED,\n> +\t\t\tsize_t length = lseek(plane.fd.fd(), 0, SEEK_END);\n> +\t\t\tvoid *memory = mmap(NULL, length, PROT_READ, MAP_SHARED,\n>  \t\t\t\t\t    plane.fd.fd(), 0);\n> -\t\t\tmappedBuffers_[buffer.get()] = { memory, plane.length };\n> +\t\t\tmappedBuffers_[buffer.get()] = { memory, length };\n> +\t\t\tplaneData_[buffer.get()] = { static_cast<uint8_t *>(memory) + plane.offset,\n> +\t\t\t\t\t\t     plane.length };\n>  \n>  \t\t\t/* Store buffers on the free list. */\n>  \t\t\tfreeBuffers_[stream].enqueue(buffer.get());\n> @@ -541,6 +545,7 @@ error:\n>  \t\tmunmap(buffer.memory, buffer.size);\n>  \t}\n>  \tmappedBuffers_.clear();\n> +\tplaneData_.clear();\n>  \n>  \tfreeBuffers_.clear();\n>  \n> @@ -577,6 +582,7 @@ void MainWindow::stopCapture()\n>  \t\tmunmap(buffer.memory, buffer.size);\n>  \t}\n>  \tmappedBuffers_.clear();\n> +\tplaneData_.clear();\n>  \n>  \trequests_.clear();\n>  \tfreeQueue_.clear();\n> @@ -673,10 +679,10 @@ void MainWindow::processRaw(FrameBuffer *buffer,\n>  \t\t\t\t\t\t\t\"DNG Files (*.dng)\");\n>  \n>  \tif (!filename.isEmpty()) {\n> -\t\tconst MappedBuffer &mapped = mappedBuffers_[buffer];\n> +\t\tvoid *memory = planeData_[buffer].data();\n>  \t\tDNGWriter::write(filename.toStdString().c_str(), camera_.get(),\n>  \t\t\t\t rawStream_->configuration(), metadata, buffer,\n> -\t\t\t\t mapped.memory);\n> +\t\t\t\t memory);\n>  \t}\n>  #endif\n>  \n> @@ -753,7 +759,7 @@ void MainWindow::processViewfinder(FrameBuffer *buffer)\n>  \t\t<< \"fps:\" << Qt::fixed << qSetRealNumberPrecision(2) << fps;\n>  \n>  \t/* Render the frame on the viewfinder. */\n> -\tviewfinder_->render(buffer, &mappedBuffers_[buffer]);\n> +\t// HACK HACK HACK viewfinder_->render(buffer, &planeData_[buffer]);\n\nI'm afraid this needs a fix :-) Could it be as simple as\n\n\tviewfinder_->render(buffer, planeData_[buffer]);\n\n?\n\n>  }\n>  \n>  void MainWindow::queueRequest(FrameBuffer *buffer)\n> diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h\n> index 85d56ce4..f35cce36 100644\n> --- a/src/qcam/main_window.h\n> +++ b/src/qcam/main_window.h\n> @@ -107,6 +107,7 @@ private:\n>  \n>  \tstd::unique_ptr<CameraConfiguration> config_;\n>  \tstd::map<FrameBuffer *, MappedBuffer> mappedBuffers_;\n> +\tstd::map<FrameBuffer *, Span<uint8_t>> planeData_;\n>  \n>  \t/* Capture state, buffers queue and statistics */\n>  \tbool isCapturing_;","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 DF24CBD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 23 Aug 2021 23:05:33 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 45A65688A3;\n\tTue, 24 Aug 2021 01:05:33 +0200 (CEST)","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 02D7368890\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 24 Aug 2021 01:05:31 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 70F932A5;\n\tTue, 24 Aug 2021 01:05:31 +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=\"VU7LY7O1\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1629759931;\n\tbh=utNouOXRVEw6mCVtBm1AsfeAc6Uoh6Z1OttVzZGTXNQ=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=VU7LY7O1rqi+AQvPtDuSvUTzo9GnX9+degDjBYXAqF/CGVQj6Widjb4zjg6XtmRpW\n\tVUzyTtt/LCPdYPbZhmJtF0oKPOu3Ypa0xTyj0G5c0yzI9G2I25cdZtilevxpRZHA++\n\tgzYJzW3W8O3BKpqNM9jDSYxGmAPF7ESCXt8EkRsU=","Date":"Tue, 24 Aug 2021 02:05:21 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Hirokazu Honda <hiroh@chromium.org>","Message-ID":"<YSQpsVkiZQiTRLjf@pendragon.ideasonboard.com>","References":"<20210823131221.1034059-1-hiroh@chromium.org>\n\t<20210823131221.1034059-7-hiroh@chromium.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20210823131221.1034059-7-hiroh@chromium.org>","Subject":"Re: [libcamera-devel] [RFC PATCH v2 06/10] qcam: main_window: Use\n\toffset mapping FrameBuffer","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@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":19034,"web_url":"https://patchwork.libcamera.org/comment/19034/","msgid":"<CAO5uPHPkGpPMnQs6R-KNFEvUpeGDZcwaThUyZQrz2ZisSSwZ6g@mail.gmail.com>","date":"2021-08-25T06:15:40","subject":"Re: [libcamera-devel] [RFC PATCH v2 06/10] qcam: main_window: Use\n\toffset mapping FrameBuffer","submitter":{"id":63,"url":"https://patchwork.libcamera.org/api/people/63/","name":"Hirokazu Honda","email":"hiroh@chromium.org"},"content":"Hi Laurent,\n\nOn Tue, Aug 24, 2021 at 8:05 AM Laurent Pinchart\n<laurent.pinchart@ideasonboard.com> wrote:\n>\n> Hi Hiro,\n>\n> Thank you for the patch.\n>\n> On Mon, Aug 23, 2021 at 10:12:17PM +0900, Hirokazu Honda wrote:\n> > FrameBuffer::Plane has offset info now. This uses the offset\n> > in mapping FrameBuffer in MainWindow.\n> >\n> > Signed-off-by: Hirokazu Honda <hiroh@chromium.org>\n> > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > ---\n> >  src/qcam/main_window.cpp | 16 +++++++++++-----\n> >  src/qcam/main_window.h   |  1 +\n> >  2 files changed, 12 insertions(+), 5 deletions(-)\n> >\n> > diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp\n> > index 39d034de..7fdec4a8 100644\n> > --- a/src/qcam/main_window.cpp\n> > +++ b/src/qcam/main_window.cpp\n> > @@ -10,6 +10,7 @@\n> >  #include <iomanip>\n> >  #include <string>\n> >  #include <sys/mman.h>\n> > +#include <unistd.h>\n> >\n> >  #include <QComboBox>\n> >  #include <QCoreApplication>\n> > @@ -472,9 +473,12 @@ int MainWindow::startCapture()\n> >               for (const std::unique_ptr<FrameBuffer> &buffer : allocator_->buffers(stream)) {\n> >                       /* Map memory buffers and cache the mappings. */\n> >                       const FrameBuffer::Plane &plane = buffer->planes().front();\n> > -                     void *memory = mmap(NULL, plane.length, PROT_READ, MAP_SHARED,\n> > +                     size_t length = lseek(plane.fd.fd(), 0, SEEK_END);\n> > +                     void *memory = mmap(NULL, length, PROT_READ, MAP_SHARED,\n> >                                           plane.fd.fd(), 0);\n> > -                     mappedBuffers_[buffer.get()] = { memory, plane.length };\n> > +                     mappedBuffers_[buffer.get()] = { memory, length };\n> > +                     planeData_[buffer.get()] = { static_cast<uint8_t *>(memory) + plane.offset,\n> > +                                                  plane.length };\n> >\n> >                       /* Store buffers on the free list. */\n> >                       freeBuffers_[stream].enqueue(buffer.get());\n> > @@ -541,6 +545,7 @@ error:\n> >               munmap(buffer.memory, buffer.size);\n> >       }\n> >       mappedBuffers_.clear();\n> > +     planeData_.clear();\n> >\n> >       freeBuffers_.clear();\n> >\n> > @@ -577,6 +582,7 @@ void MainWindow::stopCapture()\n> >               munmap(buffer.memory, buffer.size);\n> >       }\n> >       mappedBuffers_.clear();\n> > +     planeData_.clear();\n> >\n> >       requests_.clear();\n> >       freeQueue_.clear();\n> > @@ -673,10 +679,10 @@ void MainWindow::processRaw(FrameBuffer *buffer,\n> >                                                       \"DNG Files (*.dng)\");\n> >\n> >       if (!filename.isEmpty()) {\n> > -             const MappedBuffer &mapped = mappedBuffers_[buffer];\n> > +             void *memory = planeData_[buffer].data();\n> >               DNGWriter::write(filename.toStdString().c_str(), camera_.get(),\n> >                                rawStream_->configuration(), metadata, buffer,\n> > -                              mapped.memory);\n> > +                              memory);\n> >       }\n> >  #endif\n> >\n> > @@ -753,7 +759,7 @@ void MainWindow::processViewfinder(FrameBuffer *buffer)\n> >               << \"fps:\" << Qt::fixed << qSetRealNumberPrecision(2) << fps;\n> >\n> >       /* Render the frame on the viewfinder. */\n> > -     viewfinder_->render(buffer, &mappedBuffers_[buffer]);\n> > +     // HACK HACK HACK viewfinder_->render(buffer, &planeData_[buffer]);\n>\n> I'm afraid this needs a fix :-) Could it be as simple as\n>\n>         viewfinder_->render(buffer, planeData_[buffer]);\n>\n> ?\n\nYeah, I commented out while I was waiting for your Span patch. :-)\n\n-Hiro\n>\n> >  }\n> >\n> >  void MainWindow::queueRequest(FrameBuffer *buffer)\n> > diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h\n> > index 85d56ce4..f35cce36 100644\n> > --- a/src/qcam/main_window.h\n> > +++ b/src/qcam/main_window.h\n> > @@ -107,6 +107,7 @@ private:\n> >\n> >       std::unique_ptr<CameraConfiguration> config_;\n> >       std::map<FrameBuffer *, MappedBuffer> mappedBuffers_;\n> > +     std::map<FrameBuffer *, Span<uint8_t>> planeData_;\n> >\n> >       /* Capture state, buffers queue and statistics */\n> >       bool isCapturing_;\n>\n> --\n> Regards,\n>\n> Laurent Pinchart","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 85D2ABD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 25 Aug 2021 06:15:54 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DA803688A3;\n\tWed, 25 Aug 2021 08:15:52 +0200 (CEST)","from mail-ej1-x631.google.com (mail-ej1-x631.google.com\n\t[IPv6:2a00:1450:4864:20::631])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E38E560257\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 25 Aug 2021 08:15:51 +0200 (CEST)","by mail-ej1-x631.google.com with SMTP id me10so20895304ejb.11\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 24 Aug 2021 23:15:51 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"UIAs8iv7\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to\n\t:cc; bh=fWi/7TUs5blFDKD1Ex+6YtW4qFpFrogMjV8LStnFRp8=;\n\tb=UIAs8iv7pmOPxAV5jvFW9umSO1rTLe0saEN0spllhLETITHklZNKehBomevC9WAzeq\n\twQcbgaOVhsshlwKDbVHhbMk5XO9UaY5kmaaYNIQFZDlbbJ0aHAXZknjps1wkNEHfhSQB\n\txsJ1w1a3NE59mKMPKfBEQXUaRjVXg4XMMF8JI=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to:cc;\n\tbh=fWi/7TUs5blFDKD1Ex+6YtW4qFpFrogMjV8LStnFRp8=;\n\tb=GuNQQhXAq8XaSgVMiV6ct6GB0gISG4wmIi046HyrpUlHnzkaGddaiDCBIz1OXU2E8V\n\tnoY/36IpL6KLyassy2UdHdPmoqRjnQydeLSkXQLzzpHDTyVtwyNluYBfdqS1dkXF8ppQ\n\t4nQgoVDk7u74Kidg1BvsmUcD9U1kxaHE7u+3nw+2GQKQZjut81lQUKKoDfau4WvDSpWS\n\tRCC2rH7Xuy2jrw4glTIwzKL571Kks57rQQTBz1pI9M4I2E+gBeFnWwWFluRvBc8Qs0QI\n\t4qyHqRrTslOQYZywO1E/Fv5MzUFQcuht06PPlhd5EX+VNeFSFxsJ0JNIOlJqKHEKAwi1\n\tnV+A==","X-Gm-Message-State":"AOAM533Qj0d4lFihyiXd2+Yd2IUsSSYpCsSumOmytCZ4syxQkbOJz+zU\n\tm/jrYN0EH81A/Ll0QH/pBw5pUXHRHWa1sgAJd6yIaQ==","X-Google-Smtp-Source":"ABdhPJz0foc4EPQx4a+nXhJFSUqj9+BWjk6uuh+Awq/k9st6QnSAdbdmYZDsyrkbUKo/44t1ah1kDU8VUQmbj6xpW+M=","X-Received":"by 2002:a17:907:969f:: with SMTP id\n\thd31mr22499332ejc.475.1629872151514; \n\tTue, 24 Aug 2021 23:15:51 -0700 (PDT)","MIME-Version":"1.0","References":"<20210823131221.1034059-1-hiroh@chromium.org>\n\t<20210823131221.1034059-7-hiroh@chromium.org>\n\t<YSQpsVkiZQiTRLjf@pendragon.ideasonboard.com>","In-Reply-To":"<YSQpsVkiZQiTRLjf@pendragon.ideasonboard.com>","From":"Hirokazu Honda <hiroh@chromium.org>","Date":"Wed, 25 Aug 2021 15:15:40 +0900","Message-ID":"<CAO5uPHPkGpPMnQs6R-KNFEvUpeGDZcwaThUyZQrz2ZisSSwZ6g@mail.gmail.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Subject":"Re: [libcamera-devel] [RFC PATCH v2 06/10] qcam: main_window: Use\n\toffset mapping FrameBuffer","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]