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