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 *****************************************************************************/
34 #include <vlc_common.h>
36 #include <vlc_input.h>
37 #include <vlc_es_out.h>
38 #include <vlc_block.h>
41 #include "input_internal.h"
47 #include "../stream_output/stream_output.h"
49 #include <vlc_iso_lang.h>
50 /* FIXME we should find a better way than including that */
51 #include "../text/iso-639_def.h"
53 /*****************************************************************************
55 *****************************************************************************/
61 /* Number of es for this pgrm */
66 /* Clock for this program */
67 input_clock_t *p_clock;
70 char *psz_now_playing;
80 es_out_pgrm_t *p_pgrm;
82 /* Channel in the track type */
86 char *psz_language_code;
89 decoder_t *p_dec_record;
91 /* Fields for Video with CC */
92 bool pb_cc_present[4];
93 es_out_id_t *pp_cc_es[4];
95 /* Field for CC track from a master video */
96 es_out_id_t *p_master;
98 /* ID for the meta data */
104 input_thread_t *p_input;
111 es_out_pgrm_t **pgrm;
112 es_out_pgrm_t **pp_selected_pgrm; /* --programs */
113 es_out_pgrm_t *p_pgrm; /* Master program */
130 int i_audio_last, i_audio_id;
131 int i_sub_last, i_sub_id;
132 int i_default_sub_id; /* As specified in container; if applicable */
133 char **ppsz_audio_language;
134 char **ppsz_sub_language;
136 /* current main es */
137 es_out_id_t *p_es_audio;
138 es_out_id_t *p_es_video;
139 es_out_id_t *p_es_sub;
142 int64_t i_audio_delay;
145 /* Rate used for clock */
150 mtime_t i_pause_date;
152 /* Current preroll */
153 mtime_t i_preroll_end;
155 /* Used for buffering */
157 mtime_t i_buffering_extra_initial;
158 mtime_t i_buffering_extra_stream;
159 mtime_t i_buffering_extra_system;
162 sout_instance_t *p_sout_record;
165 static es_out_id_t *EsOutAdd ( es_out_t *, const es_format_t * );
166 static int EsOutSend ( es_out_t *, es_out_id_t *, block_t * );
167 static void EsOutDel ( es_out_t *, es_out_id_t * );
168 static int EsOutControl( es_out_t *, int i_query, va_list );
169 static void EsOutDelete ( es_out_t * );
171 static void EsOutSelect( es_out_t *, es_out_id_t *es, bool b_force );
172 static void EsOutUpdateInfo( es_out_t *, es_out_id_t *es, const es_format_t *, const vlc_meta_t * );
173 static int EsOutSetRecord( es_out_t *, bool b_record );
175 static bool EsIsSelected( es_out_id_t *es );
176 static void EsSelect( es_out_t *out, es_out_id_t *es );
177 static void EsUnselect( es_out_t *out, es_out_id_t *es, bool b_update );
178 static void EsOutDecoderChangeDelay( es_out_t *out, es_out_id_t *p_es );
179 static void EsOutDecodersChangePause( es_out_t *out, bool b_paused, mtime_t i_date );
180 static void EsOutProgramChangePause( es_out_t *out, bool b_paused, mtime_t i_date );
181 static void EsOutProgramsChangeRate( es_out_t *out );
182 static void EsOutDecodersStopBuffering( es_out_t *out, bool b_forced );
183 static char *LanguageGetName( const char *psz_code );
184 static char *LanguageGetCode( const char *psz_lang );
185 static char **LanguageSplit( const char *psz_langs );
186 static int LanguageArrayIndex( char **ppsz_langs, char *psz_lang );
188 static char *EsOutProgramGetMetaName( es_out_pgrm_t *p_pgrm );
190 static const vlc_fourcc_t EsOutFourccClosedCaptions[4] = {
191 VLC_FOURCC('c', 'c', '1', ' '),
192 VLC_FOURCC('c', 'c', '2', ' '),
193 VLC_FOURCC('c', 'c', '3', ' '),
194 VLC_FOURCC('c', 'c', '4', ' '),
196 static inline int EsOutGetClosedCaptionsChannel( vlc_fourcc_t fcc )
199 for( i = 0; i < 4; i++ )
201 if( fcc == EsOutFourccClosedCaptions[i] )
208 /*****************************************************************************
210 *****************************************************************************/
211 es_out_t *input_EsOutNew( input_thread_t *p_input, int i_rate )
216 es_out_t *out = malloc( sizeof( *out ) );
220 es_out_sys_t *p_sys = malloc( sizeof( *p_sys ) );
227 out->pf_add = EsOutAdd;
228 out->pf_send = EsOutSend;
229 out->pf_del = EsOutDel;
230 out->pf_control = EsOutControl;
231 out->pf_destroy = EsOutDelete;
233 out->b_sout = p_input->p->p_sout != NULL;
236 vlc_mutex_init_recursive( &p_sys->lock );
237 p_sys->p_input = p_input;
239 p_sys->b_active = false;
240 p_sys->i_mode = ES_OUT_MODE_AUTO;
243 TAB_INIT( p_sys->i_pgrm, p_sys->pgrm );
244 p_sys->p_pgrm = NULL;
248 TAB_INIT( p_sys->i_es, p_sys->es );
255 var_Get( p_input, "audio-track", &val );
256 p_sys->i_audio_last = val.i_int;
258 var_Get( p_input, "sub-track", &val );
259 p_sys->i_sub_last = val.i_int;
261 p_sys->i_default_sub_id = -1;
263 if( !p_input->b_preparsing )
265 var_Get( p_input, "audio-language", &val );
266 p_sys->ppsz_audio_language = LanguageSplit(val.psz_string);
267 if( p_sys->ppsz_audio_language )
269 for( i = 0; p_sys->ppsz_audio_language[i]; i++ )
270 msg_Dbg( p_input, "selected audio language[%d] %s",
271 i, p_sys->ppsz_audio_language[i] );
273 free( val.psz_string );
275 var_Get( p_input, "sub-language", &val );
276 p_sys->ppsz_sub_language = LanguageSplit(val.psz_string);
277 if( p_sys->ppsz_sub_language )
279 for( i = 0; p_sys->ppsz_sub_language[i]; i++ )
280 msg_Dbg( p_input, "selected subtitle language[%d] %s",
281 i, p_sys->ppsz_sub_language[i] );
283 free( val.psz_string );
287 p_sys->ppsz_sub_language = NULL;
288 p_sys->ppsz_audio_language = NULL;
291 var_Get( p_input, "audio-track-id", &val );
292 p_sys->i_audio_id = val.i_int;
294 var_Get( p_input, "sub-track-id", &val );
295 p_sys->i_sub_id = val.i_int;
297 p_sys->p_es_audio = NULL;
298 p_sys->p_es_video = NULL;
299 p_sys->p_es_sub = NULL;
301 p_sys->i_audio_delay= 0;
302 p_sys->i_spu_delay = 0;
304 p_sys->b_paused = false;
305 p_sys->i_pause_date = -1;
307 p_sys->i_rate = i_rate;
309 p_sys->b_buffering = true;
310 p_sys->i_buffering_extra_initial = 0;
311 p_sys->i_buffering_extra_stream = 0;
312 p_sys->i_buffering_extra_system = 0;
313 p_sys->i_preroll_end = -1;
315 p_sys->p_sout_record = NULL;
320 /*****************************************************************************
322 *****************************************************************************/
323 static void EsOutDelete( es_out_t *out )
325 es_out_sys_t *p_sys = out->p_sys;
328 if( p_sys->p_sout_record )
329 EsOutSetRecord( out, false );
331 for( i = 0; i < p_sys->i_es; i++ )
333 if( p_sys->es[i]->p_dec )
334 input_DecoderDelete( p_sys->es[i]->p_dec );
336 free( p_sys->es[i]->psz_language );
337 free( p_sys->es[i]->psz_language_code );
338 es_format_Clean( &p_sys->es[i]->fmt );
340 free( p_sys->es[i] );
342 if( p_sys->ppsz_audio_language )
344 for( i = 0; p_sys->ppsz_audio_language[i]; i++ )
345 free( p_sys->ppsz_audio_language[i] );
346 free( p_sys->ppsz_audio_language );
348 if( p_sys->ppsz_sub_language )
350 for( i = 0; p_sys->ppsz_sub_language[i]; i++ )
351 free( p_sys->ppsz_sub_language[i] );
352 free( p_sys->ppsz_sub_language );
356 /* FIXME duplicate work EsOutProgramDel (but we cannot use it) add a EsOutProgramClean ? */
357 for( i = 0; i < p_sys->i_pgrm; i++ )
359 es_out_pgrm_t *p_pgrm = p_sys->pgrm[i];
360 input_clock_Delete( p_pgrm->p_clock );
361 free( p_pgrm->psz_now_playing );
362 free( p_pgrm->psz_publisher );
363 free( p_pgrm->psz_name );
365 vlc_epg_Delete( p_pgrm->p_epg );
369 TAB_CLEAN( p_sys->i_pgrm, p_sys->pgrm );
370 vlc_mutex_destroy( &p_sys->lock );
376 static mtime_t EsOutGetWakeup( es_out_t *out )
378 es_out_sys_t *p_sys = out->p_sys;
379 input_thread_t *p_input = p_sys->p_input;
384 /* We do not have a wake up date if the input cannot have its speed
385 * controlled or sout is imposing its own or while buffering
387 * FIXME for !p_input->b_can_pace_control a wkeup time is still needed to avoid too strong buffering */
388 if( !p_input->b_can_pace_control ||
389 p_input->p->b_out_pace_control ||
393 return input_clock_GetWakeup( p_sys->p_pgrm->p_clock );
396 static es_out_id_t *EsOutGetFromID( es_out_t *out, int i_id )
401 /* Special HACK, -i_id is the cat of the stream */
402 return (es_out_id_t*)((uint8_t*)NULL-i_id);
405 for( i = 0; i < out->p_sys->i_es; i++ )
407 if( out->p_sys->es[i]->i_id == i_id )
408 return out->p_sys->es[i];
413 static bool EsOutDecodersIsEmpty( es_out_t *out )
415 es_out_sys_t *p_sys = out->p_sys;
418 if( p_sys->b_buffering && p_sys->p_pgrm )
420 EsOutDecodersStopBuffering( out, true );
421 if( p_sys->b_buffering )
425 for( i = 0; i < p_sys->i_es; i++ )
427 es_out_id_t *es = p_sys->es[i];
429 if( es->p_dec && !input_DecoderIsEmpty( es->p_dec ) )
431 if( es->p_dec_record && !input_DecoderIsEmpty( es->p_dec_record ) )
437 static void EsOutSetDelay( es_out_t *out, int i_cat, int64_t i_delay )
439 es_out_sys_t *p_sys = out->p_sys;
441 if( i_cat == AUDIO_ES )
442 p_sys->i_audio_delay = i_delay;
443 else if( i_cat == SPU_ES )
444 p_sys->i_spu_delay = i_delay;
446 for( int i = 0; i < p_sys->i_es; i++ )
447 EsOutDecoderChangeDelay( out, p_sys->es[i] );
450 static int EsOutSetRecord( es_out_t *out, bool b_record )
452 es_out_sys_t *p_sys = out->p_sys;
453 input_thread_t *p_input = p_sys->p_input;
455 assert( ( b_record && !p_sys->p_sout_record ) || ( !b_record && p_sys->p_sout_record ) );
459 char *psz_path = var_CreateGetString( p_input, "input-record-path" );
460 if( !psz_path || *psz_path == '\0' )
463 psz_path = strdup( config_GetHomeDir() );
466 char *psz_sout = NULL; // TODO conf
468 if( !psz_sout && psz_path )
470 char *psz_file = input_CreateFilename( VLC_OBJECT(p_input), psz_path, INPUT_RECORD_PREFIX, NULL );
473 if( asprintf( &psz_sout, "#record{dst-prefix='%s'}", psz_file ) < 0 )
484 p_sys->p_sout_record = sout_NewInstance( p_input, psz_sout );
488 if( !p_sys->p_sout_record )
491 for( int i = 0; i < p_sys->i_es; i++ )
493 es_out_id_t *p_es = p_sys->es[i];
495 if( !p_es->p_dec || p_es->p_master )
498 p_es->p_dec_record = input_DecoderNew( p_input, &p_es->fmt, p_es->p_pgrm->p_clock, p_sys->p_sout_record );
499 if( p_es->p_dec_record && p_sys->b_buffering )
500 input_DecoderStartBuffering( p_es->p_dec_record );
505 for( int i = 0; i < p_sys->i_es; i++ )
507 es_out_id_t *p_es = p_sys->es[i];
509 if( !p_es->p_dec_record )
512 input_DecoderDelete( p_es->p_dec_record );
513 p_es->p_dec_record = NULL;
516 sout_DeleteInstance( p_sys->p_sout_record );
518 p_sys->p_sout_record = NULL;
523 static void EsOutChangePause( es_out_t *out, bool b_paused, mtime_t i_date )
525 es_out_sys_t *p_sys = out->p_sys;
527 /* XXX the order is important */
530 EsOutDecodersChangePause( out, true, i_date );
531 EsOutProgramChangePause( out, true, i_date );
535 if( p_sys->i_buffering_extra_initial > 0 )
537 mtime_t i_stream_start;
538 mtime_t i_system_start;
539 mtime_t i_stream_duration;
540 mtime_t i_system_duration;
542 i_ret = input_clock_GetState( p_sys->p_pgrm->p_clock,
543 &i_stream_start, &i_system_start,
544 &i_stream_duration, &i_system_duration );
547 /* FIXME pcr != exactly what wanted */
548 const mtime_t i_used = /*(i_stream_duration - p_sys->p_input->i_pts_delay)*/ p_sys->i_buffering_extra_system - p_sys->i_buffering_extra_initial;
551 p_sys->i_buffering_extra_initial = 0;
552 p_sys->i_buffering_extra_stream = 0;
553 p_sys->i_buffering_extra_system = 0;
555 EsOutProgramChangePause( out, false, i_date );
556 EsOutDecodersChangePause( out, false, i_date );
558 EsOutProgramsChangeRate( out );
560 p_sys->b_paused = b_paused;
561 p_sys->i_pause_date = i_date;
564 static void EsOutChangeRate( es_out_t *out, int i_rate )
566 es_out_sys_t *p_sys = out->p_sys;
568 p_sys->i_rate = i_rate;
570 if( !p_sys->b_paused )
571 EsOutProgramsChangeRate( out );
574 static void EsOutChangePosition( es_out_t *out )
576 es_out_sys_t *p_sys = out->p_sys;
578 input_SendEventCache( p_sys->p_input, 0.0 );
580 for( int i = 0; i < p_sys->i_es; i++ )
582 es_out_id_t *p_es = p_sys->es[i];
587 input_DecoderStartBuffering( p_es->p_dec );
589 if( p_es->p_dec_record )
590 input_DecoderStartBuffering( p_es->p_dec );
593 for( int i = 0; i < p_sys->i_pgrm; i++ )
594 input_clock_Reset( p_sys->pgrm[i]->p_clock );
596 p_sys->b_buffering = true;
597 p_sys->i_buffering_extra_initial = 0;
598 p_sys->i_buffering_extra_stream = 0;
599 p_sys->i_buffering_extra_system = 0;
600 p_sys->i_preroll_end = -1;
605 static void EsOutDecodersStopBuffering( es_out_t *out, bool b_forced )
607 es_out_sys_t *p_sys = out->p_sys;
610 mtime_t i_stream_start;
611 mtime_t i_system_start;
612 mtime_t i_stream_duration;
613 mtime_t i_system_duration;
614 i_ret = input_clock_GetState( p_sys->p_pgrm->p_clock,
615 &i_stream_start, &i_system_start,
616 &i_stream_duration, &i_system_duration );
617 assert( !i_ret || b_forced );
621 mtime_t i_preroll_duration = 0;
622 if( p_sys->i_preroll_end >= 0 )
623 i_preroll_duration = __MAX( p_sys->i_preroll_end - i_stream_start, 0 );
625 const mtime_t i_buffering_duration = p_sys->p_input->i_pts_delay +
627 p_sys->i_buffering_extra_stream - p_sys->i_buffering_extra_initial;
629 if( i_stream_duration <= i_buffering_duration && !b_forced )
631 const double f_level = (double)i_stream_duration / i_buffering_duration;
632 input_SendEventCache( p_sys->p_input, f_level );
634 msg_Dbg( p_sys->p_input, "Buffering %d%%", (int)(100 * f_level) );
637 input_SendEventCache( p_sys->p_input, 1.0 );
639 msg_Dbg( p_sys->p_input, "Stream buffering done (%d ms in %d ms)",
640 (int)(i_stream_duration/1000), (int)(i_system_duration/1000) );
641 p_sys->b_buffering = false;
642 p_sys->i_preroll_end = -1;
644 if( p_sys->i_buffering_extra_initial > 0 )
650 const mtime_t i_decoder_buffering_start = mdate();
651 for( int i = 0; i < p_sys->i_es; i++ )
653 es_out_id_t *p_es = p_sys->es[i];
657 input_DecoderWaitBuffering( p_es->p_dec );
658 if( p_es->p_dec_record )
659 input_DecoderWaitBuffering( p_es->p_dec_record );
662 msg_Dbg( p_sys->p_input, "Decoder buffering done in %d ms",
663 (int)(mdate() - i_decoder_buffering_start)/1000 );
665 const mtime_t i_wakeup_delay = 10*1000; /* FIXME CLEANUP thread wake up time*/
666 const mtime_t i_current_date = p_sys->b_paused ? p_sys->i_pause_date : mdate();
668 input_clock_ChangeSystemOrigin( p_sys->p_pgrm->p_clock, i_current_date + i_wakeup_delay - i_buffering_duration );
670 for( int i = 0; i < p_sys->i_es; i++ )
672 es_out_id_t *p_es = p_sys->es[i];
677 input_DecoderStopBuffering( p_es->p_dec );
678 if( p_es->p_dec_record )
679 input_DecoderStopBuffering( p_es->p_dec );
682 static void EsOutDecodersChangePause( es_out_t *out, bool b_paused, mtime_t i_date )
684 es_out_sys_t *p_sys = out->p_sys;
686 /* Pause decoders first */
687 for( int i = 0; i < p_sys->i_es; i++ )
689 es_out_id_t *es = p_sys->es[i];
693 input_DecoderChangePause( es->p_dec, b_paused, i_date );
694 if( es->p_dec_record )
695 input_DecoderChangePause( es->p_dec_record, b_paused, i_date );
699 static void EsOutProgramChangePause( es_out_t *out, bool b_paused, mtime_t i_date )
701 es_out_sys_t *p_sys = out->p_sys;
703 for( int i = 0; i < p_sys->i_pgrm; i++ )
704 input_clock_ChangePause( p_sys->pgrm[i]->p_clock, b_paused, i_date );
707 static void EsOutDecoderChangeDelay( es_out_t *out, es_out_id_t *p_es )
709 es_out_sys_t *p_sys = out->p_sys;
712 if( p_es->fmt.i_cat == AUDIO_ES )
713 i_delay = p_sys->i_audio_delay;
714 else if( p_es->fmt.i_cat == SPU_ES )
715 i_delay = p_sys->i_spu_delay;
720 input_DecoderChangeDelay( p_es->p_dec, i_delay );
721 if( p_es->p_dec_record )
722 input_DecoderChangeDelay( p_es->p_dec_record, i_delay );
725 static void EsOutProgramsChangeRate( es_out_t *out )
727 es_out_sys_t *p_sys = out->p_sys;
729 for( int i = 0; i < p_sys->i_pgrm; i++ )
730 input_clock_ChangeRate( p_sys->pgrm[i]->p_clock, p_sys->i_rate );
733 static void EsOutFrameNext( es_out_t *out )
735 es_out_sys_t *p_sys = out->p_sys;
736 es_out_id_t *p_es_video = NULL;
738 if( p_sys->b_buffering )
740 msg_Warn( p_sys->p_input, "buffering, ignoring 'frame next'" );
744 assert( p_sys->b_paused );
746 for( int i = 0; i < p_sys->i_es; i++ )
748 es_out_id_t *p_es = p_sys->es[i];
750 if( p_es->fmt.i_cat == VIDEO_ES && p_es->p_dec )
759 msg_Warn( p_sys->p_input, "No video track selected, ignoring 'frame next'" );
764 input_DecoderFrameNext( p_es_video->p_dec, &i_duration );
766 msg_Dbg( out->p_sys->p_input, "EsOutFrameNext consummed %d ms", (int)(i_duration/1000) );
768 if( i_duration <= 0 )
769 i_duration = 40*1000;
771 /* FIXME it is not a clean way ? */
772 if( p_sys->i_buffering_extra_initial <= 0 )
774 mtime_t i_stream_start;
775 mtime_t i_system_start;
776 mtime_t i_stream_duration;
777 mtime_t i_system_duration;
780 i_ret = input_clock_GetState( p_sys->p_pgrm->p_clock,
781 &i_stream_start, &i_system_start,
782 &i_stream_duration, &i_system_duration );
786 p_sys->i_buffering_extra_initial = 1 + i_stream_duration - p_sys->p_input->i_pts_delay; /* FIXME < 0 ? */
787 p_sys->i_buffering_extra_system =
788 p_sys->i_buffering_extra_stream = p_sys->i_buffering_extra_initial;
791 const int i_rate = input_clock_GetRate( p_sys->p_pgrm->p_clock );
793 p_sys->b_buffering = true;
794 p_sys->i_buffering_extra_system += i_duration;
795 p_sys->i_buffering_extra_stream = p_sys->i_buffering_extra_initial +
796 ( p_sys->i_buffering_extra_system - p_sys->i_buffering_extra_initial ) *
797 INPUT_RATE_DEFAULT / i_rate;
799 p_sys->i_preroll_end = -1;
801 static mtime_t EsOutGetBuffering( es_out_t *out )
803 es_out_sys_t *p_sys = out->p_sys;
809 mtime_t i_stream_start;
810 mtime_t i_system_start;
811 mtime_t i_stream_duration;
812 mtime_t i_system_duration;
813 i_ret = input_clock_GetState( p_sys->p_pgrm->p_clock,
814 &i_stream_start, &i_system_start,
815 &i_stream_duration, &i_system_duration );
822 if( p_sys->b_buffering && p_sys->i_buffering_extra_initial <= 0 )
824 i_delay = i_stream_duration;
828 mtime_t i_system_duration;
829 if( p_sys->b_paused )
831 i_system_duration = p_sys->i_pause_date - i_system_start;
832 if( p_sys->i_buffering_extra_initial > 0 )
833 i_system_duration += p_sys->i_buffering_extra_system - p_sys->i_buffering_extra_initial;
837 i_system_duration = mdate() - i_system_start;
840 const mtime_t i_consumed = i_system_duration * INPUT_RATE_DEFAULT / p_sys->i_rate - i_stream_duration;
841 i_delay = p_sys->p_input->i_pts_delay - i_consumed;
848 static void EsOutESVarUpdateGeneric( es_out_t *out, int i_id, es_format_t *fmt, const char *psz_language,
851 es_out_sys_t *p_sys = out->p_sys;
852 input_thread_t *p_input = p_sys->p_input;
853 const bool b_teletext = fmt->i_cat == SPU_ES && fmt->i_codec == VLC_FOURCC( 't', 'e', 'l', 'x' );
854 vlc_value_t val, text;
858 /* TODO it should probably be a list */
860 input_SendEventTeletext( p_sys->p_input, -1 );
862 input_SendEventEsDel( p_input, SPU_ES, i_id );
866 /* Get the number of ES already added */
868 if( fmt->i_cat == AUDIO_ES )
869 psz_var = "audio-es";
870 else if( fmt->i_cat == VIDEO_ES )
871 psz_var = "video-es";
875 var_Change( p_input, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
880 /* First one, we need to add the "Disable" choice */
881 val2.i_int = -1; text.psz_string = _("Disable");
882 var_Change( p_input, psz_var, VLC_VAR_ADDCHOICE, &val2, &text );
886 /* Take care of the ES description */
887 if( fmt->psz_description && *fmt->psz_description )
889 if( psz_language && *psz_language )
891 text.psz_string = malloc( strlen( fmt->psz_description) +
892 strlen( psz_language ) + 10 );
893 sprintf( text.psz_string, "%s - [%s]", fmt->psz_description,
896 else text.psz_string = strdup( fmt->psz_description );
900 if( psz_language && *psz_language )
902 if( asprintf( &text.psz_string, "%s %i - [%s]", _( "Track" ), val.i_int, psz_language ) == -1 )
903 text.psz_string = NULL;
907 if( asprintf( &text.psz_string, "%s %i", _( "Track" ), val.i_int ) == -1 )
908 text.psz_string = NULL;
912 input_SendEventEsAdd( p_input, fmt->i_cat, i_id, text.psz_string );
914 free( text.psz_string );
918 /* TODO it should probably be a list */
919 if( var_GetInteger( p_sys->p_input, "teletext-es" ) < 0 )
920 input_SendEventTeletext( p_sys->p_input, i_id );
924 static void EsOutESVarUpdate( es_out_t *out, es_out_id_t *es,
927 EsOutESVarUpdateGeneric( out, es->i_id, &es->fmt, es->psz_language, b_delete );
930 /* EsOutProgramSelect:
931 * Select a program and update the object variable
933 static void EsOutProgramSelect( es_out_t *out, es_out_pgrm_t *p_pgrm )
935 es_out_sys_t *p_sys = out->p_sys;
936 input_thread_t *p_input = p_sys->p_input;
939 if( p_sys->p_pgrm == p_pgrm )
940 return; /* Nothing to do */
944 es_out_pgrm_t *old = p_sys->p_pgrm;
945 msg_Dbg( p_input, "unselecting program id=%d", old->i_id );
947 for( i = 0; i < p_sys->i_es; i++ )
949 if( p_sys->es[i]->p_pgrm == old && EsIsSelected( p_sys->es[i] ) &&
950 p_sys->i_mode != ES_OUT_MODE_ALL )
951 EsUnselect( out, p_sys->es[i], true );
954 p_sys->p_es_audio = NULL;
955 p_sys->p_es_sub = NULL;
956 p_sys->p_es_video = NULL;
959 msg_Dbg( p_input, "selecting program id=%d", p_pgrm->i_id );
961 /* Mark it selected */
962 p_pgrm->b_selected = true;
964 /* Switch master stream */
965 p_sys->p_pgrm = p_pgrm;
967 /* Update "program" */
968 input_SendEventProgramSelect( p_input, p_pgrm->i_id );
971 input_SendEventEsDel( p_input, AUDIO_ES, -1 );
972 input_SendEventEsDel( p_input, VIDEO_ES, -1 );
973 input_SendEventEsDel( p_input, SPU_ES, -1 );
976 var_SetInteger( p_input, "teletext-es", -1 );
978 for( i = 0; i < p_sys->i_es; i++ )
980 if( p_sys->es[i]->p_pgrm == p_sys->p_pgrm )
981 EsOutESVarUpdate( out, p_sys->es[i], false );
982 EsOutSelect( out, p_sys->es[i], false );
985 /* Update now playing */
986 input_item_SetNowPlaying( p_input->p->p_item, p_pgrm->psz_now_playing );
987 input_item_SetPublisher( p_input->p->p_item, p_pgrm->psz_publisher );
989 input_SendEventMeta( p_input );
995 static es_out_pgrm_t *EsOutProgramAdd( es_out_t *out, int i_group )
997 es_out_sys_t *p_sys = out->p_sys;
998 input_thread_t *p_input = p_sys->p_input;
1000 es_out_pgrm_t *p_pgrm = malloc( sizeof( es_out_pgrm_t ) );
1005 p_pgrm->i_id = i_group;
1007 p_pgrm->b_selected = false;
1008 p_pgrm->psz_name = NULL;
1009 p_pgrm->psz_now_playing = NULL;
1010 p_pgrm->psz_publisher = NULL;
1011 p_pgrm->p_epg = NULL;
1012 p_pgrm->p_clock = input_clock_New( p_input->p->i_cr_average, p_sys->i_rate );
1013 if( !p_pgrm->p_clock )
1020 TAB_APPEND( p_sys->i_pgrm, p_sys->pgrm, p_pgrm );
1022 /* Update "program" variable */
1023 input_SendEventProgramAdd( p_input, i_group, NULL );
1025 if( i_group == var_GetInteger( p_input, "program" ) )
1026 EsOutProgramSelect( out, p_pgrm );
1034 static int EsOutProgramDel( es_out_t *out, int i_group )
1036 es_out_sys_t *p_sys = out->p_sys;
1037 input_thread_t *p_input = p_sys->p_input;
1038 es_out_pgrm_t *p_pgrm = NULL;
1041 for( i = 0; i < p_sys->i_pgrm; i++ )
1043 if( p_sys->pgrm[i]->i_id == i_group )
1045 p_pgrm = p_sys->pgrm[i];
1050 if( p_pgrm == NULL )
1051 return VLC_EGENERIC;
1055 msg_Dbg( p_input, "can't delete program %d which still has %i ES",
1056 i_group, p_pgrm->i_es );
1057 return VLC_EGENERIC;
1060 TAB_REMOVE( p_sys->i_pgrm, p_sys->pgrm, p_pgrm );
1062 /* If program is selected we need to unselect it */
1063 if( p_sys->p_pgrm == p_pgrm )
1064 p_sys->p_pgrm = NULL;
1066 input_clock_Delete( p_pgrm->p_clock );
1068 free( p_pgrm->psz_name );
1069 free( p_pgrm->psz_now_playing );
1070 free( p_pgrm->psz_publisher );
1072 vlc_epg_Delete( p_pgrm->p_epg );
1075 /* Update "program" variable */
1076 input_SendEventProgramDel( p_input, i_group );
1081 /* EsOutProgramMeta:
1083 static char *EsOutProgramGetMetaName( es_out_pgrm_t *p_pgrm )
1086 if( p_pgrm->psz_name )
1088 if( asprintf( &psz, _("%s [%s %d]"), p_pgrm->psz_name, _("Program"), p_pgrm->i_id ) == -1 )
1093 if( asprintf( &psz, "%s %d", _("Program"), p_pgrm->i_id ) == -1 )
1099 static void EsOutProgramMeta( es_out_t *out, int i_group, vlc_meta_t *p_meta )
1101 es_out_sys_t *p_sys = out->p_sys;
1102 es_out_pgrm_t *p_pgrm = NULL;
1103 input_thread_t *p_input = p_sys->p_input;
1105 const char *psz_title = NULL;
1106 const char *psz_provider = NULL;
1109 msg_Dbg( p_input, "EsOutProgramMeta: number=%d", i_group );
1111 /* Check against empty meta data (empty for what we handle) */
1112 if( !vlc_meta_Get( p_meta, vlc_meta_Title) &&
1113 !vlc_meta_Get( p_meta, vlc_meta_NowPlaying) &&
1114 !vlc_meta_Get( p_meta, vlc_meta_Publisher) &&
1115 vlc_dictionary_keys_count( &p_meta->extra_tags ) <= 0 )
1120 for( i = 0; i < p_sys->i_pgrm; i++ )
1122 if( p_sys->pgrm[i]->i_id == i_group )
1124 p_pgrm = p_sys->pgrm[i];
1128 if( p_pgrm == NULL )
1129 p_pgrm = EsOutProgramAdd( out, i_group ); /* Create it */
1132 psz_title = vlc_meta_Get( p_meta, vlc_meta_Title);
1133 psz_provider = vlc_meta_Get( p_meta, vlc_meta_Publisher);
1135 /* Update the description text of the program */
1136 if( psz_title && *psz_title )
1138 if( !p_pgrm->psz_name || strcmp( p_pgrm->psz_name, psz_title ) )
1140 char *psz_cat = EsOutProgramGetMetaName( p_pgrm );
1142 /* Remove old entries */
1143 input_Control( p_input, INPUT_DEL_INFO, psz_cat, NULL );
1144 /* TODO update epg name */
1147 free( p_pgrm->psz_name );
1148 p_pgrm->psz_name = strdup( psz_title );
1151 if( psz_provider && *psz_provider )
1153 if( asprintf( &psz_text, "%s [%s]", psz_title, psz_provider ) < 0 )
1158 psz_text = strdup( psz_title );
1161 /* ugly but it works */
1164 input_SendEventProgramDel( p_input, i_group );
1165 input_SendEventProgramAdd( p_input, i_group, psz_text );
1171 psz_cat = EsOutProgramGetMetaName( p_pgrm );
1174 if( p_sys->p_pgrm == p_pgrm )
1176 input_item_SetPublisher( p_input->p->p_item, psz_provider );
1177 input_SendEventMeta( p_input );
1179 input_Control( p_input, INPUT_ADD_INFO, psz_cat, input_MetaTypeToLocalizedString(vlc_meta_Publisher), psz_provider );
1181 char ** ppsz_all_keys = vlc_dictionary_all_keys( &p_meta->extra_tags );
1182 for( i = 0; ppsz_all_keys[i]; i++ )
1184 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _(ppsz_all_keys[i]),
1185 vlc_dictionary_value_for_key( &p_meta->extra_tags, ppsz_all_keys[i] ) );
1186 free( ppsz_all_keys[i] );
1188 free( ppsz_all_keys );
1193 static void vlc_epg_Merge( vlc_epg_t *p_dst, const vlc_epg_t *p_src )
1198 for( i = 0; i < p_src->i_event; i++ )
1200 vlc_epg_event_t *p_evt = p_src->pp_event[i];
1204 for( j = 0; j < p_dst->i_event; j++ )
1206 if( p_dst->pp_event[j]->i_start == p_evt->i_start && p_dst->pp_event[j]->i_duration == p_evt->i_duration )
1211 if( p_dst->pp_event[j]->i_start > p_evt->i_start )
1216 vlc_epg_event_t *p_copy = calloc( 1, sizeof(vlc_epg_event_t) );
1219 p_copy->i_start = p_evt->i_start;
1220 p_copy->i_duration = p_evt->i_duration;
1221 p_copy->psz_name = p_evt->psz_name ? strdup( p_evt->psz_name ) : NULL;
1222 p_copy->psz_short_description = p_evt->psz_short_description ? strdup( p_evt->psz_short_description ) : NULL;
1223 p_copy->psz_description = p_evt->psz_description ? strdup( p_evt->psz_description ) : NULL;
1224 TAB_INSERT( p_dst->i_event, p_dst->pp_event, p_copy, j );
1227 /* Update current */
1228 vlc_epg_SetCurrent( p_dst, p_src->p_current ? p_src->p_current->i_start : -1 );
1230 /* Keep only 1 old event */
1231 if( p_dst->p_current )
1233 while( p_dst->i_event > 1 && p_dst->pp_event[0] != p_dst->p_current && p_dst->pp_event[1] != p_dst->p_current )
1234 TAB_REMOVE( p_dst->i_event, p_dst->pp_event, p_dst->pp_event[0] );
1238 static void EsOutProgramEpg( es_out_t *out, int i_group, vlc_epg_t *p_epg )
1240 es_out_sys_t *p_sys = out->p_sys;
1241 input_thread_t *p_input = p_sys->p_input;
1242 es_out_pgrm_t *p_pgrm = NULL;
1247 for( i = 0; i < p_sys->i_pgrm; i++ )
1249 if( p_sys->pgrm[i]->i_id == i_group )
1251 p_pgrm = p_sys->pgrm[i];
1255 if( p_pgrm == NULL )
1256 p_pgrm = EsOutProgramAdd( out, i_group ); /* Create it */
1259 if( !p_pgrm->p_epg )
1260 p_pgrm->p_epg = vlc_epg_New( p_pgrm->psz_name );
1261 vlc_epg_Merge( p_pgrm->p_epg, p_epg );
1264 psz_cat = EsOutProgramGetMetaName( p_pgrm );
1265 #ifdef HAVE_LOCALTIME_R
1267 if( asprintf( &psz_epg, "EPG %s", psz_cat ) == -1 )
1269 input_Control( p_input, INPUT_DEL_INFO, psz_epg, NULL );
1270 msg_Dbg( p_input, "EsOutProgramEpg: number=%d name=%s", i_group, p_pgrm->p_epg->psz_name );
1271 for( i = 0; i < p_pgrm->p_epg->i_event; i++ )
1273 const vlc_epg_event_t *p_evt = p_pgrm->p_epg->pp_event[i];
1274 time_t t_start = (time_t)p_evt->i_start;
1276 char psz_start[128];
1278 localtime_r( &t_start, &tm_start );
1280 snprintf( psz_start, sizeof(psz_start), "%2.2d:%2.2d:%2.2d", tm_start.tm_hour, tm_start.tm_min, tm_start.tm_sec );
1281 if( p_evt->psz_short_description || p_evt->psz_description )
1282 input_Control( p_input, INPUT_ADD_INFO, psz_epg, psz_start, "%s (%2.2d:%2.2d) - %s",
1284 p_evt->i_duration/60/60, (p_evt->i_duration/60)%60,
1285 p_evt->psz_short_description ? p_evt->psz_short_description : p_evt->psz_description );
1287 input_Control( p_input, INPUT_ADD_INFO, psz_epg, psz_start, "%s (%2.2d:%2.2d)",
1289 p_evt->i_duration/60/60, (p_evt->i_duration/60)%60 );
1293 /* Update now playing */
1294 free( p_pgrm->psz_now_playing );
1295 p_pgrm->psz_now_playing = NULL;
1296 if( p_epg->p_current && p_epg->p_current->psz_name && *p_epg->p_current->psz_name )
1297 p_pgrm->psz_now_playing = strdup( p_epg->p_current->psz_name );
1299 if( p_pgrm == p_sys->p_pgrm )
1301 input_item_SetNowPlaying( p_input->p->p_item, p_pgrm->psz_now_playing );
1302 input_SendEventMeta( p_input );
1305 if( p_pgrm->psz_now_playing )
1307 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1308 input_MetaTypeToLocalizedString(vlc_meta_NowPlaying),
1309 p_pgrm->psz_now_playing );
1313 input_Control( p_input, INPUT_DEL_INFO, psz_cat,
1314 input_MetaTypeToLocalizedString(vlc_meta_NowPlaying) );
1323 static es_out_id_t *EsOutAdd( es_out_t *out, const es_format_t *fmt )
1325 es_out_sys_t *p_sys = out->p_sys;
1326 input_thread_t *p_input = p_sys->p_input;
1328 if( fmt->i_group < 0 )
1330 msg_Err( p_input, "invalid group number" );
1334 es_out_id_t *es = malloc( sizeof( *es ) );
1335 es_out_pgrm_t *p_pgrm = NULL;
1341 vlc_mutex_lock( &p_sys->lock );
1343 /* Search the program */
1344 for( i = 0; i < p_sys->i_pgrm; i++ )
1346 if( fmt->i_group == p_sys->pgrm[i]->i_id )
1348 p_pgrm = p_sys->pgrm[i];
1352 if( p_pgrm == NULL )
1354 /* Create a new one */
1355 p_pgrm = EsOutProgramAdd( out, fmt->i_group );
1358 /* Increase ref count for program */
1362 es->p_pgrm = p_pgrm;
1363 es_format_Copy( &es->fmt, fmt );
1364 if( es->fmt.i_id < 0 )
1365 es->fmt.i_id = out->p_sys->i_id;
1366 es->i_id = es->fmt.i_id;
1367 es->i_meta_id = out->p_sys->i_id;
1369 switch( es->fmt.i_cat )
1373 audio_replay_gain_t rg;
1375 es->i_channel = p_sys->i_audio;
1377 memset( &rg, 0, sizeof(rg) );
1378 vlc_mutex_lock( &p_input->p->p_item->lock );
1379 vlc_audio_replay_gain_MergeFromMeta( &rg, p_input->p->p_item->p_meta );
1380 vlc_mutex_unlock( &p_input->p->p_item->lock );
1382 for( i = 0; i < AUDIO_REPLAY_GAIN_MAX; i++ )
1384 if( !es->fmt.audio_replay_gain.pb_peak[i] )
1386 es->fmt.audio_replay_gain.pb_peak[i] = rg.pb_peak[i];
1387 es->fmt.audio_replay_gain.pf_peak[i] = rg.pf_peak[i];
1389 if( !es->fmt.audio_replay_gain.pb_gain[i] )
1391 es->fmt.audio_replay_gain.pb_gain[i] = rg.pb_gain[i];
1392 es->fmt.audio_replay_gain.pf_gain[i] = rg.pf_gain[i];
1399 es->i_channel = p_sys->i_video;
1400 if( es->fmt.video.i_frame_rate && es->fmt.video.i_frame_rate_base )
1401 vlc_ureduce( &es->fmt.video.i_frame_rate,
1402 &es->fmt.video.i_frame_rate_base,
1403 es->fmt.video.i_frame_rate,
1404 es->fmt.video.i_frame_rate_base, 0 );
1408 es->i_channel = p_sys->i_sub;
1415 es->psz_language = LanguageGetName( es->fmt.psz_language ); /* remember so we only need to do it once */
1416 es->psz_language_code = LanguageGetCode( es->fmt.psz_language );
1418 es->p_dec_record = NULL;
1419 for( i = 0; i < 4; i++ )
1420 es->pb_cc_present[i] = false;
1421 es->p_master = NULL;
1423 if( es->p_pgrm == p_sys->p_pgrm )
1424 EsOutESVarUpdate( out, es, false );
1426 /* Select it if needed */
1427 EsOutSelect( out, es, false );
1430 TAB_APPEND( out->p_sys->i_es, out->p_sys->es, es );
1431 p_sys->i_id++; /* always incremented */
1432 switch( es->fmt.i_cat )
1445 EsOutUpdateInfo( out, es, &es->fmt, NULL );
1447 vlc_mutex_unlock( &p_sys->lock );
1452 static bool EsIsSelected( es_out_id_t *es )
1456 bool b_decode = false;
1457 if( es->p_master->p_dec )
1459 int i_channel = EsOutGetClosedCaptionsChannel( es->fmt.i_codec );
1460 if( i_channel != -1 )
1461 input_DecoderGetCcState( es->p_master->p_dec, &b_decode, i_channel );
1467 return es->p_dec != NULL;
1470 static void EsCreateDecoder( es_out_t *out, es_out_id_t *p_es )
1472 es_out_sys_t *p_sys = out->p_sys;
1473 input_thread_t *p_input = p_sys->p_input;
1475 p_es->p_dec = input_DecoderNew( p_input, &p_es->fmt, p_es->p_pgrm->p_clock, p_input->p->p_sout );
1478 if( p_sys->b_buffering )
1479 input_DecoderStartBuffering( p_es->p_dec );
1481 if( !p_es->p_master && p_sys->p_sout_record )
1483 p_es->p_dec_record = input_DecoderNew( p_input, &p_es->fmt, p_es->p_pgrm->p_clock, p_sys->p_sout_record );
1484 if( p_es->p_dec_record && p_sys->b_buffering )
1485 input_DecoderStartBuffering( p_es->p_dec_record );
1489 EsOutDecoderChangeDelay( out, p_es );
1491 static void EsDestroyDecoder( es_out_t *out, es_out_id_t *p_es )
1498 input_DecoderDelete( p_es->p_dec );
1501 if( p_es->p_dec_record )
1503 input_DecoderDelete( p_es->p_dec_record );
1504 p_es->p_dec_record = NULL;
1508 static void EsSelect( es_out_t *out, es_out_id_t *es )
1510 es_out_sys_t *p_sys = out->p_sys;
1511 input_thread_t *p_input = p_sys->p_input;
1514 if( EsIsSelected( es ) )
1516 msg_Warn( p_input, "ES 0x%x is already selected", es->i_id );
1523 if( !es->p_master->p_dec )
1526 i_channel = EsOutGetClosedCaptionsChannel( es->fmt.i_codec );
1527 if( i_channel == -1 || input_DecoderSetCcState( es->p_master->p_dec, true, i_channel ) )
1532 if( es->fmt.i_cat == VIDEO_ES || es->fmt.i_cat == SPU_ES )
1534 if( !var_GetBool( p_input, out->b_sout ? "sout-video" : "video" ) )
1536 msg_Dbg( p_input, "video is disabled, not selecting ES 0x%x",
1541 else if( es->fmt.i_cat == AUDIO_ES )
1543 var_Get( p_input, "audio", &val );
1544 if( !var_GetBool( p_input, out->b_sout ? "sout-audio" : "audio" ) )
1546 msg_Dbg( p_input, "audio is disabled, not selecting ES 0x%x",
1551 if( es->fmt.i_cat == SPU_ES )
1553 var_Get( p_input, "spu", &val );
1554 if( !var_GetBool( p_input, out->b_sout ? "sout-spu" : "spu" ) )
1556 msg_Dbg( p_input, "spu is disabled, not selecting ES 0x%x",
1562 EsCreateDecoder( out, es );
1564 if( es->p_dec == NULL || es->p_pgrm != p_sys->p_pgrm )
1568 /* Mark it as selected */
1569 input_SendEventEsSelect( p_input, es->fmt.i_cat, es->i_id );
1572 static void EsUnselect( es_out_t *out, es_out_id_t *es, bool b_update )
1574 es_out_sys_t *p_sys = out->p_sys;
1575 input_thread_t *p_input = p_sys->p_input;
1577 if( !EsIsSelected( es ) )
1579 msg_Warn( p_input, "ES 0x%x is already unselected", es->i_id );
1585 if( es->p_master->p_dec )
1587 int i_channel = EsOutGetClosedCaptionsChannel( es->fmt.i_codec );
1588 if( i_channel != -1 )
1589 input_DecoderSetCcState( es->p_master->p_dec, false, i_channel );
1594 const int i_spu_id = var_GetInteger( p_input, "spu-es");
1596 for( i = 0; i < 4; i++ )
1598 if( !es->pb_cc_present[i] || !es->pp_cc_es[i] )
1601 if( i_spu_id == es->pp_cc_es[i]->i_id )
1603 /* Force unselection of the CC */
1604 input_SendEventEsSelect( p_input, SPU_ES, -1 );
1606 EsOutDel( out, es->pp_cc_es[i] );
1608 es->pb_cc_present[i] = false;
1610 EsDestroyDecoder( out, es );
1617 if( es->p_dec == NULL )
1620 /* Mark it as unselected */
1621 input_SendEventEsSelect( p_input, es->fmt.i_cat, -1 );
1625 * Select an ES given the current mode
1626 * XXX: you need to take a the lock before (stream.stream_lock)
1628 * \param out The es_out structure
1629 * \param es es_out_id structure
1630 * \param b_force ...
1633 static void EsOutSelect( es_out_t *out, es_out_id_t *es, bool b_force )
1635 es_out_sys_t *p_sys = out->p_sys;
1637 int i_cat = es->fmt.i_cat;
1639 if( !p_sys->b_active ||
1640 ( !b_force && es->fmt.i_priority < 0 ) )
1645 if( p_sys->i_mode == ES_OUT_MODE_ALL || b_force )
1647 if( !EsIsSelected( es ) )
1648 EsSelect( out, es );
1650 else if( p_sys->i_mode == ES_OUT_MODE_PARTIAL )
1654 var_Get( p_sys->p_input, "programs", &val );
1655 for ( i = 0; i < val.p_list->i_count; i++ )
1657 if ( val.p_list->p_values[i].i_int == es->p_pgrm->i_id || b_force )
1659 if( !EsIsSelected( es ) )
1660 EsSelect( out, es );
1664 var_Change( p_sys->p_input, "programs", VLC_VAR_FREELIST, &val, NULL );
1666 else if( p_sys->i_mode == ES_OUT_MODE_AUTO )
1670 if( es->p_pgrm != p_sys->p_pgrm )
1673 if( i_cat == AUDIO_ES )
1675 int idx1 = LanguageArrayIndex( p_sys->ppsz_audio_language,
1676 es->psz_language_code );
1678 if( p_sys->p_es_audio &&
1679 p_sys->p_es_audio->fmt.i_priority >= es->fmt.i_priority )
1681 int idx2 = LanguageArrayIndex( p_sys->ppsz_audio_language,
1682 p_sys->p_es_audio->psz_language_code );
1684 if( idx1 < 0 || ( idx2 >= 0 && idx2 <= idx1 ) )
1686 i_wanted = es->i_channel;
1690 /* Select audio if (no audio selected yet)
1691 * - no audio-language
1692 * - no audio code for the ES
1693 * - audio code in the requested list */
1695 !strcmp( es->psz_language_code, "??" ) ||
1696 !p_sys->ppsz_audio_language )
1697 i_wanted = es->i_channel;
1700 if( p_sys->i_audio_last >= 0 )
1701 i_wanted = p_sys->i_audio_last;
1703 if( p_sys->i_audio_id >= 0 )
1705 if( es->i_id == p_sys->i_audio_id )
1706 i_wanted = es->i_channel;
1711 else if( i_cat == SPU_ES )
1713 int idx1 = LanguageArrayIndex( p_sys->ppsz_sub_language,
1714 es->psz_language_code );
1716 if( p_sys->p_es_sub &&
1717 p_sys->p_es_sub->fmt.i_priority >= es->fmt.i_priority )
1719 int idx2 = LanguageArrayIndex( p_sys->ppsz_sub_language,
1720 p_sys->p_es_sub->psz_language_code );
1722 msg_Dbg( p_sys->p_input, "idx1=%d(%s) idx2=%d(%s)",
1723 idx1, es->psz_language_code, idx2,
1724 p_sys->p_es_sub->psz_language_code );
1726 if( idx1 < 0 || ( idx2 >= 0 && idx2 <= idx1 ) )
1728 /* We found a SPU that matches our language request */
1729 i_wanted = es->i_channel;
1731 else if( idx1 >= 0 )
1733 msg_Dbg( p_sys->p_input, "idx1=%d(%s)",
1734 idx1, es->psz_language_code );
1736 i_wanted = es->i_channel;
1738 else if( p_sys->i_default_sub_id >= 0 )
1740 if( es->i_id == p_sys->i_default_sub_id )
1741 i_wanted = es->i_channel;
1744 if( p_sys->i_sub_last >= 0 )
1745 i_wanted = p_sys->i_sub_last;
1747 if( p_sys->i_sub_id >= 0 )
1749 if( es->i_id == p_sys->i_sub_id )
1750 i_wanted = es->i_channel;
1755 else if( i_cat == VIDEO_ES )
1757 i_wanted = es->i_channel;
1760 if( i_wanted == es->i_channel && !EsIsSelected( es ) )
1761 EsSelect( out, es );
1764 /* FIXME TODO handle priority here */
1765 if( EsIsSelected( es ) )
1767 if( i_cat == AUDIO_ES )
1769 if( p_sys->i_mode == ES_OUT_MODE_AUTO &&
1770 p_sys->p_es_audio &&
1771 p_sys->p_es_audio != es &&
1772 EsIsSelected( p_sys->p_es_audio ) )
1774 EsUnselect( out, p_sys->p_es_audio, false );
1776 p_sys->p_es_audio = es;
1778 else if( i_cat == SPU_ES )
1780 if( p_sys->i_mode == ES_OUT_MODE_AUTO &&
1782 p_sys->p_es_sub != es &&
1783 EsIsSelected( p_sys->p_es_sub ) )
1785 EsUnselect( out, p_sys->p_es_sub, false );
1787 p_sys->p_es_sub = es;
1789 else if( i_cat == VIDEO_ES )
1791 p_sys->p_es_video = es;
1797 * Send a block for the given es_out
1799 * \param out the es_out to send from
1800 * \param es the es_out_id
1801 * \param p_block the data block to send
1803 static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
1805 es_out_sys_t *p_sys = out->p_sys;
1806 input_thread_t *p_input = p_sys->p_input;
1809 if( libvlc_stats( p_input ) )
1811 vlc_mutex_lock( &p_input->p->counters.counters_lock );
1812 stats_UpdateInteger( p_input, p_input->p->counters.p_demux_read,
1813 p_block->i_buffer, &i_total );
1814 stats_UpdateFloat( p_input , p_input->p->counters.p_demux_bitrate,
1815 (float)i_total, NULL );
1816 vlc_mutex_unlock( &p_input->p->counters.counters_lock );
1819 vlc_mutex_lock( &p_sys->lock );
1821 /* Mark preroll blocks */
1822 if( p_sys->i_preroll_end >= 0 )
1824 int64_t i_date = p_block->i_pts;
1826 i_date = p_block->i_dts;
1828 if( i_date < p_sys->i_preroll_end )
1829 p_block->i_flags |= BLOCK_FLAG_PREROLL;
1832 p_block->i_rate = 0;
1836 block_Release( p_block );
1837 vlc_mutex_unlock( &p_sys->lock );
1842 if( es->p_dec_record )
1844 block_t *p_dup = block_Duplicate( p_block );
1846 input_DecoderDecode( es->p_dec_record, p_dup );
1848 input_DecoderDecode( es->p_dec, p_block );
1850 es_format_t fmt_dsc;
1851 vlc_meta_t *p_meta_dsc;
1852 if( input_DecoderHasFormatChanged( es->p_dec, &fmt_dsc, &p_meta_dsc ) )
1854 EsOutUpdateInfo( out, es, &fmt_dsc, p_meta_dsc );
1856 es_format_Clean( &fmt_dsc );
1858 vlc_meta_Delete( p_meta_dsc );
1861 /* Check CC status */
1864 input_DecoderIsCcPresent( es->p_dec, pb_cc );
1865 for( int i = 0; i < 4; i++ )
1867 static const vlc_fourcc_t fcc[4] = {
1868 VLC_FOURCC('c', 'c', '1', ' '),
1869 VLC_FOURCC('c', 'c', '2', ' '),
1870 VLC_FOURCC('c', 'c', '3', ' '),
1871 VLC_FOURCC('c', 'c', '4', ' '),
1875 if( es->pb_cc_present[i] || !pb_cc[i] )
1877 msg_Dbg( p_input, "Adding CC track %d for es[%d]", 1+i, es->i_id );
1879 es_format_Init( &fmt, SPU_ES, fcc[i] );
1880 fmt.i_group = es->fmt.i_group;
1881 if( asprintf( &fmt.psz_description,
1882 _("Closed captions %u"), 1 + i ) == -1 )
1883 fmt.psz_description = NULL;
1884 es->pp_cc_es[i] = EsOutAdd( out, &fmt );
1885 es->pp_cc_es[i]->p_master = es;
1886 es_format_Clean( &fmt );
1889 es->pb_cc_present[i] = true;
1892 vlc_mutex_unlock( &p_sys->lock );
1897 /*****************************************************************************
1899 *****************************************************************************/
1900 static void EsOutDel( es_out_t *out, es_out_id_t *es )
1902 es_out_sys_t *p_sys = out->p_sys;
1903 bool b_reselect = false;
1906 vlc_mutex_lock( &p_sys->lock );
1908 /* We don't try to reselect */
1911 while( !p_sys->p_input->b_die && !p_sys->b_buffering && es->p_dec )
1913 if( input_DecoderIsEmpty( es->p_dec ) &&
1914 ( !es->p_dec_record || input_DecoderIsEmpty( es->p_dec_record ) ))
1916 /* FIXME there should be a way to have auto deleted es, but there will be
1917 * a problem when another codec of the same type is created (mainly video) */
1920 EsUnselect( out, es, es->p_pgrm == p_sys->p_pgrm );
1923 if( es->p_pgrm == p_sys->p_pgrm )
1924 EsOutESVarUpdate( out, es, true );
1926 TAB_REMOVE( p_sys->i_es, p_sys->es, es );
1929 if( es->p_pgrm->i_es == 0 )
1931 msg_Dbg( p_sys->p_input, "Program doesn't contain anymore ES" );
1934 if( p_sys->p_es_audio == es || p_sys->p_es_video == es ||
1935 p_sys->p_es_sub == es ) b_reselect = true;
1937 if( p_sys->p_es_audio == es ) p_sys->p_es_audio = NULL;
1938 if( p_sys->p_es_video == es ) p_sys->p_es_video = NULL;
1939 if( p_sys->p_es_sub == es ) p_sys->p_es_sub = NULL;
1941 switch( es->fmt.i_cat )
1954 /* Re-select another track when needed */
1957 for( i = 0; i < p_sys->i_es; i++ )
1959 if( es->fmt.i_cat == p_sys->es[i]->fmt.i_cat )
1960 EsOutSelect( out, p_sys->es[i], false );
1964 free( es->psz_language );
1965 free( es->psz_language_code );
1967 es_format_Clean( &es->fmt );
1969 vlc_mutex_unlock( &p_sys->lock );
1975 * Control query handler
1977 * \param out the es_out to control
1978 * \param i_query A es_out query as defined in include/ninput.h
1979 * \param args a variable list of arguments for the query
1980 * \return VLC_SUCCESS or an error code
1982 static int EsOutControlLocked( es_out_t *out, int i_query, va_list args )
1984 es_out_sys_t *p_sys = out->p_sys;
1992 case ES_OUT_SET_ES_STATE:
1993 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
1994 b = (bool) va_arg( args, int );
1995 if( b && !EsIsSelected( es ) )
1997 EsSelect( out, es );
1998 return EsIsSelected( es ) ? VLC_SUCCESS : VLC_EGENERIC;
2000 else if( !b && EsIsSelected( es ) )
2002 EsUnselect( out, es, es->p_pgrm == p_sys->p_pgrm );
2007 case ES_OUT_GET_ES_STATE:
2008 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
2009 pb = (bool*) va_arg( args, bool * );
2011 *pb = EsIsSelected( es );
2014 case ES_OUT_SET_ACTIVE:
2016 b = (bool) va_arg( args, int );
2017 p_sys->b_active = b;
2021 case ES_OUT_SET_MODE:
2022 i = (int) va_arg( args, int );
2023 if( i == ES_OUT_MODE_NONE || i == ES_OUT_MODE_ALL ||
2024 i == ES_OUT_MODE_AUTO || i == ES_OUT_MODE_PARTIAL )
2028 /* Reapply policy mode */
2029 for( i = 0; i < p_sys->i_es; i++ )
2031 if( EsIsSelected( p_sys->es[i] ) )
2033 EsUnselect( out, p_sys->es[i],
2034 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
2037 for( i = 0; i < p_sys->i_es; i++ )
2039 EsOutSelect( out, p_sys->es[i], false );
2043 return VLC_EGENERIC;
2046 case ES_OUT_RESTART_ES:
2050 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
2054 else if( es == (es_out_id_t*)((uint8_t*)NULL+AUDIO_ES) )
2056 else if( es == (es_out_id_t*)((uint8_t*)NULL+VIDEO_ES) )
2058 else if( es == (es_out_id_t*)((uint8_t*)NULL+SPU_ES) )
2063 for( i = 0; i < p_sys->i_es; i++ )
2067 if( es == p_sys->es[i] )
2069 EsOutSelect( out, es, true );
2075 if( i_cat == UNKNOWN_ES || p_sys->es[i]->fmt.i_cat == i_cat )
2077 if( EsIsSelected( p_sys->es[i] ) )
2079 if( i_query == ES_OUT_RESTART_ES )
2081 if( p_sys->es[i]->p_dec )
2083 EsDestroyDecoder( out, p_sys->es[i] );
2084 EsCreateDecoder( out, p_sys->es[i] );
2089 EsUnselect( out, p_sys->es[i],
2090 p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
2099 case ES_OUT_SET_ES_DEFAULT:
2101 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
2105 /*p_sys->i_default_video_id = -1;*/
2106 /*p_sys->i_default_audio_id = -1;*/
2107 p_sys->i_default_sub_id = -1;
2109 else if( es == (es_out_id_t*)((uint8_t*)NULL+AUDIO_ES) )
2111 /*p_sys->i_default_video_id = -1;*/
2113 else if( es == (es_out_id_t*)((uint8_t*)NULL+VIDEO_ES) )
2115 /*p_sys->i_default_audio_id = -1;*/
2117 else if( es == (es_out_id_t*)((uint8_t*)NULL+SPU_ES) )
2119 p_sys->i_default_sub_id = -1;
2123 /*if( es->fmt.i_cat == VIDEO_ES )
2124 p_sys->i_default_video_id = es->i_id;
2126 if( es->fmt.i_cat == AUDIO_ES )
2127 p_sys->i_default_audio_id = es->i_id;
2129 if( es->fmt.i_cat == SPU_ES )
2130 p_sys->i_default_sub_id = es->i_id;
2135 case ES_OUT_SET_PCR:
2136 case ES_OUT_SET_GROUP_PCR:
2138 es_out_pgrm_t *p_pgrm = NULL;
2142 if( i_query == ES_OUT_SET_PCR )
2144 p_pgrm = p_sys->p_pgrm;
2149 i_group = (int)va_arg( args, int );
2150 for( i = 0; i < p_sys->i_pgrm; i++ )
2152 if( p_sys->pgrm[i]->i_id == i_group )
2154 p_pgrm = p_sys->pgrm[i];
2159 if( p_pgrm == NULL )
2160 p_pgrm = EsOutProgramAdd( out, i_group ); /* Create it */
2162 i_pcr = (int64_t)va_arg( args, int64_t );
2164 * TODO do not use mdate() but proper stream acquisition date */
2165 input_clock_Update( p_pgrm->p_clock, VLC_OBJECT(p_sys->p_input),
2166 p_sys->p_input->b_can_pace_control || p_sys->b_buffering, i_pcr, mdate() );
2167 /* Check buffering state on master clock update */
2168 if( p_sys->b_buffering && p_pgrm == p_sys->p_pgrm )
2169 EsOutDecodersStopBuffering( out, false );
2174 case ES_OUT_RESET_PCR:
2175 msg_Err( p_sys->p_input, "ES_OUT_RESET_PCR called" );
2176 EsOutChangePosition( out );
2182 int64_t i_ts = (int64_t)va_arg( args, int64_t );
2183 int64_t *pi_ts = (int64_t *)va_arg( args, int64_t * );
2184 *pi_ts = input_clock_GetTS( p_sys->p_pgrm->p_clock, NULL,
2185 p_sys->p_input->i_pts_delay, i_ts );
2188 return VLC_EGENERIC;
2190 case ES_OUT_SET_GROUP:
2193 i = (int) va_arg( args, int );
2194 for( j = 0; j < p_sys->i_pgrm; j++ )
2196 es_out_pgrm_t *p_pgrm = p_sys->pgrm[j];
2197 if( p_pgrm->i_id == i )
2199 EsOutProgramSelect( out, p_pgrm );
2203 return VLC_EGENERIC;
2206 case ES_OUT_SET_ES_FMT:
2208 /* This ain't pretty but is need by some demuxers (eg. Ogg )
2209 * to update the p_extra data */
2211 es = (es_out_id_t*) va_arg( args, es_out_id_t * );
2212 p_fmt = (es_format_t*) va_arg( args, es_format_t * );
2214 return VLC_EGENERIC;
2216 if( p_fmt->i_extra )
2218 es->fmt.i_extra = p_fmt->i_extra;
2219 es->fmt.p_extra = realloc( es->fmt.p_extra, p_fmt->i_extra );
2220 memcpy( es->fmt.p_extra, p_fmt->p_extra, p_fmt->i_extra );
2225 EsDestroyDecoder( out, es );
2227 EsCreateDecoder( out, es );
2229 es->p_dec->fmt_in.i_extra = p_fmt->i_extra;
2230 es->p_dec->fmt_in.p_extra =
2231 realloc( es->p_dec->fmt_in.p_extra, p_fmt->i_extra );
2232 memcpy( es->p_dec->fmt_in.p_extra,
2233 p_fmt->p_extra, p_fmt->i_extra );
2240 case ES_OUT_SET_NEXT_DISPLAY_TIME:
2242 const int64_t i_date = (int64_t)va_arg( args, int64_t );
2245 return VLC_EGENERIC;
2247 p_sys->i_preroll_end = i_date;
2251 case ES_OUT_SET_GROUP_META:
2253 int i_group = (int)va_arg( args, int );
2254 vlc_meta_t *p_meta = (vlc_meta_t*)va_arg( args, vlc_meta_t * );
2256 EsOutProgramMeta( out, i_group, p_meta );
2259 case ES_OUT_SET_GROUP_EPG:
2261 int i_group = (int)va_arg( args, int );
2262 vlc_epg_t *p_epg = (vlc_epg_t*)va_arg( args, vlc_epg_t * );
2264 EsOutProgramEpg( out, i_group, p_epg );
2267 case ES_OUT_DEL_GROUP:
2269 int i_group = (int)va_arg( args, int );
2271 return EsOutProgramDel( out, i_group );
2274 case ES_OUT_GET_WAKE_UP:
2276 mtime_t *pi_wakeup = (mtime_t*)va_arg( args, mtime_t* );
2277 *pi_wakeup = EsOutGetWakeup( out );
2281 case ES_OUT_SET_ES_BY_ID:
2282 case ES_OUT_RESTART_ES_BY_ID:
2283 case ES_OUT_SET_ES_DEFAULT_BY_ID:
2285 const int i_id = (int)va_arg( args, int );
2286 es_out_id_t *p_es = EsOutGetFromID( out, i_id );
2291 case ES_OUT_SET_ES_BY_ID: i_new_query = ES_OUT_SET_ES; break;
2292 case ES_OUT_RESTART_ES_BY_ID: i_new_query = ES_OUT_RESTART_ES; break;
2293 case ES_OUT_SET_ES_DEFAULT_BY_ID: i_new_query = ES_OUT_SET_ES_DEFAULT; break;
2297 /* TODO if the lock is made non recursive it should be changed */
2298 return es_out_Control( out, i_new_query, p_es );
2301 case ES_OUT_GET_BUFFERING:
2302 pb = (bool *)va_arg( args, bool* );
2303 *pb = p_sys->b_buffering;
2306 case ES_OUT_GET_EMPTY:
2307 pb = (bool *)va_arg( args, bool* );
2308 *pb = EsOutDecodersIsEmpty( out );
2311 case ES_OUT_SET_DELAY:
2313 const int i_cat = (int)va_arg( args, int );
2314 const mtime_t i_delay = (mtime_t)va_arg( args, mtime_t );
2315 EsOutSetDelay( out, i_cat, i_delay );
2319 case ES_OUT_SET_RECORD_STATE:
2320 b = (bool) va_arg( args, int );
2321 return EsOutSetRecord( out, b );
2323 case ES_OUT_SET_PAUSE_STATE:
2325 const bool b_source_paused = (bool)va_arg( args, int );
2326 const bool b_paused = (bool)va_arg( args, int );
2327 const mtime_t i_date = (mtime_t) va_arg( args, mtime_t );
2329 assert( !b_source_paused == !b_paused );
2330 EsOutChangePause( out, b_paused, i_date );
2335 case ES_OUT_SET_RATE:
2337 const int i_src_rate = (int)va_arg( args, int );
2338 const int i_rate = (int)va_arg( args, int );
2340 assert( i_src_rate == i_rate );
2341 EsOutChangeRate( out, i_rate );
2346 case ES_OUT_SET_TIME:
2348 const mtime_t i_date = (mtime_t)va_arg( args, mtime_t );
2350 assert( i_date == -1 );
2351 EsOutChangePosition( out );
2356 case ES_OUT_SET_FRAME_NEXT:
2357 EsOutFrameNext( out );
2360 case ES_OUT_SET_TIMES:
2362 double f_position = (double)va_arg( args, double );
2363 mtime_t i_time = (mtime_t)va_arg( args, mtime_t );
2364 mtime_t i_length = (mtime_t)va_arg( args, mtime_t );
2366 /* Fix for buffering delay */
2367 const mtime_t i_delay = EsOutGetBuffering( out );
2374 f_position -= (double)i_delay / i_length;
2375 if( f_position < 0 )
2378 input_SendEventTimes( p_sys->p_input, f_position, i_time, i_length );
2383 msg_Err( p_sys->p_input, "unknown query in es_out_Control" );
2384 return VLC_EGENERIC;
2387 static int EsOutControl( es_out_t *out, int i_query, va_list args )
2389 es_out_sys_t *p_sys = out->p_sys;
2392 vlc_mutex_lock( &p_sys->lock );
2393 i_ret = EsOutControlLocked( out, i_query, args );
2394 vlc_mutex_unlock( &p_sys->lock );
2399 /****************************************************************************
2400 * LanguageGetName: try to expend iso639 into plain name
2401 ****************************************************************************/
2402 static char *LanguageGetName( const char *psz_code )
2404 const iso639_lang_t *pl;
2406 if( psz_code == NULL )
2408 return strdup( "" );
2411 if( strlen( psz_code ) == 2 )
2413 pl = GetLang_1( psz_code );
2415 else if( strlen( psz_code ) == 3 )
2417 pl = GetLang_2B( psz_code );
2418 if( !strcmp( pl->psz_iso639_1, "??" ) )
2420 pl = GetLang_2T( psz_code );
2425 return strdup( psz_code );
2428 if( !strcmp( pl->psz_iso639_1, "??" ) )
2430 return strdup( psz_code );
2434 if( *pl->psz_native_name )
2436 return strdup( pl->psz_native_name );
2438 return strdup( pl->psz_eng_name );
2442 /* Get a 2 char code */
2443 static char *LanguageGetCode( const char *psz_lang )
2445 const iso639_lang_t *pl;
2447 if( psz_lang == NULL || *psz_lang == '\0' )
2448 return strdup("??");
2450 for( pl = p_languages; pl->psz_iso639_1 != NULL; pl++ )
2452 if( !strcasecmp( pl->psz_eng_name, psz_lang ) ||
2453 !strcasecmp( pl->psz_native_name, psz_lang ) ||
2454 !strcasecmp( pl->psz_iso639_1, psz_lang ) ||
2455 !strcasecmp( pl->psz_iso639_2T, psz_lang ) ||
2456 !strcasecmp( pl->psz_iso639_2B, psz_lang ) )
2460 if( pl->psz_iso639_1 != NULL )
2461 return strdup( pl->psz_iso639_1 );
2463 return strdup("??");
2466 static char **LanguageSplit( const char *psz_langs )
2473 if( psz_langs == NULL ) return NULL;
2475 psz_parser = psz_dup = strdup(psz_langs);
2477 while( psz_parser && *psz_parser )
2482 psz = strchr(psz_parser, ',' );
2483 if( psz ) *psz++ = '\0';
2485 if( !strcmp( psz_parser, "any" ) )
2487 TAB_APPEND( i_psz, ppsz, strdup("any") );
2491 psz_code = LanguageGetCode( psz_parser );
2492 if( strcmp( psz_code, "??" ) )
2494 TAB_APPEND( i_psz, ppsz, psz_code );
2507 TAB_APPEND( i_psz, ppsz, NULL );
2514 static int LanguageArrayIndex( char **ppsz_langs, char *psz_lang )
2518 if( !ppsz_langs || !psz_lang ) return -1;
2520 for( i = 0; ppsz_langs[i]; i++ )
2522 if( !strcasecmp( ppsz_langs[i], psz_lang ) ||
2523 !strcasecmp( ppsz_langs[i], "any" ) )
2532 /****************************************************************************
2534 * - add meta info to the playlist item
2535 ****************************************************************************/
2536 static void EsOutUpdateInfo( es_out_t *out, es_out_id_t *es, const es_format_t *fmt, const vlc_meta_t *p_meta )
2538 es_out_sys_t *p_sys = out->p_sys;
2539 input_thread_t *p_input = p_sys->p_input;
2540 const es_format_t *p_fmt_es = &es->fmt;
2544 /* Create category name */
2545 if( asprintf( &psz_cat, _("Stream %d"), es->i_meta_id ) == -1 )
2548 /* Remove previous information */
2549 input_Control( p_input, INPUT_DEL_INFO, psz_cat, NULL );
2551 /* Add informations */
2552 const char *psz_type;
2553 switch( fmt->i_cat )
2556 psz_type = _("Audio");
2559 psz_type = _("Video");
2562 psz_type = _("Subtitle");
2570 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Type"), psz_type );
2572 if( es->i_meta_id != es->i_id )
2573 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Original ID"),
2576 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Codec"),
2577 "%.4s", (char*)&p_fmt_es->i_codec );
2579 if( es->psz_language && *es->psz_language )
2580 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Language"),
2581 "%s", es->psz_language );
2582 if( fmt->psz_description && *fmt->psz_description )
2583 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Description"),
2584 "%s", fmt->psz_description );
2586 switch( fmt->i_cat )
2589 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
2590 _("Type"), _("Audio") );
2592 if( fmt->audio.i_physical_channels & AOUT_CHAN_PHYSMASK )
2593 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Channels"),
2594 "%s", aout_FormatPrintChannels( &fmt->audio ) );
2595 else if( fmt->audio.i_channels > 0 )
2596 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Channels"),
2597 "%u", fmt->audio.i_channels );
2599 if( fmt->audio.i_rate > 0 )
2601 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Sample rate"),
2602 _("%u Hz"), fmt->audio.i_rate );
2603 /* FIXME that should be removed or improved ! (used by text/strings.c) */
2604 var_SetInteger( p_input, "sample-rate", fmt->audio.i_rate );
2607 unsigned int i_bitspersample = fmt->audio.i_bitspersample;
2608 if( i_bitspersample <= 0 )
2609 i_bitspersample = aout_BitsPerSample( p_fmt_es->i_codec );
2610 if( i_bitspersample > 0 )
2611 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
2612 _("Bits per sample"), "%u",
2615 if( fmt->i_bitrate > 0 )
2617 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Bitrate"),
2618 _("%u kb/s"), fmt->i_bitrate / 1000 );
2619 /* FIXME that should be removed or improved ! (used by text/strings.c) */
2620 var_SetInteger( p_input, "bit-rate", fmt->i_bitrate );
2622 for( int i = 0; i < AUDIO_REPLAY_GAIN_MAX; i++ )
2624 const audio_replay_gain_t *p_rg = &fmt->audio_replay_gain;
2625 if( !p_rg->pb_gain[i] )
2627 const char *psz_name;
2628 if( i == AUDIO_REPLAY_GAIN_TRACK )
2629 psz_name = _("Track replay gain");
2631 psz_name = _("Album replay gain");
2632 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
2633 psz_name, _("%.2f dB"), p_rg->pf_gain[i] );
2638 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
2639 _("Type"), _("Video") );
2641 if( fmt->video.i_width > 0 && fmt->video.i_height > 0 )
2642 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
2643 _("Resolution"), "%ux%u",
2644 fmt->video.i_width, fmt->video.i_height );
2646 if( fmt->video.i_visible_width > 0 &&
2647 fmt->video.i_visible_height > 0 )
2648 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
2649 _("Display resolution"), "%ux%u",
2650 fmt->video.i_visible_width,
2651 fmt->video.i_visible_height);
2652 if( fmt->video.i_frame_rate > 0 &&
2653 fmt->video.i_frame_rate_base > 0 )
2655 div = lldiv( (float)fmt->video.i_frame_rate /
2656 fmt->video.i_frame_rate_base * 1000000,
2659 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
2660 _("Frame rate"), "%"PRId64".%06u",
2661 div.quot, (unsigned int )div.rem );
2663 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
2664 _("Frame rate"), "%"PRId64, div.quot );
2669 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
2670 _("Type"), _("Subtitle") );
2677 /* Append generic meta */
2680 char **ppsz_all_keys = vlc_dictionary_all_keys( &p_meta->extra_tags );
2681 for( int i = 0; ppsz_all_keys && ppsz_all_keys[i]; i++ )
2683 char *psz_key = ppsz_all_keys[i];
2684 char *psz_value = vlc_dictionary_value_for_key( &p_meta->extra_tags, psz_key );
2687 input_Control( p_input, INPUT_ADD_INFO, psz_cat, _(psz_key), _(psz_value) );
2690 free( ppsz_all_keys );