mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05:00
Work on event loop
Make a new epoll based event loop and use it for the data tranport. Simplify the spa event api a little and rename to SpaLoop
This commit is contained in:
parent
0d2fa5ebc8
commit
ae93f15965
33 changed files with 1286 additions and 954 deletions
|
|
@ -22,13 +22,12 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
|
||||
#include <libudev.h>
|
||||
|
||||
#include <spa/log.h>
|
||||
#include <spa/id-map.h>
|
||||
#include <spa/poll.h>
|
||||
#include <spa/loop.h>
|
||||
#include <spa/monitor.h>
|
||||
#include <lib/debug.h>
|
||||
|
||||
|
|
@ -54,7 +53,7 @@ struct _SpaV4l2Monitor {
|
|||
URI uri;
|
||||
SpaIDMap *map;
|
||||
SpaLog *log;
|
||||
SpaPoll *main_loop;
|
||||
SpaLoop *main_loop;
|
||||
|
||||
SpaMonitorEventCallback event_cb;
|
||||
void *user_data;
|
||||
|
|
@ -65,9 +64,7 @@ struct _SpaV4l2Monitor {
|
|||
|
||||
V4l2Item uitem;
|
||||
|
||||
int fd;
|
||||
SpaPollFd fds[1];
|
||||
SpaPollItem poll;
|
||||
SpaSource source;
|
||||
};
|
||||
|
||||
static SpaResult
|
||||
|
|
@ -180,19 +177,18 @@ fill_item (V4l2Item *item, struct udev_device *udevice)
|
|||
}
|
||||
|
||||
|
||||
static int
|
||||
v4l2_on_fd_events (SpaPollNotifyData *data)
|
||||
static void
|
||||
v4l2_on_fd_events (SpaSource *source)
|
||||
{
|
||||
SpaV4l2Monitor *this = data->user_data;
|
||||
SpaV4l2Monitor *this = source->data;
|
||||
struct udev_device *dev;
|
||||
const char *action;
|
||||
SpaMonitorItem *item;
|
||||
|
||||
|
||||
dev = udev_monitor_receive_device (this->umonitor);
|
||||
fill_item (&this->uitem, dev);
|
||||
if (dev == NULL)
|
||||
return 0;
|
||||
return;
|
||||
|
||||
if ((action = udev_device_get_action (dev)) == NULL)
|
||||
action = "change";
|
||||
|
|
@ -208,8 +204,6 @@ v4l2_on_fd_events (SpaPollNotifyData *data)
|
|||
}
|
||||
item->event.size = sizeof (this->uitem);
|
||||
this->event_cb (&this->monitor, &item->event, this->user_data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
|
|
@ -241,23 +235,14 @@ spa_v4l2_monitor_set_event_callback (SpaMonitor *monitor,
|
|||
NULL);
|
||||
|
||||
udev_monitor_enable_receiving (this->umonitor);
|
||||
this->fd = udev_monitor_get_fd (this->umonitor);;
|
||||
this->source.func = v4l2_on_fd_events;
|
||||
this->source.data = this;
|
||||
this->source.fd = udev_monitor_get_fd (this->umonitor);;
|
||||
this->source.mask = SPA_IO_IN | SPA_IO_ERR;
|
||||
|
||||
this->fds[0].fd = this->fd;
|
||||
this->fds[0].events = POLLIN | POLLPRI | POLLERR;
|
||||
this->fds[0].revents = 0;
|
||||
|
||||
this->poll.id = 0;
|
||||
this->poll.enabled = true;
|
||||
this->poll.fds = this->fds;
|
||||
this->poll.n_fds = 1;
|
||||
this->poll.idle_cb = NULL;
|
||||
this->poll.before_cb = NULL;
|
||||
this->poll.after_cb = v4l2_on_fd_events;
|
||||
this->poll.user_data = this;
|
||||
spa_poll_add_item (this->main_loop, &this->poll);
|
||||
spa_loop_add_source (this->main_loop, &this->source);
|
||||
} else {
|
||||
spa_poll_remove_item (this->main_loop, &this->poll);
|
||||
spa_loop_remove_source (this->main_loop, &this->source);
|
||||
}
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
|
|
@ -372,7 +357,7 @@ v4l2_monitor_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__MainLoop) == 0)
|
||||
else if (strcmp (support[i].uri, SPA_LOOP__MainLoop) == 0)
|
||||
this->main_loop = support[i].data;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
#include <spa/video/format.h>
|
||||
#include <spa/list.h>
|
||||
#include <spa/log.h>
|
||||
#include <spa/loop.h>
|
||||
#include <spa/id-map.h>
|
||||
#include <lib/debug.h>
|
||||
#include <lib/props.h>
|
||||
|
|
@ -88,8 +89,8 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
SpaLog *log;
|
||||
SpaPoll *main_loop;
|
||||
SpaPoll *data_loop;
|
||||
SpaLoop *main_loop;
|
||||
SpaLoop *data_loop;
|
||||
|
||||
bool export_buf;
|
||||
bool started;
|
||||
|
|
@ -115,8 +116,8 @@ typedef struct {
|
|||
unsigned int n_buffers;
|
||||
SpaList ready;
|
||||
|
||||
SpaPollFd fds[1];
|
||||
SpaPollItem poll;
|
||||
bool source_enabled;
|
||||
SpaSource source;
|
||||
|
||||
SpaPortInfo info;
|
||||
SpaAllocParam *params[2];
|
||||
|
|
@ -228,7 +229,7 @@ spa_v4l2_source_node_set_props (SpaNode *node,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
do_pause_done (SpaPoll *poll,
|
||||
do_pause_done (SpaLoop *loop,
|
||||
bool async,
|
||||
uint32_t seq,
|
||||
size_t size,
|
||||
|
|
@ -253,7 +254,7 @@ do_pause_done (SpaPoll *poll,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
do_pause (SpaPoll *poll,
|
||||
do_pause (SpaLoop *loop,
|
||||
bool async,
|
||||
uint32_t seq,
|
||||
size_t size,
|
||||
|
|
@ -275,7 +276,7 @@ do_pause (SpaPoll *poll,
|
|||
ac.event.size = sizeof (SpaNodeEventAsyncComplete);
|
||||
ac.seq = seq;
|
||||
ac.res = res;
|
||||
spa_poll_invoke (this->state[0].main_loop,
|
||||
spa_loop_invoke (this->state[0].main_loop,
|
||||
do_pause_done,
|
||||
seq,
|
||||
sizeof (ac),
|
||||
|
|
@ -286,7 +287,7 @@ do_pause (SpaPoll *poll,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
do_start_done (SpaPoll *poll,
|
||||
do_start_done (SpaLoop *loop,
|
||||
bool async,
|
||||
uint32_t seq,
|
||||
size_t size,
|
||||
|
|
@ -307,7 +308,7 @@ do_start_done (SpaPoll *poll,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
do_start (SpaPoll *poll,
|
||||
do_start (SpaLoop *loop,
|
||||
bool async,
|
||||
uint32_t seq,
|
||||
size_t size,
|
||||
|
|
@ -329,7 +330,7 @@ do_start (SpaPoll *poll,
|
|||
ac.event.size = sizeof (SpaNodeEventAsyncComplete);
|
||||
ac.seq = seq;
|
||||
ac.res = res;
|
||||
spa_poll_invoke (this->state[0].main_loop,
|
||||
spa_loop_invoke (this->state[0].main_loop,
|
||||
do_start_done,
|
||||
seq,
|
||||
sizeof (ac),
|
||||
|
|
@ -372,7 +373,7 @@ spa_v4l2_source_node_send_command (SpaNode *node,
|
|||
if ((res = spa_v4l2_stream_on (this)) < 0)
|
||||
return res;
|
||||
|
||||
return spa_poll_invoke (this->state[0].data_loop,
|
||||
return spa_loop_invoke (this->state[0].data_loop,
|
||||
do_start,
|
||||
++this->seq,
|
||||
command->size,
|
||||
|
|
@ -392,7 +393,7 @@ spa_v4l2_source_node_send_command (SpaNode *node,
|
|||
if (!state->started)
|
||||
return SPA_RESULT_OK;
|
||||
|
||||
return spa_poll_invoke (this->state[0].data_loop,
|
||||
return spa_loop_invoke (this->state[0].data_loop,
|
||||
do_pause,
|
||||
++this->seq,
|
||||
command->size,
|
||||
|
|
@ -1007,9 +1008,9 @@ 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__MainLoop) == 0)
|
||||
else if (strcmp (support[i].uri, SPA_LOOP__MainLoop) == 0)
|
||||
this->state[0].main_loop = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_POLL__DataLoop) == 0)
|
||||
else if (strcmp (support[i].uri, SPA_LOOP__DataLoop) == 0)
|
||||
this->state[0].data_loop = support[i].data;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
#define CLEAR(x) memset(&(x), 0, sizeof(x))
|
||||
|
||||
static int v4l2_on_fd_events (SpaPollNotifyData *data);
|
||||
static void v4l2_on_fd_events (SpaSource *source);
|
||||
|
||||
static int
|
||||
xioctl (int fd, int request, void *arg)
|
||||
|
|
@ -69,19 +69,11 @@ spa_v4l2_open (SpaV4l2Source *this)
|
|||
return -1;
|
||||
}
|
||||
|
||||
state->fds[0].fd = state->fd;
|
||||
state->fds[0].events = POLLIN | POLLPRI | POLLERR;
|
||||
state->fds[0].revents = 0;
|
||||
|
||||
state->poll.id = 0;
|
||||
state->poll.enabled = false;
|
||||
state->poll.fds = state->fds;
|
||||
state->poll.n_fds = 1;
|
||||
state->poll.idle_cb = NULL;
|
||||
state->poll.before_cb = NULL;
|
||||
state->poll.after_cb = v4l2_on_fd_events;
|
||||
state->poll.user_data = this;
|
||||
spa_poll_add_item (state->data_loop, &state->poll);
|
||||
state->source.func = v4l2_on_fd_events;
|
||||
state->source.data = this;
|
||||
state->source.fd = state->fd;
|
||||
state->source.mask = SPA_IO_IN | SPA_IO_ERR;
|
||||
state->source.rmask = 0;
|
||||
|
||||
state->opened = true;
|
||||
|
||||
|
|
@ -158,7 +150,8 @@ spa_v4l2_close (SpaV4l2Source *this)
|
|||
|
||||
spa_log_info (state->log, "v4l2: close");
|
||||
|
||||
spa_poll_remove_item (state->data_loop, &state->poll);
|
||||
if (state->source_enabled)
|
||||
spa_loop_remove_source (state->data_loop, &state->source);
|
||||
|
||||
if (close(state->fd))
|
||||
perror ("close");
|
||||
|
|
@ -890,27 +883,25 @@ mmap_read (SpaV4l2Source *this)
|
|||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
v4l2_on_fd_events (SpaPollNotifyData *data)
|
||||
static void
|
||||
v4l2_on_fd_events (SpaSource *source)
|
||||
{
|
||||
SpaV4l2Source *this = data->user_data;
|
||||
SpaV4l2Source *this = source->data;
|
||||
SpaNodeEventHaveOutput ho;
|
||||
|
||||
if (data->fds[0].revents & POLLERR)
|
||||
return -1;
|
||||
if (source->rmask & SPA_IO_ERR)
|
||||
return;
|
||||
|
||||
if (!(data->fds[0].revents & POLLIN))
|
||||
return 0;
|
||||
if (!(source->rmask & SPA_IO_IN))
|
||||
return;
|
||||
|
||||
if (mmap_read (this) < 0)
|
||||
return 0;
|
||||
return;
|
||||
|
||||
ho.event.type = SPA_NODE_EVENT_TYPE_HAVE_OUTPUT;
|
||||
ho.event.size = sizeof (ho);
|
||||
ho.port_id = 0;
|
||||
this->event_cb (&this->node, &ho.event, this->user_data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
|
|
@ -1150,8 +1141,13 @@ static SpaResult
|
|||
spa_v4l2_port_set_enabled (SpaV4l2Source *this, bool enabled)
|
||||
{
|
||||
SpaV4l2State *state = &this->state[0];
|
||||
state->poll.enabled = enabled;
|
||||
spa_poll_update_item (state->data_loop, &state->poll);
|
||||
if (state->source_enabled != enabled) {
|
||||
state->source_enabled = enabled;
|
||||
if (enabled)
|
||||
spa_loop_add_source (state->data_loop, &state->source);
|
||||
else
|
||||
spa_loop_remove_source (state->data_loop, &state->source);
|
||||
}
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue