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 );
112 static void EsOutAddInfo( es_out_t *, es_out_id_t *es );
114 static void EsSelect( es_out_t *out, es_out_id_t *es );
115 static void EsUnselect( es_out_t *out, es_out_id_t *es, vlc_bool_t b_update );
116 static char *LanguageGetName( const char *psz_code );
118 /*****************************************************************************
120 *****************************************************************************/
121 es_out_t *input_EsOutNew( input_thread_t *p_input )
123 es_out_t *out = malloc( sizeof( es_out_t ) );
124 es_out_sys_t *p_sys = malloc( sizeof( es_out_sys_t ) );
127 out->pf_add = EsOutAdd;
128 out->pf_send = EsOutSend;
129 out->pf_del = EsOutDel;
130 out->pf_control = EsOutControl;
133 p_sys->p_input = p_input;
135 p_sys->b_active = VLC_FALSE;
136 p_sys->i_mode = ES_OUT_MODE_AUTO;
141 p_sys->p_pgrm = NULL;
151 var_Get( p_input, "audio-channel", &val );
152 p_sys->i_audio_last = val.i_int;
154 var_Get( p_input, "spu-channel", &val );
155 p_sys->i_sub_last = val.i_int;
157 p_sys->p_es_audio = NULL;
158 p_sys->p_es_video = NULL;
159 p_sys->p_es_sub = NULL;
161 p_sys->i_audio_delay= 0;
162 p_sys->i_spu_delay = 0;
167 /*****************************************************************************
169 *****************************************************************************/
170 void input_EsOutDelete( es_out_t *out )
172 es_out_sys_t *p_sys = out->p_sys;
175 for( i = 0; i < p_sys->i_es; i++ )
177 if( p_sys->es[i]->p_dec )
179 input_DecoderDelete( p_sys->es[i]->p_dec );
181 if( p_sys->es[i]->psz_description )
182 free( p_sys->es[i]->psz_description );
183 es_format_Clean( &p_sys->es[i]->fmt );
185 free( p_sys->es[i] );
190 for( i = 0; i < p_sys->i_pgrm; i++ )
192 free( p_sys->pgrm[i] );
201 es_out_id_t *input_EsOutGetFromID( es_out_t *out, int i_id )
206 /* Special HACK, -i_id is tha cat of the stream */
207 return (es_out_id_t*)((uint8_t*)NULL-i_id);
210 for( i = 0; i < out->p_sys->i_es; i++ )
212 if( out->p_sys->es[i]->i_id == i_id )
213 return out->p_sys->es[i];
218 void input_EsOutDiscontinuity( es_out_t *out, vlc_bool_t b_audio )
220 es_out_sys_t *p_sys = out->p_sys;
223 for( i = 0; i < p_sys->i_es; i++ )
225 es_out_id_t *es = p_sys->es[i];
227 /* Send a dummy block to let decoder know that
228 * there is a discontinuity */
229 if( es->p_dec && ( !b_audio || es->fmt.i_cat == AUDIO_ES ) )
231 input_DecoderDiscontinuity( es->p_dec );
236 void input_EsOutSetDelay( es_out_t *out, int i_cat, int64_t i_delay )
238 es_out_sys_t *p_sys = out->p_sys;
240 if( i_cat == AUDIO_ES )
241 p_sys->i_audio_delay = i_delay;
242 else if( i_cat == SPU_ES )
243 p_sys->i_spu_delay = i_delay;
246 vlc_bool_t input_EsOutDecodersEmpty( es_out_t *out )
248 es_out_sys_t *p_sys = out->p_sys;
251 for( i = 0; i < p_sys->i_es; i++ )
253 es_out_id_t *es = p_sys->es[i];
255 if( es->p_dec && !input_DecoderEmpty( es->p_dec ) )
261 /*****************************************************************************
263 *****************************************************************************/
264 static void EsOutESVarUpdate( es_out_t *out, es_out_id_t *es,
265 vlc_bool_t b_delete )
267 es_out_sys_t *p_sys = out->p_sys;
268 input_thread_t *p_input = p_sys->p_input;
269 vlc_value_t val, text;
273 if( es->fmt.i_cat == AUDIO_ES )
274 psz_var = "audio-es";
275 else if( es->fmt.i_cat == VIDEO_ES )
276 psz_var = "video-es";
277 else if( es->fmt.i_cat == SPU_ES )
284 val.i_int = es->i_id;
285 var_Change( p_input, psz_var, VLC_VAR_DELCHOICE, &val, NULL );
286 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
290 /* Get the number of ES already added */
291 var_Change( p_input, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
296 /* First one, we need to add the "Disable" choice */
297 val2.i_int = -1; text.psz_string = _("Disable");
298 var_Change( p_input, psz_var, VLC_VAR_ADDCHOICE, &val2, &text );
302 /* Take care of the ES description */
303 if( es->psz_description && *es->psz_description )
305 text.psz_string = strdup( es->psz_description );
309 text.psz_string = malloc( strlen( _("Track %i") ) + 20 );
310 sprintf( text.psz_string, _("Track %i"), val.i_int );
313 val.i_int = es->i_id;
314 var_Change( p_input, psz_var, VLC_VAR_ADDCHOICE, &val, &text );
316 free( text.psz_string );
318 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
321 /* EsOutProgramSelect:
322 * Select a program and update the object variable
324 static void EsOutProgramSelect( es_out_t *out, es_out_pgrm_t *p_pgrm )
326 es_out_sys_t *p_sys = out->p_sys;
327 input_thread_t *p_input = p_sys->p_input;
331 if( p_sys->p_pgrm == p_pgrm )
332 return; /* Nothing to do */
336 es_out_pgrm_t *old = p_sys->p_pgrm;
337 msg_Dbg( p_input, "Unselecting program id=%d", old->i_id );
339 for( i = 0; i < p_sys->i_es; i++ )
341 if( p_sys->es[i]->p_pgrm == old && p_sys->es[i]->p_dec &&
342 p_sys->i_mode != ES_OUT_MODE_ALL )
343 EsUnselect( out, p_sys->es[i], VLC_TRUE );
347 msg_Dbg( p_input, "Selecting program id=%d", p_pgrm->i_id );
349 /* Mark it selected */
350 p_pgrm->b_selected = VLC_TRUE;
352 /* Switch master stream */
353 if( p_sys->p_pgrm && p_sys->p_pgrm->clock.b_master )
355 p_sys->p_pgrm->clock.b_master = VLC_FALSE;
357 p_pgrm->clock.b_master = VLC_TRUE;
358 p_sys->p_pgrm = p_pgrm;
360 /* Update "program" */
361 val.i_int = p_pgrm->i_id;
362 var_Change( p_input, "program", VLC_VAR_SETVALUE, &val, NULL );
365 var_Change( p_input, "audio-es", VLC_VAR_CLEARCHOICES, NULL, NULL );
366 var_Change( p_input, "video-es", VLC_VAR_CLEARCHOICES, NULL, NULL );
367 var_Change( p_input, "spu-es", VLC_VAR_CLEARCHOICES, NULL, NULL );
368 for( i = 0; i < p_sys->i_es; i++ )
370 EsOutESVarUpdate( out, p_sys->es[i], VLC_FALSE );
371 EsOutSelect( out, p_sys->es[i], VLC_FALSE );
374 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
380 static es_out_pgrm_t *EsOutProgramAdd( es_out_t *out, int i_group )
382 es_out_sys_t *p_sys = out->p_sys;
383 input_thread_t *p_input = p_sys->p_input;
386 es_out_pgrm_t *p_pgrm = malloc( sizeof( es_out_pgrm_t ) );
389 p_pgrm->i_id = i_group;
391 p_pgrm->b_selected = VLC_FALSE;
392 input_ClockInit( &p_pgrm->clock, VLC_FALSE, p_input->input.i_cr_average );
395 TAB_APPEND( p_sys->i_pgrm, p_sys->pgrm, p_pgrm );
397 /* Update "program" variable */
399 var_Change( p_input, "program", VLC_VAR_ADDCHOICE, &val, NULL );
401 if( i_group == var_GetInteger( p_input, "program" ) )
403 EsOutProgramSelect( out, p_pgrm );
407 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
415 static es_out_id_t *EsOutAdd( es_out_t *out, es_format_t *fmt )
417 es_out_sys_t *p_sys = out->p_sys;
418 input_thread_t *p_input = p_sys->p_input;
420 es_out_id_t *es = malloc( sizeof( es_out_id_t ) );
421 es_out_pgrm_t *p_pgrm = NULL;
424 if( fmt->i_group < 0 )
426 msg_Err( p_input, "invakud group number" );
430 /* Search the program */
431 for( i = 0; i < p_sys->i_pgrm; i++ )
433 if( fmt->i_group == p_sys->pgrm[i]->i_id )
435 p_pgrm = p_sys->pgrm[i];
441 /* Create a new one */
442 p_pgrm = EsOutProgramAdd( out, fmt->i_group );
445 /* Increase ref count for program */
450 fmt->i_id = out->p_sys->i_id;
451 es->i_id = fmt->i_id;
453 es_format_Copy( &es->fmt, fmt );
457 es->i_channel = p_sys->i_audio;
461 es->i_channel = p_sys->i_video;
465 es->i_channel = p_sys->i_sub;
472 es->psz_description = LanguageGetName( fmt->psz_language );
475 if( es->p_pgrm == p_sys->p_pgrm )
476 EsOutESVarUpdate( out, es, VLC_FALSE );
478 /* Select it if needed */
479 EsOutSelect( out, es, VLC_FALSE );
482 TAB_APPEND( out->p_sys->i_es, out->p_sys->es, es );
483 p_sys->i_id++; /* always incremented */
497 EsOutAddInfo( out, es );
502 static void EsSelect( es_out_t *out, es_out_id_t *es )
504 es_out_sys_t *p_sys = out->p_sys;
505 input_thread_t *p_input = p_sys->p_input;
511 msg_Warn( p_input, "ES 0x%x is already selected", es->i_id );
515 if( es->fmt.i_cat == VIDEO_ES || es->fmt.i_cat == SPU_ES )
517 if( !var_GetBool( p_input, "video" ) ||
518 ( p_input->p_sout && !var_GetBool( p_input, "sout-video" ) ) )
520 msg_Dbg( p_input, "video is disabled, not selecting ES 0x%x",
525 else if( es->fmt.i_cat == AUDIO_ES )
527 var_Get( p_input, "audio", &val );
528 if( !var_GetBool( p_input, "audio" ) ||
529 ( p_input->p_sout && !var_GetBool( p_input, "sout-audio" ) ) )
531 msg_Dbg( p_input, "audio is disabled, not selecting ES 0x%x",
537 es->p_dec = input_DecoderNew( p_input, &es->fmt, VLC_FALSE );
538 if( es->p_dec == NULL || es->p_pgrm != p_sys->p_pgrm )
541 if( es->fmt.i_cat == VIDEO_ES )
542 psz_var = "video-es";
543 else if( es->fmt.i_cat == AUDIO_ES )
544 psz_var = "audio-es";
545 else if( es->fmt.i_cat == SPU_ES )
550 /* Mark it as selected */
551 val.i_int = es->i_id;
552 var_Change( p_input, psz_var, VLC_VAR_SETVALUE, &val, NULL );
555 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
558 static void EsUnselect( es_out_t *out, es_out_id_t *es, vlc_bool_t b_update )
560 es_out_sys_t *p_sys = out->p_sys;
561 input_thread_t *p_input = p_sys->p_input;
565 if( es->p_dec == NULL )
567 msg_Warn( p_input, "ES 0x%x is already unselected", es->i_id );
571 input_DecoderDelete( es->p_dec );
578 if( es->p_dec == NULL )
580 if( es->fmt.i_cat == VIDEO_ES )
581 psz_var = "video-es";
582 else if( es->fmt.i_cat == AUDIO_ES )
583 psz_var = "audio-es";
584 else if( es->fmt.i_cat == SPU_ES )
589 /* Mark it as selected */
591 var_Change( p_input, psz_var, VLC_VAR_SETVALUE, &val, NULL );
593 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
597 * Select an ES given the current mode
598 * XXX: you need to take a the lock before (stream.stream_lock)
600 * \param out The es_out structure
601 * \param es es_out_id structure
605 static void EsOutSelect( es_out_t *out, es_out_id_t *es, vlc_bool_t b_force )
607 es_out_sys_t *p_sys = out->p_sys;
609 int i_cat = es->fmt.i_cat;
611 if( !p_sys->b_active ||
612 ( !b_force && es->fmt.i_priority < 0 ) )
617 if( p_sys->i_mode == ES_OUT_MODE_ALL || b_force )
622 else if( p_sys->i_mode == ES_OUT_MODE_AUTO )
626 if( es->p_pgrm != p_sys->p_pgrm )
629 if( i_cat == AUDIO_ES )
631 if( p_sys->p_es_audio &&
632 p_sys->p_es_audio->fmt.i_priority >= es->fmt.i_priority )
636 i_wanted = p_sys->i_audio_last >= 0 ?
637 p_sys->i_audio_last : es->i_channel;
639 else if( i_cat == SPU_ES )
641 if( p_sys->p_es_sub &&
642 p_sys->p_es_sub->fmt.i_priority >=
647 i_wanted = p_sys->i_sub_last;
649 else if( i_cat == VIDEO_ES )
651 i_wanted = es->i_channel;
654 if( i_wanted == es->i_channel && es->p_dec == NULL )
658 /* FIXME TODO handle priority here */
661 if( i_cat == AUDIO_ES )
663 if( p_sys->i_mode == ES_OUT_MODE_AUTO &&
665 p_sys->p_es_audio != es &&
666 p_sys->p_es_audio->p_dec )
668 EsUnselect( out, p_sys->p_es_audio, VLC_FALSE );
670 p_sys->p_es_audio = es;
672 else if( i_cat == SPU_ES )
674 if( p_sys->i_mode == ES_OUT_MODE_AUTO &&
676 p_sys->p_es_sub != es &&
677 p_sys->p_es_sub->p_dec )
679 EsUnselect( out, p_sys->p_es_sub, VLC_FALSE );
681 p_sys->p_es_sub = es;
683 else if( i_cat == VIDEO_ES )
685 p_sys->p_es_video = es;
691 * Send a block for the given es_out
693 * \param out the es_out to send from
694 * \param es the es_out_id
695 * \param p_block the data block to send
697 static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
699 es_out_sys_t *p_sys = out->p_sys;
700 input_thread_t *p_input = p_sys->p_input;
701 es_out_pgrm_t *p_pgrm = es->p_pgrm;
704 if( es->fmt.i_cat == AUDIO_ES )
705 i_delay = p_sys->i_audio_delay;
706 else if( es->fmt.i_cat == SPU_ES )
707 i_delay = p_sys->i_spu_delay;
711 /* +11 -> avoid null value with non null dts/pts */
712 if( p_block->i_dts > 0 )
715 input_ClockGetTS( p_input, &p_pgrm->clock,
716 ( p_block->i_dts + 11 ) * 9 / 100 ) + i_delay;
718 if( p_block->i_pts > 0 )
721 input_ClockGetTS( p_input, &p_pgrm->clock,
722 ( p_block->i_pts + 11 ) * 9 / 100 ) + i_delay;
725 p_block->i_rate = p_input->i_rate;
727 /* TODO handle mute */
728 if( es->p_dec && ( es->fmt.i_cat != AUDIO_ES || p_input->i_rate == INPUT_RATE_DEFAULT ) )
730 input_DecoderDecode( es->p_dec, p_block );
734 block_Release( p_block );
740 /*****************************************************************************
742 *****************************************************************************/
743 static void EsOutDel( es_out_t *out, es_out_id_t *es )
745 es_out_sys_t *p_sys = out->p_sys;
747 /* We don't try to reselect */
749 EsUnselect( out, es, es->p_pgrm == p_sys->p_pgrm );
751 if( es->p_pgrm == p_sys->p_pgrm )
752 EsOutESVarUpdate( out, es, VLC_TRUE );
754 TAB_REMOVE( p_sys->i_es, p_sys->es, es );
757 if( es->p_pgrm->i_es == 0 )
759 msg_Warn( p_sys->p_input, "Program doesn't contain anymore ES, "
763 if( p_sys->p_es_audio == es ) p_sys->p_es_audio = NULL;
764 if( p_sys->p_es_video == es ) p_sys->p_es_video = NULL;
765 if( p_sys->p_es_sub == es ) p_sys->p_es_sub = NULL;
767 switch( es->fmt.i_cat )
780 if( es->psz_description )
781 free( es->psz_description );
783 es_format_Clean( &es->fmt );
789 * Control query handler
791 * \param out the es_out to control
792 * \param i_query A es_out query as defined in include/ninput.h
793 * \param args a variable list of arguments for the query
794 * \return VLC_SUCCESS or an error code
796 static int EsOutControl( es_out_t *out, int i_query, va_list args )
798 es_out_sys_t *p_sys = out->p_sys;
806 case ES_OUT_SET_ES_STATE:
807 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
808 b = (vlc_bool_t) va_arg( args, vlc_bool_t );
809 if( b && es->p_dec == NULL )
812 return es->p_dec ? VLC_SUCCESS : VLC_EGENERIC;
814 else if( !b && es->p_dec )
816 EsUnselect( out, es, es->p_pgrm == p_sys->p_pgrm );
821 case ES_OUT_GET_ES_STATE:
822 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
823 pb = (vlc_bool_t*) va_arg( args, vlc_bool_t * );
825 *pb = es->p_dec ? VLC_TRUE : VLC_FALSE;
828 case ES_OUT_SET_ACTIVE:
830 b = (vlc_bool_t) va_arg( args, vlc_bool_t );
834 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
838 case ES_OUT_GET_ACTIVE:
839 pb = (vlc_bool_t*) va_arg( args, vlc_bool_t * );
840 *pb = p_sys->b_active;
843 case ES_OUT_SET_MODE:
844 i = (int) va_arg( args, int );
845 if( i == ES_OUT_MODE_NONE || i == ES_OUT_MODE_ALL ||
846 i == ES_OUT_MODE_AUTO )
850 /* Reapply policy mode */
851 for( i = 0; i < p_sys->i_es; i++ )
853 if( p_sys->es[i]->p_dec )
855 EsUnselect( out, p_sys->es[i],
856 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
859 for( i = 0; i < p_sys->i_es; i++ )
861 EsOutSelect( out, p_sys->es[i], VLC_FALSE );
867 case ES_OUT_GET_MODE:
868 pi = (int*) va_arg( args, int* );
873 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
874 /* Special case NULL, NULL+i_cat */
877 for( i = 0; i < p_sys->i_es; i++ )
879 if( p_sys->es[i]->p_dec )
880 EsUnselect( out, p_sys->es[i],
881 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
884 else if( es == (es_out_id_t*)((uint8_t*)NULL+AUDIO_ES) )
886 for( i = 0; i < p_sys->i_es; i++ )
888 if( p_sys->es[i]->p_dec &&
889 p_sys->es[i]->fmt.i_cat == AUDIO_ES )
890 EsUnselect( out, p_sys->es[i],
891 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
894 else if( es == (es_out_id_t*)((uint8_t*)NULL+VIDEO_ES) )
896 for( i = 0; i < p_sys->i_es; i++ )
898 if( p_sys->es[i]->p_dec &&
899 p_sys->es[i]->fmt.i_cat == VIDEO_ES )
900 EsUnselect( out, p_sys->es[i],
901 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
904 else if( es == (es_out_id_t*)((uint8_t*)NULL+SPU_ES) )
906 for( i = 0; i < p_sys->i_es; i++ )
908 if( p_sys->es[i]->p_dec &&
909 p_sys->es[i]->fmt.i_cat == SPU_ES )
910 EsUnselect( out, p_sys->es[i],
911 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
916 for( i = 0; i < p_sys->i_es; i++ )
918 if( es == p_sys->es[i] )
920 EsOutSelect( out, es, VLC_TRUE );
928 case ES_OUT_SET_GROUP_PCR:
930 es_out_pgrm_t *p_pgrm = NULL;
934 if( i_query == ES_OUT_SET_PCR )
936 p_pgrm = p_sys->p_pgrm;
941 i_group = (int)va_arg( args, int );
942 for( i = 0; i < p_sys->i_pgrm; i++ )
944 if( p_sys->pgrm[i]->i_id == i_group )
946 p_pgrm = p_sys->pgrm[i];
952 p_pgrm = EsOutProgramAdd( out, i_group ); /* Create it */
954 i_pcr = (int64_t)va_arg( args, int64_t );
956 /* 11 is a vodoo trick to avoid non_pcr*9/100 to be null */
957 input_ClockSetPCR( p_sys->p_input, &p_pgrm->clock,
958 (i_pcr + 11 ) * 9 / 100);
962 case ES_OUT_RESET_PCR:
963 for( i = 0; i < p_sys->i_pgrm; i++ )
965 p_sys->pgrm[i]->clock.i_synchro_state = SYNCHRO_REINIT;
966 p_sys->pgrm[i]->clock.last_pts = 0;
970 case ES_OUT_GET_GROUP:
971 pi = (int*) va_arg( args, int* );
973 *pi = p_sys->p_pgrm->i_id;
975 *pi = -1; /* FIXME */
978 case ES_OUT_SET_GROUP:
981 i = (int) va_arg( args, int );
982 for( j = 0; j < p_sys->i_pgrm; j++ )
984 es_out_pgrm_t *p_pgrm = p_sys->pgrm[j];
985 if( p_pgrm->i_id == i )
987 EsOutProgramSelect( out, p_pgrm );
996 /* This ain't pretty but is need by some demuxers (eg. Ogg )
997 * to update the p_extra data */
999 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
1000 p_fmt = (es_format_t*) va_arg( args, es_format_t * );
1001 if( es == NULL ) return VLC_EGENERIC;
1003 if( p_fmt->i_extra )
1005 es->fmt.i_extra = p_fmt->i_extra;
1006 es->fmt.p_extra = realloc( es->fmt.p_extra, p_fmt->i_extra );
1007 memcpy( es->fmt.p_extra, p_fmt->p_extra, p_fmt->i_extra );
1009 if( !es->p_dec ) return VLC_SUCCESS;
1011 es->p_dec->fmt_in.i_extra = p_fmt->i_extra;
1012 es->p_dec->fmt_in.p_extra =
1013 realloc( es->p_dec->fmt_in.p_extra, p_fmt->i_extra );
1014 memcpy( es->p_dec->fmt_in.p_extra,
1015 p_fmt->p_extra, p_fmt->i_extra );
1022 msg_Err( p_sys->p_input, "unknown query in es_out_Control" );
1023 return VLC_EGENERIC;
1027 /****************************************************************************
1028 * LanguageGetName: try to expend iso639 into plain name
1029 ****************************************************************************/
1030 static char *LanguageGetName( const char *psz_code )
1032 const iso639_lang_t *pl;
1034 if( psz_code == NULL )
1036 return strdup( "" );
1039 if( strlen( psz_code ) == 2 )
1041 pl = GetLang_1( psz_code );
1043 else if( strlen( psz_code ) == 3 )
1045 pl = GetLang_2B( psz_code );
1046 if( !strcmp( pl->psz_iso639_1, "??" ) )
1048 pl = GetLang_2T( psz_code );
1053 return strdup( psz_code );
1056 if( !strcmp( pl->psz_iso639_1, "??" ) )
1058 return strdup( psz_code );
1062 if( *pl->psz_native_name )
1064 return strdup( pl->psz_native_name );
1066 return strdup( pl->psz_eng_name );
1070 /****************************************************************************
1072 * - add meta info to the playlist item
1073 ****************************************************************************/
1074 static void EsOutAddInfo( es_out_t *out, es_out_id_t *es )
1076 es_out_sys_t *p_sys = out->p_sys;
1077 input_thread_t *p_input = p_sys->p_input;
1078 es_format_t *fmt = &es->fmt;
1081 /* Add stream info */
1082 asprintf( &psz_cat, _("Stream %d"), out->p_sys->i_id - 1 );
1084 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Codec"),
1085 "%.4s", (char*)&fmt->i_codec );
1087 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Language"),
1088 "%s", es->psz_description );
1090 /* Add information */
1091 switch( fmt->i_cat )
1094 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1095 _("Type"), _("Audio") );
1097 if( fmt->audio.i_channels > 0 )
1098 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Channels"),
1099 "%d", fmt->audio.i_channels );
1101 if( fmt->audio.i_rate > 0 )
1102 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Sample rate"),
1103 _("%d Hz"), fmt->audio.i_rate );
1105 if( fmt->audio.i_bitspersample > 0 )
1106 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1107 _("Bits per sample"), "%d",
1108 fmt->audio.i_bitspersample );
1110 if( fmt->i_bitrate > 0 )
1111 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Bitrate"),
1112 _("%d kb/s"), fmt->i_bitrate / 1000 );
1116 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1117 _("Type"), _("Video") );
1119 if( fmt->video.i_width > 0 && fmt->video.i_height > 0 )
1120 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1121 _("Resolution"), "%dx%d",
1122 fmt->video.i_width, fmt->video.i_height );
1124 if( fmt->video.i_visible_width > 0 &&
1125 fmt->video.i_visible_height > 0 )
1126 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1127 _("Display resolution"), "%dx%d",
1128 fmt->video.i_visible_width,
1129 fmt->video.i_visible_height);
1133 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1134 _("Type"), _("Subtitle") );