2023-02-08 18:12:00 +01:00
|
|
|
/* PipeWire */
|
|
|
|
|
/* SPDX-FileCopyrightText: Copyright © 2019 Wim Taymans */
|
|
|
|
|
/* SPDX-License-Identifier: MIT */
|
2019-05-28 14:04:58 +02:00
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
|
|
#include <spa/pod/parser.h>
|
|
|
|
|
#include <spa/monitor/device.h>
|
|
|
|
|
|
|
|
|
|
#include "pipewire/pipewire.h"
|
|
|
|
|
|
|
|
|
|
struct device_data {
|
|
|
|
|
struct spa_device *device;
|
|
|
|
|
struct spa_hook device_listener;
|
|
|
|
|
struct spa_hook device_methods;
|
|
|
|
|
|
|
|
|
|
struct pw_proxy *proxy;
|
|
|
|
|
struct spa_hook proxy_listener;
|
|
|
|
|
};
|
|
|
|
|
|
2019-12-11 16:51:38 +01:00
|
|
|
static void proxy_device_destroy(void *_data)
|
2019-05-28 14:04:58 +02:00
|
|
|
{
|
|
|
|
|
struct device_data *data = _data;
|
|
|
|
|
spa_hook_remove(&data->device_listener);
|
2020-11-06 15:53:32 +01:00
|
|
|
spa_hook_remove(&data->device_methods);
|
|
|
|
|
spa_hook_remove(&data->proxy_listener);
|
2019-05-28 14:04:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct pw_proxy_events proxy_events = {
|
|
|
|
|
PW_VERSION_PROXY_EVENTS,
|
2019-12-11 16:51:38 +01:00
|
|
|
.destroy = proxy_device_destroy,
|
2019-05-28 14:04:58 +02:00
|
|
|
};
|
|
|
|
|
|
2019-12-11 07:46:59 +01:00
|
|
|
struct pw_proxy *pw_core_spa_device_export(struct pw_core *core,
|
2020-03-19 18:12:07 +01:00
|
|
|
const char *type, const struct spa_dict *props, void *object,
|
2019-05-30 16:11:31 +02:00
|
|
|
size_t user_data_size)
|
2019-05-28 14:04:58 +02:00
|
|
|
{
|
|
|
|
|
struct spa_device *device = object;
|
2019-12-06 17:37:41 +01:00
|
|
|
struct spa_interface *iface, *diface;
|
2019-05-28 14:04:58 +02:00
|
|
|
struct pw_proxy *proxy;
|
|
|
|
|
struct device_data *data;
|
|
|
|
|
|
2019-12-11 07:46:59 +01:00
|
|
|
proxy = pw_core_create_object(core,
|
2019-12-17 10:47:31 +01:00
|
|
|
"client-device",
|
|
|
|
|
SPA_TYPE_INTERFACE_Device,
|
|
|
|
|
SPA_VERSION_DEVICE,
|
|
|
|
|
props,
|
|
|
|
|
user_data_size + sizeof(struct device_data));
|
2019-05-28 14:04:58 +02:00
|
|
|
if (proxy == NULL)
|
2019-09-27 10:06:25 +02:00
|
|
|
return NULL;
|
2019-05-28 14:04:58 +02:00
|
|
|
|
|
|
|
|
data = pw_proxy_get_user_data(proxy);
|
2021-05-06 13:41:44 +10:00
|
|
|
data = SPA_PTROFF(data, user_data_size, struct device_data);
|
2019-05-28 14:04:58 +02:00
|
|
|
data->device = device;
|
|
|
|
|
data->proxy = proxy;
|
|
|
|
|
|
2019-05-29 10:39:24 +02:00
|
|
|
iface = (struct spa_interface*)proxy;
|
2019-12-06 17:37:41 +01:00
|
|
|
diface = (struct spa_interface*)device;
|
2019-05-29 10:39:24 +02:00
|
|
|
|
2019-05-28 14:04:58 +02:00
|
|
|
pw_proxy_add_listener(proxy, &data->proxy_listener, &proxy_events, data);
|
2019-05-29 10:39:24 +02:00
|
|
|
|
|
|
|
|
pw_proxy_add_object_listener(proxy, &data->device_methods,
|
2019-12-06 17:37:41 +01:00
|
|
|
diface->cb.funcs, diface->cb.data);
|
2019-05-29 10:39:24 +02:00
|
|
|
spa_device_add_listener(device, &data->device_listener,
|
|
|
|
|
iface->cb.funcs, iface->cb.data);
|
2019-05-28 14:04:58 +02:00
|
|
|
|
|
|
|
|
return proxy;
|
|
|
|
|
}
|