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

PipeWire 1.0.3

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
17#include <float.h>
18
19#include <spa/pod/builder.h>
20#include <spa/pod/parser.h>
21#include <spa/param/latency.h>
22
23static inline int
24 spa_latency_info_compare(const struct spa_latency_info *a, const struct spa_latency_info *b)
25{
26 if (a->min_quantum == b->min_quantum &&
27 a->max_quantum == b->max_quantum &&
28 a->min_rate == b->min_rate &&
29 a->max_rate == b->max_rate &&
30 a->min_ns == b->min_ns &&
31 a->max_ns == b->max_ns)
32 return 0;
33 return 1;
34}
35
36static inline void
37 spa_latency_info_combine_start(struct spa_latency_info *info, enum spa_direction direction)
38{
39 *info = SPA_LATENCY_INFO(direction,
40 .min_quantum = FLT_MAX,
41 .max_quantum = 0.0f,
42 .min_rate = UINT32_MAX,
43 .max_rate = 0,
44 .min_ns = UINT64_MAX,
45 .max_ns = 0);
46}
47static inline void
48 spa_latency_info_combine_finish(struct spa_latency_info *info)
49{
50 if (info->min_quantum == FLT_MAX)
51 info->min_quantum = 0;
52 if (info->min_rate == UINT32_MAX)
53 info->min_rate = 0;
54 if (info->min_ns == UINT64_MAX)
55 info->min_ns = 0;
56}
57
58static inline int
59 spa_latency_info_combine(struct spa_latency_info *info, const struct spa_latency_info *other)
60{
61 if (info->direction != other->direction)
62 return -EINVAL;
63 if (other->min_quantum < info->min_quantum)
64 info->min_quantum = other->min_quantum;
65 if (other->max_quantum > info->max_quantum)
66 info->max_quantum = other->max_quantum;
67 if (other->min_rate < info->min_rate)
68 info->min_rate = other->min_rate;
69 if (other->max_rate > info->max_rate)
70 info->max_rate = other->max_rate;
71 if (other->min_ns < info->min_ns)
72 info->min_ns = other->min_ns;
73 if (other->max_ns > info->max_ns)
74 info->max_ns = other->max_ns;
75 return 0;
76}
77
78static inline int
79 spa_latency_parse(const struct spa_pod *latency, struct spa_latency_info *info)
80{
81 int res;
82 spa_zero(*info);
83 if ((res = spa_pod_parse_object(latency,
84 SPA_TYPE_OBJECT_ParamLatency, NULL,
85 SPA_PARAM_LATENCY_direction, SPA_POD_Id(&info->direction),
86 SPA_PARAM_LATENCY_minQuantum, SPA_POD_OPT_Float(&info->min_quantum),
87 SPA_PARAM_LATENCY_maxQuantum, SPA_POD_OPT_Float(&info->max_quantum),
88 SPA_PARAM_LATENCY_minRate, SPA_POD_OPT_Int(&info->min_rate),
89 SPA_PARAM_LATENCY_maxRate, SPA_POD_OPT_Int(&info->max_rate),
90 SPA_PARAM_LATENCY_minNs, SPA_POD_OPT_Long(&info->min_ns),
91 SPA_PARAM_LATENCY_maxNs, SPA_POD_OPT_Long(&info->max_ns))) < 0)
92 return res;
93 info->direction = (enum spa_direction)(info->direction & 1);
94 return 0;
95}
96
97static inline struct spa_pod *
98 spa_latency_build(struct spa_pod_builder *builder, uint32_t id, const struct spa_latency_info *info)
99{
100 return (struct spa_pod *)spa_pod_builder_add_object(builder,
101 SPA_TYPE_OBJECT_ParamLatency, id,
102 SPA_PARAM_LATENCY_direction, SPA_POD_Id(info->direction),
103 SPA_PARAM_LATENCY_minQuantum, SPA_POD_Float(info->min_quantum),
104 SPA_PARAM_LATENCY_maxQuantum, SPA_POD_Float(info->max_quantum),
105 SPA_PARAM_LATENCY_minRate, SPA_POD_Int(info->min_rate),
106 SPA_PARAM_LATENCY_maxRate, SPA_POD_Int(info->max_rate),
107 SPA_PARAM_LATENCY_minNs, SPA_POD_Long(info->min_ns),
108 SPA_PARAM_LATENCY_maxNs, SPA_POD_Long(info->max_ns));
109}
110
111static inline int
112 spa_process_latency_parse(const struct spa_pod *latency, struct spa_process_latency_info *info)
113{
114 int res;
115 spa_zero(*info);
116 if ((res = spa_pod_parse_object(latency,
117 SPA_TYPE_OBJECT_ParamProcessLatency, NULL,
118 SPA_PARAM_PROCESS_LATENCY_quantum, SPA_POD_OPT_Float(&info->quantum),
119 SPA_PARAM_PROCESS_LATENCY_rate, SPA_POD_OPT_Int(&info->rate),
120 SPA_PARAM_PROCESS_LATENCY_ns, SPA_POD_OPT_Long(&info->ns))) < 0)
121 return res;
122 return 0;
123}
124
125static inline struct spa_pod *
126 spa_process_latency_build(struct spa_pod_builder *builder, uint32_t id,
127 const struct spa_process_latency_info *info)
128{
129 return (struct spa_pod *)spa_pod_builder_add_object(builder,
130 SPA_TYPE_OBJECT_ParamProcessLatency, id,
131 SPA_PARAM_PROCESS_LATENCY_quantum, SPA_POD_Float(info->quantum),
132 SPA_PARAM_PROCESS_LATENCY_rate, SPA_POD_Int(info->rate),
133 SPA_PARAM_PROCESS_LATENCY_ns, SPA_POD_Long(info->ns));
134}
135
136static inline int
137 spa_process_latency_info_add(const struct spa_process_latency_info *process,
138 struct spa_latency_info *info)
139{
140 info->min_quantum += process->quantum;
141 info->max_quantum += process->quantum;
142 info->min_rate += process->rate;
143 info->max_rate += process->rate;
144 info->min_ns += process->ns;
145 info->max_ns += process->ns;
146 return 0;
147}
148
153#ifdef __cplusplus
154} /* extern "C" */
155#endif
156
157#endif /* SPA_PARAM_LATENCY_UTILS_H */
builder.h
spa/pod/builder.h
spa_latency_parse
static int spa_latency_parse(const struct spa_pod *latency, struct spa_latency_info *info)
Definition latency-utils.h:84
spa_process_latency_build
static 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:131
spa_latency_info_combine
static int spa_latency_info_combine(struct spa_latency_info *info, const struct spa_latency_info *other)
Definition latency-utils.h:64
spa_latency_build
static struct spa_pod * spa_latency_build(struct spa_pod_builder *builder, uint32_t id, const struct spa_latency_info *info)
Definition latency-utils.h:103
SPA_LATENCY_INFO
#define SPA_LATENCY_INFO(dir,...)
Definition latency.h:48
spa_process_latency_info_add
static int spa_process_latency_info_add(const struct spa_process_latency_info *process, struct spa_latency_info *info)
Definition latency-utils.h:142
spa_process_latency_parse
static int spa_process_latency_parse(const struct spa_pod *latency, struct spa_process_latency_info *info)
Definition latency-utils.h:117
spa_latency_info_combine_finish
static void spa_latency_info_combine_finish(struct spa_latency_info *info)
Definition latency-utils.h:53
spa_latency_info_compare
static int spa_latency_info_compare(const struct spa_latency_info *a, const struct spa_latency_info *b)
Definition latency-utils.h:29
spa_latency_info_combine_start
static void spa_latency_info_combine_start(struct spa_latency_info *info, enum spa_direction direction)
Definition latency-utils.h:42
SPA_PARAM_PROCESS_LATENCY_rate
@ SPA_PARAM_PROCESS_LATENCY_rate
latency (Int) relative to rate
Definition latency.h:54
SPA_PARAM_PROCESS_LATENCY_ns
@ SPA_PARAM_PROCESS_LATENCY_ns
latency (Long) in nanoseconds
Definition latency.h:55
SPA_PARAM_PROCESS_LATENCY_quantum
@ SPA_PARAM_PROCESS_LATENCY_quantum
latency relative to quantum (Float)
Definition latency.h:53
SPA_PARAM_LATENCY_maxNs
@ SPA_PARAM_LATENCY_maxNs
max latency (Long) in nanoseconds
Definition latency.h:33
SPA_PARAM_LATENCY_minRate
@ SPA_PARAM_LATENCY_minRate
min latency (Int) relative to rate
Definition latency.h:30
SPA_PARAM_LATENCY_minQuantum
@ SPA_PARAM_LATENCY_minQuantum
min latency relative to quantum (Float)
Definition latency.h:28
SPA_PARAM_LATENCY_maxRate
@ SPA_PARAM_LATENCY_maxRate
max latency (Int) relative to rate
Definition latency.h:31
SPA_PARAM_LATENCY_maxQuantum
@ SPA_PARAM_LATENCY_maxQuantum
max latency relative to quantum (Float)
Definition latency.h:29
SPA_PARAM_LATENCY_direction
@ SPA_PARAM_LATENCY_direction
direction, input/output (Id enum spa_direction)
Definition latency.h:27
SPA_PARAM_LATENCY_minNs
@ SPA_PARAM_LATENCY_minNs
min latency (Long) in nanoseconds
Definition latency.h:32
SPA_POD_OPT_Float
#define SPA_POD_OPT_Float(val)
Definition parser.h:526
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:522
spa_pod_builder_add_object
#define spa_pod_builder_add_object(b, type, id,...)
Definition builder.h:659
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:576
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:524
SPA_TYPE_OBJECT_ParamLatency
@ SPA_TYPE_OBJECT_ParamLatency
Definition type.h:84
SPA_TYPE_OBJECT_ParamProcessLatency
@ SPA_TYPE_OBJECT_ParamProcessLatency
Definition type.h:85
spa_zero
#define spa_zero(x)
Definition defs.h:421
spa_direction
spa_direction
Definition defs.h:92
latency.h
spa/param/latency.h
parser.h
spa/pod/parser.h
spa_latency_info
helper structure for managing latency objects
Definition latency.h:37
spa_latency_info::min_rate
uint32_t min_rate
Definition latency.h:41
spa_latency_info::max_rate
uint32_t max_rate
Definition latency.h:42
spa_latency_info::direction
enum spa_direction direction
Definition latency.h:38
spa_latency_info::max_quantum
float max_quantum
Definition latency.h:40
spa_latency_info::min_quantum
float min_quantum
Definition latency.h:39
spa_latency_info::min_ns
uint64_t min_ns
Definition latency.h:43
spa_latency_info::max_ns
uint64_t max_ns
Definition latency.h:44
spa_pod_builder
Definition builder.h:53
spa_pod
Definition pod.h:43
spa_pod::type
uint32_t type
Definition pod.h:45
spa_process_latency_info
Helper structure for managing process latency objects.
Definition latency.h:59
spa_process_latency_info::quantum
float quantum
Definition latency.h:60
spa_process_latency_info::rate
uint32_t rate
Definition latency.h:61
spa_process_latency_info::ns
uint64_t ns
Definition latency.h:62