]>
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 <polyp/timeval.h>
37 #include <polyp/xmalloc.h>
39 #include <polypcore/iochannel.h>
40 #include <polypcore/sink.h>
41 #include <polypcore/module.h>
42 #include <polypcore/core-util.h>
43 #include <polypcore/modargs.h>
44 #include <polypcore/log.h>
46 #include "module-null-sink-symdef.h"
48 PA_MODULE_AUTHOR("Lennart Poettering")
49 PA_MODULE_DESCRIPTION("Clocked NULL sink")
50 PA_MODULE_VERSION(PACKAGE_VERSION
)
52 "format=<sample format> "
53 "channels=<number of channels> "
55 "sink_name=<name of sink>"
56 "channel_map=<channel map>")
58 #define DEFAULT_SINK_NAME "null"
64 pa_time_event
*time_event
;
68 static const char* const valid_modargs
[] = {
77 static void time_callback(pa_mainloop_api
*m
, pa_time_event
*e
, const struct timeval
*tv
, void *userdata
) {
78 struct userdata
*u
= userdata
;
80 struct timeval ntv
= *tv
;
85 if (pa_sink_render(u
->sink
, u
->block_size
, &chunk
) >= 0) {
87 pa_memblock_unref(chunk
.memblock
);
91 pa_timeval_add(&ntv
, pa_bytes_to_usec(l
, &u
->sink
->sample_spec
));
92 m
->time_restart(e
, &ntv
);
95 int pa__init(pa_core
*c
, pa_module
*m
) {
96 struct userdata
*u
= NULL
;
99 pa_modargs
*ma
= NULL
;
103 if (!(ma
= pa_modargs_new(m
->argument
, valid_modargs
))) {
104 pa_log(__FILE__
": failed to parse module arguments.");
108 ss
= c
->default_sample_spec
;
109 if (pa_modargs_get_sample_spec_and_channel_map(ma
, &ss
, &map
, PA_CHANNEL_MAP_DEFAULT
) < 0) {
110 pa_log(__FILE__
": invalid sample format specification or channel map.");
114 u
= pa_xmalloc0(sizeof(struct userdata
));
119 if (!(u
->sink
= pa_sink_new(c
, __FILE__
, pa_modargs_get_value(ma
, "sink_name", DEFAULT_SINK_NAME
), 0, &ss
, &map
))) {
120 pa_log(__FILE__
": failed to create sink.");
124 u
->sink
->userdata
= u
;
125 pa_sink_set_owner(u
->sink
, m
);
126 u
->sink
->description
= pa_sprintf_malloc("NULL sink");
128 pa_gettimeofday(&tv
);
129 u
->time_event
= c
->mainloop
->time_new(c
->mainloop
, &tv
, time_callback
, u
);
131 u
->block_size
= pa_bytes_per_second(&ss
) / 10;
146 void pa__done(pa_core
*c
, pa_module
*m
) {
150 if (!(u
= m
->userdata
))
153 pa_sink_disconnect(u
->sink
);
154 pa_sink_unref(u
->sink
);
156 u
->core
->mainloop
->time_free(u
->time_event
);