mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
Add poll interface and remove poll events
Use an interface to change items in a poll loop.
This commit is contained in:
parent
fc4fd1424a
commit
2905d91467
20 changed files with 227 additions and 148 deletions
|
|
@ -88,6 +88,9 @@ typedef void (*SpaNotify) (void *data);
|
|||
#define SPA_CLAMP(v,a,b) ((v)>(b) ? (b) : ((v) < (a) ? (a) : (v)))
|
||||
|
||||
#define SPA_MEMBER(b,o,t) ((t*)((uint8_t*)(b) + (o)))
|
||||
|
||||
#define SPA_CONTAINER_OF(p,t,m) (t*)((uint8_t*)p - offsetof (t,m))
|
||||
|
||||
#define SPA_PTRDIFF(p1,p2) ((uint8_t*)(p1) - (uint8_t*)(p2))
|
||||
|
||||
#define SPA_PTR_TO_INT(p) ((int) ((intptr_t) (p)))
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ extern "C" {
|
|||
|
||||
typedef struct _SpaDict SpaDict;
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <spa/defs.h>
|
||||
|
||||
typedef struct {
|
||||
|
|
@ -38,6 +40,18 @@ struct _SpaDict {
|
|||
SpaDictItem *items;
|
||||
};
|
||||
|
||||
static inline const char *
|
||||
spa_dict_lookup (const SpaDict *dict, const char *key)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < dict->n_items; i++) {
|
||||
if (!strcmp (dict->items[i].key, key))
|
||||
return dict->items[i].value;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -37,9 +37,6 @@ typedef struct _SpaNodeEvent SpaNodeEvent;
|
|||
#define SPA_NODE_EVENT__HaveOutput SPA_NODE_EVENT_PREFIX "HaveOutput"
|
||||
#define SPA_NODE_EVENT__NeedInput SPA_NODE_EVENT_PREFIX "NeedInput"
|
||||
#define SPA_NODE_EVENT__ReuseBuffer SPA_NODE_EVENT_PREFIX "ReuseBuffer"
|
||||
#define SPA_NODE_EVENT__AddPoll SPA_NODE_EVENT_PREFIX "AddPoll"
|
||||
#define SPA_NODE_EVENT__UpdatePoll SPA_NODE_EVENT_PREFIX "UpdatePoll"
|
||||
#define SPA_NODE_EVENT__RemovePoll SPA_NODE_EVENT_PREFIX "RemovePoll"
|
||||
#define SPA_NODE_EVENT__Drained SPA_NODE_EVENT_PREFIX "Drained"
|
||||
#define SPA_NODE_EVENT__Marker SPA_NODE_EVENT_PREFIX "Marker"
|
||||
#define SPA_NODE_EVENT__Error SPA_NODE_EVENT_PREFIX "Error"
|
||||
|
|
@ -53,9 +50,6 @@ typedef struct _SpaNodeEvent SpaNodeEvent;
|
|||
* @SPA_NODE_EVENT_TYPE_HAVE_OUTPUT: emited when an async node has output that can be pulled
|
||||
* @SPA_NODE_EVENT_TYPE_NEED_INPUT: emited when more data can be pushed to an async node
|
||||
* @SPA_NODE_EVENT_TYPE_REUSE_BUFFER: emited when a buffer can be reused
|
||||
* @SPA_NODE_EVENT_TYPE_ADD_POLL: emited when a pollfd should be added. data points to #SpaPollItem
|
||||
* @SPA_NODE_EVENT_TYPE_UPDATE_POLL: update the pollfd item
|
||||
* @SPA_NODE_EVENT_TYPE_REMOVE_POLL: emited when a pollfd should be removed. data points to #SpaPollItem
|
||||
* @SPA_NODE_EVENT_TYPE_DRAINED: emited when DRAIN command completed
|
||||
* @SPA_NODE_EVENT_TYPE_MARKER: emited when MARK command completed
|
||||
* @SPA_NODE_EVENT_TYPE_ERROR: emited when error occured
|
||||
|
|
@ -69,9 +63,6 @@ typedef enum {
|
|||
SPA_NODE_EVENT_TYPE_HAVE_OUTPUT,
|
||||
SPA_NODE_EVENT_TYPE_NEED_INPUT,
|
||||
SPA_NODE_EVENT_TYPE_REUSE_BUFFER,
|
||||
SPA_NODE_EVENT_TYPE_ADD_POLL,
|
||||
SPA_NODE_EVENT_TYPE_UPDATE_POLL,
|
||||
SPA_NODE_EVENT_TYPE_REMOVE_POLL,
|
||||
SPA_NODE_EVENT_TYPE_DRAINED,
|
||||
SPA_NODE_EVENT_TYPE_MARKER,
|
||||
SPA_NODE_EVENT_TYPE_ERROR,
|
||||
|
|
|
|||
|
|
@ -24,7 +24,16 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct _SpaPoll SpaPoll;
|
||||
|
||||
#define SPA_POLL_URI "http://spaplug.in/ns/poll"
|
||||
#define SPA_POLL_PREFIX SPA_POLL_URI "#"
|
||||
#define SPA_POLL__MainLoop SPA_POLL_PREFIX "MainLoop"
|
||||
#define SPA_POLL__DataLoop SPA_POLL_PREFIX "DataLoop"
|
||||
|
||||
#include <spa/defs.h>
|
||||
#include <spa/plugin.h>
|
||||
#include <spa/dict.h>
|
||||
|
||||
/**
|
||||
* SpaPollFd:
|
||||
|
|
@ -56,7 +65,8 @@ typedef int (*SpaPollNotify) (SpaPollNotifyData *data);
|
|||
|
||||
/**
|
||||
* SpaPollItem:
|
||||
* @id: id of the poll item
|
||||
* @id: id of the poll item. This will be set when
|
||||
* adding the item to #SpaPoll.
|
||||
* @enabled: if the item is enabled
|
||||
* @fds: array of file descriptors to watch
|
||||
* @n_fds: number of elements in @fds
|
||||
|
|
@ -76,6 +86,50 @@ typedef struct {
|
|||
void *user_data;
|
||||
} SpaPollItem;
|
||||
|
||||
/**
|
||||
* SpaPoll:
|
||||
*
|
||||
* Register poll events
|
||||
*/
|
||||
struct _SpaPoll {
|
||||
/* pointer to the handle owning this interface */
|
||||
SpaHandle *handle;
|
||||
/* the total size of this structure. This can be used to expand this
|
||||
* structure in the future */
|
||||
size_t size;
|
||||
/**
|
||||
* SpaPoll::info
|
||||
*
|
||||
* Extra information
|
||||
*/
|
||||
const SpaDict *info;
|
||||
/**
|
||||
* SpaPoll::add_item:
|
||||
* @poll: a #SpaPoll
|
||||
* @item: a #SpaPollItem
|
||||
*
|
||||
* Add @item to the list of polled items.
|
||||
*
|
||||
* The id in @item will be set and must be passed when updating or removing
|
||||
* the @item.
|
||||
*
|
||||
* Returns: #SPA_RESULT_OK on success
|
||||
* #SPA_RESULT_INVALID_ARGUMENTS when @poll or @item is %NULL
|
||||
*/
|
||||
SpaResult (*add_item) (SpaPoll *poll,
|
||||
SpaPollItem *item);
|
||||
|
||||
SpaResult (*update_item) (SpaPoll *poll,
|
||||
SpaPollItem *item);
|
||||
|
||||
SpaResult (*remove_item) (SpaPoll *poll,
|
||||
SpaPollItem *item);
|
||||
};
|
||||
|
||||
#define spa_poll_add_item(n,...) (n)->add_item((n),__VA_ARGS__)
|
||||
#define spa_poll_update_item(n,...) (n)->update_item((n),__VA_ARGS__)
|
||||
#define spa_poll_remove_item(n,...) (n)->remove_item((n),__VA_ARGS__)
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue