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
30 #include <samplerate.h>
41 #include "subscribe.h"
43 struct pa_core
* pa_core_new(struct pa_mainloop_api
*m
) {
45 c
= pa_xmalloc(sizeof(struct pa_core
));
48 c
->clients
= pa_idxset_new(NULL
, NULL
);
49 c
->sinks
= pa_idxset_new(NULL
, NULL
);
50 c
->sources
= pa_idxset_new(NULL
, NULL
);
51 c
->source_outputs
= pa_idxset_new(NULL
, NULL
);
52 c
->sink_inputs
= pa_idxset_new(NULL
, NULL
);
54 c
->default_source_name
= c
->default_sink_name
= NULL
;
60 c
->autoload_hashmap
= NULL
;
62 c
->default_sample_spec
.format
= PA_SAMPLE_S16NE
;
63 c
->default_sample_spec
.rate
= 44100;
64 c
->default_sample_spec
.channels
= 2;
66 c
->module_auto_unload_event
= NULL
;
67 c
->module_defer_unload_event
= NULL
;
68 c
->scache_auto_unload_event
= NULL
;
70 c
->subscription_defer_event
= NULL
;
71 c
->subscription_event_queue
= NULL
;
72 c
->subscriptions
= NULL
;
74 c
->memblock_stat
= pa_memblock_stat_new();
76 c
->disallow_module_loading
= 0;
80 c
->exit_idle_time
= -1;
81 c
->module_idle_time
= 20;
82 c
->scache_idle_time
= 20;
84 c
->resample_method
= SRC_SINC_FASTEST
;
86 pa_check_signal_is_blocked(SIGPIPE
);
91 void pa_core_free(struct pa_core
*c
) {
94 pa_module_unload_all(c
);
97 assert(pa_idxset_isempty(c
->clients
));
98 pa_idxset_free(c
->clients
, NULL
, NULL
);
100 assert(pa_idxset_isempty(c
->sinks
));
101 pa_idxset_free(c
->sinks
, NULL
, NULL
);
103 assert(pa_idxset_isempty(c
->sources
));
104 pa_idxset_free(c
->sources
, NULL
, NULL
);
106 assert(pa_idxset_isempty(c
->source_outputs
));
107 pa_idxset_free(c
->source_outputs
, NULL
, NULL
);
109 assert(pa_idxset_isempty(c
->sink_inputs
));
110 pa_idxset_free(c
->sink_inputs
, NULL
, NULL
);
115 pa_subscription_free_all(c
);
118 c
->mainloop
->time_free(c
->quit_event
);
120 pa_xfree(c
->default_source_name
);
121 pa_xfree(c
->default_sink_name
);
123 pa_memblock_stat_unref(c
->memblock_stat
);
128 static void quit_callback(struct pa_mainloop_api
*m
, struct pa_time_event
*e
, const struct timeval
*tv
, void *userdata
) {
129 struct pa_core
*c
= userdata
;
130 assert(c
->quit_event
= e
);
135 void pa_core_check_quit(struct pa_core
*c
) {
138 if (!c
->quit_event
&& c
->exit_idle_time
>= 0 && pa_idxset_ncontents(c
->clients
) == 0) {
140 gettimeofday(&tv
, NULL
);
141 tv
.tv_sec
+= c
->exit_idle_time
;
142 c
->quit_event
= c
->mainloop
->time_new(c
->mainloop
, &tv
, quit_callback
, c
);
143 } else if (c
->quit_event
&& pa_idxset_ncontents(c
->clients
) > 0) {
144 c
->mainloop
->time_free(c
->quit_event
);
145 c
->quit_event
= NULL
;