PA_LLIST_PREPEND(pa_stream, c->streams, s);
+ /* The context and stream will point at each other. We cannot ref count
+ both though since that will create a loop. */
+ pa_context_ref(s->context);
+
return s;
}
}
static void stream_free(pa_stream *s) {
- assert(s);
+ assert(s && s->context && !s->channel_valid);
+
+ PA_LLIST_REMOVE(pa_stream, s->context->streams, s);
+
+ pa_context_unref(s->context);
if (s->ipol_event) {
assert(s->mainloop);
if (s->channel_valid)
pa_dynarray_put((s->direction == PA_STREAM_PLAYBACK) ? s->context->playback_streams : s->context->record_streams, s->channel, NULL);
- PA_LLIST_REMOVE(pa_stream, s->context->streams, s);
+ s->channel = 0;
+ s->channel_valid = 0;
+
+ /* We keep a ref as long as we're connected */
pa_stream_unref(s);
}
s->channel_valid = 1;
pa_dynarray_put((s->direction == PA_STREAM_RECORD) ? s->context->record_streams : s->context->playback_streams, s->channel, s);
+ /* We add an extra ref as long as we're connected (i.e. in the dynarray) */
+ pa_stream_ref(s);
+
if (s->interpolate) {
struct timeval tv;
pa_operation_unref(pa_stream_get_latency_info(s, NULL, NULL));