{"id":11019,"url":"https://patchwork.libcamera.org/api/1.1/patches/11019/?format=json","web_url":"https://patchwork.libcamera.org/patch/11019/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210126173008.446321-4-jacopo@jmondi.org>","date":"2021-01-26T17:30:05","name":"[libcamera-devel,v2,3/6] android: camera_device: Compute frame durations","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"6725d2f97c03cba882f2fad1f804082712fdc85b","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/1.1/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/11019/mbox/","series":[{"id":1612,"url":"https://patchwork.libcamera.org/api/1.1/series/1612/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1612","date":"2021-01-26T17:30:02","name":"android: Report frame durations","version":2,"mbox":"https://patchwork.libcamera.org/series/1612/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/11019/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/11019/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 99121BD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 26 Jan 2021 17:29:58 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DCF2D68331;\n\tTue, 26 Jan 2021 18:29:57 +0100 (CET)","from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net\n\t[217.70.183.196])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 426A16831B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 26 Jan 2021 18:29:54 +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 relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 0F6FAE0009\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 26 Jan 2021 17:29:53 +0000 (UTC)"],"X-Originating-IP":"93.34.118.233","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue, 26 Jan 2021 18:30:05 +0100","Message-Id":"<20210126173008.446321-4-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.30.0","In-Reply-To":"<20210126173008.446321-1-jacopo@jmondi.org>","References":"<20210126173008.446321-1-jacopo@jmondi.org>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v2 3/6] 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 | 72 +++++++++++++++++++++++++----------\n 1 file changed, 52 insertions(+), 20 deletions(-)","diff":"diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex 1a384460974c..e3d43bea4700 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 <math.h>\n #include <sys/mman.h>\n #include <tuple>\n #include <vector>\n@@ -682,10 +683,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, 782 bytes of static metadata\n+\t * Currently: 54 entries, 802 bytes of static metadata\n \t */\n-\tuint32_t numEntries = 53;\n-\tuint32_t byteSize = 782;\n+\tuint32_t numEntries = 54;\n+\tuint32_t byteSize = 802;\n \n \t/*\n \t * Calculate space occupation in bytes for dynamically built metadata\n@@ -760,12 +761,34 @@ 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 minFrameDurationUsec = -1;\n+\tint64_t maxFrameDurationUsec = -1;\n+\tconst auto frameDurationsInfo = controlsInfo.find(&controls::FrameDurations);\n+\tif (frameDurationsInfo != controlsInfo.end()) {\n+\t\tminFrameDurationUsec = frameDurationsInfo->second.min().get<int64_t>();\n+\t\tmaxFrameDurationUsec = frameDurationsInfo->second.max().get<int64_t>();\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 minFps = static_cast<int32_t>(::round(1000000.0f /\n+\t\t\t\t\t\t\t      maxFrameDurationUsec));\n+\t\tminFps = std::max(1, minFps);\n+\t\tint maxFps = static_cast<int32_t>(::round(1000000.0f /\n+\t\t\t\t\t\t\t  minFrameDurationUsec));\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@@ -929,6 +952,12 @@ const camera_metadata_t *CameraDevice::getStaticMetadata()\n \tstaticMetadata_->addEntry(ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE,\n \t\t\t\t  &timestampSource, 1);\n \n+\tif (maxFrameDurationUsec > 0) {\n+\t\tint64_t maxFrameDuration = maxFrameDurationUsec * 1000;\n+\t\tstaticMetadata_->addEntry(ANDROID_SENSOR_INFO_MAX_FRAME_DURATION,\n+\t\t\t\t\t  &maxFrameDuration, 1);\n+\t}\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@@ -1063,18 +1092,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 (minFrameDurationUsec > 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(minFrameDurationUsec * 1000);\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@@ -1156,6 +1187,7 @@ const camera_metadata_t *CameraDevice::getStaticMetadata()\n \t\tANDROID_SENSOR_INFO_SENSITIVITY_RANGE,\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_ORIENTATION,\n \t\tANDROID_SENSOR_AVAILABLE_TEST_PATTERN_MODES,\n \t\tANDROID_SENSOR_INFO_PHYSICAL_SIZE,\n","prefixes":["libcamera-devel","v2","3/6"]}