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,
249 vlc_bool_t b_delete )
251 es_out_sys_t *p_sys = out->p_sys;
252 input_thread_t *p_input = p_sys->p_input;
253 vlc_value_t val, text;
257 if( es->fmt.i_cat == AUDIO_ES )
258 psz_var = "audio-es";
259 else if( es->fmt.i_cat == VIDEO_ES )
260 psz_var = "video-es";
261 else if( es->fmt.i_cat == SPU_ES )
268 val.i_int = es->i_id;
269 var_Change( p_input, psz_var, VLC_VAR_DELCHOICE, &val, NULL );
270 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
274 /* Get the number of ES already added */
275 var_Change( p_input, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
280 /* First one, we need to add the "Disable" choice */
281 val2.i_int = -1; text.psz_string = _("Disable");
282 var_Change( p_input, psz_var, VLC_VAR_ADDCHOICE, &val2, &text );
286 /* Take care of the ES description */
287 if( es->psz_description && *es->psz_description )
289 text.psz_string = strdup( es->psz_description );
293 text.psz_string = malloc( strlen( _("Track %i") ) + 20 );
294 sprintf( text.psz_string, _("Track %i"), val.i_int );
297 val.i_int = es->i_id;
298 var_Change( p_input, psz_var, VLC_VAR_ADDCHOICE, &val, &text );
300 free( text.psz_string );
302 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
305 /* EsOutProgramSelect:
306 * Select a program and update the object variable
308 static void EsOutProgramSelect( es_out_t *out, es_out_pgrm_t *p_pgrm )
310 es_out_sys_t *p_sys = out->p_sys;
311 input_thread_t *p_input = p_sys->p_input;
315 if( p_sys->p_pgrm == p_pgrm )
316 return; /* Nothing to do */
320 es_out_pgrm_t *old = p_sys->p_pgrm;
321 msg_Dbg( p_input, "Unselecting program id=%d", old->i_id );
323 for( i = 0; i < p_sys->i_es; i++ )
325 if( p_sys->es[i]->p_pgrm == old && p_sys->es[i]->p_dec &&
326 p_sys->i_mode != ES_OUT_MODE_ALL )
327 EsUnselect( out, p_sys->es[i], VLC_TRUE );
331 msg_Dbg( p_input, "Selecting program id=%d", p_pgrm->i_id );
333 /* Mark it selected */
334 p_pgrm->b_selected = VLC_TRUE;
336 /* Switch master stream */
337 if( p_sys->p_pgrm && p_sys->p_pgrm->clock.b_master )
339 p_sys->p_pgrm->clock.b_master = VLC_FALSE;
341 p_pgrm->clock.b_master = VLC_TRUE;
342 p_sys->p_pgrm = p_pgrm;
344 /* Update "program" */
345 val.i_int = p_pgrm->i_id;
346 var_Change( p_input, "program", VLC_VAR_SETVALUE, &val, NULL );
349 var_Change( p_input, "audio-es", VLC_VAR_CLEARCHOICES, NULL, NULL );
350 var_Change( p_input, "video-es", VLC_VAR_CLEARCHOICES, NULL, NULL );
351 var_Change( p_input, "spu-es", VLC_VAR_CLEARCHOICES, NULL, NULL );
352 for( i = 0; i < p_sys->i_es; i++ )
354 EsOutESVarUpdate( out, p_sys->es[i], VLC_FALSE );
355 EsOutSelect( out, p_sys->es[i], VLC_FALSE );
358 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
364 static es_out_pgrm_t *EsOutProgramAdd( es_out_t *out, int i_group )
366 es_out_sys_t *p_sys = out->p_sys;
367 input_thread_t *p_input = p_sys->p_input;
370 es_out_pgrm_t *p_pgrm = malloc( sizeof( es_out_pgrm_t ) );
373 p_pgrm->i_id = i_group;
375 p_pgrm->b_selected = VLC_FALSE;
376 input_ClockInit( &p_pgrm->clock, VLC_FALSE, p_input->input.i_cr_average );
379 TAB_APPEND( p_sys->i_pgrm, p_sys->pgrm, p_pgrm );
381 /* Update "program" variable */
383 var_Change( p_input, "program", VLC_VAR_ADDCHOICE, &val, NULL );
385 if( i_group == var_GetInteger( p_input, "program" ) )
387 EsOutProgramSelect( out, p_pgrm );
391 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
399 static es_out_id_t *EsOutAdd( es_out_t *out, es_format_t *fmt )
401 es_out_sys_t *p_sys = out->p_sys;
402 input_thread_t *p_input = p_sys->p_input;
404 es_out_id_t *es = malloc( sizeof( es_out_id_t ) );
405 es_out_pgrm_t *p_pgrm = NULL;
408 if( fmt->i_group < 0 )
410 msg_Err( p_input, "invakud group number" );
414 /* Search the program */
415 for( i = 0; i < p_sys->i_pgrm; i++ )
417 if( fmt->i_group == p_sys->pgrm[i]->i_id )
419 p_pgrm = p_sys->pgrm[i];
425 /* Create a new one */
426 p_pgrm = EsOutProgramAdd( out, fmt->i_group );
429 /* Increase ref count for program */
434 fmt->i_id = out->p_sys->i_id;
435 es->i_id = fmt->i_id;
437 es_format_Copy( &es->fmt, fmt );
441 es->i_channel = p_sys->i_audio;
445 es->i_channel = p_sys->i_video;
449 es->i_channel = p_sys->i_sub;
456 es->psz_description = LanguageGetName( fmt->psz_language );
459 if( es->p_pgrm == p_sys->p_pgrm )
460 EsOutESVarUpdate( out, es, VLC_FALSE );
463 /* Add stream info */
464 sprintf( psz_cat, _("Stream %d"), out->p_sys->i_id - 1 );
466 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Codec"),
467 "%.4s", (char*)&fmt->i_codec );
469 if( *psz_description )
470 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Language"),
471 "%s", psz_description );
473 if( fmt->psz_description && *fmt->psz_description )
474 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Description"),
475 "%s", fmt->psz_description );
477 /* Add information */
481 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
482 _("Type"), _("Audio") );
484 if( fmt->audio.i_channels > 0 )
485 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Channels"),
486 "%d", fmt->audio.i_channels );
488 if( fmt->audio.i_rate > 0 )
489 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Sample rate"),
490 _("%d Hz"), fmt->audio.i_rate );
492 if( fmt->audio.i_bitspersample > 0 )
493 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
494 _("Bits per sample"), "%d",
495 fmt->audio.i_bitspersample );
497 if( fmt->i_bitrate > 0 )
498 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Bitrate"),
499 _("%d bps"), fmt->i_bitrate );
503 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
504 _("Type"), _("Video") );
506 if( fmt->video.i_width > 0 && fmt->video.i_height > 0 )
507 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
508 _("Resolution"), "%dx%d",
509 fmt->video.i_width, fmt->video.i_height );
511 if( fmt->video.i_visible_width > 0 &&
512 fmt->video.i_visible_height > 0 )
513 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
514 _("Display resolution"), "%dx%d",
515 fmt->video.i_visible_width,
516 fmt->video.i_visible_height);
520 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
521 _("Type"), _("Subtitle") );
527 free( psz_description );
530 /* Select it if needed */
531 EsOutSelect( out, es, VLC_FALSE );
534 TAB_APPEND( out->p_sys->i_es, out->p_sys->es, es );
535 p_sys->i_id++; /* always incremented */
552 static void EsSelect( es_out_t *out, es_out_id_t *es )
554 es_out_sys_t *p_sys = out->p_sys;
555 input_thread_t *p_input = p_sys->p_input;
561 msg_Warn( p_input, "ES 0x%x is already selected", es->i_id );
565 if( es->fmt.i_cat == VIDEO_ES || es->fmt.i_cat == SPU_ES )
567 if( !var_GetBool( p_input, "video" ) ||
568 ( p_input->p_sout && !var_GetBool( p_input, "sout-video" ) ) )
570 msg_Dbg( p_input, "video is disabled, not selecting ES 0x%x",
575 else if( es->fmt.i_cat == AUDIO_ES )
577 var_Get( p_input, "audio", &val );
578 if( !var_GetBool( p_input, "audio" ) ||
579 ( p_input->p_sout && !var_GetBool( p_input, "sout-audio" ) ) )
581 msg_Dbg( p_input, "audio is disabled, not selecting ES 0x%x",
587 es->p_dec = input_DecoderNew( p_input, &es->fmt, VLC_FALSE );
588 if( es->p_dec == NULL || es->p_pgrm != p_sys->p_pgrm )
591 if( es->fmt.i_cat == VIDEO_ES )
592 psz_var = "video-es";
593 else if( es->fmt.i_cat == AUDIO_ES )
594 psz_var = "audio-es";
595 else if( es->fmt.i_cat == SPU_ES )
600 /* Mark it as selected */
601 val.i_int = es->i_id;
602 var_Change( p_input, psz_var, VLC_VAR_SETVALUE, &val, NULL );
605 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
608 static void EsUnselect( es_out_t *out, es_out_id_t *es, vlc_bool_t b_update )
610 es_out_sys_t *p_sys = out->p_sys;
611 input_thread_t *p_input = p_sys->p_input;
615 if( es->p_dec == NULL )
617 msg_Warn( p_input, "ES 0x%x is already unselected", es->i_id );
621 input_DecoderDelete( es->p_dec );
628 if( es->p_dec == NULL )
630 if( es->fmt.i_cat == VIDEO_ES )
631 psz_var = "video-es";
632 else if( es->fmt.i_cat == AUDIO_ES )
633 psz_var = "audio-es";
634 else if( es->fmt.i_cat == SPU_ES )
639 /* Mark it as selected */
641 var_Change( p_input, psz_var, VLC_VAR_SETVALUE, &val, NULL );
643 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
647 * Select an ES given the current mode
648 * XXX: you need to take a the lock before (stream.stream_lock)
650 * \param out The es_out structure
651 * \param es es_out_id structure
655 static void EsOutSelect( es_out_t *out, es_out_id_t *es, vlc_bool_t b_force )
657 es_out_sys_t *p_sys = out->p_sys;
659 int i_cat = es->fmt.i_cat;
661 if( !p_sys->b_active ||
662 ( !b_force && es->fmt.i_priority < 0 ) )
667 if( p_sys->i_mode == ES_OUT_MODE_ALL || b_force )
672 else if( p_sys->i_mode == ES_OUT_MODE_AUTO )
676 if( es->p_pgrm != p_sys->p_pgrm )
679 if( i_cat == AUDIO_ES )
681 if( p_sys->p_es_audio &&
682 p_sys->p_es_audio->fmt.i_priority >= es->fmt.i_priority )
686 i_wanted = p_sys->i_audio_last >= 0 ?
687 p_sys->i_audio_last : es->i_channel;
689 else if( i_cat == SPU_ES )
691 if( p_sys->p_es_sub &&
692 p_sys->p_es_sub->fmt.i_priority >=
697 i_wanted = p_sys->i_sub_last;
699 else if( i_cat == VIDEO_ES )
701 i_wanted = es->i_channel;
704 if( i_wanted == es->i_channel && es->p_dec == NULL )
708 /* FIXME TODO handle priority here */
711 if( i_cat == AUDIO_ES )
713 if( p_sys->i_mode == ES_OUT_MODE_AUTO &&
715 p_sys->p_es_audio != es &&
716 p_sys->p_es_audio->p_dec )
718 EsUnselect( out, p_sys->p_es_audio, VLC_FALSE );
720 p_sys->p_es_audio = es;
722 else if( i_cat == SPU_ES )
724 if( p_sys->i_mode == ES_OUT_MODE_AUTO &&
726 p_sys->p_es_sub != es &&
727 p_sys->p_es_sub->p_dec )
729 EsUnselect( out, p_sys->p_es_sub, VLC_FALSE );
731 p_sys->p_es_sub = es;
733 else if( i_cat == VIDEO_ES )
735 p_sys->p_es_video = es;
741 * Send a block for the given es_out
743 * \param out the es_out to send from
744 * \param es the es_out_id
745 * \param p_block the data block to send
747 static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
749 es_out_sys_t *p_sys = out->p_sys;
750 input_thread_t *p_input = p_sys->p_input;
751 es_out_pgrm_t *p_pgrm = es->p_pgrm;
754 if( es->fmt.i_cat == AUDIO_ES )
755 i_delay = p_sys->i_audio_delay;
756 else if( es->fmt.i_cat == SPU_ES )
757 i_delay = p_sys->i_spu_delay;
761 /* +11 -> avoid null value with non null dts/pts */
762 if( p_block->i_dts > 0 )
765 input_ClockGetTS( p_input, &p_pgrm->clock,
766 ( p_block->i_dts + 11 ) * 9 / 100 ) + i_delay;
768 if( p_block->i_pts > 0 )
771 input_ClockGetTS( p_input, &p_pgrm->clock,
772 ( p_block->i_pts + 11 ) * 9 / 100 ) + i_delay;
775 p_block->i_rate = p_input->i_rate;
777 /* TODO handle mute */
778 if( es->p_dec && ( es->fmt.i_cat != AUDIO_ES || p_input->i_rate == INPUT_RATE_DEFAULT ) )
780 input_DecoderDecode( es->p_dec, p_block );
784 block_Release( p_block );
790 /*****************************************************************************
792 *****************************************************************************/
793 static void EsOutDel( es_out_t *out, es_out_id_t *es )
795 es_out_sys_t *p_sys = out->p_sys;
797 /* We don't try to reselect */
799 EsUnselect( out, es, es->p_pgrm == p_sys->p_pgrm );
801 if( es->p_pgrm == p_sys->p_pgrm )
802 EsOutESVarUpdate( out, es, VLC_TRUE );
804 TAB_REMOVE( p_sys->i_es, p_sys->es, es );
807 if( es->p_pgrm->i_es == 0 )
809 msg_Err( p_sys->p_input, "Program doesn't contain anymore ES, "
813 if( p_sys->p_es_audio == es ) p_sys->p_es_audio = NULL;
814 if( p_sys->p_es_video == es ) p_sys->p_es_video = NULL;
815 if( p_sys->p_es_sub == es ) p_sys->p_es_sub = NULL;
817 switch( es->fmt.i_cat )
830 if( es->psz_description )
831 free( es->psz_description );
833 es_format_Clean( &es->fmt );
839 * Control query handler
841 * \param out the es_out to control
842 * \param i_query A es_out query as defined in include/ninput.h
843 * \param args a variable list of arguments for the query
844 * \return VLC_SUCCESS or an error code
846 static int EsOutControl( es_out_t *out, int i_query, va_list args )
848 es_out_sys_t *p_sys = out->p_sys;
856 case ES_OUT_SET_ES_STATE:
857 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
858 b = (vlc_bool_t) va_arg( args, vlc_bool_t );
859 if( b && es->p_dec == NULL )
862 return es->p_dec ? VLC_SUCCESS : VLC_EGENERIC;
864 else if( !b && es->p_dec )
866 EsUnselect( out, es, es->p_pgrm == p_sys->p_pgrm );
871 case ES_OUT_GET_ES_STATE:
872 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
873 pb = (vlc_bool_t*) va_arg( args, vlc_bool_t * );
875 *pb = es->p_dec ? VLC_TRUE : VLC_FALSE;
878 case ES_OUT_SET_ACTIVE:
880 b = (vlc_bool_t) va_arg( args, vlc_bool_t );
884 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
888 case ES_OUT_GET_ACTIVE:
889 pb = (vlc_bool_t*) va_arg( args, vlc_bool_t * );
890 *pb = p_sys->b_active;
893 case ES_OUT_SET_MODE:
894 i = (int) va_arg( args, int );
895 if( i == ES_OUT_MODE_NONE || i == ES_OUT_MODE_ALL ||
896 i == ES_OUT_MODE_AUTO )
900 /* Reapply policy mode */
901 for( i = 0; i < p_sys->i_es; i++ )
903 if( p_sys->es[i]->p_dec )
905 EsUnselect( out, p_sys->es[i],
906 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
909 for( i = 0; i < p_sys->i_es; i++ )
911 EsOutSelect( out, p_sys->es[i], VLC_FALSE );
917 case ES_OUT_GET_MODE:
918 pi = (int*) va_arg( args, int* );
923 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
924 /* Special case NULL, NULL+i_cat */
927 for( i = 0; i < p_sys->i_es; i++ )
929 if( p_sys->es[i]->p_dec )
930 EsUnselect( out, p_sys->es[i],
931 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
934 else if( es == (es_out_id_t*)((uint8_t*)NULL+AUDIO_ES) )
936 for( i = 0; i < p_sys->i_es; i++ )
938 if( p_sys->es[i]->p_dec &&
939 p_sys->es[i]->fmt.i_cat == AUDIO_ES )
940 EsUnselect( out, p_sys->es[i],
941 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
944 else if( es == (es_out_id_t*)((uint8_t*)NULL+VIDEO_ES) )
946 for( i = 0; i < p_sys->i_es; i++ )
948 if( p_sys->es[i]->p_dec &&
949 p_sys->es[i]->fmt.i_cat == VIDEO_ES )
950 EsUnselect( out, p_sys->es[i],
951 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
954 else if( es == (es_out_id_t*)((uint8_t*)NULL+SPU_ES) )
956 for( i = 0; i < p_sys->i_es; i++ )
958 if( p_sys->es[i]->p_dec &&
959 p_sys->es[i]->fmt.i_cat == SPU_ES )
960 EsUnselect( out, p_sys->es[i],
961 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
966 for( i = 0; i < p_sys->i_es; i++ )
968 if( es == p_sys->es[i] )
970 EsOutSelect( out, es, VLC_TRUE );
978 case ES_OUT_SET_GROUP_PCR:
980 es_out_pgrm_t *p_pgrm = NULL;
984 if( i_query == ES_OUT_SET_PCR )
986 p_pgrm = p_sys->p_pgrm;
991 i_group = (int)va_arg( args, int );
992 for( i = 0; i < p_sys->i_pgrm; i++ )
994 if( p_sys->pgrm[i]->i_id == i_group )
996 p_pgrm = p_sys->pgrm[i];
1001 if( p_pgrm == NULL )
1002 p_pgrm = EsOutProgramAdd( out, i_group ); /* Create it */
1004 i_pcr = (int64_t)va_arg( args, int64_t );
1005 /* search program */
1006 /* 11 is a vodoo trick to avoid non_pcr*9/100 to be null */
1007 input_ClockSetPCR( p_sys->p_input, &p_pgrm->clock,
1008 (i_pcr + 11 ) * 9 / 100);
1012 case ES_OUT_RESET_PCR:
1013 for( i = 0; i < p_sys->i_pgrm; i++ )
1015 p_sys->pgrm[i]->clock.i_synchro_state = SYNCHRO_REINIT;
1016 p_sys->pgrm[i]->clock.last_pts = 0;
1020 case ES_OUT_GET_GROUP:
1021 pi = (int*) va_arg( args, int* );
1023 *pi = p_sys->p_pgrm->i_id;
1025 *pi = -1; /* FIXME */
1028 case ES_OUT_SET_GROUP:
1031 i = (int) va_arg( args, int );
1032 for( j = 0; j < p_sys->i_pgrm; j++ )
1034 es_out_pgrm_t *p_pgrm = p_sys->pgrm[j];
1035 if( p_pgrm->i_id == i )
1037 EsOutProgramSelect( out, p_pgrm );
1041 return VLC_EGENERIC;
1045 msg_Err( p_sys->p_input, "unknown query in es_out_Control" );
1046 return VLC_EGENERIC;
1050 /****************************************************************************
1051 * LanguageGetName: try to expend iso639 into plain name
1052 ****************************************************************************/
1053 static char *LanguageGetName( const char *psz_code )
1055 const iso639_lang_t *pl;
1057 if( psz_code == NULL )
1059 return strdup( "" );
1062 if( strlen( psz_code ) == 2 )
1064 pl = GetLang_1( psz_code );
1066 else if( strlen( psz_code ) == 3 )
1068 pl = GetLang_2B( psz_code );
1069 if( !strcmp( pl->psz_iso639_1, "??" ) )
1071 pl = GetLang_2T( psz_code );
1076 return strdup( psz_code );
1079 if( !strcmp( pl->psz_iso639_1, "??" ) )
1081 return strdup( psz_code );
1085 if( *pl->psz_native_name )
1087 return strdup( pl->psz_native_name );
1089 return strdup( pl->psz_eng_name );