[libcamera-devel] [PATCH 3/3] gst: utils: Add framerate to caps

Marian Cichy m.cichy at pengutronix.de
Mon Mar 22 11:42:42 CET 2021


Access the frame duration from the controlList of the stream
configuration and convert it to values fitting for GST_FRACTION. By
setting the frame rate to the caps configuration, the Gstreamer pipeline
has information about the camera frame rate, which can be potentially
used for more efficient memory allocation or for debug purposes.

Signed-off-by: Marian Cichy <m.cichy at pengutronix.de>
---
 src/gstreamer/gstlibcamera-utils.cpp | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/gstreamer/gstlibcamera-utils.cpp b/src/gstreamer/gstlibcamera-utils.cpp
index 5381dca5..fdd8b85c 100644
--- a/src/gstreamer/gstlibcamera-utils.cpp
+++ b/src/gstreamer/gstlibcamera-utils.cpp
@@ -8,6 +8,7 @@
 
 #include "gstlibcamera-utils.h"
 
+#include <libcamera/control_ids.h>
 #include <libcamera/formats.h>
 
 using namespace libcamera;
@@ -128,10 +129,16 @@ gst_libcamera_stream_configuration_to_caps(const StreamConfiguration &stream_cfg
 {
 	GstCaps *caps = gst_caps_new_empty();
 	GstStructure *s = bare_structure_from_format(stream_cfg.pixelFormat);
+	int numerator;
+	int denominator;
+	double framerate = 1'000'000 / static_cast<double>(stream_cfg.controls.get(
+				controls::FrameDurations)[0]);
 
+	gst_util_double_to_fraction(framerate, &numerator, &denominator);
 	gst_structure_set(s,
 			  "width", G_TYPE_INT, stream_cfg.size.width,
 			  "height", G_TYPE_INT, stream_cfg.size.height,
+			  "framerate", GST_TYPE_FRACTION, numerator, denominator,
 			  nullptr);
 	gst_caps_append_structure(caps, s);
 
-- 
2.29.2



More information about the libcamera-devel mailing list