diff options
author | Tanu Kaskinen <tanu.kaskinen@linux.intel.com> | 2015-05-04 21:03:40 +0300 |
---|---|---|
committer | Tanu Kaskinen <tanu.kaskinen@linux.intel.com> | 2015-08-21 14:33:10 +0300 |
commit | f5fecff0b4cef99f7881ad146b72d44e4f06a698 (patch) | |
tree | eebbbd469e00b528d7fe52be2d49e950d4c488e7 /src | |
parent | c50766b52ad4cdefa51d7186389c1fb777402802 (diff) |
alsa: Add pa_alsa_jack_new() and pa_alsa_jack_free()
This reduces code duplication in alsa-mixer.c and alsa-ucm.c. No
functional changes.
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/alsa/alsa-mixer.c | 45 | ||||
-rw-r--r-- | src/modules/alsa/alsa-mixer.h | 3 | ||||
-rw-r--r-- | src/modules/alsa/alsa-ucm.c | 16 |
3 files changed, 39 insertions, 25 deletions
diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c index bbe1d0f5a..3068fc381 100644 --- a/src/modules/alsa/alsa-mixer.c +++ b/src/modules/alsa/alsa-mixer.c @@ -107,6 +107,34 @@ struct description_map { const char *description; }; +pa_alsa_jack *pa_alsa_jack_new(pa_alsa_path *path, const char *name, const char *alsa_name) { + pa_alsa_jack *jack; + + pa_assert(name); + + jack = pa_xnew0(pa_alsa_jack, 1); + jack->path = path; + jack->name = pa_xstrdup(name); + + if (alsa_name) + jack->alsa_name = pa_xstrdup(alsa_name); + else + jack->alsa_name = pa_sprintf_malloc("%s Jack", name); + + jack->state_unplugged = PA_AVAILABLE_NO; + jack->state_plugged = PA_AVAILABLE_YES; + + return jack; +} + +void pa_alsa_jack_free(pa_alsa_jack *jack) { + pa_assert(jack); + + pa_xfree(jack->alsa_name); + pa_xfree(jack->name); + pa_xfree(jack); +} + static const char *lookup_description(const char *key, const struct description_map dm[], unsigned n) { unsigned i; @@ -524,14 +552,6 @@ static void decibel_fix_free(pa_alsa_decibel_fix *db_fix) { pa_xfree(db_fix); } -static void jack_free(pa_alsa_jack *j) { - pa_assert(j); - - pa_xfree(j->alsa_name); - pa_xfree(j->name); - pa_xfree(j); -} - static void element_free(pa_alsa_element *e) { pa_alsa_option *o; pa_assert(e); @@ -557,7 +577,7 @@ void pa_alsa_path_free(pa_alsa_path *p) { while ((j = p->jacks)) { PA_LLIST_REMOVE(pa_alsa_jack, p->jacks, j); - jack_free(j); + pa_alsa_jack_free(j); } while ((e = p->elements)) { @@ -1793,12 +1813,7 @@ static pa_alsa_jack* jack_get(pa_alsa_path *p, const char *section) { if (pa_streq(j->name, section)) goto finish; - j = pa_xnew0(pa_alsa_jack, 1); - j->state_unplugged = PA_AVAILABLE_NO; - j->state_plugged = PA_AVAILABLE_YES; - j->path = p; - j->name = pa_xstrdup(section); - j->alsa_name = pa_sprintf_malloc("%s Jack", section); + j = pa_alsa_jack_new(p, section, NULL); PA_LLIST_INSERT_AFTER(pa_alsa_jack, p->jacks, p->last_jack, j); finish: diff --git a/src/modules/alsa/alsa-mixer.h b/src/modules/alsa/alsa-mixer.h index ec39fab99..835361b61 100644 --- a/src/modules/alsa/alsa-mixer.h +++ b/src/modules/alsa/alsa-mixer.h @@ -170,6 +170,9 @@ struct pa_alsa_jack { pa_alsa_required_t required_absent; }; +pa_alsa_jack *pa_alsa_jack_new(pa_alsa_path *path, const char *name, const char *alsa_name); +void pa_alsa_jack_free(pa_alsa_jack *jack); + /* A path wraps a series of elements into a single entity which can be * used to control it as if it had a single volume slider, a single * mute switch and a single list of selectable options. */ diff --git a/src/modules/alsa/alsa-ucm.c b/src/modules/alsa/alsa-ucm.c index ef6adcda4..98d9a5dc7 100644 --- a/src/modules/alsa/alsa-ucm.c +++ b/src/modules/alsa/alsa-ucm.c @@ -1268,6 +1268,7 @@ static pa_alsa_jack* ucm_get_jack(pa_alsa_ucm_config *ucm, pa_alsa_ucm_device *d const char *device_name; char *name; const char *jack_control; + char *alsa_name; pa_assert(ucm); pa_assert(device); @@ -1280,17 +1281,14 @@ static pa_alsa_jack* ucm_get_jack(pa_alsa_ucm_config *ucm, pa_alsa_ucm_device *d if (pa_streq(j->name, name)) goto out; - j = pa_xnew0(pa_alsa_jack, 1); - j->state_unplugged = PA_AVAILABLE_NO; - j->state_plugged = PA_AVAILABLE_YES; - j->name = pa_xstrdup(name); - jack_control = pa_proplist_gets(device->proplist, PA_ALSA_PROP_UCM_JACK_CONTROL); if (jack_control) - j->alsa_name = pa_xstrdup(jack_control); + alsa_name = pa_xstrdup(jack_control); else - j->alsa_name = pa_sprintf_malloc("%s Jack", device_name); + alsa_name = pa_sprintf_malloc("%s Jack", device_name); + j = pa_alsa_jack_new(NULL, name, alsa_name); + pa_xfree(alsa_name); PA_LLIST_PREPEND(pa_alsa_jack, ucm->jacks, j); out: @@ -1597,9 +1595,7 @@ void pa_alsa_ucm_free(pa_alsa_ucm_config *ucm) { } PA_LLIST_FOREACH_SAFE(ji, jn, ucm->jacks) { PA_LLIST_REMOVE(pa_alsa_jack, ucm->jacks, ji); - pa_xfree(ji->alsa_name); - pa_xfree(ji->name); - pa_xfree(ji); + pa_alsa_jack_free(ji); } if (ucm->ucm_mgr) { snd_use_case_mgr_close(ucm->ucm_mgr); |