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