+ s->state = PA_SINK_DISCONNECTED;
+}
+
+static void sink_free(struct pa_sink *s) {
+ assert(s && s->ref == 0);
+
+ if (s->state != PA_SINK_DISCONNECTED)
+ pa_sink_disconnect(s);
+
+ pa_log(__FILE__": freed %u \"%s\"\n", s->index, s->name);
+
+ pa_source_unref(s->monitor_source);
+ s->monitor_source = NULL;
+
+ pa_idxset_free(s->inputs, NULL, NULL);
+
+ pa_xfree(s->name);
+ pa_xfree(s->description);
+ pa_xfree(s);
+}
+
+void pa_sink_unref(struct pa_sink*s) {
+ assert(s && s->ref >= 1);
+
+ if (!(--s->ref))
+ sink_free(s);
+}
+
+struct pa_sink* pa_sink_ref(struct pa_sink *s) {
+ assert(s && s->ref >= 1);
+ s->ref++;
+ return s;