[pulseaudio-discuss] [PATCH] core: New hook: PA_CORE_HOOK_CARD_PROFILE_ABOUT_TO_ACTIVATE.
David Henningsson
david.henningsson at canonical.com
Wed Oct 19 04:29:42 PDT 2011
Looks good and does not seem to interfere with anything in the jack
detection patches. Having a card pointer might even be helpful.
Just a thought: Can profiles be added after pa_card_new? In that case
they will never get a correct card pointer.
On 10/18/2011 05:08 PM, Tanu Kaskinen wrote:
> The hook users probably want access to the card object as well,
> so a pa_card pointer was added to pa_card_profile.
> ---
> src/pulsecore/card.c | 17 +++++++++++++----
> src/pulsecore/card.h | 6 ++++++
> src/pulsecore/core.h | 1 +
> 3 files changed, 20 insertions(+), 4 deletions(-)
>
> diff --git a/src/pulsecore/card.c b/src/pulsecore/card.c
> index feaa444..b9e2988 100644
> --- a/src/pulsecore/card.c
> +++ b/src/pulsecore/card.c
> @@ -43,6 +43,7 @@ pa_card_profile *pa_card_profile_new(const char *name, const char *description,
> pa_assert(name);
>
> c = pa_xmalloc(PA_ALIGN(sizeof(pa_card_profile)) + extra);
> + c->card = NULL;
> c->name = pa_xstrdup(name);
> c->description = pa_xstrdup(description);
>
> @@ -55,6 +56,7 @@ pa_card_profile *pa_card_profile_new(const char *name, const char *description,
>
> void pa_card_profile_free(pa_card_profile *c) {
> pa_assert(c);
> + pa_assert(!c->card); /* Make sure nobody frees a profile while it's still in use. */
>
> pa_xfree(c->name);
> pa_xfree(c->description);
> @@ -106,6 +108,8 @@ void pa_card_new_data_done(pa_card_new_data *data) {
> pa_card *pa_card_new(pa_core *core, pa_card_new_data *data) {
> pa_card *c;
> const char *name;
> + void *state;
> + pa_card_profile *p;
>
> pa_core_assert_ref(core);
> pa_assert(data);
> @@ -140,6 +144,11 @@ pa_card *pa_card_new(pa_core *core, pa_card_new_data *data) {
> c->profiles = data->profiles;
> data->profiles = NULL;
>
> + if (c->profiles) {
> + PA_HASHMAP_FOREACH(p, c->profiles, state)
> + p->card = c;
> + }
> +
> c->active_profile = NULL;
> c->save_profile = FALSE;
>
> @@ -148,9 +157,6 @@ pa_card *pa_card_new(pa_core *core, pa_card_new_data *data) {
> c->save_profile = data->save_profile;
>
> if (!c->active_profile&& c->profiles) {
> - void *state;
> - pa_card_profile *p;
> -
> PA_HASHMAP_FOREACH(p, c->profiles, state)
> if (!c->active_profile || p->priority> c->active_profile->priority)
> c->active_profile = p;
> @@ -198,8 +204,10 @@ void pa_card_free(pa_card *c) {
> if (c->profiles) {
> pa_card_profile *p;
>
> - while ((p = pa_hashmap_steal_first(c->profiles)))
> + while ((p = pa_hashmap_steal_first(c->profiles))) {
> + p->card = NULL;
> pa_card_profile_free(p);
> + }
>
> pa_hashmap_free(c->profiles, NULL, NULL);
> }
> @@ -231,6 +239,7 @@ int pa_card_set_profile(pa_card *c, const char *name, pa_bool_t save) {
> return 0;
> }
>
> + pa_hook_fire(&c->core->hooks[PA_CORE_HOOK_CARD_PROFILE_ABOUT_TO_ACTIVATE], profile);
> if ((r = c->set_profile(c, profile))< 0)
> return r;
>
> diff --git a/src/pulsecore/card.h b/src/pulsecore/card.h
> index 2d691b6..8dca0e4 100644
> --- a/src/pulsecore/card.h
> +++ b/src/pulsecore/card.h
> @@ -30,6 +30,12 @@ typedef struct pa_card pa_card;
> #include<pulsecore/idxset.h>
>
> typedef struct pa_card_profile {
> + /* This pointer is set when this pa_card_profile instance is in the
> + * profiles hashmap of pa_card. At other times this is NULL. Managing
> + * this pointer is the responsibility of whoever manages the
> + * pa_card.profiles hashmap. */
> + pa_card *card;
> +
> char *name;
> char *description;
>
> diff --git a/src/pulsecore/core.h b/src/pulsecore/core.h
> index d0641cf..dbd0c6f 100644
> --- a/src/pulsecore/core.h
> +++ b/src/pulsecore/core.h
> @@ -113,6 +113,7 @@ typedef enum pa_core_hook {
> PA_CORE_HOOK_CARD_PUT,
> PA_CORE_HOOK_CARD_UNLINK,
> PA_CORE_HOOK_CARD_PROFILE_CHANGED,
> + PA_CORE_HOOK_CARD_PROFILE_ABOUT_TO_ACTIVATE,
> PA_CORE_HOOK_MAX
> } pa_core_hook_t;
>
--
David Henningsson, Canonical Ltd.
http://launchpad.net/~diwic
More information about the pulseaudio-discuss
mailing list