Patch Detail
Show a patch.
GET /api/1.1/patches/9507/?format=api
{ "id": 9507, "url": "https://patchwork.libcamera.org/api/1.1/patches/9507/?format=api", "web_url": "https://patchwork.libcamera.org/patch/9507/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20200907071604.8355-7-david.plowman@raspberrypi.com>", "date": "2020-09-07T07:16:01", "name": "[libcamera-devel,v8,6/8] libcamera: raspberrypi: Set camera flips correctly from user transform", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "88ecc2209cd51e4d8bc1bc550fda2a216349bc6d", "submitter": { "id": 42, "url": "https://patchwork.libcamera.org/api/1.1/people/42/?format=api", "name": "David Plowman", "email": "david.plowman@raspberrypi.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/9507/mbox/", "series": [ { "id": 1268, "url": "https://patchwork.libcamera.org/api/1.1/series/1268/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1268", "date": "2020-09-07T07:15:55", "name": "2D transforms", "version": 8, "mbox": "https://patchwork.libcamera.org/series/1268/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/9507/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/9507/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 3B619BDB1C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 7 Sep 2020 07:16:17 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id EB28062BD4;\n\tMon, 7 Sep 2020 09:16:16 +0200 (CEST)", "from mail-wm1-x332.google.com (mail-wm1-x332.google.com\n\t[IPv6:2a00:1450:4864:20::332])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 49FDF62B76\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 7 Sep 2020 09:16:14 +0200 (CEST)", "by mail-wm1-x332.google.com with SMTP id q9so13311198wmj.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 07 Sep 2020 00:16:14 -0700 (PDT)", "from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72])\n\tby smtp.gmail.com with ESMTPSA id\n\tb2sm25543636wmh.47.2020.09.07.00.16.12\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 07 Sep 2020 00:16:12 -0700 (PDT)" ], "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"kxPAXtHU\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=ZsirvipDnqTf25QoPZDhiXxb01dneq/9RIzqw5Legzo=;\n\tb=kxPAXtHUrA3TWhDkmoH77xLp6RIAQ840fzyII4+8vov3WX6yTGtv5iIs6KMgbnt8ZT\n\tWTA6ehoVR2De62WGWJsbQoKFMgPen0AUECNc9FNwy3G+3ZjxgJLI3bKJDWSnGAzwETIo\n\tLV4fR93rnebIFFcVJQht5roJbXwCzzw4BwDyB4S/78DecCF9/ZuSzSkyL3r1jp0J18vY\n\tCMmAfUPSf7e5p50/rI/aEqAPBjgjXAe3OrddxYF1JlvDESrwsBFkCDGloTWC3fOUmGNt\n\tNZ87i37oHOaX8gNdUAQpGdLFbebpMdxYQnkpUbvhzHhhJ4VBSTQSTlpZoeEKP9NbTCFs\n\tfoaA==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=ZsirvipDnqTf25QoPZDhiXxb01dneq/9RIzqw5Legzo=;\n\tb=Ku6smxr/CvvWI9WxNaZnI3c6B9GjZWRvpI8+4+Z3MIyMGGXViIlfUNj/7iQkfUpqWP\n\teyiW+FTQZFthQo8fGIHEUhZHvhn4KHgZwdi1+s155zOLE3hoCFh7dI4oNqTydPDfMLlr\n\tbkKQJXMOI0xjp1jqDvnQICftvLZ1r55n8iwk8Ag/r1DLMqfgoUU8aDMfbVsUq0MKHT3m\n\t2RSgtZs80cTwt7OGPs9LQdAPdKDQqyH3DpaQR+QOQEloMxsS7bYYljUNqEcczJYDl8UD\n\tS/NfAtt3oRJ4GprjMLjvG2s6YpKGI6Yp/EDlgIY/ow46bjFj6lTd3Uw91Ucx0I8O59YZ\n\tgtAw==", "X-Gm-Message-State": "AOAM533WKMR2iFS3D/BG0hs+kJQNgalzgOTO4l+oC/8XadcoOHPpvNGJ\n\tUxpMYNoJ/6rE9dNXsgB6iVHjnnUC/YiR1g==", "X-Google-Smtp-Source": "ABdhPJwtTJ458DYjQNsdtbIQH/A+FdLk9aiKJ9i0t8CfSVg8lKwLI5IsaqJ0nlevb2gXdSDseJRTcQ==", "X-Received": "by 2002:a7b:c2aa:: with SMTP id\n\tc10mr19165305wmk.86.1599462973399; \n\tMon, 07 Sep 2020 00:16:13 -0700 (PDT)", "From": "David Plowman <david.plowman@raspberrypi.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Mon, 7 Sep 2020 08:16:01 +0100", "Message-Id": "<20200907071604.8355-7-david.plowman@raspberrypi.com>", "X-Mailer": "git-send-email 2.20.1", "In-Reply-To": "<20200907071604.8355-1-david.plowman@raspberrypi.com>", "References": "<20200907071604.8355-1-david.plowman@raspberrypi.com>", "MIME-Version": "1.0", "Subject": "[libcamera-devel] [PATCH v8 6/8] libcamera: raspberrypi: Set camera\n\tflips correctly from user transform", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "Content-Type": "text/plain; charset=\"us-ascii\"", "Content-Transfer-Encoding": "7bit", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "The Raspberry Pi pipeline handler allows all transforms except those\ninvolving a transpose. The user transform is combined with any\ninherent rotation of the camera, and the camera's H and V flip bits\nare set accordingly.\n\nNote that the validate() method has to work out what the final Bayer\norder of any raw streams will be, before configure() actually applies\nthe transform to the sensor. We make a note of the \"native\"\n(untransformed) Bayer order when the system starts, so that we can\ndeduce transformed Bayer orders more easily.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\n---\n .../pipeline/raspberrypi/raspberrypi.cpp | 155 ++++++++++++++++--\n 1 file changed, 143 insertions(+), 12 deletions(-)", "diff": "diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex 1087257..cc9af2c 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -23,6 +23,7 @@\n \n #include <linux/videodev2.h>\n \n+#include \"libcamera/internal/bayer_format.h\"\n #include \"libcamera/internal/camera_sensor.h\"\n #include \"libcamera/internal/device_enumerator.h\"\n #include \"libcamera/internal/ipa_manager.h\"\n@@ -287,6 +288,7 @@ class RPiCameraData : public CameraData\n public:\n \tRPiCameraData(PipelineHandler *pipe)\n \t\t: CameraData(pipe), sensor_(nullptr), state_(State::Stopped),\n+\t\t supportsFlips_(false), flipsAlterBayerOrder_(false),\n \t\t dropFrame_(false), ispOutputCount_(0)\n \t{\n \t}\n@@ -294,7 +296,7 @@ public:\n \tvoid frameStarted(uint32_t sequence);\n \n \tint loadIPA();\n-\tint configureIPA();\n+\tint configureIPA(const CameraConfiguration *config);\n \n \tvoid queueFrameAction(unsigned int frame, const IPAOperationData &action);\n \n@@ -335,6 +337,15 @@ public:\n \tstd::queue<FrameBuffer *> embeddedQueue_;\n \tstd::deque<Request *> requestQueue_;\n \n+\t/*\n+\t * Manage horizontal and vertical flips supported (or not) by the\n+\t * sensor. Also store the \"native\" Bayer order (that is, with no\n+\t * transforms applied).\n+\t */\n+\tbool supportsFlips_;\n+\tbool flipsAlterBayerOrder_;\n+\tBayerFormat::Order nativeBayerOrder_;\n+\n private:\n \tvoid checkRequestCompleted();\n \tvoid tryRunPipeline();\n@@ -352,6 +363,9 @@ public:\n \n \tStatus validate() override;\n \n+\t/* Cache the combinedTransform_ that will be applied to the sensor */\n+\tTransform combinedTransform_;\n+\n private:\n \tconst RPiCameraData *data_;\n };\n@@ -400,11 +414,61 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n \tif (config_.empty())\n \t\treturn Invalid;\n \n-\tif (transform != Transform::Identity) {\n-\t\ttransform = Transform::Identity;\n+\t/*\n+\t * What if the platform has a non-90 degree rotation? We can't even\n+\t * \"adjust\" the configuration and carry on. Alternatively, raising an\n+\t * error means the platform can never run. Let's just print a warning\n+\t * and continue regardless; the rotation is effectively set to zero.\n+\t */\n+\tint32_t rotation = data_->sensor_->properties().get(properties::Rotation);\n+\tbool success;\n+\tTransform rotationTransform = transformFromRotation(rotation, &success);\n+\tif (!success)\n+\t\tLOG(RPI, Warning) << \"Invalid rotation of \" << rotation\n+\t\t\t\t << \" degrees - ignoring\";\n+\tTransform combined = transform * rotationTransform;\n+\n+\t/*\n+\t * We combine the platform and user transform, but must \"adjust away\"\n+\t * any combined result that includes a transform, as we can't do those.\n+\t * In this case, flipping only the transpose bit is helpful to\n+\t * applications - they either get the transform they requested, or have\n+\t * to do a simple transpose themselves (they don't have to worry about\n+\t * the other possible cases).\n+\t */\n+\tif (!!(combined & Transform::Transpose)) {\n+\t\t/*\n+\t\t * Flipping the transpose bit in \"transform\" flips it in the\n+\t\t * combined result too (as it's the last thing that happens),\n+\t\t * which is of course clearing it.\n+\t\t */\n+\t\ttransform ^= Transform::Transpose;\n+\t\tcombined &= ~Transform::Transpose;\n+\t\tstatus = Adjusted;\n+\t}\n+\n+\t/*\n+\t * We also check if the sensor doesn't do h/vflips at all, in which\n+\t * case we clear them, and the application will have to do everything.\n+\t */\n+\tif (!data_->supportsFlips_ && !!combined) {\n+\t\t/*\n+\t\t * If the sensor can do no transforms, then combined must be\n+\t\t * changed to the identity. The only user transform that gives\n+\t\t * rise to this the inverse of the rotation. (Recall that\n+\t\t * combined = transform * rotationTransform.)\n+\t\t */\n+\t\ttransform = -rotationTransform;\n+\t\tcombined = Transform::Identity;\n \t\tstatus = Adjusted;\n \t}\n \n+\t/*\n+\t * Store the final combined transform that configure() will need to\n+\t * apply to the sensor to save us working it out again.\n+\t */\n+\tcombinedTransform_ = combined;\n+\n \tunsigned int rawCount = 0, outCount = 0, count = 0, maxIndex = 0;\n \tstd::pair<int, Size> outSize[2];\n \tSize maxSize;\n@@ -420,7 +484,23 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n \t\t\tif (ret)\n \t\t\t\treturn Invalid;\n \n-\t\t\tPixelFormat sensorPixFormat = sensorFormat.fourcc.toPixelFormat();\n+\t\t\t/*\n+\t\t\t * Some sensors change their Bayer order when they are\n+\t\t\t * h-flipped or v-flipped, according to the transform.\n+\t\t\t * If this one does, we must advertise the transformed\n+\t\t\t * Bayer order in the raw stream. Note how we must\n+\t\t\t * fetch the \"native\" (i.e. untransformed) Bayer order,\n+\t\t\t * because the sensor may currently be flipped!\n+\t\t\t */\n+\t\t\tV4L2PixelFormat fourcc = sensorFormat.fourcc;\n+\t\t\tif (data_->flipsAlterBayerOrder_) {\n+\t\t\t\tBayerFormat bayer(fourcc);\n+\t\t\t\tbayer.order = data_->nativeBayerOrder_;\n+\t\t\t\tbayer = bayer.transform(combined);\n+\t\t\t\tfourcc = bayer.toV4L2PixelFormat();\n+\t\t\t}\n+\n+\t\t\tPixelFormat sensorPixFormat = fourcc.toPixelFormat();\n \t\t\tif (cfg.size != sensorFormat.size ||\n \t\t\t cfg.pixelFormat != sensorPixFormat) {\n \t\t\t\tcfg.size = sensorFormat.size;\n@@ -756,7 +836,7 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n \tcrop.y = (sensorFormat.size.height - crop.height) >> 1;\n \tdata->isp_[Isp::Input].dev()->setSelection(V4L2_SEL_TGT_CROP, &crop);\n \n-\tret = data->configureIPA();\n+\tret = data->configureIPA(config);\n \tif (ret)\n \t\tLOG(RPI, Error) << \"Failed to configure the IPA: \" << ret;\n \n@@ -967,6 +1047,47 @@ bool PipelineHandlerRPi::match(DeviceEnumerator *enumerator)\n \t/* Initialize the camera properties. */\n \tdata->properties_ = data->sensor_->properties();\n \n+\t/*\n+\t * We cache three things about the sensor in relation to transforms\n+\t * (meaning horizontal and vertical flips).\n+\t *\n+\t * Firstly, does it support them?\n+\t * Secondly, if you use them does it affect the Bayer ordering?\n+\t * Thirdly, what is the \"native\" Bayer order, when no transforms are\n+\t * applied?\n+\t *\n+\t * As part of answering the final question, we reset the camera to\n+\t * no transform at all.\n+\t */\n+\n+\tV4L2VideoDevice *dev = data->unicam_[Unicam::Image].dev();\n+\tconst struct v4l2_query_ext_ctrl *hflipCtrl = dev->controlInfo(V4L2_CID_HFLIP);\n+\tif (hflipCtrl) {\n+\t\t/* We assume it will support vflips too... */\n+\t\tdata->supportsFlips_ = true;\n+\t\tdata->flipsAlterBayerOrder_ = hflipCtrl->flags & V4L2_CTRL_FLAG_MODIFY_LAYOUT;\n+\n+\t\tControlList ctrls(dev->controls());\n+\t\tctrls.set(V4L2_CID_HFLIP, 0);\n+\t\tctrls.set(V4L2_CID_VFLIP, 0);\n+\t\tdev->setControls(&ctrls);\n+\t}\n+\n+\t/* Look for a valid Bayer format. */\n+\tBayerFormat bayerFormat;\n+\tfor (const auto &iter : dev->formats()) {\n+\t\tV4L2PixelFormat v4l2Format = iter.first;\n+\t\tbayerFormat = BayerFormat(v4l2Format);\n+\t\tif (bayerFormat.isValid())\n+\t\t\tbreak;\n+\t}\n+\n+\tif (!bayerFormat.isValid()) {\n+\t\tLOG(RPI, Error) << \"No Bayer format found\";\n+\t\treturn false;\n+\t}\n+\tdata->nativeBayerOrder_ = bayerFormat.order;\n+\n \t/*\n \t * List the available output streams.\n \t * Currently cannot do Unicam streams!\n@@ -1114,8 +1235,12 @@ int RPiCameraData::loadIPA()\n \treturn ipa_->init(settings);\n }\n \n-int RPiCameraData::configureIPA()\n+int RPiCameraData::configureIPA(const CameraConfiguration *config)\n {\n+\t/* We know config must be an RPiCameraConfiguration. */\n+\tconst RPiCameraConfiguration *rpiConfig =\n+\t\tstatic_cast<const RPiCameraConfiguration *>(config);\n+\n \tstd::map<unsigned int, IPAStream> streamConfig;\n \tstd::map<unsigned int, const ControlInfoMap &> entityControls;\n \tIPAOperationData ipaConfig = {};\n@@ -1172,12 +1297,18 @@ int RPiCameraData::configureIPA()\n \t\t\tsensorMetadata_ = result.data[2];\n \t\t}\n \n-\t\t/* Configure the H/V flip controls based on the sensor rotation. */\n-\t\tControlList ctrls(unicam_[Unicam::Image].dev()->controls());\n-\t\tint32_t rotation = sensor_->properties().get(properties::Rotation);\n-\t\tctrls.set(V4L2_CID_HFLIP, static_cast<int32_t>(!!rotation));\n-\t\tctrls.set(V4L2_CID_VFLIP, static_cast<int32_t>(!!rotation));\n-\t\tunicam_[Unicam::Image].dev()->setControls(&ctrls);\n+\t\t/*\n+\t\t * Configure the H/V flip controls based on the combination of\n+\t\t * the sensor and user transform.\n+\t\t */\n+\t\tif (supportsFlips_) {\n+\t\t\tControlList ctrls(unicam_[Unicam::Image].dev()->controls());\n+\t\t\tctrls.set(V4L2_CID_HFLIP,\n+\t\t\t\t static_cast<int32_t>(!!(rpiConfig->combinedTransform_ & Transform::HFlip)));\n+\t\t\tctrls.set(V4L2_CID_VFLIP,\n+\t\t\t\t static_cast<int32_t>(!!(rpiConfig->combinedTransform_ & Transform::VFlip)));\n+\t\t\tunicam_[Unicam::Image].dev()->setControls(&ctrls);\n+\t\t}\n \t}\n \n \tif (result.operation & RPI_IPA_CONFIG_SENSOR) {\n", "prefixes": [ "libcamera-devel", "v8", "6/8" ] }