]>
code.delx.au - pulseaudio/blob - src/modules/module-detect.c
4 This file is part of polypaudio.
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 polypaudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
33 #include <sys/types.h>
36 #include <polyp/xmalloc.h>
38 #include <polypcore/core-error.h>
39 #include <polypcore/module.h>
40 #include <polypcore/modargs.h>
41 #include <polypcore/log.h>
42 #include <polypcore/core-util.h>
44 #include "module-detect-symdef.h"
46 PA_MODULE_AUTHOR("Lennart Poettering")
47 PA_MODULE_DESCRIPTION("Detect available audio hardware and load matching drivers")
48 PA_MODULE_VERSION(PACKAGE_VERSION
)
49 PA_MODULE_USAGE("just-one=<boolean>")
53 static int detect_alsa(pa_core
*c
, int just_one
) {
55 int n
= 0, n_sink
= 0, n_source
= 0;
57 if (!(f
= fopen("/proc/asound/devices", "r"))) {
60 pa_log_error(__FILE__
": open(\"/proc/asound/devices\") failed: %s", pa_cstrerror(errno
));
66 char line
[64], args
[64];
67 unsigned device
, subdevice
;
70 if (!fgets(line
, sizeof(line
), f
))
73 line
[strcspn(line
, "\r\n")] = 0;
75 if (pa_endswith(line
, "digital audio playback"))
77 else if (pa_endswith(line
, "digital audio capture"))
82 if (just_one
&& is_sink
&& n_sink
>= 1)
85 if (just_one
&& !is_sink
&& n_source
>= 1)
88 if (sscanf(line
, " %*i: [%u- %u]: ", &device
, &subdevice
) != 2)
91 /* Only one sink per device */
95 snprintf(args
, sizeof(args
), "device=hw:%u,0", device
);
96 if (!pa_module_load(c
, is_sink
? "module-alsa-sink" : "module-alsa-source", args
))
114 static int detect_oss(pa_core
*c
, int just_one
) {
118 if (!(f
= fopen("/dev/sndstat", "r")) &&
119 !(f
= fopen("/proc/sndstat", "r")) &&
120 !(f
= fopen("/proc/asound/oss/sndstat", "r"))) {
123 pa_log_error(__FILE__
": failed to open OSS sndstat device: %s", pa_cstrerror(errno
));
129 char line
[64], args
[64];
132 if (!fgets(line
, sizeof(line
), f
))
135 line
[strcspn(line
, "\r\n")] = 0;
138 b
= strcmp(line
, "Audio devices:") == 0;
145 if (sscanf(line
, "%u: ", &device
) != 1)
149 snprintf(args
, sizeof(args
), "device=/dev/dsp");
151 snprintf(args
, sizeof(args
), "device=/dev/dsp%u", device
);
153 if (!pa_module_load(c
, "module-oss", args
))
168 static int detect_solaris(pa_core
*c
, int just_one
) {
173 dev
= getenv("AUDIODEV");
177 if (stat(dev
, &s
) < 0) {
179 pa_log_error(__FILE__
": failed to open device %s: %s", dev
, pa_cstrerror(errno
));
183 if (!S_ISCHR(s
.st_mode
))
186 snprintf(args
, sizeof(args
), "device=%s", dev
);
188 if (!pa_module_load(c
, "module-solaris", args
))
196 static int detect_waveout(pa_core
*c
, int just_one
) {
198 * FIXME: No point in enumerating devices until the plugin supports
199 * selecting anything but the first.
201 if (!pa_module_load(c
, "module-waveout", ""))
208 int pa__init(pa_core
*c
, pa_module
*m
) {
209 int just_one
= 0, n
= 0;
212 static const char* const valid_modargs
[] = {
220 if (!(ma
= pa_modargs_new(m
->argument
, valid_modargs
))) {
221 pa_log(__FILE__
": Failed to parse module arguments");
225 if (pa_modargs_get_value_boolean(ma
, "just-one", &just_one
) < 0) {
226 pa_log(__FILE__
": just_one= expects a boolean argument.");
231 if ((n
= detect_alsa(c
, just_one
)) <= 0)
234 if ((n
= detect_oss(c
, just_one
)) <= 0)
237 if ((n
= detect_solaris(c
, just_one
)) <= 0)
240 if ((n
= detect_waveout(c
, just_one
)) <= 0)
243 pa_log_warn(__FILE__
": failed to detect any sound hardware.");
247 pa_log_info(__FILE__
": loaded %i modules.", n
);
249 /* We were successful and can unload ourselves now. */
250 pa_module_unload_request(m
);
264 void pa__done(PA_GCC_UNUSED pa_core
*c
, PA_GCC_UNUSED pa_module
*m
) {