mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-07 13:30:09 -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
|
|
@ -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");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue