]>
code.delx.au - pulseaudio/blob - src/modules/module-null-sink.c
4 This file is part of polypaudio.
6 polypaudio 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 polypaudio 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 polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
36 #include <polypcore/iochannel.h>
37 #include <polypcore/sink.h>
38 #include <polypcore/module.h>
39 #include <polypcore/util.h>
40 #include <polypcore/modargs.h>
41 #include <polypcore/xmalloc.h>
42 #include <polypcore/log.h>
44 #include "module-null-sink-symdef.h"
46 PA_MODULE_AUTHOR("Lennart Poettering")
47 PA_MODULE_DESCRIPTION("Clocked NULL sink")
48 PA_MODULE_VERSION(PACKAGE_VERSION
)
50 "format=<sample format> "
51 "channels=<number of channels> "
53 "sink_name=<name of sink>"
54 "channel_map=<channel map>")
56 #define DEFAULT_SINK_NAME "null"
62 pa_time_event
*time_event
;
66 static const char* const valid_modargs
[] = {
75 static void time_callback(pa_mainloop_api
*m
, pa_time_event
*e
, const struct timeval
*tv
, void *userdata
) {
76 struct userdata
*u
= userdata
;
78 struct timeval ntv
= *tv
;
83 if (pa_sink_render(u
->sink
, u
->block_size
, &chunk
) >= 0) {
85 pa_memblock_unref(chunk
.memblock
);
89 pa_timeval_add(&ntv
, pa_bytes_to_usec(l
, &u
->sink
->sample_spec
));
90 m
->time_restart(e
, &ntv
);
93 int pa__init(pa_core
*c
, pa_module
*m
) {
94 struct userdata
*u
= NULL
;
97 pa_modargs
*ma
= NULL
;
101 if (!(ma
= pa_modargs_new(m
->argument
, valid_modargs
))) {
102 pa_log(__FILE__
": failed to parse module arguments.");
106 ss
= c
->default_sample_spec
;
107 if (pa_modargs_get_sample_spec_and_channel_map(ma
, &ss
, &map
) < 0) {
108 pa_log(__FILE__
": invalid sample format specification or channel map.");
112 u
= pa_xmalloc0(sizeof(struct userdata
));
117 if (!(u
->sink
= pa_sink_new(c
, __FILE__
, pa_modargs_get_value(ma
, "sink_name", DEFAULT_SINK_NAME
), 0, &ss
, &map
))) {
118 pa_log(__FILE__
": failed to create sink.");
122 u
->sink
->userdata
= u
;
123 pa_sink_set_owner(u
->sink
, m
);
124 u
->sink
->description
= pa_sprintf_malloc("NULL sink");
126 pa_gettimeofday(&tv
);
127 u
->time_event
= c
->mainloop
->time_new(c
->mainloop
, &tv
, time_callback
, u
);
129 u
->block_size
= pa_bytes_per_second(&ss
) / 10;
144 void pa__done(pa_core
*c
, pa_module
*m
) {
148 if (!(u
= m
->userdata
))
151 pa_sink_disconnect(u
->sink
);
152 pa_sink_unref(u
->sink
);
154 u
->core
->mainloop
->time_free(u
->time_event
);