pw-dump: improve choice values

Place range and step values on a single line
This commit is contained in:
Wim Taymans 2020-12-18 17:49:46 +01:00
parent f7a7feea4e
commit abe12cf790

View file

@ -359,35 +359,45 @@ static void put_pod_value(struct data *d, const char *key, const struct spa_type
static const char *step_labels[] = { "default", "min", "max", "step", NULL };
static const char *enum_labels[] = { "default", "alt%u" };
static const char *flags_labels[] = { "default", "flag%u" };
const char **labels, *label;
char buffer[64];
int max_labels, flags = 0;
put_begin(d, NULL, "{", 0);
SPA_POD_CHOICE_BODY_FOREACH(b, size, p) {
const char *label;
switch (b->type) {
case SPA_CHOICE_Range:
label = range_labels[SPA_CLAMP(index, 0, 3)];
labels = range_labels;
max_labels = 3;
flags |= STATE_SIMPLE;
break;
case SPA_CHOICE_Step:
label = step_labels[SPA_CLAMP(index, 0, 4)];
labels = step_labels;
max_labels = 4;
flags |= STATE_SIMPLE;
break;
case SPA_CHOICE_Enum:
label = enum_labels[SPA_CLAMP(index, 0, 1)];
labels = enum_labels;
max_labels = 1;
break;
case SPA_CHOICE_Flags:
label = flags_labels[SPA_CLAMP(index, 0, 1)];
labels = flags_labels;
max_labels = 1;
break;
default:
label = NULL;
labels = NULL;
break;
}
if (label == NULL)
if (labels == NULL)
break;
put_begin(d, NULL, "{", flags);
SPA_POD_CHOICE_BODY_FOREACH(b, size, p) {
if ((label = labels[SPA_CLAMP(index, 0, max_labels)]) == NULL)
break;
snprintf(buffer, sizeof(buffer), label, index);
put_pod_value(d, buffer, info, b->child.type, p, b->child.size);
index++;
}
put_end(d, "}", 0);
put_end(d, "}", flags);
}
break;
}