1 /*****************************************************************************
2 * es_out.c: Es Out handler for input.
3 *****************************************************************************
4 * Copyright (C) 2003-2004 the VideoLAN team
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * Jean-Paul Saman <jpsaman #_at_# m2x dot nl>
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
32 #include <vlc_input.h>
33 #include <vlc_es_out.h>
34 #include <vlc_block.h>
37 #include "input_internal.h"
39 #include "vlc_playlist.h"
41 /* FIXME we should find a better way than including that */
42 #include "../text/iso-639_def.h"
44 /*****************************************************************************
46 *****************************************************************************/
52 /* Number of es for this pgrm */
55 vlc_bool_t b_selected;
57 /* Clock for this program */
61 char *psz_now_playing;
71 es_out_pgrm_t *p_pgrm;
74 int64_t i_preroll_end;
76 /* Channel in the track type */
80 char *psz_language_code;
86 input_thread_t *p_input;
91 es_out_pgrm_t **pp_selected_pgrm; /* --programs */
92 es_out_pgrm_t *p_pgrm; /* Master program */
109 int i_audio_last, i_audio_id;
110 int i_sub_last, i_sub_id;
111 int i_default_sub_id; /* As specified in container; if applicable */
112 char **ppsz_audio_language;
113 char **ppsz_sub_language;
115 /* current main es */
116 es_out_id_t *p_es_audio;
117 es_out_id_t *p_es_video;
118 es_out_id_t *p_es_sub;
121 int64_t i_audio_delay;
125 static es_out_id_t *EsOutAdd ( es_out_t *, es_format_t * );
126 static int EsOutSend ( es_out_t *, es_out_id_t *, block_t * );
127 static void EsOutDel ( es_out_t *, es_out_id_t * );
128 static void EsOutSelect( es_out_t *out, es_out_id_t *es, vlc_bool_t b_force );
129 static int EsOutControl( es_out_t *, int i_query, va_list );
131 static void EsOutAddInfo( es_out_t *, es_out_id_t *es );
133 static void EsSelect( es_out_t *out, es_out_id_t *es );
134 static void EsUnselect( es_out_t *out, es_out_id_t *es, vlc_bool_t b_update );
135 static char *LanguageGetName( const char *psz_code );
136 static char *LanguageGetCode( const char *psz_lang );
137 static char **LanguageSplit( const char *psz_langs );
138 static int LanguageArrayIndex( char **ppsz_langs, char *psz_lang );
140 static char *EsOutProgramGetMetaName( es_out_pgrm_t *p_pgrm );
142 /*****************************************************************************
144 *****************************************************************************/
145 es_out_t *input_EsOutNew( input_thread_t *p_input )
147 es_out_t *out = malloc( sizeof( es_out_t ) );
148 es_out_sys_t *p_sys = malloc( sizeof( es_out_sys_t ) );
152 out->pf_add = EsOutAdd;
153 out->pf_send = EsOutSend;
154 out->pf_del = EsOutDel;
155 out->pf_control = EsOutControl;
157 out->b_sout = (p_input->p->p_sout != NULL ? VLC_TRUE : VLC_FALSE);
159 p_sys->p_input = p_input;
161 p_sys->b_active = VLC_FALSE;
162 p_sys->i_mode = ES_OUT_MODE_AUTO;
165 TAB_INIT( p_sys->i_pgrm, p_sys->pgrm );
166 p_sys->p_pgrm = NULL;
170 TAB_INIT( p_sys->i_es, p_sys->es );
177 var_Get( p_input, "audio-track", &val );
178 p_sys->i_audio_last = val.i_int;
180 var_Get( p_input, "sub-track", &val );
181 p_sys->i_sub_last = val.i_int;
183 p_sys->i_default_sub_id = -1;
185 if( !p_input->b_preparsing )
187 var_Get( p_input, "audio-language", &val );
188 p_sys->ppsz_audio_language = LanguageSplit(val.psz_string);
189 if( p_sys->ppsz_audio_language )
191 for( i = 0; p_sys->ppsz_audio_language[i]; i++ )
192 msg_Dbg( p_input, "selected audio language[%d] %s",
193 i, p_sys->ppsz_audio_language[i] );
195 if( val.psz_string ) free( val.psz_string );
197 var_Get( p_input, "sub-language", &val );
198 p_sys->ppsz_sub_language = LanguageSplit(val.psz_string);
199 if( p_sys->ppsz_sub_language )
201 for( i = 0; p_sys->ppsz_sub_language[i]; i++ )
202 msg_Dbg( p_input, "selected subtitle language[%d] %s",
203 i, p_sys->ppsz_sub_language[i] );
205 if( val.psz_string ) free( val.psz_string );
209 p_sys->ppsz_sub_language = NULL;
210 p_sys->ppsz_audio_language = NULL;
213 var_Get( p_input, "audio-track-id", &val );
214 p_sys->i_audio_id = val.i_int;
216 var_Get( p_input, "sub-track-id", &val );
217 p_sys->i_sub_id = val.i_int;
219 p_sys->p_es_audio = NULL;
220 p_sys->p_es_video = NULL;
221 p_sys->p_es_sub = NULL;
223 p_sys->i_audio_delay= 0;
224 p_sys->i_spu_delay = 0;
229 /*****************************************************************************
231 *****************************************************************************/
232 void input_EsOutDelete( es_out_t *out )
234 es_out_sys_t *p_sys = out->p_sys;
237 for( i = 0; i < p_sys->i_es; i++ )
239 if( p_sys->es[i]->p_dec )
241 input_DecoderDelete( p_sys->es[i]->p_dec );
243 if( p_sys->es[i]->psz_language )
244 free( p_sys->es[i]->psz_language );
245 if( p_sys->es[i]->psz_language_code )
246 free( p_sys->es[i]->psz_language_code );
247 es_format_Clean( &p_sys->es[i]->fmt );
249 free( p_sys->es[i] );
251 if( p_sys->ppsz_audio_language )
253 for( i = 0; p_sys->ppsz_audio_language[i]; i++ )
254 free( p_sys->ppsz_audio_language[i] );
255 free( p_sys->ppsz_audio_language );
257 if( p_sys->ppsz_sub_language )
259 for( i = 0; p_sys->ppsz_sub_language[i]; i++ )
260 free( p_sys->ppsz_sub_language[i] );
261 free( p_sys->ppsz_sub_language );
267 /* FIXME duplicate work EsOutProgramDel (but we cannot use it) add a EsOutProgramClean ? */
268 for( i = 0; i < p_sys->i_pgrm; i++ )
270 es_out_pgrm_t *p_pgrm = p_sys->pgrm[i];
271 if( p_pgrm->psz_now_playing )
272 free( p_pgrm->psz_now_playing );
273 if( p_pgrm->psz_publisher )
274 free( p_pgrm->psz_publisher );
275 if( p_pgrm->psz_name )
276 free( p_pgrm->psz_name );
278 vlc_epg_Delete( p_pgrm->p_epg );
282 TAB_CLEAN( p_sys->i_pgrm, p_sys->pgrm );
288 es_out_id_t *input_EsOutGetFromID( es_out_t *out, int i_id )
293 /* Special HACK, -i_id is tha cat of the stream */
294 return (es_out_id_t*)((uint8_t*)NULL-i_id);
297 for( i = 0; i < out->p_sys->i_es; i++ )
299 if( out->p_sys->es[i]->i_id == i_id )
300 return out->p_sys->es[i];
305 void input_EsOutDiscontinuity( es_out_t *out, vlc_bool_t b_flush, vlc_bool_t b_audio )
307 es_out_sys_t *p_sys = out->p_sys;
310 for( i = 0; i < p_sys->i_es; i++ )
312 es_out_id_t *es = p_sys->es[i];
314 /* Send a dummy block to let decoder know that
315 * there is a discontinuity */
316 if( es->p_dec && ( !b_audio || es->fmt.i_cat == AUDIO_ES ) )
317 input_DecoderDiscontinuity( es->p_dec, b_flush );
320 void input_EsOutSetRate( es_out_t *out )
322 es_out_sys_t *p_sys = out->p_sys;
325 for( i = 0; i < p_sys->i_pgrm; i++ )
326 input_ClockSetRate( p_sys->p_input, &p_sys->pgrm[i]->clock );
329 void input_EsOutSetDelay( es_out_t *out, int i_cat, int64_t i_delay )
331 es_out_sys_t *p_sys = out->p_sys;
333 if( i_cat == AUDIO_ES )
334 p_sys->i_audio_delay = i_delay;
335 else if( i_cat == SPU_ES )
336 p_sys->i_spu_delay = i_delay;
339 vlc_bool_t input_EsOutDecodersEmpty( es_out_t *out )
341 es_out_sys_t *p_sys = out->p_sys;
344 for( i = 0; i < p_sys->i_es; i++ )
346 es_out_id_t *es = p_sys->es[i];
348 if( es->p_dec && !input_DecoderEmpty( es->p_dec ) )
354 /*****************************************************************************
356 *****************************************************************************/
357 static void EsOutESVarUpdate( es_out_t *out, es_out_id_t *es,
358 vlc_bool_t b_delete )
360 es_out_sys_t *p_sys = out->p_sys;
361 input_thread_t *p_input = p_sys->p_input;
362 vlc_value_t val, text;
366 if( es->fmt.i_cat == AUDIO_ES )
367 psz_var = "audio-es";
368 else if( es->fmt.i_cat == VIDEO_ES )
369 psz_var = "video-es";
370 else if( es->fmt.i_cat == SPU_ES )
377 val.i_int = es->i_id;
378 var_Change( p_input, psz_var, VLC_VAR_DELCHOICE, &val, NULL );
379 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
383 /* Get the number of ES already added */
384 var_Change( p_input, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
389 /* First one, we need to add the "Disable" choice */
390 val2.i_int = -1; text.psz_string = _("Disable");
391 var_Change( p_input, psz_var, VLC_VAR_ADDCHOICE, &val2, &text );
395 /* Take care of the ES description */
396 if( es->fmt.psz_description && *es->fmt.psz_description )
398 if( es->psz_language && *es->psz_language )
400 text.psz_string = malloc( strlen( es->fmt.psz_description) +
401 strlen( es->psz_language ) + 10 );
402 sprintf( text.psz_string, "%s - [%s]", es->fmt.psz_description,
405 else text.psz_string = strdup( es->fmt.psz_description );
409 if( es->psz_language && *es->psz_language )
412 text.psz_string = malloc( strlen( _("Track %i") )+
413 strlen( es->psz_language ) + 30 );
414 asprintf( &temp, _("Track %i"), val.i_int );
415 sprintf( text.psz_string, "%s - [%s]", temp, es->psz_language );
420 text.psz_string = malloc( strlen( _("Track %i") ) + 20 );
421 sprintf( text.psz_string, _("Track %i"), val.i_int );
425 val.i_int = es->i_id;
426 var_Change( p_input, psz_var, VLC_VAR_ADDCHOICE, &val, &text );
428 free( text.psz_string );
430 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
433 /* EsOutProgramSelect:
434 * Select a program and update the object variable
436 static void EsOutProgramSelect( es_out_t *out, es_out_pgrm_t *p_pgrm )
438 es_out_sys_t *p_sys = out->p_sys;
439 input_thread_t *p_input = p_sys->p_input;
443 if( p_sys->p_pgrm == p_pgrm )
444 return; /* Nothing to do */
448 es_out_pgrm_t *old = p_sys->p_pgrm;
449 msg_Dbg( p_input, "unselecting program id=%d", old->i_id );
451 for( i = 0; i < p_sys->i_es; i++ )
453 if( p_sys->es[i]->p_pgrm == old && p_sys->es[i]->p_dec &&
454 p_sys->i_mode != ES_OUT_MODE_ALL )
455 EsUnselect( out, p_sys->es[i], VLC_TRUE );
458 p_sys->p_es_audio = NULL;
459 p_sys->p_es_sub = NULL;
460 p_sys->p_es_video = NULL;
463 msg_Dbg( p_input, "selecting program id=%d", p_pgrm->i_id );
465 /* Mark it selected */
466 p_pgrm->b_selected = VLC_TRUE;
468 /* Switch master stream */
469 if( p_sys->p_pgrm && p_sys->p_pgrm->clock.b_master )
471 p_sys->p_pgrm->clock.b_master = VLC_FALSE;
473 p_pgrm->clock.b_master = VLC_TRUE;
474 p_sys->p_pgrm = p_pgrm;
476 /* Update "program" */
477 val.i_int = p_pgrm->i_id;
478 var_Change( p_input, "program", VLC_VAR_SETVALUE, &val, NULL );
481 var_Change( p_input, "audio-es", VLC_VAR_CLEARCHOICES, NULL, NULL );
482 var_Change( p_input, "video-es", VLC_VAR_CLEARCHOICES, NULL, NULL );
483 var_Change( p_input, "spu-es", VLC_VAR_CLEARCHOICES, NULL, NULL );
484 for( i = 0; i < p_sys->i_es; i++ )
486 if( p_sys->es[i]->p_pgrm == p_sys->p_pgrm )
487 EsOutESVarUpdate( out, p_sys->es[i], VLC_FALSE );
488 EsOutSelect( out, p_sys->es[i], VLC_FALSE );
491 /* Update now playing */
492 input_item_SetNowPlaying( p_input->p->input.p_item,
493 p_pgrm->psz_now_playing );
494 input_item_SetPublisher( p_input->p->input.p_item,
495 p_pgrm->psz_publisher );
497 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
503 static es_out_pgrm_t *EsOutProgramAdd( es_out_t *out, int i_group )
505 es_out_sys_t *p_sys = out->p_sys;
506 input_thread_t *p_input = p_sys->p_input;
509 es_out_pgrm_t *p_pgrm = malloc( sizeof( es_out_pgrm_t ) );
512 p_pgrm->i_id = i_group;
514 p_pgrm->b_selected = VLC_FALSE;
515 p_pgrm->psz_name = NULL;
516 p_pgrm->psz_now_playing = NULL;
517 p_pgrm->psz_publisher = NULL;
518 p_pgrm->p_epg = NULL;
519 input_ClockInit( p_input, &p_pgrm->clock, VLC_FALSE, p_input->p->input.i_cr_average );
522 TAB_APPEND( p_sys->i_pgrm, p_sys->pgrm, p_pgrm );
524 /* Update "program" variable */
526 var_Change( p_input, "program", VLC_VAR_ADDCHOICE, &val, NULL );
528 if( i_group == var_GetInteger( p_input, "program" ) )
530 EsOutProgramSelect( out, p_pgrm );
534 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
542 static int EsOutProgramDel( es_out_t *out, int i_group )
544 es_out_sys_t *p_sys = out->p_sys;
545 input_thread_t *p_input = p_sys->p_input;
546 es_out_pgrm_t *p_pgrm = NULL;
550 for( i = 0; i < p_sys->i_pgrm; i++ )
552 if( p_sys->pgrm[i]->i_id == i_group )
554 p_pgrm = p_sys->pgrm[i];
564 msg_Dbg( p_input, "can't delete program %d which still has %i ES",
565 i_group, p_pgrm->i_es );
569 TAB_REMOVE( p_sys->i_pgrm, p_sys->pgrm, p_pgrm );
571 /* If program is selected we need to unselect it */
572 if( p_sys->p_pgrm == p_pgrm ) p_sys->p_pgrm = NULL;
574 if( p_pgrm->psz_name ) free( p_pgrm->psz_name );
575 if( p_pgrm->psz_now_playing ) free( p_pgrm->psz_now_playing );
576 if( p_pgrm->psz_publisher ) free( p_pgrm->psz_publisher );
578 vlc_epg_Delete( p_pgrm->p_epg );
581 /* Update "program" variable */
583 var_Change( p_input, "program", VLC_VAR_DELCHOICE, &val, NULL );
585 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
592 static char *EsOutProgramGetMetaName( es_out_pgrm_t *p_pgrm )
595 if( p_pgrm->psz_name )
596 asprintf( &psz, _("%s [%s %d]"), p_pgrm->psz_name, _("Program"), p_pgrm->i_id );
598 asprintf( &psz, "%s %d", _("Program"), p_pgrm->i_id );
602 static void EsOutProgramMeta( es_out_t *out, int i_group, vlc_meta_t *p_meta )
604 es_out_sys_t *p_sys = out->p_sys;
605 es_out_pgrm_t *p_pgrm = NULL;
606 input_thread_t *p_input = p_sys->p_input;
608 const char *psz_title = NULL;
609 const char *psz_provider = NULL;
612 msg_Dbg( p_input, "EsOutProgramMeta: number=%d", i_group );
614 /* Check against empty meta data (empty for what we handle) */
615 if( !vlc_meta_Get( p_meta, vlc_meta_Title) &&
616 !vlc_meta_Get( p_meta, vlc_meta_NowPlaying) &&
617 !vlc_meta_Get( p_meta, vlc_meta_Publisher) &&
618 vlc_dictionary_keys_count( &p_meta->extra_tags ) <= 0 )
621 for( i = 0; i < p_sys->i_pgrm; i++ )
623 if( p_sys->pgrm[i]->i_id == i_group )
625 p_pgrm = p_sys->pgrm[i];
630 p_pgrm = EsOutProgramAdd( out, i_group ); /* Create it */
633 psz_title = vlc_meta_Get( p_meta, vlc_meta_Title);
634 psz_provider = vlc_meta_Get( p_meta, vlc_meta_Publisher);
636 /* Update the description text of the program */
637 if( psz_title && *psz_title )
642 if( !p_pgrm->psz_name || strcmp( p_pgrm->psz_name, psz_title ) )
644 char *psz_cat = EsOutProgramGetMetaName( p_pgrm );
646 /* Remove old entries */
647 input_Control( p_input, INPUT_DEL_INFO, psz_cat, NULL );
648 /* TODO update epg name */
651 if( p_pgrm->psz_name ) free( p_pgrm->psz_name );
652 p_pgrm->psz_name = strdup( psz_title );
654 /* ugly but it works */
656 var_Change( p_input, "program", VLC_VAR_DELCHOICE, &val, NULL );
658 if( psz_provider && *psz_provider )
660 asprintf( &text.psz_string, "%s [%s]", psz_title, psz_provider );
661 var_Change( p_input, "program", VLC_VAR_ADDCHOICE, &val, &text );
662 free( text.psz_string );
666 text.psz_string = (char *)psz_title;
667 var_Change( p_input, "program", VLC_VAR_ADDCHOICE, &val, &text );
671 psz_cat = EsOutProgramGetMetaName( p_pgrm );
674 if( p_sys->p_pgrm == p_pgrm )
675 input_item_SetPublisher( p_input->p->input.p_item, psz_provider );
676 input_Control( p_input, INPUT_ADD_INFO, psz_cat, input_MetaTypeToLocalizedString(vlc_meta_Publisher), psz_provider );
678 char ** ppsz_all_keys = vlc_dictionary_all_keys( &p_meta->extra_tags );
679 for( i = 0; ppsz_all_keys[i]; i++ )
681 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _(ppsz_all_keys[i]),
682 vlc_dictionary_value_for_key( &p_meta->extra_tags, ppsz_all_keys[i] ) );
683 free( ppsz_all_keys[i] );
685 free( ppsz_all_keys );
690 static void vlc_epg_Merge( vlc_epg_t *p_dst, const vlc_epg_t *p_src )
695 for( i = 0; i < p_src->i_event; i++ )
697 vlc_epg_event_t *p_evt = p_src->pp_event[i];
698 vlc_bool_t b_add = VLC_TRUE;
701 for( j = 0; j < p_dst->i_event; j++ )
703 if( p_dst->pp_event[j]->i_start == p_evt->i_start && p_dst->pp_event[j]->i_duration == p_evt->i_duration )
708 if( p_dst->pp_event[j]->i_start > p_evt->i_start )
713 vlc_epg_event_t *p_copy = malloc( sizeof(vlc_epg_event_t) );
716 memset( p_copy, 0, sizeof(vlc_epg_event_t) );
717 p_copy->i_start = p_evt->i_start;
718 p_copy->i_duration = p_evt->i_duration;
719 p_copy->psz_name = p_evt->psz_name ? strdup( p_evt->psz_name ) : NULL;
720 p_copy->psz_short_description = p_evt->psz_short_description ? strdup( p_evt->psz_short_description ) : NULL;
721 p_copy->psz_description = p_evt->psz_description ? strdup( p_evt->psz_description ) : NULL;
722 TAB_INSERT( p_dst->i_event, p_dst->pp_event, p_copy, j );
726 vlc_epg_SetCurrent( p_dst, p_src->p_current ? p_src->p_current->i_start : -1 );
728 /* Keep only 1 old event */
729 if( p_dst->p_current )
731 while( p_dst->i_event > 1 && p_dst->pp_event[0] != p_dst->p_current && p_dst->pp_event[1] != p_dst->p_current )
732 TAB_REMOVE( p_dst->i_event, p_dst->pp_event, p_dst->pp_event[0] );
736 static void EsOutProgramEpg( es_out_t *out, int i_group, vlc_epg_t *p_epg )
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 = NULL;
745 for( i = 0; i < p_sys->i_pgrm; i++ )
747 if( p_sys->pgrm[i]->i_id == i_group )
749 p_pgrm = p_sys->pgrm[i];
754 p_pgrm = EsOutProgramAdd( out, i_group ); /* Create it */
758 p_pgrm->p_epg = vlc_epg_New( p_pgrm->psz_name );
759 vlc_epg_Merge( p_pgrm->p_epg, p_epg );
762 psz_cat = EsOutProgramGetMetaName( p_pgrm );
763 #ifdef HAVE_LOCALTIME_R
765 if( asprintf( &psz_epg, "EPG %s", psz_cat ) == -1 )
767 input_Control( p_input, INPUT_DEL_INFO, psz_epg, NULL );
768 msg_Dbg( p_input, "EsOutProgramEpg: number=%d name=%s", i_group, p_pgrm->p_epg->psz_name );
769 for( i = 0; i < p_pgrm->p_epg->i_event; i++ )
771 const vlc_epg_event_t *p_evt = p_pgrm->p_epg->pp_event[i];
772 time_t t_start = (time_t)p_evt->i_start;
776 localtime_r( &t_start, &tm_start );
778 snprintf( psz_start, sizeof(psz_start), "%2.2d:%2.2d:%2.2d", tm_start.tm_hour, tm_start.tm_min, tm_start.tm_sec );
779 if( p_evt->psz_short_description || p_evt->psz_description )
780 input_Control( p_input, INPUT_ADD_INFO, psz_epg, psz_start, "%s (%2.2d:%2.2d) - %s",
782 p_evt->i_duration/60/60, (p_evt->i_duration/60)%60,
783 p_evt->psz_short_description ? p_evt->psz_short_description : p_evt->psz_description );
785 input_Control( p_input, INPUT_ADD_INFO, psz_epg, psz_start, "%s (%2.2d:%2.2d)",
787 p_evt->i_duration/60/60, (p_evt->i_duration/60)%60 );
791 /* Update now playing */
792 if( p_pgrm->psz_now_playing )
793 free( p_pgrm->psz_now_playing );
794 p_pgrm->psz_now_playing = NULL;
795 if( p_epg->p_current && p_epg->p_current->psz_name && *p_epg->p_current->psz_name )
796 p_pgrm->psz_now_playing = strdup( p_epg->p_current->psz_name );
798 if( p_pgrm == p_sys->p_pgrm )
799 input_item_SetNowPlaying( p_input->p->input.p_item, p_pgrm->psz_now_playing );
801 if( p_pgrm->psz_now_playing )
803 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
804 input_MetaTypeToLocalizedString(vlc_meta_NowPlaying),
805 p_pgrm->psz_now_playing );
809 input_Control( p_input, INPUT_DEL_INFO, psz_cat,
810 input_MetaTypeToLocalizedString(vlc_meta_NowPlaying) );
819 static es_out_id_t *EsOutAdd( es_out_t *out, es_format_t *fmt )
821 es_out_sys_t *p_sys = out->p_sys;
822 input_thread_t *p_input = p_sys->p_input;
824 es_out_id_t *es = malloc( sizeof( es_out_id_t ) );
825 es_out_pgrm_t *p_pgrm = NULL;
828 if( fmt->i_group < 0 )
830 msg_Err( p_input, "invalid group number" );
834 /* Search the program */
835 for( i = 0; i < p_sys->i_pgrm; i++ )
837 if( fmt->i_group == p_sys->pgrm[i]->i_id )
839 p_pgrm = p_sys->pgrm[i];
845 /* Create a new one */
846 p_pgrm = EsOutProgramAdd( out, fmt->i_group );
849 /* Increase ref count for program */
854 fmt->i_id = out->p_sys->i_id;
855 es->i_id = fmt->i_id;
857 es_format_Copy( &es->fmt, fmt );
858 es->i_preroll_end = -1;
863 es->i_channel = p_sys->i_audio;
867 es->i_channel = p_sys->i_video;
868 if( fmt->video.i_frame_rate && fmt->video.i_frame_rate_base )
869 vlc_ureduce( &es->fmt.video.i_frame_rate,
870 &es->fmt.video.i_frame_rate_base,
871 fmt->video.i_frame_rate,
872 fmt->video.i_frame_rate_base, 0 );
876 es->i_channel = p_sys->i_sub;
883 es->psz_language = LanguageGetName( fmt->psz_language ); /* remember so we only need to do it once */
884 es->psz_language_code = LanguageGetCode( fmt->psz_language );
887 if( es->p_pgrm == p_sys->p_pgrm )
888 EsOutESVarUpdate( out, es, VLC_FALSE );
890 /* Select it if needed */
891 EsOutSelect( out, es, VLC_FALSE );
894 TAB_APPEND( out->p_sys->i_es, out->p_sys->es, es );
895 p_sys->i_id++; /* always incremented */
909 EsOutAddInfo( out, es );
914 static void EsSelect( es_out_t *out, es_out_id_t *es )
916 es_out_sys_t *p_sys = out->p_sys;
917 input_thread_t *p_input = p_sys->p_input;
923 msg_Warn( p_input, "ES 0x%x is already selected", es->i_id );
927 if( es->fmt.i_cat == VIDEO_ES || es->fmt.i_cat == SPU_ES )
929 if( !var_GetBool( p_input, "video" ) ||
930 ( p_input->p->p_sout && !var_GetBool( p_input, "sout-video" ) ) )
932 msg_Dbg( p_input, "video is disabled, not selecting ES 0x%x",
937 else if( es->fmt.i_cat == AUDIO_ES )
939 var_Get( p_input, "audio", &val );
940 if( !var_GetBool( p_input, "audio" ) ||
941 ( p_input->p->p_sout && !var_GetBool( p_input, "sout-audio" ) ) )
943 msg_Dbg( p_input, "audio is disabled, not selecting ES 0x%x",
948 if( es->fmt.i_cat == SPU_ES )
950 var_Get( p_input, "spu", &val );
951 if( !var_GetBool( p_input, "spu" ) ||
952 ( p_input->p->p_sout && !var_GetBool( p_input, "sout-spu" ) ) )
954 msg_Dbg( p_input, "spu is disabled, not selecting ES 0x%x",
960 es->i_preroll_end = -1;
961 es->p_dec = input_DecoderNew( p_input, &es->fmt, VLC_FALSE );
962 if( es->p_dec == NULL || es->p_pgrm != p_sys->p_pgrm )
965 if( es->fmt.i_cat == VIDEO_ES )
966 psz_var = "video-es";
967 else if( es->fmt.i_cat == AUDIO_ES )
968 psz_var = "audio-es";
969 else if( es->fmt.i_cat == SPU_ES )
974 /* Mark it as selected */
975 val.i_int = es->i_id;
976 var_Change( p_input, psz_var, VLC_VAR_SETVALUE, &val, NULL );
979 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
982 static void EsUnselect( es_out_t *out, es_out_id_t *es, vlc_bool_t b_update )
984 es_out_sys_t *p_sys = out->p_sys;
985 input_thread_t *p_input = p_sys->p_input;
989 if( es->p_dec == NULL )
991 msg_Warn( p_input, "ES 0x%x is already unselected", es->i_id );
995 input_DecoderDelete( es->p_dec );
1002 if( es->p_dec == NULL )
1004 if( es->fmt.i_cat == VIDEO_ES )
1005 psz_var = "video-es";
1006 else if( es->fmt.i_cat == AUDIO_ES )
1007 psz_var = "audio-es";
1008 else if( es->fmt.i_cat == SPU_ES )
1013 /* Mark it as selected */
1015 var_Change( p_input, psz_var, VLC_VAR_SETVALUE, &val, NULL );
1017 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
1021 * Select an ES given the current mode
1022 * XXX: you need to take a the lock before (stream.stream_lock)
1024 * \param out The es_out structure
1025 * \param es es_out_id structure
1026 * \param b_force ...
1029 static void EsOutSelect( es_out_t *out, es_out_id_t *es, vlc_bool_t b_force )
1031 es_out_sys_t *p_sys = out->p_sys;
1033 int i_cat = es->fmt.i_cat;
1035 if( !p_sys->b_active ||
1036 ( !b_force && es->fmt.i_priority < 0 ) )
1041 if( p_sys->i_mode == ES_OUT_MODE_ALL || b_force )
1044 EsSelect( out, es );
1046 else if( p_sys->i_mode == ES_OUT_MODE_PARTIAL )
1050 var_Get( p_sys->p_input, "programs", &val );
1051 for ( i = 0; i < val.p_list->i_count; i++ )
1053 if ( val.p_list->p_values[i].i_int == es->p_pgrm->i_id || b_force )
1056 EsSelect( out, es );
1060 var_Change( p_sys->p_input, "programs", VLC_VAR_FREELIST, &val, NULL );
1062 else if( p_sys->i_mode == ES_OUT_MODE_AUTO )
1066 if( es->p_pgrm != p_sys->p_pgrm )
1069 if( i_cat == AUDIO_ES )
1071 int idx1 = LanguageArrayIndex( p_sys->ppsz_audio_language,
1072 es->psz_language_code );
1074 if( p_sys->p_es_audio &&
1075 p_sys->p_es_audio->fmt.i_priority >= es->fmt.i_priority )
1077 int idx2 = LanguageArrayIndex( p_sys->ppsz_audio_language,
1078 p_sys->p_es_audio->psz_language_code );
1080 if( idx1 < 0 || ( idx2 >= 0 && idx2 <= idx1 ) )
1082 i_wanted = es->i_channel;
1086 /* Select audio if (no audio selected yet)
1087 * - no audio-language
1088 * - no audio code for the ES
1089 * - audio code in the requested list */
1091 !strcmp( es->psz_language_code, "??" ) ||
1092 !p_sys->ppsz_audio_language )
1093 i_wanted = es->i_channel;
1096 if( p_sys->i_audio_last >= 0 )
1097 i_wanted = p_sys->i_audio_last;
1099 if( p_sys->i_audio_id >= 0 )
1101 if( es->i_id == p_sys->i_audio_id )
1102 i_wanted = es->i_channel;
1107 else if( i_cat == SPU_ES )
1109 int idx1 = LanguageArrayIndex( p_sys->ppsz_sub_language,
1110 es->psz_language_code );
1112 if( p_sys->p_es_sub &&
1113 p_sys->p_es_sub->fmt.i_priority >= es->fmt.i_priority )
1115 int idx2 = LanguageArrayIndex( p_sys->ppsz_sub_language,
1116 p_sys->p_es_sub->psz_language_code );
1118 msg_Dbg( p_sys->p_input, "idx1=%d(%s) idx2=%d(%s)",
1119 idx1, es->psz_language_code, idx2,
1120 p_sys->p_es_sub->psz_language_code );
1122 if( idx1 < 0 || ( idx2 >= 0 && idx2 <= idx1 ) )
1124 /* We found a SPU that matches our language request */
1125 i_wanted = es->i_channel;
1127 else if( idx1 >= 0 )
1129 msg_Dbg( p_sys->p_input, "idx1=%d(%s)",
1130 idx1, es->psz_language_code );
1132 i_wanted = es->i_channel;
1134 else if( p_sys->i_default_sub_id >= 0 )
1136 if( es->i_id == p_sys->i_default_sub_id )
1137 i_wanted = es->i_channel;
1140 if( p_sys->i_sub_last >= 0 )
1141 i_wanted = p_sys->i_sub_last;
1143 if( p_sys->i_sub_id >= 0 )
1145 if( es->i_id == p_sys->i_sub_id )
1146 i_wanted = es->i_channel;
1151 else if( i_cat == VIDEO_ES )
1153 i_wanted = es->i_channel;
1156 if( i_wanted == es->i_channel && es->p_dec == NULL )
1157 EsSelect( out, es );
1160 /* FIXME TODO handle priority here */
1163 if( i_cat == AUDIO_ES )
1165 if( p_sys->i_mode == ES_OUT_MODE_AUTO &&
1166 p_sys->p_es_audio &&
1167 p_sys->p_es_audio != es &&
1168 p_sys->p_es_audio->p_dec )
1170 EsUnselect( out, p_sys->p_es_audio, VLC_FALSE );
1172 p_sys->p_es_audio = es;
1174 else if( i_cat == SPU_ES )
1176 if( p_sys->i_mode == ES_OUT_MODE_AUTO &&
1178 p_sys->p_es_sub != es &&
1179 p_sys->p_es_sub->p_dec )
1181 EsUnselect( out, p_sys->p_es_sub, VLC_FALSE );
1183 p_sys->p_es_sub = es;
1185 else if( i_cat == VIDEO_ES )
1187 p_sys->p_es_video = es;
1193 * Send a block for the given es_out
1195 * \param out the es_out to send from
1196 * \param es the es_out_id
1197 * \param p_block the data block to send
1199 static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
1201 es_out_sys_t *p_sys = out->p_sys;
1202 input_thread_t *p_input = p_sys->p_input;
1203 es_out_pgrm_t *p_pgrm = es->p_pgrm;
1207 if( es->fmt.i_cat == AUDIO_ES )
1208 i_delay = p_sys->i_audio_delay;
1209 else if( es->fmt.i_cat == SPU_ES )
1210 i_delay = p_sys->i_spu_delay;
1214 if( p_input->p_libvlc->b_stats )
1216 vlc_mutex_lock( &p_input->p->counters.counters_lock );
1217 stats_UpdateInteger( p_input, p_input->p->counters.p_demux_read,
1218 p_block->i_buffer, &i_total );
1219 stats_UpdateFloat( p_input , p_input->p->counters.p_demux_bitrate,
1220 (float)i_total, NULL );
1221 vlc_mutex_unlock( &p_input->p->counters.counters_lock );
1224 /* Mark preroll blocks */
1225 if( es->i_preroll_end >= 0 )
1227 int64_t i_date = p_block->i_pts;
1229 i_date = p_block->i_dts;
1231 if( i_date < es->i_preroll_end )
1232 p_block->i_flags |= BLOCK_FLAG_PREROLL;
1234 es->i_preroll_end = -1;
1237 if( p_block->i_dts > 0 && (p_block->i_flags&BLOCK_FLAG_PREROLL) )
1239 p_block->i_dts += i_delay;
1241 else if( p_block->i_dts > 0 )
1244 input_ClockGetTS( p_input, &p_pgrm->clock, p_block->i_dts ) + i_delay;
1246 if( p_block->i_pts > 0 && (p_block->i_flags&BLOCK_FLAG_PREROLL) )
1248 p_block->i_pts += i_delay;
1250 else if( p_block->i_pts > 0 )
1253 input_ClockGetTS( p_input, &p_pgrm->clock, p_block->i_pts ) + i_delay;
1255 if ( es->fmt.i_codec == VLC_FOURCC( 't', 'e', 'l', 'x' ) )
1257 mtime_t current_date = mdate();
1259 || p_block->i_pts > current_date + 10000000
1260 || current_date > p_block->i_pts )
1262 /* ETSI EN 300 472 Annex A : do not take into account the PTS
1263 * for teletext streams. */
1264 p_block->i_pts = current_date + 400000
1265 + p_input->i_pts_delay + i_delay;
1269 p_block->i_rate = p_input->p->i_rate;
1271 /* TODO handle mute */
1273 ( es->fmt.i_cat != AUDIO_ES ||
1274 ( p_input->p->i_rate >= INPUT_RATE_DEFAULT/AOUT_MAX_INPUT_RATE &&
1275 p_input->p->i_rate <= INPUT_RATE_DEFAULT*AOUT_MAX_INPUT_RATE ) ) )
1277 input_DecoderDecode( es->p_dec, p_block );
1281 block_Release( p_block );
1287 /*****************************************************************************
1289 *****************************************************************************/
1290 static void EsOutDel( es_out_t *out, es_out_id_t *es )
1292 es_out_sys_t *p_sys = out->p_sys;
1293 vlc_bool_t b_reselect = VLC_FALSE;
1296 /* We don't try to reselect */
1299 while( !out->p_sys->p_input->b_die && es->p_dec )
1301 if( input_DecoderEmpty( es->p_dec ) )
1305 EsUnselect( out, es, es->p_pgrm == p_sys->p_pgrm );
1308 if( es->p_pgrm == p_sys->p_pgrm )
1309 EsOutESVarUpdate( out, es, VLC_TRUE );
1311 TAB_REMOVE( p_sys->i_es, p_sys->es, es );
1314 if( es->p_pgrm->i_es == 0 )
1316 msg_Dbg( p_sys->p_input, "Program doesn't contain anymore ES" );
1319 if( p_sys->p_es_audio == es || p_sys->p_es_video == es ||
1320 p_sys->p_es_sub == es ) b_reselect = VLC_TRUE;
1322 if( p_sys->p_es_audio == es ) p_sys->p_es_audio = NULL;
1323 if( p_sys->p_es_video == es ) p_sys->p_es_video = NULL;
1324 if( p_sys->p_es_sub == es ) p_sys->p_es_sub = NULL;
1326 switch( es->fmt.i_cat )
1339 /* Re-select another track when needed */
1341 for( i = 0; i < p_sys->i_es; i++ )
1343 if( es->fmt.i_cat == p_sys->es[i]->fmt.i_cat )
1344 EsOutSelect( out, p_sys->es[i], VLC_FALSE );
1347 if( es->psz_language )
1348 free( es->psz_language );
1349 if( es->psz_language_code )
1350 free( es->psz_language_code );
1352 es_format_Clean( &es->fmt );
1358 * Control query handler
1360 * \param out the es_out to control
1361 * \param i_query A es_out query as defined in include/ninput.h
1362 * \param args a variable list of arguments for the query
1363 * \return VLC_SUCCESS or an error code
1365 static int EsOutControl( es_out_t *out, int i_query, va_list args )
1367 es_out_sys_t *p_sys = out->p_sys;
1375 case ES_OUT_SET_ES_STATE:
1376 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
1377 b = (vlc_bool_t) va_arg( args, vlc_bool_t );
1378 if( b && es->p_dec == NULL )
1380 EsSelect( out, es );
1381 return es->p_dec ? VLC_SUCCESS : VLC_EGENERIC;
1383 else if( !b && es->p_dec )
1385 EsUnselect( out, es, es->p_pgrm == p_sys->p_pgrm );
1390 case ES_OUT_GET_ES_STATE:
1391 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
1392 pb = (vlc_bool_t*) va_arg( args, vlc_bool_t * );
1394 *pb = es->p_dec ? VLC_TRUE : VLC_FALSE;
1397 case ES_OUT_SET_ACTIVE:
1399 b = (vlc_bool_t) va_arg( args, vlc_bool_t );
1400 p_sys->b_active = b;
1403 var_SetBool( p_sys->p_input, "intf-change", VLC_TRUE );
1407 case ES_OUT_GET_ACTIVE:
1408 pb = (vlc_bool_t*) va_arg( args, vlc_bool_t * );
1409 *pb = p_sys->b_active;
1412 case ES_OUT_SET_MODE:
1413 i = (int) va_arg( args, int );
1414 if( i == ES_OUT_MODE_NONE || i == ES_OUT_MODE_ALL ||
1415 i == ES_OUT_MODE_AUTO || i == ES_OUT_MODE_PARTIAL )
1419 /* Reapply policy mode */
1420 for( i = 0; i < p_sys->i_es; i++ )
1422 if( p_sys->es[i]->p_dec )
1424 EsUnselect( out, p_sys->es[i],
1425 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
1428 for( i = 0; i < p_sys->i_es; i++ )
1430 EsOutSelect( out, p_sys->es[i], VLC_FALSE );
1434 return VLC_EGENERIC;
1436 case ES_OUT_GET_MODE:
1437 pi = (int*) va_arg( args, int* );
1438 *pi = p_sys->i_mode;
1442 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
1443 /* Special case NULL, NULL+i_cat */
1446 for( i = 0; i < p_sys->i_es; i++ )
1448 if( p_sys->es[i]->p_dec )
1449 EsUnselect( out, p_sys->es[i],
1450 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
1453 else if( es == (es_out_id_t*)((uint8_t*)NULL+AUDIO_ES) )
1455 for( i = 0; i < p_sys->i_es; i++ )
1457 if( p_sys->es[i]->p_dec &&
1458 p_sys->es[i]->fmt.i_cat == AUDIO_ES )
1459 EsUnselect( out, p_sys->es[i],
1460 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
1463 else if( es == (es_out_id_t*)((uint8_t*)NULL+VIDEO_ES) )
1465 for( i = 0; i < p_sys->i_es; i++ )
1467 if( p_sys->es[i]->p_dec &&
1468 p_sys->es[i]->fmt.i_cat == VIDEO_ES )
1469 EsUnselect( out, p_sys->es[i],
1470 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
1473 else if( es == (es_out_id_t*)((uint8_t*)NULL+SPU_ES) )
1475 for( i = 0; i < p_sys->i_es; i++ )
1477 if( p_sys->es[i]->p_dec &&
1478 p_sys->es[i]->fmt.i_cat == SPU_ES )
1479 EsUnselect( out, p_sys->es[i],
1480 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
1485 for( i = 0; i < p_sys->i_es; i++ )
1487 if( es == p_sys->es[i] )
1489 EsOutSelect( out, es, VLC_TRUE );
1495 playlist_t * p_playlist = pl_Yield( p_sys->p_input );
1497 p_playlist->gc_date = mdate();
1498 vlc_cond_signal( &p_playlist->object_wait );
1500 pl_Release( p_playlist );
1504 case ES_OUT_SET_DEFAULT:
1506 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
1510 /*p_sys->i_default_video_id = -1;*/
1511 /*p_sys->i_default_audio_id = -1;*/
1512 p_sys->i_default_sub_id = -1;
1514 else if( es == (es_out_id_t*)((uint8_t*)NULL+AUDIO_ES) )
1516 /*p_sys->i_default_video_id = -1;*/
1518 else if( es == (es_out_id_t*)((uint8_t*)NULL+VIDEO_ES) )
1520 /*p_sys->i_default_audio_id = -1;*/
1522 else if( es == (es_out_id_t*)((uint8_t*)NULL+SPU_ES) )
1524 p_sys->i_default_sub_id = -1;
1528 /*if( es->fmt.i_cat == VIDEO_ES )
1529 p_sys->i_default_video_id = es->i_id;
1531 if( es->fmt.i_cat == AUDIO_ES )
1532 p_sys->i_default_audio_id = es->i_id;
1534 if( es->fmt.i_cat == SPU_ES )
1535 p_sys->i_default_sub_id = es->i_id;
1540 case ES_OUT_SET_PCR:
1541 case ES_OUT_SET_GROUP_PCR:
1543 es_out_pgrm_t *p_pgrm = NULL;
1547 if( i_query == ES_OUT_SET_PCR )
1549 p_pgrm = p_sys->p_pgrm;
1554 i_group = (int)va_arg( args, int );
1555 for( i = 0; i < p_sys->i_pgrm; i++ )
1557 if( p_sys->pgrm[i]->i_id == i_group )
1559 p_pgrm = p_sys->pgrm[i];
1564 if( p_pgrm == NULL )
1565 p_pgrm = EsOutProgramAdd( out, i_group ); /* Create it */
1567 i_pcr = (int64_t)va_arg( args, int64_t );
1568 /* search program */
1569 input_ClockSetPCR( p_sys->p_input, &p_pgrm->clock, i_pcr );
1573 case ES_OUT_RESET_PCR:
1574 for( i = 0; i < p_sys->i_pgrm; i++ )
1576 p_sys->pgrm[i]->clock.i_synchro_state = SYNCHRO_REINIT;
1577 p_sys->pgrm[i]->clock.last_pts = 0;
1584 int64_t i_ts = (int64_t)va_arg( args, int64_t );
1585 int64_t *pi_ts = (int64_t *)va_arg( args, int64_t * );
1586 *pi_ts = input_ClockGetTS( p_sys->p_input,
1587 &p_sys->p_pgrm->clock, i_ts );
1590 return VLC_EGENERIC;
1592 case ES_OUT_GET_GROUP:
1593 pi = (int*) va_arg( args, int* );
1595 *pi = p_sys->p_pgrm->i_id;
1597 *pi = -1; /* FIXME */
1600 case ES_OUT_SET_GROUP:
1603 i = (int) va_arg( args, int );
1604 for( j = 0; j < p_sys->i_pgrm; j++ )
1606 es_out_pgrm_t *p_pgrm = p_sys->pgrm[j];
1607 if( p_pgrm->i_id == i )
1609 EsOutProgramSelect( out, p_pgrm );
1613 return VLC_EGENERIC;
1616 case ES_OUT_SET_FMT:
1618 /* This ain't pretty but is need by some demuxers (eg. Ogg )
1619 * to update the p_extra data */
1621 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
1622 p_fmt = (es_format_t*) va_arg( args, es_format_t * );
1623 if( es == NULL ) return VLC_EGENERIC;
1625 if( p_fmt->i_extra )
1627 es->fmt.i_extra = p_fmt->i_extra;
1628 es->fmt.p_extra = realloc( es->fmt.p_extra, p_fmt->i_extra );
1629 memcpy( es->fmt.p_extra, p_fmt->p_extra, p_fmt->i_extra );
1631 if( !es->p_dec ) return VLC_SUCCESS;
1634 input_DecoderDelete( es->p_dec );
1635 es->p_dec = input_DecoderNew( p_sys->p_input,
1636 &es->fmt, VLC_FALSE );
1639 es->p_dec->fmt_in.i_extra = p_fmt->i_extra;
1640 es->p_dec->fmt_in.p_extra =
1641 realloc( es->p_dec->fmt_in.p_extra, p_fmt->i_extra );
1642 memcpy( es->p_dec->fmt_in.p_extra,
1643 p_fmt->p_extra, p_fmt->i_extra );
1650 case ES_OUT_SET_NEXT_DISPLAY_TIME:
1654 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
1655 i_date = (int64_t)va_arg( args, int64_t );
1657 if( !es || !es->p_dec )
1658 return VLC_EGENERIC;
1660 /* XXX We should call input_ClockGetTS but PCR has been reseted
1661 * and it will return 0, so we won't call input_ClockGetTS on all preroll samples
1662 * but that's ugly(more time discontinuity), it need to be improved -- fenrir */
1663 es->i_preroll_end = i_date;
1667 case ES_OUT_SET_GROUP_META:
1669 int i_group = (int)va_arg( args, int );
1670 vlc_meta_t *p_meta = (vlc_meta_t*)va_arg( args, vlc_meta_t * );
1672 EsOutProgramMeta( out, i_group, p_meta );
1675 case ES_OUT_SET_GROUP_EPG:
1677 int i_group = (int)va_arg( args, int );
1678 vlc_epg_t *p_epg = (vlc_epg_t*)va_arg( args, vlc_epg_t * );
1680 EsOutProgramEpg( out, i_group, p_epg );
1683 case ES_OUT_DEL_GROUP:
1685 int i_group = (int)va_arg( args, int );
1687 return EsOutProgramDel( out, i_group );
1691 msg_Err( p_sys->p_input, "unknown query in es_out_Control" );
1692 return VLC_EGENERIC;
1696 /****************************************************************************
1697 * LanguageGetName: try to expend iso639 into plain name
1698 ****************************************************************************/
1699 static char *LanguageGetName( const char *psz_code )
1701 const iso639_lang_t *pl;
1703 if( psz_code == NULL )
1705 return strdup( "" );
1708 if( strlen( psz_code ) == 2 )
1710 pl = GetLang_1( psz_code );
1712 else if( strlen( psz_code ) == 3 )
1714 pl = GetLang_2B( psz_code );
1715 if( !strcmp( pl->psz_iso639_1, "??" ) )
1717 pl = GetLang_2T( psz_code );
1722 return strdup( psz_code );
1725 if( !strcmp( pl->psz_iso639_1, "??" ) )
1727 return strdup( psz_code );
1731 if( *pl->psz_native_name )
1733 return strdup( pl->psz_native_name );
1735 return strdup( pl->psz_eng_name );
1739 /* Get a 2 char code */
1740 static char *LanguageGetCode( const char *psz_lang )
1742 const iso639_lang_t *pl;
1744 if( psz_lang == NULL || *psz_lang == '\0' )
1745 return strdup("??");
1747 for( pl = p_languages; pl->psz_iso639_1 != NULL; pl++ )
1749 if( !strcasecmp( pl->psz_eng_name, psz_lang ) ||
1750 !strcasecmp( pl->psz_native_name, psz_lang ) ||
1751 !strcasecmp( pl->psz_iso639_1, psz_lang ) ||
1752 !strcasecmp( pl->psz_iso639_2T, psz_lang ) ||
1753 !strcasecmp( pl->psz_iso639_2B, psz_lang ) )
1757 if( pl->psz_iso639_1 != NULL )
1758 return strdup( pl->psz_iso639_1 );
1760 return strdup("??");
1763 static char **LanguageSplit( const char *psz_langs )
1770 if( psz_langs == NULL ) return NULL;
1772 psz_parser = psz_dup = strdup(psz_langs);
1774 while( psz_parser && *psz_parser )
1779 psz = strchr(psz_parser, ',' );
1780 if( psz ) *psz++ = '\0';
1782 psz_code = LanguageGetCode( psz_parser );
1783 if( strcmp( psz_code, "??" ) )
1785 TAB_APPEND( i_psz, ppsz, psz_code );
1793 TAB_APPEND( i_psz, ppsz, NULL );
1800 static int LanguageArrayIndex( char **ppsz_langs, char *psz_lang )
1804 if( !ppsz_langs || !psz_lang ) return -1;
1806 for( i = 0; ppsz_langs[i]; i++ )
1807 if( !strcasecmp( ppsz_langs[i], psz_lang ) ) return i;
1812 /****************************************************************************
1814 * - add meta info to the playlist item
1815 ****************************************************************************/
1816 static void EsOutAddInfo( es_out_t *out, es_out_id_t *es )
1818 es_out_sys_t *p_sys = out->p_sys;
1819 input_thread_t *p_input = p_sys->p_input;
1820 es_format_t *fmt = &es->fmt;
1824 /* Add stream info */
1825 asprintf( &psz_cat, _("Stream %d"), out->p_sys->i_id - 1 );
1827 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Codec"),
1828 "%.4s", (char*)&fmt->i_codec );
1830 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Language"),
1831 "%s", es->psz_language );
1833 /* Add information */
1834 switch( fmt->i_cat )
1837 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1838 _("Type"), _("Audio") );
1840 if( fmt->audio.i_channels > 0 )
1841 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Channels"),
1842 "%u", fmt->audio.i_channels );
1844 if( fmt->audio.i_rate > 0 )
1846 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Sample rate"),
1847 _("%u Hz"), fmt->audio.i_rate );
1848 var_SetInteger( p_input, "sample-rate", fmt->audio.i_rate );
1851 if( fmt->audio.i_bitspersample > 0 )
1852 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1853 _("Bits per sample"), "%u",
1854 fmt->audio.i_bitspersample );
1856 if( fmt->i_bitrate > 0 )
1858 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Bitrate"),
1859 _("%u kb/s"), fmt->i_bitrate / 1000 );
1860 var_SetInteger( p_input, "bit-rate", fmt->i_bitrate );
1865 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1866 _("Type"), _("Video") );
1868 if( fmt->video.i_width > 0 && fmt->video.i_height > 0 )
1869 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1870 _("Resolution"), "%ux%u",
1871 fmt->video.i_width, fmt->video.i_height );
1873 if( fmt->video.i_visible_width > 0 &&
1874 fmt->video.i_visible_height > 0 )
1875 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1876 _("Display resolution"), "%ux%u",
1877 fmt->video.i_visible_width,
1878 fmt->video.i_visible_height);
1879 if( fmt->video.i_frame_rate > 0 &&
1880 fmt->video.i_frame_rate_base > 0 )
1882 div = lldiv( (float)fmt->video.i_frame_rate /
1883 fmt->video.i_frame_rate_base * 1000000,
1885 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1886 _("Frame rate"), I64Fd".%06u",
1887 div.quot, (unsigned int )div.rem );
1892 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1893 _("Type"), _("Subtitle") );