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 /*****************************************************************************
247 *****************************************************************************/
248 static void EsOutESVarUpdate( es_out_t *out, es_out_id_t *es )
250 es_out_sys_t *p_sys = out->p_sys;
251 input_thread_t *p_input = p_sys->p_input;
252 vlc_value_t val, text;
256 if( es->fmt.i_cat == AUDIO_ES )
257 psz_var = "audio-es";
258 else if( es->fmt.i_cat == VIDEO_ES )
259 psz_var = "video-es";
260 else if( es->fmt.i_cat == SPU_ES )
265 /* Get the number of ES already added */
266 var_Change( p_input, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
271 /* First one, we need to add the "Disable" choice */
272 val2.i_int = -1; text.psz_string = _("Disable");
273 var_Change( p_input, psz_var, VLC_VAR_ADDCHOICE, &val2, &text );
277 /* Take care of the ES description */
278 if( es->psz_description && *es->psz_description )
280 text.psz_string = strdup( es->psz_description );
284 text.psz_string = malloc( strlen( _("Track %i") ) + 20 );
285 sprintf( text.psz_string, _("Track %i"), val.i_int );
288 val.i_int = es->i_id;
289 var_Change( p_input, psz_var, VLC_VAR_ADDCHOICE, &val, &text );
291 free( text.psz_string );
293 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
296 /* EsOutProgramSelect:
297 * Select a program and update the object variable
299 static void EsOutProgramSelect( es_out_t *out, es_out_pgrm_t *p_pgrm )
301 es_out_sys_t *p_sys = out->p_sys;
302 input_thread_t *p_input = p_sys->p_input;
306 if( p_sys->p_pgrm == p_pgrm )
307 return; /* Nothing to do */
311 es_out_pgrm_t *old = p_sys->p_pgrm;
312 msg_Dbg( p_input, "Unselecting program id=%d", old->i_id );
314 for( i = 0; i < p_sys->i_es; i++ )
316 if( p_sys->es[i]->p_pgrm == old && p_sys->es[i]->p_dec &&
317 p_sys->i_mode != ES_OUT_MODE_ALL )
318 EsUnselect( out, p_sys->es[i], VLC_TRUE );
322 msg_Dbg( p_input, "Selecting program id=%d", p_pgrm->i_id );
324 /* Mark it selected */
325 p_pgrm->b_selected = VLC_TRUE;
327 /* Switch master stream */
328 if( p_sys->p_pgrm && p_sys->p_pgrm->clock.b_master )
330 p_sys->p_pgrm->clock.b_master = VLC_FALSE;
332 p_pgrm->clock.b_master = VLC_TRUE;
333 p_sys->p_pgrm = p_pgrm;
335 /* Update "program" */
336 val.i_int = p_pgrm->i_id;
337 var_Change( p_input, "program", VLC_VAR_SETVALUE, &val, NULL );
340 var_Change( p_input, "audio-es", VLC_VAR_CLEARCHOICES, NULL, NULL );
341 var_Change( p_input, "video-es", VLC_VAR_CLEARCHOICES, NULL, NULL );
342 var_Change( p_input, "spu-es", VLC_VAR_CLEARCHOICES, NULL, NULL );
343 for( i = 0; i < p_sys->i_es; i++ )
345 EsOutESVarUpdate( out, p_sys->es[i] );
346 EsOutSelect( out, p_sys->es[i], VLC_FALSE );
349 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
355 static es_out_pgrm_t *EsOutProgramAdd( es_out_t *out, int i_group )
357 es_out_sys_t *p_sys = out->p_sys;
358 input_thread_t *p_input = p_sys->p_input;
361 es_out_pgrm_t *p_pgrm = malloc( sizeof( es_out_pgrm_t ) );
364 p_pgrm->i_id = i_group;
366 p_pgrm->b_selected = VLC_FALSE;
367 input_ClockInit( &p_pgrm->clock, VLC_FALSE, p_input->input.i_cr_average );
370 TAB_APPEND( p_sys->i_pgrm, p_sys->pgrm, p_pgrm );
372 /* Update "program" variable */
374 var_Change( p_input, "program", VLC_VAR_ADDCHOICE, &val, NULL );
376 if( i_group == var_GetInteger( p_input, "program" ) )
378 EsOutProgramSelect( out, p_pgrm );
382 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
390 static es_out_id_t *EsOutAdd( es_out_t *out, es_format_t *fmt )
392 es_out_sys_t *p_sys = out->p_sys;
393 input_thread_t *p_input = p_sys->p_input;
395 es_out_id_t *es = malloc( sizeof( es_out_id_t ) );
396 es_out_pgrm_t *p_pgrm = NULL;
399 if( fmt->i_group < 0 )
401 msg_Err( p_input, "invakud group number" );
405 /* Search the program */
406 for( i = 0; i < p_sys->i_pgrm; i++ )
408 if( fmt->i_group == p_sys->pgrm[i]->i_id )
410 p_pgrm = p_sys->pgrm[i];
416 /* Create a new one */
417 p_pgrm = EsOutProgramAdd( out, fmt->i_group );
420 /* Increase ref count for program */
425 fmt->i_id = out->p_sys->i_id;
426 es->i_id = fmt->i_id;
428 es_format_Copy( &es->fmt, fmt );
432 es->i_channel = p_sys->i_audio;
436 es->i_channel = p_sys->i_video;
440 es->i_channel = p_sys->i_sub;
447 es->psz_description = LanguageGetName( fmt->psz_language );
450 if( es->p_pgrm == p_sys->p_pgrm )
451 EsOutESVarUpdate( out, es );
454 /* Add stream info */
455 sprintf( psz_cat, _("Stream %d"), out->p_sys->i_id - 1 );
457 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Codec"),
458 "%.4s", (char*)&fmt->i_codec );
460 if( *psz_description )
461 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Language"),
462 "%s", psz_description );
464 if( fmt->psz_description && *fmt->psz_description )
465 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Description"),
466 "%s", fmt->psz_description );
468 /* Add information */
472 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
473 _("Type"), _("Audio") );
475 if( fmt->audio.i_channels > 0 )
476 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Channels"),
477 "%d", fmt->audio.i_channels );
479 if( fmt->audio.i_rate > 0 )
480 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Sample rate"),
481 _("%d Hz"), fmt->audio.i_rate );
483 if( fmt->audio.i_bitspersample > 0 )
484 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
485 _("Bits per sample"), "%d",
486 fmt->audio.i_bitspersample );
488 if( fmt->i_bitrate > 0 )
489 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Bitrate"),
490 _("%d bps"), fmt->i_bitrate );
494 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
495 _("Type"), _("Video") );
497 if( fmt->video.i_width > 0 && fmt->video.i_height > 0 )
498 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
499 _("Resolution"), "%dx%d",
500 fmt->video.i_width, fmt->video.i_height );
502 if( fmt->video.i_visible_width > 0 &&
503 fmt->video.i_visible_height > 0 )
504 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
505 _("Display resolution"), "%dx%d",
506 fmt->video.i_visible_width,
507 fmt->video.i_visible_height);
511 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
512 _("Type"), _("Subtitle") );
518 free( psz_description );
521 /* Select it if needed */
522 EsOutSelect( out, es, VLC_FALSE );
525 TAB_APPEND( out->p_sys->i_es, out->p_sys->es, es );
526 p_sys->i_id++; /* always incremented */
543 static void EsSelect( es_out_t *out, es_out_id_t *es )
545 es_out_sys_t *p_sys = out->p_sys;
546 input_thread_t *p_input = p_sys->p_input;
552 msg_Warn( p_input, "ES 0x%x is already selected", es->i_id );
556 if( es->fmt.i_cat == VIDEO_ES || es->fmt.i_cat == SPU_ES )
558 if( !var_GetBool( p_input, "video" ) || ( p_input->p_sout && !var_GetBool( p_input, "sout-video" ) ) )
560 msg_Dbg( p_input, "video is disabled, not selecting ES 0x%x", es->i_id );
564 else if( es->fmt.i_cat == AUDIO_ES )
566 var_Get( p_input, "audio", &val );
567 if( !var_GetBool( p_input, "audio" ) || ( p_input->p_sout && !var_GetBool( p_input, "sout-audio" ) ) )
569 msg_Dbg( p_input, "audio is disabled, not selecting ES 0x%x", es->i_id );
574 es->p_dec = input_DecoderNew( p_input, &es->fmt, VLC_FALSE );
575 if( es->p_dec == NULL || es->p_pgrm != p_sys->p_pgrm )
578 if( es->fmt.i_cat == VIDEO_ES )
579 psz_var = "video-es";
580 else if( es->fmt.i_cat == AUDIO_ES )
581 psz_var = "audio-es";
582 else if( es->fmt.i_cat == SPU_ES )
587 /* Mark it as selected */
588 val.i_int = es->i_id;
589 var_Change( p_input, psz_var, VLC_VAR_SETVALUE, &val, NULL );
592 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
595 static void EsUnselect( es_out_t *out, es_out_id_t *es, vlc_bool_t b_update )
597 es_out_sys_t *p_sys = out->p_sys;
598 input_thread_t *p_input = p_sys->p_input;
602 if( es->p_dec == NULL )
604 msg_Warn( p_input, "ES 0x%x is already unselected", es->i_id );
608 input_DecoderDelete( es->p_dec );
615 if( es->p_dec == NULL )
617 if( es->fmt.i_cat == VIDEO_ES )
618 psz_var = "video-es";
619 else if( es->fmt.i_cat == AUDIO_ES )
620 psz_var = "audio-es";
621 else if( es->fmt.i_cat == SPU_ES )
626 /* Mark it as selected */
628 var_Change( p_input, psz_var, VLC_VAR_SETVALUE, &val, NULL );
630 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
634 * Select an ES given the current mode
635 * XXX: you need to take a the lock before (stream.stream_lock)
637 * \param out The es_out structure
638 * \param es es_out_id structure
642 static void EsOutSelect( es_out_t *out, es_out_id_t *es, vlc_bool_t b_force )
644 es_out_sys_t *p_sys = out->p_sys;
646 int i_cat = es->fmt.i_cat;
648 if( !p_sys->b_active ||
649 ( !b_force && es->fmt.i_priority < 0 ) )
654 if( p_sys->i_mode == ES_OUT_MODE_ALL || b_force )
659 else if( p_sys->i_mode == ES_OUT_MODE_AUTO )
663 if( es->p_pgrm != p_sys->p_pgrm )
666 if( i_cat == AUDIO_ES )
668 if( p_sys->p_es_audio &&
669 p_sys->p_es_audio->fmt.i_priority >= es->fmt.i_priority )
673 i_wanted = p_sys->i_audio_last >= 0 ?
674 p_sys->i_audio_last : es->i_channel;
676 else if( i_cat == SPU_ES )
678 if( p_sys->p_es_sub &&
679 p_sys->p_es_sub->fmt.i_priority >=
684 i_wanted = p_sys->i_sub_last;
686 else if( i_cat == VIDEO_ES )
688 i_wanted = es->i_channel;
691 if( i_wanted == es->i_channel && es->p_dec == NULL )
695 /* FIXME TODO handle priority here */
698 if( i_cat == AUDIO_ES )
700 if( p_sys->i_mode == ES_OUT_MODE_AUTO &&
702 p_sys->p_es_audio != es &&
703 p_sys->p_es_audio->p_dec )
705 EsUnselect( out, p_sys->p_es_audio, VLC_FALSE );
707 p_sys->p_es_audio = es;
709 else if( i_cat == SPU_ES )
711 if( p_sys->i_mode == ES_OUT_MODE_AUTO &&
713 p_sys->p_es_sub != es &&
714 p_sys->p_es_sub->p_dec )
716 EsUnselect( out, p_sys->p_es_sub, VLC_FALSE );
718 p_sys->p_es_sub = es;
720 else if( i_cat == VIDEO_ES )
722 p_sys->p_es_video = es;
728 * Send a block for the given es_out
730 * \param out the es_out to send from
731 * \param es the es_out_id
732 * \param p_block the data block to send
734 static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
736 es_out_sys_t *p_sys = out->p_sys;
737 input_thread_t *p_input = p_sys->p_input;
738 es_out_pgrm_t *p_pgrm = es->p_pgrm;
741 if( es->fmt.i_cat == AUDIO_ES )
742 i_delay = p_sys->i_audio_delay;
743 else if( es->fmt.i_cat == SPU_ES )
744 i_delay = p_sys->i_spu_delay;
748 /* +11 -> avoid null value with non null dts/pts */
749 if( p_block->i_dts > 0 )
752 input_ClockGetTS( p_input, &p_pgrm->clock,
753 ( p_block->i_dts + 11 ) * 9 / 100 ) + i_delay;
755 if( p_block->i_pts > 0 )
758 input_ClockGetTS( p_input, &p_pgrm->clock,
759 ( p_block->i_pts + 11 ) * 9 / 100 ) + i_delay;
762 p_block->i_rate = p_input->i_rate;
764 /* TODO handle mute */
765 if( es->p_dec && ( es->fmt.i_cat != AUDIO_ES || p_input->i_rate == INPUT_RATE_DEFAULT ) )
767 input_DecoderDecode( es->p_dec, p_block );
771 block_Release( p_block );
777 /*****************************************************************************
779 *****************************************************************************/
780 static void EsOutDel( es_out_t *out, es_out_id_t *es )
782 es_out_sys_t *p_sys = out->p_sys;
784 /* We don't try to reselect */
786 EsUnselect( out, es, es->p_pgrm == p_sys->p_pgrm );
788 TAB_REMOVE( p_sys->i_es, p_sys->es, es );
791 if( es->p_pgrm->i_es == 0 )
793 msg_Err( p_sys->p_input, "Program doesn't have es anymore, clenaing TODO ?" );
796 if( p_sys->p_es_audio == es ) p_sys->p_es_audio = NULL;
797 if( p_sys->p_es_video == es ) p_sys->p_es_video = NULL;
798 if( p_sys->p_es_sub == es ) p_sys->p_es_sub = NULL;
800 switch( es->fmt.i_cat )
813 if( es->psz_description )
814 free( es->psz_description );
816 es_format_Clean( &es->fmt );
822 * Control query handler
824 * \param out the es_out to control
825 * \param i_query A es_out query as defined in include/ninput.h
826 * \param args a variable list of arguments for the query
827 * \return VLC_SUCCESS or an error code
829 static int EsOutControl( es_out_t *out, int i_query, va_list args )
831 es_out_sys_t *p_sys = out->p_sys;
839 case ES_OUT_SET_ES_STATE:
840 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
841 b = (vlc_bool_t) va_arg( args, vlc_bool_t );
842 if( b && es->p_dec == NULL )
845 return es->p_dec ? VLC_SUCCESS : VLC_EGENERIC;
847 else if( !b && es->p_dec )
849 EsUnselect( out, es, es->p_pgrm == p_sys->p_pgrm );
854 case ES_OUT_GET_ES_STATE:
855 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
856 pb = (vlc_bool_t*) va_arg( args, vlc_bool_t * );
858 *pb = es->p_dec ? VLC_TRUE : VLC_FALSE;
861 case ES_OUT_SET_ACTIVE:
863 b = (vlc_bool_t) va_arg( args, vlc_bool_t );
867 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
871 case ES_OUT_GET_ACTIVE:
872 pb = (vlc_bool_t*) va_arg( args, vlc_bool_t * );
873 *pb = p_sys->b_active;
876 case ES_OUT_SET_MODE:
877 i = (int) va_arg( args, int );
878 if( i == ES_OUT_MODE_NONE || i == ES_OUT_MODE_ALL ||
879 i == ES_OUT_MODE_AUTO )
883 /* Reapply policy mode */
884 for( i = 0; i < p_sys->i_es; i++ )
886 if( p_sys->es[i]->p_dec )
888 EsUnselect( out, p_sys->es[i], p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
891 for( i = 0; i < p_sys->i_es; i++ )
893 EsOutSelect( out, p_sys->es[i], VLC_FALSE );
899 case ES_OUT_GET_MODE:
900 pi = (int*) va_arg( args, int* );
905 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
906 /* Special case NULL, NULL+i_cat */
909 for( i = 0; i < p_sys->i_es; i++ )
911 if( p_sys->es[i]->p_dec )
912 EsUnselect( out, p_sys->es[i],
913 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
916 else if( es == (es_out_id_t*)((uint8_t*)NULL+AUDIO_ES) )
918 for( i = 0; i < p_sys->i_es; i++ )
920 if( p_sys->es[i]->p_dec && p_sys->es[i]->fmt.i_cat == AUDIO_ES )
921 EsUnselect( out, p_sys->es[i], p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
924 else if( es == (es_out_id_t*)((uint8_t*)NULL+VIDEO_ES) )
926 for( i = 0; i < p_sys->i_es; i++ )
928 if( p_sys->es[i]->p_dec && p_sys->es[i]->fmt.i_cat == VIDEO_ES )
929 EsUnselect( out, p_sys->es[i], p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
932 else if( es == (es_out_id_t*)((uint8_t*)NULL+SPU_ES) )
934 for( i = 0; i < p_sys->i_es; i++ )
936 if( p_sys->es[i]->p_dec && p_sys->es[i]->fmt.i_cat == SPU_ES )
937 EsUnselect( out, p_sys->es[i], p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
942 for( i = 0; i < p_sys->i_es; i++ )
944 if( es == p_sys->es[i] )
946 EsOutSelect( out, es, VLC_TRUE );
954 case ES_OUT_SET_GROUP_PCR:
956 es_out_pgrm_t *p_pgrm = NULL;
960 if( i_query == ES_OUT_SET_PCR )
962 p_pgrm = p_sys->p_pgrm;
967 i_group = (int)va_arg( args, int );
968 for( i = 0; i < p_sys->i_pgrm; i++ )
970 if( p_sys->pgrm[i]->i_id == i_group )
972 p_pgrm = p_sys->pgrm[i];
978 p_pgrm = EsOutProgramAdd( out, i_group ); /* Create it */
980 i_pcr = (int64_t)va_arg( args, int64_t );
982 /* 11 is a vodoo trick to avoid non_pcr*9/100 to be null */
983 input_ClockSetPCR( p_sys->p_input, &p_pgrm->clock, (i_pcr + 11 ) * 9 / 100);
987 case ES_OUT_RESET_PCR:
988 for( i = 0; i < p_sys->i_pgrm; i++ )
990 p_sys->pgrm[i]->clock.i_synchro_state = SYNCHRO_REINIT;
991 p_sys->pgrm[i]->clock.last_pts = 0;
995 case ES_OUT_GET_GROUP:
996 pi = (int*) va_arg( args, int* );
998 *pi = p_sys->p_pgrm->i_id;
1000 *pi = -1; /* FIXME */
1003 case ES_OUT_SET_GROUP:
1006 i = (int) va_arg( args, int );
1007 for( j = 0; j < p_sys->i_pgrm; j++ )
1009 es_out_pgrm_t *p_pgrm = p_sys->pgrm[j];
1010 if( p_pgrm->i_id == i )
1012 EsOutProgramSelect( out, p_pgrm );
1016 return VLC_EGENERIC;
1020 msg_Err( p_sys->p_input, "unknown query in es_out_Control" );
1021 return VLC_EGENERIC;
1025 /****************************************************************************
1026 * LanguageGetName: try to expend iso639 into plain name
1027 ****************************************************************************/
1028 static char *LanguageGetName( const char *psz_code )
1030 const iso639_lang_t *pl;
1032 if( psz_code == NULL )
1034 return strdup( "" );
1037 if( strlen( psz_code ) == 2 )
1039 pl = GetLang_1( psz_code );
1041 else if( strlen( psz_code ) == 3 )
1043 pl = GetLang_2B( psz_code );
1044 if( !strcmp( pl->psz_iso639_1, "??" ) )
1046 pl = GetLang_2T( psz_code );
1051 return strdup( psz_code );
1054 if( !strcmp( pl->psz_iso639_1, "??" ) )
1056 return strdup( psz_code );
1060 if( *pl->psz_native_name )
1062 return strdup( pl->psz_native_name );
1064 return strdup( pl->psz_eng_name );