2011-02-25 12:35:14 +05:30
|
|
|
/***
|
|
|
|
|
This file is part of PulseAudio.
|
|
|
|
|
|
|
|
|
|
Copyright 2011 Intel Corporation
|
|
|
|
|
Copyright 2011 Collabora Multimedia
|
|
|
|
|
Copyright 2011 Arun Raghavan <arun.raghavan@collabora.co.uk>
|
|
|
|
|
|
|
|
|
|
PulseAudio is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published
|
|
|
|
|
by the Free Software Foundation; either version 2.1 of the License,
|
|
|
|
|
or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
PulseAudio is distributed in the hope that it will be useful, but
|
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2014-11-26 14:14:51 +01:00
|
|
|
along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
|
2011-02-25 12:35:14 +05:30
|
|
|
***/
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
#include <pulse/json.h>
|
2011-02-25 12:35:14 +05:30
|
|
|
#include <pulse/internal.h>
|
|
|
|
|
#include <pulse/xmalloc.h>
|
|
|
|
|
|
2013-11-18 19:43:48 +02:00
|
|
|
#include <pulsecore/core-format.h>
|
2011-02-25 12:35:14 +05:30
|
|
|
#include <pulsecore/core-util.h>
|
2011-08-10 10:30:15 +02:00
|
|
|
#include <pulsecore/i18n.h>
|
2011-02-25 12:35:14 +05:30
|
|
|
#include <pulsecore/macro.h>
|
2016-06-01 17:18:32 +05:30
|
|
|
#include <pulsecore/strbuf.h>
|
2011-02-25 12:35:14 +05:30
|
|
|
|
|
|
|
|
#include "format.h"
|
|
|
|
|
|
2011-04-13 14:05:18 +05:30
|
|
|
#define PA_JSON_MIN_KEY "min"
|
|
|
|
|
#define PA_JSON_MAX_KEY "max"
|
|
|
|
|
|
|
|
|
|
static int pa_format_info_prop_compatible(const char *one, const char *two);
|
|
|
|
|
|
2011-08-12 21:55:48 +05:30
|
|
|
static const char* const _encoding_str_table[]= {
|
|
|
|
|
[PA_ENCODING_PCM] = "pcm",
|
|
|
|
|
[PA_ENCODING_AC3_IEC61937] = "ac3-iec61937",
|
|
|
|
|
[PA_ENCODING_EAC3_IEC61937] = "eac3-iec61937",
|
|
|
|
|
[PA_ENCODING_MPEG_IEC61937] = "mpeg-iec61937",
|
|
|
|
|
[PA_ENCODING_DTS_IEC61937] = "dts-iec61937",
|
2013-02-11 23:32:09 +09:00
|
|
|
[PA_ENCODING_MPEG2_AAC_IEC61937] = "mpeg2-aac-iec61937",
|
2017-08-15 12:24:12 -05:00
|
|
|
[PA_ENCODING_TRUEHD_IEC61937] = "truehd-iec61937",
|
|
|
|
|
[PA_ENCODING_DTSHD_IEC61937] = "dtshd-iec61937",
|
2011-08-12 21:55:48 +05:30
|
|
|
[PA_ENCODING_ANY] = "any",
|
|
|
|
|
};
|
2011-03-08 20:15:36 +05:30
|
|
|
|
2011-08-12 21:55:48 +05:30
|
|
|
const char *pa_encoding_to_string(pa_encoding_t e) {
|
2011-03-08 20:15:36 +05:30
|
|
|
if (e < 0 || e >= PA_ENCODING_MAX)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2011-08-12 21:55:48 +05:30
|
|
|
return _encoding_str_table[e];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pa_encoding_t pa_encoding_from_string(const char *encoding) {
|
|
|
|
|
pa_encoding_t e;
|
|
|
|
|
|
|
|
|
|
for (e = PA_ENCODING_ANY; e < PA_ENCODING_MAX; e++)
|
|
|
|
|
if (pa_streq(_encoding_str_table[e], encoding))
|
|
|
|
|
return e;
|
|
|
|
|
|
|
|
|
|
return PA_ENCODING_INVALID;
|
2011-03-08 20:15:36 +05:30
|
|
|
}
|
|
|
|
|
|
2011-02-25 12:35:14 +05:30
|
|
|
pa_format_info* pa_format_info_new(void) {
|
|
|
|
|
pa_format_info *f = pa_xnew(pa_format_info, 1);
|
|
|
|
|
|
|
|
|
|
f->encoding = PA_ENCODING_INVALID;
|
|
|
|
|
f->plist = pa_proplist_new();
|
|
|
|
|
|
|
|
|
|
return f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pa_format_info* pa_format_info_copy(const pa_format_info *src) {
|
|
|
|
|
pa_format_info *dest;
|
|
|
|
|
|
|
|
|
|
pa_assert(src);
|
|
|
|
|
|
|
|
|
|
dest = pa_xnew(pa_format_info, 1);
|
|
|
|
|
|
|
|
|
|
dest->encoding = src->encoding;
|
|
|
|
|
|
|
|
|
|
if (src->plist)
|
|
|
|
|
dest->plist = pa_proplist_copy(src->plist);
|
|
|
|
|
else
|
|
|
|
|
dest->plist = NULL;
|
|
|
|
|
|
|
|
|
|
return dest;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pa_format_info_free(pa_format_info *f) {
|
|
|
|
|
pa_assert(f);
|
|
|
|
|
|
|
|
|
|
pa_proplist_free(f->plist);
|
|
|
|
|
pa_xfree(f);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-08 20:14:46 +05:30
|
|
|
int pa_format_info_valid(const pa_format_info *f) {
|
2016-04-29 17:35:28 +05:30
|
|
|
return (f->encoding >= 0 && f->encoding < PA_ENCODING_MAX && f->plist != NULL);
|
2011-02-25 12:35:14 +05:30
|
|
|
}
|
2011-02-28 10:53:41 +05:30
|
|
|
|
2011-03-08 20:14:46 +05:30
|
|
|
int pa_format_info_is_pcm(const pa_format_info *f) {
|
2011-03-01 16:34:06 +05:30
|
|
|
return f->encoding == PA_ENCODING_PCM;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-08 20:15:36 +05:30
|
|
|
char *pa_format_info_snprint(char *s, size_t l, const pa_format_info *f) {
|
|
|
|
|
char *tmp;
|
|
|
|
|
|
|
|
|
|
pa_assert(s);
|
|
|
|
|
pa_assert(l > 0);
|
|
|
|
|
pa_assert(f);
|
|
|
|
|
|
|
|
|
|
pa_init_i18n();
|
|
|
|
|
|
|
|
|
|
if (!pa_format_info_valid(f))
|
|
|
|
|
pa_snprintf(s, l, _("(invalid)"));
|
|
|
|
|
else {
|
2011-08-12 21:04:38 +05:30
|
|
|
tmp = pa_proplist_to_string_sep(f->plist, " ");
|
|
|
|
|
if (tmp[0])
|
|
|
|
|
pa_snprintf(s, l, "%s, %s", pa_encoding_to_string(f->encoding), tmp);
|
|
|
|
|
else
|
|
|
|
|
pa_snprintf(s, l, "%s", pa_encoding_to_string(f->encoding));
|
2011-03-08 20:15:36 +05:30
|
|
|
pa_xfree(tmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-12 21:55:48 +05:30
|
|
|
pa_format_info* pa_format_info_from_string(const char *str) {
|
|
|
|
|
pa_format_info *f = pa_format_info_new();
|
|
|
|
|
char *encoding = NULL, *properties = NULL;
|
|
|
|
|
size_t pos;
|
|
|
|
|
|
|
|
|
|
pos = strcspn(str, ",");
|
|
|
|
|
|
|
|
|
|
encoding = pa_xstrndup(str, pos);
|
|
|
|
|
f->encoding = pa_encoding_from_string(pa_strip(encoding));
|
|
|
|
|
if (f->encoding == PA_ENCODING_INVALID)
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
if (pos != strlen(str)) {
|
|
|
|
|
pa_proplist *plist;
|
|
|
|
|
|
|
|
|
|
properties = pa_xstrdup(&str[pos+1]);
|
|
|
|
|
plist = pa_proplist_from_string(properties);
|
|
|
|
|
|
|
|
|
|
if (!plist)
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
pa_proplist_free(f->plist);
|
|
|
|
|
f->plist = plist;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
if (encoding)
|
|
|
|
|
pa_xfree(encoding);
|
|
|
|
|
if (properties)
|
|
|
|
|
pa_xfree(properties);
|
|
|
|
|
return f;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
pa_format_info_free(f);
|
|
|
|
|
f = NULL;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-17 21:14:18 +02:00
|
|
|
int pa_format_info_is_compatible(const pa_format_info *first, const pa_format_info *second) {
|
2011-02-28 10:53:41 +05:30
|
|
|
const char *key;
|
|
|
|
|
void *state = NULL;
|
|
|
|
|
|
|
|
|
|
pa_assert(first);
|
|
|
|
|
pa_assert(second);
|
|
|
|
|
|
|
|
|
|
if (first->encoding != second->encoding)
|
2013-06-27 19:28:09 +02:00
|
|
|
return false;
|
2011-02-28 10:53:41 +05:30
|
|
|
|
|
|
|
|
while ((key = pa_proplist_iterate(first->plist, &state))) {
|
|
|
|
|
const char *value_one, *value_two;
|
|
|
|
|
|
|
|
|
|
value_one = pa_proplist_gets(first->plist, key);
|
|
|
|
|
value_two = pa_proplist_gets(second->plist, key);
|
|
|
|
|
|
2011-04-13 14:05:18 +05:30
|
|
|
if (!value_two || !pa_format_info_prop_compatible(value_one, value_two))
|
2013-06-27 19:28:09 +02:00
|
|
|
return false;
|
2011-02-28 10:53:41 +05:30
|
|
|
}
|
|
|
|
|
|
2013-06-27 19:28:09 +02:00
|
|
|
return true;
|
2011-02-28 10:53:41 +05:30
|
|
|
}
|
|
|
|
|
|
2013-12-17 21:14:18 +02:00
|
|
|
pa_format_info* pa_format_info_from_sample_spec(const pa_sample_spec *ss, const pa_channel_map *map) {
|
2011-02-28 10:53:41 +05:30
|
|
|
char cm[PA_CHANNEL_MAP_SNPRINT_MAX];
|
|
|
|
|
pa_format_info *f;
|
|
|
|
|
|
|
|
|
|
pa_assert(ss && pa_sample_spec_valid(ss));
|
|
|
|
|
pa_assert(!map || pa_channel_map_valid(map));
|
|
|
|
|
|
|
|
|
|
f = pa_format_info_new();
|
|
|
|
|
f->encoding = PA_ENCODING_PCM;
|
|
|
|
|
|
2011-04-13 15:37:25 +05:30
|
|
|
pa_format_info_set_sample_format(f, ss->format);
|
|
|
|
|
pa_format_info_set_rate(f, ss->rate);
|
|
|
|
|
pa_format_info_set_channels(f, ss->channels);
|
2011-02-28 10:53:41 +05:30
|
|
|
|
|
|
|
|
if (map) {
|
|
|
|
|
pa_channel_map_snprint(cm, sizeof(cm), map);
|
2011-04-13 14:05:18 +05:30
|
|
|
pa_format_info_set_prop_string(f, PA_PROP_FORMAT_CHANNEL_MAP, cm);
|
2011-02-28 10:53:41 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* For PCM streams */
|
2013-12-17 21:14:18 +02:00
|
|
|
int pa_format_info_to_sample_spec(const pa_format_info *f, pa_sample_spec *ss, pa_channel_map *map) {
|
2011-02-28 10:53:41 +05:30
|
|
|
pa_assert(f);
|
|
|
|
|
pa_assert(ss);
|
2012-03-05 20:30:33 +05:30
|
|
|
|
|
|
|
|
if (!pa_format_info_is_pcm(f))
|
2013-11-18 19:43:48 +02:00
|
|
|
return pa_format_info_to_sample_spec_fake(f, ss, map);
|
2011-02-28 10:53:41 +05:30
|
|
|
|
2013-11-25 16:15:54 +02:00
|
|
|
if (pa_format_info_get_sample_format(f, &ss->format) < 0)
|
2013-12-03 16:45:45 +02:00
|
|
|
return -PA_ERR_INVALID;
|
2013-11-25 14:34:58 +02:00
|
|
|
if (pa_format_info_get_rate(f, &ss->rate) < 0)
|
2013-12-03 16:45:45 +02:00
|
|
|
return -PA_ERR_INVALID;
|
2013-11-25 14:51:37 +02:00
|
|
|
if (pa_format_info_get_channels(f, &ss->channels) < 0)
|
2013-12-03 16:45:45 +02:00
|
|
|
return -PA_ERR_INVALID;
|
2013-11-25 14:59:44 +02:00
|
|
|
if (map && pa_format_info_get_channel_map(f, map) < 0)
|
2013-12-03 16:45:45 +02:00
|
|
|
return -PA_ERR_INVALID;
|
2011-04-13 14:05:18 +05:30
|
|
|
|
2013-12-03 16:45:45 +02:00
|
|
|
return 0;
|
2011-02-28 10:53:41 +05:30
|
|
|
}
|
|
|
|
|
|
2013-12-17 21:14:18 +02:00
|
|
|
pa_prop_type_t pa_format_info_get_prop_type(const pa_format_info *f, const char *key) {
|
2012-02-06 17:17:34 +05:30
|
|
|
const char *str;
|
2016-06-01 17:18:32 +05:30
|
|
|
pa_json_object *o;
|
|
|
|
|
const pa_json_object *o1;
|
2012-02-06 17:17:34 +05:30
|
|
|
pa_prop_type_t type;
|
|
|
|
|
|
|
|
|
|
pa_assert(f);
|
|
|
|
|
pa_assert(key);
|
|
|
|
|
|
|
|
|
|
str = pa_proplist_gets(f->plist, key);
|
|
|
|
|
if (!str)
|
|
|
|
|
return PA_PROP_TYPE_INVALID;
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
o = pa_json_parse(str);
|
2014-08-18 14:38:30 +02:00
|
|
|
if (!o)
|
2012-02-06 17:17:34 +05:30
|
|
|
return PA_PROP_TYPE_INVALID;
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
switch (pa_json_object_get_type(o)) {
|
|
|
|
|
case PA_JSON_TYPE_INT:
|
2012-02-06 17:17:34 +05:30
|
|
|
type = PA_PROP_TYPE_INT;
|
|
|
|
|
break;
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
case PA_JSON_TYPE_STRING:
|
2012-02-06 17:17:34 +05:30
|
|
|
type = PA_PROP_TYPE_STRING;
|
|
|
|
|
break;
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
case PA_JSON_TYPE_ARRAY:
|
|
|
|
|
if (pa_json_object_get_array_length(o) == 0) {
|
2012-02-06 17:17:34 +05:30
|
|
|
/* Unlikely, but let's account for this anyway. We need at
|
|
|
|
|
* least one element to figure out the array type. */
|
|
|
|
|
type = PA_PROP_TYPE_INVALID;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
o1 = pa_json_object_get_array_member(o, 0);
|
2012-02-06 17:17:34 +05:30
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
if (pa_json_object_get_type(o1) == PA_JSON_TYPE_INT)
|
2012-02-06 17:17:34 +05:30
|
|
|
type = PA_PROP_TYPE_INT_ARRAY;
|
2016-06-01 17:18:32 +05:30
|
|
|
else if (pa_json_object_get_type(o1) == PA_JSON_TYPE_STRING)
|
2012-02-06 17:17:34 +05:30
|
|
|
type = PA_PROP_TYPE_STRING_ARRAY;
|
|
|
|
|
else
|
|
|
|
|
type = PA_PROP_TYPE_INVALID;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
case PA_JSON_TYPE_OBJECT:
|
2012-02-06 17:17:34 +05:30
|
|
|
/* We actually know at this point that it's a int range, but let's
|
|
|
|
|
* confirm. */
|
2016-06-01 17:18:32 +05:30
|
|
|
if (!pa_json_object_get_object_member(o, PA_JSON_MIN_KEY)) {
|
2012-02-06 17:17:34 +05:30
|
|
|
type = PA_PROP_TYPE_INVALID;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
if (!pa_json_object_get_object_member(o, PA_JSON_MAX_KEY)) {
|
2012-02-06 17:17:34 +05:30
|
|
|
type = PA_PROP_TYPE_INVALID;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type = PA_PROP_TYPE_INT_RANGE;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
type = PA_PROP_TYPE_INVALID;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-01 17:18:39 +05:30
|
|
|
pa_json_object_free(o);
|
2012-02-06 17:17:34 +05:30
|
|
|
return type;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-17 21:14:18 +02:00
|
|
|
int pa_format_info_get_prop_int(const pa_format_info *f, const char *key, int *v) {
|
2011-04-13 14:05:18 +05:30
|
|
|
const char *str;
|
2016-06-01 17:18:32 +05:30
|
|
|
pa_json_object *o;
|
2011-04-13 14:05:18 +05:30
|
|
|
|
|
|
|
|
pa_assert(f);
|
|
|
|
|
pa_assert(key);
|
|
|
|
|
pa_assert(v);
|
|
|
|
|
|
2012-02-06 11:20:17 +05:30
|
|
|
str = pa_proplist_gets(f->plist, key);
|
|
|
|
|
if (!str)
|
|
|
|
|
return -PA_ERR_NOENTITY;
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
o = pa_json_parse(str);
|
2014-08-18 14:38:30 +02:00
|
|
|
if (!o) {
|
2013-12-18 18:28:55 +02:00
|
|
|
pa_log_debug("Failed to parse format info property '%s'.", key);
|
2012-02-06 11:20:17 +05:30
|
|
|
return -PA_ERR_INVALID;
|
2013-12-18 18:28:55 +02:00
|
|
|
}
|
2012-02-06 11:20:17 +05:30
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
if (pa_json_object_get_type(o) != PA_JSON_TYPE_INT) {
|
2013-12-18 18:28:55 +02:00
|
|
|
pa_log_debug("Format info property '%s' type is not int.", key);
|
2016-06-01 17:18:39 +05:30
|
|
|
pa_json_object_free(o);
|
2012-02-06 11:14:53 +05:30
|
|
|
return -PA_ERR_INVALID;
|
2011-04-13 14:05:18 +05:30
|
|
|
}
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
*v = pa_json_object_get_int(o);
|
2016-06-01 17:18:39 +05:30
|
|
|
pa_json_object_free(o);
|
2011-04-13 14:05:18 +05:30
|
|
|
|
2012-02-06 11:14:53 +05:30
|
|
|
return 0;
|
2011-04-13 14:05:18 +05:30
|
|
|
}
|
|
|
|
|
|
2013-12-17 21:14:18 +02:00
|
|
|
int pa_format_info_get_prop_int_range(const pa_format_info *f, const char *key, int *min, int *max) {
|
2012-02-06 16:18:49 +05:30
|
|
|
const char *str;
|
2016-06-01 17:18:32 +05:30
|
|
|
pa_json_object *o;
|
|
|
|
|
const pa_json_object *o1;
|
2012-02-06 16:18:49 +05:30
|
|
|
int ret = -PA_ERR_INVALID;
|
|
|
|
|
|
|
|
|
|
pa_assert(f);
|
|
|
|
|
pa_assert(key);
|
|
|
|
|
pa_assert(min);
|
|
|
|
|
pa_assert(max);
|
|
|
|
|
|
|
|
|
|
str = pa_proplist_gets(f->plist, key);
|
|
|
|
|
if (!str)
|
|
|
|
|
return -PA_ERR_NOENTITY;
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
o = pa_json_parse(str);
|
2014-08-18 14:38:30 +02:00
|
|
|
if (!o) {
|
2013-12-18 18:28:55 +02:00
|
|
|
pa_log_debug("Failed to parse format info property '%s'.", key);
|
2012-02-06 16:18:49 +05:30
|
|
|
return -PA_ERR_INVALID;
|
2013-12-18 18:28:55 +02:00
|
|
|
}
|
2012-02-06 16:18:49 +05:30
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
if (pa_json_object_get_type(o) != PA_JSON_TYPE_OBJECT)
|
2012-02-06 16:18:49 +05:30
|
|
|
goto out;
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
if (!(o1 = pa_json_object_get_object_member(o, PA_JSON_MIN_KEY)) ||
|
|
|
|
|
(pa_json_object_get_type(o1) != PA_JSON_TYPE_INT))
|
2012-02-06 16:18:49 +05:30
|
|
|
goto out;
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
*min = pa_json_object_get_int(o1);
|
2012-02-06 16:18:49 +05:30
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
if (!(o1 = pa_json_object_get_object_member(o, PA_JSON_MAX_KEY)) ||
|
|
|
|
|
(pa_json_object_get_type(o1) != PA_JSON_TYPE_INT))
|
2012-02-06 16:18:49 +05:30
|
|
|
goto out;
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
*max = pa_json_object_get_int(o1);
|
2012-02-06 16:18:49 +05:30
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
|
|
out:
|
2013-12-18 18:28:55 +02:00
|
|
|
if (ret < 0)
|
|
|
|
|
pa_log_debug("Format info property '%s' is not a valid int range.", key);
|
|
|
|
|
|
2016-06-01 17:18:39 +05:30
|
|
|
pa_json_object_free(o);
|
2012-02-06 16:18:49 +05:30
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-17 21:14:18 +02:00
|
|
|
int pa_format_info_get_prop_int_array(const pa_format_info *f, const char *key, int **values, int *n_values) {
|
2012-02-06 16:18:49 +05:30
|
|
|
const char *str;
|
2016-06-01 17:18:32 +05:30
|
|
|
pa_json_object *o;
|
|
|
|
|
const pa_json_object *o1;
|
2012-02-06 16:18:49 +05:30
|
|
|
int i, ret = -PA_ERR_INVALID;
|
|
|
|
|
|
|
|
|
|
pa_assert(f);
|
|
|
|
|
pa_assert(key);
|
|
|
|
|
pa_assert(values);
|
|
|
|
|
pa_assert(n_values);
|
|
|
|
|
|
|
|
|
|
str = pa_proplist_gets(f->plist, key);
|
|
|
|
|
if (!str)
|
|
|
|
|
return -PA_ERR_NOENTITY;
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
o = pa_json_parse(str);
|
2014-08-18 14:38:30 +02:00
|
|
|
if (!o) {
|
2013-12-18 18:28:55 +02:00
|
|
|
pa_log_debug("Failed to parse format info property '%s'.", key);
|
2012-02-06 16:18:49 +05:30
|
|
|
return -PA_ERR_INVALID;
|
2013-12-18 18:28:55 +02:00
|
|
|
}
|
2012-02-06 16:18:49 +05:30
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
if (pa_json_object_get_type(o) != PA_JSON_TYPE_ARRAY)
|
2012-02-06 16:18:49 +05:30
|
|
|
goto out;
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
*n_values = pa_json_object_get_array_length(o);
|
2012-02-06 16:18:49 +05:30
|
|
|
*values = pa_xnew(int, *n_values);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < *n_values; i++) {
|
2016-06-01 17:18:32 +05:30
|
|
|
o1 = pa_json_object_get_array_member(o, i);
|
2012-02-06 16:18:49 +05:30
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
if (pa_json_object_get_type(o1) != PA_JSON_TYPE_INT) {
|
2012-02-06 16:18:49 +05:30
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
(*values)[i] = pa_json_object_get_int(o1);
|
2012-02-06 16:18:49 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
|
|
out:
|
2013-12-18 18:28:55 +02:00
|
|
|
if (ret < 0)
|
|
|
|
|
pa_log_debug("Format info property '%s' is not a valid int array.", key);
|
|
|
|
|
|
2016-06-01 17:18:39 +05:30
|
|
|
pa_json_object_free(o);
|
2012-02-06 16:18:49 +05:30
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-17 21:14:18 +02:00
|
|
|
int pa_format_info_get_prop_string(const pa_format_info *f, const char *key, char **v) {
|
2011-04-13 14:05:18 +05:30
|
|
|
const char *str = NULL;
|
2016-06-01 17:18:32 +05:30
|
|
|
pa_json_object *o;
|
2011-04-13 14:05:18 +05:30
|
|
|
|
|
|
|
|
pa_assert(f);
|
|
|
|
|
pa_assert(key);
|
|
|
|
|
pa_assert(v);
|
|
|
|
|
|
2011-08-16 15:21:45 +05:30
|
|
|
str = pa_proplist_gets(f->plist, key);
|
2011-05-20 19:21:02 +05:30
|
|
|
if (!str)
|
2012-02-06 11:14:53 +05:30
|
|
|
return -PA_ERR_NOENTITY;
|
2011-05-20 19:21:02 +05:30
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
o = pa_json_parse(str);
|
2014-08-18 14:38:30 +02:00
|
|
|
if (!o) {
|
2013-12-18 18:28:55 +02:00
|
|
|
pa_log_debug("Failed to parse format info property '%s'.", key);
|
2012-02-06 11:20:17 +05:30
|
|
|
return -PA_ERR_INVALID;
|
2013-12-18 18:28:55 +02:00
|
|
|
}
|
2012-02-06 11:20:17 +05:30
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
if (pa_json_object_get_type(o) != PA_JSON_TYPE_STRING) {
|
2013-12-18 18:28:55 +02:00
|
|
|
pa_log_debug("Format info property '%s' type is not string.", key);
|
2016-06-01 17:18:39 +05:30
|
|
|
pa_json_object_free(o);
|
2012-02-06 11:14:53 +05:30
|
|
|
return -PA_ERR_INVALID;
|
2011-04-13 14:05:18 +05:30
|
|
|
}
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
*v = pa_xstrdup(pa_json_object_get_string(o));
|
2016-06-01 17:18:39 +05:30
|
|
|
pa_json_object_free(o);
|
2011-04-13 14:05:18 +05:30
|
|
|
|
2012-02-06 11:14:53 +05:30
|
|
|
return 0;
|
2011-04-13 14:05:18 +05:30
|
|
|
}
|
|
|
|
|
|
2013-12-17 21:14:18 +02:00
|
|
|
int pa_format_info_get_prop_string_array(const pa_format_info *f, const char *key, char ***values, int *n_values) {
|
2012-02-06 16:18:49 +05:30
|
|
|
const char *str;
|
2016-06-01 17:18:32 +05:30
|
|
|
pa_json_object *o;
|
|
|
|
|
const pa_json_object *o1;
|
2012-02-06 16:18:49 +05:30
|
|
|
int i, ret = -PA_ERR_INVALID;
|
|
|
|
|
|
|
|
|
|
pa_assert(f);
|
|
|
|
|
pa_assert(key);
|
|
|
|
|
pa_assert(values);
|
|
|
|
|
pa_assert(n_values);
|
|
|
|
|
|
|
|
|
|
str = pa_proplist_gets(f->plist, key);
|
|
|
|
|
if (!str)
|
|
|
|
|
return -PA_ERR_NOENTITY;
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
o = pa_json_parse(str);
|
2014-08-18 14:38:30 +02:00
|
|
|
if (!o) {
|
2013-12-18 18:28:55 +02:00
|
|
|
pa_log_debug("Failed to parse format info property '%s'.", key);
|
2012-02-06 16:18:49 +05:30
|
|
|
return -PA_ERR_INVALID;
|
2013-12-18 18:28:55 +02:00
|
|
|
}
|
2012-02-06 16:18:49 +05:30
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
if (pa_json_object_get_type(o) != PA_JSON_TYPE_ARRAY)
|
2012-02-06 16:18:49 +05:30
|
|
|
goto out;
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
*n_values = pa_json_object_get_array_length(o);
|
2012-02-06 16:18:49 +05:30
|
|
|
*values = pa_xnew(char *, *n_values);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < *n_values; i++) {
|
2016-06-01 17:18:32 +05:30
|
|
|
o1 = pa_json_object_get_array_member(o, i);
|
2012-02-06 16:18:49 +05:30
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
if (pa_json_object_get_type(o1) != PA_JSON_TYPE_STRING) {
|
2012-02-06 16:18:49 +05:30
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
(*values)[i] = pa_xstrdup(pa_json_object_get_string(o1));
|
2012-02-06 16:18:49 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
|
|
out:
|
2013-12-18 18:28:55 +02:00
|
|
|
if (ret < 0)
|
|
|
|
|
pa_log_debug("Format info property '%s' is not a valid string array.", key);
|
|
|
|
|
|
2016-06-01 17:18:39 +05:30
|
|
|
pa_json_object_free(o);
|
2012-02-06 16:18:49 +05:30
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pa_format_info_free_string_array(char **values, int n_values) {
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < n_values; i++)
|
|
|
|
|
pa_xfree(values[i]);
|
|
|
|
|
|
|
|
|
|
pa_xfree(values);
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-26 08:52:52 +05:30
|
|
|
int pa_format_info_get_sample_format(const pa_format_info *f, pa_sample_format_t *sf) {
|
|
|
|
|
int r;
|
|
|
|
|
char *sf_str;
|
|
|
|
|
pa_sample_format_t sf_local;
|
|
|
|
|
|
|
|
|
|
pa_assert(f);
|
|
|
|
|
pa_assert(sf);
|
|
|
|
|
|
|
|
|
|
r = pa_format_info_get_prop_string(f, PA_PROP_FORMAT_SAMPLE_FORMAT, &sf_str);
|
|
|
|
|
if (r < 0)
|
|
|
|
|
return r;
|
|
|
|
|
|
|
|
|
|
sf_local = pa_parse_sample_format(sf_str);
|
|
|
|
|
pa_xfree(sf_str);
|
|
|
|
|
|
|
|
|
|
if (!pa_sample_format_valid(sf_local)) {
|
|
|
|
|
pa_log_debug("Invalid sample format.");
|
|
|
|
|
return -PA_ERR_INVALID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*sf = sf_local;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int pa_format_info_get_rate(const pa_format_info *f, uint32_t *rate) {
|
|
|
|
|
int r;
|
|
|
|
|
int rate_local;
|
|
|
|
|
|
|
|
|
|
pa_assert(f);
|
|
|
|
|
pa_assert(rate);
|
|
|
|
|
|
|
|
|
|
r = pa_format_info_get_prop_int(f, PA_PROP_FORMAT_RATE, &rate_local);
|
|
|
|
|
if (r < 0)
|
|
|
|
|
return r;
|
|
|
|
|
|
|
|
|
|
if (!pa_sample_rate_valid(rate_local)) {
|
|
|
|
|
pa_log_debug("Invalid sample rate: %i", rate_local);
|
|
|
|
|
return -PA_ERR_INVALID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*rate = rate_local;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int pa_format_info_get_channels(const pa_format_info *f, uint8_t *channels) {
|
|
|
|
|
int r;
|
|
|
|
|
int channels_local;
|
|
|
|
|
|
|
|
|
|
pa_assert(f);
|
|
|
|
|
pa_assert(channels);
|
|
|
|
|
|
|
|
|
|
r = pa_format_info_get_prop_int(f, PA_PROP_FORMAT_CHANNELS, &channels_local);
|
|
|
|
|
if (r < 0)
|
|
|
|
|
return r;
|
|
|
|
|
|
|
|
|
|
if (!pa_channels_valid(channels_local)) {
|
|
|
|
|
pa_log_debug("Invalid channel count: %i", channels_local);
|
|
|
|
|
return -PA_ERR_INVALID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*channels = channels_local;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int pa_format_info_get_channel_map(const pa_format_info *f, pa_channel_map *map) {
|
|
|
|
|
int r;
|
|
|
|
|
char *map_str;
|
|
|
|
|
|
|
|
|
|
pa_assert(f);
|
|
|
|
|
pa_assert(map);
|
|
|
|
|
|
|
|
|
|
r = pa_format_info_get_prop_string(f, PA_PROP_FORMAT_CHANNEL_MAP, &map_str);
|
|
|
|
|
if (r < 0)
|
|
|
|
|
return r;
|
|
|
|
|
|
|
|
|
|
map = pa_channel_map_parse(map, map_str);
|
|
|
|
|
pa_xfree(map_str);
|
|
|
|
|
|
|
|
|
|
if (!map) {
|
|
|
|
|
pa_log_debug("Failed to parse channel map.");
|
|
|
|
|
return -PA_ERR_INVALID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-06 16:34:53 +05:30
|
|
|
void pa_format_info_set_sample_format(pa_format_info *f, pa_sample_format_t sf) {
|
|
|
|
|
pa_format_info_set_prop_string(f, PA_PROP_FORMAT_SAMPLE_FORMAT, pa_sample_format_to_string(sf));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pa_format_info_set_rate(pa_format_info *f, int rate) {
|
|
|
|
|
pa_format_info_set_prop_int(f, PA_PROP_FORMAT_RATE, rate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pa_format_info_set_channels(pa_format_info *f, int channels) {
|
|
|
|
|
pa_format_info_set_prop_int(f, PA_PROP_FORMAT_CHANNELS, channels);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pa_format_info_set_channel_map(pa_format_info *f, const pa_channel_map *map) {
|
|
|
|
|
char map_str[PA_CHANNEL_MAP_SNPRINT_MAX];
|
|
|
|
|
|
|
|
|
|
pa_channel_map_snprint(map_str, sizeof(map_str), map);
|
|
|
|
|
|
|
|
|
|
pa_format_info_set_prop_string(f, PA_PROP_FORMAT_CHANNEL_MAP, map_str);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-13 14:05:18 +05:30
|
|
|
void pa_format_info_set_prop_int(pa_format_info *f, const char *key, int value) {
|
|
|
|
|
pa_assert(f);
|
|
|
|
|
pa_assert(key);
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
pa_proplist_setf(f->plist, key, "%d", value);
|
2011-04-13 14:05:18 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pa_format_info_set_prop_int_array(pa_format_info *f, const char *key, const int *values, int n_values) {
|
2016-06-01 17:18:32 +05:30
|
|
|
pa_strbuf *buf;
|
|
|
|
|
char *str;
|
2011-04-13 14:05:18 +05:30
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
pa_assert(f);
|
|
|
|
|
pa_assert(key);
|
2016-06-01 17:18:32 +05:30
|
|
|
pa_assert(n_values > 0);
|
2011-04-13 14:05:18 +05:30
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
buf = pa_strbuf_new();
|
2011-04-13 14:05:18 +05:30
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
pa_strbuf_printf(buf, "[ %d", values[0]);
|
2011-04-13 14:05:18 +05:30
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
for (i = 1; i < n_values; i++)
|
|
|
|
|
pa_strbuf_printf(buf, ", %d", values[i]);
|
2011-04-13 14:05:18 +05:30
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
pa_strbuf_printf(buf, " ]");
|
|
|
|
|
str = pa_strbuf_to_string_free(buf);
|
|
|
|
|
|
|
|
|
|
pa_proplist_sets(f->plist, key, str);
|
|
|
|
|
pa_xfree (str);
|
2011-04-13 14:05:18 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pa_format_info_set_prop_int_range(pa_format_info *f, const char *key, int min, int max) {
|
|
|
|
|
pa_assert(f);
|
|
|
|
|
pa_assert(key);
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
pa_proplist_setf(f->plist, key, "{ \"" PA_JSON_MIN_KEY "\": %d, \"" PA_JSON_MAX_KEY "\": %d }",
|
|
|
|
|
min, max);
|
2011-04-13 14:05:18 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pa_format_info_set_prop_string(pa_format_info *f, const char *key, const char *value) {
|
|
|
|
|
pa_assert(f);
|
|
|
|
|
pa_assert(key);
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
pa_proplist_setf(f->plist, key, "\"%s\"", value);
|
2011-04-13 14:05:18 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pa_format_info_set_prop_string_array(pa_format_info *f, const char *key, const char **values, int n_values) {
|
2016-06-01 17:18:32 +05:30
|
|
|
pa_strbuf *buf;
|
|
|
|
|
char *str;
|
2011-04-13 14:05:18 +05:30
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
pa_assert(f);
|
|
|
|
|
pa_assert(key);
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
buf = pa_strbuf_new();
|
2011-04-13 14:05:18 +05:30
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
pa_strbuf_printf(buf, "[ \"%s\"", values[0]);
|
|
|
|
|
|
|
|
|
|
for (i = 1; i < n_values; i++)
|
|
|
|
|
pa_strbuf_printf(buf, ", \"%s\"", values[i]);
|
2011-04-13 14:05:18 +05:30
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
pa_strbuf_printf(buf, " ]");
|
|
|
|
|
str = pa_strbuf_to_string_free(buf);
|
2011-04-13 14:05:18 +05:30
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
pa_proplist_sets(f->plist, key, str);
|
|
|
|
|
pa_xfree (str);
|
2011-04-13 14:05:18 +05:30
|
|
|
}
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
static bool pa_json_is_fixed_type(pa_json_object *o) {
|
|
|
|
|
switch(pa_json_object_get_type(o)) {
|
|
|
|
|
case PA_JSON_TYPE_OBJECT:
|
|
|
|
|
case PA_JSON_TYPE_ARRAY:
|
2013-06-27 19:28:09 +02:00
|
|
|
return false;
|
2011-04-13 14:05:18 +05:30
|
|
|
|
|
|
|
|
default:
|
2013-06-27 19:28:09 +02:00
|
|
|
return true;
|
2011-04-13 14:05:18 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int pa_format_info_prop_compatible(const char *one, const char *two) {
|
2016-06-01 17:18:32 +05:30
|
|
|
pa_json_object *o1 = NULL, *o2 = NULL;
|
2011-04-13 14:05:18 +05:30
|
|
|
int i, ret = 0;
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
o1 = pa_json_parse(one);
|
2014-08-18 14:38:30 +02:00
|
|
|
if (!o1)
|
2011-04-13 14:05:18 +05:30
|
|
|
goto out;
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
o2 = pa_json_parse(two);
|
2014-08-18 14:38:30 +02:00
|
|
|
if (!o2)
|
2011-04-13 14:05:18 +05:30
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
/* We don't deal with both values being non-fixed - just because there is no immediate need (FIXME) */
|
2013-06-27 19:28:09 +02:00
|
|
|
pa_return_val_if_fail(pa_json_is_fixed_type(o1) || pa_json_is_fixed_type(o2), false);
|
2011-04-13 14:05:18 +05:30
|
|
|
|
|
|
|
|
if (pa_json_is_fixed_type(o1) && pa_json_is_fixed_type(o2)) {
|
2016-06-01 17:18:32 +05:30
|
|
|
ret = pa_json_object_equal(o1, o2);
|
2011-04-13 14:05:18 +05:30
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pa_json_is_fixed_type(o1)) {
|
2016-06-01 17:18:32 +05:30
|
|
|
pa_json_object *tmp = o2;
|
2011-04-13 14:05:18 +05:30
|
|
|
o2 = o1;
|
|
|
|
|
o1 = tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* o2 is now a fixed type, and o1 is not */
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
if (pa_json_object_get_type(o1) == PA_JSON_TYPE_ARRAY) {
|
|
|
|
|
for (i = 0; i < pa_json_object_get_array_length(o1); i++) {
|
|
|
|
|
if (pa_json_object_equal(pa_json_object_get_array_member(o1, i), o2)) {
|
2011-04-13 14:05:18 +05:30
|
|
|
ret = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-01 17:18:32 +05:30
|
|
|
} else if (pa_json_object_get_type(o1) == PA_JSON_TYPE_OBJECT) {
|
2011-04-13 14:05:18 +05:30
|
|
|
/* o1 should be a range type */
|
|
|
|
|
int min, max, v;
|
2016-06-01 17:18:32 +05:30
|
|
|
const pa_json_object *o_min = NULL, *o_max = NULL;
|
2011-04-13 14:05:18 +05:30
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
if (pa_json_object_get_type(o2) != PA_JSON_TYPE_INT) {
|
2011-04-13 14:05:18 +05:30
|
|
|
/* We don't support non-integer ranges */
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
if (!(o_min = pa_json_object_get_object_member(o1, PA_JSON_MIN_KEY)) ||
|
|
|
|
|
pa_json_object_get_type(o_min) != PA_JSON_TYPE_INT)
|
2011-04-13 14:05:18 +05:30
|
|
|
goto out;
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
if (!(o_max = pa_json_object_get_object_member(o1, PA_JSON_MAX_KEY)) ||
|
|
|
|
|
pa_json_object_get_type(o_max) != PA_JSON_TYPE_INT)
|
2011-04-13 14:05:18 +05:30
|
|
|
goto out;
|
|
|
|
|
|
2016-06-01 17:18:32 +05:30
|
|
|
v = pa_json_object_get_int(o2);
|
|
|
|
|
min = pa_json_object_get_int(o_min);
|
|
|
|
|
max = pa_json_object_get_int(o_max);
|
2011-04-13 14:05:18 +05:30
|
|
|
|
|
|
|
|
ret = v >= min && v <= max;
|
|
|
|
|
} else {
|
|
|
|
|
pa_log_warn("Got a format type that we don't support");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
if (o1)
|
2016-06-01 17:18:39 +05:30
|
|
|
pa_json_object_free(o1);
|
2011-04-13 14:05:18 +05:30
|
|
|
if (o2)
|
2016-06-01 17:18:39 +05:30
|
|
|
pa_json_object_free(o2);
|
2011-04-13 14:05:18 +05:30
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|