media-session: add conf file for v4l2 and bluez as well

This commit is contained in:
Wim Taymans 2021-01-12 20:38:47 +01:00
parent 4cba8fc7e9
commit fac80e76d2
9 changed files with 292 additions and 116 deletions

View file

@ -43,6 +43,8 @@
#include "media-session.h"
#define SESSION_CONF "v4l2-monitor.conf"
struct device;
struct node {
@ -83,6 +85,8 @@ struct impl {
struct sm_media_session *session;
struct spa_hook session_listener;
struct pw_properties *conf;
struct spa_handle *handle;
struct spa_device *monitor;
struct spa_hook listener;
@ -123,7 +127,7 @@ static struct node *v4l2_create_node(struct device *dev, uint32_t id,
struct node *node;
struct impl *impl = dev->impl;
int i, res;
const char *str, *d;
const char *str, *d, *rules;
pw_log_debug("new node %u", id);
@ -168,6 +172,9 @@ static struct node *v4l2_create_node(struct device *dev, uint32_t id,
pw_properties_set(node->props, PW_KEY_FACTORY_NAME, info->factory_name);
if ((rules = pw_properties_get(impl->conf, "rules")) != NULL)
sm_media_session_match_rules(rules, strlen(rules), dev->props);
node->impl = impl;
node->device = dev;
node->id = id;
@ -383,6 +390,7 @@ static struct device *v4l2_create_device(struct impl *impl, uint32_t id,
struct spa_handle *handle;
int res;
void *iface;
const char *rules;
pw_log_debug("new device %u", id);
@ -418,6 +426,9 @@ static struct device *v4l2_create_device(struct impl *impl, uint32_t 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);
dev->sdevice = sm_media_session_export_device(impl->session,
&dev->props->dict, dev->device);
@ -485,6 +496,7 @@ static void session_destroy(void *data)
spa_hook_remove(&impl->session_listener);
spa_hook_remove(&impl->listener);
pw_unload_spa_handle(impl->handle);
pw_properties_free(impl->conf);
free(impl);
}
@ -504,6 +516,11 @@ int sm_v4l2_monitor_start(struct sm_media_session *sess)
if (impl == NULL)
return -errno;
impl->conf = pw_properties_new(NULL, NULL);
if (impl->conf == NULL) {
res = -errno;
goto out_free;
}
impl->session = sess;
impl->handle = pw_context_load_spa_handle(context, SPA_NAME_API_V4L2_ENUM_UDEV, NULL);
@ -517,9 +534,14 @@ int sm_v4l2_monitor_start(struct sm_media_session *sess)
goto out_unload;
}
impl->monitor = iface;
spa_list_init(&impl->device_list);
if ((res = sm_media_session_load_conf(impl->session,
SESSION_CONF, impl->conf)) < 0)
pw_log_info("can't load "SESSION_CONF" config: %s", spa_strerror(res));
spa_device_add_listener(impl->monitor, &impl->listener,
&v4l2_udev_callbacks, impl);