6#include <pipewire/extensions/metadata.h>
8#include <QtCore/qspan.h>
14#ifndef PW_KEY_DEVICE_SYSFS_PATH
15# define PW_KEY_DEVICE_SYSFS_PATH "device.sysfs.path"
17#ifndef PW_KEY_OBJECT_SERIAL
18# define PW_KEY_OBJECT_SERIAL "object.serial"
25 struct spa_dict info = SPA_DICT_INIT(keyValuePairs.data(), uint32_t(keyValuePairs.size()));
27 return PwPropertiesHandle{
28 pw_properties_new_dict(&info),
34 QSpan<
const spa_dict_item> items{ dict.items, dict.n_items };
37 for (
const spa_dict_item &item : items)
38 map.emplace(item.key, item.value);
44std::optional<std::string_view> resolveInDictionary(
const PwPropertyDict &dict,
47 if (
auto it = dict.find(key); it != dict.end())
52template <
typename Converter>
53auto resolveInDictionaryHelper(
const PwPropertyDict &dict, std::string_view key,
56 using ResultType =
decltype(convert(std::declval<std::string_view>()));
58 if (
auto it = dict.find(key); it != dict.end())
59 return convert(it->second);
60 return ResultType{ std::nullopt };
69struct Converter<uint32_t>
71 std::optional<uint32_t> operator()(std::string_view sv)
const
74 uint32_t ret = QLatin1StringView(sv).toInt(&ok);
83struct Converter<uint64_t>
85 std::optional<uint64_t> operator()(std::string_view sv)
const
87 static_assert(
sizeof(qulonglong) ==
sizeof(uint64_t));
90 uint64_t ret = QLatin1StringView(sv).toULongLong(&ok);
99std::optional<T> resolveInDictionary(
const PwPropertyDict &dict, std::string_view key)
101 return resolveInDictionaryHelper(dict, key, Converter<T>{});
108 return resolveInDictionary(dict, PW_KEY_MEDIA_CLASS);
113 return resolveInDictionary(dict, PW_KEY_NODE_NAME);
118 return resolveInDictionary(dict, PW_KEY_NODE_DESCRIPTION);
123 auto resolvedUint32 = resolveInDictionary<uint32_t>(dict, PW_KEY_DEVICE_ID);
136 return resolveInDictionary(dict, PW_KEY_DEVICE_NAME);
141 return resolveInDictionary(dict, PW_KEY_DEVICE_DESCRIPTION);
154 return resolveInDictionary(dict, PW_KEY_METADATA_NAME);
std::optional< std::string_view > getMetadataName(const PwPropertyDict &)
std::optional< ObjectSerial > getObjectSerial(const PwPropertyDict &)
std::optional< std::string_view > getNodeName(const PwPropertyDict &)
PwPropertyDict toPropertyDict(const spa_dict &)
std::optional< std::string_view > getDeviceSysfsPath(const PwPropertyDict &)
std::optional< std::string_view > getDeviceName(const PwPropertyDict &)
StrongIdType< uint32_t, ObjectIdTag > ObjectId
std::optional< std::string_view > getDeviceDescription(const PwPropertyDict &)
StrongIdType< uint64_t, ObjectSerialTag > ObjectSerial
std::optional< std::string_view > getMediaClass(const PwPropertyDict &)
std::optional< ObjectId > getDeviceId(const PwPropertyDict &)
std::optional< std::string_view > getNodeDescription(const PwPropertyDict &)
PwPropertiesHandle makeProperties(QSpan< const spa_dict_item >)
#define PW_KEY_DEVICE_SYSFS_PATH
#define PW_KEY_OBJECT_SERIAL