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
32 #include "source-output.h"
35 #include "subscribe.h"
38 struct pa_source
* pa_source_new(struct pa_core
*core
, const char *name
, int fail
, const struct pa_sample_spec
*spec
) {
42 assert(core
&& spec
&& name
&& *name
);
44 s
= pa_xmalloc(sizeof(struct pa_source
));
46 if (!(name
= pa_namereg_register(core
, name
, PA_NAMEREG_SOURCE
, s
, fail
))) {
52 s
->state
= PA_SOURCE_RUNNING
;
54 s
->name
= pa_xstrdup(name
);
55 s
->description
= NULL
;
59 s
->sample_spec
= *spec
;
60 s
->outputs
= pa_idxset_new(NULL
, NULL
);
63 s
->get_latency
= NULL
;
67 r
= pa_idxset_put(core
->sources
, s
, &s
->index
);
68 assert(s
->index
!= PA_IDXSET_INVALID
&& r
>= 0);
70 pa_sample_spec_snprint(st
, sizeof(st
), spec
);
71 pa_log(__FILE__
": created %u \"%s\" with sample spec \"%s\"\n", s
->index
, s
->name
, st
);
73 pa_subscription_post(core
, PA_SUBSCRIPTION_EVENT_SOURCE
| PA_SUBSCRIPTION_EVENT_NEW
, s
->index
);
78 void pa_source_disconnect(struct pa_source
*s
) {
79 struct pa_source_output
*o
, *j
= NULL
;
80 assert(s
&& s
->state
== PA_SOURCE_RUNNING
);
82 pa_namereg_unregister(s
->core
, s
->name
);
84 while ((o
= pa_idxset_first(s
->outputs
, NULL
))) {
86 pa_source_output_kill(o
);
90 pa_idxset_remove_by_data(s
->core
->sources
, s
, NULL
);
91 pa_subscription_post(s
->core
, PA_SUBSCRIPTION_EVENT_SOURCE
| PA_SUBSCRIPTION_EVENT_REMOVE
, s
->index
);
95 s
->state
= PA_SOURCE_DISCONNECTED
;
98 static void source_free(struct pa_source
*s
) {
101 if (s
->state
!= PA_SOURCE_DISCONNECTED
)
102 pa_source_disconnect(s
);
104 pa_log(__FILE__
": freed %u \"%s\"\n", s
->index
, s
->name
);
106 pa_idxset_free(s
->outputs
, NULL
, NULL
);
109 pa_xfree(s
->description
);
113 void pa_source_unref(struct pa_source
*s
) {
114 assert(s
&& s
->ref
>= 1);
120 struct pa_source
* pa_source_ref(struct pa_source
*s
) {
121 assert(s
&& s
->ref
>= 1);
126 void pa_source_notify(struct pa_source
*s
) {
127 assert(s
&& s
->ref
>= 1);
133 static int do_post(void *p
, uint32_t index
, int *del
, void*userdata
) {
134 const struct pa_memchunk
*chunk
= userdata
;
135 struct pa_source_output
*o
= p
;
136 assert(o
&& o
->push
&& del
&& chunk
);
138 pa_source_output_push(o
, chunk
);
142 void pa_source_post(struct pa_source
*s
, const struct pa_memchunk
*chunk
) {
143 assert(s
&& s
->ref
>= 1 && chunk
);
146 pa_idxset_foreach(s
->outputs
, do_post
, (void*) chunk
);
150 void pa_source_set_owner(struct pa_source
*s
, struct pa_module
*m
) {
155 pa_usec_t
pa_source_get_latency(struct pa_source
*s
) {
156 assert(s
&& s
->ref
>= 1);
161 return s
->get_latency(s
);