From e7cecaaea605d313e63a25c964b809c731f2b009 Mon Sep 17 00:00:00 2001 From: Huang-Huang Bao Date: Tue, 16 Feb 2021 13:47:54 +0800 Subject: [PATCH] media-session: apply updated properties to bluez/v4l2 device handle --- src/examples/media-session/bluez-monitor.c | 53 +++++++++++----------- src/examples/media-session/v4l2-monitor.c | 40 ++++++++-------- 2 files changed, 48 insertions(+), 45 deletions(-) diff --git a/src/examples/media-session/bluez-monitor.c b/src/examples/media-session/bluez-monitor.c index f37c39f0d..9afd259ce 100644 --- a/src/examples/media-session/bluez-monitor.c +++ b/src/examples/media-session/bluez-monitor.c @@ -427,13 +427,30 @@ static struct device *bluez5_create_device(struct impl *impl, uint32_t id, return NULL; } + device = calloc(1, sizeof(*device)); + if (device == NULL) { + res = -errno; + goto exit; + } + + device->impl = impl; + device->id = id; + device->priority = 1000; + device->props = pw_properties_new_dict(info->props); + update_device_props(device); + + spa_list_init(&device->node_list); + + if ((rules = pw_properties_get(impl->conf, "rules")) != NULL) + sm_media_session_match_rules(rules, strlen(rules), device->props); + handle = pw_context_load_spa_handle(context, - info->factory_name, - info->props); + info->factory_name, + &device->props->dict); if (handle == NULL) { res = -errno; pw_log_error("can't make factory instance: %m"); - goto exit; + goto clean_device; } if ((res = spa_handle_get_interface(handle, info->type, &iface)) < 0) { @@ -441,31 +458,15 @@ static struct device *bluez5_create_device(struct impl *impl, uint32_t id, goto unload_handle; } - device = calloc(1, sizeof(*device)); - if (device == NULL) { + device->handle = handle; + device->device = iface; + device->sdevice = sm_media_session_export_device(impl->session, + &device->props->dict, device->device); + if (device->sdevice == NULL) { res = -errno; goto unload_handle; } - device->impl = impl; - device->id = id; - device->priority = 1000; - device->handle = handle; - device->device = iface; - device->props = pw_properties_new_dict(info->props); - update_device_props(device); - device->sdevice = sm_media_session_export_device(impl->session, - &device->props->dict, device->device); - if (device->sdevice == NULL) { - res = -errno; - goto clean_device; - } - - spa_list_init(&device->node_list); - - if ((rules = pw_properties_get(impl->conf, "rules")) != NULL) - sm_media_session_match_rules(rules, strlen(rules), device->props); - sm_object_add_listener(&device->sdevice->obj, &device->listener, &device_events, device); @@ -474,11 +475,11 @@ static struct device *bluez5_create_device(struct impl *impl, uint32_t id, return device; +unload_handle: + pw_unload_spa_handle(handle); clean_device: pw_properties_free(device->props); free(device); -unload_handle: - pw_unload_spa_handle(handle); exit: errno = -res; return NULL; diff --git a/src/examples/media-session/v4l2-monitor.c b/src/examples/media-session/v4l2-monitor.c index b05493eb0..ecb75d085 100644 --- a/src/examples/media-session/v4l2-monitor.c +++ b/src/examples/media-session/v4l2-monitor.c @@ -421,13 +421,27 @@ static struct device *v4l2_create_device(struct impl *impl, uint32_t id, return NULL; } + dev = calloc(1, sizeof(*dev)); + if (dev == NULL) { + res = -errno; + goto exit; + } + + dev->impl = impl; + dev->id = id; + dev->props = pw_properties_new_dict(info->props); + v4l2_update_device_props(dev); + + if ((rules = pw_properties_get(impl->conf, "rules")) != NULL) + sm_media_session_match_rules(rules, strlen(rules), dev->props); + handle = pw_context_load_spa_handle(context, - info->factory_name, - info->props); + info->factory_name, + &dev->props->dict); if (handle == NULL) { res = -errno; pw_log_error("can't make factory instance: %m"); - goto exit; + goto clean_device; } if ((res = spa_handle_get_interface(handle, info->type, &iface)) < 0) { @@ -435,24 +449,11 @@ static struct device *v4l2_create_device(struct impl *impl, uint32_t id, goto unload_handle; } - dev = calloc(1, sizeof(*dev)); - if (dev == NULL) { - res = -errno; - goto unload_handle; - } - - dev->impl = impl; - dev->id = id; dev->handle = handle; dev->device = iface; - dev->props = pw_properties_new_dict(info->props); - v4l2_update_device_props(dev); - - if ((rules = pw_properties_get(impl->conf, "rules")) != NULL) - sm_media_session_match_rules(rules, strlen(rules), dev->props); dev->sdevice = sm_media_session_export_device(impl->session, - &dev->props->dict, dev->device); + &dev->props->dict, dev->device); if (dev->sdevice == NULL) { res = -errno; @@ -470,10 +471,11 @@ static struct device *v4l2_create_device(struct impl *impl, uint32_t id, return dev; -clean_device: - free(dev); unload_handle: pw_unload_spa_handle(handle); +clean_device: + pw_properties_free(dev->props); + free(dev); exit: errno = -res; return NULL;