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 Lesser 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 Lesser 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 <polypcore/source-output.h>
32 #include <polypcore/namereg.h>
33 #include <polypcore/xmalloc.h>
34 #include <polypcore/core-subscribe.h>
35 #include <polypcore/log.h>
39 pa_source
* pa_source_new(
44 const pa_sample_spec
*spec
,
45 const pa_channel_map
*map
) {
56 s
= pa_xnew(pa_source
, 1);
58 if (!(name
= pa_namereg_register(core
, name
, PA_NAMEREG_SOURCE
, s
, fail
))) {
65 s
->state
= PA_SOURCE_RUNNING
;
66 s
->name
= pa_xstrdup(name
);
67 s
->description
= NULL
;
68 s
->driver
= pa_xstrdup(driver
);
71 s
->sample_spec
= *spec
;
73 s
->channel_map
= *map
;
75 pa_channel_map_init_auto(&s
->channel_map
, spec
->channels
);
77 s
->outputs
= pa_idxset_new(NULL
, NULL
);
80 s
->get_latency
= NULL
;
84 r
= pa_idxset_put(core
->sources
, s
, &s
->index
);
85 assert(s
->index
!= PA_IDXSET_INVALID
&& r
>= 0);
87 pa_sample_spec_snprint(st
, sizeof(st
), spec
);
88 pa_log_info(__FILE__
": created %u \"%s\" with sample spec \"%s\"\n", s
->index
, s
->name
, st
);
90 pa_subscription_post(core
, PA_SUBSCRIPTION_EVENT_SOURCE
| PA_SUBSCRIPTION_EVENT_NEW
, s
->index
);
95 void pa_source_disconnect(pa_source
*s
) {
96 pa_source_output
*o
, *j
= NULL
;
99 assert(s
->state
== PA_SOURCE_RUNNING
);
101 pa_namereg_unregister(s
->core
, s
->name
);
103 while ((o
= pa_idxset_first(s
->outputs
, NULL
))) {
105 pa_source_output_kill(o
);
109 pa_idxset_remove_by_data(s
->core
->sources
, s
, NULL
);
111 s
->get_latency
= NULL
;
114 s
->state
= PA_SOURCE_DISCONNECTED
;
115 pa_subscription_post(s
->core
, PA_SUBSCRIPTION_EVENT_SOURCE
| PA_SUBSCRIPTION_EVENT_REMOVE
, s
->index
);
118 static void source_free(pa_source
*s
) {
122 if (s
->state
!= PA_SOURCE_DISCONNECTED
)
123 pa_source_disconnect(s
);
125 pa_log_info(__FILE__
": freed %u \"%s\"\n", s
->index
, s
->name
);
127 pa_idxset_free(s
->outputs
, NULL
, NULL
);
130 pa_xfree(s
->description
);
135 void pa_source_unref(pa_source
*s
) {
143 pa_source
* pa_source_ref(pa_source
*s
) {
151 void pa_source_notify(pa_source
*s
) {
159 static int do_post(void *p
, PA_GCC_UNUSED
uint32_t idx
, int *del
, void*userdata
) {
160 pa_source_output
*o
= p
;
161 const pa_memchunk
*chunk
= userdata
;
166 pa_source_output_push(o
, chunk
);
170 void pa_source_post(pa_source
*s
, const pa_memchunk
*chunk
) {
176 pa_idxset_foreach(s
->outputs
, do_post
, (void*) chunk
);
180 void pa_source_set_owner(pa_source
*s
, pa_module
*m
) {
187 pa_usec_t
pa_source_get_latency(pa_source
*s
) {
194 return s
->get_latency(s
);