mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
spa: add spa_json_begin_array/object and relaxed versions
Add spa_json_begin_array/object to replace spa_json_init+spa_json_begin_array/object This function is better because it does not waste a useless spa_json structure as an iterator. The relaxed versions also error out when the container is mismatched because parsing a mismatched container is not going to give any results anyway.
This commit is contained in:
parent
feccb882b6
commit
cd81b5f39a
51 changed files with 401 additions and 452 deletions
|
|
@ -1021,15 +1021,14 @@ static const struct global_info node_info = {
|
|||
/** metadata */
|
||||
static int json_object_find(const char *obj, const char *key, char *value, size_t len)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
const char *v;
|
||||
char k[128];
|
||||
|
||||
spa_json_init(&it[0], obj, strlen(obj));
|
||||
if (spa_json_enter_object(&it[0], &it[1]) <= 0)
|
||||
if (spa_json_begin_object(&it[0], obj, strlen(obj)) <= 0)
|
||||
return -EINVAL;
|
||||
|
||||
while (spa_json_get_string(&it[1], k, sizeof(k)) > 0) {
|
||||
while (spa_json_get_string(&it[0], k, sizeof(k)) > 0) {
|
||||
if (spa_streq(k, key)) {
|
||||
if (spa_json_get_string(&it[1], value, len) <= 0)
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -3458,21 +3458,20 @@ static jack_uuid_t client_make_uuid(uint32_t id, bool monitor)
|
|||
|
||||
static int json_object_find(const char *obj, const char *key, char *value, size_t len)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
const char *v;
|
||||
char k[128];
|
||||
|
||||
spa_json_init(&it[0], obj, strlen(obj));
|
||||
if (spa_json_enter_object(&it[0], &it[1]) <= 0)
|
||||
if (spa_json_begin_object(&it[0], obj, strlen(obj)) <= 0)
|
||||
return -EINVAL;
|
||||
|
||||
while (spa_json_get_string(&it[1], k, sizeof(k)) > 0) {
|
||||
while (spa_json_get_string(&it[0], k, sizeof(k)) > 0) {
|
||||
if (spa_streq(k, key)) {
|
||||
if (spa_json_get_string(&it[1], value, len) <= 0)
|
||||
if (spa_json_get_string(&it[0], value, len) <= 0)
|
||||
continue;
|
||||
return 0;
|
||||
} else {
|
||||
if (spa_json_next(&it[1], &v) <= 0)
|
||||
if (spa_json_next(&it[0], &v) <= 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -362,23 +362,37 @@ static inline int spa_json_begin(struct spa_json * iter, const char *data, size_
|
|||
return spa_json_next(iter, val);
|
||||
}
|
||||
|
||||
static inline int spa_json_is_container(const char *val, int len)
|
||||
{
|
||||
return len > 0 && (*val == '{' || *val == '[');
|
||||
}
|
||||
|
||||
static inline int spa_json_enter_container(struct spa_json *iter, struct spa_json *sub, char type)
|
||||
{
|
||||
const char *value;
|
||||
int len;
|
||||
if ((len = spa_json_next(iter, &value)) <= 0)
|
||||
return len;
|
||||
if (!spa_json_is_container(value, len))
|
||||
return -EPROTO;
|
||||
if (*value != type)
|
||||
return -1;
|
||||
return -EINVAL;
|
||||
spa_json_enter(iter, sub);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline int spa_json_is_container(const char *val, int len)
|
||||
static inline int spa_json_begin_container(struct spa_json * iter,
|
||||
const char *data, size_t size, char type, bool relax)
|
||||
{
|
||||
return len > 0 && (*val == '{' || *val == '[');
|
||||
int res;
|
||||
spa_json_init(iter, data, size);
|
||||
res = spa_json_enter_container(iter, iter, type);
|
||||
if (res == -EPROTO && relax)
|
||||
spa_json_init(iter, data, size);
|
||||
else if (res <= 0)
|
||||
return res;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return length of container at current position, starting at \a value.
|
||||
*
|
||||
|
|
@ -405,6 +419,14 @@ static inline int spa_json_enter_object(struct spa_json *iter, struct spa_json *
|
|||
{
|
||||
return spa_json_enter_container(iter, sub, '{');
|
||||
}
|
||||
static inline int spa_json_begin_object_relax(struct spa_json * iter, const char *data, size_t size)
|
||||
{
|
||||
return spa_json_begin_container(iter, data, size, '{', true);
|
||||
}
|
||||
static inline int spa_json_begin_object(struct spa_json * iter, const char *data, size_t size)
|
||||
{
|
||||
return spa_json_begin_container(iter, data, size, '{', false);
|
||||
}
|
||||
|
||||
/* array */
|
||||
static inline bool spa_json_is_array(const char *val, int len)
|
||||
|
|
@ -415,6 +437,14 @@ static inline int spa_json_enter_array(struct spa_json *iter, struct spa_json *s
|
|||
{
|
||||
return spa_json_enter_container(iter, sub, '[');
|
||||
}
|
||||
static inline int spa_json_begin_array_relax(struct spa_json * iter, const char *data, size_t size)
|
||||
{
|
||||
return spa_json_begin_container(iter, data, size, '[', true);
|
||||
}
|
||||
static inline int spa_json_begin_array(struct spa_json * iter, const char *data, size_t size)
|
||||
{
|
||||
return spa_json_begin_container(iter, data, size, '[', false);
|
||||
}
|
||||
|
||||
/* null */
|
||||
static inline bool spa_json_is_null(const char *val, int len)
|
||||
|
|
|
|||
|
|
@ -70,10 +70,9 @@ static int parse_mic_geometry(struct impl_data *impl, const char *mic_geometry,
|
|||
{
|
||||
int res;
|
||||
size_t i;
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
|
||||
spa_json_init(&it[0], mic_geometry, strlen(mic_geometry));
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0) {
|
||||
if (spa_json_begin_array(&it[0], mic_geometry, strlen(mic_geometry)) <= 0) {
|
||||
spa_log_error(impl->log, "Error: webrtc.mic-geometry expects an array");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
|
@ -81,7 +80,7 @@ static int parse_mic_geometry(struct impl_data *impl, const char *mic_geometry,
|
|||
for (i = 0; i < geometry.size(); i++) {
|
||||
float f[3];
|
||||
|
||||
if ((res = parse_point(&it[1], f)) < 0) {
|
||||
if ((res = parse_point(&it[0], f)) < 0) {
|
||||
spa_log_error(impl->log, "Error: can't parse webrtc.mic-geometry points: %d", res);
|
||||
return res;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -452,17 +452,16 @@ static int add_pro_profile(pa_card *impl, uint32_t index)
|
|||
|
||||
static bool contains_string(const char *arr, const char *str)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char v[256];
|
||||
|
||||
if (arr == NULL || str == NULL)
|
||||
return false;
|
||||
|
||||
spa_json_init(&it[0], arr, strlen(arr));
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], arr, strlen(arr));
|
||||
if (spa_json_begin_array_relax(&it[0], arr, strlen(arr)) <= 0)
|
||||
return false;
|
||||
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0) {
|
||||
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0) {
|
||||
if (spa_streq(v, str))
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -968,16 +968,15 @@ int spa_alsa_init(struct state *state, const struct spa_dict *info)
|
|||
} else if (spa_streq(k, "clock.quantum-limit")) {
|
||||
spa_atou32(s, &state->quantum_limit, 0);
|
||||
} else if (spa_streq(k, SPA_KEY_API_ALSA_BIND_CTLS)) {
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char v[256];
|
||||
unsigned int i = 0;
|
||||
|
||||
/* Read a list of ALSA control names to bind as params */
|
||||
spa_json_init(&it[0], s, strlen(s));
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], s, strlen(s));
|
||||
if (spa_json_begin_array_relax(&it[0], s, strlen(s)) <= 0)
|
||||
continue;
|
||||
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 &&
|
||||
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
|
||||
i < SPA_N_ELEMENTS(state->bound_ctls)) {
|
||||
snprintf(state->bound_ctls[i].name,
|
||||
sizeof(state->bound_ctls[i].name), "%s", v);
|
||||
|
|
|
|||
|
|
@ -325,15 +325,14 @@ static inline uint32_t spa_alsa_channel_from_name(const char *name)
|
|||
|
||||
static inline void spa_alsa_parse_position(struct channel_map *map, const char *val, size_t len)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char v[256];
|
||||
|
||||
spa_json_init(&it[0], val, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], val, len);
|
||||
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
|
||||
return;
|
||||
|
||||
map->channels = 0;
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 &&
|
||||
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
|
||||
map->channels < SPA_AUDIO_MAX_CHANNELS) {
|
||||
map->pos[map->channels++] = spa_alsa_channel_from_name(v);
|
||||
}
|
||||
|
|
@ -341,16 +340,15 @@ static inline void spa_alsa_parse_position(struct channel_map *map, const char *
|
|||
|
||||
static inline uint32_t spa_alsa_parse_rates(uint32_t *rates, uint32_t max, const char *val, size_t len)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char v[256];
|
||||
uint32_t count;
|
||||
|
||||
spa_json_init(&it[0], val, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], val, len);
|
||||
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
|
||||
return 0;
|
||||
|
||||
count = 0;
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && count < max)
|
||||
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 && count < max)
|
||||
rates[count++] = atoi(v);
|
||||
return count;
|
||||
}
|
||||
|
|
@ -367,15 +365,14 @@ static inline uint32_t spa_alsa_iec958_codec_from_name(const char *name)
|
|||
|
||||
static inline void spa_alsa_parse_iec958_codecs(uint64_t *codecs, const char *val, size_t len)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char v[256];
|
||||
|
||||
spa_json_init(&it[0], val, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], val, len);
|
||||
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
|
||||
return;
|
||||
|
||||
*codecs = 0;
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0)
|
||||
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0)
|
||||
*codecs |= 1ULL << spa_alsa_iec958_codec_from_name(v);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1830,15 +1830,14 @@ static int do_auto_port_config(struct impl *this, const char *str)
|
|||
bool have_format = false, monitor = false, control = false;
|
||||
struct spa_audio_info format = { 0, };
|
||||
enum spa_param_port_config_mode mode = SPA_PARAM_PORT_CONFIG_MODE_none;
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char key[1024], val[256];
|
||||
|
||||
spa_json_init(&it[0], str, strlen(str));
|
||||
if (spa_json_enter_object(&it[0], &it[1]) <= 0)
|
||||
if (spa_json_begin_object(&it[0], str, strlen(str)) <= 0)
|
||||
return -EINVAL;
|
||||
|
||||
while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) {
|
||||
if (spa_json_get_string(&it[1], val, sizeof(val)) <= 0)
|
||||
while (spa_json_get_string(&it[0], key, sizeof(key)) > 0) {
|
||||
if (spa_json_get_string(&it[0], val, sizeof(val)) <= 0)
|
||||
break;
|
||||
|
||||
if (spa_streq(key, "mode")) {
|
||||
|
|
|
|||
|
|
@ -3425,15 +3425,14 @@ static uint32_t channel_from_name(const char *name)
|
|||
|
||||
static inline uint32_t parse_position(uint32_t *pos, const char *val, size_t len)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char v[256];
|
||||
uint32_t i = 0;
|
||||
|
||||
spa_json_init(&it[0], val, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], val, len);
|
||||
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
|
||||
return 0;
|
||||
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 &&
|
||||
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
|
||||
i < SPA_AUDIO_MAX_CHANNELS) {
|
||||
pos[i++] = channel_from_name(v);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -286,15 +286,14 @@ static inline uint32_t spa_avb_channel_from_name(const char *name)
|
|||
|
||||
static inline void spa_avb_parse_position(struct channel_map *map, const char *val, size_t len)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char v[256];
|
||||
|
||||
spa_json_init(&it[0], val, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], val, len);
|
||||
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
|
||||
return;
|
||||
|
||||
map->channels = 0;
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 &&
|
||||
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
|
||||
map->channels < SPA_AUDIO_MAX_CHANNELS) {
|
||||
map->pos[map->channels++] = spa_avb_channel_from_name(v);
|
||||
}
|
||||
|
|
@ -302,16 +301,15 @@ static inline void spa_avb_parse_position(struct channel_map *map, const char *v
|
|||
|
||||
static inline uint32_t spa_avb_parse_rates(uint32_t *rates, uint32_t max, const char *val, size_t len)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char v[256];
|
||||
uint32_t count;
|
||||
|
||||
spa_json_init(&it[0], val, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], val, len);
|
||||
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
|
||||
return 0;
|
||||
|
||||
count = 0;
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 && count < max)
|
||||
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 && count < max)
|
||||
rates[count++] = atoi(v);
|
||||
return count;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6075,13 +6075,11 @@ impl_get_size(const struct spa_handle_factory *factory,
|
|||
|
||||
int spa_bt_profiles_from_json_array(const char *str)
|
||||
{
|
||||
struct spa_json it, it_array;
|
||||
struct spa_json it_array;
|
||||
char role_name[256];
|
||||
enum spa_bt_profile profiles = SPA_BT_PROFILE_NULL;
|
||||
|
||||
spa_json_init(&it, str, strlen(str));
|
||||
|
||||
if (spa_json_enter_array(&it, &it_array) <= 0)
|
||||
if (spa_json_begin_array(&it_array, str, strlen(str)) <= 0)
|
||||
return -EINVAL;
|
||||
|
||||
while (spa_json_get_string(&it_array, role_name, sizeof(role_name)) > 0) {
|
||||
|
|
@ -6144,7 +6142,7 @@ static void parse_broadcast_source_config(struct spa_bt_monitor *monitor, const
|
|||
char bcode[BROADCAST_CODE_LEN + 3];
|
||||
int cursor;
|
||||
int big_id = 0;
|
||||
struct spa_json it[4], it_array[4];
|
||||
struct spa_json it[3], it_array[4];
|
||||
struct spa_list big_list = SPA_LIST_INIT(&big_list);
|
||||
struct spa_error_location loc;
|
||||
struct spa_bt_big *big;
|
||||
|
|
@ -6153,14 +6151,12 @@ static void parse_broadcast_source_config(struct spa_bt_monitor *monitor, const
|
|||
if (!(info && (str = spa_dict_lookup(info, "bluez5.bcast_source.config"))))
|
||||
return;
|
||||
|
||||
spa_json_init(&it[0], str, strlen(str));
|
||||
|
||||
/* Verify is an array of BIGS */
|
||||
if (spa_json_enter_array(&it[0], &it_array[0]) <= 0)
|
||||
if (spa_json_begin_array(&it_array[0], str, strlen(str)) <= 0)
|
||||
goto parse_failed;
|
||||
|
||||
/* Iterate on all BIG objects */
|
||||
while (spa_json_enter_object(&it_array[0], &it[1]) > 0) {
|
||||
while (spa_json_enter_object(&it_array[0], &it[0]) > 0) {
|
||||
struct spa_bt_big *big_entry = calloc(1, sizeof(struct spa_bt_big));
|
||||
|
||||
if (!big_entry)
|
||||
|
|
@ -6171,22 +6167,22 @@ static void parse_broadcast_source_config(struct spa_bt_monitor *monitor, const
|
|||
spa_list_append(&big_list, &big_entry->link);
|
||||
|
||||
/* Iterate on all BIG values */
|
||||
while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) {
|
||||
while (spa_json_get_string(&it[0], key, sizeof(key)) > 0) {
|
||||
if (spa_streq(key, "broadcast_code")) {
|
||||
if (spa_json_get_string(&it[1], bcode, sizeof(bcode)) <= 0)
|
||||
if (spa_json_get_string(&it[0], bcode, sizeof(bcode)) <= 0)
|
||||
goto parse_failed;
|
||||
if (strlen(bcode) > BROADCAST_CODE_LEN)
|
||||
goto parse_failed;
|
||||
memcpy(big_entry->broadcast_code, bcode, strlen(bcode));
|
||||
spa_log_debug(monitor->log, "big_entry->broadcast_code %s", big_entry->broadcast_code);
|
||||
} else if (spa_streq(key, "encryption")) {
|
||||
if (spa_json_get_bool(&it[1], &big_entry->encryption) <= 0)
|
||||
if (spa_json_get_bool(&it[0], &big_entry->encryption) <= 0)
|
||||
goto parse_failed;
|
||||
spa_log_debug(monitor->log, "big_entry->encryption %d", big_entry->encryption);
|
||||
} else if (spa_streq(key, "bis")) {
|
||||
if (spa_json_enter_array(&it[1], &it_array[1]) <= 0)
|
||||
if (spa_json_enter_array(&it[0], &it_array[1]) <= 0)
|
||||
goto parse_failed;
|
||||
while (spa_json_enter_object(&it_array[1], &it[2]) > 0) {
|
||||
while (spa_json_enter_object(&it_array[1], &it[1]) > 0) {
|
||||
/* Iterate on all BIS values */
|
||||
struct spa_bt_bis *bis_entry = calloc(1, sizeof(struct spa_bt_bis));
|
||||
|
||||
|
|
@ -6196,19 +6192,19 @@ static void parse_broadcast_source_config(struct spa_bt_monitor *monitor, const
|
|||
spa_list_init(&bis_entry->metadata_list);
|
||||
spa_list_append(&big_entry->bis_list, &bis_entry->link);
|
||||
|
||||
while (spa_json_get_string(&it[2], bis_key, sizeof(bis_key)) > 0) {
|
||||
while (spa_json_get_string(&it[1], bis_key, sizeof(bis_key)) > 0) {
|
||||
if (spa_streq(bis_key, "qos_preset")) {
|
||||
if (spa_json_get_string(&it[2], bis_entry->qos_preset, sizeof(bis_entry->qos_preset)) <= 0)
|
||||
if (spa_json_get_string(&it[1], bis_entry->qos_preset, sizeof(bis_entry->qos_preset)) <= 0)
|
||||
goto parse_failed;
|
||||
spa_log_debug(monitor->log, "bis_entry->qos_preset %s", bis_entry->qos_preset);
|
||||
} else if (spa_streq(bis_key, "audio_channel_allocation")) {
|
||||
if (spa_json_get_int(&it[2], &bis_entry->channel_allocation) <= 0)
|
||||
if (spa_json_get_int(&it[1], &bis_entry->channel_allocation) <= 0)
|
||||
goto parse_failed;
|
||||
spa_log_debug(monitor->log, "bis_entry->channel_allocation %d", bis_entry->channel_allocation);
|
||||
} else if (spa_streq(bis_key, "metadata")) {
|
||||
if (spa_json_enter_array(&it[2], &it_array[2]) <= 0)
|
||||
if (spa_json_enter_array(&it[1], &it_array[2]) <= 0)
|
||||
goto parse_failed;
|
||||
while (spa_json_enter_object(&it_array[2], &it[3]) > 0) {
|
||||
while (spa_json_enter_object(&it_array[2], &it[2]) > 0) {
|
||||
struct spa_bt_metadata *metadata_entry = calloc(1, sizeof(struct spa_bt_metadata));
|
||||
|
||||
if (!metadata_entry)
|
||||
|
|
@ -6216,13 +6212,13 @@ static void parse_broadcast_source_config(struct spa_bt_monitor *monitor, const
|
|||
|
||||
spa_list_append(&bis_entry->metadata_list, &metadata_entry->link);
|
||||
|
||||
while (spa_json_get_string(&it[3], qos_key, sizeof(qos_key)) > 0) {
|
||||
while (spa_json_get_string(&it[2], qos_key, sizeof(qos_key)) > 0) {
|
||||
if (spa_streq(qos_key, "type")) {
|
||||
if (spa_json_get_int(&it[3], &metadata_entry->type) <= 0)
|
||||
if (spa_json_get_int(&it[2], &metadata_entry->type) <= 0)
|
||||
goto parse_failed;
|
||||
spa_log_debug(monitor->log, "metadata_entry->type %d", metadata_entry->type);
|
||||
} else if (spa_streq(qos_key, "value")) {
|
||||
if (spa_json_enter_array(&it[3], &it_array[3]) <= 0)
|
||||
if (spa_json_enter_array(&it[2], &it_array[3]) <= 0)
|
||||
goto parse_failed;
|
||||
for (cursor = 0; cursor < METADATA_MAX_LEN - 1; cursor++) {
|
||||
int temp_val = 0;
|
||||
|
|
@ -6254,7 +6250,7 @@ errno_failed:
|
|||
|
||||
parse_failed:
|
||||
str = spa_dict_lookup(info, "bluez5.bcast_source.config");
|
||||
if (spa_json_get_error(&it[0], str, &loc)) {
|
||||
if (spa_json_get_error(&it_array[0], str, &loc)) {
|
||||
spa_debug_log_error_location(monitor->log, SPA_LOG_LEVEL_WARN,
|
||||
&loc, "malformed bluez5.bcast_source.config: %s", loc.reason);
|
||||
} else {
|
||||
|
|
@ -6272,7 +6268,7 @@ static int parse_codec_array(struct spa_bt_monitor *this, const struct spa_dict
|
|||
const struct media_codec * const * const media_codecs = this->media_codecs;
|
||||
const char *str;
|
||||
struct spa_dict_item *codecs;
|
||||
struct spa_json it, it_array;
|
||||
struct spa_json it_array;
|
||||
char codec_name[256];
|
||||
size_t num_codecs;
|
||||
int i;
|
||||
|
|
@ -6290,9 +6286,7 @@ static int parse_codec_array(struct spa_bt_monitor *this, const struct spa_dict
|
|||
if (info == NULL || (str = spa_dict_lookup(info, "bluez5.codecs")) == NULL)
|
||||
goto fallback;
|
||||
|
||||
spa_json_init(&it, str, strlen(str));
|
||||
|
||||
if (spa_json_enter_array(&it, &it_array) <= 0) {
|
||||
if (spa_json_begin_array(&it_array, str, strlen(str)) <= 0) {
|
||||
spa_log_error(this->log, "property bluez5.codecs '%s' is not an array", str);
|
||||
goto fallback;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -881,15 +881,14 @@ static uint32_t channel_from_name(const char *name)
|
|||
|
||||
static inline void parse_position(struct impl *this, const char *val, size_t len)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char v[256];
|
||||
|
||||
spa_json_init(&it[0], val, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], val, len);
|
||||
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
|
||||
return;
|
||||
|
||||
this->props.channels = 0;
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 &&
|
||||
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
|
||||
this->props.channels < SPA_AUDIO_MAX_CHANNELS) {
|
||||
this->props.pos[this->props.channels++] = channel_from_name(v);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -274,20 +274,18 @@ get_server_name(const struct spa_dict *props)
|
|||
|
||||
static int parse_socket_args(struct impl *impl, const char *str)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char socket[PATH_MAX];
|
||||
|
||||
spa_json_init(&it[0], str, strlen(str));
|
||||
|
||||
if (spa_json_enter_object(&it[0], &it[1]) <= 0)
|
||||
if (spa_json_begin_object(&it[0], str, strlen(str)) <= 0)
|
||||
return -EINVAL;
|
||||
|
||||
while (spa_json_get_string(&it[1], socket, sizeof(socket)) > 0) {
|
||||
while (spa_json_get_string(&it[0], socket, sizeof(socket)) > 0) {
|
||||
char value[256];
|
||||
const char *val;
|
||||
int len;
|
||||
|
||||
if ((len = spa_json_next(&it[1], &val)) <= 0)
|
||||
if ((len = spa_json_next(&it[0], &val)) <= 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (spa_json_parse_stringn(val, len, value, sizeof(value)) <= 0)
|
||||
|
|
|
|||
|
|
@ -283,20 +283,19 @@ static int do_help(struct adp *adp, const char *args, FILE *out)
|
|||
|
||||
static int do_discover(struct adp *adp, const char *args, FILE *out)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char key[128];
|
||||
uint64_t entity_id = 0ULL;
|
||||
|
||||
spa_json_init(&it[0], args, strlen(args));
|
||||
if (spa_json_enter_object(&it[0], &it[1]) <= 0)
|
||||
if (spa_json_begin_object(&it[0], args, strlen(args)) <= 0)
|
||||
return -EINVAL;
|
||||
|
||||
while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) {
|
||||
while (spa_json_get_string(&it[0], key, sizeof(key)) > 0) {
|
||||
int len;
|
||||
const char *value;
|
||||
uint64_t id_val;
|
||||
|
||||
if ((len = spa_json_next(&it[1], &value)) <= 0)
|
||||
if ((len = spa_json_next(&it[0], &value)) <= 0)
|
||||
break;
|
||||
|
||||
if (spa_json_is_null(value, len))
|
||||
|
|
|
|||
|
|
@ -253,7 +253,7 @@ static int load_state(struct maap *maap)
|
|||
{
|
||||
const char *str;
|
||||
char key[512];
|
||||
struct spa_json it[3];
|
||||
struct spa_json it[2];
|
||||
bool have_offset = false;
|
||||
int count = 0, offset = 0;
|
||||
|
||||
|
|
@ -263,18 +263,17 @@ static int load_state(struct maap *maap)
|
|||
if ((str = pw_properties_get(maap->props, "maap.addresses")) == NULL)
|
||||
return 0;
|
||||
|
||||
spa_json_init(&it[0], str, strlen(str));
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
if (spa_json_begin_array(&it[0], str, strlen(str)) <= 0)
|
||||
return 0;
|
||||
|
||||
if (spa_json_enter_object(&it[1], &it[2]) <= 0)
|
||||
if (spa_json_enter_object(&it[0], &it[1]) <= 0)
|
||||
return 0;
|
||||
|
||||
while (spa_json_get_string(&it[2], key, sizeof(key)) > 0) {
|
||||
while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) {
|
||||
const char *val;
|
||||
int len;
|
||||
|
||||
if ((len = spa_json_next(&it[2], &val)) <= 0)
|
||||
if ((len = spa_json_next(&it[1], &val)) <= 0)
|
||||
break;
|
||||
|
||||
if (spa_streq(key, "start")) {
|
||||
|
|
|
|||
|
|
@ -330,15 +330,14 @@ static uint32_t channel_from_name(const char *name)
|
|||
|
||||
static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char v[256];
|
||||
|
||||
spa_json_init(&it[0], val, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], val, len);
|
||||
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
|
||||
return;
|
||||
|
||||
info->channels = 0;
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 &&
|
||||
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
|
||||
info->channels < SPA_AUDIO_MAX_CHANNELS) {
|
||||
info->position[info->channels++] = channel_from_name(v);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1201,15 +1201,14 @@ static uint32_t channel_from_name(const char *name)
|
|||
|
||||
static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char v[256];
|
||||
|
||||
spa_json_init(&it[0], val, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], val, len);
|
||||
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
|
||||
return;
|
||||
|
||||
info->channels = 0;
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 &&
|
||||
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
|
||||
info->channels < SPA_AUDIO_MAX_CHANNELS) {
|
||||
info->position[info->channels++] = channel_from_name(v);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -457,15 +457,14 @@ static uint32_t channel_from_name(const char *name)
|
|||
|
||||
static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char v[256];
|
||||
|
||||
spa_json_init(&it[0], val, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], val, len);
|
||||
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
|
||||
return;
|
||||
|
||||
info->channels = 0;
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 &&
|
||||
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
|
||||
info->channels < SPA_AUDIO_MAX_CHANNELS) {
|
||||
info->position[info->channels++] = channel_from_name(v);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -292,15 +292,14 @@ static uint32_t channel_from_name(const char *name)
|
|||
|
||||
static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char v[256];
|
||||
|
||||
spa_json_init(&it[0], val, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], val, len);
|
||||
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
|
||||
return;
|
||||
|
||||
info->channels = 0;
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 &&
|
||||
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
|
||||
info->channels < SPA_AUDIO_MAX_CHANNELS) {
|
||||
info->position[info->channels++] = channel_from_name(v);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -298,15 +298,14 @@ static uint32_t channel_from_name(const char *name)
|
|||
|
||||
static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char v[256];
|
||||
|
||||
spa_json_init(&it[0], val, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], val, len);
|
||||
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
|
||||
return;
|
||||
|
||||
info->channels = 0;
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 &&
|
||||
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
|
||||
info->channels < SPA_AUDIO_MAX_CHANNELS) {
|
||||
info->position[info->channels++] = channel_from_name(v);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1416,15 +1416,14 @@ static uint32_t channel_from_name(const char *name)
|
|||
|
||||
static void parse_devices(struct impl *impl, const char *val, size_t len)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char v[FFADO_MAX_SPECSTRING_LENGTH];
|
||||
|
||||
spa_json_init(&it[0], val, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], val, len);
|
||||
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
|
||||
return;
|
||||
|
||||
impl->n_devices = 0;
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 &&
|
||||
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
|
||||
impl->n_devices < FFADO_MAX_SPECSTRINGS) {
|
||||
impl->devices[impl->n_devices++] = strdup(v);
|
||||
}
|
||||
|
|
@ -1435,12 +1434,11 @@ static void parse_position(struct spa_audio_info_raw *info, const char *val, siz
|
|||
struct spa_json it[2];
|
||||
char v[256];
|
||||
|
||||
spa_json_init(&it[0], val, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], val, len);
|
||||
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
|
||||
return;
|
||||
|
||||
info->channels = 0;
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 &&
|
||||
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
|
||||
info->channels < SPA_AUDIO_MAX_CHANNELS) {
|
||||
info->position[info->channels++] = channel_from_name(v);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2714,7 +2714,7 @@ error:
|
|||
*/
|
||||
static int load_graph(struct graph *graph, struct pw_properties *props)
|
||||
{
|
||||
struct spa_json it[3];
|
||||
struct spa_json it[2];
|
||||
struct spa_json inputs, outputs, *pinputs = NULL, *poutputs = NULL;
|
||||
struct spa_json cvolumes, pvolumes, *pcvolumes = NULL, *ppvolumes = NULL;
|
||||
struct spa_json nodes, *pnodes = NULL, links, *plinks = NULL;
|
||||
|
|
@ -2730,57 +2730,56 @@ static int load_graph(struct graph *graph, struct pw_properties *props)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
spa_json_init(&it[0], json, strlen(json));
|
||||
if (spa_json_enter_object(&it[0], &it[1]) <= 0) {
|
||||
if (spa_json_begin_object(&it[0], json, strlen(json)) <= 0) {
|
||||
pw_log_error("filter.graph must be an object");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) {
|
||||
while (spa_json_get_string(&it[0], key, sizeof(key)) > 0) {
|
||||
if (spa_streq("nodes", key)) {
|
||||
if (spa_json_enter_array(&it[1], &nodes) <= 0) {
|
||||
if (spa_json_enter_array(&it[0], &nodes) <= 0) {
|
||||
pw_log_error("nodes expects an array");
|
||||
return -EINVAL;
|
||||
}
|
||||
pnodes = &nodes;
|
||||
}
|
||||
else if (spa_streq("links", key)) {
|
||||
if (spa_json_enter_array(&it[1], &links) <= 0) {
|
||||
if (spa_json_enter_array(&it[0], &links) <= 0) {
|
||||
pw_log_error("links expects an array");
|
||||
return -EINVAL;
|
||||
}
|
||||
plinks = &links;
|
||||
}
|
||||
else if (spa_streq("inputs", key)) {
|
||||
if (spa_json_enter_array(&it[1], &inputs) <= 0) {
|
||||
if (spa_json_enter_array(&it[0], &inputs) <= 0) {
|
||||
pw_log_error("inputs expects an array");
|
||||
return -EINVAL;
|
||||
}
|
||||
pinputs = &inputs;
|
||||
}
|
||||
else if (spa_streq("outputs", key)) {
|
||||
if (spa_json_enter_array(&it[1], &outputs) <= 0) {
|
||||
if (spa_json_enter_array(&it[0], &outputs) <= 0) {
|
||||
pw_log_error("outputs expects an array");
|
||||
return -EINVAL;
|
||||
}
|
||||
poutputs = &outputs;
|
||||
}
|
||||
else if (spa_streq("capture.volumes", key)) {
|
||||
if (spa_json_enter_array(&it[1], &cvolumes) <= 0) {
|
||||
if (spa_json_enter_array(&it[0], &cvolumes) <= 0) {
|
||||
pw_log_error("capture.volumes expects an array");
|
||||
return -EINVAL;
|
||||
}
|
||||
pcvolumes = &cvolumes;
|
||||
}
|
||||
else if (spa_streq("playback.volumes", key)) {
|
||||
if (spa_json_enter_array(&it[1], &pvolumes) <= 0) {
|
||||
if (spa_json_enter_array(&it[0], &pvolumes) <= 0) {
|
||||
pw_log_error("playback.volumes expects an array");
|
||||
return -EINVAL;
|
||||
}
|
||||
ppvolumes = &pvolumes;
|
||||
} else {
|
||||
pw_log_warn("unexpected graph key '%s'", key);
|
||||
if (spa_json_next(&it[1], &val) < 0)
|
||||
if (spa_json_next(&it[0], &val) < 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -2788,25 +2787,25 @@ static int load_graph(struct graph *graph, struct pw_properties *props)
|
|||
pw_log_error("filter.graph is missing a nodes array");
|
||||
return -EINVAL;
|
||||
}
|
||||
while (spa_json_enter_object(pnodes, &it[2]) > 0) {
|
||||
if ((res = load_node(graph, &it[2])) < 0)
|
||||
while (spa_json_enter_object(pnodes, &it[1]) > 0) {
|
||||
if ((res = load_node(graph, &it[1])) < 0)
|
||||
return res;
|
||||
}
|
||||
if (plinks != NULL) {
|
||||
while (spa_json_enter_object(plinks, &it[2]) > 0) {
|
||||
if ((res = parse_link(graph, &it[2])) < 0)
|
||||
while (spa_json_enter_object(plinks, &it[1]) > 0) {
|
||||
if ((res = parse_link(graph, &it[1])) < 0)
|
||||
return res;
|
||||
}
|
||||
}
|
||||
if (pcvolumes != NULL) {
|
||||
while (spa_json_enter_object(pcvolumes, &it[2]) > 0) {
|
||||
if ((res = parse_volume(graph, &it[2], true)) < 0)
|
||||
while (spa_json_enter_object(pcvolumes, &it[1]) > 0) {
|
||||
if ((res = parse_volume(graph, &it[1], true)) < 0)
|
||||
return res;
|
||||
}
|
||||
}
|
||||
if (ppvolumes != NULL) {
|
||||
while (spa_json_enter_object(ppvolumes, &it[2]) > 0) {
|
||||
if ((res = parse_volume(graph, &it[2], false)) < 0)
|
||||
while (spa_json_enter_object(ppvolumes, &it[1]) > 0) {
|
||||
if ((res = parse_volume(graph, &it[1], false)) < 0)
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
|
@ -2913,15 +2912,14 @@ static uint32_t channel_from_name(const char *name)
|
|||
|
||||
static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char v[256];
|
||||
|
||||
spa_json_init(&it[0], val, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], val, len);
|
||||
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
|
||||
return;
|
||||
|
||||
info->channels = 0;
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 &&
|
||||
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
|
||||
info->channels < SPA_AUDIO_MAX_CHANNELS) {
|
||||
info->position[info->channels++] = channel_from_name(v);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -278,7 +278,7 @@ static void *bq_instantiate(const struct fc_descriptor * Descriptor,
|
|||
unsigned long SampleRate, int index, const char *config)
|
||||
{
|
||||
struct builtin *impl;
|
||||
struct spa_json it[4];
|
||||
struct spa_json it[3];
|
||||
const char *val;
|
||||
char key[256];
|
||||
uint32_t best_rate = 0;
|
||||
|
|
@ -298,69 +298,68 @@ static void *bq_instantiate(const struct fc_descriptor * Descriptor,
|
|||
goto error;
|
||||
}
|
||||
|
||||
spa_json_init(&it[0], config, strlen(config));
|
||||
if (spa_json_enter_object(&it[0], &it[1]) <= 0) {
|
||||
if (spa_json_begin_object(&it[0], config, strlen(config)) <= 0) {
|
||||
pw_log_error("biquads:config section must be an object");
|
||||
goto error;
|
||||
}
|
||||
|
||||
while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) {
|
||||
while (spa_json_get_string(&it[0], key, sizeof(key)) > 0) {
|
||||
if (spa_streq(key, "coefficients")) {
|
||||
if (spa_json_enter_array(&it[1], &it[2]) <= 0) {
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0) {
|
||||
pw_log_error("biquads:coefficients require an array");
|
||||
goto error;
|
||||
}
|
||||
while (spa_json_enter_object(&it[2], &it[3]) > 0) {
|
||||
while (spa_json_enter_object(&it[1], &it[2]) > 0) {
|
||||
int32_t rate = 0;
|
||||
float b0 = 1.0f, b1 = 0.0f, b2 = 0.0f;
|
||||
float a0 = 1.0f, a1 = 0.0f, a2 = 0.0f;
|
||||
|
||||
while (spa_json_get_string(&it[3], key, sizeof(key)) > 0) {
|
||||
while (spa_json_get_string(&it[2], key, sizeof(key)) > 0) {
|
||||
if (spa_streq(key, "rate")) {
|
||||
if (spa_json_get_int(&it[3], &rate) <= 0) {
|
||||
if (spa_json_get_int(&it[2], &rate) <= 0) {
|
||||
pw_log_error("biquads:rate requires a number");
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
else if (spa_streq(key, "b0")) {
|
||||
if (spa_json_get_float(&it[3], &b0) <= 0) {
|
||||
if (spa_json_get_float(&it[2], &b0) <= 0) {
|
||||
pw_log_error("biquads:b0 requires a float");
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
else if (spa_streq(key, "b1")) {
|
||||
if (spa_json_get_float(&it[3], &b1) <= 0) {
|
||||
if (spa_json_get_float(&it[2], &b1) <= 0) {
|
||||
pw_log_error("biquads:b1 requires a float");
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
else if (spa_streq(key, "b2")) {
|
||||
if (spa_json_get_float(&it[3], &b2) <= 0) {
|
||||
if (spa_json_get_float(&it[2], &b2) <= 0) {
|
||||
pw_log_error("biquads:b2 requires a float");
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
else if (spa_streq(key, "a0")) {
|
||||
if (spa_json_get_float(&it[3], &a0) <= 0) {
|
||||
if (spa_json_get_float(&it[2], &a0) <= 0) {
|
||||
pw_log_error("biquads:a0 requires a float");
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
else if (spa_streq(key, "a1")) {
|
||||
if (spa_json_get_float(&it[3], &a1) <= 0) {
|
||||
if (spa_json_get_float(&it[2], &a1) <= 0) {
|
||||
pw_log_error("biquads:a1 requires a float");
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
else if (spa_streq(key, "a2")) {
|
||||
if (spa_json_get_float(&it[3], &a2) <= 0) {
|
||||
if (spa_json_get_float(&it[2], &a2) <= 0) {
|
||||
pw_log_error("biquads:a0 requires a float");
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
else {
|
||||
pw_log_warn("biquads: ignoring coefficients key: '%s'", key);
|
||||
if (spa_json_next(&it[3], &val) < 0)
|
||||
if (spa_json_next(&it[2], &val) < 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -373,7 +372,7 @@ static void *bq_instantiate(const struct fc_descriptor * Descriptor,
|
|||
}
|
||||
else {
|
||||
pw_log_warn("biquads: ignoring config key: '%s'", key);
|
||||
if (spa_json_next(&it[1], &val) < 0)
|
||||
if (spa_json_next(&it[0], &val) < 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -865,7 +864,7 @@ static void * convolver_instantiate(const struct fc_descriptor * Descriptor,
|
|||
float *samples;
|
||||
int offset = 0, length = 0, channel = index, n_samples = 0, len;
|
||||
uint32_t i = 0;
|
||||
struct spa_json it[3];
|
||||
struct spa_json it[2];
|
||||
const char *val;
|
||||
char key[256], v[256];
|
||||
char *filenames[MAX_RATES] = { 0 };
|
||||
|
|
@ -881,45 +880,44 @@ static void * convolver_instantiate(const struct fc_descriptor * Descriptor,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
spa_json_init(&it[0], config, strlen(config));
|
||||
if (spa_json_enter_object(&it[0], &it[1]) <= 0) {
|
||||
if (spa_json_begin_object(&it[0], config, strlen(config)) <= 0) {
|
||||
pw_log_error("convolver:config must be an object");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) {
|
||||
while (spa_json_get_string(&it[0], key, sizeof(key)) > 0) {
|
||||
if (spa_streq(key, "blocksize")) {
|
||||
if (spa_json_get_int(&it[1], &blocksize) <= 0) {
|
||||
if (spa_json_get_int(&it[0], &blocksize) <= 0) {
|
||||
pw_log_error("convolver:blocksize requires a number");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else if (spa_streq(key, "tailsize")) {
|
||||
if (spa_json_get_int(&it[1], &tailsize) <= 0) {
|
||||
if (spa_json_get_int(&it[0], &tailsize) <= 0) {
|
||||
pw_log_error("convolver:tailsize requires a number");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else if (spa_streq(key, "gain")) {
|
||||
if (spa_json_get_float(&it[1], &gain) <= 0) {
|
||||
if (spa_json_get_float(&it[0], &gain) <= 0) {
|
||||
pw_log_error("convolver:gain requires a number");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else if (spa_streq(key, "delay")) {
|
||||
if (spa_json_get_int(&it[1], &delay) <= 0) {
|
||||
if (spa_json_get_int(&it[0], &delay) <= 0) {
|
||||
pw_log_error("convolver:delay requires a number");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else if (spa_streq(key, "filename")) {
|
||||
if ((len = spa_json_next(&it[1], &val)) <= 0) {
|
||||
if ((len = spa_json_next(&it[0], &val)) <= 0) {
|
||||
pw_log_error("convolver:filename requires a string or an array");
|
||||
return NULL;
|
||||
}
|
||||
if (spa_json_is_array(val, len)) {
|
||||
spa_json_enter(&it[1], &it[2]);
|
||||
while (spa_json_get_string(&it[2], v, sizeof(v)) > 0 &&
|
||||
spa_json_enter(&it[0], &it[1]);
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 &&
|
||||
i < SPA_N_ELEMENTS(filenames)) {
|
||||
filenames[i] = strdup(v);
|
||||
i++;
|
||||
|
|
@ -933,32 +931,32 @@ static void * convolver_instantiate(const struct fc_descriptor * Descriptor,
|
|||
}
|
||||
}
|
||||
else if (spa_streq(key, "offset")) {
|
||||
if (spa_json_get_int(&it[1], &offset) <= 0) {
|
||||
if (spa_json_get_int(&it[0], &offset) <= 0) {
|
||||
pw_log_error("convolver:offset requires a number");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else if (spa_streq(key, "length")) {
|
||||
if (spa_json_get_int(&it[1], &length) <= 0) {
|
||||
if (spa_json_get_int(&it[0], &length) <= 0) {
|
||||
pw_log_error("convolver:length requires a number");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else if (spa_streq(key, "channel")) {
|
||||
if (spa_json_get_int(&it[1], &channel) <= 0) {
|
||||
if (spa_json_get_int(&it[0], &channel) <= 0) {
|
||||
pw_log_error("convolver:channel requires a number");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else if (spa_streq(key, "resample_quality")) {
|
||||
if (spa_json_get_int(&it[1], &resample_quality) <= 0) {
|
||||
if (spa_json_get_int(&it[0], &resample_quality) <= 0) {
|
||||
pw_log_error("convolver:resample_quality requires a number");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
pw_log_warn("convolver: ignoring config key: '%s'", key);
|
||||
if (spa_json_next(&it[1], &val) < 0)
|
||||
if (spa_json_next(&it[0], &val) < 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -1097,7 +1095,7 @@ static void *delay_instantiate(const struct fc_descriptor * Descriptor,
|
|||
unsigned long SampleRate, int index, const char *config)
|
||||
{
|
||||
struct delay_impl *impl;
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
const char *val;
|
||||
char key[256];
|
||||
float max_delay = 1.0f;
|
||||
|
|
@ -1108,21 +1106,20 @@ static void *delay_instantiate(const struct fc_descriptor * Descriptor,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
spa_json_init(&it[0], config, strlen(config));
|
||||
if (spa_json_enter_object(&it[0], &it[1]) <= 0) {
|
||||
if (spa_json_begin_object(&it[0], config, strlen(config)) <= 0) {
|
||||
pw_log_error("delay:config must be an object");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) {
|
||||
while (spa_json_get_string(&it[0], key, sizeof(key)) > 0) {
|
||||
if (spa_streq(key, "max-delay")) {
|
||||
if (spa_json_get_float(&it[1], &max_delay) <= 0) {
|
||||
if (spa_json_get_float(&it[0], &max_delay) <= 0) {
|
||||
pw_log_error("delay:max-delay requires a number");
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
pw_log_warn("delay: ignoring config key: '%s'", key);
|
||||
if (spa_json_next(&it[1], &val) < 0)
|
||||
if (spa_json_next(&it[0], &val) < 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ static void * spatializer_instantiate(const struct fc_descriptor * Descriptor,
|
|||
unsigned long SampleRate, int index, const char *config)
|
||||
{
|
||||
struct spatializer_impl *impl;
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
const char *val;
|
||||
char key[256];
|
||||
char filename[PATH_MAX] = "";
|
||||
|
|
@ -47,8 +47,7 @@ static void * spatializer_instantiate(const struct fc_descriptor * Descriptor,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
spa_json_init(&it[0], config, strlen(config));
|
||||
if (spa_json_enter_object(&it[0], &it[1]) <= 0) {
|
||||
if (spa_json_begin_object(&it[0], config, strlen(config)) <= 0) {
|
||||
pw_log_error("spatializer: expected object in config");
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -59,29 +58,29 @@ static void * spatializer_instantiate(const struct fc_descriptor * Descriptor,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) {
|
||||
while (spa_json_get_string(&it[0], key, sizeof(key)) > 0) {
|
||||
if (spa_streq(key, "blocksize")) {
|
||||
if (spa_json_get_int(&it[1], &impl->blocksize) <= 0) {
|
||||
if (spa_json_get_int(&it[0], &impl->blocksize) <= 0) {
|
||||
pw_log_error("spatializer:blocksize requires a number");
|
||||
errno = EINVAL;
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
else if (spa_streq(key, "tailsize")) {
|
||||
if (spa_json_get_int(&it[1], &impl->tailsize) <= 0) {
|
||||
if (spa_json_get_int(&it[0], &impl->tailsize) <= 0) {
|
||||
pw_log_error("spatializer:tailsize requires a number");
|
||||
errno = EINVAL;
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
else if (spa_streq(key, "filename")) {
|
||||
if (spa_json_get_string(&it[1], filename, sizeof(filename)) <= 0) {
|
||||
if (spa_json_get_string(&it[0], filename, sizeof(filename)) <= 0) {
|
||||
pw_log_error("spatializer:filename requires a string");
|
||||
errno = EINVAL;
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
else if (spa_json_next(&it[1], &val) < 0)
|
||||
else if (spa_json_next(&it[0], &val) < 0)
|
||||
break;
|
||||
}
|
||||
if (!filename[0]) {
|
||||
|
|
|
|||
|
|
@ -1001,15 +1001,14 @@ static uint32_t channel_from_name(const char *name)
|
|||
|
||||
static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char v[256];
|
||||
|
||||
spa_json_init(&it[0], val, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], val, len);
|
||||
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
|
||||
return;
|
||||
|
||||
info->channels = 0;
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 &&
|
||||
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
|
||||
info->channels < SPA_AUDIO_MAX_CHANNELS) {
|
||||
info->position[info->channels++] = channel_from_name(v);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -773,15 +773,14 @@ static uint32_t channel_from_name(const char *name)
|
|||
|
||||
static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char v[256];
|
||||
|
||||
spa_json_init(&it[0], val, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], val, len);
|
||||
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
|
||||
return;
|
||||
|
||||
info->channels = 0;
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 &&
|
||||
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
|
||||
info->channels < SPA_AUDIO_MAX_CHANNELS) {
|
||||
info->position[info->channels++] = channel_from_name(v);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,21 +66,20 @@ struct factory_data {
|
|||
*/
|
||||
static int fill_metadata(struct pw_metadata *metadata, const char *str)
|
||||
{
|
||||
struct spa_json it[3];
|
||||
struct spa_json it[2];
|
||||
|
||||
spa_json_init(&it[0], str, strlen(str));
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
if (spa_json_begin_array(&it[0], str, strlen(str)) <= 0)
|
||||
return -EINVAL;
|
||||
|
||||
while (spa_json_enter_object(&it[1], &it[2]) > 0) {
|
||||
while (spa_json_enter_object(&it[0], &it[1]) > 0) {
|
||||
char key[256], *k = NULL, *v = NULL, *t = NULL;
|
||||
int id = 0;
|
||||
|
||||
while (spa_json_get_string(&it[2], key, sizeof(key)) > 0) {
|
||||
while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) {
|
||||
int len;
|
||||
const char *val;
|
||||
|
||||
if ((len = spa_json_next(&it[2], &val)) <= 0)
|
||||
if ((len = spa_json_next(&it[1], &val)) <= 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (spa_streq(key, "id")) {
|
||||
|
|
@ -94,7 +93,7 @@ static int fill_metadata(struct pw_metadata *metadata, const char *str)
|
|||
spa_json_parse_stringn(val, len, t, len+1);
|
||||
} else if (spa_streq(key, "value")) {
|
||||
if (spa_json_is_container(val, len))
|
||||
len = spa_json_container_len(&it[2], val, len);
|
||||
len = spa_json_container_len(&it[1], val, len);
|
||||
if ((v = malloc(len+1)) != NULL)
|
||||
spa_json_parse_stringn(val, len, v, len+1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1156,15 +1156,14 @@ static uint32_t channel_from_name(const char *name)
|
|||
|
||||
static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char v[256];
|
||||
|
||||
spa_json_init(&it[0], val, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], val, len);
|
||||
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
|
||||
return;
|
||||
|
||||
info->channels = 0;
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 &&
|
||||
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
|
||||
info->channels < SPA_AUDIO_MAX_CHANNELS) {
|
||||
info->position[info->channels++] = channel_from_name(v);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1182,15 +1182,14 @@ static uint32_t channel_from_name(const char *name)
|
|||
|
||||
static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char v[256];
|
||||
|
||||
spa_json_init(&it[0], val, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], val, len);
|
||||
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
|
||||
return;
|
||||
|
||||
info->channels = 0;
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 &&
|
||||
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
|
||||
info->channels < SPA_AUDIO_MAX_CHANNELS) {
|
||||
info->position[info->channels++] = channel_from_name(v);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -764,15 +764,14 @@ static uint32_t channel_from_name(const char *name)
|
|||
|
||||
static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char v[256];
|
||||
|
||||
spa_json_init(&it[0], val, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], val, len);
|
||||
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
|
||||
return;
|
||||
|
||||
info->channels = 0;
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 &&
|
||||
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
|
||||
info->channels < SPA_AUDIO_MAX_CHANNELS) {
|
||||
info->position[info->channels++] = channel_from_name(v);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1659,7 +1659,7 @@ static int create_servers(struct pw_protocol *this, struct pw_impl_core *core,
|
|||
const struct pw_properties *props, const struct pw_properties *args)
|
||||
{
|
||||
const char *sockets = args ? pw_properties_get(args, "sockets") : NULL;
|
||||
struct spa_json it[3];
|
||||
struct spa_json it[2];
|
||||
spa_autoptr(pw_properties) p = pw_properties_copy(props);
|
||||
|
||||
if (sockets == NULL) {
|
||||
|
|
@ -1681,12 +1681,10 @@ static int create_servers(struct pw_protocol *this, struct pw_impl_core *core,
|
|||
return 0;
|
||||
}
|
||||
|
||||
spa_json_init(&it[0], sockets, strlen(sockets));
|
||||
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
if (spa_json_begin_array(&it[0], sockets, strlen(sockets)) <= 0)
|
||||
goto error_invalid;
|
||||
|
||||
while (spa_json_enter_object(&it[1], &it[2]) > 0) {
|
||||
while (spa_json_enter_object(&it[0], &it[1]) > 0) {
|
||||
struct socket_info info = {0};
|
||||
char key[256];
|
||||
char name[PATH_MAX];
|
||||
|
|
@ -1698,11 +1696,11 @@ static int create_servers(struct pw_protocol *this, struct pw_impl_core *core,
|
|||
pw_properties_clear(p);
|
||||
pw_properties_update(p, &props->dict);
|
||||
|
||||
while (spa_json_get_string(&it[2], key, sizeof(key)) > 0) {
|
||||
while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) {
|
||||
const char *value;
|
||||
int len;
|
||||
|
||||
if ((len = spa_json_next(&it[2], &value)) <= 0)
|
||||
if ((len = spa_json_next(&it[1], &value)) <= 0)
|
||||
goto error_invalid;
|
||||
|
||||
if (spa_streq(key, "name")) {
|
||||
|
|
@ -1762,7 +1760,7 @@ static int create_servers(struct pw_protocol *this, struct pw_impl_core *core,
|
|||
info.has_mode = true;
|
||||
} else if (spa_streq(key, "props")) {
|
||||
if (spa_json_is_container(value, len))
|
||||
len = spa_json_container_len(&it[2], value, len);
|
||||
len = spa_json_container_len(&it[1], value, len);
|
||||
|
||||
pw_properties_update_string(p, value, len);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ int pw_protocol_native_connect_local_socket(struct pw_protocol_client *client,
|
|||
void *data)
|
||||
{
|
||||
const char *name;
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char path[PATH_MAX];
|
||||
int res = -EINVAL;
|
||||
|
||||
|
|
@ -160,12 +160,10 @@ int pw_protocol_native_connect_local_socket(struct pw_protocol_client *client,
|
|||
if (name == NULL)
|
||||
return -EINVAL;
|
||||
|
||||
spa_json_init(&it[0], name, strlen(name));
|
||||
|
||||
if (spa_json_enter_array(&it[0], &it[1]) < 0)
|
||||
if (spa_json_begin_array(&it[0], name, strlen(name)) <= 0)
|
||||
return try_connect_name(client, name, done_callback, data);
|
||||
|
||||
while (spa_json_get_string(&it[1], path, sizeof(path)) > 0) {
|
||||
while (spa_json_get_string(&it[0], path, sizeof(path)) > 0) {
|
||||
res = try_connect_name(client, path, done_callback, data);
|
||||
if (res < 0)
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -68,25 +68,24 @@ static int parse_cmd(void *user_data, const char *location,
|
|||
const char *section, const char *str, size_t len)
|
||||
{
|
||||
struct impl *impl = user_data;
|
||||
struct spa_json it[3];
|
||||
struct spa_json it[2];
|
||||
char key[512];
|
||||
int res = 0;
|
||||
|
||||
spa_autofree char *s = strndup(str, len);
|
||||
spa_json_init(&it[0], s, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) < 0) {
|
||||
if (spa_json_begin_array(&it[0], s, len) < 0) {
|
||||
pw_log_error("config file error: pulse.cmd is not an array");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
while (spa_json_enter_object(&it[1], &it[2]) > 0) {
|
||||
while (spa_json_enter_object(&it[0], &it[1]) > 0) {
|
||||
char *cmd = NULL, *args = NULL, *flags = NULL;
|
||||
|
||||
while (spa_json_get_string(&it[2], key, sizeof(key)) > 0) {
|
||||
while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) {
|
||||
const char *val;
|
||||
int len;
|
||||
|
||||
if ((len = spa_json_next(&it[2], &val)) <= 0)
|
||||
if ((len = spa_json_next(&it[1], &val)) <= 0)
|
||||
break;
|
||||
|
||||
if (spa_streq(key, "cmd")) {
|
||||
|
|
@ -97,7 +96,7 @@ static int parse_cmd(void *user_data, const char *location,
|
|||
spa_json_parse_stringn(val, len, args, len+1);
|
||||
} else if (spa_streq(key, "flags")) {
|
||||
if (spa_json_is_container(val, len))
|
||||
len = spa_json_container_len(&it[2], val, len);
|
||||
len = spa_json_container_len(&it[1], val, len);
|
||||
flags = (char*)val;
|
||||
spa_json_parse_stringn(val, len, flags, len+1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -440,15 +440,14 @@ void channel_map_parse(const char *str, struct channel_map *map)
|
|||
|
||||
void channel_map_parse_position(const char *str, struct channel_map *map)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char v[256];
|
||||
|
||||
spa_json_init(&it[0], str, strlen(str));
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], str, strlen(str));
|
||||
if (spa_json_begin_array_relax(&it[0], str, strlen(str)) <= 0)
|
||||
return;
|
||||
|
||||
map->channels = 0;
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 &&
|
||||
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
|
||||
map->channels < SPA_AUDIO_MAX_CHANNELS) {
|
||||
map->map[map->channels++] = channel_name2id(v);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -177,7 +177,7 @@ static int do_extension_stream_restore_read(struct module *module, struct client
|
|||
reply = reply_new(client, tag);
|
||||
|
||||
spa_dict_for_each(item, &client->routes->dict) {
|
||||
struct spa_json it[3];
|
||||
struct spa_json it[2];
|
||||
const char *value;
|
||||
char name[1024], key[128];
|
||||
char device_name[1024] = "\0";
|
||||
|
|
@ -191,45 +191,44 @@ static int do_extension_stream_restore_read(struct module *module, struct client
|
|||
|
||||
pw_log_debug("%s -> %s: %s", item->key, name, item->value);
|
||||
|
||||
spa_json_init(&it[0], item->value, strlen(item->value));
|
||||
if (spa_json_enter_object(&it[0], &it[1]) <= 0)
|
||||
if (spa_json_begin_object(&it[0], item->value, strlen(item->value)) <= 0)
|
||||
continue;
|
||||
|
||||
while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) {
|
||||
while (spa_json_get_string(&it[0], key, sizeof(key)) > 0) {
|
||||
if (spa_streq(key, "volume")) {
|
||||
if (spa_json_get_float(&it[1], &volume) <= 0)
|
||||
if (spa_json_get_float(&it[0], &volume) <= 0)
|
||||
continue;
|
||||
}
|
||||
else if (spa_streq(key, "mute")) {
|
||||
if (spa_json_get_bool(&it[1], &mute) <= 0)
|
||||
if (spa_json_get_bool(&it[0], &mute) <= 0)
|
||||
continue;
|
||||
}
|
||||
else if (spa_streq(key, "volumes")) {
|
||||
vol = VOLUME_INIT;
|
||||
if (spa_json_enter_array(&it[1], &it[2]) <= 0)
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
continue;
|
||||
|
||||
for (vol.channels = 0; vol.channels < CHANNELS_MAX; vol.channels++) {
|
||||
if (spa_json_get_float(&it[2], &vol.values[vol.channels]) <= 0)
|
||||
if (spa_json_get_float(&it[1], &vol.values[vol.channels]) <= 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (spa_streq(key, "channels")) {
|
||||
if (spa_json_enter_array(&it[1], &it[2]) <= 0)
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
continue;
|
||||
|
||||
for (map.channels = 0; map.channels < CHANNELS_MAX; map.channels++) {
|
||||
char chname[16];
|
||||
if (spa_json_get_string(&it[2], chname, sizeof(chname)) <= 0)
|
||||
if (spa_json_get_string(&it[1], chname, sizeof(chname)) <= 0)
|
||||
break;
|
||||
map.map[map.channels] = channel_name2id(chname);
|
||||
}
|
||||
}
|
||||
else if (spa_streq(key, "target-node")) {
|
||||
if (spa_json_get_string(&it[1], device_name, sizeof(device_name)) <= 0)
|
||||
if (spa_json_get_string(&it[0], device_name, sizeof(device_name)) <= 0)
|
||||
continue;
|
||||
}
|
||||
else if (spa_json_next(&it[1], &value) <= 0)
|
||||
else if (spa_json_next(&it[0], &value) <= 0)
|
||||
break;
|
||||
}
|
||||
message_put(reply,
|
||||
|
|
|
|||
|
|
@ -930,21 +930,20 @@ static void manager_object_data_timeout(void *data, struct pw_manager_object *o,
|
|||
|
||||
static int json_object_find(const char *obj, const char *key, char *value, size_t len)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
const char *v;
|
||||
char k[128];
|
||||
|
||||
spa_json_init(&it[0], obj, strlen(obj));
|
||||
if (spa_json_enter_object(&it[0], &it[1]) <= 0)
|
||||
if (spa_json_begin_object(&it[0], obj, strlen(obj)) <= 0)
|
||||
return -EINVAL;
|
||||
|
||||
while (spa_json_get_string(&it[1], k, sizeof(k)) > 0) {
|
||||
while (spa_json_get_string(&it[0], k, sizeof(k)) > 0) {
|
||||
if (spa_streq(k, key)) {
|
||||
if (spa_json_get_string(&it[1], value, len) <= 0)
|
||||
if (spa_json_get_string(&it[0], value, len) <= 0)
|
||||
continue;
|
||||
return 0;
|
||||
} else {
|
||||
if (spa_json_next(&it[1], &v) <= 0)
|
||||
if (spa_json_next(&it[0], &v) <= 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -977,29 +977,28 @@ int servers_create_and_start(struct impl *impl, const char *addresses, struct pw
|
|||
{
|
||||
int len, res, count = 0, err = 0; /* store the first error to return when no servers could be created */
|
||||
const char *v;
|
||||
struct spa_json it[3];
|
||||
struct spa_json it[2];
|
||||
|
||||
/* update `err` if it hasn't been set to an errno */
|
||||
#define UPDATE_ERR(e) do { if (err == 0) err = (e); } while (false)
|
||||
|
||||
/* collect addresses into an array of `struct sockaddr_storage` */
|
||||
spa_json_init(&it[0], addresses, strlen(addresses));
|
||||
|
||||
/* [ <server-spec> ... ] */
|
||||
if (spa_json_enter_array(&it[0], &it[1]) < 0)
|
||||
if (spa_json_begin_array(&it[0], addresses, strlen(addresses)) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
/* a server-spec is either an address or an object */
|
||||
while ((len = spa_json_next(&it[1], &v)) > 0) {
|
||||
while ((len = spa_json_next(&it[0], &v)) > 0) {
|
||||
char addr_str[FORMATTED_SOCKET_ADDR_STRLEN] = { 0 };
|
||||
char key[128], client_access[64] = { 0 };
|
||||
struct sockaddr_storage addrs[2];
|
||||
int i, max_clients = MAX_CLIENTS, listen_backlog = LISTEN_BACKLOG, n_addr;
|
||||
|
||||
if (spa_json_is_object(v, len)) {
|
||||
spa_json_enter(&it[1], &it[2]);
|
||||
while (spa_json_get_string(&it[2], key, sizeof(key)) > 0) {
|
||||
if ((len = spa_json_next(&it[2], &v)) <= 0)
|
||||
spa_json_enter(&it[0], &it[1]);
|
||||
while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) {
|
||||
if ((len = spa_json_next(&it[1], &v)) <= 0)
|
||||
break;
|
||||
|
||||
if (spa_streq(key, "address")) {
|
||||
|
|
|
|||
|
|
@ -805,15 +805,14 @@ static inline uint32_t channel_from_name(const char *name)
|
|||
|
||||
static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char v[256];
|
||||
|
||||
spa_json_init(&it[0], val, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], val, len);
|
||||
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
|
||||
return;
|
||||
|
||||
info->channels = 0;
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 &&
|
||||
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
|
||||
info->channels < SPA_AUDIO_MAX_CHANNELS) {
|
||||
info->position[info->channels++] = channel_from_name(v);
|
||||
}
|
||||
|
|
@ -890,7 +889,7 @@ static void copy_props(struct impl *impl, const char *key)
|
|||
static int parse_params(struct impl *impl)
|
||||
{
|
||||
const char *str;
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char value[512];
|
||||
|
||||
pw_properties_fetch_bool(impl->props, "capture", &impl->capture);
|
||||
|
|
@ -965,9 +964,8 @@ static int parse_params(struct impl *impl)
|
|||
if ((str = pw_properties_get(impl->props, "server.address")) == NULL)
|
||||
str = DEFAULT_SERVER;
|
||||
|
||||
spa_json_init(&it[0], str, strlen(str));
|
||||
if (spa_json_enter_array(&it[0], &it[1]) > 0) {
|
||||
while (spa_json_get_string(&it[1], value, sizeof(value)) > 0) {
|
||||
if (spa_json_begin_array_relax(&it[0], str, strlen(str)) > 0) {
|
||||
while (spa_json_get_string(&it[0], value, sizeof(value)) > 0) {
|
||||
if (create_server(impl, value) == NULL) {
|
||||
pw_log_warn("%p: can't create server for %s: %m",
|
||||
impl, value);
|
||||
|
|
|
|||
|
|
@ -1074,15 +1074,14 @@ static uint32_t channel_from_name(const char *name)
|
|||
|
||||
static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char v[256];
|
||||
|
||||
spa_json_init(&it[0], val, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], val, len);
|
||||
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
|
||||
return;
|
||||
|
||||
info->channels = 0;
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 &&
|
||||
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
|
||||
info->channels < SPA_AUDIO_MAX_CHANNELS) {
|
||||
info->position[info->channels++] = channel_from_name(v);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -965,19 +965,16 @@ static struct session *session_new_announce(struct impl *impl, struct node *node
|
|||
sess->ts_refclk_ptp = pw_properties_get_bool(props, "rtp.fetch-ts-refclk", false);
|
||||
if ((str = pw_properties_get(props, PW_KEY_NODE_CHANNELNAMES)) != NULL) {
|
||||
struct spa_strbuf buf;
|
||||
struct spa_json it[1];
|
||||
char v[256];
|
||||
int count = 0;
|
||||
|
||||
spa_strbuf_init(&buf, sdp->channelmap, sizeof(sdp->channelmap));
|
||||
|
||||
struct spa_json it[2];
|
||||
char v[256];
|
||||
|
||||
spa_json_init(&it[0], str, strlen(str));
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], str, strlen(str));
|
||||
|
||||
if (spa_json_get_string(&it[1], v, sizeof(v)) > 0)
|
||||
spa_strbuf_append(&buf, "%s", v);
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0)
|
||||
spa_strbuf_append(&buf, ", %s", v);
|
||||
if (spa_json_begin_array_relax(&it[0], str, strlen(str)) > 0) {
|
||||
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0)
|
||||
spa_strbuf_append(&buf, "%s%s", count++ > 0 ? ", " : "", v);
|
||||
}
|
||||
}
|
||||
|
||||
pw_log_info("created new session for node:%u", node->id);
|
||||
|
|
@ -1799,30 +1796,24 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
|
|||
struct spa_strbuf buf;
|
||||
if ((str = pw_properties_get(props, "sap.preamble-extra")) != NULL) {
|
||||
spa_strbuf_init(&buf, buffer, sizeof(buffer));
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char line[256];
|
||||
|
||||
spa_json_init(&it[0], str, strlen(str));
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], str, strlen(str));
|
||||
|
||||
while (spa_json_get_string(&it[1], line, sizeof(line)) > 0)
|
||||
spa_strbuf_append(&buf, "%s\n", line);
|
||||
|
||||
if (spa_json_begin_array_relax(&it[0], str, strlen(str)) > 0) {
|
||||
while (spa_json_get_string(&it[0], line, sizeof(line)) > 0)
|
||||
spa_strbuf_append(&buf, "%s\n", line);
|
||||
}
|
||||
impl->extra_attrs_preamble = strdup(buffer);
|
||||
}
|
||||
if ((str = pw_properties_get(props, "sap.end-extra")) != NULL) {
|
||||
spa_strbuf_init(&buf, buffer, sizeof(buffer));
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char line[256];
|
||||
|
||||
spa_json_init(&it[0], str, strlen(str));
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], str, strlen(str));
|
||||
|
||||
while (spa_json_get_string(&it[1], line, sizeof(line)) > 0)
|
||||
spa_strbuf_append(&buf, "%s\n", line);
|
||||
|
||||
if (spa_json_begin_array_relax(&it[0], str, strlen(str)) > 0) {
|
||||
while (spa_json_get_string(&it[0], line, sizeof(line)) > 0)
|
||||
spa_strbuf_append(&buf, "%s\n", line);
|
||||
}
|
||||
impl->extra_attrs_end = strdup(buffer);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -291,15 +291,14 @@ static uint32_t channel_from_name(const char *name)
|
|||
|
||||
static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char v[256];
|
||||
|
||||
spa_json_init(&it[0], val, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], val, len);
|
||||
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
|
||||
return;
|
||||
|
||||
info->channels = 0;
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 &&
|
||||
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
|
||||
info->channels < SPA_AUDIO_MAX_CHANNELS) {
|
||||
info->position[info->channels++] = channel_from_name(v);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -486,14 +486,13 @@ static int snapcast_connect(struct tunnel *t)
|
|||
static int add_snapcast_stream(struct impl *impl, struct tunnel *t,
|
||||
struct pw_properties *props, const char *servers)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char v[256];
|
||||
|
||||
spa_json_init(&it[0], servers, strlen(servers));
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], servers, strlen(servers));
|
||||
if (spa_json_begin_array_relax(&it[0], servers, strlen(servers)) <= 0)
|
||||
return -EINVAL;
|
||||
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0) {
|
||||
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0) {
|
||||
t->server_address = strdup(v);
|
||||
snapcast_connect(t);
|
||||
return 0;
|
||||
|
|
@ -523,15 +522,14 @@ static inline uint32_t channel_from_name(const char *name)
|
|||
|
||||
static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char v[256];
|
||||
|
||||
spa_json_init(&it[0], val, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], val, len);
|
||||
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
|
||||
return;
|
||||
|
||||
info->channels = 0;
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 &&
|
||||
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
|
||||
info->channels < SPA_AUDIO_MAX_CHANNELS) {
|
||||
info->position[info->channels++] = channel_from_name(v);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -209,15 +209,14 @@ static uint32_t channel_from_name(const char *name)
|
|||
|
||||
static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char v[256];
|
||||
|
||||
spa_json_init(&it[0], val, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], val, len);
|
||||
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
|
||||
return;
|
||||
|
||||
info->channels = 0;
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 &&
|
||||
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
|
||||
info->channels < SPA_AUDIO_MAX_CHANNELS) {
|
||||
info->position[info->channels++] = channel_from_name(v);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -565,19 +565,18 @@ static int parse_spa_libs(void *user_data, const char *location,
|
|||
{
|
||||
struct data *d = user_data;
|
||||
struct pw_context *context = d->context;
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char key[512], value[512];
|
||||
int res;
|
||||
|
||||
spa_json_init(&it[0], str, len);
|
||||
if (spa_json_enter_object(&it[0], &it[1]) < 0) {
|
||||
if (spa_json_begin_object(&it[0], str, len) < 0) {
|
||||
pw_log_error("config file error: context.spa-libs is not an "
|
||||
"object in '%.*s'", (int)len, str);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) {
|
||||
if (spa_json_get_string(&it[1], value, sizeof(value)) > 0) {
|
||||
while (spa_json_get_string(&it[0], key, sizeof(key)) > 0) {
|
||||
if (spa_json_get_string(&it[0], value, sizeof(value)) > 0) {
|
||||
if ((res = pw_context_add_spa_lib(context, key, value)) < 0) {
|
||||
pw_log_error("error adding spa-libs for '%s' in '%.*s': %s",
|
||||
key, (int)len, str, spa_strerror(res));
|
||||
|
|
@ -752,27 +751,26 @@ static int parse_modules(void *user_data, const char *location,
|
|||
{
|
||||
struct data *d = user_data;
|
||||
struct pw_context *context = d->context;
|
||||
struct spa_json it[4];
|
||||
struct spa_json it[3];
|
||||
char key[512];
|
||||
int res = 0, r;
|
||||
|
||||
spa_autofree char *s = strndup(str, len);
|
||||
spa_json_init(&it[0], s, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) < 0) {
|
||||
if (spa_json_begin_array(&it[0], s, len) < 0) {
|
||||
pw_log_error("context.modules is not an array in '%.*s'",
|
||||
(int)len, str);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
while ((r = spa_json_enter_object(&it[1], &it[2])) > 0) {
|
||||
while ((r = spa_json_enter_object(&it[0], &it[1])) > 0) {
|
||||
char *name = NULL, *args = NULL, *flags = NULL;
|
||||
bool have_match = true;
|
||||
|
||||
while (spa_json_get_string(&it[2], key, sizeof(key)) > 0) {
|
||||
while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) {
|
||||
const char *val;
|
||||
int l;
|
||||
|
||||
if ((l = spa_json_next(&it[2], &val)) <= 0) {
|
||||
if ((l = spa_json_next(&it[1], &val)) <= 0) {
|
||||
pw_log_warn("malformed module: key '%s' has no "
|
||||
"value in '%.*s'", key, (int)len, str);
|
||||
break;
|
||||
|
|
@ -783,13 +781,13 @@ static int parse_modules(void *user_data, const char *location,
|
|||
spa_json_parse_stringn(val, l, name, l+1);
|
||||
} else if (spa_streq(key, "args")) {
|
||||
if (spa_json_is_container(val, l))
|
||||
l = spa_json_container_len(&it[2], val, l);
|
||||
l = spa_json_container_len(&it[1], val, l);
|
||||
|
||||
args = (char*)val;
|
||||
spa_json_parse_stringn(val, l, args, l+1);
|
||||
} else if (spa_streq(key, "flags")) {
|
||||
if (spa_json_is_container(val, l))
|
||||
l = spa_json_container_len(&it[2], val, l);
|
||||
l = spa_json_container_len(&it[1], val, l);
|
||||
flags = (char*)val;
|
||||
spa_json_parse_stringn(val, l, flags, l+1);
|
||||
} else if (spa_streq(key, "condition")) {
|
||||
|
|
@ -798,8 +796,8 @@ static int parse_modules(void *user_data, const char *location,
|
|||
(int)len, str);
|
||||
break;
|
||||
}
|
||||
spa_json_enter(&it[2], &it[3]);
|
||||
have_match = find_match(&it[3], &context->properties->dict, true);
|
||||
spa_json_enter(&it[1], &it[2]);
|
||||
have_match = find_match(&it[2], &context->properties->dict, true);
|
||||
} else {
|
||||
pw_log_warn("unknown module key '%s' in '%.*s'", key,
|
||||
(int)len, str);
|
||||
|
|
@ -862,26 +860,25 @@ static int parse_objects(void *user_data, const char *location,
|
|||
{
|
||||
struct data *d = user_data;
|
||||
struct pw_context *context = d->context;
|
||||
struct spa_json it[4];
|
||||
struct spa_json it[3];
|
||||
char key[512];
|
||||
int res = 0, r;
|
||||
|
||||
spa_autofree char *s = strndup(str, len);
|
||||
spa_json_init(&it[0], s, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) < 0) {
|
||||
if (spa_json_begin_array(&it[0], s, len) < 0) {
|
||||
pw_log_error("config file error: context.objects is not an array");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
while ((r = spa_json_enter_object(&it[1], &it[2])) > 0) {
|
||||
while ((r = spa_json_enter_object(&it[0], &it[1])) > 0) {
|
||||
char *factory = NULL, *args = NULL, *flags = NULL;
|
||||
bool have_match = true;
|
||||
|
||||
while (spa_json_get_string(&it[2], key, sizeof(key)) > 0) {
|
||||
while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) {
|
||||
const char *val;
|
||||
int l;
|
||||
|
||||
if ((l = spa_json_next(&it[2], &val)) <= 0) {
|
||||
if ((l = spa_json_next(&it[1], &val)) <= 0) {
|
||||
pw_log_warn("malformed object: key '%s' has no "
|
||||
"value in '%.*s'", key, (int)len, str);
|
||||
break;
|
||||
|
|
@ -892,13 +889,13 @@ static int parse_objects(void *user_data, const char *location,
|
|||
spa_json_parse_stringn(val, l, factory, l+1);
|
||||
} else if (spa_streq(key, "args")) {
|
||||
if (spa_json_is_container(val, l))
|
||||
l = spa_json_container_len(&it[2], val, l);
|
||||
l = spa_json_container_len(&it[1], val, l);
|
||||
|
||||
args = (char*)val;
|
||||
spa_json_parse_stringn(val, l, args, l+1);
|
||||
} else if (spa_streq(key, "flags")) {
|
||||
if (spa_json_is_container(val, l))
|
||||
l = spa_json_container_len(&it[2], val, l);
|
||||
l = spa_json_container_len(&it[1], val, l);
|
||||
|
||||
flags = (char*)val;
|
||||
spa_json_parse_stringn(val, l, flags, l+1);
|
||||
|
|
@ -908,8 +905,8 @@ static int parse_objects(void *user_data, const char *location,
|
|||
(int)len, str);
|
||||
break;
|
||||
}
|
||||
spa_json_enter(&it[2], &it[3]);
|
||||
have_match = find_match(&it[3], &context->properties->dict, true);
|
||||
spa_json_enter(&it[1], &it[2]);
|
||||
have_match = find_match(&it[2], &context->properties->dict, true);
|
||||
} else {
|
||||
pw_log_warn("unknown object key '%s' in '%.*s'", key,
|
||||
(int)len, str);
|
||||
|
|
@ -1046,29 +1043,28 @@ static int parse_exec(void *user_data, const char *location,
|
|||
{
|
||||
struct data *d = user_data;
|
||||
struct pw_context *context = d->context;
|
||||
struct spa_json it[4];
|
||||
struct spa_json it[3];
|
||||
char key[512];
|
||||
int r, res = 0;
|
||||
|
||||
spa_autofree char *s = strndup(str, len);
|
||||
spa_json_init(&it[0], s, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) < 0) {
|
||||
if (spa_json_begin_array(&it[0], s, len) < 0) {
|
||||
pw_log_error("config file error: context.exec is not an array in '%.*s'",
|
||||
(int)len, str);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
while ((r = spa_json_enter_object(&it[1], &it[2])) > 0) {
|
||||
while ((r = spa_json_enter_object(&it[0], &it[1])) > 0) {
|
||||
char *path = NULL;
|
||||
const char *args_val = "[]";
|
||||
int args_len = 2;
|
||||
bool have_match = true;
|
||||
|
||||
while (spa_json_get_string(&it[2], key, sizeof(key)) > 0) {
|
||||
while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) {
|
||||
const char *val;
|
||||
int l;
|
||||
|
||||
if ((l = spa_json_next(&it[2], &val)) <= 0) {
|
||||
if ((l = spa_json_next(&it[1], &val)) <= 0) {
|
||||
pw_log_warn("malformed exec: key '%s' has no "
|
||||
"value in '%.*s'", key, (int)len, str);
|
||||
break;
|
||||
|
|
@ -1079,7 +1075,7 @@ static int parse_exec(void *user_data, const char *location,
|
|||
spa_json_parse_stringn(val, l, path, l+1);
|
||||
} else if (spa_streq(key, "args")) {
|
||||
if (spa_json_is_container(val, l))
|
||||
l = spa_json_container_len(&it[2], val, l);
|
||||
l = spa_json_container_len(&it[1], val, l);
|
||||
args_val = val;
|
||||
args_len = l;
|
||||
} else if (spa_streq(key, "condition")) {
|
||||
|
|
@ -1088,8 +1084,8 @@ static int parse_exec(void *user_data, const char *location,
|
|||
(int)len, str);
|
||||
goto next;
|
||||
}
|
||||
spa_json_enter(&it[2], &it[3]);
|
||||
have_match = find_match(&it[3], &context->properties->dict, true);
|
||||
spa_json_enter(&it[1], &it[2]);
|
||||
have_match = find_match(&it[2], &context->properties->dict, true);
|
||||
} else {
|
||||
pw_log_warn("unknown exec key '%s' in '%.*s'", key,
|
||||
(int)len, str);
|
||||
|
|
@ -1307,31 +1303,30 @@ int pw_conf_match_rules(const char *str, size_t len, const char *location,
|
|||
void *data)
|
||||
{
|
||||
const char *val;
|
||||
struct spa_json it[4], actions;
|
||||
struct spa_json it[3], actions;
|
||||
int r;
|
||||
|
||||
spa_json_init(&it[0], str, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) < 0) {
|
||||
if (spa_json_begin_array(&it[0], str, len) < 0) {
|
||||
pw_log_warn("expect array of match rules in: '%.*s'", (int)len, str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
while ((r = spa_json_enter_object(&it[1], &it[2])) > 0) {
|
||||
while ((r = spa_json_enter_object(&it[0], &it[1])) > 0) {
|
||||
char key[64];
|
||||
bool have_match = false, have_actions = false;
|
||||
|
||||
while (spa_json_get_string(&it[2], key, sizeof(key)) > 0) {
|
||||
while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) {
|
||||
if (spa_streq(key, "matches")) {
|
||||
if (spa_json_enter_array(&it[2], &it[3]) < 0) {
|
||||
if (spa_json_enter_array(&it[1], &it[2]) < 0) {
|
||||
pw_log_warn("expected array as matches in '%.*s'",
|
||||
(int)len, str);
|
||||
break;
|
||||
}
|
||||
|
||||
have_match = find_match(&it[3], props, false);
|
||||
have_match = find_match(&it[2], props, false);
|
||||
}
|
||||
else if (spa_streq(key, "actions")) {
|
||||
if (spa_json_enter_object(&it[2], &actions) > 0)
|
||||
if (spa_json_enter_object(&it[1], &actions) > 0)
|
||||
have_actions = true;
|
||||
else
|
||||
pw_log_warn("expected object as match actions in '%.*s'",
|
||||
|
|
@ -1339,7 +1334,7 @@ int pw_conf_match_rules(const char *str, size_t len, const char *location,
|
|||
}
|
||||
else {
|
||||
pw_log_warn("unknown match key '%s'", key);
|
||||
if (spa_json_next(&it[2], &val) <= 0) {
|
||||
if (spa_json_next(&it[1], &val) <= 0) {
|
||||
pw_log_warn("malformed match rule: key '%s' has "
|
||||
"no value in '%.*s'", key, (int)len, str);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -204,19 +204,18 @@ static int setup_data_loops(struct impl *impl)
|
|||
lib_name = pw_properties_get(this->properties, "context.data-loop." PW_KEY_LIBRARY_NAME_SYSTEM);
|
||||
|
||||
if ((str = pw_properties_get(this->properties, "context.data-loops")) != NULL) {
|
||||
struct spa_json it[4];
|
||||
struct spa_json it[2];
|
||||
char key[512];
|
||||
int r, len = strlen(str);
|
||||
spa_autofree char *s = strndup(str, len);
|
||||
|
||||
i = 0;
|
||||
spa_json_init(&it[0], s, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) < 0) {
|
||||
if (spa_json_begin_array(&it[0], s, len) < 0) {
|
||||
pw_log_error("context.data-loops is not an array in '%s'", str);
|
||||
res = -EINVAL;
|
||||
goto exit;
|
||||
}
|
||||
while ((r = spa_json_enter_object(&it[1], &it[2])) > 0) {
|
||||
while ((r = spa_json_enter_object(&it[0], &it[1])) > 0) {
|
||||
char *props = NULL;
|
||||
|
||||
if (i >= MAX_LOOPS) {
|
||||
|
|
@ -229,17 +228,17 @@ static int setup_data_loops(struct impl *impl)
|
|||
pw_properties_update(pr, &this->properties->dict);
|
||||
pw_properties_set(pr, PW_KEY_LIBRARY_NAME_SYSTEM, lib_name);
|
||||
|
||||
while (spa_json_get_string(&it[2], key, sizeof(key)) > 0) {
|
||||
while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) {
|
||||
const char *val;
|
||||
int l;
|
||||
|
||||
if ((l = spa_json_next(&it[2], &val)) <= 0) {
|
||||
if ((l = spa_json_next(&it[1], &val)) <= 0) {
|
||||
pw_log_warn("malformed data-loop: key '%s' has no "
|
||||
"value in '%.*s'", key, (int)len, str);
|
||||
break;
|
||||
}
|
||||
if (spa_json_is_container(val, l))
|
||||
l = spa_json_container_len(&it[2], val, l);
|
||||
l = spa_json_container_len(&it[1], val, l);
|
||||
|
||||
props = (char*)val;
|
||||
spa_json_parse_stringn(val, l, props, l+1);
|
||||
|
|
|
|||
|
|
@ -1282,20 +1282,18 @@ int pw_impl_port_add(struct pw_impl_port *port, struct pw_impl_node *node)
|
|||
|
||||
channel_names = pw_properties_get(nprops, PW_KEY_NODE_CHANNELNAMES);
|
||||
if (channel_names != NULL) {
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char v[256];
|
||||
uint32_t i;
|
||||
|
||||
spa_json_init(&it[0], channel_names, strlen(channel_names));
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], channel_names, strlen(channel_names));
|
||||
if (spa_json_begin_array_relax(&it[0], channel_names, strlen(channel_names)) > 0) {
|
||||
for (i = 0; i < port->port_id + 1; i++)
|
||||
if (spa_json_get_string(&it[0], v, sizeof(v)) <= 0)
|
||||
break;
|
||||
|
||||
for (i = 0; i < port->port_id + 1; i++)
|
||||
if (spa_json_get_string(&it[1], v, sizeof(v)) <= 0)
|
||||
break;
|
||||
|
||||
if (i == port->port_id + 1 && strlen(v) > 0)
|
||||
snprintf(position, sizeof(position), "%s", v);
|
||||
if (i == port->port_id + 1 && strlen(v) > 0)
|
||||
snprintf(position, sizeof(position), "%s", v);
|
||||
}
|
||||
}
|
||||
|
||||
if (pw_properties_get(port->properties, PW_KEY_PORT_NAME) == NULL) {
|
||||
|
|
|
|||
|
|
@ -210,7 +210,7 @@ exit_noupdate:
|
|||
static int update_string(struct pw_properties *props, const char *str, size_t size,
|
||||
int *count, struct spa_error_location *loc)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char key[1024];
|
||||
struct spa_error_location el;
|
||||
bool err;
|
||||
|
|
@ -220,29 +220,28 @@ static int update_string(struct pw_properties *props, const char *str, size_t si
|
|||
if (props)
|
||||
properties_init(&changes, 16);
|
||||
|
||||
spa_json_init(&it[0], str, size);
|
||||
if (spa_json_enter_object(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], str, size);
|
||||
if ((res = spa_json_begin_object_relax(&it[0], str, size)) <= 0)
|
||||
return res;
|
||||
|
||||
while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) {
|
||||
while (spa_json_get_string(&it[0], key, sizeof(key)) > 0) {
|
||||
int len;
|
||||
const char *value;
|
||||
char *val = NULL;
|
||||
|
||||
if ((len = spa_json_next(&it[1], &value)) <= 0)
|
||||
if ((len = spa_json_next(&it[0], &value)) <= 0)
|
||||
break;
|
||||
|
||||
if (spa_json_is_null(value, len))
|
||||
val = NULL;
|
||||
else {
|
||||
if (spa_json_is_container(value, len))
|
||||
len = spa_json_container_len(&it[1], value, len);
|
||||
len = spa_json_container_len(&it[0], value, len);
|
||||
if (len <= 0)
|
||||
break;
|
||||
|
||||
if (props) {
|
||||
if ((val = malloc(len+1)) == NULL) {
|
||||
it[1].state = SPA_JSON_ERROR_FLAG;
|
||||
it[0].state = SPA_JSON_ERROR_FLAG;
|
||||
break;
|
||||
}
|
||||
spa_json_parse_stringn(value, len, val, len+1);
|
||||
|
|
@ -257,12 +256,12 @@ static int update_string(struct pw_properties *props, const char *str, size_t si
|
|||
}
|
||||
/* item changed or added, apply changes later */
|
||||
if ((errno = -add_item(&changes, key, false, val, true) < 0)) {
|
||||
it[1].state = SPA_JSON_ERROR_FLAG;
|
||||
it[0].state = SPA_JSON_ERROR_FLAG;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((err = spa_json_get_error(&it[1], str, &el))) {
|
||||
if ((err = spa_json_get_error(&it[0], str, &el))) {
|
||||
if (loc == NULL)
|
||||
spa_debug_log_error_location(pw_log_get(), SPA_LOG_LEVEL_WARN,
|
||||
&el, "error parsing more than %d properties: %s",
|
||||
|
|
|
|||
|
|
@ -90,14 +90,13 @@ static bool uint32_array_contains(uint32_t *vals, uint32_t n_vals, uint32_t val)
|
|||
static uint32_t parse_uint32_array(const char *str, uint32_t *vals, uint32_t max, uint32_t def)
|
||||
{
|
||||
uint32_t count = 0, r;
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char v[256];
|
||||
|
||||
spa_json_init(&it[0], str, strlen(str));
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], str, strlen(str));
|
||||
if (spa_json_begin_array_relax(&it[0], str, strlen(str)) <= 0)
|
||||
return 0;
|
||||
|
||||
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 &&
|
||||
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
|
||||
count < max) {
|
||||
if (spa_atou32(v, &r, 0))
|
||||
vals[count++] = r;
|
||||
|
|
|
|||
|
|
@ -27,15 +27,14 @@ do { \
|
|||
|
||||
static int parse_affinity(const char *affinity, cpu_set_t *set)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
int v;
|
||||
|
||||
CPU_ZERO(set);
|
||||
spa_json_init(&it[0], affinity, strlen(affinity));
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], affinity, strlen(affinity));
|
||||
if (spa_json_begin_array_relax(&it[0], affinity, strlen(affinity)) <= 0)
|
||||
return 0;
|
||||
|
||||
while (spa_json_get_int(&it[1], &v) > 0) {
|
||||
while (spa_json_get_int(&it[0], &v) > 0) {
|
||||
if (v >= 0 && v < CPU_SETSIZE)
|
||||
CPU_SET(v, set);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ SPA_EXPORT
|
|||
char **pw_strv_parse(const char *val, size_t len, int max_tokens, int *n_tokens)
|
||||
{
|
||||
struct pw_array arr;
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
int n = 0, l, res;
|
||||
const char *value;
|
||||
struct spa_error_location el;
|
||||
|
|
@ -140,11 +140,10 @@ char **pw_strv_parse(const char *val, size_t len, int max_tokens, int *n_tokens)
|
|||
|
||||
pw_array_init(&arr, sizeof(char*) * 16);
|
||||
|
||||
spa_json_init(&it[0], val, len);
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
spa_json_init(&it[1], val, len);
|
||||
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
|
||||
return NULL;
|
||||
|
||||
while ((l = spa_json_next(&it[1], &value)) > 0 && n + 1 < max_tokens) {
|
||||
while ((l = spa_json_next(&it[0], &value)) > 0 && n + 1 < max_tokens) {
|
||||
char *s;
|
||||
|
||||
if ((s = malloc(l+1)) == NULL)
|
||||
|
|
@ -161,7 +160,7 @@ char **pw_strv_parse(const char *val, size_t len, int max_tokens, int *n_tokens)
|
|||
if ((res = pw_array_add_ptr(&arr, NULL)) < 0)
|
||||
goto error;
|
||||
done:
|
||||
if ((res = spa_json_get_error(&it[1], val, &el))) {
|
||||
if ((res = spa_json_get_error(&it[0], val, &el))) {
|
||||
spa_debug_log_error_location(pw_log_get(), SPA_LOG_LEVEL_WARN,
|
||||
&el, "error parsing strv: %s", el.reason);
|
||||
|
||||
|
|
@ -179,7 +178,7 @@ done:
|
|||
error_errno:
|
||||
res = -errno;
|
||||
error:
|
||||
it[1].state = SPA_JSON_ERROR_FLAG;
|
||||
it[0].state = SPA_JSON_ERROR_FLAG;
|
||||
errno = -res;
|
||||
goto done;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1276,7 +1276,7 @@ static int get_data_from_json(struct data *data, const char *json_path)
|
|||
int fd, len;
|
||||
void *json;
|
||||
struct stat sbuf;
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
const char *value;
|
||||
struct spa_error_location loc;
|
||||
|
||||
|
|
@ -1296,18 +1296,16 @@ static int get_data_from_json(struct data *data, const char *json_path)
|
|||
}
|
||||
|
||||
close(fd);
|
||||
spa_json_init(&it[0], json, sbuf.st_size);
|
||||
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0) {
|
||||
if (spa_json_begin_array(&it[0], json, sbuf.st_size) <= 0) {
|
||||
fprintf(stderr, "expected top-level array in JSON file '%s'\n", json_path);
|
||||
munmap(json, sbuf.st_size);
|
||||
return -1;
|
||||
}
|
||||
|
||||
while ((len = spa_json_next(&it[1], &value)) > 0 && spa_json_is_object(value, len)) {
|
||||
while ((len = spa_json_next(&it[0], &value)) > 0 && spa_json_is_object(value, len)) {
|
||||
struct pw_properties *obj;
|
||||
obj = pw_properties_new(NULL, NULL);
|
||||
len = spa_json_container_len(&it[1], value, len);
|
||||
len = spa_json_container_len(&it[0], value, len);
|
||||
pw_properties_update_string(obj, value, len);
|
||||
handle_json_obj(data, obj);
|
||||
pw_properties_free(obj);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue