json: remove json from public API
[platform/upstream/pulseaudio.git] / src / pulse / format.c
index 424df0e..00bae2d 100644 (file)
   General Public License for more details.
 
   You should have received a copy of the GNU Lesser General Public License
-  along with PulseAudio; if not, write to the Free Software
-  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
-  USA.
+  along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
 ***/
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
 
-#include <json.h>
-
 #include <pulse/internal.h>
 #include <pulse/xmalloc.h>
 
 #include <pulsecore/core-format.h>
 #include <pulsecore/core-util.h>
 #include <pulsecore/i18n.h>
+#include <pulsecore/json.h>
 #include <pulsecore/macro.h>
+#include <pulsecore/strbuf.h>
 
 #include "format.h"
 
@@ -49,6 +47,8 @@ static const char* const _encoding_str_table[]= {
     [PA_ENCODING_MPEG_IEC61937] = "mpeg-iec61937",
     [PA_ENCODING_DTS_IEC61937] = "dts-iec61937",
     [PA_ENCODING_MPEG2_AAC_IEC61937] = "mpeg2-aac-iec61937",
+    [PA_ENCODING_TRUEHD_IEC61937] = "truehd-iec61937",
+    [PA_ENCODING_DTSHD_IEC61937] = "dtshd-iec61937",
     [PA_ENCODING_ANY] = "any",
 };
 
@@ -171,7 +171,7 @@ error:
     goto out;
 }
 
