]> code.delx.au - pulseaudio/blob - polyp/source-output.c
b8083a79afa9f230fefeccd55d59dd8e962302ec
[pulseaudio] / polyp / source-output.c
1 /* $Id$ */
2
3 /***
4 This file is part of polypaudio.
5
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.
10
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.
15
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
19 USA.
20 ***/
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <assert.h>
27 #include <stdlib.h>
28 #include <string.h>
29
30 #include "source-output.h"
31 #include "xmalloc.h"
32 #include "subscribe.h"
33
34 struct pa_source_output* pa_source_output_new(struct pa_source *s, const char *name, const struct pa_sample_spec *spec) {
35 struct pa_source_output *o;
36 struct pa_resampler *resampler = NULL;
37 int r;
38 assert(s && spec);
39
40 if (!pa_sample_spec_equal(&s->sample_spec, spec))
41 if (!(resampler = pa_resampler_new(&s->sample_spec, spec, s->core->memblock_stat)))
42 return NULL;
43
44 o = pa_xmalloc(sizeof(struct pa_source_output));
45 o->name = pa_xstrdup(name);
46 o->client = NULL;
47 o->owner = NULL;
48 o->source = s;
49 o->sample_spec = *spec;
50
51 o->push = NULL;
52 o->kill = NULL;
53 o->userdata = NULL;
54 o->resampler = resampler;
55
56 assert(s->core);
57 r = pa_idxset_put(s->core->source_outputs, o, &o->index);
58 assert(r == 0 && o->index != PA_IDXSET_INVALID);
59 r = pa_idxset_put(s->outputs, o, NULL);
60 assert(r == 0);
61
62 pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT|PA_SUBSCRIPTION_EVENT_NEW, o->index);
63
64 return o;
65 }
66
67 void pa_source_output_free(struct pa_source_output* o) {
68 assert(o);
69
70 assert(o->source && o->source->core);
71 pa_idxset_remove_by_data(o->source->core->source_outputs, o, NULL);
72 pa_idxset_remove_by_data(o->source->outputs, o, NULL);
73
74 if (o->resampler)
75 pa_resampler_free(o->resampler);
76
77 pa_subscription_post(o->source->core, PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT|PA_SUBSCRIPTION_EVENT_REMOVE, o->index);
78
79 pa_xfree(o->name);
80 pa_xfree(o);
81 }
82
83 void pa_source_output_kill(struct pa_source_output*i) {
84 assert(i);
85
86 if (i->kill)
87 i->kill(i);
88 }
89
90 void pa_source_output_push(struct pa_source_output *o, const struct pa_memchunk *chunk) {
91 struct pa_memchunk rchunk;
92 assert(o && chunk && chunk->length && o->push);
93
94 if (!o->resampler) {
95 o->push(o, chunk);
96 return;
97 }
98
99 pa_resampler_run(o->resampler, chunk, &rchunk);
100 if (!rchunk.length)
101 return;
102
103 assert(rchunk.memblock);
104 o->push(o, &rchunk);
105 pa_memblock_unref(rchunk.memblock);
106 }