summaryrefslogtreecommitdiff
path: root/src/sink.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sink.c')
-rw-r--r--src/sink.c102
1 files changed, 19 insertions, 83 deletions
diff --git a/src/sink.c b/src/sink.c
index 8f6b13b..e086a64 100644
--- a/src/sink.c
+++ b/src/sink.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include <glib.h>
#include <pulse/pulseaudio.h>
#include <ncurses.h>
#include <string.h>
@@ -7,26 +8,30 @@
#include "sink_input.h"
#include "sink.h"
-/*
- * return an initilized sink
- */
-sink_info* sink_init(void) {
-
- sink_info* sink = (sink_info*) calloc(1, sizeof(sink_info));
+void sink_check_input_list(sink_info* sink) {
- sink->name = NULL;
- sink->device = NULL;
- sink->input_counter = 0;
- sink->input_max = 1;
- sink->input_list = NULL;
+ if (sink->input_counter >= sink->input_max)
+ sink_input_list_enlarge(&sink->input_list, &sink->input_max, sink->input_counter);
+}
- sink->input_list = sink_input_list_init(sink->input_max);
+/*
+ * init a sink list
+ */
+void sink_list_alloc(GArray **sink_list) {
+ *sink_list = g_array_sized_new(false, false, sizeof(sink_info), 16);
+}
- return sink;
+/*
+ * 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);
}
/*
- * frees all components of a sink
+ * frees all dynamic allocated components of a sink
*/
void sink_clear(sink_info* sink) {
@@ -37,74 +42,5 @@ void sink_clear(sink_info* sink) {
free(sink->device);
sink_input_list_clear(sink->input_list, &sink->input_max);
-
- free(sink);
- //sink = NULL;
-}
-
-void sink_check(sink_info** sink) {
-
- if (sink == NULL)
- printf("Error: sink = NULL\n");
-
- if ((*sink) == NULL)
- (*sink) = sink_init();
}
-/*
- * check the list length and resize the list, if current position = max
- */
-void sink_list_check(sink_info*** sink_list, uint32_t* max, uint32_t counter) {
- if (counter < *max)
- return;
-
- *max *= 2;
- *sink_list = (sink_info**) realloc(*sink_list, (*max) * sizeof(sink_info*));
-
-
- for (int i = counter; i < *max; ++i)
- (*sink_list)[i] = NULL;
-
-}
-
-void sink_check_input_list(sink_info* sink) {
-
- if (sink->input_counter >= sink->input_max)
- sink_input_list_enlarge(&sink->input_list, &sink->input_max, sink->input_counter);
-}
-
-sink_info** sink_list_init(uint32_t max) {
-
- sink_info** sink_list = (sink_info**) calloc(max, sizeof(sink_info*));
-
- for (int i = 0; i < max; ++i)
- sink_list[i] = NULL;
-
- return sink_list;
-}
-
-void sink_list_reset(sink_info** sink_list, uint32_t* counter) {
-
- for (int i = 0; i < (*counter); ++i)
- sink_list[i]->input_counter = 0;
-
- (*counter) = 0;
-}
-
-void sink_list_clear(sink_info** sink_list, uint32_t* max, uint32_t* counter) {
-
- for (int i = 0; i < (*max); ++i)
- if (sink_list[i] != NULL)
- sink_clear(sink_list[i]);
-
- (*max) = 0;
- (*counter) = 0;
-
- free(sink_list);
- // sink_list = NULL;
-
- /* TODO: for all *_clear:
- * setting local parameter to NULL doesnt do want is wanted
- * pointer to sink_list would be needed here...
- */
-}