-
Notifications
You must be signed in to change notification settings - Fork 0
/
satip_main.c
315 lines (251 loc) · 8.45 KB
/
satip_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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
/*
* satip: startup and main loop
*
* Copyright (C) 2014 [email protected]
* DVB-C and DVB-T(2) support added by [email protected]
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdlib.h>
#include <stdio.h>
#include <sys/socket.h>
#include <errno.h>
#include <poll.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sched.h>
#include "satip_config.h"
#include "satip_vtuner.h"
#include "satip_rtsp.h"
#include "satip_rtp.h"
#include "log.h"
#include "polltimer.h"
int dbg_level = MSG_ERROR;
unsigned int dbg_mask = MSG_MAIN | MSG_NET | MSG_HW | MSG_SRV; // MSG_DATA
int use_syslog = 0;
int enabled_workarounds = 0;
//#define TEST_SEQUENCER
#ifdef TEST_SEQUENCER
static int cseq=0;
static void test_sequencer(void* param)
{
t_satip_config* sc=(t_satip_config*)param;
cseq++;
switch (cseq)
{
case 1:
if ( (sc->fe_type == SATIP_FE_TYPE_SAT) )
{
satip_set_freq(sc,118360);
satip_set_modsys(sc, SATIPCFG_MS_DVB_S);
satip_set_pilots(sc, SATIPCFG_P_OFF);
satip_set_fecinner(sc, SATIPCFG_F_34);
satip_set_polarization(sc, SATIPCFG_P_HORIZONTAL);
satip_set_rolloff(sc, SATIPCFG_R_0_35);
satip_set_symbol_rate(sc,27500);
satip_set_modtype(sc, SATIPCFG_MT_QPSK);
satip_set_position(sc, 1);
satip_add_pid(sc, 18);
}
else if ( (sc->fe_type == SATIP_FE_TYPE_CAB) )
{
satip_set_freq(sc,4180);
satip_set_modsys(sc, SATIPCFG_MS_DVB_C);
satip_set_symbol_rate(sc,6900);
satip_set_modtype(sc, SATIPCFG_MT_256QAM);
satip_add_pid(sc, 6000);
}
break;
case 200:
//satip_add_pid(sc, 19);
break;
case 400:
break;
default:
break;
}
}
#endif
static void enable_rt_scheduling()
{
struct sched_param schedp;
if ( mlockall(MCL_CURRENT|MCL_FUTURE) )
DEBUG(MSG_MAIN,"Pages not locked\n");
else
DEBUG(MSG_MAIN,"Pages locked\n");
schedp.sched_priority = sched_get_priority_min(SCHED_FIFO);
if ( sched_setscheduler(0, SCHED_FIFO, &schedp) )
DEBUG(MSG_MAIN,"No realtime scheduling\n");
else
DEBUG(MSG_MAIN,"Realtime scheduling enabled at prio %d\n",schedp.sched_priority);
}
void print_usage(void)
{
printf("Usage: satip-client <options>\n"
" -s <ip address> IP address of SAT>IP server (MANDATORY)\n"
" -t <frontend_type> Frontend type: (MANDATORY)\n"
" 0: DVB-S2\n"
" 1: DVB-C\n"
" 2: DVB-T\n"
" -p <port> Port number of SAT>IP server (default: 554)\n"
#if defined(VTUNER_TYPE_VUPLUS)
" -d <vtuner_device> Vtuner device (default: /dev/misc/vtuner0)\n"
#elif defined(VTUNER_TYPE_ORIGINAL)
" -d <vtuner_device> Vtuner device (default: /dev/vtunerc0)\n"
#endif
" -f <num> Force usage of frontend <num> on SAT>IP server\n"
" -m <debug_mask> Used for debugging, see code\n"
" -l <log_level> Log level:\n"
" 0: None\n"
" 1: Error (default)\n"
" 2: Warning\n"
" 3: Info\n"
" 4: Debug\n"
" -y Use syslog instead of STDERR for logging\n"
" -w <workaround_mask> Enable workarounds for known quirks for some device\n"
" 0: Disable all workarounds (default)\n"
" 1: Enable workaround ADD-DUMMY-PID (AVM Fritz!WLAN Repeater DVB-C)\n"
" 2: Enable workaround FORCE-FULL-PID (AVM Fritz!WLAN Repeater DVB-C)\n"
" 4: Enable workaround FORCE-FE-LOCK (AVM Fritz!WLAN Repeater DVB-C) CURRENTLY ALWAYS ACTIVE!\n"
" Example: -w3 means enable first two workarounds"
" -h Print help\n"
);
}
int main(int argc, char** argv)
{
char* host = NULL;
char* port = "554";
#if defined(VTUNER_TYPE_ORIGINAL)
char* device = "/dev/vtunerc0";
#elif defined(VTUNER_TYPE_VUPLUS)
char* device = "/dev/misc/vtuner0";
#endif // VTUNER_TYPE_VUPLUS
int frontend = -1;
int type = -1;
t_satip_config* satconf;
struct satip_rtsp* srtsp;
struct satip_rtp* srtp;
struct satip_vtuner* satvt;
struct pollfd pollfds[2];
int poll_idx;
struct polltimer* timerq=NULL;
int opt;
while((opt = getopt(argc, argv, "s:p:d:f:m:l:t:yw:h")) != -1 )
{
switch(opt)
{
case 's':
host = optarg;
break;
case 'p':
port = optarg;
break;
case 'd':
device = optarg;
break;
case 'f':
frontend = atoi(optarg);
break;
case 'm':
dbg_mask = atoi(optarg);
break;
case 'l':
dbg_level = atoi(optarg);
break;
case 't':
type = atoi(optarg);
break;
case 'w':
enabled_workarounds=atoi(optarg);
break;
case 'y':
use_syslog=1;
break;
case 'h':
/* fall through ... */
default:
ERROR(MSG_MAIN,"unknown option %c\n",opt);
print_usage();
exit(1);
}
}
if ( host==NULL )
{
ERROR(MSG_MAIN,"No server IP argument. Please specify SAT>IP server address.\n");
print_usage();
exit(1);
}
if ( type==-1 )
{
ERROR(MSG_MAIN,"No type argument. Please specify frontend type.\n");
print_usage();
exit(1);
}
enable_rt_scheduling();
satconf = satip_new_config(frontend, type);
#ifdef TEST_SEQUENCER
struct polltimer_periodic* periodic;
device = device;
satvt = NULL;
polltimer_periodic_start(&timerq,
&periodic,
test_sequencer,
10,
(void*)satconf);
srtp = satip_rtp_new(0);
/* no vtuner fd*/
poll_idx=0;
#else
satvt = satip_vtuner_new( device, satconf );
if ( satvt == NULL )
{
ERROR(MSG_MAIN,"vtuner control failed\n");
exit(1);
}
srtp = satip_rtp_new(satip_vtuner_fd(satvt));
pollfds[0].fd=satip_vtuner_fd(satvt);
pollfds[0].events = POLLPRI;
poll_idx=1;
#endif
srtsp = satip_rtsp_new(satconf,&timerq, host, port,
satip_rtp_port(srtp));
while (1)
{
/* apply any updates on rtsp */
satip_rtsp_check_update(srtsp);
/* vt control events */
pollfds[0].revents = 0;
/* rtsp socket may be closed */
pollfds[poll_idx].fd = satip_rtsp_socket(srtsp);
pollfds[poll_idx].events = satip_rtsp_pollflags(srtsp);
pollfds[poll_idx].revents = 0;
/* poll and timeout on next pending timer */
if ( poll(pollfds, pollfds[poll_idx].events == 0 ? poll_idx : poll_idx+1 ,
polltimer_next_ms(timerq) ) ==-1 &&
errno!=EINTR )
{
perror(NULL);
exit(1);
}
/* schedule timer callbacks */
polltimer_call_next(&timerq);
/* vt control event handling */
if ( poll_idx>0 && pollfds[0].revents !=0 )
satip_vtuner_event(satvt);
/* rtsp event handling */
if ( pollfds[poll_idx].revents !=0 )
satip_rtsp_pollevents(srtsp, pollfds[poll_idx].revents);
}
return 0;
}