]> git.sesse.net Git - vlc/blob - src/input/es_out.c
* all: begin to introduce access_t (nothing working yet).
[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 "vlc_playlist.h"
34 #include "codecs.h"
35 #include "iso_lang.h"
36
37 /*****************************************************************************
38  * Local prototypes
39  *****************************************************************************/
40 struct es_out_id_t
41 {
42     int             i_channel;
43     es_descriptor_t *p_es;
44 };
45
46 struct es_out_sys_t
47 {
48     input_thread_t *p_input;
49     vlc_bool_t      b_convert_ts_auto;  /* automatically convert TimeStamp */
50
51     /* all es */
52     int         i_id;
53
54     int         i_es;
55     es_out_id_t **es;
56
57     /* mode gestion */
58     vlc_bool_t  b_active;
59     int         i_mode;
60
61     /* es count */
62     int         i_audio;
63     int         i_video;
64     int         i_sub;
65
66     /* es to select */
67     int         i_audio_last;
68     int         i_sub_last;
69
70     /* current main es */
71     es_out_id_t *p_es_audio;
72     es_out_id_t *p_es_video;
73     es_out_id_t *p_es_sub;
74 };
75
76 static es_out_id_t *EsOutAdd    ( es_out_t *, es_format_t * );
77 static int          EsOutSend   ( es_out_t *, es_out_id_t *, block_t * );
78 static void         EsOutDel    ( es_out_t *, es_out_id_t * );
79 static int          EsOutControl( es_out_t *, int i_query, va_list );
80
81 static char *LanguageGetName( const char *psz_code );
82
83 /**
84  * Create a new es_out structure
85  *
86  * \param p_input The related input thread
87  * \return the new es_out_t
88  */
89 es_out_t *input_EsOutNew( input_thread_t *p_input )
90 {
91     es_out_t     *out = malloc( sizeof( es_out_t ) );
92     es_out_sys_t *p_sys = malloc( sizeof( es_out_sys_t ) );
93     vlc_value_t  val;
94
95     out->pf_add     = EsOutAdd;
96     out->pf_send    = EsOutSend;
97     out->pf_del     = EsOutDel;
98     out->pf_control = EsOutControl;
99     out->p_sys      = p_sys;
100
101     p_sys->p_input = p_input;
102     p_sys->b_convert_ts_auto = VLC_TRUE;
103
104     p_sys->b_active = VLC_FALSE;
105     p_sys->i_mode   = ES_OUT_MODE_AUTO;
106
107     p_sys->i_id    = 1;
108
109     p_sys->i_es    = 0;
110     p_sys->es      = NULL;
111
112     p_sys->i_audio = 0;
113     p_sys->i_video = 0;
114     p_sys->i_sub   = 0;
115
116     var_Get( p_input, "audio-channel", &val );
117     p_sys->i_audio_last = val.i_int;
118
119     var_Get( p_input, "spu-channel", &val );
120     p_sys->i_sub_last = val.i_int;
121
122     p_sys->p_es_audio = NULL;
123     p_sys->p_es_video = NULL;
124     p_sys->p_es_sub   = NULL;
125
126     return out;
127 }
128
129 /**
130  * Deletes an es_out structure
131  *
132  * \param out  the es_out structure to destroy
133  * \return nothing
134  */
135 void input_EsOutDelete( es_out_t *out )
136 {
137     es_out_sys_t *p_sys = out->p_sys;
138     int i;
139
140     for( i = 0; i < p_sys->i_es; i++ )
141     {
142         free( p_sys->es[i] );
143     }
144     if( p_sys->es )
145     {
146         free( p_sys->es );
147     }
148     free( p_sys );
149     free( out );
150 }
151
152 /**
153  * Add a program
154  *
155  * \param out the es_out
156  * \param i_group ...
157  * \return a program descriptor for the new program
158  */
159 static pgrm_descriptor_t *EsOutAddProgram( es_out_t *out, int i_group )
160 {
161     input_thread_t    *p_input = out->p_sys->p_input;
162     pgrm_descriptor_t *p_pgrm;
163     es_descriptor_t   *p_pmt;
164
165     /* FIXME we should use a object variable but a lot of place in src/input
166      * have to be changed */
167     int               i_select = config_GetInt( p_input, "program" );
168
169     /* create it */
170     p_pgrm = input_AddProgram( p_input, i_group, 0 );
171
172     /* XXX welcome to kludge, add a dummy es, if you want to understand
173      * why have a look at input_SetProgram. Basicaly, it assume the first
174      * es to be the PMT, how that is stupid, nevertheless it is needed for
175      * the old ts demuxer */
176     p_pmt = input_AddES( p_input, p_pgrm, 0, UNKNOWN_ES, NULL, 0 );
177     p_pmt->i_fourcc = VLC_FOURCC( 'n', 'u', 'l', 'l' );
178
179     /* Select i_select or the first by default */
180     if( p_input->stream.p_selected_program == NULL &&
181         ( i_select <= 0 || i_select == i_group ) )
182     {
183         p_input->stream.p_selected_program = p_pgrm;
184     }
185
186     return p_pgrm;
187 }
188
189 /**
190  * Select an ES given the current mode
191  * XXX: you need to take a the lock before (stream.stream_lock)
192  *
193  * \param out The es_out structure
194  * \param es es_out_id structure
195  * \param b_force ...
196  * \return nothing
197  */
198 static void EsOutSelect( es_out_t *out, es_out_id_t *es, vlc_bool_t b_force )
199 {
200     es_out_sys_t      *p_sys = out->p_sys;
201     input_thread_t    *p_input = p_sys->p_input;
202
203     int i_cat = es->p_es->i_cat;
204
205     if( !p_sys->b_active ||
206         ( !b_force && es->p_es->fmt.i_priority < 0 ) )
207     {
208         return;
209     }
210
211     if( p_sys->i_mode == ES_OUT_MODE_ALL || b_force )
212     {
213         if( !es->p_es->p_dec )
214         {
215             input_SelectES( p_input, es->p_es );
216         }
217     }
218     else if( p_sys->i_mode == ES_OUT_MODE_AUTO )
219     {
220         int i_wanted  = -1;
221
222         if( es->p_es->p_pgrm != NULL &&
223             es->p_es->p_pgrm != p_input->stream.p_selected_program )
224         {
225             return;
226         }
227
228         if( i_cat == AUDIO_ES )
229         {
230             if( p_sys->p_es_audio &&
231                 p_sys->p_es_audio->p_es->fmt.i_priority >=
232                     es->p_es->fmt.i_priority )
233             {
234                 return;
235             }
236             i_wanted  = p_sys->i_audio_last >= 0 ?
237                             p_sys->i_audio_last : es->i_channel;
238         }
239         else if( i_cat == SPU_ES )
240         {
241             if( p_sys->p_es_sub &&
242                 p_sys->p_es_sub->p_es->fmt.i_priority >=
243                     es->p_es->fmt.i_priority )
244             {
245                 return;
246             }
247             i_wanted  = p_sys->i_sub_last;
248         }
249         else if( i_cat == VIDEO_ES )
250         {
251             i_wanted  = es->i_channel;
252         }
253
254         if( i_wanted == es->i_channel && es->p_es->p_dec == NULL )
255         {
256             input_SelectES( p_input, es->p_es );
257         }
258     }
259
260     /* FIXME TODO handle priority here */
261     if( es->p_es->p_dec )
262     {
263         if( i_cat == AUDIO_ES )
264         {
265             if( p_sys->i_mode == ES_OUT_MODE_AUTO &&
266                 p_sys->p_es_audio && p_sys->p_es_audio->p_es->p_dec )
267             {
268                 input_UnselectES( p_input, p_sys->p_es_audio->p_es );
269             }
270             p_sys->p_es_audio = es;
271         }
272         else if( i_cat == SPU_ES )
273         {
274             if( p_sys->i_mode == ES_OUT_MODE_AUTO &&
275                 p_sys->p_es_sub && p_sys->p_es_sub->p_es->p_dec )
276             {
277                 input_UnselectES( p_input, p_sys->p_es_sub->p_es );
278             }
279             p_sys->p_es_sub = es;
280         }
281         else if( i_cat == VIDEO_ES )
282         {
283             p_sys->p_es_video = es;
284         }
285     }
286 }
287
288 /**
289  * Add an es_out
290  *
291  * \param out the es_out to add
292  * \param fmt the es_format of the es_out
293  * \return an es_out id
294  */
295 static es_out_id_t *EsOutAdd( es_out_t *out, es_format_t *fmt )
296 {
297     es_out_sys_t      *p_sys = out->p_sys;
298     input_thread_t    *p_input = p_sys->p_input;
299     es_out_id_t       *es = malloc( sizeof( es_out_id_t ) );
300     pgrm_descriptor_t *p_pgrm = NULL;
301     char              psz_cat[sizeof( _("Stream ") ) + 10];
302     char              *psz_description;
303
304     vlc_mutex_lock( &p_input->stream.stream_lock );
305     if( fmt->i_group >= 0 )
306     {
307         /* search program */
308         p_pgrm = input_FindProgram( p_input, fmt->i_group );
309
310         if( p_pgrm == NULL )
311         {
312             /* Create it */
313             p_pgrm = EsOutAddProgram( out, fmt->i_group );
314         }
315     }
316     if( fmt->i_id < 0 )
317     {
318         fmt->i_id = out->p_sys->i_id - 1;
319     }
320
321     psz_description = LanguageGetName( fmt->psz_language );
322     es->p_es = input_AddES( p_input, p_pgrm, fmt->i_id + 1,
323                             fmt->i_cat, psz_description, 0 );
324     es->p_es->i_stream_id = fmt->i_id;
325     es->p_es->i_fourcc = fmt->i_codec;
326
327     switch( fmt->i_cat )
328     {
329     case AUDIO_ES:
330         es->i_channel = p_sys->i_audio;
331         break;
332
333     case VIDEO_ES:
334         es->i_channel = p_sys->i_video;
335         break;
336
337     case SPU_ES:
338         es->i_channel = p_sys->i_sub;
339         break;
340
341     default:
342         es->i_channel = 0;
343         break;
344     }
345
346     /* Add stream info */
347     vlc_mutex_unlock( &p_input->stream.stream_lock );
348     sprintf( psz_cat, _("Stream %d"), out->p_sys->i_id - 1 );
349
350     input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Codec"),
351                    "%.4s", (char*)&fmt->i_codec );
352
353     if( *psz_description )
354         input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Language"),
355                        "%s", psz_description );
356
357     if( fmt->psz_description && *fmt->psz_description )
358         input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Description"),
359                        "%s", fmt->psz_description );
360
361     /* Add information */
362     switch( fmt->i_cat )
363     {
364     case AUDIO_ES:
365         input_Control( p_input, INPUT_ADD_INFO, psz_cat,
366                        _("Type"), _("Audio") );
367
368         if( fmt->audio.i_channels > 0 )
369             input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Channels"),
370                            "%d", fmt->audio.i_channels );
371
372         if( fmt->audio.i_rate > 0 )
373             input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Sample rate"),
374                            _("%d Hz"), fmt->audio.i_rate );
375
376         if( fmt->audio.i_bitspersample > 0 )
377             input_Control( p_input, INPUT_ADD_INFO, psz_cat,
378                            _("Bits per sample"), "%d",
379                            fmt->audio.i_bitspersample );
380
381         if( fmt->i_bitrate > 0 )
382             input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Bitrate"),
383                            _("%d bps"), fmt->i_bitrate );
384         break;
385
386     case VIDEO_ES:
387         input_Control( p_input, INPUT_ADD_INFO, psz_cat,
388                        _("Type"), _("Video") );
389
390         if( fmt->video.i_width > 0 && fmt->video.i_height > 0 )
391             input_Control( p_input, INPUT_ADD_INFO, psz_cat,
392                            _("Resolution"), "%dx%d",
393                            fmt->video.i_width, fmt->video.i_height );
394
395         if( fmt->video.i_visible_width > 0 &&
396             fmt->video.i_visible_height > 0 )
397             input_Control( p_input, INPUT_ADD_INFO, psz_cat,
398                            _("Display resolution"), "%dx%d",
399                            fmt->video.i_visible_width,
400                            fmt->video.i_visible_height);
401         break;
402
403     case SPU_ES:
404         input_Control( p_input, INPUT_ADD_INFO, psz_cat,
405                        _("Type"), _("Subtitle") );
406         break;
407
408     default:
409         break;
410     }
411
412     vlc_mutex_lock( &p_input->stream.stream_lock );
413     free( psz_description );
414
415     es_format_Copy( &es->p_es->fmt, fmt );
416
417     /* Apply mode
418      * XXX change that when we do group too */
419     if( 1 )
420     {
421         EsOutSelect( out, es, VLC_FALSE );
422     }
423     vlc_mutex_unlock( &p_input->stream.stream_lock );
424
425     TAB_APPEND( out->p_sys->i_es, out->p_sys->es, es );
426     p_sys->i_id++;  /* always incremented */
427     switch( fmt->i_cat )
428     {
429         case AUDIO_ES:
430             p_sys->i_audio++;
431             break;
432         case SPU_ES:
433             p_sys->i_sub++;
434             break;
435         case VIDEO_ES:
436             p_sys->i_video++;
437             break;
438     }
439
440     return es;
441 }
442
443 /**
444  * Send a block for the given es_out
445  *
446  * \param out the es_out to send from
447  * \param es the es_out_id
448  * \param p_block the data block to send
449  */
450 static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
451 {
452     es_out_sys_t *p_sys = out->p_sys;
453
454     if( p_sys->b_convert_ts_auto )
455     {
456         pgrm_descriptor_t *p_pgrm = es->p_es->p_pgrm;
457         input_thread_t    *p_input = p_sys->p_input;
458
459         if( p_pgrm == NULL )
460         {
461             p_pgrm = p_sys->p_input->stream.p_selected_program;
462         }
463
464         /* +11 -> avoid null value with non null dts/pts */
465         if( p_block->i_dts > 0 && p_pgrm )
466         {
467             p_block->i_dts =
468                 input_ClockGetTS( p_input, p_pgrm, ( p_block->i_dts + 11 ) * 9 / 100 );
469         }
470         if( p_block->i_pts > 0 && p_pgrm )
471         {
472             p_block->i_pts =
473                 input_ClockGetTS( p_input, p_pgrm, ( p_block->i_pts + 11 )* 9 / 100 );
474         }
475     }
476
477     vlc_mutex_lock( &out->p_sys->p_input->stream.stream_lock );
478     p_block->i_rate = out->p_sys->p_input->stream.control.i_rate;
479     if( es->p_es->p_dec &&
480         (es->p_es->i_cat!=AUDIO_ES || !p_sys->p_input->stream.control.b_mute) )
481     {
482         vlc_mutex_unlock( &out->p_sys->p_input->stream.stream_lock );
483         input_DecodeBlock( es->p_es->p_dec, p_block );
484     }
485     else
486     {
487         vlc_mutex_unlock( &out->p_sys->p_input->stream.stream_lock );
488         block_Release( p_block );
489     }
490
491     return VLC_SUCCESS;
492 }
493
494 /*****************************************************************************
495  * EsOutDel:
496  *****************************************************************************/
497 static void EsOutDel( es_out_t *out, es_out_id_t *es )
498 {
499     es_out_sys_t *p_sys = out->p_sys;
500
501     TAB_REMOVE( p_sys->i_es, p_sys->es, es );
502
503     switch( es->p_es->i_cat )
504     {
505         case AUDIO_ES:
506             p_sys->i_audio--;
507             break;
508         case SPU_ES:
509             p_sys->i_sub--;
510             break;
511         case VIDEO_ES:
512             p_sys->i_video--;
513             break;
514     }
515
516     /* We don't try to reselect */
517     vlc_mutex_lock( &p_sys->p_input->stream.stream_lock );
518     if( es->p_es->p_dec )
519     {
520         input_UnselectES( p_sys->p_input, es->p_es );
521     }
522
523     if( es->p_es->p_waveformatex )
524     {
525         free( es->p_es->p_waveformatex );
526         es->p_es->p_waveformatex = NULL;
527     }
528     if( es->p_es->p_bitmapinfoheader )
529     {
530         free( es->p_es->p_bitmapinfoheader );
531         es->p_es->p_bitmapinfoheader = NULL;
532     }
533     input_DelES( p_sys->p_input, es->p_es );
534
535     if( p_sys->p_es_audio == es ) p_sys->p_es_audio = NULL;
536     if( p_sys->p_es_video == es ) p_sys->p_es_video = NULL;
537     if( p_sys->p_es_sub   == es ) p_sys->p_es_sub   = NULL;
538
539     vlc_mutex_unlock( &p_sys->p_input->stream.stream_lock );
540
541     free( es );
542 }
543
544 /**
545  * Control query handler
546  *
547  * \param out the es_out to control
548  * \param i_query A es_out query as defined in include/ninput.h
549  * \param args a variable list of arguments for the query
550  * \return VLC_SUCCESS or an error code
551  */
552 static int EsOutControl( es_out_t *out, int i_query, va_list args )
553 {
554     es_out_sys_t *p_sys = out->p_sys;
555     vlc_bool_t  b, *pb;
556     int         i, *pi;
557
558     es_out_id_t *es;
559
560     switch( i_query )
561     {
562         case ES_OUT_SET_ES_STATE:
563             vlc_mutex_lock( &p_sys->p_input->stream.stream_lock );
564             es = (es_out_id_t*) va_arg( args, es_out_id_t * );
565             b = (vlc_bool_t) va_arg( args, vlc_bool_t );
566             if( b && es->p_es->p_dec == NULL )
567             {
568                 input_SelectES( p_sys->p_input, es->p_es );
569                 vlc_mutex_unlock( &p_sys->p_input->stream.stream_lock );
570                 return es->p_es->p_dec ? VLC_SUCCESS : VLC_EGENERIC;
571             }
572             else if( !b && es->p_es->p_dec )
573             {
574                 input_UnselectES( p_sys->p_input, es->p_es );
575                 vlc_mutex_unlock( &p_sys->p_input->stream.stream_lock );
576                 return VLC_SUCCESS;
577             }
578             vlc_mutex_unlock( &p_sys->p_input->stream.stream_lock );
579             return VLC_SUCCESS;
580
581         case ES_OUT_GET_ES_STATE:
582             es = (es_out_id_t*) va_arg( args, es_out_id_t * );
583             pb = (vlc_bool_t*) va_arg( args, vlc_bool_t * );
584
585             *pb = es->p_es->p_dec ? VLC_TRUE : VLC_FALSE;
586             return VLC_SUCCESS;
587
588         case ES_OUT_SET_ACTIVE:
589         {
590             b = (vlc_bool_t) va_arg( args, vlc_bool_t );
591             p_sys->b_active = b;
592
593             if( b )
594             {
595                 vlc_value_t val;
596                 val.b_bool = VLC_TRUE;
597                 var_Set( p_sys->p_input, "intf-change", val );
598             }
599             return VLC_SUCCESS;
600         }
601
602         case ES_OUT_GET_ACTIVE:
603             pb = (vlc_bool_t*) va_arg( args, vlc_bool_t * );
604             *pb = p_sys->b_active;
605             return VLC_SUCCESS;
606
607         case ES_OUT_SET_MODE:
608             i = (int) va_arg( args, int );
609             if( i == ES_OUT_MODE_NONE || i == ES_OUT_MODE_ALL ||
610                 i == ES_OUT_MODE_AUTO )
611             {
612                 vlc_value_t val;
613
614                 p_sys->i_mode = i;
615
616                 /* Reapply policy mode */
617                 vlc_mutex_lock( &p_sys->p_input->stream.stream_lock );
618                 for( i = 0; i < p_sys->i_es; i++ )
619                 {
620                     if( p_sys->es[i]->p_es->p_dec )
621                     {
622                         input_UnselectES( p_sys->p_input, p_sys->es[i]->p_es );
623                     }
624                 }
625                 for( i = 0; i < p_sys->i_es; i++ )
626                 {
627                     EsOutSelect( out, p_sys->es[i], VLC_FALSE );
628                 }
629                 vlc_mutex_unlock( &p_sys->p_input->stream.stream_lock );
630
631                 val.b_bool = VLC_TRUE;
632                 var_Set( p_sys->p_input, "intf-change", val );
633
634                 return VLC_SUCCESS;
635             }
636             return VLC_EGENERIC;
637
638         case ES_OUT_GET_MODE:
639             pi = (int*) va_arg( args, int* );
640             *pi = p_sys->i_mode;
641             return VLC_SUCCESS;
642
643         case ES_OUT_SET_ES:
644             es = (es_out_id_t*) va_arg( args, es_out_id_t * );
645             if( es == NULL )
646             {
647                 for( i = 0; i < p_sys->i_es; i++ )
648                 {
649                     vlc_mutex_lock( &p_sys->p_input->stream.stream_lock );
650                     if( p_sys->es[i]->p_es->p_dec )
651                     {
652                         input_UnselectES( p_sys->p_input, p_sys->es[i]->p_es );
653                     }
654                     vlc_mutex_unlock( &p_sys->p_input->stream.stream_lock );
655                 }
656             }
657             else
658             {
659                 vlc_mutex_lock( &p_sys->p_input->stream.stream_lock );
660                 EsOutSelect( out, es, VLC_TRUE );
661                 vlc_mutex_unlock( &p_sys->p_input->stream.stream_lock );
662             }
663             return VLC_SUCCESS;
664
665         case ES_OUT_SET_PCR:
666         case ES_OUT_SET_GROUP_PCR:
667         {
668             pgrm_descriptor_t *p_pgrm = NULL;
669             int64_t           i_pcr;
670
671             if( i_query == ES_OUT_SET_PCR )
672             {
673                 p_pgrm = p_sys->p_input->stream.p_selected_program;
674             }
675             else
676             {
677                 int i_group = (int)va_arg( args, int );
678                 p_pgrm = input_FindProgram( p_sys->p_input, i_group );
679                 if( p_pgrm == NULL )
680                 {
681                     /* we create the requested program */
682                     p_pgrm = EsOutAddProgram( out, i_group );
683                 }
684             }
685             i_pcr = (int64_t)va_arg( args, int64_t );
686             /* search program */
687             if( p_pgrm )
688             {
689                 /* 11 is a vodoo trick to avoid non_pcr*9/100 to be null */
690                 input_ClockManageRef( p_sys->p_input, p_pgrm, (i_pcr + 11 ) * 9 / 100);
691             }
692             return VLC_SUCCESS;
693         }
694
695         case ES_OUT_RESET_PCR:
696             for( i = 0; i < p_sys->p_input->stream.i_pgrm_number; i++ )
697             {
698                 p_sys->p_input->stream.pp_programs[i]->i_synchro_state =
699                     SYNCHRO_REINIT;
700                 p_sys->p_input->stream.pp_programs[i]->last_pts = 0;
701             }
702             return VLC_SUCCESS;
703
704         case ES_OUT_CONVERT_TIMESTAMP:
705         case ES_OUT_CONVERT_GROUP_TIMESTAMP:
706         {
707             pgrm_descriptor_t *p_pgrm = NULL;
708
709             if( i_query == ES_OUT_CONVERT_TIMESTAMP )
710             {
711                 p_pgrm = p_sys->p_input->stream.p_selected_program;
712             }
713             else
714             {
715                 int i_group = (int)va_arg( args, int );
716                 p_pgrm = input_FindProgram( p_sys->p_input, i_group );
717             }
718             if( p_pgrm )
719             {
720                 int64_t *pi_ts = (int64_t*)va_arg( args, int64_t* );
721
722                 *pi_ts = input_ClockGetTS( p_sys->p_input, p_pgrm, ( *pi_ts + 11 ) * 9 / 100 );
723             }
724             p_sys->b_convert_ts_auto = VLC_FALSE;
725             return VLC_SUCCESS;
726         }
727
728         default:
729             msg_Err( p_sys->p_input, "unknown query in es_out_Control" );
730             return VLC_EGENERIC;
731     }
732 }
733
734 /****************************************************************************
735  * LanguageGetName: try to expend iso639 into plain name
736  ****************************************************************************/
737 static char *LanguageGetName( const char *psz_code )
738 {
739     const iso639_lang_t *pl;
740
741     if( psz_code == NULL )
742     {
743         return strdup( "" );
744     }
745
746     if( strlen( psz_code ) == 2 )
747     {
748         pl = GetLang_1( psz_code );
749     }
750     else if( strlen( psz_code ) == 3 )
751     {
752         pl = GetLang_2B( psz_code );
753         if( !strcmp( pl->psz_iso639_1, "??" ) )
754         {
755             pl = GetLang_2T( psz_code );
756         }
757     }
758     else
759     {
760         return strdup( psz_code );
761     }
762
763     if( !strcmp( pl->psz_iso639_1, "??" ) )
764     {
765        return strdup( psz_code );
766     }
767     else
768     {
769         if( *pl->psz_native_name )
770         {
771             return strdup( pl->psz_native_name );
772         }
773         return strdup( pl->psz_eng_name );
774     }
775 }