mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-07 13:30:09 -05:00
core_proxy: prepare to rename pw_remote -> pw_core_proxy
The pw_remote object is really a wrapper around the pw_core_proxy. The events it emits are also available in the core proxy and are generally awkward to use. With some clever new pw_core_proxy_* methods and a pw_core_connect to create the core_proxy, we can convert all code away from pw_remote. This is a first step in this conversion, using the pw_remote behind the scenes. It leaks into some places because it really needs to become its own struct in a next step.
This commit is contained in:
parent
f8aabe69fe
commit
8a959ea7a1
37 changed files with 919 additions and 1185 deletions
|
|
@ -43,7 +43,7 @@ static const struct spa_dict_item module_props[] = {
|
|||
{ PW_KEY_MODULE_VERSION, PACKAGE_VERSION },
|
||||
};
|
||||
|
||||
struct pw_proxy *pw_remote_spa_device_export(struct pw_core_proxy *core_proxy,
|
||||
struct pw_proxy *pw_core_proxy_spa_device_export(struct pw_core_proxy *core_proxy,
|
||||
uint32_t type, struct pw_properties *props, void *object,
|
||||
size_t user_data_size);
|
||||
|
||||
|
|
@ -188,7 +188,7 @@ int pipewire__module_init(struct pw_module *module, const char *args)
|
|||
pw_protocol_native_ext_client_device_init(core);
|
||||
|
||||
data->export_spadevice.type = SPA_TYPE_INTERFACE_Device;
|
||||
data->export_spadevice.func = pw_remote_spa_device_export;
|
||||
data->export_spadevice.func = pw_core_proxy_spa_device_export;
|
||||
pw_core_register_export_type(core, &data->export_spadevice);
|
||||
|
||||
pw_module_add_listener(module, &data->module_listener, &module_events, data);
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ static const struct pw_proxy_events proxy_events = {
|
|||
.destroy = device_proxy_destroy,
|
||||
};
|
||||
|
||||
struct pw_proxy *pw_remote_spa_device_export(struct pw_core_proxy *core_proxy,
|
||||
struct pw_proxy *pw_core_proxy_spa_device_export(struct pw_core_proxy *core_proxy,
|
||||
uint32_t type, struct pw_properties *props, void *object,
|
||||
size_t user_data_size)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -68,9 +68,10 @@ struct link {
|
|||
};
|
||||
|
||||
struct node_data {
|
||||
struct pw_remote *remote;
|
||||
struct pw_core *core;
|
||||
|
||||
struct pw_mempool *pool;
|
||||
|
||||
uint32_t remote_id;
|
||||
int rtwritefd;
|
||||
struct pw_memmap *activation;
|
||||
|
|
@ -133,7 +134,7 @@ static void clean_transport(struct node_data *data)
|
|||
}
|
||||
pw_array_clear(&data->links);
|
||||
|
||||
while ((mm = pw_mempool_find_tag(data->remote->pool, tag, sizeof(uint32_t))) != NULL)
|
||||
while ((mm = pw_mempool_find_tag(data->pool, tag, sizeof(uint32_t))) != NULL)
|
||||
pw_memmap_free(mm);
|
||||
|
||||
pw_memmap_free(data->activation);
|
||||
|
|
@ -241,7 +242,7 @@ static int client_node_transport(void *object,
|
|||
|
||||
clean_transport(data);
|
||||
|
||||
data->activation = pw_mempool_map_id(data->remote->pool, mem_id,
|
||||
data->activation = pw_mempool_map_id(data->pool, mem_id,
|
||||
PW_MEMMAP_FLAG_READWRITE, offset, size, NULL);
|
||||
if (data->activation == NULL) {
|
||||
pw_log_debug("remote-node %p: can't map activation: %m", proxy);
|
||||
|
|
@ -408,7 +409,7 @@ client_node_set_io(void *object,
|
|||
void *ptr;
|
||||
uint32_t tag[5] = { data->remote_id, id, };
|
||||
|
||||
if ((mm = pw_mempool_find_tag(data->remote->pool, tag, sizeof(tag))) != NULL)
|
||||
if ((mm = pw_mempool_find_tag(data->pool, tag, sizeof(tag))) != NULL)
|
||||
pw_memmap_free(mm);
|
||||
|
||||
if (memid == SPA_ID_INVALID) {
|
||||
|
|
@ -416,7 +417,7 @@ client_node_set_io(void *object,
|
|||
size = 0;
|
||||
}
|
||||
else {
|
||||
mm = pw_mempool_map_id(data->remote->pool, memid,
|
||||
mm = pw_mempool_map_id(data->pool, memid,
|
||||
PW_MEMMAP_FLAG_READWRITE, offset, size, tag);
|
||||
if (mm == NULL) {
|
||||
pw_log_warn("can't map memory id %u: %m", memid);
|
||||
|
|
@ -599,7 +600,7 @@ client_node_port_use_buffers(void *object,
|
|||
off_t offset;
|
||||
struct pw_memmap *mm;
|
||||
|
||||
mm = pw_mempool_map_id(data->remote->pool, buffers[i].mem_id,
|
||||
mm = pw_mempool_map_id(data->pool, buffers[i].mem_id,
|
||||
prot, buffers[i].offset, buffers[i].size, NULL);
|
||||
if (mm == NULL) {
|
||||
res = -errno;
|
||||
|
|
@ -661,7 +662,7 @@ client_node_port_use_buffers(void *object,
|
|||
uint32_t mem_id = SPA_PTR_TO_UINT32(d->data);
|
||||
struct pw_memblock *bm;
|
||||
|
||||
bm = pw_mempool_find_id(data->remote->pool, mem_id);
|
||||
bm = pw_mempool_find_id(data->pool, mem_id);
|
||||
if (bm == NULL) {
|
||||
pw_log_error("unknown buffer mem %u", mem_id);
|
||||
res = -ENODEV;
|
||||
|
|
@ -730,7 +731,7 @@ client_node_port_set_io(void *object,
|
|||
goto error_exit;
|
||||
}
|
||||
|
||||
if ((mm = pw_mempool_find_tag(data->remote->pool, tag, sizeof(tag))) != NULL)
|
||||
if ((mm = pw_mempool_find_tag(data->pool, tag, sizeof(tag))) != NULL)
|
||||
pw_memmap_free(mm);
|
||||
|
||||
if (memid == SPA_ID_INVALID) {
|
||||
|
|
@ -738,7 +739,7 @@ client_node_port_set_io(void *object,
|
|||
size = 0;
|
||||
}
|
||||
else {
|
||||
mm = pw_mempool_map_id(data->remote->pool, memid,
|
||||
mm = pw_mempool_map_id(data->pool, memid,
|
||||
PW_MEMMAP_FLAG_READWRITE, offset, size, tag);
|
||||
if (mm == NULL) {
|
||||
res = -errno;
|
||||
|
|
@ -819,7 +820,7 @@ client_node_set_activation(void *object,
|
|||
size = 0;
|
||||
}
|
||||
else {
|
||||
mm = pw_mempool_map_id(data->remote->pool, memid,
|
||||
mm = pw_mempool_map_id(data->pool, memid,
|
||||
PW_MEMMAP_FLAG_READWRITE, offset, size, NULL);
|
||||
if (mm == NULL) {
|
||||
res = -errno;
|
||||
|
|
@ -1104,7 +1105,7 @@ static const struct spa_node_callbacks node_callbacks = {
|
|||
.xrun = node_xrun
|
||||
};
|
||||
|
||||
static struct pw_proxy *node_export(struct pw_remote *remote, void *object, bool do_free,
|
||||
static struct pw_proxy *node_export(struct pw_core_proxy *core_proxy, void *object, bool do_free,
|
||||
size_t user_data_size)
|
||||
{
|
||||
struct pw_node *node = object;
|
||||
|
|
@ -1112,7 +1113,7 @@ static struct pw_proxy *node_export(struct pw_remote *remote, void *object, bool
|
|||
struct node_data *data;
|
||||
int i;
|
||||
|
||||
client_node = pw_core_proxy_create_object(remote->core_proxy,
|
||||
client_node = pw_core_proxy_create_object(core_proxy,
|
||||
"client-node",
|
||||
PW_TYPE_INTERFACE_ClientNode,
|
||||
PW_VERSION_CLIENT_NODE,
|
||||
|
|
@ -1122,7 +1123,7 @@ static struct pw_proxy *node_export(struct pw_remote *remote, void *object, bool
|
|||
return NULL;
|
||||
|
||||
data = pw_proxy_get_user_data(client_node);
|
||||
data->remote = remote;
|
||||
data->pool = pw_core_proxy_get_mempool(core_proxy);
|
||||
data->node = node;
|
||||
data->do_free = do_free;
|
||||
data->core = pw_node_get_core(node);
|
||||
|
|
@ -1166,13 +1167,12 @@ struct pw_proxy *pw_core_proxy_node_export(struct pw_core_proxy *core_proxy,
|
|||
size_t user_data_size)
|
||||
{
|
||||
struct pw_node *node = object;
|
||||
struct pw_remote *remote = pw_proxy_get_remote((struct pw_proxy*)core_proxy);
|
||||
|
||||
if (props) {
|
||||
pw_node_update_properties(node, &props->dict);
|
||||
pw_properties_free(props);
|
||||
}
|
||||
return node_export(remote, object, false, user_data_size);
|
||||
return node_export(core_proxy, object, false, user_data_size);
|
||||
}
|
||||
|
||||
struct pw_proxy *pw_core_proxy_spa_node_export(struct pw_core_proxy *core_proxy,
|
||||
|
|
@ -1180,9 +1180,8 @@ struct pw_proxy *pw_core_proxy_spa_node_export(struct pw_core_proxy *core_proxy,
|
|||
size_t user_data_size)
|
||||
{
|
||||
struct pw_node *node;
|
||||
struct pw_remote *remote = pw_proxy_get_remote((struct pw_proxy*)core_proxy);
|
||||
|
||||
node = pw_node_new(pw_remote_get_core(remote), props, 0);
|
||||
node = pw_node_new(pw_core_proxy_get_core(core_proxy), props, 0);
|
||||
if (node == NULL)
|
||||
return NULL;
|
||||
|
||||
|
|
@ -1190,5 +1189,5 @@ struct pw_proxy *pw_core_proxy_spa_node_export(struct pw_core_proxy *core_proxy,
|
|||
pw_node_register(node, NULL);
|
||||
pw_node_set_active(node, true);
|
||||
|
||||
return node_export(remote, node, true, user_data_size);
|
||||
return node_export(core_proxy, node, true, user_data_size);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ struct protocol_data {
|
|||
|
||||
struct client {
|
||||
struct pw_protocol_client this;
|
||||
struct pw_core *core;
|
||||
|
||||
struct spa_source *source;
|
||||
|
||||
|
|
@ -579,9 +580,11 @@ static void
|
|||
on_remote_data(void *data, int fd, uint32_t mask)
|
||||
{
|
||||
struct client *impl = data;
|
||||
struct pw_remote *this = impl->this.remote;
|
||||
struct pw_core_proxy *this = impl->this.core_proxy;
|
||||
struct pw_remote *remote = pw_proxy_get_remote((struct pw_proxy*)this);
|
||||
struct pw_protocol_native_connection *conn = impl->connection;
|
||||
struct pw_core *core = pw_remote_get_core(this);
|
||||
struct pw_core *core = pw_core_proxy_get_core(this);
|
||||
struct pw_loop *loop = pw_core_get_main_loop(core);
|
||||
int res;
|
||||
|
||||
if (mask & (SPA_IO_ERR | SPA_IO_HUP)) {
|
||||
|
|
@ -593,7 +596,7 @@ on_remote_data(void *data, int fd, uint32_t mask)
|
|||
if (res >= 0) {
|
||||
int mask = impl->source->mask;
|
||||
SPA_FLAG_CLEAR(mask, SPA_IO_OUT);
|
||||
pw_loop_update_io(core->main_loop,
|
||||
pw_loop_update_io(loop,
|
||||
impl->source, mask);
|
||||
impl->flushing = false;
|
||||
} else if (res != EAGAIN)
|
||||
|
|
@ -620,7 +623,7 @@ on_remote_data(void *data, int fd, uint32_t mask)
|
|||
pw_log_trace(NAME" %p: got message %d from %u seq:%d",
|
||||
this, msg->opcode, msg->id, msg->seq);
|
||||
|
||||
this->recv_seq = msg->seq;
|
||||
remote->recv_seq = msg->seq;
|
||||
|
||||
if (debug_messages) {
|
||||
fprintf(stderr, "<<<<<<<<< in: id:%d op:%d size:%d seq:%d\n",
|
||||
|
|
@ -628,7 +631,7 @@ on_remote_data(void *data, int fd, uint32_t mask)
|
|||
spa_debug_pod(0, NULL, (struct spa_pod *)msg->data);
|
||||
}
|
||||
|
||||
proxy = pw_remote_find_proxy(this, msg->id);
|
||||
proxy = pw_core_proxy_find_proxy(this, msg->id);
|
||||
if (proxy == NULL || proxy->zombie) {
|
||||
if (proxy == NULL)
|
||||
pw_log_error(NAME" %p: could not find proxy %u", this, msg->id);
|
||||
|
|
@ -667,25 +670,24 @@ on_remote_data(void *data, int fd, uint32_t mask)
|
|||
return;
|
||||
error:
|
||||
pw_log_error(NAME" %p: got connection error %d (%s)", impl, res, spa_strerror(res));
|
||||
pw_proxy_notify((struct pw_proxy*)this->core_proxy,
|
||||
pw_proxy_notify((struct pw_proxy*)this,
|
||||
struct pw_core_proxy_events, error, 0, 0,
|
||||
this->recv_seq, res, "connection error");
|
||||
pw_loop_destroy_source(pw_core_get_main_loop(core), impl->source);
|
||||
remote->recv_seq, res, "connection error");
|
||||
pw_loop_destroy_source(loop, impl->source);
|
||||
impl->source = NULL;
|
||||
pw_remote_disconnect(this);
|
||||
pw_core_proxy_disconnect(this);
|
||||
}
|
||||
|
||||
|
||||
static void on_need_flush(void *data)
|
||||
{
|
||||
struct client *impl = data;
|
||||
struct pw_remote *remote = impl->this.remote;
|
||||
|
||||
if (!impl->flushing && impl->source) {
|
||||
int mask = impl->source->mask;
|
||||
impl->flushing = true;
|
||||
SPA_FLAG_SET(mask, SPA_IO_OUT);
|
||||
pw_loop_update_io(remote->core->main_loop,
|
||||
pw_loop_update_io(impl->core->main_loop,
|
||||
impl->source, mask);
|
||||
}
|
||||
}
|
||||
|
|
@ -698,15 +700,15 @@ static const struct pw_protocol_native_connection_events client_conn_events = {
|
|||
static int impl_connect_fd(struct pw_protocol_client *client, int fd, bool do_close)
|
||||
{
|
||||
struct client *impl = SPA_CONTAINER_OF(client, struct client, this);
|
||||
struct pw_remote *remote = client->remote;
|
||||
int res;
|
||||
|
||||
impl->disconnecting = false;
|
||||
|
||||
pw_protocol_native_connection_set_fd(impl->connection, fd);
|
||||
impl->source = pw_loop_add_io(remote->core->main_loop,
|
||||
impl->flushing = true;
|
||||
impl->source = pw_loop_add_io(impl->core->main_loop,
|
||||
fd,
|
||||
SPA_IO_IN | SPA_IO_HUP | SPA_IO_ERR,
|
||||
SPA_IO_IN | SPA_IO_OUT | SPA_IO_HUP | SPA_IO_ERR,
|
||||
do_close, on_remote_data, impl);
|
||||
if (impl->source == NULL) {
|
||||
res = -errno;
|
||||
|
|
@ -730,12 +732,11 @@ error_cleanup:
|
|||
static void impl_disconnect(struct pw_protocol_client *client)
|
||||
{
|
||||
struct client *impl = SPA_CONTAINER_OF(client, struct client, this);
|
||||
struct pw_remote *remote = client->remote;
|
||||
|
||||
impl->disconnecting = true;
|
||||
|
||||
if (impl->source)
|
||||
pw_loop_destroy_source(remote->core->main_loop, impl->source);
|
||||
pw_loop_destroy_source(impl->core->main_loop, impl->source);
|
||||
impl->source = NULL;
|
||||
|
||||
if (impl->connection)
|
||||
|
|
@ -755,7 +756,6 @@ static void impl_destroy(struct pw_protocol_client *client)
|
|||
|
||||
static struct pw_protocol_client *
|
||||
impl_new_client(struct pw_protocol *protocol,
|
||||
struct pw_remote *remote,
|
||||
struct pw_properties *properties)
|
||||
{
|
||||
struct client *impl;
|
||||
|
|
@ -768,9 +768,9 @@ impl_new_client(struct pw_protocol *protocol,
|
|||
|
||||
this = &impl->this;
|
||||
this->protocol = protocol;
|
||||
this->remote = remote;
|
||||
|
||||
impl->connection = pw_protocol_native_connection_new(remote->core, -1);
|
||||
impl->core = protocol->core;
|
||||
impl->connection = pw_protocol_native_connection_new(protocol->core, -1);
|
||||
if (impl->connection == NULL) {
|
||||
res = -errno;
|
||||
goto error_free;
|
||||
|
|
@ -872,10 +872,10 @@ get_name(const struct pw_properties *properties)
|
|||
|
||||
static struct pw_protocol_server *
|
||||
impl_add_server(struct pw_protocol *protocol,
|
||||
struct pw_core *core,
|
||||
struct pw_properties *properties)
|
||||
{
|
||||
struct pw_protocol_server *this;
|
||||
struct pw_core *core = protocol->core;
|
||||
struct server *s;
|
||||
const char *name;
|
||||
int res;
|
||||
|
|
@ -1034,7 +1034,7 @@ int pipewire__module_init(struct pw_module *module, const char *args)
|
|||
if (val == NULL)
|
||||
val = pw_properties_get(pw_core_get_properties(core), PW_KEY_CORE_DAEMON);
|
||||
if (val && pw_properties_parse_bool(val)) {
|
||||
if (impl_add_server(this, core, NULL) == NULL) {
|
||||
if (impl_add_server(this, NULL) == NULL) {
|
||||
res = -errno;
|
||||
goto error_cleanup;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,8 +23,10 @@
|
|||
*/
|
||||
|
||||
int pw_protocol_native_connect_local_socket(struct pw_protocol_client *client,
|
||||
const struct spa_dict *props,
|
||||
void (*done_callback) (void *data, int res),
|
||||
void *data);
|
||||
int pw_protocol_native_connect_portal_screencast(struct pw_protocol_client *client,
|
||||
const struct spa_dict *props,
|
||||
void (*done_callback) (void *data, int res),
|
||||
void *data);
|
||||
|
|
|
|||
|
|
@ -37,12 +37,12 @@
|
|||
#include <pipewire/pipewire.h>
|
||||
|
||||
static const char *
|
||||
get_remote(const struct pw_properties *properties)
|
||||
get_remote(const struct spa_dict *props)
|
||||
{
|
||||
const char *name = NULL;
|
||||
|
||||
if (properties)
|
||||
name = pw_properties_get(properties, PW_KEY_REMOTE_NAME);
|
||||
if (props)
|
||||
name = spa_dict_lookup(props, PW_KEY_REMOTE_NAME);
|
||||
if (name == NULL)
|
||||
name = getenv("PIPEWIRE_REMOTE");
|
||||
if (name == NULL)
|
||||
|
|
@ -51,10 +51,10 @@ get_remote(const struct pw_properties *properties)
|
|||
}
|
||||
|
||||
int pw_protocol_native_connect_local_socket(struct pw_protocol_client *client,
|
||||
const struct spa_dict *props,
|
||||
void (*done_callback) (void *data, int res),
|
||||
void *data)
|
||||
{
|
||||
struct pw_remote *remote = client->remote;
|
||||
struct sockaddr_un addr;
|
||||
socklen_t size;
|
||||
const char *runtime_dir, *name = NULL;
|
||||
|
|
@ -66,7 +66,7 @@ int pw_protocol_native_connect_local_socket(struct pw_protocol_client *client,
|
|||
goto error;
|
||||
}
|
||||
|
||||
name = get_remote(pw_remote_get_properties(remote));
|
||||
name = get_remote(props);
|
||||
|
||||
if ((fd = socket(PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0)) < 0) {
|
||||
res = -errno;
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
#include <pipewire/pipewire.h>
|
||||
|
||||
int pw_protocol_native_connect_portal_screencast(struct pw_protocol_client *client,
|
||||
const struct spa_dict *props,
|
||||
void (*done_callback) (void *data, int res),
|
||||
void *data)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue