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 );
364 p_sys->p_es_audio = NULL;
365 p_sys->p_es_sub = NULL;
366 p_sys->p_es_video = NULL;
369 msg_Dbg( p_input, "Selecting program id=%d", p_pgrm->i_id );
371 /* Mark it selected */
372 p_pgrm->b_selected = VLC_TRUE;
374 /* Switch master stream */
375 if( p_sys->p_pgrm && p_sys->p_pgrm->clock.b_master )
377 p_sys->p_pgrm->clock.b_master = VLC_FALSE;
379 p_pgrm->clock.b_master = VLC_TRUE;
380 p_sys->p_pgrm = p_pgrm;
382 /* Update "program" */
383 val.i_int = p_pgrm->i_id;
384 var_Change( p_input, "program", VLC_VAR_SETVALUE, &val, NULL );
387 var_Change( p_input, "audio-es", VLC_VAR_CLEARCHOICES, NULL, NULL );
388 var_Change( p_input, "video-es", VLC_VAR_CLEARCHOICES, NULL, NULL );
389 var_Change( p_input, "spu-es", VLC_VAR_CLEARCHOICES, NULL, NULL );
390 for( i = 0; i < p_sys->i_es; i++ )
392 if( p_sys->es[i]->p_pgrm == p_sys->p_pgrm )
393 EsOutESVarUpdate( out, p_sys->es[i], VLC_FALSE );
394 EsOutSelect( out, p_sys->es[i], VLC_FALSE );
397 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
403 static es_out_pgrm_t *EsOutProgramAdd( es_out_t *out, int i_group )
405 es_out_sys_t *p_sys = out->p_sys;
406 input_thread_t *p_input = p_sys->p_input;
409 es_out_pgrm_t *p_pgrm = malloc( sizeof( es_out_pgrm_t ) );
412 p_pgrm->i_id = i_group;
414 p_pgrm->b_selected = VLC_FALSE;
415 input_ClockInit( &p_pgrm->clock, VLC_FALSE, p_input->input.i_cr_average );
418 TAB_APPEND( p_sys->i_pgrm, p_sys->pgrm, p_pgrm );
420 /* Update "program" variable */
422 var_Change( p_input, "program", VLC_VAR_ADDCHOICE, &val, NULL );
424 if( i_group == var_GetInteger( p_input, "program" ) )
426 EsOutProgramSelect( out, p_pgrm );
430 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
438 static es_out_id_t *EsOutAdd( es_out_t *out, es_format_t *fmt )
440 es_out_sys_t *p_sys = out->p_sys;
441 input_thread_t *p_input = p_sys->p_input;
443 es_out_id_t *es = malloc( sizeof( es_out_id_t ) );
444 es_out_pgrm_t *p_pgrm = NULL;
447 if( fmt->i_group < 0 )
449 msg_Err( p_input, "invalid group number" );
453 /* Search the program */
454 for( i = 0; i < p_sys->i_pgrm; i++ )
456 if( fmt->i_group == p_sys->pgrm[i]->i_id )
458 p_pgrm = p_sys->pgrm[i];
464 /* Create a new one */
465 p_pgrm = EsOutProgramAdd( out, fmt->i_group );
468 /* Increase ref count for program */
473 fmt->i_id = out->p_sys->i_id;
474 es->i_id = fmt->i_id;
476 es_format_Copy( &es->fmt, fmt );
480 es->i_channel = p_sys->i_audio;
484 es->i_channel = p_sys->i_video;
488 es->i_channel = p_sys->i_sub;
495 es->psz_language = LanguageGetName( fmt->psz_language ); /* remember so we only need to do it once */
498 if( es->p_pgrm == p_sys->p_pgrm )
499 EsOutESVarUpdate( out, es, VLC_FALSE );
501 /* Select it if needed */
502 EsOutSelect( out, es, VLC_FALSE );
505 TAB_APPEND( out->p_sys->i_es, out->p_sys->es, es );
506 p_sys->i_id++; /* always incremented */
520 EsOutAddInfo( out, es );
525 static void EsSelect( es_out_t *out, es_out_id_t *es )
527 es_out_sys_t *p_sys = out->p_sys;
528 input_thread_t *p_input = p_sys->p_input;
534 msg_Warn( p_input, "ES 0x%x is already selected", es->i_id );
538 if( es->fmt.i_cat == VIDEO_ES || es->fmt.i_cat == SPU_ES )
540 if( !var_GetBool( p_input, "video" ) ||
541 ( p_input->p_sout && !var_GetBool( p_input, "sout-video" ) ) )
543 msg_Dbg( p_input, "video is disabled, not selecting ES 0x%x",
548 else if( es->fmt.i_cat == AUDIO_ES )
550 var_Get( p_input, "audio", &val );
551 if( !var_GetBool( p_input, "audio" ) ||
552 ( p_input->p_sout && !var_GetBool( p_input, "sout-audio" ) ) )
554 msg_Dbg( p_input, "audio is disabled, not selecting ES 0x%x",
560 es->p_dec = input_DecoderNew( p_input, &es->fmt, VLC_FALSE );
561 if( es->p_dec == NULL || es->p_pgrm != p_sys->p_pgrm )
564 if( es->fmt.i_cat == VIDEO_ES )
565 psz_var = "video-es";
566 else if( es->fmt.i_cat == AUDIO_ES )
567 psz_var = "audio-es";
568 else if( es->fmt.i_cat == SPU_ES )
573 /* Mark it as selected */
574 val.i_int = es->i_id;
575 var_Change( p_input, psz_var, VLC_VAR_SETVALUE, &val, NULL );
578 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
581 static void EsUnselect( es_out_t *out, es_out_id_t *es, vlc_bool_t b_update )
583 es_out_sys_t *p_sys = out->p_sys;
584 input_thread_t *p_input = p_sys->p_input;
588 if( es->p_dec == NULL )
590 msg_Warn( p_input, "ES 0x%x is already unselected", es->i_id );
594 input_DecoderDelete( es->p_dec );
601 if( es->p_dec == NULL )
603 if( es->fmt.i_cat == VIDEO_ES )
604 psz_var = "video-es";
605 else if( es->fmt.i_cat == AUDIO_ES )
606 psz_var = "audio-es";
607 else if( es->fmt.i_cat == SPU_ES )
612 /* Mark it as selected */
614 var_Change( p_input, psz_var, VLC_VAR_SETVALUE, &val, NULL );
616 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
620 * Select an ES given the current mode
621 * XXX: you need to take a the lock before (stream.stream_lock)
623 * \param out The es_out structure
624 * \param es es_out_id structure
628 static void EsOutSelect( es_out_t *out, es_out_id_t *es, vlc_bool_t b_force )
630 es_out_sys_t *p_sys = out->p_sys;
632 int i_cat = es->fmt.i_cat;
634 if( !p_sys->b_active ||
635 ( !b_force && es->fmt.i_priority < 0 ) )
640 if( p_sys->i_mode == ES_OUT_MODE_ALL || b_force )
645 else if( p_sys->i_mode == ES_OUT_MODE_PARTIAL )
649 var_Get( p_sys->p_input, "programs", &val );
650 for ( i = 0; i < val.p_list->i_count; i++ )
652 if ( val.p_list->p_values[i].i_int == es->p_pgrm->i_id || b_force )
659 var_Change( p_sys->p_input, "programs", VLC_VAR_FREELIST, &val, NULL );
661 else if( p_sys->i_mode == ES_OUT_MODE_AUTO )
665 if( es->p_pgrm != p_sys->p_pgrm )
668 if( i_cat == AUDIO_ES )
670 if( p_sys->p_es_audio &&
671 p_sys->p_es_audio->fmt.i_priority >= es->fmt.i_priority )
675 i_wanted = p_sys->i_audio_last >= 0 ?
676 p_sys->i_audio_last : es->i_channel;
678 else if( i_cat == SPU_ES )
680 if( p_sys->p_es_sub &&
681 p_sys->p_es_sub->fmt.i_priority >=
686 i_wanted = p_sys->i_sub_last;
688 else if( i_cat == VIDEO_ES )
690 i_wanted = es->i_channel;
693 if( i_wanted == es->i_channel && es->p_dec == NULL )
697 /* FIXME TODO handle priority here */
700 if( i_cat == AUDIO_ES )
702 if( p_sys->i_mode == ES_OUT_MODE_AUTO &&
704 p_sys->p_es_audio != es &&
705 p_sys->p_es_audio->p_dec )
707 EsUnselect( out, p_sys->p_es_audio, VLC_FALSE );
709 p_sys->p_es_audio = es;
711 else if( i_cat == SPU_ES )
713 if( p_sys->i_mode == ES_OUT_MODE_AUTO &&
715 p_sys->p_es_sub != es &&
716 p_sys->p_es_sub->p_dec )
718 EsUnselect( out, p_sys->p_es_sub, VLC_FALSE );
720 p_sys->p_es_sub = es;
722 else if( i_cat == VIDEO_ES )
724 p_sys->p_es_video = es;
730 * Send a block for the given es_out
732 * \param out the es_out to send from
733 * \param es the es_out_id
734 * \param p_block the data block to send
736 static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
738 es_out_sys_t *p_sys = out->p_sys;
739 input_thread_t *p_input = p_sys->p_input;
740 es_out_pgrm_t *p_pgrm = es->p_pgrm;
743 if( es->fmt.i_cat == AUDIO_ES )
744 i_delay = p_sys->i_audio_delay;
745 else if( es->fmt.i_cat == SPU_ES )
746 i_delay = p_sys->i_spu_delay;
750 /* +11 -> avoid null value with non null dts/pts */
751 if( p_block->i_dts > 0 )
754 input_ClockGetTS( p_input, &p_pgrm->clock,
755 ( p_block->i_dts + 11 ) * 9 / 100 ) + i_delay;
757 if( p_block->i_pts > 0 )
760 input_ClockGetTS( p_input, &p_pgrm->clock,
761 ( p_block->i_pts + 11 ) * 9 / 100 ) + i_delay;
763 if ( es->fmt.i_codec == VLC_FOURCC( 't', 'e', 'l', 'x' ) )
765 mtime_t current_date = mdate();
767 || p_block->i_pts > current_date + 10000000
768 || current_date > p_block->i_pts )
770 /* ETSI EN 300 472 Annex A : do not take into account the PTS
771 * for teletext streams. */
772 p_block->i_pts = current_date + 400000
773 + p_input->i_pts_delay + i_delay;
777 p_block->i_rate = p_input->i_rate;
779 /* TODO handle mute */
780 if( es->p_dec && ( es->fmt.i_cat != AUDIO_ES ||
781 p_input->i_rate == INPUT_RATE_DEFAULT ) )
783 input_DecoderDecode( es->p_dec, p_block );
787 block_Release( p_block );
793 /*****************************************************************************
795 *****************************************************************************/
796 static void EsOutDel( es_out_t *out, es_out_id_t *es )
798 es_out_sys_t *p_sys = out->p_sys;
800 /* We don't try to reselect */
802 EsUnselect( out, es, es->p_pgrm == p_sys->p_pgrm );
804 if( es->p_pgrm == p_sys->p_pgrm )
805 EsOutESVarUpdate( out, es, VLC_TRUE );
807 TAB_REMOVE( p_sys->i_es, p_sys->es, es );
810 if( es->p_pgrm->i_es == 0 )
812 msg_Warn( p_sys->p_input, "Program doesn't contain anymore ES, "
816 if( p_sys->p_es_audio == es ) p_sys->p_es_audio = NULL;
817 if( p_sys->p_es_video == es ) p_sys->p_es_video = NULL;
818 if( p_sys->p_es_sub == es ) p_sys->p_es_sub = NULL;
820 switch( es->fmt.i_cat )
833 if( es->psz_language )
834 free( es->psz_language );
836 es_format_Clean( &es->fmt );
842 * Control query handler
844 * \param out the es_out to control
845 * \param i_query A es_out query as defined in include/ninput.h
846 * \param args a variable list of arguments for the query
847 * \return VLC_SUCCESS or an error code
849 static int EsOutControl( es_out_t *out, int i_query, va_list args )
851 es_out_sys_t *p_sys = out->p_sys;
859 case ES_OUT_SET_ES_STATE:
860 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
861 b = (vlc_bool_t) va_arg( args, vlc_bool_t );
862 if( b && es->p_dec == NULL )
865 return es->p_dec ? VLC_SUCCESS : VLC_EGENERIC;
867 else if( !b && es->p_dec )
869 EsUnselect( out, es, es->p_pgrm == p_sys->p_pgrm );
874 case ES_OUT_GET_ES_STATE:
875 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
876 pb = (vlc_bool_t*) va_arg( args, vlc_bool_t * );
878 *pb = es->p_dec ? VLC_TRUE : VLC_FALSE;
881 case ES_OUT_SET_ACTIVE:
883 b = (vlc_bool_t) va_arg( args, vlc_bool_t );
887 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
891 case ES_OUT_GET_ACTIVE:
892 pb = (vlc_bool_t*) va_arg( args, vlc_bool_t * );
893 *pb = p_sys->b_active;
896 case ES_OUT_SET_MODE:
897 i = (int) va_arg( args, int );
898 if( i == ES_OUT_MODE_NONE || i == ES_OUT_MODE_ALL ||
899 i == ES_OUT_MODE_AUTO || i == ES_OUT_MODE_PARTIAL )
903 /* Reapply policy mode */
904 for( i = 0; i < p_sys->i_es; i++ )
906 if( p_sys->es[i]->p_dec )
908 EsUnselect( out, p_sys->es[i],
909 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
912 for( i = 0; i < p_sys->i_es; i++ )
914 EsOutSelect( out, p_sys->es[i], VLC_FALSE );
920 case ES_OUT_GET_MODE:
921 pi = (int*) va_arg( args, int* );
926 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
927 /* Special case NULL, NULL+i_cat */
930 for( i = 0; i < p_sys->i_es; i++ )
932 if( p_sys->es[i]->p_dec )
933 EsUnselect( out, p_sys->es[i],
934 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
937 else if( es == (es_out_id_t*)((uint8_t*)NULL+AUDIO_ES) )
939 for( i = 0; i < p_sys->i_es; i++ )
941 if( p_sys->es[i]->p_dec &&
942 p_sys->es[i]->fmt.i_cat == AUDIO_ES )
943 EsUnselect( out, p_sys->es[i],
944 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
947 else if( es == (es_out_id_t*)((uint8_t*)NULL+VIDEO_ES) )
949 for( i = 0; i < p_sys->i_es; i++ )
951 if( p_sys->es[i]->p_dec &&
952 p_sys->es[i]->fmt.i_cat == VIDEO_ES )
953 EsUnselect( out, p_sys->es[i],
954 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
957 else if( es == (es_out_id_t*)((uint8_t*)NULL+SPU_ES) )
959 for( i = 0; i < p_sys->i_es; i++ )
961 if( p_sys->es[i]->p_dec &&
962 p_sys->es[i]->fmt.i_cat == SPU_ES )
963 EsUnselect( out, p_sys->es[i],
964 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
969 for( i = 0; i < p_sys->i_es; i++ )
971 if( es == p_sys->es[i] )
973 EsOutSelect( out, es, VLC_TRUE );
981 case ES_OUT_SET_GROUP_PCR:
983 es_out_pgrm_t *p_pgrm = NULL;
987 if( i_query == ES_OUT_SET_PCR )
989 p_pgrm = p_sys->p_pgrm;
994 i_group = (int)va_arg( args, int );
995 for( i = 0; i < p_sys->i_pgrm; i++ )
997 if( p_sys->pgrm[i]->i_id == i_group )
999 p_pgrm = p_sys->pgrm[i];
1004 if( p_pgrm == NULL )
1005 p_pgrm = EsOutProgramAdd( out, i_group ); /* Create it */
1007 i_pcr = (int64_t)va_arg( args, int64_t );
1008 /* search program */
1009 /* 11 is a vodoo trick to avoid non_pcr*9/100 to be null */
1010 input_ClockSetPCR( p_sys->p_input, &p_pgrm->clock,
1011 (i_pcr + 11 ) * 9 / 100);
1015 case ES_OUT_RESET_PCR:
1016 for( i = 0; i < p_sys->i_pgrm; i++ )
1018 p_sys->pgrm[i]->clock.i_synchro_state = SYNCHRO_REINIT;
1019 p_sys->pgrm[i]->clock.last_pts = 0;
1026 int64_t i_ts = (int64_t)va_arg( args, int64_t );
1027 int64_t *pi_ts = (int64_t *)va_arg( args, int64_t * );
1028 *pi_ts = input_ClockGetTS( p_sys->p_input,
1029 &p_sys->p_pgrm->clock,
1030 ( i_ts + 11 ) * 9 / 100 );
1033 return VLC_EGENERIC;
1035 case ES_OUT_GET_GROUP:
1036 pi = (int*) va_arg( args, int* );
1038 *pi = p_sys->p_pgrm->i_id;
1040 *pi = -1; /* FIXME */
1043 case ES_OUT_SET_GROUP:
1046 i = (int) va_arg( args, int );
1047 for( j = 0; j < p_sys->i_pgrm; j++ )
1049 es_out_pgrm_t *p_pgrm = p_sys->pgrm[j];
1050 if( p_pgrm->i_id == i )
1052 EsOutProgramSelect( out, p_pgrm );
1056 return VLC_EGENERIC;
1059 case ES_OUT_SET_FMT:
1061 /* This ain't pretty but is need by some demuxers (eg. Ogg )
1062 * to update the p_extra data */
1064 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
1065 p_fmt = (es_format_t*) va_arg( args, es_format_t * );
1066 if( es == NULL ) return VLC_EGENERIC;
1068 if( p_fmt->i_extra )
1070 es->fmt.i_extra = p_fmt->i_extra;
1071 es->fmt.p_extra = realloc( es->fmt.p_extra, p_fmt->i_extra );
1072 memcpy( es->fmt.p_extra, p_fmt->p_extra, p_fmt->i_extra );
1074 if( !es->p_dec ) return VLC_SUCCESS;
1076 es->p_dec->fmt_in.i_extra = p_fmt->i_extra;
1077 es->p_dec->fmt_in.p_extra =
1078 realloc( es->p_dec->fmt_in.p_extra, p_fmt->i_extra );
1079 memcpy( es->p_dec->fmt_in.p_extra,
1080 p_fmt->p_extra, p_fmt->i_extra );
1087 msg_Err( p_sys->p_input, "unknown query in es_out_Control" );
1088 return VLC_EGENERIC;
1092 /****************************************************************************
1093 * LanguageGetName: try to expend iso639 into plain name
1094 ****************************************************************************/
1095 static char *LanguageGetName( const char *psz_code )
1097 const iso639_lang_t *pl;
1099 if( psz_code == NULL )
1101 return strdup( "" );
1104 if( strlen( psz_code ) == 2 )
1106 pl = GetLang_1( psz_code );
1108 else if( strlen( psz_code ) == 3 )
1110 pl = GetLang_2B( psz_code );
1111 if( !strcmp( pl->psz_iso639_1, "??" ) )
1113 pl = GetLang_2T( psz_code );
1118 return strdup( psz_code );
1121 if( !strcmp( pl->psz_iso639_1, "??" ) )
1123 return strdup( psz_code );
1127 if( *pl->psz_native_name )
1129 return strdup( pl->psz_native_name );
1131 return strdup( pl->psz_eng_name );
1135 /****************************************************************************
1137 * - add meta info to the playlist item
1138 ****************************************************************************/
1139 static void EsOutAddInfo( es_out_t *out, es_out_id_t *es )
1141 es_out_sys_t *p_sys = out->p_sys;
1142 input_thread_t *p_input = p_sys->p_input;
1143 es_format_t *fmt = &es->fmt;
1146 /* Add stream info */
1147 asprintf( &psz_cat, _("Stream %d"), out->p_sys->i_id - 1 );
1149 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Codec"),
1150 "%.4s", (char*)&fmt->i_codec );
1152 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Language"),
1153 "%s", es->psz_language );
1155 /* Add information */
1156 switch( fmt->i_cat )
1159 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1160 _("Type"), _("Audio") );
1162 if( fmt->audio.i_channels > 0 )
1163 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Channels"),
1164 "%d", fmt->audio.i_channels );
1166 if( fmt->audio.i_rate > 0 )
1167 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Sample rate"),
1168 _("%d Hz"), fmt->audio.i_rate );
1170 if( fmt->audio.i_bitspersample > 0 )
1171 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1172 _("Bits per sample"), "%d",
1173 fmt->audio.i_bitspersample );
1175 if( fmt->i_bitrate > 0 )
1176 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Bitrate"),
1177 _("%d kb/s"), fmt->i_bitrate / 1000 );
1181 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1182 _("Type"), _("Video") );
1184 if( fmt->video.i_width > 0 && fmt->video.i_height > 0 )
1185 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1186 _("Resolution"), "%dx%d",
1187 fmt->video.i_width, fmt->video.i_height );
1189 if( fmt->video.i_visible_width > 0 &&
1190 fmt->video.i_visible_height > 0 )
1191 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1192 _("Display resolution"), "%dx%d",
1193 fmt->video.i_visible_width,
1194 fmt->video.i_visible_height);
1198 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1199 _("Type"), _("Subtitle") );