]> code.delx.au - pulseaudio/commitdiff
include a few HAL properties in our card/sink/source properties for ALSA devices
authorLennart Poettering <lennart@poettering.net>
Sat, 24 Jan 2009 00:25:11 +0000 (01:25 +0100)
committerLennart Poettering <lennart@poettering.net>
Sat, 24 Jan 2009 00:25:11 +0000 (01:25 +0100)
configure.ac
src/Makefile.am
src/modules/alsa/alsa-sink.c
src/modules/alsa/alsa-source.c
src/modules/alsa/alsa-util.c
src/modules/alsa/alsa-util.h
src/modules/alsa/module-alsa-card.c
src/modules/dbus-util.h
src/modules/hal-util.c [new file with mode: 0644]
src/modules/hal-util.h [new file with mode: 0644]
src/modules/module-hal-detect.c

index be79759cbaa1016fefb09948487b908c717ac605..34ce25a3b5c77bb108669235ceefbd22d524510e 100644 (file)
@@ -916,7 +916,10 @@ AC_ARG_ENABLE([hal],
         [hal=auto])
 if test "x${hal}" != xno -a \( "x$HAVE_OSS" = "x1" -o "x$HAVE_ALSA" = "x1" \) ; then
     PKG_CHECK_MODULES(HAL, [ hal >= 0.5.11 ],
-        HAVE_HAL=1,
+        [
+            HAVE_HAL=1
+            AC_DEFINE([HAVE_HAL], 1, [Have HAL.])
+        ],
         [
             HAVE_HAL=0
             if test "x$hal" = xyes ; then
index e27bfbad9e56d8f8ba28dbbf73b8e8ecf97d82c1..d82d8a6e04f80b67cdaa80fe0d8f1ee3de5a7d5f 100644 (file)
@@ -1268,6 +1268,12 @@ libalsa_util_la_LDFLAGS = -avoid-version
 libalsa_util_la_LIBADD = $(AM_LIBADD) $(ASOUNDLIB_LIBS) libpulsecore-@PA_MAJORMINORMICRO@.la libpulsecommon-@PA_MAJORMINORMICRO@.la libpulse.la
 libalsa_util_la_CFLAGS = $(AM_CFLAGS) $(ASOUNDLIB_CFLAGS)
 
+if HAVE_HAL
+libalsa_util_la_SOURCES += modules/hal-util.h modules/hal-util.c
+libalsa_util_la_LIBADD += $(HAL_LIBS) libdbus-util.la
+libalsa_util_la_CFLAGS += $(HAL_CFLAGS)
+endif
+
 module_alsa_sink_la_SOURCES = modules/alsa/module-alsa-sink.c
 module_alsa_sink_la_LDFLAGS = $(MODULE_LDFLAGS)
 module_alsa_sink_la_LIBADD = $(AM_LIBADD) $(ASOUNDLIB_LIBS) libalsa-util.la libpulsecore-@PA_MAJORMINORMICRO@.la libpulsecommon-@PA_MAJORMINORMICRO@.la libpulse.la
index 94b289ff0ebf2657aab0a0a24cec773ce44613d4..5020eac14c2a8871d8e493d75009ff1a6aa98e92 100644 (file)
@@ -1436,7 +1436,7 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
     pa_sink_new_data_set_sample_spec(&data, &ss);
     pa_sink_new_data_set_channel_map(&data, &map);
 
-    pa_alsa_init_proplist_pcm(data.proplist, pcm_info);
+    pa_alsa_init_proplist_pcm(m->core, data.proplist, pcm_info);
     pa_proplist_sets(data.proplist, PA_PROP_DEVICE_STRING, u->device_name);
     pa_proplist_setf(data.proplist, PA_PROP_DEVICE_BUFFERING_BUFFER_SIZE, "%lu", (unsigned long) (period_frames * frame_size * nfrags));
     pa_proplist_setf(data.proplist, PA_PROP_DEVICE_BUFFERING_FRAGMENT_SIZE, "%lu", (unsigned long) (period_frames * frame_size));
index b8ad2e25b45781e2a575d114cd5f3121d3e53893..96e0d89ef98df5e67d07e47627cdd6b658071cca 100644 (file)
@@ -1261,7 +1261,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
     pa_source_new_data_set_sample_spec(&data, &ss);
     pa_source_new_data_set_channel_map(&data, &map);
 
-    pa_alsa_init_proplist_pcm(data.proplist, pcm_info);
+    pa_alsa_init_proplist_pcm(m->core, data.proplist, pcm_info);
     pa_proplist_sets(data.proplist, PA_PROP_DEVICE_STRING, u->device_name);
     pa_proplist_setf(data.proplist, PA_PROP_DEVICE_BUFFERING_BUFFER_SIZE, "%lu", (unsigned long) (period_frames * frame_size * nfrags));
     pa_proplist_setf(data.proplist, PA_PROP_DEVICE_BUFFERING_FRAGMENT_SIZE, "%lu", (unsigned long) (period_frames * frame_size));
index 599079cada78ad760fd630110b2eb95fe2d50fda..7e5a35032e6298a421f48a0992562ddf2e95f3d9 100644 (file)
 
 #include "alsa-util.h"
 
+#ifdef HAVE_HAL
+#include "hal-util.h"
+#endif
+
 struct pa_alsa_fdlist {
     unsigned num_fds;
     struct pollfd *fds;
@@ -1248,7 +1252,7 @@ void pa_alsa_redirect_errors_dec(void) {
         snd_lib_error_set_handler(NULL);
 }
 
-void pa_alsa_init_proplist_card(pa_proplist *p, int card) {
+void pa_alsa_init_proplist_card(pa_core *c, pa_proplist *p, int card) {
     char *cn, *lcn;
 
     pa_assert(p);
@@ -1265,9 +1269,13 @@ void pa_alsa_init_proplist_card(pa_proplist *p, int card) {
         pa_proplist_sets(p, "alsa.long_card_name", lcn);
         free(lcn);
     }
+
+#ifdef HAVE_HAL
+    pa_hal_get_info(c, p, card);
+#endif
 }
 
-void pa_alsa_init_proplist_pcm(pa_proplist *p, snd_pcm_info_t *pcm_info) {
+void pa_alsa_init_proplist_pcm(pa_core *c, pa_proplist *p, snd_pcm_info_t *pcm_info) {
 
     static const char * const alsa_class_table[SND_PCM_CLASS_LAST+1] = {
         [SND_PCM_CLASS_GENERIC] = "generic",
@@ -1321,7 +1329,7 @@ void pa_alsa_init_proplist_pcm(pa_proplist *p, snd_pcm_info_t *pcm_info) {
     pa_proplist_setf(p, "alsa.device", "%u", snd_pcm_info_get_device(pcm_info));
 
     if ((card = snd_pcm_info_get_card(pcm_info)) >= 0) {
-        pa_alsa_init_proplist_card(p, card);
+        pa_alsa_init_proplist_card(c, p, card);
         cn = pa_proplist_gets(p, "alsa.card_name");
     }
 
index 18b04028188dcf66d48f3fa2533a65d0695dcc11..f2d3278b533e90313f95296cd6b7b778a63d2ce5 100644 (file)
@@ -32,6 +32,7 @@
 #include <pulse/proplist.h>
 
 #include <pulsecore/rtpoll.h>
+#include <pulsecore/core.h>
 
 typedef struct pa_alsa_fdlist pa_alsa_fdlist;
 
@@ -118,8 +119,8 @@ void pa_alsa_dump_status(snd_pcm_t *pcm);
 void pa_alsa_redirect_errors_inc(void);
 void pa_alsa_redirect_errors_dec(void);
 
-void pa_alsa_init_proplist_pcm(pa_proplist *p, snd_pcm_info_t *pcm_info);
-void pa_alsa_init_proplist_card(pa_proplist *p, int card);
+void pa_alsa_init_proplist_pcm(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);
 
 int pa_alsa_recover_from_poll(snd_pcm_t *pcm, int revents);
 
index d8a37fe68359ec054516eb56c9c4bb4e7a4e09a6..891195c3554837d1ef7f99673f7b9e88dd52c2a4 100644 (file)
@@ -281,7 +281,7 @@ int pa__init(pa_module*m) {
     pa_card_new_data_init(&data);
     data.driver = __FILE__;
     data.module = m;
-    pa_alsa_init_proplist_card(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);
     set_card_name(&data, ma, u->device_id);
 
index 2b24ac63ae46bea0bd37299f60ef39c4b505de94..c4794dac251fc0f6bd32c0258f3f19f76bb900d9 100644 (file)
@@ -24,6 +24,8 @@
 
 #include <dbus/dbus.h>
 
+#include <pulsecore/core.h>
+
 typedef struct pa_dbus_connection pa_dbus_connection;
 
 /* return the DBusConnection of the specified type for the given core,
diff --git a/src/modules/hal-util.c b/src/modules/hal-util.c
new file mode 100644 (file)
index 0000000..82bbc57
--- /dev/null
@@ -0,0 +1,127 @@
+/***
+  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 <pulsecore/log.h>
+
+#include <hal/libhal.h>
+
+#include "dbus-util.h"
+#include "hal-util.h"
+
+int pa_hal_get_info(pa_core *core, pa_proplist *p, int card) {
+    pa_dbus_connection *c = NULL;
+    LibHalContext *hal = NULL;
+    DBusError error;
+    int r = -1;
+    char **udis = NULL, *t;
+    int n, i;
+
+    pa_assert(core);
+    pa_assert(p);
+    pa_assert(card >= 0);
+
+    dbus_error_init(&error);
+
+    if (!(c = pa_dbus_bus_get(core, DBUS_BUS_SYSTEM, &error)) || dbus_error_is_set(&error)) {
+        pa_log_error("Unable to contact DBUS system bus: %s: %s", error.name, error.message);
+        goto finish;
+    }
+
+
+    if (!(hal = libhal_ctx_new())) {
+        pa_log_error("libhal_ctx_new() finished");
+        goto finish;
+    }
+
+    if (!libhal_ctx_set_dbus_connection(hal, pa_dbus_connection_get(c))) {
+        pa_log_error("Error establishing DBUS connection: %s: %s", error.name, error.message);
+        goto finish;
+    }
+
+    if (!libhal_ctx_init(hal, &error)) {
+        pa_log_error("Couldn't connect to hald: %s: %s", error.name, error.message);
+        goto finish;
+    }
+
+    if (!(udis = libhal_find_device_by_capability(hal, "sound", &n, &error)) < 0) {
+        pa_log_error("Couldn't find devices: %s: %s", error.name, error.message);
+        goto finish;
+    }
+
+    for (i = 0; i < n; i++) {
+        dbus_int32_t this_card;
+
+        this_card = libhal_device_get_property_int(hal, udis[i], "sound.card", &error);
+        if (dbus_error_is_set(&error)) {
+            dbus_error_free(&error);
+            continue;
+        }
+
+        if (this_card == card)
+            break;
+
+    }
+
+    if (i >= n)
+        goto finish;
+
+    pa_proplist_sets(p, "hal.udi", udis[i]);
+
+    t = libhal_device_get_property_string(hal, udis[i], "info.product", &error);
+    if (dbus_error_is_set(&error))
+        dbus_error_free(&error);
+    if (t) {
+        pa_proplist_sets(p, "hal.product", t);
+        libhal_free_string(t);
+    }
+
+    t = libhal_device_get_property_string(hal, udis[i], "sound.card_id", &error);
+    if (dbus_error_is_set(&error))
+        dbus_error_free(&error);
+    if (t) {
+        pa_proplist_sets(p, "hal.card_id", t);
+        libhal_free_string(t);
+    }
+
+    r = 0;
+
+finish:
+
+    if (udis)
+        libhal_free_string_array(udis);
+
+    dbus_error_free(&error);
+
+    if (hal) {
+        libhal_ctx_shutdown(hal, &error);
+        libhal_ctx_free(hal);
+        dbus_error_free(&error);
+    }
+
+    if (c)
+        pa_dbus_connection_unref(c);
+
+    return r;
+}
diff --git a/src/modules/hal-util.h b/src/modules/hal-util.h
new file mode 100644 (file)
index 0000000..3c0e094
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef foohalutilhfoo
+#define foohalutilhfoo
+
+/***
+  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_hal_get_info(pa_core *core, pa_proplist *p, int card);
+
+#endif
index 309b0060d3b549496893f1f469cd19cd7dd3dba3..d3b351a4f1a169ccc7094d423fb51a71e49b9e98 100644 (file)
@@ -801,7 +801,6 @@ fail:
     return -1;
 }
 
-
 void pa__done(pa_module *m) {
     struct userdata *u;