mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
spa: add keys for properties
Define and document property keys
This commit is contained in:
parent
1f250046a3
commit
49ef8f9b5f
35 changed files with 333 additions and 134 deletions
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
#include <spa/support/log.h>
|
||||
#include <spa/support/loop.h>
|
||||
#include <spa/utils/keys.h>
|
||||
#include <spa/pod/builder.h>
|
||||
#include <spa/monitor/device.h>
|
||||
#include <spa/monitor/utils.h>
|
||||
|
|
@ -71,6 +72,7 @@ static int emit_info(struct impl *this, bool full)
|
|||
{
|
||||
int res;
|
||||
struct spa_dict_item items[6];
|
||||
uint32_t n_items = 0;
|
||||
struct spa_device_info info;
|
||||
struct spa_param_info params[2];
|
||||
|
||||
|
|
@ -80,13 +82,13 @@ static int emit_info(struct impl *this, bool full)
|
|||
info = SPA_DEVICE_INFO_INIT();
|
||||
|
||||
info.change_mask = SPA_DEVICE_CHANGE_MASK_PROPS;
|
||||
items[0] = SPA_DICT_ITEM_INIT("device.api", "v4l2");
|
||||
items[1] = SPA_DICT_ITEM_INIT("device.path", (char *)this->props.device);
|
||||
items[2] = SPA_DICT_ITEM_INIT("media.class", "Video/Device");
|
||||
items[3] = SPA_DICT_ITEM_INIT("v4l2.driver", (char *)this->dev.cap.driver);
|
||||
items[4] = SPA_DICT_ITEM_INIT("v4l2.card", (char *)this->dev.cap.card);
|
||||
items[5] = SPA_DICT_ITEM_INIT("v4l2.bus", (char *)this->dev.cap.bus_info);
|
||||
info.props = &SPA_DICT_INIT(items, 6);
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_MEDIA_CLASS, "Video/Device");
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_DEVICE_API, "v4l2");
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_API_V4L2_PATH, (char *)this->props.device);
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_API_V4L2_CAP_DRIVER, (char *)this->dev.cap.driver);
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_API_V4L2_CAP_CARD, (char *)this->dev.cap.card);
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_API_V4L2_CAP_BUS_INFO, (char *)this->dev.cap.bus_info);
|
||||
info.props = &SPA_DICT_INIT(items, n_items);
|
||||
|
||||
info.change_mask |= SPA_DEVICE_CHANGE_MASK_PARAMS;
|
||||
params[0] = SPA_PARAM_INFO(SPA_PARAM_EnumProfile, SPA_PARAM_INFO_READ);
|
||||
|
|
@ -103,7 +105,7 @@ static int emit_info(struct impl *this, bool full)
|
|||
oinfo.type = SPA_TYPE_INTERFACE_Node;
|
||||
oinfo.factory_name = "api.v4l2.source";
|
||||
oinfo.change_mask = SPA_DEVICE_OBJECT_CHANGE_MASK_PROPS;
|
||||
oinfo.props = &SPA_DICT_INIT(items, 6);
|
||||
oinfo.props = &SPA_DICT_INIT(items, n_items);
|
||||
|
||||
spa_device_emit_object_info(&this->hooks, 0, &oinfo);
|
||||
}
|
||||
|
|
@ -236,7 +238,7 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
|
||||
reset_props(&this->props);
|
||||
|
||||
if (info && (str = spa_dict_lookup(info, "device.path")))
|
||||
if (info && (str = spa_dict_lookup(info, SPA_KEY_API_V4L2_PATH)))
|
||||
strncpy(this->props.device, str, 63);
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@
|
|||
#include <spa/support/loop.h>
|
||||
#include <spa/support/plugin.h>
|
||||
#include <spa/utils/type.h>
|
||||
#include <spa/utils/keys.h>
|
||||
#include <spa/monitor/monitor.h>
|
||||
#include <spa/monitor/utils.h>
|
||||
|
||||
|
|
@ -116,33 +117,34 @@ static int emit_object_info(struct impl *this, uint32_t id, struct udev_device *
|
|||
if (!(name && *name))
|
||||
name = "Unknown";
|
||||
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT("udev-probed", "1");
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT("device.path", udev_device_get_devnode(dev));
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT("device.name", name);
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_MONITOR_API,"udev");
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_DEVICE_API, "v4l2");
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_DEVICE_NAME, name);
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_API_V4L2_PATH, udev_device_get_devnode(dev));
|
||||
|
||||
if ((str = udev_device_get_property_value(dev, "USEC_INITIALIZED")) && *str)
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT("device.plugged.usec", str);
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_DEVICE_PLUGGED_USEC, str);
|
||||
|
||||
str = udev_device_get_property_value(dev, "ID_PATH");
|
||||
if (!(str && *str))
|
||||
str = udev_device_get_syspath(dev);
|
||||
if (str && *str) {
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT("device.bus_path", str);
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_DEVICE_BUS_PATH, str);
|
||||
}
|
||||
if ((str = udev_device_get_syspath(dev)) && *str) {
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT("sysfs.path", str);
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_DEVICE_SYSFS_PATH, str);
|
||||
}
|
||||
if ((str = udev_device_get_property_value(dev, "ID_ID")) && *str) {
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT("udev.id", str);
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_DEVICE_ID, str);
|
||||
}
|
||||
if ((str = udev_device_get_property_value(dev, "ID_BUS")) && *str) {
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT("device.bus", str);
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_DEVICE_BUS, str);
|
||||
}
|
||||
if ((str = udev_device_get_property_value(dev, "SUBSYSTEM")) && *str) {
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT("device.subsystem", str);
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_DEVICE_SUBSYSTEM, str);
|
||||
}
|
||||
if ((str = udev_device_get_property_value(dev, "ID_VENDOR_ID")) && *str) {
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT("device.vendor.id", str);
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_DEVICE_VENDOR_ID, str);
|
||||
}
|
||||
str = udev_device_get_property_value(dev, "ID_VENDOR_FROM_DATABASE");
|
||||
if (!(str && *str)) {
|
||||
|
|
@ -152,17 +154,17 @@ static int emit_object_info(struct impl *this, uint32_t id, struct udev_device *
|
|||
}
|
||||
}
|
||||
if (str && *str) {
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT("device.vendor.name", str);
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_DEVICE_VENDOR_NAME, str);
|
||||
}
|
||||
if ((str = udev_device_get_property_value(dev, "ID_MODEL_ID")) && *str) {
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT("device.product.id", str);
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_DEVICE_PRODUCT_ID, str);
|
||||
}
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT("device.product.name", name);
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_DEVICE_PRODUCT_NAME, name);
|
||||
if ((str = udev_device_get_property_value(dev, "ID_SERIAL")) && *str) {
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT("device.serial", str);
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_DEVICE_SERIAL, str);
|
||||
}
|
||||
if ((str = udev_device_get_property_value(dev, "ID_V4L_CAPABILITIES")) && *str) {
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT("device.capabilities", str);
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_DEVICE_CAPABILITIES, str);
|
||||
}
|
||||
info.props = &SPA_DICT_INIT(items, n_items);
|
||||
spa_monitor_call_object_info(&this->callbacks, id, &info);
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@
|
|||
#include <spa/support/log.h>
|
||||
#include <spa/support/loop.h>
|
||||
#include <spa/utils/list.h>
|
||||
#include <spa/utils/keys.h>
|
||||
#include <spa/monitor/device.h>
|
||||
#include <spa/node/node.h>
|
||||
#include <spa/node/io.h>
|
||||
#include <spa/node/utils.h>
|
||||
|
|
@ -315,11 +317,11 @@ static int impl_node_send_command(void *object, const struct spa_command *comman
|
|||
}
|
||||
|
||||
static const struct spa_dict_item info_items[] = {
|
||||
{ "device.api", "v4l2" },
|
||||
{ "media.class", "Video/Source" },
|
||||
{ "media.role", "Camera" },
|
||||
{ "node.pause-on-idle", "false" },
|
||||
{ "node.driver", "true" },
|
||||
{ SPA_KEY_DEVICE_API, "v4l2" },
|
||||
{ SPA_KEY_MEDIA_CLASS, "Video/Source" },
|
||||
{ SPA_KEY_MEDIA_ROLE, "Camera" },
|
||||
{ SPA_KEY_NODE_PAUSE_ON_IDLE, "false" },
|
||||
{ SPA_KEY_NODE_DRIVER, "true" },
|
||||
};
|
||||
|
||||
static void emit_node_info(struct impl *this, bool full)
|
||||
|
|
@ -1013,7 +1015,7 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
port->dev.log = this->log;
|
||||
port->dev.fd = -1;
|
||||
|
||||
if (info && (str = spa_dict_lookup(info, "device.path"))) {
|
||||
if (info && (str = spa_dict_lookup(info, SPA_KEY_API_V4L2_PATH))) {
|
||||
strncpy(this->props.device, str, 63);
|
||||
if ((res = spa_v4l2_open(&port->dev, this->props.device)) < 0)
|
||||
return res;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue