Patch Detail
Show a patch.
GET /api/1.1/patches/4077/?format=api
{ "id": 4077, "url": "https://patchwork.libcamera.org/api/1.1/patches/4077/?format=api", "web_url": "https://patchwork.libcamera.org/patch/4077/", "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": "<20200618111236.26897-3-david.plowman@raspberrypi.com>", "date": "2020-06-18T11:12:36", "name": "[libcamera-devel,v2,2/2] libcamera: raspberrypi: recalculate camera exposure/gain when camera mode changes", "commit_ref": "846e7d999a15ce0c3784a790cd5c249ba7aaa5c6", "pull_url": null, "state": "accepted", "archived": false, "hash": "bb8eb9eaf0f19bafdd970f732825901546663896", "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/4077/mbox/", "series": [ { "id": 1014, "url": "https://patchwork.libcamera.org/api/1.1/series/1014/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1014", "date": "2020-06-18T11:12:34", "name": "Raspberry pi IPAs: update sensor exposure/gain when camera mode changes", "version": 2, "mbox": "https://patchwork.libcamera.org/series/1014/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/4077/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/4077/checks/", "tags": {}, "headers": { "Return-Path": "<david.plowman@raspberrypi.com>", "Received": [ "from mail-wm1-x330.google.com (mail-wm1-x330.google.com\n\t[IPv6:2a00:1450:4864:20::330])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 79C23607DE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 18 Jun 2020 13:12:58 +0200 (CEST)", "by mail-wm1-x330.google.com with SMTP id a6so1398857wmm.5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 18 Jun 2020 04:12:58 -0700 (PDT)", "from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72])\n\tby smtp.gmail.com with ESMTPSA id\n\te10sm3103857wrn.11.2020.06.18.04.12.56\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 18 Jun 2020 04:12:56 -0700 (PDT)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"a0N/zIlq\"; 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=vfF7umJN63KhWa9zfa1zff+dqwZNZIkIJp+wbjDa9aQ=;\n\tb=a0N/zIlq8SU9F94epC1dSJlaZCO26PxB+SnFuuLvn5sMEzzt5XjxvtVbZbMs6LE1s7\n\tca7dctV9/Ef3mlIbqnbI15QoWbIYN+JxVNRbB/QQspGXqjiS+aGbKplEYF83CxxyQ3M4\n\tOUspoFyHgVEA4h7Ngi3bwubcmRP9WJOvKfIC8hXMa9EUi6D5WdPXDIe8jCpfx9t4tLKE\n\tdAMvJpQKOTBtXMKS/dVr8hVrmLXuE3TnaoGP0G69JiFQUbIcFcptEV5ZkZ7XjtwBC90u\n\tVgGB/No6D5BqGwkiUIeQdRUzIzs9E3UWh4ASJN30NcL4r5yd4HScu/NzILTV/VRpEbze\n\t3SOA==", "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=vfF7umJN63KhWa9zfa1zff+dqwZNZIkIJp+wbjDa9aQ=;\n\tb=DgOibxUNrCOkzAesYnhX5zOscDvilVQjg5m0yxVcuQDQkokyZ6/03jjrToSB+a+wXf\n\tB5jpOBX++n05jJ0JoLPuSS5ksZzUHVz4CFtscWXrWSy0UEEhrcruN8+NPS5eTvsmJCIP\n\tuEwLcvrM5OTOYCrWdanoqP64m01yx/NePXTQvVEfATy8roBhX56KHHr2Aa7BlsdrE0Hr\n\tNGUZFCxE69fizuU2g2UM8d7UtH3DKxFHkNzd6baWnSHLOvyRH6BecVFkDZv1XXBg/wQS\n\tyjDRy9opo6NlYVd60ibgEUMXKcmNlpfjnJmiucfvWYBto/z5ne1gcT2J7nGYV6babnnP\n\tUi8g==", "X-Gm-Message-State": "AOAM533qZ73ucZdEu/swQvhIEr99sQNF44BEBJgdecLAjvWSaL9yiT42\n\tJCmvqoOeqsnC7j5gNcJabYUxmHhIHww=", "X-Google-Smtp-Source": "ABdhPJx5infg9dfKJ+Z0qgkgNjcJcDE+/68UupVCwBUeTDgWB5FJ0bp9q3mBlRWtOmjKMMJFWPyJFA==", "X-Received": "by 2002:a1c:9687:: with SMTP id\n\ty129mr3495953wmd.30.1592478777423; \n\tThu, 18 Jun 2020 04:12:57 -0700 (PDT)", "From": "David Plowman <david.plowman@raspberrypi.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Thu, 18 Jun 2020 12:12:36 +0100", "Message-Id": "<20200618111236.26897-3-david.plowman@raspberrypi.com>", "X-Mailer": "git-send-email 2.20.1", "In-Reply-To": "<20200618111236.26897-1-david.plowman@raspberrypi.com>", "References": "<20200618111236.26897-1-david.plowman@raspberrypi.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2 2/2] libcamera: raspberrypi:\n\trecalculate camera exposure/gain when camera mode changes", "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>", "X-List-Received-Date": "Thu, 18 Jun 2020 11:12:58 -0000" }, "content": "This commit causes the AGC to recalculate its camera exposure/gain\nvalues when the camera mode changes. For example it's possible\nthat the exposure profile could be changed by the application so\nthe division between exposure time and analogue gain may be\ndifferent.\n\nThe other underlying reason (and which this commit accomplishes too)\nis that the sensor's line timing may change in a new mode, and because\nV4L2 drivers store a number of exposure _lines_, the resulting _time_\nwill \"change under our feet\". So we have to go through the process of\nrecalculating the correct number of lines and writing this back to the\nsensor with every mode switch, regardless of anything else.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\n---\n src/ipa/raspberrypi/controller/rpi/agc.cpp | 12 +++++++++++\n src/ipa/raspberrypi/controller/rpi/agc.hpp | 1 +\n src/ipa/raspberrypi/raspberrypi.cpp | 25 +++++++++++-----------\n 3 files changed, 26 insertions(+), 12 deletions(-)", "diff": "diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp\nindex a474287..c02b5ec 100644\n--- a/src/ipa/raspberrypi/controller/rpi/agc.cpp\n+++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp\n@@ -221,6 +221,18 @@ void Agc::SetConstraintMode(std::string const &constraint_mode_name)\n \tconstraint_mode_name_ = constraint_mode_name;\n }\n \n+void Agc::SwitchMode(CameraMode const &camera_mode, Metadata *metadata)\n+{\n+\t// On a mode switch, it's possible the exposure profile could change,\n+\t// so we run through the dividing up of exposure/gain again and\n+\t// write the results into the metadata we've been given.\n+\tif (status_.total_exposure_value) {\n+\t\thousekeepConfig();\n+\t\tdivvyupExposure();\n+\t\twriteAndFinish(metadata, false);\n+\t}\n+}\n+\n void Agc::Prepare(Metadata *image_metadata)\n {\n \tAgcStatus status;\ndiff --git a/src/ipa/raspberrypi/controller/rpi/agc.hpp b/src/ipa/raspberrypi/controller/rpi/agc.hpp\nindex dbcefba..9a7e89c 100644\n--- a/src/ipa/raspberrypi/controller/rpi/agc.hpp\n+++ b/src/ipa/raspberrypi/controller/rpi/agc.hpp\n@@ -75,6 +75,7 @@ public:\n \tvoid SetMeteringMode(std::string const &metering_mode_name) override;\n \tvoid SetExposureMode(std::string const &exposure_mode_name) override;\n \tvoid SetConstraintMode(std::string const &contraint_mode_name) override;\n+\tvoid SwitchMode(CameraMode const &camera_mode, Metadata *metadata) override;\n \tvoid Prepare(Metadata *image_metadata) override;\n \tvoid Process(StatisticsPtr &stats, Metadata *image_metadata) override;\n \ndiff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\nindex d6fd3df..42c84b1 100644\n--- a/src/ipa/raspberrypi/raspberrypi.cpp\n+++ b/src/ipa/raspberrypi/raspberrypi.cpp\n@@ -247,29 +247,30 @@ void IPARPi::configure(const CameraSensorInfo &sensorInfo,\n \t\tmistrust_count_ = helper_->MistrustFramesStartup();\n \t}\n \n+\tstruct AgcStatus agcStatus;\n+\t/* These zero values mean not program anything (unless overwritten). */\n+\tagcStatus.shutter_time = 0.0;\n+\tagcStatus.analogue_gain = 0.0;\n+\n \tif (!controllerInit_) {\n \t\t/* Load the tuning file for this sensor. */\n \t\tcontroller_.Read(tuningFile_.c_str());\n \t\tcontroller_.Initialise();\n \t\tcontrollerInit_ = true;\n \n-\t\t/* Calculate initial values for gain and exposure. */\n-\t\tint32_t gain_code = helper_->GainCode(DEFAULT_ANALOGUE_GAIN);\n-\t\tint32_t exposure_lines = helper_->ExposureLines(DEFAULT_EXPOSURE_TIME);\n-\n-\t\tControlList ctrls(unicam_ctrls_);\n-\t\tctrls.set(V4L2_CID_ANALOGUE_GAIN, gain_code);\n-\t\tctrls.set(V4L2_CID_EXPOSURE, exposure_lines);\n-\n-\t\tIPAOperationData op;\n-\t\top.operation = RPI_IPA_ACTION_V4L2_SET_STAGGERED;\n-\t\top.controls.push_back(ctrls);\n-\t\tqueueFrameAction.emit(0, op);\n+\t\t/* Supply initial values for gain and exposure. */\n+\t\tagcStatus.shutter_time = DEFAULT_EXPOSURE_TIME;\n+\t\tagcStatus.analogue_gain = DEFAULT_ANALOGUE_GAIN;\n \t}\n \n \tRPi::Metadata metadata;\n \tcontroller_.SwitchMode(mode_, &metadata);\n \n+\t/* SwitchMode may supply updated exposure/gain values to use. */\n+\tmetadata.Get(\"agc.status\", agcStatus);\n+\tif (agcStatus.shutter_time != 0.0 && agcStatus.analogue_gain != 0.0)\n+\t\tapplyAGC(&agcStatus);\n+\n \tlastMode_ = mode_;\n }\n \n", "prefixes": [ "libcamera-devel", "v2", "2/2" ] }