]> code.delx.au - pulseaudio/blob - src/modules/alsa/module-alsa-sink.c
modules: add {sink|source|card}_properties argument to all modules
[pulseaudio] / src / modules / alsa / module-alsa-sink.c
1 /***
2 This file is part of PulseAudio.
3
4 Copyright 2004-2008 Lennart Poettering
5 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
6
7 PulseAudio is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published
9 by the Free Software Foundation; either version 2.1 of the License,
10 or (at your option) any later version.
11
12 PulseAudio is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with PulseAudio; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA.
21 ***/
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <pulsecore/core.h>
28 #include <pulsecore/module.h>
29 #include <pulsecore/sink.h>
30 #include <pulsecore/modargs.h>
31
32 #include "alsa-util.h"
33 #include "alsa-sink.h"
34 #include "module-alsa-sink-symdef.h"
35
36 PA_MODULE_AUTHOR("Lennart Poettering");
37 PA_MODULE_DESCRIPTION("ALSA Sink");
38 PA_MODULE_VERSION(PACKAGE_VERSION);
39 PA_MODULE_LOAD_ONCE(FALSE);
40 PA_MODULE_USAGE(
41 "name=<name of the sink, to be prefixed> "
42 "sink_name=<name for the sink> "
43 "sink_properities=<properties for the sink> "
44 "device=<ALSA device> "
45 "device_id=<ALSA card index> "
46 "format=<sample format> "
47 "rate=<sample rate> "
48 "channels=<number of channels> "
49 "channel_map=<channel map> "
50 "fragments=<number of fragments> "
51 "fragment_size=<fragment size> "
52 "mmap=<enable memory mapping?> "
53 "tsched=<enable system timer based scheduling mode?> "
54 "tsched_buffer_size=<buffer size when using timer based scheduling> "
55 "tsched_buffer_watermark=<lower fill watermark> "
56 "ignore_dB=<ignore dB information from the device?> "
57 "control=<name of mixer control>");
58
59 static const char* const valid_modargs[] = {
60 "name",
61 "sink_name",
62 "sink_properties",
63 "device",
64 "device_id",
65 "format",
66 "rate",
67 "channels",
68 "channel_map",
69 "fragments",
70 "fragment_size",
71 "mmap",
72 "tsched",
73 "tsched_buffer_size",
74 "tsched_buffer_watermark",
75 "ignore_dB",
76 "control",
77 NULL
78 };
79
80 int pa__init(pa_module*m) {
81 pa_modargs *ma = NULL;
82
83 pa_assert(m);
84
85 pa_alsa_redirect_errors_inc();
86 snd_config_update_free_global();
87
88 if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
89 pa_log("Failed to parse module arguments");
90 goto fail;
91 }
92
93 if (!(m->userdata = pa_alsa_sink_new(m, ma, __FILE__, NULL, NULL)))
94 goto fail;
95
96 pa_modargs_free(ma);
97
98 return 0;
99
100 fail:
101
102 if (ma)
103 pa_modargs_free(ma);
104
105 pa__done(m);
106
107 return -1;
108 }
109
110 int pa__get_n_used(pa_module *m) {
111 pa_sink *sink;
112
113 pa_assert(m);
114 pa_assert_se(sink = m->userdata);
115
116 return pa_sink_linked_by(sink);
117 }
118
119 void pa__done(pa_module*m) {
120 pa_sink *sink;
121
122 pa_assert(m);
123
124 if ((sink = m->userdata))
125 pa_alsa_sink_free(sink);
126
127 snd_config_update_free_global();
128 pa_alsa_redirect_errors_dec();
129 }