From patchwork Wed Dec 28 22:29:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 18058 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 65213C3220 for ; Wed, 28 Dec 2022 22:30:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 79905625DA; Wed, 28 Dec 2022 23:30:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1672266622; bh=mdNLrM37PI0D7ObVE2l8aYpp1/ZKGb0nAzRZE/FtT/U=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Rl6+nQgd2b9z240CPA2qrG9XJJ8Of81S0jNUJeYuUfQ3hM4CNxTd7lNn6Ogjw+8cq djb+m29fEP5l5XvSGvW1iFFOwM+amfHr9/wh6P/n9QtAq9Xtl/9/XBlNGrOb9pUsWp oDaVX7XD4Ikhocw7WsFEmB0KF3jJCzXbYS39AZwcsdQcyUqt4cFZPySvM8M21HCtHq IGgYcdHw5b7PHt4aWul3MLK9xdcTaIxudysy8utBA/7/dV25fxP8zb+jHiZAljyjLl 1qhXp62qTXCR5v2HhrSCM3LTO7EyaKglu8BVxPovyh+tjrJhqHA56T5BlLYyEhoKvU R/kbEsoh5zH2w== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E69F661F13 for ; Wed, 28 Dec 2022 23:30:18 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="wpbj1XKc"; dkim-atps=neutral Received: from pyrite.mediacom.info (unknown [IPv6:2604:2d80:ad8a:9000:1bf9:855b:22de:3645]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7649F109; Wed, 28 Dec 2022 23:30:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1672266618; bh=mdNLrM37PI0D7ObVE2l8aYpp1/ZKGb0nAzRZE/FtT/U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wpbj1XKc1XPnCDbfVo1NDPeWsyAC535yxfBpjM/+XOTF0QokjSoPY2sqUtDtLEBMG DZF+EaGiqb4VRExwCKFrSI8O10SOnT7PnqarmB8YuRbHvNnst/Z4eX9Rdf3btDZ3yP Ll1UFRY6Zu1/ICVcRolQ8OTCNYaYwKE8AylHXC/Y= To: libcamera-devel@lists.libcamera.org Date: Wed, 28 Dec 2022 16:29:46 -0600 Message-Id: <20221228223003.2265712-3-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221228223003.2265712-1-paul.elder@ideasonboard.com> References: <20221228223003.2265712-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v10 02/19] libcamera: property: Add MinimumRequests property X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Paul Elder via libcamera-devel From: Paul Elder Reply-To: Paul Elder Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: NĂ­colas F. R. A. Prado The MinimumRequests property reports the minimum number of capture requests that the camera pipeline requires to have queued in order to sustain capture operations without frame drops. At this quantity, there's no guarantee that manual per-frame controls will apply correctly. The quantity needed for that may be added as a separate property in the future. Signed-off-by: NĂ­colas F. R. A. Prado Reviewed-by: Laurent Pinchart Reviewed-by: Paul Elder Signed-off-by: Paul Elder Acked-by: Umang Jain --- Changes in v10: - ipu3: add a constant to populate MinimumRequests, as we'll also use it elsewhere - update pipeline handler guide to set vivid' MinimumRequests to 2 - expand the MinimumRequests property description to include a line about startup - add isi Changes in v9: - rebased Changes in v8: - Changed the MinimumRequests property meaning to require that frames aren't dropped - Set MinimumRequests on SimplePipeline depending on device and usage of converter - Undid definition of default MinimumRequests on CameraSensor constructor - Updated pipeline-handler guides with new MinimumRequests property Changes in v7: - Renamed property from MinNumRequests to MinimumRequests - Changed MinimumRequests property's description Changes in v6: - Removed comment from Raspberrypi MinNumRequests setting - Removed an extra blank line --- Documentation/guides/pipeline-handler.rst | 20 +++++++--- src/libcamera/pipeline/imx8-isi/imx8-isi.cpp | 2 + src/libcamera/pipeline/ipu3/ipu3.cpp | 4 ++ .../pipeline/raspberrypi/raspberrypi.cpp | 2 + src/libcamera/pipeline/rkisp1/rkisp1.cpp | 2 + src/libcamera/pipeline/simple/simple.cpp | 40 +++++++++++++++++-- src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 2 + src/libcamera/pipeline/vimc/vimc.cpp | 2 + src/libcamera/property_ids.yaml | 22 ++++++++++ 9 files changed, 87 insertions(+), 9 deletions(-) diff --git a/Documentation/guides/pipeline-handler.rst b/Documentation/guides/pipeline-handler.rst index e1930fdf..bfa87faa 100644 --- a/Documentation/guides/pipeline-handler.rst +++ b/Documentation/guides/pipeline-handler.rst @@ -658,19 +658,29 @@ associated with immutable values, which represent static characteristics that ca be used by applications to identify camera devices in the system. Properties can be registered by inspecting the values of V4L2 controls from the video devices and camera sensor (for example to retrieve the position and orientation of a camera) -or to express other immutable characteristics. The example pipeline handler does -not register any property, but examples are available in the libcamera code -base. +or to express other immutable characteristics. -.. TODO: Add a property example to the pipeline handler. At least the model. +A required property is ``MinimumRequests``, which indicates how many requests +need to be queued in the pipeline for capture without frame drops to be +possible. + +In our case, the vivid driver requires two buffers before it'll start streaming +(can be seen in the ``min_buffers_needed`` property for the ``vid_cap`` queue in +vivid's driver code). Therefore we will set our ``MinimumRequests`` to two. +Append the following line to ``init()``: + +.. code-block:: cpp + + properties_.set(properties::MinimumRequests, 2); At this point you need to add the following includes to the top of the file for -handling controls: +handling controls and properties: .. code-block:: cpp #include #include + #include Generating a default configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp b/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp index 0c67e35d..9e1063d0 100644 --- a/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp +++ b/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include "libcamera/internal/bayer_format.h" @@ -170,6 +171,7 @@ int ISICameraData::init() return ret; properties_ = sensor_->properties(); + properties_.set(properties::MinimumRequests, 2); return 0; } diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index e4d79ea4..dd7df136 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -169,6 +169,8 @@ private: MediaDevice *imguMediaDev_; std::vector ipaBuffers_; + + static constexpr unsigned int kMinimumRequests = 3; }; IPU3CameraConfiguration::IPU3CameraConfiguration(IPU3CameraData *data) @@ -1126,6 +1128,8 @@ int PipelineHandlerIPU3::registerCameras() /* Initialize the camera properties. */ data->properties_ = cio2->sensor()->properties(); + data->properties_.set(properties::MinimumRequests, kMinimumRequests); + ret = initControls(data.get()); if (ret) continue; diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 8569df17..4a08d01e 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -1063,6 +1063,8 @@ int PipelineHandlerRPi::start(Camera *camera, const ControlList *controls) /* Enable SOF event generation. */ data->unicam_[Unicam::Image].dev()->setFrameStartEnabled(true); + data->properties_.set(properties::MinimumRequests, 3); + /* * Reset the delayed controls with the gain and exposure values set by * the IPA. diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 5bdb4d25..76f59f2e 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -1103,6 +1104,7 @@ int PipelineHandlerRkISP1::createCamera(MediaEntity *sensor) /* Initialize the camera properties. */ data->properties_ = data->sensor_->properties(); + data->properties_.set(properties::MinimumRequests, 3); /* * \todo Read dealy values from the sensor itself or from a diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index 24ded4db..8ed983fe 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -180,6 +181,10 @@ class SimplePipelineHandler; struct SimplePipelineInfo { const char *driver; + /* + * Minimum number of buffers required by the driver to start streaming. + */ + unsigned int minimumBuffers; /* * Each converter in the list contains the name * and the number of streams it supports. @@ -190,10 +195,10 @@ struct SimplePipelineInfo { namespace { static const SimplePipelineInfo supportedDevices[] = { - { "imx7-csi", { { "pxp", 1 } } }, - { "mxc-isi", {} }, - { "qcom-camss", {} }, - { "sun6i-csi", {} }, + { "imx7-csi", 2, { { "pxp", 1 } } }, + { "mxc-isi", 3, {} }, + { "qcom-camss", 1, {} }, + { "sun6i-csi", 3, {} }, }; } /* namespace */ @@ -271,6 +276,8 @@ public: bool useConverter_; std::queue> converterQueue_; + const SimplePipelineInfo *deviceInfo; + private: void tryPipeline(unsigned int code, const Size &size); static std::vector routedSourcePads(MediaPad *sink); @@ -1168,6 +1175,29 @@ int SimplePipelineHandler::configure(Camera *camera, CameraConfiguration *c) inputCfg.stride = captureFormat.planes[0].bpl; inputCfg.bufferCount = kNumInternalBuffers; + /* Set the MinimumRequests property. */ + unsigned int minimumRequests; + + if (data->useConverter_) { + /* + * The application will interact only with the capture node of + * the converter. Require two buffers for a frame drop free + * conversion, plus one extra to account for requeue delays. + */ + minimumRequests = 3; + } else { + /* + * The application will interact directly with the video capture + * device. Require the minimum required by the driver, plus one + * extra to account for requeue delays. Force at least three + * buffers in order to not drop frames. + */ + minimumRequests = std::max(data->deviceInfo->minimumBuffers + 1, + 3U); + } + + data->properties_.set(properties::MinimumRequests, minimumRequests); + return data->converter_->configure(inputCfg, outputCfgs); } @@ -1506,6 +1536,8 @@ bool SimplePipelineHandler::match(DeviceEnumerator *enumerator) bool registered = false; for (std::unique_ptr &data : pipelines) { + data->deviceInfo = info; + int ret = data->init(); if (ret < 0) continue; diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp index 277465b7..7f580955 100644 --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp @@ -500,6 +500,8 @@ int UVCCameraData::init(MediaDevice *media) properties_.set(properties::PixelArraySize, resolution); properties_.set(properties::PixelArrayActiveAreas, { Rectangle(resolution) }); + properties_.set(properties::MinimumRequests, 3); + /* Initialise the supported controls. */ ControlInfoMap::Map ctrls; diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp index 204f5ad7..d2633be4 100644 --- a/src/libcamera/pipeline/vimc/vimc.cpp +++ b/src/libcamera/pipeline/vimc/vimc.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -571,6 +572,7 @@ int VimcCameraData::init() /* Initialize the camera properties. */ properties_ = sensor_->properties(); + properties_.set(properties::MinimumRequests, 3); return 0; } diff --git a/src/libcamera/property_ids.yaml b/src/libcamera/property_ids.yaml index cb55e0ed..cc0decdc 100644 --- a/src/libcamera/property_ids.yaml +++ b/src/libcamera/property_ids.yaml @@ -690,6 +690,28 @@ controls: that is twice that of the full resolution mode. This value will be valid after the configure method has returned successfully. + - MinimumRequests: + type: int32_t + description: | + The minimum number of capture requests that the camera pipeline requires + to have queued in order to sustain capture operations without frame + drops. At this quantity, there's no guarantee that manual per-frame + controls will apply correctly. This is also the minimum number of + requests that must be queued before capture starts. + + This property is based on the minimum number of memory buffers + needed to fill the capture pipeline composed of hardware processing + blocks plus as many buffers as needed to take into account propagation + delays and avoid dropping frames. + + \todo Should this be a per-stream property? + + \todo Extend this property to expose the different minimum buffer and + request counts (the minimum number of buffers to be able to capture at + all, the minimum number of buffers to sustain capture without frame + drop, and the minimum number of requests to ensure proper operation of + per-frame controls). + # ---------------------------------------------------------------------------- # Draft properties section