1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include "core.h"
#include "module.h"
#include "sink.h"
#include "source.h"
struct core* core_new(struct mainloop *m) {
struct core* c;
c = malloc(sizeof(struct core));
assert(c);
c->mainloop = m;
c->clients = idxset_new(NULL, NULL);
c->sinks = idxset_new(NULL, NULL);
c->sources = idxset_new(NULL, NULL);
c->output_streams = idxset_new(NULL, NULL);
c->input_streams = idxset_new(NULL, NULL);
c->default_source_index = c->default_sink_index = IDXSET_INVALID;
c->modules = NULL;
return c;
};
void core_free(struct core *c) {
assert(c);
module_unload_all(c);
assert(!c->modules);
assert(idxset_isempty(c->clients));
idxset_free(c->clients, NULL, NULL);
assert(idxset_isempty(c->sinks));
idxset_free(c->sinks, NULL, NULL);
assert(idxset_isempty(c->sources));
idxset_free(c->sources, NULL, NULL);
assert(idxset_isempty(c->output_streams));
idxset_free(c->output_streams, NULL, NULL);
assert(idxset_isempty(c->input_streams));
idxset_free(c->input_streams, NULL, NULL);
free(c);
};
struct sink* core_get_default_sink(struct core *c) {
struct sink *sink;
assert(c);
if ((sink = idxset_get_by_index(c->sinks, c->default_sink_index)))
return sink;
if (!(sink = idxset_rrobin(c->sinks, NULL)))
return NULL;
fprintf(stderr, "Default sink vanished, setting to %u\n", sink->index);
c->default_sink_index = sink->index;
return sink;
}
struct source* core_get_default_source(struct core *c) {
struct source *source;
assert(c);
if ((source = idxset_get_by_index(c->sources, c->default_source_index)))
return source;
if (!(source = idxset_rrobin(c->sources, NULL)))
return NULL;
fprintf(stderr, "Default source vanished, setting to %u\n", source->index);
c->default_source_index = source->index;
return source;
}
|