From e4cee8eec2d34c675b502a71f234ba8ad99db7cd Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 20 Nov 2023 17:51:27 +0100 Subject: [PATCH] libcamera: add latency param query JACK queries this unconditionally but it's a good idea to implement this like v4l2-source. --- spa/plugins/libcamera/libcamera-source.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/spa/plugins/libcamera/libcamera-source.cpp b/spa/plugins/libcamera/libcamera-source.cpp index 8a08dca2c..3d9273419 100644 --- a/spa/plugins/libcamera/libcamera-source.cpp +++ b/spa/plugins/libcamera/libcamera-source.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -96,7 +97,8 @@ struct port { #define PORT_IO 3 #define PORT_Format 4 #define PORT_Buffers 5 -#define N_PORT_PARAMS 6 +#define PORT_Latency 6 +#define N_PORT_PARAMS 7 struct spa_param_info params[N_PORT_PARAMS]; uint32_t fmt_index = 0; @@ -114,6 +116,7 @@ struct port { params[PORT_IO] = SPA_PARAM_INFO(SPA_PARAM_IO, SPA_PARAM_INFO_READ); params[PORT_Format] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_WRITE); params[PORT_Buffers] = SPA_PARAM_INFO(SPA_PARAM_Buffers, 0); + params[PORT_Latency] = SPA_PARAM_INFO(SPA_PARAM_Latency, SPA_PARAM_INFO_READ); info.flags = SPA_PORT_FLAG_LIVE | SPA_PORT_FLAG_PHYSICAL | SPA_PORT_FLAG_TERMINAL; info.params = params; @@ -152,6 +155,8 @@ struct impl { struct spa_io_position *position = nullptr; struct spa_io_clock *clock = nullptr; + struct spa_latency_info latency[2]; + std::shared_ptr manager; std::shared_ptr camera; @@ -601,6 +606,15 @@ next: return 0; } break; + case SPA_PARAM_Latency: + switch (result.index) { + case 0: case 1: + param = spa_latency_build(&b, id, &impl->latency[result.index]); + break; + default: + return 0; + } + break; default: return -ENOENT; } @@ -961,6 +975,9 @@ impl::impl(spa_log *log, spa_loop *data_loop, spa_system *system, info.flags = SPA_NODE_FLAG_RT; info.params = params; info.n_params = N_NODE_PARAMS; + + latency[SPA_DIRECTION_INPUT] = SPA_LATENCY_INFO(SPA_DIRECTION_INPUT); + latency[SPA_DIRECTION_OUTPUT] = SPA_LATENCY_INFO(SPA_DIRECTION_OUTPUT); } static size_t