{"id":3951,"url":"https://patchwork.libcamera.org/api/patches/3951/?format=json","web_url":"https://patchwork.libcamera.org/patch/3951/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20200605141002.49119-8-jacopo@jmondi.org>","date":"2020-06-05T14:10:01","name":"[libcamera-devel,v3,7/8] libcamera: camera_sensor: Initialize frame durations","commit_ref":null,"pull_url":null,"state":"superseded","archived":true,"hash":"47e783583a3153e45789d6a3e6978d86783ec4ed","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":{"id":15,"url":"https://patchwork.libcamera.org/api/users/15/?format=json","username":"jmondi","first_name":"Jacopo","last_name":"Mondi","email":"jacopo@jmondi.org"},"mbox":"https://patchwork.libcamera.org/patch/3951/mbox/","series":[{"id":958,"url":"https://patchwork.libcamera.org/api/series/958/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=958","date":"2020-06-05T14:09:54","name":"android: Build stream configuration map","version":3,"mbox":"https://patchwork.libcamera.org/series/958/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/3951/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/3951/checks/","tags":{},"headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net\n\t[217.70.183.200])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5920061645\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  5 Jun 2020 16:07:13 +0200 (CEST)","from localhost.localdomain (93-34-118-233.ip49.fastwebnet.it\n\t[93.34.118.233]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay7-d.mail.gandi.net (Postfix) with ESMTPSA id F180A20009;\n\tFri,  5 Jun 2020 14:07:12 +0000 (UTC)"],"X-Originating-IP":"93.34.118.233","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri,  5 Jun 2020 16:10:01 +0200","Message-Id":"<20200605141002.49119-8-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.27.0","In-Reply-To":"<20200605141002.49119-1-jacopo@jmondi.org>","References":"<20200605141002.49119-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 7/8] libcamera: camera_sensor:\n\tInitialize frame 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>","X-List-Received-Date":"Fri, 05 Jun 2020 14:07:13 -0000"},"content":"Calculate the camera minimum and maximum frame durations, and register\nthe corresponding FrameDurationLimits property with those values.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/camera_sensor.cpp | 74 +++++++++++++++++++++++++++++++++\n 1 file changed, 74 insertions(+)","diff":"diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\nindex b9428175c55e..b144940f047d 100644\n--- a/src/libcamera/camera_sensor.cpp\n+++ b/src/libcamera/camera_sensor.cpp\n@@ -283,6 +283,80 @@ int CameraSensor::initProperties()\n \t\tpropertyValue = 0;\n \tproperties_.set(properties::Rotation, propertyValue);\n \n+\t/* Frame durations. */\n+\tstd::map<uint32_t, const ControlInfo *> controlLimits;\n+\tstd::array<uint32_t, 3> controlIds = {\n+\t\tV4L2_CID_VBLANK,\n+\t\tV4L2_CID_HBLANK,\n+\t\tV4L2_CID_PIXEL_RATE\n+\t};\n+\tfor (uint32_t controlId : controlIds) {\n+\t\t/*\n+\t\t * Make sure the subdevice reports VBLANK, HBLANK and PIXEL_RATE\n+\t\t * controls and collect the control information.\n+\t\t */\n+\t\tauto it = controls.find(controlId);\n+\t\tif (it == controls.end()) {\n+\t\t\tLOG(CameraSensor, Error)\n+\t\t\t\t<< \"Camera sensor does not support control \"\n+\t\t\t\t<< controlId;\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\tcontrolLimits[controlId] = &it->second;\n+\t}\n+\n+\t/*\n+\t * While the maximum line and frame sizes can be calculated by adding\n+\t * each control's maximum supported value to the current configuration,\n+\t * the minimum sizes shall be calculated by using the minimum available\n+\t * resolution. Get the current and smalles available size then calculate\n+\t * the frame durations.\n+\t */\n+\tV4L2SubdeviceFormat fmt{};\n+\tint ret = subdev_->getFormat(0, &fmt);\n+\tif (ret)\n+\t\treturn ret;\n+\tconst Size &currentSize = fmt.size;\n+\tconst Size &minSize = *sizes_.begin();\n+\n+\tstd::vector<int32_t> durations;\n+\tint32_t duration;\n+\n+\t/*\n+\t * Pixel rate is reported in Hz while frame duration is expressed in\n+\t * nanoseconds. Adjust it and calculate the minimum and maximum\n+\t * durations.\n+\t */\n+\tint64_t pixelRate = controlLimits[V4L2_CID_PIXEL_RATE]->max().get<int64_t>();\n+\tfloat rate = static_cast<float>(pixelRate) / 1e9F;\n+\n+\t/* Minimum frame duration: higher frame rate. */\n+\tduration = (minSize.width +\n+\t\t    controlLimits[V4L2_CID_HBLANK]->min().get<int32_t>())\n+\t\t * (minSize.height +\n+\t\t    controlLimits[V4L2_CID_VBLANK]->min().get<int32_t>());\n+\tduration = static_cast<int32_t>(static_cast<float>(duration) / rate);\n+\tdurations.push_back(duration);\n+\n+\tpixelRate = controlLimits[V4L2_CID_PIXEL_RATE]->min().get<int64_t>();\n+\trate = static_cast<float>(pixelRate) / 1e9F;\n+\n+\t/* Maximum frame duration: lower frame rate. */\n+\tduration = (currentSize.width +\n+\t\t    controlLimits[V4L2_CID_HBLANK]->max().get<int32_t>())\n+\t\t * (currentSize.height +\n+\t\t    controlLimits[V4L2_CID_VBLANK]->max().get<int32_t>());\n+\tduration = static_cast<int32_t>(static_cast<float>(duration) / rate);\n+\tdurations.push_back(duration);\n+\n+\tproperties_.set(properties::FrameDurationLimits, durations);\n+\n+\tLOG(CameraSensor, Debug) << \"Frame durations interval = [\"\n+\t\t\t\t << durations[0] << \" - \"\n+\t\t\t\t << durations[1] << \"]\";\n+\n+\treturn 0;\n }\n \n /**\n","prefixes":["libcamera-devel","v3","7/8"]}