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, see <http://www.gnu.org/licenses/>.
19 ***/
20
21 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24
25 #include <pulsecore/module.h>
26 #include <pulsecore/sink.h>
27 #include <pulsecore/modargs.h>
28
29 #include "alsa-util.h"
30 #include "alsa-sink.h"
31
32 PA_MODULE_AUTHOR("Lennart Poettering");
33 PA_MODULE_DESCRIPTION("ALSA Sink");
34 PA_MODULE_VERSION(PACKAGE_VERSION);
35 PA_MODULE_LOAD_ONCE(false);
36 PA_MODULE_USAGE(
37 "name=<name of the sink, to be prefixed> "
38 "sink_name=<name for the sink> "
39 "sink_properties=<properties for the sink> "
40 "namereg_fail=<when false attempt to synthesise new sink_name if it is already taken> "
41 "device=<ALSA device> "
42 "device_id=<ALSA card index> "
43 "format=<sample format> "
44 "rate=<sample rate> "
45 "alternate_rate=<alternate 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 "ignore_dB=<ignore dB information from the device?> "
55 "control=<name of mixer control, or name and index separated by a comma> "
56 "rewind_safeguard=<number of bytes that cannot be rewound> "
57 "deferred_volume=<Synchronize software and hardware volume changes to avoid momentary jumps?> "
58 "deferred_volume_safety_margin=<usec adjustment depending on volume direction> "
59 "deferred_volume_extra_delay=<usec adjustment to HW volume changes> "
60 "fixed_latency_range=<disable latency range changes on underrun?>");
61
62 static const char* const valid_modargs[] = {
63 "name",
64 "sink_name",
65 "sink_properties",
66 "namereg_fail",
67 "device",
68 "device_id",
69 "format",
70 "rate",
71 "alternate_rate",
72 "channels",
73 "channel_map",
74 "fragments",
75 "fragment_size",
76 "mmap",
77 "tsched",
78 "tsched_buffer_size",
79 "tsched_buffer_watermark",
80 "ignore_dB",
81 "control",
82 "rewind_safeguard",
83 "deferred_volume",
84 "deferred_volume_safety_margin",
85 "deferred_volume_extra_delay",
86 "fixed_latency_range",
87 NULL
88 };
89
pa__init(pa_module * m)90 int pa__init(pa_module*m) {
91 pa_modargs *ma = NULL;
92
93 pa_assert(m);
94
95 pa_alsa_refcnt_inc();
96
97 if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
98 pa_log("Failed to parse module arguments");
99 goto fail;
100 }
101
102 if (!(m->userdata = pa_alsa_sink_new(m, ma, __FILE__, NULL, NULL)))
103 goto fail;
104
105 pa_modargs_free(ma);
106
107 return 0;
108
109 fail:
110
111 if (ma)
112 pa_modargs_free(ma);
113
114 pa__done(m);
115
116 return -1;
117 }
118
pa__get_n_used(pa_module * m)119 int pa__get_n_used(pa_module *m) {
120 pa_sink *sink;
121
122 pa_assert(m);
123 pa_assert_se(sink = m->userdata);
124
125 return pa_sink_linked_by(sink);
126 }
127
pa__done(pa_module * m)128 void pa__done(pa_module*m) {
129 pa_sink *sink;
130
131 pa_assert(m);
132
133 if ((sink = m->userdata))
134 pa_alsa_sink_free(sink);
135
136 pa_alsa_refcnt_dec();
137 }
138