summaryrefslogtreecommitdiff
path: root/pinos/client/connection.h
blob: 96d34b7df573844ae728418af5ab6aceedffa27a (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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/* Simple Plugin API
 * Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#ifndef __PINOS_CONNECTION_H__
#define __PINOS_CONNECTION_H__

#ifdef __cplusplus
extern "C" {
#endif

#include <spa/defs.h>
#include <spa/props.h>
#include <spa/format.h>
#include <spa/port.h>
#include <spa/node.h>

typedef struct _PinosConnection PinosConnection;

typedef enum {
  PINOS_MESSAGE_INVALID                  = 0,

  PINOS_MESSAGE_SYNC,
  PINOS_MESSAGE_NOTIFY_DONE,
  PINOS_MESSAGE_GET_REGISTRY,
  PINOS_MESSAGE_REMOVE_ID,
  PINOS_MESSAGE_CORE_INFO,

  PINOS_MESSAGE_BIND,
  PINOS_MESSAGE_NOTIFY_GLOBAL,
  PINOS_MESSAGE_NOTIFY_GLOBAL_REMOVE,

  PINOS_MESSAGE_CREATE_NODE,
  PINOS_MESSAGE_CREATE_NODE_DONE,

  PINOS_MESSAGE_CREATE_CLIENT_NODE,
  PINOS_MESSAGE_CREATE_CLIENT_NODE_DONE,

  PINOS_MESSAGE_DESTROY,

  PINOS_MESSAGE_MODULE_INFO,
  PINOS_MESSAGE_NODE_INFO,
  PINOS_MESSAGE_CLIENT_INFO,
  PINOS_MESSAGE_LINK_INFO,

  /* client to server */
  PINOS_MESSAGE_NODE_UPDATE,
  PINOS_MESSAGE_PORT_UPDATE,
  PINOS_MESSAGE_NODE_STATE_CHANGE,

  PINOS_MESSAGE_PORT_STATUS_CHANGE,
  PINOS_MESSAGE_NODE_EVENT,

  /* server to client */
  PINOS_MESSAGE_TRANSPORT_UPDATE,

  PINOS_MESSAGE_ADD_PORT,
  PINOS_MESSAGE_REMOVE_PORT,

  PINOS_MESSAGE_SET_FORMAT,
  PINOS_MESSAGE_SET_PROPERTY,

  PINOS_MESSAGE_NODE_COMMAND,
  PINOS_MESSAGE_PORT_COMMAND,

  /* both */
  PINOS_MESSAGE_ADD_MEM,
  PINOS_MESSAGE_USE_BUFFERS,

} PinosMessageType;

#include <pinos/client/introspect.h>

/* PINOS_MESSAGE_SYNC */
typedef struct {
  uint32_t     seq;
} PinosMessageSync;

/* PINOS_MESSAGE_NOTIFY_DONE */
typedef struct {
  uint32_t     seq;
} PinosMessageNotifyDone;

/* PINOS_MESSAGE_GET_REGISTRY */
typedef struct {
  uint32_t     seq;
  uint32_t     new_id;
} PinosMessageGetRegistry;

/* PINOS_MESSAGE_REMOVE_ID */
typedef struct {
  uint32_t     id;
} PinosMessageRemoveId;

/* PINOS_MESSAGE_CORE_INFO */
typedef struct {
  PinosCoreInfo *info;
} PinosMessageCoreInfo;

/* PINOS_MESSAGE_MODULE_INFO */
typedef struct {
  PinosModuleInfo *info;
} PinosMessageModuleInfo;

/* PINOS_MESSAGE_NODE_INFO */
typedef struct {
  PinosNodeInfo *info;
} PinosMessageNodeInfo;

/* PINOS_MESSAGE_CLIENT_INFO */
typedef struct {
  PinosClientInfo *info;
} PinosMessageClientInfo;

/* PINOS_MESSAGE_LINK_INFO */
typedef struct {
  PinosLinkInfo *info;
} PinosMessageLinkInfo;

/* PINOS_MESSAGE_BIND */
typedef struct {
  uint32_t     id;
  uint32_t     new_id;
} PinosMessageBind;

/* PINOS_MESSAGE_NOTIFY_GLOBAL */
typedef struct {
  uint32_t     id;
  const char * type;
} PinosMessageNotifyGlobal;

/* PINOS_MESSAGE_NOTIFY_GLOBAL_REMOVE */
typedef struct {
  uint32_t     id;
} PinosMessageNotifyGlobalRemove;

/* PINOS_MESSAGE_CREATE_NODE */
typedef struct {
  uint32_t     seq;
  const char  *factory_name;
  const char  *name;
  SpaDict     *props;
  uint32_t     new_id;
} PinosMessageCreateNode;

/* PINOS_MESSAGE_CREATE_NODE_DONE */
typedef struct {
  uint32_t     seq;
} PinosMessageCreateNodeDone;

/* PINOS_MESSAGE_CREATE_CLIENT_NODE */
typedef struct {
  uint32_t     seq;
  const char  *name;
  SpaDict     *props;
  uint32_t     new_id;
} PinosMessageCreateClientNode;

