simplify events and commands

This commit is contained in:
Wim Taymans 2016-10-24 15:30:15 +02:00
parent 0373f73bac
commit d3dd90bb05
25 changed files with 220 additions and 252 deletions

View file

@ -186,7 +186,8 @@ v4l2_on_fd_events (SpaPollNotifyData *data)
SpaV4l2Monitor *this = data->user_data;
struct udev_device *dev;
const char *action;
SpaMonitorEvent event;
SpaMonitorItem *item;
dev = udev_monitor_receive_device (this->umonitor);
fill_item (&this->uitem, dev);
@ -196,16 +197,17 @@ v4l2_on_fd_events (SpaPollNotifyData *data)
if ((action = udev_device_get_action (dev)) == NULL)
action = "change";
item = &this->uitem.item;
if (strcmp (action, "add") == 0) {
event.type = SPA_MONITOR_EVENT_TYPE_ADDED;
item->event.type = SPA_MONITOR_EVENT_TYPE_ADDED;
} else if (strcmp (action, "change") == 0) {
event.type = SPA_MONITOR_EVENT_TYPE_CHANGED;
item->event.type = SPA_MONITOR_EVENT_TYPE_CHANGED;
} else if (strcmp (action, "remove") == 0) {
event.type = SPA_MONITOR_EVENT_TYPE_REMOVED;
item->event.type = SPA_MONITOR_EVENT_TYPE_REMOVED;
}
event.data = &this->uitem.item;
event.size = sizeof (this->uitem);
this->event_cb (&this->monitor, &event, this->user_data);
item->event.size = sizeof (this->uitem);
this->event_cb (&this->monitor, &item->event, this->user_data);
return 0;
}

View file

@ -225,25 +225,23 @@ spa_v4l2_source_node_set_props (SpaNode *node,
}
static SpaResult
do_command_complete (SpaPoll *poll,
uint32_t seq,
size_t size,
void *data,
void *user_data)
do_send_event (SpaPoll *poll,
bool async,
uint32_t seq,
size_t size,
void *data,
void *user_data)
{
SpaV4l2Source *this = user_data;
SpaNodeEvent event;
event.type = SPA_NODE_EVENT_TYPE_ASYNC_COMPLETE;
event.size = size;
event.data = data;
this->event_cb (&this->node, &event, this->user_data);
this->event_cb (&this->node, data, this->user_data);
return SPA_RESULT_OK;
}
static SpaResult
do_start (SpaPoll *poll,
bool async,
uint32_t seq,
size_t size,
void *data,
@ -255,19 +253,24 @@ do_start (SpaPoll *poll,
res = spa_v4l2_start (this);
ac.seq = seq;
ac.res = res;
spa_poll_invoke (this->state[0].main_loop,
do_command_complete,
seq,
sizeof (ac),
&ac,
this);
if (async) {
ac.event.type = SPA_NODE_EVENT_TYPE_ASYNC_COMPLETE;
ac.event.size = sizeof (SpaNodeEventAsyncComplete);
ac.seq = seq;
ac.res = res;
spa_poll_invoke (this->state[0].main_loop,
do_send_event,
seq,
sizeof (ac),
&ac,
this);
}
return res;
}
static SpaResult
do_pause (SpaPoll *poll,
bool async,
uint32_t seq,
size_t size,
void *data,
@ -279,18 +282,21 @@ do_pause (SpaPoll *poll,
res = spa_v4l2_pause (this);
ac.seq = seq;
ac.res = res;
spa_poll_invoke (this->state[0].main_loop,
do_command_complete,
seq,
sizeof (ac),
&ac,
this);
if (async) {
ac.event.type = SPA_NODE_EVENT_TYPE_ASYNC_COMPLETE;
ac.event.size = sizeof (SpaNodeEventAsyncComplete);
ac.seq = seq;
ac.res = res;
spa_poll_invoke (this->state[0].main_loop,
do_send_event,
seq,
sizeof (ac),
&ac,
this);
}
return res;
}
static SpaResult
spa_v4l2_source_node_send_command (SpaNode *node,
SpaNodeCommand *command)

View file

@ -895,7 +895,6 @@ static int
v4l2_on_fd_events (SpaPollNotifyData *data)
{
SpaV4l2Source *this = data->user_data;
SpaNodeEvent event;
SpaNodeEventHaveOutput ho;
if (data->fds[0].revents & POLLERR)
@ -907,11 +906,10 @@ v4l2_on_fd_events (SpaPollNotifyData *data)
if (mmap_read (this) < 0)
return 0;
event.type = SPA_NODE_EVENT_TYPE_HAVE_OUTPUT;
event.size = sizeof (ho);
event.data = &ho;
ho.event.type = SPA_NODE_EVENT_TYPE_HAVE_OUTPUT;
ho.event.size = sizeof (ho);
ho.port_id = 0;
this->event_cb (&this->node, &event, this->user_data);
this->event_cb (&this->node, &ho.event, this->user_data);
return 0;
}