mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -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
|
|
@ -27,6 +27,7 @@ extern "C" {
|
|||
#endif
|
||||
#include <inttypes.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef enum {
|
||||
|
|
|
|||
95
spa/include/spa/loop.h
Normal file
95
spa/include/spa/loop.h
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
/* Simple Plugin API
|
||||
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __SPA_LOOP_H__
|
||||
#define __SPA_LOOP_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct _SpaLoop SpaLoop;
|
||||
typedef struct _SpaSource SpaSource;
|
||||
|
||||
#define SPA_LOOP_URI "http://spaplug.in/ns/loop"
|
||||
#define SPA_LOOP_PREFIX SPA_LOOP_URI "#"
|
||||
#define SPA_LOOP__MainLoop SPA_LOOP_PREFIX "MainLoop"
|
||||
#define SPA_LOOP__DataLoop SPA_LOOP_PREFIX "DataLoop"
|
||||
|
||||
#include <spa/defs.h>
|
||||
|
||||
typedef void (*SpaSourceFunc) (SpaSource *source);
|
||||
|
||||
typedef enum {
|
||||
SPA_IO_IN = (1 << 0),
|
||||
SPA_IO_OUT = (1 << 1),
|
||||
SPA_IO_HUP = (1 << 2),
|
||||
SPA_IO_ERR = (1 << 3),
|
||||
} SpaIO;
|
||||
|
||||
struct _SpaSource {
|
||||
SpaLoop *loop;
|
||||
SpaSourceFunc func;
|
||||
void *data;
|
||||
int fd;
|
||||
SpaIO mask;
|
||||
SpaIO rmask;
|
||||
void *loop_private;
|
||||
};
|
||||
|
||||
typedef SpaResult (*SpaInvokeFunc) (SpaLoop *loop,
|
||||
bool async,
|
||||
uint32_t seq,
|
||||
size_t size,
|
||||
void *data,
|
||||
void *user_data);
|
||||
/**
|
||||
* SpaLoop:
|
||||
*
|
||||
* Register sources to an event loop
|
||||
*/
|
||||
struct _SpaLoop {
|
||||
/* the total size of this structure. This can be used to expand this
|
||||
* structure in the future */
|
||||
size_t size;
|
||||
|
||||
SpaResult (*add_source) (SpaLoop *loop,
|
||||
SpaSource *source);
|
||||
SpaResult (*update_source) (SpaSource *source);
|
||||
|
||||
void (*remove_source) (SpaSource *source);
|
||||
|
||||
SpaResult (*invoke) (SpaLoop *loop,
|
||||
SpaInvokeFunc func,
|
||||
uint32_t seq,
|
||||
size_t size,
|
||||
void *data,
|
||||
void *user_data);
|
||||
};
|
||||
|
||||
#define spa_loop_add_source(l,...) (l)->add_source((l),__VA_ARGS__)
|
||||
#define spa_loop_update_source(l,...) (l)->update_source(__VA_ARGS__)
|
||||
#define spa_loop_remove_source(l,...) (l)->remove_source(__VA_ARGS__)
|
||||
#define spa_loop_invoke(l,...) (l)->invoke((l),__VA_ARGS__)
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* __SPA_LOOP_H__ */
|
||||
|
|
@ -27,7 +27,6 @@ extern "C" {
|
|||
typedef struct _SpaNodeEvent SpaNodeEvent;
|
||||
|
||||
#include <spa/defs.h>
|
||||
#include <spa/poll.h>
|
||||
#include <spa/node.h>
|
||||
|
||||
#define SPA_NODE_EVENT_URI "http://spaplug.in/ns/node-event"
|
||||
|
|
|
|||
|
|
@ -1,183 +0,0 @@
|
|||
/* Simple Plugin API
|
||||
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __SPA_POLL_H__
|
||||
#define __SPA_POLL_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct _SpaPoll SpaPoll;
|
||||
|
||||
#define SPA_POLL_URI "http://spaplug.in/ns/poll"
|
||||
#define SPA_POLL_PREFIX SPA_POLL_URI "#"
|
||||
#define SPA_POLL__MainLoop SPA_POLL_PREFIX "MainLoop"
|
||||
#define SPA_POLL__DataLoop SPA_POLL_PREFIX "DataLoop"
|
||||
|
||||
#include <spa/defs.h>
|
||||
#include <spa/plugin.h>
|
||||
#include <spa/dict.h>
|
||||
|
||||
/**
|
||||
* SpaPollFd:
|
||||
* @fd: a file descriptor
|
||||
* @events: events to watch
|
||||
* @revents: events after poll
|
||||
*/
|
||||
typedef struct {
|
||||
int fd;
|
||||
short events;
|
||||
short revents;
|
||||
} SpaPollFd;
|
||||
|
||||
/**
|
||||
* SpaPollNotifyData:
|
||||
* @user_data: user data
|
||||
* @fds: array of file descriptors
|
||||
* @n_fds: number of elements in @fds
|
||||
*
|
||||
* Data passed to #SpaPollNotify.
|
||||
*/
|
||||
typedef struct {
|
||||
void *user_data;
|
||||
SpaPollFd *fds;
|
||||
unsigned int n_fds;
|
||||
} SpaPollNotifyData;
|
||||
|
||||
typedef SpaResult (*SpaPollNotify) (SpaPollNotifyData *data);
|
||||
|
||||
/**
|
||||
* SpaPollItem:
|
||||
* @id: id of the poll item. This will be set when
|
||||
* adding the item to #SpaPoll.
|
||||
* @enabled: if the item is enabled
|
||||
* @fds: array of file descriptors to watch
|
||||
* @n_fds: number of elements in @fds
|
||||
* @idle_cb: callback called when there is no other work
|
||||
* @before_cb: callback called before starting the poll
|
||||
* @after_cb: callback called after the poll loop
|
||||
* @user_data: user data passed to callbacks
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t id;
|
||||
bool enabled;
|
||||
SpaPollFd *fds;
|
||||
unsigned int n_fds;
|
||||
SpaPollNotify idle_cb;
|
||||
SpaPollNotify before_cb;
|
||||
SpaPollNotify after_cb;
|
||||
void *user_data;
|
||||
} SpaPollItem;
|
||||
|
||||
|
||||
/**
|
||||
* SpaPollInvokeFunc:
|
||||
* @poll: a #SpaPoll
|
||||
* @async: If this function was called async
|
||||
* @seq: sequence number
|
||||
* @size: size of data
|
||||
* @data: data
|
||||
* @user_data: extra user data
|
||||
*
|
||||
* Function called from SpaPoll::invoke. If @async is %true, invoke returned
|
||||
* an async return value and this function should possibly schedule an async
|
||||
* reply.
|
||||
*
|
||||
* Returns: the result of the invoke function
|
||||
*/
|
||||
typedef SpaResult (*SpaPollInvokeFunc) (SpaPoll *poll,
|
||||
bool async,
|
||||
uint32_t seq,
|
||||
size_t size,
|
||||
void *data,
|
||||
void *user_data);
|
||||
|
||||
|
||||
/**
|
||||
* SpaPoll:
|
||||
*
|
||||
* Register poll events
|
||||
*/
|
||||
struct _SpaPoll {
|
||||
/* the total size of this structure. This can be used to expand this
|
||||
* structure in the future */
|
||||
size_t size;
|
||||
/**
|
||||
* SpaPoll::info
|
||||
*
|
||||
* Extra information
|
||||
*/
|
||||
const SpaDict *info;
|
||||
/**
|
||||
* SpaPoll::add_item:
|
||||
* @poll: a #SpaPoll
|
||||
* @item: a #SpaPollItem
|
||||
*
|
||||
* Add @item to the list of polled items.
|
||||
*
|
||||
* The id in @item will be set and must be passed when updating or removing
|
||||
* the @item.
|
||||
*
|
||||
* Returns: #SPA_RESULT_OK on success
|
||||
* #SPA_RESULT_INVALID_ARGUMENTS when @poll or @item is %NULL
|
||||
*/
|
||||
SpaResult (*add_item) (SpaPoll *poll,
|
||||
SpaPollItem *item);
|
||||
|
||||
SpaResult (*update_item) (SpaPoll *poll,
|
||||
SpaPollItem *item);
|
||||
|
||||
SpaResult (*remove_item) (SpaPoll *poll,
|
||||
SpaPollItem *item);
|
||||
|
||||
/**
|
||||
* SpaPoll::invoke:
|
||||
* @poll: a #SpaPoll
|
||||
* @func: function to call
|
||||
* @seq: sequence number
|
||||
* @size: size of data
|
||||
* @data: data
|
||||
* @user_data: extra user data
|
||||
*
|
||||
* Invoke @func from the poll context of @poll. @seq, @data, @size and
|
||||
* @user_data are passed to @func.
|
||||
*
|
||||
* Returns: The result of @func when this function is already called in
|
||||
* the @poll context, otherwise an async return value with @seq or, when
|
||||
* @seq is %SPA_ID_INVALID, %SPA_RETURN_OK.
|
||||
*/
|
||||
SpaResult (*invoke) (SpaPoll *poll,
|
||||
SpaPollInvokeFunc func,
|
||||
uint32_t seq,
|
||||
size_t size,
|
||||
void *data,
|
||||
void *user_data);
|
||||
};
|
||||
|
||||
#define spa_poll_add_item(n,...) (n)->add_item((n),__VA_ARGS__)
|
||||
#define spa_poll_update_item(n,...) (n)->update_item((n),__VA_ARGS__)
|
||||
#define spa_poll_remove_item(n,...) (n)->remove_item((n),__VA_ARGS__)
|
||||
#define spa_poll_invoke(n,...) (n)->invoke((n),__VA_ARGS__)
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* __SPA_POLL_H__ */
|
||||
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
#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>
|
||||
|
||||
|
|
@ -56,7 +56,7 @@ struct _SpaALSAMonitor {
|
|||
URI uri;
|
||||
SpaIDMap *map;
|
||||
SpaLog *log;
|
||||
SpaPoll *main_loop;
|
||||
SpaLoop *main_loop;
|
||||
|
||||
SpaMonitorEventCallback event_cb;
|
||||
void *user_data;
|
||||
|
|
@ -68,8 +68,7 @@ struct _SpaALSAMonitor {
|
|||
ALSAItem uitem;
|
||||
|
||||
int fd;
|
||||
SpaPollFd fds[1];
|
||||
SpaPollItem poll;
|
||||
SpaSource source;
|
||||
};
|
||||
|
||||
static SpaResult
|
||||
|
|
@ -244,17 +243,17 @@ fill_item (SpaALSAMonitor *this, ALSAItem *item, struct udev_device *udevice)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
alsa_on_fd_events (SpaPollNotifyData *data)
|
||||
static void
|
||||
alsa_on_fd_events (SpaSource *source)
|
||||
{
|
||||
SpaALSAMonitor *this = data->user_data;
|
||||
SpaALSAMonitor *this = source->data;
|
||||
struct udev_device *dev;
|
||||
const char *str;
|
||||
SpaMonitorItem *item;
|
||||
|
||||
dev = udev_monitor_receive_device (this->umonitor);
|
||||
if (fill_item (this, &this->uitem, dev) < 0)
|
||||
return 0;
|
||||
return;
|
||||
|
||||
if ((str = udev_device_get_action (dev)) == NULL)
|
||||
str = "change";
|
||||
|
|
@ -270,8 +269,6 @@ alsa_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
|
||||
|
|
@ -303,22 +300,15 @@ spa_alsa_monitor_set_event_callback (SpaMonitor *monitor,
|
|||
NULL);
|
||||
|
||||
udev_monitor_enable_receiving (this->umonitor);
|
||||
this->fd = udev_monitor_get_fd (this->umonitor);;
|
||||
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 = alsa_on_fd_events;
|
||||
this->poll.user_data = this;
|
||||
spa_poll_add_item (this->main_loop, &this->poll);
|
||||
this->source.func = alsa_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;
|
||||
|
||||
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;
|
||||
|
|
@ -433,7 +423,7 @@ alsa_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) {
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ spa_alsa_sink_node_set_props (SpaNode *node,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
do_send_event (SpaPoll *poll,
|
||||
do_send_event (SpaLoop *loop,
|
||||
bool async,
|
||||
uint32_t seq,
|
||||
size_t size,
|
||||
|
|
@ -167,7 +167,7 @@ do_send_event (SpaPoll *poll,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
do_command (SpaPoll *poll,
|
||||
do_command (SpaLoop *loop,
|
||||
bool async,
|
||||
uint32_t seq,
|
||||
size_t size,
|
||||
|
|
@ -197,7 +197,7 @@ do_command (SpaPoll *poll,
|
|||
ac.event.size = sizeof (SpaNodeEventAsyncComplete);
|
||||
ac.seq = seq;
|
||||
ac.res = res;
|
||||
spa_poll_invoke (this->main_loop,
|
||||
spa_loop_invoke (this->main_loop,
|
||||
do_send_event,
|
||||
SPA_ID_INVALID,
|
||||
sizeof (ac),
|
||||
|
|
@ -231,7 +231,7 @@ spa_alsa_sink_node_send_command (SpaNode *node,
|
|||
if (this->n_buffers == 0)
|
||||
return SPA_RESULT_NO_BUFFERS;
|
||||
|
||||
return spa_poll_invoke (this->data_loop,
|
||||
return spa_loop_invoke (this->data_loop,
|
||||
do_command,
|
||||
++this->seq,
|
||||
command->size,
|
||||
|
|
@ -790,9 +790,9 @@ alsa_sink_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)
|
||||
else if (strcmp (support[i].uri, SPA_LOOP__DataLoop) == 0)
|
||||
this->data_loop = 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) {
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ spa_alsa_source_node_set_props (SpaNode *node,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
do_send_event (SpaPoll *poll,
|
||||
do_send_event (SpaLoop *loop,
|
||||
bool async,
|
||||
uint32_t seq,
|
||||
size_t size,
|
||||
|
|
@ -168,7 +168,7 @@ do_send_event (SpaPoll *poll,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
do_start (SpaPoll *poll,
|
||||
do_start (SpaLoop *loop,
|
||||
bool async,
|
||||
uint32_t seq,
|
||||
size_t size,
|
||||
|
|
@ -188,7 +188,7 @@ do_start (SpaPoll *poll,
|
|||
ac.event.size = sizeof (SpaNodeEventAsyncComplete);
|
||||
ac.seq = seq;
|
||||
ac.res = res;
|
||||
spa_poll_invoke (this->main_loop,
|
||||
spa_loop_invoke (this->main_loop,
|
||||
do_send_event,
|
||||
SPA_ID_INVALID,
|
||||
sizeof (ac),
|
||||
|
|
@ -199,7 +199,7 @@ do_start (SpaPoll *poll,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
do_pause (SpaPoll *poll,
|
||||
do_pause (SpaLoop *loop,
|
||||
bool async,
|
||||
uint32_t seq,
|
||||
size_t size,
|
||||
|
|
@ -219,7 +219,7 @@ do_pause (SpaPoll *poll,
|
|||
ac.event.size = sizeof (SpaNodeEventAsyncComplete);
|
||||
ac.seq = seq;
|
||||
ac.res = res;
|
||||
spa_poll_invoke (this->main_loop,
|
||||
spa_loop_invoke (this->main_loop,
|
||||
do_send_event,
|
||||
SPA_ID_INVALID,
|
||||
sizeof (ac),
|
||||
|
|
@ -252,7 +252,7 @@ spa_alsa_source_node_send_command (SpaNode *node,
|
|||
if (this->n_buffers == 0)
|
||||
return SPA_RESULT_NO_BUFFERS;
|
||||
|
||||
return spa_poll_invoke (this->data_loop,
|
||||
return spa_loop_invoke (this->data_loop,
|
||||
do_start,
|
||||
++this->seq,
|
||||
0,
|
||||
|
|
@ -268,7 +268,7 @@ spa_alsa_source_node_send_command (SpaNode *node,
|
|||
if (this->n_buffers == 0)
|
||||
return SPA_RESULT_NO_BUFFERS;
|
||||
|
||||
return spa_poll_invoke (this->data_loop,
|
||||
return spa_loop_invoke (this->data_loop,
|
||||
do_pause,
|
||||
++this->seq,
|
||||
0,
|
||||
|
|
@ -888,9 +888,9 @@ 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)
|
||||
else if (strcmp (support[i].uri, SPA_LOOP__DataLoop) == 0)
|
||||
this->data_loop = 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) {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#define CHECK(s,msg) if ((err = (s)) < 0) { spa_log_error (state->log, msg ": %s", snd_strerror(err)); return err; }
|
||||
|
||||
static int alsa_on_fd_events (SpaPollNotifyData *data);
|
||||
static void alsa_on_fd_events (SpaSource *source);
|
||||
|
||||
static int
|
||||
spa_alsa_open (SpaALSAState *state)
|
||||
|
|
@ -35,16 +35,6 @@ spa_alsa_open (SpaALSAState *state)
|
|||
SND_PCM_NO_AUTO_FORMAT), "open failed");
|
||||
|
||||
|
||||
state->poll.id = 0;
|
||||
state->poll.enabled = false;
|
||||
state->poll.fds = state->fds;
|
||||
state->poll.n_fds = 0;
|
||||
state->poll.idle_cb = NULL;
|
||||
state->poll.before_cb = NULL;
|
||||
state->poll.after_cb = alsa_on_fd_events;
|
||||
state->poll.user_data = state;
|
||||
spa_poll_add_item (state->data_loop, &state->poll);
|
||||
|
||||
state->opened = true;
|
||||
|
||||
return 0;
|
||||
|
|
@ -58,8 +48,6 @@ spa_alsa_close (SpaALSAState *state)
|
|||
if (!state->opened)
|
||||
return 0;
|
||||
|
||||
spa_poll_remove_item (state->data_loop, &state->poll);
|
||||
|
||||
spa_log_info (state->log, "Device closing");
|
||||
CHECK (snd_pcm_close (state->hndl), "close failed");
|
||||
|
||||
|
|
@ -508,44 +496,48 @@ mmap_read (SpaALSAState *state)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
alsa_on_fd_events (SpaPollNotifyData *data)
|
||||
static void
|
||||
alsa_on_fd_events (SpaSource *source)
|
||||
{
|
||||
SpaALSAState *state = data->user_data;
|
||||
SpaALSAState *state = source->data;
|
||||
snd_pcm_t *hndl = state->hndl;
|
||||
int err;
|
||||
unsigned short revents = 0;
|
||||
|
||||
#if 0
|
||||
snd_pcm_poll_descriptors_revents (hndl,
|
||||
(struct pollfd *)data->fds,
|
||||
data->n_fds,
|
||||
state->fds,
|
||||
state->n_fds,
|
||||
&revents);
|
||||
if (revents & POLLERR) {
|
||||
|
||||
spa_log_debug (state->log, "revents: %d %d", revents, state->n_fds);
|
||||
#endif
|
||||
revents = source->rmask;
|
||||
|
||||
if (revents & SPA_IO_ERR) {
|
||||
if ((err = xrun_recovery (state, hndl, err)) < 0) {
|
||||
spa_log_error (state->log, "error: %s", snd_strerror (err));
|
||||
return -1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (state->stream == SND_PCM_STREAM_CAPTURE) {
|
||||
if (!(revents & POLLIN))
|
||||
return 0;
|
||||
if (!(revents & SPA_IO_IN))
|
||||
return;
|
||||
|
||||
mmap_read (state);
|
||||
} else {
|
||||
if (!(revents & POLLOUT))
|
||||
return 0;
|
||||
if (!(revents & SPA_IO_OUT))
|
||||
return;
|
||||
|
||||
mmap_write (state);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SpaResult
|
||||
spa_alsa_start (SpaALSAState *state, bool xrun_recover)
|
||||
{
|
||||
int err;
|
||||
int err, i;
|
||||
|
||||
if (state->started)
|
||||
return SPA_RESULT_OK;
|
||||
|
|
@ -559,19 +551,33 @@ spa_alsa_start (SpaALSAState *state, bool xrun_recover)
|
|||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
|
||||
if ((state->poll.n_fds = snd_pcm_poll_descriptors_count (state->hndl)) <= 0) {
|
||||
spa_log_error (state->log, "Invalid poll descriptors count %d", state->poll.n_fds);
|
||||
for (i = 0; i < state->n_fds; i++)
|
||||
spa_loop_remove_source (state->data_loop, &state->sources[i]);
|
||||
|
||||
if ((state->n_fds = snd_pcm_poll_descriptors_count (state->hndl)) <= 0) {
|
||||
spa_log_error (state->log, "Invalid poll descriptors count %d", state->n_fds);
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
|
||||
if ((err = snd_pcm_poll_descriptors (state->hndl, (struct pollfd *)state->fds, state->poll.n_fds)) < 0) {
|
||||
if ((err = snd_pcm_poll_descriptors (state->hndl, state->fds, state->n_fds)) < 0) {
|
||||
spa_log_error (state->log, "snd_pcm_poll_descriptors: %s", snd_strerror(err));
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
|
||||
if (!xrun_recover) {
|
||||
state->poll.enabled = true;
|
||||
spa_poll_update_item (state->data_loop, &state->poll);
|
||||
for (i = 0; i < state->n_fds; i++) {
|
||||
state->sources[i].func = alsa_on_fd_events;
|
||||
state->sources[i].data = state;
|
||||
state->sources[i].fd = state->fds[i].fd;
|
||||
state->sources[i].mask = 0;
|
||||
if (state->fds[i].events & POLLIN)
|
||||
state->sources[i].mask |= SPA_IO_IN;
|
||||
if (state->fds[i].events & POLLOUT)
|
||||
state->sources[i].mask |= SPA_IO_OUT;
|
||||
if (state->fds[i].events & POLLERR)
|
||||
state->sources[i].mask |= SPA_IO_ERR;
|
||||
if (state->fds[i].events & POLLHUP)
|
||||
state->sources[i].mask |= SPA_IO_HUP;
|
||||
spa_loop_add_source (state->data_loop, &state->sources[i]);
|
||||
}
|
||||
|
||||
if (state->stream == SND_PCM_STREAM_PLAYBACK) {
|
||||
|
|
@ -591,15 +597,14 @@ spa_alsa_start (SpaALSAState *state, bool xrun_recover)
|
|||
SpaResult
|
||||
spa_alsa_pause (SpaALSAState *state, bool xrun_recover)
|
||||
{
|
||||
int err;
|
||||
int err, i;
|
||||
|
||||
if (!state->started)
|
||||
return SPA_RESULT_OK;
|
||||
|
||||
if (!xrun_recover) {
|
||||
state->poll.enabled = false;
|
||||
spa_poll_update_item (state->data_loop, &state->poll);
|
||||
}
|
||||
for (i = 0; i < state->n_fds; i++)
|
||||
spa_loop_remove_source (state->data_loop, &state->sources[i]);
|
||||
state->n_fds = 0;
|
||||
|
||||
if ((err = snd_pcm_drop (state->hndl)) < 0)
|
||||
spa_log_error (state->log, "snd_pcm_drop %s", snd_strerror (err));
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ extern "C" {
|
|||
#include <spa/log.h>
|
||||
#include <spa/list.h>
|
||||
#include <spa/node.h>
|
||||
#include <spa/loop.h>
|
||||
#include <spa/ringbuffer.h>
|
||||
#include <spa/audio/format.h>
|
||||
|
||||
|
|
@ -73,8 +74,8 @@ struct _SpaALSAState {
|
|||
URI uri;
|
||||
SpaIDMap *map;
|
||||
SpaLog *log;
|
||||
SpaPoll *main_loop;
|
||||
SpaPoll *data_loop;
|
||||
SpaLoop *main_loop;
|
||||
SpaLoop *data_loop;
|
||||
|
||||
snd_pcm_stream_t stream;
|
||||
snd_output_t *output;
|
||||
|
|
@ -114,8 +115,9 @@ struct _SpaALSAState {
|
|||
size_t ready_offset;
|
||||
|
||||
bool started;
|
||||
SpaPollFd fds[16];
|
||||
SpaPollItem poll;
|
||||
int n_fds;
|
||||
struct pollfd fds[16];
|
||||
SpaSource sources[16];
|
||||
|
||||
int64_t sample_count;
|
||||
int64_t last_ticks;
|
||||
|
|
|
|||
|
|
@ -22,11 +22,11 @@
|
|||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/timerfd.h>
|
||||
#include <poll.h>
|
||||
|
||||
#include <spa/id-map.h>
|
||||
#include <spa/log.h>
|
||||
#include <spa/node.h>
|
||||
#include <spa/loop.h>
|
||||
#include <spa/list.h>
|
||||
#include <spa/audio/format.h>
|
||||
#include <lib/props.h>
|
||||
|
|
@ -71,15 +71,15 @@ struct _SpaAudioTestSrc {
|
|||
URI uri;
|
||||
SpaIDMap *map;
|
||||
SpaLog *log;
|
||||
SpaPoll *data_loop;
|
||||
SpaLoop *data_loop;
|
||||
|
||||
SpaAudioTestSrcProps props[2];
|
||||
|
||||
SpaNodeEventCallback event_cb;
|
||||
void *user_data;
|
||||
|
||||
SpaPollItem timer;
|
||||
SpaPollFd fds[1];
|
||||
bool timer_enabled;
|
||||
SpaSource timer_source;
|
||||
struct itimerspec timerspec;
|
||||
|
||||
SpaPortInfo info;
|
||||
|
|
@ -256,20 +256,19 @@ fill_buffer (SpaAudioTestSrc *this, ATSBuffer *b)
|
|||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static int audiotestsrc_on_output (SpaPollNotifyData *data);
|
||||
|
||||
static SpaResult update_poll_enabled (SpaAudioTestSrc *this, bool enabled);
|
||||
static SpaResult update_loop_enabled (SpaAudioTestSrc *this, bool enabled);
|
||||
|
||||
static int
|
||||
audiotestsrc_on_output (SpaPollNotifyData *data)
|
||||
static void
|
||||
audiotestsrc_on_output (SpaSource *source)
|
||||
{
|
||||
SpaAudioTestSrc *this = data->user_data;
|
||||
SpaAudioTestSrc *this = source->data;
|
||||
ATSBuffer *b;
|
||||
|
||||
if (spa_list_is_empty (&this->empty)) {
|
||||
if (!this->props[1].live)
|
||||
update_poll_enabled (this, false);
|
||||
return 0;
|
||||
update_loop_enabled (this, false);
|
||||
return;
|
||||
}
|
||||
b = spa_list_first (&this->empty, ATSBuffer, list);
|
||||
spa_list_remove (&b->list);
|
||||
|
|
@ -288,19 +287,17 @@ audiotestsrc_on_output (SpaPollNotifyData *data)
|
|||
if (this->props[1].live) {
|
||||
uint64_t expirations, next_time;
|
||||
|
||||
if (read (this->fds[0].fd, &expirations, sizeof (uint64_t)) < sizeof (uint64_t))
|
||||
if (read (this->timer_source.fd, &expirations, sizeof (uint64_t)) < sizeof (uint64_t))
|
||||
perror ("read timerfd");
|
||||
|
||||
next_time = this->start_time + this->elapsed_time;
|
||||
this->timerspec.it_value.tv_sec = next_time / SPA_NSEC_PER_SEC;
|
||||
this->timerspec.it_value.tv_nsec = next_time % SPA_NSEC_PER_SEC;
|
||||
timerfd_settime (this->fds[0].fd, TFD_TIMER_ABSTIME, &this->timerspec, NULL);
|
||||
timerfd_settime (this->timer_source.fd, TFD_TIMER_ABSTIME, &this->timerspec, NULL);
|
||||
}
|
||||
|
||||
spa_list_insert (this->ready.prev, &b->list);
|
||||
send_have_output (this);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -310,10 +307,15 @@ update_state (SpaAudioTestSrc *this, SpaNodeState state)
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
update_poll_enabled (SpaAudioTestSrc *this, bool enabled)
|
||||
update_loop_enabled (SpaAudioTestSrc *this, bool enabled)
|
||||
{
|
||||
if (this->event_cb) {
|
||||
this->timer.enabled = enabled;
|
||||
this->timer_enabled = enabled;
|
||||
if (enabled)
|
||||
this->timer_source.mask = SPA_IO_IN;
|
||||
else
|
||||
this->timer_source.mask = 0;
|
||||
|
||||
if (this->props[1].live) {
|
||||
if (enabled) {
|
||||
uint64_t next_time = this->start_time + this->elapsed_time;
|
||||
|
|
@ -324,18 +326,11 @@ update_poll_enabled (SpaAudioTestSrc *this, bool enabled)
|
|||
this->timerspec.it_value.tv_sec = 0;
|
||||
this->timerspec.it_value.tv_nsec = 0;
|
||||
}
|
||||
timerfd_settime (this->fds[0].fd, TFD_TIMER_ABSTIME, &this->timerspec, NULL);
|
||||
this->timer.fds = this->fds;
|
||||
this->timer.n_fds = 1;
|
||||
this->timer.idle_cb = NULL;
|
||||
this->timer.after_cb = audiotestsrc_on_output;
|
||||
} else {
|
||||
this->timer.fds = NULL;
|
||||
this->timer.n_fds = 0;
|
||||
this->timer.idle_cb = audiotestsrc_on_output;
|
||||
this->timer.after_cb = NULL;
|
||||
timerfd_settime (this->timer_source.fd, TFD_TIMER_ABSTIME, &this->timerspec, NULL);
|
||||
|
||||
this->timer_source.func = audiotestsrc_on_output;
|
||||
}
|
||||
spa_poll_update_item (this->data_loop, &this->timer);
|
||||
spa_loop_update_source (this->data_loop, &this->timer_source);
|
||||
}
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
@ -377,7 +372,7 @@ spa_audiotestsrc_node_send_command (SpaNode *node,
|
|||
this->elapsed_time = 0;
|
||||
|
||||
this->started = true;
|
||||
update_poll_enabled (this, true);
|
||||
update_loop_enabled (this, true);
|
||||
update_state (this, SPA_NODE_STATE_STREAMING);
|
||||
break;
|
||||
}
|
||||
|
|
@ -393,7 +388,7 @@ spa_audiotestsrc_node_send_command (SpaNode *node,
|
|||
return SPA_RESULT_OK;
|
||||
|
||||
this->started = false;
|
||||
update_poll_enabled (this, false);
|
||||
update_loop_enabled (this, false);
|
||||
update_state (this, SPA_NODE_STATE_PAUSED);
|
||||
break;
|
||||
}
|
||||
|
|
@ -419,14 +414,14 @@ spa_audiotestsrc_node_set_event_callback (SpaNode *node,
|
|||
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
|
||||
|
||||
if (event_cb == NULL && this->event_cb) {
|
||||
spa_poll_remove_item (this->data_loop, &this->timer);
|
||||
spa_loop_remove_source (this->data_loop, &this->timer_source);
|
||||
}
|
||||
|
||||
this->event_cb = event_cb;
|
||||
this->user_data = user_data;
|
||||
|
||||
if (this->event_cb) {
|
||||
spa_poll_add_item (this->data_loop, &this->timer);
|
||||
spa_loop_add_source (this->data_loop, &this->timer_source);
|
||||
}
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
@ -801,7 +796,7 @@ spa_audiotestsrc_node_port_reuse_buffer (SpaNode *node,
|
|||
spa_list_insert (this->empty.prev, &b->list);
|
||||
|
||||
if (!this->props[1].live)
|
||||
update_poll_enabled (this, true);
|
||||
update_loop_enabled (this, true);
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
@ -958,7 +953,7 @@ audiotestsrc_clear (SpaHandle *handle)
|
|||
|
||||
this = (SpaAudioTestSrc *) handle;
|
||||
|
||||
close (this->fds[0].fd);
|
||||
close (this->timer_source.fd);
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
@ -986,7 +981,7 @@ 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)
|
||||
else if (strcmp (support[i].uri, SPA_LOOP__DataLoop) == 0)
|
||||
this->data_loop = support[i].data;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
|
|
@ -1009,21 +1004,15 @@ audiotestsrc_init (const SpaHandleFactory *factory,
|
|||
spa_list_init (&this->empty);
|
||||
spa_list_init (&this->ready);
|
||||
|
||||
this->fds[0].fd = timerfd_create (CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC);
|
||||
this->fds[0].events = POLLIN | POLLPRI | POLLERR;
|
||||
this->fds[0].revents = 0;
|
||||
this->timer_source.func = audiotestsrc_on_output;
|
||||
this->timer_source.data = this;
|
||||
this->timer_source.fd = timerfd_create (CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC);
|
||||
this->timer_source.mask = SPA_IO_IN | SPA_IO_ERR;
|
||||
this->timerspec.it_value.tv_sec = 0;
|
||||
this->timerspec.it_value.tv_nsec = 0;
|
||||
this->timerspec.it_interval.tv_sec = 0;
|
||||
this->timerspec.it_interval.tv_nsec = 0;
|
||||
|
||||
this->timer.id = 0;
|
||||
this->timer.enabled = false;
|
||||
this->timer.idle_cb = NULL;
|
||||
this->timer.before_cb = NULL;
|
||||
this->timer.after_cb = NULL;
|
||||
this->timer.user_data = this;
|
||||
|
||||
this->info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS |
|
||||
SPA_PORT_INFO_FLAG_NO_REF;
|
||||
if (this->props[1].live)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,10 +23,10 @@
|
|||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/timerfd.h>
|
||||
#include <poll.h>
|
||||
|
||||
#include <spa/id-map.h>
|
||||
#include <spa/log.h>
|
||||
#include <spa/loop.h>
|
||||
#include <spa/node.h>
|
||||
#include <spa/list.h>
|
||||
#include <spa/video/format.h>
|
||||
|
|
@ -74,15 +74,15 @@ struct _SpaVideoTestSrc {
|
|||
URI uri;
|
||||
SpaIDMap *map;
|
||||
SpaLog *log;
|
||||
SpaPoll *data_loop;
|
||||
SpaLoop *data_loop;
|
||||
|
||||
SpaVideoTestSrcProps props[2];
|
||||
|
||||
SpaNodeEventCallback event_cb;
|
||||
void *user_data;
|
||||
|
||||
SpaPollItem timer;
|
||||
SpaPollFd fds[1];
|
||||
SpaSource timer_source;
|
||||
bool timer_enabled;
|
||||
struct itimerspec timerspec;
|
||||
|
||||
SpaPortInfo info;
|
||||
|
|
@ -205,18 +205,18 @@ fill_buffer (SpaVideoTestSrc *this, VTSBuffer *b)
|
|||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult update_poll_enabled (SpaVideoTestSrc *this, bool enabled);
|
||||
static SpaResult update_loop_enabled (SpaVideoTestSrc *this, bool enabled);
|
||||
|
||||
static int
|
||||
videotestsrc_on_output (SpaPollNotifyData *data)
|
||||
static void
|
||||
videotestsrc_on_output (SpaSource *source)
|
||||
{
|
||||
SpaVideoTestSrc *this = data->user_data;
|
||||
SpaVideoTestSrc *this = source->data;
|
||||
VTSBuffer *b;
|
||||
|
||||
if (spa_list_is_empty (&this->empty)) {
|
||||
if (!this->props[1].live)
|
||||
update_poll_enabled (this, false);
|
||||
return 0;
|
||||
update_loop_enabled (this, false);
|
||||
return;
|
||||
}
|
||||
b = spa_list_first (&this->empty, VTSBuffer, list);
|
||||
spa_list_remove (&b->list);
|
||||
|
|
@ -235,19 +235,17 @@ videotestsrc_on_output (SpaPollNotifyData *data)
|
|||
if (this->props[1].live) {
|
||||
uint64_t expirations, next_time;
|
||||
|
||||
if (read (this->fds[0].fd, &expirations, sizeof (uint64_t)) < sizeof (uint64_t))
|
||||
if (read (this->timer_source.fd, &expirations, sizeof (uint64_t)) < sizeof (uint64_t))
|
||||
perror ("read timerfd");
|
||||
|
||||
next_time = this->start_time + this->elapsed_time;
|
||||
this->timerspec.it_value.tv_sec = next_time / SPA_NSEC_PER_SEC;
|
||||
this->timerspec.it_value.tv_nsec = next_time % SPA_NSEC_PER_SEC;
|
||||
timerfd_settime (this->fds[0].fd, TFD_TIMER_ABSTIME, &this->timerspec, NULL);
|
||||
timerfd_settime (this->timer_source.fd, TFD_TIMER_ABSTIME, &this->timerspec, NULL);
|
||||
}
|
||||
|
||||
spa_list_insert (this->ready.prev, &b->list);
|
||||
send_have_output (this);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -257,10 +255,15 @@ update_state (SpaVideoTestSrc *this, SpaNodeState state)
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
update_poll_enabled (SpaVideoTestSrc *this, bool enabled)
|
||||
update_loop_enabled (SpaVideoTestSrc *this, bool enabled)
|
||||
{
|
||||
if (this->event_cb && this->timer.enabled != enabled) {
|
||||
this->timer.enabled = enabled;
|
||||
if (this->event_cb && this->timer_enabled != enabled) {
|
||||
this->timer_enabled = enabled;
|
||||
if (enabled)
|
||||
this->timer_source.mask = SPA_IO_IN;
|
||||
else
|
||||
this->timer_source.mask = 0;
|
||||
|
||||
if (this->props[1].live) {
|
||||
if (enabled) {
|
||||
uint64_t next_time = this->start_time + this->elapsed_time;
|
||||
|
|
@ -271,18 +274,9 @@ update_poll_enabled (SpaVideoTestSrc *this, bool enabled)
|
|||
this->timerspec.it_value.tv_sec = 0;
|
||||
this->timerspec.it_value.tv_nsec = 0;
|
||||
}
|
||||
timerfd_settime (this->fds[0].fd, TFD_TIMER_ABSTIME, &this->timerspec, NULL);
|
||||
this->timer.fds = this->fds;
|
||||
this->timer.n_fds = 1;
|
||||
this->timer.idle_cb = NULL;
|
||||
this->timer.after_cb = videotestsrc_on_output;
|
||||
} else {
|
||||
this->timer.fds = NULL;
|
||||
this->timer.n_fds = 0;
|
||||
this->timer.idle_cb = videotestsrc_on_output;
|
||||
this->timer.after_cb = NULL;
|
||||
timerfd_settime (this->timer_source.fd, TFD_TIMER_ABSTIME, &this->timerspec, NULL);
|
||||
}
|
||||
spa_poll_update_item (this->data_loop, &this->timer);
|
||||
spa_loop_update_source (this->data_loop, &this->timer_source);
|
||||
}
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
@ -324,7 +318,7 @@ spa_videotestsrc_node_send_command (SpaNode *node,
|
|||
this->elapsed_time = 0;
|
||||
|
||||
this->started = true;
|
||||
update_poll_enabled (this, true);
|
||||
update_loop_enabled (this, true);
|
||||
update_state (this, SPA_NODE_STATE_STREAMING);
|
||||
break;
|
||||
}
|
||||
|
|
@ -340,7 +334,7 @@ spa_videotestsrc_node_send_command (SpaNode *node,
|
|||
return SPA_RESULT_OK;
|
||||
|
||||
this->started = false;
|
||||
update_poll_enabled (this, false);
|
||||
update_loop_enabled (this, false);
|
||||
update_state (this, SPA_NODE_STATE_PAUSED);
|
||||
break;
|
||||
}
|
||||
|
|
@ -365,15 +359,14 @@ spa_videotestsrc_node_set_event_callback (SpaNode *node,
|
|||
|
||||
this = SPA_CONTAINER_OF (node, SpaVideoTestSrc, node);
|
||||
|
||||
if (event_cb == NULL && this->event_cb) {
|
||||
spa_poll_remove_item (this->data_loop, &this->timer);
|
||||
}
|
||||
if (event_cb == NULL && this->event_cb)
|
||||
spa_loop_remove_source (this->data_loop, &this->timer_source);
|
||||
|
||||
this->event_cb = event_cb;
|
||||
this->user_data = user_data;
|
||||
|
||||
if (this->event_cb) {
|
||||
spa_poll_add_item (this->data_loop, &this->timer);
|
||||
spa_loop_add_source (this->data_loop, &this->timer_source);
|
||||
}
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
@ -748,7 +741,7 @@ spa_videotestsrc_node_port_reuse_buffer (SpaNode *node,
|
|||
spa_list_insert (this->empty.prev, &b->list);
|
||||
|
||||
if (!this->props[1].live)
|
||||
update_poll_enabled (this, true);
|
||||
update_loop_enabled (this, true);
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
@ -910,7 +903,7 @@ videotestsrc_clear (SpaHandle *handle)
|
|||
|
||||
this = (SpaVideoTestSrc *) handle;
|
||||
|
||||
close (this->fds[0].fd);
|
||||
close (this->timer_source.fd);
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
@ -938,7 +931,7 @@ 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)
|
||||
else if (strcmp (support[i].uri, SPA_LOOP__DataLoop) == 0)
|
||||
this->data_loop = support[i].data;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
|
|
@ -957,21 +950,16 @@ videotestsrc_init (const SpaHandleFactory *factory,
|
|||
spa_list_init (&this->empty);
|
||||
spa_list_init (&this->ready);
|
||||
|
||||
this->fds[0].fd = timerfd_create (CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC);
|
||||
this->fds[0].events = POLLIN | POLLPRI | POLLERR;
|
||||
this->fds[0].revents = 0;
|
||||
this->timer_source.func = videotestsrc_on_output;
|
||||
this->timer_source.data = this;
|
||||
this->timer_source.fd = timerfd_create (CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC);
|
||||
this->timer_source.mask = SPA_IO_IN;
|
||||
this->timer_source.rmask = 0;
|
||||
this->timerspec.it_value.tv_sec = 0;
|
||||
this->timerspec.it_value.tv_nsec = 0;
|
||||
this->timerspec.it_interval.tv_sec = 0;
|
||||
this->timerspec.it_interval.tv_nsec = 0;
|
||||
|
||||
this->timer.id = 0;
|
||||
this->timer.enabled = false;
|
||||
this->timer.idle_cb = NULL;
|
||||
this->timer.before_cb = NULL;
|
||||
this->timer.after_cb = NULL;
|
||||
this->timer.user_data = this;
|
||||
|
||||
this->info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS |
|
||||
SPA_PORT_INFO_FLAG_NO_REF;
|
||||
if (this->props[1].live)
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
executable('test-mixer', 'test-mixer.c',
|
||||
include_directories : [spa_inc, spa_libinc ],
|
||||
dependencies : [dl_lib, pthread_lib],
|
||||
link_with : spalib,
|
||||
install : false)
|
||||
|
||||
executable('test-v4l2', 'test-v4l2.c',
|
||||
include_directories : [spa_inc, spa_libinc ],
|
||||
dependencies : [dl_lib, sdl_dep, pthread_lib],
|
||||
link_with : spalib,
|
||||
install : false)
|
||||
#executable('test-mixer', 'test-mixer.c',
|
||||
# include_directories : [spa_inc, spa_libinc ],
|
||||
# dependencies : [dl_lib, pthread_lib],
|
||||
# link_with : spalib,
|
||||
# install : false)
|
||||
#
|
||||
#executable('test-v4l2', 'test-v4l2.c',
|
||||
# include_directories : [spa_inc, spa_libinc ],
|
||||
# dependencies : [dl_lib, sdl_dep, pthread_lib],
|
||||
# link_with : spalib,
|
||||
# install : false)
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
#include <spa/id-map.h>
|
||||
#include <spa/log.h>
|
||||
#include <spa/node.h>
|
||||
#include <spa/loop.h>
|
||||
#include <spa/video/format.h>
|
||||
#include <lib/debug.h>
|
||||
#include <lib/props.h>
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
#include <spa/log.h>
|
||||
#include <spa/id-map.h>
|
||||
#include <spa/monitor.h>
|
||||
#include <spa/poll.h>
|
||||
#include <spa/loop.h>
|
||||
#include <lib/debug.h>
|
||||
#include <lib/mapper.h>
|
||||
|
||||
|
|
@ -41,16 +41,16 @@ typedef struct {
|
|||
|
||||
SpaIDMap *map;
|
||||
SpaLog *log;
|
||||
SpaPoll main_loop;
|
||||
SpaLoop main_loop;
|
||||
|
||||
SpaSupport support[3];
|
||||
unsigned int n_support;
|
||||
|
||||
unsigned int n_poll;
|
||||
SpaPollItem poll[16];
|
||||
unsigned int n_sources;
|
||||
SpaSource sources[16];
|
||||
|
||||
bool rebuild_fds;
|
||||
SpaPollFd fds[16];
|
||||
struct pollfd fds[16];
|
||||
unsigned int n_fds;
|
||||
} AppData;
|
||||
|
||||
|
|
@ -97,31 +97,28 @@ on_monitor_event (SpaMonitor *monitor,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
do_add_item (SpaPoll *poll,
|
||||
SpaPollItem *item)
|
||||
do_add_source (SpaLoop *loop,
|
||||
SpaSource *source)
|
||||
{
|
||||
AppData *data = SPA_CONTAINER_OF (poll, AppData, main_loop);
|
||||
AppData *data = SPA_CONTAINER_OF (loop, AppData, main_loop);
|
||||
|
||||
data->poll[data->n_poll] = *item;
|
||||
data->n_poll++;
|
||||
if (item->n_fds)
|
||||
data->rebuild_fds = true;
|
||||
data->sources[data->n_sources] = *source;
|
||||
data->n_sources++;
|
||||
data->rebuild_fds = true;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
static SpaResult
|
||||
do_update_item (SpaPoll *poll,
|
||||
SpaPollItem *item)
|
||||
do_update_source (SpaSource *source)
|
||||
{
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
do_remove_item (SpaPoll *poll,
|
||||
SpaPollItem *item)
|
||||
static void
|
||||
do_remove_source (SpaSource *source)
|
||||
{
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static void
|
||||
handle_monitor (AppData *data, SpaMonitor *monitor)
|
||||
{
|
||||
|
|
@ -145,23 +142,16 @@ handle_monitor (AppData *data, SpaMonitor *monitor)
|
|||
spa_monitor_set_event_callback (monitor, on_monitor_event, &data);
|
||||
|
||||
while (true) {
|
||||
SpaPollNotifyData ndata;
|
||||
int i, j, r;
|
||||
int i, r;
|
||||
|
||||
/* rebuild */
|
||||
if (data->rebuild_fds) {
|
||||
data->n_fds = 0;
|
||||
for (i = 0; i < data->n_poll; i++) {
|
||||
SpaPollItem *p = &data->poll[i];
|
||||
|
||||
if (!p->enabled)
|
||||
continue;
|
||||
|
||||
for (j = 0; j < p->n_fds; j++)
|
||||
data->fds[data->n_fds + j] = p->fds[j];
|
||||
p->fds = &data->fds[data->n_fds];
|
||||
data->n_fds += p->n_fds;
|
||||
for (i = 0; i < data->n_sources; i++) {
|
||||
SpaSource *p = &data->sources[i];
|
||||
data->fds[i].fd = p->fd;
|
||||
data->fds[i].events = p->mask;
|
||||
}
|
||||
data->n_fds = data->n_sources;
|
||||
data->rebuild_fds = false;
|
||||
}
|
||||
|
||||
|
|
@ -177,15 +167,9 @@ handle_monitor (AppData *data, SpaMonitor *monitor)
|
|||
}
|
||||
|
||||
/* after */
|
||||
for (i = 0; i < data->n_poll; i++) {
|
||||
SpaPollItem *p = &data->poll[i];
|
||||
|
||||
if (p->enabled && p->after_cb) {
|
||||
ndata.fds = p->fds;
|
||||
ndata.n_fds = p->n_fds;
|
||||
ndata.user_data = p->user_data;
|
||||
p->after_cb (&ndata);
|
||||
}
|
||||
for (i = 0; i < data->n_sources; i++) {
|
||||
SpaSource *p = &data->sources[i];
|
||||
p->func (p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -201,17 +185,16 @@ main (int argc, char *argv[])
|
|||
|
||||
data.map = spa_id_map_get_default ();
|
||||
data.log = NULL;
|
||||
data.main_loop.size = sizeof (SpaPoll);
|
||||
data.main_loop.info = NULL;
|
||||
data.main_loop.add_item = do_add_item;
|
||||
data.main_loop.update_item = do_update_item;
|
||||
data.main_loop.remove_item = do_remove_item;
|
||||
data.main_loop.size = sizeof (SpaLoop);
|
||||
data.main_loop.add_source = do_add_source;
|
||||
data.main_loop.update_source = do_update_source;
|
||||
data.main_loop.remove_source = do_remove_source;
|
||||
|
||||
data.support[0].uri = SPA_ID_MAP_URI;
|
||||
data.support[0].data = data.map;
|
||||
data.support[1].uri = SPA_LOG_URI;
|
||||
data.support[1].data = data.log;
|
||||
data.support[2].uri = SPA_POLL__MainLoop;
|
||||
data.support[2].uri = SPA_LOOP__MainLoop;
|
||||
data.support[2].data = &data.main_loop;
|
||||
data.n_support = 3;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue