]>
code.delx.au - pulseaudio/blob - src/modules/module-null-sink.c
54a8e89023cb7ff80cc1cb1e9046f7645160363d
4 This file is part of PulseAudio.
6 Copyright 2004-2006 Lennart Poettering
8 PulseAudio is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published
10 by the Free Software Foundation; either version 2 of the License,
11 or (at your option) any later version.
13 PulseAudio is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with PulseAudio; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
38 #include <pulse/timeval.h>
39 #include <pulse/xmalloc.h>
41 #include <pulsecore/iochannel.h>
42 #include <pulsecore/sink.h>
43 #include <pulsecore/module.h>
44 #include <pulsecore/core-util.h>
45 #include <pulsecore/modargs.h>
46 #include <pulsecore/log.h>
48 #include "module-null-sink-symdef.h"
50 PA_MODULE_AUTHOR("Lennart Poettering")
51 PA_MODULE_DESCRIPTION("Clocked NULL sink")
52 PA_MODULE_VERSION(PACKAGE_VERSION
)
54 "format=<sample format> "
55 "channels=<number of channels> "
57 "sink_name=<name of sink>"
58 "channel_map=<channel map>"
59 "description=<description for the sink>")
61 #define DEFAULT_SINK_NAME "null"
67 pa_time_event
*time_event
;
71 struct timeval start_time
;
74 static const char* const valid_modargs
[] = {
84 static void time_callback(pa_mainloop_api
*m
, pa_time_event
*e
, const struct timeval
*tv
, void *userdata
) {
85 struct userdata
*u
= userdata
;
87 struct timeval ntv
= *tv
;
92 if (pa_sink_render(u
->sink
, u
->block_size
, &chunk
) >= 0) {
94 pa_memblock_unref(chunk
.memblock
);
98 pa_timeval_add(&ntv
, pa_bytes_to_usec(l
, &u
->sink
->sample_spec
));
99 m
->time_restart(e
, &ntv
);
104 static pa_usec_t
get_latency(pa_sink
*s
) {
105 struct userdata
*u
= s
->userdata
;
109 a
= pa_timeval_diff(pa_gettimeofday(&now
), &u
->start_time
);
110 b
= pa_bytes_to_usec(u
->n_bytes
, &s
->sample_spec
);
112 return b
> a
? b
- a
: 0;
115 int pa__init(pa_core
*c
, pa_module
*m
) {
116 struct userdata
*u
= NULL
;
119 pa_modargs
*ma
= NULL
;
124 if (!(ma
= pa_modargs_new(m
->argument
, valid_modargs
))) {
125 pa_log("failed to parse module arguments.");
129 ss
= c
->default_sample_spec
;
130 if (pa_modargs_get_sample_spec_and_channel_map(ma
, &ss
, &map
, PA_CHANNEL_MAP_DEFAULT
) < 0) {
131 pa_log("invalid sample format specification or channel map.");
135 u
= pa_xnew0(struct userdata
, 1);
140 if (!(u
->sink
= pa_sink_new(c
, __FILE__
, pa_modargs_get_value(ma
, "sink_name", DEFAULT_SINK_NAME
), 0, &ss
, &map
))) {
141 pa_log("failed to create sink.");
145 u
->sink
->get_latency
= get_latency
;
146 u
->sink
->userdata
= u
;
147 pa_sink_set_owner(u
->sink
, m
);
148 pa_sink_set_description(u
->sink
, pa_modargs_get_value(ma
, "description", "NULL sink"));
151 pa_gettimeofday(&u
->start_time
);
153 u
->time_event
= c
->mainloop
->time_new(c
->mainloop
, &u
->start_time
, time_callback
, u
);
155 u
->block_size
= pa_bytes_per_second(&ss
) / 10;
170 void pa__done(pa_core
*c
, pa_module
*m
) {
174 if (!(u
= m
->userdata
))
177 pa_sink_disconnect(u
->sink
);
178 pa_sink_unref(u
->sink
);
180 u
->core
->mainloop
->time_free(u
->time_event
);