mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05:00
spa: make common function to find type from short name
This commit is contained in:
parent
ba7e5d619d
commit
aa128ed489
4 changed files with 25 additions and 47 deletions
|
|
@ -96,6 +96,26 @@ static inline uint32_t spa_debug_type_find_type(const struct spa_type_info *info
|
||||||
return SPA_ID_INVALID;
|
return SPA_ID_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline const struct spa_type_info *spa_debug_type_find_short(const struct spa_type_info *info, const char *name)
|
||||||
|
{
|
||||||
|
while (info && info->name) {
|
||||||
|
if (strcmp(spa_debug_type_short_name(info->name), name) == 0)
|
||||||
|
return info;
|
||||||
|
if (strcmp(info->name, name) == 0)
|
||||||
|
return info;
|
||||||
|
if (info->type != 0 && info->type == (uint32_t)atoi(name))
|
||||||
|
return info;
|
||||||
|
info++;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint32_t spa_debug_type_find_type_short(const struct spa_type_info *info, const char *name)
|
||||||
|
{
|
||||||
|
if ((info = spa_debug_type_find_short(info, name)) == NULL)
|
||||||
|
return SPA_ID_INVALID;
|
||||||
|
return info->type;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* \}
|
* \}
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -44,20 +44,6 @@ extern "C" {
|
||||||
* \{
|
* \{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static inline const struct spa_type_info *spa_debug_type_info_short(const struct spa_type_info *info, const char *name)
|
|
||||||
{
|
|
||||||
while (info && info->name) {
|
|
||||||
if (spa_streq(info->name, name))
|
|
||||||
return info;
|
|
||||||
if (spa_streq(spa_debug_type_short_name(info->name), name))
|
|
||||||
return info;
|
|
||||||
if (info->type != 0 && info->type == (uint32_t)atoi(name))
|
|
||||||
return info;
|
|
||||||
info++;
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int spa_json_to_pod_part(struct spa_pod_builder *b, uint32_t flags, uint32_t id,
|
static inline int spa_json_to_pod_part(struct spa_pod_builder *b, uint32_t flags, uint32_t id,
|
||||||
const struct spa_type_info *info, struct spa_json *iter, const char *value, int len)
|
const struct spa_type_info *info, struct spa_json *iter, const char *value, int len)
|
||||||
{
|
{
|
||||||
|
|
@ -80,7 +66,7 @@ static inline int spa_json_to_pod_part(struct spa_pod_builder *b, uint32_t flags
|
||||||
const struct spa_type_info *pi;
|
const struct spa_type_info *pi;
|
||||||
if ((l = spa_json_next(&it[0], &v)) <= 0)
|
if ((l = spa_json_next(&it[0], &v)) <= 0)
|
||||||
break;
|
break;
|
||||||
if ((pi = spa_debug_type_info_short(ti->values, key)) != NULL)
|
if ((pi = spa_debug_type_find_short(ti->values, key)) != NULL)
|
||||||
type = pi->type;
|
type = pi->type;
|
||||||
else if (!spa_atou32(key, &type, 0))
|
else if (!spa_atou32(key, &type, 0))
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -149,7 +135,7 @@ static inline int spa_json_to_pod_part(struct spa_pod_builder *b, uint32_t flags
|
||||||
spa_json_parse_stringn(value, len, val, len+1);
|
spa_json_parse_stringn(value, len, val, len+1);
|
||||||
switch (info ? info->parent : (uint32_t)SPA_TYPE_Struct) {
|
switch (info ? info->parent : (uint32_t)SPA_TYPE_Struct) {
|
||||||
case SPA_TYPE_Id:
|
case SPA_TYPE_Id:
|
||||||
if ((ti = spa_debug_type_info_short(info->values, val)) != NULL)
|
if ((ti = spa_debug_type_find_short(info->values, val)) != NULL)
|
||||||
type = ti->type;
|
type = ti->type;
|
||||||
else if (!spa_atou32(val, &type, 0))
|
else if (!spa_atou32(val, &type, 0))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
|
||||||
|
|
@ -173,20 +173,6 @@ static const struct pw_impl_node_events node_events = {
|
||||||
.port_init = node_port_init,
|
.port_init = node_port_init,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct spa_type_info *find_type_info(const struct spa_type_info *info, const char *name)
|
|
||||||
{
|
|
||||||
while (info && info->name) {
|
|
||||||
if (spa_streq(info->name, name))
|
|
||||||
return info;
|
|
||||||
if (spa_streq(spa_debug_type_short_name(info->name), name))
|
|
||||||
return info;
|
|
||||||
if (info->type != 0 && info->type == (uint32_t)atoi(name))
|
|
||||||
return info;
|
|
||||||
info++;
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int handle_node_param(struct pw_impl_node *node, const char *key, const char *value)
|
static int handle_node_param(struct pw_impl_node *node, const char *key, const char *value)
|
||||||
{
|
{
|
||||||
const struct spa_type_info *ti;
|
const struct spa_type_info *ti;
|
||||||
|
|
@ -195,7 +181,7 @@ static int handle_node_param(struct pw_impl_node *node, const char *key, const c
|
||||||
struct spa_pod *pod;
|
struct spa_pod *pod;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
ti = find_type_info(spa_type_param, key);
|
ti = spa_debug_type_find_short(spa_type_param, key);
|
||||||
if (ti == NULL)
|
if (ti == NULL)
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1477,20 +1477,6 @@ static bool do_export_node(struct data *data, const char *cmd, char *args, char
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct spa_type_info *find_type_info(const struct spa_type_info *info, const char *name)
|
|
||||||
{
|
|
||||||
while (info && info->name) {
|
|
||||||
if (spa_streq(info->name, name))
|
|
||||||
return info;
|
|
||||||
if (spa_streq(spa_debug_type_short_name(info->name), name))
|
|
||||||
return info;
|
|
||||||
if (info->type != 0 && info->type == (uint32_t)atoi(name))
|
|
||||||
return info;
|
|
||||||
info++;
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool do_enum_params(struct data *data, const char *cmd, char *args, char **error)
|
static bool do_enum_params(struct data *data, const char *cmd, char *args, char **error)
|
||||||
{
|
{
|
||||||
struct remote_data *rd = data->current;
|
struct remote_data *rd = data->current;
|
||||||
|
|
@ -1507,7 +1493,7 @@ static bool do_enum_params(struct data *data, const char *cmd, char *args, char
|
||||||
}
|
}
|
||||||
|
|
||||||
id = atoi(a[0]);
|
id = atoi(a[0]);
|
||||||
ti = find_type_info(spa_type_param, a[1]);
|
ti = spa_debug_type_find_short(spa_type_param, a[1]);
|
||||||
if (ti == NULL) {
|
if (ti == NULL) {
|
||||||
*error = spa_aprintf("%s: unknown param type: %s", cmd, a[1]);
|
*error = spa_aprintf("%s: unknown param type: %s", cmd, a[1]);
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -1574,7 +1560,7 @@ static bool do_set_param(struct data *data, const char *cmd, char *args, char **
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ti = find_type_info(spa_type_param, a[1]);
|
ti = spa_debug_type_find_short(spa_type_param, a[1]);
|
||||||
if (ti == NULL) {
|
if (ti == NULL) {
|
||||||
*error = spa_aprintf("%s: unknown param type: %s", cmd, a[1]);
|
*error = spa_aprintf("%s: unknown param type: %s", cmd, a[1]);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue