Add poll interface and remove poll events

Use an interface to change items in a poll loop.
This commit is contained in:
Wim Taymans 2016-10-07 17:10:46 +02:00
parent fc4fd1424a
commit 2905d91467
20 changed files with 227 additions and 148 deletions

View file

@ -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");

View file

@ -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;

View file

@ -69,6 +69,7 @@ struct _SpaALSAState {
URI uri;
SpaIDMap *map;
SpaLog *log;
SpaPoll *data_loop;
snd_pcm_stream_t stream;
snd_output_t *output;