]> code.delx.au - pulseaudio/blob - src/modules/alsa/module-alsa-sink.c
Merge branch 'master' of ssh://rootserver/home/lennart/git/public/pulseaudio
[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 "device=<ALSA device> "
44 "device_id=<ALSA card index> "
45 "format=<sample format> "
46 "rate=<sample rate> "
47 "channels=<number of channels> "
48 "channel_map=<channel map> "
49 "fragments=<number of fragments> "
50 "fragment_size=<fragment size> "
51 "mmap=<enable memory mapping?> "
52 "tsched=<enable system timer based scheduling mode?> "
53 "tsched_buffer_size=<buffer size when using timer based scheduling> "
54 "tsched_buffer_watermark=<lower fill watermark> "
55 "ignore_dB=<ignore dB information from the device?>");
56
57 static const char* const valid_modargs[] = {
58 "name",
59 "sink_name",
60 "device",
61 "device_id",
62 "format",
63 "rate",
64 "channels",
65 "channel_map",
66 "fragments",
67 "fragment_size",
68 "mmap",
69 "tsched",
70 "tsched_buffer_size",
71 "tsched_buffer_watermark",
72 "ignore_dB",
73 NULL
74 };
75
76 int pa__init(pa_module*m) {
77 pa_modargs *ma = NULL;
78
79 pa_assert(m);
80
81 pa_alsa_redirect_errors_inc();
82 snd_config_update_free_global();
83
84 if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
85 pa_log("Failed to parse module arguments");
86 goto fail;
87 }
88
89 if (!(m->userdata = pa_alsa_sink_new(m, ma, __FILE__, NULL, NULL)))
90 goto fail;
91
92 pa_modargs_free(ma);
93
94 return 0;
95
96 fail:
97
98 if (ma)
99 pa_modargs_free(ma);
100
101 pa__done(m);
102
103 return -1;
104 }
105
106 int pa__get_n_used(pa_module *m) {
107 pa_sink *sink;
108
109 pa_assert(m);
110 pa_assert_se(sink = m->userdata);
111
112 return pa_sink_linked_by(sink);
113 }
114
115 void pa__done(pa_module*m) {
116 pa_sink *sink;
117
118 pa_assert(m);
119
120 if ((sink = m->userdata))
121 pa_alsa_sink_free(sink);
122
123 snd_config_update_free_global();
124 pa_alsa_redirect_errors_dec();
125 }