Added -vo matrixview
[mplayer/kovensky.git] / stream / dvb_tune.c
blob8b7bdb731719ddb1ba45574515964402f0944f0c
1 /* dvbtune - tune.c
3 Copyright (C) Dave Chapman 2001,2002
5 Modified for use with MPlayer, for details see the changelog at
6 http://svn.mplayerhq.hu/mplayer/trunk/
7 $Id$
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 Or, point your browser to http://www.gnu.org/copyleft/gpl.html
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <ctype.h>
29 #include <sys/ioctl.h>
30 #include <poll.h>
31 #include <unistd.h>
32 #include <fcntl.h>
33 #include <time.h>
34 #include <errno.h>
35 #include "config.h"
37 #ifdef CONFIG_DVB_HEAD
38 #include <linux/dvb/dmx.h>
39 #include <linux/dvb/frontend.h>
40 #else
41 #include <ost/dmx.h>
42 #include <ost/sec.h>
43 #include <ost/frontend.h>
44 #endif
46 #include "dvbin.h"
47 #include "mp_msg.h"
51 int dvb_get_tuner_type(int fe_fd)
53 #ifdef CONFIG_DVB_HEAD
54 struct dvb_frontend_info fe_info;
55 #else
56 FrontendInfo fe_info;
57 #endif
59 int res;
61 res = ioctl(fe_fd, FE_GET_INFO, &fe_info);
62 if(res < 0)
64 mp_msg(MSGT_DEMUX, MSGL_ERR, "FE_GET_INFO error: %d, FD: %d\n\n", errno, fe_fd);
65 return 0;
68 switch(fe_info.type)
70 case FE_OFDM:
71 mp_msg(MSGT_DEMUX, MSGL_V, "TUNER TYPE SEEMS TO BE DVB-T\n");
72 return TUNER_TER;
74 case FE_QPSK:
75 mp_msg(MSGT_DEMUX, MSGL_V, "TUNER TYPE SEEMS TO BE DVB-S\n");
76 return TUNER_SAT;
78 case FE_QAM:
79 mp_msg(MSGT_DEMUX, MSGL_V, "TUNER TYPE SEEMS TO BE DVB-C\n");
80 return TUNER_CBL;
82 #ifdef DVB_ATSC
83 case FE_ATSC:
84 mp_msg(MSGT_DEMUX, MSGL_V, "TUNER TYPE SEEMS TO BE DVB-ATSC\n");
85 return TUNER_ATSC;
86 #endif
87 default:
88 mp_msg(MSGT_DEMUX, MSGL_ERR, "UNKNOWN TUNER TYPE\n");
89 return 0;
94 int dvb_set_ts_filt(int fd, uint16_t pid, dmx_pes_type_t pestype);
96 int dvb_open_devices(dvb_priv_t *priv, int n, int demux_cnt)
98 int i;
99 char frontend_dev[32], dvr_dev[32], demux_dev[32];
100 #ifndef CONFIG_DVB_HEAD
101 char sec_dev[32];
102 #endif
104 #ifdef CONFIG_DVB_HEAD
105 sprintf(frontend_dev, "/dev/dvb/adapter%d/frontend0", n);
106 sprintf(dvr_dev, "/dev/dvb/adapter%d/dvr0", n);
107 sprintf(demux_dev, "/dev/dvb/adapter%d/demux0", n);
108 #else
109 sprintf(frontend_dev, "/dev/ost/frontend%d", n);
110 sprintf(dvr_dev, "/dev/ost/dvr%d", n);
111 sprintf(demux_dev, "/dev/ost/demux%d", n);
112 sprintf(sec_dev, "/dev/ost/sec%d", n);
113 #endif
114 priv->fe_fd = open(frontend_dev, O_RDWR | O_NONBLOCK);
115 if(priv->fe_fd < 0)
117 mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR OPENING FRONTEND DEVICE %s: ERRNO %d\n", frontend_dev, errno);
118 return 0;
120 #ifndef CONFIG_DVB_HEAD
121 priv->sec_fd = open(sec_dev, O_RDWR);
122 if(priv->sec_fd < 0)
124 mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR OPENING SEC DEVICE %s: ERRNO %d\n", sec_dev, errno);
125 close(priv->fe_fd);
126 return 0;
128 #endif
129 priv->demux_fds_cnt = 0;
130 mp_msg(MSGT_DEMUX, MSGL_V, "DVB_OPEN_DEVICES(%d)\n", demux_cnt);
131 for(i = 0; i < demux_cnt; i++)
133 priv->demux_fds[i] = open(demux_dev, O_RDWR | O_NONBLOCK);
134 if(priv->demux_fds[i] < 0)
136 mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR OPENING DEMUX 0: %d\n", errno);
137 return 0;
139 else
141 mp_msg(MSGT_DEMUX, MSGL_V, "OPEN(%d), file %s: FD=%d, CNT=%d\n", i, demux_dev, priv->demux_fds[i], priv->demux_fds_cnt);
142 priv->demux_fds_cnt++;
147 priv->dvr_fd = open(dvr_dev, O_RDONLY| O_NONBLOCK);
148 if(priv->dvr_fd < 0)
150 mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR OPENING DVR DEVICE %s: %d\n", dvr_dev, errno);
151 return 0;
154 return 1;
158 int dvb_fix_demuxes(dvb_priv_t *priv, int cnt)
160 int i;
161 char demux_dev[32];
163 #ifdef CONFIG_DVB_HEAD
164 sprintf(demux_dev, "/dev/dvb/adapter%d/demux0", priv->card);
165 #else
166 sprintf(demux_dev, "/dev/ost/demux%d", priv->card);
167 #endif
169 mp_msg(MSGT_DEMUX, MSGL_V, "FIX %d -> %d\n", priv->demux_fds_cnt, cnt);
170 if(priv->demux_fds_cnt >= cnt)
172 for(i = priv->demux_fds_cnt-1; i >= cnt; i--)
174 mp_msg(MSGT_DEMUX, MSGL_V, "FIX, CLOSE fd(%d): %d\n", i, priv->demux_fds[i]);
175 close(priv->demux_fds[i]);
177 priv->demux_fds_cnt = cnt;
179 else if(priv->demux_fds_cnt < cnt)
181 for(i = priv->demux_fds_cnt; i < cnt; i++)
183 priv->demux_fds[i] = open(demux_dev, O_RDWR | O_NONBLOCK);
184 mp_msg(MSGT_DEMUX, MSGL_V, "FIX, OPEN fd(%d): %d\n", i, priv->demux_fds[i]);
185 if(priv->demux_fds[i] < 0)
187 mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR OPENING DEMUX 0: %d\n", errno);
188 return 0;
190 else
191 priv->demux_fds_cnt++;
195 return 1;
198 int dvb_set_ts_filt(int fd, uint16_t pid, dmx_pes_type_t pestype)
200 int i;
201 struct dmx_pes_filter_params pesFilterParams;
203 pesFilterParams.pid = pid;
204 pesFilterParams.input = DMX_IN_FRONTEND;
205 pesFilterParams.output = DMX_OUT_TS_TAP;
206 #ifdef CONFIG_DVB_HEAD
207 pesFilterParams.pes_type = pestype;
208 #else
209 pesFilterParams.pesType = pestype;
210 #endif
212 pesFilterParams.flags = DMX_IMMEDIATE_START;
214 errno = 0;
215 if ((i = ioctl(fd, DMX_SET_PES_FILTER, &pesFilterParams)) < 0)
217 mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR IN SETTING DMX_FILTER %i for fd %d: ERRNO: %d", pid, fd, errno);
218 return 0;
221 mp_msg(MSGT_DEMUX, MSGL_V, "SET PES FILTER ON PID %d to fd %d, RESULT: %d, ERRNO: %d\n", pid, fd, i, errno);
222 return 1;
226 int dvb_demux_stop(int fd)
228 int i;
229 i = ioctl(fd, DMX_STOP);
231 mp_msg(MSGT_DEMUX, MSGL_DBG2, "STOPPING FD: %d, RESULT: %d\n", fd, i);
233 return (i==0);
237 int dvb_demux_start(int fd)
239 int i;
240 i = ioctl(fd, DMX_START);
242 mp_msg(MSGT_DEMUX, MSGL_DBG2, "STARTING FD: %d, RESULT: %d\n", fd, i);
244 return (i==0);
248 static int tune_it(int fd_frontend, int fd_sec, unsigned int freq, unsigned int srate, char pol, int tone,
249 fe_spectral_inversion_t specInv, unsigned int diseqc, fe_modulation_t modulation, fe_code_rate_t HP_CodeRate,
250 fe_transmit_mode_t TransmissionMode, fe_guard_interval_t guardInterval, fe_bandwidth_t bandwidth,
251 fe_code_rate_t LP_CodeRate, fe_hierarchy_t hier, int tmout);
254 int dvb_tune(dvb_priv_t *priv, int freq, char pol, int srate, int diseqc, int tone,
255 fe_spectral_inversion_t specInv, fe_modulation_t modulation, fe_guard_interval_t guardInterval,
256 fe_transmit_mode_t TransmissionMode, fe_bandwidth_t bandWidth, fe_code_rate_t HP_CodeRate,
257 fe_code_rate_t LP_CodeRate, fe_hierarchy_t hier, int timeout)
259 int ris;
261 mp_msg(MSGT_DEMUX, MSGL_INFO, "dvb_tune Freq: %lu\n", (long unsigned int) freq);
263 ris = tune_it(priv->fe_fd, priv->sec_fd, freq, srate, pol, tone, specInv, diseqc, modulation, HP_CodeRate, TransmissionMode, guardInterval, bandWidth, LP_CodeRate, hier, timeout);
265 if(ris != 0)
266 mp_msg(MSGT_DEMUX, MSGL_INFO, "dvb_tune, TUNING FAILED\n");
268 return (ris == 0);
272 #ifndef CONFIG_DVB_HEAD
273 static int SecGetStatus (int fd, struct secStatus *state)
275 if(ioctl(fd, SEC_GET_STATUS, state) < 0)
277 mp_msg(MSGT_DEMUX, MSGL_ERR, ("SEC GET STATUS: "));
278 return -1;
281 switch (state->busMode)
283 case SEC_BUS_IDLE:
284 mp_msg(MSGT_DEMUX, MSGL_V, "SEC BUS MODE: IDLE (%d)\n",state->busMode);
285 break;
286 case SEC_BUS_BUSY:
287 mp_msg(MSGT_DEMUX, MSGL_V, "SEC BUS MODE: BUSY (%d)\n",state->busMode);
288 break;
289 case SEC_BUS_OFF:
290 mp_msg(MSGT_DEMUX, MSGL_V, "SEC BUS MODE: OFF (%d)\n",state->busMode);
291 break;
292 case SEC_BUS_OVERLOAD:
293 mp_msg(MSGT_DEMUX, MSGL_V, "SEC BUS MODE: OVERLOAD (%d)\n",state->busMode);
294 break;
295 default:
296 mp_msg(MSGT_DEMUX, MSGL_V, "SEC BUS MODE: unknown (%d)\n",state->busMode);
297 break;
300 switch (state->selVolt)
302 case SEC_VOLTAGE_OFF:
303 mp_msg(MSGT_DEMUX, MSGL_V, "SEC VOLTAGE: OFF (%d)\n",state->selVolt);
304 break;
305 case SEC_VOLTAGE_LT:
306 mp_msg(MSGT_DEMUX, MSGL_V, "SEC VOLTAGE: LT (%d)\n",state->selVolt);
307 break;
308 case SEC_VOLTAGE_13:
309 mp_msg(MSGT_DEMUX, MSGL_V, "SEC VOLTAGE: 13 (%d)\n",state->selVolt);
310 break;
311 case SEC_VOLTAGE_13_5:
312 mp_msg(MSGT_DEMUX, MSGL_V, "SEC VOLTAGE: 13.5 (%d)\n",state->selVolt);
313 break;
314 case SEC_VOLTAGE_18:
315 mp_msg(MSGT_DEMUX, MSGL_V, "SEC VOLTAGE: 18 (%d)\n",state->selVolt);
316 break;
317 case SEC_VOLTAGE_18_5:
318 mp_msg(MSGT_DEMUX, MSGL_V, "SEC VOLTAGE: 18.5 (%d)\n",state->selVolt);
319 break;
320 default:
321 mp_msg(MSGT_DEMUX, MSGL_V, "SEC VOLTAGE: unknown (%d)\n",state->selVolt);
322 break;
325 mp_msg(MSGT_DEMUX, MSGL_V, "SEC CONT TONE: %s\n", (state->contTone == SEC_TONE_ON ? "ON" : "OFF"));
326 return 0;
329 #endif
331 static void print_status(fe_status_t festatus)
333 mp_msg(MSGT_DEMUX, MSGL_V, "FE_STATUS:");
334 if (festatus & FE_HAS_SIGNAL) mp_msg(MSGT_DEMUX, MSGL_V," FE_HAS_SIGNAL");
335 #ifdef CONFIG_DVB_HEAD
336 if (festatus & FE_TIMEDOUT) mp_msg(MSGT_DEMUX, MSGL_V, " FE_TIMEDOUT");
337 #else
338 if (festatus & FE_HAS_POWER) mp_msg(MSGT_DEMUX, MSGL_V, " FE_HAS_POWER");
339 if (festatus & FE_SPECTRUM_INV) mp_msg(MSGT_DEMUX, MSGL_V, " FE_SPECTRUM_INV");
340 if (festatus & FE_TUNER_HAS_LOCK) mp_msg(MSGT_DEMUX, MSGL_V, " FE_TUNER_HAS_LOCK");
341 #endif
342 if (festatus & FE_HAS_LOCK) mp_msg(MSGT_DEMUX, MSGL_V, " FE_HAS_LOCK");
343 if (festatus & FE_HAS_CARRIER) mp_msg(MSGT_DEMUX, MSGL_V, " FE_HAS_CARRIER");
344 if (festatus & FE_HAS_VITERBI) mp_msg(MSGT_DEMUX, MSGL_V, " FE_HAS_VITERBI");
345 if (festatus & FE_HAS_SYNC) mp_msg(MSGT_DEMUX, MSGL_V, " FE_HAS_SYNC");
346 mp_msg(MSGT_DEMUX, MSGL_V, "\n");
350 #ifdef CONFIG_DVB_HEAD
351 static int check_status(int fd_frontend, int tmout)
353 int32_t strength;
354 fe_status_t festatus;
355 struct pollfd pfd[1];
356 int ok=0, locks=0;
357 time_t tm1, tm2;
359 pfd[0].fd = fd_frontend;
360 pfd[0].events = POLLPRI;
362 mp_msg(MSGT_DEMUX, MSGL_V, "Getting frontend status\n");
363 tm1 = tm2 = time((time_t*) NULL);
364 while(!ok)
366 festatus = 0;
367 if(poll(pfd,1,tmout*1000) > 0)
369 if (pfd[0].revents & POLLPRI)
371 if(ioctl(fd_frontend, FE_READ_STATUS, &festatus) >= 0)
372 if(festatus & FE_HAS_LOCK)
373 locks++;
376 usleep(10000);
377 tm2 = time((time_t*) NULL);
378 if((festatus & FE_TIMEDOUT) || (locks >= 2) || (tm2 - tm1 >= tmout))
379 ok = 1;
382 if(festatus & FE_HAS_LOCK)
384 strength=0;
385 if(ioctl(fd_frontend,FE_READ_BER,&strength) >= 0)
386 mp_msg(MSGT_DEMUX, MSGL_V, "Bit error rate: %d\n",strength);
388 strength=0;
389 if(ioctl(fd_frontend,FE_READ_SIGNAL_STRENGTH,&strength) >= 0)
390 mp_msg(MSGT_DEMUX, MSGL_V, "Signal strength: %d\n",strength);
392 strength=0;
393 if(ioctl(fd_frontend,FE_READ_SNR,&strength) >= 0)
394 mp_msg(MSGT_DEMUX, MSGL_V, "SNR: %d\n",strength);
396 strength=0;
397 if(ioctl(fd_frontend,FE_READ_UNCORRECTED_BLOCKS,&strength) >= 0)
398 mp_msg(MSGT_DEMUX, MSGL_V, "UNC: %d\n",strength);
400 print_status(festatus);
402 else
404 mp_msg(MSGT_DEMUX, MSGL_ERR, "Not able to lock to the signal on the given frequency, timeout: %d\n", tmout);
405 return -1;
407 return 0;
410 #else
412 static int check_status(int fd_frontend, int tmout)
414 int i,res;
415 int32_t strength;
416 fe_status_t festatus;
417 FrontendEvent event;
419 struct pollfd pfd[1];
421 i = 0; res = -1;
422 while ((i < 3) && (res < 0))
424 pfd[0].fd = fd_frontend;
425 pfd[0].events = POLLIN | POLLPRI;
427 if(poll(pfd,1,tmout*1000) > 0)
429 if (pfd[0].revents & POLLPRI)
431 mp_msg(MSGT_DEMUX, MSGL_V, "Getting frontend event\n");
432 if ( ioctl(fd_frontend, FE_GET_EVENT, &event) < 0)
434 mp_msg(MSGT_DEMUX, MSGL_ERR, "FE_GET_EVENT");
435 return -1;
437 mp_msg(MSGT_DEMUX, MSGL_V, "Received ");
438 switch(event.type)
440 case FE_UNEXPECTED_EV:
441 mp_msg(MSGT_DEMUX, MSGL_V, "unexpected event\n");
442 res = -1;
443 break;
445 case FE_FAILURE_EV:
446 mp_msg(MSGT_DEMUX, MSGL_V, "failure event\n");
447 res = -1;
448 break;
450 case FE_COMPLETION_EV:
451 mp_msg(MSGT_DEMUX, MSGL_V, "completion event\n");
452 res = 0;
453 break;
456 i++;
460 if (res > 0)
461 switch (event.type)
463 case FE_UNEXPECTED_EV: mp_msg(MSGT_DEMUX, MSGL_V, "FE_UNEXPECTED_EV\n");
464 break;
465 case FE_COMPLETION_EV: mp_msg(MSGT_DEMUX, MSGL_V, "FE_COMPLETION_EV\n");
466 break;
467 case FE_FAILURE_EV: mp_msg(MSGT_DEMUX, MSGL_V, "FE_FAILURE_EV\n");
468 break;
471 if (event.type == FE_COMPLETION_EV)
473 strength=0;
474 if(ioctl(fd_frontend,FE_READ_BER,&strength) >= 0)
475 mp_msg(MSGT_DEMUX, MSGL_V, "Bit error rate: %d\n",strength);
477 strength=0;
478 if(ioctl(fd_frontend,FE_READ_SIGNAL_STRENGTH,&strength) >= 0)
479 mp_msg(MSGT_DEMUX, MSGL_V, "Signal strength: %d\n",strength);
481 strength=0;
482 if(ioctl(fd_frontend,FE_READ_SNR,&strength) >= 0)
483 mp_msg(MSGT_DEMUX, MSGL_V, "SNR: %d\n",strength);
485 festatus=0;
486 mp_msg(MSGT_DEMUX, MSGL_V, "FE_STATUS:");
488 if(ioctl(fd_frontend,FE_READ_STATUS,&festatus) >= 0)
489 print_status(festatus);
490 else
491 mp_msg(MSGT_DEMUX, MSGL_ERR, " ERROR, UNABLE TO READ_STATUS");
493 mp_msg(MSGT_DEMUX, MSGL_V, "\n");
495 else
497 mp_msg(MSGT_DEMUX, MSGL_V, "Not able to lock to the signal on the given frequency\n");
498 return -1;
500 return 0;
502 #endif
504 #ifdef CONFIG_DVB_HEAD
506 struct diseqc_cmd {
507 struct dvb_diseqc_master_cmd cmd;
508 uint32_t wait;
511 static int diseqc_send_msg(int fd, fe_sec_voltage_t v, struct diseqc_cmd *cmd,
512 fe_sec_tone_mode_t t, fe_sec_mini_cmd_t b)
514 if(ioctl(fd, FE_SET_TONE, SEC_TONE_OFF) == -1)
515 return -1;
516 if(ioctl(fd, FE_SET_VOLTAGE, v) == -1)
517 return -1;
518 usleep(15 * 1000);
519 if(ioctl(fd, FE_DISEQC_SEND_MASTER_CMD, &cmd->cmd) == -1)
520 return -1;
521 usleep(cmd->wait * 1000);
522 usleep(15 * 1000);
523 if(ioctl(fd, FE_DISEQC_SEND_BURST, b) == -1)
524 return -1;
525 usleep(15 * 1000);
526 if(ioctl(fd, FE_SET_TONE, t) == -1)
527 return -1;
529 return 0;
532 /* digital satellite equipment control,
533 * specification is available from http://www.eutelsat.com/
535 static int do_diseqc(int secfd, int sat_no, int polv, int hi_lo)
537 struct diseqc_cmd cmd = { {{0xe0, 0x10, 0x38, 0xf0, 0x00, 0x00}, 4}, 0 };
539 /* param: high nibble: reset bits, low nibble set bits,
540 * bits are: option, position, polarizaion, band
542 cmd.cmd.msg[3] =
543 0xf0 | (((sat_no * 4) & 0x0f) | (hi_lo ? 1 : 0) | (polv ? 0 : 2));
545 return diseqc_send_msg(secfd, polv ? SEC_VOLTAGE_13 : SEC_VOLTAGE_18,
546 &cmd, hi_lo ? SEC_TONE_ON : SEC_TONE_OFF,
547 (sat_no / 4) % 2 ? SEC_MINI_B : SEC_MINI_A);
550 #else
552 static int do_diseqc(int secfd, int sat_no, int polv, int hi_lo)
554 struct secCommand scmd;
555 struct secCmdSequence scmds;
557 scmds.continuousTone = (hi_lo ? SEC_TONE_ON : SEC_TONE_OFF);
558 scmds.voltage = (polv ? SEC_VOLTAGE_13 : SEC_VOLTAGE_18);
559 scmds.miniCommand = SEC_MINI_NONE;
561 scmd.type = SEC_CMDTYPE_DISEQC;
562 scmds.numCommands = 1;
563 scmds.commands = &scmd;
565 scmd.u.diseqc.addr = 0x10;
566 scmd.u.diseqc.cmd = 0x38;
567 scmd.u.diseqc.numParams = 1;
568 scmd.u.diseqc.params[0] = 0xf0 |
569 (((sat_no) << 2) & 0x0F) |
570 (hi_lo ? 1 : 0) |
571 (polv ? 0 : 2);
573 if (ioctl(secfd,SEC_SEND_SEQUENCE,&scmds) < 0)
575 mp_msg(MSGT_DEMUX, MSGL_ERR, "Error sending DisEqC");
576 return -1;
579 return 0;
581 #endif
583 static int tune_it(int fd_frontend, int fd_sec, unsigned int freq, unsigned int srate, char pol, int tone,
584 fe_spectral_inversion_t specInv, unsigned int diseqc, fe_modulation_t modulation, fe_code_rate_t HP_CodeRate,
585 fe_transmit_mode_t TransmissionMode, fe_guard_interval_t guardInterval, fe_bandwidth_t bandwidth,
586 fe_code_rate_t LP_CodeRate, fe_hierarchy_t hier, int timeout)
588 int res, hi_lo, dfd;
589 #ifdef CONFIG_DVB_HEAD
590 struct dvb_frontend_parameters feparams;
591 struct dvb_frontend_info fe_info;
592 #else
593 FrontendParameters feparams;
594 FrontendInfo fe_info;
595 FrontendEvent event;
596 struct secStatus sec_state;
597 #endif
600 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",
601 fd_frontend, fd_sec, (long unsigned int)freq, (long unsigned int)srate, pol, tone, diseqc);
604 memset(&feparams, 0, sizeof(feparams));
605 if ( (res = ioctl(fd_frontend,FE_GET_INFO, &fe_info) < 0))
607 mp_msg(MSGT_DEMUX, MSGL_FATAL, "FE_GET_INFO FAILED\n");
608 return -1;
612 #ifdef CONFIG_DVB_HEAD
613 mp_msg(MSGT_DEMUX, MSGL_V, "Using DVB card \"%s\"\n", fe_info.name);
614 #endif
616 switch(fe_info.type)
618 case FE_OFDM:
619 #ifdef CONFIG_DVB_HEAD
620 if (freq < 1000000) freq*=1000UL;
621 feparams.frequency=freq;
622 feparams.inversion=specInv;
623 feparams.u.ofdm.bandwidth=bandwidth;
624 feparams.u.ofdm.code_rate_HP=HP_CodeRate;
625 feparams.u.ofdm.code_rate_LP=LP_CodeRate;
626 feparams.u.ofdm.constellation=modulation;
627 feparams.u.ofdm.transmission_mode=TransmissionMode;
628 feparams.u.ofdm.guard_interval=guardInterval;
629 feparams.u.ofdm.hierarchy_information=hier;
630 #else
631 if (freq < 1000000) freq*=1000UL;
632 feparams.Frequency=freq;
633 feparams.Inversion=specInv;
634 feparams.u.ofdm.bandWidth=bandwidth;
635 feparams.u.ofdm.HP_CodeRate=HP_CodeRate;
636 feparams.u.ofdm.LP_CodeRate=LP_CodeRate;
637 feparams.u.ofdm.Constellation=modulation;
638 feparams.u.ofdm.TransmissionMode=TransmissionMode;
639 feparams.u.ofdm.guardInterval=guardInterval;
640 feparams.u.ofdm.HierarchyInformation=hier;
641 #endif
642 mp_msg(MSGT_DEMUX, MSGL_V, "tuning DVB-T to %d Hz, bandwidth: %d\n",freq, bandwidth);
643 break;
644 case FE_QPSK:
645 if (freq > 2200000)
647 // this must be an absolute frequency
648 if (freq < SLOF)
650 #ifdef CONFIG_DVB_HEAD
651 freq = feparams.frequency=(freq-LOF1);
652 #else
653 freq = feparams.Frequency=(freq-LOF1);
654 #endif
655 hi_lo = 0;
657 else
659 #ifdef CONFIG_DVB_HEAD
660 freq = feparams.frequency=(freq-LOF2);
661 #else
662 freq = feparams.Frequency=(freq-LOF2);
663 #endif
664 hi_lo = 1;
667 else
669 // this is an L-Band frequency
670 #ifdef CONFIG_DVB_HEAD
671 feparams.frequency=freq;
672 #else
673 feparams.Frequency=freq;
674 #endif
677 #ifdef CONFIG_DVB_HEAD
678 feparams.inversion=specInv;
679 feparams.u.qpsk.symbol_rate=srate;
680 feparams.u.qpsk.fec_inner=HP_CodeRate;
681 dfd = fd_frontend;
682 #else
683 feparams.Inversion=specInv;
684 feparams.u.qpsk.SymbolRate=srate;
685 feparams.u.qpsk.FEC_inner=HP_CodeRate;
686 dfd = fd_sec;
687 #endif
689 mp_msg(MSGT_DEMUX, MSGL_V, "tuning DVB-S to Freq: %u, Pol: %c Srate: %d, 22kHz: %s, LNB: %d\n",freq,pol,srate,hi_lo ? "on" : "off", diseqc);
691 if(do_diseqc(dfd, diseqc, (pol == 'V' ? 1 : 0), hi_lo) == 0)
692 mp_msg(MSGT_DEMUX, MSGL_V, "DISEQC SETTING SUCCEDED\n");
693 else
695 mp_msg(MSGT_DEMUX, MSGL_ERR, "DISEQC SETTING FAILED\n");
696 return -1;
698 break;
699 case FE_QAM:
700 mp_msg(MSGT_DEMUX, MSGL_V, "tuning DVB-C to %d, srate=%d\n",freq,srate);
701 #ifdef CONFIG_DVB_HEAD
702 feparams.frequency=freq;
703 feparams.inversion=specInv;
704 feparams.u.qam.symbol_rate = srate;
705 feparams.u.qam.fec_inner = HP_CodeRate;
706 feparams.u.qam.modulation = modulation;
707 #else
708 feparams.Frequency=freq;
709 feparams.Inversion=specInv;
710 feparams.u.qam.SymbolRate = srate;
711 feparams.u.qam.FEC_inner = HP_CodeRate;
712 feparams.u.qam.QAM = modulation;
713 #endif
714 break;
715 #ifdef DVB_ATSC
716 case FE_ATSC:
717 mp_msg(MSGT_DEMUX, MSGL_V, "tuning ATSC to %d, modulation=%d\n",freq,modulation);
718 feparams.frequency=freq;
719 feparams.u.vsb.modulation = modulation;
720 break;
721 #endif
722 default:
723 mp_msg(MSGT_DEMUX, MSGL_V, "Unknown FE type. Aborting\n");
724 return 0;
726 usleep(100000);
728 #ifndef CONFIG_DVB_HEAD
729 if (fd_sec) SecGetStatus(fd_sec, &sec_state);
730 while(1)
732 if(ioctl(fd_frontend, FE_GET_EVENT, &event) == -1)
733 break;
735 #endif
737 if(ioctl(fd_frontend,FE_SET_FRONTEND,&feparams) < 0)
739 mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR tuning channel\n");
740 return -1;
743 return(check_status(fd_frontend, timeout));