From patchwork Tue Mar 16 15:52:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marian Cichy X-Patchwork-Id: 11595 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 BFCECBD80C for ; Tue, 16 Mar 2021 15:52:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5D5EE68D4F; Tue, 16 Mar 2021 16:52:32 +0100 (CET) Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C84BA68D4E for ; Tue, 16 Mar 2021 16:52:27 +0100 (CET) Received: from dude02.hi.pengutronix.de ([2001:67c:670:100:1d::28]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lMBzf-0000V4-1E; Tue, 16 Mar 2021 16:52:27 +0100 Received: from mci by dude02.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1lMBze-0003Dl-Iz; Tue, 16 Mar 2021 16:52:26 +0100 From: Marian Cichy To: libcamera-devel@lists.libcamera.org Date: Tue, 16 Mar 2021 16:52:09 +0100 Message-Id: <20210316155211.6679-5-m.cichy@pengutronix.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210316155211.6679-1-m.cichy@pengutronix.de> References: <20210316155211.6679-1-m.cichy@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::28 X-SA-Exim-Mail-From: mci@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: libcamera-devel@lists.libcamera.org Subject: [libcamera-devel] [RFC PATCH 4/6] pipeline: simple: Propagate frame interval through pipeline 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: , Cc: graphics@pengutronix.de, Marian Cichy Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" By propagating the frame interval from the sensor to the camera interface, userspace applications can query the frame interval there. This is useful for example with the gstreamer libcamerasrc, which can integrate this information into the Gstreamer pipeline, which is a valuable information for other elements. Signed-off-by: Marian Cichy --- src/libcamera/pipeline/simple/simple.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index d7128156..296412e2 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -182,6 +182,7 @@ public: std::vector> converterBuffers_; bool useConverter_; std::queue> converterQueue_; + Fraction frameInterval_; }; class SimpleCameraConfiguration : public CameraConfiguration @@ -458,6 +459,7 @@ int SimpleCameraData::setupFormats(V4L2SubdeviceFormat *format, V4L2Subdevice::Whence whence) { SimplePipelineHandler *pipe = static_cast(pipe_); + Fraction frameInterval; int ret; /* @@ -478,6 +480,14 @@ int SimpleCameraData::setupFormats(V4L2SubdeviceFormat *format, ret = subdev->getFormat(source->index(), format, whence); if (ret < 0) return ret; + } else { + V4L2Subdevice *subdev = pipe->subdev(source->entity()); + ret = subdev->getFrameInterval(source->index(), &frameInterval); + if (ret < 0) + LOG(SimplePipeline, Debug) << "Getting frame interval from sensor failed"; + else + LOG(SimplePipeline, Debug) << "Sensor frame interval: " + << frameInterval.toString(); } if (sink->entity()->function() != MEDIA_ENT_F_IO_V4L) { @@ -488,6 +498,18 @@ int SimpleCameraData::setupFormats(V4L2SubdeviceFormat *format, if (ret < 0) return ret; + /* set frameinterval on all subdevs if we got one from the sensor */ + if (frameInterval.numerator != 0 && frameInterval.denominator != 0) { + ret = subdev->setFrameInterval(sink->index(), &frameInterval); + if (ret == 0) { + LOG(SimplePipeline, Debug) << "Set frame interval: " + << frameInterval.toString(); + /* Always remember the last frame interval we successfully + * set, as this determines the final frame interval at the end */ + frameInterval_ = frameInterval; + } + } + if (format->mbus_code != sourceFormat.mbus_code || format->size != sourceFormat.size) { LOG(SimplePipeline, Debug) @@ -668,6 +690,7 @@ CameraConfiguration *SimplePipelineHandler::generateConfiguration(Camera *camera StreamConfiguration cfg{ StreamFormats{ formats } }; cfg.pixelFormat = formats.begin()->first; cfg.size = formats.begin()->second[0].max; + cfg.frameInterval = data->frameInterval_; config->addConfiguration(cfg); }