From patchwork Fri Oct 22 14:39:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14265 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 44476BDB1C for ; Fri, 22 Oct 2021 14:40:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 07AF268F5C; Fri, 22 Oct 2021 16:40:24 +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="ol88NpK6"; dkim-atps=neutral Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3EFD968F5C for ; Fri, 22 Oct 2021 16:40:18 +0200 (CEST) Received: by mail-wr1-x435.google.com with SMTP id d13so628087wrf.11 for ; Fri, 22 Oct 2021 07:40:18 -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=rS8souYoYk4gsvn/YKRYkOCcLKCa7xP51raLarZqbo4=; b=ol88NpK6Ey5/Okp8QARlt78mRmmJMXUgV+amxGlHTmLYOFo2+mGvln4OG+2bV9De/0 T8ELAwmOPKvijfKvNGAkQNoQMOEDApPLP9HWo96AkpeVH/Twe8ngiRBrnav6dwwF3EBM tkcZ1VEYFGr21wZ+UEJloPzKn97b0i2ZsdxawcvNwr+wzAhWs7zhGlvqiTmwFmats6/s HHsu0cHImga/nJreJwp/vQXEXZk1tfAR7+yCBbvmtZmPb0LNnDC1RqJfWCD3byDFr2pE mEBUgyW75CZqxcl9OVYs74g66w0AXbFPXhk3dTFh8xtX5q0Wstzef/R456BW2wnIXBen JVxw== 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=rS8souYoYk4gsvn/YKRYkOCcLKCa7xP51raLarZqbo4=; b=Rgj+3QHTKQqF0S7KEsiUVAKqfyvsV3Jmn2HpyU6e2g/XpYrvsACb7hVrov2Atd/5Hp lafq7TlaleE1y5DFPMEg/BcTnefD4pSxlUvI33BJHm/eBcTayP61sOu5Jc3I9F8SUAaU TlwpsrVAQb88b7/2ZGb3pax/bUyoCAHFCQ5Dd9fsp+0IFmjWVQfFsTNifp8Pi2FNn9fc 5sz9XhbAK5pudysmUspLtbrfjHf+EGQuq/TntsOAHtYiqQAX8/Kh988xDhz9aLctnH3Y thDVyMJK3Q0KRQtyg8s7/BoHKCxpM2/CVDv6c206nsWb2Us/JnUPXnHlRl0OYGm5edDW qxwg== X-Gm-Message-State: AOAM533Fi7ltb8p414V0po3vVJd8eXStrZZCN0Cj+ydPsiH9YPz1tXfC AxLmKKP3XJTzn2KROX41z6/UPl2GtwnXnfec X-Google-Smtp-Source: ABdhPJzl6sbD06rcbkqF5xcv33M7elMJNUXvLDXpz9008h8GPX4+9lZFpSm8JyArskhIK0XQYxsipw== X-Received: by 2002:adf:e689:: with SMTP id r9mr320484wrm.426.1634913617698; Fri, 22 Oct 2021 07:40:17 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:f00d:ddf0:61b0:a4cd]) by smtp.gmail.com with ESMTPSA id r205sm8577878wma.3.2021.10.22.07.40.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Oct 2021 07:40:16 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Fri, 22 Oct 2021 15:39:07 +0100 Message-Id: <20211022143907.3089419-7-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211022143907.3089419-1-naush@raspberrypi.com> References: <20211022143907.3089419-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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 Review-by: David Plowman --- .../pipeline/raspberrypi/raspberrypi.cpp | 60 +++++++------------ 1 file changed, 21 insertions(+), 39 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index c5e9607c7d95..ad6f1231bbf6 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -627,16 +627,34 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) /* First calculate the best sensor mode we can use based on the user request. */ V4L2SubdeviceFormat sensorFormat = findBestMode(data->sensorFormats_, rawStream ? sensorSize : maxSize); - V4L2DeviceFormat unicamFormat = toV4L2DeviceFormat(sensorFormat, unpacked); 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); + } + + V4L2DeviceFormat unicamFormat = toV4L2DeviceFormat(sensorFormat, unpacked); ret = data->unicam_[Unicam::Image].dev()->setFormat(&unicamFormat); if (ret) return ret; @@ -645,10 +663,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; @@ -871,23 +885,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); @@ -1301,10 +1298,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; @@ -1355,17 +1348,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);