mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-03 09:01:54 -05:00
client-device: directly map resource to spa_device
The resource is an implementation of a spa_device with remote methods so we directly use this as a device implementation.
This commit is contained in:
parent
e9ecc47696
commit
32ee1f045d
2 changed files with 51 additions and 124 deletions
|
|
@ -44,113 +44,26 @@ struct impl {
|
|||
struct pw_device *device;
|
||||
struct spa_hook device_listener;
|
||||
|
||||
struct spa_device impl;
|
||||
struct spa_hook_list hooks;
|
||||
|
||||
struct pw_resource *resource;
|
||||
struct spa_hook resource_listener;
|
||||
struct spa_hook implementation_listener;
|
||||
struct spa_hook object_listener;
|
||||
|
||||
struct pw_global *parent;
|
||||
unsigned int registered:1;
|
||||
};
|
||||
|
||||
#define pw_device_resource(r,m,v,...) \
|
||||
pw_resource_call_res(r,struct spa_device_methods,m,v,__VA_ARGS__)
|
||||
|
||||
#define pw_device_resource_enum_params(r,...) \
|
||||
pw_device_resource(r,enum_params,0,__VA_ARGS__)
|
||||
#define pw_device_resource_set_param(r,...) \
|
||||
pw_device_resource(r,set_param,0,__VA_ARGS__)
|
||||
|
||||
static int device_add_listener(void *object,
|
||||
struct spa_hook *listener,
|
||||
const struct spa_device_events *events,
|
||||
void *data)
|
||||
{
|
||||
struct impl *impl = object;
|
||||
struct spa_hook_list save;
|
||||
|
||||
spa_hook_list_isolate(&impl->hooks, &save, listener, events, data);
|
||||
pw_log_debug("client-device %p: add listener", impl);
|
||||
|
||||
spa_hook_list_join(&impl->hooks, &save);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int device_sync(void *object, int seq)
|
||||
{
|
||||
struct impl *impl = object;
|
||||
|
||||
pw_log_debug("client-device %p: sync %d", impl, seq);
|
||||
|
||||
return pw_resource_ping(impl->resource, seq);
|
||||
}
|
||||
|
||||
static int device_enum_params(void *object, int seq,
|
||||
uint32_t id, uint32_t index, uint32_t max,
|
||||
const struct spa_pod *filter)
|
||||
{
|
||||
struct impl *impl = object;
|
||||
pw_log_debug("client-device %p: enum params", impl);
|
||||
return pw_device_resource_enum_params(impl->resource, seq, id, index, max, filter);
|
||||
}
|
||||
|
||||
static int device_set_param(void *object,
|
||||
uint32_t id, uint32_t flags,
|
||||
const struct spa_pod *param)
|
||||
{
|
||||
struct impl *impl = object;
|
||||
pw_log_debug("client-device %p: set param", impl);
|
||||
return pw_device_resource_set_param(impl->resource, id, flags, param);
|
||||
}
|
||||
|
||||
static const struct spa_device_methods impl_device = {
|
||||
SPA_VERSION_DEVICE_METHODS,
|
||||
.add_listener = device_add_listener,
|
||||
.sync = device_sync,
|
||||
.enum_params = device_enum_params,
|
||||
.set_param = device_set_param,
|
||||
};
|
||||
|
||||
static void device_info(void *data, const struct spa_device_info *info)
|
||||
{
|
||||
struct impl *impl = data;
|
||||
spa_device_emit_info(&impl->hooks, info);
|
||||
|
||||
if (!impl->registered) {
|
||||
pw_device_register(impl->device, impl->resource->client, impl->parent, NULL);
|
||||
impl->registered = true;
|
||||
}
|
||||
}
|
||||
|
||||
static void device_result(void *data, int seq, int res, uint32_t type, const void *result)
|
||||
{
|
||||
struct impl *impl = data;
|
||||
pw_log_debug("client-device %p: result %d %d %u", impl, seq, res, type);
|
||||
spa_device_emit_result(&impl->hooks, seq, res, type, result);
|
||||
}
|
||||
|
||||
static void device_event(void *data, const struct spa_event *event)
|
||||
{
|
||||
struct impl *impl = data;
|
||||
spa_device_emit_event(&impl->hooks, event);
|
||||
}
|
||||
|
||||
static void device_object_info(void *data, uint32_t id,
|
||||
const struct spa_device_object_info *info)
|
||||
{
|
||||
struct impl *impl = data;
|
||||
spa_device_emit_object_info(&impl->hooks, id, info);
|
||||
}
|
||||
|
||||
static const struct spa_device_events resource_implementation = {
|
||||
static const struct spa_device_events object_events = {
|
||||
SPA_VERSION_DEVICE_EVENTS,
|
||||
.info = device_info,
|
||||
.result = device_result,
|
||||
.event = device_event,
|
||||
.object_info = device_object_info,
|
||||
};
|
||||
|
||||
static void device_resource_destroy(void *data)
|
||||
|
|
@ -162,20 +75,13 @@ static void device_resource_destroy(void *data)
|
|||
impl->resource = NULL;
|
||||
spa_hook_remove(&impl->device_listener);
|
||||
spa_hook_remove(&impl->resource_listener);
|
||||
spa_hook_remove(&impl->implementation_listener);
|
||||
spa_hook_remove(&impl->object_listener);
|
||||
pw_device_destroy(impl->device);
|
||||
}
|
||||
|
||||
static void device_resource_pong(void *data, int seq)
|
||||
{
|
||||
struct impl *impl = data;
|
||||
spa_device_emit_result(&impl->hooks, seq, 0, 0, NULL);
|
||||
}
|
||||
|
||||
static const struct pw_resource_events resource_events = {
|
||||
PW_VERSION_RESOURCE_EVENTS,
|
||||
.destroy = device_resource_destroy,
|
||||
.pong = device_resource_pong,
|
||||
};
|
||||
|
||||
static void device_destroy(void *data)
|
||||
|
|
@ -187,7 +93,7 @@ static void device_destroy(void *data)
|
|||
impl->device = NULL;
|
||||
spa_hook_remove(&impl->device_listener);
|
||||
spa_hook_remove(&impl->resource_listener);
|
||||
spa_hook_remove(&impl->implementation_listener);
|
||||
spa_hook_remove(&impl->object_listener);
|
||||
pw_resource_destroy(impl->resource);
|
||||
}
|
||||
|
||||
|
|
@ -219,23 +125,19 @@ struct pw_device *pw_client_device_new(struct pw_resource *resource,
|
|||
impl->resource = resource;
|
||||
impl->parent = parent;
|
||||
|
||||
impl->impl.iface = SPA_INTERFACE_INIT(
|
||||
SPA_TYPE_INTERFACE_Device,
|
||||
SPA_VERSION_DEVICE,
|
||||
&impl_device, impl);
|
||||
spa_hook_list_init(&impl->hooks);
|
||||
pw_device_set_implementation(device, &impl->impl);
|
||||
|
||||
pw_device_add_listener(impl->device,
|
||||
&impl->device_listener,
|
||||
&device_events, impl);
|
||||
pw_device_set_implementation(device,
|
||||
(struct spa_device*)resource);
|
||||
|
||||
pw_resource_add_listener(impl->resource,
|
||||
&impl->resource_listener,
|
||||
&resource_events,
|
||||
impl);
|
||||
pw_resource_add_object_listener(impl->resource,
|
||||
&impl->implementation_listener,
|
||||
&resource_implementation,
|
||||
&impl->object_listener,
|
||||
&object_events,
|
||||
impl);
|
||||
|
||||
return device;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue