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