]> code.delx.au - pulseaudio/blob - src/modules/alsa/module-alsa-source.c
alsa-mixer: Add surround 2.1 profile
[pulseaudio] / src / modules / alsa / module-alsa-source.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 <stdio.h>
28
29 #include <asoundlib.h>
30
31 #ifdef HAVE_VALGRIND_MEMCHECK_H
32 #include <valgrind/memcheck.h>
33 #endif
34
35 #include <pulsecore/module.h>
36 #include <pulsecore/modargs.h>
37 #include <pulsecore/log.h>
38 #include <pulsecore/macro.h>
39
40 #include "alsa-util.h"
41 #include "alsa-source.h"
42 #include "module-alsa-source-symdef.h"
43
44 PA_MODULE_AUTHOR("Lennart Poettering");
45 PA_MODULE_DESCRIPTION("ALSA Source");
46 PA_MODULE_VERSION(PACKAGE_VERSION);
47 PA_MODULE_LOAD_ONCE(false);
48 PA_MODULE_USAGE(
49 "name=<name for the source, to be prefixed> "
50 "source_name=<name for the source> "
51 "source_properties=<properties for the source> "
52 "namereg_fail=<when false attempt to synthesise new source_name if it is already taken> "
53 "device=<ALSA device> "
54 "device_id=<ALSA card index> "
55 "format=<sample format> "
56 "rate=<sample rate> "
57 "alternate_rate=<alternate sample rate> "
58 "channels=<number of channels> "
59 "channel_map=<channel map> "
60 "fragments=<number of fragments> "
61 "fragment_size=<fragment size> "
62 "mmap=<enable memory mapping?> "
63 "tsched=<enable system timer based scheduling mode?> "
64 "tsched_buffer_size=<buffer size when using timer based scheduling> "
65 "tsched_buffer_watermark=<upper fill watermark> "
66 "ignore_dB=<ignore dB information from the device?> "
67 "control=<name of mixer control>"
68 "deferred_volume=<Synchronize software and hardware volume changes to avoid momentary jumps?> "
69 "deferred_volume_safety_margin=<usec adjustment depending on volume direction> "
70 "deferred_volume_extra_delay=<usec adjustment to HW volume changes> "
71 "fixed_latency_range=<disable latency range changes on overrun?>");
72
73 static const char* const valid_modargs[] = {
74 "name",
75 "source_name",
76 "source_properties",
77 "namereg_fail",
78 "device",
79 "device_id",
80 "format",
81 "rate",
82 "alternate_rate",
83 "channels",
84 "channel_map",
85 "fragments",
86 "fragment_size",
87 "mmap",
88 "tsched",
89 "tsched_buffer_size",
90 "tsched_buffer_watermark",
91 "ignore_dB",
92 "control",
93 "deferred_volume",
94 "deferred_volume_safety_margin",
95 "deferred_volume_extra_delay",
96 "fixed_latency_range",
97 NULL
98 };
99
100 int pa__init(pa_module*m) {
101 pa_modargs *ma = NULL;
102
103 pa_assert(m);
104
105 pa_alsa_refcnt_inc();
106
107 if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
108 pa_log("Failed to parse module arguments");
109 goto fail;
110 }
111
112 if (!(m->userdata = pa_alsa_source_new(m, ma, __FILE__, NULL, NULL)))
113 goto fail;
114
115 pa_modargs_free(ma);
116
117 return 0;
118
119 fail:
120
121 if (ma)
122 pa_modargs_free(ma);
123
124 pa__done(m);
125
126 return -1;
127 }
128
129 int pa__get_n_used(pa_module *m) {
130 pa_source *source;
131
132 pa_assert(m);
133 pa_assert_se(source = m->userdata);
134
135 return pa_source_linked_by(source);
136 }
137
138 void pa__done(pa_module*m) {
139 pa_source *source;
140
141 pa_assert(m);
142
143 if ((source = m->userdata))
144 pa_alsa_source_free(source);
145
146 pa_alsa_refcnt_dec();
147 }