1 /* PipeWire
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 PIPEWIRE_LINK_H
26 #define PIPEWIRE_LINK_H
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #include <spa/utils/defs.h>
33 #include <spa/utils/hook.h>
34 
35 #include <pipewire/proxy.h>
36 
37 #define PW_TYPE_INTERFACE_Link	PW_TYPE_INFO_INTERFACE_BASE "Link"
38 
39 #define PW_VERSION_LINK		3
40 struct pw_link;
41 
42 /** \enum pw_link_state The different link states \memberof pw_link */
43 enum pw_link_state {
44 	PW_LINK_STATE_ERROR = -2,	/**< the link is in error */
45 	PW_LINK_STATE_UNLINKED = -1,	/**< the link is unlinked */
46 	PW_LINK_STATE_INIT = 0,		/**< the link is initialized */
47 	PW_LINK_STATE_NEGOTIATING = 1,	/**< the link is negotiating formats */
48 	PW_LINK_STATE_ALLOCATING = 2,	/**< the link is allocating buffers */
49 	PW_LINK_STATE_PAUSED = 3,	/**< the link is paused */
50 };
51 
52 /** Convert a \ref pw_link_state to a readable string \memberof pw_link */
53 const char * pw_link_state_as_string(enum pw_link_state state);
54 /** The link information. Extra information can be added in later versions \memberof pw_introspect */
55 struct pw_link_info {
56 	uint32_t id;			/**< id of the global */
57 	uint32_t output_node_id;	/**< server side output node id */
58 	uint32_t output_port_id;	/**< output port id */
59 	uint32_t input_node_id;		/**< server side input node id */
60 	uint32_t input_port_id;		/**< input port id */
61 #define PW_LINK_CHANGE_MASK_STATE	(1 << 0)
62 #define PW_LINK_CHANGE_MASK_FORMAT	(1 << 1)
63 #define PW_LINK_CHANGE_MASK_PROPS	(1 << 2)
64 #define PW_LINK_CHANGE_MASK_ALL		((1 << 3)-1)
65 	uint64_t change_mask;		/**< bitfield of changed fields since last call */
66 	enum pw_link_state state;	/**< the current state of the link */
67 	const char *error;		/**< an error reason if \a state is error */
68 	struct spa_pod *format;		/**< format over link */
69 	struct spa_dict *props;		/**< the properties of the link */
70 };
71 
72 struct pw_link_info *
73 pw_link_info_update(struct pw_link_info *info,
74 		    const struct pw_link_info *update);
75 
76 void
77 pw_link_info_free(struct pw_link_info *info);
78 
79 
80 #define PW_LINK_EVENT_INFO	0
81 #define PW_LINK_EVENT_NUM	1
82 
83 /** Link events */
84 struct pw_link_events {
85 #define PW_VERSION_LINK_EVENTS	0
86 	uint32_t version;
87 	/**
88 	 * Notify link info
89 	 *
90 	 * \param info info about the link
91 	 */
92 	void (*info) (void *object, const struct pw_link_info *info);
93 };
94 
95 #define PW_LINK_METHOD_ADD_LISTENER	0
96 #define PW_LINK_METHOD_NUM		1
97 
98 /** Link methods */
99 struct pw_link_methods {
100 #define PW_VERSION_LINK_METHODS		0
101 	uint32_t version;
102 
103 	int (*add_listener) (void *object,
104 			struct spa_hook *listener,
105 			const struct pw_link_events *events,
106 			void *data);
107 };
108 
109 #define pw_link_method(o,method,version,...)				\
110 ({									\
111 	int _res = -ENOTSUP;						\
112 	spa_interface_call_res((struct spa_interface*)o,		\
113 			struct pw_link_methods, _res,			\
114 			method, version, ##__VA_ARGS__);		\
115 	_res;								\
116 })
117 
118 #define pw_link_add_listener(c,...)		pw_link_method(c,add_listener,0,__VA_ARGS__)
119 
120 #ifdef __cplusplus
121 }  /* extern "C" */
122 #endif
123 
124 #endif /* PIPEWIRE_LINK_H */
125