annotate src/alsa/alsa.c @ 2857:59727b85a091

Restart dialog
author Paula Stanciu <paula.stanciu@gmail.com>
date Fri, 01 Aug 2008 23:18:21 +0300
parents 1e4d147bdc2b
children 8b7a44631121
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
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
42 static void alsa_init(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
43 {
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
44 mcs_handle_t *cfgfile;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
45
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
46 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
47
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
48 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
49 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
50 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
51 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
52 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
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 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
55 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
56 &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
57 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
58 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
59 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
60 &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
61 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
62 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
63 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
64 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
65
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 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
67 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
68
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 if (dlopen("libasound.so.2", RTLD_NOW | RTLD_GLOBAL) == 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
70 {
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 g_message("Cannot load alsa library: %s", dlerror());
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 /* FIXME, this plugin wont work... */
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 }
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 }
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
75
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
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
77 static OutputPlugin alsa_op =
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
78 {
1630
e669c0e6a1f3 alsa: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
79 .description = "ALSA Output Plugin",
e669c0e6a1f3 alsa: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
80 .init = alsa_init,
e669c0e6a1f3 alsa: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
81 .cleanup = alsa_cleanup,
e669c0e6a1f3 alsa: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
82 .about = alsa_about,
e669c0e6a1f3 alsa: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
83 .configure = alsa_configure,
e669c0e6a1f3 alsa: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
84 .get_volume = alsa_get_volume,
e669c0e6a1f3 alsa: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
85 .set_volume = alsa_set_volume,
e669c0e6a1f3 alsa: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
86 .open_audio = alsa_open,
e669c0e6a1f3 alsa: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
87 .write_audio = alsa_write,
1632
67b5bf777a38 fix C99 initialisations
William Pitcock <nenolod@atheme.org>
parents: 1630
diff changeset
88 .close_audio = alsa_close,
1630
e669c0e6a1f3 alsa: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
89 .flush = alsa_flush,
e669c0e6a1f3 alsa: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
90 .pause = alsa_pause,
e669c0e6a1f3 alsa: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
91 .buffer_free = alsa_free,
e669c0e6a1f3 alsa: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
92 .buffer_playing = alsa_playing,
1632
67b5bf777a38 fix C99 initialisations
William Pitcock <nenolod@atheme.org>
parents: 1630
diff changeset
93 .output_time = alsa_get_output_time,
67b5bf777a38 fix C99 initialisations
William Pitcock <nenolod@atheme.org>
parents: 1630
diff changeset
94 .written_time = alsa_get_written_time,
1630
e669c0e6a1f3 alsa: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents: 1395
diff changeset
95 .tell_audio = alsa_tell
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
96 };
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
97
1084
f6fab42de168 [svn] - alsa: commit to plugin API v2
nenolod
parents: 12
diff changeset
98 OutputPlugin *alsa_oplist[] = { &alsa_op, NULL };
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
99
1395
761e17b23e0c added Discovery plugin type
Cristi Magherusan <majeru@atheme-project.org>
parents: 1111
diff changeset
100 DECLARE_PLUGIN(alsa, NULL, NULL, NULL, alsa_oplist, NULL, NULL, NULL, NULL)