+ +
2da5fe7 OpenAVX v0.2.0 - High-performance open-standard IP audio and video transport suite
saifmukhtar · 2026-11-24
main
| 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 | #include <float.h> |
| 9 | |
| 10 | #include <spa/pod/builder.h> |
| 11 | #include <spa/pod/parser.h> |
| 12 | #include <spa/param/latency.h> |
| 13 | |
| 14 | #ifdef __cplusplus |
| 15 | extern "C" { |
| 16 | #endif |
| 17 | |
| 18 | /** |
| 19 | * \addtogroup spa_param |
| 20 | * \{ |
| 21 | */ |
| 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_UNSET(direction); |
| 48 | } |
| 49 | |
| 50 | SPA_API_LATENCY_UTILS void |
| 51 | spa_latency_info_combine_finish(struct spa_latency_info *info) |
| 52 | { |
| 53 | struct spa_latency_info unset = SPA_LATENCY_INFO_UNSET(info->direction); |
| 54 | if (info->min_quantum == unset.min_quantum) |
| 55 | info->min_quantum = 0; |
| 56 | if (info->max_quantum == unset.max_quantum) |
| 57 | info->max_quantum = 0; |
| 58 | if (info->min_rate == unset.min_rate) |
| 59 | info->min_rate = 0; |
| 60 | if (info->max_rate == unset.max_rate) |
| 61 | info->max_rate = 0; |
| 62 | if (info->min_ns == unset.min_ns) |
| 63 | info->min_ns = 0; |
| 64 | if (info->max_ns == unset.max_ns) |
| 65 | info->max_ns = 0; |
| 66 | } |
| 67 | |
| 68 | SPA_API_LATENCY_UTILS int |
| 69 | spa_latency_info_combine(struct spa_latency_info *info, const struct spa_latency_info *other) |
| 70 | { |
| 71 | if (info->direction != other->direction) |
| 72 | return -EINVAL; |
| 73 | if (other->min_quantum < info->min_quantum) |
| 74 | info->min_quantum = other->min_quantum; |
| 75 | if (other->max_quantum > info->max_quantum) |
| 76 | info->max_quantum = other->max_quantum; |
| 77 | if (other->min_rate < info->min_rate) |
| 78 | info->min_rate = other->min_rate; |
| 79 | if (other->max_rate > info->max_rate) |
| 80 | info->max_rate = other->max_rate; |
| 81 | if (other->min_ns < info->min_ns) |
| 82 | info->min_ns = other->min_ns; |
| 83 | if (other->max_ns > info->max_ns) |
| 84 | info->max_ns = other->max_ns; |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | SPA_API_LATENCY_UTILS int |
| 89 | spa_latency_parse(const struct spa_pod *latency, struct spa_latency_info *info) |
| 90 | { |
| 91 | int res; |
| 92 | spa_zero(*info); |
| 93 | if ((res = spa_pod_parse_object(latency, |
| 94 | SPA_TYPE_OBJECT_ParamLatency, NULL, |
| 95 | SPA_PARAM_LATENCY_direction, SPA_POD_Id(&info->direction), |
| 96 | SPA_PARAM_LATENCY_minQuantum, SPA_POD_OPT_Float(&info->min_quantum), |
| 97 | SPA_PARAM_LATENCY_maxQuantum, SPA_POD_OPT_Float(&info->max_quantum), |
| 98 | SPA_PARAM_LATENCY_minRate, SPA_POD_OPT_Int(&info->min_rate), |
| 99 | SPA_PARAM_LATENCY_maxRate, SPA_POD_OPT_Int(&info->max_rate), |
| 100 | SPA_PARAM_LATENCY_minNs, SPA_POD_OPT_Long(&info->min_ns), |
| 101 | SPA_PARAM_LATENCY_maxNs, SPA_POD_OPT_Long(&info->max_ns))) < 0) |
| 102 | return res; |
| 103 | info->direction = (enum spa_direction)(info->direction & 1); |
| 104 | return 0; |
| 105 | } |
| 106 | |
| 107 | SPA_API_LATENCY_UTILS struct spa_pod * |
| 108 | spa_latency_build(struct spa_pod_builder *builder, uint32_t id, const struct spa_latency_info *info) |
| 109 | { |
| 110 | return (struct spa_pod *)spa_pod_builder_add_object(builder, |
| 111 | SPA_TYPE_OBJECT_ParamLatency, id, |
| 112 | SPA_PARAM_LATENCY_direction, SPA_POD_Id(info->direction), |
| 113 | SPA_PARAM_LATENCY_minQuantum, SPA_POD_Float(info->min_quantum), |
| 114 | SPA_PARAM_LATENCY_maxQuantum, SPA_POD_Float(info->max_quantum), |
| 115 | SPA_PARAM_LATENCY_minRate, SPA_POD_Int(info->min_rate), |
| 116 | SPA_PARAM_LATENCY_maxRate, SPA_POD_Int(info->max_rate), |
| 117 | SPA_PARAM_LATENCY_minNs, SPA_POD_Long(info->min_ns), |
| 118 | SPA_PARAM_LATENCY_maxNs, SPA_POD_Long(info->max_ns)); |
| 119 | } |
| 120 | |
| 121 | SPA_API_LATENCY_UTILS int |
| 122 | spa_process_latency_parse(const struct spa_pod *latency, struct spa_process_latency_info *info) |
| 123 | { |
| 124 | int res; |
| 125 | spa_zero(*info); |
| 126 | if ((res = spa_pod_parse_object(latency, |
| 127 | SPA_TYPE_OBJECT_ParamProcessLatency, NULL, |
| 128 | SPA_PARAM_PROCESS_LATENCY_quantum, SPA_POD_OPT_Float(&info->quantum), |
| 129 | SPA_PARAM_PROCESS_LATENCY_rate, SPA_POD_OPT_Int(&info->rate), |
| 130 | SPA_PARAM_PROCESS_LATENCY_ns, SPA_POD_OPT_Long(&info->ns))) < 0) |
| 131 | return res; |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | SPA_API_LATENCY_UTILS struct spa_pod * |
| 136 | spa_process_latency_build(struct spa_pod_builder *builder, uint32_t id, |
| 137 | const struct spa_process_latency_info *info) |
| 138 | { |
| 139 | return (struct spa_pod *)spa_pod_builder_add_object(builder, |
| 140 | SPA_TYPE_OBJECT_ParamProcessLatency, id, |
| 141 | SPA_PARAM_PROCESS_LATENCY_quantum, SPA_POD_Float(info->quantum), |
| 142 | SPA_PARAM_PROCESS_LATENCY_rate, SPA_POD_Int(info->rate), |
| 143 | SPA_PARAM_PROCESS_LATENCY_ns, SPA_POD_Long(info->ns)); |
| 144 | } |
| 145 | |
| 146 | SPA_API_LATENCY_UTILS int |
| 147 | spa_process_latency_info_add(const struct spa_process_latency_info *process, |
| 148 | struct spa_latency_info *info) |
| 149 | { |
| 150 | info->min_quantum += process->quantum; |
| 151 | info->max_quantum += process->quantum; |
| 152 | info->min_rate += process->rate; |
| 153 | info->max_rate += process->rate; |
| 154 | info->min_ns += process->ns; |
| 155 | info->max_ns += process->ns; |
| 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | SPA_API_LATENCY_UTILS int |
| 160 | spa_process_latency_info_compare(const struct spa_process_latency_info *a, |
| 161 | const struct spa_process_latency_info *b) |
| 162 | { |
| 163 | if (a->quantum == b->quantum && |
| 164 | a->rate == b->rate && |
| 165 | a->ns == b->ns) |
| 166 | return 0; |
| 167 | return 1; |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * \} |
| 172 | */ |
| 173 | |
| 174 | #ifdef __cplusplus |
| 175 | } /* extern "C" */ |
| 176 | #endif |
| 177 | |
| 178 | #endif /* SPA_PARAM_LATENCY_UTILS_H */ |