]>
code.delx.au - pulseaudio/blob - src/modules/module-detect.c
4 This file is part of PulseAudio.
6 PulseAudio 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 PulseAudio 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 PulseAudio; 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 <pulse/xmalloc.h>
38 #include <pulsecore/core-error.h>
39 #include <pulsecore/module.h>
40 #include <pulsecore/modargs.h>
41 #include <pulsecore/log.h>
42 #include <pulsecore/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", 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 || strcmp(line
, "Installed devices:") == 0;
145 if (sscanf(line
, "%u: ", &device
) == 1) {
147 snprintf(args
, sizeof(args
), "device=/dev/dsp");
149 snprintf(args
, sizeof(args
), "device=/dev/dsp%u", device
);
151 if (!pa_module_load(c
, "module-oss", args
))
154 } else if (sscanf(line
, "pcm%u: ", &device
) == 1) {
155 /* FreeBSD support, the devices are named /dev/dsp0.0, dsp0.1 and so on */
156 snprintf(args
, sizeof(args
), "device=/dev/dsp%u.0", device
);
158 if (!pa_module_load(c
, "module-oss", args
))
174 static int detect_solaris(pa_core
*c
, int just_one
) {
179 dev
= getenv("AUDIODEV");
183 if (stat(dev
, &s
) < 0) {
185 pa_log_error(__FILE__
": failed to open device %s: %s", dev
, pa_cstrerror(errno
));
189 if (!S_ISCHR(s
.st_mode
))
192 snprintf(args
, sizeof(args
), "device=%s", dev
);
194 if (!pa_module_load(c
, "module-solaris", args
))
202 static int detect_waveout(pa_core
*c
, int just_one
) {
204 * FIXME: No point in enumerating devices until the plugin supports
205 * selecting anything but the first.
207 if (!pa_module_load(c
, "module-waveout", ""))
214 int pa__init(pa_core
*c
, pa_module
*m
) {
215 int just_one
= 0, n
= 0;
218 static const char* const valid_modargs
[] = {
226 if (!(ma
= pa_modargs_new(m
->argument
, valid_modargs
))) {
227 pa_log(__FILE__
": Failed to parse module arguments");
231 if (pa_modargs_get_value_boolean(ma
, "just-one", &just_one
) < 0) {
232 pa_log(__FILE__
": just_one= expects a boolean argument.");
237 if ((n
= detect_alsa(c
, just_one
)) <= 0)
240 if ((n
= detect_oss(c
, just_one
)) <= 0)
243 if ((n
= detect_solaris(c
, just_one
)) <= 0)
246 if ((n
= detect_waveout(c
, just_one
)) <= 0)
249 pa_log_warn(__FILE__
": failed to detect any sound hardware.");
253 pa_log_info(__FILE__
": loaded %i modules.", n
);
255 /* We were successful and can unload ourselves now. */
256 pa_module_unload_request(m
);
270 void pa__done(PA_GCC_UNUSED pa_core
*c
, PA_GCC_UNUSED pa_module
*m
) {