diff options
author | Lennart Poettering <lennart@poettering.net> | 2004-09-14 20:53:25 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2004-09-14 20:53:25 +0000 |
commit | 6e019795bff589ef0a867772975e34da78fffefb (patch) | |
tree | 46beb189b4048d516d92f6002f91135360342334 /polyp/source-output.c | |
parent | 8c6593dabf3253e20fead143855267570a403c9a (diff) |
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
Diffstat (limited to 'polyp/source-output.c')
-rw-r--r-- | polyp/source-output.c | 56 |
1 files changed, 46 insertions, 10 deletions
diff --git a/polyp/source-output.c b/polyp/source-output.c index 55448b5c..3abf9c18 100644 --- a/polyp/source-output.c +++ b/polyp/source-output.c @@ -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); +} |