{"id":3893,"url":"https://patchwork.libcamera.org/api/1.1/patches/3893/?format=json","web_url":"https://patchwork.libcamera.org/patch/3893/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200602013909.3170593-5-niklas.soderlund@ragnatech.se>","date":"2020-06-02T01:39:03","name":"[libcamera-devel,04/10] libcamera: ipu3: Breakout stream assignment to new function","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"f0d26457eca22d1d3e5e0926fff05d17d902491d","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/1.1/people/5/?format=json","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/3893/mbox/","series":[{"id":943,"url":"https://patchwork.libcamera.org/api/1.1/series/943/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=943","date":"2020-06-02T01:38:59","name":"libcamera: ipu3: Allow zero-copy RAW stream","version":1,"mbox":"https://patchwork.libcamera.org/series/943/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/3893/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/3893/checks/","tags":{},"headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net\n\t[195.74.38.227])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EEE8861012\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  2 Jun 2020 03:39:29 +0200 (CEST)","from bismarck.berto.se (p4fca2392.dip0.t-ipconnect.de\n\t[79.202.35.146]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA\n\tid d519e034-a471-11ea-a73e-0050569116f7;\n\tTue, 02 Jun 2020 03:39:00 +0200 (CEST)"],"X-Halon-ID":"d519e034-a471-11ea-a73e-0050569116f7","Authorized-sender":"niklas@soderlund.pp.se","From":"=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue,  2 Jun 2020 03:39:03 +0200","Message-Id":"<20200602013909.3170593-5-niklas.soderlund@ragnatech.se>","X-Mailer":"git-send-email 2.26.2","In-Reply-To":"<20200602013909.3170593-1-niklas.soderlund@ragnatech.se>","References":"<20200602013909.3170593-1-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 04/10] libcamera: ipu3: Breakout stream\n\tassignment to new function","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>","X-List-Received-Date":"Tue, 02 Jun 2020 01:39:30 -0000"},"content":"Picking which stream that is most suitable for the requested\nconfiguration is mixed with adjusting the requested format when\nvalidating configurations. This is hard to read and got worse when\nsupport for Bayer formats where added, break it out into a separate\nfunction.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n src/libcamera/pipeline/ipu3/ipu3.cpp | 87 +++++++++++++++++-----------\n 1 file changed, 53 insertions(+), 34 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex f7363244e1d2d0ff..0e7555c716b36749 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -190,6 +190,7 @@ private:\n \tstatic constexpr unsigned int IPU3_BUFFER_COUNT = 4;\n \tstatic constexpr unsigned int IPU3_MAX_STREAMS = 3;\n \n+\tint updateStreams();\n \tvoid adjustStream(StreamConfiguration &cfg, bool scale);\n \n \t/*\n@@ -256,6 +257,51 @@ IPU3CameraConfiguration::IPU3CameraConfiguration(Camera *camera,\n \tdata_ = data;\n }\n \n+int IPU3CameraConfiguration::updateStreams()\n+{\n+\tstd::set<const IPU3Stream *> availableStreams = {\n+\t\t&data_->outStream_,\n+\t\t&data_->vfStream_,\n+\t\t&data_->rawStream_,\n+\t};\n+\n+\t/* Pick the stream most suitable for the requested configuration. */\n+\tstd::vector<const IPU3Stream *> streams;\n+\tfor (unsigned int i = 0; i < config_.size(); ++i) {\n+\t\tconst StreamConfiguration &cfg = config_[i];\n+\t\tconst IPU3Stream *stream;\n+\n+\t\t/*\n+\t\t * Only the raw stream can support Bayer formats.\n+\t\t */\n+\t\tif (cfg.pixelFormat.modifier() == IPU3_FORMAT_MOD_PACKED)\n+\t\t\tstream = &data_->rawStream_;\n+\t\t/*\n+\t\t * Output stream can't scale so can only be used if the size\n+\t\t * matches the size of the sensor.\n+\t\t *\n+\t\t * NOTE: It can crop but is not supported.\n+\t\t */\n+\t\telse if (cfg.size == sensorFormat_.size)\n+\t\t\tstream = &data_->outStream_;\n+\t\t/*\n+\t\t * Pick the view finder stream last as it may scale.\n+\t\t */\n+\t\telse\n+\t\t\tstream = &data_->vfStream_;\n+\n+\t\tif (availableStreams.find(stream) == availableStreams.end())\n+\t\t\treturn -EINVAL;\n+\n+\t\tstreams.push_back(stream);\n+\t\tavailableStreams.erase(stream);\n+\t}\n+\n+\tstreams_ = streams;\n+\n+\treturn 0;\n+}\n+\n void IPU3CameraConfiguration::adjustStream(StreamConfiguration &cfg, bool scale)\n {\n \t/* The only pixel format the driver supports is NV12. */\n@@ -342,40 +388,16 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate()\n \tif (!sensorFormat_.size.width || !sensorFormat_.size.height)\n \t\tsensorFormat_.size = sensor->resolution();\n \n-\t/*\n-\t * Verify and update all configuration entries, and assign a stream to\n-\t * each of them. The viewfinder stream can scale, while the output\n-\t * stream can crop only, so select the output stream when the requested\n-\t * resolution is equal to the sensor resolution, and the viewfinder\n-\t * stream otherwise.\n-\t */\n-\tstd::set<const IPU3Stream *> availableStreams = {\n-\t\t&data_->outStream_,\n-\t\t&data_->vfStream_,\n-\t\t&data_->rawStream_,\n-\t};\n \n-\tstreams_.clear();\n-\tstreams_.reserve(config_.size());\n+\t/* Assign streams to each configuration entry. */\n+\tif (updateStreams())\n+\t\treturn Invalid;\n \n+\t/* Verify and adjust configuration if needed. */\n \tfor (unsigned int i = 0; i < config_.size(); ++i) {\n \t\tStreamConfiguration &cfg = config_[i];\n-\t\tconst PixelFormat pixelFormat = cfg.pixelFormat;\n-\t\tconst Size size = cfg.size;\n-\t\tconst IPU3Stream *stream;\n-\n-\t\tif (cfg.pixelFormat.modifier() == IPU3_FORMAT_MOD_PACKED)\n-\t\t\tstream = &data_->rawStream_;\n-\t\telse if (cfg.size == sensorFormat_.size)\n-\t\t\tstream = &data_->outStream_;\n-\t\telse\n-\t\t\tstream = &data_->vfStream_;\n-\n-\t\tif (availableStreams.find(stream) == availableStreams.end())\n-\t\t\tstream = *availableStreams.begin();\n-\n-\t\tLOG(IPU3, Debug)\n-\t\t\t<< \"Assigned '\" << stream->name_ << \"' to stream \" << i;\n+\t\tconst StreamConfiguration org = cfg;\n+\t\tconst IPU3Stream *stream = streams_[i];\n \n \t\tif (stream->raw_) {\n \t\t\tconst auto &itFormat =\n@@ -392,15 +414,12 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate()\n \n \t\tcfg.bufferCount = IPU3_BUFFER_COUNT;\n \n-\t\tif (cfg.pixelFormat != pixelFormat || cfg.size != size) {\n+\t\tif (cfg.pixelFormat != org.pixelFormat || cfg.size != org.size) {\n \t\t\tLOG(IPU3, Debug)\n \t\t\t\t<< \"Stream \" << i << \" configuration adjusted to \"\n \t\t\t\t<< cfg.toString();\n \t\t\tstatus = Adjusted;\n \t\t}\n-\n-\t\tstreams_.push_back(stream);\n-\t\tavailableStreams.erase(stream);\n \t}\n \n \treturn status;\n","prefixes":["libcamera-devel","04/10"]}