Patch Detail
Show a patch.
GET /api/patches/11359/?format=api
{ "id": 11359, "url": "https://patchwork.libcamera.org/api/patches/11359/?format=api", "web_url": "https://patchwork.libcamera.org/patch/11359/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/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": "<20210222105222.393677-4-jacopo@jmondi.org>", "date": "2021-02-22T10:52:20", "name": "[libcamera-devel,v3,3/5] android: camera_device: Compute frame durations", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "da02c6101fd795f76b144196d861c86557a46684", "submitter": { "id": 3, "url": "https://patchwork.libcamera.org/api/people/3/?format=api", "name": "Jacopo Mondi", "email": "jacopo@jmondi.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/11359/mbox/", "series": [ { "id": 1717, "url": "https://patchwork.libcamera.org/api/series/1717/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1717", "date": "2021-02-22T10:52:17", "name": "android: Report frame durations", "version": 3, "mbox": "https://patchwork.libcamera.org/series/1717/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/11359/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/11359/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 02D68BD1F1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 22 Feb 2021 10:52:03 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3DDB968A16;\n\tMon, 22 Feb 2021 11:52:02 +0100 (CET)", "from relay11.mail.gandi.net (relay11.mail.gandi.net\n\t[217.70.178.231])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 195AC68A05\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 22 Feb 2021 11:51:59 +0100 (CET)", "from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay11.mail.gandi.net (Postfix) with ESMTPSA id DCDDC100012\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 22 Feb 2021 10:51:58 +0000 (UTC)" ], "From": "Jacopo Mondi <jacopo@jmondi.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Mon, 22 Feb 2021 11:52:20 +0100", "Message-Id": "<20210222105222.393677-4-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.30.0", "In-Reply-To": "<20210222105222.393677-1-jacopo@jmondi.org>", "References": "<20210222105222.393677-1-jacopo@jmondi.org>", "MIME-Version": "1.0", "Subject": "[libcamera-devel] [PATCH v3 3/5] android: camera_device: Compute\n\tframe durations", "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": "Use the FrameDuration control reported by pipeline handlers to register\nthe Auto-Exposure routine FPS range, the minimum stream frame durations\nand the sensor maximum frame duration.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/android/camera_device.cpp | 84 ++++++++++++++++++++++++++---------\n 1 file changed, 64 insertions(+), 20 deletions(-)", "diff": "diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex 1e2a5b5f91da..1658e4a4dd9f 100644\n--- a/src/android/camera_device.cpp\n+++ b/src/android/camera_device.cpp\n@@ -9,6 +9,7 @@\n #include \"camera_ops.h\"\n #include \"post_processor.h\"\n \n+#include <cmath>\n #include <fstream>\n #include <sys/mman.h>\n #include <tuple>\n@@ -708,10 +709,10 @@ std::tuple<uint32_t, uint32_t> CameraDevice::calculateStaticMetadataSize()\n {\n \t/*\n \t * \\todo Keep this in sync with the actual number of entries.\n-\t * Currently: 53 entries, 854 bytes of static metadata\n+\t * Currently: 54 entries, 874 bytes of static metadata\n \t */\n-\tuint32_t numEntries = 53;\n-\tuint32_t byteSize = 854;\n+\tuint32_t numEntries = 54;\n+\tuint32_t byteSize = 874;\n \n \t/*\n \t * Calculate space occupation in bytes for dynamically built metadata\n@@ -801,12 +802,48 @@ const camera_metadata_t *CameraDevice::getStaticMetadata()\n \t\t\t\t aeAvailableModes.data(),\n \t\t\t\t aeAvailableModes.size());\n \n-\tstd::vector<int32_t> availableAeFpsTarget = {\n-\t\t15, 30,\n-\t};\n-\tstaticMetadata_->addEntry(ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES,\n-\t\t\t\t availableAeFpsTarget.data(),\n-\t\t\t\t availableAeFpsTarget.size());\n+\tint64_t minFrameDurationNsec = -1;\n+\tint64_t maxFrameDurationNsec = -1;\n+\tconst auto frameDurationsInfo = controlsInfo.find(&controls::FrameDurations);\n+\tif (frameDurationsInfo != controlsInfo.end()) {\n+\t\tminFrameDurationNsec = frameDurationsInfo->second.min().get<int64_t>() * 1000;\n+\t\tmaxFrameDurationNsec = frameDurationsInfo->second.max().get<int64_t>() * 1000;\n+\n+\t\t/*\n+\t\t * Adjust the minimum frame duration to comply with Android\n+\t\t * requirements. The camera service mandates all preview/record\n+\t\t * streams to have a minimum frame duration < 33,366 milliseconds\n+\t\t * (see MAX_PREVIEW_RECORD_DURATION_NS in the camera service\n+\t\t * implementation).\n+\t\t *\n+\t\t * If we're close enough (+ 500 useconds) to that value, round\n+\t\t * the minimum frame duration of the camera to an accepted\n+\t\t * value.\n+\t\t */\n+\t\tstatic constexpr int64_t MAX_PREVIEW_RECORD_DURATION_NS = 1e9 / 29.97;\n+\t\tif (minFrameDurationNsec > MAX_PREVIEW_RECORD_DURATION_NS &&\n+\t\t minFrameDurationNsec < MAX_PREVIEW_RECORD_DURATION_NS + 500000)\n+\t\t\tminFrameDurationNsec = MAX_PREVIEW_RECORD_DURATION_NS - 1000;\n+\n+\t\t/*\n+\t\t * The AE routine frame rate limits are computed using the frame\n+\t\t * duration limits, as libcamera clips the AE routine to the\n+\t\t * frame durations.\n+\t\t */\n+\t\tint32_t maxFps = static_cast<int32_t>(std::round(1e9 / minFrameDurationNsec));\n+\t\tint32_t minFps = static_cast<int32_t>(std::round(1e9 / maxFrameDurationNsec));\n+\t\tminFps = std::max(1, minFps);\n+\n+\t\t/*\n+\t\t * Register to the camera service {min, max} and {max, max}\n+\t\t * intervals as requested by the metadata documentation.\n+\t\t */\n+\t\tint32_t availableAeFpsTarget[] = {\n+\t\t\tminFps, maxFps, maxFps, maxFps\n+\t\t};\n+\t\tstaticMetadata_->addEntry(ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES,\n+\t\t\t\t\t availableAeFpsTarget, 4);\n+\t}\n \n \tstd::vector<int32_t> aeCompensationRange = {\n \t\t0, 0,\n@@ -996,6 +1033,10 @@ const camera_metadata_t *CameraDevice::getStaticMetadata()\n \tstaticMetadata_->addEntry(ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE,\n \t\t\t\t ×tampSource, 1);\n \n+\tif (maxFrameDurationNsec > 0)\n+\t\tstaticMetadata_->addEntry(ANDROID_SENSOR_INFO_MAX_FRAME_DURATION,\n+\t\t\t\t\t &maxFrameDurationNsec, 1);\n+\n \t/* Statistics static metadata. */\n \tuint8_t faceDetectMode = ANDROID_STATISTICS_FACE_DETECT_MODE_OFF;\n \tstaticMetadata_->addEntry(ANDROID_STATISTICS_INFO_AVAILABLE_FACE_DETECT_MODES,\n@@ -1130,18 +1171,20 @@ const camera_metadata_t *CameraDevice::getStaticMetadata()\n \t\t\t\t availableStallDurations.data(),\n \t\t\t\t availableStallDurations.size());\n \n-\t/* \\todo Collect the minimum frame duration from the camera. */\n-\tstd::vector<int64_t> minFrameDurations;\n-\tminFrameDurations.reserve(streamConfigurations_.size() * 4);\n-\tfor (const auto &entry : streamConfigurations_) {\n-\t\tminFrameDurations.push_back(entry.androidFormat);\n-\t\tminFrameDurations.push_back(entry.resolution.width);\n-\t\tminFrameDurations.push_back(entry.resolution.height);\n-\t\tminFrameDurations.push_back(33333333);\n+\t/* Use the minimum frame duration for all the YUV/RGB formats. */\n+\tif (minFrameDurationNsec > 0) {\n+\t\tstd::vector<int64_t> minFrameDurations;\n+\t\tminFrameDurations.reserve(streamConfigurations_.size() * 4);\n+\t\tfor (const auto &entry : streamConfigurations_) {\n+\t\t\tminFrameDurations.push_back(entry.androidFormat);\n+\t\t\tminFrameDurations.push_back(entry.resolution.width);\n+\t\t\tminFrameDurations.push_back(entry.resolution.height);\n+\t\t\tminFrameDurations.push_back(minFrameDurationNsec);\n+\t\t}\n+\t\tstaticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS,\n+\t\t\t\t\t minFrameDurations.data(),\n+\t\t\t\t\t minFrameDurations.size());\n \t}\n-\tstaticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS,\n-\t\t\t\t minFrameDurations.data(),\n-\t\t\t\t minFrameDurations.size());\n \n \tuint8_t croppingType = ANDROID_SCALER_CROPPING_TYPE_CENTER_ONLY;\n \tstaticMetadata_->addEntry(ANDROID_SCALER_CROPPING_TYPE, &croppingType, 1);\n@@ -1241,6 +1284,7 @@ const camera_metadata_t *CameraDevice::getStaticMetadata()\n \t\tANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE,\n \t\tANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT,\n \t\tANDROID_SENSOR_INFO_EXPOSURE_TIME_RANGE,\n+\t\tANDROID_SENSOR_INFO_MAX_FRAME_DURATION,\n \t\tANDROID_SENSOR_INFO_PHYSICAL_SIZE,\n \t\tANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE,\n \t\tANDROID_SENSOR_INFO_SENSITIVITY_RANGE,\n", "prefixes": [ "libcamera-devel", "v3", "3/5" ] }