2
2
* input.c: input thread
3
3
*****************************************************************************
4
4
* Copyright (C) 1998-2007 the VideoLAN team
5
* $Id: bbccf7e925518293c219eaf932e25250de2208ed $
5
* $Id: 6840657836708c4684c0b2f04efac3bce10fd289 $
7
7
* Authors: Christophe Massiot <massiot@via.ecp.fr>
8
8
* Laurent Aimar <fenrir@via.ecp.fr>
91
91
static void AppendAttachment( int *pi_attachment, input_attachment_t ***ppp_attachment,
92
92
int i_new, input_attachment_t **pp_new );
94
static void SubtitleAdd( input_thread_t *p_input, char *psz_subtitle, bool b_forced );
94
96
/*****************************************************************************
95
97
* This function creates a new input, and returns a pointer
96
98
* to its description. On error, it returns NULL.
979
981
if( psz_subtitle != NULL )
981
983
msg_Dbg( p_input, "forced subtitle: %s", psz_subtitle );
982
input_AddSubtitles( p_input, psz_subtitle, false );
984
SubtitleAdd( p_input, psz_subtitle, true );
985
987
var_Get( p_input, "sub-autodetect-file", &val );
988
990
char *psz_autopath = var_GetNonEmptyString( p_input, "sub-autodetect-path" );
989
char **subs = subtitles_Detect( p_input, psz_autopath,
990
p_input->p->input.p_item->psz_uri );
993
if( psz_autopath == NULL )
994
psz_autopath = strdup("");
996
/* Try to autoselect the first autodetected subtitles file
997
* if no subtitles file was specified */
998
if( ( psz_subtitle == NULL ) && subs && subs[0] )
1000
input_AddSubtitles( p_input, subs[0], false );
1005
/* Then, just add the following subtitles files */
1006
for( ; subs && subs[i]; i++ )
1008
if( !psz_subtitle || strcmp( psz_subtitle, subs[i] ) )
1010
sub = InputSourceNew( p_input );
1011
if( !InputSourceInit( p_input, sub, subs[i], "subtitle" ) )
1013
TAB_APPEND( p_input->p->i_slave, p_input->p->slave, sub );
991
char **ppsz_subs = subtitles_Detect( p_input, psz_autopath,
992
p_input->p->input.p_item->psz_uri );
1020
993
free( psz_autopath );
995
for( int i = 0; ppsz_subs && ppsz_subs[i]; i++ )
997
/* Try to autoselect the first autodetected subtitles file
998
* if no subtitles file was specified */
999
bool b_forced = i == 0 && !psz_subtitle;
1001
if( !psz_subtitle || strcmp( psz_subtitle, ppsz_subs[i] ) )
1002
SubtitleAdd( p_input, ppsz_subs[i], b_forced );
1004
free( ppsz_subs[i] );
1022
1008
free( psz_subtitle );
2473
2467
if( demux_Control( in->p_demux, DEMUX_SET_TIME, i_time ) )
2475
msg_Err( p_input, "seek failed for slave %d -> EOF", i );
2470
msg_Err( p_input, "seek failed for slave %d -> EOF", i );
2476
2471
in->b_eof = true;
2808
2807
/*****************************************************************************
2809
2808
* input_AddSubtitles: add a subtitles file and enable it
2810
2809
*****************************************************************************/
2811
bool input_AddSubtitles( input_thread_t *p_input, char *psz_subtitle,
2812
bool b_check_extension )
2810
static void SubtitleAdd( input_thread_t *p_input, char *psz_subtitle, bool b_forced )
2814
2812
input_source_t *sub;
2815
2813
vlc_value_t count;
2816
2814
vlc_value_t list;
2817
2815
char *psz_path, *psz_extension;
2819
if( b_check_extension && !subtitles_Filter( psz_subtitle ) )
2824
2817
/* if we are provided a subtitle.sub file,
2825
2818
* see if we don't have a subtitle.idx and use it instead */
2826
2819
psz_path = strdup( psz_subtitle );
2829
2822
psz_extension = strrchr( psz_path, '.');
2830
2823
if( psz_extension && strcmp( psz_extension, ".sub" ) == 0 )
2834
2827
strcpy( psz_extension, ".idx" );
2835
/* FIXME: a portable wrapper for stat() or access() would be more suited */
2836
if( ( f = utf8_fopen( psz_path, "rt" ) ) )
2829
if( !utf8_stat( psz_path, &st ) )
2839
2831
msg_Dbg( p_input, "using %s subtitles file instead of %s",
2840
2832
psz_path, psz_subtitle );
2841
2833
strcpy( psz_subtitle, psz_path );
2847
2839
var_Change( p_input, "spu-es", VLC_VAR_CHOICESCOUNT, &count, NULL );
2849
2841
sub = InputSourceNew( p_input );
2850
if( !InputSourceInit( p_input, sub, psz_subtitle, "subtitle" ) )
2852
TAB_APPEND( p_input->p->i_slave, p_input->p->slave, sub );
2855
if( !var_Change( p_input, "spu-es", VLC_VAR_GETLIST, &list, NULL ) )
2842
if( InputSourceInit( p_input, sub, psz_subtitle, "subtitle" ) )
2847
TAB_APPEND( p_input->p->i_slave, p_input->p->slave, sub );
2850
if( b_forced && !var_Change( p_input, "spu-es", VLC_VAR_GETLIST, &list, NULL ) )
2852
if( count.i_int == 0 )
2854
/* if it was first one, there is disable too */
2856
if( count.i_int < list.p_list->i_count )
2857
if( count.i_int == 0 )
2859
/* if it was first one, there is disable too */
2858
int i_id = list.p_list->p_values[count.i_int].i_int;
2859
es_out_id_t *p_es = input_EsOutGetFromID( p_input->p->p_es_out, i_id );
2861
if( count.i_int < list.p_list->i_count )
2863
input_ControlPush( p_input, INPUT_CONTROL_SET_ES,
2864
&list.p_list->p_values[count.i_int] );
2866
var_Change( p_input, "spu-es", VLC_VAR_FREELIST, &list, NULL );
2861
es_out_Control( p_input->p->p_es_out, ES_OUT_SET_DEFAULT, p_es );
2862
es_out_Control( p_input->p->p_es_out, ES_OUT_SET_ES, p_es );
2864
var_Change( p_input, "spu-es", VLC_VAR_FREELIST, &list, NULL );
2868
bool input_AddSubtitles( input_thread_t *p_input, char *psz_subtitle,
2869
bool b_check_extension )
2873
if( b_check_extension && !subtitles_Filter( psz_subtitle ) )
2876
assert( psz_subtitle != NULL );
2878
val.psz_string = strdup( psz_subtitle );
2879
if( val.psz_string )
2880
input_ControlPush( p_input, INPUT_CONTROL_ADD_SUBTITLE, &val );