annotate src/alsa/alsa.c @ 3020:fdcf79446ddf

Port to new API, lowest prio and NO_DEVICES to avoid autoselect.
author Tony Vroon <chainsaw@gentoo.org>
date Thu, 09 Apr 2009 21:57:39 +0100
parents 8b7a44631121
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1 /* XMMS - ALSA output plugin
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
2 * Copyright (C) 2001 Matthieu Sozeau
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
3 *
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
7 * (at your option) any later version.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
8 *
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
9 * This program is distributed in the hope that it will be useful,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
12 * GNU General Public License for more details.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
13 *
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
15 * along with this program; if not, write to the Free Software
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
17 */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
18
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
19 #include "alsa.h"
2610
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
20 #include <glib.h>
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
21 #include <stdlib.h>
2610
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
22 #include <dlfcn.h>
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
23 #include <ctype.h>
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
24
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
25 struct alsa_config alsa_cfg;
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
26
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
27
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
28 static void alsa_cleanup(void)
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
29 {
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
30 if (alsa_cfg.pcm_device) {
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
31 free(alsa_cfg.pcm_device);
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
32 alsa_cfg.pcm_device = NULL;
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
33 }
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
34
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
35 if (alsa_cfg.mixer_device) {
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
36 free(alsa_cfg.mixer_device);
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
37 alsa_cfg.mixer_device = NULL;
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
38 }
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
39 }
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
40
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
41
3003
8b7a44631121 Add hardware_present probe for a meaningful return code. Probe priority 1.
Tony Vroon <chainsaw@gentoo.org>
parents: 2610
diff changeset
42 static OutputPluginInitStatus alsa_init(void)
2610
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
43 {
3003
8b7a44631121 Add hardware_present probe for a meaningful return code. Probe priority 1.
Tony Vroon <chainsaw@gentoo.org>
parents: 2610
diff changeset
44 if (dlopen("libasound.so.2", RTLD_NOW | RTLD_GLOBAL) == NULL)
8b7a44631121 Add hardware_present probe for a meaningful return code. Probe priority 1.
Tony Vroon <chainsaw@gentoo.org>
parents: 2610
diff changeset
45 {
8b7a44631121 Add hardware_present probe for a meaningful return code. Probe priority 1.
Tony Vroon <chainsaw@gentoo.org>
parents: 2610
diff changeset
46 g_message("Cannot load alsa library: %s", dlerror());
8b7a44631121 Add hardware_present probe for a meaningful return code. Probe priority 1.
Tony Vroon <chainsaw@gentoo.org>
parents: 2610
diff changeset
47 return OUTPUT_PLUGIN_INIT_FAIL;
8b7a44631121 Add hardware_present probe for a meaningful return code. Probe priority 1.
Tony Vroon <chainsaw@gentoo.org>
parents: 2610
diff changeset
48 }
8b7a44631121 Add hardware_present probe for a meaningful return code. Probe priority 1.
Tony Vroon <chainsaw@gentoo.org>
parents: 2610
diff changeset
49
2610
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
50 mcs_handle_t *cfgfile;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
51
2610
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
52 memset(&alsa_cfg, 0, sizeof (alsa_cfg));
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
53
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
54 alsa_cfg.buffer_time = 500;
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
55 alsa_cfg.period_time = 100;
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
56 alsa_cfg.debug = 0;
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
57 alsa_cfg.vol.left = 100;
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
58 alsa_cfg.vol.right = 100;
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
59
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
60 cfgfile = aud_cfg_db_open();
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
61 if (!aud_cfg_db_get_string(cfgfile, ALSA_CFGID, "pcm_device",
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
62 &alsa_cfg.pcm_device))
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
63 alsa_cfg.pcm_device = g_strdup("default");
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
64 g_message("device: %s", alsa_cfg.pcm_device);
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
65 if (!aud_cfg_db_get_string(cfgfile, ALSA_CFGID, "mixer_device",
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
66 &alsa_cfg.mixer_device))
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
67 alsa_cfg.mixer_device = g_strdup("PCM");
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
68 aud_cfg_db_get_int(cfgfile, ALSA_CFGID, "mixer_card", &alsa_cfg.mixer_card);
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
69 aud_cfg_db_get_int(cfgfile, ALSA_CFGID, "buffer_time", &alsa_cfg.buffer_time);
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
70 aud_cfg_db_get_int(cfgfile, ALSA_CFGID, "period_time", &alsa_cfg.period_time);
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
71
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
72 aud_cfg_db_get_bool(cfgfile, ALSA_CFGID, "debug", &alsa_cfg.debug);
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
73 aud_cfg_db_close(cfgfile);
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
74
3003
8b7a44631121 Add hardware_present probe for a meaningful return code. Probe priority 1.
Tony Vroon <chainsaw@gentoo.org>
parents: 2610
diff changeset
75 if (!alsa_hardware_present())
2610
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
76 {
3003
8b7a44631121 Add hardware_present probe for a meaningful return code. Probe priority 1.
Tony Vroon <chainsaw@gentoo.org>
parents: 2610
diff changeset
77 return OUTPUT_PLUGIN_INIT_NO_DEVICES;
8b7a44631121 Add hardware_present probe for a meaningful return code. Probe priority 1.
Tony Vroon <chainsaw@gentoo.org>
parents: 2610
diff changeset
78 } else {
8b7a44631121 Add hardware_present probe for a meaningful return code. Probe priority 1.
Tony Vroon <chainsaw@gentoo.org>
parents: 2610
diff changeset
79 return OUTPUT_PLUGIN_INIT_FOUND_DEVICES;
2610
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
80 }
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
81 }
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
82
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
83
1e4d147bdc2b Combine init.c into alsa.c and use a preprocessor define for configdb ID for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1753
diff changeset
84 static OutputPlugin alsa_op =
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
85 {
1630
e669c0e6a1f3 alsa: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
86 .description = "ALSA Output Plugin",
3003
8b7a44631121 Add hardware_present probe for a meaningful return code. Probe priority 1.
Tony Vroon <chainsaw@gentoo.org>
parents: 2610
diff changeset
87 .probe_priority = 1,
1630
e669c0e6a1f3 alsa: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
88 .init = alsa_init,
e669c0e6a1f3 alsa: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
89 .cleanup = alsa_cleanup,
e669c0e6a1f3 alsa: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
90 .about = alsa_about,
e669c0e6a1f3 alsa: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
91 .configure = alsa_configure,
e669c0e6a1f3 alsa: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
92 .get_volume = alsa_get_volume,
e669c0e6a1f3 alsa: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
93 .set_volume = alsa_set_volume,
e669c0e6a1f3 alsa: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
94 .open_audio = alsa_open,
e669c0e6a1f3 alsa: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
95 .write_audio = alsa_write,
1632
67b5bf777a38 fix C99 initialisations
William Pitcock <nenolod@atheme.org>
parents: 1630
diff changeset
96 .close_audio = alsa_close,
1630
e669c0e6a1f3 alsa: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
97 .flush = alsa_flush,
e669c0e6a1f3 alsa: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
98 .pause = alsa_pause,
e669c0e6a1f3 alsa: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
99 .buffer_free = alsa_free,
e669c0e6a1f3 alsa: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
100 .buffer_playing = alsa_playing,
1632
67b5bf777a38 fix C99 initialisations
William Pitcock <nenolod@atheme.org>
parents: 1630
diff changeset
101 .output_time = alsa_get_output_time,
67b5bf777a38 fix C99 initialisations
William Pitcock <nenolod@atheme.org>
parents: 1630
diff changeset
102 .written_time = alsa_get_written_time,
1630
e669c0e6a1f3 alsa: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
103 .tell_audio = alsa_tell
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
104 };
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
105
1084
f6fab42de168 [svn] - alsa: commit to plugin API v2
nenolod
parents: 12
diff changeset
106 OutputPlugin *alsa_oplist[] = { &alsa_op, NULL };
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
107
1395
761e17b23e0c added Discovery plugin type
Cristi Magherusan <majeru@atheme-project.org>
parents: 1111
diff changeset
108 DECLARE_PLUGIN(alsa, NULL, NULL, NULL, alsa_oplist, NULL, NULL, NULL, NULL)