PipeWire 1.6.8

Loading...
Searching...
No Matches
peer-utils.h
Go to the documentation of this file.
1/* Simple Plugin API */
2/* SPDX-FileCopyrightText: Copyright © 2023 Wim Taymans */
3/* SPDX-License-Identifier: MIT */
4
5#ifndef SPA_PARAM_PEER_PARAM_UTILS_H
6#define SPA_PARAM_PEER_PARAM_UTILS_H
7
8#include <float.h>
9
10#include <spa/utils/dict.h>
11#include <spa/pod/builder.h>
12#include <spa/pod/iter.h>
13#include <spa/pod/parser.h>
14#include <spa/pod/compare.h>
15#include <spa/param/peer.h>
16
17#ifdef __cplusplus
18 extern "C" {
19#endif
20
25
26#ifndef SPA_API_PEER_PARAM_UTILS
27 #ifdef SPA_API_IMPL
28 #define SPA_API_PEER_PARAM_UTILS SPA_API_IMPL
29 #else
30 #define SPA_API_PEER_PARAM_UTILS static inline
31 #endif
32#endif
33
34 SPA_API_PEER_PARAM_UTILS int
35 spa_peer_param_parse(const struct spa_pod *param, struct spa_peer_param_info *info,
36 size_t size, void **state)
37{
38 int res;
39 const struct spa_pod_object *obj = (const struct spa_pod_object*)param;
40 const struct spa_pod_prop *first, *start, *cur;
41
42 if ((res = spa_pod_parse_object(param,
43 SPA_TYPE_OBJECT_PeerParam, NULL)) < 0)
44 return res;
45
46 first = spa_pod_prop_first(&obj->body);
47 start = *state ? spa_pod_prop_next((struct spa_pod_prop*)*state) : first;
48
49 res = 0;
50 for (cur = start; spa_pod_prop_is_inside(&obj->body, obj->pod.size, cur);
51 cur = spa_pod_prop_next(cur)) {
52 info->peer_id = cur->key;
53 info->param = &cur->value;
54 *state = (void*)cur;
55 return 1;
56 }
57 return 0;
58}
59
60
61 SPA_API_PEER_PARAM_UTILS void
62 spa_peer_param_build_start(struct spa_pod_builder *builder, struct spa_pod_frame *f, uint32_t id)
63{
64 spa_pod_builder_push_object(builder, f, SPA_TYPE_OBJECT_PeerParam, id);
65}
66
67 SPA_API_PEER_PARAM_UTILS void
68 spa_peer_param_build_add_param(struct spa_pod_builder *builder, uint32_t peer_id,
69 const struct spa_pod *param)
70{
71 spa_pod_builder_prop(builder, peer_id, 0);
72 if (param)
73 spa_pod_builder_primitive(builder, param);
74 else
75 spa_pod_builder_none(builder);
76}
77
78 SPA_API_PEER_PARAM_UTILS struct spa_pod *
79 spa_peer_param_build_end(struct spa_pod_builder *builder, struct spa_pod_frame *f)
80{
81 return (struct spa_pod*)spa_pod_builder_pop(builder, f);
82}
83
84
86 */
87
88#ifdef __cplusplus
89} /* extern "C" */
90#endif
91
92#endif /* SPA_PARAM_PEER_PARAM_UTILS_H */
builder.h
spa/pod/builder.h
compare.h
spa/pod/compare.h
res
uint32_t int int res
Definition core.h:433
spa_peer_param_build_start
SPA_API_PEER_PARAM_UTILS void spa_peer_param_build_start(struct spa_pod_builder *builder, struct spa_pod_frame *f, uint32_t id)
Definition peer-utils.h:69
spa_peer_param_parse
SPA_API_PEER_PARAM_UTILS int spa_peer_param_parse(const struct spa_pod *param, struct spa_peer_param_info *info, size_t size, void **state)
Definition peer-utils.h:42
spa_peer_param_build_add_param
SPA_API_PEER_PARAM_UTILS void spa_peer_param_build_add_param(struct spa_pod_builder *builder, uint32_t peer_id, const struct spa_pod *param)
Definition peer-utils.h:75
SPA_API_PEER_PARAM_UTILS
#define SPA_API_PEER_PARAM_UTILS
Definition peer-utils.h:37
spa_peer_param_build_end
SPA_API_PEER_PARAM_UTILS struct spa_pod * spa_peer_param_build_end(struct spa_pod_builder *builder, struct spa_pod_frame *f)
Definition peer-utils.h:86
spa_pod_builder_pop
SPA_API_POD_BUILDER void * spa_pod_builder_pop(struct spa_pod_builder *builder, struct spa_pod_frame *frame)
Definition builder.h:213
spa_pod_prop_first
SPA_API_POD_ITER struct spa_pod_prop * spa_pod_prop_first(const struct spa_pod_object_body *body)
Definition iter.h:51
spa_pod_builder_none
SPA_API_POD_BUILDER int spa_pod_builder_none(struct spa_pod_builder *builder)
Definition builder.h:262
spa_pod_prop_is_inside
SPA_API_POD_ITER bool spa_pod_prop_is_inside(const struct spa_pod_object_body *body, uint32_t size, const struct spa_pod_prop *iter)
Definition iter.h:56
spa_pod_builder_push_object
SPA_API_POD_BUILDER int spa_pod_builder_push_object(struct spa_pod_builder *builder, struct spa_pod_frame *frame, uint32_t type, uint32_t id)
Definition builder.h:475
spa_pod_prop_next
SPA_API_POD_ITER struct spa_pod_prop * spa_pod_prop_next(const struct spa_pod_prop *iter)
Definition iter.h:65
spa_pod_builder_primitive
SPA_API_POD_BUILDER int spa_pod_builder_primitive(struct spa_pod_builder *builder, const struct spa_pod *p)
Definition builder.h:250
spa_pod_parse_object
#define spa_pod_parse_object(pod, type, id,...)
Definition parser.h:935
spa_pod_builder_prop
SPA_API_POD_BUILDER int spa_pod_builder_prop(struct spa_pod_builder *builder, uint32_t key, uint32_t flags)
Definition builder.h:490
SPA_TYPE_OBJECT_PeerParam
@ SPA_TYPE_OBJECT_PeerParam
Definition type.h:98
iter.h
spa/pod/iter.h
parser.h
spa/pod/parser.h
peer.h
spa/param/peer.h
spa_peer_param_info
Definition peer.h:30
spa_pod_builder
Definition builder.h:63
spa_pod_frame
Definition body.h:38
spa_pod_object
Definition pod.h:202
spa_pod_object::pod
struct spa_pod pod
Definition pod.h:203
spa_pod_object::body
struct spa_pod_object_body body
Definition pod.h:204
spa_pod_prop
Definition pod.h:227
spa_pod_prop::key
uint32_t key
key of property, list of valid keys depends on the object type
Definition pod.h:228
spa_pod_prop::value
struct spa_pod value
Definition pod.h:249
spa_pod
Definition pod.h:57
spa_pod::size
uint32_t size
Definition pod.h:58
dict.h
spa/utils/dict.h