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
33 #include <pulse/xmalloc.h>
35 #include <pulsecore/sink-input.h>
36 #include <pulsecore/gccmacro.h>
38 #include "play-memchunk.h"
40 static void sink_input_kill_cb(pa_sink_input
*i
) {
42 assert(i
&& i
->userdata
);
45 pa_sink_input_disconnect(i
);
46 pa_sink_input_unref(i
);
48 pa_memblock_unref(c
->memblock
);
52 static int sink_input_peek_cb(pa_sink_input
*i
, pa_memchunk
*chunk
) {
54 assert(i
&& chunk
&& i
->userdata
);
62 pa_memblock_ref(c
->memblock
);
67 static void si_kill_cb(PA_GCC_UNUSED pa_mainloop_api
*m
, void *i
) {
68 sink_input_kill_cb(i
);
71 static void sink_input_drop_cb(pa_sink_input
*i
, size_t length
) {
73 assert(i
&& length
&& i
->userdata
);
76 if (length
>= c
->length
) {
83 pa_mainloop_api_once(i
->sink
->core
->mainloop
, si_kill_cb
, i
);
90 const pa_sample_spec
*ss
,
91 const pa_channel_map
*map
,
92 const pa_memchunk
*chunk
,
97 pa_sink_input_new_data data
;
103 if (volume
&& pa_cvolume_is_muted(volume
))
106 pa_sink_input_new_data_init(&data
);
109 data
.driver
= __FILE__
;
110 pa_sink_input_new_data_set_sample_spec(&data
, ss
);
111 pa_sink_input_new_data_set_channel_map(&data
, map
);
112 pa_sink_input_new_data_set_volume(&data
, volume
);
114 if (!(si
= pa_sink_input_new(sink
->core
, &data
, 0)))
117 si
->peek
= sink_input_peek_cb
;
118 si
->drop
= sink_input_drop_cb
;
119 si
->kill
= sink_input_kill_cb
;
121 si
->userdata
= nchunk
= pa_xnew(pa_memchunk
, 1);
124 pa_memblock_ref(chunk
->memblock
);