]>
code.delx.au - pulseaudio/blob - polyp/play-memchunk.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 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 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
31 #include "play-memchunk.h"
32 #include "sink-input.h"
35 static void sink_input_kill(struct pa_sink_input
*i
) {
36 struct pa_memchunk
*c
;
37 assert(i
&& i
->userdata
);
40 pa_memblock_unref(c
->memblock
);
42 pa_sink_input_free(i
);
45 static int sink_input_peek(struct pa_sink_input
*i
, struct pa_memchunk
*chunk
) {
46 struct pa_memchunk
*c
;
47 assert(i
&& chunk
&& i
->userdata
);
53 assert(c
->memblock
&& c
->memblock
->length
);
55 pa_memblock_ref(c
->memblock
);
60 static void si_kill(struct pa_mainloop_api
*m
, void *i
) {
64 static void sink_input_drop(struct pa_sink_input
*i
, const struct pa_memchunk
*chunk
, size_t length
) {
65 struct pa_memchunk
*c
;
66 assert(i
&& length
&& i
->userdata
);
69 assert(!memcmp(chunk
, c
, sizeof(chunk
)));
70 assert(length
<= c
->length
);
76 pa_mainloop_api_once(i
->sink
->core
->mainloop
, si_kill
, i
);
79 int pa_play_memchunk(struct pa_sink
*sink
, const char *name
, const struct pa_sample_spec
*ss
, const struct pa_memchunk
*chunk
, pa_volume_t volume
) {
80 struct pa_sink_input
*si
;
81 struct pa_memchunk
*nchunk
;
83 assert(sink
&& chunk
);
88 if (!(si
= pa_sink_input_new(sink
, name
, ss
)))
92 si
->peek
= sink_input_peek
;
93 si
->drop
= sink_input_drop
;
94 si
->kill
= sink_input_kill
;
96 si
->userdata
= nchunk
= pa_xmalloc(sizeof(struct pa_memchunk
));
99 pa_memblock_ref(chunk
->memblock
);
101 pa_sink_notify(sink
);