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
32 #include "source-output.h"
35 #include "subscribe.h"
38 pa_source
* pa_source_new(
43 const pa_sample_spec
*spec
,
44 const pa_channel_map
*map
) {
55 s
= pa_xnew(pa_source
, 1);
57 if (!(name
= pa_namereg_register(core
, name
, PA_NAMEREG_SOURCE
, s
, fail
))) {
64 s
->state
= PA_SOURCE_RUNNING
;
65 s
->name
= pa_xstrdup(name
);
66 s
->description
= NULL
;
67 s
->driver
= pa_xstrdup(driver
);
70 s
->sample_spec
= *spec
;
72 s
->channel_map
= *map
;
74 pa_channel_map_init_auto(&s
->channel_map
, spec
->channels
);
76 s
->outputs
= pa_idxset_new(NULL
, NULL
);
79 s
->get_latency
= NULL
;
83 r
= pa_idxset_put(core
->sources
, s
, &s
->index
);
84 assert(s
->index
!= PA_IDXSET_INVALID
&& r
>= 0);
86 pa_sample_spec_snprint(st
, sizeof(st
), spec
);
87 pa_log_info(__FILE__
": created %u \"%s\" with sample spec \"%s\"\n", s
->index
, s
->name
, st
);
89 pa_subscription_post(core
, PA_SUBSCRIPTION_EVENT_SOURCE
| PA_SUBSCRIPTION_EVENT_NEW
, s
->index
);
94 void pa_source_disconnect(pa_source
*s
) {
95 pa_source_output
*o
, *j
= NULL
;
98 assert(s
->state
== PA_SOURCE_RUNNING
);
100 pa_namereg_unregister(s
->core
, s
->name
);
102 while ((o
= pa_idxset_first(s
->outputs
, NULL
))) {
104 pa_source_output_kill(o
);
108 pa_idxset_remove_by_data(s
->core
->sources
, s
, NULL
);
110 s
->get_latency
= NULL
;
113 s
->state
= PA_SOURCE_DISCONNECTED
;
114 pa_subscription_post(s
->core
, PA_SUBSCRIPTION_EVENT_SOURCE
| PA_SUBSCRIPTION_EVENT_REMOVE
, s
->index
);
117 static void source_free(pa_source
*s
) {
121 if (s
->state
!= PA_SOURCE_DISCONNECTED
)
122 pa_source_disconnect(s
);
124 pa_log_info(__FILE__
": freed %u \"%s\"\n", s
->index
, s
->name
);
126 pa_idxset_free(s
->outputs
, NULL
, NULL
);
129 pa_xfree(s
->description
);
134 void pa_source_unref(pa_source
*s
) {
142 pa_source
* pa_source_ref(pa_source
*s
) {
150 void pa_source_notify(pa_source
*s
) {
158 static int do_post(void *p
, PA_GCC_UNUSED
uint32_t idx
, int *del
, void*userdata
) {
159 pa_source_output
*o
= p
;
160 const pa_memchunk
*chunk
= userdata
;
165 pa_source_output_push(o
, chunk
);
169 void pa_source_post(pa_source
*s
, const pa_memchunk
*chunk
) {
175 pa_idxset_foreach(s
->outputs
, do_post
, (void*) chunk
);
179 void pa_source_set_owner(pa_source
*s
, pa_module
*m
) {
186 pa_usec_t
pa_source_get_latency(pa_source
*s
) {
193 return s
->get_latency(s
);