forked from gozfree/aquila
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
140 lines (126 loc) · 3.49 KB
/
main.c
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/******************************************************************************
* Copyright (C) 2014-2018 Zhifeng Gong <gozfree@163.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with libraries; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/
#include <gear-lib/libdebug.h>
#include <gear-lib/liblog.h>
#include "aquila.h"
#include "device.h"
#include "codec.h"
#include "playback.h"
#include "protocol.h"
#include "muxer.h"
static struct aquila aq_instance;
int aquila_init(struct aquila *aq)
{
struct aq_config *c = &aq->config;
struct queue *q_src, *q_snk;
int i;//, j;
if (-1 == load_conf(c)) {
loge("load_conf failed!\n");
return -1;
}
if (c->filter_num <= 0) {
logi("filter graph should not be empty\n");
return -1;
}
aq->queue = CALLOC(c->filter_num, struct queue *);
if (!aq->queue) {
loge("malloc queue failed!\n");
return -1;
}
for (i = 0; i < c->filter_num - 1; i++) {
aq->queue[i] = queue_create();
}
aq->filter = CALLOC(c->filter_num, struct filter_ctx *);
if (!aq->filter) {
loge("malloc filter failed!\n");
return -1;
}
for (i = 0; i < c->filter_num; i++) {
if (i == 0) {
q_src = NULL;
q_snk = aq->queue[i];
} else if (i < c->filter_num) {
q_src = aq->queue[i-1];
q_snk = aq->queue[i];
} else {
q_src = aq->queue[i];
q_snk = NULL;
}
aq->filter[i] = filter_create(&c->filter[i], q_src, q_snk);
}
aq->run = true;
return 0;
}
int aquila_dispatch(struct aquila *aq)
{
int i;
for (i = 0; i < aq->config.filter_num; i++) {
filter_dispatch(aq->filter[i], 0);
}
while (aq->run) {
sleep(2);
}
return 0;
}
void aquila_deinit(struct aquila *aq)
{
int i;
struct aq_config *c = &aq->config;
for (i = 0; i < aq->config.filter_num; i++) {
filter_destroy(aq->filter[i]);
}
aq->run = false;
unload_conf(c);
}
static void sigint_handler(int sig)
{
aquila_deinit(&aq_instance);
}
void signal_init()
{
signal(SIGPIPE, SIG_IGN);
signal(SIGINT, sigint_handler);
}
void register_class()
{
device_register_all();
playback_register_all();
codec_register_all();
filter_register_all();
protocol_register_all();
muxer_register_all();
}
int main(int argc, char **argv)
{
debug_backtrace_init();
signal_init();
register_class();
memset(&aq_instance, 0, sizeof(aq_instance));
if (-1 == aquila_init(&aq_instance)) {
loge("aquila_init failed!\n");
goto quit;
}
if (-1 == aquila_dispatch(&aq_instance)) {
loge("aquila_dispatch failed!\n");
return -1;
}
logi("quit\n");
quit:
aquila_deinit(&aq_instance);
return 0;
}