]> git.sesse.net Git - vlc/blob - src/input/es_out.c
* src/input/es_out.c: ES_OUT_SET_FMT restarts the decoder.
[vlc] / src / input / es_out.c
1 /*****************************************************************************
2  * es_out.c: Es Out handler for input.
3  *****************************************************************************
4  * Copyright (C) 2003-2004 VideoLAN
5  * $Id$
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
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  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>
28
29 #include <vlc/vlc.h>
30 #include <vlc/input.h>
31 #include <vlc/decoder.h>
32
33 #include "input_internal.h"
34
35 #include "vlc_playlist.h"
36 #include "iso_lang.h"
37 /* FIXME we should find a better way than including that */
38 #include "../misc/iso-639_def.h"
39
40 /*****************************************************************************
41  * Local prototypes
42  *****************************************************************************/
43 typedef struct
44 {
45     /* Program ID */
46     int i_id;
47
48     /* Number of es for this pgrm */
49     int i_es;
50
51     vlc_bool_t b_selected;
52
53     /* Clock for this program */
54     input_clock_t clock;
55
56 } es_out_pgrm_t;
57
58 struct es_out_id_t
59 {
60     /* ES ID */
61     int       i_id;
62     es_out_pgrm_t *p_pgrm;
63
64     /* */
65     int64_t i_preroll_end;
66
67     /* Channel in the track type */
68     int         i_channel;
69     es_format_t fmt;
70     char        *psz_language;
71     char        *psz_language_code;
72     decoder_t   *p_dec;
73 };
74
75 struct es_out_sys_t
76 {
77     input_thread_t *p_input;
78
79     /* all programs */
80     int           i_pgrm;
81     es_out_pgrm_t **pgrm;
82     es_out_pgrm_t **pp_selected_pgrm; /* --programs */
83     es_out_pgrm_t *p_pgrm;  /* Master program */
84
85     /* all es */
86     int         i_id;
87     int         i_es;
88     es_out_id_t **es;
89
90     /* mode gestion */
91     vlc_bool_t  b_active;
92     int         i_mode;
93
94     /* es count */
95     int         i_audio;
96     int         i_video;
97     int         i_sub;
98
99     /* es to select */
100     int         i_audio_last;
101     int         i_sub_last;
102     char        **ppsz_audio_language;
103     char        **ppsz_sub_language;
104
105     /* current main es */
106     es_out_id_t *p_es_audio;
107     es_out_id_t *p_es_video;
108     es_out_id_t *p_es_sub;
109
110     /* delay */
111     int64_t i_audio_delay;
112     int64_t i_spu_delay;
113 };
114
115 static es_out_id_t *EsOutAdd    ( es_out_t *, es_format_t * );
116 static int          EsOutSend   ( es_out_t *, es_out_id_t *, block_t * );
117 static void         EsOutDel    ( es_out_t *, es_out_id_t * );
118 static void         EsOutSelect( es_out_t *out, es_out_id_t *es, vlc_bool_t b_force );
119 static int          EsOutControl( es_out_t *, int i_query, va_list );
120
121 static void         EsOutAddInfo( es_out_t *, es_out_id_t *es );
122
123 static void EsSelect( es_out_t *out, es_out_id_t *es );
124 static void EsUnselect( es_out_t *out, es_out_id_t *es, vlc_bool_t b_update );
125 static char *LanguageGetName( const char *psz_code );
126 static char *LanguageGetCode( const char *psz_lang );
127 static char **LanguageSplit( const char *psz_langs );
128 static int LanguageArrayIndex( char **ppsz_langs, char *psz_lang );
129
130 /*****************************************************************************
131  * input_EsOutNew:
132  *****************************************************************************/
133 es_out_t *input_EsOutNew( input_thread_t *p_input )
134 {
135     es_out_t     *out = malloc( sizeof( es_out_t ) );
136     es_out_sys_t *p_sys = malloc( sizeof( es_out_sys_t ) );
137     vlc_value_t  val;
138     int i;
139
140     out->pf_add     = EsOutAdd;
141     out->pf_send    = EsOutSend;
142     out->pf_del     = EsOutDel;
143     out->pf_control = EsOutControl;
144     out->p_sys      = p_sys;
145
146     p_sys->p_input = p_input;
147
148     p_sys->b_active = VLC_FALSE;
149     p_sys->i_mode   = ES_OUT_MODE_AUTO;
150
151
152     p_sys->i_pgrm   = 0;
153     p_sys->pgrm     = NULL;
154     p_sys->p_pgrm   = NULL;
155
156     p_sys->i_id    = 0;
157     p_sys->i_es    = 0;
158     p_sys->es      = NULL;
159
160     p_sys->i_audio = 0;
161     p_sys->i_video = 0;
162     p_sys->i_sub   = 0;
163
164     /* */
165     var_Get( p_input, "audio-track", &val );
166     p_sys->i_audio_last = val.i_int;
167
168     var_Get( p_input, "sub-track", &val );
169     p_sys->i_sub_last = val.i_int;
170
171     var_Get( p_input, "audio-language", &val );
172     p_sys->ppsz_audio_language = LanguageSplit(val.psz_string);
173     if( p_sys->ppsz_audio_language )
174     {
175         for( i = 0; p_sys->ppsz_audio_language[i]; i++ )
176             msg_Dbg( p_input, "Select audio in language[%d] %s",
177                      i, p_sys->ppsz_audio_language[i] );
178     }
179
180     var_Get( p_input, "sub-language", &val );
181     p_sys->ppsz_sub_language = LanguageSplit(val.psz_string);
182     if( p_sys->ppsz_sub_language )
183     {
184         for( i = 0; p_sys->ppsz_sub_language[i]; i++ )
185             msg_Dbg( p_input, "Select subtitle in language[%d] %s",
186                      i, p_sys->ppsz_sub_language[i] );
187     }
188
189     /* */
190     p_sys->p_es_audio = NULL;
191     p_sys->p_es_video = NULL;
192     p_sys->p_es_sub   = NULL;
193
194     p_sys->i_audio_delay= 0;
195     p_sys->i_spu_delay  = 0;
196
197     return out;
198 }
199
200 /*****************************************************************************
201  * input_EsOutDelete:
202  *****************************************************************************/
203 void input_EsOutDelete( es_out_t *out )
204 {
205     es_out_sys_t *p_sys = out->p_sys;
206     int i;
207
208     for( i = 0; i < p_sys->i_es; i++ )
209     {
210         if( p_sys->es[i]->p_dec )
211         {
212             input_DecoderDelete( p_sys->es[i]->p_dec );
213         }
214         if( p_sys->es[i]->psz_language )
215             free( p_sys->es[i]->psz_language );
216         if( p_sys->es[i]->psz_language_code )
217             free( p_sys->es[i]->psz_language_code );
218         es_format_Clean( &p_sys->es[i]->fmt );
219
220         free( p_sys->es[i] );
221     }
222     if( p_sys->ppsz_audio_language )
223     {
224         for( i = 0; p_sys->ppsz_audio_language[i]; i++ )
225             free( p_sys->ppsz_audio_language[i] );
226         free( p_sys->ppsz_audio_language );
227     }
228     if( p_sys->ppsz_sub_language )
229     {
230         for( i = 0; p_sys->ppsz_sub_language[i]; i++ )
231             free( p_sys->ppsz_sub_language[i] );
232         free( p_sys->ppsz_sub_language );
233     }
234
235     if( p_sys->es )
236         free( p_sys->es );
237
238     for( i = 0; i < p_sys->i_pgrm; i++ )
239     {
240         free( p_sys->pgrm[i] );
241     }
242     if( p_sys->pgrm )
243         free( p_sys->pgrm );
244
245     free( p_sys );
246     free( out );
247 }
248
249 es_out_id_t *input_EsOutGetFromID( es_out_t *out, int i_id )
250 {
251     int i;
252     if( i_id < 0 )
253     {
254         /* Special HACK, -i_id is tha cat of the stream */
255         return (es_out_id_t*)((uint8_t*)NULL-i_id);
256     }
257
258     for( i = 0; i < out->p_sys->i_es; i++ )
259     {
260         if( out->p_sys->es[i]->i_id == i_id )
261             return out->p_sys->es[i];
262     }
263     return NULL;
264 }
265
266 void input_EsOutDiscontinuity( es_out_t *out, vlc_bool_t b_audio )
267 {
268     es_out_sys_t      *p_sys = out->p_sys;
269     int i;
270
271     for( i = 0; i < p_sys->i_es; i++ )
272     {
273         es_out_id_t *es = p_sys->es[i];
274
275         /* Send a dummy block to let decoder know that
276          * there is a discontinuity */
277         if( es->p_dec && ( !b_audio || es->fmt.i_cat == AUDIO_ES ) )
278         {
279             input_DecoderDiscontinuity( es->p_dec );
280         }
281     }
282 }
283
284 void input_EsOutSetDelay( es_out_t *out, int i_cat, int64_t i_delay )
285 {
286     es_out_sys_t *p_sys = out->p_sys;
287
288     if( i_cat == AUDIO_ES )
289         p_sys->i_audio_delay = i_delay;
290     else if( i_cat == SPU_ES )
291         p_sys->i_spu_delay = i_delay;
292 }
293
294 vlc_bool_t input_EsOutDecodersEmpty( es_out_t *out )
295 {
296     es_out_sys_t      *p_sys = out->p_sys;
297     int i;
298
299     for( i = 0; i < p_sys->i_es; i++ )
300     {
301         es_out_id_t *es = p_sys->es[i];
302
303         if( es->p_dec && !input_DecoderEmpty( es->p_dec ) )
304             return VLC_FALSE;
305     }
306     return VLC_TRUE;
307 }
308
309 /*****************************************************************************
310  *
311  *****************************************************************************/
312 static void EsOutESVarUpdate( es_out_t *out, es_out_id_t *es,
313                               vlc_bool_t b_delete )
314 {
315     es_out_sys_t      *p_sys = out->p_sys;
316     input_thread_t    *p_input = p_sys->p_input;
317     vlc_value_t       val, text;
318
319     char *psz_var;
320
321     if( es->fmt.i_cat == AUDIO_ES )
322         psz_var = "audio-es";
323     else if( es->fmt.i_cat == VIDEO_ES )
324         psz_var = "video-es";
325     else if( es->fmt.i_cat == SPU_ES )
326         psz_var = "spu-es";
327     else
328         return;
329
330     if( b_delete )
331     {
332         val.i_int = es->i_id;
333         var_Change( p_input, psz_var, VLC_VAR_DELCHOICE, &val, NULL );
334         var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
335         return;
336     }
337
338     /* Get the number of ES already added */
339     var_Change( p_input, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
340     if( val.i_int == 0 )
341     {
342         vlc_value_t val2;
343
344         /* First one, we need to add the "Disable" choice */
345         val2.i_int = -1; text.psz_string = _("Disable");
346         var_Change( p_input, psz_var, VLC_VAR_ADDCHOICE, &val2, &text );
347         val.i_int++;
348     }
349
350     /* Take care of the ES description */
351     if( es->fmt.psz_description && *es->fmt.psz_description )
352     {
353         if( es->psz_language && *es->psz_language )
354         {
355             text.psz_string = malloc( strlen( es->fmt.psz_description) + strlen( es->psz_language ) + 10 );
356             sprintf( text.psz_string, "%s - [%s]", es->fmt.psz_description, es->psz_language );
357         }
358         else text.psz_string = strdup( es->fmt.psz_description );
359     }
360     else
361     {
362         if( es->psz_language && *es->psz_language )
363         {
364             char *temp;
365             text.psz_string = malloc( strlen( _("Track %i") )+ strlen( es->psz_language ) + 30 );
366             asprintf( &temp,  _("Track %i"), val.i_int );
367             sprintf( text.psz_string, "%s - [%s]", temp, es->psz_language );
368             free( temp );
369         }
370         else
371         {
372             text.psz_string = malloc( strlen( _("Track %i") ) + 20 );
373             sprintf( text.psz_string, _("Track %i"), val.i_int );
374         }
375     }
376
377     val.i_int = es->i_id;
378     var_Change( p_input, psz_var, VLC_VAR_ADDCHOICE, &val, &text );
379
380     free( text.psz_string );
381
382     var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
383 }
384
385 /* EsOutProgramSelect:
386  *  Select a program and update the object variable
387  */
388 static void EsOutProgramSelect( es_out_t *out, es_out_pgrm_t *p_pgrm )
389 {
390     es_out_sys_t      *p_sys = out->p_sys;
391     input_thread_t    *p_input = p_sys->p_input;
392     vlc_value_t       val;
393     int               i;
394
395     if( p_sys->p_pgrm == p_pgrm )
396         return; /* Nothing to do */
397
398     if( p_sys->p_pgrm )
399     {
400         es_out_pgrm_t *old = p_sys->p_pgrm;
401         msg_Dbg( p_input, "Unselecting program id=%d", old->i_id );
402
403         for( i = 0; i < p_sys->i_es; i++ )
404         {
405             if( p_sys->es[i]->p_pgrm == old && p_sys->es[i]->p_dec &&
406                 p_sys->i_mode != ES_OUT_MODE_ALL )
407                 EsUnselect( out, p_sys->es[i], VLC_TRUE );
408         }
409
410         p_sys->p_es_audio = NULL;
411         p_sys->p_es_sub = NULL;
412         p_sys->p_es_video = NULL;
413     }
414
415     msg_Dbg( p_input, "Selecting program id=%d", p_pgrm->i_id );
416
417     /* Mark it selected */
418     p_pgrm->b_selected = VLC_TRUE;
419
420     /* Switch master stream */
421     if( p_sys->p_pgrm && p_sys->p_pgrm->clock.b_master )
422     {
423         p_sys->p_pgrm->clock.b_master = VLC_FALSE;
424     }
425     p_pgrm->clock.b_master = VLC_TRUE;
426     p_sys->p_pgrm = p_pgrm;
427
428     /* Update "program" */
429     val.i_int = p_pgrm->i_id;
430     var_Change( p_input, "program", VLC_VAR_SETVALUE, &val, NULL );
431
432     /* Update "es-*" */
433     var_Change( p_input, "audio-es", VLC_VAR_CLEARCHOICES, NULL, NULL );
434     var_Change( p_input, "video-es", VLC_VAR_CLEARCHOICES, NULL, NULL );
435     var_Change( p_input, "spu-es",   VLC_VAR_CLEARCHOICES, NULL, NULL );
436     for( i = 0; i < p_sys->i_es; i++ )
437     {
438         if( p_sys->es[i]->p_pgrm == p_sys->p_pgrm )
439             EsOutESVarUpdate( out, p_sys->es[i], VLC_FALSE );
440         EsOutSelect( out, p_sys->es[i], VLC_FALSE );
441     }
442
443     var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
444 }
445
446 /* EsOutAddProgram:
447  *  Add a program
448  */
449 static es_out_pgrm_t *EsOutProgramAdd( es_out_t *out, int i_group )
450 {
451     es_out_sys_t      *p_sys = out->p_sys;
452     input_thread_t    *p_input = p_sys->p_input;
453     vlc_value_t       val;
454
455     es_out_pgrm_t *p_pgrm = malloc( sizeof( es_out_pgrm_t ) );
456
457     /* Init */
458     p_pgrm->i_id = i_group;
459     p_pgrm->i_es = 0;
460     p_pgrm->b_selected = VLC_FALSE;
461     input_ClockInit( &p_pgrm->clock, VLC_FALSE, p_input->input.i_cr_average );
462
463     /* Append it */
464     TAB_APPEND( p_sys->i_pgrm, p_sys->pgrm, p_pgrm );
465
466     /* Update "program" variable */
467     val.i_int = i_group;
468     var_Change( p_input, "program", VLC_VAR_ADDCHOICE, &val, NULL );
469
470     if( i_group == var_GetInteger( p_input, "program" ) )
471     {
472         EsOutProgramSelect( out, p_pgrm );
473     }
474     else
475     {
476         var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
477     }
478     return p_pgrm;
479 }
480
481 /* EsOutAdd:
482  *  Add an es_out
483  */
484 static es_out_id_t *EsOutAdd( es_out_t *out, es_format_t *fmt )
485 {
486     es_out_sys_t      *p_sys = out->p_sys;
487     input_thread_t    *p_input = p_sys->p_input;
488
489     es_out_id_t       *es = malloc( sizeof( es_out_id_t ) );
490     es_out_pgrm_t     *p_pgrm = NULL;
491     int i;
492
493     if( fmt->i_group < 0 )
494     {
495         msg_Err( p_input, "invalid group number" );
496         return NULL;
497     }
498
499     /* Search the program */
500     for( i = 0; i < p_sys->i_pgrm; i++ )
501     {
502         if( fmt->i_group == p_sys->pgrm[i]->i_id )
503         {
504             p_pgrm = p_sys->pgrm[i];
505             break;
506         }
507     }
508     if( p_pgrm == NULL )
509     {
510         /* Create a new one */
511         p_pgrm = EsOutProgramAdd( out, fmt->i_group );
512     }
513
514     /* Increase ref count for program */
515     p_pgrm->i_es++;
516
517     /* Set up ES */
518     if( fmt->i_id < 0 )
519         fmt->i_id = out->p_sys->i_id;
520     es->i_id = fmt->i_id;
521     es->p_pgrm = p_pgrm;
522     es_format_Copy( &es->fmt, fmt );
523     es->i_preroll_end = -1;
524
525     switch( fmt->i_cat )
526     {
527     case AUDIO_ES:
528         es->i_channel = p_sys->i_audio;
529         break;
530
531     case VIDEO_ES:
532         es->i_channel = p_sys->i_video;
533         break;
534
535     case SPU_ES:
536         es->i_channel = p_sys->i_sub;
537         break;
538
539     default:
540         es->i_channel = 0;
541         break;
542     }
543     es->psz_language = LanguageGetName( fmt->psz_language ); /* remember so we only need to do it once */
544     es->psz_language_code = LanguageGetCode( fmt->psz_language );
545     es->p_dec = NULL;
546
547     if( es->p_pgrm == p_sys->p_pgrm )
548         EsOutESVarUpdate( out, es, VLC_FALSE );
549
550     /* Select it if needed */
551     EsOutSelect( out, es, VLC_FALSE );
552
553
554     TAB_APPEND( out->p_sys->i_es, out->p_sys->es, es );
555     p_sys->i_id++;  /* always incremented */
556     switch( fmt->i_cat )
557     {
558         case AUDIO_ES:
559             p_sys->i_audio++;
560             break;
561         case SPU_ES:
562             p_sys->i_sub++;
563             break;
564         case VIDEO_ES:
565             p_sys->i_video++;
566             break;
567     }
568
569     EsOutAddInfo( out, es );
570
571     return es;
572 }
573
574 static void EsSelect( es_out_t *out, es_out_id_t *es )
575 {
576     es_out_sys_t   *p_sys = out->p_sys;
577     input_thread_t *p_input = p_sys->p_input;
578     vlc_value_t    val;
579     char           *psz_var;
580
581     if( es->p_dec )
582     {
583         msg_Warn( p_input, "ES 0x%x is already selected", es->i_id );
584         return;
585     }
586
587     if( es->fmt.i_cat == VIDEO_ES || es->fmt.i_cat == SPU_ES )
588     {
589         if( !var_GetBool( p_input, "video" ) ||
590             ( p_input->p_sout && !var_GetBool( p_input, "sout-video" ) ) )
591         {
592             msg_Dbg( p_input, "video is disabled, not selecting ES 0x%x",
593                      es->i_id );
594             return;
595         }
596     }
597     else if( es->fmt.i_cat == AUDIO_ES )
598     {
599         var_Get( p_input, "audio", &val );
600         if( !var_GetBool( p_input, "audio" ) ||
601             ( p_input->p_sout && !var_GetBool( p_input, "sout-audio" ) ) )
602         {
603             msg_Dbg( p_input, "audio is disabled, not selecting ES 0x%x",
604                      es->i_id );
605             return;
606         }
607     }
608
609     es->i_preroll_end = -1;
610     es->p_dec = input_DecoderNew( p_input, &es->fmt, VLC_FALSE );
611     if( es->p_dec == NULL || es->p_pgrm != p_sys->p_pgrm )
612         return;
613
614     if( es->fmt.i_cat == VIDEO_ES )
615         psz_var = "video-es";
616     else if( es->fmt.i_cat == AUDIO_ES )
617         psz_var = "audio-es";
618     else if( es->fmt.i_cat == SPU_ES )
619         psz_var = "spu-es";
620     else
621         return;
622
623     /* Mark it as selected */
624     val.i_int = es->i_id;
625     var_Change( p_input, psz_var, VLC_VAR_SETVALUE, &val, NULL );
626
627
628     var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
629 }
630
631 static void EsUnselect( es_out_t *out, es_out_id_t *es, vlc_bool_t b_update )
632 {
633     es_out_sys_t   *p_sys = out->p_sys;
634     input_thread_t *p_input = p_sys->p_input;
635     vlc_value_t    val;
636     char           *psz_var;
637
638     if( es->p_dec == NULL )
639     {
640         msg_Warn( p_input, "ES 0x%x is already unselected", es->i_id );
641         return;
642     }
643
644     input_DecoderDelete( es->p_dec );
645     es->p_dec = NULL;
646
647     if( !b_update )
648         return;
649
650     /* Update var */
651     if( es->p_dec == NULL )
652         return;
653     if( es->fmt.i_cat == VIDEO_ES )
654         psz_var = "video-es";
655     else if( es->fmt.i_cat == AUDIO_ES )
656         psz_var = "audio-es";
657     else if( es->fmt.i_cat == SPU_ES )
658         psz_var = "spu-es";
659     else
660         return;
661
662     /* Mark it as selected */
663     val.i_int = -1;
664     var_Change( p_input, psz_var, VLC_VAR_SETVALUE, &val, NULL );
665
666     var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
667 }
668
669 /**
670  * Select an ES given the current mode
671  * XXX: you need to take a the lock before (stream.stream_lock)
672  *
673  * \param out The es_out structure
674  * \param es es_out_id structure
675  * \param b_force ...
676  * \return nothing
677  */
678 static void EsOutSelect( es_out_t *out, es_out_id_t *es, vlc_bool_t b_force )
679 {
680     es_out_sys_t      *p_sys = out->p_sys;
681
682     int i_cat = es->fmt.i_cat;
683
684     if( !p_sys->b_active ||
685         ( !b_force && es->fmt.i_priority < 0 ) )
686     {
687         return;
688     }
689
690     if( p_sys->i_mode == ES_OUT_MODE_ALL || b_force )
691     {
692         if( !es->p_dec )
693             EsSelect( out, es );
694     }
695     else if( p_sys->i_mode == ES_OUT_MODE_PARTIAL )
696     {
697         vlc_value_t val;
698         int i;
699         var_Get( p_sys->p_input, "programs", &val );
700         for ( i = 0; i < val.p_list->i_count; i++ )
701         {
702             if ( val.p_list->p_values[i].i_int == es->p_pgrm->i_id || b_force )
703             {
704                 if( !es->p_dec )
705                     EsSelect( out, es );
706                 break;
707             }
708         }
709         var_Change( p_sys->p_input, "programs", VLC_VAR_FREELIST, &val, NULL );
710     }
711     else if( p_sys->i_mode == ES_OUT_MODE_AUTO )
712     {
713         int i_wanted  = -1;
714
715         if( es->p_pgrm != p_sys->p_pgrm )
716             return;
717
718         if( i_cat == AUDIO_ES )
719         {
720             int idx1 = LanguageArrayIndex( p_sys->ppsz_audio_language,
721                                      es->psz_language_code );
722
723             if( p_sys->p_es_audio &&
724                 p_sys->p_es_audio->fmt.i_priority >= es->fmt.i_priority )
725             {
726                 int idx2 = LanguageArrayIndex( p_sys->ppsz_audio_language,
727                                          p_sys->p_es_audio->psz_language_code );
728
729                 if( idx1 < 0 || ( idx2 >= 0 && idx2 <= idx1 ) )
730                     return;
731                 i_wanted = es->i_channel;
732             }
733             else
734             {
735                 /* Select audio if (no audio selected yet)
736                  * - no audio-language
737                  * - no audio code for the ES
738                  * - audio code in the requested list */
739                 if( idx1 >= 0 ||
740                     !strcmp( es->psz_language_code, "??" ) ||
741                     !p_sys->ppsz_audio_language )
742                     i_wanted = es->i_channel;
743             }
744
745             if( p_sys->i_audio_last >= 0 )
746                 i_wanted = p_sys->i_audio_last;
747         }
748         else if( i_cat == SPU_ES )
749         {
750             int idx1 = LanguageArrayIndex( p_sys->ppsz_sub_language,
751                                      es->psz_language_code );
752
753             if( p_sys->p_es_sub &&
754                 p_sys->p_es_sub->fmt.i_priority >= es->fmt.i_priority )
755             {
756                 int idx2 = LanguageArrayIndex( p_sys->ppsz_sub_language,
757                                          p_sys->p_es_sub->psz_language_code );
758
759                 msg_Dbg( p_sys->p_input, "idx1=%d(%s) idx2=%d(%s)",
760                         idx1, es->psz_language_code, idx2,
761                         p_sys->p_es_sub->psz_language_code );
762
763                 if( idx1 < 0 || ( idx2 >= 0 && idx2 <= idx1 ) )
764                     return;
765                 /* We found a SPU that matches our language request */
766                 i_wanted  = es->i_channel;
767             }
768             else if( idx1 >= 0 )
769             {
770                 msg_Dbg( p_sys->p_input, "idx1=%d(%s)",
771                         idx1, es->psz_language_code );
772
773                 i_wanted  = es->i_channel;
774             }
775             if( p_sys->i_sub_last >= 0 )
776                 i_wanted  = p_sys->i_sub_last;
777         }
778         else if( i_cat == VIDEO_ES )
779         {
780             i_wanted  = es->i_channel;
781         }
782
783         if( i_wanted == es->i_channel && es->p_dec == NULL )
784             EsSelect( out, es );
785     }
786
787     /* FIXME TODO handle priority here */
788     if( es->p_dec )
789     {
790         if( i_cat == AUDIO_ES )
791         {
792             if( p_sys->i_mode == ES_OUT_MODE_AUTO &&
793                 p_sys->p_es_audio &&
794                 p_sys->p_es_audio != es &&
795                 p_sys->p_es_audio->p_dec )
796             {
797                 EsUnselect( out, p_sys->p_es_audio, VLC_FALSE );
798             }
799             p_sys->p_es_audio = es;
800         }
801         else if( i_cat == SPU_ES )
802         {
803             if( p_sys->i_mode == ES_OUT_MODE_AUTO &&
804                 p_sys->p_es_sub &&
805                 p_sys->p_es_sub != es &&
806                 p_sys->p_es_sub->p_dec )
807             {
808                 EsUnselect( out, p_sys->p_es_sub, VLC_FALSE );
809             }
810             p_sys->p_es_sub = es;
811         }
812         else if( i_cat == VIDEO_ES )
813         {
814             p_sys->p_es_video = es;
815         }
816     }
817 }
818
819 /**
820  * Send a block for the given es_out
821  *
822  * \param out the es_out to send from
823  * \param es the es_out_id
824  * \param p_block the data block to send
825  */
826 static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
827 {
828     es_out_sys_t *p_sys = out->p_sys;
829     input_thread_t    *p_input = p_sys->p_input;
830     es_out_pgrm_t *p_pgrm = es->p_pgrm;
831     int64_t i_delay;
832
833     if( es->fmt.i_cat == AUDIO_ES )
834         i_delay = p_sys->i_audio_delay;
835     else if( es->fmt.i_cat == SPU_ES )
836         i_delay = p_sys->i_spu_delay;
837     else
838         i_delay = 0;
839
840     /* Mark preroll blocks */
841     if( es->i_preroll_end >= 0 )
842     {
843         int64_t i_date = p_block->i_pts;
844         if( i_date <= 0 )
845             i_date = p_block->i_dts;
846
847         if( i_date < es->i_preroll_end )
848             p_block->i_flags |= BLOCK_FLAG_PREROLL;
849         else
850             es->i_preroll_end = -1;
851     }
852
853     /* +11 -> avoid null value with non null dts/pts */
854     if( p_block->i_dts > 0 )
855     {
856         p_block->i_dts =
857             input_ClockGetTS( p_input, &p_pgrm->clock,
858                               ( p_block->i_dts + 11 ) * 9 / 100 ) + i_delay;
859     }
860     if( p_block->i_pts > 0 )
861     {
862         p_block->i_pts =
863             input_ClockGetTS( p_input, &p_pgrm->clock,
864                               ( p_block->i_pts + 11 ) * 9 / 100 ) + i_delay;
865     }
866     if ( es->fmt.i_codec == VLC_FOURCC( 't', 'e', 'l', 'x' ) )
867     {
868         mtime_t current_date = mdate();
869         if( !p_block->i_pts
870                || p_block->i_pts > current_date + 10000000
871                || current_date > p_block->i_pts )
872         {
873             /* ETSI EN 300 472 Annex A : do not take into account the PTS
874              * for teletext streams. */
875             p_block->i_pts = current_date + 400000
876                                + p_input->i_pts_delay + i_delay;
877         }
878     }
879
880     p_block->i_rate = p_input->i_rate;
881
882     /* TODO handle mute */
883     if( es->p_dec && ( es->fmt.i_cat != AUDIO_ES ||
884         p_input->i_rate == INPUT_RATE_DEFAULT ) )
885     {
886         input_DecoderDecode( es->p_dec, p_block );
887     }
888     else
889     {
890         block_Release( p_block );
891     }
892
893     return VLC_SUCCESS;
894 }
895
896 /*****************************************************************************
897  * EsOutDel:
898  *****************************************************************************/
899 static void EsOutDel( es_out_t *out, es_out_id_t *es )
900 {
901     es_out_sys_t *p_sys = out->p_sys;
902
903     /* We don't try to reselect */
904     if( es->p_dec )
905         EsUnselect( out, es, es->p_pgrm == p_sys->p_pgrm );
906
907     if( es->p_pgrm == p_sys->p_pgrm )
908         EsOutESVarUpdate( out, es, VLC_TRUE );
909
910     TAB_REMOVE( p_sys->i_es, p_sys->es, es );
911
912     es->p_pgrm->i_es--;
913     if( es->p_pgrm->i_es == 0 )
914     {
915         msg_Warn( p_sys->p_input, "Program doesn't contain anymore ES, "
916                   "TODO cleaning ?" );
917     }
918
919     if( p_sys->p_es_audio == es ) p_sys->p_es_audio = NULL;
920     if( p_sys->p_es_video == es ) p_sys->p_es_video = NULL;
921     if( p_sys->p_es_sub   == es ) p_sys->p_es_sub   = NULL;
922
923     switch( es->fmt.i_cat )
924     {
925         case AUDIO_ES:
926             p_sys->i_audio--;
927             break;
928         case SPU_ES:
929             p_sys->i_sub--;
930             break;
931         case VIDEO_ES:
932             p_sys->i_video--;
933             break;
934     }
935
936     if( es->psz_language )
937         free( es->psz_language );
938     if( es->psz_language_code )
939         free( es->psz_language_code );
940
941     es_format_Clean( &es->fmt );
942
943     free( es );
944 }
945
946 /**
947  * Control query handler
948  *
949  * \param out the es_out to control
950  * \param i_query A es_out query as defined in include/ninput.h
951  * \param args a variable list of arguments for the query
952  * \return VLC_SUCCESS or an error code
953  */
954 static int EsOutControl( es_out_t *out, int i_query, va_list args )
955 {
956     es_out_sys_t *p_sys = out->p_sys;
957     vlc_bool_t  b, *pb;
958     int         i, *pi;
959
960     es_out_id_t *es;
961
962     switch( i_query )
963     {
964         case ES_OUT_SET_ES_STATE:
965             es = (es_out_id_t*) va_arg( args, es_out_id_t * );
966             b = (vlc_bool_t) va_arg( args, vlc_bool_t );
967             if( b && es->p_dec == NULL )
968             {
969                 EsSelect( out, es );
970                 return es->p_dec ? VLC_SUCCESS : VLC_EGENERIC;
971             }
972             else if( !b && es->p_dec )
973             {
974                 EsUnselect( out, es, es->p_pgrm == p_sys->p_pgrm );
975                 return VLC_SUCCESS;
976             }
977             return VLC_SUCCESS;
978
979         case ES_OUT_GET_ES_STATE:
980             es = (es_out_id_t*) va_arg( args, es_out_id_t * );
981             pb = (vlc_bool_t*) va_arg( args, vlc_bool_t * );
982
983             *pb = es->p_dec ? VLC_TRUE : VLC_FALSE;
984             return VLC_SUCCESS;
985
986         case ES_OUT_SET_ACTIVE:
987         {
988             b = (vlc_bool_t) va_arg( args, vlc_bool_t );
989             p_sys->b_active = b;
990             /* Needed ? */
991             if( b )
992                 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
993             return VLC_SUCCESS;
994         }
995
996         case ES_OUT_GET_ACTIVE:
997             pb = (vlc_bool_t*) va_arg( args, vlc_bool_t * );
998             *pb = p_sys->b_active;
999             return VLC_SUCCESS;
1000
1001         case ES_OUT_SET_MODE:
1002             i = (int) va_arg( args, int );
1003             if( i == ES_OUT_MODE_NONE || i == ES_OUT_MODE_ALL ||
1004                 i == ES_OUT_MODE_AUTO || i == ES_OUT_MODE_PARTIAL )
1005             {
1006                 p_sys->i_mode = i;
1007
1008                 /* Reapply policy mode */
1009                 for( i = 0; i < p_sys->i_es; i++ )
1010                 {
1011                     if( p_sys->es[i]->p_dec )
1012                     {
1013                         EsUnselect( out, p_sys->es[i],
1014                                     p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
1015                     }
1016                 }
1017                 for( i = 0; i < p_sys->i_es; i++ )
1018                 {
1019                     EsOutSelect( out, p_sys->es[i], VLC_FALSE );
1020                 }
1021                 return VLC_SUCCESS;
1022             }
1023             return VLC_EGENERIC;
1024
1025         case ES_OUT_GET_MODE:
1026             pi = (int*) va_arg( args, int* );
1027             *pi = p_sys->i_mode;
1028             return VLC_SUCCESS;
1029
1030         case ES_OUT_SET_ES:
1031             es = (es_out_id_t*) va_arg( args, es_out_id_t * );
1032             /* Special case NULL, NULL+i_cat */
1033             if( es == NULL )
1034             {
1035                 for( i = 0; i < p_sys->i_es; i++ )
1036                 {
1037                     if( p_sys->es[i]->p_dec )
1038                         EsUnselect( out, p_sys->es[i],
1039                                     p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
1040                 }
1041             }
1042             else if( es == (es_out_id_t*)((uint8_t*)NULL+AUDIO_ES) )
1043             {
1044                 for( i = 0; i < p_sys->i_es; i++ )
1045                 {
1046                     if( p_sys->es[i]->p_dec &&
1047                         p_sys->es[i]->fmt.i_cat == AUDIO_ES )
1048                         EsUnselect( out, p_sys->es[i],
1049                                     p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
1050                 }
1051             }
1052             else if( es == (es_out_id_t*)((uint8_t*)NULL+VIDEO_ES) )
1053             {
1054                 for( i = 0; i < p_sys->i_es; i++ )
1055                 {
1056                     if( p_sys->es[i]->p_dec &&
1057                         p_sys->es[i]->fmt.i_cat == VIDEO_ES )
1058                         EsUnselect( out, p_sys->es[i],
1059                                     p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
1060                 }
1061             }
1062             else if( es == (es_out_id_t*)((uint8_t*)NULL+SPU_ES) )
1063             {
1064                 for( i = 0; i < p_sys->i_es; i++ )
1065                 {
1066                     if( p_sys->es[i]->p_dec &&
1067                         p_sys->es[i]->fmt.i_cat == SPU_ES )
1068                         EsUnselect( out, p_sys->es[i],
1069                                     p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
1070                 }
1071             }
1072             else
1073             {
1074                 for( i = 0; i < p_sys->i_es; i++ )
1075                 {
1076                     if( es == p_sys->es[i] )
1077                     {
1078                         EsOutSelect( out, es, VLC_TRUE );
1079                         break;
1080                     }
1081                 }
1082             }
1083             return VLC_SUCCESS;
1084
1085         case ES_OUT_SET_PCR:
1086         case ES_OUT_SET_GROUP_PCR:
1087         {
1088             es_out_pgrm_t *p_pgrm = NULL;
1089             int            i_group = 0;
1090             int64_t        i_pcr;
1091
1092             if( i_query == ES_OUT_SET_PCR )
1093             {
1094                 p_pgrm = p_sys->p_pgrm;
1095             }
1096             else
1097             {
1098                 int i;
1099                 i_group = (int)va_arg( args, int );
1100                 for( i = 0; i < p_sys->i_pgrm; i++ )
1101                 {
1102                     if( p_sys->pgrm[i]->i_id == i_group )
1103                     {
1104                         p_pgrm = p_sys->pgrm[i];
1105                         break;
1106                     }
1107                 }
1108             }
1109             if( p_pgrm == NULL )
1110                 p_pgrm = EsOutProgramAdd( out, i_group );   /* Create it */
1111
1112             i_pcr = (int64_t)va_arg( args, int64_t );
1113             /* search program */
1114             /* 11 is a vodoo trick to avoid non_pcr*9/100 to be null */
1115             input_ClockSetPCR( p_sys->p_input, &p_pgrm->clock,
1116                                (i_pcr + 11 ) * 9 / 100);
1117             return VLC_SUCCESS;
1118         }
1119
1120         case ES_OUT_RESET_PCR:
1121             for( i = 0; i < p_sys->i_pgrm; i++ )
1122             {
1123                 p_sys->pgrm[i]->clock.i_synchro_state =  SYNCHRO_REINIT;
1124                 p_sys->pgrm[i]->clock.last_pts = 0;
1125             }
1126             return VLC_SUCCESS;
1127
1128         case ES_OUT_GET_TS:
1129             if( p_sys->p_pgrm )
1130             {
1131                 int64_t i_ts = (int64_t)va_arg( args, int64_t );
1132                 int64_t *pi_ts = (int64_t *)va_arg( args, int64_t * );
1133                 *pi_ts = input_ClockGetTS( p_sys->p_input,
1134                                            &p_sys->p_pgrm->clock,
1135                                            ( i_ts + 11 ) * 9 / 100 );
1136                 return VLC_SUCCESS;
1137             }
1138             return VLC_EGENERIC;
1139
1140         case ES_OUT_GET_GROUP:
1141             pi = (int*) va_arg( args, int* );
1142             if( p_sys->p_pgrm )
1143                 *pi = p_sys->p_pgrm->i_id;
1144             else
1145                 *pi = -1;    /* FIXME */
1146             return VLC_SUCCESS;
1147
1148         case ES_OUT_SET_GROUP:
1149         {
1150             int j;
1151             i = (int) va_arg( args, int );
1152             for( j = 0; j < p_sys->i_pgrm; j++ )
1153             {
1154                 es_out_pgrm_t *p_pgrm = p_sys->pgrm[j];
1155                 if( p_pgrm->i_id == i )
1156                 {
1157                     EsOutProgramSelect( out, p_pgrm );
1158                     return VLC_SUCCESS;
1159                 }
1160             }
1161             return VLC_EGENERIC;
1162         }
1163
1164         case ES_OUT_SET_FMT:
1165         {
1166             /* This ain't pretty but is need by some demuxers (eg. Ogg )
1167              * to update the p_extra data */
1168             es_format_t *p_fmt;
1169             es = (es_out_id_t*) va_arg( args, es_out_id_t * );
1170             p_fmt = (es_format_t*) va_arg( args, es_format_t * );
1171             if( es == NULL ) return VLC_EGENERIC;
1172
1173             if( p_fmt->i_extra )
1174             {
1175                 es->fmt.i_extra = p_fmt->i_extra;
1176                 es->fmt.p_extra = realloc( es->fmt.p_extra, p_fmt->i_extra );
1177                 memcpy( es->fmt.p_extra, p_fmt->p_extra, p_fmt->i_extra );
1178
1179                 if( !es->p_dec ) return VLC_SUCCESS;
1180
1181 #if 1
1182                 input_DecoderDelete( es->p_dec );
1183                 es->p_dec = input_DecoderNew( p_sys->p_input,
1184                                               &es->fmt, VLC_FALSE );
1185
1186 #else
1187                 es->p_dec->fmt_in.i_extra = p_fmt->i_extra;
1188                 es->p_dec->fmt_in.p_extra =
1189                     realloc( es->p_dec->fmt_in.p_extra, p_fmt->i_extra );
1190                 memcpy( es->p_dec->fmt_in.p_extra,
1191                         p_fmt->p_extra, p_fmt->i_extra );
1192 #endif
1193             }
1194
1195             return VLC_SUCCESS;
1196         }
1197
1198         case ES_OUT_SET_NEXT_DISPLAY_TIME:
1199         {
1200             int64_t i_date;
1201
1202             es = (es_out_id_t*) va_arg( args, es_out_id_t * );
1203             i_date = (int64_t)va_arg( args, int64_t );
1204
1205             if( !es || !es->p_dec )
1206                 return VLC_EGENERIC;
1207
1208             es->i_preroll_end = i_date;
1209             input_DecoderPreroll( es->p_dec, i_date );
1210
1211             return VLC_SUCCESS;
1212         }
1213
1214         default:
1215             msg_Err( p_sys->p_input, "unknown query in es_out_Control" );
1216             return VLC_EGENERIC;
1217     }
1218 }
1219
1220 /****************************************************************************
1221  * LanguageGetName: try to expend iso639 into plain name
1222  ****************************************************************************/
1223 static char *LanguageGetName( const char *psz_code )
1224 {
1225     const iso639_lang_t *pl;
1226
1227     if( psz_code == NULL )
1228     {
1229         return strdup( "" );
1230     }
1231
1232     if( strlen( psz_code ) == 2 )
1233     {
1234         pl = GetLang_1( psz_code );
1235     }
1236     else if( strlen( psz_code ) == 3 )
1237     {
1238         pl = GetLang_2B( psz_code );
1239         if( !strcmp( pl->psz_iso639_1, "??" ) )
1240         {
1241             pl = GetLang_2T( psz_code );
1242         }
1243     }
1244     else
1245     {
1246         return strdup( psz_code );
1247     }
1248
1249     if( !strcmp( pl->psz_iso639_1, "??" ) )
1250     {
1251        return strdup( psz_code );
1252     }
1253     else
1254     {
1255         if( *pl->psz_native_name )
1256         {
1257             return strdup( pl->psz_native_name );
1258         }
1259         return strdup( pl->psz_eng_name );
1260     }
1261 }
1262
1263 /* Get a 2 char code */
1264 static char *LanguageGetCode( const char *psz_lang )
1265 {
1266     const iso639_lang_t *pl;
1267
1268     if( psz_lang == NULL || *psz_lang == '\0' )
1269         return strdup("??");
1270
1271     for( pl = p_languages; pl->psz_iso639_1 != NULL; pl++ )
1272     {
1273         if( !strcasecmp( pl->psz_eng_name, psz_lang ) ||
1274             !strcasecmp( pl->psz_native_name, psz_lang ) ||
1275             !strcasecmp( pl->psz_iso639_1, psz_lang ) ||
1276             !strcasecmp( pl->psz_iso639_2T, psz_lang ) ||
1277             !strcasecmp( pl->psz_iso639_2B, psz_lang ) )
1278             break;
1279     }
1280
1281     if( pl->psz_iso639_1 != NULL )
1282         return strdup( pl->psz_iso639_1 );
1283
1284     return strdup("??");
1285 }
1286
1287 static char **LanguageSplit( const char *psz_langs )
1288 {
1289     char *psz_dup;
1290     char *psz_parser;
1291     char **ppsz = NULL;
1292     int i_psz = 0;
1293
1294     if( psz_langs == NULL )
1295         return NULL;
1296
1297     psz_parser = psz_dup = strdup(psz_langs);
1298
1299     while( psz_parser && *psz_parser )
1300     {
1301         char *psz;
1302         char *psz_code;
1303
1304         psz = strchr(psz_parser, ',' );
1305         if( psz )
1306         {
1307             *psz++ = '\0';
1308         }
1309
1310         psz_code = LanguageGetCode( psz_parser );
1311         if( strcmp( psz_code, "??" ) )
1312         {
1313             TAB_APPEND( i_psz, ppsz, psz_code );
1314         }
1315
1316         psz_parser = psz;
1317     }
1318
1319     if( i_psz )
1320     {
1321         TAB_APPEND( i_psz, ppsz, NULL );
1322     }
1323
1324     return ppsz;
1325 }
1326
1327 static int LanguageArrayIndex( char **ppsz_langs, char *psz_lang )
1328 {
1329     int i;
1330
1331     if( !ppsz_langs || !psz_lang )
1332         return -1;
1333
1334     for( i = 0; ppsz_langs[i]; i++ )
1335         if( !strcasecmp( ppsz_langs[i], psz_lang ) )
1336             return i;
1337
1338     return -1;
1339 }
1340
1341 /****************************************************************************
1342  * EsOutAddInfo:
1343  * - add meta info to the playlist item
1344  ****************************************************************************/
1345 static void EsOutAddInfo( es_out_t *out, es_out_id_t *es )
1346 {
1347     es_out_sys_t   *p_sys = out->p_sys;
1348     input_thread_t *p_input = p_sys->p_input;
1349     es_format_t    *fmt = &es->fmt;
1350     char           *psz_cat;
1351
1352     /* Add stream info */
1353     asprintf( &psz_cat, _("Stream %d"), out->p_sys->i_id - 1 );
1354
1355     input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Codec"),
1356                    "%.4s", (char*)&fmt->i_codec );
1357
1358     input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Language"),
1359                    "%s", es->psz_language );
1360
1361     /* Add information */
1362     switch( fmt->i_cat )
1363     {
1364     case AUDIO_ES:
1365         input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1366                        _("Type"), _("Audio") );
1367
1368         if( fmt->audio.i_channels > 0 )
1369             input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Channels"),
1370                            "%d", fmt->audio.i_channels );
1371
1372         if( fmt->audio.i_rate > 0 )
1373             input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Sample rate"),
1374                            _("%d Hz"), fmt->audio.i_rate );
1375
1376         if( fmt->audio.i_bitspersample > 0 )
1377             input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1378                            _("Bits per sample"), "%d",
1379                            fmt->audio.i_bitspersample );
1380
1381         if( fmt->i_bitrate > 0 )
1382             input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Bitrate"),
1383                            _("%d kb/s"), fmt->i_bitrate / 1000 );
1384         break;
1385
1386     case VIDEO_ES:
1387         input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1388                        _("Type"), _("Video") );
1389
1390         if( fmt->video.i_width > 0 && fmt->video.i_height > 0 )
1391             input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1392                            _("Resolution"), "%dx%d",
1393                            fmt->video.i_width, fmt->video.i_height );
1394
1395         if( fmt->video.i_visible_width > 0 &&
1396             fmt->video.i_visible_height > 0 )
1397             input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1398                            _("Display resolution"), "%dx%d",
1399                            fmt->video.i_visible_width,
1400                            fmt->video.i_visible_height);
1401         break;
1402
1403     case SPU_ES:
1404         input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1405                        _("Type"), _("Subtitle") );
1406         break;
1407
1408     default:
1409         break;
1410     }
1411
1412     free( psz_cat );
1413 }