[{"id":26942,"web_url":"https://patchwork.libcamera.org/comment/26942/","msgid":"<i4tmxigzamxylum56wo7v53uvms4zpd2hjkyj2yqaagkejmoai@xx44veaarqba>","date":"2023-04-26T16:24:13","subject":"Re: [libcamera-devel] [PATCH 12/13] pipeline: raspberrypi: Add\n\tstream flags to RPi::Stream","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi Naush\n\nOn Wed, Apr 26, 2023 at 02:10:56PM +0100, Naushir Patuck via libcamera-devel wrote:\n> Add a flags_ field to indicate stream state information in RPi::Stream.\n> This replaces the existing external_ and importOnly_ boolean flags.\n>\n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> ---\n>  .../pipeline/rpi/common/pipeline_base.cpp     |  8 ++--\n>  .../pipeline/rpi/common/rpi_stream.cpp        | 40 ++++++++++--------\n>  .../pipeline/rpi/common/rpi_stream.h          | 42 ++++++++++++-------\n>  src/libcamera/pipeline/rpi/vc4/vc4.cpp        |  8 ++--\n>  4 files changed, 60 insertions(+), 38 deletions(-)\n>\n> diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> index 012766b38c32..4d38d511c383 100644\n> --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> @@ -31,6 +31,8 @@ using namespace RPi;\n>\n>  LOG_DEFINE_CATEGORY(RPI)\n>\n> +using Flag = RPi::Stream::StreamFlag;\n> +\n\nThe only doubt I have is about \"Flag\" not being better expressed as\n\"StreamFlags\" in the two 'using' directives in this patch.\n\nThe rest looks good\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n\nThanks\n  j\n\n>  namespace {\n>\n>  constexpr unsigned int defaultRawBitDepth = 12;\n> @@ -504,7 +506,7 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config)\n>  \t/* Start by freeing all buffers and reset the stream states. */\n>  \tdata->freeBuffers();\n>  \tfor (auto const stream : data->streams_)\n> -\t\tstream->setExternal(false);\n> +\t\tstream->clearFlags(Flag::External);\n>\n>  \tstd::vector<CameraData::StreamParams> rawStreams, ispStreams;\n>  \tstd::optional<BayerFormat::Packing> packing;\n> @@ -752,7 +754,7 @@ int PipelineHandlerBase::queueRequestDevice(Camera *camera, Request *request)\n>\n>  \t/* Push all buffers supplied in the Request to the respective streams. */\n>  \tfor (auto stream : data->streams_) {\n> -\t\tif (!stream->isExternal())\n> +\t\tif (!(stream->getFlags() & Flag::External))\n>  \t\t\tcontinue;\n>\n>  \t\tFrameBuffer *buffer = request->findBuffer(stream);\n> @@ -931,7 +933,7 @@ int PipelineHandlerBase::queueAllBuffers(Camera *camera)\n>  \tint ret;\n>\n>  \tfor (auto const stream : data->streams_) {\n> -\t\tif (!stream->isExternal()) {\n> +\t\tif (!(stream->getFlags() & Flag::External)) {\n>  \t\t\tret = stream->queueAllBuffers();\n>  \t\t\tif (ret < 0)\n>  \t\t\t\treturn ret;\n> diff --git a/src/libcamera/pipeline/rpi/common/rpi_stream.cpp b/src/libcamera/pipeline/rpi/common/rpi_stream.cpp\n> index b7e4130f5e56..c158843cb0ed 100644\n> --- a/src/libcamera/pipeline/rpi/common/rpi_stream.cpp\n> +++ b/src/libcamera/pipeline/rpi/common/rpi_stream.cpp\n> @@ -14,6 +14,24 @@ LOG_DEFINE_CATEGORY(RPISTREAM)\n>\n>  namespace RPi {\n>\n> +void Stream::setFlags(StreamFlags flags)\n> +{\n> +\tflags_ |= flags;\n> +\n> +\t/* Import streams cannot be external. */\n> +\tASSERT(!(flags_ & StreamFlag::External) || !(flags_ & StreamFlag::ImportOnly));\n> +}\n> +\n> +void Stream::clearFlags(StreamFlags flags)\n> +{\n> +\tflags_ &= ~flags;\n> +}\n> +\n> +RPi::Stream::StreamFlags Stream::getFlags() const\n> +{\n> +\treturn flags_;\n> +}\n> +\n>  V4L2VideoDevice *Stream::dev() const\n>  {\n>  \treturn dev_.get();\n> @@ -32,18 +50,6 @@ void Stream::resetBuffers()\n>  \t\tavailableBuffers_.push(buffer.get());\n>  }\n>\n> -void Stream::setExternal(bool external)\n> -{\n> -\t/* Import streams cannot be external. */\n> -\tASSERT(!external || !importOnly_);\n> -\texternal_ = external;\n> -}\n> -\n> -bool Stream::isExternal() const\n> -{\n> -\treturn external_;\n> -}\n> -\n>  void Stream::setExportedBuffers(std::vector<std::unique_ptr<FrameBuffer>> *buffers)\n>  {\n>  \tfor (auto const &buffer : *buffers)\n> @@ -57,7 +63,7 @@ const BufferMap &Stream::getBuffers() const\n>\n>  unsigned int Stream::getBufferId(FrameBuffer *buffer) const\n>  {\n> -\tif (importOnly_)\n> +\tif (flags_ & StreamFlag::ImportOnly)\n>  \t\treturn 0;\n>\n>  \t/* Find the buffer in the map, and return the buffer id. */\n> @@ -88,7 +94,7 @@ int Stream::prepareBuffers(unsigned int count)\n>  {\n>  \tint ret;\n>\n> -\tif (!importOnly_) {\n> +\tif (!(flags_ & StreamFlag::ImportOnly)) {\n>  \t\tif (count) {\n>  \t\t\t/* Export some frame buffers for internal use. */\n>  \t\t\tret = dev_->exportBuffers(count, &internalBuffers_);\n> @@ -113,7 +119,7 @@ int Stream::prepareBuffers(unsigned int count)\n>  \t * \\todo Find a better heuristic, or, even better, an exact solution to\n>  \t * this issue.\n>  \t */\n> -\tif (isExternal() || importOnly_)\n> +\tif ((flags_ & StreamFlag::External) || (flags_ & StreamFlag::ImportOnly))\n>  \t\tcount = count * 2;\n>\n>  \treturn dev_->importBuffers(count);\n> @@ -160,7 +166,7 @@ int Stream::queueBuffer(FrameBuffer *buffer)\n>\n>  void Stream::returnBuffer(FrameBuffer *buffer)\n>  {\n> -\tif (!external_) {\n> +\tif (!(flags_ & StreamFlag::External)) {\n>  \t\t/* For internal buffers, simply requeue back to the device. */\n>  \t\tqueueToDevice(buffer);\n>  \t\treturn;\n> @@ -204,7 +210,7 @@ int Stream::queueAllBuffers()\n>  {\n>  \tint ret;\n>\n> -\tif (external_)\n> +\tif (flags_ & StreamFlag::External)\n>  \t\treturn 0;\n>\n>  \twhile (!availableBuffers_.empty()) {\n> diff --git a/src/libcamera/pipeline/rpi/common/rpi_stream.h b/src/libcamera/pipeline/rpi/common/rpi_stream.h\n> index b8c74de35863..6edd304bdfe2 100644\n> --- a/src/libcamera/pipeline/rpi/common/rpi_stream.h\n> +++ b/src/libcamera/pipeline/rpi/common/rpi_stream.h\n> @@ -12,6 +12,7 @@\n>  #include <unordered_map>\n>  #include <vector>\n>\n> +#include <libcamera/base/flags.h>\n>  #include <libcamera/stream.h>\n>\n>  #include \"libcamera/internal/v4l2_videodevice.h\"\n> @@ -37,25 +38,41 @@ enum BufferMask {\n>  class Stream : public libcamera::Stream\n>  {\n>  public:\n> +\tenum class StreamFlag {\n> +\t\tNone\t\t= 0,\n> +\t\t/*\n> +\t\t * Indicates that this stream only imports buffers, e.g. the ISP\n> +\t\t * input stream.\n> +\t\t */\n> +\t\tImportOnly\t= (1 << 0),\n> +\t\t/*\n> +\t\t * Indicates that this stream is active externally, i.e. the\n> +\t\t * buffers might be provided by (and returned to) the application.\n> +\t\t */\n> +\t\tExternal\t= (1 << 1),\n> +\t};\n> +\n> +\tusing StreamFlags = Flags<StreamFlag>;\n> +\n>  \tStream()\n> -\t\t: id_(BufferMask::MaskID)\n> +\t\t: flags_(StreamFlag::None), id_(BufferMask::MaskID)\n>  \t{\n>  \t}\n>\n> -\tStream(const char *name, MediaEntity *dev, bool importOnly = false)\n> -\t\t: external_(false), importOnly_(importOnly), name_(name),\n> +\tStream(const char *name, MediaEntity *dev, StreamFlags flags = StreamFlag::None)\n> +\t\t: flags_(flags), name_(name),\n>  \t\t  dev_(std::make_unique<V4L2VideoDevice>(dev)), id_(BufferMask::MaskID)\n>  \t{\n>  \t}\n>\n> +\tvoid setFlags(StreamFlags flags);\n> +\tvoid clearFlags(StreamFlags flags);\n> +\tStreamFlags getFlags() const;\n> +\n>  \tV4L2VideoDevice *dev() const;\n>  \tconst std::string &name() const;\n> -\tbool isImporter() const;\n>  \tvoid resetBuffers();\n>\n> -\tvoid setExternal(bool external);\n> -\tbool isExternal() const;\n> -\n>  \tvoid setExportedBuffers(std::vector<std::unique_ptr<FrameBuffer>> *buffers);\n>  \tconst BufferMap &getBuffers() const;\n>  \tunsigned int getBufferId(FrameBuffer *buffer) const;\n> @@ -112,14 +129,7 @@ private:\n>  \tvoid clearBuffers();\n>  \tint queueToDevice(FrameBuffer *buffer);\n>\n> -\t/*\n> -\t * Indicates that this stream is active externally, i.e. the buffers\n> -\t * might be provided by (and returned to) 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> +\tStreamFlags flags_;\n>\n>  \t/* Stream name identifier. */\n>  \tstd::string name_;\n> @@ -182,4 +192,6 @@ public:\n>\n>  } /* namespace RPi */\n>\n> +LIBCAMERA_FLAGS_ENABLE_OPERATORS(RPi::Stream::StreamFlag)\n> +\n>  } /* namespace libcamera */\n> diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n> index a085a06376a8..bd7bfb3a7663 100644\n> --- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n> +++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n> @@ -23,6 +23,8 @@ namespace libcamera {\n>\n>  LOG_DECLARE_CATEGORY(RPI)\n>\n> +using Flag = RPi::Stream::StreamFlag;\n> +\n>  namespace {\n>\n>  enum class Unicam : unsigned int { Image, Embedded };\n> @@ -320,7 +322,7 @@ int PipelineHandlerVc4::platformRegister(std::unique_ptr<RPi::CameraData> &camer\n>  \t}\n>\n>  \t/* Tag the ISP input stream as an import stream. */\n> -\tdata->isp_[Isp::Input] = RPi::Stream(\"ISP Input\", ispOutput0, true);\n> +\tdata->isp_[Isp::Input] = RPi::Stream(\"ISP Input\", ispOutput0, Flag::ImportOnly);\n>  \tdata->isp_[Isp::Output0] = RPi::Stream(\"ISP Output0\", ispCapture1);\n>  \tdata->isp_[Isp::Output1] = RPi::Stream(\"ISP Output1\", ispCapture2);\n>  \tdata->isp_[Isp::Stats] = RPi::Stream(\"ISP Stats\", ispCapture3);\n> @@ -502,7 +504,7 @@ int Vc4CameraData::platformConfigure(const V4L2SubdeviceFormat &sensorFormat,\n>  \t */\n>  \tif (!rawStreams.empty()) {\n>  \t\trawStreams[0].cfg->setStream(&unicam_[Unicam::Image]);\n> -\t\tunicam_[Unicam::Image].setExternal(true);\n> +\t\tunicam_[Unicam::Image].setFlags(Flag::External);\n>  \t}\n>\n>  \tret = isp_[Isp::Input].dev()->setFormat(&unicamFormat);\n> @@ -547,7 +549,7 @@ int Vc4CameraData::platformConfigure(const V4L2SubdeviceFormat &sensorFormat,\n>  \t\t\t<< ColorSpace::toString(cfg->colorSpace);\n>\n>  \t\tcfg->setStream(stream);\n> -\t\tstream->setExternal(true);\n> +\t\tstream->setFlags(Flag::External);\n>  \t}\n>\n>  \tispOutputTotal_ = outStreams.size();\n> --\n> 2.34.1\n>","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 0FE56C3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 26 Apr 2023 16:24:19 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8912A627DC;\n\tWed, 26 Apr 2023 18:24:18 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BFA22627D4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 26 Apr 2023 18:24:16 +0200 (CEST)","from ideasonboard.com (93-61-96-190.ip145.fastwebnet.it\n\t[93.61.96.190])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 2ADDBD8B;\n\tWed, 26 Apr 2023 18:24:05 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1682526258;\n\tbh=peq0e29Q0XiEtizkUxnfixz5MA9dbgXD9MZ9cPHutpI=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=U/Nx8amfc0NHwnXM8lOf39EJ7BuCkvYUSi1gCKcnrzxBDkTPj40ZmvAaVpjtGJiUI\n\tCSZm/yGxrUoLIkHy27Ts46tzPujTiaOQh3wAitsnh5UDEx3wE0lYygCRiYBCa/GVI3\n\tU6oNDcFWiOj8/iztye/V10Zk444tuJPKj+UivYb+PndoZY5K62Eu6WyH+8av7FVmTl\n\tbaR2zJa8JXi9FXRUOjfyjWMyybD97UBOkSRW4dEZCSLZSWJ6Ld79U8qsYjDvTgMvT0\n\tucHwu8VXjMA7XsjFstFFMZ56hjh5F4kpiU/faiMwROLJl3tx3QC5GnZmbRqWlS4l5T\n\t6VFoZAyJZXgVQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1682526245;\n\tbh=peq0e29Q0XiEtizkUxnfixz5MA9dbgXD9MZ9cPHutpI=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=p4I/8032axFo1hYjPZ3kcpFZ1u6baQKHLJI+NyJzhgv2ZxmiGJ6iRCLn/7TVGqRHo\n\tp+YT6BfNrSMb1uofTvC42IaeBbaX2jJY4QfkGRCFOYmN0S9jKUMMaVfr5DPUr8PZ+p\n\tZo+AVF68Hme5wSzXTHIbX4f0HJatdTzbR+CmnVpg="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"p4I/8032\"; dkim-atps=neutral","Date":"Wed, 26 Apr 2023 18:24:13 +0200","To":"Naushir Patuck <naush@raspberrypi.com>","Message-ID":"<i4tmxigzamxylum56wo7v53uvms4zpd2hjkyj2yqaagkejmoai@xx44veaarqba>","References":"<20230426131057.21550-1-naush@raspberrypi.com>\n\t<20230426131057.21550-13-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20230426131057.21550-13-naush@raspberrypi.com>","Subject":"Re: [libcamera-devel] [PATCH 12/13] pipeline: raspberrypi: Add\n\tstream flags to RPi::Stream","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>","From":"Jacopo Mondi via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":26947,"web_url":"https://patchwork.libcamera.org/comment/26947/","msgid":"<CAEmqJPq_=HGuVGJJN4dBN277rLQZ2XQSTuK6R3vsigX2jMFeUg@mail.gmail.com>","date":"2023-04-27T06:53:56","subject":"Re: [libcamera-devel] [PATCH 12/13] pipeline: raspberrypi: Add\n\tstream flags to RPi::Stream","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"content":"Hi Jacopo,\n\nThank you for your feedback.\n\nOn Wed, 26 Apr 2023 at 17:24, Jacopo Mondi\n<jacopo.mondi@ideasonboard.com> wrote:\n>\n> Hi Naush\n>\n> On Wed, Apr 26, 2023 at 02:10:56PM +0100, Naushir Patuck via libcamera-devel wrote:\n> > Add a flags_ field to indicate stream state information in RPi::Stream.\n> > This replaces the existing external_ and importOnly_ boolean flags.\n> >\n> > Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> > ---\n> >  .../pipeline/rpi/common/pipeline_base.cpp     |  8 ++--\n> >  .../pipeline/rpi/common/rpi_stream.cpp        | 40 ++++++++++--------\n> >  .../pipeline/rpi/common/rpi_stream.h          | 42 ++++++++++++-------\n> >  src/libcamera/pipeline/rpi/vc4/vc4.cpp        |  8 ++--\n> >  4 files changed, 60 insertions(+), 38 deletions(-)\n> >\n> > diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > index 012766b38c32..4d38d511c383 100644\n> > --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > @@ -31,6 +31,8 @@ using namespace RPi;\n> >\n> >  LOG_DEFINE_CATEGORY(RPI)\n> >\n> > +using Flag = RPi::Stream::StreamFlag;\n> > +\n>\n> The only doubt I have is about \"Flag\" not being better expressed as\n> \"StreamFlags\" in the two 'using' directives in this patch.\n\nAck.  I'll change it to StreamFlag and reply-to this patch with the update.\n\nRegards,\nNaush\n\n\n>\n> The rest looks good\n> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n>\n> Thanks\n>   j\n>\n> >  namespace {\n> >\n> >  constexpr unsigned int defaultRawBitDepth = 12;\n> > @@ -504,7 +506,7 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config)\n> >       /* Start by freeing all buffers and reset the stream states. */\n> >       data->freeBuffers();\n> >       for (auto const stream : data->streams_)\n> > -             stream->setExternal(false);\n> > +             stream->clearFlags(Flag::External);\n> >\n> >       std::vector<CameraData::StreamParams> rawStreams, ispStreams;\n> >       std::optional<BayerFormat::Packing> packing;\n> > @@ -752,7 +754,7 @@ int PipelineHandlerBase::queueRequestDevice(Camera *camera, Request *request)\n> >\n> >       /* Push all buffers supplied in the Request to the respective streams. */\n> >       for (auto stream : data->streams_) {\n> > -             if (!stream->isExternal())\n> > +             if (!(stream->getFlags() & Flag::External))\n> >                       continue;\n> >\n> >               FrameBuffer *buffer = request->findBuffer(stream);\n> > @@ -931,7 +933,7 @@ int PipelineHandlerBase::queueAllBuffers(Camera *camera)\n> >       int ret;\n> >\n> >       for (auto const stream : data->streams_) {\n> > -             if (!stream->isExternal()) {\n> > +             if (!(stream->getFlags() & Flag::External)) {\n> >                       ret = stream->queueAllBuffers();\n> >                       if (ret < 0)\n> >                               return ret;\n> > diff --git a/src/libcamera/pipeline/rpi/common/rpi_stream.cpp b/src/libcamera/pipeline/rpi/common/rpi_stream.cpp\n> > index b7e4130f5e56..c158843cb0ed 100644\n> > --- a/src/libcamera/pipeline/rpi/common/rpi_stream.cpp\n> > +++ b/src/libcamera/pipeline/rpi/common/rpi_stream.cpp\n> > @@ -14,6 +14,24 @@ LOG_DEFINE_CATEGORY(RPISTREAM)\n> >\n> >  namespace RPi {\n> >\n> > +void Stream::setFlags(StreamFlags flags)\n> > +{\n> > +     flags_ |= flags;\n> > +\n> > +     /* Import streams cannot be external. */\n> > +     ASSERT(!(flags_ & StreamFlag::External) || !(flags_ & StreamFlag::ImportOnly));\n> > +}\n> > +\n> > +void Stream::clearFlags(StreamFlags flags)\n> > +{\n> > +     flags_ &= ~flags;\n> > +}\n> > +\n> > +RPi::Stream::StreamFlags Stream::getFlags() const\n> > +{\n> > +     return flags_;\n> > +}\n> > +\n> >  V4L2VideoDevice *Stream::dev() const\n> >  {\n> >       return dev_.get();\n> > @@ -32,18 +50,6 @@ void Stream::resetBuffers()\n> >               availableBuffers_.push(buffer.get());\n> >  }\n> >\n> > -void Stream::setExternal(bool external)\n> > -{\n> > -     /* Import streams cannot be external. */\n> > -     ASSERT(!external || !importOnly_);\n> > -     external_ = external;\n> > -}\n> > -\n> > -bool Stream::isExternal() const\n> > -{\n> > -     return external_;\n> > -}\n> > -\n> >  void Stream::setExportedBuffers(std::vector<std::unique_ptr<FrameBuffer>> *buffers)\n> >  {\n> >       for (auto const &buffer : *buffers)\n> > @@ -57,7 +63,7 @@ const BufferMap &Stream::getBuffers() const\n> >\n> >  unsigned int Stream::getBufferId(FrameBuffer *buffer) const\n> >  {\n> > -     if (importOnly_)\n> > +     if (flags_ & StreamFlag::ImportOnly)\n> >               return 0;\n> >\n> >       /* Find the buffer in the map, and return the buffer id. */\n> > @@ -88,7 +94,7 @@ int Stream::prepareBuffers(unsigned int count)\n> >  {\n> >       int ret;\n> >\n> > -     if (!importOnly_) {\n> > +     if (!(flags_ & StreamFlag::ImportOnly)) {\n> >               if (count) {\n> >                       /* Export some frame buffers for internal use. */\n> >                       ret = dev_->exportBuffers(count, &internalBuffers_);\n> > @@ -113,7 +119,7 @@ int Stream::prepareBuffers(unsigned int count)\n> >        * \\todo Find a better heuristic, or, even better, an exact solution to\n> >        * this issue.\n> >        */\n> > -     if (isExternal() || importOnly_)\n> > +     if ((flags_ & StreamFlag::External) || (flags_ & StreamFlag::ImportOnly))\n> >               count = count * 2;\n> >\n> >       return dev_->importBuffers(count);\n> > @@ -160,7 +166,7 @@ int Stream::queueBuffer(FrameBuffer *buffer)\n> >\n> >  void Stream::returnBuffer(FrameBuffer *buffer)\n> >  {\n> > -     if (!external_) {\n> > +     if (!(flags_ & StreamFlag::External)) {\n> >               /* For internal buffers, simply requeue back to the device. */\n> >               queueToDevice(buffer);\n> >               return;\n> > @@ -204,7 +210,7 @@ int Stream::queueAllBuffers()\n> >  {\n> >       int ret;\n> >\n> > -     if (external_)\n> > +     if (flags_ & StreamFlag::External)\n> >               return 0;\n> >\n> >       while (!availableBuffers_.empty()) {\n> > diff --git a/src/libcamera/pipeline/rpi/common/rpi_stream.h b/src/libcamera/pipeline/rpi/common/rpi_stream.h\n> > index b8c74de35863..6edd304bdfe2 100644\n> > --- a/src/libcamera/pipeline/rpi/common/rpi_stream.h\n> > +++ b/src/libcamera/pipeline/rpi/common/rpi_stream.h\n> > @@ -12,6 +12,7 @@\n> >  #include <unordered_map>\n> >  #include <vector>\n> >\n> > +#include <libcamera/base/flags.h>\n> >  #include <libcamera/stream.h>\n> >\n> >  #include \"libcamera/internal/v4l2_videodevice.h\"\n> > @@ -37,25 +38,41 @@ enum BufferMask {\n> >  class Stream : public libcamera::Stream\n> >  {\n> >  public:\n> > +     enum class StreamFlag {\n> > +             None            = 0,\n> > +             /*\n> > +              * Indicates that this stream only imports buffers, e.g. the ISP\n> > +              * input stream.\n> > +              */\n> > +             ImportOnly      = (1 << 0),\n> > +             /*\n> > +              * Indicates that this stream is active externally, i.e. the\n> > +              * buffers might be provided by (and returned to) the application.\n> > +              */\n> > +             External        = (1 << 1),\n> > +     };\n> > +\n> > +     using StreamFlags = Flags<StreamFlag>;\n> > +\n> >       Stream()\n> > -             : id_(BufferMask::MaskID)\n> > +             : flags_(StreamFlag::None), id_(BufferMask::MaskID)\n> >       {\n> >       }\n> >\n> > -     Stream(const char *name, MediaEntity *dev, bool importOnly = false)\n> > -             : external_(false), importOnly_(importOnly), name_(name),\n> > +     Stream(const char *name, MediaEntity *dev, StreamFlags flags = StreamFlag::None)\n> > +             : flags_(flags), name_(name),\n> >                 dev_(std::make_unique<V4L2VideoDevice>(dev)), id_(BufferMask::MaskID)\n> >       {\n> >       }\n> >\n> > +     void setFlags(StreamFlags flags);\n> > +     void clearFlags(StreamFlags flags);\n> > +     StreamFlags getFlags() const;\n> > +\n> >       V4L2VideoDevice *dev() const;\n> >       const std::string &name() const;\n> > -     bool isImporter() const;\n> >       void resetBuffers();\n> >\n> > -     void setExternal(bool external);\n> > -     bool isExternal() const;\n> > -\n> >       void setExportedBuffers(std::vector<std::unique_ptr<FrameBuffer>> *buffers);\n> >       const BufferMap &getBuffers() const;\n> >       unsigned int getBufferId(FrameBuffer *buffer) const;\n> > @@ -112,14 +129,7 @@ private:\n> >       void clearBuffers();\n> >       int queueToDevice(FrameBuffer *buffer);\n> >\n> > -     /*\n> > -      * Indicates that this stream is active externally, i.e. the buffers\n> > -      * might be provided by (and returned to) the application.\n> > -      */\n> > -     bool external_;\n> > -\n> > -     /* Indicates that this stream only imports buffers, e.g. ISP input. */\n> > -     bool importOnly_;\n> > +     StreamFlags flags_;\n> >\n> >       /* Stream name identifier. */\n> >       std::string name_;\n> > @@ -182,4 +192,6 @@ public:\n> >\n> >  } /* namespace RPi */\n> >\n> > +LIBCAMERA_FLAGS_ENABLE_OPERATORS(RPi::Stream::StreamFlag)\n> > +\n> >  } /* namespace libcamera */\n> > diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n> > index a085a06376a8..bd7bfb3a7663 100644\n> > --- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n> > +++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n> > @@ -23,6 +23,8 @@ namespace libcamera {\n> >\n> >  LOG_DECLARE_CATEGORY(RPI)\n> >\n> > +using Flag = RPi::Stream::StreamFlag;\n> > +\n> >  namespace {\n> >\n> >  enum class Unicam : unsigned int { Image, Embedded };\n> > @@ -320,7 +322,7 @@ int PipelineHandlerVc4::platformRegister(std::unique_ptr<RPi::CameraData> &camer\n> >       }\n> >\n> >       /* Tag the ISP input stream as an import stream. */\n> > -     data->isp_[Isp::Input] = RPi::Stream(\"ISP Input\", ispOutput0, true);\n> > +     data->isp_[Isp::Input] = RPi::Stream(\"ISP Input\", ispOutput0, Flag::ImportOnly);\n> >       data->isp_[Isp::Output0] = RPi::Stream(\"ISP Output0\", ispCapture1);\n> >       data->isp_[Isp::Output1] = RPi::Stream(\"ISP Output1\", ispCapture2);\n> >       data->isp_[Isp::Stats] = RPi::Stream(\"ISP Stats\", ispCapture3);\n> > @@ -502,7 +504,7 @@ int Vc4CameraData::platformConfigure(const V4L2SubdeviceFormat &sensorFormat,\n> >        */\n> >       if (!rawStreams.empty()) {\n> >               rawStreams[0].cfg->setStream(&unicam_[Unicam::Image]);\n> > -             unicam_[Unicam::Image].setExternal(true);\n> > +             unicam_[Unicam::Image].setFlags(Flag::External);\n> >       }\n> >\n> >       ret = isp_[Isp::Input].dev()->setFormat(&unicamFormat);\n> > @@ -547,7 +549,7 @@ int Vc4CameraData::platformConfigure(const V4L2SubdeviceFormat &sensorFormat,\n> >                       << ColorSpace::toString(cfg->colorSpace);\n> >\n> >               cfg->setStream(stream);\n> > -             stream->setExternal(true);\n> > +             stream->setFlags(Flag::External);\n> >       }\n> >\n> >       ispOutputTotal_ = outStreams.size();\n> > --\n> > 2.34.1\n> >","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 528D9BDCBD\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 27 Apr 2023 06:54:09 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 063C7627DF;\n\tThu, 27 Apr 2023 08:54:09 +0200 (CEST)","from mail-yw1-x1135.google.com (mail-yw1-x1135.google.com\n\t[IPv6:2607:f8b0:4864:20::1135])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D515B61EAF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 27 Apr 2023 08:54:07 +0200 (CEST)","by mail-yw1-x1135.google.com with SMTP id\n\t00721157ae682-555d2810415so116912587b3.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 26 Apr 2023 23:54:07 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1682578449;\n\tbh=L1+J24xQCOfzT4oTeRjRYwIJzhpr1m60t/M6UvUThwo=;\n\th=References:In-Reply-To:Date:To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=EDt2oDaNF2A5SyN7wWXTyVGZILtCvGBfhRDRoYzUgkf/0KBwNLFA7GB7ILNOGjMQv\n\tbZKPYK/GQ1KAl/0EXnqMQUOPFwaUjljMY7E7ML8Yjvi+Dg0jI0vvq/Y0jVcwcre7DO\n\tLEkz7G2guJHNw/hnz6F3Afwt4nt4aLHI4bn1vi6sYfj0TliTBEnJT7VimVxF+Dz8WJ\n\tuLsTZJ5Q3BuEl29PaNe02Q6thVOvYOIU8KGJfFN3csw+iJr2OLHObxuI8PBMjRTFgi\n\tFv60MbFVtcwrDFdqtd8jPQifuZBTdy64UePUPg8rkwL0NcffMO2VpGEKAbxauAeMes\n\tpGBnkjKhclMlA==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1682578447; x=1685170447;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:from:to:cc:subject:date:message-id:reply-to;\n\tbh=fRdzSpoQ5hSllzVxuaXJuhShXbWqD9OkrSnfg5RVgV0=;\n\tb=Xivna+OJaf5hEBuUnFYN10HHexStbmrcDLTG8wgaH/sTGUyBqeBqT2UEPCF4DZZAJF\n\tHcHw1aR7PBJqoD7T5Q3U7J3oclLRgOutldsWzlQOl4/EJoCzicTj3UpMwmMCCFs+KKeB\n\tuxInit1kPXhcvQW1OLW4u3o7EARsB6QDX022woGdPOlWbogPBBNqK8HmpdESAxj3RsLR\n\tnIDMQLy02UsHGT/jxy09rx1KhR5lvIjgQot282fzMIZEbhfJdS0IKk4OzIMhJC9mEEaM\n\t9TUe6vpOyOt+ixdI3tu3ohMSshWsd1YHefwbFCRbi2LySPPStkJPG2w1x5/ILwfn80+b\n\tvOLw=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"Xivna+OJ\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20221208; t=1682578447; x=1685170447;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=fRdzSpoQ5hSllzVxuaXJuhShXbWqD9OkrSnfg5RVgV0=;\n\tb=IlhvaOwejVgW9cjtLNcqSahP7gm0zcISgxAFsuYMV/bWfnLvnnYXVseBNXssj15wbI\n\ta8zMd6ot7DM6DSfZlN12uBh+ZckMixKVyQyDzkSz9UC1vZAKIHFJ+VvFp30E1y2/nSkL\n\trQlb4V3wKNDKvgo/9bGquMB3Vie/tNfohlwC1Zh06BNs0kQJ7R9Vw9wB6AKv3IBIucgE\n\tKC2IT7ch1upg6b5iZ2754hIRgBT69QArc0+06YyH/CsX5YsuxPlKY40/yirgUSLlUT3Q\n\to9wKXbcYR7ojrCd2Z1X6EXuMrorlyumEFLyzU8ju0fKmwnLODDxNDr3ZRA3v8DHgyfKg\n\tupOw==","X-Gm-Message-State":"AC+VfDw02ZHrWUCjG5P8LEK2WZNnCp5EHOll0Olz+AjypOdVA0CrjkhG\n\tuj3E8uRH+VW/uqItuyDESdt7SeicI37qQy88u5uWt0rV3xmvfSyvU1c=","X-Google-Smtp-Source":"ACHHUZ4Nmyn3LmsQZQwWMGBuGxdmj3dcKJ0fHDNNWAGSOX7ZFL0mVYnpk+ldbxbg9BErmwNPuvSPlQzgIWD7tJ2NGo0=","X-Received":"by 2002:a0d:ee81:0:b0:54f:b615:ab5d with SMTP id\n\tx123-20020a0dee81000000b0054fb615ab5dmr597192ywe.14.1682578446706;\n\tWed, 26 Apr 2023 23:54:06 -0700 (PDT)","MIME-Version":"1.0","References":"<20230426131057.21550-1-naush@raspberrypi.com>\n\t<20230426131057.21550-13-naush@raspberrypi.com>\n\t<i4tmxigzamxylum56wo7v53uvms4zpd2hjkyj2yqaagkejmoai@xx44veaarqba>","In-Reply-To":"<i4tmxigzamxylum56wo7v53uvms4zpd2hjkyj2yqaagkejmoai@xx44veaarqba>","Date":"Thu, 27 Apr 2023 07:53:56 +0100","Message-ID":"<CAEmqJPq_=HGuVGJJN4dBN277rLQZ2XQSTuK6R3vsigX2jMFeUg@mail.gmail.com>","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Subject":"Re: [libcamera-devel] [PATCH 12/13] pipeline: raspberrypi: Add\n\tstream flags to RPi::Stream","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>","From":"Naushir Patuck via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Naushir Patuck <naush@raspberrypi.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]