diff --git a/src/modules/module-client-device/protocol-native.c b/src/modules/module-client-device/protocol-native.c index e936ee0bb..ed65e7f74 100644 --- a/src/modules/module-client-device/protocol-native.c +++ b/src/modules/module-client-device/protocol-native.c @@ -35,7 +35,9 @@ static int device_marshal_add_listener(void *object, const struct spa_device_events *events, void *data) { - return -ENOTSUP; + struct pw_resource *resource = object; + pw_resource_add_object_listener(resource, listener, events, data); + return 0; } static int device_demarshal_add_listener(void *object, @@ -44,6 +46,36 @@ static int device_demarshal_add_listener(void *object, return -ENOTSUP; } +static int device_marshal_sync(void *object, int seq) +{ + struct pw_protocol_native_message *msg; + struct pw_resource *resource = object; + struct spa_pod_builder *b; + + b = pw_protocol_native_begin_resource(resource, SPA_DEVICE_METHOD_SYNC, &msg); + + spa_pod_builder_add_struct(b, + SPA_POD_Int(SPA_RESULT_RETURN_ASYNC(msg->seq))); + + return pw_protocol_native_end_resource(resource, b); +} + +static int device_demarshal_sync(void *object, + const struct pw_protocol_native_message *msg) +{ + struct pw_proxy *proxy = object; + struct spa_pod_parser prs; + int seq; + + spa_pod_parser_init(&prs, msg->data, msg->size); + if (spa_pod_parser_get_struct(&prs, + SPA_POD_Int(&seq)) < 0) + return -EINVAL; + + pw_proxy_notify(proxy, struct spa_device_methods, sync, 0, seq); + return 0; +} + static int device_marshal_enum_params(void *object, int seq, uint32_t id, uint32_t index, uint32_t max, const struct spa_pod *filter) @@ -51,18 +83,15 @@ static int device_marshal_enum_params(void *object, int seq, struct pw_protocol_native_message *msg; struct pw_resource *resource = object; struct spa_pod_builder *b; - struct spa_pod_frame f[2]; b = pw_protocol_native_begin_resource(resource, SPA_DEVICE_METHOD_ENUM_PARAMS, &msg); - spa_pod_builder_push_struct(b, &f[0]); - spa_pod_builder_add(b, + spa_pod_builder_add_struct(b, SPA_POD_Int(SPA_RESULT_RETURN_ASYNC(msg->seq)), SPA_POD_Id(id), SPA_POD_Int(index), SPA_POD_Int(max), - SPA_POD_Pod(filter), NULL); - spa_pod_builder_pop(b, &f[0]); + SPA_POD_Pod(filter)); return pw_protocol_native_end_resource(resource, b); } @@ -95,16 +124,13 @@ static int device_marshal_set_param(void *object, { struct pw_resource *resource = object; struct spa_pod_builder *b; - struct spa_pod_frame f[2]; b = pw_protocol_native_begin_resource(resource, SPA_DEVICE_METHOD_SET_PARAM, NULL); - spa_pod_builder_push_struct(b, &f[0]); - spa_pod_builder_add(b, + spa_pod_builder_add_struct(b, SPA_POD_Id(id), SPA_POD_Int(flags), - SPA_POD_Pod(param), NULL); - spa_pod_builder_pop(b, &f[0]); + SPA_POD_Pod(param)); return pw_protocol_native_end_resource(resource, b); } @@ -322,14 +348,11 @@ static void device_marshal_event(void *object, const struct spa_event *event) { struct pw_proxy *proxy = object; struct spa_pod_builder *b; - struct spa_pod_frame f[2]; b = pw_protocol_native_begin_proxy(proxy, SPA_DEVICE_EVENT_RESULT, NULL); - spa_pod_builder_push_struct(b, &f[0]); - spa_pod_builder_add(b, - SPA_POD_Pod(event), - NULL); - spa_pod_builder_pop(b, &f[0]); + + spa_pod_builder_add_struct(b, + SPA_POD_Pod(event)); pw_protocol_native_end_proxy(proxy, b); } @@ -447,6 +470,7 @@ static int device_demarshal_object_info(void *object, static const struct spa_device_methods pw_protocol_native_device_method_marshal = { SPA_VERSION_DEVICE_METHODS, .add_listener = &device_marshal_add_listener, + .sync = &device_marshal_sync, .enum_params = &device_marshal_enum_params, .set_param = &device_marshal_set_param }; @@ -455,6 +479,7 @@ static const struct pw_protocol_native_demarshal pw_protocol_native_device_method_demarshal[SPA_DEVICE_METHOD_NUM] = { [SPA_DEVICE_METHOD_ADD_LISTENER] = { &device_demarshal_add_listener, 0 }, + [SPA_DEVICE_METHOD_SYNC] = { &device_demarshal_sync, 0 }, [SPA_DEVICE_METHOD_ENUM_PARAMS] = { &device_demarshal_enum_params, 0 }, [SPA_DEVICE_METHOD_SET_PARAM] = { &device_demarshal_set_param, 0 }, }; diff --git a/src/modules/module-client-device/resource-device.c b/src/modules/module-client-device/resource-device.c index b3ba6c2fc..907dba84b 100644 --- a/src/modules/module-client-device/resource-device.c +++ b/src/modules/module-client-device/resource-device.c @@ -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;