add logic for initializing a useful icon name

This commit is contained in:
Lennart Poettering 2009-03-01 21:34:01 +01:00
parent 784ac5b0da
commit 671b927955
10 changed files with 95 additions and 20 deletions

View file

@ -1667,7 +1667,7 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
pa_proplist_sets(data.proplist, PA_PROP_DEVICE_PROFILE_DESCRIPTION, profile->description); pa_proplist_sets(data.proplist, PA_PROP_DEVICE_PROFILE_DESCRIPTION, profile->description);
} }
pa_alsa_set_description(data.proplist); pa_alsa_init_description(data.proplist);
u->sink = pa_sink_new(m->core, &data, PA_SINK_HARDWARE|PA_SINK_LATENCY); u->sink = pa_sink_new(m->core, &data, PA_SINK_HARDWARE|PA_SINK_LATENCY);
pa_sink_new_data_done(&data); pa_sink_new_data_done(&data);

View file

@ -1509,7 +1509,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
pa_proplist_sets(data.proplist, PA_PROP_DEVICE_PROFILE_DESCRIPTION, profile->description); pa_proplist_sets(data.proplist, PA_PROP_DEVICE_PROFILE_DESCRIPTION, profile->description);
} }
pa_alsa_set_description(data.proplist); pa_alsa_init_description(data.proplist);
u->source = pa_source_new(m->core, &data, PA_SOURCE_HARDWARE|PA_SOURCE_LATENCY); u->source = pa_source_new(m->core, &data, PA_SOURCE_HARDWARE|PA_SOURCE_LATENCY);
pa_source_new_data_done(&data); pa_source_new_data_done(&data);

View file

@ -1366,33 +1366,24 @@ void pa_alsa_redirect_errors_dec(void) {
snd_lib_error_set_handler(NULL); snd_lib_error_set_handler(NULL);
} }
void pa_alsa_set_description(pa_proplist *p) { pa_bool_t pa_alsa_init_description(pa_proplist *p) {
const char *s; const char *s;
pa_assert(p); pa_assert(p);
if (pa_proplist_contains(p, PA_PROP_DEVICE_DESCRIPTION)) if (pa_device_init_description(p))
return; return TRUE;
if ((s = pa_proplist_gets(p, PA_PROP_DEVICE_FORM_FACTOR)))
if (pa_streq(s, "internal")) {
pa_proplist_sets(p, PA_PROP_DEVICE_DESCRIPTION, _("Internal Audio"));
return;
}
if ((s = pa_proplist_gets(p, PA_PROP_DEVICE_PRODUCT_NAME))) {
pa_proplist_sets(p, PA_PROP_DEVICE_DESCRIPTION, s);
return;
}
if ((s = pa_proplist_gets(p, "alsa.card_name"))) { if ((s = pa_proplist_gets(p, "alsa.card_name"))) {
pa_proplist_sets(p, PA_PROP_DEVICE_DESCRIPTION, s); pa_proplist_sets(p, PA_PROP_DEVICE_DESCRIPTION, s);
return; return TRUE;
} }
if ((s = pa_proplist_gets(p, "alsa.name"))) { if ((s = pa_proplist_gets(p, "alsa.name"))) {
pa_proplist_sets(p, PA_PROP_DEVICE_DESCRIPTION, s); pa_proplist_sets(p, PA_PROP_DEVICE_DESCRIPTION, s);
return; return TRUE;
} }
return FALSE;
} }
void pa_alsa_init_proplist_card(pa_core *c, pa_proplist *p, int card) { void pa_alsa_init_proplist_card(pa_core *c, pa_proplist *p, int card) {

View file

@ -123,7 +123,7 @@ void pa_alsa_redirect_errors_dec(void);
void pa_alsa_init_proplist_pcm_info(pa_core *c, pa_proplist *p, snd_pcm_info_t *pcm_info); void pa_alsa_init_proplist_pcm_info(pa_core *c, pa_proplist *p, snd_pcm_info_t *pcm_info);
void pa_alsa_init_proplist_card(pa_core *c, pa_proplist *p, int card); void pa_alsa_init_proplist_card(pa_core *c, pa_proplist *p, int card);
void pa_alsa_init_proplist_pcm(pa_core *c, pa_proplist *p, snd_pcm_t *pcm); void pa_alsa_init_proplist_pcm(pa_core *c, pa_proplist *p, snd_pcm_t *pcm);
void pa_alsa_set_description(pa_proplist *p); pa_bool_t pa_alsa_init_description(pa_proplist *p);
int pa_alsa_recover_from_poll(snd_pcm_t *pcm, int revents); int pa_alsa_recover_from_poll(snd_pcm_t *pcm, int revents);

View file

@ -318,7 +318,7 @@ int pa__init(pa_module *m) {
data.module = m; data.module = m;
pa_alsa_init_proplist_card(m->core, data.proplist, alsa_card_index); pa_alsa_init_proplist_card(m->core, data.proplist, alsa_card_index);
pa_proplist_sets(data.proplist, PA_PROP_DEVICE_STRING, u->device_id); pa_proplist_sets(data.proplist, PA_PROP_DEVICE_STRING, u->device_id);
pa_alsa_set_description(data.proplist); pa_alsa_init_description(data.proplist);
set_card_name(&data, ma, u->device_id); set_card_name(&data, ma, u->device_id);
if (reserve) if (reserve)

View file

@ -171,6 +171,12 @@ PA_C_DECL_BEGIN
/** For devices: bus of the device if applicable. One of "isa", "pci", "usb", "firewire", "bluetooth" */ /** For devices: bus of the device if applicable. One of "isa", "pci", "usb", "firewire", "bluetooth" */
#define PA_PROP_DEVICE_BUS "device.bus" #define PA_PROP_DEVICE_BUS "device.bus"
/** For devices: icon for the device. A binary blob containing PNG image data */
#define PA_PROP_DEVICE_ICON "device.icon"
/** For devices: an XDG icon name for the device. e.g. "sound-card-speakers-usb" */
#define PA_PROP_DEVICE_ICON_NAME "device.icon_name"
/** For devices: access mode of the device if applicable. One of "mmap", "mmap_rewrite", "serial" */ /** For devices: access mode of the device if applicable. One of "mmap", "mmap_rewrite", "serial" */
#define PA_PROP_DEVICE_ACCESS_MODE "device.access_mode" #define PA_PROP_DEVICE_ACCESS_MODE "device.access_mode"

View file

@ -160,6 +160,9 @@ pa_card *pa_card_new(pa_core *core, pa_card_new_data *data) {
c->userdata = NULL; c->userdata = NULL;
c->set_profile = NULL; c->set_profile = NULL;
pa_device_init_description(c->proplist);
pa_device_init_icon(c->proplist, TRUE);
pa_assert_se(pa_idxset_put(core->cards, c, &c->index) >= 0); pa_assert_se(pa_idxset_put(core->cards, c, &c->index) >= 0);
pa_log_info("Created %u \"%s\"", c->index, c->name); pa_log_info("Created %u \"%s\"", c->index, c->name);

View file

@ -33,6 +33,7 @@
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulse/util.h> #include <pulse/util.h>
#include <pulse/i18n.h>
#include <pulsecore/sink-input.h> #include <pulsecore/sink-input.h>
#include <pulsecore/namereg.h> #include <pulsecore/namereg.h>
@ -172,6 +173,9 @@ pa_sink* pa_sink_new(
if (data->card) if (data->card)
pa_proplist_update(data->proplist, PA_UPDATE_MERGE, data->card->proplist); pa_proplist_update(data->proplist, PA_UPDATE_MERGE, data->card->proplist);
pa_device_init_description(data->proplist);
pa_device_init_icon(data->proplist, TRUE);
if (pa_hook_fire(&core->hooks[PA_CORE_HOOK_SINK_FIXATE], data) < 0) { if (pa_hook_fire(&core->hooks[PA_CORE_HOOK_SINK_FIXATE], data) < 0) {
pa_xfree(s); pa_xfree(s);
pa_namereg_unregister(core, name); pa_namereg_unregister(core, name);
@ -1886,3 +1890,68 @@ size_t pa_sink_get_max_request(pa_sink *s) {
return r; return r;
} }
/* Called from main context */
pa_bool_t pa_device_init_icon(pa_proplist *p, pa_bool_t is_sink) {
const char *ff, *t = NULL, *s = "", *profile, *bus;
pa_assert(p);
if (pa_proplist_contains(p, PA_PROP_DEVICE_ICON_NAME))
return TRUE;
if ((ff = pa_proplist_gets(p, PA_PROP_DEVICE_FORM_FACTOR))) {
if (pa_streq(ff, "microphone"))
t = "audio-input-microphone";
else if (pa_streq(ff, "webcam"))
t = "camera-web";
else if (pa_streq(ff, "computer"))
t = "computer";
else if (pa_streq(ff, "handset"))
t = "phone";
}
if (!t) {
if (is_sink)
t = "audio-card";
else
t = "audio-input-microphone";
}
if ((profile = pa_proplist_gets(p, PA_PROP_DEVICE_PROFILE_NAME))) {
if (strstr(profile, "analog"))
s = "-analog";
else if (strstr(profile, "iec958"))
s = "-iec958";
else if (strstr(profile, "hdmi"))
s = "-hdmi";
}
bus = pa_proplist_gets(p, PA_PROP_DEVICE_BUS);
pa_proplist_setf(p, PA_PROP_DEVICE_ICON_NAME, "%s%s%s%s", t, pa_strempty(s), bus ? "-" : "", pa_strempty(bus));
return TRUE;
}
pa_bool_t pa_device_init_description(pa_proplist *p) {
const char *s;
pa_assert(p);
if (pa_proplist_contains(p, PA_PROP_DEVICE_DESCRIPTION))
return TRUE;
if ((s = pa_proplist_gets(p, PA_PROP_DEVICE_FORM_FACTOR)))
if (pa_streq(s, "internal")) {
pa_proplist_sets(p, PA_PROP_DEVICE_DESCRIPTION, _("Internal Audio"));
return TRUE;
}
if ((s = pa_proplist_gets(p, PA_PROP_DEVICE_PRODUCT_NAME))) {
pa_proplist_sets(p, PA_PROP_DEVICE_DESCRIPTION, s);
return TRUE;
}
return FALSE;
}

View file

@ -225,6 +225,9 @@ void pa_sink_attach(pa_sink *s);
void pa_sink_set_soft_volume(pa_sink *s, const pa_cvolume *volume); void pa_sink_set_soft_volume(pa_sink *s, const pa_cvolume *volume);
pa_bool_t pa_device_init_description(pa_proplist *p);
pa_bool_t pa_device_init_icon(pa_proplist *p, pa_bool_t is_sink);
/**** May be called by everyone, from main context */ /**** May be called by everyone, from main context */
/* The returned value is supposed to be in the time domain of the sound card! */ /* The returned value is supposed to be in the time domain of the sound card! */

View file

@ -163,6 +163,9 @@ pa_source* pa_source_new(
if (data->card) if (data->card)
pa_proplist_update(data->proplist, PA_UPDATE_MERGE, data->card->proplist); pa_proplist_update(data->proplist, PA_UPDATE_MERGE, data->card->proplist);
pa_device_init_description(data->proplist);
pa_device_init_icon(data->proplist, FALSE);
if (pa_hook_fire(&core->hooks[PA_CORE_HOOK_SOURCE_FIXATE], data) < 0) { if (pa_hook_fire(&core->hooks[PA_CORE_HOOK_SOURCE_FIXATE], data) < 0) {
pa_xfree(s); pa_xfree(s);
pa_namereg_unregister(core, name); pa_namereg_unregister(core, name);