[pulseaudio-discuss] [PATCH v2 1/5] card: Store a pa_card pointer in pa_card_profile.
Tanu Kaskinen
tanuk at iki.fi
Thu Oct 25 06:49:23 PDT 2012
On Fri, 2012-06-29 at 18:04 +0300, Tanu Kaskinen wrote:
> From: Tanu Kaskinen <tanu.kaskinen at digia.com>
>
> ---
> src/pulsecore/card.c | 22 +++++++++++++++-------
> src/pulsecore/card.h | 1 +
> 2 files changed, 16 insertions(+), 7 deletions(-)
>
> diff --git a/src/pulsecore/card.c b/src/pulsecore/card.c
> index 492c051..cec24a5 100644
> --- a/src/pulsecore/card.c
> +++ b/src/pulsecore/card.c
> @@ -44,6 +44,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);
>
> @@ -56,6 +57,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); /* Card profiles shouldn't be freed before removing them from the card. */
>
> pa_xfree(c->name);
> pa_xfree(c->description);
> @@ -111,6 +113,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 *profile;
>
> pa_core_assert_ref(core);
> pa_assert(data);
> @@ -149,6 +153,11 @@ pa_card *pa_card_new(pa_core *core, pa_card_new_data *data) {
> c->ports = data->ports;
> data->ports = NULL;
>
> + if (c->profiles) {
> + PA_HASHMAP_FOREACH(profile, c->profiles, state)
> + profile->card = c;
> + }
> +
> c->active_profile = NULL;
> c->save_profile = FALSE;
>
> @@ -157,12 +166,9 @@ pa_card *pa_card_new(pa_core *core, pa_card_new_data *data) {
> c->save_profile = data->save_profile;
>
> if (!c->active_profile) {
> - 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;
> + PA_HASHMAP_FOREACH(profile, c->profiles, state)
> + if (!c->active_profile || profile->priority > c->active_profile->priority)
> + c->active_profile = profile;
> }
>
> c->userdata = NULL;
> @@ -209,8 +215,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);
> }
> diff --git a/src/pulsecore/card.h b/src/pulsecore/card.h
> index 6f942e8..0188c51 100644
> --- a/src/pulsecore/card.h
> +++ b/src/pulsecore/card.h
> @@ -30,6 +30,7 @@ typedef struct pa_card pa_card;
> #include <pulsecore/idxset.h>
>
> typedef struct pa_card_profile {
> + pa_card *card;
> char *name;
> char *description;
This one is now reviewed and applied. The rest of the patch set remains
unreviewed.
--
Tanu
More information about the pulseaudio-discuss
mailing list