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