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