-int pa_format_info_is_compatible(pa_format_info *first, pa_format_info *second) {
+int pa_format_info_is_compatible(const pa_format_info *first, const pa_format_info *second) {
     const char *key;
     void *state = NULL;
 
@@ -194,7 +194,7 @@ int pa_format_info_is_compatible(pa_format_info *first, pa_format_info *second)
     return true;
 }
 
-pa_format_info* pa_format_info_from_sample_spec(pa_sample_spec *ss, pa_channel_map *map) {
+pa_format_info* pa_format_info_from_sample_spec(const pa_sample_spec *ss, const pa_channel_map *map) {
     char cm[PA_CHANNEL_MAP_SNPRINT_MAX];
     pa_format_info *f;
 
@@ -217,10 +217,7 @@ pa_format_info* pa_format_info_from_sample_spec(pa_sample_spec *ss, pa_channel_m
 }
 
 /* For PCM streams */
-int pa_format_info_to_sample_spec(pa_format_info *f, pa_sample_spec *ss, pa_channel_map *map) {
-    char *m = NULL;
-    int ret = -PA_ERR_INVALID;
-
+int pa_format_info_to_sample_spec(const pa_format_info *f, pa_sample_spec *ss, pa_channel_map *map) {
     pa_assert(f);
     pa_assert(ss);
 
@@ -228,32 +225,21 @@ int pa_format_info_to_sample_spec(pa_format_info *f, pa_sample_spec *ss, pa_chan
         return pa_format_info_to_sample_spec_fake(f, ss, map);
 
     if (pa_format_info_get_sample_format(f, &ss->format) < 0)
-        goto out;
+        return -PA_ERR_INVALID;
     if (pa_format_info_get_rate(f, &ss->rate) < 0)
-        goto out;
+        return -PA_ERR_INVALID;
     if (pa_format_info_get_channels(f, &ss->channels) < 0)
-        goto out;
-
-    if (map) {
-        pa_channel_map_init(map);
-
-        if (pa_format_info_get_prop_string(f, PA_PROP_FORMAT_CHANNEL_MAP, &m) == 0)
-            if (pa_channel_map_parse(map, m) == NULL)
-                goto out;
-    }
-
-    ret = 0;
-
-out:
-    if (m)
-        pa_xfree(m);
+        return -PA_ERR_INVALID;
+    if (map && pa_format_info_get_channel_map(f, map) < 0)
+        return -PA_ERR_INVALID;
 
-    return ret;
+    return 0;
 }
 
-pa_prop_type_t pa_format_info_get_prop_type(pa_format_info *f, const char *key) {
+pa_prop_type_t pa_format_info_get_prop_type(const pa_format_info *f, const char *key) {
     const char *str;
-    json_object *o, *o1;
+    pa_json_object *o;
+    const pa_json_object *o1;
     pa_prop_type_t type;
 
     pa_assert(f);
@@ -263,55 +249,50 @@ pa_prop_type_t pa_format_info_get_prop_type(pa_format_info *f, const char *key)
     if (!str)
         return PA_PROP_TYPE_INVALID;
 
-    o = json_tokener_parse(str);
-    if (is_error(o))
+    o = pa_json_parse(str);
+    if (!o)
         return PA_PROP_TYPE_INVALID;
 
-    switch (json_object_get_type(o)) {
-        case json_type_int:
+    switch (pa_json_object_get_type(o)) {
+        case PA_JSON_TYPE_INT:
             type = PA_PROP_TYPE_INT;
             break;
 
-        case json_type_string:
+        case PA_JSON_TYPE_STRING:
             type = PA_PROP_TYPE_STRING;
             break;
 
-        case json_type_array:
-            if (json_object_array_length(o) == 0) {
+        case PA_JSON_TYPE_ARRAY:
+            if (pa_json_object_get_array_length(o) == 0) {
                 /* 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;
             }
 
-            o1 = json_object_array_get_idx(o, 1);
+            o1 = pa_json_object_get_array_member(o, 0);
 
-            if (json_object_get_type(o1) == json_type_int)
+            if (pa_json_object_get_type(o1) == PA_JSON_TYPE_INT)
                 type = PA_PROP_TYPE_INT_ARRAY;
-            else if (json_object_get_type(o1) == json_type_string)
+            else if (pa_json_object_get_type(o1) == PA_JSON_TYPE_STRING)
                 type = PA_PROP_TYPE_STRING_ARRAY;
             else
                 type = PA_PROP_TYPE_INVALID;
 
-            json_object_put(o1);
             break;
 
-        case json_type_object:
+        case PA_JSON_TYPE_OBJECT:
             /* We actually know at this point that it's a int range, but let's
              * confirm. */
-            o1 = json_object_object_get(o, PA_JSON_MIN_KEY);
-            if (!o1) {
+            if (!pa_json_object_get_object_member(o, PA_JSON_MIN_KEY)) {
                 type = PA_PROP_TYPE_INVALID;
                 break;
             }
-            json_object_put(o1);
 
-            o1 = json_object_object_get(o, PA_JSON_MAX_KEY);
-            if (!o1) {
+            if (!pa_json_object_get_object_member(o, PA_JSON_MAX_KEY)) {
                 type = PA_PROP_TYPE_INVALID;
                 break;
             }
-            json_object_put(o1);
 
             type = PA_PROP_TYPE_INT_RANGE;
             break;
@@ -321,13 +302,13 @@ pa_prop_type_t pa_format_info_get_prop_type(pa_format_info *f, const char *key)
             break;
     }
 
-    json_object_put(o);
+    pa_json_object_free(o);
     return type;
 }
 
-int pa_format_info_get_prop_int(pa_format_info *f, const char *key, int *v) {
+int pa_format_info_get_prop_int(const pa_format_info *f, const char *key, int *v) {
     const char *str;
-    json_object *o;
+    pa_json_object *o;
 
     pa_assert(f);
     pa_assert(key);
@@ -337,24 +318,28 @@ int pa_format_info_get_prop_int(pa_format_info *f, const char *key, int *v) {
     if (!str)
         return -PA_ERR_NOENTITY;
 
-    o = json_tokener_parse(str);
-    if (is_error(o))
+    o = pa_json_parse(str);
+    if (!o) {
+        pa_log_debug("Failed to parse format info property '%s'.", key);
         return -PA_ERR_INVALID;
+    }
 
-    if (json_object_get_type(o) != json_type_int) {
-        json_object_put(o);
+    if (pa_json_object_get_type(o) != PA_JSON_TYPE_INT) {
+        pa_log_debug("Format info property '%s' type is not int.", key);
+        pa_json_object_free(o);
         return -PA_ERR_INVALID;
     }
 
-    *v = json_object_get_int(o);
-    json_object_put(o);
+    *v = pa_json_object_get_int(o);
+    pa_json_object_free(o);
 
     return 0;
 }
 
-int pa_format_info_get_prop_int_range(pa_format_info *f, const char *key, int *min, int *max) {
+int pa_format_info_get_prop_int_range(const pa_format_info *f, const char *key, int *min, int *max) {
     const char *str;
-    json_object *o, *o1;
+    pa_json_object *o;
+    const pa_json_object *o1;
     int ret = -PA_ERR_INVALID;
 
     pa_assert(f);
@@ -366,35 +351,41 @@ int pa_format_info_get_prop_int_range(pa_format_info *f, const char *key, int *m
     if (!str)
         return -PA_ERR_NOENTITY;
 
-    o = json_tokener_parse(str);
-    if (is_error(o))
+    o = pa_json_parse(str);
+    if (!o) {
+        pa_log_debug("Failed to parse format info property '%s'.", key);
         return -PA_ERR_INVALID;
+    }
 
-    if (json_object_get_type(o) != json_type_object)
+    if (pa_json_object_get_type(o) != PA_JSON_TYPE_OBJECT)
         goto out;
 
-    if (!(o1 = json_object_object_get(o, PA_JSON_MIN_KEY)))
+    if (!(o1 = pa_json_object_get_object_member(o, PA_JSON_MIN_KEY)) ||
+            (pa_json_object_get_type(o1) != PA_JSON_TYPE_INT))
         goto out;
 
-    *min = json_object_get_int(o1);
-    json_object_put(o1);
+    *min = pa_json_object_get_int(o1);
 
-    if (!(o1 = json_object_object_get(o, PA_JSON_MAX_KEY)))
+    if (!(o1 = pa_json_object_get_object_member(o, PA_JSON_MAX_KEY)) ||
+            (pa_json_object_get_type(o1) != PA_JSON_TYPE_INT))
         goto out;
 
-    *max = json_object_get_int(o1);
-    json_object_put(o1);
+    *max = pa_json_object_get_int(o1);
 
     ret = 0;
 
 out:
-    json_object_put(o);
+    if (ret < 0)
+        pa_log_debug("Format info property '%s' is not a valid int range.", key);
+
+    pa_json_object_free(o);
     return ret;
 }
 
-int pa_format_info_get_prop_int_array(pa_format_info *f, const char *key, int **values, int *n_values) {
+int pa_format_info_get_prop_int_array(const pa_format_info *f, const char *key, int **values, int *n_values) {
     const char *str;
-    json_object *o, *o1;
+    pa_json_object *o;
+    const pa_json_object *o1;
     int i, ret = -PA_ERR_INVALID;
 
     pa_assert(f);
@@ -406,38 +397,41 @@ int pa_format_info_get_prop_int_array(pa_format_info *f, const char *key, int **
     if (!str)
         return -PA_ERR_NOENTITY;
 
-    o = json_tokener_parse(str);
-    if (is_error(o))
+    o = pa_json_parse(str);
+    if (!o) {
+        pa_log_debug("Failed to parse format info property '%s'.", key);
         return -PA_ERR_INVALID;
+    }
 
-    if (json_object_get_type(o) != json_type_array)
+    if (pa_json_object_get_type(o) != PA_JSON_TYPE_ARRAY)
         goto out;
 
-    *n_values = json_object_array_length(o);
+    *n_values = pa_json_object_get_array_length(o);
     *values = pa_xnew(int, *n_values);
 
     for (i = 0; i < *n_values; i++) {
-        o1 = json_object_array_get_idx(o, i);
+        o1 = pa_json_object_get_array_member(o, i);
 
-        if (json_object_get_type(o1) != json_type_int) {
-            json_object_put(o1);
+        if (pa_json_object_get_type(o1) != PA_JSON_TYPE_INT) {
             goto out;
         }
 
-        (*values)[i] = json_object_get_int(o1);
-        json_object_put(o1);
+        (*values)[i] = pa_json_object_get_int(o1);
     }
 
     ret = 0;
 
 out:
-    json_object_put(o);
+    if (ret < 0)
+        pa_log_debug("Format info property '%s' is not a valid int array.", key);
+
+    pa_json_object_free(o);
     return ret;
 }
 
-int pa_format_info_get_prop_string(pa_format_info *f, const char *key, char **v) {
+int pa_format_info_get_prop_string(const pa_format_info *f, const char *key, char **v) {
     const char *str = NULL;
-    json_object *o;
+    pa_json_object *o;
 
     pa_assert(f);
     pa_assert(key);
@@ -447,24 +441,28 @@ int pa_format_info_get_prop_string(pa_format_info *f, const char *key, char **v)
     if (!str)
         return -PA_ERR_NOENTITY;
 
-    o = json_tokener_parse(str);
-    if (is_error(o))
+    o = pa_json_parse(str);
+    if (!o) {
+        pa_log_debug("Failed to parse format info property '%s'.", key);
         return -PA_ERR_INVALID;
+    }
 
-    if (json_object_get_type(o) != json_type_string) {
-        json_object_put(o);
+    if (pa_json_object_get_type(o) != PA_JSON_TYPE_STRING) {
+        pa_log_debug("Format info property '%s' type is not string.", key);
+        pa_json_object_free(o);
         return -PA_ERR_INVALID;
     }
 
-    *v = pa_xstrdup(json_object_get_string(o));
-    json_object_put(o);
+    *v = pa_xstrdup(pa_json_object_get_string(o));
+    pa_json_object_free(o);
 
     return 0;
 }
 
-int pa_format_info_get_prop_string_array(pa_format_info *f, const char *key, char ***values, int *n_values) {
+int pa_format_info_get_prop_string_array(const pa_format_info *f, const char *key, char ***values, int *n_values) {
     const char *str;
-    json_object *o, *o1;
+    pa_json_object *o;
+    const pa_json_object *o1;
     int i, ret = -PA_ERR_INVALID;
 
     pa_assert(f);
@@ -476,32 +474,35 @@ int pa_format_info_get_prop_string_array(pa_format_info *f, const char *key, cha
     if (!str)
         return -PA_ERR_NOENTITY;
 
-    o = json_tokener_parse(str);
-    if (is_error(o))
+    o = pa_json_parse(str);
+    if (!o) {
+        pa_log_debug("Failed to parse format info property '%s'.", key);
         return -PA_ERR_INVALID;
+    }
 
-    if (json_object_get_type(o) != json_type_array)
+    if (pa_json_object_get_type(o) != PA_JSON_TYPE_ARRAY)
         goto out;
 
-    *n_values = json_object_array_length(o);
+    *n_values = pa_json_object_get_array_length(o);
     *values = pa_xnew(char *, *n_values);
 
     for (i = 0; i < *n_values; i++) {
-        o1 = json_object_array_get_idx(o, i);
+        o1 = pa_json_object_get_array_member(o, i);
 
-        if (json_object_get_type(o1) != json_type_string) {
-            json_object_put(o1);
+        if (pa_json_object_get_type(o1) != PA_JSON_TYPE_STRING) {
             goto out;
         }
 
-        (*values)[i] = pa_xstrdup(json_object_get_string(o1));
-        json_object_put(o1);
+        (*values)[i] = pa_xstrdup(pa_json_object_get_string(o1));
     }
 
     ret = 0;
 
 out:
-    json_object_put(o);
+    if (ret < 0)
+        pa_log_debug("Format info property '%s' is not a valid string array.", key);
+
+    pa_json_object_free(o);
     return ret;
 }
 
@@ -514,6 +515,95 @@ void pa_format_info_free_string_array(char **values, int n_values) {
     pa_xfree(values);
 }
 
+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;
+}
+
 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));
 }
@@ -535,85 +625,76 @@ void pa_format_info_set_channel_map(pa_format_info *f, const pa_channel_map *map
 }
 
 void pa_format_info_set_prop_int(pa_format_info *f, const char *key, int value) {
-    json_object *o;
-
     pa_assert(f);
     pa_assert(key);
 
-    o = json_object_new_int(value);
-
-    pa_proplist_sets(f->plist, key, json_object_to_json_string(o));
-
-    json_object_put(o);
+    pa_proplist_setf(f->plist, key, "%d", value);
 }
 
 void pa_format_info_set_prop_int_array(pa_format_info *f, const char *key, const int *values, int n_values) {
-    json_object *o;
+    pa_strbuf *buf;
+    char *str;
     int i;
 
     pa_assert(f);
     pa_assert(key);
+    pa_assert(n_values > 0);
 
-    o = json_object_new_array();
+    buf = pa_strbuf_new();
 
-    for (i = 0; i < n_values; i++)
-        json_object_array_add(o, json_object_new_int(values[i]));
+    pa_strbuf_printf(buf, "[ %d", values[0]);
+
+    for (i = 1; i < n_values; i++)
+        pa_strbuf_printf(buf, ", %d", values[i]);
 
-    pa_proplist_sets(f->plist, key, json_object_to_json_string(o));
+    pa_strbuf_printf(buf, " ]");
+    str = pa_strbuf_to_string_free(buf);
 
-    json_object_put(o);
+    pa_proplist_sets(f->plist, key, str);
+    pa_xfree (str);
 }
 
 void pa_format_info_set_prop_int_range(pa_format_info *f, const char *key, int min, int max) {
-    json_object *o;
-
     pa_assert(f);
     pa_assert(key);
 
-    o = json_object_new_object();
-
-    json_object_object_add(o, PA_JSON_MIN_KEY, json_object_new_int(min));
-    json_object_object_add(o, PA_JSON_MAX_KEY, json_object_new_int(max));
-
-    pa_proplist_sets(f->plist, key, json_object_to_json_string(o));
-
-    json_object_put(o);
+    pa_proplist_setf(f->plist, key, "{ \"" PA_JSON_MIN_KEY "\": %d, \"" PA_JSON_MAX_KEY "\": %d }",
+            min, max);
 }
 
 void pa_format_info_set_prop_string(pa_format_info *f, const char *key, const char *value) {
-    json_object *o;
-
     pa_assert(f);
     pa_assert(key);
 
-    o = json_object_new_string(value);
-
-    pa_proplist_sets(f->plist, key, json_object_to_json_string(o));
-
-    json_object_put(o);
+    pa_proplist_setf(f->plist, key, "\"%s\"", value);
 }
 
 void pa_format_info_set_prop_string_array(pa_format_info *f, const char *key, const char **values, int n_values) {
-    json_object *o;
+    pa_strbuf *buf;
+    char *str;
     int i;
 
     pa_assert(f);
     pa_assert(key);
 
-    o = json_object_new_array();
+    buf = pa_strbuf_new();
 
-    for (i = 0; i < n_values; i++)
-        json_object_array_add(o, json_object_new_string(values[i]));
+    pa_strbuf_printf(buf, "[ \"%s\"", values[0]);
+
+    for (i = 1; i < n_values; i++)
+        pa_strbuf_printf(buf, ", \"%s\"", values[i]);
 
-    pa_proplist_sets(f->plist, key, json_object_to_json_string(o));
+    pa_strbuf_printf(buf, " ]");
+    str = pa_strbuf_to_string_free(buf);
 
-    json_object_put(o);
+    pa_proplist_sets(f->plist, key, str);
+    pa_xfree (str);
 }
 
-static bool pa_json_is_fixed_type(json_object *o) {
-    switch(json_object_get_type(o)) {
-        case json_type_object:
-        case json_type_array:
+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:
             return false;
 
         default:
@@ -621,67 +702,62 @@ static bool pa_json_is_fixed_type(json_object *o) {
     }
 }
 
-static int pa_json_value_equal(json_object *o1, json_object *o2) {
-    return (json_object_get_type(o1) == json_object_get_type(o2)) &&
-        pa_streq(json_object_to_json_string(o1), json_object_to_json_string(o2));
-}
-
 static int pa_format_info_prop_compatible(const char *one, const char *two) {
-    json_object *o1 = NULL, *o2 = NULL;
+    pa_json_object *o1 = NULL, *o2 = NULL;
     int i, ret = 0;
 
-    o1 = json_tokener_parse(one);
-    if (is_error(o1))
+    o1 = pa_json_parse(one);
+    if (!o1)
         goto out;
 
-    o2 = json_tokener_parse(two);
-    if (is_error(o2))
+    o2 = pa_json_parse(two);
+    if (!o2)
         goto out;
 
     /* We don't deal with both values being non-fixed - just because there is no immediate need (FIXME) */
     pa_return_val_if_fail(pa_json_is_fixed_type(o1) || pa_json_is_fixed_type(o2), false);
 
     if (pa_json_is_fixed_type(o1) && pa_json_is_fixed_type(o2)) {
-        ret = pa_json_value_equal(o1, o2);
+        ret = pa_json_object_equal(o1, o2);
         goto out;
     }
 
     if (pa_json_is_fixed_type(o1)) {
-        json_object *tmp = o2;
+        pa_json_object *tmp = o2;
         o2 = o1;
         o1 = tmp;
     }
 
     /* o2 is now a fixed type, and o1 is not */
 
-    if (json_object_get_type(o1) == json_type_array) {
-        for (i = 0; i < json_object_array_length(o1); i++) {
-            if (pa_json_value_equal(json_object_array_get_idx(o1, i), o2)) {
+    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)) {
                 ret = 1;
                 break;
             }
         }
-    } else if (json_object_get_type(o1) == json_type_object) {
+    } else if (pa_json_object_get_type(o1) == PA_JSON_TYPE_OBJECT) {
         /* o1 should be a range type */
         int min, max, v;
-        json_object *o_min = NULL, *o_max = NULL;
+        const pa_json_object *o_min = NULL, *o_max = NULL;
 
-        if (json_object_get_type(o2) != json_type_int) {
+        if (pa_json_object_get_type(o2) != PA_JSON_TYPE_INT) {
             /* We don't support non-integer ranges */
             goto out;
         }
 
-        o_min = json_object_object_get(o1, PA_JSON_MIN_KEY);
-        if (!o_min || json_object_get_type(o_min) != json_type_int)
+        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)
             goto out;
 
-        o_max = json_object_object_get(o1, PA_JSON_MAX_KEY);
-        if (!o_max || json_object_get_type(o_max) != json_type_int)
+        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)
             goto out;
 
-        v = json_object_get_int(o2);
-        min = json_object_get_int(o_min);
-        max = json_object_get_int(o_max);
+        v = pa_json_object_get_int(o2);
+        min = pa_json_object_get_int(o_min);
+        max = pa_json_object_get_int(o_max);
 
         ret = v >= min && v <= max;
     } else {
@@ -690,9 +766,9 @@ static int pa_format_info_prop_compatible(const char *one, const char *two) {
 
 out:
     if (o1)
-        json_object_put(o1);
+        pa_json_object_free(o1);
     if (o2)
-        json_object_put(o2);
+        pa_json_object_free(o2);
 
     return ret;
 }