From f44ba092651aa75055e109e04b4164ea92ae7fdc Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 19 Jun 2006 21:53:48 +0000 Subject: big s/polyp/pulse/g git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1033 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/pulsecore/source.c | 313 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 313 insertions(+) create mode 100644 src/pulsecore/source.c (limited to 'src/pulsecore/source.c') diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c new file mode 100644 index 00000000..84151a92 --- /dev/null +++ b/src/pulsecore/source.c @@ -0,0 +1,313 @@ +/* $Id$ */ + +/*** + This file is part of PulseAudio. + + PulseAudio is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published + by the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + PulseAudio is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with PulseAudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include "source.h" + +#define CHECK_VALIDITY_RETURN_NULL(condition) \ +do {\ +if (!(condition)) \ + return NULL; \ +} while (0) + +pa_source* pa_source_new( + pa_core *core, + const char *driver, + const char *name, + int fail, + const pa_sample_spec *spec, + const pa_channel_map *map) { + + pa_source *s; + char st[256]; + int r; + pa_channel_map tmap; + + assert(core); + assert(name); + assert(spec); + + CHECK_VALIDITY_RETURN_NULL(pa_sample_spec_valid(spec)); + + if (!map) + map = pa_channel_map_init_auto(&tmap, spec->channels, PA_CHANNEL_MAP_DEFAULT); + + CHECK_VALIDITY_RETURN_NULL(map && pa_channel_map_valid(map)); + CHECK_VALIDITY_RETURN_NULL(map->channels == spec->channels); + CHECK_VALIDITY_RETURN_NULL(!driver || pa_utf8_valid(driver)); + CHECK_VALIDITY_RETURN_NULL(pa_utf8_valid(name) && *name); + + s = pa_xnew(pa_source, 1); + + if (!(name = pa_namereg_register(core, name, PA_NAMEREG_SOURCE, s, fail))) { + pa_xfree(s); + return NULL; + } + + s->ref = 1; + s->core = core; + s->state = PA_SOURCE_RUNNING; + s->name = pa_xstrdup(name); + s->description = NULL; + s->driver = pa_xstrdup(driver); + s->owner = NULL; + + s->sample_spec = *spec; + s->channel_map = *map; + + s->outputs = pa_idxset_new(NULL, NULL); + s->monitor_of = NULL; + + pa_cvolume_reset(&s->sw_volume, spec->channels); + pa_cvolume_reset(&s->hw_volume, spec->channels); + s->sw_muted = 0; + s->hw_muted = 0; + + s->get_latency = NULL; + s->notify = NULL; + s->set_hw_volume = NULL; + s->get_hw_volume = NULL; + s->set_hw_mute = NULL; + s->get_hw_mute = NULL; + s->userdata = NULL; + + r = pa_idxset_put(core->sources, s, &s->index); + assert(s->index != PA_IDXSET_INVALID && r >= 0); + + pa_sample_spec_snprint(st, sizeof(st), spec); + pa_log_info(__FILE__": created %u \"%s\" with sample spec \"%s\"", s->index, s->name, st); + + pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_SOURCE | PA_SUBSCRIPTION_EVENT_NEW, s->index); + + return s; +} + +void pa_source_disconnect(pa_source *s) { + pa_source_output *o, *j = NULL; + + assert(s); + assert(s->state == PA_SOURCE_RUNNING); + + pa_namereg_unregister(s->core, s->name); + + while ((o = pa_idxset_first(s->outputs, NULL))) { + assert(o != j); + pa_source_output_kill(o); + j = o; + } + + pa_idxset_remove_by_data(s->core->sources, s, NULL); + + s->get_latency = NULL; + s->notify = NULL; + s->get_hw_volume = NULL; + s->set_hw_volume = NULL; + s->set_hw_mute = NULL; + s->get_hw_mute = NULL; + + s->state = PA_SOURCE_DISCONNECTED; + pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE | PA_SUBSCRIPTION_EVENT_REMOVE, s->index); +} + +static void source_free(pa_source *s) { + assert(s); + assert(!s->ref); + + if (s->state != PA_SOURCE_DISCONNECTED) + pa_source_disconnect(s); + + pa_log_info(__FILE__": freed %u \"%s\"", s->index, s->name); + + pa_idxset_free(s->outputs, NULL, NULL); + + pa_xfree(s->name); + pa_xfree(s->description); + pa_xfree(s->driver); + pa_xfree(s); +} + +void pa_source_unref(pa_source *s) { + assert(s); + assert(s->ref >= 1); + + if (!(--s->ref)) + source_free(s); +} + +pa_source* pa_source_ref(pa_source *s) { + assert(s); + assert(s->ref >= 1); + + s->ref++; + return s; +} + +void pa_source_notify(pa_source*s) { + assert(s); + assert(s->ref >= 1); + + if (s->notify) + s->notify(s); +} + +static int do_post(void *p, PA_GCC_UNUSED uint32_t idx, PA_GCC_UNUSED int *del, void*userdata) { + pa_source_output *o = p; + const pa_memchunk *chunk = userdata; + + assert(o); + assert(chunk); + + pa_source_output_push(o, chunk); + return 0; +} + +void pa_source_post(pa_source*s, const pa_memchunk *chunk) { + assert(s); + assert(s->ref >= 1); + assert(chunk); + + pa_source_ref(s); + + if (s->sw_muted || !pa_cvolume_is_norm(&s->sw_volume)) { + pa_memchunk vchunk = *chunk; + + pa_memblock_ref(vchunk.memblock); + pa_memchunk_make_writable(&vchunk, s->core->memblock_stat, 0); + if (s->sw_muted) + pa_silence_memchunk(&vchunk, &s->sample_spec); + else + pa_volume_memchunk(&vchunk, &s->sample_spec, &s->sw_volume); + pa_idxset_foreach(s->outputs, do_post, &vchunk); + pa_memblock_unref(vchunk.memblock); + } else + pa_idxset_foreach(s->outputs, do_post, (void*) chunk); + + pa_source_unref(s); +} + +void pa_source_set_owner(pa_source *s, pa_module *m) { + assert(s); + assert(s->ref >= 1); + + s->owner = m; +} + +pa_usec_t pa_source_get_latency(pa_source *s) { + assert(s); + assert(s->ref >= 1); + + if (!s->get_latency) + return 0; + + return s->get_latency(s); +} + +void pa_source_set_volume(pa_source *s, pa_mixer_t m, const pa_cvolume *volume) { + pa_cvolume *v; + + assert(s); + assert(s->ref >= 1); + assert(volume); + + if (m == PA_MIXER_HARDWARE && s->set_hw_volume) + v = &s->hw_volume; + else + v = &s->sw_volume; + + if (pa_cvolume_equal(v, volume)) + return; + + *v = *volume; + + if (v == &s->hw_volume) + if (s->set_hw_volume(s) < 0) + s->sw_volume = *volume; + + pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, s->index); +} + +const pa_cvolume *pa_source_get_volume(pa_source *s, pa_mixer_t m) { + assert(s); + assert(s->ref >= 1); + + if (m == PA_MIXER_HARDWARE && s->set_hw_volume) { + + if (s->get_hw_volume) + s->get_hw_volume(s); + + return &s->hw_volume; + } else + return &s->sw_volume; +} + +void pa_source_set_mute(pa_source *s, pa_mixer_t m, int mute) { + int *t; + + assert(s); + assert(s->ref >= 1); + + if (m == PA_MIXER_HARDWARE && s->set_hw_mute) + t = &s->hw_muted; + else + t = &s->sw_muted; + + if (!!*t == !!mute) + return; + + *t = !!mute; + + if (t == &s->hw_muted) + if (s->set_hw_mute(s) < 0) + s->sw_muted = !!mute; + + pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, s->index); +} + +int pa_source_get_mute(pa_source *s, pa_mixer_t m) { + assert(s); + assert(s->ref >= 1); + + if (m == PA_MIXER_HARDWARE && s->set_hw_mute) { + + if (s->get_hw_mute) + s->get_hw_mute(s); + + return s->hw_muted; + } else + return s->sw_muted; +} -- cgit From 6e38949039cca052ee0d167b92f895e4d95ee30d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 16 Jul 2006 17:26:55 +0000 Subject: add a new boolean variable is_hardware to pa_sink/pa_source to denote wether the specific device is a hardware device or virtual/software git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1090 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/pulsecore/source.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/pulsecore/source.c') diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c index 84151a92..48b6daea 100644 --- a/src/pulsecore/source.c +++ b/src/pulsecore/source.c @@ -98,6 +98,8 @@ pa_source* pa_source_new( s->sw_muted = 0; s->hw_muted = 0; + s->is_hardware = 0; + s->get_latency = NULL; s->notify = NULL; s->set_hw_volume = NULL; -- cgit From c90dd53268bec8516be3b37e8af1989290f022a2 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 11 Aug 2006 17:53:34 +0000 Subject: * introduce new functions pa_sink_set_description() and pa_source_set_description() for changing the description of a sink/source * allow sinks without monitor sources attached git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1203 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/pulsecore/source.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/pulsecore/source.c') diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c index 48b6daea..f9c0703d 100644 --- a/src/pulsecore/source.c +++ b/src/pulsecore/source.c @@ -313,3 +313,19 @@ int pa_source_get_mute(pa_source *s, pa_mixer_t m) { } else return s->sw_muted; } + +void pa_source_set_description(pa_source *s, const char *description) { + assert(s); + assert(s->ref >= 1); + + if (!description && !s->description) + return; + + if (description && s->description && !strcmp(description, s->description)) + return; + + pa_xfree(s->description); + s->description = pa_xstrdup(description); + + pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, s->index); +} -- cgit From 3aba099fc3e515db5c4b1f2990c48fdb4160ff52 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 12 Aug 2006 02:19:36 +0000 Subject: clean up event generation a little: suppress unnecessary events and generate new ones on owner change git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1212 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/pulsecore/source.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/pulsecore/source.c') diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c index f9c0703d..903de88b 100644 --- a/src/pulsecore/source.c +++ b/src/pulsecore/source.c @@ -225,8 +225,12 @@ void pa_source_post(pa_source*s, const pa_memchunk *chunk) { void pa_source_set_owner(pa_source *s, pa_module *m) { assert(s); assert(s->ref >= 1); + + if (m == s->owner) + return; s->owner = m; + pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, s->index); } pa_usec_t pa_source_get_latency(pa_source *s) { -- cgit From b5207fc9cac954d49132ff4e6760a60e4e6f2b51 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 12 Aug 2006 16:50:58 +0000 Subject: add pa_sink_used_by()/pa_source_used_by() git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1226 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/pulsecore/source.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/pulsecore/source.c') diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c index 903de88b..ae72f040 100644 --- a/src/pulsecore/source.c +++ b/src/pulsecore/source.c @@ -333,3 +333,10 @@ void pa_source_set_description(pa_source *s, const char *description) { pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, s->index); } + +unsigned pa_source_used_by(pa_source *s) { + assert(s); + assert(s->ref >= 1); + + return pa_idxset_size(s->outputs); +} -- cgit From 79cb80c5740dd00fae89464e7d03f1a7ade6ccdd Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 13 Aug 2006 19:53:18 +0000 Subject: implement hook_source_disconnect git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1248 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/pulsecore/source.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/pulsecore/source.c') diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c index ae72f040..0d55da44 100644 --- a/src/pulsecore/source.c +++ b/src/pulsecore/source.c @@ -125,7 +125,10 @@ void pa_source_disconnect(pa_source *s) { assert(s); assert(s->state == PA_SOURCE_RUNNING); + s->state = PA_SOURCE_DISCONNECTED; pa_namereg_unregister(s->core, s->name); + + pa_hook_fire(&s->core->hook_source_disconnect, s); while ((o = pa_idxset_first(s->outputs, NULL))) { assert(o != j); @@ -142,7 +145,6 @@ void pa_source_disconnect(pa_source *s) { s->set_hw_mute = NULL; s->get_hw_mute = NULL; - s->state = PA_SOURCE_DISCONNECTED; pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE | PA_SUBSCRIPTION_EVENT_REMOVE, s->index); } -- cgit From 0e436a6926af56f37a74a03bb5e143e078ca0d55 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 18 Aug 2006 19:55:18 +0000 Subject: Rework memory management to allow shared memory data transfer. The central idea is to allocate all audio memory blocks from a per-process memory pool which is available as read-only SHM segment to other local processes. Then, instead of writing the actual audio data to the socket just write references to this shared memory pool. To work optimally all memory blocks should now be of type PA_MEMBLOCK_POOL or PA_MEMBLOCK_POOL_EXTERNAL. The function pa_memblock_new() now generates memory blocks of this type by default. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1266 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/pulsecore/source.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/pulsecore/source.c') diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c index 0d55da44..cb5b1030 100644 --- a/src/pulsecore/source.c +++ b/src/pulsecore/source.c @@ -211,7 +211,7 @@ void pa_source_post(pa_source*s, const pa_memchunk *chunk) { pa_memchunk vchunk = *chunk; pa_memblock_ref(vchunk.memblock); - pa_memchunk_make_writable(&vchunk, s->core->memblock_stat, 0); + pa_memchunk_make_writable(&vchunk, 0); if (s->sw_muted) pa_silence_memchunk(&vchunk, &s->sample_spec); else -- cgit From e385d93e5aad6a6fce754c00c804ff1d6a6746d4 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 18 Aug 2006 21:38:40 +0000 Subject: remove all occurences of pa_logXXX(__FILE__": and replace them by pa_logXXX(" git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1272 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/pulsecore/source.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/pulsecore/source.c') diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c index cb5b1030..c48d6aaa 100644 --- a/src/pulsecore/source.c +++ b/src/pulsecore/source.c @@ -112,7 +112,7 @@ pa_source* pa_source_new( assert(s->index != PA_IDXSET_INVALID && r >= 0); pa_sample_spec_snprint(st, sizeof(st), spec); - pa_log_info(__FILE__": created %u \"%s\" with sample spec \"%s\"", s->index, s->name, st); + pa_log_info("created %u \"%s\" with sample spec \"%s\"", s->index, s->name, st); pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_SOURCE | PA_SUBSCRIPTION_EVENT_NEW, s->index); @@ -155,7 +155,7 @@ static void source_free(pa_source *s) { if (s->state != PA_SOURCE_DISCONNECTED) pa_source_disconnect(s); - pa_log_info(__FILE__": freed %u \"%s\"", s->index, s->name); + pa_log_info("freed %u \"%s\"", s->index, s->name); pa_idxset_free(s->outputs, NULL, NULL); -- cgit From 521daf6f0ac4fa6a2fbfb5d523c0c743342dca2b Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 4 Jan 2007 13:43:45 +0000 Subject: Huge trailing whitespace cleanup. Let's keep the tree pure from here on, mmmkay? git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1418 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/pulsecore/source.c | 54 +++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'src/pulsecore/source.c') diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c index c48d6aaa..702dbeff 100644 --- a/src/pulsecore/source.c +++ b/src/pulsecore/source.c @@ -2,17 +2,17 @@ /*** This file is part of PulseAudio. - + PulseAudio is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + PulseAudio is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with PulseAudio; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -52,12 +52,12 @@ pa_source* pa_source_new( int fail, const pa_sample_spec *spec, const pa_channel_map *map) { - + pa_source *s; char st[256]; int r; pa_channel_map tmap; - + assert(core); assert(name); assert(spec); @@ -86,7 +86,7 @@ pa_source* pa_source_new( s->description = NULL; s->driver = pa_xstrdup(driver); s->owner = NULL; - + s->sample_spec = *spec; s->channel_map = *map; @@ -112,16 +112,16 @@ pa_source* pa_source_new( assert(s->index != PA_IDXSET_INVALID && r >= 0); pa_sample_spec_snprint(st, sizeof(st), spec); - pa_log_info("created %u \"%s\" with sample spec \"%s\"", s->index, s->name, st); + pa_log_info("created %u \"%s\" with sample spec \"%s\"", s->index, s->name, st); pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_SOURCE | PA_SUBSCRIPTION_EVENT_NEW, s->index); - + return s; } void pa_source_disconnect(pa_source *s) { pa_source_output *o, *j = NULL; - + assert(s); assert(s->state == PA_SOURCE_RUNNING); @@ -129,7 +129,7 @@ void pa_source_disconnect(pa_source *s) { pa_namereg_unregister(s->core, s->name); pa_hook_fire(&s->core->hook_source_disconnect, s); - + while ((o = pa_idxset_first(s->outputs, NULL))) { assert(o != j); pa_source_output_kill(o); @@ -144,18 +144,18 @@ void pa_source_disconnect(pa_source *s) { s->set_hw_volume = NULL; s->set_hw_mute = NULL; s->get_hw_mute = NULL; - + pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE | PA_SUBSCRIPTION_EVENT_REMOVE, s->index); } static void source_free(pa_source *s) { assert(s); assert(!s->ref); - + if (s->state != PA_SOURCE_DISCONNECTED) pa_source_disconnect(s); - - pa_log_info("freed %u \"%s\"", s->index, s->name); + + pa_log_info("freed %u \"%s\"", s->index, s->name); pa_idxset_free(s->outputs, NULL, NULL); @@ -176,7 +176,7 @@ void pa_source_unref(pa_source *s) { pa_source* pa_source_ref(pa_source *s) { assert(s); assert(s->ref >= 1); - + s->ref++; return s; } @@ -192,7 +192,7 @@ void pa_source_notify(pa_source*s) { static int do_post(void *p, PA_GCC_UNUSED uint32_t idx, PA_GCC_UNUSED int *del, void*userdata) { pa_source_output *o = p; const pa_memchunk *chunk = userdata; - + assert(o); assert(chunk); @@ -209,7 +209,7 @@ void pa_source_post(pa_source*s, const pa_memchunk *chunk) { if (s->sw_muted || !pa_cvolume_is_norm(&s->sw_volume)) { pa_memchunk vchunk = *chunk; - + pa_memblock_ref(vchunk.memblock); pa_memchunk_make_writable(&vchunk, 0); if (s->sw_muted) @@ -230,7 +230,7 @@ void pa_source_set_owner(pa_source *s, pa_module *m) { if (m == s->owner) return; - + s->owner = m; pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, s->index); } @@ -247,19 +247,19 @@ pa_usec_t pa_source_get_latency(pa_source *s) { void pa_source_set_volume(pa_source *s, pa_mixer_t m, const pa_cvolume *volume) { pa_cvolume *v; - + assert(s); assert(s->ref >= 1); assert(volume); - if (m == PA_MIXER_HARDWARE && s->set_hw_volume) + if (m == PA_MIXER_HARDWARE && s->set_hw_volume) v = &s->hw_volume; else v = &s->sw_volume; if (pa_cvolume_equal(v, volume)) return; - + *v = *volume; if (v == &s->hw_volume) @@ -277,7 +277,7 @@ const pa_cvolume *pa_source_get_volume(pa_source *s, pa_mixer_t m) { if (s->get_hw_volume) s->get_hw_volume(s); - + return &s->hw_volume; } else return &s->sw_volume; @@ -285,18 +285,18 @@ const pa_cvolume *pa_source_get_volume(pa_source *s, pa_mixer_t m) { void pa_source_set_mute(pa_source *s, pa_mixer_t m, int mute) { int *t; - + assert(s); assert(s->ref >= 1); - if (m == PA_MIXER_HARDWARE && s->set_hw_mute) + if (m == PA_MIXER_HARDWARE && s->set_hw_mute) t = &s->hw_muted; else t = &s->sw_muted; if (!!*t == !!mute) return; - + *t = !!mute; if (t == &s->hw_muted) @@ -314,7 +314,7 @@ int pa_source_get_mute(pa_source *s, pa_mixer_t m) { if (s->get_hw_mute) s->get_hw_mute(s); - + return s->hw_muted; } else return s->sw_muted; @@ -329,7 +329,7 @@ void pa_source_set_description(pa_source *s, const char *description) { if (description && s->description && !strcmp(description, s->description)) return; - + pa_xfree(s->description); s->description = pa_xstrdup(description); -- cgit From 06211b7c8fd329137ae9003818543912a87d9898 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 13 Feb 2007 15:35:19 +0000 Subject: Add copyright notices to all relevant files. (based on svn log) git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1426 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/pulsecore/source.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/pulsecore/source.c') diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c index 702dbeff..9bb2d342 100644 --- a/src/pulsecore/source.c +++ b/src/pulsecore/source.c @@ -3,6 +3,9 @@ /*** This file is part of PulseAudio. + Copyright 2004-2006 Lennart Poettering + Copyright 2006 Pierre Ossman for Cendio AB + PulseAudio is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, -- cgit From a67c21f093202f142438689d3f7cfbdf4ea82eea Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 28 Oct 2007 19:13:50 +0000 Subject: merge 'lennart' branch back into trunk. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1971 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/pulsecore/source.c | 560 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 401 insertions(+), 159 deletions(-) (limited to 'src/pulsecore/source.c') diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c index 9bb2d342..9a6902ae 100644 --- a/src/pulsecore/source.c +++ b/src/pulsecore/source.c @@ -27,7 +27,6 @@ #endif #include -#include #include #include @@ -42,11 +41,9 @@ #include "source.h" -#define CHECK_VALIDITY_RETURN_NULL(condition) \ -do {\ -if (!(condition)) \ - return NULL; \ -} while (0) +static PA_DEFINE_CHECK_TYPE(pa_source, pa_msgobject); + +static void source_free(pa_object *o); pa_source* pa_source_new( pa_core *core, @@ -58,274 +55,359 @@ pa_source* pa_source_new( pa_source *s; char st[256]; - int r; pa_channel_map tmap; - assert(core); - assert(name); - assert(spec); + pa_assert(core); + pa_assert(name); + pa_assert(spec); - CHECK_VALIDITY_RETURN_NULL(pa_sample_spec_valid(spec)); + pa_return_null_if_fail(pa_sample_spec_valid(spec)); if (!map) map = pa_channel_map_init_auto(&tmap, spec->channels, PA_CHANNEL_MAP_DEFAULT); - CHECK_VALIDITY_RETURN_NULL(map && pa_channel_map_valid(map)); - CHECK_VALIDITY_RETURN_NULL(map->channels == spec->channels); - CHECK_VALIDITY_RETURN_NULL(!driver || pa_utf8_valid(driver)); - CHECK_VALIDITY_RETURN_NULL(pa_utf8_valid(name) && *name); + pa_return_null_if_fail(map && pa_channel_map_valid(map)); + pa_return_null_if_fail(map->channels == spec->channels); + pa_return_null_if_fail(!driver || pa_utf8_valid(driver)); + pa_return_null_if_fail(pa_utf8_valid(name) && *name); - s = pa_xnew(pa_source, 1); + s = pa_msgobject_new(pa_source); if (!(name = pa_namereg_register(core, name, PA_NAMEREG_SOURCE, s, fail))) { pa_xfree(s); return NULL; } - s->ref = 1; + s->parent.parent.free = source_free; + s->parent.process_msg = pa_source_process_msg; + s->core = core; - s->state = PA_SOURCE_RUNNING; + s->state = PA_SOURCE_INIT; + s->flags = 0; s->name = pa_xstrdup(name); s->description = NULL; s->driver = pa_xstrdup(driver); - s->owner = NULL; + s->module = NULL; s->sample_spec = *spec; s->channel_map = *map; s->outputs = pa_idxset_new(NULL, NULL); + s->n_corked = 0; s->monitor_of = NULL; - pa_cvolume_reset(&s->sw_volume, spec->channels); - pa_cvolume_reset(&s->hw_volume, spec->channels); - s->sw_muted = 0; - s->hw_muted = 0; - - s->is_hardware = 0; + pa_cvolume_reset(&s->volume, spec->channels); + s->muted = FALSE; + s->refresh_volume = s->refresh_muted = FALSE; s->get_latency = NULL; - s->notify = NULL; - s->set_hw_volume = NULL; - s->get_hw_volume = NULL; - s->set_hw_mute = NULL; - s->get_hw_mute = NULL; + s->set_volume = NULL; + s->get_volume = NULL; + s->set_mute = NULL; + s->get_mute = NULL; + s->set_state = NULL; s->userdata = NULL; - r = pa_idxset_put(core->sources, s, &s->index); - assert(s->index != PA_IDXSET_INVALID && r >= 0); + s->asyncmsgq = NULL; + s->rtpoll = NULL; + + pa_assert_se(pa_idxset_put(core->sources, s, &s->index) >= 0); pa_sample_spec_snprint(st, sizeof(st), spec); - pa_log_info("created %u \"%s\" with sample spec \"%s\"", s->index, s->name, st); + pa_log_info("Created source %u \"%s\" with sample spec \"%s\"", s->index, s->name, st); - pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_SOURCE | PA_SUBSCRIPTION_EVENT_NEW, s->index); + s->thread_info.outputs = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func); + s->thread_info.soft_volume = s->volume; + s->thread_info.soft_muted = s->muted; + s->thread_info.state = s->state; return s; } -void pa_source_disconnect(pa_source *s) { +static int source_set_state(pa_source *s, pa_source_state_t state) { + int ret; + + pa_assert(s); + + if (s->state == state) + return 0; + + if ((s->state == PA_SOURCE_SUSPENDED && PA_SOURCE_OPENED(state)) || + (PA_SOURCE_OPENED(s->state) && state == PA_SOURCE_SUSPENDED)) { + pa_source_output *o; + uint32_t idx; + + /* We're suspending or resuming, tell everyone about it */ + + for (o = PA_SOURCE_OUTPUT(pa_idxset_first(s->outputs, &idx)); o; o = PA_SOURCE_OUTPUT(pa_idxset_next(s->outputs, &idx))) + if (o->suspend) + o->suspend(o, state == PA_SINK_SUSPENDED); + } + + if (s->set_state) + if ((ret = s->set_state(s, state)) < 0) + return -1; + + if (pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SOURCE_MESSAGE_SET_STATE, PA_UINT_TO_PTR(state), 0, NULL) < 0) + return -1; + + s->state = state; + + if (state != PA_SOURCE_UNLINKED) /* if we enter UNLINKED state pa_source_unlink() will fire the apropriate events */ + pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SOURCE_STATE_CHANGED], s); + return 0; +} + +void pa_source_put(pa_source *s) { + pa_source_assert_ref(s); + + pa_assert(s->state == PA_SINK_INIT); + pa_assert(s->rtpoll); + pa_assert(s->asyncmsgq); + + pa_assert_se(source_set_state(s, PA_SOURCE_IDLE) == 0); + + pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE | PA_SUBSCRIPTION_EVENT_NEW, s->index); + pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SOURCE_NEW_POST], s); +} + +void pa_source_unlink(pa_source *s) { + pa_bool_t linked; pa_source_output *o, *j = NULL; - assert(s); - assert(s->state == PA_SOURCE_RUNNING); + pa_assert(s); + + /* See pa_sink_unlink() for a couple of comments how this function + * works. */ - s->state = PA_SOURCE_DISCONNECTED; - pa_namereg_unregister(s->core, s->name); + linked = PA_SOURCE_LINKED(s->state); - pa_hook_fire(&s->core->hook_source_disconnect, s); + if (linked) + pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SOURCE_UNLINK], s); + + if (s->state != PA_SOURCE_UNLINKED) + pa_namereg_unregister(s->core, s->name); + pa_idxset_remove_by_data(s->core->sources, s, NULL); while ((o = pa_idxset_first(s->outputs, NULL))) { - assert(o != j); + pa_assert(o != j); pa_source_output_kill(o); j = o; } - pa_idxset_remove_by_data(s->core->sources, s, NULL); + if (linked) + source_set_state(s, PA_SOURCE_UNLINKED); + else + s->state = PA_SOURCE_UNLINKED; s->get_latency = NULL; - s->notify = NULL; - s->get_hw_volume = NULL; - s->set_hw_volume = NULL; - s->set_hw_mute = NULL; - s->get_hw_mute = NULL; - - pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE | PA_SUBSCRIPTION_EVENT_REMOVE, s->index); + s->get_volume = NULL; + s->set_volume = NULL; + s->set_mute = NULL; + s->get_mute = NULL; + s->set_state = NULL; + + if (linked) { + pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE | PA_SUBSCRIPTION_EVENT_REMOVE, s->index); + pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SOURCE_UNLINK_POST], s); + } } -static void source_free(pa_source *s) { - assert(s); - assert(!s->ref); +static void source_free(pa_object *o) { + pa_source_output *so; + pa_source *s = PA_SOURCE(o); - if (s->state != PA_SOURCE_DISCONNECTED) - pa_source_disconnect(s); + pa_assert(s); + pa_assert(pa_source_refcnt(s) == 0); - pa_log_info("freed %u \"%s\"", s->index, s->name); + if (PA_SOURCE_LINKED(s->state)) + pa_source_unlink(s); + + pa_log_info("Freeing source %u \"%s\"", s->index, s->name); pa_idxset_free(s->outputs, NULL, NULL); + while ((so = pa_hashmap_steal_first(s->thread_info.outputs))) + pa_source_output_unref(so); + + pa_hashmap_free(s->thread_info.outputs, NULL, NULL); + pa_xfree(s->name); pa_xfree(s->description); pa_xfree(s->driver); pa_xfree(s); } -void pa_source_unref(pa_source *s) { - assert(s); - assert(s->ref >= 1); - - if (!(--s->ref)) - source_free(s); -} +int pa_source_update_status(pa_source*s) { + pa_source_assert_ref(s); + pa_assert(PA_SOURCE_LINKED(s->state)); -pa_source* pa_source_ref(pa_source *s) { - assert(s); - assert(s->ref >= 1); + if (s->state == PA_SOURCE_SUSPENDED) + return 0; - s->ref++; - return s; + return source_set_state(s, pa_source_used_by(s) ? PA_SOURCE_RUNNING : PA_SOURCE_IDLE); } -void pa_source_notify(pa_source*s) { - assert(s); - assert(s->ref >= 1); +int pa_source_suspend(pa_source *s, pa_bool_t suspend) { + pa_source_assert_ref(s); + pa_assert(PA_SOURCE_LINKED(s->state)); - if (s->notify) - s->notify(s); + if (suspend) + return source_set_state(s, PA_SOURCE_SUSPENDED); + else + return source_set_state(s, pa_source_used_by(s) ? PA_SOURCE_RUNNING : PA_SOURCE_IDLE); } -static int do_post(void *p, PA_GCC_UNUSED uint32_t idx, PA_GCC_UNUSED int *del, void*userdata) { - pa_source_output *o = p; - const pa_memchunk *chunk = userdata; +void pa_source_ping(pa_source *s) { + pa_source_assert_ref(s); + pa_assert(PA_SOURCE_LINKED(s->state)); - assert(o); - assert(chunk); - - pa_source_output_push(o, chunk); - return 0; + pa_asyncmsgq_post(s->asyncmsgq, PA_MSGOBJECT(s), PA_SOURCE_MESSAGE_PING, NULL, 0, NULL, NULL); } void pa_source_post(pa_source*s, const pa_memchunk *chunk) { - assert(s); - assert(s->ref >= 1); - assert(chunk); + pa_source_output *o; + void *state = NULL; - pa_source_ref(s); + pa_source_assert_ref(s); + pa_assert(PA_SOURCE_OPENED(s->thread_info.state)); + pa_assert(chunk); - if (s->sw_muted || !pa_cvolume_is_norm(&s->sw_volume)) { + if (s->thread_info.state != PA_SOURCE_RUNNING) + return; + + if (s->thread_info.soft_muted || !pa_cvolume_is_norm(&s->thread_info.soft_volume)) { pa_memchunk vchunk = *chunk; pa_memblock_ref(vchunk.memblock); pa_memchunk_make_writable(&vchunk, 0); - if (s->sw_muted) + + if (s->thread_info.soft_muted || pa_cvolume_is_muted(&s->thread_info.soft_volume)) pa_silence_memchunk(&vchunk, &s->sample_spec); else - pa_volume_memchunk(&vchunk, &s->sample_spec, &s->sw_volume); - pa_idxset_foreach(s->outputs, do_post, &vchunk); + pa_volume_memchunk(&vchunk, &s->sample_spec, &s->thread_info.soft_volume); + + while ((o = pa_hashmap_iterate(s->thread_info.outputs, &state, NULL))) + pa_source_output_push(o, &vchunk); + pa_memblock_unref(vchunk.memblock); - } else - pa_idxset_foreach(s->outputs, do_post, (void*) chunk); + } else { - pa_source_unref(s); + while ((o = pa_hashmap_iterate(s->thread_info.outputs, &state, NULL))) + pa_source_output_push(o, chunk); + } } -void pa_source_set_owner(pa_source *s, pa_module *m) { - assert(s); - assert(s->ref >= 1); +pa_usec_t pa_source_get_latency(pa_source *s) { + pa_usec_t usec; - if (m == s->owner) - return; + pa_source_assert_ref(s); + pa_assert(PA_SOURCE_LINKED(s->state)); - s->owner = m; - pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, s->index); -} + if (!PA_SOURCE_OPENED(s->state)) + return 0; -pa_usec_t pa_source_get_latency(pa_source *s) { - assert(s); - assert(s->ref >= 1); + if (s->get_latency) + return s->get_latency(s); - if (!s->get_latency) + if (pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SOURCE_MESSAGE_GET_LATENCY, &usec, 0, NULL) < 0) return 0; - return s->get_latency(s); + return usec; } -void pa_source_set_volume(pa_source *s, pa_mixer_t m, const pa_cvolume *volume) { - pa_cvolume *v; +void pa_source_set_volume(pa_source *s, const pa_cvolume *volume) { + int changed; - assert(s); - assert(s->ref >= 1); - assert(volume); + pa_source_assert_ref(s); + pa_assert(PA_SOURCE_LINKED(s->state)); + pa_assert(volume); - if (m == PA_MIXER_HARDWARE && s->set_hw_volume) - v = &s->hw_volume; - else - v = &s->sw_volume; + changed = !pa_cvolume_equal(volume, &s->volume); + s->volume = *volume; - if (pa_cvolume_equal(v, volume)) - return; + if (s->set_volume && s->set_volume(s) < 0) + s->set_volume = NULL; - *v = *volume; + if (!s->set_volume) + pa_asyncmsgq_post(s->asyncmsgq, PA_MSGOBJECT(s), PA_SOURCE_MESSAGE_SET_VOLUME, pa_xnewdup(struct pa_cvolume, volume, 1), 0, NULL, pa_xfree); - if (v == &s->hw_volume) - if (s->set_hw_volume(s) < 0) - s->sw_volume = *volume; + if (changed) + pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, s->index); +} - pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, s->index); +const pa_cvolume *pa_source_get_volume(pa_source *s) { + pa_cvolume old_volume; + + pa_source_assert_ref(s); + pa_assert(PA_SOURCE_LINKED(s->state)); + + old_volume = s->volume; + + if (s->get_volume && s->get_volume(s) < 0) + s->get_volume = NULL; + + if (!s->get_volume && s->refresh_volume) + pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SOURCE_MESSAGE_GET_VOLUME, &s->volume, 0, NULL); + + if (!pa_cvolume_equal(&old_volume, &s->volume)) + pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, s->index); + + return &s->volume; } -const pa_cvolume *pa_source_get_volume(pa_source *s, pa_mixer_t m) { - assert(s); - assert(s->ref >= 1); +void pa_source_set_mute(pa_source *s, pa_bool_t mute) { + int changed; + + pa_source_assert_ref(s); + pa_assert(PA_SOURCE_LINKED(s->state)); + + changed = s->muted != mute; + s->muted = mute; - if (m == PA_MIXER_HARDWARE && s->set_hw_volume) { + if (s->set_mute && s->set_mute(s) < 0) + s->set_mute = NULL; - if (s->get_hw_volume) - s->get_hw_volume(s); + if (!s->set_mute) + pa_asyncmsgq_post(s->asyncmsgq, PA_MSGOBJECT(s), PA_SOURCE_MESSAGE_SET_MUTE, PA_UINT_TO_PTR(mute), 0, NULL, NULL); - return &s->hw_volume; - } else - return &s->sw_volume; + if (changed) + pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, s->index); } -void pa_source_set_mute(pa_source *s, pa_mixer_t m, int mute) { - int *t; +pa_bool_t pa_source_get_mute(pa_source *s) { + pa_bool_t old_muted; - assert(s); - assert(s->ref >= 1); + pa_source_assert_ref(s); + pa_assert(PA_SOURCE_LINKED(s->state)); - if (m == PA_MIXER_HARDWARE && s->set_hw_mute) - t = &s->hw_muted; - else - t = &s->sw_muted; + old_muted = s->muted; - if (!!*t == !!mute) - return; + if (s->get_mute && s->get_mute(s) < 0) + s->get_mute = NULL; - *t = !!mute; + if (!s->get_mute && s->refresh_muted) + pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SOURCE_MESSAGE_GET_MUTE, &s->muted, 0, NULL); - if (t == &s->hw_muted) - if (s->set_hw_mute(s) < 0) - s->sw_muted = !!mute; + if (old_muted != s->muted) + pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, s->index); - pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, s->index); + return s->muted; } -int pa_source_get_mute(pa_source *s, pa_mixer_t m) { - assert(s); - assert(s->ref >= 1); +void pa_source_set_module(pa_source *s, pa_module *m) { + pa_source_assert_ref(s); - if (m == PA_MIXER_HARDWARE && s->set_hw_mute) { + if (m == s->module) + return; - if (s->get_hw_mute) - s->get_hw_mute(s); + s->module = m; - return s->hw_muted; - } else - return s->sw_muted; + pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, s->index); } void pa_source_set_description(pa_source *s, const char *description) { - assert(s); - assert(s->ref >= 1); + pa_source_assert_ref(s); if (!description && !s->description) return; @@ -336,12 +418,172 @@ void pa_source_set_description(pa_source *s, const char *description) { pa_xfree(s->description); s->description = pa_xstrdup(description); - pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, s->index); + if (PA_SOURCE_LINKED(s->state)) { + pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SOURCE_DESCRIPTION_CHANGED], s); + pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, s->index); + } } -unsigned pa_source_used_by(pa_source *s) { - assert(s); - assert(s->ref >= 1); +void pa_source_set_asyncmsgq(pa_source *s, pa_asyncmsgq *q) { + pa_source_assert_ref(s); + pa_assert(q); + + s->asyncmsgq = q; +} + +void pa_source_set_rtpoll(pa_source *s, pa_rtpoll *p) { + pa_source_assert_ref(s); + pa_assert(p); + + s->rtpoll = p; +} + +unsigned pa_source_linked_by(pa_source *s) { + pa_source_assert_ref(s); + pa_assert(PA_SOURCE_LINKED(s->state)); return pa_idxset_size(s->outputs); } + +unsigned pa_source_used_by(pa_source *s) { + unsigned ret; + + pa_source_assert_ref(s); + pa_assert(PA_SOURCE_LINKED(s->state)); + + ret = pa_idxset_size(s->outputs); + pa_assert(ret >= s->n_corked); + + return ret - s->n_corked; +} + +int pa_source_process_msg(pa_msgobject *object, int code, void *userdata, int64_t offset, pa_memchunk *chunk) { + pa_source *s = PA_SOURCE(object); + pa_source_assert_ref(s); + pa_assert(s->thread_info.state != PA_SOURCE_UNLINKED); + + switch ((pa_source_message_t) code) { + case PA_SOURCE_MESSAGE_ADD_OUTPUT: { + pa_source_output *o = PA_SOURCE_OUTPUT(userdata); + pa_hashmap_put(s->thread_info.outputs, PA_UINT32_TO_PTR(o->index), pa_source_output_ref(o)); + + pa_assert(!o->thread_info.attached); + o->thread_info.attached = TRUE; + + if (o->attach) + o->attach(o); + + return 0; + } + + case PA_SOURCE_MESSAGE_REMOVE_OUTPUT: { + pa_source_output *o = PA_SOURCE_OUTPUT(userdata); + + if (o->detach) + o->detach(o); + + pa_assert(o->thread_info.attached); + o->thread_info.attached = FALSE; + + if (pa_hashmap_remove(s->thread_info.outputs, PA_UINT32_TO_PTR(o->index))) + pa_source_output_unref(o); + + return 0; + } + + case PA_SOURCE_MESSAGE_SET_VOLUME: + s->thread_info.soft_volume = *((pa_cvolume*) userdata); + return 0; + + case PA_SOURCE_MESSAGE_SET_MUTE: + s->thread_info.soft_muted = PA_PTR_TO_UINT(userdata); + return 0; + + case PA_SOURCE_MESSAGE_GET_VOLUME: + *((pa_cvolume*) userdata) = s->thread_info.soft_volume; + return 0; + + case PA_SOURCE_MESSAGE_GET_MUTE: + *((pa_bool_t*) userdata) = s->thread_info.soft_muted; + return 0; + + case PA_SOURCE_MESSAGE_PING: + return 0; + + case PA_SOURCE_MESSAGE_SET_STATE: + s->thread_info.state = PA_PTR_TO_UINT(userdata); + return 0; + + case PA_SOURCE_MESSAGE_DETACH: + + /* We're detaching all our output streams so that the + * asyncmsgq and rtpoll fields can be changed without + * problems */ + pa_source_detach_within_thread(s); + break; + + case PA_SOURCE_MESSAGE_ATTACH: + + /* Reattach all streams */ + pa_source_attach_within_thread(s); + break; + + case PA_SOURCE_MESSAGE_GET_LATENCY: + case PA_SOURCE_MESSAGE_MAX: + ; + } + + return -1; +} + +int pa_source_suspend_all(pa_core *c, pa_bool_t suspend) { + uint32_t idx; + pa_source *source; + int ret = 0; + + pa_core_assert_ref(c); + + for (source = PA_SOURCE(pa_idxset_first(c->sources, &idx)); source; source = PA_SOURCE(pa_idxset_next(c->sources, &idx))) + ret -= pa_source_suspend(source, suspend) < 0; + + return ret; +} + +void pa_source_detach(pa_source *s) { + pa_source_assert_ref(s); + pa_assert(PA_SOURCE_LINKED(s->state)); + + pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SOURCE_MESSAGE_DETACH, NULL, 0, NULL); +} + +void pa_source_attach(pa_source *s) { + pa_source_assert_ref(s); + pa_assert(PA_SOURCE_LINKED(s->state)); + + pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SOURCE_MESSAGE_ATTACH, NULL, 0, NULL); +} + +void pa_source_detach_within_thread(pa_source *s) { + pa_source_output *o; + void *state = NULL; + + pa_source_assert_ref(s); + pa_assert(PA_SOURCE_LINKED(s->thread_info.state)); + + while ((o = pa_hashmap_iterate(s->thread_info.outputs, &state, NULL))) + if (o->detach) + o->detach(o); +} + +void pa_source_attach_within_thread(pa_source *s) { + pa_source_output *o; + void *state = NULL; + + pa_source_assert_ref(s); + pa_assert(PA_SOURCE_LINKED(s->thread_info.state)); + + while ((o = pa_hashmap_iterate(s->thread_info.outputs, &state, NULL))) + if (o->attach) + o->attach(o); + +} -- cgit From 14a9b80afbb0bddc216462b72156f14e032e1b5e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 21 Nov 2007 01:30:40 +0000 Subject: - Check process name when dealing with PID files - Add new PA_STREAM_FIX_CHANNELS, FIX_RATE, FIX_FORMAT, DONT_MOVE, VARIABLE_RATES to pa_sream_flags_t adn implement it - Expose those flags in pacat - Add notifications about device suspend/resume to the protocol and expose them in libpulse - Allow changing of buffer_attr during playback - allow disabling for remixing globally - hookup polkit support git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2067 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/pulsecore/source.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src/pulsecore/source.c') diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c index 9a6902ae..5fd65cef 100644 --- a/src/pulsecore/source.c +++ b/src/pulsecore/source.c @@ -126,23 +126,16 @@ pa_source* pa_source_new( static int source_set_state(pa_source *s, pa_source_state_t state) { int ret; + pa_bool_t suspend_change; pa_assert(s); if (s->state == state) return 0; - if ((s->state == PA_SOURCE_SUSPENDED && PA_SOURCE_OPENED(state)) || - (PA_SOURCE_OPENED(s->state) && state == PA_SOURCE_SUSPENDED)) { - pa_source_output *o; - uint32_t idx; - - /* We're suspending or resuming, tell everyone about it */ - - for (o = PA_SOURCE_OUTPUT(pa_idxset_first(s->outputs, &idx)); o; o = PA_SOURCE_OUTPUT(pa_idxset_next(s->outputs, &idx))) - if (o->suspend) - o->suspend(o, state == PA_SINK_SUSPENDED); - } + suspend_change = + (s->state == PA_SOURCE_SUSPENDED && PA_SOURCE_OPENED(state)) || + (PA_SOURCE_OPENED(s->state) && state == PA_SOURCE_SUSPENDED); if (s->set_state) if ((ret = s->set_state(s, state)) < 0) @@ -153,8 +146,20 @@ static int source_set_state(pa_source *s, pa_source_state_t state) { s->state = state; + if (suspend_change) { + pa_source_output *o; + uint32_t idx; + + /* We're suspending or resuming, tell everyone about it */ + + for (o = PA_SOURCE_OUTPUT(pa_idxset_first(s->outputs, &idx)); o; o = PA_SOURCE_OUTPUT(pa_idxset_next(s->outputs, &idx))) + if (o->suspend) + o->suspend(o, state == PA_SINK_SUSPENDED); + } + if (state != PA_SOURCE_UNLINKED) /* if we enter UNLINKED state pa_source_unlink() will fire the apropriate events */ pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SOURCE_STATE_CHANGED], s); + return 0; } -- cgit From 86b9ef8c961bed9d3a65f044741bb423c26d8005 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 13 Feb 2008 22:13:44 +0000 Subject: deal with a possibly failing pa_channel_map_init_auto() correctly git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2105 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/pulsecore/source.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/pulsecore/source.c') diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c index 5fd65cef..d707ad86 100644 --- a/src/pulsecore/source.c +++ b/src/pulsecore/source.c @@ -64,7 +64,7 @@ pa_source* pa_source_new( pa_return_null_if_fail(pa_sample_spec_valid(spec)); if (!map) - map = pa_channel_map_init_auto(&tmap, spec->channels, PA_CHANNEL_MAP_DEFAULT); + pa_return_null_if_fail(map = pa_channel_map_init_auto(&tmap, spec->channels, PA_CHANNEL_MAP_DEFAULT)); pa_return_null_if_fail(map && pa_channel_map_valid(map)); pa_return_null_if_fail(map->channels == spec->channels); -- cgit