]> git.sesse.net Git - vlc/blob - modules/access/dvb/access.c
* qdsk.c : fix a typo
[vlc] / modules / access / dvb / access.c
1 /*****************************************************************************
2  * access.c: DVB card input v4l2 only
3  *****************************************************************************
4  * Copyright (C) 1998-2003 VideoLAN
5  *
6  * Authors: Johan Bilien <jobi@via.ecp.fr>
7  *          Jean-Paul Saman <jpsaman@wxs.nl>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
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.
18  *
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, USA.
22  *****************************************************************************/
23
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <stdio.h>
29 #include <stdlib.h>
30
31 #include <vlc/vlc.h>
32 #include <vlc/input.h>
33
34 #include "../../demux/mpeg/system.h"
35
36 #ifdef HAVE_UNISTD_H
37 #   include <unistd.h>
38 #endif
39
40 #include <fcntl.h>
41 #include <sys/types.h>
42
43 #ifdef HAVE_ERRNO_H
44 #    include <string.h>
45 #    include <errno.h>
46 #endif
47
48 #ifdef STRNCASECMP_IN_STRINGS_H
49 #   include <strings.h>
50 #endif
51
52 /* DVB Card Drivers */
53 #include <linux/dvb/dmx.h>
54 #include <linux/dvb/frontend.h>
55
56 #include "dvb.h"
57
58 #define SATELLITE_READ_ONCE 3
59
60 /*****************************************************************************
61  * Local prototypes
62  *****************************************************************************/
63 static ssize_t SatelliteRead( input_thread_t * p_input, byte_t * p_buffer,
64                               size_t i_len);
65 static int     SatelliteSetArea    ( input_thread_t *, input_area_t * );
66 static int     SatelliteSetProgram ( input_thread_t *, pgrm_descriptor_t * );
67 static void    SatelliteSeek       ( input_thread_t *, off_t );
68
69 /*****************************************************************************
70  * Open: open the frontend device
71  *****************************************************************************/
72 int E_(Open) ( vlc_object_t *p_this )
73 {
74     struct dvb_frontend_info frontend_info;
75     struct dvb_frontend_parameters fep;
76     input_thread_t *    p_input = (input_thread_t *)p_this;
77     input_socket_t *    p_satellite;
78     char *              psz_parser;
79     char *              psz_next;
80     int                 i_fd = 0;
81     unsigned int        u_adapter = 1;
82     unsigned int        u_device = 0;
83     unsigned int        u_freq = 0;
84     unsigned int        u_srate = 0;
85     unsigned int        u_lnb_lof1;
86     unsigned int        u_lnb_lof2;
87     unsigned int        u_lnb_slof;
88     int                 i_bandwidth = 0;
89     int                 i_modulation = 0;
90     int                 i_guard = 0;
91     int                 i_transmission = 0;
92     int                 i_hierarchy = 0;
93     vlc_bool_t          b_polarisation = 0;
94     int                 i_fec = 0;
95     int                 i_code_rate_HP = 0;
96     int                 i_code_rate_LP = 0;
97     vlc_bool_t          b_diseqc;
98     vlc_bool_t          b_probe;
99     char                dvr[] = DVR;
100     char                frontend[] = FRONTEND;
101     int                 i_len = 0;
102     vlc_value_t         val;
103     int                 i_test;
104
105     
106     /* parse the options passed in command line : */
107     psz_parser = strdup( p_input->psz_name );
108
109     if( !psz_parser )
110     {
111         return( -1 );
112     }
113
114     // Get adapter and device number to use for this dvb card
115     u_adapter = config_GetInt( p_input, "adapter" );
116     u_device  = config_GetInt( p_input, "device" );
117   
118     /* Get antenna configuration options */
119     b_diseqc = config_GetInt( p_input, "diseqc" );
120     u_lnb_lof1 = config_GetInt( p_input, "lnb-lof1" );
121     u_lnb_lof2 = config_GetInt( p_input, "lnb-lof2" );
122     u_lnb_slof = config_GetInt( p_input, "lnb-slof" );
123
124     /*Get modulation parametters*/
125     i_bandwidth = config_GetInt( p_input, "bandwidth");
126     i_code_rate_HP = config_GetInt(p_input, "code-rate-hp");
127     i_code_rate_LP = config_GetInt(p_input, "code-rate-lp");
128     i_modulation  = config_GetInt(p_input, "modulation");
129     i_transmission = config_GetInt(p_input, "transmission");
130     i_guard = config_GetInt(p_input, "guard");
131     i_hierarchy = config_GetInt(p_input, "hierarchy");
132
133
134     /* Determine frontend device information and capabilities */
135     b_probe = config_GetInt( p_input, "probe" );
136     if (b_probe)
137     {
138         if ( ioctl_InfoFrontend(p_input, &frontend_info, u_adapter, u_device) < 0 )
139         {
140             msg_Err( p_input, "(access) cannot determine frontend info" );
141             return -1;
142         }
143     }
144     else /* no frontend probing is done so use default border values. */
145     {
146         msg_Dbg( p_input, "using default values for frontend info" );
147         i_len = sizeof(FRONTEND);
148         if (snprintf(frontend, sizeof(FRONTEND), FRONTEND, u_adapter, u_device) >= i_len)
149         {
150             msg_Err( p_input, "snprintf() truncated string for FRONTEND" );
151             frontend[sizeof(FRONTEND)] = '\0';
152         }
153         strncpy(frontend_info.name, frontend, 128);
154
155         msg_Dbg(p_input, "method of access is %s", p_input->psz_access);
156         
157         frontend_info.type = FE_QPSK;
158         if (strncmp( p_input->psz_access, "qpsk",4 ) ==0)
159             frontend_info.type = FE_QPSK;
160         else if (strncmp( p_input->psz_access, "cable",5 ) ==0)
161             frontend_info.type = FE_QAM;
162         else if (strncmp( p_input->psz_access, "terrestrial",11) ==0)
163             frontend_info.type = FE_OFDM;
164
165         frontend_info.frequency_max =   12999000;
166         frontend_info.frequency_min =    9750000;
167         frontend_info.symbol_rate_max = 30000000;
168         frontend_info.symbol_rate_min =  1000000;
169     }
170     
171     /* Register Callback functions */
172     p_input->pf_read = SatelliteRead;
173     p_input->pf_set_program = SatelliteSetProgram;
174     p_input->pf_set_area = SatelliteSetArea;
175     p_input->pf_seek = SatelliteSeek;
176
177     i_test = strtol( psz_parser, &psz_next, 10 );
178     if ( psz_next == psz_parser )
179     {
180         for ( ;; )
181         {
182             if( !strncmp( psz_parser, "frequency=",
183                                strlen( "frequency=" ) ) )
184             {
185                 u_freq =
186                   strtol( psz_parser + strlen( "frequency=" ),
187                             &psz_parser, 0 );
188             }
189             else if( !strncmp( psz_parser, "polarization=",
190                                strlen( "polarization=" ) ) )
191             {
192                 char *psz_parser_init;
193                 psz_parser += strlen( "polarization=" );
194                 psz_parser_init = psz_parser;
195                 while ( *psz_parser != ':')
196                 {
197                 psz_parser++;
198                 }
199                 if ((!strncmp( psz_parser_init, "V" ,
200                      psz_parser - psz_parser_init ) ) || 
201                    (!strncmp( psz_parser_init, "V" ,
202                      psz_parser - psz_parser_init ) ) )
203                 {
204                     b_polarisation = VLC_FALSE;
205                 }
206                 else if ((!strncmp( psz_parser_init, "H" ,
207                      psz_parser - psz_parser_init ) ) ||
208                    (!strncmp( psz_parser_init, "h" ,
209                      psz_parser - psz_parser_init ) ) )
210
211                 {
212                     b_polarisation = VLC_TRUE;
213                 }
214             }
215             else if( !strncmp( psz_parser, "fec=",
216                                strlen( "fec=" ) ) )
217             {
218                 i_fec =
219                 (int)strtol( psz_parser + strlen( "fec=" ),
220                             &psz_parser, 0 );
221             }
222             else if( !strncmp( psz_parser, "srate=",
223                                strlen( "srate=" ) ) )
224             {
225                 u_srate =
226                 (unsigned int)strtol( psz_parser + strlen( "srate=" ),
227                             &psz_parser, 0 );
228             }
229             else if( !strncmp( psz_parser, "program=",
230                                strlen( "program=" ) ) )
231             {
232                 val.i_int = (int)strtol( psz_parser + strlen( "program=" ),
233                             &psz_parser, 0 );
234                 var_Set( p_input, "program", val );
235             }
236             else if( !strncmp( psz_parser, "diseqc",
237                                strlen( "disecq" ) ) )
238             {
239                 psz_parser += strlen("disecq");
240                 b_diseqc = VLC_TRUE;
241             }
242             else if( !strncmp( psz_parser, "lnb-lof1=",
243                                strlen( "lnb-lof1=" ) ) )
244             {
245                 u_lnb_lof1 =
246                 (unsigned int)strtol( psz_parser + strlen( "lnb_lof1=" ),
247                             &psz_parser, 0 );
248             }
249             else if( !strncmp( psz_parser, "lnb-lof2=",
250                                strlen( "lnb-lof2=" ) ) )
251             {
252                 u_lnb_lof2 =
253                 (unsigned int)strtol( psz_parser + strlen( "lnb_lof2=" ),
254                             &psz_parser, 0 );
255             }
256             else if( !strncmp( psz_parser, "lnb-slof=",
257                                strlen( "lnb-slof=" ) ) )
258             {
259                 u_lnb_slof =
260                 (unsigned int)strtol( psz_parser + strlen( "lnb_slof=" ),
261                             &psz_parser, 0 );
262             }
263             else if( !strncmp( psz_parser, "device=",
264                                strlen( "device=" ) ) )
265             {
266                 u_device =
267                 (unsigned int)strtol( psz_parser + strlen( "device=" ),
268                             &psz_parser, 0 );
269             }
270             else if( !strncmp( psz_parser, "adapter=",
271                                strlen( "adapter=" ) ) )
272             {
273                 u_adapter =
274                 (unsigned int)strtol( psz_parser + strlen( "adapter=" ),
275                             &psz_parser, 0 );
276             }
277             else if (!strncmp( psz_parser, "modulation=",
278                                strlen( "modulation=" ) ) )
279             {
280                 i_modulation = (int)strtol( psz_parser + strlen( "modulation=" ),
281                             &psz_parser, 0 );
282             }
283             else if (!strncmp( psz_parser, "bandwidth=",
284                                strlen( "bandwidth=" ) ) )
285             {
286                 i_bandwidth = (int)strtol( psz_parser + strlen( "bandwidth=" ),
287                             &psz_parser, 0 );
288             }
289             else if (!strncmp( psz_parser, "guard=",
290                                strlen( "guard=" ) ) )
291             {
292                 i_guard = (int)strtol( psz_parser + strlen( "guard=" ),
293                             &psz_parser, 0 );
294             }
295             else if (!strncmp( psz_parser, "transmission=",
296                                strlen( "transmission=" ) ) )
297             {
298                 i_transmission = (int)strtol( psz_parser + 
299                             strlen( "transmission=" ),&psz_parser, 0 );
300             }
301             else if (!strncmp( psz_parser, "hierarchy=",
302                                strlen( "hierarchy=" ) ) )
303             {
304                 i_hierarchy = (int)strtol( psz_parser + 
305                                 strlen( "hierarchy=" ),&psz_parser, 0 );
306             }
307             else if (!strncmp( psz_parser, "code-rate-HP=",
308                                strlen( "code-rate-HP=" ) ) )
309             {
310                 i_code_rate_HP = (int)strtol( psz_parser + 
311                                 strlen( "code-rate-HP=" ),&psz_parser, 0 );
312             }
313             else if (!strncmp( psz_parser, "code-rate-LP=",
314                                strlen( "code-rate-LP=" ) ) )
315             {
316                 i_code_rate_LP = (int)strtol( psz_parser +
317                                 strlen( "code-rate-LP=" ),&psz_parser, 0 );
318             }
319             else if( !strncmp( psz_parser, "probe",
320                                strlen( "probe" ) ) )
321             {
322                 psz_parser += strlen("probe");
323                 b_probe = VLC_TRUE;
324             }
325             if( *psz_parser )
326                 psz_parser++;
327             else
328             break;
329         }
330     }
331     else
332     {
333         msg_Warn(p_input,"DVV Input syntax has changed, please see documentation for further informations");
334         u_freq = (unsigned int)i_test;
335         if( *psz_next )
336         {
337             psz_parser = psz_next + 1;
338             b_polarisation = (vlc_bool_t)strtol( psz_parser, &psz_next, 10 );
339             if( *psz_next )
340             {
341                 psz_parser = psz_next + 1;
342                 i_fec = (int)strtol( psz_parser, &psz_next, 10 );
343                 if( *psz_next )
344                 {
345                     psz_parser = psz_next + 1;
346                     u_srate = (unsigned int)strtol( psz_parser, &psz_next, 10 );
347                 }
348             }
349         }
350     }
351
352     /* Workaround for backwards compatibility */
353     if (strncmp( p_input->psz_access, "satellite",9 ) ==0)
354     {
355         msg_Warn( p_input, "invalid frequency %d possibly in kHz, trying value *1000 Hz", u_freq );
356         u_freq *= 1000;
357     }
358     
359     /* Validating input values */
360     if ( ((u_freq) > frontend_info.frequency_max) ||
361          ((u_freq) < frontend_info.frequency_min) )
362     {
363         msg_Warn( p_input, "invalid frequency %d (Hz), using default one", u_freq );
364         u_freq = config_GetInt( p_input, "frequency" );
365         if ( ((u_freq) > frontend_info.frequency_max) ||
366              ((u_freq) < frontend_info.frequency_min) )
367         {
368             msg_Err( p_input, "invalid default frequency" );
369             return -1;
370         }
371     }
372
373     /* Workaround for backwards compatibility */
374     if (strncmp( p_input->psz_access, "satellite", 9 ) ==0)
375     {
376         msg_Warn( p_input, "invalid symbol rate %d possibly specified in kHz, trying value *1000 Hz", u_freq );
377         u_srate *= 1000;
378     }
379     
380     if ( ((u_srate) > frontend_info.symbol_rate_max) ||
381          ((u_srate) < frontend_info.symbol_rate_min) )
382     {
383         msg_Warn( p_input, "invalid symbol rate, using default one" );
384         u_srate = config_GetInt( p_input, "symbol-rate" );
385         if ( ((u_srate) > frontend_info.symbol_rate_max) ||
386              ((u_srate) < frontend_info.symbol_rate_min) )
387         {
388             msg_Err( p_input, "invalid default symbol rate" );
389             return -1;
390         }
391     }
392
393     if( b_polarisation && (b_polarisation != 1) )
394     {
395         msg_Warn( p_input, "invalid polarization, using default one" );
396         b_polarisation = config_GetInt( p_input, "polarization" );
397         if( b_polarisation && b_polarisation != 1 )
398         {
399             msg_Err( p_input, "invalid default polarization" );
400             return -1;
401         }
402     }
403
404     if( (i_fec > 9) || (i_fec < 1) )
405     {
406         msg_Warn( p_input, "invalid FEC, using default one" );
407         i_fec = config_GetInt( p_input, "fec" );
408         if( (i_fec > 9) || (i_fec < 1) )
409         {
410             msg_Err( p_input, "invalid default FEC" );
411             return -1;
412         }
413     }
414     /* Setting frontend parameters for tuning the hardware */      
415     switch( frontend_info.type )
416     {
417         /* DVB-S: satellite and budget cards (nova) */
418         case FE_QPSK:
419             fep.frequency = u_freq;
420             fep.inversion = dvb_DecodeInversion(p_input, (int) b_polarisation);
421             fep.u.qpsk.symbol_rate = u_srate;
422             fep.u.qpsk.fec_inner = dvb_DecodeFEC(p_input, i_fec); 
423             msg_Dbg( p_input, "satellite (QPSK) frontend found on %s", frontend_info.name );
424             break;
425             
426         /* DVB-C */
427         case FE_QAM:
428             fep.frequency = u_freq;
429             fep.inversion = dvb_DecodeInversion(p_input, (int) b_polarisation);
430             fep.u.qam.symbol_rate = u_srate;
431             fep.u.qam.fec_inner = dvb_DecodeFEC(p_input, i_fec); 
432             fep.u.qam.modulation = dvb_DecodeModulation(p_input, i_modulation); 
433             msg_Dbg( p_input, "cable (QAM) frontend found on %s", frontend_info.name );
434             break;
435
436         /* DVB-T */
437         case FE_OFDM:
438             fep.frequency = u_freq;
439             fep.inversion = dvb_DecodeInversion(p_input, (int) b_polarisation);
440             fep.u.ofdm.bandwidth = dvb_DecodeBandwidth(p_input, i_bandwidth);
441             fep.u.ofdm.code_rate_HP = dvb_DecodeFEC(p_input, i_code_rate_HP); 
442             fep.u.ofdm.code_rate_LP = dvb_DecodeFEC(p_input, i_code_rate_LP);
443             fep.u.ofdm.constellation = dvb_DecodeModulation(p_input, i_modulation); 
444             fep.u.ofdm.transmission_mode = dvb_DecodeTransmission(p_input, i_transmission);
445             fep.u.ofdm.guard_interval = dvb_DecodeGuardInterval(p_input, i_guard);
446             fep.u.ofdm.hierarchy_information = dvb_DecodeHierarchy(p_input, i_hierarchy);
447             msg_Dbg( p_input, "terrestrial (OFDM) frontend found on %s", frontend_info.name );
448             break;
449
450         default:
451             msg_Err( p_input, "Could not determine frontend type on %s", frontend_info.name );
452             return -1;
453     }
454
455     /* Initialise structure */
456     p_satellite = malloc( sizeof( input_socket_t ) );
457
458     if( p_satellite == NULL )
459     {
460         msg_Err( p_input, "out of memory" );
461         return -1;
462     }
463
464     p_input->p_access_data = (void *)p_satellite;
465
466     /* Open the DVR device */
467     i_len = sizeof(DVR);
468     if (snprintf(dvr, sizeof(DVR), DVR, u_adapter, u_device) >= i_len)
469     {
470         msg_Err( p_input, "snprintf() truncated string for DVR" );
471         dvr[sizeof(DVR)] = '\0';
472     }
473     msg_Dbg( p_input, "opening DVR device '%s'", dvr );
474
475     if( (p_satellite->i_handle = open( dvr,
476                                    /*O_NONBLOCK | O_LARGEFILE*/0 )) == (-1) )
477     {
478 #   ifdef HAVE_ERRNO_H
479         msg_Warn( p_input, "cannot open `%s' (%s)", dvr, strerror(errno) );
480 #   else
481         msg_Warn( p_input, "cannot open `%s'", dvr );
482 #   endif
483         free( p_satellite );
484         return -1;
485     }
486
487     /* Initialize the Satellite Card */
488     switch (ioctl_SetFrontend (p_input, fep, b_polarisation,
489                                u_lnb_lof1, u_lnb_lof2, u_lnb_slof,
490                                u_adapter, u_device ))
491     {
492         case -2:
493             msg_Err( p_input, "frontend returned an unexpected event" );
494             close( p_satellite->i_handle );
495             free( p_satellite );
496             return -1;
497         case -3:
498             msg_Err( p_input, "frontend returned no event" );
499             close( p_satellite->i_handle );
500             free( p_satellite );
501             return -1;
502         case -4:
503             msg_Err( p_input, "frontend: timeout when polling for event" );
504             close( p_satellite->i_handle );
505             free( p_satellite );
506             return -1;
507         case -5:
508             msg_Err( p_input, "an error occured when polling frontend device" );
509             close( p_satellite->i_handle );
510             free( p_satellite );
511             return -1;
512         case -1:
513             msg_Err( p_input, "frontend returned a failure event" );
514             close( p_satellite->i_handle );
515             free( p_satellite );
516             return -1;
517         default:
518             break;
519     }
520
521     msg_Dbg( p_input, "setting filter on PAT" );
522
523     if ( ioctl_SetDMXFilter(p_input, 0, &i_fd, 21, u_adapter, u_device ) < 0 )
524     {
525 #   ifdef HAVE_ERRNO_H
526         msg_Err( p_input, "an error occured when setting filter on PAT (%s)", strerror(errno) );
527 #   else
528         msg_Err( p_input, "an error occured when setting filter on PAT" );
529 #   endif        
530         close( p_satellite->i_handle );
531         free( p_satellite );
532         return -1;
533     }
534
535     if( input_InitStream( p_input, sizeof( stream_ts_data_t ) ) == -1 )
536     {
537         msg_Err( p_input, "could not initialize stream structure" );
538         close( p_satellite->i_handle );
539         free( p_satellite );
540         return( -1 );
541     }
542
543     vlc_mutex_lock( &p_input->stream.stream_lock );
544
545     p_input->stream.b_pace_control = 1;
546     p_input->stream.b_seekable = 0;
547     p_input->stream.p_selected_area->i_tell = 0;
548
549     vlc_mutex_unlock( &p_input->stream.stream_lock );
550
551     p_input->i_mtu = SATELLITE_READ_ONCE * TS_PACKET_SIZE;
552     p_input->stream.i_method = INPUT_METHOD_SATELLITE;
553
554     return 0;
555 }
556
557 /*****************************************************************************
558  * Close : Close the device
559  *****************************************************************************/
560 void E_(Close) ( vlc_object_t *p_this )
561 {
562     input_thread_t *    p_input = (input_thread_t *)p_this;
563     input_socket_t *    p_satellite;
564     unsigned int        i_es_index;
565
566     if ( p_input->stream.p_selected_program )
567     {
568         for ( i_es_index = 1 ;
569                 i_es_index < p_input->stream.p_selected_program->i_es_number;
570                 i_es_index ++ )
571         {
572 #define p_es p_input->stream.p_selected_program->pp_es[i_es_index]
573             if ( p_es->p_decoder_fifo )
574             {
575                 ioctl_UnsetDMXFilter(p_input, p_es->i_demux_fd );
576             }
577 #undef p_es
578         }
579     }
580
581     p_satellite = (input_socket_t *)p_input;
582     close( p_satellite->i_handle );
583 }
584
585 /*****************************************************************************
586  * SatelliteRead: reads data from the satellite card
587  *****************************************************************************/
588 static ssize_t SatelliteRead( input_thread_t * p_input, byte_t * p_buffer,
589                               size_t i_len )
590 {
591     input_socket_t * p_access_data = (input_socket_t *)p_input->p_access_data;
592     ssize_t i_ret;
593     unsigned int u_adapter = 1;
594     unsigned int u_device = 0;
595     unsigned int i;
596
597     // Get adapter and device number to use for this dvb card
598     u_adapter = config_GetInt( p_input, "adapter" );
599     u_device  = config_GetInt( p_input, "device" );
600
601     /* if not set, set filters to the PMTs */
602     for( i = 0; i < p_input->stream.i_pgrm_number; i++ )
603     {
604         if ( p_input->stream.pp_programs[i]->pp_es[0]->i_demux_fd == 0 )
605         {
606             ioctl_SetDMXFilter(p_input, p_input->stream.pp_programs[i]->pp_es[0]->i_id,
607                        &p_input->stream.pp_programs[i]->pp_es[0]->i_demux_fd,
608                        21, u_adapter, u_device );
609         }
610     }
611
612     i_ret = read( p_access_data->i_handle, p_buffer, i_len );
613  
614     if( i_ret < 0 )
615     {
616 #   ifdef HAVE_ERRNO_H
617         msg_Err( p_input, "read failed (%s)", strerror(errno) );
618 #   else
619         msg_Err( p_input, "read failed" );
620 #   endif
621     }
622
623     return i_ret;
624 }
625
626 /*****************************************************************************
627  * SatelliteSetArea : Does nothing
628  *****************************************************************************/
629 static int SatelliteSetArea( input_thread_t * p_input, input_area_t * p_area )
630 {
631     return -1;
632 }
633
634 /*****************************************************************************
635  * SatelliteSetProgram : Sets the card filters according to the
636  *                 selected program,
637  *                 and makes the appropriate changes to stream structure.
638  *****************************************************************************/
639 int SatelliteSetProgram( input_thread_t    * p_input,
640                          pgrm_descriptor_t * p_new_prg )
641 {
642     unsigned int i_es_index;
643     vlc_value_t val;
644     unsigned int u_adapter = 1;
645     unsigned int u_device = 0;
646     unsigned int u_video_type = 1; /* default video type */
647     unsigned int u_audio_type = 2; /* default audio type */
648
649     /* Get adapter and device number to use for this dvb card */
650     u_adapter = config_GetInt( p_input, "adapter" );
651     u_device  = config_GetInt( p_input, "device" );
652
653     if ( p_input->stream.p_selected_program )
654     {
655         for ( i_es_index = 1 ; /* 0 should be the PMT */
656                 i_es_index < p_input->stream.p_selected_program->i_es_number ;
657                 i_es_index ++ )
658         {
659 #define p_es p_input->stream.p_selected_program->pp_es[i_es_index]
660             if ( p_es->p_decoder_fifo )
661             {
662                 input_UnselectES( p_input , p_es );
663             }
664             if ( p_es->i_demux_fd > 0)
665             {
666                 ioctl_UnsetDMXFilter(p_input, p_es->i_demux_fd );
667                 p_es->i_demux_fd = 0;
668             }
669 #undef p_es
670         }
671     }
672
673     for (i_es_index = 1 ; i_es_index < p_new_prg->i_es_number ; i_es_index ++ )
674     {
675 #define p_es p_new_prg->pp_es[i_es_index]
676         switch( p_es->i_cat )
677         {
678             case MPEG1_VIDEO_ES:
679             case MPEG2_VIDEO_ES:
680             case MPEG2_MOTO_VIDEO_ES:
681                 if ( input_SelectES( p_input , p_es ) == 0 )
682                 {
683                     ioctl_SetDMXFilter(p_input, p_es->i_id, &p_es->i_demux_fd, u_video_type,
684                                        u_adapter, u_device);
685                     u_video_type += 5;
686                 }
687                 break;
688             case MPEG1_AUDIO_ES:
689             case MPEG2_AUDIO_ES:
690                 if ( input_SelectES( p_input , p_es ) == 0 )
691                 {
692                     ioctl_SetDMXFilter(p_input, p_es->i_id, &p_es->i_demux_fd, u_audio_type,
693                                        u_adapter, u_device);
694                     input_SelectES( p_input , p_es );
695                     u_audio_type += 5;
696                 }
697                 break;
698             default:
699                 ioctl_SetDMXFilter(p_input, p_es->i_id, &p_es->i_demux_fd, 21, u_adapter, u_device);
700                 input_SelectES( p_input , p_es );
701                 msg_Warn(p_input, "ES streamtype 0x%d found used as DMX_PES_OTHER !!",(int) p_es->i_cat);
702                 break;
703 #undef p_es
704         }
705     }
706
707     p_input->stream.p_selected_program = p_new_prg;
708
709     /* Update the navigation variables without triggering a callback */
710     val.i_int = p_new_prg->i_number;
711     var_Change( p_input, "program", VLC_VAR_SETVALUE, &val, NULL );
712
713     return 0;
714 }
715
716 /*****************************************************************************
717  * SatelliteSeek: does nothing (not a seekable stream
718  *****************************************************************************/
719 static void SatelliteSeek( input_thread_t * p_input, off_t i_off )
720 {
721     ;
722 }
723