From patchwork Wed Mar 20 16:30:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 750 Return-Path: Received: from relay12.mail.gandi.net (relay12.mail.gandi.net [217.70.178.232]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 935746110E for ; Wed, 20 Mar 2019 17:30:30 +0100 (CET) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay12.mail.gandi.net (Postfix) with ESMTPSA id 2F0EB200009; Wed, 20 Mar 2019 16:30:30 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 20 Mar 2019 17:30:28 +0100 Message-Id: <20190320163055.22056-5-jacopo@jmondi.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190320163055.22056-1-jacopo@jmondi.org> References: <20190320163055.22056-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 04/31] libcamera: ipu3: Set stream configuration from sensor X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Mar 2019 16:30:30 -0000 Inspect all image sizes provided by the sensor and select the biggest of them, associated with an image format code supported by the CIO2 unit. Signed-off-by: Jacopo Mondi --- src/libcamera/pipeline/ipu3/ipu3.cpp | 47 +++++++++++++++++++--------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 2602f89617a3..1df074553fd1 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -5,6 +5,7 @@ * ipu3.cpp - Pipeline handler for Intel IPU3 */ +#include #include #include @@ -74,6 +75,8 @@ private: Stream stream_; }; + static constexpr unsigned int IPU3_BUFFER_COUNT = 4; + IPU3CameraData *cameraData(const Camera *camera) { return static_cast( @@ -106,26 +109,40 @@ std::map PipelineHandlerIPU3::streamConfiguration(Camera *camera, std::set &streams) { - IPU3CameraData *data = cameraData(camera); std::map configs; - V4L2SubdeviceFormat format = {}; + IPU3CameraData *data = cameraData(camera); + V4L2Subdevice *sensor = data->sensor_; + StreamConfiguration *config = &configs[&data->stream_]; + unsigned int bestSize = 0; - /* - * FIXME: As of now, return the image format reported by the sensor. - * In future good defaults should be provided for each stream. - */ - if (data->sensor_->getFormat(0, &format)) { - LOG(IPU3, Error) << "Failed to create stream configurations"; - return configs; + const FormatEnum formats = sensor->formats(0); + for (auto it = formats.begin(); it != formats.end(); ++it) { + int cio2Code = mediaBusToCIO2Format(it->first); + if (cio2Code == -EINVAL) + continue; + + for (const SizeRange &range : it->second) { + unsigned int frameSize = range.maxWidth + * range.maxHeight; + + /* Use the largest image size the sensor provides. */ + if (frameSize < bestSize) + continue; + + bestSize = frameSize; + + config->width = range.maxWidth; + config->height = range.maxHeight; + config->pixelFormat = cio2Code; + } } - StreamConfiguration config = {}; - config.width = format.width; - config.height = format.height; - config.pixelFormat = V4L2_PIX_FMT_IPU3_SGRBG10; - config.bufferCount = 4; + config->bufferCount = IPU3_BUFFER_COUNT; - configs[&data->stream_] = config; + LOG(IPU3, Debug) + << "Stream format set to: " << config->width << "x" + << config->height << "- 0x" << std::hex << std::setfill('0') + << std::setw(4) << config->pixelFormat; return configs; }