2 /*****************************************************************************
3 * es_out.c: Es Out handler for input.
4 *****************************************************************************
5 * Copyright (C) 2003-2004 VideoLAN
8 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
31 #include <vlc/input.h>
32 #include <vlc/decoder.h>
34 #include "input_internal.h"
36 #include "vlc_playlist.h"
39 /*****************************************************************************
41 *****************************************************************************/
47 /* Number of es for this pgrm */
50 vlc_bool_t b_selected;
52 /* Clock for this program */
61 es_out_pgrm_t *p_pgrm;
63 /* Channel in the track type */
72 input_thread_t *p_input;
77 es_out_pgrm_t **pp_selected_pgrm; /* --programs */
78 es_out_pgrm_t *p_pgrm; /* Master program */
99 es_out_id_t *p_es_audio;
100 es_out_id_t *p_es_video;
101 es_out_id_t *p_es_sub;
104 int64_t i_audio_delay;
108 static es_out_id_t *EsOutAdd ( es_out_t *, es_format_t * );
109 static int EsOutSend ( es_out_t *, es_out_id_t *, block_t * );
110 static void EsOutDel ( es_out_t *, es_out_id_t * );
111 static void EsOutSelect( es_out_t *out, es_out_id_t *es, vlc_bool_t b_force );
112 static int EsOutControl( es_out_t *, int i_query, va_list );
114 static void EsOutAddInfo( es_out_t *, es_out_id_t *es );
116 static void EsSelect( es_out_t *out, es_out_id_t *es );
117 static void EsUnselect( es_out_t *out, es_out_id_t *es, vlc_bool_t b_update );
118 static char *LanguageGetName( const char *psz_code );
120 /*****************************************************************************
122 *****************************************************************************/
123 es_out_t *input_EsOutNew( input_thread_t *p_input )
125 es_out_t *out = malloc( sizeof( es_out_t ) );
126 es_out_sys_t *p_sys = malloc( sizeof( es_out_sys_t ) );
129 out->pf_add = EsOutAdd;
130 out->pf_send = EsOutSend;
131 out->pf_del = EsOutDel;
132 out->pf_control = EsOutControl;
135 p_sys->p_input = p_input;
137 p_sys->b_active = VLC_FALSE;
138 p_sys->i_mode = ES_OUT_MODE_AUTO;
143 p_sys->p_pgrm = NULL;
153 var_Get( p_input, "audio-channel", &val );
154 p_sys->i_audio_last = val.i_int;
156 var_Get( p_input, "spu-channel", &val );
157 p_sys->i_sub_last = val.i_int;
159 p_sys->p_es_audio = NULL;
160 p_sys->p_es_video = NULL;
161 p_sys->p_es_sub = NULL;
163 p_sys->i_audio_delay= 0;
164 p_sys->i_spu_delay = 0;
169 /*****************************************************************************
171 *****************************************************************************/
172 void input_EsOutDelete( es_out_t *out )
174 es_out_sys_t *p_sys = out->p_sys;
177 for( i = 0; i < p_sys->i_es; i++ )
179 if( p_sys->es[i]->p_dec )
181 input_DecoderDelete( p_sys->es[i]->p_dec );
183 if( p_sys->es[i]->psz_language )
184 free( p_sys->es[i]->psz_language );
185 es_format_Clean( &p_sys->es[i]->fmt );
187 free( p_sys->es[i] );
192 for( i = 0; i < p_sys->i_pgrm; i++ )
194 free( p_sys->pgrm[i] );
203 es_out_id_t *input_EsOutGetFromID( es_out_t *out, int i_id )
208 /* Special HACK, -i_id is tha cat of the stream */
209 return (es_out_id_t*)((uint8_t*)NULL-i_id);
212 for( i = 0; i < out->p_sys->i_es; i++ )
214 if( out->p_sys->es[i]->i_id == i_id )
215 return out->p_sys->es[i];
220 void input_EsOutDiscontinuity( es_out_t *out, vlc_bool_t b_audio )
222 es_out_sys_t *p_sys = out->p_sys;
225 for( i = 0; i < p_sys->i_es; i++ )
227 es_out_id_t *es = p_sys->es[i];
229 /* Send a dummy block to let decoder know that
230 * there is a discontinuity */
231 if( es->p_dec && ( !b_audio || es->fmt.i_cat == AUDIO_ES ) )
233 input_DecoderDiscontinuity( es->p_dec );
238 void input_EsOutSetDelay( es_out_t *out, int i_cat, int64_t i_delay )
240 es_out_sys_t *p_sys = out->p_sys;
242 if( i_cat == AUDIO_ES )
243 p_sys->i_audio_delay = i_delay;
244 else if( i_cat == SPU_ES )
245 p_sys->i_spu_delay = i_delay;
248 vlc_bool_t input_EsOutDecodersEmpty( es_out_t *out )
250 es_out_sys_t *p_sys = out->p_sys;
253 for( i = 0; i < p_sys->i_es; i++ )
255 es_out_id_t *es = p_sys->es[i];
257 if( es->p_dec && !input_DecoderEmpty( es->p_dec ) )
263 /*****************************************************************************
265 *****************************************************************************/
266 static void EsOutESVarUpdate( es_out_t *out, es_out_id_t *es,
267 vlc_bool_t b_delete )
269 es_out_sys_t *p_sys = out->p_sys;
270 input_thread_t *p_input = p_sys->p_input;
271 vlc_value_t val, text;
275 if( es->fmt.i_cat == AUDIO_ES )
276 psz_var = "audio-es";
277 else if( es->fmt.i_cat == VIDEO_ES )
278 psz_var = "video-es";
279 else if( es->fmt.i_cat == SPU_ES )
286 val.i_int = es->i_id;
287 var_Change( p_input, psz_var, VLC_VAR_DELCHOICE, &val, NULL );
288 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
292 /* Get the number of ES already added */
293 var_Change( p_input, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
298 /* First one, we need to add the "Disable" choice */
299 val2.i_int = -1; text.psz_string = _("Disable");
300 var_Change( p_input, psz_var, VLC_VAR_ADDCHOICE, &val2, &text );
304 /* Take care of the ES description */
305 if( es->fmt.psz_description && *es->fmt.psz_description )
307 if( es->psz_language && *es->psz_language )
309 text.psz_string = malloc( strlen( es->fmt.psz_description) + strlen( es->psz_language ) + 10 );
310 sprintf( text.psz_string, "%s - [%s]", es->fmt.psz_description, es->psz_language );
312 else text.psz_string = strdup( es->fmt.psz_description );
316 if( es->psz_language && *es->psz_language )
319 text.psz_string = malloc( strlen( _("Track %i") )+ strlen( es->psz_language ) + 30 );
320 asprintf( &temp, _("Track %i"), val.i_int );
321 sprintf( text.psz_string, "%s - [%s]", temp, es->psz_language );
326 text.psz_string = malloc( strlen( _("Track %i") ) + 20 );
327 sprintf( text.psz_string, _("Track %i"), val.i_int );
331 val.i_int = es->i_id;
332 var_Change( p_input, psz_var, VLC_VAR_ADDCHOICE, &val, &text );
334 free( text.psz_string );
336 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
339 /* EsOutProgramSelect:
340 * Select a program and update the object variable
342 static void EsOutProgramSelect( es_out_t *out, es_out_pgrm_t *p_pgrm )
344 es_out_sys_t *p_sys = out->p_sys;
345 input_thread_t *p_input = p_sys->p_input;
349 if( p_sys->p_pgrm == p_pgrm )
350 return; /* Nothing to do */
354 es_out_pgrm_t *old = p_sys->p_pgrm;
355 msg_Dbg( p_input, "Unselecting program id=%d", old->i_id );
357 for( i = 0; i < p_sys->i_es; i++ )
359 if( p_sys->es[i]->p_pgrm == old && p_sys->es[i]->p_dec &&
360 p_sys->i_mode != ES_OUT_MODE_ALL )
361 EsUnselect( out, p_sys->es[i], VLC_TRUE );
365 msg_Dbg( p_input, "Selecting program id=%d", p_pgrm->i_id );
367 /* Mark it selected */
368 p_pgrm->b_selected = VLC_TRUE;
370 /* Switch master stream */
371 if( p_sys->p_pgrm && p_sys->p_pgrm->clock.b_master )
373 p_sys->p_pgrm->clock.b_master = VLC_FALSE;
375 p_pgrm->clock.b_master = VLC_TRUE;
376 p_sys->p_pgrm = p_pgrm;
378 /* Update "program" */
379 val.i_int = p_pgrm->i_id;
380 var_Change( p_input, "program", VLC_VAR_SETVALUE, &val, NULL );
383 var_Change( p_input, "audio-es", VLC_VAR_CLEARCHOICES, NULL, NULL );
384 var_Change( p_input, "video-es", VLC_VAR_CLEARCHOICES, NULL, NULL );
385 var_Change( p_input, "spu-es", VLC_VAR_CLEARCHOICES, NULL, NULL );
386 for( i = 0; i < p_sys->i_es; i++ )
388 EsOutESVarUpdate( out, p_sys->es[i], VLC_FALSE );
389 EsOutSelect( out, p_sys->es[i], VLC_FALSE );
392 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
398 static es_out_pgrm_t *EsOutProgramAdd( es_out_t *out, int i_group )
400 es_out_sys_t *p_sys = out->p_sys;
401 input_thread_t *p_input = p_sys->p_input;
404 es_out_pgrm_t *p_pgrm = malloc( sizeof( es_out_pgrm_t ) );
407 p_pgrm->i_id = i_group;
409 p_pgrm->b_selected = VLC_FALSE;
410 input_ClockInit( &p_pgrm->clock, VLC_FALSE, p_input->input.i_cr_average );
413 TAB_APPEND( p_sys->i_pgrm, p_sys->pgrm, p_pgrm );
415 /* Update "program" variable */
417 var_Change( p_input, "program", VLC_VAR_ADDCHOICE, &val, NULL );
419 if( i_group == var_GetInteger( p_input, "program" ) )
421 EsOutProgramSelect( out, p_pgrm );
425 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
433 static es_out_id_t *EsOutAdd( es_out_t *out, es_format_t *fmt )
435 es_out_sys_t *p_sys = out->p_sys;
436 input_thread_t *p_input = p_sys->p_input;
438 es_out_id_t *es = malloc( sizeof( es_out_id_t ) );
439 es_out_pgrm_t *p_pgrm = NULL;
442 if( fmt->i_group < 0 )
444 msg_Err( p_input, "invalid group number" );
448 /* Search the program */
449 for( i = 0; i < p_sys->i_pgrm; i++ )
451 if( fmt->i_group == p_sys->pgrm[i]->i_id )
453 p_pgrm = p_sys->pgrm[i];
459 /* Create a new one */
460 p_pgrm = EsOutProgramAdd( out, fmt->i_group );
463 /* Increase ref count for program */
468 fmt->i_id = out->p_sys->i_id;
469 es->i_id = fmt->i_id;
471 es_format_Copy( &es->fmt, fmt );
475 es->i_channel = p_sys->i_audio;
479 es->i_channel = p_sys->i_video;
483 es->i_channel = p_sys->i_sub;
490 es->psz_language = LanguageGetName( fmt->psz_language ); /* remember so we only need to do it once */
493 if( es->p_pgrm == p_sys->p_pgrm )
494 EsOutESVarUpdate( out, es, VLC_FALSE );
496 /* Select it if needed */
497 EsOutSelect( out, es, VLC_FALSE );
500 TAB_APPEND( out->p_sys->i_es, out->p_sys->es, es );
501 p_sys->i_id++; /* always incremented */
515 EsOutAddInfo( out, es );
520 static void EsSelect( es_out_t *out, es_out_id_t *es )
522 es_out_sys_t *p_sys = out->p_sys;
523 input_thread_t *p_input = p_sys->p_input;
529 msg_Warn( p_input, "ES 0x%x is already selected", es->i_id );
533 if( es->fmt.i_cat == VIDEO_ES || es->fmt.i_cat == SPU_ES )
535 if( !var_GetBool( p_input, "video" ) ||
536 ( p_input->p_sout && !var_GetBool( p_input, "sout-video" ) ) )
538 msg_Dbg( p_input, "video is disabled, not selecting ES 0x%x",
543 else if( es->fmt.i_cat == AUDIO_ES )
545 var_Get( p_input, "audio", &val );
546 if( !var_GetBool( p_input, "audio" ) ||
547 ( p_input->p_sout && !var_GetBool( p_input, "sout-audio" ) ) )
549 msg_Dbg( p_input, "audio is disabled, not selecting ES 0x%x",
555 es->p_dec = input_DecoderNew( p_input, &es->fmt, VLC_FALSE );
556 if( es->p_dec == NULL || es->p_pgrm != p_sys->p_pgrm )
559 if( es->fmt.i_cat == VIDEO_ES )
560 psz_var = "video-es";
561 else if( es->fmt.i_cat == AUDIO_ES )
562 psz_var = "audio-es";
563 else if( es->fmt.i_cat == SPU_ES )
568 /* Mark it as selected */
569 val.i_int = es->i_id;
570 var_Change( p_input, psz_var, VLC_VAR_SETVALUE, &val, NULL );
573 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
576 static void EsUnselect( es_out_t *out, es_out_id_t *es, vlc_bool_t b_update )
578 es_out_sys_t *p_sys = out->p_sys;
579 input_thread_t *p_input = p_sys->p_input;
583 if( es->p_dec == NULL )
585 msg_Warn( p_input, "ES 0x%x is already unselected", es->i_id );
589 input_DecoderDelete( es->p_dec );
596 if( es->p_dec == NULL )
598 if( es->fmt.i_cat == VIDEO_ES )
599 psz_var = "video-es";
600 else if( es->fmt.i_cat == AUDIO_ES )
601 psz_var = "audio-es";
602 else if( es->fmt.i_cat == SPU_ES )
607 /* Mark it as selected */
609 var_Change( p_input, psz_var, VLC_VAR_SETVALUE, &val, NULL );
611 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
615 * Select an ES given the current mode
616 * XXX: you need to take a the lock before (stream.stream_lock)
618 * \param out The es_out structure
619 * \param es es_out_id structure
623 static void EsOutSelect( es_out_t *out, es_out_id_t *es, vlc_bool_t b_force )
625 es_out_sys_t *p_sys = out->p_sys;
627 int i_cat = es->fmt.i_cat;
629 if( !p_sys->b_active ||
630 ( !b_force && es->fmt.i_priority < 0 ) )
635 if( p_sys->i_mode == ES_OUT_MODE_ALL || b_force )
640 else if( p_sys->i_mode == ES_OUT_MODE_PARTIAL )
644 var_Get( p_sys->p_input, "programs", &val );
645 for ( i = 0; i < val.p_list->i_count; i++ )
647 if ( val.p_list->p_values[i].i_int == es->p_pgrm->i_id || b_force )
654 var_Change( p_sys->p_input, "programs", VLC_VAR_FREELIST, &val, NULL );
656 else if( p_sys->i_mode == ES_OUT_MODE_AUTO )
660 if( es->p_pgrm != p_sys->p_pgrm )
663 if( i_cat == AUDIO_ES )
665 if( p_sys->p_es_audio &&
666 p_sys->p_es_audio->fmt.i_priority >= es->fmt.i_priority )
670 i_wanted = p_sys->i_audio_last >= 0 ?
671 p_sys->i_audio_last : es->i_channel;
673 else if( i_cat == SPU_ES )
675 if( p_sys->p_es_sub &&
676 p_sys->p_es_sub->fmt.i_priority >=
681 i_wanted = p_sys->i_sub_last;
683 else if( i_cat == VIDEO_ES )
685 i_wanted = es->i_channel;
688 if( i_wanted == es->i_channel && es->p_dec == NULL )
692 /* FIXME TODO handle priority here */
695 if( i_cat == AUDIO_ES )
697 if( p_sys->i_mode == ES_OUT_MODE_AUTO &&
699 p_sys->p_es_audio != es &&
700 p_sys->p_es_audio->p_dec )
702 EsUnselect( out, p_sys->p_es_audio, VLC_FALSE );
704 p_sys->p_es_audio = es;
706 else if( i_cat == SPU_ES )
708 if( p_sys->i_mode == ES_OUT_MODE_AUTO &&
710 p_sys->p_es_sub != es &&
711 p_sys->p_es_sub->p_dec )
713 EsUnselect( out, p_sys->p_es_sub, VLC_FALSE );
715 p_sys->p_es_sub = es;
717 else if( i_cat == VIDEO_ES )
719 p_sys->p_es_video = es;
725 * Send a block for the given es_out
727 * \param out the es_out to send from
728 * \param es the es_out_id
729 * \param p_block the data block to send
731 static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
733 es_out_sys_t *p_sys = out->p_sys;
734 input_thread_t *p_input = p_sys->p_input;
735 es_out_pgrm_t *p_pgrm = es->p_pgrm;
738 if( es->fmt.i_cat == AUDIO_ES )
739 i_delay = p_sys->i_audio_delay;
740 else if( es->fmt.i_cat == SPU_ES )
741 i_delay = p_sys->i_spu_delay;
745 /* +11 -> avoid null value with non null dts/pts */
746 if( p_block->i_dts > 0 )
749 input_ClockGetTS( p_input, &p_pgrm->clock,
750 ( p_block->i_dts + 11 ) * 9 / 100 ) + i_delay;
752 if( p_block->i_pts > 0 )
755 input_ClockGetTS( p_input, &p_pgrm->clock,
756 ( p_block->i_pts + 11 ) * 9 / 100 ) + i_delay;
758 if ( es->fmt.i_codec == VLC_FOURCC( 't', 'e', 'l', 'x' ) )
760 mtime_t current_date = mdate();
762 || p_block->i_pts > current_date + 10000000
763 || current_date > p_block->i_pts )
765 /* ETSI EN 300 472 Annex A : do not take into account the PTS
766 * for teletext streams. */
767 p_block->i_pts = current_date + 400000
768 + p_input->i_pts_delay + i_delay;
772 p_block->i_rate = p_input->i_rate;
774 /* TODO handle mute */
775 if( es->p_dec && ( es->fmt.i_cat != AUDIO_ES ||
776 p_input->i_rate == INPUT_RATE_DEFAULT ) )
778 input_DecoderDecode( es->p_dec, p_block );
782 block_Release( p_block );
788 /*****************************************************************************
790 *****************************************************************************/
791 static void EsOutDel( es_out_t *out, es_out_id_t *es )
793 es_out_sys_t *p_sys = out->p_sys;
795 /* We don't try to reselect */
797 EsUnselect( out, es, es->p_pgrm == p_sys->p_pgrm );
799 if( es->p_pgrm == p_sys->p_pgrm )
800 EsOutESVarUpdate( out, es, VLC_TRUE );
802 TAB_REMOVE( p_sys->i_es, p_sys->es, es );
805 if( es->p_pgrm->i_es == 0 )
807 msg_Warn( p_sys->p_input, "Program doesn't contain anymore ES, "
811 if( p_sys->p_es_audio == es ) p_sys->p_es_audio = NULL;
812 if( p_sys->p_es_video == es ) p_sys->p_es_video = NULL;
813 if( p_sys->p_es_sub == es ) p_sys->p_es_sub = NULL;
815 switch( es->fmt.i_cat )
828 if( es->psz_language )
829 free( es->psz_language );
831 es_format_Clean( &es->fmt );
837 * Control query handler
839 * \param out the es_out to control
840 * \param i_query A es_out query as defined in include/ninput.h
841 * \param args a variable list of arguments for the query
842 * \return VLC_SUCCESS or an error code
844 static int EsOutControl( es_out_t *out, int i_query, va_list args )
846 es_out_sys_t *p_sys = out->p_sys;
854 case ES_OUT_SET_ES_STATE:
855 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
856 b = (vlc_bool_t) va_arg( args, vlc_bool_t );
857 if( b && es->p_dec == NULL )
860 return es->p_dec ? VLC_SUCCESS : VLC_EGENERIC;
862 else if( !b && es->p_dec )
864 EsUnselect( out, es, es->p_pgrm == p_sys->p_pgrm );
869 case ES_OUT_GET_ES_STATE:
870 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
871 pb = (vlc_bool_t*) va_arg( args, vlc_bool_t * );
873 *pb = es->p_dec ? VLC_TRUE : VLC_FALSE;
876 case ES_OUT_SET_ACTIVE:
878 b = (vlc_bool_t) va_arg( args, vlc_bool_t );
882 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
886 case ES_OUT_GET_ACTIVE:
887 pb = (vlc_bool_t*) va_arg( args, vlc_bool_t * );
888 *pb = p_sys->b_active;
891 case ES_OUT_SET_MODE:
892 i = (int) va_arg( args, int );
893 if( i == ES_OUT_MODE_NONE || i == ES_OUT_MODE_ALL ||
894 i == ES_OUT_MODE_AUTO || i == ES_OUT_MODE_PARTIAL )
898 /* Reapply policy mode */
899 for( i = 0; i < p_sys->i_es; i++ )
901 if( p_sys->es[i]->p_dec )
903 EsUnselect( out, p_sys->es[i],
904 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
907 for( i = 0; i < p_sys->i_es; i++ )
909 EsOutSelect( out, p_sys->es[i], VLC_FALSE );
915 case ES_OUT_GET_MODE:
916 pi = (int*) va_arg( args, int* );
921 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
922 /* Special case NULL, NULL+i_cat */
925 for( i = 0; i < p_sys->i_es; i++ )
927 if( p_sys->es[i]->p_dec )
928 EsUnselect( out, p_sys->es[i],
929 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
932 else if( es == (es_out_id_t*)((uint8_t*)NULL+AUDIO_ES) )
934 for( i = 0; i < p_sys->i_es; i++ )
936 if( p_sys->es[i]->p_dec &&
937 p_sys->es[i]->fmt.i_cat == AUDIO_ES )
938 EsUnselect( out, p_sys->es[i],
939 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
942 else if( es == (es_out_id_t*)((uint8_t*)NULL+VIDEO_ES) )
944 for( i = 0; i < p_sys->i_es; i++ )
946 if( p_sys->es[i]->p_dec &&
947 p_sys->es[i]->fmt.i_cat == VIDEO_ES )
948 EsUnselect( out, p_sys->es[i],
949 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
952 else if( es == (es_out_id_t*)((uint8_t*)NULL+SPU_ES) )
954 for( i = 0; i < p_sys->i_es; i++ )
956 if( p_sys->es[i]->p_dec &&
957 p_sys->es[i]->fmt.i_cat == SPU_ES )
958 EsUnselect( out, p_sys->es[i],
959 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
964 for( i = 0; i < p_sys->i_es; i++ )
966 if( es == p_sys->es[i] )
968 EsOutSelect( out, es, VLC_TRUE );
976 case ES_OUT_SET_GROUP_PCR:
978 es_out_pgrm_t *p_pgrm = NULL;
982 if( i_query == ES_OUT_SET_PCR )
984 p_pgrm = p_sys->p_pgrm;
989 i_group = (int)va_arg( args, int );
990 for( i = 0; i < p_sys->i_pgrm; i++ )
992 if( p_sys->pgrm[i]->i_id == i_group )
994 p_pgrm = p_sys->pgrm[i];
1000 p_pgrm = EsOutProgramAdd( out, i_group ); /* Create it */
1002 i_pcr = (int64_t)va_arg( args, int64_t );
1003 /* search program */
1004 /* 11 is a vodoo trick to avoid non_pcr*9/100 to be null */
1005 input_ClockSetPCR( p_sys->p_input, &p_pgrm->clock,
1006 (i_pcr + 11 ) * 9 / 100);
1010 case ES_OUT_RESET_PCR:
1011 for( i = 0; i < p_sys->i_pgrm; i++ )
1013 p_sys->pgrm[i]->clock.i_synchro_state = SYNCHRO_REINIT;
1014 p_sys->pgrm[i]->clock.last_pts = 0;
1021 int64_t i_ts = (int64_t)va_arg( args, int64_t );
1022 int64_t *pi_ts = (int64_t *)va_arg( args, int64_t * );
1023 *pi_ts = input_ClockGetTS( p_sys->p_input,
1024 &p_sys->p_pgrm->clock,
1025 ( i_ts + 11 ) * 9 / 100 );
1028 return VLC_EGENERIC;
1030 case ES_OUT_GET_GROUP:
1031 pi = (int*) va_arg( args, int* );
1033 *pi = p_sys->p_pgrm->i_id;
1035 *pi = -1; /* FIXME */
1038 case ES_OUT_SET_GROUP:
1041 i = (int) va_arg( args, int );
1042 for( j = 0; j < p_sys->i_pgrm; j++ )
1044 es_out_pgrm_t *p_pgrm = p_sys->pgrm[j];
1045 if( p_pgrm->i_id == i )
1047 EsOutProgramSelect( out, p_pgrm );
1051 return VLC_EGENERIC;
1054 case ES_OUT_SET_FMT:
1056 /* This ain't pretty but is need by some demuxers (eg. Ogg )
1057 * to update the p_extra data */
1059 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
1060 p_fmt = (es_format_t*) va_arg( args, es_format_t * );
1061 if( es == NULL ) return VLC_EGENERIC;
1063 if( p_fmt->i_extra )
1065 es->fmt.i_extra = p_fmt->i_extra;
1066 es->fmt.p_extra = realloc( es->fmt.p_extra, p_fmt->i_extra );
1067 memcpy( es->fmt.p_extra, p_fmt->p_extra, p_fmt->i_extra );
1069 if( !es->p_dec ) return VLC_SUCCESS;
1071 es->p_dec->fmt_in.i_extra = p_fmt->i_extra;
1072 es->p_dec->fmt_in.p_extra =
1073 realloc( es->p_dec->fmt_in.p_extra, p_fmt->i_extra );
1074 memcpy( es->p_dec->fmt_in.p_extra,
1075 p_fmt->p_extra, p_fmt->i_extra );
1082 msg_Err( p_sys->p_input, "unknown query in es_out_Control" );
1083 return VLC_EGENERIC;
1087 /****************************************************************************
1088 * LanguageGetName: try to expend iso639 into plain name
1089 ****************************************************************************/
1090 static char *LanguageGetName( const char *psz_code )
1092 const iso639_lang_t *pl;
1094 if( psz_code == NULL )
1096 return strdup( "" );
1099 if( strlen( psz_code ) == 2 )
1101 pl = GetLang_1( psz_code );
1103 else if( strlen( psz_code ) == 3 )
1105 pl = GetLang_2B( psz_code );
1106 if( !strcmp( pl->psz_iso639_1, "??" ) )
1108 pl = GetLang_2T( psz_code );
1113 return strdup( psz_code );
1116 if( !strcmp( pl->psz_iso639_1, "??" ) )
1118 return strdup( psz_code );
1122 if( *pl->psz_native_name )
1124 return strdup( pl->psz_native_name );
1126 return strdup( pl->psz_eng_name );
1130 /****************************************************************************
1132 * - add meta info to the playlist item
1133 ****************************************************************************/
1134 static void EsOutAddInfo( es_out_t *out, es_out_id_t *es )
1136 es_out_sys_t *p_sys = out->p_sys;
1137 input_thread_t *p_input = p_sys->p_input;
1138 es_format_t *fmt = &es->fmt;
1141 /* Add stream info */
1142 asprintf( &psz_cat, _("Stream %d"), out->p_sys->i_id - 1 );
1144 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Codec"),
1145 "%.4s", (char*)&fmt->i_codec );
1147 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Language"),
1148 "%s", es->psz_language );
1150 /* Add information */
1151 switch( fmt->i_cat )
1154 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1155 _("Type"), _("Audio") );
1157 if( fmt->audio.i_channels > 0 )
1158 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Channels"),
1159 "%d", fmt->audio.i_channels );
1161 if( fmt->audio.i_rate > 0 )
1162 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Sample rate"),
1163 _("%d Hz"), fmt->audio.i_rate );
1165 if( fmt->audio.i_bitspersample > 0 )
1166 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1167 _("Bits per sample"), "%d",
1168 fmt->audio.i_bitspersample );
1170 if( fmt->i_bitrate > 0 )
1171 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Bitrate"),
1172 _("%d kb/s"), fmt->i_bitrate / 1000 );
1176 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1177 _("Type"), _("Video") );
1179 if( fmt->video.i_width > 0 && fmt->video.i_height > 0 )
1180 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1181 _("Resolution"), "%dx%d",
1182 fmt->video.i_width, fmt->video.i_height );
1184 if( fmt->video.i_visible_width > 0 &&
1185 fmt->video.i_visible_height > 0 )
1186 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1187 _("Display resolution"), "%dx%d",
1188 fmt->video.i_visible_width,
1189 fmt->video.i_visible_height);
1193 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1194 _("Type"), _("Subtitle") );