[{"id":2264,"web_url":"https://patchwork.libcamera.org/comment/2264/","msgid":"<20190714104953.GI31102@wyvern>","date":"2019-07-14T10:49:53","subject":"Re: [libcamera-devel] [PATCH v2 10/16] libcamera: stream: Shorten\n\taccess to the bufferPool","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Jacopo,\n\nThanks for your patch.\n\nOn 2019-07-13 20:23:45 +0300, Laurent Pinchart wrote:\n> From: Jacopo Mondi <jacopo@jmondi.org>\n> \n> All interactions with the Stream's buffers currently go through the\n> BufferPool. In order to shorten accessing the buffers array, and eventually\n> restrict access to the Stream's internal buffer pool, provide operations to\n> access, create and destroy buffers.\n> \n> It is still possible to access the pool for pipeline handlers to\n> populate it by exporting buffers from a video device to Stream's pool.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  include/libcamera/stream.h |  4 ++++\n>  src/cam/capture.cpp        |  2 +-\n>  src/libcamera/camera.cpp   |  4 ++--\n>  src/libcamera/stream.cpp   | 36 ++++++++++++++++++++++++++++++++++--\n>  src/qcam/main_window.cpp   |  2 +-\n>  5 files changed, 42 insertions(+), 6 deletions(-)\n> \n> diff --git a/include/libcamera/stream.h b/include/libcamera/stream.h\n> index f595a630eb4a..bc14fb60480e 100644\n> --- a/include/libcamera/stream.h\n> +++ b/include/libcamera/stream.h\n> @@ -71,11 +71,15 @@ public:\n>  \tstd::unique_ptr<Buffer> createBuffer(unsigned int index);\n>  \n>  \tBufferPool &bufferPool() { return bufferPool_; }\n> +\tstd::vector<BufferMemory> &buffers() { return bufferPool_.buffers(); }\n>  \tconst StreamConfiguration &configuration() const { return configuration_; }\n>  \n>  protected:\n>  \tfriend class Camera;\n>  \n> +\tvoid createBuffers(unsigned int count);\n> +\tvoid destroyBuffers();\n> +\n>  \tBufferPool bufferPool_;\n>  \tStreamConfiguration configuration_;\n>  };\n> diff --git a/src/cam/capture.cpp b/src/cam/capture.cpp\n> index 66ec1abaa5ac..5ffa4ae291da 100644\n> --- a/src/cam/capture.cpp\n> +++ b/src/cam/capture.cpp\n> @@ -154,7 +154,7 @@ void Capture::requestComplete(Request *request, const std::map<Stream *, Buffer\n>  \tfor (auto it = buffers.begin(); it != buffers.end(); ++it) {\n>  \t\tStream *stream = it->first;\n>  \t\tBuffer *buffer = it->second;\n> -\t\tBufferMemory *mem = &stream->bufferPool().buffers()[buffer->index()];\n> +\t\tBufferMemory *mem = &stream->buffers()[buffer->index()];\n>  \t\tconst std::string &name = streamName_[stream];\n>  \n>  \t\tinfo << \" \" << name\n> diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\n> index 1f307654ab01..61d3e821f48f 100644\n> --- a/src/libcamera/camera.cpp\n> +++ b/src/libcamera/camera.cpp\n> @@ -683,7 +683,7 @@ int Camera::configure(CameraConfiguration *config)\n>  \t\t * Allocate buffer objects in the pool.\n>  \t\t * Memory will be allocated and assigned later.\n>  \t\t */\n> -\t\tstream->bufferPool().createBuffers(cfg.bufferCount);\n> +\t\tstream->createBuffers(cfg.bufferCount);\n>  \t}\n>  \n>  \tstate_ = CameraConfigured;\n> @@ -744,7 +744,7 @@ int Camera::freeBuffers()\n>  \t\t * All mappings must be destroyed before buffers can be freed\n>  \t\t * by the V4L2 device that has allocated them.\n>  \t\t */\n> -\t\tstream->bufferPool().destroyBuffers();\n> +\t\tstream->destroyBuffers();\n>  \t}\n>  \n>  \tstate_ = CameraConfigured;\n> diff --git a/src/libcamera/stream.cpp b/src/libcamera/stream.cpp\n> index 6d80646b55cd..884fbfebd52c 100644\n> --- a/src/libcamera/stream.cpp\n> +++ b/src/libcamera/stream.cpp\n> @@ -435,19 +435,51 @@ std::unique_ptr<Buffer> Stream::createBuffer(unsigned int index)\n>   * \\fn Stream::bufferPool()\n>   * \\brief Retrieve the buffer pool for the stream\n>   *\n> - * The buffer pool handles the buffers used to capture frames at the output of\n> - * the stream. It is initially created empty and shall be populated with\n> + * The buffer pool handles the memory buffers used to store frames for the\n> + * stream. It is initially created empty and shall be populated with\n>   * buffers before being used.\n>   *\n>   * \\return A reference to the buffer pool\n>   */\n>  \n> +/**\n> + * \\fn Stream::buffers()\n> + * \\brief Retrieve the memory buffers in the Stream's buffer pool\n> + * \\return The list of stream's memory buffers\n> + */\n> +\n>  /**\n>   * \\fn Stream::configuration()\n>   * \\brief Retrieve the active configuration of the stream\n>   * \\return The active configuration of the stream\n>   */\n>  \n> +/**\n> + * \\brief Create buffers for the stream\n> + * \\param count The number of buffers to create\n\ns/param/param[in]/\n\nWith this fixed,\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> + *\n> + * Create \\a count empty buffers in the Stream's buffer pool.\n> + */\n> +void Stream::createBuffers(unsigned int count)\n> +{\n> +\tdestroyBuffers();\n> +\tif (count == 0)\n> +\t\treturn;\n> +\n> +\tbufferPool_.createBuffers(count);\n> +}\n> +\n> +/**\n> + * \\brief Destroy buffers in the stream\n> + *\n> + * If no buffers have been created or if buffers have already been destroyed no\n> + * operation is performed.\n> + */\n> +void Stream::destroyBuffers()\n> +{\n> +\tbufferPool_.destroyBuffers();\n> +}\n> +\n>  /**\n>   * \\var Stream::bufferPool_\n>   * \\brief The pool of buffers associated with the stream\n> diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp\n> index 7023e1158fb6..92f888323f0b 100644\n> --- a/src/qcam/main_window.cpp\n> +++ b/src/qcam/main_window.cpp\n> @@ -235,7 +235,7 @@ void MainWindow::requestComplete(Request *request,\n>  \t\t  << \" fps: \" << std::fixed << std::setprecision(2) << fps\n>  \t\t  << std::endl;\n>  \n> -\tBufferMemory *mem = &stream->bufferPool().buffers()[buffer->index()];\n> +\tBufferMemory *mem = &stream->buffers()[buffer->index()];\n>  \tdisplay(buffer, mem);\n>  \n>  \trequest = camera_->createRequest();\n> -- \n> Regards,\n> \n> Laurent Pinchart\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-pg1-x541.google.com (mail-pg1-x541.google.com\n\t[IPv6:2607:f8b0:4864:20::541])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C447A61572\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 14 Jul 2019 12:49:59 +0200 (CEST)","by mail-pg1-x541.google.com with SMTP id l21so6407542pgm.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 14 Jul 2019 03:49:59 -0700 (PDT)","from localhost (softbank126159224182.bbtec.net. [126.159.224.182])\n\tby smtp.gmail.com with ESMTPSA id\n\tf14sm13201887pfn.53.2019.07.14.03.49.57\n\t(version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256);\n\tSun, 14 Jul 2019 03:49:57 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to\n\t:user-agent; bh=ati2XtdBwlD/xOyDbcl0lvgAgCs/lcrGOyQ56nWB4jI=;\n\tb=CIjHn4CWBKVXWWhHbMBts8fnfqWZ5fh+Kwe6LsxUo9aFTeTfXhCUNzg2VLw64UFUjs\n\te0GwR0YfUOCu9EY/ItX8DcFJF8BNrQpd3Bz9Cu1K1Msse72UAj71alpBKPK0T2JAyKTR\n\tiefBPSCIXYOU3dWrPMG0ue3uzzLaRbR/KomeMDuluN1MQxFYMvZgM8SrXpQZAPX06PQh\n\taj8yJGEadWOaRhYoytYjCkXxvsRYsYQ9r/LKZ7PzQAird79BNYJYzBphUIQeZ0sMcD54\n\tXUo0QoQsTRFeDRG8CiZxVm6toMnGZcyKywn71ittWzEx7wynTWD6M+qQzemau807OL7p\n\tBNVA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to:user-agent;\n\tbh=ati2XtdBwlD/xOyDbcl0lvgAgCs/lcrGOyQ56nWB4jI=;\n\tb=Vues91J8Wh/Vm+M0JST2MoSeuCP1mqVqyH7uUqNhuwGJbW4LIN8vKjL2/WuQvM/ohP\n\t68z3tvgyUzKWPLcIzy8JyrxaA6fIOwP82bgNmMGhbKe4q+mZJM/XGc1XuM6ErLKfHHp/\n\twy8rGYk1P4iuxNvL++VZPo1FcaTK6A1DZsyz631z+F+eaw0wi1vyULsShlzfxxItracq\n\tlT4IkmhvgBkE6+dt/o8x/lCyo1gMD2KLuXctpL1yc8KCLVpsUXPOQ7QCXjZ8u99g/8Wi\n\t2DLpfq7prkChNa0/vOJOvUV9HpLM2qFrG4eAQe162ovkh9yfKK0JnHuPY/76gc+o2Lh9\n\tb0Xg==","X-Gm-Message-State":"APjAAAVPdhU+KeM9qJHitEwE0TXjo7dUsXWcdDo+ETv3eDmX+kE/VT2y\n\tX+CysOT7ER7pACZBqoK/yTg=","X-Google-Smtp-Source":"APXvYqwptE0ViukpmFNzAHDGQCx+44IFD+w46LkBvbkIPjaZaROxBvWO2LIRa2AwNn13io8HGbDNpg==","X-Received":"by 2002:a17:90a:9604:: with SMTP id\n\tv4mr22537579pjo.66.1563101398424; \n\tSun, 14 Jul 2019 03:49:58 -0700 (PDT)","Date":"Sun, 14 Jul 2019 19:49:53 +0900","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190714104953.GI31102@wyvern>","References":"<20190713172351.25452-1-laurent.pinchart@ideasonboard.com>\n\t<20190713172351.25452-11-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190713172351.25452-11-laurent.pinchart@ideasonboard.com>","User-Agent":"Mutt/1.12.1 (2019-06-15)","Subject":"Re: [libcamera-devel] [PATCH v2 10/16] libcamera: stream: Shorten\n\taccess to the bufferPool","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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>","X-List-Received-Date":"Sun, 14 Jul 2019 10:50:00 -0000"}}]