1 /* Simple Plugin API 2 * 3 * Copyright © 2018 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_POD_H 26 #define SPA_POD_H 27 28 #ifdef __cplusplus 29 extern "C" { 30 #endif 31 32 #include <spa/utils/defs.h> 33 #include <spa/utils/type.h> 34 35 #define SPA_POD_BODY_SIZE(pod) (((struct spa_pod*)(pod))->size) 36 #define SPA_POD_TYPE(pod) (((struct spa_pod*)(pod))->type) 37 #define SPA_POD_SIZE(pod) (sizeof(struct spa_pod) + SPA_POD_BODY_SIZE(pod)) 38 #define SPA_POD_CONTENTS_SIZE(type,pod) (SPA_POD_SIZE(pod)-sizeof(type)) 39 40 #define SPA_POD_CONTENTS(type,pod) SPA_MEMBER((pod),sizeof(type),void) 41 #define SPA_POD_CONTENTS_CONST(type,pod) SPA_MEMBER((pod),sizeof(type),const void) 42 #define SPA_POD_BODY(pod) SPA_MEMBER((pod),sizeof(struct spa_pod),void) 43 #define SPA_POD_BODY_CONST(pod) SPA_MEMBER((pod),sizeof(struct spa_pod),const void) 44 45 struct spa_pod { 46 uint32_t size; /* size of the body */ 47 uint32_t type; /* a basic id of enum spa_type */ 48 }; 49 50 #define SPA_POD_VALUE(type,pod) (((type*)pod)->value) 51 52 struct spa_pod_bool { 53 struct spa_pod pod; 54 int32_t value; 55 int32_t _padding; 56 }; 57 58 struct spa_pod_id { 59 struct spa_pod pod; 60 uint32_t value; 61 int32_t _padding; 62 }; 63 64 struct spa_pod_int { 65 struct spa_pod pod; 66 int32_t value; 67 int32_t _padding; 68 }; 69 70 struct spa_pod_long { 71 struct spa_pod pod; 72 int64_t value; 73 }; 74 75 struct spa_pod_float { 76 struct spa_pod pod; 77 float value; 78 int32_t _padding; 79 }; 80 81 struct spa_pod_double { 82 struct spa_pod pod; 83 double value; 84 }; 85 86 struct spa_pod_string { 87 struct spa_pod pod; 88 /* value here */ 89 }; 90 91 struct spa_pod_bytes { 92 struct spa_pod pod; 93 /* value here */ 94 }; 95 96 struct spa_pod_rectangle { 97 struct spa_pod pod; 98 struct spa_rectangle value; 99 }; 100 101 struct spa_pod_fraction { 102 struct spa_pod pod; 103 struct spa_fraction value; 104 }; 105 106 struct spa_pod_bitmap { 107 struct spa_pod pod; 108 /* array of uint8_t follows with the bitmap */ 109 }; 110 111 #define SPA_POD_ARRAY_CHILD(arr) (&((struct spa_pod_array*)(arr))->body.child) 112 #define SPA_POD_ARRAY_VALUE_TYPE(arr) (SPA_POD_TYPE(SPA_POD_ARRAY_CHILD(arr))) 113 #define SPA_POD_ARRAY_VALUE_SIZE(arr) (SPA_POD_BODY_SIZE(SPA_POD_ARRAY_CHILD(arr))) 114 #define SPA_POD_ARRAY_N_VALUES(arr) ((SPA_POD_BODY_SIZE(arr) - sizeof(struct spa_pod_array_body)) / SPA_POD_ARRAY_VALUE_SIZE(arr)) 115 #define SPA_POD_ARRAY_VALUES(arr) SPA_POD_CONTENTS(struct spa_pod_array, arr) 116 117 struct spa_pod_array_body { 118 struct spa_pod child; 119 /* array with elements of child.size follows */ 120 }; 121 122 struct spa_pod_array { 123 struct spa_pod pod; 124 struct spa_pod_array_body body; 125 }; 126 127 #define SPA_POD_CHOICE_CHILD(choice) (&((struct spa_pod_choice*)(choice))->body.child) 128 #define SPA_POD_CHOICE_TYPE(choice) (((struct spa_pod_choice*)(choice))->body.type) 129 #define SPA_POD_CHOICE_FLAGS(choice) (((struct spa_pod_choice*)(choice))->body.flags) 130 #define SPA_POD_CHOICE_VALUE_TYPE(choice) (SPA_POD_TYPE(SPA_POD_CHOICE_CHILD(choice))) 131 #define SPA_POD_CHOICE_VALUE_SIZE(choice) (SPA_POD_BODY_SIZE(SPA_POD_CHOICE_CHILD(choice))) 132 #define SPA_POD_CHOICE_N_VALUES(choice) ((SPA_POD_BODY_SIZE(choice) - sizeof(struct spa_pod_choice_body)) / SPA_POD_CHOICE_VALUE_SIZE(choice)) 133 #define SPA_POD_CHOICE_VALUES(choice) (SPA_POD_CONTENTS(struct spa_pod_choice, choice)) 134 135 enum spa_choice_type { 136 SPA_CHOICE_None, /**< no choice, first value is current */ 137 SPA_CHOICE_Range, /**< range: default, min, max */ 138 SPA_CHOICE_Step, /**< range with step: default, min, max, step */ 139 SPA_CHOICE_Enum, /**< list: default, alternative,... */ 140 SPA_CHOICE_Flags, /**< flags: default, possible flags,... */ 141 }; 142 143 struct spa_pod_choice_body { 144 uint32_t type; /**< type of choice, one of enum spa_choice_type */ 145 uint32_t flags; /**< extra flags */ 146 struct spa_pod child; 147 /* array with elements of child.size follows. Note that there might be more 148 * elements than required by \a type, which should be ignored. */ 149 }; 150 151 struct spa_pod_choice { 152 struct spa_pod pod; 153 struct spa_pod_choice_body body; 154 }; 155 156 struct spa_pod_struct { 157 struct spa_pod pod; 158 /* one or more spa_pod follow */ 159 }; 160 161 #define SPA_POD_OBJECT_TYPE(obj) (((struct spa_pod_object*)(obj))->body.type) 162 #define SPA_POD_OBJECT_ID(obj) (((struct spa_pod_object*)(obj))->body.id) 163 164 struct spa_pod_object_body { 165 uint32_t type; /**< one of enum spa_type */ 166 uint32_t id; /**< id of the object, depends on the object type */ 167 /* contents follow, series of spa_pod_prop */ 168 }; 169 170 struct spa_pod_object { 171 struct spa_pod pod; 172 struct spa_pod_object_body body; 173 }; 174 175 struct spa_pod_pointer_body { 176 uint32_t type; /**< pointer id, one of enum spa_type */ 177 uint32_t _padding; 178 const void *value; 179 }; 180 181 struct spa_pod_pointer { 182 struct spa_pod pod; 183 struct spa_pod_pointer_body body; 184 }; 185 186 struct spa_pod_fd { 187 struct spa_pod pod; 188 int64_t value; 189 }; 190 191 #define SPA_POD_PROP_SIZE(prop) (sizeof(struct spa_pod_prop) + (prop)->value.size) 192 193 /* props can be inside an object */ 194 struct spa_pod_prop { 195 uint32_t key; /**< key of property, list of valid keys depends on the 196 * object type */ 197 #define SPA_POD_PROP_FLAG_READONLY (1u<<0) /**< is read-only */ 198 #define SPA_POD_PROP_FLAG_HARDWARE (1u<<1) /**< some sort of hardware parameter */ 199 uint32_t flags; /**< flags for property */ 200 struct spa_pod value; 201 /* value follows */ 202 }; 203 204 #define SPA_POD_CONTROL_SIZE(ev) (sizeof(struct spa_pod_control) + (ev)->value.size) 205 206 /* controls can be inside a sequence and mark timed values */ 207 struct spa_pod_control { 208 uint32_t offset; /**< media offset */ 209 uint32_t type; /**< type of control, enum spa_control_type */ 210 struct spa_pod value; /**< control value, depends on type */ 211 /* value contents follow */ 212 }; 213 214 struct spa_pod_sequence_body { 215 uint32_t unit; 216 uint32_t pad; 217 /* series of struct spa_pod_control follows */ 218 }; 219 220 /** a sequence of timed controls */ 221 struct spa_pod_sequence { 222 struct spa_pod pod; 223 struct spa_pod_sequence_body body; 224 }; 225 226 227 #ifdef __cplusplus 228 } /* extern "C" */ 229 #endif 230 231 #endif /* SPA_POD_H */ 232