summaryrefslogtreecommitdiff
path: root/src/sink.c
blob: 9f36f3e9fb0154604a73f4001bafff46f8bfdb32 (plain)
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
#include <glib.h>

#define SINK_C
#include "sink.h"
#include "sink_input.h"

/*
 * init a sink list
 */
GArray *sink_list_alloc(void)
{
	return g_array_sized_new(FALSE, FALSE, sizeof(sink_info), 16);
}

/*
 * frees all dynamic allocated components of a sink 
 */
static void sink_clear(sink_info* sink)
{
	g_free(sink->name);
	g_free(sink->device);
	sink_input_list_free(sink->input_list);
}

/*
 * frees a complete sink array
 */
void sink_list_free(GArray *sink_list)
{
	for (int i = 0; i < sink_list->len; ++i)
		sink_clear(&g_array_index(sink_list, sink_info, i));
	g_array_free(sink_list, TRUE);
}

/*
 * get sink at index from sink_list
 */
sink_info *sink_list_get(gint index)
{
	return &g_array_index(sink_list, sink_info, index);
}

/*
 * get an input association to an sink by their indizes
 */
sink_input_info *sink_input_get(gint sink_list_index, gint index)
{
	return &g_array_index(sink_list_get(sink_list_index)->input_list, sink_input_info, index);
}