mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05:00
loop: add before_iterate signal
Add before_iterate signal and use it to flush data to clients.
This commit is contained in:
parent
9b93fd396a
commit
3e472c2dae
5 changed files with 60 additions and 19 deletions
|
|
@ -291,7 +291,6 @@ pinos_connection_end_write (PinosConnection *conn,
|
|||
*p++ = (opcode << 24) | (size & 0xffffff);
|
||||
|
||||
buf->buffer_size += 8 + size;
|
||||
pinos_connection_flush (conn);
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ typedef struct {
|
|||
SpaSource source;
|
||||
|
||||
bool disconnecting;
|
||||
PinosListener before_iterate;
|
||||
} PinosContextImpl;
|
||||
|
||||
/**
|
||||
|
|
@ -353,6 +354,14 @@ static const PinosRegistryEvents registry_events = {
|
|||
|
||||
typedef bool (*PinosDemarshalFunc) (void *object, void *data, size_t size);
|
||||
|
||||
static void
|
||||
on_before_iterate (PinosListener *listener,
|
||||
PinosLoop *loop)
|
||||
{
|
||||
PinosContextImpl *impl = SPA_CONTAINER_OF (listener, PinosContextImpl, before_iterate);
|
||||
pinos_connection_flush (impl->connection);
|
||||
}
|
||||
|
||||
static void
|
||||
on_context_data (SpaSource *source,
|
||||
int fd,
|
||||
|
|
@ -446,6 +455,10 @@ pinos_context_new (PinosLoop *loop,
|
|||
|
||||
this->state = PINOS_CONTEXT_STATE_UNCONNECTED;
|
||||
|
||||
pinos_signal_add (&loop->before_iterate,
|
||||
&impl->before_iterate,
|
||||
on_before_iterate);
|
||||
|
||||
pinos_map_init (&this->objects, 64);
|
||||
|
||||
spa_list_init (&this->stream_list);
|
||||
|
|
@ -482,6 +495,8 @@ pinos_context_destroy (PinosContext *context)
|
|||
spa_list_for_each_safe (proxy, t2, &context->proxy_list, link)
|
||||
pinos_proxy_destroy (proxy);
|
||||
|
||||
pinos_signal_remove (&impl->before_iterate);
|
||||
|
||||
pinos_map_clear (&context->objects);
|
||||
|
||||
free (context->name);
|
||||
|
|
|
|||
|
|
@ -274,9 +274,12 @@ loop_iterate (SpaLoopControl *ctrl,
|
|||
int timeout)
|
||||
{
|
||||
PinosLoopImpl *impl = SPA_CONTAINER_OF (ctrl, PinosLoopImpl, control);
|
||||
PinosLoop *loop = &impl->this;
|
||||
struct epoll_event ep[32];
|
||||
int i, nfds, save_errno;
|
||||
|
||||
pinos_signal_emit (&loop->before_iterate, loop);
|
||||
|
||||
if (SPA_UNLIKELY (impl->pre_func))
|
||||
impl->pre_func (ctrl, impl->hook_data);
|
||||
|
||||
|
|
@ -592,6 +595,7 @@ pinos_loop_new (void)
|
|||
|
||||
spa_list_init (&impl->source_list);
|
||||
|
||||
pinos_signal_init (&this->before_iterate);
|
||||
pinos_signal_init (&this->destroy_signal);
|
||||
|
||||
impl->loop.size = sizeof (SpaLoop);
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@ struct _PinosLoop {
|
|||
SpaLoopControl *control;
|
||||
SpaLoopUtils *utils;
|
||||
|
||||
PINOS_SIGNAL (before_iterate, (PinosListener *listener,
|
||||
PinosLoop *loop));
|
||||
PINOS_SIGNAL (destroy_signal, (PinosListener *listener,
|
||||
PinosLoop *loop));
|
||||
};
|
||||
|
|
|
|||
|
|
@ -73,6 +73,8 @@ typedef struct {
|
|||
|
||||
SpaList socket_list;
|
||||
SpaList client_list;
|
||||
|
||||
PinosListener before_iterate;
|
||||
} PinosProtocolNative;
|
||||
|
||||
typedef struct {
|
||||
|
|
@ -106,6 +108,17 @@ on_resource_added (PinosListener *listener,
|
|||
pinos_protocol_native_server_setup (resource);
|
||||
}
|
||||
|
||||
static void
|
||||
on_before_iterate (PinosListener *listener,
|
||||
PinosLoop *loop)
|
||||
{
|
||||
PinosProtocolNative *this = SPA_CONTAINER_OF (listener, PinosProtocolNative, before_iterate);
|
||||
PinosProtocolNativeClient *client, *tmp;
|
||||
|
||||
spa_list_for_each_safe (client, tmp, &this->client_list, link)
|
||||
pinos_connection_flush (client->connection);
|
||||
}
|
||||
|
||||
static void
|
||||
connection_data (SpaSource *source,
|
||||
int fd,
|
||||
|
|
@ -126,6 +139,7 @@ connection_data (SpaSource *source,
|
|||
return;
|
||||
}
|
||||
|
||||
if (mask & SPA_IO_IN) {
|
||||
while (pinos_connection_get_next (conn, &opcode, &id, &message, &size)) {
|
||||
PinosResource *resource;
|
||||
const PinosDemarshalFunc *demarshal;
|
||||
|
|
@ -148,6 +162,7 @@ connection_data (SpaSource *source,
|
|||
} else
|
||||
pinos_log_error ("protocol-native %p: function %d not implemented", client->impl, opcode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static PinosProtocolNativeClient *
|
||||
|
|
@ -409,6 +424,10 @@ pinos_protocol_native_new (PinosCore *core,
|
|||
if (!add_socket (impl, s))
|
||||
goto error;
|
||||
|
||||
pinos_signal_add (&impl->core->main_loop->loop->before_iterate,
|
||||
&impl->before_iterate,
|
||||
on_before_iterate);
|
||||
|
||||
return impl;
|
||||
|
||||
error:
|
||||
|
|
@ -425,6 +444,8 @@ pinos_protocol_native_destroy (PinosProtocolNative *impl)
|
|||
|
||||
pinos_log_debug ("protocol-native %p: destroy", impl);
|
||||
|
||||
pinos_signal_remove (&impl->before_iterate);
|
||||
|
||||
pinos_global_destroy (impl->global);
|
||||
|
||||
spa_list_for_each_safe (object, tmp, &impl->object_list, link)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue