]>
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
34 #include <polypcore/module.h>
35 #include <polypcore/modargs.h>
36 #include <polypcore/xmalloc.h>
37 #include <polypcore/log.h>
39 #include "module-detect-symdef.h"
41 PA_MODULE_AUTHOR("Lennart Poettering")
42 PA_MODULE_DESCRIPTION("Detect available audio hardware and load matching drivers")
43 PA_MODULE_VERSION(PACKAGE_VERSION
)
44 PA_MODULE_USAGE("just-one=<boolean>")
46 static const char *endswith(const char *haystack
, const char *needle
) {
50 if ((l
= strlen(haystack
)) < (m
= strlen(needle
)))
53 if (strcmp(p
= haystack
+ l
- m
, needle
))
60 static int detect_alsa(pa_core
*c
, int just_one
) {
62 int n
= 0, n_sink
= 0, n_source
= 0;
64 if (!(f
= fopen("/proc/asound/devices", "r"))) {
67 pa_log_error(__FILE__
": open(\"/proc/asound/devices\") failed: %s\n", strerror(errno
));
73 char line
[64], args
[64];
74 unsigned device
, subdevice
;
77 if (!fgets(line
, sizeof(line
), f
))
80 line
[strcspn(line
, "\r\n")] = 0;
82 if (endswith(line
, "digital audio playback"))
84 else if (endswith(line
, "digital audio capture"))
89 if (just_one
&& is_sink
&& n_sink
>= 1)
92 if (just_one
&& !is_sink
&& n_source
>= 1)
95 if (sscanf(line
, " %*i: [%u- %u]: ", &device
, &subdevice
) != 2)
98 /* Only one sink per device */
102 snprintf(args
, sizeof(args
), "device=hw:%u,0", device
);
103 if (!pa_module_load(c
, is_sink
? "module-alsa-sink" : "module-alsa-source", args
))
121 static int detect_oss(pa_core
*c
, int just_one
) {
125 if (!(f
= fopen("/dev/sndstat", "r")) &&
126 !(f
= fopen("/proc/sndstat", "r")) &&
127 !(f
= fopen("/proc/asound/oss/sndstat", "r"))) {
130 pa_log_error(__FILE__
": failed to open OSS sndstat device: %s\n", strerror(errno
));
136 char line
[64], args
[64];
139 if (!fgets(line
, sizeof(line
), f
))
142 line
[strcspn(line
, "\r\n")] = 0;
145 b
= strcmp(line
, "Audio devices:") == 0;
152 if (sscanf(line
, "%u: ", &device
) != 1)
156 snprintf(args
, sizeof(args
), "device=/dev/dsp");
158 snprintf(args
, sizeof(args
), "device=/dev/dsp%u", device
);
160 if (!pa_module_load(c
, "module-oss", args
))
175 static int detect_solaris(pa_core
*c
, int just_one
) {
180 dev
= getenv("AUDIODEV");
184 if (stat(dev
, &s
) < 0) {
186 pa_log_error(__FILE__
": failed to open device %s: %s\n", dev
, strerror(errno
));
193 snprintf(args
, sizeof(args
), "device=%s", dev
);
195 if (!pa_module_load(c
, "module-solaris", args
))
203 static int detect_waveout(pa_core
*c
, int just_one
) {
205 * FIXME: No point in enumerating devices until the plugin supports
206 * selecting anything but the first.
208 if (!pa_module_load(c
, "module-waveout", ""))
215 int pa__init(pa_core
*c
, pa_module
*m
) {
216 int just_one
= 0, n
= 0;
219 static const char* const valid_modargs
[] = {
227 if (!(ma
= pa_modargs_new(m
->argument
, valid_modargs
))) {
228 pa_log(__FILE__
": Failed to parse module arguments\n");
232 if (pa_modargs_get_value_boolean(ma
, "just-one", &just_one
) < 0) {
233 pa_log(__FILE__
": just_one= expects a boolean argument.\n");
238 if ((n
= detect_alsa(c
, just_one
)) <= 0)
241 if ((n
= detect_oss(c
, just_one
)) <= 0)
244 if ((n
= detect_solaris(c
, just_one
)) <= 0)
247 if ((n
= detect_waveout(c
, just_one
)) <= 0)
250 pa_log_warn(__FILE__
": failed to detect any sound hardware.\n");
254 pa_log_info(__FILE__
": loaded %i modules.\n", n
);
256 /* We were successful and can unload ourselves now. */
257 pa_module_unload_request(m
);
271 void pa__done(pa_core
*c
, pa_module
*m
) {