2 This file is part of PulseAudio.
4 Copyright 2009 Lennart Poettering
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 #include <pulse/xmalloc.h>
27 #include <pulsecore/core-util.h>
28 #include <pulsecore/modargs.h>
30 #include "alsa-util.h"
31 #include "module-alsa-card-symdef.h"
33 PA_MODULE_AUTHOR("Lennart Poettering");
34 PA_MODULE_DESCRIPTION("ALSA Card");
35 PA_MODULE_VERSION(PACKAGE_VERSION
);
36 PA_MODULE_LOAD_ONCE(FALSE
);
38 "name=<name for the sink/source> "
39 "device_id=<ALSA card index> "
40 "format=<sample format> "
42 "fragments=<number of fragments> "
43 "fragment_size=<fragment size> "
44 "mmap=<enable memory mapping?> "
45 "tsched=<enable system timer based scheduling mode?> "
46 "tsched_buffer_size=<buffer size when using timer based scheduling> "
47 "tsched_buffer_watermark=<lower fill watermark> "
48 "profile=<profile name>");
50 static const char* const valid_modargs
[] = {
63 "tsched_buffer_watermark",
67 #define DEFAULT_DEVICE_ID "0"
79 const pa_alsa_profile_info
*sink
, *source
;
82 static void enumerate_cb(
83 const pa_alsa_profile_info
*sink
,
84 const pa_alsa_profile_info
*source
,
87 pa_hashmap
*profiles
= (pa_hashmap
*) userdata
;
90 struct profile_data
*d
;
93 n
= pa_sprintf_malloc("%s+%s", sink
->name
, source
->name
);
94 t
= pa_sprintf_malloc("Output %s + Input %s", sink
->description
, source
->description
);
96 n
= pa_xstrdup(sink
->name
);
97 t
= pa_sprintf_malloc("Output %s", sink
->description
);
100 n
= pa_xstrdup(source
->name
);
101 t
= pa_sprintf_malloc("Input %s", source
->description
);
104 pa_log_info("Found output profile '%s'", t
);
106 p
= pa_card_profile_new(n
, t
, sizeof(struct profile_data
));
112 p
->n_sources
= !!source
;
115 p
->max_sink_channels
= sink
->map
.channels
;
117 p
->max_source_channels
= source
->map
.channels
;
119 d
= PA_CARD_PROFILE_DATA(p
);
124 pa_hashmap_put(profiles
, p
->name
, p
);
127 int pa__init(pa_module
*m
) {
128 pa_card_new_data data
;
133 pa_alsa_redirect_errors_inc();
137 if (!(ma
= pa_modargs_new(m
->argument
, valid_modargs
))) {
138 pa_log("Failed to parse module arguments");
142 m
->userdata
= u
= pa_xnew0(struct userdata
, 1);
145 u
->device_id
= pa_xstrdup(pa_modargs_get_value(ma
, "device_id", DEFAULT_DEVICE_ID
));
147 if ((alsa_card_index
= snd_card_get_index(u
->device_id
)) < 0) {
148 pa_log("Card '%s' doesn't exist: %s", u
->device_id
, snd_strerror(alsa_card_index
));
152 pa_card_new_data_init(&data
);
153 data
.driver
= __FILE__
;
155 pa_alsa_init_proplist_card(data
.proplist
, alsa_card_index
);
156 pa_proplist_sets(data
.proplist
, PA_PROP_DEVICE_STRING
, u
->device_id
);
157 pa_card_new_data_set_name(&data
, pa_modargs_get_value(ma
, "name", u
->device_id
));
159 data
.profiles
= pa_hashmap_new(pa_idxset_string_hash_func
, pa_idxset_string_compare_func
);
160 if (pa_alsa_probe_profiles(u
->device_id
, &m
->core
->default_sample_spec
, enumerate_cb
, data
.profiles
) < 0) {
161 pa_card_new_data_done(&data
);
165 u
->card
= pa_card_new(m
->core
, &data
);
166 pa_card_new_data_done(&data
);
179 void pa__done(pa_module
*m
) {
184 if (!(u
= m
->userdata
))
188 pa_card_free(u
->card
);
190 pa_xfree(u
->device_id
);
194 snd_config_update_free_global();
195 pa_alsa_redirect_errors_dec();