summaryrefslogtreecommitdiff
path: root/src/sink.c
blob: 18a5c7c1d5f03c4e94136c83e923f5b882a6cd32 (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
#include <stdio.h>
#include <glib.h>
#include <pulse/pulseaudio.h>
#include <ncurses.h>
#include <string.h>
#include <stdlib.h>

#include "sink_input.h"
#include "sink.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) {
	if (sink->name != NULL)
		free(sink->name);
	
	if (sink->device != NULL)
		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);
}