1 /*****************************************************************************
2 * dvb.c : functions to control a DVB card under Linux with v4l2
3 *****************************************************************************
4 * Copyright (C) 1998-2004 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>
10 * Christophe Massiot <massiot@via.ecp.fr>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
25 *****************************************************************************/
28 #include <vlc/input.h>
30 #include <sys/ioctl.h>
33 #include <sys/types.h>
41 /* DVB Card Drivers */
42 #include <linux/dvb/version.h>
43 #include <linux/dvb/dmx.h>
44 #include <linux/dvb/frontend.h>
46 #include <linux/errno.h>
56 struct dvb_frontend_info info;
59 /* Local prototypes */
60 static int FrontendInfo( access_t * );
61 static int FrontendSetQPSK( access_t * );
62 static int FrontendSetQAM( access_t * );
63 static int FrontendSetOFDM( access_t * );
64 static int FrontendCheck( access_t * );
66 /*****************************************************************************
67 * FrontendOpen : Determine frontend device information and capabilities
68 *****************************************************************************/
69 int E_(FrontendOpen)( access_t *p_access )
71 access_sys_t *p_sys = p_access->p_sys;
72 frontend_t * p_frontend;
73 unsigned int i_adapter, i_device;
77 i_adapter = var_GetInteger( p_access, "dvb-adapter" );
78 i_device = var_GetInteger( p_access, "dvb-device" );
79 b_probe = var_GetBool( p_access, "dvb-probe" );
81 if( snprintf( frontend, sizeof(frontend), FRONTEND, i_adapter, i_device ) >= (int)sizeof(frontend) )
83 msg_Err( p_access, "snprintf() truncated string for FRONTEND" );
84 frontend[sizeof(frontend) - 1] = '\0';
87 p_sys->p_frontend = p_frontend = malloc( sizeof(frontend_t) );
89 msg_Dbg( p_access, "Opening device %s", frontend );
90 if( (p_frontend->i_handle = open(frontend, O_RDWR | O_NONBLOCK)) < 0 )
92 msg_Err( p_access, "FrontEndOpen: opening device failed (%s)",
100 char * psz_expected = NULL;
103 if( FrontendInfo( p_access ) < 0 )
105 close( p_frontend->i_handle );
110 switch( p_frontend->info.type )
122 psz_real = "unknown";
126 if( (!strncmp( p_access->psz_access, "qpsk", 4 ) ||
127 !strncmp( p_access->psz_access, "dvb-s", 5 ) ||
128 !strncmp( p_access->psz_access, "satellite", 9 ) ) &&
129 (p_frontend->info.type != FE_QPSK) )
131 psz_expected = "DVB-S";
133 if( (!strncmp( p_access->psz_access, "cable", 5 ) ||
134 !strncmp( p_access->psz_access, "dvb-c", 5 ) ) &&
135 (p_frontend->info.type != FE_QAM) )
137 psz_expected = "DVB-C";
139 if( (!strncmp( p_access->psz_access, "terrestrial", 11 ) ||
140 !strncmp( p_access->psz_access, "dvb-t", 5 ) ) &&
141 (p_frontend->info.type != FE_OFDM) )
143 psz_expected = "DVB-T";
146 if( psz_expected != NULL )
148 msg_Err( p_access, "the user asked for %s, and the tuner is %s",
149 psz_expected, psz_real );
150 close( p_frontend->i_handle );
155 else /* no frontend probing is done so use default border values. */
157 msg_Dbg( p_access, "using default values for frontend info" );
159 msg_Dbg( p_access, "method of access is %s", p_access->psz_access );
160 p_frontend->info.type = FE_QPSK;
161 if( !strncmp( p_access->psz_access, "qpsk", 4 ) ||
162 !strncmp( p_access->psz_access, "dvb-s", 5 ) )
163 p_frontend->info.type = FE_QPSK;
164 else if( !strncmp( p_access->psz_access, "cable", 5 ) ||
165 !strncmp( p_access->psz_access, "dvb-c", 5 ) )
166 p_frontend->info.type = FE_QAM;
167 else if( !strncmp( p_access->psz_access, "terrestrial", 11 ) ||
168 !strncmp( p_access->psz_access, "dvb-t", 5 ) )
169 p_frontend->info.type = FE_OFDM;
175 /*****************************************************************************
176 * FrontendClose : Close the frontend
177 *****************************************************************************/
178 void E_(FrontendClose)( access_t *p_access )
180 access_sys_t *p_sys = p_access->p_sys;
182 if( p_sys->p_frontend )
184 close( p_sys->p_frontend->i_handle );
185 free( p_sys->p_frontend );
187 p_sys->p_frontend = NULL;
191 /*****************************************************************************
192 * FrontendSet : Tune !
193 *****************************************************************************/
194 int E_(FrontendSet)( access_t *p_access )
196 access_sys_t *p_sys = p_access->p_sys;
198 switch( p_sys->p_frontend->info.type )
200 /* DVB-S: satellite and budget cards (nova) */
202 if( FrontendSetQPSK( p_access ) < 0 )
204 msg_Err( p_access, "DVB-S: tuning failed" );
211 if( FrontendSetQAM( p_access ) < 0 )
213 msg_Err( p_access, "DVB-C: tuning failed" );
220 if( FrontendSetOFDM( p_access ) < 0 )
222 msg_Err( p_access, "DVB-T: tuning failed" );
228 msg_Err( p_access, "Could not determine frontend type on %s",
229 p_sys->p_frontend->info.name );
235 /*****************************************************************************
236 * FrontendInfo : Return information about given frontend
237 *****************************************************************************/
238 static int FrontendInfo( access_t *p_access )
240 access_sys_t *p_sys = p_access->p_sys;
241 frontend_t *p_frontend = p_sys->p_frontend;
244 /* Determine type of frontend */
245 if( (i_ret = ioctl( p_frontend->i_handle, FE_GET_INFO,
246 &p_frontend->info )) < 0 )
248 msg_Err( p_access, "ioctl FE_GET_INFO failed (%d) %s", i_ret,
253 /* Print out frontend capabilities. */
254 msg_Dbg(p_access, "Frontend Info:" );
255 msg_Dbg(p_access, " name = %s", p_frontend->info.name );
256 switch( p_frontend->info.type )
259 msg_Dbg( p_access, " type = QPSK (DVB-S)" );
262 msg_Dbg( p_access, " type = QAM (DVB-C)" );
265 msg_Dbg( p_access, " type = OFDM (DVB-T)" );
267 #if 0 /* DVB_API_VERSION == 3 */
269 msg_Dbg(p_access, " type = MEMORY" );
272 msg_Dbg(p_access, " type = NETWORK" );
276 msg_Err( p_access, " unknown frontend type (%d)",
277 p_frontend->info.type );
280 msg_Dbg(p_access, " frequency_min = %u (kHz)",
281 p_frontend->info.frequency_min);
282 msg_Dbg(p_access, " frequency_max = %u (kHz)",
283 p_frontend->info.frequency_max);
284 msg_Dbg(p_access, " frequency_stepsize = %u",
285 p_frontend->info.frequency_stepsize);
286 msg_Dbg(p_access, " frequency_tolerance = %u",
287 p_frontend->info.frequency_tolerance);
288 msg_Dbg(p_access, " symbol_rate_min = %u (kHz)",
289 p_frontend->info.symbol_rate_min);
290 msg_Dbg(p_access, " symbol_rate_max = %u (kHz)",
291 p_frontend->info.symbol_rate_max);
292 msg_Dbg(p_access, " symbol_rate_tolerance (ppm) = %u",
293 p_frontend->info.symbol_rate_tolerance);
294 msg_Dbg(p_access, " notifier_delay (ms) = %u",
295 p_frontend->info.notifier_delay );
297 msg_Dbg(p_access, "Frontend Info capability list:");
298 if( p_frontend->info.caps & FE_IS_STUPID)
299 msg_Dbg(p_access, " no capabilities - frontend is stupid!");
300 if( p_frontend->info.caps & FE_CAN_INVERSION_AUTO)
301 msg_Dbg(p_access, " inversion auto");
302 if( p_frontend->info.caps & FE_CAN_FEC_1_2)
303 msg_Dbg(p_access, " forward error correction 1/2");
304 if( p_frontend->info.caps & FE_CAN_FEC_2_3)
305 msg_Dbg(p_access, " forward error correction 2/3");
306 if( p_frontend->info.caps & FE_CAN_FEC_3_4)
307 msg_Dbg(p_access, " forward error correction 3/4");
308 if( p_frontend->info.caps & FE_CAN_FEC_4_5)
309 msg_Dbg(p_access, " forward error correction 4/5");
310 if( p_frontend->info.caps & FE_CAN_FEC_5_6)
311 msg_Dbg(p_access, " forward error correction 5/6");
312 if( p_frontend->info.caps & FE_CAN_FEC_6_7)
313 msg_Dbg(p_access, " forward error correction 6/7");
314 if( p_frontend->info.caps & FE_CAN_FEC_7_8)
315 msg_Dbg(p_access, " forward error correction 7/8");
316 if( p_frontend->info.caps & FE_CAN_FEC_8_9)
317 msg_Dbg(p_access, " forward error correction 8/9");
318 if( p_frontend->info.caps & FE_CAN_FEC_AUTO)
319 msg_Dbg(p_access, " forward error correction auto");
320 if( p_frontend->info.caps & FE_CAN_QPSK)
321 msg_Dbg(p_access, " card can do QPSK");
322 if( p_frontend->info.caps & FE_CAN_QAM_16)
323 msg_Dbg(p_access, " card can do QAM 16");
324 if( p_frontend->info.caps & FE_CAN_QAM_32)
325 msg_Dbg(p_access, " card can do QAM 32");
326 if( p_frontend->info.caps & FE_CAN_QAM_64)
327 msg_Dbg(p_access, " card can do QAM 64");
328 if( p_frontend->info.caps & FE_CAN_QAM_128)
329 msg_Dbg(p_access, " card can do QAM 128");
330 if( p_frontend->info.caps & FE_CAN_QAM_256)
331 msg_Dbg(p_access, " card can do QAM 256");
332 if( p_frontend->info.caps & FE_CAN_QAM_AUTO)
333 msg_Dbg(p_access, " card can do QAM auto");
334 if( p_frontend->info.caps & FE_CAN_TRANSMISSION_MODE_AUTO)
335 msg_Dbg(p_access, " transmission mode auto");
336 if( p_frontend->info.caps & FE_CAN_BANDWIDTH_AUTO)
337 msg_Dbg(p_access, " bandwidth mode auto");
338 if( p_frontend->info.caps & FE_CAN_GUARD_INTERVAL_AUTO)
339 msg_Dbg(p_access, " guard interval mode auto");
340 if( p_frontend->info.caps & FE_CAN_HIERARCHY_AUTO)
341 msg_Dbg(p_access, " hierarchy mode auto");
342 if( p_frontend->info.caps & FE_CAN_MUTE_TS)
343 msg_Dbg(p_access, " card can mute TS");
344 if( p_frontend->info.caps & FE_CAN_CLEAN_SETUP)
345 msg_Dbg(p_access, " clean setup");
346 msg_Dbg(p_access, "End of capability list");
351 /*****************************************************************************
352 * Decoding the DVB parameters (common)
353 *****************************************************************************/
354 static fe_spectral_inversion_t DecodeInversion( access_t *p_access )
357 fe_spectral_inversion_t fe_inversion = 0;
359 var_Get( p_access, "dvb-inversion", &val );
360 msg_Dbg( p_access, "using inversion=%d", val.i_int );
364 case 0: fe_inversion = INVERSION_OFF; break;
365 case 1: fe_inversion = INVERSION_ON; break;
366 case 2: fe_inversion = INVERSION_AUTO; break;
368 msg_Dbg( p_access, "dvb has inversion not set, using auto");
369 fe_inversion = INVERSION_AUTO;
375 static fe_code_rate_t DecodeFEC( access_t *p_access, int i_val )
377 fe_code_rate_t fe_fec = FEC_NONE;
379 msg_Dbg( p_access, "using fec=%d", i_val );
383 case 0: fe_fec = FEC_NONE; break;
384 case 1: fe_fec = FEC_1_2; break;
385 case 2: fe_fec = FEC_2_3; break;
386 case 3: fe_fec = FEC_3_4; break;
387 case 4: fe_fec = FEC_4_5; break;
388 case 5: fe_fec = FEC_5_6; break;
389 case 6: fe_fec = FEC_6_7; break;
390 case 7: fe_fec = FEC_7_8; break;
391 case 8: fe_fec = FEC_8_9; break;
392 case 9: fe_fec = FEC_AUTO; break;
396 msg_Err( p_access, "argument has invalid FEC (%d)", i_val);
402 static fe_modulation_t DecodeModulation( access_t *p_access )
405 fe_modulation_t fe_modulation = 0;
407 var_Get( p_access, "dvb-modulation", &val );
411 case -1: fe_modulation = QPSK; break;
412 case 0: fe_modulation = QAM_AUTO; break;
413 case 16: fe_modulation = QAM_16; break;
414 case 32: fe_modulation = QAM_32; break;
415 case 64: fe_modulation = QAM_64; break;
416 case 128: fe_modulation = QAM_128; break;
417 case 256: fe_modulation = QAM_256; break;
419 msg_Dbg( p_access, "terrestrial/cable dvb has constellation/modulation not set, using auto");
420 fe_modulation = QAM_AUTO;
423 return fe_modulation;
426 /*****************************************************************************
427 * FrontendSetQPSK : controls the FE device
428 *****************************************************************************/
429 static fe_sec_voltage_t DecodeVoltage( access_t *p_access )
432 fe_sec_voltage_t fe_voltage;
434 var_Get( p_access, "dvb-voltage", &val );
435 msg_Dbg( p_access, "using voltage=%d", val.i_int );
439 case 0: fe_voltage = SEC_VOLTAGE_OFF; break;
440 case 13: fe_voltage = SEC_VOLTAGE_13; break;
441 case 18: fe_voltage = SEC_VOLTAGE_18; break;
443 fe_voltage = SEC_VOLTAGE_OFF;
444 msg_Err( p_access, "argument has invalid voltage (%d)", val.i_int );
450 static fe_sec_tone_mode_t DecodeTone( access_t *p_access )
453 fe_sec_tone_mode_t fe_tone;
455 var_Get( p_access, "dvb-tone", &val );
456 msg_Dbg( p_access, "using tone=%d", val.i_int );
460 case 0: fe_tone = SEC_TONE_OFF; break;
461 case 1: fe_tone = SEC_TONE_ON; break;
463 fe_tone = SEC_TONE_OFF;
464 msg_Err( p_access, "argument has invalid tone mode (%d)", val.i_int);
472 struct dvb_diseqc_master_cmd cmd;
476 static int DoDiseqc( access_t *p_access )
478 access_sys_t *p_sys = p_access->p_sys;
479 frontend_t * p_frontend = p_sys->p_frontend;
481 int i_frequency, i_lnb_slof;
482 fe_sec_voltage_t fe_voltage;
483 fe_sec_tone_mode_t fe_tone;
486 var_Get( p_access, "dvb-frequency", &val );
487 i_frequency = val.i_int;
488 var_Get( p_access, "dvb-lnb-slof", &val );
489 i_lnb_slof = val.i_int;
491 var_Get( p_access, "dvb-tone", &val );
492 if( val.i_int == -1 /* auto */ )
494 if( i_frequency >= i_lnb_slof )
498 var_Set( p_access, "dvb-tone", val );
501 fe_voltage = DecodeVoltage( p_access );
502 fe_tone = DecodeTone( p_access );
504 if( (i_err = ioctl( p_frontend->i_handle, FE_SET_VOLTAGE, fe_voltage )) < 0 )
506 msg_Err( p_access, "ioctl FE_SET_VOLTAGE failed, voltage=%d (%d) %s",
507 fe_voltage, i_err, strerror(errno) );
511 var_Get( p_access, "dvb-satno", &val );
514 /* digital satellite equipment control,
515 * specification is available from http://www.eutelsat.com/
517 if( (i_err = ioctl( p_frontend->i_handle, FE_SET_TONE,
518 SEC_TONE_OFF )) < 0 )
520 msg_Err( p_access, "ioctl FE_SET_TONE failed, tone=off (%d) %s",
521 i_err, strerror(errno) );
527 if( val.i_int >= 1 && val.i_int <= 4 )
529 /* 1.x compatible equipment */
530 struct diseqc_cmd_t cmd = { {{0xe0, 0x10, 0x38, 0xf0, 0x00, 0x00}, 4}, 0 };
532 /* param: high nibble: reset bits, low nibble set bits,
533 * bits are: option, position, polarization, band
535 cmd.cmd.msg[3] = 0xf0 /* reset bits */
536 | (((val.i_int - 1) * 4) & 0xc)
537 | (fe_voltage == SEC_VOLTAGE_13 ? 0 : 2)
538 | (fe_tone == SEC_TONE_ON ? 1 : 0);
540 if( (i_err = ioctl( p_frontend->i_handle, FE_DISEQC_SEND_MASTER_CMD,
543 msg_Err( p_access, "ioctl FE_SEND_MASTER_CMD failed (%d) %s",
544 i_err, strerror(errno) );
548 msleep(cmd.wait * 1000);
552 /* A or B simple diseqc */
553 if( (i_err = ioctl( p_frontend->i_handle, FE_DISEQC_SEND_BURST,
554 val.i_int == -1 ? SEC_MINI_A : SEC_MINI_B )) < 0 )
556 msg_Err( p_access, "ioctl FE_SEND_BURST failed (%d) %s",
557 i_err, strerror(errno) );
565 if( (i_err = ioctl( p_frontend->i_handle, FE_SET_TONE, fe_tone )) < 0 )
567 msg_Err( p_access, "ioctl FE_SET_TONE failed, tone=%s (%d) %s",
568 fe_tone == SEC_TONE_ON ? "on" : "off", i_err,
577 static int FrontendSetQPSK( access_t *p_access )
579 access_sys_t *p_sys = p_access->p_sys;
580 frontend_t * p_frontend = p_sys->p_frontend;
581 struct dvb_frontend_parameters fep;
584 int i_frequency, i_lnb_slof;
586 /* Prepare the fep structure */
587 var_Get( p_access, "dvb-frequency", &val );
588 i_frequency = val.i_int;
589 var_Get( p_access, "dvb-lnb-slof", &val );
590 i_lnb_slof = val.i_int;
592 if( i_frequency >= i_lnb_slof )
593 var_Get( p_access, "dvb-lnb-lof2", &val );
595 var_Get( p_access, "dvb-lnb-lof1", &val );
596 fep.frequency = i_frequency - val.i_int;
598 fep.inversion = DecodeInversion( p_access );
600 var_Get( p_access, "dvb-srate", &val );
601 fep.u.qpsk.symbol_rate = val.i_int;
603 var_Get( p_access, "dvb-fec", &val );
604 fep.u.qpsk.fec_inner = DecodeFEC( p_access, val.i_int );
606 if( DoDiseqc( p_access ) < 0 )
613 /* Empty the event queue */
616 struct dvb_frontend_event event;
617 if( ioctl( p_frontend->i_handle, FE_GET_EVENT, &event ) < 0 )
621 /* Now send it all to the frontend device */
622 if( (i_ret = ioctl( p_frontend->i_handle, FE_SET_FRONTEND, &fep )) < 0 )
624 msg_Err( p_access, "DVB-S: setting frontend failed (%d) %s", i_ret,
629 return FrontendCheck( p_access );
632 /*****************************************************************************
633 * FrontendSetQAM : controls the FE device
634 *****************************************************************************/
635 static int FrontendSetQAM( access_t *p_access )
637 access_sys_t *p_sys = p_access->p_sys;
638 frontend_t * p_frontend = p_sys->p_frontend;
639 struct dvb_frontend_parameters fep;
643 /* Prepare the fep structure */
645 var_Get( p_access, "dvb-frequency", &val );
646 fep.frequency = val.i_int;
648 fep.inversion = DecodeInversion( p_access );
650 var_Get( p_access, "dvb-srate", &val );
651 fep.u.qam.symbol_rate = val.i_int;
653 var_Get( p_access, "dvb-fec", &val );
654 fep.u.qam.fec_inner = DecodeFEC( p_access, val.i_int );
656 fep.u.qam.modulation = DecodeModulation( p_access );
658 /* Empty the event queue */
661 struct dvb_frontend_event event;
662 if( ioctl( p_frontend->i_handle, FE_GET_EVENT, &event ) < 0 )
666 /* Now send it all to the frontend device */
667 if( (i_ret = ioctl( p_frontend->i_handle, FE_SET_FRONTEND, &fep )) < 0 )
669 msg_Err( p_access, "DVB-C: setting frontend failed (%d) %s", i_ret,
674 return FrontendCheck( p_access );
677 /*****************************************************************************
678 * FrontendSetOFDM : controls the FE device
679 *****************************************************************************/
680 static fe_bandwidth_t DecodeBandwidth( access_t *p_access )
683 fe_bandwidth_t fe_bandwidth = 0;
685 var_Get( p_access, "dvb-bandwidth", &val );
686 msg_Dbg( p_access, "using bandwidth=%d", val.i_int );
690 case 0: fe_bandwidth = BANDWIDTH_AUTO; break;
691 case 6: fe_bandwidth = BANDWIDTH_6_MHZ; break;
692 case 7: fe_bandwidth = BANDWIDTH_7_MHZ; break;
693 case 8: fe_bandwidth = BANDWIDTH_8_MHZ; break;
695 msg_Dbg( p_access, "terrestrial dvb has bandwidth not set, using auto" );
696 fe_bandwidth = BANDWIDTH_AUTO;
702 static fe_transmit_mode_t DecodeTransmission( access_t *p_access )
705 fe_transmit_mode_t fe_transmission = 0;
707 var_Get( p_access, "dvb-transmission", &val );
708 msg_Dbg( p_access, "using transmission=%d", val.i_int );
712 case 0: fe_transmission = TRANSMISSION_MODE_AUTO; break;
713 case 2: fe_transmission = TRANSMISSION_MODE_2K; break;
714 case 8: fe_transmission = TRANSMISSION_MODE_8K; break;
716 msg_Dbg( p_access, "terrestrial dvb has transmission mode not set, using auto");
717 fe_transmission = TRANSMISSION_MODE_AUTO;
720 return fe_transmission;
723 static fe_guard_interval_t DecodeGuardInterval( access_t *p_access )
726 fe_guard_interval_t fe_guard = 0;
728 var_Get( p_access, "dvb-guard", &val );
729 msg_Dbg( p_access, "using guard=%d", val.i_int );
733 case 0: fe_guard = GUARD_INTERVAL_AUTO; break;
734 case 4: fe_guard = GUARD_INTERVAL_1_4; break;
735 case 8: fe_guard = GUARD_INTERVAL_1_8; break;
736 case 16: fe_guard = GUARD_INTERVAL_1_16; break;
737 case 32: fe_guard = GUARD_INTERVAL_1_32; break;
739 msg_Dbg( p_access, "terrestrial dvb has guard interval not set, using auto");
740 fe_guard = GUARD_INTERVAL_AUTO;
746 static fe_hierarchy_t DecodeHierarchy( access_t *p_access )
749 fe_hierarchy_t fe_hierarchy = 0;
751 var_Get( p_access, "dvb-hierarchy", &val );
752 msg_Dbg( p_access, "using hierarchy=%d", val.i_int );
756 case -1: fe_hierarchy = HIERARCHY_NONE; break;
757 case 0: fe_hierarchy = HIERARCHY_AUTO; break;
758 case 1: fe_hierarchy = HIERARCHY_1; break;
759 case 2: fe_hierarchy = HIERARCHY_2; break;
760 case 4: fe_hierarchy = HIERARCHY_4; break;
762 msg_Dbg( p_access, "terrestrial dvb has hierarchy not set, using auto");
763 fe_hierarchy = HIERARCHY_AUTO;
769 static int FrontendSetOFDM( access_t * p_access )
771 access_sys_t *p_sys = p_access->p_sys;
772 frontend_t * p_frontend = p_sys->p_frontend;
773 struct dvb_frontend_parameters fep;
777 /* Prepare the fep structure */
779 var_Get( p_access, "dvb-frequency", &val );
780 fep.frequency = val.i_int;
782 fep.inversion = DecodeInversion( p_access );
784 fep.u.ofdm.bandwidth = DecodeBandwidth( p_access );
785 var_Get( p_access, "dvb-code-rate-hp", &val );
786 fep.u.ofdm.code_rate_HP = DecodeFEC( p_access, val.i_int );
787 var_Get( p_access, "dvb-code-rate-lp", &val );
788 fep.u.ofdm.code_rate_LP = DecodeFEC( p_access, val.i_int );
789 fep.u.ofdm.constellation = DecodeModulation( p_access );
790 fep.u.ofdm.transmission_mode = DecodeTransmission( p_access );
791 fep.u.ofdm.guard_interval = DecodeGuardInterval( p_access );
792 fep.u.ofdm.hierarchy_information = DecodeHierarchy( p_access );
794 /* Empty the event queue */
797 struct dvb_frontend_event event;
798 if( ioctl( p_frontend->i_handle, FE_GET_EVENT, &event ) < 0 )
802 /* Now send it all to the frontend device */
803 if( (ret = ioctl( p_frontend->i_handle, FE_SET_FRONTEND, &fep )) < 0 )
805 msg_Err( p_access, "DVB-T: setting frontend failed (%d) %s", ret,
810 return FrontendCheck( p_access );
813 /******************************************************************
814 * FrontendCheck: Check completion of the frontend control sequence
815 ******************************************************************/
816 static int FrontendCheck( access_t * p_access )
818 access_sys_t *p_sys = p_access->p_sys;
819 frontend_t * p_frontend = p_sys->p_frontend;
822 while ( !p_access->b_die && !p_access->b_error )
825 if( (i_ret = ioctl( p_frontend->i_handle, FE_READ_STATUS,
828 msg_Err( p_access, "reading frontend status failed (%d) %s",
829 i_ret, strerror(errno) );
833 if(status & FE_HAS_SIGNAL) /* found something above the noise level */
834 msg_Dbg(p_access, "check frontend ... has signal");
836 if(status & FE_HAS_CARRIER) /* found a DVB signal */
837 msg_Dbg(p_access, "check frontend ... has carrier");
839 if(status & FE_HAS_VITERBI) /* FEC is stable */
840 msg_Dbg(p_access, "check frontend ... has stable forward error correction");
842 if(status & FE_HAS_SYNC) /* found sync bytes */
843 msg_Dbg(p_access, "check frontend ... has sync");
845 if(status & FE_HAS_LOCK) /* everything's working... */
848 msg_Dbg(p_access, "check frontend ... has lock");
849 msg_Dbg(p_access, "tuning succeeded");
851 /* Read some statistics */
853 if( ioctl( p_frontend->i_handle, FE_READ_BER, &value ) >= 0 )
854 msg_Dbg( p_access, "Bit error rate: %d", value );
857 if( ioctl( p_frontend->i_handle, FE_READ_SIGNAL_STRENGTH, &value ) >= 0 )
858 msg_Dbg( p_access, "Signal strength: %d", value );
861 if( ioctl( p_frontend->i_handle, FE_READ_SNR, &value ) >= 0 )
862 msg_Dbg( p_access, "SNR: %d", value );
867 if(status & FE_TIMEDOUT) /* no lock within the last ~2 seconds */
869 msg_Err(p_access, "tuning failed ... timed out");
873 if(status & FE_REINIT)
875 /* frontend was reinitialized, */
876 /* application is recommended to reset */
877 /* DiSEqC, tone and parameters */
878 msg_Err(p_access, "tuning failed ... resend frontend parameters");
892 /*****************************************************************************
893 * DMXSetFilter : controls the demux to add a filter
894 *****************************************************************************/
895 int E_(DMXSetFilter)( access_t * p_access, int i_pid, int * pi_fd, int i_type )
897 struct dmx_pes_filter_params s_filter_params;
899 unsigned int i_adapter, i_device;
903 var_Get( p_access, "dvb-adapter", &val );
904 i_adapter = val.i_int;
905 var_Get( p_access, "dvb-device", &val );
906 i_device = val.i_int;
908 if( snprintf( dmx, sizeof(dmx), DMX, i_adapter, i_device )
909 >= (int)sizeof(dmx) )
911 msg_Err( p_access, "snprintf() truncated string for DMX" );
912 dmx[sizeof(dmx) - 1] = '\0';
915 msg_Dbg( p_access, "Opening device %s", dmx );
916 if( (*pi_fd = open(dmx, O_RDWR)) < 0 )
918 msg_Err( p_access, "DMXSetFilter: opening device failed (%s)",
923 /* We fill the DEMUX structure : */
924 s_filter_params.pid = i_pid;
925 s_filter_params.input = DMX_IN_FRONTEND;
926 s_filter_params.output = DMX_OUT_TS_TAP;
927 s_filter_params.flags = DMX_IMMEDIATE_START;
932 msg_Dbg(p_access, "DMXSetFilter: DMX_PES_VIDEO0 for PID %d", i_pid);
933 s_filter_params.pes_type = DMX_PES_VIDEO0;
936 msg_Dbg(p_access, "DMXSetFilter: DMX_PES_AUDIO0 for PID %d", i_pid);
937 s_filter_params.pes_type = DMX_PES_AUDIO0;
940 msg_Dbg(p_access, "DMXSetFilter: DMX_PES_TELETEXT0 for PID %d", i_pid);
941 s_filter_params.pes_type = DMX_PES_TELETEXT0;
944 msg_Dbg(p_access, "DMXSetFilter: DMX_PES_SUBTITLE0 for PID %d", i_pid);
945 s_filter_params.pes_type = DMX_PES_SUBTITLE0;
948 msg_Dbg(p_access, "DMXSetFilter: DMX_PES_PCR0 for PID %d", i_pid);
949 s_filter_params.pes_type = DMX_PES_PCR0;
953 msg_Dbg(p_access, "DMXSetFilter: DMX_PES_VIDEO1 for PID %d", i_pid);
954 s_filter_params.pes_type = DMX_PES_VIDEO1;
957 msg_Dbg(p_access, "DMXSetFilter: DMX_PES_AUDIO1 for PID %d", i_pid);
958 s_filter_params.pes_type = DMX_PES_AUDIO1;
961 msg_Dbg(p_access, "DMXSetFilter: DMX_PES_TELETEXT1 for PID %d", i_pid);
962 s_filter_params.pes_type = DMX_PES_TELETEXT1;
965 msg_Dbg(p_access, "DMXSetFilter: DMX_PES_SUBTITLE1 for PID %d", i_pid);
966 s_filter_params.pes_type = DMX_PES_SUBTITLE1;
969 msg_Dbg(p_access, "DMXSetFilter: DMX_PES_PCR1 for PID %d", i_pid);
970 s_filter_params.pes_type = DMX_PES_PCR1;
974 msg_Dbg(p_access, "DMXSetFilter: DMX_PES_VIDEO2 for PID %d", i_pid);
975 s_filter_params.pes_type = DMX_PES_VIDEO2;
978 msg_Dbg(p_access, "DMXSetFilter: DMX_PES_AUDIO2 for PID %d", i_pid);
979 s_filter_params.pes_type = DMX_PES_AUDIO2;
982 msg_Dbg(p_access, "DMXSetFilter: DMX_PES_TELETEXT2 for PID %d", i_pid);
983 s_filter_params.pes_type = DMX_PES_TELETEXT2;
986 msg_Dbg(p_access, "DMXSetFilter: DMX_PES_SUBTITLE2 for PID %d", i_pid);
987 s_filter_params.pes_type = DMX_PES_SUBTITLE2;
990 msg_Dbg(p_access, "DMXSetFilter: DMX_PES_PCR2 for PID %d", i_pid);
991 s_filter_params.pes_type = DMX_PES_PCR2;
995 msg_Dbg(p_access, "DMXSetFilter: DMX_PES_VIDEO3 for PID %d", i_pid);
996 s_filter_params.pes_type = DMX_PES_VIDEO3;
999 msg_Dbg(p_access, "DMXSetFilter: DMX_PES_AUDIO3 for PID %d", i_pid);
1000 s_filter_params.pes_type = DMX_PES_AUDIO3;
1003 msg_Dbg(p_access, "DMXSetFilter: DMX_PES_TELETEXT3 for PID %d", i_pid);
1004 s_filter_params.pes_type = DMX_PES_TELETEXT3;
1007 msg_Dbg(p_access, "DMXSetFilter: DMX_PES_SUBTITLE3 for PID %d", i_pid);
1008 s_filter_params.pes_type = DMX_PES_SUBTITLE3;
1011 msg_Dbg(p_access, "DMXSetFilter: DMX_PES_PCR3 for PID %d", i_pid);
1012 s_filter_params.pes_type = DMX_PES_PCR3;
1014 /* Usually used by Nova cards */
1017 msg_Dbg(p_access, "DMXSetFilter: DMX_PES_OTHER for PID %d", i_pid);
1018 s_filter_params.pes_type = DMX_PES_OTHER;
1022 /* We then give the order to the device : */
1023 if( (i_ret = ioctl( *pi_fd, DMX_SET_PES_FILTER, &s_filter_params )) < 0 )
1025 msg_Err( p_access, "DMXSetFilter: failed with %d (%s)", i_ret,
1027 return VLC_EGENERIC;
1032 /*****************************************************************************
1033 * DMXUnsetFilter : removes a filter
1034 *****************************************************************************/
1035 int E_(DMXUnsetFilter)( access_t * p_access, int i_fd )
1039 if( (i_ret = ioctl( i_fd, DMX_STOP )) < 0 )
1041 msg_Err( p_access, "DMX_STOP failed for demux (%d) %s",
1042 i_ret, strerror(errno) );
1046 msg_Dbg( p_access, "DMXUnsetFilter: closing demux %d", i_fd );
1056 /*****************************************************************************
1058 *****************************************************************************/
1059 int E_(DVROpen)( access_t * p_access )
1061 access_sys_t *p_sys = p_access->p_sys;
1062 unsigned int i_adapter, i_device;
1066 var_Get( p_access, "dvb-adapter", &val );
1067 i_adapter = val.i_int;
1068 var_Get( p_access, "dvb-device", &val );
1069 i_device = val.i_int;
1071 if( snprintf( dvr, sizeof(dvr), DVR, i_adapter, i_device )
1072 >= (int)sizeof(dvr) )
1074 msg_Err( p_access, "snprintf() truncated string for DVR" );
1075 dvr[sizeof(dvr) - 1] = '\0';
1078 msg_Dbg( p_access, "Opening device %s", dvr );
1079 if( (p_sys->i_handle = open(dvr, O_RDONLY)) < 0 )
1081 msg_Err( p_access, "DVROpen: opening device failed (%s)",
1083 return VLC_EGENERIC;
1089 /*****************************************************************************
1091 *****************************************************************************/
1092 void E_(DVRClose)( access_t * p_access )
1094 access_sys_t *p_sys = p_access->p_sys;
1096 close( p_sys->i_handle );