From patchwork Thu Jul 9 13:28:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 8728 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 988BFBD792 for ; Thu, 9 Jul 2020 13:29:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6666E61218; Thu, 9 Jul 2020 15:29:22 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="TECbZkSH"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 100C661243 for ; Thu, 9 Jul 2020 15:29:21 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8AA56525; Thu, 9 Jul 2020 15:29:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594301360; bh=EXuaUjfqdW0vH+xE8/bLlGW5Wr9ixh4D3YtVQ3EAfZ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TECbZkSH2rHTxOYTnqIeWsUskswUCR6t9EOInpAbk1nOsbbRrvMWElPYLiOpyEfrz zyhE9SVxYuQxsckYRve4MxHLKRBXIrA7/JhNlNKlRZbK9k4VOKiEbMLp5ljW9zS+aI 6+uP6rgx69/HISoxon7yKWrN8AVOFDjMs+wVpyNE= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Thu, 9 Jul 2020 22:28:25 +0900 Message-Id: <20200709132835.112593-14-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200709132835.112593-1-paul.elder@ideasonboard.com> References: <20200709132835.112593-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 13/23] libcamera: raspberrypi: Fill stride and frameSize at config validation X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Fill the stride and frameSize fields of the StreamConfiguration at configuration validation time instead of at camera configuration time. This allows applications to get the stride when trying a configuration without modifying the active configuration of the camera. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart Reviewed-by: Naushir Patuck --- Changes in v5: - clean up code a bit - move setting default size and width into separate patch Changes in v4: - mention motivation in commit message - also fill stride and frameSize in the default format New in v3 --- .../pipeline/raspberrypi/raspberrypi.cpp | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 1822ac9..a08ad6a 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -427,6 +427,10 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() */ V4L2PixFmtMap fmts = data_->unicam_[Unicam::Image].dev()->formats(); V4L2DeviceFormat sensorFormat = findBestMode(fmts, cfg.size); + int ret = data_->unicam_[Unicam::Image].dev()->tryFormat(&sensorFormat); + if (ret) + return Invalid; + PixelFormat sensorPixFormat = sensorFormat.fourcc.toPixelFormat(); if (cfg.size != sensorFormat.size || cfg.pixelFormat != sensorPixFormat) { @@ -434,6 +438,10 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() cfg.pixelFormat = sensorPixFormat; status = Adjusted; } + + cfg.stride = sensorFormat.planes[0].bpl; + cfg.frameSize = sensorFormat.planes[0].size; + rawCount++; } else { outSize[outCount] = std::make_pair(count, cfg.size); @@ -478,19 +486,34 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() * have that fixed up in the code above. * */ - PixelFormat &cfgPixFmt = config_.at(outSize[i].first).pixelFormat; - V4L2PixFmtMap fmts; + StreamConfiguration &cfg = config_.at(outSize[i].first); + PixelFormat &cfgPixFmt = cfg.pixelFormat; + V4L2VideoDevice *dev; if (i == maxIndex) - fmts = data_->isp_[Isp::Output0].dev()->formats(); + dev = data_->isp_[Isp::Output0].dev(); else - fmts = data_->isp_[Isp::Output1].dev()->formats(); + dev = data_->isp_[Isp::Output1].dev(); + + V4L2PixFmtMap fmts = dev->formats(); if (fmts.find(V4L2PixelFormat::fromPixelFormat(cfgPixFmt, false)) == fmts.end()) { /* If we cannot find a native format, use a default one. */ cfgPixFmt = formats::NV12; status = Adjusted; } + + V4L2DeviceFormat format = {}; + format.fourcc = dev->toV4L2PixelFormat(cfg.pixelFormat); + format.size = cfg.size; + + int ret = dev->tryFormat(&format); + if (ret) + return Invalid; + + cfg.stride = format.planes[0].bpl; + cfg.frameSize = format.planes[0].size; + } return status; @@ -655,7 +678,6 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) if (isRaw(cfg.pixelFormat)) { cfg.setStream(&data->isp_[Isp::Input]); - cfg.stride = sensorFormat.planes[0].bpl; data->isp_[Isp::Input].setExternal(true); continue; } @@ -679,7 +701,6 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) } cfg.setStream(&data->isp_[Isp::Output0]); - cfg.stride = format.planes[0].bpl; data->isp_[Isp::Output0].setExternal(true); } @@ -705,7 +726,6 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) */ if (!cfg.stream()) { cfg.setStream(&data->isp_[Isp::Output1]); - cfg.stride = format.planes[0].bpl; data->isp_[Isp::Output1].setExternal(true); } }