mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-16 07:00:00 -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
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
#include <spa/node.h>
|
||||
#include <spa/node-command.h>
|
||||
#include <spa/node-event.h>
|
||||
#include <spa/poll.h>
|
||||
#include <spa/port.h>
|
||||
#include <spa/props.h>
|
||||
#include <spa/queue.h>
|
||||
|
|
@ -51,6 +52,8 @@ static const char *uris[] = {
|
|||
SPA_PROPS_URI,
|
||||
SPA_QUEUE_URI,
|
||||
SPA_RINGBUFFER_URI,
|
||||
SPA_POLL__MainLoop,
|
||||
SPA_POLL__DataLoop,
|
||||
};
|
||||
|
||||
static uint32_t
|
||||
|
|
|
|||
|
|
@ -768,6 +768,8 @@ alsa_source_init (const SpaHandleFactory *factory,
|
|||
this->map = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_LOG_URI) == 0)
|
||||
this->log = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_POLL__DataLoop) == 0)
|
||||
this->data_loop = support[i].data;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
spa_log_error (this->log, "an id-map is needed");
|
||||
|
|
|
|||
|
|
@ -434,7 +434,6 @@ int
|
|||
spa_alsa_start (SpaALSAState *state)
|
||||
{
|
||||
int err;
|
||||
SpaNodeEvent event;
|
||||
|
||||
if (spa_alsa_open (state) < 0)
|
||||
return -1;
|
||||
|
|
@ -455,10 +454,6 @@ spa_alsa_start (SpaALSAState *state)
|
|||
return err;
|
||||
}
|
||||
|
||||
event.type = SPA_NODE_EVENT_TYPE_ADD_POLL;
|
||||
event.data = &state->poll;
|
||||
event.size = sizeof (state->poll);
|
||||
|
||||
state->poll.id = 0;
|
||||
state->poll.enabled = true;
|
||||
state->poll.fds = state->fds;
|
||||
|
|
@ -466,7 +461,7 @@ spa_alsa_start (SpaALSAState *state)
|
|||
state->poll.before_cb = NULL;
|
||||
state->poll.after_cb = alsa_on_fd_events;
|
||||
state->poll.user_data = state;
|
||||
state->event_cb (&state->node, &event, state->user_data);
|
||||
spa_poll_add_item (state->data_loop, &state->poll);
|
||||
|
||||
mmap_write (state);
|
||||
err = snd_pcm_start (state->hndl);
|
||||
|
|
@ -477,18 +472,11 @@ spa_alsa_start (SpaALSAState *state)
|
|||
int
|
||||
spa_alsa_stop (SpaALSAState *state)
|
||||
{
|
||||
SpaNodeEvent event;
|
||||
|
||||
if (!state->opened)
|
||||
return 0;
|
||||
|
||||
event.type = SPA_NODE_EVENT_TYPE_REMOVE_POLL;
|
||||
event.data = &state->poll;
|
||||
event.size = sizeof (state->poll);
|
||||
state->event_cb (&state->node, &event, state->user_data);
|
||||
|
||||
spa_poll_remove_item (state->data_loop, &state->poll);
|
||||
snd_pcm_drop (state->hndl);
|
||||
|
||||
spa_alsa_close (state);
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ struct _SpaALSAState {
|
|||
URI uri;
|
||||
SpaIDMap *map;
|
||||
SpaLog *log;
|
||||
SpaPoll *data_loop;
|
||||
|
||||
snd_pcm_stream_t stream;
|
||||
snd_output_t *output;
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ struct _SpaAudioTestSrc {
|
|||
URI uri;
|
||||
SpaIDMap *map;
|
||||
SpaLog *log;
|
||||
SpaPoll *data_loop;
|
||||
|
||||
SpaAudioTestSrcProps props[2];
|
||||
|
||||
|
|
@ -311,10 +312,7 @@ update_state (SpaAudioTestSrc *this, SpaNodeState state)
|
|||
static SpaResult
|
||||
update_poll_enabled (SpaAudioTestSrc *this, bool enabled)
|
||||
{
|
||||
SpaNodeEvent event;
|
||||
|
||||
if (this->event_cb) {
|
||||
event.type = SPA_NODE_EVENT_TYPE_UPDATE_POLL;
|
||||
this->timer.enabled = enabled;
|
||||
if (this->props[1].live) {
|
||||
if (enabled) {
|
||||
|
|
@ -337,9 +335,7 @@ update_poll_enabled (SpaAudioTestSrc *this, bool enabled)
|
|||
this->timer.idle_cb = audiotestsrc_on_output;
|
||||
this->timer.after_cb = NULL;
|
||||
}
|
||||
event.data = &this->timer;
|
||||
event.size = sizeof (this->timer);
|
||||
this->event_cb (&this->node, &event, this->user_data);
|
||||
spa_poll_update_item (this->data_loop, &this->timer);
|
||||
}
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
@ -416,7 +412,6 @@ spa_audiotestsrc_node_set_event_callback (SpaNode *node,
|
|||
void *user_data)
|
||||
{
|
||||
SpaAudioTestSrc *this;
|
||||
SpaNodeEvent event;
|
||||
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -424,20 +419,14 @@ spa_audiotestsrc_node_set_event_callback (SpaNode *node,
|
|||
this = (SpaAudioTestSrc *) node->handle;
|
||||
|
||||
if (event_cb == NULL && this->event_cb) {
|
||||
event.type = SPA_NODE_EVENT_TYPE_REMOVE_POLL;
|
||||
event.data = &this->timer;
|
||||
event.size = sizeof (this->timer);
|
||||
this->event_cb (&this->node, &event, this->user_data);
|
||||
spa_poll_remove_item (this->data_loop, &this->timer);
|
||||
}
|
||||
|
||||
this->event_cb = event_cb;
|
||||
this->user_data = user_data;
|
||||
|
||||
if (this->event_cb) {
|
||||
event.type = SPA_NODE_EVENT_TYPE_ADD_POLL;
|
||||
event.data = &this->timer;
|
||||
event.size = sizeof (this->timer);
|
||||
this->event_cb (&this->node, &event, this->user_data);
|
||||
spa_poll_add_item (this->data_loop, &this->timer);
|
||||
}
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
@ -1016,11 +1005,17 @@ audiotestsrc_init (const SpaHandleFactory *factory,
|
|||
this->map = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_LOG_URI) == 0)
|
||||
this->log = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_POLL__DataLoop) == 0)
|
||||
this->data_loop = support[i].data;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
spa_log_error (this->log, "an id-map is needed");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
if (this->data_loop == NULL) {
|
||||
spa_log_error (this->log, "a data_loop is needed");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
this->uri.node = spa_id_map_get_id (this->map, SPA_NODE_URI);
|
||||
this->uri.clock = spa_id_map_get_id (this->map, SPA_CLOCK_URI);
|
||||
|
||||
|
|
|
|||
|
|
@ -100,6 +100,7 @@ struct _SpaProxy {
|
|||
URI uri;
|
||||
SpaIDMap *map;
|
||||
SpaLog *log;
|
||||
SpaPoll *data_loop;
|
||||
|
||||
SpaProxyProps props[2];
|
||||
|
||||
|
|
@ -143,26 +144,19 @@ reset_proxy_props (SpaProxyProps *props)
|
|||
static SpaResult
|
||||
update_poll (SpaProxy *this, int socketfd)
|
||||
{
|
||||
SpaNodeEvent event;
|
||||
SpaProxyProps *p;
|
||||
SpaResult res = SPA_RESULT_OK;
|
||||
|
||||
p = &this->props[1];
|
||||
|
||||
if (p->socketfd != -1) {
|
||||
event.type = SPA_NODE_EVENT_TYPE_REMOVE_POLL;
|
||||
event.data = &this->poll;
|
||||
event.size = sizeof (this->poll);
|
||||
this->event_cb (&this->node, &event, this->user_data);
|
||||
spa_poll_remove_item (this->data_loop, &this->poll);
|
||||
}
|
||||
p->socketfd = socketfd;
|
||||
|
||||
if (p->socketfd != -1) {
|
||||
this->fds[0].fd = p->socketfd;
|
||||
event.type = SPA_NODE_EVENT_TYPE_ADD_POLL;
|
||||
event.data = &this->poll;
|
||||
event.size = sizeof (this->poll);
|
||||
this->event_cb (&this->node, &event, this->user_data);
|
||||
spa_poll_add_item (this->data_loop, &this->poll);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
@ -1121,9 +1115,6 @@ handle_node_event (SpaProxy *this,
|
|||
case SPA_NODE_EVENT_TYPE_HAVE_OUTPUT:
|
||||
case SPA_NODE_EVENT_TYPE_NEED_INPUT:
|
||||
case SPA_NODE_EVENT_TYPE_REUSE_BUFFER:
|
||||
case SPA_NODE_EVENT_TYPE_ADD_POLL:
|
||||
case SPA_NODE_EVENT_TYPE_UPDATE_POLL:
|
||||
case SPA_NODE_EVENT_TYPE_REMOVE_POLL:
|
||||
case SPA_NODE_EVENT_TYPE_DRAINED:
|
||||
case SPA_NODE_EVENT_TYPE_MARKER:
|
||||
case SPA_NODE_EVENT_TYPE_ERROR:
|
||||
|
|
@ -1377,11 +1368,17 @@ proxy_init (const SpaHandleFactory *factory,
|
|||
this->map = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_LOG_URI) == 0)
|
||||
this->log = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_POLL__DataLoop) == 0)
|
||||
this->data_loop = support[i].data;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
spa_log_error (this->log, "an id-map is needed");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
if (this->data_loop == NULL) {
|
||||
spa_log_error (this->log, "a data-loop is needed");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
this->uri.node = spa_id_map_get_id (this->map, SPA_NODE_URI);
|
||||
|
||||
this->node = proxy_node;
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
SpaLog *log;
|
||||
SpaPoll *data_loop;
|
||||
|
||||
bool export_buf;
|
||||
bool started;
|
||||
|
|
@ -843,6 +844,7 @@ v4l2_source_init (const SpaHandleFactory *factory,
|
|||
{
|
||||
SpaV4l2Source *this;
|
||||
unsigned int i;
|
||||
const char *str;
|
||||
|
||||
if (factory == NULL || handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -857,11 +859,17 @@ v4l2_source_init (const SpaHandleFactory *factory,
|
|||
this->map = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_LOG_URI) == 0)
|
||||
this->log = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_POLL__DataLoop) == 0)
|
||||
this->state[0].data_loop = support[i].data;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
spa_log_error (this->log, "an id-map is needed");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
if (this->state[0].data_loop == NULL) {
|
||||
spa_log_error (this->log, "a data_loop is needed");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
this->uri.node = spa_id_map_get_id (this->map, SPA_NODE_URI);
|
||||
this->uri.clock = spa_id_map_get_id (this->map, SPA_CLOCK_URI);
|
||||
|
||||
|
|
@ -881,11 +889,9 @@ v4l2_source_init (const SpaHandleFactory *factory,
|
|||
|
||||
this->state[0].export_buf = true;
|
||||
|
||||
for (i = 0; info && i < info->n_items; i++) {
|
||||
if (!strcmp (info->items[i].key, "device.path")) {
|
||||
strncpy (this->props[1].device, info->items[i].value, 63);
|
||||
this->props[1].props.unset_mask &= ~1;
|
||||
}
|
||||
if (info && (str = spa_dict_lookup (info, "device.path"))) {
|
||||
strncpy (this->props[1].device, str, 63);
|
||||
this->props[1].props.unset_mask &= ~1;
|
||||
}
|
||||
|
||||
update_state (this, SPA_NODE_STATE_CONFIGURE);
|
||||
|
|
|
|||
|
|
@ -1121,7 +1121,6 @@ spa_v4l2_start (SpaV4l2Source *this)
|
|||
{
|
||||
SpaV4l2State *state = &this->state[0];
|
||||
enum v4l2_buf_type type;
|
||||
SpaNodeEvent event;
|
||||
|
||||
if (state->started)
|
||||
return SPA_RESULT_OK;
|
||||
|
|
@ -1134,10 +1133,6 @@ spa_v4l2_start (SpaV4l2Source *this)
|
|||
state->started = true;
|
||||
update_state (this, SPA_NODE_STATE_STREAMING);
|
||||
|
||||
event.type = SPA_NODE_EVENT_TYPE_ADD_POLL;
|
||||
event.data = &state->poll;
|
||||
event.size = sizeof (state->poll);
|
||||
|
||||
state->fds[0].fd = state->fd;
|
||||
state->fds[0].events = POLLIN | POLLPRI | POLLERR;
|
||||
state->fds[0].revents = 0;
|
||||
|
|
@ -1150,7 +1145,7 @@ spa_v4l2_start (SpaV4l2Source *this)
|
|||
state->poll.before_cb = NULL;
|
||||
state->poll.after_cb = v4l2_on_fd_events;
|
||||
state->poll.user_data = this;
|
||||
this->event_cb (&this->node, &event, this->user_data);
|
||||
spa_poll_add_item (state->data_loop, &state->poll);
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
@ -1160,7 +1155,6 @@ spa_v4l2_pause (SpaV4l2Source *this)
|
|||
{
|
||||
SpaV4l2State *state = &this->state[0];
|
||||
enum v4l2_buf_type type;
|
||||
SpaNodeEvent event;
|
||||
int i;
|
||||
|
||||
if (!state->started)
|
||||
|
|
@ -1168,10 +1162,7 @@ spa_v4l2_pause (SpaV4l2Source *this)
|
|||
|
||||
state->started = false;
|
||||
|
||||
event.type = SPA_NODE_EVENT_TYPE_REMOVE_POLL;
|
||||
event.data = &state->poll;
|
||||
event.size = sizeof (state->poll);
|
||||
this->event_cb (&this->node, &event, this->user_data);
|
||||
spa_poll_remove_item (state->data_loop, &state->poll);
|
||||
|
||||
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
if (xioctl (state->fd, VIDIOC_STREAMOFF, &type) < 0) {
|
||||
|
|
|
|||
|
|
@ -70,9 +70,10 @@ struct _SpaVideoTestSrc {
|
|||
SpaNode node;
|
||||
SpaClock clock;
|
||||
|
||||
URI uri;
|
||||
SpaIDMap *map;
|
||||
SpaLog *log;
|
||||
URI uri;
|
||||
SpaPoll *data_loop;
|
||||
|
||||
SpaVideoTestSrcProps props[2];
|
||||
|
||||
|
|
@ -259,10 +260,7 @@ update_state (SpaVideoTestSrc *this, SpaNodeState state)
|
|||
static SpaResult
|
||||
update_poll_enabled (SpaVideoTestSrc *this, bool enabled)
|
||||
{
|
||||
SpaNodeEvent event;
|
||||
|
||||
if (this->event_cb && this->timer.enabled != enabled) {
|
||||
event.type = SPA_NODE_EVENT_TYPE_UPDATE_POLL;
|
||||
this->timer.enabled = enabled;
|
||||
if (this->props[1].live) {
|
||||
if (enabled) {
|
||||
|
|
@ -285,9 +283,7 @@ update_poll_enabled (SpaVideoTestSrc *this, bool enabled)
|
|||
this->timer.idle_cb = videotestsrc_on_output;
|
||||
this->timer.after_cb = NULL;
|
||||
}
|
||||
event.data = &this->timer;
|
||||
event.size = sizeof (this->timer);
|
||||
this->event_cb (&this->node, &event, this->user_data);
|
||||
spa_poll_update_item (this->data_loop, &this->timer);
|
||||
}
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
@ -364,7 +360,6 @@ spa_videotestsrc_node_set_event_callback (SpaNode *node,
|
|||
void *user_data)
|
||||
{
|
||||
SpaVideoTestSrc *this;
|
||||
SpaNodeEvent event;
|
||||
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -372,20 +367,14 @@ spa_videotestsrc_node_set_event_callback (SpaNode *node,
|
|||
this = (SpaVideoTestSrc *) node->handle;
|
||||
|
||||
if (event_cb == NULL && this->event_cb) {
|
||||
event.type = SPA_NODE_EVENT_TYPE_REMOVE_POLL;
|
||||
event.data = &this->timer;
|
||||
event.size = sizeof (this->timer);
|
||||
this->event_cb (&this->node, &event, this->user_data);
|
||||
spa_poll_remove_item (this->data_loop, &this->timer);
|
||||
}
|
||||
|
||||
this->event_cb = event_cb;
|
||||
this->user_data = user_data;
|
||||
|
||||
if (this->event_cb) {
|
||||
event.type = SPA_NODE_EVENT_TYPE_ADD_POLL;
|
||||
event.data = &this->timer;
|
||||
event.size = sizeof (this->timer);
|
||||
this->event_cb (&this->node, &event, this->user_data);
|
||||
spa_poll_add_item (this->data_loop, &this->timer);
|
||||
}
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
@ -964,6 +953,8 @@ videotestsrc_init (const SpaHandleFactory *factory,
|
|||
this->map = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_LOG_URI) == 0)
|
||||
this->log = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_POLL__DataLoop) == 0)
|
||||
this->data_loop = support[i].data;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
spa_log_error (this->log, "an id-map is needed");
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ typedef struct {
|
|||
unsigned int n_support;
|
||||
SpaIDMap *map;
|
||||
SpaLog *log;
|
||||
SpaPoll data_loop;
|
||||
URI uri;
|
||||
} AppData;
|
||||
|
||||
|
|
@ -165,25 +166,29 @@ on_sink_event (SpaNode *node, SpaNodeEvent *event, void *user_data)
|
|||
printf ("got error %d\n", res);
|
||||
break;
|
||||
}
|
||||
case SPA_NODE_EVENT_TYPE_ADD_POLL:
|
||||
{
|
||||
SpaPollItem *poll = event->data;
|
||||
int i;
|
||||
|
||||
data->poll = *poll;
|
||||
for (i = 0; i < data->poll.n_fds; i++) {
|
||||
data->fds[i] = poll->fds[i];
|
||||
}
|
||||
data->n_fds = data->poll.n_fds;
|
||||
data->poll.fds = data->fds;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
printf ("got event %d\n", event->type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
do_add_item (SpaPoll *poll,
|
||||
SpaPollItem *item)
|
||||
{
|
||||
AppData *data = SPA_CONTAINER_OF (poll, AppData, data_loop);
|
||||
int i;
|
||||
|
||||
data->poll = *item;
|
||||
for (i = 0; i < data->poll.n_fds; i++) {
|
||||
data->fds[i] = item->fds[i];
|
||||
}
|
||||
data->n_fds = data->poll.n_fds;
|
||||
data->poll.fds = data->fds;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
make_nodes (AppData *data)
|
||||
{
|
||||
|
|
@ -355,9 +360,18 @@ main (int argc, char *argv[])
|
|||
SpaResult res;
|
||||
|
||||
data.map = spa_id_map_get_default();
|
||||
data.data_loop.handle = NULL;
|
||||
data.data_loop.size = sizeof (SpaPoll);
|
||||
data.data_loop.info = NULL;
|
||||
data.data_loop.add_item = do_add_item;
|
||||
data.data_loop.update_item = NULL;
|
||||
data.data_loop.remove_item = NULL;
|
||||
|
||||
data.support[0].uri = SPA_ID_MAP_URI;
|
||||
data.support[0].data = data.map;
|
||||
data.n_support = 1;
|
||||
data.support[1].uri = SPA_POLL__DataLoop;
|
||||
data.support[1].data = &data.data_loop;
|
||||
data.n_support = 2;
|
||||
|
||||
data.uri.node = spa_id_map_get_id (data.map, SPA_NODE_URI);
|
||||
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ typedef struct {
|
|||
unsigned int n_support;
|
||||
SpaIDMap *map;
|
||||
SpaLog *log;
|
||||
SpaPoll data_loop;
|
||||
URI uri;
|
||||
} AppData;
|
||||
|
||||
|
|
@ -106,7 +107,7 @@ make_node (AppData *data, SpaNode **node, const char *lib, const char *name)
|
|||
continue;
|
||||
|
||||
handle = calloc (1, factory->size);
|
||||
if ((res = spa_handle_factory_init (factory, handle, NULL, NULL, 0)) < 0) {
|
||||
if ((res = spa_handle_factory_init (factory, handle, NULL, data->support, data->n_support)) < 0) {
|
||||
printf ("can't make factory instance: %d\n", res);
|
||||
return res;
|
||||
}
|
||||
|
|
@ -188,22 +189,43 @@ on_source_event (SpaNode *node, SpaNodeEvent *event, void *user_data)
|
|||
spa_node_port_reuse_buffer (data->source, 0, info->buffer_id);
|
||||
break;
|
||||
}
|
||||
case SPA_NODE_EVENT_TYPE_ADD_POLL:
|
||||
{
|
||||
SpaPollItem *poll = event->data;
|
||||
|
||||
data->poll = *poll;
|
||||
data->fds[0] = poll->fds[0];
|
||||
data->n_fds = 1;
|
||||
data->poll.fds = data->fds;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
printf ("got event %d\n", event->type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
do_add_item (SpaPoll *poll,
|
||||
SpaPollItem *item)
|
||||
{
|
||||
AppData *data = SPA_CONTAINER_OF (poll, AppData, data_loop);
|
||||
int i;
|
||||
|
||||
data->poll = *item;
|
||||
for (i = 0; i < data->poll.n_fds; i++) {
|
||||
data->fds[i] = item->fds[i];
|
||||
}
|
||||
data->n_fds = data->poll.n_fds;
|
||||
data->poll.fds = data->fds;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
do_update_item (SpaPoll *poll,
|
||||
SpaPollItem *item)
|
||||
{
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
do_remove_item (SpaPoll *poll,
|
||||
SpaPollItem *item)
|
||||
{
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
make_nodes (AppData *data, const char *device)
|
||||
{
|
||||
|
|
@ -220,7 +242,7 @@ make_nodes (AppData *data, const char *device)
|
|||
if ((res = spa_node_get_props (data->source, &props)) < 0)
|
||||
printf ("got get_props error %d\n", res);
|
||||
|
||||
value.value = device ? device : "/dev/video0";
|
||||
value.value = device ? device : "/dev/video7";
|
||||
value.size = strlen (value.value)+1;
|
||||
spa_props_set_value (props, spa_props_index_for_name (props, "device"), &value);
|
||||
|
||||
|
|
@ -433,9 +455,18 @@ main (int argc, char *argv[])
|
|||
|
||||
data.map = spa_id_map_get_default ();
|
||||
|
||||
data.data_loop.handle = NULL;
|
||||
data.data_loop.size = sizeof (SpaPoll);
|
||||
data.data_loop.info = NULL;
|
||||
data.data_loop.add_item = do_add_item;
|
||||
data.data_loop.update_item = do_update_item;
|
||||
data.data_loop.remove_item = do_remove_item;
|
||||
|
||||
data.support[0].uri = SPA_ID_MAP_URI;
|
||||
data.support[0].data = data.map;
|
||||
data.n_support = 1;
|
||||
data.support[1].uri = SPA_POLL__DataLoop;
|
||||
data.support[1].data = &data.data_loop;
|
||||
data.n_support = 2;
|
||||
|
||||
data.uri.node = spa_id_map_get_id (data.map, SPA_NODE_URI);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue