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 **pp_selected_pgrm; /* --programs */
77 es_out_pgrm_t *p_pgrm; /* Master program */
98 es_out_id_t *p_es_audio;
99 es_out_id_t *p_es_video;
100 es_out_id_t *p_es_sub;
103 int64_t i_audio_delay;
107 static es_out_id_t *EsOutAdd ( es_out_t *, es_format_t * );
108 static int EsOutSend ( es_out_t *, es_out_id_t *, block_t * );
109 static void EsOutDel ( es_out_t *, es_out_id_t * );
110 static void EsOutSelect( es_out_t *out, es_out_id_t *es, vlc_bool_t b_force );
111 static int EsOutControl( es_out_t *, int i_query, va_list );
113 static void EsOutAddInfo( es_out_t *, es_out_id_t *es );
115 static void EsSelect( es_out_t *out, es_out_id_t *es );
116 static void EsUnselect( es_out_t *out, es_out_id_t *es, vlc_bool_t b_update );
117 static char *LanguageGetName( const char *psz_code );
119 /*****************************************************************************
121 *****************************************************************************/
122 es_out_t *input_EsOutNew( input_thread_t *p_input )
124 es_out_t *out = malloc( sizeof( es_out_t ) );
125 es_out_sys_t *p_sys = malloc( sizeof( es_out_sys_t ) );
128 out->pf_add = EsOutAdd;
129 out->pf_send = EsOutSend;
130 out->pf_del = EsOutDel;
131 out->pf_control = EsOutControl;
134 p_sys->p_input = p_input;
136 p_sys->b_active = VLC_FALSE;
137 p_sys->i_mode = ES_OUT_MODE_AUTO;
142 p_sys->p_pgrm = NULL;
152 var_Get( p_input, "audio-channel", &val );
153 p_sys->i_audio_last = val.i_int;
155 var_Get( p_input, "spu-channel", &val );
156 p_sys->i_sub_last = val.i_int;
158 p_sys->p_es_audio = NULL;
159 p_sys->p_es_video = NULL;
160 p_sys->p_es_sub = NULL;
162 p_sys->i_audio_delay= 0;
163 p_sys->i_spu_delay = 0;
168 /*****************************************************************************
170 *****************************************************************************/
171 void input_EsOutDelete( es_out_t *out )
173 es_out_sys_t *p_sys = out->p_sys;
176 for( i = 0; i < p_sys->i_es; i++ )
178 if( p_sys->es[i]->p_dec )
180 input_DecoderDelete( p_sys->es[i]->p_dec );
182 if( p_sys->es[i]->psz_description )
183 free( p_sys->es[i]->psz_description );
184 es_format_Clean( &p_sys->es[i]->fmt );
186 free( p_sys->es[i] );
191 for( i = 0; i < p_sys->i_pgrm; i++ )
193 free( p_sys->pgrm[i] );
202 es_out_id_t *input_EsOutGetFromID( es_out_t *out, int i_id )
207 /* Special HACK, -i_id is tha cat of the stream */
208 return (es_out_id_t*)((uint8_t*)NULL-i_id);
211 for( i = 0; i < out->p_sys->i_es; i++ )
213 if( out->p_sys->es[i]->i_id == i_id )
214 return out->p_sys->es[i];
219 void input_EsOutDiscontinuity( es_out_t *out, vlc_bool_t b_audio )
221 es_out_sys_t *p_sys = out->p_sys;
224 for( i = 0; i < p_sys->i_es; i++ )
226 es_out_id_t *es = p_sys->es[i];
228 /* Send a dummy block to let decoder know that
229 * there is a discontinuity */
230 if( es->p_dec && ( !b_audio || es->fmt.i_cat == AUDIO_ES ) )
232 input_DecoderDiscontinuity( es->p_dec );
237 void input_EsOutSetDelay( es_out_t *out, int i_cat, int64_t i_delay )
239 es_out_sys_t *p_sys = out->p_sys;
241 if( i_cat == AUDIO_ES )
242 p_sys->i_audio_delay = i_delay;
243 else if( i_cat == SPU_ES )
244 p_sys->i_spu_delay = i_delay;
247 vlc_bool_t input_EsOutDecodersEmpty( es_out_t *out )
249 es_out_sys_t *p_sys = out->p_sys;
252 for( i = 0; i < p_sys->i_es; i++ )
254 es_out_id_t *es = p_sys->es[i];
256 if( es->p_dec && !input_DecoderEmpty( es->p_dec ) )
262 /*****************************************************************************
264 *****************************************************************************/
265 static void EsOutESVarUpdate( es_out_t *out, es_out_id_t *es,
266 vlc_bool_t b_delete )
268 es_out_sys_t *p_sys = out->p_sys;
269 input_thread_t *p_input = p_sys->p_input;
270 vlc_value_t val, text;
274 if( es->fmt.i_cat == AUDIO_ES )
275 psz_var = "audio-es";
276 else if( es->fmt.i_cat == VIDEO_ES )
277 psz_var = "video-es";
278 else if( es->fmt.i_cat == SPU_ES )
285 val.i_int = es->i_id;
286 var_Change( p_input, psz_var, VLC_VAR_DELCHOICE, &val, NULL );
287 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
291 /* Get the number of ES already added */
292 var_Change( p_input, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
297 /* First one, we need to add the "Disable" choice */
298 val2.i_int = -1; text.psz_string = _("Disable");
299 var_Change( p_input, psz_var, VLC_VAR_ADDCHOICE, &val2, &text );
303 /* Take care of the ES description */
304 if( es->psz_description && *es->psz_description )
306 text.psz_string = strdup( es->psz_description );
310 text.psz_string = malloc( strlen( _("Track %i") ) + 20 );
311 sprintf( text.psz_string, _("Track %i"), val.i_int );
314 val.i_int = es->i_id;
315 var_Change( p_input, psz_var, VLC_VAR_ADDCHOICE, &val, &text );
317 free( text.psz_string );
319 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
322 /* EsOutProgramSelect:
323 * Select a program and update the object variable
325 static void EsOutProgramSelect( es_out_t *out, es_out_pgrm_t *p_pgrm )
327 es_out_sys_t *p_sys = out->p_sys;
328 input_thread_t *p_input = p_sys->p_input;
332 if( p_sys->p_pgrm == p_pgrm )
333 return; /* Nothing to do */
337 es_out_pgrm_t *old = p_sys->p_pgrm;
338 msg_Dbg( p_input, "Unselecting program id=%d", old->i_id );
340 for( i = 0; i < p_sys->i_es; i++ )
342 if( p_sys->es[i]->p_pgrm == old && p_sys->es[i]->p_dec &&
343 p_sys->i_mode != ES_OUT_MODE_ALL )
344 EsUnselect( out, p_sys->es[i], VLC_TRUE );
348 msg_Dbg( p_input, "Selecting program id=%d", p_pgrm->i_id );
350 /* Mark it selected */
351 p_pgrm->b_selected = VLC_TRUE;
353 /* Switch master stream */
354 if( p_sys->p_pgrm && p_sys->p_pgrm->clock.b_master )
356 p_sys->p_pgrm->clock.b_master = VLC_FALSE;
358 p_pgrm->clock.b_master = VLC_TRUE;
359 p_sys->p_pgrm = p_pgrm;
361 /* Update "program" */
362 val.i_int = p_pgrm->i_id;
363 var_Change( p_input, "program", VLC_VAR_SETVALUE, &val, NULL );
366 var_Change( p_input, "audio-es", VLC_VAR_CLEARCHOICES, NULL, NULL );
367 var_Change( p_input, "video-es", VLC_VAR_CLEARCHOICES, NULL, NULL );
368 var_Change( p_input, "spu-es", VLC_VAR_CLEARCHOICES, NULL, NULL );
369 for( i = 0; i < p_sys->i_es; i++ )
371 EsOutESVarUpdate( out, p_sys->es[i], VLC_FALSE );
372 EsOutSelect( out, p_sys->es[i], VLC_FALSE );
375 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
381 static es_out_pgrm_t *EsOutProgramAdd( es_out_t *out, int i_group )
383 es_out_sys_t *p_sys = out->p_sys;
384 input_thread_t *p_input = p_sys->p_input;
387 es_out_pgrm_t *p_pgrm = malloc( sizeof( es_out_pgrm_t ) );
390 p_pgrm->i_id = i_group;
392 p_pgrm->b_selected = VLC_FALSE;
393 input_ClockInit( &p_pgrm->clock, VLC_FALSE, p_input->input.i_cr_average );
396 TAB_APPEND( p_sys->i_pgrm, p_sys->pgrm, p_pgrm );
398 /* Update "program" variable */
400 var_Change( p_input, "program", VLC_VAR_ADDCHOICE, &val, NULL );
402 if( i_group == var_GetInteger( p_input, "program" ) )
404 EsOutProgramSelect( out, p_pgrm );
408 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
416 static es_out_id_t *EsOutAdd( es_out_t *out, es_format_t *fmt )
418 es_out_sys_t *p_sys = out->p_sys;
419 input_thread_t *p_input = p_sys->p_input;
421 es_out_id_t *es = malloc( sizeof( es_out_id_t ) );
422 es_out_pgrm_t *p_pgrm = NULL;
425 if( fmt->i_group < 0 )
427 msg_Err( p_input, "invalid group number" );
431 /* Search the program */
432 for( i = 0; i < p_sys->i_pgrm; i++ )
434 if( fmt->i_group == p_sys->pgrm[i]->i_id )
436 p_pgrm = p_sys->pgrm[i];
442 /* Create a new one */
443 p_pgrm = EsOutProgramAdd( out, fmt->i_group );
446 /* Increase ref count for program */
451 fmt->i_id = out->p_sys->i_id;
452 es->i_id = fmt->i_id;
454 es_format_Copy( &es->fmt, fmt );
458 es->i_channel = p_sys->i_audio;
462 es->i_channel = p_sys->i_video;
466 es->i_channel = p_sys->i_sub;
473 es->psz_description = LanguageGetName( fmt->psz_language );
476 if( es->p_pgrm == p_sys->p_pgrm )
477 EsOutESVarUpdate( out, es, VLC_FALSE );
479 /* Select it if needed */
480 EsOutSelect( out, es, VLC_FALSE );
483 TAB_APPEND( out->p_sys->i_es, out->p_sys->es, es );
484 p_sys->i_id++; /* always incremented */
498 EsOutAddInfo( out, es );
503 static void EsSelect( es_out_t *out, es_out_id_t *es )
505 es_out_sys_t *p_sys = out->p_sys;
506 input_thread_t *p_input = p_sys->p_input;
512 msg_Warn( p_input, "ES 0x%x is already selected", es->i_id );
516 if( es->fmt.i_cat == VIDEO_ES || es->fmt.i_cat == SPU_ES )
518 if( !var_GetBool( p_input, "video" ) ||
519 ( p_input->p_sout && !var_GetBool( p_input, "sout-video" ) ) )
521 msg_Dbg( p_input, "video is disabled, not selecting ES 0x%x",
526 else if( es->fmt.i_cat == AUDIO_ES )
528 var_Get( p_input, "audio", &val );
529 if( !var_GetBool( p_input, "audio" ) ||
530 ( p_input->p_sout && !var_GetBool( p_input, "sout-audio" ) ) )
532 msg_Dbg( p_input, "audio is disabled, not selecting ES 0x%x",
538 es->p_dec = input_DecoderNew( p_input, &es->fmt, VLC_FALSE );
539 if( es->p_dec == NULL || es->p_pgrm != p_sys->p_pgrm )
542 if( es->fmt.i_cat == VIDEO_ES )
543 psz_var = "video-es";
544 else if( es->fmt.i_cat == AUDIO_ES )
545 psz_var = "audio-es";
546 else if( es->fmt.i_cat == SPU_ES )
551 /* Mark it as selected */
552 val.i_int = es->i_id;
553 var_Change( p_input, psz_var, VLC_VAR_SETVALUE, &val, NULL );
556 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
559 static void EsUnselect( es_out_t *out, es_out_id_t *es, vlc_bool_t b_update )
561 es_out_sys_t *p_sys = out->p_sys;
562 input_thread_t *p_input = p_sys->p_input;
566 if( es->p_dec == NULL )
568 msg_Warn( p_input, "ES 0x%x is already unselected", es->i_id );
572 input_DecoderDelete( es->p_dec );
579 if( es->p_dec == NULL )
581 if( es->fmt.i_cat == VIDEO_ES )
582 psz_var = "video-es";
583 else if( es->fmt.i_cat == AUDIO_ES )
584 psz_var = "audio-es";
585 else if( es->fmt.i_cat == SPU_ES )
590 /* Mark it as selected */
592 var_Change( p_input, psz_var, VLC_VAR_SETVALUE, &val, NULL );
594 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
598 * Select an ES given the current mode
599 * XXX: you need to take a the lock before (stream.stream_lock)
601 * \param out The es_out structure
602 * \param es es_out_id structure
606 static void EsOutSelect( es_out_t *out, es_out_id_t *es, vlc_bool_t b_force )
608 es_out_sys_t *p_sys = out->p_sys;
610 int i_cat = es->fmt.i_cat;
612 if( !p_sys->b_active ||
613 ( !b_force && es->fmt.i_priority < 0 ) )
618 if( p_sys->i_mode == ES_OUT_MODE_ALL || b_force )
623 else if( p_sys->i_mode == ES_OUT_MODE_PARTIAL )
627 var_Get( p_sys->p_input, "programs", &val );
628 for ( i = 0; i < val.p_list->i_count; i++ )
630 if ( val.p_list->p_values[i].i_int == es->p_pgrm->i_id || b_force )
637 var_Change( p_sys->p_input, "programs", VLC_VAR_FREELIST, &val, NULL );
639 else if( p_sys->i_mode == ES_OUT_MODE_AUTO )
643 if( es->p_pgrm != p_sys->p_pgrm )
646 if( i_cat == AUDIO_ES )
648 if( p_sys->p_es_audio &&
649 p_sys->p_es_audio->fmt.i_priority >= es->fmt.i_priority )
653 i_wanted = p_sys->i_audio_last >= 0 ?
654 p_sys->i_audio_last : es->i_channel;
656 else if( i_cat == SPU_ES )
658 if( p_sys->p_es_sub &&
659 p_sys->p_es_sub->fmt.i_priority >=
664 i_wanted = p_sys->i_sub_last;
666 else if( i_cat == VIDEO_ES )
668 i_wanted = es->i_channel;
671 if( i_wanted == es->i_channel && es->p_dec == NULL )
675 /* FIXME TODO handle priority here */
678 if( i_cat == AUDIO_ES )
680 if( p_sys->i_mode == ES_OUT_MODE_AUTO &&
682 p_sys->p_es_audio != es &&
683 p_sys->p_es_audio->p_dec )
685 EsUnselect( out, p_sys->p_es_audio, VLC_FALSE );
687 p_sys->p_es_audio = es;
689 else if( i_cat == SPU_ES )
691 if( p_sys->i_mode == ES_OUT_MODE_AUTO &&
693 p_sys->p_es_sub != es &&
694 p_sys->p_es_sub->p_dec )
696 EsUnselect( out, p_sys->p_es_sub, VLC_FALSE );
698 p_sys->p_es_sub = es;
700 else if( i_cat == VIDEO_ES )
702 p_sys->p_es_video = es;
708 * Send a block for the given es_out
710 * \param out the es_out to send from
711 * \param es the es_out_id
712 * \param p_block the data block to send
714 static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
716 es_out_sys_t *p_sys = out->p_sys;
717 input_thread_t *p_input = p_sys->p_input;
718 es_out_pgrm_t *p_pgrm = es->p_pgrm;
721 if( es->fmt.i_cat == AUDIO_ES )
722 i_delay = p_sys->i_audio_delay;
723 else if( es->fmt.i_cat == SPU_ES )
724 i_delay = p_sys->i_spu_delay;
728 /* +11 -> avoid null value with non null dts/pts */
729 if( p_block->i_dts > 0 )
732 input_ClockGetTS( p_input, &p_pgrm->clock,
733 ( p_block->i_dts + 11 ) * 9 / 100 ) + i_delay;
735 if( p_block->i_pts > 0 )
738 input_ClockGetTS( p_input, &p_pgrm->clock,
739 ( p_block->i_pts + 11 ) * 9 / 100 ) + i_delay;
742 p_block->i_rate = p_input->i_rate;
744 /* TODO handle mute */
745 if( es->p_dec && ( es->fmt.i_cat != AUDIO_ES ||
746 p_input->i_rate == INPUT_RATE_DEFAULT ) )
748 input_DecoderDecode( es->p_dec, p_block );
752 block_Release( p_block );
758 /*****************************************************************************
760 *****************************************************************************/
761 static void EsOutDel( es_out_t *out, es_out_id_t *es )
763 es_out_sys_t *p_sys = out->p_sys;
765 /* We don't try to reselect */
767 EsUnselect( out, es, es->p_pgrm == p_sys->p_pgrm );
769 if( es->p_pgrm == p_sys->p_pgrm )
770 EsOutESVarUpdate( out, es, VLC_TRUE );
772 TAB_REMOVE( p_sys->i_es, p_sys->es, es );
775 if( es->p_pgrm->i_es == 0 )
777 msg_Warn( p_sys->p_input, "Program doesn't contain anymore ES, "
781 if( p_sys->p_es_audio == es ) p_sys->p_es_audio = NULL;
782 if( p_sys->p_es_video == es ) p_sys->p_es_video = NULL;
783 if( p_sys->p_es_sub == es ) p_sys->p_es_sub = NULL;
785 switch( es->fmt.i_cat )
798 if( es->psz_description )
799 free( es->psz_description );
801 es_format_Clean( &es->fmt );
807 * Control query handler
809 * \param out the es_out to control
810 * \param i_query A es_out query as defined in include/ninput.h
811 * \param args a variable list of arguments for the query
812 * \return VLC_SUCCESS or an error code
814 static int EsOutControl( es_out_t *out, int i_query, va_list args )
816 es_out_sys_t *p_sys = out->p_sys;
824 case ES_OUT_SET_ES_STATE:
825 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
826 b = (vlc_bool_t) va_arg( args, vlc_bool_t );
827 if( b && es->p_dec == NULL )
830 return es->p_dec ? VLC_SUCCESS : VLC_EGENERIC;
832 else if( !b && es->p_dec )
834 EsUnselect( out, es, es->p_pgrm == p_sys->p_pgrm );
839 case ES_OUT_GET_ES_STATE:
840 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
841 pb = (vlc_bool_t*) va_arg( args, vlc_bool_t * );
843 *pb = es->p_dec ? VLC_TRUE : VLC_FALSE;
846 case ES_OUT_SET_ACTIVE:
848 b = (vlc_bool_t) va_arg( args, vlc_bool_t );
852 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
856 case ES_OUT_GET_ACTIVE:
857 pb = (vlc_bool_t*) va_arg( args, vlc_bool_t * );
858 *pb = p_sys->b_active;
861 case ES_OUT_SET_MODE:
862 i = (int) va_arg( args, int );
863 if( i == ES_OUT_MODE_NONE || i == ES_OUT_MODE_ALL ||
864 i == ES_OUT_MODE_AUTO || i == ES_OUT_MODE_PARTIAL )
868 /* Reapply policy mode */
869 for( i = 0; i < p_sys->i_es; i++ )
871 if( p_sys->es[i]->p_dec )
873 EsUnselect( out, p_sys->es[i],
874 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
877 for( i = 0; i < p_sys->i_es; i++ )
879 EsOutSelect( out, p_sys->es[i], VLC_FALSE );
885 case ES_OUT_GET_MODE:
886 pi = (int*) va_arg( args, int* );
891 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
892 /* Special case NULL, NULL+i_cat */
895 for( i = 0; i < p_sys->i_es; i++ )
897 if( p_sys->es[i]->p_dec )
898 EsUnselect( out, p_sys->es[i],
899 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
902 else if( es == (es_out_id_t*)((uint8_t*)NULL+AUDIO_ES) )
904 for( i = 0; i < p_sys->i_es; i++ )
906 if( p_sys->es[i]->p_dec &&
907 p_sys->es[i]->fmt.i_cat == AUDIO_ES )
908 EsUnselect( out, p_sys->es[i],
909 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
912 else if( es == (es_out_id_t*)((uint8_t*)NULL+VIDEO_ES) )
914 for( i = 0; i < p_sys->i_es; i++ )
916 if( p_sys->es[i]->p_dec &&
917 p_sys->es[i]->fmt.i_cat == VIDEO_ES )
918 EsUnselect( out, p_sys->es[i],
919 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
922 else if( es == (es_out_id_t*)((uint8_t*)NULL+SPU_ES) )
924 for( i = 0; i < p_sys->i_es; i++ )
926 if( p_sys->es[i]->p_dec &&
927 p_sys->es[i]->fmt.i_cat == SPU_ES )
928 EsUnselect( out, p_sys->es[i],
929 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
934 for( i = 0; i < p_sys->i_es; i++ )
936 if( es == p_sys->es[i] )
938 EsOutSelect( out, es, VLC_TRUE );
946 case ES_OUT_SET_GROUP_PCR:
948 es_out_pgrm_t *p_pgrm = NULL;
952 if( i_query == ES_OUT_SET_PCR )
954 p_pgrm = p_sys->p_pgrm;
959 i_group = (int)va_arg( args, int );
960 for( i = 0; i < p_sys->i_pgrm; i++ )
962 if( p_sys->pgrm[i]->i_id == i_group )
964 p_pgrm = p_sys->pgrm[i];
970 p_pgrm = EsOutProgramAdd( out, i_group ); /* Create it */
972 i_pcr = (int64_t)va_arg( args, int64_t );
974 /* 11 is a vodoo trick to avoid non_pcr*9/100 to be null */
975 input_ClockSetPCR( p_sys->p_input, &p_pgrm->clock,
976 (i_pcr + 11 ) * 9 / 100);
980 case ES_OUT_RESET_PCR:
981 for( i = 0; i < p_sys->i_pgrm; i++ )
983 p_sys->pgrm[i]->clock.i_synchro_state = SYNCHRO_REINIT;
984 p_sys->pgrm[i]->clock.last_pts = 0;
991 int64_t i_ts = (int64_t)va_arg( args, int64_t );
992 int64_t *pi_ts = (int64_t *)va_arg( args, int64_t * );
993 *pi_ts = input_ClockGetTS( p_sys->p_input,
994 &p_sys->p_pgrm->clock,
995 ( i_ts + 11 ) * 9 / 100 );
1000 case ES_OUT_GET_GROUP:
1001 pi = (int*) va_arg( args, int* );
1003 *pi = p_sys->p_pgrm->i_id;
1005 *pi = -1; /* FIXME */
1008 case ES_OUT_SET_GROUP:
1011 i = (int) va_arg( args, int );
1012 for( j = 0; j < p_sys->i_pgrm; j++ )
1014 es_out_pgrm_t *p_pgrm = p_sys->pgrm[j];
1015 if( p_pgrm->i_id == i )
1017 EsOutProgramSelect( out, p_pgrm );
1021 return VLC_EGENERIC;
1024 case ES_OUT_SET_FMT:
1026 /* This ain't pretty but is need by some demuxers (eg. Ogg )
1027 * to update the p_extra data */
1029 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
1030 p_fmt = (es_format_t*) va_arg( args, es_format_t * );
1031 if( es == NULL ) return VLC_EGENERIC;
1033 if( p_fmt->i_extra )
1035 es->fmt.i_extra = p_fmt->i_extra;
1036 es->fmt.p_extra = realloc( es->fmt.p_extra, p_fmt->i_extra );
1037 memcpy( es->fmt.p_extra, p_fmt->p_extra, p_fmt->i_extra );
1039 if( !es->p_dec ) return VLC_SUCCESS;
1041 es->p_dec->fmt_in.i_extra = p_fmt->i_extra;
1042 es->p_dec->fmt_in.p_extra =
1043 realloc( es->p_dec->fmt_in.p_extra, p_fmt->i_extra );
1044 memcpy( es->p_dec->fmt_in.p_extra,
1045 p_fmt->p_extra, p_fmt->i_extra );
1052 msg_Err( p_sys->p_input, "unknown query in es_out_Control" );
1053 return VLC_EGENERIC;
1057 /****************************************************************************
1058 * LanguageGetName: try to expend iso639 into plain name
1059 ****************************************************************************/
1060 static char *LanguageGetName( const char *psz_code )
1062 const iso639_lang_t *pl;
1064 if( psz_code == NULL )
1066 return strdup( "" );
1069 if( strlen( psz_code ) == 2 )
1071 pl = GetLang_1( psz_code );
1073 else if( strlen( psz_code ) == 3 )
1075 pl = GetLang_2B( psz_code );
1076 if( !strcmp( pl->psz_iso639_1, "??" ) )
1078 pl = GetLang_2T( psz_code );
1083 return strdup( psz_code );
1086 if( !strcmp( pl->psz_iso639_1, "??" ) )
1088 return strdup( psz_code );
1092 if( *pl->psz_native_name )
1094 return strdup( pl->psz_native_name );
1096 return strdup( pl->psz_eng_name );
1100 /****************************************************************************
1102 * - add meta info to the playlist item
1103 ****************************************************************************/
1104 static void EsOutAddInfo( es_out_t *out, es_out_id_t *es )
1106 es_out_sys_t *p_sys = out->p_sys;
1107 input_thread_t *p_input = p_sys->p_input;
1108 es_format_t *fmt = &es->fmt;
1111 /* Add stream info */
1112 asprintf( &psz_cat, _("Stream %d"), out->p_sys->i_id - 1 );
1114 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Codec"),
1115 "%.4s", (char*)&fmt->i_codec );
1117 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Language"),
1118 "%s", es->psz_description );
1120 /* Add information */
1121 switch( fmt->i_cat )
1124 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1125 _("Type"), _("Audio") );
1127 if( fmt->audio.i_channels > 0 )
1128 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Channels"),
1129 "%d", fmt->audio.i_channels );
1131 if( fmt->audio.i_rate > 0 )
1132 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Sample rate"),
1133 _("%d Hz"), fmt->audio.i_rate );
1135 if( fmt->audio.i_bitspersample > 0 )
1136 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1137 _("Bits per sample"), "%d",
1138 fmt->audio.i_bitspersample );
1140 if( fmt->i_bitrate > 0 )
1141 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Bitrate"),
1142 _("%d kb/s"), fmt->i_bitrate / 1000 );
1146 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1147 _("Type"), _("Video") );
1149 if( fmt->video.i_width > 0 && fmt->video.i_height > 0 )
1150 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1151 _("Resolution"), "%dx%d",
1152 fmt->video.i_width, fmt->video.i_height );
1154 if( fmt->video.i_visible_width > 0 &&
1155 fmt->video.i_visible_height > 0 )
1156 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1157 _("Display resolution"), "%dx%d",
1158 fmt->video.i_visible_width,
1159 fmt->video.i_visible_height);
1163 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1164 _("Type"), _("Subtitle") );