mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-08 13:29:59 -05:00
format: Add more property getters
This adds integer range/array and string array property getters to the pa_format_info API. Corresponding tests added as well to ensure the code is valgrind-clean. The corresponding functions are added to map-file manually for now.
This commit is contained in:
parent
c60f698f1e
commit
59af940dd5
3 changed files with 192 additions and 1 deletions
|
|
@ -327,6 +327,90 @@ int pa_format_info_get_prop_int(pa_format_info *f, const char *key, int *v) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int pa_format_info_get_prop_int_range(pa_format_info *f, const char *key, int *min, int *max) {
|
||||
const char *str;
|
||||
json_object *o, *o1;
|
||||
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;
|
||||
|
||||
o = json_tokener_parse(str);
|
||||
if (is_error(o))
|
||||
return -PA_ERR_INVALID;
|
||||
|
||||
if (json_object_get_type(o) != json_type_object)
|
||||
goto out;
|
||||
|
||||
if (!(o1 = json_object_object_get(o, PA_JSON_MIN_KEY)))
|
||||
goto out;
|
||||
|
||||
*min = json_object_get_int(o1);
|
||||
json_object_put(o1);
|
||||
|
||||
if (!(o1 = json_object_object_get(o, PA_JSON_MAX_KEY)))
|
||||
goto out;
|
||||
|
||||
*max = json_object_get_int(o1);
|
||||
json_object_put(o1);
|
||||
|
||||
ret = 0;
|
||||
|
||||
out:
|
||||
json_object_put(o);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pa_format_info_get_prop_int_array(pa_format_info *f, const char *key, int **values, int *n_values)
|
||||
{
|
||||
const char *str;
|
||||
json_object *o, *o1;
|
||||
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;
|
||||
|
||||
o = json_tokener_parse(str);
|
||||
if (is_error(o))
|
||||
return -PA_ERR_INVALID;
|
||||
|
||||
if (json_object_get_type(o) != json_type_array)
|
||||
goto out;
|
||||
|
||||
*n_values = json_object_array_length(o);
|
||||
*values = pa_xnew(int, *n_values);
|
||||
|
||||
for (i = 0; i < *n_values; i++) {
|
||||
o1 = json_object_array_get_idx(o, i);
|
||||
|
||||
if (json_object_get_type(o1) != json_type_int) {
|
||||
json_object_put(o1);
|
||||
goto out;
|
||||
}
|
||||
|
||||
(*values)[i] = json_object_get_int(o1);
|
||||
json_object_put(o1);
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
out:
|
||||
json_object_put(o);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pa_format_info_get_prop_string(pa_format_info *f, const char *key, char **v) {
|
||||
const char *str = NULL;
|
||||
json_object *o;
|
||||
|
|
@ -354,6 +438,59 @@ int pa_format_info_get_prop_string(pa_format_info *f, const char *key, char **v)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int pa_format_info_get_prop_string_array(pa_format_info *f, const char *key, char ***values, int *n_values)
|
||||
{
|
||||
const char *str;
|
||||
json_object *o, *o1;
|
||||
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;
|
||||
|
||||
o = json_tokener_parse(str);
|
||||
if (is_error(o))
|
||||
return -PA_ERR_INVALID;
|
||||
|
||||
if (json_object_get_type(o) != json_type_array)
|
||||
goto out;
|
||||
|
||||
*n_values = json_object_array_length(o);
|
||||
*values = pa_xnew(char *, *n_values);
|
||||
|
||||
for (i = 0; i < *n_values; i++) {
|
||||
o1 = json_object_array_get_idx(o, i);
|
||||
|
||||
if (json_object_get_type(o1) != json_type_string) {
|
||||
json_object_put(o1);
|
||||
goto out;
|
||||
}
|
||||
|
||||
(*values)[i] = pa_xstrdup(json_object_get_string(o1));
|
||||
json_object_put(o1);
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
out:
|
||||
json_object_put(o);
|
||||
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);
|
||||
}
|
||||
|
||||
void pa_format_info_set_prop_int(pa_format_info *f, const char *key, int value) {
|
||||
json_object *o;
|
||||
|
||||
|
|
|
|||
|
|
@ -124,9 +124,23 @@ int pa_format_info_to_sample_spec(pa_format_info *f, pa_sample_spec *ss, pa_chan
|
|||
|
||||
/** Gets an integer property from the given format info. Returns 0 on success and a negative integer on failure. \since 2.0 */
|
||||
int pa_format_info_get_prop_int(pa_format_info *f, const char *key, int *v);
|
||||
/** Gets an integer range property from the given format info. Returns 0 on success and a negative integer on failure.
|
||||
* \since 2.0 */
|
||||
int pa_format_info_get_prop_int_range(pa_format_info *f, const char *key, int *min, int *max);
|
||||
/** Gets an integer array property from the given format info. \a values contains the values and \a n_values contains the
|
||||
* number of elements. The caller must free \a values using \ref pa_xfree. Returns 0 on success and a negative integer on
|
||||
* failure. \since 2.0 */
|
||||
int pa_format_info_get_prop_int_array(pa_format_info *f, const char *key, int **values, int *n_values);
|
||||
/** Gets a string property from the given format info. The caller must free the returned string using \ref pa_xfree. Returns
|
||||
* 0 on success and a negative integer on failure. \since 2.0 */
|
||||
int pa_format_info_get_prop_string(pa_format_info *f, const char *key, char **v);
|
||||
/** Gets a string array property from the given format info. \a values contains the values and \a n_values contains
|
||||
* the number of elements. The caller must free \a values using \ref pa_format_info_free_string_array. Returns 0 on success and
|
||||
* a negative integer on failure. \since 2.0 */
|
||||
int pa_format_info_get_prop_string_array(pa_format_info *f, const char *key, char ***values, int *n_values);
|
||||
|
||||
/** Frees a string array returned by \ref pa_format_info_get_prop_string_array. \since 2.0 */
|
||||
void pa_format_info_free_string_array(char **values, int n_values);
|
||||
|
||||
/** Sets an integer property on the given format info. \since 1.0 */
|
||||
void pa_format_info_set_prop_int(pa_format_info *f, const char *key, int value);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue