From patchwork Thu Jan 13 14:15:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 15279 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 006D9C325A for ; Thu, 13 Jan 2022 14:16:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 81887605A8; Thu, 13 Jan 2022 15:16:06 +0100 (CET) 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="YnJ6M6i0"; 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 C40A5604F4 for ; Thu, 13 Jan 2022 15:16:03 +0100 (CET) Received: by mail-wr1-x436.google.com with SMTP id r28so10395199wrc.3 for ; Thu, 13 Jan 2022 06:16:03 -0800 (PST) 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=1gghCCn3+u5hZC9uavWRxTF4TMcfMQGnUBz1f6/Oh/0=; b=YnJ6M6i0juUtUBdIosECvCj7DTXwnT5YpypjXgaf/n5sWBIo5+y4K9TKeUSLYaYYAf 8UU7yzCxI7aJ+3MN5JN5jBUSlEygdLmu+FHWEQQyHGlJVDbpvlqci/HxTHagVNwNwXh5 upeABzcrenoQcit5R9FQT0DhcPtPMBv3t4qzuGTwx8lITVotngTmjinrS6Spbcdv9cq/ DXu6BY0Zv9QFb3HwFLUjz6N/weiC9K9ceePs/ps2vaZvCEvNJGarh7Gh1LrSWOLyPTY6 lRgdAhSLUBqUUcAm+QUN5VdXZX2iSk3gURa11Wl5ODOfMoQvk9D53xtkSe9xg6LD4KtH CiBg== 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=1gghCCn3+u5hZC9uavWRxTF4TMcfMQGnUBz1f6/Oh/0=; b=MQvcqul7GgdK26HbfRDifNPSoakHq4PPr6k3Icc15bQtxA+Zvst6D9EDHhOkFxbBV+ R8MgyeJJSX41XnJIjSaf2FFx2aVZk3n77AxSTbwqv+W72T2IbO7oYmN50Xy/GZ+q/1v6 gf9SwWhhPaDDQW7jStj77hmrIgANZ6OJQPMWzK1i8/Be/wbINo6Ei2j6UVWiSdxE2A8n OTSBIAzuMzBrCmukx1g47tg03RRLw6UG2Wqlg/oS2+I2wIaZiMv74ChG6V5Nf+XHzCDP B4P6HGZTP3ipgKj4NZughAwnk9yD0bzH3aegi/5q8R6JzXgxBTkrv7ViM2ghOaRKBfy+ S6+g== X-Gm-Message-State: AOAM53288/KAn48HX+uAPlH+4GEoM7OUiZUSDSCkW0+7YGRu+giigd8A Nx2Tm1J09+DWSb+q9QKkrqIRQXmVUGyLf4uN X-Google-Smtp-Source: ABdhPJzXS103rFB6gTOQizdBRDwOoL8U1BL5epkL90/aQdd3ymnBF8BRYP2/c5On/tP/aGw0BobrGw== X-Received: by 2002:a5d:688c:: with SMTP id h12mr4281225wru.421.1642083363223; Thu, 13 Jan 2022 06:16:03 -0800 (PST) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id b2sm3284584wrd.35.2022.01.13.06.16.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jan 2022 06:16:02 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Thu, 13 Jan 2022 14:15:57 +0000 Message-Id: <20220113141558.5805-2-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220113141558.5805-1-david.plowman@raspberrypi.com> References: <20220113141558.5805-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/2] libcamera: camera_sensor: Clear camera flips after opening the device 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" We clear the V4L2_CID_HFLIP and V4L2_CID_VFLIP controls immediately after opening the camera device. This means the camera's Bayer format and mbus codes will be in the sensor's "native" order, and we document this to be the case so that it can be relied upon. Clearing the flips is harmless where sensor flips do not affect the Bayer order. This also fixes a bug in the Raspberry Pi pipeline handler where the native Bayer order was being computed wrongly, but the new behaviour here will be helpful to other pipeline handlers too. A subsequent commit will tidy up the Raspberry Pi pipeline handler in this area as it can now be simplified. Signed-off-by: David Plowman Fixes: 83a512816189 (pipeline: raspberrypi: Convert the pipeline handler to use media controller) Reviewed-by: Kieran Bingham Reviewed-by: Naushir Patuck --- src/libcamera/camera_sensor.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index c3999d35..64f7f12c 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -107,6 +107,17 @@ int CameraSensor::init() if (ret < 0) return ret; + /* + * Clear any flips to be sure we get the "native" Bayer order. This is + * harmless for sensors where the flips don't affect the Bayer order. + */ + ControlList ctrls(subdev_->controls()); + if (subdev_->controls().find(V4L2_CID_HFLIP) != subdev_->controls().end()) + ctrls.set(V4L2_CID_HFLIP, 0); + if (subdev_->controls().find(V4L2_CID_VFLIP) != subdev_->controls().end()) + ctrls.set(V4L2_CID_VFLIP, 0); + subdev_->setControls(&ctrls); + /* Enumerate, sort and cache media bus codes and sizes. */ formats_ = subdev_->formats(pad_); if (formats_.empty()) { @@ -461,6 +472,11 @@ int CameraSensor::initProperties() /** * \fn CameraSensor::mbusCodes() * \brief Retrieve the media bus codes supported by the camera sensor + * + * Any Bayer formats are listed using the sensor's native Bayer order, + * that is, with the effect of V4L2_CID_HFLIP and V4L2_CID_VFLIP undone + * (where these controls exist). + * * \return The supported media bus codes sorted in increasing order */ From patchwork Thu Jan 13 14:15:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 15280 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 A84B4C325B for ; Thu, 13 Jan 2022 14:16:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E1F3860935; Thu, 13 Jan 2022 15:16:06 +0100 (CET) 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="g9gzCMyG"; dkim-atps=neutral Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C2CA5604F4 for ; Thu, 13 Jan 2022 15:16:04 +0100 (CET) Received: by mail-wm1-x332.google.com with SMTP id v123so3977631wme.2 for ; Thu, 13 Jan 2022 06:16:04 -0800 (PST) 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=PtWJNFmk1vWzp2J6OmgnsiVLUT9BGhimEM0bzjBaDAI=; b=g9gzCMyGmMf2OQWA7mQtriNj9+2H3Xr4WNFU+xvWrzPQtXNNj+u2d5WA66ITPJOnvV p6UoSSpnohAZvshtVvKX8+uHOu1s+RaesZAiEyr/dQHIJcnLxwwU1+eBRnO2AIAvt6Xz Ui78omCBGt2UHkNS+poml+2kV/zSrtYrTtKPgBLC/bFxanqopwjE98Z3kldF0vTQJYZr pLcsGockhIZeAnvWUTNJ6lMGm8peKG5UnbEArLH7aXuK3hL9KbrFeNDAlIfldQ9zlOoq JpM8bGzb6NfYpOwWzuIPUnW7tVA7qrJRRXvnBN2jsbMCbi9xjYibUA6xadqi5X1b7QbJ RkJg== 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=PtWJNFmk1vWzp2J6OmgnsiVLUT9BGhimEM0bzjBaDAI=; b=c/ioKBYpBYDuX8yw2s/IgCrqOdCgF/BJ16X4JV0qE5OND9dNFZBYi8s5aDcIY+WZ4T /fEKFdiH8jkpXP/k9pHKabzI9uRcwdlSm2669RWOAqXmxpwPBfQVG2g0c/6kdvnwzjkp ksweePAIBcbtwVN5oO7ifTHkT3R1VNLWCDGMhGqEKg3I/X6pVKDWxVy56YJPKxxzYWki ppbY52bI2iF1hErJ/fmJLPoTuNwuZlytxZxcI8tBRXxBCus6eCyG2GlV+Q/8dovrTzfH cxMutMa2g5Gf+2lUMXRtFce8LwRrnnR8PFnMpg3rb+pHFykrwL91g/k15bw4qrsjE+w4 PFWQ== X-Gm-Message-State: AOAM530UjIoix+7TN2W2SQb5wwnf+oUG6Lzfm4DiLMeqyqxHu+ZC7MnO /0BKfvyHNFJA13Ivvb9xwIolz1zlOPneWEZc X-Google-Smtp-Source: ABdhPJy62t05DYyJVwul+KsWAltAr7HIp6VtqUvv2U+eAEf5U0A0IVqS8lXeZi5K8YT2oxeVxMtIIw== X-Received: by 2002:a05:600c:1d95:: with SMTP id p21mr4013972wms.9.1642083364227; Thu, 13 Jan 2022 06:16:04 -0800 (PST) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id b2sm3284584wrd.35.2022.01.13.06.16.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jan 2022 06:16:03 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Thu, 13 Jan 2022 14:15:58 +0000 Message-Id: <20220113141558.5805-3-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220113141558.5805-1-david.plowman@raspberrypi.com> References: <20220113141558.5805-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/2] pipeline: raspberrypi: Simplify calculation of sensor's native Bayer order 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" Now that the sensor is defined to list mbus codes using its native (untransformed) Bayer order, the method of obtaining it can be simplified. We don't have to try and reset the flips, we just use the value directly from the sensor. Signed-off-by: David Plowman Reviewed-by: Kieran Bingham Reviewed-by: Naushir Patuck --- src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 49d7ff23..79cb75c6 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -1279,8 +1279,8 @@ int PipelineHandlerRPi::registerCamera(MediaDevice *unicam, MediaDevice *isp, Me * Thirdly, what is the "native" Bayer order, when no transforms are * applied? * - * As part of answering the final question, we reset the camera to - * no transform at all. + * We note that the sensor's cached list of supported formats is + * already in the "native" order, with any flips having been undone. */ const V4L2Subdevice *sensor = data->sensor_->device(); const struct v4l2_query_ext_ctrl *hflipCtrl = sensor->controlInfo(V4L2_CID_HFLIP); @@ -1288,11 +1288,6 @@ int PipelineHandlerRPi::registerCamera(MediaDevice *unicam, MediaDevice *isp, Me /* We assume it will support vflips too... */ data->supportsFlips_ = true; data->flipsAlterBayerOrder_ = hflipCtrl->flags & V4L2_CTRL_FLAG_MODIFY_LAYOUT; - - ControlList ctrls(data->sensor_->controls()); - ctrls.set(V4L2_CID_HFLIP, 0); - ctrls.set(V4L2_CID_VFLIP, 0); - data->setSensorControls(ctrls); } /* Look for a valid Bayer format. */