~siretart/vlc/ubuntu

« back to all changes in this revision

Viewing changes to src/input/input.c

  • Committer: Reinhard Tartler
  • Date: 2008-09-26 06:45:40 UTC
  • mto: (21.2.1 vlc-0.9.3)
  • mto: This revision was merged to the branch mainline in revision 23.
  • Revision ID: siretart@tauware.de-20080926064540-0sd8zwmig33ksmy4
Tags: upstream-ubuntu-0.9.3
ImportĀ upstreamĀ versionĀ 0.9.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * input.c: input thread
3
3
 *****************************************************************************
4
4
 * Copyright (C) 1998-2007 the VideoLAN team
5
 
 * $Id: bbccf7e925518293c219eaf932e25250de2208ed $
 
5
 * $Id: 6840657836708c4684c0b2f04efac3bce10fd289 $
6
6
 *
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 );
93
93
 
 
94
static void SubtitleAdd( input_thread_t *p_input, char *psz_subtitle, bool b_forced );
 
95
 
94
96
/*****************************************************************************
95
97
 * This function creates a new input, and returns a pointer
96
98
 * to its description. On error, it returns NULL.
892
894
{
893
895
    double f_fps;
894
896
    vlc_value_t val;
895
 
    int i, i_delay;
 
897
    int i_delay;
896
898
    char *psz;
897
899
    char *psz_subtitle;
898
900
    int64_t i_length;
979
981
    if( psz_subtitle != NULL )
980
982
    {
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 );
983
985
    }
984
986
 
985
987
    var_Get( p_input, "sub-autodetect-file", &val );
986
988
    if( val.b_bool )
987
989
    {
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 );
991
 
        input_source_t *sub;
992
 
        i = 0;
993
 
        if( psz_autopath == NULL )
994
 
            psz_autopath = strdup("");
995
 
 
996
 
        /* Try to autoselect the first autodetected subtitles file
997
 
         * if no subtitles file was specified */
998
 
        if( ( psz_subtitle == NULL ) && subs && subs[0] )
999
 
        {
1000
 
            input_AddSubtitles( p_input, subs[0], false );
1001
 
            free( subs[0] );
1002
 
            i = 1;
1003
 
        }
1004
 
 
1005
 
        /* Then, just add the following subtitles files */
1006
 
        for( ; subs && subs[i]; i++ )
1007
 
        {
1008
 
            if( !psz_subtitle || strcmp( psz_subtitle, subs[i] ) )
1009
 
            {
1010
 
                sub = InputSourceNew( p_input );
1011
 
                if( !InputSourceInit( p_input, sub, subs[i], "subtitle" ) )
1012
 
                {
1013
 
                    TAB_APPEND( p_input->p->i_slave, p_input->p->slave, sub );
1014
 
                }
1015
 
                else free( sub );
1016
 
            }
1017
 
            free( subs[i] );
1018
 
        }
1019
 
        free( subs );
 
991
        char **ppsz_subs = subtitles_Detect( p_input, psz_autopath,
 
992
                                             p_input->p->input.p_item->psz_uri );
1020
993
        free( psz_autopath );
 
994
 
 
995
        for( int i = 0; ppsz_subs && ppsz_subs[i]; i++ )
 
996
        {
 
997
            /* Try to autoselect the first autodetected subtitles file
 
998
             * if no subtitles file was specified */
 
999
            bool b_forced = i == 0 && !psz_subtitle;
 
1000
 
 
1001
            if( !psz_subtitle || strcmp( psz_subtitle, ppsz_subs[i] ) )
 
1002
                SubtitleAdd( p_input, ppsz_subs[i], b_forced );
 
1003
 
 
1004
            free( ppsz_subs[i] );
 
1005
        }
 
1006
        free( ppsz_subs );
1021
1007
    }
1022
1008
    free( psz_subtitle );
1023
1009
 
1864
1850
            }
1865
1851
            break;
1866
1852
 
 
1853
        case INPUT_CONTROL_ADD_SUBTITLE:
 
