blob: a1440dfd671fa9fa54036aaa7eae221fdda95477 (
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
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
82
|
#include <stdio.h>
#include <pulse/pulseaudio.h>
#include <ncurses.h>
#include <string.h>
#include <stdlib.h>
#include "sink_input.h"
sink_input_info* sink_input_init(void) {
sink_input_info* sink_input = (sink_input_info*) calloc(1, sizeof(sink_input_info));
sink_input->name = NULL;
sink_input->pid = NULL;
return sink_input;
}
void sink_input_clear(sink_input_info* sink_input) {
if (sink_input->name != NULL)
free(sink_input->name);
if (sink_input->pid != NULL)
free(sink_input->pid);
free(sink_input);
// sink_input = NULL;
}
sink_input_info** sink_input_list_init(int max) {
sink_input_info** sink_input_list = (sink_input_info**) calloc(max, sizeof(sink_input_info*));
for (int i = 0; i < max; ++i)
sink_input_list[i] = NULL;
return sink_input_list;
}
void sink_input_list_enlarge(sink_input_info*** sink_input_list, int* max, int counter) {
*max *= 2;
*sink_input_list = (sink_input_info**) realloc(*sink_input_list, (*max) * sizeof(sink_input_info*));
for (int i = counter; i < *max; ++i)
(*sink_input_list)[i] = NULL;
}
void sink_input_list_clear(sink_input_info** sink_input_list, int *max) {
for (int i = 0; i < (*max); ++i)
if (sink_input_list[i] != NULL)
sink_input_clear(sink_input_list[i]);
(*max) = 0;
free(sink_input_list);
// sink_input_list = NULL;
}
void sink_input_check(sink_input_info** sink_input) {
if (sink_input == NULL)
printf("Error: NULL\n");
if ((*sink_input) == NULL)
(*sink_input) = sink_input_init();
}
int cmp_sink_input_list(const void *a, const void *b) {
sink_input_info* sinka = *((sink_input_info**) a);
sink_input_info* sinkb = *((sink_input_info**) b);
if (sinka->sink < sinkb->sink)
return -1;
else if (sinka->sink > sinkb->sink)
return 1;
else
return 0;
}
|