+static int check_passthrough_connection(pa_sink_input_flags_t flags, pa_sink *dest) {
+
+ if (dest->flags & PA_SINK_PASSTHROUGH) {
+
+ if (pa_idxset_size(dest->inputs) > 0) {
+
+ pa_sink_input *alt_i;
+ uint32_t idx;
+
+ alt_i = pa_idxset_first(dest->inputs, &idx);
+
+ /* only need to check the first input is not PASSTHROUGH */
+ if (alt_i->flags & PA_SINK_INPUT_PASSTHROUGH) {
+ pa_log_warn("Sink is already connected to PASSTHROUGH input");
+ return -PA_ERR_BUSY;
+ }
+
+ /* Current inputs are PCM, check new input is not PASSTHROUGH */
+ if (flags & PA_SINK_INPUT_PASSTHROUGH) {
+ pa_log_warn("Sink is already connected, cannot accept new PASSTHROUGH INPUT");
+ return -PA_ERR_BUSY;
+ }
+ }
+
+ } else {
+ if (flags & PA_SINK_INPUT_PASSTHROUGH) {
+ pa_log_warn("Cannot connect PASSTHROUGH sink input to sink without PASSTHROUGH capabilities");
+ return -PA_ERR_INVALID;
+ }
+ }
+ return PA_OK;
+}
+