From patchwork Thu Feb 28 20:04:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 680 Return-Path: Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B8E64610BA for ; Thu, 28 Feb 2019 21:03:47 +0100 (CET) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 4FDC3E0005; Thu, 28 Feb 2019 20:03:47 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Feb 2019 21:04:02 +0100 Message-Id: <20190228200410.3022-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190228200410.3022-1-jacopo@jmondi.org> References: <20190228200410.3022-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 02/10] libcamera: ipu3: Get default image sizes 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: Thu, 28 Feb 2019 20:03:47 -0000 Inspect all image sizes provided by the sensor and select the biggest one to be returned as default stream configuration instead of returning the currently applied one. Hardcode the stream pixel format to the one produced by the CIO2 unit, to be changed to the one provided by the ImgU. Signed-off-by: Jacopo Mondi --- src/libcamera/pipeline/ipu3/ipu3.cpp | 44 ++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index d3f1d9a95f81..4f1ab72debf8 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -71,6 +71,8 @@ public: bool match(DeviceEnumerator *enumerator); private: + static constexpr unsigned int IPU3_BUF_NUM = 4; + IPU3CameraData *cameraData(const Camera *camera) { return static_cast( @@ -102,27 +104,45 @@ std::map PipelineHandlerIPU3::streamConfiguration(Camera *camera, std::vector &streams) { + std::map> formats; std::map configs; IPU3CameraData *data = cameraData(camera); V4L2Subdevice *sensor = data->cio2.sensor; - V4L2SubdeviceFormat format = {}; + StreamConfiguration *config = &configs[&data->stream_]; + + config->pixelFormat = V4L2_PIX_FMT_IPU3_SGRBG10; + config->bufferCount = IPU3_BUF_NUM; /* - * FIXME: As of now, return the image format reported by the sensor. - * In future good defaults should be provided for each stream. + * Use the largest image size the sensor provides or + * use a default one. */ - if (sensor->getFormat(0, &format)) { - LOG(IPU3, Error) << "Failed to create stream configurations"; - return configs; + formats = sensor->formats(0); + if (formats.empty()) { + config->width = 1920; + config->height = 1080; + LOG(IPU3, Info) + << "Use default stream sizes " << config->width + << "x" << config->height; } - StreamConfiguration config = {}; - config.width = format.width; - config.height = format.height; - config.pixelFormat = V4L2_PIX_FMT_IPU3_SGRBG10; - config.bufferCount = 4; + auto it = formats.begin(); + while (it != formats.end()) { + for (SizeRange &range : it->second) { + if (range.maxWidth <= config->width || + range.maxHeight <= config->height) + continue; + + config->width = range.maxWidth; + config->height = range.maxHeight; + } + + ++it; + } - configs[&data->stream_] = config; + LOG(IPU3, Info) << "Stream format set to = (" << config->width << "x" + << config->height << ") - 0x" << std::hex + << config->pixelFormat; return configs; }