1 /*****************************************************************************
2 * es_out.c: Es Out handler for input.
3 *****************************************************************************
4 * Copyright (C) 2003-2004 VideoLAN
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
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.
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.
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 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
30 #include <vlc/input.h>
31 #include <vlc/decoder.h>
33 #include "input_internal.h"
35 #include "vlc_playlist.h"
38 /*****************************************************************************
40 *****************************************************************************/
46 /* Number of es for this pgrm */
49 vlc_bool_t b_selected;
51 /* Clock for this program */
60 es_out_pgrm_t *p_pgrm;
62 /* Channel in the track type */
65 char *psz_description;
71 input_thread_t *p_input;
76 es_out_pgrm_t *p_pgrm; /* Master program */
97 es_out_id_t *p_es_audio;
98 es_out_id_t *p_es_video;
99 es_out_id_t *p_es_sub;
102 int64_t i_audio_delay;
106 static es_out_id_t *EsOutAdd ( es_out_t *, es_format_t * );
107 static int EsOutSend ( es_out_t *, es_out_id_t *, block_t * );
108 static void EsOutDel ( es_out_t *, es_out_id_t * );
109 static void EsOutSelect( es_out_t *out, es_out_id_t *es, vlc_bool_t b_force );
110 static int EsOutControl( es_out_t *, int i_query, va_list );
113 static void EsSelect( es_out_t *out, es_out_id_t *es );
114 static void EsUnselect( es_out_t *out, es_out_id_t *es, vlc_bool_t b_update );
115 static char *LanguageGetName( const char *psz_code );
117 /*****************************************************************************
119 *****************************************************************************/
120 es_out_t *input_EsOutNew( input_thread_t *p_input )
122 es_out_t *out = malloc( sizeof( es_out_t ) );
123 es_out_sys_t *p_sys = malloc( sizeof( es_out_sys_t ) );
126 out->pf_add = EsOutAdd;
127 out->pf_send = EsOutSend;
128 out->pf_del = EsOutDel;
129 out->pf_control = EsOutControl;
132 p_sys->p_input = p_input;
134 p_sys->b_active = VLC_FALSE;
135 p_sys->i_mode = ES_OUT_MODE_AUTO;
140 p_sys->p_pgrm = NULL;
150 var_Get( p_input, "audio-channel", &val );
151 p_sys->i_audio_last = val.i_int;
153 var_Get( p_input, "spu-channel", &val );
154 p_sys->i_sub_last = val.i_int;
156 p_sys->p_es_audio = NULL;
157 p_sys->p_es_video = NULL;
158 p_sys->p_es_sub = NULL;
160 p_sys->i_audio_delay= 0;
161 p_sys->i_spu_delay = 0;
166 /*****************************************************************************
168 *****************************************************************************/
169 void input_EsOutDelete( es_out_t *out )
171 es_out_sys_t *p_sys = out->p_sys;
174 for( i = 0; i < p_sys->i_es; i++ )
176 if( p_sys->es[i]->p_dec )
178 input_DecoderDelete( p_sys->es[i]->p_dec );
180 if( p_sys->es[i]->psz_description )
181 free( p_sys->es[i]->psz_description );
182 es_format_Clean( &p_sys->es[i]->fmt );
184 free( p_sys->es[i] );
189 for( i = 0; i < p_sys->i_pgrm; i++ )
191 free( p_sys->pgrm[i] );
200 es_out_id_t *input_EsOutGetFromID( es_out_t *out, int i_id )
205 /* Special HACK, -i_id is tha cat of the stream */
206 return (es_out_id_t*)((uint8_t*)NULL-i_id);
209 for( i = 0; i < out->p_sys->i_es; i++ )
211 if( out->p_sys->es[i]->i_id == i_id )
212 return out->p_sys->es[i];
217 void input_EsOutDiscontinuity( es_out_t *out, vlc_bool_t b_audio )
219 es_out_sys_t *p_sys = out->p_sys;
222 for( i = 0; i < p_sys->i_es; i++ )
224 es_out_id_t *es = p_sys->es[i];
226 /* Send a dummy block to let decoder know that
227 * there is a discontinuity */
228 if( es->p_dec && ( !b_audio || es->fmt.i_cat == AUDIO_ES ) )
230 input_DecoderDiscontinuity( es->p_dec );
235 void input_EsOutSetDelay( es_out_t *out, int i_cat, int64_t i_delay )
237 es_out_sys_t *p_sys = out->p_sys;
239 if( i_cat == AUDIO_ES )
240 p_sys->i_audio_delay = i_delay;
241 else if( i_cat == SPU_ES )
242 p_sys->i_spu_delay = i_delay;
245 vlc_bool_t input_EsOutDecodersEmpty( es_out_t *out )
247 es_out_sys_t *p_sys = out->p_sys;
250 for( i = 0; i < p_sys->i_es; i++ )
252 es_out_id_t *es = p_sys->es[i];
254 if( es->p_dec && !input_DecoderEmpty( es->p_dec ) )
260 /*****************************************************************************
262 *****************************************************************************/
263 static void EsOutESVarUpdate( es_out_t *out, es_out_id_t *es,
264 vlc_bool_t b_delete )
266 es_out_sys_t *p_sys = out->p_sys;
267 input_thread_t *p_input = p_sys->p_input;
268 vlc_value_t val, text;
272 if( es->fmt.i_cat == AUDIO_ES )
273 psz_var = "audio-es";
274 else if( es->fmt.i_cat == VIDEO_ES )
275 psz_var = "video-es";
276 else if( es->fmt.i_cat == SPU_ES )
283 val.i_int = es->i_id;
284 var_Change( p_input, psz_var, VLC_VAR_DELCHOICE, &val, NULL );
285 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
289 /* Get the number of ES already added */
290 var_Change( p_input, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
295 /* First one, we need to add the "Disable" choice */
296 val2.i_int = -1; text.psz_string = _("Disable");
297 var_Change( p_input, psz_var, VLC_VAR_ADDCHOICE, &val2, &text );
301 /* Take care of the ES description */
302 if( es->psz_description && *es->psz_description )
304 text.psz_string = strdup( es->psz_description );
308 text.psz_string = malloc( strlen( _("Track %i") ) + 20 );
309 sprintf( text.psz_string, _("Track %i"), val.i_int );
312 val.i_int = es->i_id;
313 var_Change( p_input, psz_var, VLC_VAR_ADDCHOICE, &val, &text );
315 free( text.psz_string );
317 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
320 /* EsOutProgramSelect:
321 * Select a program and update the object variable
323 static void EsOutProgramSelect( es_out_t *out, es_out_pgrm_t *p_pgrm )
325 es_out_sys_t *p_sys = out->p_sys;
326 input_thread_t *p_input = p_sys->p_input;
330 if( p_sys->p_pgrm == p_pgrm )
331 return; /* Nothing to do */
335 es_out_pgrm_t *old = p_sys->p_pgrm;
336 msg_Dbg( p_input, "Unselecting program id=%d", old->i_id );
338 for( i = 0; i < p_sys->i_es; i++ )
340 if( p_sys->es[i]->p_pgrm == old && p_sys->es[i]->p_dec &&
341 p_sys->i_mode != ES_OUT_MODE_ALL )
342 EsUnselect( out, p_sys->es[i], VLC_TRUE );
346 msg_Dbg( p_input, "Selecting program id=%d", p_pgrm->i_id );
348 /* Mark it selected */
349 p_pgrm->b_selected = VLC_TRUE;
351 /* Switch master stream */
352 if( p_sys->p_pgrm && p_sys->p_pgrm->clock.b_master )
354 p_sys->p_pgrm->clock.b_master = VLC_FALSE;
356 p_pgrm->clock.b_master = VLC_TRUE;
357 p_sys->p_pgrm = p_pgrm;
359 /* Update "program" */
360 val.i_int = p_pgrm->i_id;
361 var_Change( p_input, "program", VLC_VAR_SETVALUE, &val, NULL );
364 var_Change( p_input, "audio-es", VLC_VAR_CLEARCHOICES, NULL, NULL );
365 var_Change( p_input, "video-es", VLC_VAR_CLEARCHOICES, NULL, NULL );
366 var_Change( p_input, "spu-es", VLC_VAR_CLEARCHOICES, NULL, NULL );
367 for( i = 0; i < p_sys->i_es; i++ )
369 EsOutESVarUpdate( out, p_sys->es[i], VLC_FALSE );
370 EsOutSelect( out, p_sys->es[i], VLC_FALSE );
373 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
379 static es_out_pgrm_t *EsOutProgramAdd( es_out_t *out, int i_group )
381 es_out_sys_t *p_sys = out->p_sys;
382 input_thread_t *p_input = p_sys->p_input;
385 es_out_pgrm_t *p_pgrm = malloc( sizeof( es_out_pgrm_t ) );
388 p_pgrm->i_id = i_group;
390 p_pgrm->b_selected = VLC_FALSE;
391 input_ClockInit( &p_pgrm->clock, VLC_FALSE, p_input->input.i_cr_average );
394 TAB_APPEND( p_sys->i_pgrm, p_sys->pgrm, p_pgrm );
396 /* Update "program" variable */
398 var_Change( p_input, "program", VLC_VAR_ADDCHOICE, &val, NULL );
400 if( i_group == var_GetInteger( p_input, "program" ) )
402 EsOutProgramSelect( out, p_pgrm );
406 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
414 static es_out_id_t *EsOutAdd( es_out_t *out, es_format_t *fmt )
416 es_out_sys_t *p_sys = out->p_sys;
417 input_thread_t *p_input = p_sys->p_input;
419 es_out_id_t *es = malloc( sizeof( es_out_id_t ) );
420 es_out_pgrm_t *p_pgrm = NULL;
423 if( fmt->i_group < 0 )
425 msg_Err( p_input, "invakud group number" );
429 /* Search the program */
430 for( i = 0; i < p_sys->i_pgrm; i++ )
432 if( fmt->i_group == p_sys->pgrm[i]->i_id )
434 p_pgrm = p_sys->pgrm[i];
440 /* Create a new one */
441 p_pgrm = EsOutProgramAdd( out, fmt->i_group );
444 /* Increase ref count for program */
449 fmt->i_id = out->p_sys->i_id;
450 es->i_id = fmt->i_id;
452 es_format_Copy( &es->fmt, fmt );
456 es->i_channel = p_sys->i_audio;
460 es->i_channel = p_sys->i_video;
464 es->i_channel = p_sys->i_sub;
471 es->psz_description = LanguageGetName( fmt->psz_language );
474 if( es->p_pgrm == p_sys->p_pgrm )
475 EsOutESVarUpdate( out, es, VLC_FALSE );
478 /* Add stream info */
479 sprintf( psz_cat, _("Stream %d"), out->p_sys->i_id - 1 );
481 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Codec"),
482 "%.4s", (char*)&fmt->i_codec );
484 if( *psz_description )
485 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Language"),
486 "%s", psz_description );
488 if( fmt->psz_description && *fmt->psz_description )
489 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Description"),
490 "%s", fmt->psz_description );
492 /* Add information */
496 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
497 _("Type"), _("Audio") );
499 if( fmt->audio.i_channels > 0 )
500 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Channels"),
501 "%d", fmt->audio.i_channels );
503 if( fmt->audio.i_rate > 0 )
504 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Sample rate"),
505 _("%d Hz"), fmt->audio.i_rate );
507 if( fmt->audio.i_bitspersample > 0 )
508 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
509 _("Bits per sample"), "%d",
510 fmt->audio.i_bitspersample );
512 if( fmt->i_bitrate > 0 )
513 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Bitrate"),
514 _("%d bps"), fmt->i_bitrate );
518 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
519 _("Type"), _("Video") );
521 if( fmt->video.i_width > 0 && fmt->video.i_height > 0 )
522 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
523 _("Resolution"), "%dx%d",
524 fmt->video.i_width, fmt->video.i_height );
526 if( fmt->video.i_visible_width > 0 &&
527 fmt->video.i_visible_height > 0 )
528 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
529 _("Display resolution"), "%dx%d",
530 fmt->video.i_visible_width,
531 fmt->video.i_visible_height);
535 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
536 _("Type"), _("Subtitle") );
542 free( psz_description );
545 /* Select it if needed */
546 EsOutSelect( out, es, VLC_FALSE );
549 TAB_APPEND( out->p_sys->i_es, out->p_sys->es, es );
550 p_sys->i_id++; /* always incremented */
567 static void EsSelect( es_out_t *out, es_out_id_t *es )
569 es_out_sys_t *p_sys = out->p_sys;
570 input_thread_t *p_input = p_sys->p_input;
576 msg_Warn( p_input, "ES 0x%x is already selected", es->i_id );
580 if( es->fmt.i_cat == VIDEO_ES || es->fmt.i_cat == SPU_ES )
582 if( !var_GetBool( p_input, "video" ) ||
583 ( p_input->p_sout && !var_GetBool( p_input, "sout-video" ) ) )
585 msg_Dbg( p_input, "video is disabled, not selecting ES 0x%x",
590 else if( es->fmt.i_cat == AUDIO_ES )
592 var_Get( p_input, "audio", &val );
593 if( !var_GetBool( p_input, "audio" ) ||
594 ( p_input->p_sout && !var_GetBool( p_input, "sout-audio" ) ) )
596 msg_Dbg( p_input, "audio is disabled, not selecting ES 0x%x",
602 es->p_dec = input_DecoderNew( p_input, &es->fmt, VLC_FALSE );
603 if( es->p_dec == NULL || es->p_pgrm != p_sys->p_pgrm )
606 if( es->fmt.i_cat == VIDEO_ES )
607 psz_var = "video-es";
608 else if( es->fmt.i_cat == AUDIO_ES )
609 psz_var = "audio-es";
610 else if( es->fmt.i_cat == SPU_ES )
615 /* Mark it as selected */
616 val.i_int = es->i_id;
617 var_Change( p_input, psz_var, VLC_VAR_SETVALUE, &val, NULL );
620 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
623 static void EsUnselect( es_out_t *out, es_out_id_t *es, vlc_bool_t b_update )
625 es_out_sys_t *p_sys = out->p_sys;
626 input_thread_t *p_input = p_sys->p_input;
630 if( es->p_dec == NULL )
632 msg_Warn( p_input, "ES 0x%x is already unselected", es->i_id );
636 input_DecoderDelete( es->p_dec );
643 if( es->p_dec == NULL )
645 if( es->fmt.i_cat == VIDEO_ES )
646 psz_var = "video-es";
647 else if( es->fmt.i_cat == AUDIO_ES )
648 psz_var = "audio-es";
649 else if( es->fmt.i_cat == SPU_ES )
654 /* Mark it as selected */
656 var_Change( p_input, psz_var, VLC_VAR_SETVALUE, &val, NULL );
658 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
662 * Select an ES given the current mode
663 * XXX: you need to take a the lock before (stream.stream_lock)
665 * \param out The es_out structure
666 * \param es es_out_id structure
670 static void EsOutSelect( es_out_t *out, es_out_id_t *es, vlc_bool_t b_force )
672 es_out_sys_t *p_sys = out->p_sys;
674 int i_cat = es->fmt.i_cat;
676 if( !p_sys->b_active ||
677 ( !b_force && es->fmt.i_priority < 0 ) )
682 if( p_sys->i_mode == ES_OUT_MODE_ALL || b_force )
687 else if( p_sys->i_mode == ES_OUT_MODE_AUTO )
691 if( es->p_pgrm != p_sys->p_pgrm )
694 if( i_cat == AUDIO_ES )
696 if( p_sys->p_es_audio &&
697 p_sys->p_es_audio->fmt.i_priority >= es->fmt.i_priority )
701 i_wanted = p_sys->i_audio_last >= 0 ?
702 p_sys->i_audio_last : es->i_channel;
704 else if( i_cat == SPU_ES )
706 if( p_sys->p_es_sub &&
707 p_sys->p_es_sub->fmt.i_priority >=
712 i_wanted = p_sys->i_sub_last;
714 else if( i_cat == VIDEO_ES )
716 i_wanted = es->i_channel;
719 if( i_wanted == es->i_channel && es->p_dec == NULL )
723 /* FIXME TODO handle priority here */
726 if( i_cat == AUDIO_ES )
728 if( p_sys->i_mode == ES_OUT_MODE_AUTO &&
730 p_sys->p_es_audio != es &&
731 p_sys->p_es_audio->p_dec )
733 EsUnselect( out, p_sys->p_es_audio, VLC_FALSE );
735 p_sys->p_es_audio = es;
737 else if( i_cat == SPU_ES )
739 if( p_sys->i_mode == ES_OUT_MODE_AUTO &&
741 p_sys->p_es_sub != es &&
742 p_sys->p_es_sub->p_dec )
744 EsUnselect( out, p_sys->p_es_sub, VLC_FALSE );
746 p_sys->p_es_sub = es;
748 else if( i_cat == VIDEO_ES )
750 p_sys->p_es_video = es;
756 * Send a block for the given es_out
758 * \param out the es_out to send from
759 * \param es the es_out_id
760 * \param p_block the data block to send
762 static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
764 es_out_sys_t *p_sys = out->p_sys;
765 input_thread_t *p_input = p_sys->p_input;
766 es_out_pgrm_t *p_pgrm = es->p_pgrm;
769 if( es->fmt.i_cat == AUDIO_ES )
770 i_delay = p_sys->i_audio_delay;
771 else if( es->fmt.i_cat == SPU_ES )
772 i_delay = p_sys->i_spu_delay;
776 /* +11 -> avoid null value with non null dts/pts */
777 if( p_block->i_dts > 0 )
780 input_ClockGetTS( p_input, &p_pgrm->clock,
781 ( p_block->i_dts + 11 ) * 9 / 100 ) + i_delay;
783 if( p_block->i_pts > 0 )
786 input_ClockGetTS( p_input, &p_pgrm->clock,
787 ( p_block->i_pts + 11 ) * 9 / 100 ) + i_delay;
790 p_block->i_rate = p_input->i_rate;
792 /* TODO handle mute */
793 if( es->p_dec && ( es->fmt.i_cat != AUDIO_ES || p_input->i_rate == INPUT_RATE_DEFAULT ) )
795 input_DecoderDecode( es->p_dec, p_block );
799 block_Release( p_block );
805 /*****************************************************************************
807 *****************************************************************************/
808 static void EsOutDel( es_out_t *out, es_out_id_t *es )
810 es_out_sys_t *p_sys = out->p_sys;
812 /* We don't try to reselect */
814 EsUnselect( out, es, es->p_pgrm == p_sys->p_pgrm );
816 if( es->p_pgrm == p_sys->p_pgrm )
817 EsOutESVarUpdate( out, es, VLC_TRUE );
819 TAB_REMOVE( p_sys->i_es, p_sys->es, es );
822 if( es->p_pgrm->i_es == 0 )
824 msg_Err( p_sys->p_input, "Program doesn't contain anymore ES, "
828 if( p_sys->p_es_audio == es ) p_sys->p_es_audio = NULL;
829 if( p_sys->p_es_video == es ) p_sys->p_es_video = NULL;
830 if( p_sys->p_es_sub == es ) p_sys->p_es_sub = NULL;
832 switch( es->fmt.i_cat )
845 if( es->psz_description )
846 free( es->psz_description );
848 es_format_Clean( &es->fmt );
854 * Control query handler
856 * \param out the es_out to control
857 * \param i_query A es_out query as defined in include/ninput.h
858 * \param args a variable list of arguments for the query
859 * \return VLC_SUCCESS or an error code
861 static int EsOutControl( es_out_t *out, int i_query, va_list args )
863 es_out_sys_t *p_sys = out->p_sys;
871 case ES_OUT_SET_ES_STATE:
872 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
873 b = (vlc_bool_t) va_arg( args, vlc_bool_t );
874 if( b && es->p_dec == NULL )
877 return es->p_dec ? VLC_SUCCESS : VLC_EGENERIC;
879 else if( !b && es->p_dec )
881 EsUnselect( out, es, es->p_pgrm == p_sys->p_pgrm );
886 case ES_OUT_GET_ES_STATE:
887 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
888 pb = (vlc_bool_t*) va_arg( args, vlc_bool_t * );
890 *pb = es->p_dec ? VLC_TRUE : VLC_FALSE;
893 case ES_OUT_SET_ACTIVE:
895 b = (vlc_bool_t) va_arg( args, vlc_bool_t );
899 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
903 case ES_OUT_GET_ACTIVE:
904 pb = (vlc_bool_t*) va_arg( args, vlc_bool_t * );
905 *pb = p_sys->b_active;
908 case ES_OUT_SET_MODE:
909 i = (int) va_arg( args, int );
910 if( i == ES_OUT_MODE_NONE || i == ES_OUT_MODE_ALL ||
911 i == ES_OUT_MODE_AUTO )
915 /* Reapply policy mode */
916 for( i = 0; i < p_sys->i_es; i++ )
918 if( p_sys->es[i]->p_dec )
920 EsUnselect( out, p_sys->es[i],
921 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
924 for( i = 0; i < p_sys->i_es; i++ )
926 EsOutSelect( out, p_sys->es[i], VLC_FALSE );
932 case ES_OUT_GET_MODE:
933 pi = (int*) va_arg( args, int* );
938 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
939 /* Special case NULL, NULL+i_cat */
942 for( i = 0; i < p_sys->i_es; i++ )
944 if( p_sys->es[i]->p_dec )
945 EsUnselect( out, p_sys->es[i],
946 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
949 else if( es == (es_out_id_t*)((uint8_t*)NULL+AUDIO_ES) )
951 for( i = 0; i < p_sys->i_es; i++ )
953 if( p_sys->es[i]->p_dec &&
954 p_sys->es[i]->fmt.i_cat == AUDIO_ES )
955 EsUnselect( out, p_sys->es[i],
956 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
959 else if( es == (es_out_id_t*)((uint8_t*)NULL+VIDEO_ES) )
961 for( i = 0; i < p_sys->i_es; i++ )
963 if( p_sys->es[i]->p_dec &&
964 p_sys->es[i]->fmt.i_cat == VIDEO_ES )
965 EsUnselect( out, p_sys->es[i],
966 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
969 else if( es == (es_out_id_t*)((uint8_t*)NULL+SPU_ES) )
971 for( i = 0; i < p_sys->i_es; i++ )
973 if( p_sys->es[i]->p_dec &&
974 p_sys->es[i]->fmt.i_cat == SPU_ES )
975 EsUnselect( out, p_sys->es[i],
976 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
981 for( i = 0; i < p_sys->i_es; i++ )
983 if( es == p_sys->es[i] )
985 EsOutSelect( out, es, VLC_TRUE );
993 case ES_OUT_SET_GROUP_PCR:
995 es_out_pgrm_t *p_pgrm = NULL;
999 if( i_query == ES_OUT_SET_PCR )
1001 p_pgrm = p_sys->p_pgrm;
1006 i_group = (int)va_arg( args, int );
1007 for( i = 0; i < p_sys->i_pgrm; i++ )
1009 if( p_sys->pgrm[i]->i_id == i_group )
1011 p_pgrm = p_sys->pgrm[i];
1016 if( p_pgrm == NULL )
1017 p_pgrm = EsOutProgramAdd( out, i_group ); /* Create it */
1019 i_pcr = (int64_t)va_arg( args, int64_t );
1020 /* search program */
1021 /* 11 is a vodoo trick to avoid non_pcr*9/100 to be null */
1022 input_ClockSetPCR( p_sys->p_input, &p_pgrm->clock,
1023 (i_pcr + 11 ) * 9 / 100);
1027 case ES_OUT_RESET_PCR:
1028 for( i = 0; i < p_sys->i_pgrm; i++ )
1030 p_sys->pgrm[i]->clock.i_synchro_state = SYNCHRO_REINIT;
1031 p_sys->pgrm[i]->clock.last_pts = 0;
1035 case ES_OUT_GET_GROUP:
1036 pi = (int*) va_arg( args, int* );
1038 *pi = p_sys->p_pgrm->i_id;
1040 *pi = -1; /* FIXME */
1043 case ES_OUT_SET_GROUP:
1046 i = (int) va_arg( args, int );
1047 for( j = 0; j < p_sys->i_pgrm; j++ )
1049 es_out_pgrm_t *p_pgrm = p_sys->pgrm[j];
1050 if( p_pgrm->i_id == i )
1052 EsOutProgramSelect( out, p_pgrm );
1056 return VLC_EGENERIC;
1060 msg_Err( p_sys->p_input, "unknown query in es_out_Control" );
1061 return VLC_EGENERIC;
1065 /****************************************************************************
1066 * LanguageGetName: try to expend iso639 into plain name
1067 ****************************************************************************/
1068 static char *LanguageGetName( const char *psz_code )
1070 const iso639_lang_t *pl;
1072 if( psz_code == NULL )
1074 return strdup( "" );
1077 if( strlen( psz_code ) == 2 )
1079 pl = GetLang_1( psz_code );
1081 else if( strlen( psz_code ) == 3 )
1083 pl = GetLang_2B( psz_code );
1084 if( !strcmp( pl->psz_iso639_1, "??" ) )
1086 pl = GetLang_2T( psz_code );
1091 return strdup( psz_code );
1094 if( !strcmp( pl->psz_iso639_1, "??" ) )
1096 return strdup( psz_code );
1100 if( *pl->psz_native_name )
1102 return strdup( pl->psz_native_name );
1104 return strdup( pl->psz_eng_name );