summaryrefslogtreecommitdiff
path: root/src/examples/media-session/media-session.h
blob: 0a33b5829270cac25bc74f6d45b8b2c142d0f659 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/* PipeWire
 *
 * Copyright © 2019 Wim Taymans
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */


#ifndef SM_MEDIA_SESSION_H
#define SM_MEDIA_SESSION_H

#include <spa/monitor/device.h>

#ifdef __cplusplus
extern "C" {
#endif

#define SM_TYPE_MEDIA_SESSION	PW_TYPE_INFO_OBJECT_BASE "SessionManager"

struct sm_media_session;

struct sm_object_events {
#define SM_VERSION_OBJECT_EVENTS	0
	uint32_t version;

	void (*update) (void *data);
	void (*destroy) (void *data);
};

struct sm_object {
	uint32_t id;
	uint32_t type;

	struct spa_list link;
	struct sm_media_session *session;

#define SM_OBJECT_CHANGE_MASK_LISTENER		(1<<1)
#define SM_OBJECT_CHANGE_MASK_PROPERTIES	(1<<2)
#define SM_OBJECT_CHANGE_MASK_BIND		(1<<3)
#define SM_OBJECT_CHANGE_MASK_LAST		(1<<8)
	uint32_t mask;			/**< monitored info */
	uint32_t avail;			/**< available info */
	uint32_t changed;		/**< changed since last update */
	struct pw_properties *props;	/**< global properties */

	struct pw_proxy *proxy;
	struct spa_hook proxy_listener;
	struct spa_hook object_listener;
	pw_destroy_t destroy;

	struct spa_hook_list hooks;

	struct spa_list data;
};

int sm_object_add_listener(struct sm_object *obj, struct spa_hook *listener,
		const struct sm_object_events *events, void *data);

struct sm_param {
	uint32_t id;
	struct spa_list link;		/**< link in param_list */
	struct spa_pod *param;
};

/** get user data with \a id and \a size to an object */
void *sm_object_add_data(struct sm_object *obj, const char *id, size_t size);
void *sm_object_get_data(struct sm_object *obj, const char *id);
int sm_object_remove_data(struct sm_object *obj, const char *id);

int sm_object_destroy(struct sm_object *obj);

struct sm_client {
	struct sm_object obj;

#define SM_CLIENT_CHANGE_MASK_INFO		(SM_OBJECT_CHANGE_MASK_LAST<<0)
#define SM_CLIENT_CHANGE_MASK_PERMISSIONS	(SM_OBJECT_CHANGE_MASK_LAST<<1)
	struct pw_client_info *info;
};

struct sm_device {
	struct sm_object obj;

	unsigned int subscribe:1;	/**< if we subscribed to param changes */

#define SM_DEVICE_CHANGE_MASK_INFO	(SM_OBJECT_CHANGE_MASK_LAST<<0)
#define SM_DEVICE_CHANGE_MASK_PARAMS	(SM_OBJECT_CHANGE_MASK_LAST<<1)
#define SM_DEVICE_CHANGE_MASK_NODES	(SM_OBJECT_CHANGE_MASK_LAST<<2)
	uint32_t n_params;
	struct spa_list param_list;	/**< list of sm_param */
	struct pw_device_info *info;
	struct spa_list node_list;
};


struct sm_node {
	struct sm_object obj;

	struct sm_device *device;	/**< optional device */
	struct spa_list link;		/**< link in device node_list */
	unsigned int subscribe:1;	/**< if we subscribed to param changes */
	uint32_t last_id;

#define SM_NODE_CHANGE_MASK_INFO	(SM_OBJECT_CHANGE_MASK_LAST<<0)
#define SM_NODE_CHANGE_MASK_PARAMS	(SM_OBJECT_CHANGE_MASK_LAST<<1)
#define SM_NODE_CHANGE_MASK_PORTS	(SM_OBJECT_CHANGE_MASK_LAST<<2)
	uint32_t n_params;
	struct spa_list param_list;	/**< list of sm_param */
	struct pw_node_info *info;
	struct spa_list port_list;
};

struct sm_port {
	struct sm_object obj;

	enum pw_direction direction;
	struct sm_node *node;
	struct spa_list link;		/**< link in node port_list */

#define SM_PORT_CHANGE_MASK_INFO	(SM_OBJECT_CHANGE_MASK_LAST<<0)
	struct pw_port_info *info;
};

struct sm_session {
	struct sm_object obj;

#define SM_SESSION_CHANGE_MASK_INFO		(SM_OBJECT_CHANGE_MASK_LAST<<0)
#define SM_SESSION_CHANGE_MASK_ENDPOINTS	(SM_OBJECT_CHANGE_MASK_LAST<<1)
	struct pw_session_info *info;
	struct spa_list endpoint_list;
};

struct sm_endpoint {
	struct sm_object obj;

	int32_t priority;

	struct sm_session *session;
	struct spa_list link;		/**< link in session endpoint_list */

#define SM_ENDPOINT_CHANGE_MASK_INFO	(SM_OBJECT_CHANGE_MASK_LAST<<0)
#define SM_ENDPOINT_CHANGE_MASK_STREAMS	(SM_OBJECT_CHANGE_MASK_LAST<<1)
	struct pw_endpoint_info *info;
	struct spa_list stream_list;
};

struct sm_endpoint_stream {
	struct sm_object obj;

	int32_t priority;

	struct sm_endpoint *endpoint;
	struct spa_list link;		/**< link in endpoint stream_list */

	struct spa_list link_list;	/**< list of links */

#define SM_ENDPOINT_STREAM_CHANGE_MASK_INFO	(SM_OBJECT_CHANGE_MASK_LAST<<0)
	struct pw_endpoint_stream_info *info;
};

struct sm_endpoint_link {
	struct sm_object obj;

	struct spa_list link;		/**< link in session link_list */

	struct spa_list output_link;
	struct sm_endpoint_stream *output;
	struct spa_list input_link;
	struct sm_endpoint_stream *input;

#define SM_ENDPOINT_LINK_CHANGE_MASK_INFO	(SM_OBJECT_CHANGE_MASK_LAST<<0)
	struct pw_endpoint_link_info *info;
};

struct sm_media_session_events {
#define SM_VERSION_MEDIA_SESSION_EVENTS	0
	uint32_t version;

	void (*create) (void *data, struct sm_object *object);
	void (*remove) (void *data, struct sm_object *object);

	void (*rescan) (void *data, int seq);
};

struct sm_media_session {
	struct sm_session *session;	/** session object managed by this session */

	struct pw_loop *loop;		/** the main loop */
	struct pw_context *context;

	struct spa_dbus_connection *dbus_connection;
};

int sm_media_session_add_listener(struct sm_media_session *sess, struct spa_hook *listener,
		const struct sm_media_session_events *events, void *data);

int sm_media_session_roundtrip(struct sm_media_session *sess);

int sm_media_session_sync(struct sm_media_session *sess,
		void (*callback) (void *data), void *data);

struct sm_object *sm_media_session_find_object(struct sm_media_session *sess, uint32_t id);

int sm_media_session_schedule_rescan(struct sm_media_session *sess);

struct pw_proxy *sm_media_session_export(struct sm_media_session *sess,
		uint32_t type, const struct spa_dict *props,
		void *object, size_t user_data_size);

struct sm_device *sm_media_session_export_device(struct sm_media_session *sess,
		const struct spa_dict *props, struct spa_device *device);

struct pw_proxy *sm_media_session_create_object(struct sm_media_session *sess,
		const char *factory_name, uint32_t type, uint32_t version,
		const struct spa_dict *props, size_t user_data_size);

struct sm_node *sm_media_session_create_node(struct sm_media_session *sess,
		const char *factory_name, const struct spa_dict *props);

int sm_media_session_create_links(struct sm_media_session *sess,
		const struct spa_dict *dict);

#ifdef __cplusplus
}
#endif

#endif