1 /*****************************************************************************
2 * dvb.c : functions to control a DVB card under Linux with v4l2
3 *****************************************************************************
4 * Copyright (C) 1998-2003 VideoLAN
6 * Authors: Damien Lucas <nitrox@via.ecp.fr>
7 * Johan Bilien <jobi@via.ecp.fr>
8 * Jean-Paul Saman <jpsaman@wxs.nl>
9 * Christopher Ross <chris@tebibyte.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
27 #include <vlc/input.h>
29 #include <sys/ioctl.h>
36 #ifdef HAVE_INTTYPES_H
37 # include <inttypes.h> /* int16_t .. */
39 #include <sys/types.h>
44 #include <sys/types.h>
48 /* DVB Card Drivers */
49 #include <linux/dvb/version.h>
50 #include <linux/dvb/dmx.h>
51 #include <linux/dvb/frontend.h>
53 #include <linux/errno.h>
59 struct dvb_diseqc_master_cmd cmd;
63 struct diseqc_cmd_t switch_cmds[] =
65 { { { 0xe0, 0x10, 0x38, 0xf0, 0x00, 0x00 }, 4 }, 0 },
66 { { { 0xe0, 0x10, 0x38, 0xf2, 0x00, 0x00 }, 4 }, 0 },
67 { { { 0xe0, 0x10, 0x38, 0xf1, 0x00, 0x00 }, 4 }, 0 },
68 { { { 0xe0, 0x10, 0x38, 0xf3, 0x00, 0x00 }, 4 }, 0 },
69 { { { 0xe0, 0x10, 0x38, 0xf4, 0x00, 0x00 }, 4 }, 0 },
70 { { { 0xe0, 0x10, 0x38, 0xf6, 0x00, 0x00 }, 4 }, 0 },
71 { { { 0xe0, 0x10, 0x38, 0xf5, 0x00, 0x00 }, 4 }, 0 },
72 { { { 0xe0, 0x10, 0x38, 0xf7, 0x00, 0x00 }, 4 }, 0 },
73 { { { 0xe0, 0x10, 0x38, 0xf8, 0x00, 0x00 }, 4 }, 0 },
74 { { { 0xe0, 0x10, 0x38, 0xfa, 0x00, 0x00 }, 4 }, 0 },
75 { { { 0xe0, 0x10, 0x38, 0xf9, 0x00, 0x00 }, 4 }, 0 },
76 { { { 0xe0, 0x10, 0x38, 0xfb, 0x00, 0x00 }, 4 }, 0 },
77 { { { 0xe0, 0x10, 0x38, 0xfc, 0x00, 0x00 }, 4 }, 0 },
78 { { { 0xe0, 0x10, 0x38, 0xfe, 0x00, 0x00 }, 4 }, 0 },
79 { { { 0xe0, 0x10, 0x38, 0xfd, 0x00, 0x00 }, 4 }, 0 },
80 { { { 0xe0, 0x10, 0x38, 0xff, 0x00, 0x00 }, 4 }, 0 }
83 static int ioctl_CheckFrontend(input_thread_t * p_input, int front);
85 /*****************************************************************************
86 * ioctl_InfoFrontend : return information about given frontend
87 *****************************************************************************/
88 int ioctl_InfoFrontend(input_thread_t * p_input, struct dvb_frontend_info *info,
89 unsigned int u_adapter, unsigned int u_device)
93 char frontend[] = FRONTEND;
96 i_len = sizeof(FRONTEND);
97 if (snprintf(frontend, sizeof(FRONTEND), FRONTEND, u_adapter, u_device) >= i_len)
99 msg_Err(p_input, "snprintf() truncated string for FRONTEND" );
100 frontend[sizeof(FRONTEND)] = '\0';
103 msg_Dbg(p_input, "Opening device %s", frontend);
104 if((front = open(frontend,O_RDWR)) < 0)
107 msg_Err(p_input, "ioctl_InfoFrontEnd: opening device failed (%s)", strerror(errno));
109 msg_Err(p_input, "ioctl_InfoFrontEnd: opening device failed");
114 /* Determine type of frontend */
115 if ((ret=ioctl(front, FE_GET_INFO, info)) < 0)
119 msg_Err(p_input, "ioctl FE_GET_INFO failed (%d) %s", ret, strerror(errno));
121 msg_Err(p_input, "ioctl FE_GET_INFO failed (%d)", ret);
125 /* Print out frontend capabilities. */
127 msg_Dbg(p_input, "Frontend Info:" );
128 msg_Dbg(p_input, " name = %s", info->name);
132 msg_Dbg(p_input, " type = QPSK (DVB-S)" );
135 msg_Dbg(p_input, " type = QAM (DVB-C)" );
138 msg_Dbg(p_input, " type = OFDM (DVB-T)" );
140 #if 0 /* DVB_API_VERSION == 3 */
142 msg_Dbg(p_input, " type = MEMORY" );
145 msg_Dbg(p_input, " type = NETWORK" );
149 msg_Err(p_input, " unknown frontend found fe_type_t(%d)", info->type );
152 msg_Dbg(p_input, " frequency_min = %u (kHz)", info->frequency_min);
153 msg_Dbg(p_input, " frequency_max = %u (kHz)", info->frequency_max);
154 msg_Dbg(p_input, " frequency_stepsize = %u", info->frequency_stepsize);
155 msg_Dbg(p_input, " frequency_tolerance = %u", info->frequency_tolerance);
156 msg_Dbg(p_input, " symbol_rate_min = %u (kHz)", info->symbol_rate_min);
157 msg_Dbg(p_input, " symbol_rate_max = %u (kHz)", info->symbol_rate_max);
158 msg_Dbg(p_input, " symbol_rate_tolerance (ppm) = %u", info->symbol_rate_tolerance);
159 msg_Dbg(p_input, " notifier_delay (ms)= %u", info->notifier_delay );
161 msg_Dbg(p_input, "Frontend Info capability list:");
162 if (info->caps&FE_IS_STUPID)
163 msg_Dbg(p_input, " no capabilities - frontend is stupid!");
164 if (info->caps&FE_CAN_INVERSION_AUTO)
165 msg_Dbg(p_input, " inversion auto");
166 if (info->caps&FE_CAN_FEC_1_2)
167 msg_Dbg(p_input, " forward error correction 1/2");
168 if (info->caps&FE_CAN_FEC_2_3)
169 msg_Dbg(p_input, " forward error correction 2/3");
170 if (info->caps&FE_CAN_FEC_3_4)
171 msg_Dbg(p_input, " forward error correction 3/4");
172 if (info->caps&FE_CAN_FEC_4_5)
173 msg_Dbg(p_input, " forward error correction 4/5");
174 if (info->caps&FE_CAN_FEC_5_6)
175 msg_Dbg(p_input, " forward error correction 5/6");
176 if (info->caps&FE_CAN_FEC_6_7)
177 msg_Dbg(p_input, " forward error correction 6/7");
178 if (info->caps&FE_CAN_FEC_7_8)
179 msg_Dbg(p_input, " forward error correction 7/8");
180 if (info->caps&FE_CAN_FEC_8_9)
181 msg_Dbg(p_input, " forward error correction 8/9");
182 if (info->caps&FE_CAN_FEC_AUTO)
183 msg_Dbg(p_input, " forward error correction auto");
184 if (info->caps&FE_CAN_QPSK)
185 msg_Dbg(p_input, " card can do QPSK");
186 if (info->caps&FE_CAN_QAM_16)
187 msg_Dbg(p_input, " card can do QAM 16");
188 if (info->caps&FE_CAN_QAM_32)
189 msg_Dbg(p_input, " card can do QAM 32");
190 if (info->caps&FE_CAN_QAM_64)
191 msg_Dbg(p_input, " card can do QAM 64");
192 if (info->caps&FE_CAN_QAM_128)
193 msg_Dbg(p_input, " card can do QAM 128");
194 if (info->caps&FE_CAN_QAM_256)
195 msg_Dbg(p_input, " card can do QAM 256");
196 if (info->caps&FE_CAN_QAM_AUTO)
197 msg_Dbg(p_input, " card can do QAM auto");
198 if (info->caps&FE_CAN_TRANSMISSION_MODE_AUTO)
199 msg_Dbg(p_input, " transmission mode auto");
200 if (info->caps&FE_CAN_BANDWIDTH_AUTO)
201 msg_Dbg(p_input, " bandwidth mode auto");
202 if (info->caps&FE_CAN_GUARD_INTERVAL_AUTO)
203 msg_Dbg(p_input, " guard interval mode auto");
204 if (info->caps&FE_CAN_HIERARCHY_AUTO)
205 msg_Dbg(p_input, " hierarchy mode auto");
206 if (info->caps&FE_CAN_MUTE_TS)
207 msg_Dbg(p_input, " card can mute TS");
208 if (info->caps&FE_CAN_CLEAN_SETUP)
209 msg_Dbg(p_input, " clean setup");
210 msg_Dbg(p_input,"End of capability list");
217 int ioctl_DiseqcSendMsg (input_thread_t *p_input, int fd, fe_sec_voltage_t v, struct diseqc_cmd_t **cmd,
218 fe_sec_tone_mode_t t, fe_sec_mini_cmd_t b)
222 if ((err = ioctl(fd, FE_SET_TONE, SEC_TONE_OFF))<0)
225 msg_Err(p_input, "ioclt FE_SET_TONE failed, tone=%s (%d) %s", SEC_TONE_ON ? "on" : "off", err, strerror(errno));
227 msg_Err(p_input, "ioclt FE_SET_TONE failed, tone=%s (%d)", SEC_TONE_ON ? "on" : "off", err);
231 if ((err = ioctl(fd, FE_SET_VOLTAGE, v))<0)
234 msg_Err(p_input, "ioclt FE_SET_VOLTAGE failed, voltage=%d (%d) %s", v, err, strerror(errno));
236 msg_Err(p_input, "ioclt FE_SET_VOLTAGE failed, voltage=%d (%d)", v, err);
244 msg_Dbg(p_input, "DiseqcSendMsg(): %02x %02x %02x %02x %02x %02x",
245 (*cmd)->cmd.msg[0], (*cmd)->cmd.msg[1],
246 (*cmd)->cmd.msg[2], (*cmd)->cmd.msg[3],
247 (*cmd)->cmd.msg[4], (*cmd)->cmd.msg[5]);
249 if ((err = ioctl(fd, FE_DISEQC_SEND_MASTER_CMD, &(*cmd)->cmd))<0)
252 msg_Err(p_input, "ioclt FE_DISEQC_SEND_MASTER_CMD failed (%d) %s", err, strerror(errno));
254 msg_Err(p_input, "ioclt FE_DISEQC_SEND_MASTER_CMD failed (%d)", err);
259 msleep((*cmd)->wait);
265 if ((err = ioctl(fd, FE_DISEQC_SEND_BURST, b))<0)
268 msg_Err(p_input, "ioctl FE_DISEQC_SEND_BURST failed, burst=%d (%d) %s",b, err, strerror(errno));
270 msg_Err(p_input, "ioctl FE_DISEQC_SEND_BURST failed, burst=%d (%d)",b, err);
276 if ((err = ioctl(fd, FE_SET_TONE, t))<0)
279 msg_Err(p_input, "ioctl FE_SET_TONE failed, tone=%d (%d) %s", t, err, strerror(errno));
281 msg_Err(p_input, "ioctl FE_SET_TONE failed, tone=%d (%d)", t, err);
289 int ioctl_SetupSwitch (input_thread_t *p_input, int frontend_fd, int switch_pos,
290 int voltage_18, int hiband)
293 struct diseqc_cmd_t *cmd[2] = { NULL, NULL };
294 int i = 4 * switch_pos + 2 * hiband + (voltage_18 ? 1 : 0);
296 msg_Dbg(p_input, "ioctl_SetupSwitch: switch pos %i, %sV, %sband",
297 switch_pos, voltage_18 ? "18" : "13", hiband ? "hi" : "lo");
298 msg_Dbg(p_input, "ioctl_SetupSwitch: index %i", i);
300 if ((i < 0) || (i >= (int)(sizeof(switch_cmds)/sizeof(struct diseqc_cmd_t))))
303 cmd[0] = &switch_cmds[i];
305 if ((ret = ioctl_DiseqcSendMsg (p_input, frontend_fd,
306 (i % 2) ? SEC_VOLTAGE_18 : SEC_VOLTAGE_13,
308 (i/2) % 2 ? SEC_TONE_ON : SEC_TONE_OFF,
309 (i/4) % 2 ? SEC_MINI_B : SEC_MINI_A))<0)
311 msg_Err(p_input, "ioctl_DiseqcSendMsg() failed (%d)", ret);
318 /*****************************************************************************
319 * ioctl_SetQPSKFrontend : controls the FE device
320 *****************************************************************************/
321 int ioctl_SetQPSKFrontend (input_thread_t * p_input, struct dvb_frontend_parameters fep, int b_polarisation,
322 unsigned int u_lnb_lof1, unsigned int u_lnb_lof2, unsigned int u_lnb_slof,
323 unsigned int u_adapter, unsigned int u_device )
328 char frontend[] = FRONTEND;
331 i_len = sizeof(FRONTEND);
332 if (snprintf(frontend, sizeof(FRONTEND), FRONTEND, u_adapter, u_device) >= i_len)
334 msg_Err(p_input, "DVB-S: FrontEnd snprintf() truncated string for FRONTEND" );
335 frontend[sizeof(FRONTEND)] = '\0';
338 /* Open the frontend device */
339 msg_Dbg(p_input, "DVB-S: Opening frontend %s", frontend);
340 if(( front = open(frontend,O_RDWR)) < 0)
343 msg_Err(p_input, "DVB-S: failed to open frontend (%s)", strerror(errno));
345 msg_Err(p_input, "DVB-S: failed to open frontend");
350 /* Set the frequency of the transponder, taking into account the
351 local frequencies of the LNB */
352 hiband = (fep.frequency >= u_lnb_slof);
354 if ((ret=ioctl_SetupSwitch (p_input, front, 0, b_polarisation, hiband))<0)
356 msg_Err(p_input, "DVB-S: Setup frontend switch failed (%d)", ret);
361 fep.frequency -= u_lnb_lof2;
363 fep.frequency -= u_lnb_lof1;
365 /* Now send it all to the frontend device */
366 if ((ret=ioctl(front, FE_SET_FRONTEND, &fep)) < 0)
370 msg_Err(p_input, "DVB-S: setting frontend failed (%d) %s", ret, strerror(errno));
372 msg_Err(p_input, "DVB-S: setting frontend failed (%d)", ret);
377 ret = ioctl_CheckFrontend(p_input, front);
379 /* Fixme: Return this instead of closing it.
380 Close front end device */
385 int ioctl_SetOFDMFrontend (input_thread_t * p_input, struct dvb_frontend_parameters fep,
386 unsigned int u_adapter, unsigned int u_device )
390 char frontend[] = FRONTEND;
393 i_len = sizeof(FRONTEND);
394 if (snprintf(frontend, sizeof(FRONTEND), FRONTEND, u_adapter, u_device) >= i_len)
396 msg_Err(p_input, "DVB-T FrontEnd snprintf() truncated string for FRONTEND" );
397 frontend[sizeof(FRONTEND)] = '\0';
400 /* Open the frontend device */
401 msg_Dbg(p_input, "DVB-T: Opening frontend %s", frontend);
402 if(( front = open(frontend,O_RDWR)) < 0)
405 msg_Err(p_input, "DVB-T: failed to open frontend (%s)", strerror(errno));
407 msg_Err(p_input, "DVB-T: failed to open frontend");
412 /* Now send it all to the frontend device */
413 if ((ret=ioctl(front, FE_SET_FRONTEND, &fep)) < 0)
417 msg_Err(p_input, "DVB-T: setting frontend failed (%d) %s", ret, strerror(errno));
419 msg_Err(p_input, "DVB-T: setting frontend failed (%d)", ret);
424 ret = ioctl_CheckFrontend(p_input, front);
426 /* Fixme: Return this instead of closing it.
427 Close front end device */
432 int ioctl_SetQAMFrontend (input_thread_t * p_input, struct dvb_frontend_parameters fep,
433 unsigned int u_adapter, unsigned int u_device )
437 char frontend[] = FRONTEND;
440 i_len = sizeof(FRONTEND);
441 if (snprintf(frontend, sizeof(FRONTEND), FRONTEND, u_adapter, u_device) >= i_len)
443 msg_Err(p_input, "DVB-C: FrontEnd snprintf() truncated string for FRONTEND" );
444 frontend[sizeof(FRONTEND)] = '\0';
447 /* Open the frontend device */
448 msg_Dbg(p_input, "DVB-C: Opening frontend %s", frontend);
449 if(( front = open(frontend,O_RDWR)) < 0)
452 msg_Err(p_input, "DVB-C: failed to open frontend (%s)", strerror(errno));
454 msg_Err(p_input, "DVB-C: failed to open frontend");
459 /* Show more info on the tuning parameters used. */
460 msg_Dbg(p_input, "DVB-C: Tuning with the following paramters:");
461 msg_Dbg(p_input, "DVB-C: Frequency %d KHz", fep.frequency );
462 msg_Dbg(p_input, "DVB-C: Inversion/polarisation: %d",fep.inversion);
463 msg_Dbg(p_input, "DVB-C: Symbolrate %d", fep.u.qam.symbol_rate);
464 msg_Dbg(p_input, "DVB-C: FEC Inner %d", fep.u.qam.fec_inner);
465 msg_Dbg(p_input, "DVB-C: Modulation %d", fep.u.qam.modulation);
467 /* Now send it all to the frontend device */
468 if ((ret=ioctl(front, FE_SET_FRONTEND, &fep)) < 0)
472 msg_Err(p_input, "DVB-C: tuning channel failed (frontend returned %d:%s)", ret, strerror(errno));
474 msg_Err(p_input, "DVB-C: tuning channel failed (frontend returned %d)", ret);
479 /* Check Status of frontend */
480 ret = ioctl_CheckFrontend(p_input, front);
482 /* Fixme: Return this instead of closing it.
483 Close front end device */
488 /******************************************************************
489 * Check completion of the frontend control sequence
490 ******************************************************************/
491 static int ioctl_CheckFrontend(input_thread_t * p_input, int front)
495 struct pollfd pfd[1];
496 struct dvb_frontend_event event;
497 /* poll for frontend event to check if tuning worked */
499 pfd[0].events = POLLIN;
505 if ((ret=ioctl(front, FE_READ_STATUS, &status))<0)
508 msg_Err(p_input, "reading frontend status failed (%d) %s", ret, strerror(errno));
510 msg_Err(p_input, "reading frontend status failed (%d)", ret);
514 if (status & FE_HAS_SIGNAL) /* found something above the noise level */
515 msg_Dbg(p_input, "check frontend ... has signal");
517 if (status & FE_HAS_CARRIER) /* found a DVB signal */
518 msg_Dbg(p_input, "check frontend ... has carrier");
520 if (status & FE_HAS_VITERBI) /* FEC is stable */
521 msg_Dbg(p_input, "check frontend ... has stable fec");
523 if (status & FE_HAS_SYNC) /* found sync bytes */
524 msg_Dbg(p_input, "check frontend ... has sync");
526 if (status & FE_HAS_LOCK) /* everything's working... */
528 msg_Dbg(p_input, "check frontend ... has lock");
529 msg_Dbg(p_input, "check frontend ... tuning status == 0x%02x!!! ..."
530 "tuning succeeded", status);
534 if (status & FE_TIMEDOUT) /* no lock within the last ~2 seconds */
536 msg_Dbg(p_input, "check frontend ... tuning status == 0x%02x!!! ..."
537 "tuning failed", status);
538 msg_Err(p_input, "check frontend ... timed out");
542 if (status & FE_REINIT)
544 /* frontend was reinitialized, */
545 /* application is recommned to reset */
546 /* DiSEqC, tone and parameters */
547 msg_Dbg(p_input, "DVB-S: tuning status == 0x%02x!!! ..."
548 "tuning failed", status);
549 msg_Err(p_input, "check frontend ... resend frontend parameters");
556 if (poll(pfd,1,3000))
558 if (pfd[0].revents & POLLIN)
560 if ( (ret=ioctl(front, FE_GET_EVENT, &event)) < 0)
563 msg_Err(p_input, "check frontend ... error occured (%d) %s", ret, strerror(errno));
565 msg_Err(p_input, "check frontend ... error occured (%d)", ret);
572 case FE_HAS_SIGNAL: /* found something above the noise level */
573 msg_Dbg(p_input, "check frontend ... has signal");
575 case FE_HAS_CARRIER: /* found a DVB signal */
576 msg_Dbg(p_input, "check frontend ... has carrier");
578 case FE_HAS_VITERBI: /* FEC is stable */
579 msg_Dbg(p_input, "check frontend ... has stable fec");
581 case FE_HAS_SYNC: /* found sync bytes */
582 msg_Dbg(p_input, "check frontend ... has sync");
584 case FE_HAS_LOCK: /* everything's working... */
585 msg_Dbg(p_input, "check frontend ... has lock");
587 case FE_TIMEDOUT: /* no lock within the last ~2 seconds */
588 msg_Err(p_input, "check frontend ... timed out");
590 case FE_REINIT: /* frontend was reinitialized, */
591 /* application is recommned to reset */
592 /* DiSEqC, tone and parameters */
593 msg_Err(p_input, "check frontend ... resend frontend parameters");
599 /* should come here */
600 msg_Err(p_input, "check frontend ... no event occured");
607 msg_Err(p_input, "check frontend ... timeout when polling for event (%s)", strerror(errno));
609 msg_Err(p_input, "check frontend ... timeout when polling for event ");
618 /*****************************************************************************
619 * ioctl_SetDMXFilter : controls the demux to add a filter
620 *****************************************************************************/
621 int ioctl_SetDMXFilter(input_thread_t * p_input, int i_pid, int * pi_fd , int i_type,
622 unsigned int u_adapter, unsigned int u_device )
624 struct dmx_pes_filter_params s_filter_params;
629 /* We first open the device */
631 if (snprintf( dmx, sizeof(DMX), DMX, u_adapter, u_device) >= i_len)
633 msg_Err(p_input, "snprintf() truncated string for DMX" );
634 dmx[sizeof(DMX)] = '\0';
637 msg_Dbg(p_input, "Opening demux device %s", dmx);
638 if (( (*pi_fd) = open(dmx, O_RDWR|O_NONBLOCK)) < 0)
641 msg_Err(p_input, "ioctl_SetDMXFilter: opening device failed (%s)", strerror(errno));
643 msg_Err(p_input, "ioctl_SetDMXFilter: opening device failed");
648 /* We fill the DEMUX structure : */
649 s_filter_params.pid = i_pid;
650 s_filter_params.input = DMX_IN_FRONTEND;
651 s_filter_params.output = DMX_OUT_TS_TAP;
655 msg_Dbg(p_input, "ioctl_SetDMXFilter: DMX_PES_VIDEO0 for PMT %d", i_pid);
656 s_filter_params.pes_type = DMX_PES_VIDEO0;
659 msg_Dbg(p_input, "ioctl_SetDMXFilter: DMX_PES_AUDIO0 for PMT %d", i_pid);
660 s_filter_params.pes_type = DMX_PES_AUDIO0;
663 msg_Dbg(p_input, "ioctl_SetDMXFilter: DMX_PES_TELETEXT0 for PMT %d", i_pid);
664 s_filter_params.pes_type = DMX_PES_TELETEXT0;
667 msg_Dbg(p_input, "ioctl_SetDMXFilter: DMX_PES_SUBTITLE0 for PMT %d", i_pid);
668 s_filter_params.pes_type = DMX_PES_SUBTITLE0;
671 msg_Dbg(p_input, "ioctl_SetDMXFilter: DMX_PES_PCR0 for PMT %d", i_pid);
672 s_filter_params.pes_type = DMX_PES_PCR0;
676 msg_Dbg(p_input, "ioctl_SetDMXFilter: DMX_PES_VIDEO1 for PMT %d", i_pid);
677 s_filter_params.pes_type = DMX_PES_VIDEO1;
680 msg_Dbg(p_input, "ioctl_SetDMXFilter: DMX_PES_AUDIO1 for PMT %d", i_pid);
681 s_filter_params.pes_type = DMX_PES_AUDIO1;
684 msg_Dbg(p_input, "ioctl_SetDMXFilter: DMX_PES_TELETEXT1 for PMT %d", i_pid);
685 s_filter_params.pes_type = DMX_PES_TELETEXT1;
688 msg_Dbg(p_input, "ioctl_SetDMXFilter: DMX_PES_SUBTITLE1 for PMT %d", i_pid);
689 s_filter_params.pes_type = DMX_PES_SUBTITLE1;
692 msg_Dbg(p_input, "ioctl_SetDMXFilter: DMX_PES_PCR1 for PMT %d", i_pid);
693 s_filter_params.pes_type = DMX_PES_PCR1;
697 msg_Dbg(p_input, "ioctl_SetDMXFilter: DMX_PES_VIDEO2 for PMT %d", i_pid);
698 s_filter_params.pes_type = DMX_PES_VIDEO2;
701 msg_Dbg(p_input, "ioctl_SetDMXFilter: DMX_PES_AUDIO2 for PMT %d", i_pid);
702 s_filter_params.pes_type = DMX_PES_AUDIO2;
705 msg_Dbg(p_input, "ioctl_SetDMXFilter: DMX_PES_TELETEXT2 for PMT %d", i_pid);
706 s_filter_params.pes_type = DMX_PES_TELETEXT2;
709 msg_Dbg(p_input, "ioctl_SetDMXFilter: DMX_PES_SUBTITLE2 for PMT %d", i_pid);
710 s_filter_params.pes_type = DMX_PES_SUBTITLE2;
713 msg_Dbg(p_input, "ioctl_SetDMXFilter: DMX_PES_PCR2 for PMT %d", i_pid);
714 s_filter_params.pes_type = DMX_PES_PCR2;
718 msg_Dbg(p_input, "ioctl_SetDMXFilter: DMX_PES_VIDEO3 for PMT %d", i_pid);
719 s_filter_params.pes_type = DMX_PES_VIDEO3;
722 msg_Dbg(p_input, "ioctl_SetDMXFilter: DMX_PES_AUDIO3 for PMT %d", i_pid);
723 s_filter_params.pes_type = DMX_PES_AUDIO3;
726 msg_Dbg(p_input, "ioctl_SetDMXFilter: DMX_PES_TELETEXT3 for PMT %d", i_pid);
727 s_filter_params.pes_type = DMX_PES_TELETEXT3;
730 msg_Dbg(p_input, "ioctl_SetDMXFilter: DMX_PES_SUBTITLE3 for PMT %d", i_pid);
731 s_filter_params.pes_type = DMX_PES_SUBTITLE3;
734 msg_Dbg(p_input, "ioctl_SetDMXFilter: DMX_PES_PCR3 for PMT %d", i_pid);
735 s_filter_params.pes_type = DMX_PES_PCR3;
737 /* Usually used by Nova cards */
739 msg_Dbg(p_input, "ioctl_SetDMXFilter: DMX_PES_OTHER for PMT %d", i_pid);
740 s_filter_params.pes_type = DMX_PES_OTHER;
742 /* What to do with i? */
744 msg_Err(p_input, "trying to set PMT id to=%d for unknown type %d", i_pid, i_type );
747 s_filter_params.flags = DMX_IMMEDIATE_START;
749 /* We then give the order to the device : */
750 if ((result = ioctl(*pi_fd, DMX_SET_PES_FILTER, &s_filter_params)) < 0)
753 msg_Err(p_input, "ioctl_SetDMXFilter: ioctl failed with %d (%s)",result, strerror(errno));
755 msg_Err(p_input, "ioctl_SetDMXFilter: ioctl failed with %d",result);
762 /*****************************************************************************
763 * ioctl_UnsetDMXFilter : removes a filter
764 *****************************************************************************/
765 int ioctl_UnsetDMXFilter(input_thread_t * p_input, int pi_fd)
769 if ((ret=ioctl( pi_fd, DMX_STOP))<0)
772 msg_Err(p_input, "ioctl DMX_STOP failed for demux %d (%d) %s", pi_fd, ret, strerror(errno));
774 msg_Err(p_input, "ioctl DMX_STOP failed for demux %d (%d)", pi_fd, ret);
778 msg_Dbg( p_input, "ioctl_UnsetDMXFilter closing demux %d", pi_fd);
783 /*****************************************************************************
784 * dvb_DecodeBandwidth : decodes arguments for DVB S/C/T card
785 *****************************************************************************/
786 fe_bandwidth_t dvb_DecodeBandwidth(input_thread_t * p_input, int bandwidth)
788 fe_bandwidth_t fe_bandwidth = 0;
793 fe_bandwidth = BANDWIDTH_AUTO;
796 fe_bandwidth = BANDWIDTH_6_MHZ;
799 fe_bandwidth = BANDWIDTH_7_MHZ;
802 fe_bandwidth = BANDWIDTH_8_MHZ;
805 msg_Dbg( p_input, "terrestrial dvb has bandwidth not set, using auto");
806 fe_bandwidth = BANDWIDTH_AUTO;
813 fe_code_rate_t dvb_DecodeFEC(input_thread_t * p_input, int fec)
815 fe_code_rate_t fe_fec = FEC_NONE;
849 msg_Err( p_input, "argument has invalid FEC (%d)", fec);
855 fe_modulation_t dvb_DecodeModulation(input_thread_t * p_input, int modulation)
857 fe_modulation_t fe_modulation = 0;
862 fe_modulation = QPSK;
865 fe_modulation = QAM_AUTO;
868 fe_modulation = QAM_16;
871 fe_modulation = QAM_32;
874 fe_modulation = QAM_64;
877 fe_modulation = QAM_128;
880 fe_modulation = QAM_256;
883 msg_Dbg( p_input, "terrestrial/cable dvb has constellation/modulation not set, using auto");
884 fe_modulation = QAM_AUTO;
887 return fe_modulation;
890 fe_transmit_mode_t dvb_DecodeTransmission(input_thread_t * p_input, int transmission)
892 fe_transmit_mode_t fe_transmission = 0;
894 switch( transmission )
897 fe_transmission = TRANSMISSION_MODE_AUTO;
900 fe_transmission = TRANSMISSION_MODE_2K;
903 fe_transmission = TRANSMISSION_MODE_8K;
906 msg_Dbg( p_input, "terrestrial dvb has transmission mode not set, using auto");
907 fe_transmission = TRANSMISSION_MODE_AUTO;
910 return fe_transmission;
913 fe_guard_interval_t dvb_DecodeGuardInterval(input_thread_t * p_input, int guard)
915 fe_guard_interval_t fe_guard = 0;
920 fe_guard = GUARD_INTERVAL_AUTO;
923 fe_guard = GUARD_INTERVAL_1_4;
926 fe_guard = GUARD_INTERVAL_1_8;
929 fe_guard = GUARD_INTERVAL_1_16;
932 fe_guard = GUARD_INTERVAL_1_32;
935 msg_Dbg( p_input, "terrestrial dvb has guard interval not set, using auto");
936 fe_guard = GUARD_INTERVAL_AUTO;
942 fe_hierarchy_t dvb_DecodeHierarchy(input_thread_t * p_input, int hierarchy)
944 fe_hierarchy_t fe_hierarchy = 0;
949 fe_hierarchy = HIERARCHY_NONE;
952 fe_hierarchy = HIERARCHY_AUTO;
955 fe_hierarchy = HIERARCHY_1;
958 fe_hierarchy = HIERARCHY_2;
961 fe_hierarchy = HIERARCHY_4;
964 msg_Dbg( p_input, "terrestrial dvb has hierarchy not set, using auto");
965 fe_hierarchy = HIERARCHY_AUTO;
971 fe_spectral_inversion_t dvb_DecodeInversion(input_thread_t * p_input, int inversion)
973 fe_spectral_inversion_t fe_inversion=0;
978 fe_inversion = INVERSION_OFF;
981 fe_inversion = INVERSION_ON;
984 fe_inversion = INVERSION_AUTO;
987 msg_Dbg( p_input, "dvb has inversion/polarisation not set, using auto");
988 fe_inversion = INVERSION_AUTO;