alsa: Remove unnecessary hctl handles being passed around

Now that we have switched to using the mixer handle only,
there is no use for sending hctl handles around.

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
This commit is contained in:
David Henningsson 2014-09-01 15:58:22 +02:00
parent f2120fc2b6
commit 300a5e3ed7
8 changed files with 28 additions and 74 deletions

View file

@ -2657,7 +2657,7 @@ static void path_create_settings(pa_alsa_path *p) {
element_create_settings(p->elements, NULL); element_create_settings(p->elements, NULL);
} }
int pa_alsa_path_probe(pa_alsa_path *p, snd_mixer_t *m, snd_hctl_t *hctl, bool ignore_dB) { int pa_alsa_path_probe(pa_alsa_path *p, snd_mixer_t *m, bool ignore_dB) {
pa_alsa_element *e; pa_alsa_element *e;
pa_alsa_jack *j; pa_alsa_jack *j;
double min_dB[PA_CHANNEL_POSITION_MAX], max_dB[PA_CHANNEL_POSITION_MAX]; double min_dB[PA_CHANNEL_POSITION_MAX], max_dB[PA_CHANNEL_POSITION_MAX];
@ -3851,7 +3851,6 @@ static void mapping_paths_probe(pa_alsa_mapping *m, pa_alsa_profile *profile,
snd_pcm_t *pcm_handle; snd_pcm_t *pcm_handle;
pa_alsa_path_set *ps; pa_alsa_path_set *ps;
snd_mixer_t *mixer_handle; snd_mixer_t *mixer_handle;
snd_hctl_t *hctl_handle;
if (direction == PA_ALSA_DIRECTION_OUTPUT) { if (direction == PA_ALSA_DIRECTION_OUTPUT) {
if (m->output_path_set) if (m->output_path_set)
@ -3870,7 +3869,7 @@ static void mapping_paths_probe(pa_alsa_mapping *m, pa_alsa_profile *profile,
pa_assert(pcm_handle); pa_assert(pcm_handle);
mixer_handle = pa_alsa_open_mixer_for_pcm(pcm_handle, NULL, &hctl_handle); mixer_handle = pa_alsa_open_mixer_for_pcm(pcm_handle, NULL);
if (!mixer_handle) { if (!mixer_handle) {
/* Cannot open mixer, remove all entries */ /* Cannot open mixer, remove all entries */
pa_hashmap_remove_all(ps->paths); pa_hashmap_remove_all(ps->paths);
@ -3878,7 +3877,7 @@ static void mapping_paths_probe(pa_alsa_mapping *m, pa_alsa_profile *profile,
} }
PA_HASHMAP_FOREACH(p, ps->paths, state) { PA_HASHMAP_FOREACH(p, ps->paths, state) {
if (pa_alsa_path_probe(p, mixer_handle, hctl_handle, m->profile_set->ignore_dB) < 0) { if (pa_alsa_path_probe(p, mixer_handle, m->profile_set->ignore_dB) < 0) {
pa_hashmap_remove(ps->paths, p); pa_hashmap_remove(ps->paths, p);
} }
} }

View file

@ -226,7 +226,7 @@ void pa_alsa_element_dump(pa_alsa_element *e);
pa_alsa_path *pa_alsa_path_new(const char *paths_dir, const char *fname, pa_alsa_direction_t direction); pa_alsa_path *pa_alsa_path_new(const char *paths_dir, const char *fname, pa_alsa_direction_t direction);
pa_alsa_path *pa_alsa_path_synthesize(const char *element, pa_alsa_direction_t direction); pa_alsa_path *pa_alsa_path_synthesize(const char *element, pa_alsa_direction_t direction);
int pa_alsa_path_probe(pa_alsa_path *p, snd_mixer_t *m, snd_hctl_t *hctl, bool ignore_dB); int pa_alsa_path_probe(pa_alsa_path *p, snd_mixer_t *m, bool ignore_dB);
void pa_alsa_path_dump(pa_alsa_path *p); void pa_alsa_path_dump(pa_alsa_path *p);
int pa_alsa_path_get_volume(pa_alsa_path *p, snd_mixer_t *m, const pa_channel_map *cm, pa_cvolume *v); int pa_alsa_path_get_volume(pa_alsa_path *p, snd_mixer_t *m, const pa_channel_map *cm, pa_cvolume *v);
int pa_alsa_path_get_mute(pa_alsa_path *path, snd_mixer_t *m, bool *muted); int pa_alsa_path_get_mute(pa_alsa_path *path, snd_mixer_t *m, bool *muted);
@ -335,7 +335,7 @@ void pa_alsa_profile_set_free(pa_alsa_profile_set *s);
void pa_alsa_profile_set_dump(pa_alsa_profile_set *s); void pa_alsa_profile_set_dump(pa_alsa_profile_set *s);
void pa_alsa_profile_set_drop_unsupported(pa_alsa_profile_set *s); void pa_alsa_profile_set_drop_unsupported(pa_alsa_profile_set *s);
snd_mixer_t *pa_alsa_open_mixer_for_pcm(snd_pcm_t *pcm, char **ctl_device, snd_hctl_t **hctl); snd_mixer_t *pa_alsa_open_mixer_for_pcm(snd_pcm_t *pcm, char **ctl_device);
pa_alsa_fdlist *pa_alsa_fdlist_new(void); pa_alsa_fdlist *pa_alsa_fdlist_new(void);
void pa_alsa_fdlist_free(pa_alsa_fdlist *fdl); void pa_alsa_fdlist_free(pa_alsa_fdlist *fdl);

View file

@ -1886,12 +1886,10 @@ static void set_sink_name(pa_sink_new_data *data, pa_modargs *ma, const char *de
} }
static void find_mixer(struct userdata *u, pa_alsa_mapping *mapping, const char *element, bool ignore_dB) { static void find_mixer(struct userdata *u, pa_alsa_mapping *mapping, const char *element, bool ignore_dB) {
snd_hctl_t *hctl;
if (!mapping && !element) if (!mapping && !element)
return; return;
if (!(u->mixer_handle = pa_alsa_open_mixer_for_pcm(u->pcm_handle, &u->control_device, &hctl))) { if (!(u->mixer_handle = pa_alsa_open_mixer_for_pcm(u->pcm_handle, &u->control_device))) {
pa_log_info("Failed to find a working mixer device."); pa_log_info("Failed to find a working mixer device.");
return; return;
} }
@ -1901,7 +1899,7 @@ static void find_mixer(struct userdata *u, pa_alsa_mapping *mapping, const char
if (!(u->mixer_path = pa_alsa_path_synthesize(element, PA_ALSA_DIRECTION_OUTPUT))) if (!(u->mixer_path = pa_alsa_path_synthesize(element, PA_ALSA_DIRECTION_OUTPUT)))
goto fail; goto fail;
if (pa_alsa_path_probe(u->mixer_path, u->mixer_handle, hctl, ignore_dB) < 0) if (pa_alsa_path_probe(u->mixer_path, u->mixer_handle, ignore_dB) < 0)
goto fail; goto fail;
pa_log_debug("Probed mixer path %s:", u->mixer_path->name); pa_log_debug("Probed mixer path %s:", u->mixer_path->name);

View file

@ -1604,12 +1604,10 @@ static void set_source_name(pa_source_new_data *data, pa_modargs *ma, const char
} }
static void find_mixer(struct userdata *u, pa_alsa_mapping *mapping, const char *element, bool ignore_dB) { static void find_mixer(struct userdata *u, pa_alsa_mapping *mapping, const char *element, bool ignore_dB) {
snd_hctl_t *hctl;
if (!mapping && !element) if (!mapping && !element)
return; return;
if (!(u->mixer_handle = pa_alsa_open_mixer_for_pcm(u->pcm_handle, &u->control_device, &hctl))) { if (!(u->mixer_handle = pa_alsa_open_mixer_for_pcm(u->pcm_handle, &u->control_device))) {
pa_log_info("Failed to find a working mixer device."); pa_log_info("Failed to find a working mixer device.");
return; return;
} }
@ -1619,7 +1617,7 @@ static void find_mixer(struct userdata *u, pa_alsa_mapping *mapping, const char
if (!(u->mixer_path = pa_alsa_path_synthesize(element, PA_ALSA_DIRECTION_INPUT))) if (!(u->mixer_path = pa_alsa_path_synthesize(element, PA_ALSA_DIRECTION_INPUT)))
goto fail; goto fail;
if (pa_alsa_path_probe(u->mixer_path, u->mixer_handle, hctl, ignore_dB) < 0) if (pa_alsa_path_probe(u->mixer_path, u->mixer_handle, ignore_dB) < 0)
goto fail; goto fail;
pa_log_debug("Probed mixer path %s:", u->mixer_path->name); pa_log_debug("Probed mixer path %s:", u->mixer_path->name);

View file

@ -1426,21 +1426,20 @@ static void profile_finalize_probing(pa_alsa_profile *p) {
static void ucm_mapping_jack_probe(pa_alsa_mapping *m) { static void ucm_mapping_jack_probe(pa_alsa_mapping *m) {
snd_pcm_t *pcm_handle; snd_pcm_t *pcm_handle;
snd_mixer_t *mixer_handle; snd_mixer_t *mixer_handle;
snd_hctl_t *hctl_handle;
pa_alsa_ucm_mapping_context *context = &m->ucm_context; pa_alsa_ucm_mapping_context *context = &m->ucm_context;
pa_alsa_ucm_device *dev; pa_alsa_ucm_device *dev;
uint32_t idx; uint32_t idx;
pcm_handle = m->direction == PA_ALSA_DIRECTION_OUTPUT ? m->output_pcm : m->input_pcm; pcm_handle = m->direction == PA_ALSA_DIRECTION_OUTPUT ? m->output_pcm : m->input_pcm;
mixer_handle = pa_alsa_open_mixer_for_pcm(pcm_handle, NULL, &hctl_handle); mixer_handle = pa_alsa_open_mixer_for_pcm(pcm_handle, NULL);
if (!mixer_handle || !hctl_handle) if (!mixer_handle)
return; return;
PA_IDXSET_FOREACH(dev, context->ucm_devices, idx) { PA_IDXSET_FOREACH(dev, context->ucm_devices, idx) {
pa_alsa_jack *jack; pa_alsa_jack *jack;
jack = m->direction == PA_ALSA_DIRECTION_OUTPUT ? dev->output_jack : dev->input_jack; jack = m->direction == PA_ALSA_DIRECTION_OUTPUT ? dev->output_jack : dev->input_jack;
pa_assert (jack); pa_assert (jack);
jack->has_control = pa_alsa_find_jack(hctl_handle, jack->alsa_name) != NULL; jack->has_control = pa_alsa_mixer_find(mixer_handle, jack->alsa_name, 0) != NULL;
pa_log_info("UCM jack %s has_control=%d", jack->name, jack->has_control); pa_log_info("UCM jack %s has_control=%d", jack->name, jack->has_control);
} }

View file

@ -1476,30 +1476,6 @@ snd_mixer_elem_t *pa_alsa_mixer_find(snd_mixer_t *mixer, const char *name, unsig
return NULL; return NULL;
} }
snd_hctl_elem_t* pa_alsa_find_jack(snd_hctl_t *hctl, const char* jack_name) {
snd_ctl_elem_id_t *id;
snd_ctl_elem_id_alloca(&id);
snd_ctl_elem_id_clear(id);
snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_CARD);
snd_ctl_elem_id_set_name(id, jack_name);
return snd_hctl_find_elem(hctl, id);
}
snd_hctl_elem_t* pa_alsa_find_eld_ctl(snd_hctl_t *hctl, int device) {
snd_ctl_elem_id_t *id;
/* See if we can find the ELD control */
snd_ctl_elem_id_alloca(&id);
snd_ctl_elem_id_clear(id);
snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_PCM);
snd_ctl_elem_id_set_name(id, "ELD");
snd_ctl_elem_id_set_device(id, device);
return snd_hctl_find_elem(hctl, id);
}
static int mixer_class_compare(const snd_mixer_elem_t *c1, const snd_mixer_elem_t *c2) static int mixer_class_compare(const snd_mixer_elem_t *c1, const snd_mixer_elem_t *c2)
{ {
/* Dummy compare function */ /* Dummy compare function */
@ -1544,7 +1520,7 @@ static int mixer_class_event(snd_mixer_class_t *class, unsigned int mask,
return 0; return 0;
} }
static int prepare_mixer(snd_mixer_t *mixer, const char *dev, snd_hctl_t **hctl) { static int prepare_mixer(snd_mixer_t *mixer, const char *dev) {
int err; int err;
snd_mixer_class_t *class; snd_mixer_class_t *class;
@ -1556,13 +1532,6 @@ static int prepare_mixer(snd_mixer_t *mixer, const char *dev, snd_hctl_t **hctl)
return -1; return -1;
} }
/* Note: The hctl handle returned should not be freed.
It is closed/freed by alsa-lib on snd_mixer_close/free */
if (hctl && (err = snd_mixer_get_hctl(mixer, dev, hctl)) < 0) {
pa_log_info("Unable to get hctl of mixer %s: %s", dev, pa_alsa_strerror(err));
return -1;
}
if (snd_mixer_class_malloc(&class)) { if (snd_mixer_class_malloc(&class)) {
pa_log_info("Failed to allocate mixer class for %s", dev); pa_log_info("Failed to allocate mixer class for %s", dev);
return -1; return -1;
@ -1590,7 +1559,7 @@ static int prepare_mixer(snd_mixer_t *mixer, const char *dev, snd_hctl_t **hctl)
return 0; return 0;
} }
snd_mixer_t *pa_alsa_open_mixer(int alsa_card_index, char **ctl_device, snd_hctl_t **hctl) { snd_mixer_t *pa_alsa_open_mixer(int alsa_card_index, char **ctl_device) {
int err; int err;
snd_mixer_t *m; snd_mixer_t *m;
char *md; char *md;
@ -1604,7 +1573,7 @@ snd_mixer_t *pa_alsa_open_mixer(int alsa_card_index, char **ctl_device, snd_hctl
/* Then, try by card index */ /* Then, try by card index */
md = pa_sprintf_malloc("hw:%i", alsa_card_index); md = pa_sprintf_malloc("hw:%i", alsa_card_index);
if (prepare_mixer(m, md, hctl) >= 0) { if (prepare_mixer(m, md) >= 0) {
if (ctl_device) if (ctl_device)
*ctl_device = md; *ctl_device = md;
@ -1620,7 +1589,7 @@ snd_mixer_t *pa_alsa_open_mixer(int alsa_card_index, char **ctl_device, snd_hctl
return NULL; return NULL;
} }
snd_mixer_t *pa_alsa_open_mixer_for_pcm(snd_pcm_t *pcm, char **ctl_device, snd_hctl_t **hctl) { snd_mixer_t *pa_alsa_open_mixer_for_pcm(snd_pcm_t *pcm, char **ctl_device) {
int err; int err;
snd_mixer_t *m; snd_mixer_t *m;
const char *dev; const char *dev;
@ -1636,7 +1605,7 @@ snd_mixer_t *pa_alsa_open_mixer_for_pcm(snd_pcm_t *pcm, char **ctl_device, snd_h
/* First, try by name */ /* First, try by name */
if ((dev = snd_pcm_name(pcm))) if ((dev = snd_pcm_name(pcm)))
if (prepare_mixer(m, dev, hctl) >= 0) { if (prepare_mixer(m, dev) >= 0) {
if (ctl_device) if (ctl_device)
*ctl_device = pa_xstrdup(dev); *ctl_device = pa_xstrdup(dev);
@ -1653,7 +1622,7 @@ snd_mixer_t *pa_alsa_open_mixer_for_pcm(snd_pcm_t *pcm, char **ctl_device, snd_h
md = pa_sprintf_malloc("hw:%i", card_idx); md = pa_sprintf_malloc("hw:%i", card_idx);
if (!dev || !pa_streq(dev, md)) if (!dev || !pa_streq(dev, md))
if (prepare_mixer(m, md, hctl) >= 0) { if (prepare_mixer(m, md) >= 0) {
if (ctl_device) if (ctl_device)
*ctl_device = md; *ctl_device = md;
@ -1671,25 +1640,19 @@ snd_mixer_t *pa_alsa_open_mixer_for_pcm(snd_pcm_t *pcm, char **ctl_device, snd_h
return NULL; return NULL;
} }
int pa_alsa_get_hdmi_eld(snd_hctl_t *hctl, int device, pa_hdmi_eld *eld) { int pa_alsa_get_hdmi_eld(snd_hctl_elem_t *elem, pa_hdmi_eld *eld) {
/* The ELD format is specific to HDA Intel sound cards and defined in the /* The ELD format is specific to HDA Intel sound cards and defined in the
HDA specification: http://www.intel.com/content/www/us/en/standards/high-definition-audio-specification.html */ HDA specification: http://www.intel.com/content/www/us/en/standards/high-definition-audio-specification.html */
int err; int err;
snd_hctl_elem_t *elem;
snd_ctl_elem_info_t *info; snd_ctl_elem_info_t *info;
snd_ctl_elem_value_t *value; snd_ctl_elem_value_t *value;
uint8_t *elddata; uint8_t *elddata;
unsigned int eldsize, mnl; unsigned int eldsize, mnl;
unsigned int device;
pa_assert(eld != NULL); pa_assert(eld != NULL);
pa_assert(elem != NULL);
/* See if we can find the ELD control */
elem = pa_alsa_find_eld_ctl(hctl, device);
if (elem == NULL) {
pa_log_debug("No ELD info control found (for device=%d)", device);
return -1;
}
/* Does it have any contents? */ /* Does it have any contents? */
snd_ctl_elem_info_alloca(&info); snd_ctl_elem_info_alloca(&info);
@ -1700,6 +1663,7 @@ int pa_alsa_get_hdmi_eld(snd_hctl_t *hctl, int device, pa_hdmi_eld *eld) {
return -1; return -1;
} }
device = snd_hctl_elem_get_device(elem);
eldsize = snd_ctl_elem_info_get_count(info); eldsize = snd_ctl_elem_info_get_count(info);
elddata = (unsigned char *) snd_ctl_elem_value_get_bytes(value); elddata = (unsigned char *) snd_ctl_elem_value_get_bytes(value);
if (elddata == NULL || eldsize == 0) { if (elddata == NULL || eldsize == 0) {

View file

@ -142,18 +142,15 @@ const char* pa_alsa_strerror(int errnum);
bool pa_alsa_may_tsched(bool want); bool pa_alsa_may_tsched(bool want);
snd_hctl_elem_t* pa_alsa_find_jack(snd_hctl_t *hctl, const char* jack_name);
snd_hctl_elem_t* pa_alsa_find_eld_ctl(snd_hctl_t *hctl, int device);
snd_mixer_elem_t *pa_alsa_mixer_find(snd_mixer_t *mixer, const char *name, unsigned int device); snd_mixer_elem_t *pa_alsa_mixer_find(snd_mixer_t *mixer, const char *name, unsigned int device);
snd_mixer_t *pa_alsa_open_mixer(int alsa_card_index, char **ctl_device, snd_hctl_t **hctl); snd_mixer_t *pa_alsa_open_mixer(int alsa_card_index, char **ctl_device);
typedef struct pa_hdmi_eld pa_hdmi_eld; typedef struct pa_hdmi_eld pa_hdmi_eld;
struct pa_hdmi_eld { struct pa_hdmi_eld {
char monitor_name[17]; char monitor_name[17];
}; };
int pa_alsa_get_hdmi_eld(snd_hctl_t *hctl, int device, pa_hdmi_eld *eld); int pa_alsa_get_hdmi_eld(snd_hctl_elem_t *elem, pa_hdmi_eld *eld);
#endif #endif

View file

@ -111,7 +111,6 @@ struct userdata {
int alsa_card_index; int alsa_card_index;
snd_mixer_t *mixer_handle; snd_mixer_t *mixer_handle;
snd_hctl_t *hctl_handle;
pa_hashmap *jacks; pa_hashmap *jacks;
pa_alsa_fdlist *mixer_fdl; pa_alsa_fdlist *mixer_fdl;
@ -422,7 +421,7 @@ static int hdmi_eld_changed(snd_mixer_elem_t *melem, unsigned int mask) {
return 0; return 0;
} }
if (pa_alsa_get_hdmi_eld(u->hctl_handle, device, &eld) < 0) if (pa_alsa_get_hdmi_eld(elem, &eld) < 0)
memset(&eld, 0, sizeof(eld)); memset(&eld, 0, sizeof(eld));
old_monitor_name = pa_proplist_gets(p->proplist, PA_PROP_DEVICE_PRODUCT_NAME); old_monitor_name = pa_proplist_gets(p->proplist, PA_PROP_DEVICE_PRODUCT_NAME);
@ -444,7 +443,7 @@ static void init_eld_ctls(struct userdata *u) {
void *state; void *state;
pa_device_port *port; pa_device_port *port;
if (!u->hctl_handle) if (!u->mixer_handle)
return; return;
PA_HASHMAP_FOREACH(port, u->card->ports, state) { PA_HASHMAP_FOREACH(port, u->card->ports, state) {
@ -501,7 +500,7 @@ static void init_jacks(struct userdata *u) {
u->mixer_fdl = pa_alsa_fdlist_new(); u->mixer_fdl = pa_alsa_fdlist_new();
u->mixer_handle = pa_alsa_open_mixer(u->alsa_card_index, NULL, &u->hctl_handle); u->mixer_handle = pa_alsa_open_mixer(u->alsa_card_index, NULL);
if (u->mixer_handle && pa_alsa_fdlist_set_handle(u->mixer_fdl, u->mixer_handle, NULL, u->core->mainloop) >= 0) { if (u->mixer_handle && pa_alsa_fdlist_set_handle(u->mixer_fdl, u->mixer_handle, NULL, u->core->mainloop) >= 0) {
PA_HASHMAP_FOREACH(jack, u->jacks, state) { PA_HASHMAP_FOREACH(jack, u->jacks, state) {
jack->melem = pa_alsa_mixer_find(u->mixer_handle, jack->alsa_name, 0); jack->melem = pa_alsa_mixer_find(u->mixer_handle, jack->alsa_name, 0);
@ -516,7 +515,7 @@ static void init_jacks(struct userdata *u) {
} }
} else } else
pa_log("Failed to open hctl/mixer for jack detection"); pa_log("Failed to open mixer for jack detection");
} }