Skip to content
Snippets Groups Projects
Commit aa93ecf7 authored by George Kiagiadakis's avatar George Kiagiadakis
Browse files

spa-pod: add the ability to specify Id properties as strings

Use the unused 'K' format letter in the varargs builder & parser methods
parent 37623888
No related branches found
No related tags found
No related merge requests found
......@@ -2260,7 +2260,10 @@ wp_spa_pod_builder_add (WpSpaPodBuilder *self, ...)
void
wp_spa_pod_builder_add_valist (WpSpaPodBuilder *self, va_list args)
{
WpSpaIdTable table = wp_spa_type_get_values_table (self->type);
do {
WpSpaIdValue key = NULL;
const char *format;
int n_values = 1;
struct spa_pod_frame f;
......@@ -2270,9 +2273,7 @@ wp_spa_pod_builder_add_valist (WpSpaPodBuilder *self, va_list args)
const char *key_name = va_arg(args, const char *);
if (!key_name)
return;
WpSpaIdTable table = wp_spa_type_get_values_table (self->type);
WpSpaIdValue key =
wp_spa_id_table_find_value_from_short_name (table, key_name);
key = wp_spa_id_table_find_value_from_short_name (table, key_name);
g_return_if_fail (key != NULL);
spa_pod_builder_prop (&self->builder, wp_spa_id_value_number (key), 0);
......@@ -2311,6 +2312,17 @@ wp_spa_pod_builder_add_valist (WpSpaPodBuilder *self, va_list args)
case 'T': /* Struct */
spa_pod_builder_primitive (&self->builder, va_arg(args, WpSpaPod *)->pod);
break;
case 'K': { /* Id as string - WirePlumber extension */
const char * id = va_arg(args, const char *);
if (key) {
WpSpaIdTable id_table = NULL;
wp_spa_id_value_get_value_type (key, &id_table);
WpSpaIdValue id_val =
wp_spa_id_table_find_value_from_short_name (id_table, id);
spa_pod_builder_id (&self->builder, wp_spa_id_value_number (id_val));
}
break;
}
default:
SPA_POD_BUILDER_COLLECT(&self->builder, *format, args);
break;
......@@ -2709,8 +2721,10 @@ gboolean
wp_spa_pod_parser_get_valist (WpSpaPodParser *self, va_list args)
{
const struct spa_pod_prop *prop = NULL;
WpSpaIdTable table = wp_spa_type_get_values_table (self->type);
do {
WpSpaIdValue key = NULL;
bool optional;
const struct spa_pod *pod = NULL;
const char *format;
......@@ -2719,9 +2733,7 @@ wp_spa_pod_parser_get_valist (WpSpaPodParser *self, va_list args)
const char *key_name = va_arg(args, const char *);
if (!key_name)
break;
WpSpaIdTable table = wp_spa_type_get_values_table (self->type);
WpSpaIdValue key =
wp_spa_id_table_find_value_from_short_name (table, key_name);
key = wp_spa_id_table_find_value_from_short_name (table, key_name);
g_return_val_if_fail (key != NULL, FALSE);
const struct spa_pod_object *object = (const struct spa_pod_object *)
......@@ -2757,6 +2769,17 @@ wp_spa_pod_parser_get_valist (WpSpaPodParser *self, va_list args)
case 'T': /* Struct */
*va_arg(args, WpSpaPod**) = wp_spa_pod_new_wrap_copy (pod);
break;
case 'K': { /* Id as string - WirePlumber extension */
const char ** idstr = va_arg(args, const char **);
uint32_t id = SPA_POD_VALUE(struct spa_pod_id, pod);
if (key) {
WpSpaIdTable id_table = NULL;
wp_spa_id_value_get_value_type (key, &id_table);
WpSpaIdValue id_val = wp_spa_id_table_find_value (id_table, id);
*idstr = wp_spa_id_value_short_name (id_val);
}
break;
}
default:
SPA_POD_PARSER_COLLECT (pod, *format, args);
break;
......
......@@ -261,8 +261,8 @@ format_audio_raw_build (const struct spa_audio_info_raw *info)
g_autoptr (WpSpaPodBuilder) builder = wp_spa_pod_builder_new_object (
"Spa:Pod:Object:Param:Format", "Format");
wp_spa_pod_builder_add (builder,
"mediaType", "I", SPA_MEDIA_TYPE_audio,
"mediaSubtype", "I", SPA_MEDIA_SUBTYPE_raw,
"mediaType", "K", "audio",
"mediaSubtype", "K", "raw",
"format", "I", info->format,
"rate", "i", info->rate,
"channels", "i", info->channels,
......@@ -330,7 +330,7 @@ si_adapter_activate_execute_step (WpSessionItem * item,
pod = wp_spa_pod_new_object (
"Spa:Pod:Object:Param:PortConfig", "PortConfig",
"direction", "I", self->direction,
"mode", "I", SPA_PARAM_PORT_CONFIG_MODE_dsp,
"mode", "K", "dsp",
"monitor", "b", self->monitor,
"control", "b", self->control_port,
"format", "P", port_format,
......
......@@ -289,9 +289,9 @@ si_convert_activate_execute_step (WpSessionItem * item,
format = wp_spa_pod_new_object (
"Spa:Pod:Object:Param:Format", "Format",
"mediaType", "I", SPA_MEDIA_TYPE_audio,
"mediaSubtype", "I", SPA_MEDIA_SUBTYPE_raw,
"format", "I", SPA_AUDIO_FORMAT_F32P,
"mediaType", "K", "audio",
"mediaSubtype", "K", "raw",
"format", "K", "F32P",
"rate", "i", rate,
"channels", "i", channels,
NULL);
......@@ -306,7 +306,7 @@ si_convert_activate_execute_step (WpSessionItem * item,
wp_spa_pod_new_object (
"Spa:Pod:Object:Param:PortConfig", "PortConfig",
"direction", "I", pw_direction_reverse (self->direction),
"mode", "I", SPA_PARAM_PORT_CONFIG_MODE_dsp,
"mode", "K", "dsp",
"format", "P", format,
NULL));
......@@ -315,7 +315,7 @@ si_convert_activate_execute_step (WpSessionItem * item,
wp_spa_pod_new_object (
"Spa:Pod:Object:Param:PortConfig", "PortConfig",
"direction", "I", self->direction,
"mode", "I", SPA_PARAM_PORT_CONFIG_MODE_dsp,
"mode", "K", "dsp",
"control", "b", self->control_port,
"format", "P", format,
NULL));
......
......@@ -952,7 +952,7 @@ test_spa_pod_unique_owner (void)
/* Create an object */
WpSpaPod *pod = wp_spa_pod_new_object (
"Spa:Pod:Object:Param:PropInfo", "PropInfo",
"id", "I", 1,
"id", "K", "unknown",
"name", "s", "prop-info-name",
NULL);
g_assert_nonnull (pod);
......@@ -1019,9 +1019,9 @@ test_spa_pod_port_config (void)
g_autoptr (WpSpaPodBuilder) builder = wp_spa_pod_builder_new_object (
"Spa:Pod:Object:Param:Format", "Format");
wp_spa_pod_builder_add (builder,
"mediaType", "I", 0,
"mediaSubtype", "I", 0,
"format", "I", 0,
"mediaType", "K", "audio",
"mediaSubtype", "K", "raw",
"format", "K", "S16LE",
"rate", "i", rate,
"channels", "i", channels,
NULL);
......@@ -1037,8 +1037,8 @@ test_spa_pod_port_config (void)
/* Build the port config to make sure the types exist */
g_autoptr (WpSpaPod) pod = wp_spa_pod_new_object (
"Spa:Pod:Object:Param:PortConfig", "PortConfig",
"direction", "I", 0,
"mode", "I", 0,
"direction", "K", "Input",
"mode", "K", "dsp",
"monitor", "b", FALSE,
"control", "b", FALSE,
"format", "P", format,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment