]>
code.delx.au - pulseaudio/blob - src/source.c
6 #include "outputstream.h"
8 struct source
* source_new(struct core
*core
, const char *name
, const struct sample_spec
*spec
) {
13 s
= malloc(sizeof(struct source
));
16 s
->name
= name
? strdup(name
) : NULL
;
17 r
= idxset_put(core
->sources
, s
, &s
->index
);
18 assert(s
->index
!= IDXSET_INVALID
&& r
>= 0);
21 s
->sample_spec
= *spec
;
22 s
->output_streams
= idxset_new(NULL
, NULL
);
24 s
->link_change_callback
= NULL
;
30 static void do_free(void *p
, void *userdata
) {
31 struct output_stream
*o
= p
;
33 output_stream_free(o
);
36 void source_free(struct source
*s
) {
37 struct output_stream
*o
;
40 while ((o
= idxset_rrobin(s
->output_streams
, NULL
)))
41 output_stream_free(o
);
42 idxset_free(s
->output_streams
, NULL
, NULL
);
44 idxset_remove_by_data(s
->core
->sources
, s
, NULL
);
45 idxset_free(s
->output_streams
, do_free
, NULL
);
51 static int do_post(void *p
, uint32_t index
, int *del
, void*userdata
) {
52 struct memchunk
*chunk
= userdata
;
53 struct output_stream
*o
= p
;
54 assert(o
&& o
->memblockq
&& index
&& del
&& chunk
);
56 memblockq_push(o
->memblockq
, chunk
, 0);
60 void source_post(struct source
*s
, struct memchunk
*chunk
) {
63 idxset_foreach(s
->output_streams
, do_post
, chunk
);