Show a patch.

GET /api/patches/8945/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 8945,
    "url": "https://patchwork.libcamera.org/api/patches/8945/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/8945/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20200724072218.943245-2-naush@raspberrypi.com>",
    "date": "2020-07-24T07:22:09",
    "name": "[libcamera-devel,v5,01/10] libcamera: pipeline: raspberrypi: Move RPiStream into a separate file",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "4b6b1dccad347de6e6625f648db32ab8eef284f9",
    "submitter": {
        "id": 34,
        "url": "https://patchwork.libcamera.org/api/people/34/?format=api",
        "name": "Naushir Patuck",
        "email": "naush@raspberrypi.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/8945/mbox/",
    "series": [
        {
            "id": 1132,
            "url": "https://patchwork.libcamera.org/api/series/1132/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1132",
            "date": "2020-07-24T07:22:08",
            "name": "Zero-copy RAW stream work",
            "version": 5,
            "mbox": "https://patchwork.libcamera.org/series/1132/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/8945/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/8945/checks/",
    "tags": {},
    "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 09116BD86F\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 24 Jul 2020 07:22:53 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CB06361192;\n\tFri, 24 Jul 2020 09:22:52 +0200 (CEST)",
            "from mail-wm1-x330.google.com (mail-wm1-x330.google.com\n\t[IPv6:2a00:1450:4864:20::330])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C757D6093B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 24 Jul 2020 09:22:49 +0200 (CEST)",
            "by mail-wm1-x330.google.com with SMTP id 184so7332682wmb.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 24 Jul 2020 00:22:49 -0700 (PDT)",
            "from naushir-VirtualBox.patuck.local ([88.97.76.4])\n\tby smtp.gmail.com with ESMTPSA id\n\t32sm246595wrn.86.2020.07.24.00.22.47\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 24 Jul 2020 00:22:47 -0700 (PDT)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"rksF9EuJ\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=R0wABbh0rXhrerDNNbs+uPoBiT7gZEbwCLJzO/rSnFg=;\n\tb=rksF9EuJ2Ecd2oiAMUQggZ26AAahoh1HUkRiuYWx4GMpUC9KRZpyRz9z9LF/OBtkg7\n\tbVasP7ph3eKlCg5R24PsNa1X1Lnw0P8JR6zM4HN4TairwoHThPMrb8fOSPnS2gsaAI8Y\n\tkv5oEQlDMYnEEKdOxaGMFzme9mueXVCgMYLSTPlwzcCn/EfFwnoVoDnwEPLGLNwatci9\n\tC3cDfKn3mS2Jmfx6uG2frO4E8b0ywRat6nKEnURbw4HEoc4tqF+owor7lr1kj9d5WpQO\n\tsqpfJeAjtsjel6wvE1sq/Kq8+DkcECQeyGY5YT4sWYzCMJpjW3h4SeLQePrMZ0I+WHHJ\n\tqhdQ==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=R0wABbh0rXhrerDNNbs+uPoBiT7gZEbwCLJzO/rSnFg=;\n\tb=BQoG7FAeLTg/U1bxAmoq68bvSFSP9j9nMGZNwXAakzsxmL6nN8IFuxNBgkuctNx+sg\n\tLPxsPFrNLMcLBu1795qAu3Ss8Hlp20O8i7/FJmYMeTyPPEubGtWieIxX1uF6Hq3QHWhf\n\t3nQXC9JtRlyHKNMuzq5tsLKVHKKyP/OWiKzzcyNPZWdbc8VcamcPxOQTyLWrOtUKzVu9\n\tc0QjCw7TX9b/GOMLgy4QQkpJc7cgcNd/KjQVvpXlArPEK96LDKplHCE0Vxn5DP2e0P40\n\tnvQjIu9EX14a/aaXdaY59NrH/CsO2kJyneZFkAEhaKHobQpaytJk6JT/6M1PKw82P3s4\n\tGj+g==",
        "X-Gm-Message-State": "AOAM531LwA/nBc0jO+P6TWlI4BOXaWvzfzU6RXC8TI3SBa750kzjQTJd\n\tKNhiRPsMYywDVwl4oKbksveJxEKkiqLWoQ==",
        "X-Google-Smtp-Source": "ABdhPJx6Mn7Z/zwIHYfuBVee78eW4UuOopE4Us7nwzOF1sCswjiYB7/YAYOndHPwh8PEBk8fh5CqUw==",
        "X-Received": "by 2002:a1c:3802:: with SMTP id f2mr463079wma.186.1595575368317; \n\tFri, 24 Jul 2020 00:22:48 -0700 (PDT)",
        "From": "Naushir Patuck <naush@raspberrypi.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Fri, 24 Jul 2020 08:22:09 +0100",
        "Message-Id": "<20200724072218.943245-2-naush@raspberrypi.com>",
        "X-Mailer": "git-send-email 2.25.1",
        "In-Reply-To": "<20200724072218.943245-1-naush@raspberrypi.com>",
        "References": "<20200724072218.943245-1-naush@raspberrypi.com>",
        "MIME-Version": "1.0",
        "Subject": "[libcamera-devel] [PATCH v5 01/10] libcamera: pipeline:\n\traspberrypi: Move RPiStream into a separate file",
        "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>",
        "Content-Type": "text/plain; charset=\"utf-8\"",
        "Content-Transfer-Encoding": "base64",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Put RPiStream into the RPi namespace and add a new log category (RPISTREAM).\nReorder methods into logical groups for readability.\n\nThere are no functional changes in this commit.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nTested-by: David Plowman <david.plowman@raspberrypi.com>\n---\n .../pipeline/raspberrypi/meson.build          |   1 +\n .../pipeline/raspberrypi/raspberrypi.cpp      | 193 ++----------------\n .../pipeline/raspberrypi/rpi_stream.cpp       | 116 +++++++++++\n .../pipeline/raspberrypi/rpi_stream.h         | 107 ++++++++++\n 4 files changed, 243 insertions(+), 174 deletions(-)\n create mode 100644 src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n create mode 100644 src/libcamera/pipeline/raspberrypi/rpi_stream.h",
    "diff": "diff --git a/src/libcamera/pipeline/raspberrypi/meson.build b/src/libcamera/pipeline/raspberrypi/meson.build\nindex ae0aed3b..7c5b6ff7 100644\n--- a/src/libcamera/pipeline/raspberrypi/meson.build\n+++ b/src/libcamera/pipeline/raspberrypi/meson.build\n@@ -3,5 +3,6 @@\n libcamera_sources += files([\n     'dma_heaps.cpp',\n     'raspberrypi.cpp',\n+    'rpi_stream.cpp',\n     'staggered_ctrl.cpp',\n ])\ndiff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex bf1c7714..6630ef57 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -19,7 +19,6 @@\n #include <libcamera/logging.h>\n #include <libcamera/property_ids.h>\n #include <libcamera/request.h>\n-#include <libcamera/stream.h>\n \n #include <linux/videodev2.h>\n \n@@ -33,6 +32,7 @@\n #include \"libcamera/internal/v4l2_videodevice.h\"\n \n #include \"dma_heaps.h\"\n+#include \"rpi_stream.h\"\n #include \"staggered_ctrl.h\"\n \n namespace libcamera {\n@@ -123,165 +123,10 @@ V4L2DeviceFormat findBestMode(V4L2PixFmtMap &formatsMap, const Size &req)\n \treturn bestMode;\n }\n \n-} /* namespace */\n-\n-/*\n- * Device stream abstraction for either an internal or external stream.\n- * Used for both Unicam and the ISP.\n- */\n-class RPiStream : public Stream\n-{\n-public:\n-\tRPiStream()\n-\t{\n-\t}\n-\n-\tRPiStream(const char *name, MediaEntity *dev, bool importOnly = false)\n-\t\t: external_(false), importOnly_(importOnly), name_(name),\n-\t\t  dev_(std::make_unique<V4L2VideoDevice>(dev))\n-\t{\n-\t}\n-\n-\tV4L2VideoDevice *dev() const\n-\t{\n-\t\treturn dev_.get();\n-\t}\n-\n-\tvoid setExternal(bool external)\n-\t{\n-\t\texternal_ = external;\n-\t}\n-\n-\tbool isExternal() const\n-\t{\n-\t\t/*\n-\t\t * Import streams cannot be external.\n-\t\t *\n-\t\t * RAW capture is a special case where we simply copy the RAW\n-\t\t * buffer out of the request. All other buffer handling happens\n-\t\t * as if the stream is internal.\n-\t\t */\n-\t\treturn external_ && !importOnly_;\n-\t}\n-\n-\tbool isImporter() const\n-\t{\n-\t\treturn importOnly_;\n-\t}\n-\n-\tvoid reset()\n-\t{\n-\t\texternal_ = false;\n-\t\tinternalBuffers_.clear();\n-\t}\n-\n-\tstd::string name() const\n-\t{\n-\t\treturn name_;\n-\t}\n-\n-\tvoid setExternalBuffers(std::vector<std::unique_ptr<FrameBuffer>> *buffers)\n-\t{\n-\t\texternalBuffers_ = buffers;\n-\t}\n-\n-\tconst std::vector<std::unique_ptr<FrameBuffer>> *getBuffers() const\n-\t{\n-\t\treturn external_ ? externalBuffers_ : &internalBuffers_;\n-\t}\n-\n-\tvoid releaseBuffers()\n-\t{\n-\t\tdev_->releaseBuffers();\n-\t\tif (!external_ && !importOnly_)\n-\t\t\tinternalBuffers_.clear();\n-\t}\n-\n-\tint importBuffers(unsigned int count)\n-\t{\n-\t\treturn dev_->importBuffers(count);\n-\t}\n-\n-\tint allocateBuffers(unsigned int count)\n-\t{\n-\t\treturn dev_->allocateBuffers(count, &internalBuffers_);\n-\t}\n-\n-\tint queueBuffers()\n-\t{\n-\t\tif (external_)\n-\t\t\treturn 0;\n-\n-\t\tfor (auto &b : internalBuffers_) {\n-\t\t\tint ret = dev_->queueBuffer(b.get());\n-\t\t\tif (ret) {\n-\t\t\t\tLOG(RPI, Error) << \"Failed to queue buffers for \"\n-\t\t\t\t\t\t<< name_;\n-\t\t\t\treturn ret;\n-\t\t\t}\n-\t\t}\n-\n-\t\treturn 0;\n-\t}\n-\n-\tbool findFrameBuffer(FrameBuffer *buffer) const\n-\t{\n-\t\tauto start = external_ ? externalBuffers_->begin() : internalBuffers_.begin();\n-\t\tauto end = external_ ? externalBuffers_->end() : internalBuffers_.end();\n-\n-\t\tif (importOnly_)\n-\t\t\treturn false;\n-\n-\t\tif (std::find_if(start, end,\n-\t\t\t\t [buffer](std::unique_ptr<FrameBuffer> const &ref) { return ref.get() == buffer; }) != end)\n-\t\t\treturn true;\n-\n-\t\treturn false;\n-\t}\n-\n-private:\n-\t/*\n-\t * Indicates that this stream is active externally, i.e. the buffers\n-\t * are provided by the application.\n-\t */\n-\tbool external_;\n-\t/* Indicates that this stream only imports buffers, e.g. ISP input. */\n-\tbool importOnly_;\n-\t/* Stream name identifier. */\n-\tstd::string name_;\n-\t/* The actual device stream. */\n-\tstd::unique_ptr<V4L2VideoDevice> dev_;\n-\t/* Internally allocated framebuffers associated with this device stream. */\n-\tstd::vector<std::unique_ptr<FrameBuffer>> internalBuffers_;\n-\t/* Externally allocated framebuffers associated with this device stream. */\n-\tstd::vector<std::unique_ptr<FrameBuffer>> *externalBuffers_;\n-};\n-\n-/*\n- * The following class is just a convenient (and typesafe) array of device\n- * streams indexed with an enum class.\n- */\n enum class Unicam : unsigned int { Image, Embedded };\n enum class Isp : unsigned int { Input, Output0, Output1, Stats };\n \n-template<typename E, std::size_t N>\n-class RPiDevice : public std::array<class RPiStream, N>\n-{\n-private:\n-\tconstexpr auto index(E e) const noexcept\n-\t{\n-\t\treturn static_cast<std::underlying_type_t<E>>(e);\n-\t}\n-public:\n-\tRPiStream &operator[](E e)\n-\t{\n-\t\treturn std::array<class RPiStream, N>::operator[](index(e));\n-\t}\n-\tconst RPiStream &operator[](E e) const\n-\t{\n-\t\treturn std::array<class RPiStream, N>::operator[](index(e));\n-\t}\n-};\n+} /* namespace */\n \n class RPiCameraData : public CameraData\n {\n@@ -305,15 +150,15 @@ public:\n \tvoid ispOutputDequeue(FrameBuffer *buffer);\n \n \tvoid clearIncompleteRequests();\n-\tvoid handleStreamBuffer(FrameBuffer *buffer, const RPiStream *stream);\n+\tvoid handleStreamBuffer(FrameBuffer *buffer, const RPi::RPiStream *stream);\n \tvoid handleState();\n \n \tCameraSensor *sensor_;\n \t/* Array of Unicam and ISP device streams and associated buffers/streams. */\n-\tRPiDevice<Unicam, 2> unicam_;\n-\tRPiDevice<Isp, 4> isp_;\n+\tRPi::RPiDevice<Unicam, 2> unicam_;\n+\tRPi::RPiDevice<Isp, 4> isp_;\n \t/* The vector below is just for convenience when iterating over all streams. */\n-\tstd::vector<RPiStream *> streams_;\n+\tstd::vector<RPi::RPiStream *> streams_;\n \t/* Buffers passed to the IPA. */\n \tstd::vector<IPABuffer> ipaBuffers_;\n \n@@ -762,7 +607,7 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n int PipelineHandlerRPi::exportFrameBuffers(Camera *camera, Stream *stream,\n \t\t\t\t\t   std::vector<std::unique_ptr<FrameBuffer>> *buffers)\n {\n-\tRPiStream *s = static_cast<RPiStream *>(stream);\n+\tRPi::RPiStream *s = static_cast<RPi::RPiStream *>(stream);\n \tunsigned int count = stream->configuration().bufferCount;\n \tint ret = s->dev()->exportBuffers(count, buffers);\n \n@@ -908,14 +753,14 @@ bool PipelineHandlerRPi::match(DeviceEnumerator *enumerator)\n \tstd::unique_ptr<RPiCameraData> data = std::make_unique<RPiCameraData>(this);\n \n \t/* Locate and open the unicam video streams. */\n-\tdata->unicam_[Unicam::Embedded] = RPiStream(\"Unicam Embedded\", unicam_->getEntityByName(\"unicam-embedded\"));\n-\tdata->unicam_[Unicam::Image] = RPiStream(\"Unicam Image\", unicam_->getEntityByName(\"unicam-image\"));\n+\tdata->unicam_[Unicam::Embedded] = RPi::RPiStream(\"Unicam Embedded\", unicam_->getEntityByName(\"unicam-embedded\"));\n+\tdata->unicam_[Unicam::Image] = RPi::RPiStream(\"Unicam Image\", unicam_->getEntityByName(\"unicam-image\"));\n \n \t/* Tag the ISP input stream as an import stream. */\n-\tdata->isp_[Isp::Input] = RPiStream(\"ISP Input\", isp_->getEntityByName(\"bcm2835-isp0-output0\"), true);\n-\tdata->isp_[Isp::Output0] = RPiStream(\"ISP Output0\", isp_->getEntityByName(\"bcm2835-isp0-capture1\"));\n-\tdata->isp_[Isp::Output1] = RPiStream(\"ISP Output1\", isp_->getEntityByName(\"bcm2835-isp0-capture2\"));\n-\tdata->isp_[Isp::Stats] = RPiStream(\"ISP Stats\", isp_->getEntityByName(\"bcm2835-isp0-capture3\"));\n+\tdata->isp_[Isp::Input] = RPi::RPiStream(\"ISP Input\", isp_->getEntityByName(\"bcm2835-isp0-output0\"), true);\n+\tdata->isp_[Isp::Output0] = RPi::RPiStream(\"ISP Output0\", isp_->getEntityByName(\"bcm2835-isp0-capture1\"));\n+\tdata->isp_[Isp::Output1] = RPi::RPiStream(\"ISP Output1\", isp_->getEntityByName(\"bcm2835-isp0-capture2\"));\n+\tdata->isp_[Isp::Stats] = RPi::RPiStream(\"ISP Stats\", isp_->getEntityByName(\"bcm2835-isp0-capture3\"));\n \n \t/* This is just for convenience so that we can easily iterate over all streams. */\n \tfor (auto &stream : data->unicam_)\n@@ -1005,7 +850,7 @@ int PipelineHandlerRPi::prepareBuffers(Camera *camera)\n \t */\n \tunsigned int maxBuffers = 0;\n \tfor (const Stream *s : camera->streams())\n-\t\tif (static_cast<const RPiStream *>(s)->isExternal())\n+\t\tif (static_cast<const RPi::RPiStream *>(s)->isExternal())\n \t\t\tmaxBuffers = std::max(maxBuffers, s->configuration().bufferCount);\n \n \tfor (auto const stream : data->streams_) {\n@@ -1255,12 +1100,12 @@ done:\n \n void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer)\n {\n-\tconst RPiStream *stream = nullptr;\n+\tconst RPi::RPiStream *stream = nullptr;\n \n \tif (state_ == State::Stopped)\n \t\treturn;\n \n-\tfor (RPiStream const &s : unicam_) {\n+\tfor (RPi::RPiStream const &s : unicam_) {\n \t\tif (s.findFrameBuffer(buffer)) {\n \t\t\tstream = &s;\n \t\t\tbreak;\n@@ -1316,12 +1161,12 @@ void RPiCameraData::ispInputDequeue(FrameBuffer *buffer)\n \n void RPiCameraData::ispOutputDequeue(FrameBuffer *buffer)\n {\n-\tconst RPiStream *stream = nullptr;\n+\tconst RPi::RPiStream *stream = nullptr;\n \n \tif (state_ == State::Stopped)\n \t\treturn;\n \n-\tfor (RPiStream const &s : isp_) {\n+\tfor (RPi::RPiStream const &s : isp_) {\n \t\tif (s.findFrameBuffer(buffer)) {\n \t\t\tstream = &s;\n \t\t\tbreak;\n@@ -1402,7 +1247,7 @@ void RPiCameraData::clearIncompleteRequests()\n \t}\n }\n \n-void RPiCameraData::handleStreamBuffer(FrameBuffer *buffer, const RPiStream *stream)\n+void RPiCameraData::handleStreamBuffer(FrameBuffer *buffer, const RPi::RPiStream *stream)\n {\n \tif (stream->isExternal()) {\n \t\tif (!dropFrame_) {\ndiff --git a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\nnew file mode 100644\nindex 00000000..2e52bd5c\n--- /dev/null\n+++ b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n@@ -0,0 +1,116 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2020, Raspberry Pi (Trading) Ltd.\n+ *\n+ * rpi_stream.cpp - Raspberry Pi device stream abstraction class.\n+ */\n+#include \"rpi_stream.h\"\n+\n+#include \"libcamera/internal/log.h\"\n+\n+namespace libcamera {\n+\n+LOG_DEFINE_CATEGORY(RPISTREAM)\n+\n+namespace RPi {\n+\n+V4L2VideoDevice *RPiStream::dev() const\n+{\n+\treturn dev_.get();\n+}\n+\n+std::string RPiStream::name() const\n+{\n+\treturn name_;\n+}\n+\n+void RPiStream::reset()\n+{\n+\texternal_ = false;\n+\tinternalBuffers_.clear();\n+}\n+\n+bool RPiStream::isImporter() const\n+{\n+\treturn importOnly_;\n+}\n+\n+void RPiStream::setExternal(bool external)\n+{\n+\texternal_ = external;\n+}\n+\n+bool RPiStream::isExternal() const\n+{\n+\t/*\n+\t * Import streams cannot be external.\n+\t *\n+\t * RAW capture is a special case where we simply copy the RAW\n+\t * buffer out of the request. All other buffer handling happens\n+\t * as if the stream is internal.\n+\t */\n+\treturn external_ && !importOnly_;\n+}\n+\n+void RPiStream::setExternalBuffers(std::vector<std::unique_ptr<FrameBuffer>> *buffers)\n+{\n+\texternalBuffers_ = buffers;\n+}\n+\n+const std::vector<std::unique_ptr<FrameBuffer>> *RPiStream::getBuffers() const\n+{\n+\treturn external_ ? externalBuffers_ : &internalBuffers_;\n+}\n+\n+bool RPiStream::findFrameBuffer(FrameBuffer *buffer) const\n+{\n+\tauto start = external_ ? externalBuffers_->begin() : internalBuffers_.begin();\n+\tauto end = external_ ? externalBuffers_->end() : internalBuffers_.end();\n+\n+\tif (importOnly_)\n+\t\treturn false;\n+\n+\tif (std::find_if(start, end,\n+\t\t\t [buffer](std::unique_ptr<FrameBuffer> const &ref) { return ref.get() == buffer; }) != end)\n+\t\treturn true;\n+\n+\treturn false;\n+}\n+\n+int RPiStream::importBuffers(unsigned int count)\n+{\n+\treturn dev_->importBuffers(count);\n+}\n+\n+int RPiStream::allocateBuffers(unsigned int count)\n+{\n+\treturn dev_->allocateBuffers(count, &internalBuffers_);\n+}\n+\n+int RPiStream::queueBuffers()\n+{\n+\tif (external_)\n+\t\treturn 0;\n+\n+\tfor (auto &b : internalBuffers_) {\n+\t\tint ret = dev_->queueBuffer(b.get());\n+\t\tif (ret) {\n+\t\t\tLOG(RPISTREAM, Error) << \"Failed to queue buffers for \"\n+\t\t\t\t\t      << name_;\n+\t\t\treturn ret;\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+}\n+\n+void RPiStream::releaseBuffers()\n+{\n+\tdev_->releaseBuffers();\n+\tif (!external_ && !importOnly_)\n+\t\tinternalBuffers_.clear();\n+}\n+\n+} /* namespace RPi */\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/pipeline/raspberrypi/rpi_stream.h b/src/libcamera/pipeline/raspberrypi/rpi_stream.h\nnew file mode 100644\nindex 00000000..8fcf522b\n--- /dev/null\n+++ b/src/libcamera/pipeline/raspberrypi/rpi_stream.h\n@@ -0,0 +1,107 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2020, Raspberry Pi (Trading) Ltd.\n+ *\n+ * rpi_stream.h - Raspberry Pi device stream abstraction class.\n+ */\n+#ifndef __LIBCAMERA_PIPELINE_RPI_STREAM_H__\n+#define __LIBCAMERA_PIPELINE_RPI_STREAM_H__\n+\n+#include <queue>\n+#include <string>\n+#include <vector>\n+\n+#include <libcamera/stream.h>\n+\n+#include \"libcamera/internal/v4l2_videodevice.h\"\n+\n+namespace libcamera {\n+\n+namespace RPi {\n+\n+/*\n+ * Device stream abstraction for either an internal or external stream.\n+ * Used for both Unicam and the ISP.\n+ */\n+class RPiStream : public Stream\n+{\n+public:\n+\tRPiStream()\n+\t{\n+\t}\n+\n+\tRPiStream(const char *name, MediaEntity *dev, bool importOnly = false)\n+\t\t: external_(false), importOnly_(importOnly), name_(name),\n+\t\t  dev_(std::make_unique<V4L2VideoDevice>(dev))\n+\t{\n+\t}\n+\n+\tV4L2VideoDevice *dev() const;\n+\tstd::string name() const;\n+\tbool isImporter() const;\n+\tvoid reset();\n+\n+\tvoid setExternal(bool external);\n+\tbool isExternal() const;\n+\n+\tvoid setExternalBuffers(std::vector<std::unique_ptr<FrameBuffer>> *buffers);\n+\tconst std::vector<std::unique_ptr<FrameBuffer>> *getBuffers() const;\n+\tbool findFrameBuffer(FrameBuffer *buffer) const;\n+\n+\tint importBuffers(unsigned int count);\n+\tint allocateBuffers(unsigned int count);\n+\n+\tint queueBuffers();\n+\tvoid releaseBuffers();\n+\n+private:\n+\t/*\n+\t * Indicates that this stream is active externally, i.e. the buffers\n+\t * are provided by the application.\n+\t */\n+\tbool external_;\n+\n+\t/* Indicates that this stream only imports buffers, e.g. ISP input. */\n+\tbool importOnly_;\n+\n+\t/* Stream name identifier. */\n+\tstd::string name_;\n+\n+\t/* The actual device stream. */\n+\tstd::unique_ptr<V4L2VideoDevice> dev_;\n+\n+\t/* Internally allocated framebuffers associated with this device stream. */\n+\tstd::vector<std::unique_ptr<FrameBuffer>> internalBuffers_;\n+\n+\t/* Externally allocated framebuffers associated with this device stream. */\n+\tstd::vector<std::unique_ptr<FrameBuffer>> *externalBuffers_;\n+};\n+\n+/*\n+ * The following class is just a convenient (and typesafe) array of device\n+ * streams indexed with an enum class.\n+ */\n+template<typename E, std::size_t N>\n+class RPiDevice : public std::array<class RPiStream, N>\n+{\n+private:\n+\tconstexpr auto index(E e) const noexcept\n+\t{\n+\t\treturn static_cast<std::underlying_type_t<E>>(e);\n+\t}\n+public:\n+\tRPiStream &operator[](E e)\n+\t{\n+\t\treturn std::array<class RPiStream, N>::operator[](index(e));\n+\t}\n+\tconst RPiStream &operator[](E e) const\n+\t{\n+\t\treturn std::array<class RPiStream, N>::operator[](index(e));\n+\t}\n+};\n+\n+} /* namespace RPi */\n+\n+} /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_PIPELINE_RPI_STREAM_H__ */\n",
    "prefixes": [
        "libcamera-devel",
        "v5",
        "01/10"
    ]
}