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

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

View file

@ -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) {