PipeWire  0.3.33
latency-utils.h
Go to the documentation of this file.
1 /* Simple Plugin API
2  *
3  * Copyright © 2021 Wim Taymans
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24 
25 #ifndef SPA_PARAM_LATENCY_UTILS_H
26 #define SPA_PARAM_LATENCY_UTILS_H
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 
33 #include <spa/pod/builder.h>
34 #include <spa/pod/parser.h>
35 #include <spa/param/param.h>
36 
39  float min_quantum;
40  float max_quantum;
41  uint32_t min_rate;
42  uint32_t max_rate;
43  uint64_t min_ns;
44  uint64_t max_ns;
45 };
46 
47 #define SPA_LATENCY_INFO(dir,...) (struct spa_latency_info) { .direction = (dir), ## __VA_ARGS__ }
48 
49 /* static */ inline int
51 {
52  if (a->min_quantum == b->min_quantum &&
53  a->max_quantum == b->max_quantum &&
54  a->min_rate == b->min_rate &&
55  a->max_rate == b->max_rate &&
56  a->min_ns == b->min_ns &&
57  a->max_ns == b->max_ns)
58  return 0;
59  return 1;
60 }
61 
62 /* static */ inline int
64 {
65  if (info->direction != other->direction)
66  return -EINVAL;
67  if (info->min_quantum == 0.0f || other->min_quantum < info->min_quantum)
68  info->min_quantum = other->min_quantum;
69  if (other->max_quantum > info->max_quantum)
70  info->max_quantum = other->max_quantum;
71  if (info->min_rate == 0U || other->min_rate < info->min_rate)
72  info->min_rate = other->min_rate;
73  if (other->max_rate > info->max_rate)
74  info->max_rate = other->max_rate;
75  if (info->min_ns == 0UL || other->min_ns < info->min_ns)
76  info->min_ns = other->min_ns;
77  if (other->max_ns > info->max_ns)
78  info->max_ns = other->max_ns;
79  return 0;
80 }
81 
82 /* static */ inline int
83 spa_latency_parse(const struct spa_pod *latency, struct spa_latency_info *info)
84 {
85  int res;
86  spa_zero(*info);
87  if ((res = spa_pod_parse_object(latency,
96  return res;
97  info->direction = (enum spa_direction)(info->direction & 1);
98  return 0;
99 }
100 
101 /* static */ inline struct spa_pod *
102 spa_latency_build(struct spa_pod_builder *builder, uint32_t id, const struct spa_latency_info *info)
103 {
104  return (struct spa_pod *)spa_pod_builder_add_object(builder,
113 }
114 
116  float quantum;
117  uint32_t rate;
118  uint64_t ns;
119 };
120 
121 #define SPA_PROCESS_LATENCY_INFO_INIT(...) (struct spa_process_latency_info) { __VA_ARGS__ }
122 
123 /* static */ inline int
124 spa_process_latency_parse(const struct spa_pod *latency, struct spa_process_latency_info *info)
125 {
126  int res;
127  spa_zero(*info);
128  if ((res = spa_pod_parse_object(latency,
133  return res;
134  return 0;
135 }
136 
137 /* static */ inline struct spa_pod *
138 spa_process_latency_build(struct spa_pod_builder *builder, uint32_t id,
139  const struct spa_process_latency_info *info)
140 {
141  return (struct spa_pod *)spa_pod_builder_add_object(builder,
146 }
147 
148 /* static */ inline int
150  struct spa_latency_info *info)
151 {
152  info->min_quantum += process->quantum;
153  info->max_quantum += process->quantum;
154  info->min_rate += process->rate;
155  info->max_rate += process->rate;
156  info->min_ns += process->ns;
157  info->max_ns += process->ns;
158  return 0;
159 }
160 
161 #ifdef __cplusplus
162 } /* extern "C" */
163 #endif
164 
165 #endif /* SPA_PARAM_LATENCY_UTILS_H */
SPA_PARAM_PROCESS_LATENCY_ns
@ SPA_PARAM_PROCESS_LATENCY_ns
latency (Long) in nanoseconds
Definition: param.h:194
SPA_POD_Float
#define SPA_POD_Float(val)
Definition: vararg.h:71
spa_latency_info::max_rate
uint32_t max_rate
Definition: latency-utils.h:42
SPA_PARAM_LATENCY_minQuantum
@ SPA_PARAM_LATENCY_minQuantum
min latency relative to quantum (Float)
Definition: param.h:181
spa_direction
spa_direction
Definition: defs.h:78
spa_latency_info::direction
enum spa_direction direction
Definition: latency-utils.h:38
SPA_PARAM_LATENCY_minNs
@ SPA_PARAM_LATENCY_minNs
min latency (Long) in nanoseconds
Definition: param.h:185
spa_latency_info_combine
int spa_latency_info_combine(struct spa_latency_info *info, const struct spa_latency_info *other)
Definition: latency-utils.h:63
SPA_POD_Int
#define SPA_POD_Int(val)
Definition: vararg.h:59
spa_zero
#define spa_zero(x)
Definition: defs.h:303
spa_latency_info::max_ns
uint64_t max_ns
Definition: latency-utils.h:44
spa_latency_info
Definition: latency-utils.h:37
spa_latency_info_compare
int spa_latency_info_compare(const struct spa_latency_info *a, struct spa_latency_info *b)
Definition: latency-utils.h:50
spa_latency_parse
int spa_latency_parse(const struct spa_pod *latency, struct spa_latency_info *info)
Definition: latency-utils.h:83
SPA_POD_OPT_Float
#define SPA_POD_OPT_Float(val)
Definition: parser.h:523
SPA_PARAM_LATENCY_direction
@ SPA_PARAM_LATENCY_direction
direction, input/output (Id enum spa_direction)
Definition: param.h:180
spa_latency_info::min_rate
uint32_t min_rate
Definition: latency-utils.h:41
spa_latency_info::max_quantum
float max_quantum
Definition: latency-utils.h:40
SPA_PARAM_LATENCY_maxRate
@ SPA_PARAM_LATENCY_maxRate
max latency (Int) relative to rate
Definition: param.h:184
SPA_PARAM_PROCESS_LATENCY_rate
@ SPA_PARAM_PROCESS_LATENCY_rate
latency (Int) relative to rate
Definition: param.h:193
SPA_POD_OPT_Int
#define SPA_POD_OPT_Int(val)
Definition: parser.h:521
SPA_PARAM_LATENCY_maxNs
@ SPA_PARAM_LATENCY_maxNs
max latency (Long) in nanoseconds
Definition: param.h:186
spa_latency_info::min_ns
uint64_t min_ns
Definition: latency-utils.h:43
spa_process_latency_info
Definition: latency-utils.h:115
spa_process_latency_parse
int spa_process_latency_parse(const struct spa_pod *latency, struct spa_process_latency_info *info)
Definition: latency-utils.h:124
spa_pod
Definition: pod/pod.h:50
spa_process_latency_info::rate
uint32_t rate
Definition: latency-utils.h:117
spa_latency_build
struct spa_pod * spa_latency_build(struct spa_pod_builder *builder, uint32_t id, const struct spa_latency_info *info)
Definition: latency-utils.h:102
spa_process_latency_build
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:138
param.h
SPA_TYPE_OBJECT_ParamProcessLatency
@ SPA_TYPE_OBJECT_ParamProcessLatency
Definition: build-12775836/doc/spa/utils/type.h:99
SPA_PARAM_LATENCY_maxQuantum
@ SPA_PARAM_LATENCY_maxQuantum
max latency relative to quantum (Float)
Definition: param.h:182
spa_pod_parse_object
#define spa_pod_parse_object(pod, type, id,...)
Definition: parser.h:560
parser.h
spa_process_latency_info::quantum
float quantum
Definition: latency-utils.h:116
spa_pod_builder_add_object
#define spa_pod_builder_add_object(b, type, id,...)
Definition: builder.h:650
SPA_TYPE_OBJECT_ParamLatency
@ SPA_TYPE_OBJECT_ParamLatency
Definition: build-12775836/doc/spa/utils/type.h:98
SPA_POD_Long
#define SPA_POD_Long(val)
Definition: vararg.h:65
SPA_PARAM_LATENCY_minRate
@ SPA_PARAM_LATENCY_minRate
min latency (Int) relative to rate
Definition: param.h:183
spa_process_latency_info::ns
uint64_t ns
Definition: latency-utils.h:118
spa_process_latency_info_add
int spa_process_latency_info_add(const struct spa_process_latency_info *process, struct spa_latency_info *info)
Definition: latency-utils.h:149
SPA_POD_Id
#define SPA_POD_Id(val)
Definition: vararg.h:56
spa_pod_builder
Definition: builder.h:63
SPA_POD_OPT_Long
#define SPA_POD_OPT_Long(val)
Definition: parser.h:522
builder.h
SPA_PARAM_PROCESS_LATENCY_quantum
@ SPA_PARAM_PROCESS_LATENCY_quantum
latency relative to quantum (Float)
Definition: param.h:192
spa_latency_info::min_quantum
float min_quantum
Definition: latency-utils.h:39