]> git.sesse.net Git - vlc/blob - modules/access/dvb/access.c
dvb/access.c removed old commandline syntax
[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     int                 i_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 parameters*/
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     /* Determine frontend device information and capabilities */
134     b_probe = config_GetInt( p_input, "probe" );
135     if (b_probe)
136     {
137         if ( ioctl_InfoFrontend(p_input, &frontend_info, u_adapter, u_device) < 0 )
138         {
139             msg_Err( p_input, "(access) cannot determine frontend info" );
140             return -1;
141         }
142     }
143     else /* no frontend probing is done so use default border values. */
144     {
145         msg_Dbg( p_input, "using default values for frontend info" );
146         i_len = sizeof(FRONTEND);
147         if (snprintf(frontend, sizeof(FRONTEND), FRONTEND, u_adapter, u_device) >= i_len)
148         {
149             msg_Err( p_input, "snprintf() truncated string for FRONTEND" );
150             frontend[sizeof(FRONTEND)] = '\0';
151         }
152         strncpy(frontend_info.name, frontend, 128);
153
154         msg_Dbg(p_input, "method of access is %s", p_input->psz_access);
155         
156         frontend_info.type = FE_QPSK;
157         if (strncmp( p_input->psz_access, "qpsk",4 ) ==0)
158             frontend_info.type = FE_QPSK;
159         else if (strncmp( p_input->psz_access, "cable",5 ) ==0)
160             frontend_info.type = FE_QAM;
161         else if (strncmp( p_input->psz_access, "terrestrial",11) ==0)
162             frontend_info.type = FE_OFDM;
163
164         frontend_info.frequency_max = u_lnb_lof2; /* in KHz, lnb_lof2 */
165         frontend_info.frequency_min = u_lnb_lof1; /* lnb_lof1 */
166
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                 (unsigned int)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                     i_polarisation = 0; //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                     i_polarisation = 1; //VLC_TRUE;
213                 }
214                 else if ((!strncmp( psz_parser_init, "A" ,
215                      psz_parser - psz_parser_init ) ) ||
216                    (!strncmp( psz_parser_init, "a" ,
217                      psz_parser - psz_parser_init ) ) )
218
219                 {
220                     i_polarisation = 2;
221                 }
222             }
223             else if( !strncmp( psz_parser, "fec=",
224                                strlen( "fec=" ) ) )
225             {
226                 i_fec =
227                 (int)strtol( psz_parser + strlen( "fec=" ),
228                             &psz_parser, 0 );
229             }
230             else if( !strncmp( psz_parser, "srate=",
231                                strlen( "srate=" ) ) )
232             {
233                 u_srate =
234                 (unsigned int)strtol( psz_parser + strlen( "srate=" ),
235                             &psz_parser, 0 );
236             }
237             else if( !strncmp( psz_parser, "program=",
238                                strlen( "program=" ) ) )
239             {
240                 val.i_int = (int)strtol( psz_parser + strlen( "program=" ),
241                             &psz_parser, 0 );
242                 var_Set( p_input, "program", val );
243             }
244             else if( !strncmp( psz_parser, "diseqc",
245                                strlen( "disecq" ) ) )
246             {
247                 psz_parser += strlen("disecq");
248                 b_diseqc = VLC_TRUE;
249             }
250             else if( !strncmp( psz_parser, "lnb-lof1=",
251                                strlen( "lnb-lof1=" ) ) )
252             {
253                 u_lnb_lof1 =
254                 (unsigned int)strtol( psz_parser + strlen( "lnb-lof1=" ),
255                             &psz_parser, 0 );                
256                 frontend_info.frequency_min = u_lnb_lof1; /* lnb_lof1 */
257             }
258             else if( !strncmp( psz_parser, "lnb-lof2=",
259                                strlen( "lnb-lof2=" ) ) )
260             {
261                 u_lnb_lof2 =
262                 (unsigned int)strtol( psz_parser + strlen( "lnb-lof2=" ),
263                             &psz_parser, 0 );
264                 frontend_info.frequency_max = u_lnb_lof2; /* in KHz, lnb_lof2 */
265             }
266             else if( !strncmp( psz_parser, "lnb-slof=",
267                                strlen( "lnb-slof=" ) ) )
268             {
269                 u_lnb_slof =
270                 (unsigned int)strtol( psz_parser + strlen( "lnb-slof=" ),
271                             &psz_parser, 0 );
272             }
273             else if( !strncmp( psz_parser, "device=",
274                                strlen( "device=" ) ) )
275             {
276                 u_device =
277                 (unsigned int)strtol( psz_parser + strlen( "device=" ),
278                             &psz_parser, 0 );
279             }
280             else if( !strncmp( psz_parser, "adapter=",
281                                strlen( "adapter=" ) ) )
282             {
283                 u_adapter =
284                 (unsigned int)strtol( psz_parser + strlen( "adapter=" ),
285                             &psz_parser, 0 );
286             }
287             else if (!strncmp( psz_parser, "modulation=",
288                                strlen( "modulation=" ) ) )
289             {
290                 i_modulation = (int)strtol( psz_parser + strlen( "modulation=" ),
291                             &psz_parser, 0 );
292             }
293             else if (!strncmp( psz_parser, "bandwidth=",
294                                strlen( "bandwidth=" ) ) )
295             {
296                 i_bandwidth = (int)strtol( psz_parser + strlen( "bandwidth=" ),
297                             &psz_parser, 0 );
298             }
299             else if (!strncmp( psz_parser, "guard=",
300                                strlen( "guard=" ) ) )
301             {
302                 i_guard = (int)strtol( psz_parser + strlen( "guard=" ),
303                             &psz_parser, 0 );
304             }
305             else if (!strncmp( psz_parser, "transmission=",
306                                strlen( "transmission=" ) ) )
307             {
308                 i_transmission = (int)strtol( psz_parser + 
309                             strlen( "transmission=" ),&psz_parser, 0 );
310             }
311             else if (!strncmp( psz_parser, "hierarchy=",
312                                strlen( "hierarchy=" ) ) )
313             {
314                 i_hierarchy = (int)strtol( psz_parser + 
315                                 strlen( "hierarchy=" ),&psz_parser, 0 );
316             }
317             else if (!strncmp( psz_parser, "code-rate-HP=",
318                                strlen( "code-rate-HP=" ) ) )
319             {
320                 i_code_rate_HP = (int)strtol( psz_parser + 
321                                 strlen( "code-rate-HP=" ),&psz_parser, 0 );
322             }
323             else if (!strncmp( psz_parser, "code-rate-LP=",
324                                strlen( "code-rate-LP=" ) ) )
325             {
326                 i_code_rate_LP = (int)strtol( psz_parser +
327                                 strlen( "code-rate-LP=" ),&psz_parser, 0 );
328             }
329             else if( !strncmp( psz_parser, "probe",
330                                strlen( "probe" ) ) )
331             {
332                 psz_parser += strlen("probe");
333                 b_probe = VLC_TRUE;
334             }
335             if( *psz_parser )
336                 psz_parser++;
337             else
338                 break;
339         }
340     }
341     else
342     {
343         msg_Err(p_input, "DVB Input old syntax deprecreated, use vlc -p dvb to see an explantion of the new syntax");
344         return -1;
345     }
346    
347     /* Validating input values */
348     if ( ((u_freq) > frontend_info.frequency_max) ||
349          ((u_freq) < frontend_info.frequency_min) )
350     {
351         if ((u_freq) > frontend_info.frequency_max)
352             msg_Err( p_input, "given frequency %u (kHz) > %u (kHz) max. frequency",
353                      u_freq, frontend_info.frequency_max );
354         else
355             msg_Err( p_input, "given frequency %u (kHz) < %u (kHz) min.frequency",
356                      u_freq, frontend_info.frequency_min );
357         msg_Err( p_input, "baling out given frequency outside specification range for this frontend" );
358         return -1;
359     }
360
361     /* Workaround for backwards compatibility */
362     if (strncmp( p_input->psz_access, "satellite", 9 ) ==0)
363     {
364         msg_Warn( p_input, "invalid symbol rate %d possibly specified in MHz, trying value *1000 KHz", u_freq );
365         u_srate *= 1000;
366     }
367     
368     if ( ((u_srate) > frontend_info.symbol_rate_max) ||
369          ((u_srate) < frontend_info.symbol_rate_min) )
370     {
371         msg_Warn( p_input, "invalid symbol rate, using default one" );
372         u_srate = config_GetInt( p_input, "symbol-rate" );
373         if ( ((u_srate) > frontend_info.symbol_rate_max) ||
374              ((u_srate) < frontend_info.symbol_rate_min) )
375         {
376             msg_Err( p_input, "invalid default symbol rate" );
377             return -1;
378         }
379     }
380
381     if( (i_fec > 9) || (i_fec < 1) )
382     {
383         msg_Warn( p_input, "invalid FEC, using default one" );
384         i_fec = config_GetInt( p_input, "fec" );
385         if( (i_fec > 9) || (i_fec < 1) )
386         {
387             msg_Err( p_input, "invalid default FEC" );
388             return -1;
389         }
390     }
391
392     /* Setting frontend parameters for tuning the hardware */      
393     msg_Dbg( p_input, "Trying to tune to channel ...");
394     switch( frontend_info.type )
395     {
396         /* DVB-S: satellite and budget cards (nova) */
397         case FE_QPSK:
398             fep.frequency = u_freq; /* KHz */
399             fep.inversion = dvb_DecodeInversion(p_input, i_polarisation);
400             fep.u.qpsk.symbol_rate = u_srate;
401             fep.u.qpsk.fec_inner = dvb_DecodeFEC(p_input, i_fec); 
402             msg_Dbg( p_input, "DVB-S: satellite (QPSK) frontend %s found", frontend_info.name );
403
404             if (ioctl_SetQPSKFrontend (p_input, fep, i_polarisation,
405                                u_lnb_lof1, u_lnb_lof2, u_lnb_slof,
406                                u_adapter, u_device )<0)
407             {
408                 msg_Err( p_input, "DVB-S: tuning failed" );
409                 return -1;
410             }
411             break;
412             
413         /* DVB-C */
414         case FE_QAM:
415             fep.frequency = u_freq; /* in Hz */
416             fep.inversion = dvb_DecodeInversion(p_input, i_polarisation);
417             fep.u.qam.symbol_rate = u_srate;
418             fep.u.qam.fec_inner = dvb_DecodeFEC(p_input, i_fec); 
419             fep.u.qam.modulation = dvb_DecodeModulation(p_input, i_modulation); 
420             msg_Dbg( p_input, "DVB-C: cable (QAM) frontend %s found", frontend_info.name );
421             if (ioctl_SetQAMFrontend (p_input, fep, u_adapter, u_device )<0)
422             {
423                 msg_Err( p_input, "DVB-C: tuning failed" );
424                 return -1;
425             }
426             break;
427
428         /* DVB-T */
429         case FE_OFDM:
430             fep.frequency = u_freq; /* in Hz */
431             fep.inversion = dvb_DecodeInversion(p_input, i_polarisation);
432             fep.u.ofdm.bandwidth = dvb_DecodeBandwidth(p_input, i_bandwidth);
433             fep.u.ofdm.code_rate_HP = dvb_DecodeFEC(p_input, i_code_rate_HP); 
434             fep.u.ofdm.code_rate_LP = dvb_DecodeFEC(p_input, i_code_rate_LP);
435             fep.u.ofdm.constellation = dvb_DecodeModulation(p_input, i_modulation); 
436             fep.u.ofdm.transmission_mode = dvb_DecodeTransmission(p_input, i_transmission);
437             fep.u.ofdm.guard_interval = dvb_DecodeGuardInterval(p_input, i_guard);
438             fep.u.ofdm.hierarchy_information = dvb_DecodeHierarchy(p_input, i_hierarchy);
439             msg_Dbg( p_input, "DVB-T: terrestrial (OFDM) frontend %s found", frontend_info.name );
440             if (ioctl_SetOFDMFrontend (p_input, fep,u_adapter, u_device )<0)
441             {
442                 msg_Err( p_input, "DVB-T: tuning failed" );
443                 return -1;
444             }
445             break;
446         default:
447             msg_Err( p_input, "Could not determine frontend type on %s", frontend_info.name );
448             return -1;
449     }
450     msg_Dbg( p_input, "Tuning done.");
451
452     /* Initialise structure */
453     p_satellite = malloc( sizeof( input_socket_t ) );
454
455     if( p_satellite == NULL )
456     {
457         msg_Err( p_input, "out of memory" );
458         return -1;
459     }
460
461     p_input->p_access_data = (void *)p_satellite;
462
463     /* Open the DVR device */
464     i_len = sizeof(DVR);
465     if (snprintf(dvr, sizeof(DVR), DVR, u_adapter, u_device) >= i_len)
466     {
467         msg_Err( p_input, "snprintf() truncated string for DVR" );
468         dvr[sizeof(DVR)] = '\0';
469     }
470     msg_Dbg( p_input, "opening DVR device '%s'", dvr );
471
472     if( (p_satellite->i_handle = open( dvr,
473                                    /*O_NONBLOCK | O_LARGEFILE*/0 )) == (-1) )
474     {
475 #   ifdef HAVE_ERRNO_H
476         msg_Warn( p_input, "cannot open `%s' (%s)", dvr, strerror(errno) );
477 #   else
478         msg_Warn( p_input, "cannot open `%s'", dvr );
479 #   endif
480         free( p_satellite );
481         return -1;
482     }
483
484     msg_Dbg( p_input, "setting filter on PAT" );
485
486     /* Set Filter on PAT packet */
487     if ( ioctl_SetDMXFilter(p_input, 0, &i_fd, 21, u_adapter, u_device ) < 0 )
488     {
489 #   ifdef HAVE_ERRNO_H
490         msg_Err( p_input, "an error occured when setting filter on PAT (%s)", strerror(errno) );
491 #   else
492         msg_Err( p_input, "an error occured when setting filter on PAT" );
493 #   endif        
494         close( p_satellite->i_handle );
495         free( p_satellite );
496         return -1;
497     }
498
499     if( input_InitStream( p_input, sizeof( stream_ts_data_t ) ) == -1 )
500     {
501         msg_Err( p_input, "could not initialize stream structure" );
502         close( p_satellite->i_handle );
503         free( p_satellite );
504         return( -1 );
505     }
506
507     vlc_mutex_lock( &p_input->stream.stream_lock );
508
509     p_input->stream.b_pace_control = 1;
510     p_input->stream.b_seekable = 0;
511     p_input->stream.p_selected_area->i_tell = 0;
512
513     vlc_mutex_unlock( &p_input->stream.stream_lock );
514
515     p_input->i_mtu = SATELLITE_READ_ONCE * TS_PACKET_SIZE;
516     p_input->stream.i_method = INPUT_METHOD_SATELLITE;
517
518     return 0;
519 }
520
521 /*****************************************************************************
522  * Close : Close the device
523  *****************************************************************************/
524 void E_(Close) ( vlc_object_t *p_this )
525 {
526     input_thread_t *    p_input = (input_thread_t *)p_this;
527     input_socket_t *    p_satellite;
528     unsigned int        i_es_index;
529
530     if ( p_input->stream.p_selected_program )
531     {
532         for ( i_es_index = 1 ;
533                 i_es_index < p_input->stream.p_selected_program->i_es_number;
534                 i_es_index ++ )
535         {
536 #define p_es p_input->stream.p_selected_program->pp_es[i_es_index]
537             if ( p_es->p_dec )
538             {
539                 ioctl_UnsetDMXFilter(p_input, p_es->i_demux_fd );
540             }
541 #undef p_es
542         }
543     }
544
545     p_satellite = (input_socket_t *)p_input;
546     close( p_satellite->i_handle );
547 }
548
549 /*****************************************************************************
550  * SatelliteRead: reads data from the satellite card
551  *****************************************************************************/
552 static ssize_t SatelliteRead( input_thread_t * p_input, byte_t * p_buffer,
553                               size_t i_len )
554 {
555     input_socket_t * p_access_data = (input_socket_t *)p_input->p_access_data;
556     ssize_t i_ret;
557     unsigned int u_adapter = 1;
558     unsigned int u_device = 0;
559     unsigned int i;
560
561     // Get adapter and device number to use for this dvb card
562     u_adapter = config_GetInt( p_input, "adapter" );
563     u_device  = config_GetInt( p_input, "device" );
564
565     /* if not set, set filters to the PMTs */
566     for( i = 0; i < p_input->stream.i_pgrm_number; i++ )
567     {
568         if ( p_input->stream.pp_programs[i]->pp_es[0]->i_demux_fd == 0 )
569         {
570             ioctl_SetDMXFilter(p_input, p_input->stream.pp_programs[i]->pp_es[0]->i_id,
571                        &p_input->stream.pp_programs[i]->pp_es[0]->i_demux_fd,
572                        21, u_adapter, u_device );
573         }
574     }
575
576     i_ret = read( p_access_data->i_handle, p_buffer, i_len );
577  
578     if( i_ret < 0 )
579     {
580 #   ifdef HAVE_ERRNO_H
581         msg_Err( p_input, "read failed (%s)", strerror(errno) );
582 #   else
583         msg_Err( p_input, "read failed" );
584 #   endif
585     }
586
587     return i_ret;
588 }
589
590 /*****************************************************************************
591  * SatelliteSetArea : Does nothing
592  *****************************************************************************/
593 static int SatelliteSetArea( input_thread_t * p_input, input_area_t * p_area )
594 {
595     return -1;
596 }
597
598 /*****************************************************************************
599  * SatelliteSetProgram : Sets the card filters according to the
600  *                 selected program,
601  *                 and makes the appropriate changes to stream structure.
602  *****************************************************************************/
603 int SatelliteSetProgram( input_thread_t    * p_input,
604                          pgrm_descriptor_t * p_new_prg )
605 {
606     unsigned int i_es_index;
607     vlc_value_t val;
608     unsigned int u_adapter = 1;
609     unsigned int u_device = 0;
610     unsigned int u_video_type = 1; /* default video type */
611     unsigned int u_audio_type = 2; /* default audio type */
612
613     /* Get adapter and device number to use for this dvb card */
614     u_adapter = config_GetInt( p_input, "adapter" );
615     u_device  = config_GetInt( p_input, "device" );
616
617     if ( p_input->stream.p_selected_program )
618     {
619         for ( i_es_index = 1 ; /* 0 should be the PMT */
620                 i_es_index < p_input->stream.p_selected_program->i_es_number ;
621                 i_es_index ++ )
622         {
623 #define p_es p_input->stream.p_selected_program->pp_es[i_es_index]
624             if ( p_es->p_dec )
625             {
626                 input_UnselectES( p_input , p_es );
627             }
628             if ( p_es->i_demux_fd > 0)
629             {
630                 ioctl_UnsetDMXFilter(p_input, p_es->i_demux_fd );
631                 p_es->i_demux_fd = 0;
632             }
633 #undef p_es
634         }
635     }
636
637     for (i_es_index = 1 ; i_es_index < p_new_prg->i_es_number ; i_es_index ++ )
638     {
639 #define p_es p_new_prg->pp_es[i_es_index]
640         switch( p_es->i_cat )
641         {
642             case MPEG1_VIDEO_ES:
643             case MPEG2_VIDEO_ES:
644             case MPEG2_MOTO_VIDEO_ES:
645                 if ( input_SelectES( p_input , p_es ) == 0 )
646                 {
647                     ioctl_SetDMXFilter(p_input, p_es->i_id, &p_es->i_demux_fd, u_video_type,
648                                        u_adapter, u_device);
649                     u_video_type += 5;
650                 }
651                 break;
652             case MPEG1_AUDIO_ES:
653             case MPEG2_AUDIO_ES:
654                 if ( input_SelectES( p_input , p_es ) == 0 )
655                 {
656                     ioctl_SetDMXFilter(p_input, p_es->i_id, &p_es->i_demux_fd, u_audio_type,
657                                        u_adapter, u_device);
658                     input_SelectES( p_input , p_es );
659                     u_audio_type += 5;
660                 }
661                 break;
662             default:
663                 ioctl_SetDMXFilter(p_input, p_es->i_id, &p_es->i_demux_fd, 21, u_adapter, u_device);
664                 input_SelectES( p_input , p_es );
665                 msg_Warn(p_input, "ES streamtype 0x%d found used as DMX_PES_OTHER !!",(int) p_es->i_cat);
666                 break;
667 #undef p_es
668         }
669     }
670
671     p_input->stream.p_selected_program = p_new_prg;
672
673     /* Update the navigation variables without triggering a callback */
674     val.i_int = p_new_prg->i_number;
675     var_Change( p_input, "program", VLC_VAR_SETVALUE, &val, NULL );
676
677     return 0;
678 }
679
680 /*****************************************************************************
681  * SatelliteSeek: does nothing (not a seekable stream
682  *****************************************************************************/
683 static void SatelliteSeek( input_thread_t * p_input, off_t i_off )
684 {
685     ;
686 }
687