9610
|
1 /* dvbtune - tune.c
|
|
2
|
|
3 Copyright (C) Dave Chapman 2001,2002
|
|
4
|
|
5 This program is free software; you can redistribute it and/or
|
|
6 modify it under the terms of the GNU General Public License
|
|
7 as published by the Free Software Foundation; either version 2
|
|
8 of the License, or (at your option) any later version.
|
|
9
|
|
10 This program is distributed in the hope that it will be useful,
|
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 GNU General Public License for more details.
|
|
14
|
|
15 You should have received a copy of the GNU General Public License
|
|
16 along with this program; if not, write to the Free Software
|
|
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
18 Or, point your browser to http://www.gnu.org/copyleft/gpl.html
|
|
19
|
|
20 */
|
|
21
|
|
22 #include <stdio.h>
|
|
23 #include <stdlib.h>
|
|
24 #include <ctype.h>
|
|
25 #include <sys/ioctl.h>
|
|
26 #include <sys/poll.h>
|
|
27 #include <unistd.h>
|
|
28 #include <fcntl.h>
|
|
29 #include <error.h>
|
10560
|
30 #include <errno.h>
|
9610
|
31 #include "config.h"
|
|
32
|
|
33 #ifdef HAVE_DVB_HEAD
|
|
34 #include <linux/dvb/dmx.h>
|
|
35 #include <linux/dvb/frontend.h>
|
10560
|
36 static char* dvb_frontenddev[4]={"/dev/dvb/adapter0/frontend0","/dev/dvb/adapter1/frontend0","/dev/dvb/adapter2/frontend0","/dev/dvb/adapter3/frontend0"};
|
|
37 char* dvb_dvrdev[4]={"/dev/dvb/adapter0/dvr0","/dev/dvb/adapter1/dvr0","/dev/dvb/adapter2/dvr0","/dev/dvb/adapter3/dvr0"};
|
|
38 char* dvb_demuxdev[4]={"/dev/dvb/adapter0/demux0","/dev/dvb/adapter1/demux0","/dev/dvb/adapter2/demux0","/dev/dvb/adapter3/demux0"};
|
|
39 static char* dvb_secdev[4]={"","","",""}; //UNUSED, ONLY FOR UNIFORMITY
|
9610
|
40 #else
|
|
41 #include <ost/dmx.h>
|
|
42 #include <ost/sec.h>
|
|
43 #include <ost/frontend.h>
|
10560
|
44 static char* dvb_frontenddev[4]={"/dev/ost/frontend0","/dev/ost/frontend1","/dev/ost/frontend2","/dev/ost/frontend3"};
|
|
45 char* dvb_dvrdev[4]={"/dev/ost/dvr0","/dev/ost/dvr1","/dev/ost/dvr2","/dev/ost/dvr3"};
|
|
46 static char* dvb_secdev[4]={"/dev/ost/sec0","/dev/ost/sec1","/dev/ost/sec2","/dev/ost/sec3"};
|
|
47 char* dvb_demuxdev[4]={"/dev/ost/demux0","/dev/ost/demux1","/dev/ost/demux2","/dev/ost/demux3"};
|
9610
|
48 #endif
|
|
49
|
|
50 #include "dvbin.h"
|
|
51 #include "../mp_msg.h"
|
|
52
|
|
53
|
|
54
|
10560
|
55 int dvb_get_tuner_type(dvb_priv_t *priv)
|
9610
|
56 {
|
10560
|
57 #ifdef HAVE_DVB_HEAD
|
|
58 struct dvb_frontend_info fe_info;
|
|
59 #else
|
|
60 FrontendInfo fe_info;
|
|
61 #endif
|
|
62
|
|
63 int res, fe_fd = -1;
|
|
64
|
|
65 fe_fd = open(dvb_frontenddev[priv->card], O_RDWR);
|
|
66 if(fe_fd < 0)
|
|
67 {
|
|
68 mp_msg(MSGT_DEMUX, MSGL_ERR, "get_tuner_type(%d, %s), ERROR IN OPENING FRONTEND DEVICE %s: %d\n", priv->card, dvb_frontenddev[priv->card], errno);
|
|
69 return 0;
|
|
70 }
|
|
71
|
|
72 res = ioctl(fe_fd, FE_GET_INFO, &fe_info);
|
|
73 if(res < 0)
|
|
74 {
|
|
75 mp_msg(MSGT_DEMUX, MSGL_ERR, "FE_GET_INFO error: %d, FD: %d\n\n", errno, fe_fd);
|
|
76 return 0;
|
|
77 }
|
|
78 close(fe_fd);
|
|
79
|
|
80 switch(fe_info.type)
|
|
81 {
|
|
82 case FE_OFDM:
|
|
83 mp_msg(MSGT_DEMUX, MSGL_INFO, "TUNER TYPE SEEMS TO BE DVB-T\n");
|
|
84 return TUNER_TER;
|
|
85
|
|
86 case FE_QPSK:
|
|
87 mp_msg(MSGT_DEMUX, MSGL_INFO, "TUNER TYPE SEEMS TO BE DVB-S\n");
|
|
88 return TUNER_SAT;
|
|
89
|
|
90 case FE_QAM:
|
|
91 mp_msg(MSGT_DEMUX, MSGL_INFO, "TUNER TYPE SEEMS TO BE DVB-C\n");
|
|
92 return TUNER_CBL;
|
|
93
|
|
94 default:
|
|
95 mp_msg(MSGT_DEMUX, MSGL_ERR, "UNKNOWN TUNER TYPE\n");
|
|
96 return 0;
|
|
97 }
|
|
98
|
|
99 }
|
|
100
|
|
101
|
|
102 static int open_fe(dvb_priv_t *priv)
|
|
103 {
|
|
104 priv->fe_fd = open(dvb_frontenddev[priv->card], O_RDWR);
|
|
105 if(priv->fe_fd < 0)
|
9610
|
106 {
|
10560
|
107 mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR IN OPENING FRONTEND DEVICE %s: %d\n", dvb_frontenddev[priv->card], errno);
|
|
108 return 0;
|
9610
|
109 }
|
|
110 #ifdef HAVE_DVB_HEAD
|
10560
|
111 priv->sec_fd=0;
|
9610
|
112 #else
|
10560
|
113 priv->sec_fd = open(dvb_secdev[priv->card], O_RDWR);
|
|
114 if(priv->sec_fd < 0)
|
|
115 {
|
|
116 mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR IN OPENING SEC DEVICE %s: %d\n", dvb_secdev[priv->card], errno);
|
|
117 close(priv->fe_fd);
|
|
118 return 0;
|
|
119 }
|
9610
|
120 #endif
|
10560
|
121
|
|
122 return 1;
|
9610
|
123 }
|
|
124
|
|
125
|
|
126
|
10560
|
127 int dvb_set_ts_filt(int fd, uint16_t pid, dmx_pes_type_t pestype)
|
9610
|
128 {
|
|
129 int i;
|
|
130 struct dmx_pes_filter_params pesFilterParams;
|
|
131
|
|
132 pesFilterParams.pid = pid;
|
|
133 pesFilterParams.input = DMX_IN_FRONTEND;
|
|
134 pesFilterParams.output = DMX_OUT_TS_TAP;
|
|
135 #ifdef HAVE_DVB_HEAD
|
|
136 pesFilterParams.pes_type = pestype;
|
|
137 #else
|
|
138 pesFilterParams.pesType = pestype;
|
|
139 #endif
|
|
140
|
10560
|
141 pesFilterParams.flags = DMX_IMMEDIATE_START;
|
|
142 //pesFilterParams.flags = DMX_START;
|
9610
|
143
|
10560
|
144 //errno = 0;
|
9610
|
145 if ((i = ioctl(fd, DMX_SET_PES_FILTER, &pesFilterParams)) < 0)
|
|
146 {
|
10560
|
147 mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR IN SETTING DMX_FILTER %i for fd %d: ERRNO: %d", pid, fd, errno);
|
|
148 return 0;
|
9610
|
149 }
|
|
150
|
10560
|
151 mp_msg(MSGT_DEMUX, MSGL_V, "SET PES FILTER ON PID %d to fd %d, RESULT: %d, ERRNO: %d\n", pid, fd, i, errno);
|
9610
|
152 return 1;
|
|
153 }
|
|
154
|
|
155
|
10560
|
156 int dvb_demux_stop(int fd)
|
9610
|
157 {
|
|
158 int i;
|
|
159 i = ioctl(fd, DMX_STOP);
|
|
160
|
|
161 mp_msg(MSGT_DEMUX, MSGL_DBG2, "STOPPING FD: %d, RESULT: %d\n", fd, i);
|
|
162
|
|
163 return (i==0);
|
|
164 }
|
|
165
|
|
166
|
10560
|
167 int dvb_demux_start(int fd)
|
|
168 {
|
|
169 int i;
|
|
170 i = ioctl(fd, DMX_START);
|
9610
|
171
|
10560
|
172 mp_msg(MSGT_DEMUX, MSGL_DBG2, "STARTING FD: %d, RESULT: %d\n", fd, i);
|
|
173
|
|
174 return (i==0);
|
|
175 }
|
|
176
|
|
177
|
|
178 static void make_nonblock(int f)
|
9610
|
179 {
|
|
180 int oldflags;
|
|
181
|
|
182 if ((oldflags=fcntl(f, F_GETFL, 0)) < 0)
|
|
183 {
|
|
184 perror("ERROR IN F_GETFL");
|
|
185 }
|
|
186
|
|
187 oldflags|=O_NONBLOCK;
|
|
188 if (fcntl(f, F_SETFL, oldflags) < 0)
|
|
189 {
|
|
190 perror("F_SETFL");
|
|
191 }
|
|
192 }
|
|
193
|
|
194
|
|
195 static int tune_it(int fd_frontend, int fd_sec, unsigned int freq, unsigned int srate, char pol, int tone,
|
|
196 fe_spectral_inversion_t specInv, unsigned int diseqc, fe_modulation_t modulation, fe_code_rate_t HP_CodeRate,
|
|
197 fe_transmit_mode_t TransmissionMode, fe_guard_interval_t guardInterval, fe_bandwidth_t bandwidth);
|
|
198
|
|
199
|
|
200 dvb_tune(dvb_priv_t *priv, int freq, char pol, int srate, int diseqc, int tone,
|
|
201 fe_spectral_inversion_t specInv, fe_modulation_t modulation, fe_guard_interval_t guardInterval,
|
|
202 fe_transmit_mode_t TransmissionMode, fe_bandwidth_t bandWidth, fe_code_rate_t HP_CodeRate)
|
|
203 {
|
10560
|
204 mp_msg(MSGT_DEMUX, MSGL_INFO, "dvb_tune Freq: %lu\n", freq);
|
|
205 if(! open_fe(priv))
|
|
206 {
|
|
207 return 0;
|
|
208 }
|
|
209
|
9610
|
210 if(freq > 100000000)
|
|
211 {
|
10560
|
212 tune_it(priv->fe_fd, 0, freq, 0, 0, tone, specInv, diseqc, modulation, HP_CodeRate, TransmissionMode, guardInterval, bandWidth);
|
9610
|
213 }
|
10560
|
214 else if(freq != 0)
|
9610
|
215 {
|
10560
|
216 tune_it(priv->fe_fd, priv->sec_fd, freq, srate, pol, tone, specInv, diseqc, modulation, HP_CodeRate, TransmissionMode, guardInterval, bandWidth);
|
9610
|
217 }
|
10560
|
218
|
|
219 close(priv->fe_fd);
|
|
220
|
|
221 #ifdef HAVE_DVB_HEAD
|
|
222 #else
|
|
223 close(priv->sec_fd);
|
|
224 #endif
|
9610
|
225
|
|
226 return 1;
|
|
227 }
|
|
228
|
|
229
|
|
230
|
|
231
|
|
232
|
|
233 #ifndef HAVE_DVB_HEAD
|
|
234 static int OSTSelftest(int fd)
|
|
235 {
|
|
236 int ans;
|
|
237
|
|
238 if ((ans = ioctl(fd, FE_SELFTEST,0) < 0))
|
|
239 {
|
|
240 mp_msg(MSGT_DEMUX, MSGL_ERR, "FE SELF TEST: ");
|
|
241 return -1;
|
|
242 }
|
|
243
|
|
244 return 0;
|
|
245 }
|
|
246
|
|
247 static int OSTSetPowerState(int fd, uint32_t state)
|
|
248 {
|
|
249 int ans;
|
|
250
|
|
251 if ((ans = ioctl(fd,FE_SET_POWER_STATE,state) < 0))
|
|
252 {
|
|
253 mp_msg(MSGT_DEMUX, MSGL_ERR, "OST SET POWER STATE: ");
|
|
254 return -1;
|
|
255 }
|
|
256
|
|
257 return 0;
|
|
258 }
|
|
259
|
|
260 static int OSTGetPowerState(int fd, uint32_t *state)
|
|
261 {
|
|
262 int ans;
|
|
263
|
|
264 if ((ans = ioctl(fd,FE_GET_POWER_STATE,state) < 0))
|
|
265 {
|
|
266 mp_msg(MSGT_DEMUX, MSGL_ERR, "OST GET POWER STATE: ");
|
|
267 return -1;
|
|
268 }
|
|
269
|
|
270 switch(*state)
|
|
271 {
|
|
272 case FE_POWER_ON:
|
|
273 mp_msg(MSGT_DEMUX, MSGL_V, "POWER ON (%d)\n",*state);
|
|
274 break;
|
|
275 case FE_POWER_STANDBY:
|
|
276 mp_msg(MSGT_DEMUX, MSGL_V, "POWER STANDBY (%d)\n",*state);
|
|
277 break;
|
|
278 case FE_POWER_SUSPEND:
|
|
279 mp_msg(MSGT_DEMUX, MSGL_V, "POWER SUSPEND (%d)\n",*state);
|
|
280 break;
|
|
281 case FE_POWER_OFF:
|
|
282 mp_msg(MSGT_DEMUX, MSGL_V, "POWER OFF (%d)\n",*state);
|
|
283 break;
|
|
284 default:
|
|
285 mp_msg(MSGT_DEMUX, MSGL_V, "unknown (%d)\n",*state);
|
|
286 break;
|
|
287 }
|
|
288
|
|
289 return 0;
|
|
290 }
|
|
291
|
|
292
|
|
293 static int SecGetStatus (int fd, struct secStatus *state)
|
|
294 {
|
|
295 int ans;
|
|
296
|
|
297 if ((ans = ioctl(fd, SEC_GET_STATUS, state) < 0))
|
|
298 {
|
|
299 mp_msg(MSGT_DEMUX, MSGL_ERR, ("SEC GET STATUS: "));
|
|
300 return -1;
|
|
301 }
|
|
302
|
|
303 switch (state->busMode)
|
|
304 {
|
|
305 case SEC_BUS_IDLE:
|
|
306 mp_msg(MSGT_DEMUX, MSGL_V, "SEC BUS MODE: IDLE (%d)\n",state->busMode);
|
|
307 break;
|
|
308 case SEC_BUS_BUSY:
|
|
309 mp_msg(MSGT_DEMUX, MSGL_V, "SEC BUS MODE: BUSY (%d)\n",state->busMode);
|
|
310 break;
|
|
311 case SEC_BUS_OFF:
|
|
312 mp_msg(MSGT_DEMUX, MSGL_V, "SEC BUS MODE: OFF (%d)\n",state->busMode);
|
|
313 break;
|
|
314 case SEC_BUS_OVERLOAD:
|
|
315 mp_msg(MSGT_DEMUX, MSGL_V, "SEC BUS MODE: OVERLOAD (%d)\n",state->busMode);
|
|
316 break;
|
|
317 default:
|
|
318 mp_msg(MSGT_DEMUX, MSGL_V, "SEC BUS MODE: unknown (%d)\n",state->busMode);
|
|
319 break;
|
|
320 }
|
|
321
|
|
322 switch (state->selVolt)
|
|
323 {
|
|
324 case SEC_VOLTAGE_OFF:
|
|
325 mp_msg(MSGT_DEMUX, MSGL_V, "SEC VOLTAGE: OFF (%d)\n",state->selVolt);
|
|
326 break;
|
|
327 case SEC_VOLTAGE_LT:
|
|
328 mp_msg(MSGT_DEMUX, MSGL_V, "SEC VOLTAGE: LT (%d)\n",state->selVolt);
|
|
329 break;
|
|
330 case SEC_VOLTAGE_13:
|
|
331 mp_msg(MSGT_DEMUX, MSGL_V, "SEC VOLTAGE: 13 (%d)\n",state->selVolt);
|
|
332 break;
|
|
333 case SEC_VOLTAGE_13_5:
|
|
334 mp_msg(MSGT_DEMUX, MSGL_V, "SEC VOLTAGE: 13.5 (%d)\n",state->selVolt);
|
|
335 break;
|
|
336 case SEC_VOLTAGE_18:
|
|
337 mp_msg(MSGT_DEMUX, MSGL_V, "SEC VOLTAGE: 18 (%d)\n",state->selVolt);
|
|
338 break;
|
|
339 case SEC_VOLTAGE_18_5:
|
|
340 mp_msg(MSGT_DEMUX, MSGL_V, "SEC VOLTAGE: 18.5 (%d)\n",state->selVolt);
|
|
341 break;
|
|
342 default:
|
|
343 mp_msg(MSGT_DEMUX, MSGL_V, "SEC VOLTAGE: unknown (%d)\n",state->selVolt);
|
|
344 break;
|
|
345 }
|
|
346
|
|
347 mp_msg(MSGT_DEMUX, MSGL_V, "SEC CONT TONE: %s\n", (state->contTone == SEC_TONE_ON ? "ON" : "OFF"));
|
|
348 return 0;
|
|
349 }
|
|
350
|
|
351 #endif
|
|
352
|
|
353 static void print_status(fe_status_t festatus)
|
|
354 {
|
|
355 mp_msg(MSGT_DEMUX, MSGL_V, "FE_STATUS:");
|
|
356 if (festatus & FE_HAS_SIGNAL) mp_msg(MSGT_DEMUX, MSGL_V," FE_HAS_SIGNAL");
|
|
357 #ifdef HAVE_DVB_HEAD
|
|
358 if (festatus & FE_TIMEDOUT) mp_msg(MSGT_DEMUX, MSGL_V, " FE_TIMEDOUT");
|
|
359 #else
|
|
360 if (festatus & FE_HAS_POWER) mp_msg(MSGT_DEMUX, MSGL_V, " FE_HAS_POWER");
|
|
361 if (festatus & FE_SPECTRUM_INV) mp_msg(MSGT_DEMUX, MSGL_V, " FE_SPECTRUM_INV");
|
|
362 if (festatus & FE_TUNER_HAS_LOCK) mp_msg(MSGT_DEMUX, MSGL_V, " FE_TUNER_HAS_LOCK");
|
|
363 #endif
|
|
364 if (festatus & FE_HAS_LOCK) mp_msg(MSGT_DEMUX, MSGL_V, " FE_HAS_LOCK");
|
|
365 if (festatus & FE_HAS_CARRIER) mp_msg(MSGT_DEMUX, MSGL_V, " FE_HAS_CARRIER");
|
|
366 if (festatus & FE_HAS_VITERBI) mp_msg(MSGT_DEMUX, MSGL_V, " FE_HAS_VITERBI");
|
|
367 if (festatus & FE_HAS_SYNC) mp_msg(MSGT_DEMUX, MSGL_V, " FE_HAS_SYNC");
|
|
368 mp_msg(MSGT_DEMUX, MSGL_V, "\n");
|
|
369 }
|
|
370
|
|
371
|
|
372 #ifdef HAVE_DVB_HEAD
|
|
373 static int check_status(int fd_frontend,struct dvb_frontend_parameters* feparams,int tone)
|
|
374 {
|
|
375 int i,res;
|
|
376 int32_t strength;
|
|
377 fe_status_t festatus;
|
|
378 struct dvb_frontend_event event;
|
|
379 struct dvb_frontend_info fe_info;
|
|
380 struct pollfd pfd[1];
|
|
381
|
|
382 if (ioctl(fd_frontend,FE_SET_FRONTEND,feparams) < 0)
|
|
383 {
|
|
384 mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR tuning channel\n");
|
|
385 return -1;
|
|
386 }
|
|
387
|
|
388 pfd[0].fd = fd_frontend;
|
|
389 pfd[0].events = POLLIN;
|
|
390
|
|
391 event.status=0;
|
|
392 while (((event.status & FE_TIMEDOUT)==0) && ((event.status & FE_HAS_LOCK)==0))
|
|
393 {
|
|
394 mp_msg(MSGT_DEMUX, MSGL_V, "polling....\n");
|
|
395 if (poll(pfd,1,10000))
|
|
396 {
|
|
397 if (pfd[0].revents & POLLIN)
|
|
398 {
|
|
399 mp_msg(MSGT_DEMUX, MSGL_V, "Getting frontend event\n");
|
|
400 if ( ioctl(fd_frontend, FE_GET_EVENT, &event) < 0)
|
|
401 {
|
|
402 mp_msg(MSGT_DEMUX, MSGL_ERR, "FE_GET_EVENT");
|
|
403 return -1;
|
|
404 }
|
|
405 }
|
|
406 print_status(event.status);
|
|
407 }
|
|
408 }
|
|
409
|
|
410 if (event.status & FE_HAS_LOCK)
|
|
411 {
|
|
412 switch(fe_info.type)
|
|
413 {
|
|
414 case FE_OFDM:
|
|
415 mp_msg(MSGT_DEMUX, MSGL_V, "Event: Frequency: %d\n",event.parameters.frequency);
|
|
416 break;
|
|
417 case FE_QPSK:
|
|
418 mp_msg(MSGT_DEMUX, MSGL_V, "Event: Frequency: %d\n",(unsigned int)((event.parameters.frequency)+(tone==SEC_TONE_OFF ? LOF1 : LOF2)));
|
|
419 mp_msg(MSGT_DEMUX, MSGL_V, " SymbolRate: %d\n",event.parameters.u.qpsk.symbol_rate);
|
|
420 mp_msg(MSGT_DEMUX, MSGL_V, " FEC_inner: %d\n",event.parameters.u.qpsk.fec_inner);
|
|
421 mp_msg(MSGT_DEMUX, MSGL_V, "\n");
|
|
422 break;
|
|
423 case FE_QAM:
|
|
424 mp_msg(MSGT_DEMUX, MSGL_V, "Event: Frequency: %d\n",event.parameters.frequency);
|
|
425 mp_msg(MSGT_DEMUX, MSGL_V, " SymbolRate: %d\n",event.parameters.u.qpsk.symbol_rate);
|
|
426 mp_msg(MSGT_DEMUX, MSGL_V, " FEC_inner: %d\n",event.parameters.u.qpsk.fec_inner);
|
|
427 break;
|
|
428 default:
|
|
429 break;
|
|
430 }
|
|
431
|
|
432 strength=0;
|
|
433 ioctl(fd_frontend,FE_READ_BER,&strength);
|
|
434 mp_msg(MSGT_DEMUX, MSGL_V, "Bit error rate: %d\n",strength);
|
|
435
|
|
436 strength=0;
|
|
437 ioctl(fd_frontend,FE_READ_SIGNAL_STRENGTH,&strength);
|
|
438 mp_msg(MSGT_DEMUX, MSGL_V, "Signal strength: %d\n",strength);
|
|
439
|
|
440 strength=0;
|
|
441 ioctl(fd_frontend,FE_READ_SNR,&strength);
|
|
442 mp_msg(MSGT_DEMUX, MSGL_V, "SNR: %d\n",strength);
|
|
443
|
|
444 festatus=0;
|
|
445 ioctl(fd_frontend,FE_READ_STATUS,&festatus);
|
|
446 print_status(festatus);
|
|
447 }
|
|
448 else
|
|
449 {
|
|
450 mp_msg(MSGT_DEMUX, MSGL_V, "Not able to lock to the signal on the given frequency\n");
|
|
451 return -1;
|
|
452 }
|
|
453 return 0;
|
|
454 }
|
|
455
|
|
456 #else
|
|
457
|
|
458 static int check_status(int fd_frontend,FrontendParameters* feparams,int tone)
|
|
459 {
|
|
460 int i,res;
|
|
461 int32_t strength;
|
|
462 fe_status_t festatus;
|
|
463 FrontendEvent event;
|
|
464 FrontendInfo fe_info;
|
|
465 struct pollfd pfd[1];
|
|
466
|
|
467 i = 0; res = -1;
|
|
468 while ((i < 3) && (res < 0))
|
|
469 {
|
|
470 if (ioctl(fd_frontend,FE_SET_FRONTEND,feparams) < 0)
|
|
471 {
|
|
472 mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR tuning channel\n");
|
|
473 return -1;
|
|
474 }
|
|
475
|
|
476 pfd[0].fd = fd_frontend;
|
|
477 pfd[0].events = POLLIN;
|
|
478
|
|
479 if (poll(pfd,1,10000))
|
|
480 {
|
|
481 if (pfd[0].revents & POLLIN)
|
|
482 {
|
|
483 mp_msg(MSGT_DEMUX, MSGL_V, "Getting frontend event\n");
|
|
484 if ( ioctl(fd_frontend, FE_GET_EVENT, &event) < 0)
|
|
485 {
|
|
486 mp_msg(MSGT_DEMUX, MSGL_ERR, "FE_GET_EVENT");
|
|
487 return -1;
|
|
488 }
|
|
489 mp_msg(MSGT_DEMUX, MSGL_V, "Received ");
|
|
490 switch(event.type)
|
|
491 {
|
|
492 case FE_UNEXPECTED_EV:
|
|
493 mp_msg(MSGT_DEMUX, MSGL_V, "unexpected event\n");
|
|
494 res = -1;
|
|
495 break;
|
|
496
|
|
497 case FE_FAILURE_EV:
|
|
498 mp_msg(MSGT_DEMUX, MSGL_V, "failure event\n");
|
|
499 res = -1;
|
|
500 break;
|
|
501
|
|
502 case FE_COMPLETION_EV:
|
|
503 mp_msg(MSGT_DEMUX, MSGL_V, "completion event\n");
|
|
504 res = 0;
|
|
505 break;
|
|
506 }
|
|
507 }
|
|
508 i++;
|
|
509 }
|
|
510 }
|
|
511
|
|
512 if (res > 0)
|
|
513 switch (event.type)
|
|
514 {
|
|
515 case FE_UNEXPECTED_EV: mp_msg(MSGT_DEMUX, MSGL_V, "FE_UNEXPECTED_EV\n");
|
|
516 break;
|
|
517 case FE_COMPLETION_EV: mp_msg(MSGT_DEMUX, MSGL_V, "FE_COMPLETION_EV\n");
|
|
518 break;
|
|
519 case FE_FAILURE_EV: mp_msg(MSGT_DEMUX, MSGL_V, "FE_FAILURE_EV\n");
|
|
520 break;
|
|
521 }
|
|
522
|
|
523 if (event.type == FE_COMPLETION_EV)
|
|
524 {
|
|
525 switch(fe_info.type)
|
|
526 {
|
|
527 case FE_OFDM:
|
|
528 mp_msg(MSGT_DEMUX, MSGL_V, "Event: Frequency: %d\n",event.u.completionEvent.Frequency);
|
|
529 break;
|
|
530
|
|
531 case FE_QPSK:
|
|
532 mp_msg(MSGT_DEMUX, MSGL_V, "Event: Frequency: %d\n",(unsigned int)((event.u.completionEvent.Frequency)+(tone==SEC_TONE_OFF ? LOF1 : LOF2)));
|
|
533 mp_msg(MSGT_DEMUX, MSGL_V, " SymbolRate: %d\n",event.u.completionEvent.u.qpsk.SymbolRate);
|
|
534 mp_msg(MSGT_DEMUX, MSGL_V, " FEC_inner: %d\n",event.u.completionEvent.u.qpsk.FEC_inner);
|
|
535 mp_msg(MSGT_DEMUX, MSGL_V, "\n");
|
|
536 break;
|
|
537
|
|
538 case FE_QAM:
|
|
539 mp_msg(MSGT_DEMUX, MSGL_V, "Event: Frequency: %d\n",event.u.completionEvent.Frequency);
|
|
540 mp_msg(MSGT_DEMUX, MSGL_V, " SymbolRate: %d\n",event.u.completionEvent.u.qpsk.SymbolRate);
|
|
541 mp_msg(MSGT_DEMUX, MSGL_V, " FEC_inner: %d\n",event.u.completionEvent.u.qpsk.FEC_inner);
|
|
542 break;
|
|
543
|
|
544 default:
|
|
545 break;
|
|
546 }
|
|
547
|
|
548 strength=0;
|
|
549 ioctl(fd_frontend,FE_READ_BER,&strength);
|
|
550 mp_msg(MSGT_DEMUX, MSGL_V, "Bit error rate: %d\n",strength);
|
|
551
|
|
552 strength=0;
|
|
553 ioctl(fd_frontend,FE_READ_SIGNAL_STRENGTH,&strength);
|
|
554 mp_msg(MSGT_DEMUX, MSGL_V, "Signal strength: %d\n",strength);
|
|
555
|
|
556 strength=0;
|
|
557 ioctl(fd_frontend,FE_READ_SNR,&strength);
|
|
558 mp_msg(MSGT_DEMUX, MSGL_V, "SNR: %d\n",strength);
|
|
559
|
|
560 festatus=0;
|
|
561 ioctl(fd_frontend,FE_READ_STATUS,&festatus);
|
|
562
|
|
563 mp_msg(MSGT_DEMUX, MSGL_V, "FE_STATUS:");
|
|
564 if (festatus & FE_HAS_POWER) mp_msg(MSGT_DEMUX, MSGL_V, " FE_HAS_POWER");
|
|
565 if (festatus & FE_HAS_SIGNAL) mp_msg(MSGT_DEMUX, MSGL_V, " FE_HAS_SIGNAL");
|
|
566 if (festatus & FE_SPECTRUM_INV) mp_msg(MSGT_DEMUX, MSGL_V, " FE_SPECTRUM_INV");
|
|
567 if (festatus & FE_HAS_LOCK) mp_msg(MSGT_DEMUX, MSGL_V, " FE_HAS_LOCK");
|
|
568 if (festatus & FE_HAS_CARRIER) mp_msg(MSGT_DEMUX, MSGL_V, " FE_HAS_CARRIER");
|
|
569 if (festatus & FE_HAS_VITERBI) mp_msg(MSGT_DEMUX, MSGL_V, " FE_HAS_VITERBI");
|
|
570 if (festatus & FE_HAS_SYNC) mp_msg(MSGT_DEMUX, MSGL_V, " FE_HAS_SYNC");
|
|
571 if (festatus & FE_TUNER_HAS_LOCK) mp_msg(MSGT_DEMUX, MSGL_V, " FE_TUNER_HAS_LOCK");
|
|
572 mp_msg(MSGT_DEMUX, MSGL_V, "\n");
|
|
573 }
|
|
574 else
|
|
575 {
|
|
576 mp_msg(MSGT_DEMUX, MSGL_V, "Not able to lock to the signal on the given frequency\n");
|
|
577 return -1;
|
|
578 }
|
|
579 return 0;
|
|
580 }
|
|
581 #endif
|
|
582
|
|
583 #ifdef HAVE_DVB_HEAD
|
|
584
|
10560
|
585 static struct diseqc_cmd {
|
9610
|
586 struct dvb_diseqc_master_cmd cmd;
|
|
587 uint32_t wait;
|
|
588 };
|
|
589
|
|
590 static void diseqc_send_msg(int fd, fe_sec_voltage_t v, struct diseqc_cmd *cmd,
|
|
591 fe_sec_tone_mode_t t, fe_sec_mini_cmd_t b)
|
|
592 {
|
|
593 ioctl(fd, FE_SET_TONE, SEC_TONE_OFF);
|
|
594 ioctl(fd, FE_SET_VOLTAGE, v);
|
|
595 usleep(15 * 1000);
|
|
596 ioctl(fd, FE_DISEQC_SEND_MASTER_CMD, &cmd->cmd);
|
|
597 usleep(cmd->wait * 1000);
|
|
598 usleep(15 * 1000);
|
|
599 ioctl(fd, FE_DISEQC_SEND_BURST, b);
|
|
600 usleep(15 * 1000);
|
|
601 ioctl(fd, FE_SET_TONE, t);
|
|
602 }
|
|
603
|
|
604
|
|
605
|
|
606
|
|
607 /* digital satellite equipment control,
|
|
608 * specification is available from http://www.eutelsat.com/
|
|
609 */
|
|
610 static int head_diseqc(int secfd, int sat_no, int pol, int hi_lo)
|
|
611 {
|
|
612 struct diseqc_cmd cmd = { {{0xe0, 0x10, 0x38, 0xf0, 0x00, 0x00}, 4}, 0 };
|
|
613
|
|
614 /* param: high nibble: reset bits, low nibble set bits,
|
|
615 * bits are: option, position, polarizaion, band
|
|
616 */
|
|
617 cmd.cmd.msg[3] =
|
|
618 0xf0 | (((sat_no * 4) & 0x0f) | (hi_lo ? 1 : 0) | (pol ? 0 : 2));
|
|
619
|
|
620 diseqc_send_msg(secfd, pol ? SEC_VOLTAGE_13 : SEC_VOLTAGE_18,
|
|
621 &cmd, hi_lo ? SEC_TONE_ON : SEC_TONE_OFF,
|
|
622 (sat_no / 4) % 2 ? SEC_MINI_B : SEC_MINI_A);
|
|
623
|
|
624 return 1;
|
|
625 }
|
|
626
|
|
627 #endif
|
|
628
|
10560
|
629 static unsigned int prev_diseqc = 0;
|
9610
|
630
|
|
631 static int tune_it(int fd_frontend, int fd_sec, unsigned int freq, unsigned int srate, char pol, int tone,
|
|
632 fe_spectral_inversion_t specInv, unsigned int diseqc, fe_modulation_t modulation, fe_code_rate_t HP_CodeRate,
|
|
633 fe_transmit_mode_t TransmissionMode, fe_guard_interval_t guardInterval, fe_bandwidth_t bandwidth)
|
|
634 {
|
|
635 int res;
|
|
636 #ifdef HAVE_DVB_HEAD
|
|
637 struct dvb_frontend_parameters feparams;
|
|
638 struct dvb_frontend_info fe_info;
|
|
639 fe_sec_voltage_t voltage;
|
|
640 #else
|
|
641 FrontendParameters feparams;
|
|
642 FrontendInfo fe_info;
|
|
643 secVoltage voltage;
|
|
644 struct secStatus sec_state;
|
|
645 #endif
|
|
646
|
10560
|
647 if(diseqc == prev_diseqc)
|
|
648 diseqc = 0;
|
|
649 else
|
|
650 prev_diseqc = diseqc;
|
9610
|
651
|
10560
|
652 mp_msg(MSGT_DEMUX, MSGL_V, "TUNE_IT, fd_frontend %d, fd_sec %d\nfreq %lu, srate %lu, pol %c, tone %i, specInv, diseqc %u, fe_modulation_t modulation,fe_code_rate_t HP_CodeRate, fe_transmit_mode_t TransmissionMode,fe_guard_interval_t guardInterval, fe_bandwidth_t bandwidth\n",
|
9610
|
653 fd_frontend, fd_sec, freq, srate, pol, tone, diseqc);
|
|
654
|
|
655
|
|
656 if ( (res = ioctl(fd_frontend,FE_GET_INFO, &fe_info) < 0))
|
|
657 {
|
|
658 mp_msg(MSGT_DEMUX, MSGL_ERR, "FE_GET_INFO: ");
|
|
659 return -1;
|
|
660 }
|
|
661
|
|
662
|
|
663 #ifdef HAVE_DVB_HEAD
|
10560
|
664 mp_msg(MSGT_DEMUX, MSGL_V, "Using DVB card \"%s\"\n", fe_info.name);
|
9610
|
665 #endif
|
|
666
|
|
667 switch(fe_info.type)
|
|
668 {
|
|
669 case FE_OFDM:
|
|
670 #ifdef HAVE_DVB_HEAD
|
|
671 if (freq < 1000000) freq*=1000UL;
|
|
672 feparams.frequency=freq;
|
|
673 feparams.inversion=INVERSION_OFF;
|
|
674 feparams.u.ofdm.bandwidth=bandwidth;
|
|
675 feparams.u.ofdm.code_rate_HP=HP_CodeRate;
|
|
676 feparams.u.ofdm.code_rate_LP=LP_CODERATE_DEFAULT;
|
|
677 feparams.u.ofdm.constellation=modulation;
|
|
678 feparams.u.ofdm.transmission_mode=TransmissionMode;
|
|
679 feparams.u.ofdm.guard_interval=guardInterval;
|
|
680 feparams.u.ofdm.hierarchy_information=HIERARCHY_DEFAULT;
|
|
681 #else
|
|
682 if (freq < 1000000) freq*=1000UL;
|
|
683 feparams.Frequency=freq;
|
|
684 feparams.Inversion=INVERSION_OFF;
|
|
685 feparams.u.ofdm.bandWidth=bandwidth;
|
|
686 feparams.u.ofdm.HP_CodeRate=HP_CodeRate;
|
|
687 feparams.u.ofdm.LP_CodeRate=LP_CODERATE_DEFAULT;
|
|
688 feparams.u.ofdm.Constellation=modulation;
|
|
689 feparams.u.ofdm.TransmissionMode=TransmissionMode;
|
|
690 feparams.u.ofdm.guardInterval=guardInterval;
|
|
691 feparams.u.ofdm.HierarchyInformation=HIERARCHY_DEFAULT;
|
|
692 #endif
|
|
693 mp_msg(MSGT_DEMUX, MSGL_V, "tuning DVB-T (%s) to %d Hz\n",DVB_T_LOCATION,freq);
|
|
694 break;
|
|
695 case FE_QPSK:
|
|
696 #ifdef HAVE_DVB_HEAD
|
|
697 mp_msg(MSGT_DEMUX, MSGL_V, "tuning DVB-S to L-Band:%d, Pol:%c Srate=%d, 22kHz=%s\n",feparams.frequency,pol,srate,tone == SEC_TONE_ON ? "on" : "off");
|
|
698 #else
|
|
699 mp_msg(MSGT_DEMUX, MSGL_V, "tuning DVB-S to L-Band:%d, Pol:%c Srate=%d, 22kHz=%s\n",feparams.Frequency,pol,srate,tone == SEC_TONE_ON ? "on" : "off");
|
|
700 #endif
|
|
701 if ((pol=='h') || (pol=='H'))
|
|
702 {
|
|
703 voltage = SEC_VOLTAGE_18;
|
|
704 }
|
|
705 else
|
|
706 {
|
|
707 voltage = SEC_VOLTAGE_13;
|
|
708 }
|
|
709 #ifdef HAVE_DVB_HEAD
|
|
710 if (ioctl(fd_frontend,FE_SET_VOLTAGE,voltage) < 0)
|
|
711 {
|
|
712 #else
|
|
713 if (ioctl(fd_sec,SEC_SET_VOLTAGE,voltage) < 0)
|
|
714 {
|
|
715 #endif
|
|
716 mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR setting voltage\n");
|
|
717 }
|
|
718
|
|
719 if (freq > 2200000)
|
|
720 {
|
|
721 // this must be an absolute frequency
|
|
722 if (freq < SLOF)
|
|
723 {
|
|
724 #ifdef HAVE_DVB_HEAD
|
|
725 feparams.frequency=(freq-LOF1);
|
|
726 #else
|
|
727 feparams.Frequency=(freq-LOF1);
|
|
728 #endif
|
|
729 if (tone < 0) tone = SEC_TONE_OFF;
|
|
730 }
|
|
731 else
|
|
732 {
|
|
733 #ifdef HAVE_DVB_HEAD
|
|
734 feparams.frequency=(freq-LOF2);
|
|
735 #else
|
|
736 feparams.Frequency=(freq-LOF2);
|
|
737 #endif
|
|
738 if (tone < 0) tone = SEC_TONE_ON;
|
|
739 }
|
|
740 }
|
|
741 else
|
|
742 {
|
|
743 // this is an L-Band frequency
|
|
744 #ifdef HAVE_DVB_HEAD
|
|
745 feparams.frequency=freq;
|
|
746 #else
|
|
747 feparams.Frequency=freq;
|
|
748 #endif
|
|
749 }
|
|
750
|
|
751 #ifdef HAVE_DVB_HEAD
|
|
752 feparams.inversion=specInv;
|
|
753 feparams.u.qpsk.symbol_rate=srate;
|
|
754 feparams.u.qpsk.fec_inner=FEC_AUTO;
|
|
755 #else
|
|
756 feparams.Inversion=specInv;
|
|
757 feparams.u.qpsk.SymbolRate=srate;
|
|
758 feparams.u.qpsk.FEC_inner=FEC_AUTO;
|
|
759 #endif
|
|
760
|
|
761 #ifdef HAVE_DVB_HEAD
|
|
762 if (ioctl(fd_frontend, FE_SET_TONE,tone) < 0)
|
|
763 {
|
|
764 mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR setting tone\n");
|
|
765 }
|
|
766 #else
|
|
767 if (ioctl(fd_sec, SEC_SET_TONE,tone) < 0)
|
|
768 {
|
|
769 mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR setting tone\n");
|
|
770 }
|
|
771 #endif
|
|
772
|
|
773 #ifdef HAVE_DVB_HEAD
|
|
774 //#warning DISEQC is unimplemented for HAVE_DVB_HEAD
|
|
775 if(diseqc > 0)
|
|
776 {
|
|
777 int ipol = (pol == 'V' ? 1 : 0);
|
|
778 int hiband = (freq >= SLOF);
|
|
779
|
|
780 if(head_diseqc(fd_frontend, diseqc-1, ipol, hiband))
|
|
781 {
|
|
782 mp_msg(MSGT_DEMUX, MSGL_V, "DISEQC SETTING SUCCEDED\n");
|
|
783 }
|
|
784 else
|
|
785 {
|
10560
|
786 mp_msg(MSGT_DEMUX, MSGL_ERR, "DISEQC SETTING FAILED\n");
|
9610
|
787 }
|
|
788 }
|
|
789 #else
|
|
790 if (diseqc > 0)
|
|
791 {
|
|
792 struct secCommand scmd;
|
|
793 struct secCmdSequence scmds;
|
|
794
|
|
795 scmds.continuousTone = tone;
|
|
796 scmds.voltage = voltage;
|
|
797 /*
|
|
798 scmds.miniCommand = toneBurst ? SEC_MINI_B : SEC_MINI_A;
|
|
799 */
|
|
800 scmds.miniCommand = SEC_MINI_NONE;
|
|
801
|
|
802 scmd.type = 0;
|
|
803 scmds.numCommands = 1;
|
|
804 scmds.commands = &scmd;
|
|
805
|
|
806 scmd.u.diseqc.addr = 0x10;
|
|
807 scmd.u.diseqc.cmd = 0x38;
|
|
808 scmd.u.diseqc.numParams = 1;
|
|
809 scmd.u.diseqc.params[0] = 0xf0 |
|
|
810 (((diseqc - 1) << 2) & 0x0c) |
|
|
811 (voltage==SEC_VOLTAGE_18 ? 0x02 : 0) |
|
|
812 (tone==SEC_TONE_ON ? 0x01 : 0);
|
|
813
|
|
814 if (ioctl(fd_sec,SEC_SEND_SEQUENCE,&scmds) < 0)
|
|
815 {
|
|
816 mp_msg(MSGT_DEMUX, MSGL_ERR, "Error sending DisEqC");
|
10560
|
817 return 0;
|
9610
|
818 }
|
|
819 }
|
|
820 #endif
|
|
821 break;
|
|
822 case FE_QAM:
|
|
823 mp_msg(MSGT_DEMUX, MSGL_V, "tuning DVB-C to %d, srate=%d\n",freq,srate);
|
|
824 #ifdef HAVE_DVB_HEAD
|
|
825 feparams.frequency=freq;
|
|
826 feparams.inversion=INVERSION_OFF;
|
|
827 feparams.u.qam.symbol_rate = srate;
|
|
828 feparams.u.qam.fec_inner = FEC_AUTO;
|
|
829 feparams.u.qam.modulation = QAM_64;
|
|
830 #else
|
|
831 feparams.Frequency=freq;
|
|
832 feparams.Inversion=INVERSION_OFF;
|
|
833 feparams.u.qam.SymbolRate = srate;
|
|
834 feparams.u.qam.FEC_inner = FEC_AUTO;
|
|
835 feparams.u.qam.QAM = QAM_64;
|
|
836 #endif
|
|
837 break;
|
|
838 default:
|
|
839 mp_msg(MSGT_DEMUX, MSGL_V, "Unknown FE type. Aborting\n");
|
10603
|
840 return 0;
|
9610
|
841 }
|
|
842 usleep(100000);
|
|
843
|
|
844 #ifndef HAVE_DVB_HEAD
|
|
845 if (fd_sec) SecGetStatus(fd_sec, &sec_state);
|
|
846 #endif
|
|
847
|
|
848 return(check_status(fd_frontend,&feparams,tone));
|
|
849 }
|