mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
improve config parsing
Use get_string to get object keys in a more generic way.
This commit is contained in:
parent
fc68e901e5
commit
0be851739f
5 changed files with 35 additions and 40 deletions
|
|
@ -204,9 +204,8 @@ static char *serialize_props(struct device *dev, const struct spa_pod *param)
|
|||
static int restore_route(struct device *dev, const char *val, uint32_t index, uint32_t device_id)
|
||||
{
|
||||
struct spa_json it[3];
|
||||
char buf[1024];
|
||||
char buf[1024], key[128];
|
||||
const char *value;
|
||||
int len;
|
||||
struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buf, sizeof(buf));
|
||||
struct spa_pod_frame f[2];
|
||||
struct spa_pod *param;
|
||||
|
|
@ -226,22 +225,22 @@ static int restore_route(struct device *dev, const char *val, uint32_t index, ui
|
|||
spa_pod_builder_push_object(&b, &f[1],
|
||||
SPA_TYPE_OBJECT_Props, SPA_PARAM_Route);
|
||||
|
||||
while ((len = spa_json_next(&it[1], &value)) > 0) {
|
||||
if (strncmp(value, "\"volume\"", len) == 0) {
|
||||
while (spa_json_get_string(&it[1], key, sizeof(key)-1) > 0) {
|
||||
if (strcmp(key, "volume") == 0) {
|
||||
float vol;
|
||||
if (spa_json_get_float(&it[1], &vol) <= 0)
|
||||
continue;
|
||||
spa_pod_builder_prop(&b, SPA_PROP_volume, 0);
|
||||
spa_pod_builder_float(&b, vol);
|
||||
}
|
||||
else if (strncmp(value, "\"mute\"", len) == 0) {
|
||||
else if (strcmp(key, "mute") == 0) {
|
||||
bool mute;
|
||||
if (spa_json_get_bool(&it[1], &mute) <= 0)
|
||||
continue;
|
||||
spa_pod_builder_prop(&b, SPA_PROP_mute, 0);
|
||||
spa_pod_builder_bool(&b, mute);
|
||||
}
|
||||
else if (strncmp(value, "\"volumes\"", len) == 0) {
|
||||
else if (strcmp(key, "volumes") == 0) {
|
||||
uint32_t n_vols;
|
||||
float vols[SPA_AUDIO_MAX_CHANNELS];
|
||||
|
||||
|
|
@ -259,7 +258,7 @@ static int restore_route(struct device *dev, const char *val, uint32_t index, ui
|
|||
spa_pod_builder_array(&b, sizeof(float), SPA_TYPE_Float,
|
||||
n_vols, vols);
|
||||
}
|
||||
else if (strncmp(value, "\"channels\"", len) == 0) {
|
||||
else if (strcmp(key, "channels") == 0) {
|
||||
uint32_t n_ch;
|
||||
uint32_t map[SPA_AUDIO_MAX_CHANNELS];
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue