diff options
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/alsa/alsa-sink.c | 2 | ||||
-rw-r--r-- | src/modules/alsa/alsa-source.c | 2 | ||||
-rw-r--r-- | src/modules/alsa/alsa-util.c | 42 | ||||
-rw-r--r-- | src/modules/alsa/alsa-util.h | 1 | ||||
-rw-r--r-- | src/modules/alsa/module-alsa-card.c | 1 | ||||
-rw-r--r-- | src/modules/bluetooth/bluetooth-util.c | 4 | ||||
-rw-r--r-- | src/modules/bluetooth/ipc.h | 3 | ||||
-rw-r--r-- | src/modules/bluetooth/module-bluetooth-device.c | 2 | ||||
-rw-r--r-- | src/modules/hal-util.c | 3 | ||||
-rw-r--r-- | src/modules/reserve.h | 21 | ||||
-rw-r--r-- | src/modules/udev-util.c | 142 | ||||
-rw-r--r-- | src/modules/udev-util.h | 30 |
12 files changed, 228 insertions, 25 deletions
diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c index 708e020c..d4325881 100644 --- a/src/modules/alsa/alsa-sink.c +++ b/src/modules/alsa/alsa-sink.c @@ -1667,6 +1667,8 @@ 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_alsa_init_description(data.proplist); + u->sink = pa_sink_new(m->core, &data, PA_SINK_HARDWARE|PA_SINK_LATENCY); pa_sink_new_data_done(&data); diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c index 4321c7ff..7a1b0f8d 100644 --- a/src/modules/alsa/alsa-source.c +++ b/src/modules/alsa/alsa-source.c @@ -1509,6 +1509,8 @@ 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_alsa_init_description(data.proplist); + u->source = pa_source_new(m->core, &data, PA_SOURCE_HARDWARE|PA_SOURCE_LATENCY); pa_source_new_data_done(&data); diff --git a/src/modules/alsa/alsa-util.c b/src/modules/alsa/alsa-util.c index 6740c069..7d833ff7 100644 --- a/src/modules/alsa/alsa-util.c +++ b/src/modules/alsa/alsa-util.c @@ -47,6 +47,10 @@ #include "hal-util.h" #endif +#ifdef HAVE_UDEV +#include "udev-util.h" +#endif + struct pa_alsa_fdlist { unsigned num_fds; struct pollfd *fds; @@ -1362,6 +1366,26 @@ void pa_alsa_redirect_errors_dec(void) { snd_lib_error_set_handler(NULL); } +pa_bool_t pa_alsa_init_description(pa_proplist *p) { + const char *s; + pa_assert(p); + + if (pa_device_init_description(p)) + return TRUE; + + if ((s = pa_proplist_gets(p, "alsa.card_name"))) { + pa_proplist_sets(p, PA_PROP_DEVICE_DESCRIPTION, s); + return TRUE; + } + + if ((s = pa_proplist_gets(p, "alsa.name"))) { + pa_proplist_sets(p, PA_PROP_DEVICE_DESCRIPTION, s); + return TRUE; + } + + return FALSE; +} + void pa_alsa_init_proplist_card(pa_core *c, pa_proplist *p, int card) { char *cn, *lcn, *dn; @@ -1385,6 +1409,10 @@ void pa_alsa_init_proplist_card(pa_core *c, pa_proplist *p, int card) { pa_xfree(dn); } +#ifdef HAVE_UDEV + pa_udev_get_info(c, p, card); +#endif + #ifdef HAVE_HAL pa_hal_get_info(c, p, card); #endif @@ -1411,7 +1439,7 @@ void pa_alsa_init_proplist_pcm_info(pa_core *c, pa_proplist *p, snd_pcm_info_t * snd_pcm_class_t class; snd_pcm_subclass_t subclass; - const char *n, *id, *sdn, *cn = NULL; + const char *n, *id, *sdn; int card; pa_assert(p); @@ -1426,6 +1454,7 @@ void pa_alsa_init_proplist_pcm_info(pa_core *c, pa_proplist *p, snd_pcm_info_t * if (alsa_class_table[class]) pa_proplist_sets(p, "alsa.class", alsa_class_table[class]); } + subclass = snd_pcm_info_get_subclass(pcm_info); if (subclass <= SND_PCM_SUBCLASS_LAST) if (alsa_subclass_table[subclass]) @@ -1443,17 +1472,8 @@ void pa_alsa_init_proplist_pcm_info(pa_core *c, pa_proplist *p, snd_pcm_info_t * pa_proplist_setf(p, "alsa.device", "%u", snd_pcm_info_get_device(pcm_info)); - if ((card = snd_pcm_info_get_card(pcm_info)) >= 0) { + if ((card = snd_pcm_info_get_card(pcm_info)) >= 0) pa_alsa_init_proplist_card(c, p, card); - cn = pa_proplist_gets(p, "alsa.card_name"); - } - - if (cn && n && !strstr(cn, n) && !strstr(n, cn)) - pa_proplist_setf(p, PA_PROP_DEVICE_DESCRIPTION, "%s, %s", cn, n); - else if (cn && (!n || strstr(cn, n))) - pa_proplist_sets(p, PA_PROP_DEVICE_DESCRIPTION, cn); - else if (n) - pa_proplist_sets(p, PA_PROP_DEVICE_DESCRIPTION, n); } void pa_alsa_init_proplist_pcm(pa_core *c, pa_proplist *p, snd_pcm_t *pcm) { diff --git a/src/modules/alsa/alsa-util.h b/src/modules/alsa/alsa-util.h index 899532e2..a8397ae9 100644 --- a/src/modules/alsa/alsa-util.h +++ b/src/modules/alsa/alsa-util.h @@ -123,6 +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_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); +pa_bool_t pa_alsa_init_description(pa_proplist *p); int pa_alsa_recover_from_poll(snd_pcm_t *pcm, int revents); diff --git a/src/modules/alsa/module-alsa-card.c b/src/modules/alsa/module-alsa-card.c index fc6b886b..9e149a48 100644 --- a/src/modules/alsa/module-alsa-card.c +++ b/src/modules/alsa/module-alsa-card.c @@ -318,6 +318,7 @@ int pa__init(pa_module *m) { data.module = m; 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_alsa_init_description(data.proplist); set_card_name(&data, ma, u->device_id); if (reserve) diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c index 7855c2ef..6b522200 100644 --- a/src/modules/bluetooth/bluetooth-util.c +++ b/src/modules/bluetooth/bluetooth-util.c @@ -811,8 +811,8 @@ const char*pa_bluetooth_get_form_factor(uint32_t class) { [1] = "headset", [2] = "hands-free", [4] = "microphone", - [5] = "external-speakers", - [6] = "headphones", + [5] = "speaker", + [6] = "headphone", [7] = "portable", [8] = "car", [10] = "hifi" diff --git a/src/modules/bluetooth/ipc.h b/src/modules/bluetooth/ipc.h index 4203150b..f030acfa 100644 --- a/src/modules/bluetooth/ipc.h +++ b/src/modules/bluetooth/ipc.h @@ -160,7 +160,8 @@ struct bt_get_capabilities_req { #define BT_HFP_CODEC_PCM 0x00 -#define BT_PCM_FLAG_NREC 1 +#define BT_PCM_FLAG_NREC 0x01 +#define BT_PCM_FLAG_PCM_ROUTING 0x02 typedef struct { uint8_t transport; diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c index b2fb1db1..3332df2c 100644 --- a/src/modules/bluetooth/module-bluetooth-device.c +++ b/src/modules/bluetooth/module-bluetooth-device.c @@ -1728,7 +1728,7 @@ static int add_card(struct userdata *u, const char * default_profile) { pa_proplist_sets(data.proplist, PA_PROP_DEVICE_STRING, u->device->address); pa_proplist_sets(data.proplist, PA_PROP_DEVICE_API, "bluez"); pa_proplist_sets(data.proplist, PA_PROP_DEVICE_CLASS, "sound"); - pa_proplist_sets(data.proplist, PA_PROP_DEVICE_CONNECTOR, "bluetooth"); + pa_proplist_sets(data.proplist, PA_PROP_DEVICE_BUS, "bluetooth"); if ((ff = pa_bluetooth_get_form_factor(u->device->class))) pa_proplist_sets(data.proplist, PA_PROP_DEVICE_FORM_FACTOR, ff); pa_proplist_sets(data.proplist, "bluez.path", u->device->path); diff --git a/src/modules/hal-util.c b/src/modules/hal-util.c index 82bbc57e..6959a706 100644 --- a/src/modules/hal-util.c +++ b/src/modules/hal-util.c @@ -89,6 +89,9 @@ int pa_hal_get_info(pa_core *core, pa_proplist *p, int card) { pa_proplist_sets(p, "hal.udi", udis[i]); + /* The data HAL stores in info.product is not actually a product + * string but simply the ALSA card name. We will hence not write + * it to PA_PROP_DEVICE_PRODUCT_NAME */ t = libhal_device_get_property_string(hal, udis[i], "info.product", &error); if (dbus_error_is_set(&error)) dbus_error_free(&error); diff --git a/src/modules/reserve.h b/src/modules/reserve.h index ceb1ad11..b315a08c 100644 --- a/src/modules/reserve.h +++ b/src/modules/reserve.h @@ -31,10 +31,11 @@ typedef struct rd_device rd_device; /* Prototype for a function that is called whenever someone else wants - * your app to release the device you having locked. A return value <= - * 0 denies the request, a positive return value agrees to it. Before - * returning your application should close the device in question - * completely to make sure the new application may acceess it. */ + * your application to release the device it has locked. A return + * value <= 0 denies the request, a positive return value agrees to + * it. Before returning your application should close the device in + * question completely to make sure the new application may access + * it. */ typedef int (*rd_request_cb_t)( rd_device *d, int forced); /* Non-zero if an application forcibly took the lock away without asking. If this is the case then the return value of this call is ignored. */ @@ -48,20 +49,20 @@ int rd_acquire( const char *device_name, /* The device to lock, e.g. "Audio0" */ const char *application_name, /* A human readable name of the application, e.g. "PulseAudio Sound Server" */ int32_t priority, /* The priority for this application. If unsure use 0 */ - rd_request_cb_t request_cb, /* Will be called whenever someone asks that this device shall be released. May be NULL if priority is INT32_MAX */ + rd_request_cb_t request_cb, /* Will be called whenever someone requests that this device shall be released. May be NULL if priority is INT32_MAX */ DBusError *error); /* If we fail due to a D-Bus related issue the error will be filled in here. May be NULL. */ -/* Unlock (if needed) and destroy a rd_device object again */ +/* Unlock (if needed) and destroy an rd_device object again */ void rd_release(rd_device *d); -/* Set the application device name for a rd_device object Returns 0 on - * success, a negative errno style return value on error. */ +/* Set the application device name for an rd_device object. Returns 0 + * on success, a negative errno style return value on error. */ int rd_set_application_device_name(rd_device *d, const char *name); -/* Attach a userdata pointer to a rd_device */ +/* Attach a userdata pointer to an rd_device */ void rd_set_userdata(rd_device *d, void *userdata); -/* Query the userdata pointer from a rd_device. Returns NULL if no +/* Query the userdata pointer from an rd_device. Returns NULL if no * userdata was set. */ void* rd_get_userdata(rd_device *d); diff --git a/src/modules/udev-util.c b/src/modules/udev-util.c new file mode 100644 index 00000000..a72bc8f8 --- /dev/null +++ b/src/modules/udev-util.c @@ -0,0 +1,142 @@ +/*** + This file is part of PulseAudio. + + Copyright 2009 Lennart Poettering + + PulseAudio is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + PulseAudio is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with PulseAudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <libudev.h> + +#include <pulse/xmalloc.h> +#include <pulse/proplist.h> + +#include <pulsecore/log.h> +#include <pulsecore/core-util.h> + +#include "udev-util.h" + +static int read_id(struct udev_device *d, const char *n) { + const char *v; + unsigned u; + + pa_assert(d); + pa_assert(n); + + if (!(v = udev_device_get_property_value(d, n))) + return -1; + + if (pa_startswith(v, "0x")) + v += 2; + + if (!*v) + return -1; + + if (sscanf(v, "%04x", &u) != 1) + return -1; + + if (u > 0xFFFFU) + return -1; + + return u; +} + +int pa_udev_get_info(pa_core *core, pa_proplist *p, int card_idx) { + int r = -1; + struct udev *udev; + struct udev_device *card; + char *t; + const char *v; + int id; + + pa_assert(core); + pa_assert(p); + pa_assert(card_idx >= 0); + + if (!(udev = udev_new())) { + pa_log_error("Failed to allocate udev context."); + goto finish; + } + + t = pa_sprintf_malloc("%s/class/sound/card%i", udev_get_sys_path(udev), card_idx); + card = udev_device_new_from_syspath(udev, t); + pa_xfree(t); + + if (!card) { + pa_log_error("Failed to get card object."); + goto finish; + } + + if (!pa_proplist_contains(p, PA_PROP_DEVICE_BUS)) + if ((v = udev_device_get_property_value(card, "ID_BUS")) && *v) + pa_proplist_sets(p, PA_PROP_DEVICE_BUS, v); + + if (!pa_proplist_contains(p, PA_PROP_DEVICE_VENDOR_ID)) + if ((id = read_id(card, "ID_VENDOR_ID")) > 0 && *v) + pa_proplist_setf(p, PA_PROP_DEVICE_VENDOR_ID, "%04x", id); + + if (!pa_proplist_contains(p, PA_PROP_DEVICE_VENDOR_NAME)) { + if ((v = udev_device_get_property_value(card, "ID_VENDOR_FROM_DATABASE")) && *v) + pa_proplist_sets(p, PA_PROP_DEVICE_VENDOR_NAME, v); + else if ((v = udev_device_get_property_value(card, "ID_VENDOR")) && *v) + pa_proplist_sets(p, PA_PROP_DEVICE_VENDOR_NAME, v); + } + + if (!pa_proplist_contains(p, PA_PROP_DEVICE_PRODUCT_ID)) + if ((id = read_id(card, "ID_MODEL_ID")) >= 0) + pa_proplist_setf(p, PA_PROP_DEVICE_PRODUCT_ID, "%04x", id); + + if (!pa_proplist_contains(p, PA_PROP_DEVICE_PRODUCT_NAME)) { + if ((v = udev_device_get_property_value(card, "ID_MODEL_FROM_DATABASE")) && *v) + pa_proplist_sets(p, PA_PROP_DEVICE_PRODUCT_NAME, v); + else if ((v = udev_device_get_property_value(card, "ID_MODEL")) && *v) + pa_proplist_sets(p, PA_PROP_DEVICE_PRODUCT_NAME, v); + } + + if (!pa_proplist_contains(p, PA_PROP_DEVICE_SERIAL)) + if ((v = udev_device_get_property_value(card, "ID_SERIAL")) && *v) + pa_proplist_sets(p, PA_PROP_DEVICE_SERIAL, v); + + if (!pa_proplist_contains(p, PA_PROP_DEVICE_FORM_FACTOR)) + if ((v = udev_device_get_property_value(card, "SOUND_FORM_FACTOR")) && *v) + pa_proplist_sets(p, PA_PROP_DEVICE_FORM_FACTOR, v); + + if (!pa_proplist_contains(p, PA_PROP_DEVICE_BUS_PATH)) + if ((v = udev_device_get_devpath(card))) + pa_proplist_sets(p, PA_PROP_DEVICE_BUS_PATH, v); + + /* This is normaly not set by th udev rules but may be useful to + * allow administrators to overwrite the device description.*/ + if (!pa_proplist_contains(p, PA_PROP_DEVICE_DESCRIPTION)) + if ((v = udev_device_get_property_value(card, "SOUND_DESCRIPTION")) && *v) + pa_proplist_sets(p, PA_PROP_DEVICE_DESCRIPTION, v); + + r = 0; + +finish: + + if (card) + udev_device_unref(card); + + if (udev) + udev_unref(udev); + + return r; +} diff --git a/src/modules/udev-util.h b/src/modules/udev-util.h new file mode 100644 index 00000000..86fbba7f --- /dev/null +++ b/src/modules/udev-util.h @@ -0,0 +1,30 @@ +#ifndef fooudevutilhfoo +#define fooudevutilhfoo + +/*** + This file is part of PulseAudio. + + Copyright 2009 Lennart Poettering + + PulseAudio is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + PulseAudio is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with PulseAudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + + +#include <pulsecore/core.h> + +int pa_udev_get_info(pa_core *core, pa_proplist *p, int card); + +#endif |