From patchwork Fri Oct 22 11:55:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14258 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 69BF3BF415 for ; Fri, 22 Oct 2021 11:55:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EB84868F5F; Fri, 22 Oct 2021 13:55:49 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="Q/hoYl4c"; dkim-atps=neutral Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D952568F5A for ; Fri, 22 Oct 2021 13:55:46 +0200 (CEST) Received: by mail-wr1-x436.google.com with SMTP id e12so3577518wra.4 for ; Fri, 22 Oct 2021 04:55:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=86xqRCs6+mA3Dlk2ANmJcOkjcIa6VXvLIhE5udLMFg4=; b=Q/hoYl4ck1jHOmE8ESc3qlpcKF3Z/zMwgEni3PXHMmVXoVNyJ/qAeAIZGVzAlac3vu xDoaX42jjRl+XrSYkBpOXrA06Djj5Mt3MsTrroCEtlQ6yOBlZgT2oIugVyfBWKtUzxX4 9lfKPNiYn/Y//Jk8nsmoAWBiE6/wDxVRMOuxrmQXksw6WV9kasu2RG4VhjKjvoLqqHUn UuLErgwOUU+iBoBrz6/JVqIhPPs37amucBvbGgqHvR56jZiVz069JvfQqBcqYkaEJ2X9 CP5uVBVgMBfjjUspA19rarHEBth4VzvwP1oLpWsuLg4iZSiC154DdrlAwLRHv0OCUnT+ TwAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=86xqRCs6+mA3Dlk2ANmJcOkjcIa6VXvLIhE5udLMFg4=; b=OQC7ua6sbbuwI8wVZitcNjzgZImFywinbm/ItlZJO0vgNabjvTcg87eEG4oae6mshg 0RQUJ3RxMDKn7oc8OUrWUCDtrgS7NjJDrWMabkYKcYfwrZ81Ha+C9wWxKEay5QNa4amh VJvbQPnpjIg9DnGCkGthy3xhMK4lcr+kO0HXIfHXzzXuLjKYD7A7NmTFOA4DmJNR8XC/ 7Xvgx8rSw00W13rNUKCTueGys66yCKT0u2Ff5icvgsS8ann1tB7u8yvU6ZBJa5Jkkuo2 8SFuwHboe2rvWwJDR02DE/sVXWt1ZakSiBJxhYtiN+ueXI64ZZvh2JmBqqnHjMHwTVf1 pgoQ== X-Gm-Message-State: AOAM530MKexfCrRzlU9fiqrys3H4dmAUf+BHC38NUT7Hd//E0rr0ZFqL 0IyDbbXoo1HIb+sL42/WF1oriHsHQ97c9/uv X-Google-Smtp-Source: ABdhPJzOHGgJxtRB2Qymi3nZyAzpFA4HBDv1EbsQG9i3ldSd4oq2Ce9m5mjIYbyo98ClJQoeP8HZ9g== X-Received: by 2002:adf:fa8b:: with SMTP id h11mr15270659wrr.74.1634903746367; Fri, 22 Oct 2021 04:55:46 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:f00d:ddf0:61b0:a4cd]) by smtp.gmail.com with ESMTPSA id l5sm7853364wru.24.2021.10.22.04.55.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Oct 2021 04:55:45 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Fri, 22 Oct 2021 12:55:37 +0100 Message-Id: <20211022115537.2964533-7-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211022115537.2964533-1-naush@raspberrypi.com> References: <20211022115537.2964533-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 6/6] pipeline: raspberrypi: Apply sensor flips at the start of configure() 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" Sensor flips might change the Bayer order of the requested format. The existing code would set a sensor format along with the appropriate Unicam and ISP input formats, but reset the latter two on start() once the flips had been requested. We can now set the sensor flips just after we set the sensor mode in configure(), thereby not needing the second pair of format sets in start(). Signed-off-by: Naushir Patuck --- .../pipeline/raspberrypi/raspberrypi.cpp | 61 +++++++------------ 1 file changed, 22 insertions(+), 39 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 5aaf24436f27..8fb6197ec283 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -639,16 +639,35 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) /* First calculate the best sensor mode we can use based on the user request. */ SensorMode sensorMode = findBestMode(data->sensorFormats_, rawStream ? sensorSize : maxSize); V4L2SubdeviceFormat sensorFormat = toV4L2SubdeviceFormat(sensorMode); - V4L2DeviceFormat unicamFormat = toV4L2DeviceFormat(sensorMode); ret = data->sensor_->setFormat(&sensorFormat); if (ret) return ret; /* - * Unicam image output format. The ISP input format gets set at start, - * just in case we have swapped bayer orders due to flips. + * Configure the H/V flip controls based on the combination of + * the sensor and user transform. */ + if (data->supportsFlips_) { + const RPiCameraConfiguration *rpiConfig = + static_cast(config); + ControlList controls; + + controls.set(V4L2_CID_HFLIP, + static_cast(!!(rpiConfig->combinedTransform_ & Transform::HFlip))); + controls.set(V4L2_CID_VFLIP, + static_cast(!!(rpiConfig->combinedTransform_ & Transform::VFlip))); + data->setSensorControls(controls); + + /* + * IPA configure may have changed the sensor flips - hence the bayer + * order. So update the sensor format now. + */ + data->sensor_->device()->getFormat(0, &sensorFormat); + sensorMode.first = BayerFormat::fromMbusCode(sensorFormat.mbus_code).toPixelFormat(); + } + + V4L2DeviceFormat unicamFormat = toV4L2DeviceFormat(sensorMode); ret = data->unicam_[Unicam::Image].dev()->setFormat(&unicamFormat); if (ret) return ret; @@ -657,10 +676,6 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) << " - Selected sensor mode: " << sensorFormat.toString() << " - Selected unicam mode: " << unicamFormat.toString(); - /* - * This format may be reset on start() if the bayer order has changed - * because of flips in the sensor. - */ ret = data->isp_[Isp::Input].dev()->setFormat(&unicamFormat); if (ret) return ret; @@ -881,23 +896,6 @@ int PipelineHandlerRPi::start(Camera *camera, const ControlList *controls) return ret; } - /* - * IPA configure may have changed the sensor flips - hence the bayer - * order. Get the sensor format and set the ISP input now. - */ - V4L2SubdeviceFormat sensorFormat; - data->sensor_->device()->getFormat(0, &sensorFormat); - - V4L2DeviceFormat ispFormat; - ispFormat.fourcc = BayerFormat::fromMbusCode(sensorFormat.mbus_code).toV4L2PixelFormat(); - ispFormat.size = sensorFormat.size; - - ret = data->isp_[Isp::Input].dev()->setFormat(&ispFormat); - if (ret) { - stop(camera); - return ret; - } - /* Enable SOF event generation. */ data->unicam_[Unicam::Image].dev()->setFrameStartEnabled(true); @@ -1311,10 +1309,6 @@ int RPiCameraData::loadIPA(ipa::RPi::SensorConfig *sensorConfig) int RPiCameraData::configureIPA(const CameraConfiguration *config) { - /* We know config must be an RPiCameraConfiguration. */ - const RPiCameraConfiguration *rpiConfig = - static_cast(config); - std::map streamConfig; std::map entityControls; ipa::RPi::IPAConfig ipaConfig; @@ -1365,17 +1359,6 @@ int RPiCameraData::configureIPA(const CameraConfiguration *config) return -EPIPE; } - /* - * Configure the H/V flip controls based on the combination of - * the sensor and user transform. - */ - if (supportsFlips_) { - controls.set(V4L2_CID_HFLIP, - static_cast(!!(rpiConfig->combinedTransform_ & Transform::HFlip))); - controls.set(V4L2_CID_VFLIP, - static_cast(!!(rpiConfig->combinedTransform_ & Transform::VFlip))); - } - if (!controls.empty()) setSensorControls(controls);