PipeWire: spa/param/latency-utils.h Source File

PipeWire 1.4.9

Loading...
Searching...
No Matches
latency-utils.h
Go to the documentation of this file.
1/* Simple Plugin API */
2/* SPDX-FileCopyrightText: Copyright © 2021 Wim Taymans */
3/* SPDX-License-Identifier: MIT */
4
5#ifndef SPA_PARAM_LATENCY_UTILS_H
6#define SPA_PARAM_LATENCY_UTILS_H
7
8#ifdef __cplusplus
9extern "C" {
10#endif
11
16
17#include <float.h>
18
19#include <spa/pod/builder.h>
20#include <spa/pod/parser.h>
21#include <spa/param/latency.h>
22
23#ifndef SPA_API_LATENCY_UTILS
24 #ifdef SPA_API_IMPL
25 #define SPA_API_LATENCY_UTILS SPA_API_IMPL
26 #else
27 #define SPA_API_LATENCY_UTILS static inline
28 #endif
29#endif
30
31 SPA_API_LATENCY_UTILS int
32 spa_latency_info_compare(const struct spa_latency_info *a, const struct spa_latency_info *b)
33{
34 if (a->min_quantum == b->min_quantum &&
35 a->max_quantum == b->max_quantum &&
36 a->min_rate == b->min_rate &&
37 a->max_rate == b->max_rate &&
38 a->min_ns == b->min_ns &&
39 a->max_ns == b->max_ns)
40 return 0;
41 return 1;
42}
43
44 SPA_API_LATENCY_UTILS void
45 spa_latency_info_combine_start(struct spa_latency_info *info, enum spa_direction direction)
46{
47 *info = SPA_LATENCY_INFO(direction,
48 .min_quantum = FLT_MAX,
49 .max_quantum = FLT_MIN,
50 .min_rate = INT32_MAX,
51 .max_rate = INT32_MIN,
52 .min_ns = INT64_MAX,
53 .max_ns = INT64_MIN);
54}
55 SPA_API_LATENCY_UTILS void
56 spa_latency_info_combine_finish(struct spa_latency_info *info)
57{
58 if (info->min_quantum == FLT_MAX)
59 info->min_quantum = 0;
60 if (info->max_quantum == FLT_MIN)
61 info->max_quantum = 0;
62 if (info->min_rate == INT32_MAX)
63 info->min_rate = 0;
64 if (info->max_rate == INT32_MIN)
65 info->max_rate = 0;
66 if (info->min_ns == INT64_MAX)
67 info->min_ns = 0;
68 if (info->max_ns == INT64_MIN)
69 info->max_ns = 0;
70}
71
72 SPA_API_LATENCY_UTILS int
73 spa_latency_info_combine(struct spa_latency_info *info, const struct spa_latency_info *other)
74{
75 if (info->direction != other->direction)
76 return -EINVAL;
77 if (other->min_quantum < info->min_quantum)
78 info->min_quantum = other->min_quantum;
79 if (other->max_quantum > info->max_quantum)
80 info->max_quantum = other->max_quantum;
81 if (other->min_rate < info->min_rate)
82 info->min_rate = other->min_rate;
83 if (other->max_rate > info->max_rate)
84 info->max_rate = other->max_rate;
85 if (other->min_ns < info->min_ns)
86 info->min_ns = other->min_ns;
87 if (other->max_ns > info->max_ns)
88 info->max_ns = other->max_ns;
89 return 0;
90}
91
92 SPA_API_LATENCY_UTILS int
93 spa_latency_parse(const struct spa_pod *latency, struct spa_latency_info *info)
94{
95 int res;
96 spa_zero(*info);
97 if ((res = spa_pod_parse_object(latency,
98 SPA_TYPE_OBJECT_ParamLatency, NULL,
99 SPA_PARAM_LATENCY_direction, SPA_POD_Id(&info->direction),
100 SPA_PARAM_LATENCY_minQuantum, SPA_POD_OPT_Float(&info->min_quantum),
101 SPA_PARAM_LATENCY_maxQuantum, SPA_POD_OPT_Float(&info->max_quantum),
102 SPA_PARAM_LATENCY_minRate, SPA_POD_OPT_Int(&info->min_rate),
103 SPA_PARAM_LATENCY_maxRate, SPA_POD_OPT_Int(&info->max_rate),
104 SPA_PARAM_LATENCY_minNs, SPA_POD_OPT_Long(&info->min_ns),
105 SPA_PARAM_LATENCY_maxNs, SPA_POD_OPT_Long(&info->max_ns))) < 0)
106 return res;
107 info->direction = (enum spa_direction)(info->direction & 1);
108 return 0;
109}
110
111 SPA_API_LATENCY_UTILS struct spa_pod *
112 spa_latency_build(struct spa_pod_builder *builder, uint32_t id, const struct spa_latency_info *info)
113{
114 return (struct spa_pod *)spa_pod_builder_add_object(builder,
115 SPA_TYPE_OBJECT_ParamLatency, id,
116 SPA_PARAM_LATENCY_direction, SPA_POD_Id(info->direction),
117 SPA_PARAM_LATENCY_minQuantum, SPA_POD_Float(info->min_quantum),
118 SPA_PARAM_LATENCY_maxQuantum, SPA_POD_Float(info->max_quantum),
119 SPA_PARAM_LATENCY_minRate, SPA_POD_Int(info->min_rate),
120 SPA_PARAM_LATENCY_maxRate, SPA_POD_Int(info->max_rate),
121 SPA_PARAM_LATENCY_minNs, SPA_POD_Long(info->min_ns),
122 SPA_PARAM_LATENCY_maxNs, SPA_POD_Long(info->max_ns));
123}
124
125 SPA_API_LATENCY_UTILS int
126 spa_process_latency_parse(const struct spa_pod *latency, struct spa_process_latency_info *info)
127{
128 int res;
129 spa_zero(*info);
130 if ((res = spa_pod_parse_object(latency,
131 SPA_TYPE_OBJECT_ParamProcessLatency, NULL,
132 SPA_PARAM_PROCESS_LATENCY_quantum, SPA_POD_OPT_Float(&info->quantum),
133 SPA_PARAM_PROCESS_LATENCY_rate, SPA_POD_OPT_Int(&info->rate),
134 SPA_PARAM_PROCESS_LATENCY_ns, SPA_POD_OPT_Long(&info->ns))) < 0)
135 return res;
136 return 0;
137}
138
139 SPA_API_LATENCY_UTILS struct spa_pod *
140 spa_process_latency_build(struct spa_pod_builder *builder, uint32_t id,
141 const struct spa_process_latency_info *info)
142{
143 return (struct spa_pod *)spa_pod_builder_add_object(builder,
144 SPA_TYPE_OBJECT_ParamProcessLatency, id,
145 SPA_PARAM_PROCESS_LATENCY_quantum, SPA_POD_Float(info->quantum),
146 SPA_PARAM_PROCESS_LATENCY_rate, SPA_POD_Int(info->rate),
147 SPA_PARAM_PROCESS_LATENCY_ns, SPA_POD_Long(info->ns));
148}
149
150 SPA_API_LATENCY_UTILS int
151 spa_process_latency_info_add(const struct spa_process_latency_info *process,
152 struct spa_latency_info *info)
153{
154 info->min_quantum += process->quantum;
155 info->max_quantum += process->quantum;
156 info->min_rate += process->rate;
157 info->max_rate += process->rate;
158 info->min_ns += process->ns;
159 info->max_ns += process->ns;
160 return 0;
161}
162
163 SPA_API_LATENCY_UTILS int
164 spa_process_latency_info_compare(const struct spa_process_latency_info *a,
165 const struct spa_process_latency_info *b)
166{
167 if (a->quantum == b->quantum &&
168 a->rate == b->rate &&
169 a->ns == b->ns)
170 return 0;
171 return 1;
172}
173
177
178#ifdef __cplusplus
179} /* extern "C" */
180#endif
181
182#endif /* SPA_PARAM_LATENCY_UTILS_H */
builder.h
spa/pod/builder.h
res
uint32_t int int res
Definition core.h:433
spa_latency_build
SPA_API_LATENCY_UTILS struct spa_pod * spa_latency_build(struct spa_pod_builder *builder, uint32_t id, const struct spa_latency_info *info)
Definition latency-utils.h:119
spa_latency_info_combine_finish
SPA_API_LATENCY_UTILS void spa_latency_info_combine_finish(struct spa_latency_info *info)
Definition latency-utils.h:63
spa_process_latency_info_add
SPA_API_LATENCY_UTILS int spa_process_latency_info_add(const struct spa_process_latency_info *process, struct spa_latency_info *info)
Definition latency-utils.h:158
spa_latency_info_combine
SPA_API_LATENCY_UTILS int spa_latency_info_combine(struct spa_latency_info *info, const struct spa_latency_info *other)
Definition latency-utils.h:80
spa_process_latency_parse
SPA_API_LATENCY_UTILS int spa_process_latency_parse(const struct spa_pod *latency, struct spa_process_latency_info *info)
Definition latency-utils.h:133
SPA_LATENCY_INFO
#define SPA_LATENCY_INFO(dir,...)
Definition latency.h:65
spa_process_latency_info_compare
SPA_API_LATENCY_UTILS int spa_process_latency_info_compare(const struct spa_process_latency_info *a, const struct spa_process_latency_info *b)
Definition latency-utils.h:171
spa_process_latency_build
SPA_API_LATENCY_UTILS struct spa_pod * spa_process_latency_build(struct spa_pod_builder *builder, uint32_t id, const struct spa_process_latency_info *info)
Definition latency-utils.h:147
SPA_API_LATENCY_UTILS
#define SPA_API_LATENCY_UTILS
Definition latency-utils.h:34
spa_latency_info_compare
SPA_API_LATENCY_UTILS int spa_latency_info_compare(const struct spa_latency_info *a, const struct spa_latency_info *b)
Definition latency-utils.h:39
spa_latency_parse
SPA_API_LATENCY_UTILS int spa_latency_parse(const struct spa_pod *latency, struct spa_latency_info *info)
Definition latency-utils.h:100
spa_latency_info_combine_start
SPA_API_LATENCY_UTILS void spa_latency_info_combine_start(struct spa_latency_info *info, enum spa_direction direction)
Definition latency-utils.h:52
SPA_PARAM_PROCESS_LATENCY_rate
@ SPA_PARAM_PROCESS_LATENCY_rate
latency (Int) relative to graph rate
Definition latency.h:76
SPA_PARAM_PROCESS_LATENCY_ns
@ SPA_PARAM_PROCESS_LATENCY_ns
latency (Long) in nanoseconds
Definition latency.h:77
SPA_PARAM_PROCESS_LATENCY_quantum
@ SPA_PARAM_PROCESS_LATENCY_quantum
latency relative to quantum (Float)
Definition latency.h:75
SPA_PARAM_LATENCY_maxNs
@ SPA_PARAM_LATENCY_maxNs
max latency (Long) in nanoseconds
Definition latency.h:50
SPA_PARAM_LATENCY_minRate
@ SPA_PARAM_LATENCY_minRate
min latency (Int) relative to graph rate
Definition latency.h:47
SPA_PARAM_LATENCY_minQuantum
@ SPA_PARAM_LATENCY_minQuantum
min latency relative to quantum (Float)
Definition latency.h:45
SPA_PARAM_LATENCY_maxRate
@ SPA_PARAM_LATENCY_maxRate
max latency (Int) relative to graph rate
Definition latency.h:48
SPA_PARAM_LATENCY_maxQuantum
@ SPA_PARAM_LATENCY_maxQuantum
max latency relative to quantum (Float)
Definition latency.h:46
SPA_PARAM_LATENCY_direction
@ SPA_PARAM_LATENCY_direction
direction, input/output (Id enum spa_direction)
Definition latency.h:44
SPA_PARAM_LATENCY_minNs
@ SPA_PARAM_LATENCY_minNs
min latency (Long) in nanoseconds
Definition latency.h:49
SPA_POD_OPT_Float
#define SPA_POD_OPT_Float(val)
Definition parser.h:536
SPA_POD_Long
#define SPA_POD_Long(val)
Definition vararg.h:65
SPA_POD_Id
#define SPA_POD_Id(val)
Definition vararg.h:49
SPA_POD_OPT_Int
#define SPA_POD_OPT_Int(val)
Definition parser.h:532
spa_pod_builder_add_object
#define spa_pod_builder_add_object(b, type, id,...)
Definition builder.h:703
SPA_POD_Float
#define SPA_POD_Float(val)
Definition vararg.h:76
spa_pod_parse_object
#define spa_pod_parse_object(pod, type, id,...)
Definition parser.h:586
SPA_POD_Int
#define SPA_POD_Int(val)
Definition vararg.h:54
SPA_POD_OPT_Long
#define SPA_POD_OPT_Long(val)
Definition parser.h:534
SPA_TYPE_OBJECT_ParamLatency
@ SPA_TYPE_OBJECT_ParamLatency
Definition type.h:95
SPA_TYPE_OBJECT_ParamProcessLatency
@ SPA_TYPE_OBJECT_ParamProcessLatency
Definition type.h:96
spa_zero
#define spa_zero(x)
Definition defs.h:508
spa_direction
spa_direction
Definition defs.h:106
latency.h
spa/param/latency.h
parser.h
spa/pod/parser.h
spa_latency_info
helper structure for managing latency objects
Definition latency.h:54
spa_latency_info::min_rate
int32_t min_rate
Definition latency.h:58
spa_latency_info::min_ns
int64_t min_ns
Definition latency.h:60
spa_latency_info::max_rate
int32_t max_rate
Definition latency.h:59
spa_latency_info::direction
enum spa_direction direction
Definition latency.h:55
spa_latency_info::max_quantum
float max_quantum
Definition latency.h:57
spa_latency_info::min_quantum
float min_quantum
Definition latency.h:56
spa_latency_info::max_ns
int64_t max_ns
Definition latency.h:61
spa_pod_builder
Definition builder.h:63
spa_pod
Definition pod.h:43
spa_process_latency_info
Helper structure for managing process latency objects.
Definition latency.h:81
spa_process_latency_info::ns
int64_t ns
Definition latency.h:84
spa_process_latency_info::quantum
float quantum
Definition latency.h:82
spa_process_latency_info::rate
int32_t rate
Definition latency.h:83