/* PINOS_MESSAGE_CREATE_CLIENT_NODE_DONE */
typedef struct {
  uint32_t     seq;
  int          datafd;
} PinosMessageCreateClientNodeDone;

/* PINOS_MESSAGE_DESTROY */
typedef struct {
  uint32_t     seq;
  uint32_t     id;
} PinosMessageDestroy;

/*  PINOS_MESSAGE_NODE_UPDATE */
typedef struct {
#define PINOS_MESSAGE_NODE_UPDATE_MAX_INPUTS   (1 << 0)
#define PINOS_MESSAGE_NODE_UPDATE_MAX_OUTPUTS  (1 << 1)
#define PINOS_MESSAGE_NODE_UPDATE_PROPS        (1 << 2)
  uint32_t        change_mask;
  unsigned int    max_input_ports;
  unsigned int    max_output_ports;
  const SpaProps *props;
} PinosMessageNodeUpdate;

/* PINOS_MESSAGE_PORT_UPDATE */
typedef struct {
  SpaDirection       direction;
  uint32_t           port_id;
#define PINOS_MESSAGE_PORT_UPDATE_POSSIBLE_FORMATS  (1 << 0)
#define PINOS_MESSAGE_PORT_UPDATE_FORMAT            (1 << 1)
#define PINOS_MESSAGE_PORT_UPDATE_PROPS             (1 << 2)
#define PINOS_MESSAGE_PORT_UPDATE_INFO              (1 << 3)
  uint32_t           change_mask;
  unsigned int       n_possible_formats;
  SpaFormat        **possible_formats;
  SpaFormat         *format;
  const SpaProps    *props;
  const SpaPortInfo *info;
} PinosMessagePortUpdate;

/* PINOS_MESSAGE_NODE_STATE_CHANGE */
typedef struct {
  SpaNodeState    state;
} PinosMessageNodeStateChange;

/* PINOS_MESSAGE_PORT_STATUS_CHANGE */

/* PINOS_MESSAGE_NODE_EVENT */
typedef struct {
  SpaNodeEvent *event;
} PinosMessageNodeEvent;

/* PINOS_MESSAGE_ADD_PORT */
typedef struct {
  uint32_t     seq;
  SpaDirection direction;
  uint32_t     port_id;
} PinosMessageAddPort;

/* PINOS_MESSAGE_REMOVE_PORT */
typedef struct {
  uint32_t     seq;
  SpaDirection direction;
  uint32_t     port_id;
} PinosMessageRemovePort;


/* PINOS_MESSAGE_SET_FORMAT */
typedef struct {
  uint32_t            seq;
  SpaDirection        direction;
  uint32_t            port_id;
  SpaPortFormatFlags  flags;
  SpaFormat          *format;
} PinosMessageSetFormat;

/* PINOS_MESSAGE_SET_PROPERTY */
typedef struct {
  uint32_t     seq;
  uint32_t     id;
  size_t       size;
  void        *value;
} PinosMessageSetProperty;

/* PINOS_MESSAGE_NODE_COMMAND */
typedef struct {
  uint32_t        seq;
  SpaNodeCommand *command;
} PinosMessageNodeCommand;

/* PINOS_MESSAGE_PORT_COMMAND */
typedef struct {
  uint32_t        port_id;
  SpaNodeCommand *command;
} PinosMessagePortCommand;

/* PINOS_MESSAGE_TRANSPORT_UPDATE */
typedef struct {
  int          memfd;
  off_t        offset;
  size_t       size;
} PinosMessageTransportUpdate;

/* PINOS_MESSAGE_ADD_MEM */
typedef struct {
  SpaDirection direction;
  uint32_t     port_id;
  uint32_t     mem_id;
  SpaDataType  type;
  int          memfd;
  uint32_t     flags;
  off_t        offset;
  size_t       size;
} PinosMessageAddMem;

typedef struct {
  uint32_t    mem_id;
  off_t       offset;
  size_t      size;
} PinosMessageMemRef;

/* PINOS_MESSAGE_USE_BUFFERS */
typedef struct {
  uint32_t            seq;
  SpaDirection        direction;
  uint32_t            port_id;
  unsigned int        n_buffers;
  PinosMessageMemRef *buffers;
} PinosMessageUseBuffers;

PinosConnection *  pinos_connection_new             (int              fd);
void               pinos_connection_destroy         (PinosConnection *conn);

bool               pinos_connection_get_next        (PinosConnection  *conn,
                                                     PinosMessageType *type,
                                                     uint32_t         *dest_id,
                                                     size_t           *size);
bool               pinos_connection_parse_message   (PinosConnection *conn,
                                                     void            *msg);
bool               pinos_connection_add_message     (PinosConnection *conn,
                                                     uint32_t         dest_id,
                                                     PinosMessageType type,
                                                     void            *msg);

bool               pinos_connection_flush           (PinosConnection *conn);
bool               pinos_connection_clear           (PinosConnection *conn);

#ifdef __cplusplus
}  /* extern "C" */
#endif

#endif /* __PINOS_CONNECTION_H__ */