+/* PA_MAX_FORMATS is defined in internal.h so we just define a sane value here */
+#define MAX_FORMATS 256
+
+static void set_sink_formats(pa_context *c, uint32_t sink, const char *str) {
+ pa_format_info *f_arr[MAX_FORMATS];
+ char *format = NULL;
+ const char *state = NULL;
+ int i = 0;
+
+ while ((format = pa_split(str, ";", &state))) {
+ pa_format_info *f = pa_format_info_from_string(pa_strip(format));
+
+ if (!f) {
+ pa_log(_("Failed to set format: invalid format string %s"), format);
+ goto error;
+ }
+
+ f_arr[i++] = f;
+ pa_xfree(format);
+ }
+
+ pa_operation_unref(pa_ext_device_restore_save_sink_formats(c, sink, i, f_arr, simple_callback, NULL));
+
+done:
+ if (format)
+ pa_xfree(format);
+ while(i--)
+ pa_format_info_free(f_arr[i]);
+
+ return;
+
+error:
+ while(i--)
+ pa_format_info_free(f_arr[i]);
+ quit(1);
+ goto done;
+}
+