add refernce counting for sinks, sources, sink-inputs and source-outputs

git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@200 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
Lennart Poettering 2004-09-14 20:53:25 +00:00
parent 8c6593dabf
commit 6e019795bf
27 changed files with 426 additions and 132 deletions

View file

@ -49,6 +49,8 @@ struct pa_source_output* pa_source_output_new(struct pa_source *s, const char *n
return NULL;
o = pa_xmalloc(sizeof(struct pa_source_output));
o->ref = 1;
o->state = PA_SOURCE_OUTPUT_RUNNING;
o->name = pa_xstrdup(name);
o->client = NULL;
o->owner = NULL;
@ -71,27 +73,55 @@ struct pa_source_output* pa_source_output_new(struct pa_source *s, const char *n
return o;
}
void pa_source_output_free(struct pa_source_output* o) {
assert(o);
assert(o->source && o->source->core);
void pa_source_output_disconnect(struct pa_source_output*o) {
assert(o && o->state == PA_SOURCE_OUTPUT_RUNNING && o->source && o->source->core);
pa_idxset_remove_by_data(o->source->core->source_outputs, o, NULL);
pa_idxset_remove_by_data(o->source->outputs, o, NULL);
pa_subscription_post(o->source->core, PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT|PA_SUBSCRIPTION_EVENT_REMOVE, o->index);
o->source = NULL;
o->push = NULL;
o->kill = NULL;
o->state = PA_SOURCE_OUTPUT_DISCONNECTED;
}
static void source_output_free(struct pa_source_output* o) {
assert(o);
if (o->state != PA_SOURCE_OUTPUT_DISCONNECTED)
pa_source_output_disconnect(o);
if (o->resampler)
pa_resampler_free(o->resampler);
pa_subscription_post(o->source->core, PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT|PA_SUBSCRIPTION_EVENT_REMOVE, o->index);
pa_xfree(o->name);
pa_xfree(o);
}
void pa_source_output_kill(struct pa_source_output*i) {
assert(i);
if (i->kill)
i->kill(i);
void pa_source_output_unref(struct pa_source_output* o) {
assert(o && o->ref >= 1);
if (!(--o->ref))
source_output_free(o);
}
struct pa_source_output* pa_source_output_ref(struct pa_source_output *o) {
assert(o && o->ref >= 1);
o->ref++;
return o;
}
void pa_source_output_kill(struct pa_source_output*o) {
assert(o && o->ref >= 1);
if (o->kill)
o->kill(o);
}
void pa_source_output_push(struct pa_source_output *o, const struct pa_memchunk *chunk) {
@ -111,3 +141,9 @@ void pa_source_output_push(struct pa_source_output *o, const struct pa_memchunk
o->push(o, &rchunk);
pa_memblock_unref(rchunk.memblock);
}
void pa_source_output_set_name(struct pa_source_output *o, const char *name) {
assert(o && o->ref >= 1);
pa_xfree(o->name);
o->name = pa_xstrdup(name);
}