1854
            if( val.psz_string )
 
1855
            {
 
1856
                SubtitleAdd( p_input, val.psz_string, true );
 
1857
                free( val.psz_string );
 
1858
            }
 
1859
            break;
 
1860
 
1867
1861
        case INPUT_CONTROL_ADD_SLAVE:
1868
1862
            if( val.psz_string )
1869
1863
            {
2472
2466
 
2473
2467
        if( demux_Control( in->p_demux, DEMUX_SET_TIME, i_time ) )
2474
2468
        {
2475
 
            msg_Err( p_input, "seek failed for slave %d -> EOF", i );
 
2469
            if( !in->b_eof )
 
2470
                msg_Err( p_input, "seek failed for slave %d -> EOF", i );
2476
2471
            in->b_eof = true;
2477
2472
        }
 
2473
        else
 
2474
        {
 
2475
            in->b_eof = false;
 
2476
        }
2478
2477
    }
2479
2478
}
2480
2479
 
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 )
2813
2811
{
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;
2818
2816
 
2819
 
    if( b_check_extension && !subtitles_Filter( psz_subtitle ) )
2820
 
    {
2821
 
        return false;
2822
 
    }
2823
 
 
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 )
2831
2824
        {
2832
 
            FILE *f;
 
2825
            struct stat st;
2833
2826
 
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" ) ) )
 
2828
 
 
2829
            if( !utf8_stat( psz_path, &st ) )
2837
2830
            {
2838
 
                fclose( f );
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 );
2848
2840
 
2849
2841
    sub = InputSourceNew( p_input );
2850
 
    if( !InputSourceInit( p_input, sub, psz_subtitle, "subtitle" ) )
2851
 
    {
2852
 
        TAB_APPEND( p_input->p->i_slave, p_input->p->slave, sub );
2853
 
 
2854
 
        /* Select the ES */
2855
 
        if( !var_Change( p_input, "spu-es", VLC_VAR_GETLIST, &list, NULL ) )
 
2842
    if( InputSourceInit( p_input, sub, psz_subtitle, "subtitle" ) )
 
2843
    {
 
2844
        free( sub );
 
2845
        return;
 
2846
    }
 
2847
    TAB_APPEND( p_input->p->i_slave, p_input->p->slave, sub );
 
2848
 
 
2849
    /* Select the ES */
 
2850
    if( b_forced && !var_Change( p_input, "spu-es", VLC_VAR_GETLIST, &list, NULL ) )
 
2851
    {
 
2852
        if( count.i_int == 0 )
 
2853
            count.i_int++;
 
2854
        /* if it was first one, there is disable too */
 
2855
 
 
2856
        if( count.i_int < list.p_list->i_count )
2856
2857
        {
2857
 
            if( count.i_int == 0 )
2858
 
                count.i_int++;
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 );
2860
2860
 
2861
 
            if( count.i_int < list.p_list->i_count )
2862
 
            {
2863
 
                input_ControlPush( p_input, INPUT_CONTROL_SET_ES,
2864
 
                                   &list.p_list->p_values[count.i_int] );
2865
 
            }
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 );
2867
2863
        }
 
2864
        var_Change( p_input, "spu-es", VLC_VAR_FREELIST, &list, NULL );
2868
2865
    }
2869
 
    else free( sub );
2870
 
 
 
2866
}
 
2867
 
 
2868
bool input_AddSubtitles( input_thread_t *p_input, char *psz_subtitle,
 
2869
                               bool b_check_extension )
 
2870
{
 
2871
    vlc_value_t val;
 
2872
 
 
2873
    if( b_check_extension && !subtitles_Filter( psz_subtitle ) )
 
2874
        return false;
 
2875
 
 
2876
    assert( psz_subtitle != NULL );
 
2877
 
 
2878
    val.psz_string = strdup( psz_subtitle );
 
2879
    if( val.psz_string )
 
2880
        input_ControlPush( p_input, INPUT_CONTROL_ADD_SUBTITLE, &val );
2871
2881
    return true;
2872
2882
}
2873
2883